<?php 

	$title = "Exacq Technologies | Video Security Access Control Integrations";
	$meta = "<meta name='description' content='Exacq video management system (VMS) software and network video recorders or video servers integrate with leading access control manufacturers for the ideal IP video security and video surveillance solutions for CCTV. ' />";
	
	$links = "<link rel='stylesheet' href='css/accessControl.css' type='text/css' media='screen' />";
	
	include("/var/www/PHPwebsite/olde_header.php");

	global $CameraTestArray;
	
	$appName = "sroot";
	
	require_once($_SERVER['DOCUMENT_ROOT'].'/zdata/sugar/route_setup.php');
	
	setDetails(); // this adds test camera array
	
	//echo "<pre style='font-size: 8pt;'>";
	//print_r($CameraTestArray);
	//echo "</pre>";
?>

<div class='page-header'>
	<div class='page-header-img'><img src='/menu/images/exacqVision-logo-gray.png' alt='exacqVision Logo Grey' title='exacqVision Logo'></div>
	<div class='page-header-text'><h1 class='enterprise'><?php echo _("Access Control Integration"); ?></h1></div>
</div>

<div id='ac-main'>
<?php
	
	/*
	We need this array for ease of use between what is in the database and the name of the logo's img.
	The array is structured as such:
	What is in the database => What the picture's name is.
	*/
	$manuf_array = Array(
			'AMAG' => 'amag64x32.jpg',
                           'American Direct' => 'AD.png',
			'CEM' => 'cem-logo.png',
			'Brivo' => 'brivo-logo.png',
                        'Continental_Access' => 'Napco.png',
			'CDVI' => 'CDVI-logo.png',
			'DSX' => 'dsx47x33.jpg',
			'G4S' => 'g4s30.jpg',
			'HartmannControls' => 'HartmannControls.jpg',
			'Gallagher' => 'gallagher.png',
			'ICT' => 'ictnew-24.jpg',
			'Identicard' => 'identicard25.jpg',
			'Infinias' => 'infinias30.jpg',
			'Inner_Range' => 'ir32.jpg',
			'Kantech' => 'kantech.png',
			'Keyscan' => 'keyscan34.jpg',
			'Lenel' => 'lenel113x20.jpg',
			'Maxxess' => 'maxxess33.jpg',
			'Open_Options' => 'open-options.png',
			'Paxton' => 'paxton29.gif',
			'PCSC' => 'pcsc23.jpg',
			'Quintron' => 'quintron_logo.png',
			'RBHAccess' => 'RBH-Access-Logo.png',
			'RedCloud' => 'redcloud20.jpg',
			'RS2' => 'rs2-93x30.jpg',
			'SoftwareHouse' => 'Software-House.png',
			'S2' => 's2-31.jpg'
		);
	
	// if the manufacturer field is not filled in
	if (@!$_REQUEST['manufacturer']){	

            $q = "select * from exacq_access_control WHERE deleted=0 and (supported='supported' or supported='basicsupported' or supported='untested') and name not like '%legacy%' ORDER BY manufacturer ASC";
            $q2 = "select * from exacq_access_control WHERE deleted=0 and (supported='supported' or supported='basicsupported' or supported='untested') and name like '%legacy%'  ORDER BY manufacturer ASC";
            
	}
	else{
		
            $q = "select * from exacq_access_control where deleted=0 and (supported='supported' or supported='basicsupported' or supported='untested') and id='".$_REQUEST['manufacturer']."' ORDER BY name ASC";
	}
	
	$p = $db->prepare($q);
	$p->execute();
	$results = $p->fetchAll(PDO::FETCH_ASSOC);
	$resultAmt = $p->rowCount();
        
        if (@!$_REQUEST['manufacturer']){
        $p2 = $db->prepare($q2);
	$p2->execute();
	$results2 = $p2->fetchAll(PDO::FETCH_ASSOC);
	$resultAmt2 = $p2->rowCount();        
	?>
    
        <div id='main-container'>
            <div id='current' class='mc-button selected'>
		<div class='mc-button-title'>Supported Manufacturers</div>
            </div>
            <div id='legacy' class='mc-button'>
		<div class='mc-button-title'>Legacy Manufacturers</div>
            </div>	
            <div id='current-container' class='mc-data-container display-it'><?php echo buildTable($results, $resultAmt); ?></div>
            <div id='legacy-container' class='mc-data-container'><?php echo buildTable($results2, $resultAmt2); ?></div>
	</div>
    
        <?php
        } else {
            echo buildTable($results, $resultAmt, false);
        }
        echo"
	</div><!-- END CONTENT WRAP -->
	<div id='details'></div>";
	
	/*$db = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	
	$dateq = "select date_modified from exacq_access_control_tests where display_on_web = 1 order by date_modified DESC";
	$datep = $db->prepare($dateq);
	$datep->execute();
	$date = $datep->fetchColumn();
	
	echo "<div><i><font size='2' color='lightgrey'>updated ".date("d M Y", strtotime($date))."</i></font></div>";*/
		

	include("/var/www/PHPwebsite/footer.php");
        
 function buildTable($results, $resultAmt, $fullList = true) {
    global $CameraTestArray;
    global $manuf_array;

    $string = "<table border='0' class='acTable'>";

    foreach ($results as $row) {

        @$resultCount++;
        if ($fullList) {
            $productName = str_replace(" - LEGACY", "", $row['name']);
        } else {
            $productName = $row['name'];
        }

        /*
          Grabs the manufacturer name and outputs the manufacturer's logo and displays at top left.
          This also displays the model link and the details about the model to the right of the manufacturer's logo.
         */
        $string .= "
		<tr class='acTr'>
			<td class='acImg' rowspan='2'>
				<a href='" . trim($row['link']) . "' target='_blank'>
					<img id='" . $row['manufacturer'] . "_img' src='https://cdn.exacq.com/images/partners/" . $manuf_array[$row['manufacturer']] . "'>
				</a>
			</td>
			<td class='acProductTr'>			
				<b>Product: 
				<a target=\"_blank\" href=\"" . trim($row['link']) . "\" class='productName'>" . $productName . "</a></b>";

        $string .= "<div class='acContent'>";
        $string .= getCameraTestHTML($row['id']);
        $string .= "</div>";

        //echo "<pre>";
        //print_r($CameraTestArray);
        //echo "</pre>";

        $TestedByExacq = false;
        foreach ($CameraTestArray as $cameraTest) {

            if ($cameraTest['parentID'] == $row['id'] && $cameraTest['recommended'] == 1) {

                $TestedByExacq = true;
            }
        }

        $string .= "<div class='ac-float-container'>";

        //if ($row['manufacturer'] == "Kantech") echo "<a href='/what-is-csa/'><img class='ac-csa' src='/resources/css/images/CSA-check-logo.png'></a>";
        // if exacq supports vca display the approval icon.
        if (@$row['vca'] == 'supported') {
            $string .= "<div class='vcaApprovedImg'>VCA Approved</div>";
        }

        if ($TestedByExacq) {

            $string .= "<div class='acApprovedImg'><img src='/support/images/supported.png' title='" . _("Tested By Exacq") . "' /></div>";
        }


        $string .= "
					<button class='acDetails' id='" . $row['id'] . "' type='button'>" . _("Integration Details") . "</button>
				</div>";

        $string .= "</td>";

        // Separates all the links into an array.
        $links = explode(',', $row['links']);
//        $linkAmt = count($links);
        /*
          Grabs links and displays them.
         */
        $string .= "<tr>
				<td class='acLinksContainer'>";

        if ($row['links']) {

            $count = 0;
            foreach ($links as $l) {

                $count++;

                // Separates the link from the link name.
                $pair = explode('~', $l);

                if (@$pair[0])
                    $string .= "<div class='acLink'><a href='" . trim($pair[0]) . "' target='_blank'>" . @$pair[1] . "</a></div>";
                else
                    $string .= "<div class='acNoNLink'>" . @$pair[1] . "</div>";
            }
        }

        $string .= "</td>
			</tr>";

        $string .= "
			</tr>";

        if (@!$_REQUEST['manufacturer']) {
            $string .= "<tr><td colspan=2 class='ac-permalink-container'><a style='color: lightgrey;' href='?manufacturer=" . $row['id'] . "'><button type='button' class='perma-button'></button></a></td></tr>";
        }

        if (@$resultCount != @$resultAmt)
            $string .= "<tr><td colspan=2><br><hr><br></td></tr>";
    }

    $string .= "</table>";
    return $string;
}        
        
        
        

