<?

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



	// ========================================================================================
	// Save New Calendar Event
	// ========================================================================================
	
	$PageTitle = $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') {
	
			$TZO = (($Settings['TimezoneOffset']+5)*3600);
	
	
			ReadFormArguments();
			Global $FormArguments;
			
			if (count($FormArguments) > 0) {
			
				if ($FormArguments['UseStartTime'] == 'y') {
					if ($FormArguments['StartTimeAmPm'] == 'pm') {
						$FormArguments['StartTimeHour'] += 12;
					}
					
					$StartTime = ($FormArguments['StartTimeHour']*60*60) + ($FormArguments['StartTimeMinute']*60);

					if ($FormArguments['UseEndTime'] == 'y') {
						if ($FormArguments['EndTimeAmPm'] == 'pm') {
							$FormArguments['EndTimeHour'] += 12;
						}
					
						$EndTime = ($FormArguments['EndTimeHour']*60*60) + ($FormArguments['EndTimeMinute']*60);
					}
					else {
						$EndTime = -1;
					}
				}
				else {
					$StartTime = -1;
									
					$EndTime = -1;
				}

				
				if ($FormArguments['HidePoster'] != 'yes') {
					$EventPoster = $CookieUsername;
				}
				
																		
				$query55 = "insert into `".$Settings['DBPrefix']."cl-Events` (StartTime,EndTime,Username,Title,Text,Link,EventType,Priority,MinLevel,MinEditLevel) values ('".$StartTime."','".$EndTime."','".$EventPoster."','".$FormArguments['Title']."','".$FormArguments['Text']."','".$FormArguments['Link']."','".$FormArguments['EventType']."','".$FormArguments['Priority']."','".$FormArguments['MinLevel']."','".$FormArguments['MinEditLevel']."')";
				$result55 = mysql_query($query55) or die (mysql_error());
				
				$query55 = "select MAX(RecordNumber) as NewEventID from `".$Settings['DBPrefix']."cl-Events` where Title='".$FormArguments['Title']."' && Text='".$FormArguments['Text']."' limit 1";
				$result55 = mysql_query($query55) or die (mysql_error());
				$row55 = mysql_fetch_array($result55);
				$NewEventID = $row55['NewEventID'];
				
				
				
				if ($FormArguments['Dates'] == '' && $FormArguments['Day'] != '' && $FormArguments['Month'] != '' && $FormArguments['Year'] != '') {
					$FormArguments['Dates'] = $FormArguments['Month'].'/'.$FormArguments['Day'].'/'.$FormArguments['Year'];				
				} 
								
				if ($FormArguments['Dates'] != '') {
					$FormArguments['Dates'] = str_replace(' ', '', $FormArguments['Dates']);
					$DatesList = explode(',', $FormArguments['Dates']);
					
					for ($i = 0; $i < count($DatesList); $i++) {
						list($Month,$Day,$Year) = explode('/', $DatesList[$i], 3);
						
						if ($Day > 0 && $Month > 0 && $Year > 0) {
												
							$DateTimestamp = (mktime (0,0,0,$Month,$Day,$Year)+$TZO);
							
							if ($AlreadyAdded[$DateTimestamp] != 1) {
							
								$query55 = "insert into `".$Settings['DBPrefix']."cl-EventDates` (EventID,DateCode) values ('".$NewEventID."','".$DateTimestamp."')";
								$result55 = mysql_query($query55) or die (mysql_error());
								
								$AlreadyAdded[$DateTimestamp] = 1;
								
							}
						
						}
											
					}			
				}
	
			
				header('Location: ' . $MainURL . '/admin/calendar.html');
				
			}
			else {
				$PageContents = $MsgText[0][98];
			}
			
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	
	

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




?>
