<?

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



	// ========================================================================================
	// edit block save
	// ========================================================================================
	
	$PageTitle = $MsgText[0][240];
	$BrowserTitle = $MsgText[0][240];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL. '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL. '/admin/blocks.html">'.$MsgText[0][151].'</a> > '.$MsgText[0][240];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		ReadFormArguments();
		Global $FormArguments;
		
				
		
		$query = "select MinLevel,MinEditLevel from `".$Settings['DBPrefix']."core-Blocks` WHERE RecordNumber='".$FormArguments['BlockIDToEdit']."' LIMIT 1";
    	$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		if ($Permissions[2] == 'y' && $row['MinLevel'] <= $UserLevel && $row['MinEditLevel'] <= $UserLevel) {
	
				
			if (count($FormArguments) > 0) {
			
			
				if ($FormArguments['PageType'] == 2 || $FormArguments['PageType'] == 3) {
					$FormArguments['BlockContents'] = $FormArguments['BlockContents2'];
				}
				else {
					$FormArguments['BlockContents'] = $FormArguments['BlockContents'];
				}
			
			
			if ($FormArguments['CreateNewBulk'] == 'y') {
			
				//print 'new bulk';
				
				for ($x = 0; $x <= intval($FormArguments['LargestPageID']); $x++) {
					if ($FormArguments['BPagesList-'.$x] == 'y') {
						
						$query69 = "select * from `".$Settings['DBPrefix']."core-Pages` WHERE RecordNumber='".$x."' LIMIT 1";
    					$result69 = mysql_query($query69) or die (mysql_error());
						$row69 = mysql_fetch_array($result69);
						
						$FormArguments['BlockContents'] .= '^^^^%%%pages/'.$row69['PageLink'].'%%%'.$row69['PageTitle'].'%%%0%%%';
						
					}
				}
			
				for ($x = 0; $x <= intval($FormArguments['LargestPageCatID']); $x++) {
					if ($FormArguments['BPageCatsList-'.$x] == 'y') {
						
						$query69 = "select * from `".$Settings['DBPrefix']."core-Pages` WHERE PageParent='".$x."'";
    					$result69 = mysql_query($query69) or die (mysql_error());
						while ($row69 = mysql_fetch_array($result69)) {
						
							$FormArguments['BlockContents'] .= '^^^^%%%pages/'.$row69['PageLink'].'%%%'.$row69['PageTitle'].'%%%0%%%';
						
						}
						
					}
				}
				
				
				//print '<br><br><br>'.$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;
			}
			
			// if they don't have permission to use php, make sure it's set to the same as before
			if ($Permissions[9] != 'y' && $FormArguments['EnablePHP'] == 1) {
				$query = "select EnablePHP,BlockContents from `".$Settings['DBPrefix']."core-Blocks` WHERE RecordNumber='".$FormArguments['BlockIDToEdit']."' LIMIT 1";
    	      			$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				if ($row['EnablePHP'] == 1) {
					$FormArguments['EnablePHP'] = $row['EnablePHP'];
					$FormArguments['BlockContents'] = addslashes($row['BlockContents']);
				}
			}
			
			
		
			if ($FormArguments['DeleteBlock'] == 'delete') {
			
				DBConnect();
				
				$query = "DELETE FROM `".$Settings['DBPrefix']."core-Blocks` WHERE RecordNumber='".$FormArguments['BlockIDToEdit']."' LIMIT 1";
	
	            $result = mysql_query($query) or die (mysql_error());
				
				header('Location: ' . $MainURL . '/admin/blocks.html');
			
			}		
			else {
			
				DBConnect();
				
				$query = "UPDATE `".$Settings['DBPrefix']."core-Blocks` SET AdminLabel='".$FormArguments['AdminLabel']."', BlockTitle='".$FormArguments['BlockTitle']."', TitleImage='".$FormArguments['TitleImage']."', TitleAlignment='".$FormArguments['TitleAlignment']."', BlockLocation='".$FormArguments['BlockLocation']."', BlockType='".$FormArguments['BlockType']."', PageType='".$FormArguments['PageType']."', BlockAlignment='".$FormArguments['BlockAlignment']."', BlockContents='".$FormArguments['BlockContents']."', NLtoBR='".$FormArguments['NLtoBR']."', EnablePHP='".$FormArguments['EnablePHP']."', BlockEnabled='".$FormArguments['BlockEnabled']."', MinLevel='".$FormArguments['MinLevel']."', MinEditLevel='".$FormArguments['MinEditLevel']."', BlockPriority='".intval($FormArguments['BlockPriority'])."', ConvertLinks='".$FormArguments['ConvertLinks']."', PagesList='".$PagesList."', PageCatsList='".$PageCatsList."', ModulesList='".$ModulesList."' WHERE RecordNumber='".$FormArguments['BlockIDToEdit']."' LIMIT 1";
				//print $query;
    	        $result = mysql_query($query) or die (mysql_error());
				
				if ($FormArguments['ReturnToBW'] == '') {
					header('Location: ' . $MainURL . '/admin/blocks.html');
				}
				else {
					header('Location: ' . $MainURL . '/admin/blocks-edit/'.$FormArguments['BlockIDToEdit']);
				}
			
			}
			
			
			}
			else {
				$PageContents = $MsgText[0][98];
			}

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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
