<?php
/* $Id: week_a5.php,v 1.7 2006/04/16 14:40:44 leyeti Exp $ */
error_reporting  (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
$myEnv["module"] = "calendar";
$myEnv["output"] = "html";

include("../../config.inc.php");
include(INCLUDEPATH ."container.inc.php");

// adding file revision into global array
if(function_exists("revisionInit")) revisionInit("\$Revision: 1.7 $", __FILE__);

//// NATYS //// Date langage :
include(CAL1_INC_DIR."date_lang.php");
$_SESSION["date_lang"] = array ("language" => $_SESSION["MGW"]->spkz,
								"lang_dir" => CAL1_DIR."lang/"
								);
///////////////

// HACK for correct display :
echo "<DIV style=\"position:absolute; visibility:hidden; z-index:-1000;\"><img src=\"".$appconf["imgpath"]."/black.gif\" width=\"1\" height=\"1\"></DIV>";

$timemask = $_SESSION["MGW"]->settings["timefmt"];
$concat=$conn->Concat("firstname", "' '", "lastname");

// include laguage specific labels
$smarty->assign("jump_to_date", Lang::getLanguageString("jump_to_date"));
$smarty->assign("jtday", Lang::getLanguageString("jtday"));
$smarty->assign("jtmonth", Lang::getLanguageString("jtmonth"));
$smarty->assign("jtyear", Lang::getLanguageString("jtyear"));
$smarty->assign("jtjump", Lang::getLanguageString("jtjump"));

// SET variable $date
// if $date is not passed, set $date to today
// if $gotodate (is passed by submit for datesearch in main template of day-view) is set,
//    check validity of gotodate and set date to gotodate
if ((!isset($_GET["date"]) || $_GET["date"]=="") && (!isset($_POST["gotodate"]) || $_POST["gotodate"]=="") ){
     $date = mktime(0,0,0, date("m", time()), date("d", time()), date("Y", time()));
	 $_SESSION['calendar_year'] = ((int)$_SESSION["calendar_year"] > 0) ? $_SESSION["calendar_year"] : date("Y", $date);
	 $_SESSION['calendar_month'] = ((int)$_SESSION["calendar_month"] > 0 && (int)$_SESSION["calendar_month"] < 13) ? $_SESSION["calendar_month"] : date("m", $date);
} else if (isset($_POST["gotodate"])){
    if (isset($_GET["gdatum"])){
	    $gmonat = substr($_GET["gdatum"],3,2);
    	$gtag = substr($_GET["gdatum"],0,2);
    	$gjahr = substr($_GET["gdatum"],6,4);
    } else{
    	$gmonat = (int)$_POST["gmonat"];
    	$gtag = (int)$_POST["gtag"];
	    $gjahr = (int)$_POST["gjahr"];
    }

    $gtag = ($gtag > 0) ? $gtag : $_SESSION['calendar_day'];
    $gmonat = ($gmonat > 0) ? $gmonat : $SESSION['calendar_month'];
    $gjahr = ($gjahr > 0) ? $gjahr : $SESSION['calendar_year'];

    if (checkdate($gmonat, $gtag, $gjahr)){
    	$date  = mktime(0,0,0, $gmonat, $gtag, $gjahr);
	    $monat = $gmonat;
    	$jahr  = $gjahr;
	    $_SESSION['calendar_year'] = $gjahr;
    	$_SESSION['calendar_month'] = $gmonat;
    } else if (!isset($_GET["date"])){
    	$date = mktime(0,0,0, date("m", time()), date("d", time()), date("Y", time()));
    	$_SESSION['calendar_year'] = ((int)$_SESSION["calendar_year"] > 0) ? $_SESSION["calendar_year"] : date("Y", $date);
    	$_SESSION['calendar_month'] = ((int)$_SESSION["calendar_month"] > 0 && (int)$_SESSION["calendar_month"] < 13) ? $_SESSION["calendar_month"] : date("m", $date);
    }
}
else{
    $_SESSION['calendar_year'] = ((int)$_SESSION["calendar_year"] > 0) ? $_SESSION["calendar_year"] : date("Y", $_GET["date"]);
    $_SESSION['calendar_month'] = ((int)$_SESSION["calendar_month"] > 0 && (int)$_SESSION["calendar_month"] < 13) ? $_SESSION["calendar_month"] : date("m", $_GET["date"]);
}

// get the settings
$holitemp 	= $_SESSION["MGW"]->settings["calendar_holiday_system"];			// calendar holiday system (country)
$interval 	= $_SESSION["MGW"]->settings["calendar_interval"];			// calender interval length in minutes
$interval_sec   = 60 * $interval;					// calender interval length in seconds
$starthour      = $_SESSION["MGW"]->settings["calendar_viewfrom"];			// start hour of day-view
$endhour   	= $_SESSION["MGW"]->settings["calendar_viewto"];			// last  hour of day-view

// Set certain values for time-handling
$actual_date_arr       = getdate($date);

$app_start_time =  mktime(0,0,0, $actual_date_arr["mon"], $actual_date_arr["mday"], $actual_date_arr["year"]);
$app_end_time   =  mktime(0,0,0, $actual_date_arr["mon"], $actual_date_arr["mday"], $actual_date_arr["year"]) + 23.5 * 3600;
// Set start/end view time according to actual date
$start_time = mktime(0,0,0, $actual_date_arr["mon"], $actual_date_arr["mday"], $actual_date_arr["year"])+ $starthour*3600;
$end_time   = mktime(0,0,0, $actual_date_arr["mon"], $actual_date_arr["mday"], $actual_date_arr["year"])+ $endhour*3600;
$actual_week_start_date     = $start_time - ($actual_date_arr["wday"]-1) * 3600 * 24 - $starthour*3600;
$actual_week_end_date       = $end_time   + (7-$actual_date_arr["wday"]) * 3600 * 24 - $endhour * 3600;

// Set day header in week-view
$woch_arr = array( Lang::getLanguageString("temp_weekday_abbr_1"), Lang::getLanguageString("temp_weekday_abbr_2"), Lang::getLanguageString("temp_weekday_abbr_3"), Lang::getLanguageString("temp_weekday_abbr_4"),
		   Lang::getLanguageString("temp_weekday_abbr_5"), Lang::getLanguageString("temp_weekday_abbr_6"), Lang::getLanguageString("temp_weekday_abbr_0"));

$w = $actual_week_start_date;
for ($i=0;$i<=6;$i++) {
    $j=$i+2;
    $colum = "d$j";
    if (get_celebrate_days($w, $holitemp) != "") $wday = get_celebrate_days($w, $holitemp);
    else if ($i <= 4) $wday = $woch_arr[$i] . ",&nbsp;"./* NATYS date*/date_lang( Lang::getLanguageString("gentemp_date_format_php"), $w) . "";
    else if ($i == 5) $wday = Lang::getLanguageString("gentemp_weekday_7");
    else if ($i == 6) $wday = Lang::getLanguageString("gentemp_weekday_1");
    //$smarty->assign("$colum", "<a class=\"edit\" href=\"index.php?date=$w&amp;".SID."\">$wday</a>");
	$smarty->assign("$colum", "<a class=\"edit\" href=\"javascript:void(0);\">$wday</a>");
    $smarty->append("clm", array("date" => $w, "wkd"=> $woch_arr[$i]));
    $w += 24*3600;
}

$wst_d      = date("d/m",    $actual_week_start_date);
$wen_d      = date("d/m/Y",  $actual_week_end_date);
$sql_start = date("Ymd", $actual_week_start_date);
$sql_ende  = date("Ymd", $actual_week_end_date);

// =======================
//  calendar change
// =======================
if (isset($_POST["new_calendarid"])){
    if ($_POST["new_calendarid"]=="all") {
	$_SESSION['calendarid'] = "all";
	$_SESSION['calendarname'] = Lang::getLanguageString("calendarownerall"); // translated all
    }
    else {
	$sql = "SELECT id, $concat AS name FROM mgw_users WHERE NOT(level=".UDELETED.") AND id = ".$_POST["new_calendarid"];

	if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
	$row = $res->FetchRow();
	$_SESSION['calendarid']   = $row["id"];
	$_SESSION['calendarname'] = $row["name"];
    }
    unset($chgcal);
}

// ===================================
// step one month back in calendar
// ===================================
if (isset($_GET["action"]) && $_GET["action"]=="mback") {
    if ($_SESSION['calendar_month'] == 1) {
	$_SESSION['calendar_month'] = 12;
	$_SESSION['calendar_year']--;
    }
    else $_SESSION['calendar_month']--;
    unset($_GET["action"]);
}

// ===================================
// step one month forward in calendar
// ===================================
if (isset($_GET["action"]) && $_GET["action"]=="mforw") {
    if ($_SESSION['calendar_month'] == 12) {
	$_SESSION['calendar_month'] = 1;
	$_SESSION['calendar_year']++;
    }
    else $_SESSION['calendar_month']++;
    unset($_GET["action"]);
}

// ===================================
// step one year back in calendar
// ===================================
if (isset($_GET["action"]) && $_GET["action"]=="yback") {
    $_SESSION['calendar_year']--;
    unset($_GET["action"]);
}

// ===================================
// step one year forward in calendar
// ===================================
if (isset($_GET["action"]) && $_GET["action"]=="yforw") {
    $_SESSION['calendar_year']++;
    unset($_GET["action"]);
}

// ========================
// GET BIRTHDAYS
// ========================

if($_SESSION["MGW"]->settings["calendar_show_birthdays"]){
    $concat = $conn->Concat("'* '","firstname","' '","lastname");
    $w = $actual_week_start_date;
    for ($i=1;$i<=7;$i++) {
//	$bdsql = "SELECT $concat AS jubilee FROM mgw_contacts WHERE SUBSTRING(birthday,6,5)='".date("m-d",$w)."' AND (ispublic='1' OR owner='".$_SESSION["MGW"]->userid."')";
    $bd_start = $conn->DBDate(mktime(0,0,1,date("m",$w),date("d",$w),date("Y",$w)));
	$bd_end = $conn->DBDate(mktime(23,59,59,date("m",$w),date("d",$w),date("Y",$w)));
	$bdsql = "SELECT $concat AS jubilee
	          FROM mgw_contacts
			  WHERE birthday >= $bd_start AND
				  birthday <= $bd_end AND
			  (ispublic='1' OR owner='".$_SESSION["MGW"]->userid."')";
	if(!$bdres = $conn->Execute($bdsql)) exit(showSQLerror($bdsql, $conn->ErrorMsg(), __LINE__, __FILE__));
	$br = "";
	$bd = array_fill(0,8,"");
	while($bdrow = $bdres->FetchRow()){
    $bd[$i] .= $bdrow["jubilee"].$br;
    $br = "<br />";
	}

	$nam = "klasse$i";
	if (get_celebrate_days(mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$i-1,date("Y",$actual_week_start_date)), $holitemp) != "")
	    $$nam = "feiertag";
	else if ((date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$i-1,date("Y",$actual_week_start_date))) == 0) || (date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$i-1,date("Y",$actual_week_start_date))) == 6))
	    $$nam = "wochenende";
	else if (mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$i-1,date("Y",$actual_week_start_date)) == mktime(0,0,0, date("m",time()),date("j",time()),date("Y",time())))
	    $$nam = "heute";
	else $$nam = "tab";

	$w += 24*3600;
    }
    $zeile = array( "von" => "",
		    "mon" => $bd[1], "tue" => $bd[2], "wed" => $bd[3], "thu" => $bd[4], "fri" => $bd[5], "sat" => $bd[6], "sun" => $bd[7],
		    "klass2" => $klasse1, "klass3" => $klasse2, "klass4" => $klasse3, "klass5" => $klasse4, "klass6" => $klasse5, "klass7" => $klasse6, "klass8" => $klasse7);

	if($bd!=null) $smarty -> append("cw", $zeile);
}