function getCameraTestHTML ($parentID) {

	global $CameraTestArray;
	
	$testedByExacq = array();
		$notTested = array();
	      $results = array();
	
	foreach ($CameraTestArray as $cameraTest) {
	
		if ($cameraTest['parentID'] == $parentID) {
		
			if ($cameraTest['recommended'] == 1) { // has been tested by exacq
			
				$testedByExacq[] = $cameraTest;
			}
			else $notTested[] = $cameraTest;
		}
	}
	
	foreach ($testedByExacq as $array) {
	
		$results[] = $array;
	}
	
	foreach ($notTested as $array) {
	
		$results[] = $array;
	}
	
	//echo "<pre>";
	//print_r($testedByExacq);
	//echo "</pre>";
	
	$tabAmt = count($results);
	
	$HTML = "<div class='tabs'>";
	
	if ($tabAmt > 1) {
	
		$HTML .= "
		<div class='tabHeader'>
			<div class='dt_imageHeader' style='text-align: right; padding-right: 70px;'>
				<img src='images/firmware-icon.png'>
				<div class='tabHeader-text-top'>"._("Select Firmware-Server Version")."</div>
			</div>
		</div>
		<br>";
	}
	
	$HTML .= "
	<table class='tabTable' camTests='".$tabAmt."'>
	<tr>
	<td>";
	
	if ($tabAmt > 1) {
	
		$HTML .= "<ul class='tabContainer'>";
		
		$i=0;
		foreach ($results as $ac) {
	
			$HTML .= "<li><a href='.tab_".$i."' onclick='return false;'><span>".$ac['ac_version']."</span></a></li>";
			$i++;
		}
		
		$HTML .= "</ul>";
		
		$i=0;
		foreach ($results as $ac) {
			
			$HTML .= "
			<div class='tab_".$i." tabResult'> <!-- ".$ac['name']." -->
			
				<table class='detailsTable'>
					<tr><td colspan='2'>".$ac['name']." "._("Test Performed on")." ".$ac['date_entered']." UTC</td></tr>
					<tr>
						<td colspan='2' style='background-color: white;'>
							<div class='dt_imageHeader'>
								<img src='images/test-record-icon.png'>
								<div class='tabHeader-text'>"._("Version")."</div>
							</div>
						</td>
					</tr>
					<tr><td colspan='2'>";
					
					if ($ac['recommended'] == 1)
						$HTML .= '<span style="color: green; font-weight: bold">'._("Tested By Exacq");
					else
						$HTML .= '<span style="color: red; font-weight: bold">'._("Untested by Exacq");
						
					$HTML .= "
					</span></td></tr>
					<tr><td>Access Control "._("Version")."</td><td>".$ac['ac_version']."</td></tr>
					<tr><td>exacqVision Server "._("Version")."</td><td>".$ac['evserver_version']."</td></tr>
					<tr><td>"._("Plugin Version")."</td><td>".$ac['plugin_ver']."</td></tr>
					<tr><td>OS "._("Support")."</td><td>".$ac['os_support']."</td></tr>
					<tr><td>"._("Integration Support Contact")."</td><td>".$ac['support_contact']."</td></tr>";
					
					if ($ac['plugin_download'] == "") {
					
						$HTML .= "<tr><td>"._("Plugin Link")."</td><td>".$ac['no_plugin_link']."</td></tr>";
					}
					else {
						
						if (stripos($ac['plugin_download'], "?type=") != false) $ac['plugin_download'] = str_replace("?type=", "?section=", $ac['plugin_download']);
						
						$HTML .= "<tr><td>"._("Plugin Link")."</td><td><a href='".trim($ac['plugin_download'])."'>["._("View Link")."]</a></td></tr>";
					}
					
					if ($ac['integration_guide'] == "") {
					
						$HTML .= "<tr><td>"._("Integration Guide")."</td><td>".$ac['no_int_guide']."</td></tr>";
					}
					else {
						$HTML .= "<tr><td>"._("Integration Guide")."</td><td><a href='".trim($ac['integration_guide'])."'>[View Link]</a></td></tr>";
					}
					
					$HTML .= "
					<tr>
						<td colspan='2' style='background-color: white;'>
							<div class='dt_imageHeader'>
								<img src='images/functional-info-icon.png'>
								<div class='tabHeader-text'>"._("Functionality")."</div>
							</div>
						</td>
					</tr>
					<tr><td>Enterprise "._("License Required")."</td>";
					
					if ($ac['enterprise']) {
						$HTML .= '<td>'._("Required").'</td></tr>';
					}
					else {
						$HTML .= '<td>'._("Not Required").'</td></tr>';
					}
					
					$HTML .= "<tr><td>"._("Video Playback")."</td>";
					$HTML .= parseTest($ac['video_playback']);
					
					$HTML .= "<tr><td>"._("Video Export")."</td>";
					$HTML .= parseTest($ac['video_export']);
					
					$HTML .= "<tr><td>"._("Input Triggers")."</td>";
					$HTML .= parseTest($ac['input_trigger_result']);
					
					$HTML .= "<tr><td>"._("Soft Triggers")."</td>";
					$HTML .= parseTest($ac['soft_triggers']);
					
					$HTML .= "<tr><td>"._("Camera Views")."</td>";
					$HTML .= parseTest($ac['views_results']);
					
					$HTML .= "<tr><td>PTZ "._("Control")."</td>";
					$HTML .= parseTest($ac['ptz_result']);
					
					$HTML .= "
					<tr><td>"._("Notes")."</td><td>".$ac['description']."</td></tr>
				</table>
			</div> <!-- END ".$ac['name']." Tab Content-->";
			
			$i++;
		}
	}
	else if ($tabAmt == 0) { // if there are no details
	
		echo "<div>"._("There are no integration details for this product").".</div>";
	}
	else {
	
		foreach ($results as $ac) {
	
			$HTML .= "
			<div class='tab-0' class='tabResult'> <!-- ".$ac['name']." -->
				<table class='detailsTable'>
					<tr><td colspan='2'>".$ac['name']." "._("Test Performed on")." ".$ac['date_entered']." UTC</td></tr>
					<tr>
						<td colspan='2' style='background-color: white;'>
							<div class='dt_imageHeader'>
								<img src='images/test-record-icon.png'>
								<div style='display: inline-block; vertical-align: middle;'>"._("Version")."</div>
							</div>
						</td>
					</tr>
					<tr><td colspan='2'>";
					
					if ($ac['recommended'] == 1)
						$HTML .= '<span style="color: green; font-weight: bold">'._("Tested By Exacq");
					else
						$HTML .= '<span style="color: red; font-weight: bold">'._("Untested by Exacq");
						
					$HTML .= "
					</span></td></tr>
					<tr><td>Access Control "._("Version")."</td><td>".$ac['ac_version']."</td></tr>
					<tr><td>exacqVision "._("Server Version")."</td><td>".$ac['evserver_version']."</td></tr>
					<tr><td>"._("Plugin Version")."</td><td>".$ac['plugin_ver']."</td></tr>
					<tr><td>OS "._("Support")."</td><td>".$ac['os_support']."</td></tr>
					<tr><td>"._("Integration Support Contact")."</td><td>".$ac['support_contact']."</td></tr>";
					
					if ($ac['plugin_download'] == "") {
					
						$HTML .= "<tr><td>"._("Plugin Link")."</td><td>".$ac['no_plugin_link']."</td></tr>";
					}
					else {
						$HTML .= "<tr><td>"._("Plugin Link")."</td><td><a href='".trim($ac['plugin_download'])."'>["._("View Link")."]</a></td></tr>";
					}
					
					if ($ac['integration_guide'] == "") {
					
						$HTML .= "<tr><td>"._("Integration Guide")."</td><td>".$ac['no_int_guide']."</td></tr>";
					}
					else {
						$HTML .= "<tr><td>"._("Integration Guide")."</td><td><a href='".trim($ac['integration_guide'])."'>["._("View Link")."]</a></td></tr>";
					}
					
					$HTML .= "
					<tr>
						<td colspan='2' style='background-color: white;'>
							<div class='dt_imageHeader'>
								<img src='images/functional-info-icon.png'>
								<div style='display: inline-block; vertical-align: middle;'>"._("Functionality")."</div>
							</div>
						</td>
					</tr>
					<tr><td style=\"font-weight: bold\">Enterprise "._("License Required")."</td>";
					
					if ($ac['enterprise']) {
						$HTML .= '<td>'._("Required").'</td></tr>';
					}
					else {
						$HTML .= '<td>'._("Not Required").'</td></tr>';
					}
					
					$HTML .= "<tr><td>"._("Video Playback")."</td>";
					$HTML .= parseTest($ac['video_playback']);
					
					$HTML .= "<tr><td>"._("Video Export")."</td>";
					$HTML .= parseTest($ac['video_export']);
					
					$HTML .= "<tr><td>"._("Input Triggers")."</td>";
					$HTML .= parseTest($ac['input_trigger_result']);
					
					$HTML .= "<tr><td>"._("Soft Triggers")."</td>";
					$HTML .= parseTest($ac['soft_triggers']);
					
					$HTML .= "<tr><td>"._("Camera Views")."</td>";
					$HTML .= parseTest($ac['views_results']);
					
					$HTML .= "<tr><td>PTZ "._("Control")."</td>";
					$HTML .= parseTest($ac['ptz_result']);
					
					$HTML .= "
					<tr><td>"._("Notes")."</td><td>".$ac['description']."</td></tr>
				</table>
			</div><!-- END ".$ac['name']." CONTENT-->";
		}
	}
	
	$HTML .= "
	</table>
	</div><!-- TABS END -->";
	
	return $HTML;
}

