prepare(); fill_time_slots(); //fill the timeslots text $agenda_edit = fill_agenda_list(); //get the different agenda's $tpl->assign("year_prev", $y_prev); $tpl->assign("year_next", $y_next); $tpl->assign("month", $month); $tpl->assign("year", $year); $tpl->assign("cur_date", $lang_week[$week_day] . " " . $d . " " . $lang_month[$month] . " " . $year); $tpl->assign("pa_link", $pa_link . "index.php"); for ($i = 1; $i < 13; $i++) { //fill the month's link bar $k = $i + $month -1; //set current month as first entry if ($k > 12) { //if larger as 12 start counting at 1 $k = $i + $month -13; $year_link = $y_next; } else { $year_link = $year; } $m = substr($lang_month[$k], 0, 3); //get the first three letters of month $tpl->assign("m$i", "$m"); } $tpl->assign("year_next", "$y_next >>"); $tpl->assign("year_prev", "<< $y_prev"); if ($d +7 > $nr) { //fill the week forward link $tpl->assign("day_forward", $d +7 - $nr); $tpl->assign("month_forward", $m_next); if (($m_next == 1) and ($m_next < $month)) //next month is in next year { $year_temp = $year +1; $tpl->assign("year_forward", $year_temp . "&a=" . $agenda_edit); } else { $tpl->assign("year_forward", $year . "&a=" . $agenda_edit); } } else { $tpl->assign("day_forward", $d +7); $tpl->assign("month_forward", $month); $tpl->assign("year_forward", $year . "&a=" . $agenda_edit); } if ($d -7 < 1) { //fill the week backward link $tpl->assign("day_back", $nr_prev + $d -7); $tpl->assign("month_back", $m_prev); if (($m_prev == 12) and ($m_next > $month)) //next month is in previous year { $year_temp = $year -1; $tpl->assign("year_back", $year_temp . "&a=" . $agenda_edit); } else { $tpl->assign("year_back", $year . "&a=" . $agenda_edit); } } else { $tpl->assign("day_back", $d -7); $tpl->assign("month_back", $month); $tpl->assign("year_back", $year . "&a=" . $agenda_edit); } foreach ($a as $key => $value) { if ($value == "") { unset ($a[$key]); //get rid of the empty ones } } if (count($a) == 1) { $single_agenda = "1"; $a_sel = array_pop($a); } for ($i = 1; $i < 6; $i++) //fill the week numbers { if ($start_week + $i -2 == 52) { $start_week = 2 - $i; } //reset to week 1 if larger that 52 $w = $start_week + $i -1; if ($single_agenda == 1) { //single agenda number $tpl->assign("w$i", "$w"); } else { $tpl->assign("w$i", $w); } } for ($i = 1; $i < 36; $i++) //fill the day numbers and set colors { // set days and weekend colors if (($i == 6) or ($i == 7) or ($i == 13) or ($i == 14) or ($i == 20) or ($i == 21) or ($i == 27) or ($i == 28) or ($i == 34) or ($i == 35)) { $tpl->assign("color$i", $weekend_color); } else { $tpl->assign("color$i", $day_color); } //set color for the day if ($i + $day -1 < 1) { //days of previous month $day_number = $nr_prev -abs($day) + $i -1; if ($i == 1) { if ($m_prev == 12) { //previous month is dec so we need previous year $query_date_first = "$y_prev-$m_prev-$day_number"; //this is the first date of the 5 weeks period } else { $query_date_first = "$year-$m_prev-$day_number"; } } //this is the first date of the 5 weeks period $week_day = date("w", mktime(12, 0, 0, $m_prev, $d, $y_prev)); $tpl->assign("$i", "$day_number"); $tpl->assign("curdate$i", "document.getElementById('date').innerHTML='$lang_week[$week_day] $day_number $lang_month[$m_prev] $y_prev';"); if (($day_number == date("j")) and ($m_prev == date("n")) and ($y_prev == date("Y"))) { $tpl->assign("color$i", $active_day_color); } } if (($i + $day -1 < $nr +1) and ($i + $day -1 > 0)) { //days of this month $day_number = $day + $i -1; if ($i == 1) { $query_date_first = "$year-$month-$day_number"; } //this is the first date of the 5 weeks period if ($i == 35) { $query_date_last = "$year-$month-$day_number"; } //this is the last date of the 5 weeks period $week_day = date("w", mktime(12, 0, 0, $month, $day_number, $year)); $tpl->assign("$i", "$day_number"); $tpl->assign("curdate$i", "document.getElementById('date').innerHTML='$lang_week[$week_day] $day_number $lang_month[$month] $year';"); if (($day_number == date("j")) and ($month == date("n")) and ($year == date("Y"))) { $tpl->assign("color$i", $active_day_color); } } if ($i + $day -1 > $nr) { //days of next month $day_number = $i - $nr + $day -1; if (($m_next == 1) and ($m_next < $month)) //next month is in next year { $y_next = $year +1; } else { $y_next = $year; } if ($day_number > $nr_next) { //we have a third month $day_number = $day_number - $nr_next; $m_next = $m_next +1; if ($m_next = 13) { $m_next = 1; } } if ($i == 35) { $query_date_last = "$y_next-$m_next-$day_number"; } //this is the last date of the 5 weeks period $week_day = date("w", mktime(12, 0, 0, $m_next, $day_number, $y_next)); $tpl->assign("$i", "$day_number"); $tpl->assign("curdate$i", "document.getElementById('date').innerHTML='$lang_week[$week_day] $day_number $lang_month[$m_next] $y_next';"); if (($day_number == date("j")) and ($m_next == date("n")) and ($y_next == date("Y"))) { $tpl->assign("color$i", $active_day_color); } } } //fill the timeslots from the mysql table //if(count($a) > 1) if ($single_agenda != 1) { //we have multiple agenda's $where_clause = ""; foreach ($a as $value) { if ($value != "") { $where_clause .= " OR agenda = $value"; //create where clause of agenda id's } } $where_clause = substr($where_clause, 3); //strip the first OR $query = "SELECT adate, timeslot, descr, agenda FROM $table_agenda_events WHERE adate >= '$query_date_first' AND adate <= '$query_date_last' AND ($where_clause) ORDER BY adate"; $result = mysql_query($query); //print $query; } else //we have 1 agenda { //$single_agenda = "1" ; // $a_sel = array_pop($a); //get agenda number $query = "SELECT adate, timeslot, descr, agenda FROM $table_agenda_events WHERE adate >= '$query_date_first' AND adate <= '$query_date_last' AND agenda = '$a_sel' ORDER BY adate"; $result = mysql_query($query); } //print $query; $numRows = mysql_num_rows($result); if ($numRows > 0) { $first_day_num = date("z", strtotime($query_date_first)); //get the daynumber of the begin date $first = 1; while ($time_list = mysql_fetch_array($result)) //fill the description from table { if (strtotime($time_list[0]) == strtotime("$year-$month-$d")) //date is current date, fill the time slot { if ($single_agenda == "1") { $tpl->assign("app" . $time_list[1], "
 " . $time_list[2] . "
