<?php
////////////////////////////////////////////////////////////////////
// Netricks' Content Manager, Copyright (c) 2003 Netricks, Inc. ////
// Content Manager is licensed under the AGPL //////////////////////
// Content Manager comes with ABSOLUTELY NO WARRANTY ///////////////
// See license.txt and readme.txt for details //////////////////////
////////////////////////////////////////////////////////////////////
ob_start("ob_gzhandler");
error_reporting(0);
include('../config.php');
$db=MySQLConnect($ConnError_Email,$ConnError_Browser);
sanitize($db);
$id= intval($_GET["id"]);
$ax=$_GET["ax"];
$act=$_GET["act"];
$movie=$_GET["movie"];
$type=$_GET["type"];
if($movie=="on"){$AddMovie="&movie=on";}
if($act!="files")
	include('header.php');
else
	include('header_upload.php');

if($nav_content=="on")
{
	if($ax=="delimage")
	{
		$v="";
		if(isset($_GET["v"]))
			$v=$_GET["v"];
		$file=stripslashes($_GET["file"]);
		$area=$_GET["area"];
		if($v=="yes")
		{
			if($area=="media/bios")
				unlink($Site_Path."media/b_thums/".$file);
			else if($area == "gallery")
				unlink($Site_Path."media/g_thumbs/".$file);	
			unlink($Site_Path.$area."/".$file);
			header("Location: ".$_SERVER["PHP_SELF"]."?ax=fileupload&act=files");
		}
		else
		{
			echo "<p class=\"bodylgbold\">Are you sure?</p>\n";
			echo "<p class=\"bodymd\">If you really want to delete &quot;".$file."&quot; from the &quot;".$area."&quot; directory, <a href=\"".$_SERVER["PHP_SELF"]."?act=files&ax=delimage&amp;area=$area&amp;file=$file&amp;v=yes\">click here</a>.</p>";
			$dem=getimagesize($Site_Path.$area."/".$file);
			echo "<p><img src=\"../".$area."/".$file."\" style=\"width:".$dem[0]."px;height:".$dem[1]."px;border-style:none;\" alt=\"\" /></p>";
		}
	}
	else if($ax=="upload")
	{

		$failure_msg="";
		$error_code="";
		$error_support="";

		$file_upload_count = count($_FILES['filename']['name']);
		if ($file_upload_count > 0)
		{
			if (count($_FILES['filename']['error']) == 0)
				$error_code = 'default';
			else
				$error_support = 'TRUE';
			
			for ($x = 0; $x < $file_upload_count; $x++)
			{
				if ($error_support)
					$error_code = $_FILES['filename']['error'][$x];
				
				$y = $x + 1;
				$failure_msg = ''.$y.'. ';

				if (($_FILES['filename']['name'][$x] == ''))
				{
					$file_name = 'filename_unavailable';
					continue;
				}
				else
					$file_name = $_FILES['filename']['name'][$x];
					
				if ($error_code != '0' && $error_code != '4'  && $error_code != 'default')
				{
					if ($error_code == '1')
						$error_message = 'Exceeded filesize allowed in php.ini.';
					elseif ($error_code == '2')
						$error_message = 'Exceeded filesize permitted by '.$sitename.'.';
					elseif ($error_code == '3')
						$error_message = 'Only a partial upload.';

					$file_failure_array[] = array('failure_msg'=>$failure_msg, 'file_name'=> $file_name, 'error_code'=>$error_message);
					continue;

				}
				if ($_FILES['filename']['tmp_name'][$x] == '')
				{
					$file_failure_array[] = array( 'failure_msg'=>$failure_msg, 'file_name'=> $file_name, 'error_code'=>'No upload - No temp name.');
					continue;
				} 
				if ($_FILES['filename']['size'][$x] <= 0)
				{
					$file_failure_array[] = array( 'failure_msg'=>$failure_msg, 'file_name'=> $file_name, 'error_code'=>'Contains no data/Corrupted');
					continue;
				}				
				if (!is_uploaded_file($_FILES['filename']['tmp_name'][$x]))
				{
					$file_failure_array[] = array( 'failure_msg'=>$failure_msg, 'file_name'=> $file_name, 'error_code'=>'File not uploaded by POST.');
					continue;
				}

				$matches = array();				
				$forbidden_img_types = "php,php3,php4,php5,phtml,exe,pl,cgi,html,htm,js,c,sh";

				if (get_magic_quotes_gpc()) 
					$_FILES['filename']['name'][$x] = stripslashes($_FILES['filename']['name'][$x]);
				
				$picture_name=	$_FILES['filename']['name'][$x];
				if (!preg_match("/(.+)\.(.*?)\Z/", $picture_name, $matches))
				{
					$matches[1] = 'invalid_fname';
					$matches[2] = 'xxx';
				}
					
				if ($matches[2] == '' ||  stristr($forbidden_img_types, $matches[2]))
				{
					$file_failure_array[] = array('failure_msg'=>$failure_msg, 'file_name'=> $file_name, 'error_code'=>'Forbidden file extension.');
					continue;
				}
			}
		}
		$file_error_count = count($file_failure_array);
		if($file_error_count > 0)
		{
?>
			<table width="100%" border=0 cellspacing=0 cellpadding=0>
			<tr class=bodymd><td class=bodymd><b>File Name<b></td><td class=bodymd><b>Error Message</b></td></tr>			
<?
			for ($i=0; $i < $file_error_count; $i++)
				echo "<tr><td class=bodymd>".$file_failure_array[$i]['failure_msg']." ".$file_failure_array[$i]['file_name']."</td><td class=bodymd>".$file_failure_array[$i]['error_code']."</td></tr>";
			echo "</table>";
		}
		else
		{
			if($_POST["folder"]=="media/bios")
			{ 
				echo "<p class=\"bodylgbold\">Uploading Image</p>\n";
				$overwrite="";
				if(isset($_POST["overwrite"]))
					$overwrite=$_POST["overwrite"];
				$folder=$_POST["folder"];
				$file_upload_count = count($_FILES['filename']['name']);
				if ($file_upload_count > 0)
				{
					for ($x = 0; $x < $file_upload_count; $x++)
					{
						$filename=$_FILES['filename']['name'][$x];
						$filename_tmp=$_FILES['filename']['tmp_name'][$x];
						$filename =str_replace(' ', '',$filename);						
						
						if ($filename_tmp == '')
						{
							continue;
						}
						$filename_ext = substr($filename, -3);
						$file_uploadpath=$Site_Path."".$folder."/".$filename;
						$file_uploadthumpath=$Site_Path."media/b_thums/".$filename;
						if(!file_exists($file_uploadpath) || $overwrite=="on")
						{
							if(move_uploaded_file($filename_tmp,$file_uploadpath))
							{
								echo "<p class=\"bodymd\">Thanks, ".$filename." has been uploaded.</p>";
								chmod ($file_uploadpath, 0644);
								$dem=getimagesize($file_uploadpath);
								$width_height = get_width_height(150, $dem[0], $dem[1]);	
								if(!resize_image_gd($file_uploadpath,$file_uploadthumpath,100,$width_height['width'],$width_height['height'],$dem))
									echo "<p class=\"bodymd\">The Thumb Image for ".$filename." cannot be resized</p>";
							}
						}
						else
						{
							echo "<p class=\"bodymd\">File Already Exists</p>\n";
							echo "<p class=\"bodymd\">&quot;$filename&quot; already exists in the target directory.</p>";
							echo "<p class=\"bodymd\">Please rename the file before uploading.</p>";
						}
					}
				}
				echo "<p class=\"bodymd\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=fileupload&act=files\">Administration Home</a></p>";	
			}
			else if($_POST["folder"]=="media/gallery")
			{ 
				echo "<p class=\"bodylgbold\">Uploading Image</p>\n";
				$overwrite="";
				if(isset($_POST["overwrite"]))
					$overwrite=$_POST["overwrite"];
				$folder=$_POST["folder"];
				$file_upload_count = count($_FILES['filename']['name']);
				if ($file_upload_count > 0)
				{
					for ($x = 0; $x < $file_upload_count; $x++)
					{
						$filename=$_FILES['filename']['name'][$x];
						$filename_tmp=$_FILES['filename']['tmp_name'][$x];
						$filename =str_replace(' ', '',$filename);

						if ($filename_tmp == '')
						{
							continue;
						}
						$filename_ext = substr($filename, -3);
						$file_uploadpath=$Site_Path."".$folder."/".$filename;
						$file_uploadthumpath=$Site_Path."media/g_thumbs/".$filename;
						if(!file_exists($file_uploadpath) || $overwrite=="on")
						{
							if(move_uploaded_file($filename_tmp,$file_uploadpath))
							{
								echo "<p class=\"bodymd\">Thanks, ".$filename." has been uploaded.</p>";
								chmod ($file_uploadpath, 0644);
								$dem=getimagesize($file_uploadpath);
								$width_height = get_width_height(150, $dem[0], $dem[1]);
								if(!resize_image_gd($file_uploadpath,$file_uploadthumpath,100,$width_height['width'],$width_height['height'],$dem))
								{
									echo "<p class=\"bodymd\">The Thumb Image for ".$filename." cannot be resized</p>";
								}						
							}
						}
						else
						{
							echo "<p class=\"bodymd\">File Already Exists</p>\n";
							echo "<p class=\"bodymd\">&quot;$filename&quot; already exists in the target directory.</p>";
							echo "<p class=\"bodymd\">Please rename the file before uploading.</p>";
						}
					}
				}
				echo "<p class=\"bodymd\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=fileupload&act=files\">Administration Home</a></p>";	
			}
			else
			{	
				echo "<p class=\"bodylgbold\">Uploading Image</p>\n";
				$overwrite="";
				if(isset($_POST["overwrite"]))
					$overwrite=$_POST["overwrite"];
				$folder=$_POST["folder"];
				$file_upload_count = count($_FILES['filename']['name']);
				if ($file_upload_count > 0)
				{
					for ($x = 0; $x < $file_upload_count; $x++)
					{
						$filename=$_FILES['filename']['name'][$x];
						$filename_tmp=$_FILES['filename']['tmp_name'][$x];						
						$filename =str_replace(' ', '',$filename);

						if ($filename_tmp == '')
						{
							continue;
						}
						$filename_ext = substr($filename, -3);
						$file_uploadpath=$Site_Path."".$folder."/".$filename;
						if(!file_exists($file_uploadpath) || $overwrite=="on")
						{
							if(move_uploaded_file($filename_tmp,$file_uploadpath))
							{
								echo "<p class=\"bodymd\">Thanks, ".$filename." has been uploaded.</p>";
								chmod ($file_uploadpath, 0644);							
							}
						}
						else
						{
							echo "<p class=\"bodymd\">File Already Exists</p>\n";
							echo "<p class=\"bodymd\">&quot;$filename&quot; already exists in the target directory.</p>";
							echo "<p class=\"bodymd\">Please rename the file before uploading.</p>";
						}
					}
				}
				echo "<p class=\"bodymd\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=fileupload&act=files\">Administration Home</a></p>";
			}
		}
    }
	
	else if($ax=="editpage")
	{ 
		$title=$_POST["title"];
		$title_nav=$_POST["title_nav"];
		$order=$_POST["order"];
		$level=$_POST["level"];
		$content=$_POST["content"];
		$metadescription=$_POST["metadescription"];
		$metakeys=$_POST["metakeys"];
		$metatitle=$_POST["metatitle"];
		$metadata=$_POST["metadata"];
		if(isset($_POST["published"]))
			$published=$_POST["published"];
		else
			$published=$_POST["published"];		
		$xml=$_POST["xml"];
		$module=$_POST["module"];
		$pageimage=$_POST["pageimage"];
		$url=$_POST["url"];
		$movie_type=$_POST["movie_type"];
        $color=$_POST["color"];
		$result=MySQLQuery("update php_content set title='$title',title_nav='$title_nav',display_order='$order',level='$level',content='$content',published='$published',module='$module',pageimage='$pageimage',url='$url',metadescription='$metadescription',metakeys='$metakeys', metatitle='$metatitle', metadata='$metadata',xml='$xml',movie_type='$movie_type',movie='$movie',navi_color='$color' where id=$id",$QueryError_Email,$QueryError_Browser);
		if ($result)
		{
			echo "<p class=\"bodylgbold\">'$title' Was Updated</p>";
			header("Location: ".$_SERVER["PHP_SELF"]);
		}
		else
		{echo "<p class=\"bodylgbold\">Error Updating '$title'</p>";}
	}
	else if($ax=="addpage")
	{
		echo "<p class=\"bodylgbold\">Inserting New Page</p>";
		$title=$_POST["title"];
		$title_nav=$_POST["title_nav"];
		$order=$_POST["order"];
		$level=$_POST["level"];
		$content=$_POST["content"];
		$metadescription=$_POST["metadescription"];
		$metakeys=$_POST["metakeys"];
		$metatitle=$_POST["metatitle"];
		$metadata=$_POST["metadata"];
		if(isset($_POST["published"]))
			$published=$_POST["published"];
		else
			$published="";
		$xml=$_POST["xml"];
		$module=$_POST["module"];
		$pageimage=$_POST["pageimage"];
		if(isset($_POST["url"]))
			$url=$_POST["url"];
		else
			$url="";
		if(isset($_POST["movie_type"]))
			$movie_type=$_POST["movie_type"]; 
		else
			$movie_type="";
		if(isset($_POST["color"]))
	        $color=$_POST["color"]; 
		else
			$color="";
		$result=MySQLQuery("insert into php_content (title,title_nav,display_order,level,content,published,module,pageimage,url,metadescription,metakeys,metatitle,metadata,xml,movie,movie_type,navi_color) values ('$title','$title_nav','$order','$level','$content','$published','$module','$pageimage','$url','$metadescription','$metakeys','$metatitle','$metadata','$xml','$movie','$movie_type','$color')",$QueryError_Email,$QueryError_Browser);
		if ($result)
		{echo "<p class=\"bodylgbold\">New page was successfully added</p>\n";}
		else
		{echo "<p class=\"bodylgbold\">Error Adding new page</p>\n";}
	}
	else if($ax=="delpage")
	{
		$title_result = MySQLQuery("SELECT id,title,module FROM php_content WHERE id=$id", $QueryError_Email, $QueryError_Browser);
		while($title_row = mysql_fetch_array($title_result))
		{
			$title=$title_row["title"];
			$module=$title_row["module"]; //echo $title.", ".$module;
		}
		if(isset($_GET["v"]) && $_GET["v"]=="y")
		{
			$result=MySQLQuery("delete from php_content where id=$id",$QueryError_Email,$QueryError_Browser);
			if ($result)
			{
			   echo "<p class=\"bodylgbold\">'$title' Was Deleted</p>\n";
				header("Location: ".$_SERVER["PHP_SELF"]);
			}
			else
			{echo "<p class=\"bodylgbold\">Error Deleting '$title'</p>\n";}
		}
		else
		{  
			if($module=="linked" or $module=="search" or $module=="none" )
			{
				echo "<p class=\"bodylgbold\">Are you sure?</p>";
				echo "<p class=\"bodymd\">If you want to delete the page \"$title\", <a href=\"".$_SERVER["PHP_SELF"]."?ax=delpage&amp;id=$id&amp;v=y\">click here</a>.</p>";
	        }else{echo "<p class=\"bodylgbold\">Sorry you may not delete the ".$module." module</p>";}
      }
	}
	
	else if($ax=="view")
	{
		$result = MySQLQuery("SELECT * FROM php_content WHERE id=$id", $QueryError_Email, $QueryError_Browser);
		if(mysql_num_rows($result))
		{
			while($row = mysql_fetch_array($result))
			{
				$main_title=stripslashes($row["title"]);
				$show_title=stripslashes($row["show_title"]);
				$main_content=stripslashes($row["content"]);
				if($main_title != "" && $show_title == "on")
				{
					echo "<p class=\"bodylgbold\">$main_title</p>\n";
				}
				if($main_content != "")
				{
					echo $main_content;
				}
			}
		}
		else
		{
			echo "<p class=\"bodymd\">There was an error processing your request</p>";
		}
	}
	else if($ax=="order")
	{
		if ($_REQUEST['footerlink'] != '') {
			foreach ($_REQUEST['footerlink'] as $k => $v) {
				if ($flsql != '') $flsql .= " OR `id` = ";
				$flsql .= "'".$k."'";
			}
			MySQLQuery("UPDATE `php_content` SET `footer_nav` = '0'", $QueryError_Email, $QueryError_Browser);
			MySQLQuery("UPDATE `php_content` SET `footer_nav` = '1' WHERE `id` = ".$flsql, $QueryError_Email, $QueryError_Browser);
		}
		else {
			MySQLQuery("UPDATE `php_content` SET `footer_nav` = '0'", $QueryError_Email, $QueryError_Browser);
		}
		$result = MySQLQuery("SELECT id FROM php_content", $QueryError_Email, $QueryError_Browser);
		if (mysql_num_rows($result))
		{
			while($row = mysql_fetch_array($result))
			{
				$id=$row["id"];
				$aorder[$id]=$_POST["order_$id"]+0;
			}
			$update_ok=1;
			foreach ($aorder as $id => $order)
			{
				if ($order>0)
				{
					$result=MySQLQuery("update php_content set display_order='$order' where id=$id",$QueryError_Email,$QueryError_Browser);
					if ($result == 0) $update_ok=0;
				}
			}
			if ($update_ok)
				header("Location: ".$_SERVER["PHP_SELF"]);
			else
				echo "<p class=\"bodylgbold\">There was an error completing your request</p>";
		}
		else
			echo "<p class=\"bodymd\">There was an error processing your request</p>";
	}
	else if($ax=="fileupload")
	{
?>
		<p class="bodylgbold">File Upload</p>
		<a id="upload"></a>
		<form id="upload_form" action="<?php echo $_SERVER["PHP_SELF"]."?ax=upload&act=files"; ?>" method="post" enctype="multipart/form-data" onsubmit="return validate_upload();">
<table border="0" cellspacing="2" cellpadding="0">
<tr>
	<td class="bodymd">
		<select name="folder">
		<option value="">Upload to:</option>
		<?/*<option value="images">images</option>
		<option value="buttons">buttons</option>*/?>
		<option value="media/headers">headers</option>
		<option value="media/files">files</option>
		<option value="media/gallery">gallery</option>
		<option value="media/events">events</option>
		<option value="media/bios">bios</option>        
        
<?PHP
if($movie_page=="yes")
	echo '<option value="media/movies">movies</option>';
?>
		
		</select>
	</td>
<tr>
<?		
		$imagename = "";
		for ($x=0; $x<$num_file_boxes; $x++)
		{
			$y = $x + 1;
			$imagename = "Img ".$y.". ";
?>
			<tr><td class="bodymd">Upload <?= $imagename ?> <a href="javascript:openHelp('popups/help.php#upload');">(?)</a>: <input type="file" name="filename[]" size="30" /></td></tr>
<?
		}
?>
	<!--<td class="bodymd">Upload File <a href="javascript:openHelp('popups/help.php#upload');">(?)</a>: <input type="file" name="filename[]" size="30" /></td>-->
<tr>
	<td><input type="submit" name="submit" value="Upload" /></td>
</tr>
<tr>
	<td class="bodymd"><input type="checkbox" name="overwrite" value="on" />Check here to overwrite any existing file/image with same name.</td>
</tr>
</table>
</form>
<?php 
		if($act=="files" and $ax=="fileupload")
			include("files.php");
    }
	else if($ax=="edit" || $ax=="add")
	{
		if($ax=="add")
		{
			$module="";
			$title="";
			$published="";
			$xml="";
			$title_nav="";
			$order="";
			$level="";
			$content="";
			$metadescription="";
			$metakeys="";
			$metatitle="";
			$metadata="";
			$pageimage="";
			$url="";
			$movie_type="";
            $color="";
			$page_title="Add Content";
			if($movie=="on")
	        {
				$form_ax=$_SERVER["PHP_SELF"]."?ax=addpage&movie=on";
			}
			else
			{
			   $form_ax=$_SERVER["PHP_SELF"]."?ax=addpage";
			}
		}
		else if($ax=="edit")
		{
			$page_title="Edit Content";
			$result=MySQLQuery("select * from php_content where id=$id",$QueryError_Email,$QueryError_Browser);
			while($row=mysql_fetch_array($result))
			{
				$id=$row["id"];
				$module=stripslashes($row["module"]);
				$title=stripslashes($row["title"]);
				$published=$row["published"];
				if($published=="on")
				{
					$published=" checked";
				}
				$xml=$row["xml"];
				if($xml=="on")
				{
					$xml=" checked";
				}
				$title_nav=stripslashes($row["title_nav"]);
				$order=$row["display_order"];
				$level=$row["level"];
				$content=stripslashes($row["content"]);
				$metadescription=stripslashes($row["metadescription"]);
				$metakeys=stripslashes($row["metakeys"]);
				$metatitle=stripslashes($row["metatitle"]);
				$metadata=stripslashes($row["metadata"]);
				$pageimage=stripslashes($row["pageimage"]);
				$url=stripslashes($row["url"]);	
				
				$movie_type=stripslashes($row["movie_type"]);
				$color=stripslashes($row["navi_color"]);
				if($movie=="on")
				{
					$form_ax=$_SERVER["PHP_SELF"]."?ax=editpage&movie=on&id=".$id;
				}
				else
				{
		            $form_ax=$_SERVER["PHP_SELF"]."?ax=editpage&id=".$id;
				}
			}
		}
		echo "<p class=\"bodylgbold\">$page_title</p>\n";
?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<form id="maincontent" name=maincontent action="<?php echo $form_ax; ?>" method="post" onsubmit="return validate_page();">
<table border="0" width="100%" cellspacing="2" cellpadding="0">
<tr><td class="bodymdbold" colspan="2" align="top" valign="left">Page Variables and Settings:</td></tr>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Hierarchy Level:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">
		<select name="level">
<?php
	if($ax=="edit")
	{
		$result=MySQLQuery("select id,title_nav,display_order,level from php_content where id=$level",$QueryError_Email,$QueryError_Browser);
		while($edit_row=mysql_fetch_array($result))
		{
			$edit_level=$edit_row["id"];
			$edit_title=$edit_row["title_nav"];
			echo "<option value=\"$edit_level\"> $edit_title</option>";
		}
		echo "<option value=\"0\"> Top-Level</option>";
		$result=MySQLQuery("select id,title_nav,display_order,level from php_content where level=0 and id!=$id and module!='linked' and module !='bannersview' order by display_order asc",$QueryError_Email,$QueryError_Browser);
		while($add_row=mysql_fetch_array($result))
		{
			$add_level=$add_row["id"];
			$add_title=stripslashes($add_row["title_nav"]);
			echo "<option value=\"$add_level\"> $add_title</option>";
		}
	}
	else if($ax="add")
	{
		echo "<option value=\"0\"> Top-Level</option>";
		$result=MySQLQuery("select id,title_nav,display_order,level from php_content where level=0 and module!='linked' and module !='bannersview' order by display_order asc",$QueryError_Email,$QueryError_Browser);
		while($add_row=mysql_fetch_array($result))
		{
			$add_level=$add_row["id"];
			$add_title=stripslashes($add_row["title_nav"]);
			echo "<option value=\"$add_level\"> $add_title</option>";
		}
	}
?>
		</select>
	</td>
</tr>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Display Order:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><input type="text" name="order" size="3" value="<?php echo $order; ?>" /></td>
</tr>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;" colspan="2"><input type="checkbox" name="published"<?php echo $published; ?> />  Publish this page to the live site?</td>
</tr>
<tr>
	<td class="bodysm" colspan="2" style="white-space:nowrap;"><hr /><input type="hidden" name="xml" value="none" /></td>
</tr>
<tr><td colspan="2" class="bodymd">Meta Title: (100 characters maximum)</td></tr>
<tr><td colspan="2" class="bodymd"><textarea name="metatitle" rows="2" cols="68"><?= $metatitle ?></textarea></td></tr>
<tr><td colspan="2" class="bodymd">Keywords: (seperate each by a comma - keyword1, keyword2, keyword3)</td></tr>
<tr><td colspan="2" class="bodymd"><textarea name="metakeys" rows="2" cols="68"><?= $metakeys ?></textarea></td></tr>
<tr><td colspan="2" class="bodymd">Description of Page: (One or Two sentences using the "Topic" two times)</td></tr>
<tr><td colspan="2" class="bodymd"><textarea name="metadescription" rows="2" cols="68"><?= $metadescription ?></textarea></td></tr>
<tr><td colspan="2" class="bodymd" align="left" valign="top" style="white-space:nowrap;">Meta Data: </td>
<tr><td colspan="2" class="bodymd" align="left" valign="top" style="white-space:nowrap;"><textarea name="metadata" rows="2" cols="68"><?= $metadata ?></textarea></td></tr>
<tr>
	<td class="bodysm" colspan="2" style="white-space:nowrap;"><hr /></td>
</tr>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Navigation Title:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><input type="text" name="title_nav" size="60" value="<?php echo $title_nav; ?>" /><br /><span class="bodysm">(100 characters maximum)</span></td>
</tr>
<?php
	if($navi_color=="yes")
	{ ?>
<SCRIPT LANGUAGE="Javascript" SRC="ColorPicker2.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cp = new ColorPicker('window'); // Popup window
</SCRIPT>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Navigation Color:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><input type="text" name="color" SIZE="20" value="<?php echo $color; ?>" /><span class="bodysm"><A HREF="#" onClick="cp.select(document.forms[0].color,'pick');return false;" NAME="pick" ID="pick"><b>Pick</b></A></span></td>
</tr>
<SCRIPT LANGUAGE="JavaScript">cp.writeDiv()</SCRIPT>
<?PHP }	?>
<?if($type!="linked"){?>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Page Title:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><input type="text" name="title" size="60" value="<?php echo $title; ?>" /><br /><span class="bodysm">(100 characters maximum. Leave blank to have no title appear.)</span></td>
</tr>
<?php
	if($movie=="on" && $movie_page == "yes")
	{ ?>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Movie Type:
   <select name="movie_type">
<?php
	if($ax=="edit")
	{
		echo "<option value=\"$movie_type\">$movie_type</option>\n";
	}
?>  <option value="mov">mov</option>
    <option value="wmv">wmv</option></select>
   </td>
</tr>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Movie:
		<select name="pageimage">
<?php
	if($ax=="edit")
	{
		echo "<option value=\"$pageimage\">$pageimage</option>\n";
	}
	echo "<option value=\"none\">none</option>\n";
	$image_dir=$Site_Path."media/movies/";
	$dir=opendir($image_dir);
	while($file=readdir($dir))
	{
		$files[]=$file;
	}
	natcasesort($files);
    foreach ($files as $file) 
	{
		if($file!="." && $file!=".." && $file!="header.gif" && stristr($file, '.db') === FALSE && stristr($file, '.htaccess') === FALSE)
		{
			echo "<option value=\"$file\">$file</option>\n";
		}
	}
	closedir($dir);
?>
		</select>	
	</td></tr>
<?}else{?>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Page Image:</td>
	<td class="bodymd">
		<select name="pageimage">
<?php
	if($ax=="edit")
	{
		echo "<option value=\"$pageimage\">$pageimage</option>\n";
	}
	echo "<option value=\"none\">none</option>\n";
	$image_dir=$Site_Path."media/headers/";
	$dir=opendir($image_dir);
	while($file=readdir($dir))
	{
		$files[]=$file;
	}
	natcasesort($files);
    foreach ($files as $file) 
	{
		if($file!="." && $file!=".." && $file!="header.gif" && stristr($file, '.db') === FALSE && stristr($file, '.htaccess') === FALSE)
		{
			echo "<option value=\"$file\">$file</option>\n";
		}
	}
	closedir($dir); 
?>
		</select>	
	</td>
</tr><?}}?>
<tr>
	<td class="bodysm" colspan="2" style="white-space:nowrap;"><hr /></td>
</tr>
<?php
$type=$_GET["type"];
if($type=="module")
{
?>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Module:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><select name="module">
<?php
	if($ax=="edit")
	{
		$result=MySQLQuery("select module from php_content where id=$id",$QueryError_Email,$QueryError_Browser);
		while($edit_row=mysql_fetch_array($result))
		{
			$edit_module=$edit_row["module"];
			echo "<option value=\"$edit_module\">".ucfirst($edit_module)."</option>\n";
		}
	}
	$result=MySQLQuery("select distinct module from php_content where module!='none' and module!='contact' and module!='bannersview' and module!='search' and module!='linked' and module!='sitemap' order by module",$QueryError_Email,$QueryError_Browser);
	while($row=mysql_fetch_array($result))
	{
		echo "<option value=\"".$row["module"]."\">".ucfirst($row["module"])."</option>";
	}	
?></select>
	</td>
</tr>
	</td>
</tr>
<?php
	}
	else if($type=="custom")
	{
		
?>
<tr>
	<td class="bodymd" colspan="2">Page Content:<br />
	<textarea id="content" name="content"><?= $content ?></textarea>
	<script type="text/javascript">CKEDITOR.replace( 'content',{
			filebrowserBrowseUrl : 'ckeditor/ckfinder/ckfinder.html',
			filebrowserImageBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Images',
			filebrowserFlashBrowseUrl : 'ckeditor/ckfinder/ckfinder.html?Type=Flash',
			filebrowserUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
			filebrowserImageUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
			filebrowserFlashUploadUrl : 'ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
		} );</script>
	</td>
</tr>

<?php
	}
	else if($type=="linked")
	{
?>
<tr>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;">Link To:</td>
	<td class="bodymd" align="left" valign="top" style="white-space:nowrap;"><input type="text" name="url" size="60" value="<?php echo $url; ?>" /><br /><span class="bodysm">(100 characters maximum. Leave blank to have no title appear.)</span></td>
</tr>
<?php } ?>
<tr>
	<td colspan="2">
<?php if($type=="module"){ ?>
	<input type="hidden" name="content" value="x-none" />
	<input type="hidden" name="url" value="none" />
<?php }else if($type=="custom"){ ?>
	<input type="hidden" name="module" value="none" />
<?php }else if($type=="linked"){ ?>
	<input type="hidden" name="module" value="linked" />
	<input type="hidden" name="content" value="x-none" />
<?php } ?>
	<input type="submit" name="submit" value="<?php echo $page_title; ?>" />
	</td>
</tr>
</table>
</form>
<?php

	}
	else
	{
		echo "<p class=\"bodylgbold\">Content Outline</p>\n";
		echo "<form id=\"reorder_form\" name=\"reorder_form\" action=\"".$_SERVER["PHP_SELF"]."?ax=order\" method=\"post\" enctype=\"multipart/form-data\">\n";
		$result = MySQLQuery("select id,title_nav,published,module,movie,display_order,footer_nav from php_content where level=0  and module !='bannersview' order by display_order asc", $QueryError_Email, $QueryError_Browser);
		if(mysql_num_rows($result))
		{
			echo "<table cellpadding=\"2\" cellspacing=\"0\">\n";
			echo "<tr class=\"rowheader\">\n";
			echo "<td style=\"white-space:nowrap;\">Global Tools</td>\n";			
			echo "<td style=\"white-space:nowrap;\">\n<a href=\"javascript:void(0);\" class=\"adminbtn\" style=\"font-weight:normal;text-align:center;\" onclick=\"javascript:document.reorder_form.submit(); return false;\">&nbsp;Update Display Order / Footer Links&nbsp;</a>\n</td>\n";
			echo "</tr>\n";
			echo "</table>\n";
			echo "<br />";

			echo "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">\n
				<tr class=\"rowheader\">\n
				<td class=\"cellheader\" style=\"width:10%;white-space:nowrap;\" align=\"left\" valign=\"top\" colspan=\"4\">Action</td>
				<td class=\"cellheader\" align=\"center\" valign=\"top\" colspan=\"1\">Foot<br>Link</td>\n
				<td class=\"cellheader\" style=\"width:80%;white-space:nowrap;\" align=\"left\" valign=\"top\" colspan=\"1\">Navigation Title</td>\n
				<td class=\"cellheader\" style=\"width:10%;white-space:nowrap;\" align=\"right\" valign=\"top\" colspan=\"1\">Published</td>\n
				</tr>\n";
			while($row = mysql_fetch_array($result))
			{
				$id=$row["id"];
				$title_nav=stripslashes($row["title_nav"]);
				$published=$row["published"];
				$module=$row["module"];
				if($published=="on"){$published="Yes";}else{$published="No";}
				$movie=$row["movie"];				
				if($movie=="on"){$movie="&movie=on";}else{$movie="";}
				$order=$row["display_order"];
				$footnav=$row["footer_nav"];
				if($module=="none")
				{
					$m_type="custom".$movie;
					$m_link="index.php?n=$id&amp;id=$id";
				}
				else if($module=="linked")
				{
					$m_type="linked";
				}
				else
				{
					$m_type="module";
					$m_link=$module.".php?n=$id&amp;id=$id";
				}
				echo "<tr class=\"rowprimary\">\n";
				if($module=="linked")
				{
					echo "<td class=\"cellprimary\" style=\"white-space:nowrap;\"></td>\n";
				}
				else
				{
					echo "<td class=\"cellprimary\" style=\"white-space:nowrap;\"><a href=\"../$m_link\" onclick=\"javascript:window.open('../$m_link','',''); return false;\" class=\"adminbtn\">View</a></td>\n";
				}
				echo "<td class=\"cellprimary\" style=\"white-space:nowrap;\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=edit&amp;type=$m_type&amp;id=$id\" class=\"adminbtn\">Edit</a></td>\n
						<td class=\"cellprimary\" style=\"white-space:nowrap;\">";
						$del_result = MySQLQuery("select level from php_content where level=$id", $QueryError_Email, $QueryError_Browser);
						if($id != 1 && !mysql_num_rows($del_result))
						{
							echo "<a href=\"".$_SERVER["PHP_SELF"]."?ax=delpage&amp;id=$id\" class=\"adminbtn\">Delete</a>";
						}
						echo "</td>\n
							<td><input type=\"text\" style=\"font-size:10px;\" maxlength=\"3\" size=\"3\" name=\"order_$id\" value=\"$order\" /></td>\n
							<td align=\"center\"><input type=\"checkbox\" name=\"footerlink[$id]\" id=\"footerlink[$id]\" value=\"1\"".($footnav=='1'?' CHECKED':'')."></td>
							<td class=\"cellprimary\" style=\"width:100%;\">$title_nav</td>\n
							<td class=\"cellprimary\" style=\"white-space:nowrap;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$published</td>\n
							</tr>\n";
				$result2 = MySQLQuery("select id,title_nav,published,module,movie,display_order,footer_nav from php_content where level!=0 and level=$id  and module !='bannersview' order by display_order asc", $QueryError_Email, $QueryError_Browser);
				if(mysql_num_rows($result2))
				{
					while($row2 = mysql_fetch_array($result2))
					{
						$id2=$row2["id"];
						$title_nav2=stripslashes($row2["title_nav"]);
						$published=$row2["published"];
						$module=$row2["module"];
						if($published=="on"){$published="Yes";}else{$published="No";}
						$movie=$row2["movie"];
						if($movie=="on"){$movie="&movie=on";}else{$movie="";}
						$order=$row2["display_order"];
						$footnav=$row2["footer_nav"];
						if($module=="none")
						{
							$m_type="custom".$movie;
							$m_link="index.php?n=$id&amp;id=$id2";
						}
						else if($module=="linked")
						{
							$m_type="linked";
						}
						else
						{
							$m_type="module";
							$m_link=$module.".php?n=$id&amp;id=$id2";
						}
						echo "<tr class=\"rowsecondary\">\n";
						if($module=="linked")
						{
							echo "<td class=\"cellsecondary\" style=\"white-space:nowrap;\"></td>\n";
						}
						else
						{
							echo "<td class=\"cellsecondary\" style=\"white-space:nowrap;\"><a href=\"../$m_link\" onclick=\"javascript:window.open('../$m_link','',''); return false;\" class=\"adminbtn\">View</a></td>\n";
						}
						echo "<td class=\"cellsecondary\" style=\"white-space:nowrap;\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=edit&amp;type=$m_type&amp;id=$id2\" class=\"adminbtn\">Edit</a></td>\n
							<td class=\"cellsecondary\" style=\"white-space:nowrap;\"><a href=\"".$_SERVER["PHP_SELF"]."?ax=delpage&amp;id=$id2\" class=\"adminbtn\">Delete</a></td>\n
							<td><input type=\"text\" style=\"font-size:10px;\" maxlength=\"3\" size=\"3\" name=\"order_$id2\" value=\"$order\" /></td>\n
							<td align=\"center\"><input type=\"checkbox\" name=\"footerlink[$id2]\" id=\"footerlink[$id2]\" value=\"1\"".($footnav=='1'?' CHECKED':'')."></td>
							<td class=\"cellsecondary\" style=\"width:100%;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$title_nav2</td>\n
							<td class=\"cellsecondary\" style=\"white-space:nowrap;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$published</td>\n
							</tr>\n";
					}
				}
			}
			echo "</table>\n";
			echo "</form>\n";
			echo "<table cellpadding=\"2\" cellspacing=\"0\">\n";
			echo "<tr class=\"rowheader\">\n";
			echo "<td style=\"white-space:nowrap;\">Global Tools</td>\n";			
			echo "<td style=\"white-space:nowrap;\">\n<a href=\"javascript:void(0);\" class=\"adminbtn\" style=\"font-weight:normal;text-align:center;\" onclick=\"javascript:document.reorder_form.submit(); return false;\">&nbsp;Update Display Order / Footer Links&nbsp;</a>\n</td>\n";
						
			echo "</tr>\n";
			echo "</table>\n";
			echo "<div align=\"right\">
				<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" style=\"width:100%;\">\n
				<tr class=\"rowheader\">\n
				<td class=\"cellheader\" align=\"left\" valign=\"top\" style=\"width:100%;\" colspan=\"2\"></td>\n
				</tr>\n</table><br />\n
				<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" style=\"width:10%;\">\n
				<tr>\n
				<td class=\"cellsecondary\" align=\"left\" valign=\"top\" style=\"width:100%;\" colspan=\"2\"><span class=\"bodysm\">Color Legend:</span></td>\n
				</tr>
				<tr class=\"rowheader\">\n
				<td class=\"cellheader\" align=\"left\" valign=\"top\" style=\"width:100%;\" colspan=\"2\"><span class=\"bodysmwt\"></span></td>\n
				</tr>
				<tr>\n
				<td class=\"cellprimary\" align=\"center\" style=\"width:50%;white-space:nowrap;\"><span class=\"bodysm\">Top-level Pages</span></td>\n
				<td class=\"cellsecondary\" align=\"center\" style=\"width:50%;white-space:nowrap;\"><span class=\"bodysm\">Sub-Level Pages</span></td>\n
				</tr>\n
				<tr class=\"rowheader\">\n
				<td class=\"cellheader\" align=\"left\" valign=\"top\" style=\"width:100%;\" colspan=\"2\"></td>\n
				</tr>\n</table>";
		}
		else
		{
			echo "<p class=\"bodymd\">No content defined.</p>\n";
		}
	}
}
else
{
	header("Location: index.php");
}
include('footer.php');
ob_end_flush();

function resize_image_gd($src, $dest, $quality, $width, $height, $image_info) {
  $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
 if (function_exists("imagecreatetruecolor")){
    $thumb = imagecreatetruecolor($width, $height);
  }
  if (!$thumb) {
    $thumb = imagecreate($width, $height);
  }
  $image_create_handle = "imagecreatefrom".$types[$image_info[2]];
  if ($image = $image_create_handle($src)) {
       $result = @imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
    
    if (!$result) {
      $result = @imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
    }
    $image_handle = "image".$types[$image_info[2]];
    $image_handle($thumb, $dest, $quality);
    imagedestroy($image);
    imagedestroy($thumb);
  }
  return (file_exists($dest)) ? 1 : 0;
}
function get_width_height($dimension, $width, $height) {  
  $ratio = $width / $height;
  if ($ratio > 1) {
    $new_width = $dimension;
    $new_height = floor(($dimension/$width) * $height);
  }
  else {
    $new_width = floor(($dimension/$height) * $width);
    $new_height = $dimension;
  }
  return array("width" => $new_width, "height" => $new_height);
}
?>