<?php
include "chkuser.php";
include "includefilemng.php";

//include "general_functions.php";
//include ("class_thumbnail.php");
	
	$edit=false;
	$edit_id=0;
	$proceed_flag=0;
	$id=0;
	$name=''; 
	$pOrder='';
	$description='';
    $special_title='';
	$update_id="id";
	$insert_primary_table="page";
	$pPosition='';
	$mendatry_check_array=array('name','description'); // mention all field which is mendetary
	$unset_array=array('savegau','edit_id','id','oldimg');
	$validate_check_array=array();	
	
	
							
	if(isset($_GET['editid'])){
	  $edit_id=$_GET['editid'];
	  $edit=true;	  
	  }
  
   if($edit){  
		$pdelre =array(); 
		$pdelr = "select * from ".$insert_primary_table." where  ".$update_id." ='$edit_id'";		
		
		$pdelq = mysql_query($pdelr,$eclipse);
		$pdelre = mysql_fetch_array($pdelq);
		
		//print_r($pdelre);
		extract ($pdelre);
		//$pass1=$pass;
		
		//$a=addslashes($name);
		
						 
		//  Edit not neccessary 		
		///////////////////
		
		
  }


if(count($_POST)){
$temp_data=$post_data=$_POST;
$edit_id=$post_data['edit_id'];
$proceed_flag=0;
$errormsg='';
list($proceed_flag,$errormsg)=validate_form_field($mendatry_check_array,$validate_check_array,$post_data,$edit_id);
	 
	 
	 if(isset($_POST['special']))
	{
	 $special="y";
	}
else
	{
	 $special="n";
	}
	 
	 
	 
	 
	 
	if($proceed_flag < 1)
	{		
	
	foreach($unset_array as $key=>$value)
		unset($post_data[$value]);

			 foreach($post_data as $k=>$v){			
			 $sql_data_array[$k]=stripslashes(htmlentities($v,ENT_QUOTES));			  
			}
					 
		
		if($edit_id>0){
		
			$updatecond=$update_id."='$edit_id'";
			$sql_data_array['special']= $special;
			tep_db_perform($insert_primary_table, $sql_data_array,"update",$updatecond);		
			$errormsg = " Record updated";
		}else{			
			tep_db_perform($insert_primary_table, $sql_data_array,"insert");		
			$id=mysql_insert_id();
			$errormsg = " Record inserted";
		}
		
		
		
		
		if(IMAGEFIELDEXIST)
			{	
			//image upload 
			$image_tmp_name = $_FILES['image']['tmp_name'];
			$image_name = $_FILES['image']['name'];
			if(strlen($image_name) > 2)
			{
			//get file extension
			$ext = getfileExtension($image_name);
			$original_file = "specialimage/" . $edit_id.".".$ext;
			move_uploaded_file($image_tmp_name,$original_file);
			//echo copy($image_tmp_name, $original_file); 
			//unlink($image_tmp_name);
			//create thumbnail
			$thumb_img_name = $edit_id;
			$thumb_img_file = $thumb_img_name.".".$ext;
			//$result = createThumbimage($thumb_img_name,$original_file,"specialimage","150","100","w");
			$sql_update ="update page   set image = '$thumb_img_file' where id = '$edit_id'";
			$sql_result = mysql_query($sql_update);
			}
			}
	
?>	
	<META HTTP-EQUIV=REFRESH CONTENT="1;URL=view_page.php">
	<?php
	}
	else
	{
	$haderr="yes";
	$errormsg = $errormsg;
	extract($temp_data);
	}


}

?>
<html>
<head>
<title>control panel </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
<script language="javascript" src="includenp/functions.js"></script>
<script language="javascript" type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript" src="tinymca.js"></script>	

