<?php
include "chkuser.php";
include "includefilemng.php";	
	
	$edit_id=0;
	$proceed_flag=0;
	$id=0;
	$name=''; 	
	$description='';
	$update_id="id";
	$insert_primary_table="pdfdoc";
	$pdf='';
	//------------------------------------------------------------------------------------------------------------
	$result=mysql_query("SELECT * FROM admin");
	$row = mysql_fetch_object($result);	
	$loop=$row->pdfperpage;
	//----------------------------------------------------------------------------------------------------------
	 if(isset($_GET['cid'])){
	  $cid=$_GET['cid'];	    
	  }   

	if(count($_POST)){
	
	$post_data=$_POST;	
	$cid=$post_data['cid'];
	$proceed_flag=0;
	$errormsg='';
	
	if($proceed_flag < 1)
	{	
		
	$nameArray=$_POST['name'];
	$file_original_path=$_FILES['pdf']['tmp_name'];
	$file_name=$_FILES['pdf']['name'];
	
	
			for($i=0;$i<$loop;$i++){				 
					if(strlen($nameArray[$i])>0){
					
					$newID=tep_db_maxid($insert_primary_table); 
					
					$sql_data_array['cid']=$cid;
					$sql_data_array['name']=$nameArray[$i];	
					
					$ext=getfileExtension($file_name[$i]);
					$pdfname=$newID.".".$ext;	
												
					$original_file="pdf/".$pdfname;
					$source=$file_original_path[$i];
								 
					copy($source,$original_file);	
											
					$sql_data_array['pdf']=$pdfname;
					tep_db_perform($insert_primary_table,$sql_data_array,"insert");									
					}						
			}
	$errormsg = " Record inserted";
	
	}
	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 colspan="2" class="normalBoldblackTxt">&nbsp;</td>
                  </tr> 
                  <?php for($i=1;$i<=$loop;$i++){?>                
                  <tr>
                    <td width="26%" class="bluebold"><span class="bluebold">Pdf Title <?php echo $i;?></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 <?php echo $i;?>:</td>
				    <td class="bluebold"><input name="pdf[]" type="file" class="inputBOX" id="pdf[]">
				      <input type="hidden" name="pdf_old" id="pdf_old" value="<?php echo $pdf_old;?>"></td>
				    </tr>
				  <tr>
                  <?php }?>
                  <td class="bluebold">&nbsp;</td>
				    <td class="bluebold">
                    <input type="hidden" name="cid" id="cid" value="<?php echo $cid;?>">                    </td>
				    </tr>
				  <tr>
                    <td width="26%" class="bluebold">&nbsp;</td>
                    <td width="74%">                    
                      <input name="savegau" type="submit" class="hbutton" id="savegau" value="ADD"></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>
