Location: PHPKode > projects > PhpScheduler > PhpScheduler/template/schedule.template.php
<?php
$basedir = dirname( __FILE__ ) . '/..';
require_once( $basedir . "/lib/date_utils.php" );
require_once( $basedir . "/lib/week_schedule.php" );
require_once( $basedir . "/lib/cours.php" );
require_once( $basedir . "/lib/io.php" );
require_once( $basedir . "/lib/user.php" );

class Schedule_Template {
	var $date_utils;
	var $semaine;
	var $annee;
	var $user;
	var $schedule;
	var $startdate;
	var $stopdate;
	/**
	 * Constructeur de la classe
	 *
	 */
	public function __construct()
	{
		$this -> date_utils = new Date_Utils();
		if ( isset( $_GET["sem"] ) ) {
			$this -> semaine = $_GET["sem"];
		}else {
			$this -> semaine = date( "W" );
			if ( date( "w" ) == 0 || date( "w" ) == 6 ) {
				$this -> semaine++;
				if ( $this -> semaine < 10 ) {
					$this -> semaine = "0" . $this -> semaine;
				}
			}
		}
		if ( isset( $_GET["annee"] ) ) {
			$this -> annee = $_GET["annee"];
		}else {
			$this -> annee = date( "Y" );
		}
		if ( isset( $_SESSION["user"] ) ) {
			$this -> user = unserialize( $_SESSION["user"] );
		}else {
			$this -> user = new user();
		}
		$this -> startdate = $this -> date_utils -> debutsem( $this -> semaine, $this -> annee );
		$this -> stopdate = $this -> date_utils -> finsem( $this -> semaine, $this -> annee );
	}
	/**
	 * Destructeur de la classe
	 *
	 */
	function __destruct()
	{
		unset( $this -> user );
	}
	/**
	 * Affichage de la semaine
	 *
	 */
	public function print_Week()
	{
		$this -> generate_Week_cache( $this -> annee, $this -> semaine );
	}
	/**
	 * Affichage de la liste des semaines
	 *
	 */
	public function print_week_list()
	{
		echo "<div class=\"bubplastic horizontal blue\">\n";
		echo "	<ul>\n";

		for( $i = 1;$i < 54;$i++ ) {
			$semaine_nb = $i;
			if ( $i < 10 ) {
				$semaine_nb = "0" . $i;
			}
			if ( $i == $this -> semaine ) {
				echo "<li class=\"highlight\">\n";
				echo "	<span class=\"menu_r\">\n";
				echo "		<a class=\"info\" href=\"" . $_SERVER["PHP_SELF"] . "?page=schedule&amp;sem=" . $semaine_nb . "&amp;annee=" . $this -> annee . "\">\n";
				echo "			" . $i . "\n";
				echo "			<span>du " . $this -> date_utils -> debutsem( $semaine_nb, $this -> annee ) . "<br />au " . $this -> date_utils -> finsem( $semaine_nb, $this -> annee ) . "</span>\n";
				echo "		</a>\n";
				echo "	</span>\n";
				echo "</li>\n";
			}
			else {
				echo "<li class=\"menu_r\">\n";
				echo "	<span class=\"menu_r\">\n";
				echo "		<a class=\"info\" href=\"" . $_SERVER["PHP_SELF"] . "?page=schedule&amp;sem=" . $semaine_nb . "&amp;annee=" . $this -> annee . "\">\n";
				echo "			" . $i . "\n";
				echo "			<span>du " . $this -> date_utils -> debutsem( $semaine_nb, $this -> annee ) . "<br />au " . $this -> date_utils -> finsem( $semaine_nb, $this -> annee ) . "</span>\n";
				echo "		</a>\n";
				echo "	</span>\n";
				echo "</li>\n";
			}
		}
		echo "</ul>\n";
		echo "</div>\n";
	}
	/**
	 * Generation du fichier cache
	 *
	 * @param int $year
	 * @param int $week
	 * @param Week_Schedule $schedule
	 */
	public function generate_Week_cache( $year, $week, $schedule = false )
	{
		if ( is_bool( $schedule ) ) {
			$this -> schedule = new Week_Schedule( $week, $year );
		}else {
			$this -> schedule = $schedule;
		}
		global $basedir;
		if ( is_writable( $basedir . "/cache" ) ) {
			$cache = fopen( $basedir . "/cache/" . $year . "_" . $week . ".php", 'w' );
			// debug("Mise en cache : OK");
			// debugCache($cache,"semaine = $week");
			fwrite( $cache, '<?php' . "\n" );
			fwrite( $cache, '@session_start();' . "\n" );
			fwrite( $cache, '$basedir = dirname(__FILE__) . "/..";' . "\n" );
			fwrite( $cache, 'require_once($basedir."/lib/user.php");' . "\n" );
			fwrite( $cache, 'if(isset($_SESSION["user"])){' . "\n" );
			fwrite( $cache, '	$user=unserialize($_SESSION["user"]);' . "\n" );
			fwrite( $cache, '}else{' . "\n" );
			fwrite( $cache, '	$user=new user();' . "\n" );
			fwrite( $cache, "}\n" );
			fwrite( $cache, '?>' . "\n" );
			
			fwrite( $cache, "<div id=\"edit_cour\">\n" );
			fwrite( $cache, "<div id=\"edit_cat_titre\" onmousedown=\"startfollow();\" onmouseup=\"stopfollow();\" class=\"subcat_title\">Editer un cours</div>\n" );
			fwrite( $cache, "<div id=\"edittext\">&nbsp;</div>\n" );
			fwrite( $cache, "<div class=\"button\" onclick=\"edit_cours_close();\">Fermer</div>\n" );
			fwrite( $cache, "</div>\n" );
			fwrite( $cache, '<div class="pdf"><a href="cache/pdf/' . $year . '-' . $week . '.pdf"><img alt="to_pdf" src="images/pdf.png" width="32px" /></a><a href="cache/vcalendar/' . $year . '-' . $week . '.ics"><img alt="to_pdf" src="images/ics.gif" width="32px" /></a></div>' . "\n" );
			fwrite( $cache, "<table width=\"100%\" cellspacing=\"0\">\n" );
			fwrite( $cache, "<tr>\n" );
			for( $i = 0;$i < 45;$i++ ) {
				fwrite( $cache, "<td class=\"reftd\">&nbsp;</td>\n" );
			}
			fwrite( $cache, "</tr>\n<tr>\n" );
			fwrite( $cache, "<td class=\"group_name\">&nbsp;</td>\n" );
			for( $i = 8;$i < 19;$i++ ) {
				fwrite( $cache, "<td class=\"h_index\" colspan=\"4\">$i h</td>\n" );
			}
			fwrite( $cache, "</tr>\n" );
			for( $i = 1;$i < 6;$i++ ) {
				$jour = $this -> date_utils -> jourSemaine( $i, $week, $year );
				$moi = $this -> date_utils -> moisSemaine( $i, $week, $year );
				fwrite( $cache, "<tr class=\"Grp1\">\n" );
				fwrite( $cache, "<td class=\"group_name\">1</td>\n" );
				setlocale( LC_TIME, 'fr', 'fr_FR', 'fr_FR.ISO8859-1' );
				for( $h = 0;$h < 44;$h++ ) {
					$timestamp = mktime( ( intval( $h / 4 ) + 8 ), ( ( $h - ( intval( $h / 4 ) * 4 ) ) * 15 ), 0, $moi, $jour, $year );
					if ( $this -> schedule -> cours_exist( $timestamp ) ) {
						$holdh = $h;
						$h = $h + $this -> schedule -> afficheCoursCache( $cache, 1, $timestamp );
						if ( $holdh == $h ) {
							fwrite( $cache, "<td \n" );
							fwrite( $cache, "<?php\n" );
							fwrite( $cache, 'if($user->droits > 1){' . "\n" );
							fwrite( $cache, '	echo " ondblclick=\"addnewcour(\'' . $timestamp . '\',\'1\');\" ";' . "\n" );
							fwrite( $cache, '}' . "\n" );
							fwrite( $cache, "?>\n" );
							fwrite( $cache, "id=\"ts_" . $timestamp . "_grp1\" title=\"" . strftime( "%H:%M ", $timestamp ) . $this -> date_utils -> joursem( $i, $week, $year ) . "\"></td>\n" );
						}
					}else {
						fwrite( $cache, "<td \n" );
						fwrite( $cache, "<?php\n" );
						fwrite( $cache, 'if($user->droits > 1){' . "\n" );
						fwrite( $cache, '	echo " ondblclick=\"addnewcour(\'' . $timestamp . '\',\'1\');\" ";' . "\n" );
						fwrite( $cache, '}' . "\n" );
						fwrite( $cache, "?>\n" );
						fwrite( $cache, "id=\"ts_" . $timestamp . "_grp1\" title=\"" . strftime( "%H:%M ", $timestamp ) . $this -> date_utils -> joursem( $i, $week, $year ) . "\"></td>\n" );
					}
				}
				fwrite( $cache, "</tr>\n" );
				fwrite( $cache, "<tr class=\"Grp2\">\n" );
				fwrite( $cache, "<td class=\"group_name\">2</td>\n" );
				for( $h = 0;$h < 44;$h++ ) {
					$timestamp = mktime( ( intval( $h / 4 ) + 8 ), ( ( $h - ( intval( $h / 4 ) * 4 ) ) * 15 ), 0, $moi, $jour, $year );
					if ( $this -> schedule -> cours_exist( $timestamp ) ) {
						$holdh = $h;
						$h = $h + $this -> schedule -> afficheCoursCache( $cache, 2, $timestamp );
						if ( $holdh == $h ) {
							fwrite( $cache, "<td \n" );
							fwrite( $cache, "<?php\n" );
							fwrite( $cache, 'if($user->droits > 1){' . "\n" );
							fwrite( $cache, '	echo " ondblclick=\"addnewcour(\'' . $timestamp . '\',\'2\');\" ";' . "\n" );
							fwrite( $cache, '}' . "\n" );
							fwrite( $cache, "?>\n" );
							fwrite( $cache, "id=\"ts_" . $timestamp . "_grp2\" title=\"" . strftime( "%H:%M ", $timestamp ) . $this -> date_utils -> joursem( $i, $week, $year ) . "\"></td>\n" );
						}
					}else {
						fwrite( $cache, "<td \n" );
						fwrite( $cache, "<?php\n" );
						fwrite( $cache, 'if($user->droits > 1){' . "\n" );
						fwrite( $cache, '	echo " ondblclick=\"addnewcour(\'' . $timestamp . '\',\'2\');\" ";' . "\n" );
						fwrite( $cache, '}' . "\n" );
						fwrite( $cache, "?>\n" );
						fwrite( $cache, "id=\"ts_" . $timestamp . "_grp2\" title=\"" . strftime( "%H:%M ", $timestamp ) . $this -> date_utils -> joursem( $i, $week, $year ) . "\"></td>\n" );
					}
				}
				fwrite( $cache, "</tr>\n<tr class=\"interday\">\n<td colspan=\"45\"></td>\n</tr>\n" );
			}
			fwrite( $cache, "</table>\n" );
			fclose( $cache );
		}else {
			echo "erreur : " . $basedir . "/cache/" . $year . "_" . $week . " is not writable.";
		}
	}
}
?>
Return current item: PhpScheduler