// ========================
// ENTRY WEEKVIEW
// ========================
if(!isset($_GET["action"])) {

    if (!IsSet($_SESSION["calendar_month"]) && !IsSet($_SESSION["calendar_year"])) {
	$_SESSION['calendar_month'] = date("m", $date);
	$_SESSION['calendar_year'] = date("Y", $date);
	$_SESSION["calendar_month"] = $_SESSION['calendar_month'];
	$_SESSION["calendar_year"] = $_SESSION['calendar_year'];
    }

    ////////////////////////////////////////////////////////////////////////
    // set calenderid = userid if calendarid is not set
    ////////////////////////////////////////////////////////////////////////
    if (!isset($_SESSION["calendarid"])) {
	$_SESSION['calendarid']   = $_SESSION["MGW"]->userid;
	$_SESSION['calendarname'] = $_SESSION["MGW"]->fullusername;
    }

    ////////////////////////////////////////////////////////////////////////
    // show user list as possible calendar owners
    ////////////////////////////////////////////////////////////////////////
    $sql = "SELECT id, $concat AS name FROM mgw_users WHERE NOT(level=".UDELETED.") order by 2";

    if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));

    while ($row = $res->FetchRow()){
	$smarty->append("td2", $row);
    }

    $smarty->assign('action', "inh");

    // Selected entry all
    if ($_SESSION['calendarid']=="all") {
	$sql_owner_part="";
    }
    else {
	$sql_owner_part="userid = ".$_SESSION['calendarid']." AND";
    }

   //// NATYS ////
   // $sql = "SELECT * FROM mgw_calendar WHERE $sql_owner_part SUBSTRING(date,1,8) >= '$sql_start' AND substring(date,1,8) <= '$sql_ende'	GROUP BY 1, date , userid , subject, location, private , duration, external, inituserid, day_ind, repeat_mode, rep_from, rep_until, dategroup_id, holiday_id ORDER BY 1";
