<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

tb-mgw is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Overview
// Moregroupware.org

// error_reporting  (E_ERROR | E_WARNING | E_PARSE);

Lang::setLocaledText($_SESSION["MGW"]->spkz, "calendar2", "calendar2");

include ROOTPATH."/modules/calendar2/inc/calendar2_func.inc.php";

if (isset($_GET['jumpto_day'])) {
	$jumpto_day_time = strtotime2($_GET['jumpto_day']);
	if ($jumpto_day_time == -1) {
		$getdate = date('Ymd');
	} else {
		$getdate = date('Ymd', $jumpto_day_time);
	}
}

if (!isset($_SESSION["MGW"]->settings["cal2_timezone"]) or $_SESSION["MGW"]->settings["cal2_timezone"] =="") {
  $_SESSION["MGW"]->settings["cal2_timezone"] = 'Same as Server';
}

if (!isset($_SESSION["MGW"]->settings["cal2_num_years"]) or $_SESSION["MGW"]->settings["cal2_num_years"] =="") {
  $_SESSION["MGW"]->settings["cal2_num_years"] = '3';
}
$num_years = $_SESSION["MGW"]->settings["cal2_num_years"];

if (isset($_SESSION["MGW"]->settings["cal2_start_time"]) and $_SESSION["MGW"]->settings["cal2_start_time"] !="") {
  $day_start = $_SESSION["MGW"]->settings["cal2_start_time"];
} else {
  $day_start = '0900';
}

if (isset($_SESSION["MGW"]->settings["cal2_end_time"]) and $_SESSION["MGW"]->settings["cal2_end_time"] !="") {
  $day_end = $_SESSION["MGW"]->settings["cal2_end_time"];
} else {
  $day_end = '1800';
}

if (isset($_SESSION["MGW"]->settings["cal2_grid_length"]) and $_SESSION["MGW"]->settings["cal2_grid_length"] !="") {
  $gridLength = $_SESSION["MGW"]->settings["cal2_grid_length"];
} else {
  $gridLength = '15';
}

if (isset($_SESSION["MGW"]->settings["cal2_start_week"]) and $_SESSION["MGW"]->settings["cal2_start_week"] !="") {
  $week_start_day = $_SESSION["MGW"]->settings["cal2_start_week"];
} else {
  $week_start_day = 'Monday';
}

include(CAL2_INC_DIR.'ical_parser.php');

$daysofweek_lang			= explode(",",$hashmap["daysofweek_lang"]);
$daysofweekshort_lang		= explode(",",$hashmap["daysofweekshort_lang"]);
$daysofweekreallyshort_lang	= explode(",",$hashmap["daysofweekreallyshort_lang"]);
$monthsofyear_lang			= explode(",",$hashmap["monthsofyear_lang"]);
$monthsofyearshort_lang		= explode(",",$hashmap["monthsofyearshort_lang"]);

$unix_time = strtotime2($getdate);
$tomorrows_date = date( 'Ymd', strtotime2('+1 day',  $unix_time));
$yesterdays_date = date( 'Ymd', strtotime2('-1 day',  $unix_time));
$display_date = localizeDate($hashmap["dateFormat_day"], $unix_time);

ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $getdate, $day_array2);
$this_day = $day_array2[3]; 
$this_month = $day_array2[2];
$this_year = $day_array2[1];
$this_week = date("W",$unix_time);

$today_today = date ('Ymd');
ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $today_today, $today_array2);
$today_day = $today_array2[3]; 
$today_month = $today_array2[2];
$today_year = $today_array2[1];
$today_week = date("W");

$all_day = array();
$day_events = array();

if (isset($master_array[$getdate]) and is_array($master_array[$getdate]) and isset($master_array[$getdate]['-1'])) {
  foreach($master_array[$getdate]['-1'] as $my_key => $allday) {
	$all_day[] = array($my_key,$all_cals[$my_key]["summary"],$all_cals[$my_key]["location"],$all_cals[$my_key]["description"]);
  }
}
if (isset($master_array[$getdate]) and is_array($master_array[$getdate]) and count($master_array[$getdate])>0 ) {
  foreach($master_array[$getdate] as $my_key => $this_events) {
    if ($my_key!=-1 and is_array($this_events) and count($this_events)>0) {
      foreach($this_events as $my_key2 => $this_time_arr) {
	    $event_start 	= strtotime2 ($this_time_arr['event_start']);
	    $event_end		= strtotime2 ($this_time_arr['event_end']);

		$event_start 	= date ($hashmap["timeFormat"], $event_start);
		$event_end 		= date ($hashmap["timeFormat"], $event_end);

	 	$day_events[] = array($my_key2,$event_start,$event_end,$all_cals[$my_key2]["summary"],$all_cals[$my_key2]["location"],$all_cals[$my_key2]["description"]);
	  }
	}
  }
}

$smarty->assign("today",localizeDate($hashmap["dateFormat_month_list"]." %Y", $unix_time));
$smarty->assign("all_day",$all_day);
$smarty->assign("day_events",$day_events);

function getcalendar2() {

    global $smarty, $conn, $myEnv;

    return $smarty->fetch("file:".ROOTPATH."/modules/calendar2/templates/default/".$myEnv["output"]."/calendar2_overview.tpl");
}
?>
