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

// Custom_view
// Moregroupware.org

$myEnv["module"] = "calendar2";
$myEnv["output"] = "html";

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

include (CAL2_INC_DIR.'init.inc.php'); 

error_reporting  (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

$myvars = array("getdate","minical_view");
foreach ($myvars as $thevar) {
  ${$thevar} = (isset($_GET[$thevar])) ? $_GET[$thevar] : (isset($_POST[$thevar]) ? $_POST[$thevar] : "");
}

if ($minical_view=="") $minical_view = $_SESSION["MGW"]->settings["cal2_default_view"];

    if (isset($_SESSION["calendar2_ical"]) and is_array($_SESSION["calendar2_ical"]) and count($_SESSION["calendar2_ical"])!=0) {
      $icals = $_SESSION["calendar2_ical"];
    } else {
      $icals = array();
    }

    $buffer = '<table border="0" cellpadding="0" cellspacing="0" class="V10"><tr><td valign="top" align="left">'."\n";

$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"]!="" and get_right_cal2($row["dcalendar"], "read")) {
    if (is_numeric($row["dcalendar"])) {
	  $cals_groups[] = array($row["dcalendar"],get_group_name($row["dcalendar"]));
	} elseif ($row["dcalendar"][0]=="#") {
	  $cals_holidays[] = substr($row["dcalendar"],1);
	} elseif ($row["dcalendar"][0]=="@") {
	  $cals_others[] = substr($row["dcalendar"],1);
	} else {
	  $cals_users[] = $row["dcalendar"];
	}
  }
}

    $buffer .= "--- ".$hashmap["users"]." ---<br>\n";
    foreach ($cals_users as $user) {
	  $cal_tmp = urlencode($user);
	  $buffer .= "<input type=\"Checkbox\" name=\"icals[]\" value=\"".$cal_tmp."\" ".(in_array($cal_tmp,$icals)?"checked":"")."> ".ucfirst($user)."<br>\n";
    }        

    $buffer .= "<br>--- ".$hashmap["groups"]." ---<br>\n";
    foreach ($cals_groups as $group) {
	  $cal_tmp = urlencode($group[0]);
	  $buffer .= "<input type=\"Checkbox\" name=\"icals[]\" value=\"".$cal_tmp."\" ".(in_array($cal_tmp,$icals)?"checked":"")."> ".ucfirst($group[1])."<br>\n";
    }        

    $buffer .= "<br>--- ".$hashmap["others"]." ---<br>\n";

	foreach ($cals_others as $other) {
		$cal_tmp = urlencode("@".$other);
		$buffer .= "<input type=\"Checkbox\" name=\"icals[]\" value=\"".$cal_tmp."\" ".(in_array($cal_tmp,$icals)?"checked":"")."> ".ucfirst($other)."<br>\n";
	}			

    $buffer .= "<input type=\"Checkbox\" name=\"icals[]\" value=\"birthdays\" ".(in_array("birthdays",$icals)?"checked":"")."> ".$hashmap["birthdays"]."<br>\n";

    $buffer .= "</td><td>&nbsp; &nbsp; &nbsp; </td><td valign='top' align='left'>--- ".$hashmap["holidays"]." ---<br>\n";

    
	foreach ($cals_holidays as $holiday) {
		$cal_tmp = urlencode("#".$holiday);
	    $buffer .= "<input type=\"Checkbox\" name=\"icals[]\" value=\"".$cal_tmp."\" ".(in_array($cal_tmp,$icals)?"checked":"")."> ".$holiday."<br>\n";
	}			
	
	$buffer .= "\n</td></tr></table>";

    $smarty->assign("minical_view",$minical_view);
    $smarty->assign("getdate",$getdate);
    $smarty->assign("buffer",$buffer);

    $smarty->display("calendar2_custom_view.tpl");

?>