<style type="text/css">
<!--
.style2 {color: #000000}
-->
</style>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td width="1%"   bgcolor="#C9C9C9"></td>
	<td width="98%"><?php include_once "top.php";?></td>
	<td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
   <td width="1%"   bgcolor="#C9C9C9"></td>
    <td width="98%"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="centertable">
      <tr>
        <td><table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="50" class="bigblackTxt">&nbsp;<a href="view_page.php" class="normalLink">Manage pages</a></td>
          </tr>
          <tr>
            <td><?php 
		  if(isset($errormsg))
		  	{echo display_error_msg($errormsg);
		   	}
			?>
            </td>
          </tr>
          <tr>
            <td>
            
              <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="4">
                <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>" name="SaveForm" ID="SaveForm" enctype="multipart/form-data" >
                 <input type="hidden" name="edit_id" value="<?php  echo $edit_id;?>">
				
                  <tr>
                    <td colspan="2" class="bigblackTxt"><?php if($edit==true){ echo "Edit";} else { echo "New";}?> cms page</td>
                  </tr>
				  <tr>
                    <td height="24" colspan="2" class="errFont"> * marked fields are mandatory </td>
                  </tr>
				  <tr>
                    <td colspan="2" class="normalBoldblackTxt"> Identification </td>
                  </tr>                 
                  <tr>
                    <td width="26%" class="bluebold"><span class="bluebold"> <span class="errFont">*</span>Page Title</span>: </td>
                    <td width="74%"><input name="name" type="text" class="inputBOX" id="name" value="<?php echo $name;?>" size="35"></td>
                  </tr>
                   
                      <input name="pPosition" type="hidden"  id="pPosition" value="<?php echo $pPosition;?>" size="35">                    
				  <tr>
                    <td width="26%" class="bluebold"><span class="errFont">*</span>Description</span> ( <span style="color:#FF0000">Don't insert images with width greater than 475 pixels</span> ) : </td>
                    <td width="74%"><textarea name="description" cols="90" rows="20" class="inputBOX" id="textarea"><?php echo stripslashes($description);?></textarea></td>
                  </tr>
				  
				<?php if($edit_id==15 )
				{
				?>
				
				  <tr>
                    <td width="26%" class="bluebold"><span class="bluebold"> <span class="errFont">*</span>Special Title</span>: </td>
                    <td width="74%"><input name="special_title" type="text" class="inputBOX" id="special_title" value="<?php echo $special_title;?>" size="35"></td>
                  </tr>
				
				<tr>
				<td class="bluebold"> Image</td>
				<td class="bluebold"><input type="file" name="image" id="image" class="inputBOX">
				<?php
				
				
				{
				echo tep_image(SPECIALIMAGE."/".$image, $alt = '', 50, 50,''); 
				}
				?>
				<input name="oldimg" type="hidden" id="oldimg" value="<?php echo $oldimg;?>" />				</td>
				</tr>
				
				
				
				
				
				 
				 
				
				  <tr>
				    <td class="bluebold">Display:</td>
				    <td class="bluebold"><input type="checkbox" name="special" value="y" <?php if($special == "y"){ echo "checked";} ?>></td>
				    </tr>
					
				<?php
				}
				?>
				  <tr>
                  <td class="bluebold">&nbsp;</td>
				    <td class="bluebold"><input type="hidden" name="pOrder" id="pOrder" value="<?php echo $_GET['cid'];?>"></td>
				    </tr>
				  <tr>
                    <td width="26%" class="bluebold">&nbsp;</td>
                    <td width="74%">                    
                      <input name="savegau" type="submit" class="hbutton" id="savegau" value="<?php if($edit_id>0) echo "UPDATE"; else echo "ADD";?>"></td>
                  </tr>
				  <tr>
                    <td align="right">&nbsp;</td>
                    <td>                      <span class="normalTxt"><span class="bigblackTxt">
                    
                      </span></span></td>
                  </tr>
                  <tr>
                    <td colspan="2">&nbsp;</td>
                  </tr>
                </form>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
    <td   bgcolor="#C9C9C9" width="1%"></td>
	<td><?php include_once "footer.php";?></td>
	<td width="1%"   bgcolor="#C9C9C9"></td>
  </tr>
</table>
</body>
</html>
