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

// Year
// Moregroupware.org

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

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

error_reporting  (E_ERROR | E_WARNING | E_PARSE);

$current_view = 'year';
include(CAL2_INC_DIR.'ical_parser.php');

store_calendar_view($current_view);
store_calendar_date($getdate);

$this_year2 = date("Y",strtotime2($getdate));

$startYear = strtotime2 ($this_year."0101");

$checkad = date ("Ymd", $startYear);

$next_year = strtotime2 ("+1 year", strtotime2($getdate));
$next_year = date ("Ymd", $next_year);
$prev_year = strtotime2 ("-1 year", strtotime2($getdate));
$prev_year = date ("Ymd", $prev_year);

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

?>

<center>
<table width="676" border="0" cellspacing="0" cellpadding="0" class="calborder">
	<tr>
		<td align="center" valign="middle" bgcolor="white">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
      			<tr>
      				<td class="navback">
      					<table width="100%" border="0" cellspacing="0" cellpadding="0">
      						<tr>
								<td align="right" width="45%" class="navback"><?php echo "<a class=\"psf\" href=\"year.php?cal=$cal&getdate=$prev_year&".SID."\"><img src=\"".IMGPATH."/left_day.gif\" alt=\"[".$hashmap["last_year_lang"]."]\" border=\"0\" align=\"right\"></a>"; ?></td>
								<td align="center" width="10%" class="navback" nowrap valign="middle"><font class="H20"><?php echo $this_year2; ?></font></td>
      							<td align="left" width="45%" class="navback"><?php echo "<a class=\"psf\" href=\"year.php?cal=$cal&getdate=$next_year&".SID."\"><img src=\"".IMGPATH."/right_day.gif\" alt=\"[".$hashmap["next_year_lang"]."]\" border=\"0\" align=\"left\"></a>"; ?></td>
      						</tr>
      					</table>
      				</td>
      			</tr>
      		</table>
		</td>
	</tr>
