<?php 
include "chkuser.php";
include "conn.php";
include "db_functions.php";
include "general_functions.php";
include ("class_thumbnail.php");

		$edit=false;
		$edit_id=0;
		$proceed_flag=0;
		$section_id=0;
		$imgname='';
		$id='';
		$pid="";
		$image="";
		$image_table="images";
		$update_id="id";
		$insert_primary_table="images";
		
		
		$mendatry_check_array=array(); 
		$unset_array=array('savegau','edit_id','image','pid','oldimage');
		$multiplevalue_field=array();		
		$validate_check_array=array();			
							
		if(isset($_GET['pid'])){
		$pid=$_GET['pid'];
		
		}					
		if(isset($_GET['editid'])){
		$edit_id=$_GET['editid'];
		$edit=true;		
		}
  
        if($edit){  
		$pdelre =array(); 
		$pdelr=mysql_query("select * from ".$insert_primary_table." where ".$update_id."='$edit_id'");			
		$pdelre=mysql_fetch_array($pdelr);
		extract($pdelre);	
		
        }

		
		if(count($_POST)){
		$temp_data=$post_data=$_POST;
		$edit_id=$post_data['edit_id'];
		$proceed_flag=0;
		$errormsg='';
		//list($proceed_flag,$errormsg)=mendatry_check_field($mendatry_check_array,$validate_check_array,$post_data,$edit_id);		
		if($proceed_flag < 1)
		{			
			foreach($unset_array as $key=>$value)
			unset($post_data[$value]);		
			foreach( $post_data as $k=>$v)
			{
			$sql_data_array[$k] = $v;
			}
			
			if($edit_id>0){	
						
							
					$newID=$_POST['edit_id']; 					
					$pid=$_POST['pid'];	
					 $imgname=$_POST['imgname'];
					$display_order=	$_POST['display_order'];				
					$image_tmp_name=$_FILES["image"]['tmp_name'];
					$image_name=$_FILES["image"]['name'];
																		
					if(strlen($image_name)>3){
					
					 $ext=getfileExtension($_FILES["image"]['name']);
			         $original_file="smallthumbnail/". $newID.".".$ext;					 
			         move_uploaded_file($image_tmp_name,$original_file);
					 					 
					 $thumb_img_name=$newID;
			         $thumb_img_file=$thumb_img_name.".".$ext;
			       	
				  createThumbimage($thumb_img_name,$original_file,"bigthumbnail","600","400","w");
				  createThumbimage($thumb_img_name,$original_file,"smallthumbnail","150","108","w");
					
					$sql_image_array['pid']=$pid;
					
													
					$sql_image_array['image']=$thumb_img_file;	
					
					 }
					 
					 $sql_image_array['imgname']=$imgname;
					  $sql_image_array['display_order']=$display_order;
				   $updatecond=$update_id."='".$newID."'";				
					tep_db_update($insert_primary_table,$sql_image_array,$updatecond);
			      
				  
				   
			     ?>
				<html>
			<HEAD>
			 <META HTTP-EQUIV=REFRESH CONTENT="0;URL=photogallery.php?pid=<?php echo $pid;?>">
			</HEAD>
			</html>		 		
			<?php
			}	
					
		}
		else
		{
		$haderr="yes";
		$errormsg = $errormsg;
		extract($temp_data);
		}

 }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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">
<style type="text/css">
<!--
.style3 {color: #000000}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script> 
</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" align="left" cellpadding="0" cellspacing="0" class="centertable">
      <tr>
        <td align="left"><table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
           <td height="35" valign="bottom"><span class="bluebold"><a href="photogallery.php" class="normalLink">Manage Photo</a></span></td>
          </tr>         
          <tr>
            <td colspan="2"><table width="100%"  border="0" align="left" cellpadding="2" cellspacing="3" bgcolor="#FFFFFF">
              <form action="" method="POST" enctype="multipart/form-data" name="SaveForm" id="SaveForm">             
                <tr>
                  <td height="25" colspan="4" class="bigblackTxt" >Edit Photo </td>
                </tr>
				 <tr>
            <td width="140"></td>
            <td width="605"><?php 
		  if(isset($errormsg))
		  	{
				echo display_error_msg($errormsg);
		   	}
			?></td>
          </tr>                <tr>
                  <td colspan="4" class="errFont">&nbsp;</td>
                </tr>
                <tr>
<td class="bluebold">Image Title :</td>
<td><input name="imgname" type="text" class="inputBOX" value="<?php echo $imgname;?>">
  <input type="hidden" name="pid"  value="<?php echo $pid;?>"/>  
  </td>
</tr>       
                <tr>
                  <td align="left" class="bluebold">Image :</td>
                  <td colspan="3"><input name="image" type="file"  class="inputBOX">
				       <?php if((file_exists("smallthumbnail/".$image)) && (strlen($image) > 4))
						{?>												
						 <img src="smallthumbnail/<?php echo $image;?>" width="20" height="20">
						<?php
						}										
						?>
				
				        <span class="bluebold">(600wx400h)</span></td>
                </tr>
				 <tr>
<td class="bluebold"> Display order :</td>
<td><input name="display_order" type="text" class="inputBOX" value="<?php echo $display_order;?>">
    
  </td>
</tr>       
                
      
				         <tr>
                  <td align="right">&nbsp;</td>
                  <td colspan="3">
				  <input name="savegau" type="submit" class="hbutton" id="savegau" value="UPDATE">
                            
                            <input name="edit_id" type="hidden" id="edit_id" value="<?php echo $edit_id;?>">
							<input name="back" type="submit" class="hbutton" id="back" onClick="MM_goToURL('parent','photogallery.php?edit_id=<?php echo $edit_id;?>');return document.MM_returnValue" value="Back">							</td>
                </tr>
                <tr>
                  <td colspan="4">&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>