//      $sql = "SELECT * FROM mgw_calendar WHERE $sql_owner_part SUBSTRING(date,1,8) >= '$sql_start' AND substring(date,1,8) <= '$sql_ende' AND id_class!='3' GROUP BY 1, date , userid , subject, location, private , duration, external, inituserid, day_ind, repeat_mode, rep_from, rep_until, dategroup_id, holiday_id, id_class, id_appt_type, id_location_type, availability, telephone, id_scheduling, subject_summ ORDER BY 1";
   $sql = "SELECT * FROM mgw_calendar
	        WHERE $sql_owner_part date >= ".$conn->DBTimeStamp(mktime(0,0,0, date("m",$actual_week_start_date), date("d",$actual_week_start_date), date("Y",$actual_week_start_date)) )." AND
            date <= ".$conn->DBTimeStamp( mktime(23,59,59, date("m",$actual_week_end_date), date("d",$actual_week_end_date), date("Y",$actual_week_end_date)))." AND id_class!='3'
			GROUP BY 1, date , userid , subject, location, private , duration, external, inituserid, day_ind, repeat_mode, rep_from, rep_until, dategroup_id, holiday_id, id_class, id_appt_type, id_location_type, availability, telephone, id_scheduling, subject_summ
			ORDER BY 1";

   ///////////////

    if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
    $num = $res->RecordCount();

    if ($num > 0){  // week NOT empty:
	//for each appointment:
	while($row = $res->FetchRow()){
	    $vmin  = $res->UnixTimeStamp($row["date"]);
	    $bmin  = $vmin + $row["duration"] * 60;

	    if (get_celebrate_days($vmin, $holitemp) != "") $t_klasse = "feiertag";
	    else if ((date("w", $vmin) == 0) || (date("w", $vmin) == 6))   $t_klasse = "wochenende";
	    else if (mktime(0,0,0, date("m",$vmin),date("j",$vmin),date("Y",$vmin)) ==
		     mktime(0,0,0, date("m",time()),date("j",time()),date("Y",time()))) $t_klasse = "heute";
	    else $t_klasse = "edit";

//// NATYS : color of appointment : appointment type
	//----- appointment type :
	$id_appt_type = $row["id_appt_type"];
	$sql_appt_type = "SELECT * FROM mgw_calendar_appt_type WHERE id=$id_appt_type";
	if(!$res_appt_type = $conn->Execute($sql_appt_type)) exit(showSQLerror($sql_appt_type, $conn->ErrorMsg(), __LINE__, __FILE__));
	$row_appt_type = $res_appt_type->FetchRow();

	$id_class = $row["id_class"];
	if ($id_class!=2) {
	    // appointment is subjected or on standby:
		$sql_class = "SELECT * FROM mgw_calendar_class WHERE id=$id_class";
		if(!$res_class = $conn->Execute($sql_class)) exit(showSQLerror($sql_class, $conn->ErrorMsg(), __LINE__, __FILE__));
		$row_class = $res_class->FetchRow();
		$appointment_type = array( 	"text" => Lang::getLanguageString("gentemp_".$row_appt_type["type"])."&nbsp;:<BR>".Lang::getLanguageString("class_".$row_class["class"]),
								"color"=> $row_class["color"]
							 	 );
	}
	else {
		$appointment_type = array( 	"text" => Lang::getLanguageString("gentemp_".$row_appt_type["type"]),
								"color"=> $row_appt_type["color"]
							 );
	}



/////////////

	    for ($w = $vmin; $w < $bmin; $w += $interval_sec){
		$datum = getdate($w);
		$vzeit = date("His", $w);
		// NATYS : extracted from if and else :
		$klasse[$datum["wday"]][$vzeit] = "$t_klasse";
		$bg_klasse[$datum["wday"]][$vzeit] = $appointment_type["color"];
		if ($w == $vmin){
		    $myid = $row["id"];
		    //NATYS $klasse[$datum["wday"]][$vzeit] = "$t_klasse";


			if ($row["private"] == 1 && $_SESSION['calendarid'] != $_SESSION["MGW"]->userid){
				// private, not owner
				if (!isset($week[$datum["wday"]][$vzeit])) $week[$datum["wday"]][$vzeit] = Lang::getLanguageString("private");
				else if ( $week[$datum["wday"]][$vzeit] == "...")  $week[$datum["wday"]][$vzeit] = Lang::getLanguageString("private");
				else $week[$datum["wday"]][$vzeit] = "<a class=\"edit\" href=\"index.php?action=sel&ind=2&date=$vmin&".SID."\">".Lang::getLanguageString("temp_row_label_1")."</a>";
			}
		    else if ($row["private"] == 0 || $_SESSION['calendarid'] == $_SESSION["MGW"]->userid){
				// not private or owner
				//// NATYS ////
				//if (!isset($week[$datum["wday"]][$vzeit]))   $week[$datum["wday"]][$vzeit] = "<a href=\"details.php?id=$myid&".SID."\" class=\"edit\">".short_string($row["subject"],$max_subject_length)."</a>";
				if (!isset($week[$datum["wday"]][$vzeit])) {
					if ($row["subject_summ"]=="") $week[$datum["wday"]][$vzeit] = "<a href=\"details.php?id=$myid&".SID."\" class=\"editlittle\">".short_string($appointment_type["text"],20)."</a>";
					//else $week[$datum["wday"]][$vzeit] = "<a href=\"details.php?id=$myid&".SID."\" class=\"editlittle\">".short_string(str_decode($row["subject_summ"]),20)."</a>";
					else $week[$datum["wday"]][$vzeit] = "<a href=\"javascript:void(0);\" class=\"editlittle\">".short_string(str_decode($row["subject_summ"]),20)."</a>";
					$idlist[$datum["wday"]][$vzeit] = $myid;
				}
				//else if ( $week[$datum["wday"]][$vzeit] == "...") $week[$datum["wday"]][$vzeit] = "<a href=\"details.php?id=$myid&".SID."\" class=\"edit\">".$row["subject"]."</a>";
				else if ( $week[$datum["wday"]][$vzeit] == "...") {
					$week[$datum["wday"]][$vzeit] = "<a href=\"javascript:void(0);\" class=\"editlittle\">".short_string(str_decode($row["subject_summ"]),20)."</a>";
					$idlist[$datum["wday"]][$vzeit] = $myid;
				}
				//////////
				else if (isset($week[$datum["wday"]][$vzeit]))    $week[$datum["wday"]][$vzeit] = "<a href=\"javascript:void(0);\" class=\"editlittle\">".Lang::getLanguageString("temp_row_label_1")."</a>";
		    }
		}
		else{
		    $week[$datum["wday"]][$vzeit] = "..." ; //"<a href=\"details.php?id=$myid&".SID."\" class=\"editlittle\">...</a>";
    		$idlist[$datum["wday"]][$vzeit] = $myid;
			//NATYS $klasse[$datum["wday"]][$vzeit] = "$t_klasse";
		}
	    } // end for
	}//end while

	// NATYS : classes for header (days)
		$t=$app_start_time;
	    $zeits = date("His", $t);
	    for ($k=1;$k<=7;$k++){
		$head_klasse_nam = "head_klasse$k";
		if (!isset($klasse[$k]["$zeits"])){
		    if (get_celebrate_days( mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)), $holitemp) != "")
			$$head_klasse_nam = "feiertag";
		    else if ((date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 0)
			     || (date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 6))
			$$head_klasse_nam = "wochenende";

		    else if (mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)) ==
			     mktime(0,0,0, date("m",time()),date("j",time()),date("Y",time())))
			$$head_klasse_nam = "heute";
		    else $$head_klasse_nam = "tab";
		 }
		}

	$cw_header = array( "h_klass2"	=>	$head_klasse1,
						"h_klass3"	=>	$head_klasse2,
						"h_klass4"	=>	$head_klasse3,
						"h_klass5"	=>	$head_klasse4,
						"h_klass6"	=>	$head_klasse5,
						"h_klass7"	=>	$head_klasse6,
						"h_klass8"	=>	$head_klasse7
						);
	$smarty->assign("cw_header",$cw_header);
	//////////



	/// properties of each cell per line.
	for($t=$app_start_time; $t<$app_end_time; $t+=$interval_sec){
	    $zeits = date("His", $t);
	    for ($k=1;$k<=6;$k++){
		$nam = "klasse$k";
		$bg_nam = "bg_klasse$k";
		$$bg_nam = IsSet($bg_klasse[$k]["$zeits"]) ? $bg_klasse[$k]["$zeits"] : ""; //$bg_klasse[$k]["$zeits"];
//echo "<br><br>$bg_nam::-> ".$bg_klasse[$k]["$zeits"];
		if (!isset($klasse[$k]["$zeits"])){
		    if (get_celebrate_days( mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)), $holitemp) != "")
			$$nam = "feiertag";
		    else if ((date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 0)
			     || (date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 6))
			$$nam = "wochenende";

		    else if (mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)) ==
			     mktime(0,0,0, date("m",time()),date("j",time()),date("Y",time())))
			$$nam = "heute";
		    else $$nam = "tab";
		}
		else $$nam = $klasse[$k]["$zeits"];
	    }

	    if (!isset($klasse[0]["$zeits"])) $klasse7 = "wochenende";
	    else $klasse7 = $klasse[0]["$zeits"];

		// add some checking for content here KFISH
        if (($t >= $start_time && $t < $end_time) || (isset($week[1][$zeits]) && $week[1][$zeits] != "") || (isset($week[2][$zeits]) && $week[2][$zeits] != "") || (isset($week[3][$zeits]) && $week[3][$zeits] != "") || (isset($week[4][$zeits]) && $week[4][$zeits] != "") || (isset($week[5][$zeits]) && $week[5][$zeits] != "") || (isset($week[6][$zeits]) && $week[6][$zeits] != "") || (isset($week[0][$zeits]) && $week[0][$zeits] != "") ){
		$zeile = array( "von" => date($timemask, $t)."&nbsp;&nbsp;-&nbsp;&nbsp;".date($timemask, $t+$interval_sec),
				"mon" => isset($week[1][$zeits]) ? $week[1][$zeits] : "",
				"tue" => isset($week[2][$zeits]) ? $week[2][$zeits] : "",
				"wed" => isset($week[3][$zeits]) ? $week[3][$zeits] : "",
				"thu" => isset($week[4][$zeits]) ? $week[4][$zeits] : "",
				"fri" => isset($week[5][$zeits]) ? $week[5][$zeits] : "",
				"sat" => isset($week[6][$zeits]) ? $week[6][$zeits] : "",
				"sun" => isset($week[0][$zeits]) ? $week[0][$zeits] : "",
				"id_mon" => isset($idlist[1][$zeits]) ? $idlist[1][$zeits] : "",
				"id_tue" => isset($idlist[2][$zeits]) ? $idlist[2][$zeits] : "",
				"id_wed" => isset($idlist[3][$zeits]) ? $idlist[3][$zeits] : "",
				"id_thu" => isset($idlist[4][$zeits]) ? $idlist[4][$zeits] : "",
				"id_fri" => isset($idlist[5][$zeits]) ? $idlist[5][$zeits] : "",
				"id_sat" => isset($idlist[6][$zeits]) ? $idlist[6][$zeits] : "",
				"id_sun" => isset($idlist[0][$zeits]) ? $idlist[0][$zeits] : "",
				"klass2" => $klasse1,
				"klass3" => $klasse2,
				"klass4" => $klasse3,
				"klass5" => $klasse4,
				"klass6" => $klasse5,
				"klass7" => $klasse6,
				"klass8" => $klasse7,
				/// NATYS ///
				"bg_klass2"	=>	isset($bg_klasse1) ? $bg_klasse1 : "",
				"bg_klass3"	=>	isset($bg_klasse2) ? $bg_klasse2 : "",
				"bg_klass4"	=>	isset($bg_klasse3) ? $bg_klasse3 : "",
				"bg_klass5"	=>	isset($bg_klasse4) ? $bg_klasse4 : "",
				"bg_klass6"	=>	isset($bg_klasse5) ? $bg_klasse5 : "",
				"bg_klass7"	=>	isset($bg_klasse6) ? $bg_klasse6 : "",
				"bg_klass8"	=>	isset($bg_klasse7) ? $bg_klasse7 : ""
				);
				/////////////
		$smarty -> append("cw", $zeile);
		//print_r($zeile);
		//echo "<BR>---<BR>";
	}
	}

    } // end if(num > 0)

    else if ($num==0){ // empty week :
	// no appointmemts that day
	for ($k=1;$k<=7;$k++){
	    $nam = "head_klasse$k";
	    if (get_celebrate_days(mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)), $holitemp) != "")
		$$nam = "feiertag";
	    else if ((date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 0) || (date("w", mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date))) == 6))
		$$nam = "wochenende";
	    else if (mktime(0,0,0, date("m",$actual_week_start_date),date("j",$actual_week_start_date)+$k-1,date("Y",$actual_week_start_date)) == mktime(0,0,0, date("m",time()),date("j",time()),date("Y",time())))
		$$nam = "heute";
	    else $$nam = "tab";
	}

	$cw_header = array( "h_klass2"	=>	$head_klasse1,
						"h_klass3"	=>	$head_klasse2,
						"h_klass4"	=>	$head_klasse3,
						"h_klass5"	=>	$head_klasse4,
						"h_klass6"	=>	$head_klasse5,
						"h_klass7"	=>	$head_klasse6,
						"h_klass8"	=>	$head_klasse7
						);
	$smarty->assign("cw_header",$cw_header);

	for($t=$start_time; $t<$end_time; $t+=$interval_sec) {
	    $leer = array(  "von"  => date($timemask, $t)."&nbsp;&nbsp;-&nbsp;&nbsp;".date($timemask, $t+$interval_sec),
			    "mon"  => " ",
			    "tue"  => " ",
			    "wed"  => " ",
			    "thu"  => " ",
			    "fri"  => " ",
			    "sat"  => " ",
			    "sun"  => " ",
			    "klass2" 	=> "$klasse1",
			    "klass3" 	=> "$klasse2",
			    "klass4" 	=> "$klasse3",
			    "klass5" 	=> "$klasse4",
			    "klass6" 	=> "$klasse5",
			    "klass7" 	=> "$klasse6",
			    "klass8" 	=> "wochenende"
			    );
	    $smarty->append("cw", $leer);
	}
    }

    $kalender  = get_monthview_static( $date, $_SESSION['calendar_year'], $_SESSION['calendar_month']);
    $feiertag  = "(" . get_celebrate_days($date, $holitemp) .	")";
    if ($feiertag == "()") $feiertag = "";
    $gestern  = $date - 3600*168;
    $morgen   = $date + 3600*168;

    // wml-stuff -----------------------
    if($myEnv["output"]=="wml"){
	for($w=-5;$w<5;$w++)  {
	    $d=$date +($w*3600*168);
	    $skw["date"]=$d;
	    $skw["kw"]=get_weeknumber($d);
	    $smarty->append('skw', $skw);
	}
    }
    //----------------------------------