</table>
<br>	
<table border="0" width="670" cellspacing="0" cellpadding="0">
	<tr>	
		<?php
		$m=0;	
		$n=0;
		do {
		
		?>
		<td width="210" valign="top" align="left">
			<table border="0" width="210" cellspacing="0" cellpadding="0" class="calborder">
				<tr>
					<td colspan="7">
						<table border="0" width="210" cellspacing="0" cellpadding="0">
							<tr>
								<td width="1" class="sideback"><img src="templates/default/media/spacer.gif" width="1" height="20" alt=" "></td>
								<?php 
									$monthlink = date("Ym", $startYear); 
									$monthlink = $monthlink . $this_day;
								?>
								<td align="center" class="sideback"><?php echo '<a class="ps3" href="month.php?cal=' . $cal . '&getdate=' . $monthlink . '&'.SID.'">'; ?><font class="G10BOLD"><?php print (localizeDate ($hashmap["dateFormat_month"], $startYear)); ?></font></a></td>
								<td width="1" class="sideback"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
				<?php
					$start_day = strtotime2($week_start_day);
					for ($i=0; $i<7; $i++) {
						$day_num = date("w", $start_day);
						$day = $daysofweekshort_lang[$day_num];
						print '<td width="30" height="14" class="dateback" align="center">'.($i==0?'<img src="templates/default/media/spacer.gif" width="15" height="5" alt=" ">':'').'<font class="V9BOLD">' . $day . '</font></td>' . "\n";
						$start_day = strtotime2("+1 day", $start_day); 
					}
				?>
				</tr>
				<tr>
					<td colspan="7">
						<table border="0" width="210" cellspacing="1" cellpadding="0" class="yearmonth">
							<?php
									$minical_time = $startYear;
									$minical_month = date("m", $minical_time);
									$minical_year = date("Y", $minical_time);
									$first_of_month = $minical_year.$minical_month."01";
									$start_day = strtotime2(dateOfWeek($first_of_month, $week_start_day));
									$i = 0;
									$whole_month = TRUE;
									$num_of_events = 0;
									do {
										$day = date ("j", $start_day);
										$daylink = date ("Ymd", $start_day);
										$check_week = date ("W", $start_day);
										$check_month = date ("m", $start_day);
										$style = "";
										if ($check_week==$today_week) {
										  $style = 'style="background-color: #C0FFC0"';
										}
										if ($check_month != $minical_month) $day= "<font class=\"V9G\">$day</font>";
										if ($i == 0) echo '<tr height="30"><td align="center" width="15" class="dateback" '.$style.'><a href="week.php?cal='.$cal.'&getdate='.$daylink.'&'.SID.'" class="psf"><font class="V9G">'.$check_week.'</font></a></td>';
                                        
                                        $theclass = "psf";
                                        
                                        if ($today_day == $day and $today_month == $minical_month and $today_year == $minical_year) {
                                          $theclass = "psf2";
                                        }

										if (isset($master_array[("$daylink")]) && ($check_month == $minical_month)) {
											foreach ($master_array[("$daylink")] as $event_times) {
												foreach ($event_times as $val) {
												  if (!isset($val["event_start"])) $image1 = '<img src="'.IMGPATH.'/allday_dot.gif" alt=" " width="11" height="10" border="0">';
												  if (isset($val["event_start"])) $image2 = '<img src="'.IMGPATH.'/event_dot.gif" alt=" " width="11" height="10" border="0">';
												}
											}	
											echo '<td width="30" height="30" align="right" valign="top" class="monthreg" onclick="window.location.href=\'day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'\'" '.$style.'>' . "\n";
											echo '<table width="100%" border="0" cellspacing="0" cellpadding="1">' . "\n";
											echo '<tr>' . "\n";
											echo '<td align="right" valign="top" class="V9">' . "\n";
											echo '<a class="'.$theclass.'" href="day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'">' . $day . '</a>' . "\n";
											echo '</td>' . "\n";
											echo '</tr>' . "\n";
											echo '<tr>' . "\n";
											echo '<td align="center" valign="top">' . $image1 . $image2 . '</td>' . "\n";
											echo '</tr>' . "\n";
											echo '</table>' . "\n";

										} elseif ($check_month == $minical_month) {
											echo '<td width="30" height="30" align="right" valign="top" class="monthreg" onclick="window.location.href=\'day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'\'" '.$style.'>' . "\n";
											echo '<font class="V9"><a class="'.$theclass.'" href="day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'">' . $day . '</a></font></td>' . "\n";
										} else {
											echo '<td width="30" height="30" align="right" valign="top" class="monthoff" onclick="window.location.href=\'day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'\'" '.$style.'>' . "\n";
											echo '<a class="'.$theclass.'" href="day.php?cal=' . $cal . '&getdate=' . $daylink . '&'.SID.'">' . $day . '</a></td>' . "\n";
										}
										$start_day = strtotime2("+1 day", $start_day); 
										$i++;
										$image1 = '';
										$image2 = '';
										if ($i == 7) { 
											echo '</tr>';
											$i = 0;
											$checkagain = date ("m", $start_day);
											if ($checkagain != $minical_month) $whole_month = FALSE;	
										}
									} while ($whole_month == TRUE);
									$startYear = strtotime2 ("+1 month", $startYear);
								?>
						</table>
					</td>
				</tr>
			</table>
		</td>
		<?php 
				if ($m < 2) echo '<td width="20"><img src="templates/default/media/spacer.gif" width="20" height="1" alt=" "></td>';
				$m++;
				$n++;
				if (($m == 3) && ($n < 12)) {
					$m = 0;
					echo '</tr><tr>';
					echo '<td colspan="5"><img src="templates/default/media/spacer.gif" width="1" height="20" alt=" "></td>';
					echo '</tr><tr>';
				}
			} while (($m < 3) && ($n < 12)); 
		?>
</tr>
</table>
<?php if (!$print) echo $calendar2_footer; ?>
</center>
<?php if (!$print) $smarty->display($appconf["gentemplates"]."/_footer.tpl"); ?>

