<?

/*
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 page
	// ========================================================================================
	
	$PageTitle = $MsgText[0][276];
	$BrowserTitle = $MsgText[0][276];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/pages.html">'.$MsgText[0][244].'</a> > '.$MsgText[0][276];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[19] == 'y') {
		
				ReadFormArguments();
				Global $FormArguments;
				
				
				if ($FormArguments['PageType'] == 2 || $FormArguments['PageType'] == 3) {
					$FormArguments['PageContents'] = $FormArguments['PageContents2'];
				}
				
				
				$FormArguments['PageContents'] = str_replace('%7BFlexMainURL%7D','{FlexMainURL}',$FormArguments['PageContents']);
					
				
				if ($FormArguments['PageEnabled'] == '') {
					$FormArguments['PageEnabled'] = 1;				
				}
				
				// make sure the min permissions level hasn't been tampered with
				if ($FormArguments['MinLevel'] > $UserLevel) {
					$FormArguments['MinLevel'] = $UserLevel;
				} 
				if ($FormArguments['MinEditLevel'] > $UserLevel) {
					$FormArguments['MinEditLevel'] = $UserLevel;
				}
				
				// and make sure php is off if they don't have permission to enable it
				if ($Permissions[9] != 'y' && $FormArguments['EnablePHP'] = '1') {
					$FormArguments['EnablePHP'] = 0;
				}
				
				
				// if the pagelink was empty, set it as the pageid
				if ($FormArguments['PageLink'] == '') {
					$FormArguments['PageLink'] = $NewID;				
				}
				
				
				
				$StartDate = 0;
				$EndDate = 0;
				if ($FormArguments['UseStartDate'] == 'Yes') {
					if ($FormArguments['SDAmPm'] == 'pm') {
						$FormArguments['SDHour'] += 12;
					}
					$StartDate = mktime($FormArguments['SDHour'], $FormArguments['SDMinute'], 0, $FormArguments['SDMonth'], $FormArguments['SDDay'], $FormArguments['SDYear']);
				}
				if ($FormArguments['UseEndDate'] == 'Yes') {
					if ($FormArguments['EDAmPm'] == 'pm') {
						$FormArguments['EDHour'] += 12;
					}
					$EndDate = mktime($FormArguments['EDHour'], $FormArguments['EDMinute'], 0, $FormArguments['EDMonth'], $FormArguments['EDDay'], $FormArguments['EDYear']);
				}
		
			
				$query = "INSERT INTO `".$Settings['DBPrefix']."core-Pages` (AdminLabel, PageLink, PageTitle, TitleImage, PageParent, PageContents, PageAlignment, TitleAlignment, NLtoBR, EnablePHP, PageEnabled, MinLevel, MinEditLevel, StartDate, EndDate, ConvertLinks, HidePage, PageType, ShowPrintable, ShowEmail, MetaKeywords, MetaDescription, BrowserTitle) VALUES ('".$FormArguments['AdminLabel']."', '".$FormArguments['PageLink']."', '".$FormArguments['PageTitle']."', '".$FormArguments['TitleImage']."', '".$FormArguments['PageCategory']."', '".$FormArguments['PageContents']."', '".$FormArguments['PageAlignment']."', '".$FormArguments['TitleAlignment']."', '".$FormArguments['NLtoBR']."', '".$FormArguments['EnablePHP']."', '".$FormArguments['PageEnabled']."', '".$FormArguments['MinLevel']."', '".$FormArguments['MinEditLevel']."', '".$StartDate."', '".$EndDate."', '".$FormArguments['ConvertLinks']."', '".$FormArguments['HidePage']."', '".$FormArguments['PageType']."', '".$FormArguments['ShowPrintable']."', '".$FormArguments['ShowEmail']."', '".$FormArguments['MetaKeywords']."', '".$FormArguments['MetaDescription']."', '".$FormArguments['BrowserTitle']."')";

		      	$result = mysql_query($query) or die (mysql_error());
				
				
				
				$query = "select RecordNumber from `".$Settings['DBPrefix']."core-Pages` where PageTitle='".$FormArguments['PageTitle']."' and PageContents='".$FormArguments['PageContents']."' and TitleAlignment='".$FormArguments['TitleAlignment']."' and AdminLabel='".$FormArguments['AdminLabel']."' and PageAlignment='".$FormArguments['PageAlignment']."' order by RecordNumber desc limit 1";
		  		$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				if ($FormArguments['PageLink'] == '') {	
					$query = "update `".$Settings['DBPrefix']."core-Pages` set PageLink='".$row['RecordNumber']."' where RecordNumber='".$row['RecordNumber']."' limit 1";
		  			$result = mysql_query($query) or die (mysql_error());	
				}
				
		
		
				if ($FormArguments['PageTypeChanged'] == 'y') {
				
					header('Location: ' . $MainURL . '/admin/pages-edit/'.$row['RecordNumber'].'.html');		
				
				}
				else {
				
					header('Location: ' . $MainURL . '/admin/pages.html');
				
				}

		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
