<?

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



	// ========================================================================================
	// main blocks admin page
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_content.gif" width="23" height="20"> '.$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') {
		
			$PageContents = $MsgText[0][152].'<br><br><a href="#new">'.$MsgText[0][153].'</a><br><br><br><br>';

			
			if ($IM['cl'] == 'y') {
				$CalendarBlockOption = '<option value=""> '.$MsgText[1][1].'</option><option value="cl-1"> &nbsp;&nbsp;&nbsp;&nbsp;'.$MsgText[1][100].'</option>';
			}
			
			
			
			
			$query32 = "select * from `".$Settings['DBPrefix']."core-PageCategories` ORDER BY Name ASC";
		$result32 = mysql_query($query32) or die (mysql_error());
		
		while ($row32 = mysql_fetch_array($result32)) { 
            
			$CategoryIDsArray[$row32['Parent']][] = $row32['RecordNumber'];
			$CategoryNamesArray[$row32['Parent']][] = $row32['Name'];
			$CategoryExists[$row32['RecordNumber']] = 'y';
			
			if ($row32['Description'] != '') { 
				$CategoryDescriptionsArray[$row32['Parent']][] = '<br>'.$row32['Description'];
			}
			else {
				$CategoryDescriptionsArray[$row32['Parent']][] = '<!--  -->';
			}
			
			
			if ($row32['RecordNumber'] > $LargestPageCatID) {
				$LargestPageCatID = $row32['RecordNumber'];
			}
			
				
		}
		
		
		$row['PagesList'] = str_replace('-','',$row['PagesList']);
		$PagesListPieces = explode(',', $row['PagesList']);
		for ($c = 0; $c < count($PagesListPieces); $c++) {
			$PageSelected[$PagesListPieces[$c]] = ' checked';
		}
		
		$row['PageCatsList'] = str_replace('-','',$row['PageCatsList']);
		$PageCatsListPieces = explode(',', $row['PageCatsList']);
		for ($c = 0; $c < count($PageCatsListPieces); $c++) {
			$PageCatSelected[$PageCatsListPieces[$c]] = ' checked';
		}
		
		
		
		
			
		//query the database and load pages data
		$query33 = "select * from `".$Settings['DBPrefix']."core-Pages` where MinLevel<='".$UserLevel."' ORDER BY PageTitle asc, PageLink asc, RecordNumber asc";
		$result33 = mysql_query($query33) or die (mysql_error());
		
				
		// if any rows are returned
		if (mysql_num_rows($result33) != 0) {
						
			while ($row33 = mysql_fetch_array($result33)) {
			
				// if the page has been orphaned, put it back in top level
				if ($CategoryExists[$row33['PageParent']] != 'y') {
					$row33['PageParent'] = 0;
				}			
            	
				$PageIDsArray[$row33['PageParent']][] = $row33['RecordNumber'];
				$PageNamesArray[$row33['PageParent']][] = $row33['PageTitle'];
				$PageLabelsArray[$row33['PageParent']][] = $row33['AdminLabel'];
				$PageLinksArray[$row33['PageParent']][] = $row33['PageLink'];
				
				
				if ($row33['RecordNumber'] > $LargestPageID) {
					$LargestPageID = $row33['RecordNumber'];
				}
				
			}
			
			
			
			$CatsPrint = '<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="PageCatsList-0" value="y"'.$PageCatSelected['0'].'>&nbsp;<b>Top Level</b>';
			
			$LastParentAbove = '0';
			$CatLevel['0'] = 0;
			
						
			if (count($PageIDsArray['0']) > 0) {
				$CatsPrint .= '<br>';	
			}
			
			if (count($CategoryIDsArray['0']) > 0) {
				$CatSpacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			else {
				$CatSpacer = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			
			for ($x = 0; $x < count($PageIDsArray['0']); $x++) {
					
				$CatsPrint .= '<table border="0" cellpadding="0" cellspacing="0"><tr><td>'.$CatSpacer.'</td><td><font size="'.$FontSize.'" color="'.$FontColor.'">&nbsp;&nbsp;&nbsp;<input type="checkbox" name="PagesList-'.$PageIDsArray['0'][$x].'" value="y"'.$PageSelected[$PageIDsArray['0'][$x]].'>&nbsp;'.$PageNamesArray['0'][$x].' ('.$PageLinksArray['0'][$x].')</font></td></tr></table>';
									
			}
			
			
			
			
			function SpiderCategories($CatParent) {
				
				Global $CategoryIDsArray, $CategoryNamesArray, $CategoryDescriptionsArray, $PageIDsArray, $PageNamesArray, $PageLinksArray, $CatsPrint, $LastParent, $LastParentAbove, $CatSpacersArray, $CatLevel, $CatsCount, $BaseURL, $ImagesURL, $MainURL, $FontSize, $FontColor, $PageCatSelected, $PageSelected;
				
				for ($i = 0; $i < count($CategoryIDsArray[$CatParent]); $i++) {
					
					$LastParentAboveB = $LastParentAbove;
					$LastParentB = $LastParent;
					
					$CatLevel[$CategoryIDsArray[$CatParent][$i]] = $CatLevel[$CatParent];
					if ($CatParent != $LastParent && $CatParent == $LastParentAbove) {
				
						$CatLevel[$CategoryIDsArray[$CatParent][$i]] = $CatLevel[$CatParent] + 1;
						$CatLevel[$CatParent]++;
						
						$CatsCount[$CatLevel[$CatParent]] = 0;
				
					}
					
					$LastParent = $CatParent;
					$LastParentAbove = $CategoryIDsArray[$CatParent][$i];
					
					$CatsCount[$CatLevel[$CatParent]]++;
					
										
					$CatSpacer = '';
					for ($x = 0; $x < $CatLevel[$CatParent]; $x++) {
						
											
						if ($CatsCount[$CatLevel[$CatParent]] == count($CategoryIDsArray[$CatParent]) && $x == $CatLevel[$CatParent]-1) {
							$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter = 'y';
						}
						else if ($CatsCount[$CatLevel[$CatParent]] == count($CategoryIDsArray[$CatParent])) {
							$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						}
						else {
							if ($x < $CatLevel[$CatParent]) {
								$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
								$ResetAfter = 'y2';
							}
							else {
								$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							}
						}
						
						$ConnectorsWidth += $ConnectorsWidthAdd;	
						$CatSpacer .= $CatSpacersArray[$x+1];
						
						if ($ResetAfter == 'y') {
							$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter = 'n';
						}
						else if ($ResetAfter == 'y2') {
							$CatSpacersArray[$CatLevel[$CatParent]] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
							$ResetAfter = 'n';
						}
									
					}
					
					$ConnectorsWidth = (($CatLevel[$CatParent]-1)*35)+35;
					$CatsPrint .= '<br><table border="0" cellpadding="0" cellspacing="0"><tr><td>'.$CatSpacer.'</td><td><font size="'.$FontSize.'" color="'.$FontColor.'">&nbsp;&nbsp;&nbsp;<input type="checkbox" name="PageCatsList-'.$CategoryIDsArray[$CatParent][$i].'" value="y"'.$PageCatSelected[$CategoryIDsArray[$CatParent][$i]].'>&nbsp;<b>'.$CategoryNamesArray[$CatParent][$i].'</b></font></td></tr></table>';
					
					$CatSpacer = '';
					for ($x = 0; $x < ($CatLevel[$CatParent]-1); $x++) {
						$CatSpacer .= $CatSpacersArray[$x+1];					
					}
					if ($CatsCount[$CatLevel[$CatParent]] == count($CategoryIDsArray[$CatParent])) {
						$CatSpacer .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					}
					else {						
						$CatSpacer .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					}

					
					if (count($CategoryIDsArray[$CategoryIDsArray[$CatParent][$i]]) > 0) {
						$CatSpacer .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					}
					else {
						$CatSpacer .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					}
					
					$ConnectorsWidth = (($CatLevel[$CatParent])*35)+35;
					
										
					for ($x = 0; $x < count($PageIDsArray[$CategoryIDsArray[$CatParent][$i]]); $x++) {
											
						$CatsPrint .= '<table border="0" cellpadding="0" cellspacing="0"><tr><td>'.$CatSpacer.'</td><td><font size="'.$FontSize.'" color="'.$FontColor.'">&nbsp;&nbsp;&nbsp;<input type="checkbox" name="PagesList-'.$PageIDsArray[$CategoryIDsArray[$CatParent][$i]][$x].'" value="y"'.$PageSelected[$PageIDsArray[$CategoryIDsArray[$CatParent][$i]][$x]].'>&nbsp;'.$PageNamesArray[$CategoryIDsArray[$CatParent][$i]][$x].' ('.$PageLinksArray[$CategoryIDsArray[$CatParent][$i]][$x].')</font></td></tr></table>';
					
					}
					
					
					if (count($CategoryIDsArray[$CatParent][$i]) > 0) {
						SpiderCategories($CategoryIDsArray[$CatParent][$i]);
					}
				
				}
				
				
			}
			
			SpiderCategories('0');
			
				
			
			
			$DisplayList = $CatsPrint;
			
			
		}
		
		
		$ModulesListPieces = explode(',', $row['ModulesList']);
		for ($c = 0; $c < count($ModulesListPieces); $c++) {
			$ModuleSelected[$ModulesListPieces[$c]] = ' checked';
		}
		
		
		$DisplayList .= '<b><br>
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-core" value="y"'.$ModuleSelected['core'].'>&nbsp;'.$MsgText[0][569].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-cl" value="y"'.$ModuleSelected['cl'].'>&nbsp;'.$MsgText[1][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-mb" value="y"'.$ModuleSelected['mb'].'>&nbsp;'.$MsgText[2][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-pg" value="y"'.$ModuleSelected['pg'].'>&nbsp;'.$MsgText[3][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-nl" value="y"'.$ModuleSelected['nl'].'>&nbsp;'.$MsgText[5][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-gb" value="y"'.$ModuleSelected['gb'].'>&nbsp;'.$MsgText[6][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-na" value="y"'.$ModuleSelected['na'].'>&nbsp;'.$MsgText[7][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-lm" value="y"'.$ModuleSelected['lm'].'>&nbsp;'.$MsgText[8][1].'
			<br>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="ModulesList-ec" value="y"'.$ModuleSelected['ec'].'>&nbsp;'.$MsgText[9][1].'			
			</b>';
			
			
			
			
			
		//query the database and load blocks data.  load only enabled blocks, and sort them by block priority.
		$query = "select * from `".$Settings['DBPrefix']."core-Blocks` where MinLevel<=".$UserLevel." and MinEditLevel<=".$UserLevel." ORDER BY BlockLocation,BlockPriority asc";
		$result = mysql_query($query) or die (mysql_error());
		
		// find largest location id
		$LargestLocationNumber = 0;
		
		// if any rows are returned, enabled blocks exist
		if (mysql_num_rows($result) != 0) {
			
			while ($row = mysql_fetch_array($result)) { 
            
				//$AllBlocksCount++;
				
				if ($row['TitleImage'] != '') {
					if (substr($row['TitleImage'],0,1) == '/') {
						$row['TitleImage'] = $BaseURL . $row['TitleImage'];
					}
					$row['BlockTitle'] = '<img src="'.$row['TitleImage'].'" alt="" border="0">';
				}
				
				$AdminBlocksArray[$row['BlockLocation']]['AdminLabel'][] = $row['AdminLabel'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockEnabled'][] = $row['BlockEnabled'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockType'][] = $row['BlockType'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockLocation'][] = $row['BlockLocation'];
				$AdminBlocksArray[$row['BlockLocation']]['RecordNumber'][] = $row['RecordNumber'];
				//$AdminBlocksArray[$row['BlockLocation']]['BlockOptions'][] = $row['BlockOptions'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockTitle'][] = $row['BlockTitle'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockContents'][] = $row['BlockContents'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockAlignment'][] = $row['BlockAlignment'];
				$AdminBlocksArray[$row['BlockLocation']]['TitleAlignment'][] = $row['TitleAlignment'];
				$AdminBlocksArray[$row['BlockLocation']]['BlockPriority'][] = $row['BlockPriority'];
				$AdminBlocksArray[$row['BlockLocation']]['MinLevel'][] = $row['MinLevel'];
				
				if ($LargestLocationNumber < $row['BlockLocation']) {
					$LargestLocationNumber = $row['BlockLocation'];
				}
			
			}
			
		}
		
		$AlignmentCodes[''] = 'left';
		$AlignmentCodes['L'] = 'left';
		$AlignmentCodes['C'] = 'center';
		$AlignmentCodes['R'] = 'right';
		
		$TitleAlignmentCodes[''] = 'center';
		$TitleAlignmentCodes['L'] = 'left';
		$TitleAlignmentCodes['C'] = 'center';
		$TitleAlignmentCodes['R'] = 'right';
		
		$TagCode[1] = 'leftblocks';
		$TagCode[2] = 'rightblocks';
		$TagCode[3] = 'topcenterblocks';
		$TagCode[4] = 'bottomcenterblocks';
		$TagCode[5] = 'topfullblocks';
		$TagCode[6] = 'bottomfullblocks';
		$TagCode[7] = 'topbannerblocks';
		$TagCode[8] = 'logoblock';
		
		
		for ($LocationCounter = 1; $LocationCounter <= $LargestLocationNumber; $LocationCounter++){
		
			// left blocks column
			if ($LocationCounter == 1 && count($AdminBlocksArray['1']) > 0) { $AdminBlocks['leftblocks'] = '<td width="27%" valign="top">'; }
			// right blocks column			
			else if ($LocationCounter == 2 && count($AdminBlocksArray['2']) > 0) { $AdminBlocks['rightblocks'] = '<td width="10"></td><td width="27%" valign="top">'; }
			
		
			for ($Counter = 0; $Counter <= (count($AdminBlocksArray[$LocationCounter]['BlockType']) - 1); $Counter++){
		
				if ($AdminBlocksArray[$LocationCounter]['AdminLabel'][$Counter] != '') {
					$AdminBlocksArray[$LocationCounter]['AdminLabel'][$Counter] .= '<br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>';
				}
		
				
				$AdminBlocks[$TagCode[$LocationCounter]] .= '<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="10" alt=""><br>';
								
						
				if ($AdminBlocksArray[$LocationCounter]['BlockEnabled'][$Counter] == '1') {
					$AdminBlocks[$TagCode[$LocationCounter]] .= '<table width="100%" border="1" cellspacing="0" cellpadding="5"><tr><td width="100%" bgcolor="#FFF6E2" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#6b7a93">';
					$EnabledBGColor = 'yellow';
				}
				else {
					$AdminBlocks[$TagCode[$LocationCounter]] .= '<table width="100%" border="1" cellspacing="0" cellpadding="5"><tr><td width="100%" bgcolor="#E4F1FF" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="#6b7a93">';
					$EnabledBGColor = 'blue';
				}
				
				if ($AdminBlocksArray[$LocationCounter]['BlockTitle'][$Counter] == '') {
					$AdminBlocksArray[$LocationCounter]['BlockTitle'][$Counter] = '('.$MsgText[0][154].')';
				}
				
				$AdminBlocks[$TagCode[$LocationCounter]] .= '<b>'.$AdminBlocksArray[$LocationCounter]['AdminLabel'][$Counter].'</b>'.$AdminBlocksArray[$LocationCounter]['BlockTitle'][$Counter] .'<br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br><a href="'.$MainURL . '/admin/blocks-edit/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'"><font color="#004191"><b>'.$MsgText[0][155].'</b></font></a> / <a href="'.$MainURL . '/admin/blocks-delete/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'"><font color="#004191"><b>'.$MsgText[0][156].'</b></font></a><br>';

				if (count($AdminBlocksArray[$LocationCounter]['BlockType']) > 1) {
					if ($Counter == 0) {
						$AdminBlocks[$TagCode[$LocationCounter]] .= '<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>'.$MsgText[0][199].': '.$AdminBlocksArray[$LocationCounter]['BlockPriority'][$Counter].' (<a href="'.$MainURL . '/admin/blocks-priority/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'/down"><img src="'.$ImagesURL.'/admin/arrow_down_'.$EnabledBGColor.'bg.gif" border="0" width="12" height="10" alt=""></a>)';
					}
					else if ($Counter == count($AdminBlocksArray[$LocationCounter]['BlockType'])-1) {
						$AdminBlocks[$TagCode[$LocationCounter]] .= '<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>'.$MsgText[0][199].': '.$AdminBlocksArray[$LocationCounter]['BlockPriority'][$Counter].' (<a href="'.$MainURL . '/admin/blocks-priority/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'/up"><img src="'.$ImagesURL.'/admin/arrow_up_'.$EnabledBGColor.'bg.gif" border="0" width="12" height="10" alt=""></a>)';
					}
					else {
						$AdminBlocks[$TagCode[$LocationCounter]] .= '<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>'.$MsgText[0][199].': '.$AdminBlocksArray[$LocationCounter]['BlockPriority'][$Counter].' (<a href="'.$MainURL . '/admin/blocks-priority/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'/up"><img src="'.$ImagesURL.'/admin/arrow_up_'.$EnabledBGColor.'bg.gif" border="0" width="12" height="10" alt=""></a><a href="'.$MainURL . '/admin/blocks-priority/'.$AdminBlocksArray[$LocationCounter]['RecordNumber'][$Counter].'/down"><img src="'.$ImagesURL.'/admin/arrow_down_'.$EnabledBGColor.'bg.gif" border="0" width="12" height="10" alt=""></a>)';
					} 
				}
				
							
				$AdminBlocks[$TagCode[$LocationCounter]] .= '<br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>'.$MsgText[0][157].': '.$AdminBlocksArray[$LocationCounter]['MinLevel'][$Counter].'</font></td></tr></table>';

								
	
			// end for $Counter (individual blocks
			}
		
			// end of left blocks column
			if ($LocationCounter == 1 && count($AdminBlocksArray['1']) > 0) { $AdminBlocks['leftblocks'] .= '</td><td width="10"></td>'; }
			// end of right blocks column
			else if ($LocationCounter == 2 && count($AdminBlocksArray['2']) > 0) { $AdminBlocks['rightblocks'] .= '</td>'; }
			
		// end for $LocationCounter (various block locations)
		}
		
		
		if ($Permissions[9] == 'y') {
			$PHPOption = '<option value="3"'.$PageTypeSelected[3].'> PHP-Enabled Code</option>';		
		}
		
		
		$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="-1"> -1 - '.$MsgText[0][161].'</option><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>';
			}
		}
		
		
		
		$PageContents .= '<div align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>

		'.$AdminBlocks[$TagCode[7]].'
	  
		'.$AdminBlocks[$TagCode[5]].'

		'.$AdminBlocks[$TagCode[8]].'
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
	'.$AdminBlocks[$TagCode[1]].'
      <td valign="top">
	  '.$AdminBlocks[$TagCode[3]].'
	  <div align="center"><br><br><br>'.$MsgText[0][163].'<br><br><br></div>
	  '.$AdminBlocks[$TagCode[4]].'
	  </td>
	'.$AdminBlocks[$TagCode[2]].'
    </tr>
</table>

'.$AdminBlocks[$TagCode[6]].'</td></tr></table></div><br><br><br><a name="new"></a><b>'.$MsgText[0][153].':</b><form name="PostForm" action="'.$MainURL.'/admin/blocks-new-save" method="post">


<script>
var ExistingImagesWindowCode = "";

function SelectImage() {
	var WindowProperties = "width=420,height=300,left=" + (screen.width-420)/2 + ",top=" + (screen.height-300)/2 + ",location=no,menubar=no,directories=no,toolbar=no,status=no,scrollbars=no,resizable=yes";

	ExistingImagesWindowCode = window.open("'.$BaseURL.'/inc-core-admin-editor-existingimages.php","existingimages",WindowProperties);
}
function ExistingImageSelected(ImageName,ImageWidth,ImageHeight) {

	ExistingImagesWindowCode.close();
	
	document.forms["PostForm"].elements["TitleImage"].value = "/images/uploaded/"+ImageName;

}
function UploadToServer() {

		var WindowProperties = "width=580,height=380,left=" + (screen.width-580)/2 + ",top=" + (screen.height-380)/2 + ",location=no,menubar=no,directories=no,toolbar=no,status=no,scrollbars=no,resizable=yes";

		UploadWindowCode = window.open("'.$BaseURL.'/inc-core-admin-editor-imageupload.php","imageupload",WindowProperties);

	  }

	  function UploadedImageSelected(ImageName,ImageWidth,ImageHeight) {

		UploadWindowCode.close();
	
		document.forms["PostForm"].elements["TitleImage"].value = "/images/uploaded/"+ImageName;
		
	  }
</script>


<b>'.$MsgText[0][517].':</b>&nbsp;&nbsp;<input type="text" name="AdminLabel" size="30"><br><font size="1">'.$MsgText[0][518].'</font><br>

<b><br>'.$MsgText[0][164].':</b>&nbsp;&nbsp;<input type="text" name="BlockTitle" size="30"><br><font size="1">'.$MsgText[0][165].'</font><br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="45"><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="45" height="1" alt=""></td>
      <td width="100%"><font face="'.$FontFace.'" size="'.$FontSize.'">
	  '.$MsgText[0][519].':&nbsp;&nbsp;<input type="text" name="TitleImage" size="40" value="'.$row['TitleImage'].'"><br><input type="button" value="'.$MsgText[0][521].'" onClick="SelectImage();">&nbsp;<input type="button" value="'.$MsgText[0][563].'" onClick="UploadToServer();"><br><font size="1">'.$MsgText[0][522].'<br></font>

<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br>

'.$MsgText[0][166].':&nbsp;&nbsp;<select name="TitleAlignment">
	<option value="L"> '.$MsgText[0][15].'</option>
	<option value="C" selected> '.$MsgText[0][16].'</option>
	<option value="R"> '.$MsgText[0][17].'</option>
</select>
<br><font size="1">'.$MsgText[0][167].'<br></font>

</td>
    </tr>
</table>

<br><b>'.$MsgText[0][168].':</b>&nbsp;&nbsp;<select name="BlockLocation">
	<option value="1"> '.$MsgText[0][7].'</option>
	<option value="2"> '.$MsgText[0][8].'</option>
	<option value="3"> '.$MsgText[0][9].'</option>
	<option value="4"> '.$MsgText[0][10].'</option>
	<option value="5"> '.$MsgText[0][11].'</option>
	<option value="6"> '.$MsgText[0][12].'</option>
	<option value="7"> '.$MsgText[0][13].'</option>
	<option value="8"> '.$MsgText[0][14].'</option>
</select>
<br><!-- <font size="1">Position of the Block within the blocks framework.</font><br> -->

<script language="JavaScript"><!--
function BlockTypeChange() {
	var BlockType = document.forms["PostForm"].elements["BlockType"].value;
		
	if (BlockType == "cr-1" || BlockType == "cr-3" || BlockType == "cr-4" || BlockType == "cr-5") {
		// block wizard types
		var DivContainer = document.getElementById("CustomOptions");
        	DivContainer.style.display = "none";
		document.forms["PostForm"].elements["SubmitButton"].value = "'.$MsgText[0][170].'";				
	}
	else if (BlockType == "cr-2" || BlockType == "cl-1") {
		// calendar & users online
		var DivContainer = document.getElementById("CustomOptions");
		DivContainer.style.display = "none";
		document.forms["PostForm"].elements["SubmitButton"].value = "'.$MsgText[0][169].'";
	}
	else {
		// custom / no selection
		var DivContainer = document.getElementById("CustomOptions");
		DivContainer.style.display = "";
		document.forms["PostForm"].elements["SubmitButton"].value = "'.$MsgText[0][169].'";
	}
}
//--></script>
<br><b>'.$MsgText[0][241].':</b>&nbsp;&nbsp;<select name="BlockType" onChange="BlockTypeChange();">
	<option value=""> '.$MsgText[0][171].'</option>
	<option value=""> -------------</option>
	<option value=""> '.$MsgText[0][172].':</option>
	<option value="cr-1"> &nbsp;&nbsp;&nbsp;&nbsp;'.$MsgText[0][173].'</option>
	<option value="cr-2"> &nbsp;&nbsp;&nbsp;&nbsp;'.$MsgText[0][174].'</option>
	<option value="cr-3"> &nbsp;&nbsp;&nbsp;&nbsp;'.$MsgText[0][175].'</option>
	<!-- <option value="cr-4"> &nbsp;&nbsp;&nbsp;&nbsp;Random Code/Text</option> -->
	<option value="cr-5"> &nbsp;&nbsp;&nbsp;&nbsp;'.$MsgText[0][176].'</option>
	'.$CalendarBlockOption.'
</select>

<br><font size="1">'.$MsgText[0][177].'<br></font>

<div id="CustomOptions" style="visibility:visible;">
<br><br>

<script>
var EditorStarted = false;

function UpdatePageType() {
	var PageType = document.getElementById("PageType").value;
	
	if (PageType == 1) {
		if (EditorStarted == false) {
			var oFCKeditor = new FCKeditor( "PageContents" ) ;

			oFCKeditor.BasePath = "'.$BaseURL.'/fckeditor/" ;

			oFCKeditor.Height	= 500 ;
			
			//oFCKeditor.Create() ;
			oFCKeditor.ReplaceTextarea();
			
			EditorStarted = true;
		}
	
		document.getElementById("EditorDiv").style.display = "";
		document.getElementById("NonEditorDiv").style.display = "none";
		document.getElementById("EnablePHP").value = 0;
	}
	else if (PageType == 2) {
		document.getElementById("EditorDiv").style.display = "none";
		document.getElementById("NonEditorDiv").style.display = "";
		document.getElementById("EnablePHP").value = 0;
	}
	else if (PageType == 3) {
		document.getElementById("EditorDiv").style.display = "none";
		document.getElementById("NonEditorDiv").style.display = "";
		document.getElementById("EnablePHP").value = 1;
	}
}
</script>

<b>'.$MsgText[0][689].':</b><br>
<select name="PageType" id="PageType" size="1" onChange="UpdatePageType();">
<option value="1"'.$PageTypeSelected[1].'> Rich Text / HTML Editor</option>
<option value="2"'.$PageTypeSelected[2].'> Plain Text / HTML Without Editor</option>
'.$PHPOption.'
</select><br><input id="EnablePHP" type="hidden" name="EnablePHP" value="0">

<br><b>'.$MsgText[0][178].':</b><br>


<div id="EditorDiv"><textarea id="PageContents" name="PageContents" cols="65" rows="8" style="width: 100%; height: 500px;" wrap="virtual"></textarea></div><div id="NonEditorDiv" style="display: none;"><textarea id="PageContents2" name="PageContents2" cols="65" rows="8" style="width: 100%; height: 500px;" wrap="virtual"></textarea></div><br>

<img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="45" height="1" alt="">'.$MsgText[0][180].':&nbsp;&nbsp;<input type="checkbox" name="NLtoBR" value="1"> '.$MsgText[0][118].'<br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="45" height="1" alt=""><font size="1">'.$MsgText[0][181].'</font><br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="1" height="4" alt=""><br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="45" height="1" alt="">'.$MsgText[0][182].':&nbsp;&nbsp;<input type="checkbox" name="ConvertLinks" value="1"> '.$MsgText[0][118].'<br><img src="'.$ImagesURL.'/admin/admin/spacer.gif" border="0" width="45" height="1" alt=""><font size="1">'.$MsgText[0][183].'</font>

</div>

<br><br><b>'.$MsgText[0][184].':</b>&nbsp;&nbsp;<select name="BlockAlignment">
	<option value="L"> '.$MsgText[0][15].'</option>
	<option value="C" selected> '.$MsgText[0][16].'</option>
	<option value="R"> '.$MsgText[0][17].'</option>
</select>
<br><font size="1">'.$MsgText[0][185].'</font><br>


<br><b>'.$MsgText[0][186].':</b>&nbsp;&nbsp;<select name="BlockEnabled">
	<option value="0"> '.$MsgText[0][187].'</option>
	<option value="1" selected> '.$MsgText[0][188].'</option>
</select>
<br>
<br>
<b>'.$MsgText[0][189].':</b>&nbsp;&nbsp;<select name="MinLevel">'.$PermissionsDropdown.'</select><br><font size="1">'.$MsgText[0][190].'<br></font>
<br>
<b>'.$MsgText[0][543].':</b>&nbsp;&nbsp;<select name="MinEditLevel">'.$PermissionsDropdown.'</select><br><font size="1">'.$MsgText[0][545].'<br></font>

<br>

<br><br>

<b>Pages To Display On:</b><br> - Leave this section blank to display the block on all site pages<br> - Selecting a page category will display the block on all pages within that category<br>

'.$DisplayList.'

<input type="hidden" name="LargestPageID" value="'.$LargestPageID.'">
<input type="hidden" name="LargestPageCatID" value="'.$LargestPageCatID.'">

<br><br><br>
<br>
<br>
<input type="submit" name="SubmitButton" value="'.$MsgText[0][169].'">
<script>var FlexCMSScriptName="'.$Settings['ScriptName'].'";</script><script type="text/javascript" src="'.$BaseURL.'/fckeditor/fckeditor.js"></script><script>UpdatePageType();</script>


</form><br>';


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

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