"); } else { $tpl->assign("app" . $time_list[1], "
 
"); } } $actual_day_num = date("z", strtotime($time_list[0])) + 1; $k = $actual_day_num - $first_day_num; //calculate the number of the day in the 5 weeks if ($k < 1) { //if negative we are in the previous or next year if ($month == 12) { $k = $k +date("z", strtotime("$year-12-31")) + 1; //add the number of days of next year } else { $k = $k +date("z", strtotime("$y_prev-12-31")) + 1; //add the number of days of previous year } } if ($first == 1) //process the very first record { if ($single_agenda == "1") //fill timeslot with text { $temp = "document.getElementById('loc$time_list[1]').innerHTML=' " . addslashes($time_list[2]) . "';"; } else //fill time slot with blank { $temp = "document.getElementById('loc$time_list[1]').innerHTML=' ';"; } $temp .= "document.getElementById('loc$time_list[1]').style.backgroundColor = '$busy_color';"; $first++; } if ($k > $k_prev) //up to the next day { $tpl->assign("dag$k_prev", $temp); //set timeslot text for the day in the template if ($single_agenda == "1") //fill timeslot with text { $temp = "document.getElementById('loc$time_list[1]').innerHTML=' " . addslashes($time_list[2]) . "';"; } else //fill time slot with blank { $temp = "document.getElementById('loc$time_list[1]').innerHTML=' ';"; } $temp .= "document.getElementById('loc$time_list[1]').style.backgroundColor = '$busy_color';"; } if ($k == $k_prev) { if ($single_agenda == "1") //fill timeslot with text { $temp .= "document.getElementById('loc$time_list[1]').innerHTML=' " . addslashes($time_list[2]) . "';"; } else //fill time slot with blank { $temp .= "document.getElementById('loc$time_list[1]').innerHTML=' ';"; } $temp .= "document.getElementById('loc$time_list[1]').style.backgroundColor = '$busy_color';"; } $k_prev = $k; } $tpl->assign("dag$k_prev", $temp); //process the very last record } $tpl->printToScreen(); ?>