<?

/*
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 block
	// ========================================================================================
	
	$PageTitle = $MsgText[0][151];
	$BrowserTitle = $MsgText[0][151];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL. '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[0][151];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[2] == 'y') {
			
			ReadFormArguments();
			Global $FormArguments;
			
			if (count($FormArguments) > 0) {
			
			
				if ($FormArguments['PageType'] == 2 || $FormArguments['PageType'] == 3) {
					$FormArguments['BlockContents'] = $FormArguments['PageContents2'];
				}
				else {
					$FormArguments['BlockContents'] = $FormArguments['PageContents'];
				}
			
			
			
			if ($FormArguments['ModulesList-core'] == 'y') {
				$ModulesList .= '-core,';
			}
			if ($FormArguments['ModulesList-cl'] == 'y') {
				$ModulesList .= '-cl,';
			}
			if ($FormArguments['ModulesList-mb'] == 'y') {
				$ModulesList .= '-mb,';
			}
			if ($FormArguments['ModulesList-pg'] == 'y') {
				$ModulesList .= '-pg,';
			}
			if ($FormArguments['ModulesList-nl'] == 'y') {
				$ModulesList .= '-nl,';
			}
			if ($FormArguments['ModulesList-gb'] == 'y') {
				$ModulesList .= '-gb,';
			}
			if ($FormArguments['ModulesList-na'] == 'y') {
				$ModulesList .= '-na,';
			}
			if ($FormArguments['ModulesList-lm'] == 'y') {
				$ModulesList .= '-lm,';
			}
			if ($FormArguments['ModulesList-ec'] == 'y') {
				$ModulesList .= '-ec,';
			}
			
			
			for ($x = 0; $x <= intval($FormArguments['LargestPageID']); $x++) {
				if ($FormArguments['PagesList-'.$x] == 'y') {
					$PagesList .= '-'.$x.',';
				}
			}
			
			for ($x = 0; $x <= intval($FormArguments['LargestPageCatID']); $x++) {
				if ($FormArguments['PageCatsList-'.$x] == 'y') {
					$PageCatsList .= '-'.$x.',';
				}
			}	
			
			
			
			
			
			
			
			// 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;
			}
			
		
			
					
			$query2 = "select max(BlockPriority) as MaxPriority from `".$Settings['DBPrefix']."core-Blocks`";
		    	$result2 = mysql_query($query2) or die (mysql_error());
			$row2 = mysql_fetch_array($result2);
								
			$NewPriority = ($row2['MaxPriority'] + 1);
			
				
				
			$query = "INSERT INTO `".$Settings['DBPrefix']."core-Blocks` (AdminLabel, BlockTitle, TitleImage, BlockContents, BlockType, PageType, BlockLocation, BlockAlignment, TitleAlignment, NLtoBR, EnablePHP, BlockPriority, BlockEnabled, MinLevel, MinEditLevel, ConvertLinks, PagesList, PageCatsList, ModulesList) VALUES ('".$FormArguments['AdminLabel']."', '".$FormArguments['BlockTitle']."', '".$FormArguments['TitleImage']."', '".$FormArguments['BlockContents']."', '".$FormArguments['BlockType']."', '".$FormArguments['PageType']."', '".$FormArguments['BlockLocation']."', '".$FormArguments['BlockAlignment']."', '".$FormArguments['TitleAlignment']."', '".$FormArguments['NLtoBR']."', '".$FormArguments['EnablePHP']."', '".$NewPriority."', '".$FormArguments['BlockEnabled']."', '".$FormArguments['MinLevel']."', '".$FormArguments['MinEditLevel']."', '".$FormArguments['ConvertLinks']."', '".$PagesList."', '".$PageCatsList."', '".$ModulesList."')";
		  	$result = mysql_query($query) or die (mysql_error());
			$RecordNumberCreated = mysql_insert_id();
			
				
			if ($FormArguments['BlockType'] == 'cr-1' || $FormArguments['BlockType'] == 'cr-3' || $FormArguments['BlockType'] == 'cr-4' || $FormArguments['BlockType'] == 'cr-5') {
				header('Location: ' . $MainURL . '/admin/blocks-edit/'.$RecordNumberCreated);
			}
			else {
				header('Location: ' . $MainURL . '/admin/blocks.html');
			}
			
			
			}
			else {
				$PageContents = $MsgText[0][98];
			}


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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