//// NATYS ////
/*
* calweek : texte "semaine n°"
* cur_week : N° de semaine actuelle
*
*/
///////////////

    $weiter = "<a class=\"navlink\" href=\"week_a5.php?date=$morgen&".SID."\" style=\"text-decoration:none;\">" . Lang::getLanguageString("forward"). " &gt;&gt;"  . "</a>";
    $zurueck= "<a class=\"navlink\" href=\"week_a5.php?date=$gestern&".SID."\" style=\"text-decoration:none;\">" . "&lt;&lt; " . Lang::getLanguageString("back"). "</a>";
    $text     = Lang::getLanguageString("calweek")." " . get_weeknumber($date) . "&nbsp;:&nbsp;&nbsp; $wst_d - $wen_d";

	$smarty->assign('weekno',get_weeknumber($date));
    $smarty->assign('SID', SID);
    $smarty->assign('cur_week', "$wst_d-$wen_d");
    $smarty->assign('header_date', $text);
    $smarty->assign('kalender', $kalender);
    $smarty->assign('gestern', $gestern);
    $smarty->assign('morgen', $morgen);
    $smarty->assign('nav_links', $zurueck);
    $smarty->assign('nav_rechts', $weiter);
    $smarty->assign('calendar_owner', $_SESSION['calendarname']);
    $smarty->assign('date', $date);
    $smarty->assign('back', "week_a5.php?date=$gestern&".SID);
    $smarty->assign('weiter', "week_a5.php?date=$morgen&".SID);
    $smarty->assign('inh', "week_a5.php?action=inh&date=$date&".SID);

    if ($_SESSION["MGW"]->userid == $_SESSION['calendarid']){
	$smarty->assign('ntext', " Neuer Termin ");
	$smarty->assign('new', "week_a5.php?action=new&date=$date&".SID);
    }

    $smarty->assign("timefmt", $_SESSION["MGW"]->settings["timefmt"]);
    $smarty->display('calendar_week_a5.tpl');
    $smarty->clear_assign('action');
}
?>