function parseTest($string) {
	switch($string) {
		case "Unsupported":
			$newString = "<td>"._("Unsupported")." (Exacq)</td></tr>";
			break;
		case "UnsupportedManuf":
			global $manuf;
			$newString = "<td>"._("Unsupported")." ($manuf)</td></tr>";
			break;
		case "Untested":
			$newString = "<td>"._("Untested")."</td></tr>";
			break;
		case "Fail":
			$newString = "<td>"._("Failed");
			break;
		case "dash":
			$newString = '<td>-</td></tr>';
			break;
		default:
			$newString = "<td>"._("Passed")."</td></tr>";
			break;
	}

	return $newString;
}
	
function setDetails () {
	
	global $db;
	global $CameraTestArray;
	
	$q = "
	SELECT AC.id as parentID, acTest.id, 
		acTest.name, acTest.date_entered, acTest.ac_version, acTest.ac_version, acTest.evserver_version, acTest.plugin_ver, acTest.display_on_web as display_on_web,
		acTest.os_support, acTest.support_contact, AC.no_plugin_link, acTest.plugin_download, AC.no_int_guide, AC.integration_guide, 
		acTest.video_playback, acTest.video_export, acTest.input_trigger_result, acTest.soft_triggers, acTest.views_results, acTest.ptz_result, 
		acTest.description, acTest.recommended, acTest.enterprise, AC.integration_guide
	FROM exacq_access_control_tests as acTest 
	JOIN exacq_access_control_exacq_access_control_tests_c as acRel
	ON acRel.exacq_acceb7fel_tests_idb=acTest.id 
	JOIN exacq_access_control as AC 
	ON AC.id=acRel.exacq_acce720fcontrol_ida
	WHERE AC.deleted=0 AND acRel.deleted=0 AND acTest.display_on_web=1 
	ORDER BY acTest.date_entered DESC";
	
	$p = $db->prepare($q);
	$p->execute();
	$results = $p->fetchAll(PDO::FETCH_ASSOC);
	$tabAmt = $p->rowCount();
	
	$CameraTestArray = $results;
}
?>		

<script type='text/javascript' src='js/accessControl.js'></script>