<?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
*/

// smenu
// Moregroupware.org

$myvars = array("cal","getdate","minical_view","print","print2");
foreach ($myvars as $thevar) {
  ${$thevar} = (isset($_GET[$thevar])) ? $_GET[$thevar] : (isset($_POST[$thevar]) ? $_POST[$thevar] : "");
}
if ($getdate=="") {	$getdate = date('Ymd'); }
$smarty->assign("print",$print);
$smarty->assign("print2",$print2);

$current_view = str_replace(".php","",basename($_SERVER["PHP_SELF"]));

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';
}

$month_event_lines 		= '1';				// Number of lines to wrap each event title in month view, 0 means display all lines.
$tomorrows_events_lines = '1';				// Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines.
$allday_week_lines 		= '1';				// Number of lines to wrap each event title in all-day events in week view, 0 means display all lines.
$week_events_lines 		= '1';				// Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines.

$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"]);
$hashmap["dow_lang"] = explode(",",$hashmap["dow_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");

$thisday2 = localizeDate($hashmap["dateFormat_week_list"], $unix_time);

$smenu[0]["name"] = Lang::getLanguageString("new_appointment");
$smenu[0]["link"] = "javascript:openEventInfo('', '')";
$smenu[0]["pic"] = "new.gif";

$smenu[1]["name"] = "empty";

$smenu[2]["name"] = Lang::getLanguageString("print");
$smenu[2]["link"] =  ROOTURL."modules/calendar2/".$current_view.".php?print=true&getdate=".$getdate."&".SID;
$smenu[2]["pic"] = "print.gif";
$smenu[2]["target"] = "_blank";
$smenu[2]["static_menu"]["show_only_pic"] = true;

$smenu[3]["name"] = "empty";

$smenu[4]["name"] = Lang::getLanguageString("custom_view");
$smenu[4]["link"] = ROOTURL."modules/calendar2/custom_view.php?minical_view=".$current_view."&getdate=".$getdate."&".SID;
$smenu[4]["pic"] = "custom_view.gif";
$smenu[4]["static_menu"]["show_only_pic"] = true;

$smenu[5]["name"] = Lang::getLanguageString("today_lang");
$smenu[5]["link"] = ROOTURL."modules/calendar2/".$current_view.".php?getdate=".$today_today."&".SID;
$smenu[5]["pic"] = "today_on.gif";
$smenu[5]["static_menu"]["show_only_pic"] = true;

$smenu[6]["name"] = Lang::getLanguageString("day_view_lang");
$smenu[6]["link"] = ROOTURL."modules/calendar2/day.php?getdate=".$getdate."&".SID;
$smenu[6]["pic"] = "day_on.gif";
$smenu[6]["static_menu"]["show_only_pic"] = true;

$smenu[7]["name"] = Lang::getLanguageString("week_view_lang");
$smenu[7]["link"] = ROOTURL."modules/calendar2/week.php?getdate=".$getdate."&".SID;
$smenu[7]["pic"] = "week_on.gif";
$smenu[7]["static_menu"]["show_only_pic"] = true;

$smenu[8]["name"] = Lang::getLanguageString("month_view_lang");
$smenu[8]["link"] = ROOTURL."modules/calendar2/month.php?getdate=".$getdate."&".SID;
$smenu[8]["pic"] = "month_on.gif";
$smenu[8]["static_menu"]["show_only_pic"] = true;

$smenu[9]["name"] = Lang::getLanguageString("month_list_view_lang");
$smenu[9]["link"] = ROOTURL."modules/calendar2/month_list.php?getdate=".$getdate."&".SID;
$smenu[9]["pic"] = "month_on.gif";
$smenu[9]["static_menu"]["show_only_pic"] = true;

$smenu[10]["name"] = Lang::getLanguageString("month_gantt_view_lang");
$smenu[10]["link"] = ROOTURL."modules/calendar2/month_gantt.php?getdate=".$getdate."&".SID;
$smenu[10]["pic"] = "gantt_on.gif";
$smenu[10]["static_menu"]["show_only_pic"] = true;

$smenu[11]["name"] = Lang::getLanguageString("year_view_lang");
$smenu[11]["link"] = ROOTURL."modules/calendar2/year.php?getdate=".$getdate."&".SID;
$smenu[11]["pic"] = "year_on.gif";
$smenu[11]["static_menu"]["show_only_pic"] = true;

$smenu[12]["name"] = Lang::getLanguageString("year_gantt_view_lang");
$smenu[12]["link"] = ROOTURL."modules/calendar2/year_gantt.php?getdate=".$getdate."&".SID;
$smenu[12]["pic"] = "gantt_on.gif";
$smenu[12]["static_menu"]["show_only_pic"] = true;

$smenu[13]["name"] = "empty";

if (queryRights2_bool("root_modules_calendar2_calendarmanager_listcalendars")) {
  $smenu[14]["name"] = Lang::getLanguageString("calendar_manager");
  $smenu[14]["link"] = ROOTURL."modules/calendar2/cal_manager.php?getdate=".$getdate."&".SID;
  $smenu[14]["pic"] = "cal_manager.gif";
}

$custom = "[null, '".Lang::getLanguageString("jump_lang")."',null, null, null,\n";
$custom2 = "<select class=\"stand\" onchange=\"execute_link(this.options[this.selectedIndex].value);\"><option>".Lang::getLanguageString("jump_lang")."</option>\n";

$check_week = strtotime2($getdate);
$start_week_time = strtotime2(dateOfWeek(date("Ymd", strtotime2("$this_year-01-01")), $week_start_day));
$end_week_time = $start_week_time + (6 * 25 * 60 * 60);

/*
$cals_users = array();
$cals_groups = array();
$cals_others = array();
$cals_holidays = array();

$sql = "SELECT dcalendar FROM mgw_calendar2_cals order by dcalendar";
if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
while($row = $res->FetchRow()) {
  if ($row["dcalendar"]!="") {
    if (is_numeric($row["dcalendar"])) {
	  $sql = "SELECT name FROM mgw_groups where id=".(int)$row["dcalendar"];
	  if(!$res2 = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
	  $row2 = $res2->FetchRow();
	  
	  if (isset($row2["name"]) and $row2["name"]!="") $cals_groups[] = array($row["dcalendar"],$row2["name"]);
	} elseif ($row["dcalendar"][0]=="#") {
	  $cals_holidays[] = substr($row["dcalendar"],1);
	} elseif ($row["dcalendar"][0]=="@") {
	  $cals_others[] = substr($row["dcalendar"],1);
	} else {
	  $sql = "SELECT id FROM mgw_users where username=".$conn->Quote($row["dcalendar"]);
	  if(!$res2 = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
	  $row2 = $res2->FetchRow();

	  if (isset($row2["id"]) and is_numeric($row2["id"])) $cals_users[] = $row["dcalendar"];
	}
  }
}
*/

/*
$custom .= "[null, '".Lang::getLanguageString("calendar_lang")."',null, null, null,\n";

$custom .= "[null, '".Lang::getLanguageString("users")."',null, null, null,\n";
$custom2 .= "<optgroup label=\"".Lang::getLanguageString("users")."\">\n";

foreach ($cals_users as $user) {
  $custom .= "[null, '".$user."','".$current_view.".php?cal=".urlencode($user)."&".SID."', null, null],";
  $custom2 .= "<option value=\"".$current_view.".php?cal=".urlencode($user)."&".SID."\">".$user."</option>\n";
}
$custom .= "],";
$custom2 .= "</optgroup>";

$custom .= "[null, '".Lang::getLanguageString("groups")."',null, null, null,\n";
$custom2 .= "<optgroup label=\"".Lang::getLanguageString("groups")."\">\n";

foreach ($cals_groups as $group) {
  $custom .= "[null, '".$group[1]."','".$current_view.".php?cal=".urlencode($group[0])."&".SID."', null, null],";
  $custom2 .= "<option value=\"".$current_view.".php?cal=".urlencode($group[0])."&".SID."\">".$group[1]."</option>\n";
}
$custom .= "],";
$custom2 .= "</optgroup>\n";

if (count($cals_holidays)>0) {
  $custom .= "[null, '".Lang::getLanguageString("holidays")."',null, null, null,";
  $custom2 .= "<optgroup label=\"".Lang::getLanguageString("holidays")."\">\n";

  foreach ($cals_holidays as $holiday) {
    $custom .= "[null, '".$holiday."','".$current_view.".php?cal=#".urlencode($holiday)."&".SID."', null, null],";
    $custom2 .= "<option value=\"#".$current_view.".php?cal=".urlencode($holiday)."&".SID."\">".$holiday."</option>\n";
  }
  $custom .= "],";
  $custom2 .= "</optgroup>\n";
}

if (count($cals_others)>0) {
  $custom .= "[null, '".Lang::getLanguageString("others")."',null, null, null,";
  $custom2 .= "<optgroup label=\"".Lang::getLanguageString("others")."\">\n";

  foreach ($cals_others as $other) {
    $custom .= "[null, '".$other."','".$current_view.".php?cal=@".urlencode($other)."&".SID."', null, null],";
    $custom2 .= "<option value=\"@".$current_view.".php?cal=".urlencode($other)."&".SID."\">".$other."</option>\n";
  }
  $custom .= "],";
  $custom2 .= "</optgroup>\n";
}

$custom .= "],";
*/
/*
$custom .= "[null, '".Lang::getLanguageString("week_lang")."',null, null, null,\n";
$custom .= "[null, 'Q1',null, null, null,".$quarter[0]."],";
$custom .= "[null, 'Q2',null, null, null,".$quarter[1]."],";
$custom .= "[null, 'Q3',null, null, null,".$quarter[2]."],";
$custom .= "[null, 'Q4',null, null, null,".$quarter[3]."],";
$custom .= "],";
*/
$custom .= "[null, '".Lang::getLanguageString("month_lang")."',null, null, null,\n";
$custom2 .= "<optgroup label=\"".Lang::getLanguageString("month_lang")."\">\n";


$month_time = strtotime2("$this_year-01-01");
$getdate_month = date("m", strtotime2($getdate));

for ($i=0; $i<12; $i++) {
	$monthdate = date ("Ymd", $month_time);
	$month_month = date("m", $month_time);
	$select_month = localizeDate(Lang::getLanguageString("dateFormat_month"), $month_time);
    $custom .= "[null, '".$select_month."' ,'month.php?cal=".$cal."&getdate=".$monthdate."&".SID."', null, null],\n";
    $custom2 .= "<option value=\"month.php?cal=".$cal."&getdate=".$monthdate."&".SID."\">".$select_month."</option>\n";
	$month_time = strtotime2 ("+1 month", $month_time);
}

$custom .= "],";
$custom2 .= "</optgroup>\n";

$custom .= "[null, '".Lang::getLanguageString("year_lang")."',null, null, null,\n";
$custom2 .= "<optgroup label=\"".Lang::getLanguageString("year_lang")."\">\n";

$year_time = strtotime2($getdate);
$getdate_year = date("Y", $year_time);

$num_years2 = $num_years;

for ($i=0; $i < ($num_years2 +2); $i++) {
  $year_time2 = strtotime2 ("-$num_years2 year", $year_time);
  $yeardate = date("Ymd", $year_time2);
  $year_year = date ("Y", $year_time2);
  $custom .= "[null, '".$year_year."' ,'year.php?cal=".$cal."&getdate=".$yeardate."&".SID."', null, null],\n";
  $custom2 .= "<option value=\"year.php?cal=".$cal."&getdate=".$yeardate."&".SID."\">".$year_year."</option>\n";
  $num_years2--;
}

$year_time = strtotime2("$this_year-01-01");
$getdate_year = date("Y", strtotime2($getdate));

for ($i=0; $i < ($num_years +1); $i++) {
  $year_year = date ("Y", $year_time);
  $yeardate = date("Ymd", $year_time);
  $custom .= "[null, '".$year_year."' ,'year.php?cal=".$cal."&getdate=".$yeardate."&".SID."', null, null],\n";
  $custom2 .= "<option value=\"year.php?cal=".$cal."&getdate=".$yeardate."&".SID."\">".$year_year."</option>\n";
  $year_time = strtotime2 ("+1 year", $year_time);
}

$custom .= "],";
$custom2 .= "</optgroup>\n";

$custom .= "],";
$custom2 .= "</select>\n";

createSubmenu($smenu);
$smarty->assign("custom_module_menu",$custom);
$smarty->assign("custom_module_menu2",$custom2);

?>
