<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# 
#			Event Widget
# 
# ***************************************

$calid = isset($_GET['cal_id'])?$_GET['cal_id']:"";
$id = parser($variables, 'id=');
$page = isset($_GET["calpage".$calid])      ?    ($_GET["calpage".$calid])          :        0;
$pageStart=$page*5;

$mois = array(''.lg("janvier").'',''.lg("fevrier").'', ''.lg("mars").'',''.lg("avril").'',''.lg("mai").'',''.lg("juin").'',''.lg("juillet").'',''.lg("aout").'',''.lg("septembre").'',''.lg("octobre").'',''.lg("novembre").'',''.lg("decembre").'');
$day = date("Y");

if (isset($_GET["calact".$calid])) {
	switch ($_GET["calact".$calid]) {
		case 'add':
			echo '<a name="agenda'.$calid.'"></a>
				<div class="widget_options">
				'.lg("add_event").':
				<form method="post" action="../widgets/scr_widget_112.inc.php?act=add&tab='.$selectedTab.'">
					<input type="hidden" name="id" value="'.$calid.'">
					<input type="hidden" name="uniq" value="'.$uniq.'">
					<input type="hidden" name="mod_id" value="'.$mod_id.'">
					<table cellpadding="0">
						<tr>
						<td>'.lg("title").' </td>
						<td><input type="text" name="title" ></td>
						</tr>
						<tr>
						<td>'.lg("comments").' </td>
						<td><input type="text" name="com"></td>
						</tr>
						<tr>
						<td>'.lg('date').' </td>
						<td><select name="jour">';

			for ( $i=1; $i<=31;$i++) {
				  echo '<option value="'.$i.'"'.($i == date("d")?' selected="selected"':'').'>'.$i.'</option>';
			}

			echo'
						</select>
						<select name="mois">';

			for($i =0; $i<=11; $i++) {
				echo' <option value="'.($i+1).'"'.($i+1 == date("m")?' selected="selected"':'').'>'.$mois[$i].'</option>';
			}

			echo '
						</select>
						<select name="annee">';

			for ($i = ($day-5); $i<=($day+5); $i++) {
				echo'<option value="'.$i.'"'.($i == date("Y")?' selected="selected"':'').'>'.$i.'</option>';
			}

			echo'
						</select>
						</td>
						</tr>
						<tr>
						<td>'.lg("hdbt").' </td>
						<td>
						<select name="heure1">';
                        
			for ($i =0; $i<24;$i++) {
				echo'<option value="'.$i.'">'.$i.'h</option>';
			}
            
			echo'		</select>
						<select name="minute1">'; 
                        
			for ($i=00; $i<60 ; $i=$i+10) {
				echo'<option value="'.$i.'">'.$i.'min</option>';
			}
            
			echo'		</select>
						</td>
						</tr>
						<tr>
						<td>'.lg("hfin").' </td>
						<td>
						<select name="heure2">';

			for ($i =0; $i<24;$i++) {
				echo'<option value="'.$i.'">'.$i.'h</option>';
			}

			echo'		</select>
						<select name="minute2">';

			for ($i=00; $i<60 ; $i=$i+10) {
				echo'<option value="'.$i.'">'.$i.'min</option>';
			}

			echo'		</select>
						</td>
						</tr>
						<tr>
						<td></td>
						<td>
						<input type="submit" value="'.lg("add").'">  <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'">'.lg('cancel').'</a>
						</td>
						</tr>
					</table>
				</form>
				</div>';
			break;
		case 'upd':
			$DB->getResults($widCal_getEvent, $DB->escape($calid),$DB->escape($_SESSION['user_id']));
			$row = $DB->fetch(0);		
			$calid = $row['cal_id'];
			$title = $row['title'];
			$comments = $row['comments'];
			$date = $row['pubdate'];
			$time = $row['time'];
			$etime = $row['endtime'];
	
			echo
			'<a name="agenda'.$calid.'"></a>
			<div class="widget_options">		 
				<form method="post" action="../widgets/scr_widget_112.inc.php?act=upd&cal_id='.$calid.'&tab='.$selectedTab.'">
					<input type="hidden" name="id" value="'.$calid.'">
					<input type="hidden" name="uniq" value="'.$uniq.'">
					<input type="hidden" name="mod_id" value="'.$mod_id.'">
					<table cellpadding="0">
						<tr>
						<td>'.lg("title").' </td>
						<td><input type="text" name="title" value="'.$title.'"></td>
						</tr>
						<tr>
						<td>'.lg("comments").' </td>
						<td><input type="text" name="com" value="'.$comments.'"></td>
						</tr>
						<tr>
						<td>'.lg('date').' </td>
						<td><select name="jour">';

			for ( $i=1; $i<=31;$i++) {
				  echo '<option value="'.$i.'"'.($i == date("d")?' selected="selected"':'').'>'.$i.'</option>';
			}

			echo'
						</select>
						<select name="mois">';

			for($i =0; $i<=11; $i++) {
				echo' <option value="'.($i+1).'"'.($i+1 == date("m")?' selected="selected"':'').'>'.$mois[$i].'</option>';
			}

			echo '
						</select>
						<select name="annee">';

			for ($i = ($day-5); $i<=($day+5); $i++) {
				echo'<option value="'.$i.'"'.($i == date("Y")?' selected="selected"':'').'>'.$i.'</option>';
			}

			echo'
						</select>
						</td>
						</tr>
						<tr>
						<td>'.lg("hdbt").' </td>
						<td>
						<select name="heure1">';
                        
			for ($i =0; $i<24;$i++) {
				echo'<option value="'.$i.'">'.$i.'h</option>';
			}
            
			echo'		</select>
						<select name="minute1">'; 
                        
			for ($i=00; $i<60 ; $i=$i+10) {
				echo'<option value="'.$i.'">'.$i.'min</option>';
			}
            
			echo'		</select>
						</td>
						</tr>
						<tr>
						<td>'.lg("hfin").' </td>
						<td>
						<select name="heure2">';

			for ($i =0; $i<24;$i++) {
				echo'<option value="'.$i.'">'.$i.'h</option>';
			}

			echo'		</select>
						<select name="minute2">';

			for ($i=00; $i<60 ; $i=$i+10) {
				echo'<option value="'.$i.'">'.$i.'min</option>';
			}

			echo'		</select>
						</td>
						</tr>
						<tr>
						<td></td>
						<td>
						<input type="submit" value="'.lg("apply").'"><a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'">'.lg('cancel').'</a>
						</td>
						</tr>
					</table>
				</form>
			</div>';
			break;
	}
}
else {
	$DB->getResults($widCal_getEvents,$DB->escape($id),$DB->escape($_SESSION['user_id']),$DB->escape($pageStart));
	$nbEvents = $DB->nbResults();
	$inc=0;
	$prevDate='';
	echo '
		<a name="agenda'.$calid.'"></a>
		<div class="widget">';

	while (($row = $DB->fetch(0)) && $inc<5) {
		$calid = $row['cal_id'];
		$date = getDBDate($row['pubdate']);
        
		if ($date!=$prevDate) {
			echo '<strong>'.formatDate($date).' :</strong><br />';
		}

		echo '
				'.$row['time'].' > '.$row['title'].'
				<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&cal_id='.$calid.'&uniq='.$uniq.'&calact'.$calid.'=upd"><img src="../../../../images/ico_edit.gif"></a>
				<a href="../widgets/del_widget_112.inc.php?act=del&mod_id='.$mod_id.'&tab='.$selectedTab.'&cal_id='.$calid.'"><img src="../../../../images/ico_close.gif"></a>
				<br />';

		$prevDate=$date;
		$inc++;
	}

	echo '</div>
		<div class="widget_options">
			<a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&calact'.$calid.'=add#agenda">+ '.lg("add_event").'</a>
		</div>';
	
	if ($page!=0) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&calpage'.$calid.'='.($page-1).'#agenda"><img src="../../../../images/ico_next2.gif" /> '.lg('previous').'</a>';
	}
	if($nbEvents==6) {
		echo ' <a href="../scripts/display_widget.php?mod_id='.$mod_id.'&tab='.$selectedTab.'&calpage'.$calid.'='.($page+1).'#agenda">'.lg('next').' <img src="../../../../images/ico_next2.gif" /></a>';
	}
}
	
?>