<?php
include "chkuser.php";
include "includefilemng.php";	
	
	$edit_id=0;
	$proceed_flag=0;
	$id=0;
	$name=''; 
	$update_id="id";
	$insert_primary_table="pdfdoc";
	$pdf='';
	
	 if(isset($_GET['cid'])){
	  $cid=$_GET['cid'];	    
	  }   

     if(isset($_GET['editid'])){
	  $edit_id=$_GET['editid'];	
	  
	    $pdelr="select * from ".$insert_primary_table." where  ".$update_id."='$edit_id'";
		$pdelq = mysql_query($pdelr);
		$pdelre = mysql_fetch_array($pdelq);
		extract ($pdelre);    
	  }   

	if(count($_POST)){	
	$post_data=$_POST;	
	$cid=$post_data['cid'];
	$edit_id=$post_data['edit_id'];
	$proceed_flag=0;
	$errormsg='';
	
	if($proceed_flag < 1)
	{	
		
	$name=$_POST['name'];
	$file_original_path=$_FILES['pdf']['tmp_name'];
	$file_name=$_FILES['pdf']['name'];
	
	
					 
					if(strlen($file_name)>0){
								
					$newID=$edit_id;
					
					$sql_data_array['cid']=$cid;
					$sql_data_array['name']=$name;	
									
					$ext=getfileExtension($file_name);
					$pdfname=$newID.".".$ext;						
					$original_file="pdf/".$pdfname;
					$source=$file_original_path;
													 
					copy($source,$original_file);	
															
					$sql_data_array['pdf']=$pdfname;
					$updatecond=$update_id."='$edit_id'";
			        tep_db_perform($insert_primary_table,$sql_data_array,"update",$updatecond);						
					}
											
			
	                $errormsg = " Record updated";
					
					?>
                    <META HTTP-EQUIV=REFRESH CONTENT="1;URL=view_pdf.php?cid=<?php echo $cid;?>"> 
              <?php      
	
	}
	else
	{
	$haderr="yes";
	$errormsg=$errormsg;
	extract($post_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>
<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="85%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="40" class="bigblackTxt">&nbsp;<a href="view_pdf.php" class="normalLink">Manage Pdf Document</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" >
                 				
                  <tr>
                    <td colspan="2" class="bigblackTxt">New Pdf Documents</td>
                  </tr>
				  <tr>
                    <td height="24" colspan="2" class="errFont"> * marked fields are mandatory </td>
                  </tr>
				  <tr>
                    <td colspan="2" class="normalBoldblackTxt">&nbsp;</td>
                  </tr> 
                            
                  <tr>
                    <td width="26%" class="bluebold"><span class="bluebold"> <span class="errFont">*</span>Pdf Title </span> :</td>
                    <td width="74%"><input name="name" type="text" class="inputBOX" id="name" value="<?php echo $name;?>" size="35"></td>
                  </tr>	
				  <tr>
				    <td class="bluebold">Pdf  Upload :</td>
				    <td class="bluebold"><input name="pdf" type="file" class="inputBOX" id="pdf"><?php echo $pdf;?>
				      <input type="hidden" name="pdf_old" id="pdf_old" value="<?php echo $pdf;?>"></td>
				    </tr>
				  <tr>
                 
                  <td class="bluebold">&nbsp;</td>
				    <td class="bluebold">
                     <input type="hidden" name="cid" id="cid" value="<?php echo $cid;?>">
                     <input type="hidden" name="edit_id" id="edit_id" value="<?php echo $edit_id;?>">
                    </td>
				    </tr>
				  <tr>
                    <td width="26%" class="bluebold">&nbsp;</td>
                    <td width="74%">                    
                      <input name="savegau" type="submit" class="hbutton" id="savegau" value="UPDATE"></td>
                  </tr>
				  <tr>
                    <td align="right">&nbsp;</td>
                    <td>&nbsp;                     
                    
                      </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>
