<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// Manage Calendar Events
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_calendar.gif" width="28" height="18"> '.$MsgText[1][2];
	$BrowserTitle = $MsgText[1][2];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[1][2];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[100] == 'y') {
		
			$query = "select Level,Description from `".$Settings['DBPrefix']."core-Permissions` where Level<=".$UserLevel;
	   		$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$LevelDescriptions[$row['Level']] = $row['Description'];
			}
		
			$PermissionsDropdown = '<option value="0" selected> 0 - '.$MsgText[0][162].'</option>';
			for ($i = 1; $i <= $UserLevel; $i++) {
				if ($LevelDescriptions[$i] != '') {
					$PermissionsDropdown .= '<option value="'.$i.'"> '.$i.' - '.$LevelDescriptions[$i].'</option>';
				}
				else {
					$PermissionsDropdown .= '<option value="'.$i.'"> '.$i.'</option>';
				}
			}
		
		
		
		
			$query55 = "select * from `".$Settings['DBPrefix']."core-Settings` where Name='TimezoneOffset' limit 1";
			$result55 = mysql_query($query55) or die (mysql_error());
			$row55 = mysql_fetch_array($result55);
			if ($row55['Value'] != '') {		
				$TZO = (($row55['Value']+5)*3600);
			}
		
	
			$PageContents = '<br><a href="#new">'.$MsgText[1][6].'</a><br><br><br><b>'.$MsgText[1][7].'</b>';
			
			
			$TodayDateArray = getdate(GetTimestamp());
			$TodayStartTimestamp = mktime(0,0,0,$TodayDateArray['mon'],$TodayDateArray['mday'],$TodayDateArray['year']);
			
			
			//==========
			// Pull the EventIDs for all dates to display, and list them (only once per ID) in an array
			//==========
			
					
			
			$query553 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".(GetTimestamp()+$TZO)." and DateCode<=".(GetTimestamp()+(60*60*24*365)+$TZO)." order by DateCode asc";
			$result553 = mysql_query($query553) or die (mysql_error());
			while ($row553 = mysql_fetch_array($result553)) {
			
				if ($DatesString[$row553['EventID']] != '') {
					$DatesString[$row553['EventID']] .= ', ';
				}
				
				/*$DatesStringCounter[$row553['EventID']]++;
				if ($DatesStringCounter[$row553['EventID']] > 3) {
					$DatesString[$row553['EventID']] .= '<br>';
					$DatesStringCounter[$row553['EventID']] = 1;
				}*/
				
				$DatesString[$row553['EventID']] .= date("n/j/Y", $row553['DateCode']-$TZO);
				
			
			}
			
			
			//==========
			// pull all the events data and if that ID is to be displayed, save it in the array
			//==========
			$query55 = "select * from `".$Settings['DBPrefix']."cl-Events` where MinLevel<='".$UserLevel."' and MinEditLevel<='".$UserLevel."' order by EventType asc, Title asc";
			$result55 = mysql_query($query55) or die (mysql_error());
			
			while ($row55 = mysql_fetch_array($result55)) {
				$EventIDsList[] = $row55['RecordNumber'];
				
				$EventData['StartTime'][$row55['RecordNumber']] = $row55['StartTime'];
				$EventData['EndTime'][$row55['RecordNumber']] = $row55['EndTime'];
				$EventData['Username'][$row55['RecordNumber']] = $row55['Username'];
				$EventData['Title'][$row55['RecordNumber']] = $row55['Title'];
				$EventData['Text'][$row55['RecordNumber']] = $row55['Text'];
					//$EventData['Link'][$row55['RecordNumber']] = $row55['Link'];
				$EventData['EventType'][$row55['RecordNumber']] = $row55['EventType'];
				$EventData['Priority'][$row55['RecordNumber']] = $row55['Priority'];		
			}
			
			
			
			//==========
			
			if (count($EventIDsList) > 0) {
			
				$PageContents .= '<br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="4" alt=""><br><table border="0" cellpadding="2" cellspacing="0"><tr><td bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#222222">'.$MsgText[1][8].'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td bgcolor="'.$BGColor.'" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#222222">'.$MsgText[1][9].'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td bgcolor="'.$BGColor.'" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#222222">'.$MsgText[1][10].'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td align="center" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#222222">'.$MsgText[0][155].' / '.$MsgText[0][156].'</td></tr>';
				
				for ($x = 0; $x < count($EventIDsList); $x++) {
				
					if ($BGColor == '#f1f1f1') {
						$BGColor = '#ffffff';
					}
					else {
						$BGColor = '#f1f1f1';
					}
					
					$TimePrint = '';
					
					if ($EventData['StartTime'][$EventIDsList[$x]] >= 0) {
							
						$Hours = 0;
						$Minutes = 0;
					
						$Seconds = $EventData['StartTime'][$EventIDsList[$x]];
						while ($Seconds >= 3600) {
							$Seconds = $Seconds - 3600;
							$Hours++;					
						}
						while ($Seconds >= 60) {
							$Seconds = $Seconds - 60;
							$Minutes++;					
						}
						
						$Suffix = 'am';
						if ($Hours >= 12) {
							$Hours -= 12;
							$Suffix = 'pm';
						}
						if ($Hours == 0) {
							$Hours = 12;
						}
						
						if ($Minutes < 10) {
							$Minutes = '0' . $Minutes;
						}
																		
						$TimePrint = $Hours . ':' . $Minutes . $Suffix;
	
						//if ($EventData['EndTime'][$EventIDsList[$x]] >= 0 && $EventData['EndTime'][$EventIDsList[$x]] > $EventData['StartTime'][$EventIDsList[$x]]) {
						if ($EventData['EndTime'][$EventIDsList[$x]] >= 0) {
							
							$Hours = 0;
							$Minutes = 0;
					
							$Seconds = $EventData['EndTime'][$EventIDsList[$x]];
							while ($Seconds >= 3600) {
								$Seconds = $Seconds - 3600;
								$Hours++;					
							}
							while ($Seconds >= 60) {
								$Seconds = $Seconds - 60;
								$Minutes++;					
							}
						
							$Suffix = 'am';
							if ($Hours >= 12) {
								$Hours -= 12;
								$Suffix = 'pm';
							}
							if ($Hours == 0) {
								$Hours = 12;
							}
							
							if ($Minutes < 10) {
								$Minutes = '0' . $Minutes;
							}
							
							$TimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix;
								
						}
										
					}
									
					
					$PageContents .= '<tr><td bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="#222222">'.$EventData['Title'][$EventIDsList[$x]].'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td bgcolor="'.$BGColor.'" align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="#222222">'.$TimePrint.'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td bgcolor="'.$BGColor.'" align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="#222222">'.$DatesString[$EventIDsList[$x]].'</font></td><td bgcolor="'.$BGColor.'">&nbsp;&nbsp;</td><td align="center" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="#222222">[ <a href="'.$MainURL.'/admin/calendar-edit/'.$EventIDsList[$x].'"><font color="#222222">'.$MsgText[0][155].'</a> | <a href="'.$MainURL.'/admin/calendar-delete/'.$EventIDsList[$x].'"><font color="#222222">'.$MsgText[0][156].'</a> ]</td></tr>';
				}
		
				$PageContents .= '</table>';
		
			}
			else {
				$PageContents .= '<br>['.$MsgText[1][11].']<br>';
			}
	
			
			
			$DateBoxesYearSelected[date('Y',GetTimestamp())] = ' selected';
			
			
			$PageContents .= '<br><br><br><a name="new"></a><b>'.$MsgText[1][6].'</b><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>
			
			
			<table border="0" cellpadding="3" cellspacing="0"><form action="'.$MainURL.'/admin/calendar-new_event" method="post" name="NewEvent">
        
	<tr>
      <td width="120"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][8].':</b> </td>
      <td><input type="text" name="Title" size="35" maxlength="255"></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][12].':</b> </td>
      <td><textarea name="Text" cols="30" rows="3" wrap="virtual"></textarea></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][13].':</b> </td>
      <td><input type="checkbox" name="UseStartTime" value="y">&nbsp; <select name="StartTimeHour">
	  		<option value="00"> 12</option>
			<option value="01"> 01</option>
			<option value="02"> 02</option>
			<option value="03"> 03</option>
			<option value="04"> 04</option>
			<option value="05"> 05</option>
			<option value="06"> 06</option>
			<option value="07"> 07</option>
			<option value="08"> 08</option>
			<option value="09"> 09</option>
			<option value="10"> 10</option>
			<option value="11"> 11</option>
		</select> <select name="StartTimeMinute">
			<option value="00"> 00</option>
			<option value="05"> 05</option>
			<option value="10"> 10</option>
			<option value="15"> 15</option>
			<option value="20"> 20</option>
			<option value="25"> 25</option>
			<option value="30"> 30</option>
			<option value="35"> 35</option>
			<option value="40"> 40</option>
			<option value="45"> 45</option>
			<option value="50"> 50</option>
			<option value="55"> 55</option>
		</select> <select name="StartTimeAmPm">
			<option value="am"> AM</option>
			<option value="pm"> PM</option>
		</select></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][14].':</b> </td>
      <td><input type="checkbox" name="UseEndTime" value="y"> &nbsp;<select name="EndTimeHour">
	  		<option value="00"> 12</option>
			<option value="01"> 01</option>
			<option value="02"> 02</option>
			<option value="03"> 03</option>
			<option value="04"> 04</option>
			<option value="05"> 05</option>
			<option value="06"> 06</option>
			<option value="07"> 07</option>
			<option value="08"> 08</option>
			<option value="09"> 09</option>
			<option value="10"> 10</option>
			<option value="11"> 11</option>
		</select> <select name="EndTimeMinute">
			<option value="00"> 00</option>
			<option value="05"> 05</option>
			<option value="10"> 10</option>
			<option value="15"> 15</option>
			<option value="20"> 20</option>
			<option value="25"> 25</option>
			<option value="30"> 30</option>
			<option value="35"> 35</option>
			<option value="40"> 40</option>
			<option value="45"> 45</option>
			<option value="50"> 50</option>
			<option value="55"> 55</option>
		</select> <select name="EndTimeAmPm">
			<option value="am"> AM</option>
			<option value="pm"> PM</option>
		</select></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][15].':</b> </td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'">	<input type="checkbox" name="HidePoster" value="yes"> '.$MsgText[0][118].'</td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][16].':</b> </td>
      <td><select name="Month">
			<option value="01"> 01 - '.$MsgText[0][34].'</option>
			<option value="02"> 02 - '.$MsgText[0][35].'</option>
			<option value="03"> 03 - '.$MsgText[0][36].'</option>
			<option value="04"> 04 - '.$MsgText[0][37].'</option>
			<option value="05"> 05 - '.$MsgText[0][38].'</option>
			<option value="06"> 06 - '.$MsgText[0][39].'</option>
			<option value="07"> 07 - '.$MsgText[0][40].'</option>
			<option value="08"> 08 - '.$MsgText[0][41].'</option>
			<option value="09"> 09 - '.$MsgText[0][42].'</option>
			<option value="10"> 10 - '.$MsgText[0][43].'</option>
			<option value="11"> 11 - '.$MsgText[0][44].'</option>
			<option value="12"> 12 - '.$MsgText[0][45].'</option>
		</select> <select name="Day">
			<option value="01"> 01</option>
			<option value="02"> 02</option>
			<option value="03"> 03</option>
			<option value="04"> 04</option>
			<option value="05"> 05</option>
			<option value="06"> 06</option>
			<option value="07"> 07</option>
			<option value="08"> 08</option>
			<option value="09"> 09</option>
			<option value="10"> 10</option>
			<option value="11"> 11</option>
			<option value="12"> 12</option>
			<option value="13"> 13</option>
			<option value="14"> 14</option>
			<option value="15"> 15</option>
			<option value="16"> 16</option>
			<option value="17"> 17</option>
			<option value="18"> 18</option>
			<option value="19"> 19</option>
			<option value="20"> 20</option>
			<option value="21"> 21</option>
			<option value="22"> 22</option>
			<option value="23"> 23</option>
			<option value="24"> 24</option>
			<option value="25"> 25</option>
			<option value="26"> 26</option>
			<option value="27"> 27</option>
			<option value="28"> 28</option>
			<option value="29"> 29</option>
			<option value="30"> 30</option>
			<option value="31"> 31</option>
		</select> <select name="Year">
			<option value="2004"'.$DateBoxesYearSelected[2004].'> 2004</option>
			<option value="2005"'.$DateBoxesYearSelected[2005].'> 2005</option>
			<option value="2006"'.$DateBoxesYearSelected[2006].'> 2006</option>
			<option value="2007"'.$DateBoxesYearSelected[2007].'> 2007</option>
			<option value="2008"'.$DateBoxesYearSelected[2008].'> 2008</option>
			<option value="2009"'.$DateBoxesYearSelected[2009].'> 2009</option>
			<option value="2010"'.$DateBoxesYearSelected[2010].'> 2010</option>
			<option value="2011"'.$DateBoxesYearSelected[2011].'> 2011</option>
			<option value="2012"'.$DateBoxesYearSelected[2012].'> 2012</option>
			<option value="2013"'.$DateBoxesYearSelected[2013].'> 2013</option>
			<option value="2014"'.$DateBoxesYearSelected[2014].'> 2014</option>
			<option value="2015"'.$DateBoxesYearSelected[2015].'> 2015</option>
			<option value="2016"'.$DateBoxesYearSelected[2016].'> 2016</option>
			<option value="2017"'.$DateBoxesYearSelected[2017].'> 2017</option>
			<option value="2018"'.$DateBoxesYearSelected[2018].'> 2018</option>
			<option value="2019"'.$DateBoxesYearSelected[2019].'> 2019</option>
			<option value="2020"'.$DateBoxesYearSelected[2020].'> 2020</option>
		</select>&nbsp;&nbsp;&nbsp;<input type="button" value="'.$MsgText[1][16].'" onClick="if ( document.forms[\'NewEvent\'].elements[\'Dates\'].value == \'\') { document.forms[\'NewEvent\'].elements[\'Dates\'].value = document.forms[\'NewEvent\'].elements[\'Month\'].value + \'/\' + document.forms[\'NewEvent\'].elements[\'Day\'].value + \'/\' + document.forms[\'NewEvent\'].elements[\'Year\'].value; } else { document.forms[\'NewEvent\'].elements[\'Dates\'].value = document.forms[\'NewEvent\'].elements[\'Dates\'].value + \', \' + document.forms[\'NewEvent\'].elements[\'Month\'].value + \'/\' + document.forms[\'NewEvent\'].elements[\'Day\'].value + \'/\' + document.forms[\'NewEvent\'].elements[\'Year\'].value; }"></td>
    </tr>
	<tr>
      <td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][17].':</b> </td>
      <td><input type="text" name="Dates" size="45"><br><font face="'.$FontFace.'" size="1">'.$MsgText[1][18].'<br></font></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][19].':</b> </td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><select name="EventType">
	<option value="1"> '.$MsgText[1][20].'</option>
	<option value="2"> '.$MsgText[1][21].'</option>
</select>
</td>
    </tr>
	<tr>
      <td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[1][22].':</b> </td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><input type="text" name="Priority" size="3"><br><font face="'.$FontFace.'" size="1">'.$MsgText[1][23].'</font></td>
    </tr>
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
    </tr>
	<tr>
      <td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[2][16].':</b> </td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><select name="MinLevel">'.$PermissionsDropdown.'</select></td>
    </tr>
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""></td>
    </tr>
	<tr>
      <td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[0][542].':</b> </td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><select name="MinEditLevel">'.$PermissionsDropdown.'</select></td>
    </tr>
	
	<tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="22" alt=""></td>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="22" alt=""></td>
    </tr>

	<input type="hidden" name="Link" value="">
	
	
	<tr>
	<td colspan="2"><div align="center"><input type="submit" value="'.$MsgText[1][24].'"></div></td>
	</tr>
			</table></form>';
	
	
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	

	// ========================================================================================




?>
