<?php
require_once 'includecss.php';
if ($sortie!='prt') require_once 'includejs.php';

function isBuggyIe()
{
	$encodeToIe6 = false;
	$ua = $_SERVER['HTTP_USER_AGENT'];
    // quick escape for non-IEs
    if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
    	|| false !== strpos($ua, 'Opera')) {
        return false;
    }
    // no regex = faaast
    $version = (float)substr($ua, 30);
    return $encodeToIe6
    		? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
    		: ($version < 7);
}

$compressoff = false;

/* == Traitement des feuilles de styles == */

if(isset($tabStyles) && count($tabStyles)>0){
	foreach($tabStyles as $name => $group){
		if( in_array('all', $group['pages']) ||
			in_array($page, $group['pages']) ){
			if( ENVIRONNEMENT == 'DEV' || $sortie=='pdf' ||
				$compressoff || isBuggyIe() ){
				foreach($group['list'] as $style){
					echo '<link rel="stylesheet" type="text/css" media="all" href="css/'.$style.'" />';
					echo "\n";
				}
			}else{
				echo '<link rel="stylesheet" type="text/css" media="all" href="'.EXTRANET_URL.'min/?g='.$name.'"/>';
				echo "\n";
			}
		}
	}
}

/* == Traitement des scripts javascripts == */

$compressoff = false;

if(isset($tabScripts) && count($tabScripts)>0){
	foreach($tabScripts as $name => $group){
		if(in_array('all', $group['pages']) || in_array($page, $group['pages'])){
			if( ENVIRONNEMENT == 'DEV' || $compressoff ){
				foreach($group['list'] as $script){
					echo '<script type="text/javascript" src="js/'.$script.'"></script>';
					echo "\n";
				}
			}else{
				echo '<script type="text/javascript" src="scripts/'.$name.'.js"></script>';
				echo "\n";
			}
		}
	}
}

if($sortie == 'prt'){
?>
<script type="text/javascript">
window.onload = function() {
	window.print();
	window.close();
}
</script>
<?php
}