<? include("si_confi.php"); ?>
<? include("ad_head.php");
$get_emp_id=base64_decode($_REQUEST['isd']);

  $select_employee_details=mysql_query("select * from `certificate_mng` where `id`='$get_emp_id'");
  $fetch_employee_details=mysql_fetch_array($select_employee_details);
  
   $filenamee=$fetch_employee_details['filen'];
   $filesubst=substr($filenamee,17);
   ?>
  <div class="container">
  <? include("mn_option.php");?>
<?
if(isset($_REQUEST['submit_emp']))
{
	$emp_id=$_REQUEST['emp_id'];
    $title=$_REQUEST['title'];
	
	$emp_row_id=$_REQUEST['emp_row_id'];
	
	$filen=$_FILES['filen']['name'];
	$select_macid=mysql_query("select * from `certificate_mng` where `id`='$emp_row_id'");
	$get_maxid=mysql_fetch_array($select_macid);
	$old_file=$get_maxid['filen'];
	
	$upload_directory="emp_certificate/";
	$newfile="$upload_directory$emp_row_id$filen";
	move_uploaded_file($_FILES['filen']['tmp_name'],$newfile);
	if($filen==NULL){ $up_files=$old_file; } else {unlink("$old_file");$up_files=$newfile; }
	
	$insert_employeee_details=mysql_query("update `certificate_mng` set `emp_id`='$emp_id',`filen`='$up_files',`title`='$title' where `id`='$emp_row_id'");
	?><script>window.location="viw_certfi.php?ed=suc";</script><? } ?>
 

   <div style="border:groove;margin-top:10px;border-width:thin;padding:20px;border-radius:4px;border-color:#cccccc;box-shadow: 10px 9px 90px #000;">
   <h2>Edit Certificate Details&nbsp;&nbsp;&nbsp;&nbsp;
   <input type="button" value="Back" style="background:#F00;color:#FFF;cursor:pointer;" onClick="window.location='viw_certfi.php'"></h2>
  <form method="post" enctype="multipart/form-data" name="form" id="add_employee" onSubmit="return validate();" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <input type="hidden" value="<? echo $get_emp_id ?>" name="emp_row_id">
        <script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="validation.js"></script>
       <table cellpadding="9" id="add_employee">
        <tr>
        <td valign="top">Employee ID</td>
        <td>
        <select name="emp_id">
        <option value="<? echo $fetch_employee_details['emp_id']; ?>"><? echo ucwords($fetch_employee_details['emp_id']); ?></option>
        <option value="" hidden="">Select</option>
        <? $seleect_employee=mysql_query("select * from `employee_mng`");
		while($fetch_employee=mysql_fetch_array($seleect_employee)){ ?>
        <option value="<? echo $fetch_employee['emp_id']; ?>"><? echo ucwords($fetch_employee['name']); ?> - <? echo ucwords($fetch_employee['emp_id']); ?></option>
		<? } ?>
        </select>
        </td>
        </tr>
         <tr>
        <td valign="top">Upload Certificate</td>
        <td><input type="file" name="filen" value="<? echo $filesubst; ?>"></td>
        </tr>
         <tr>
        <td valign="top">Title</td>
        <td><input type="text" name="title" class="required" value="<? echo $fetch_employee_details['title']; ?>"></td>
        </tr>
        <td valign="top">&nbsp;</td>
        <td><input type="submit" name="submit_emp" value="Update" oonClick="return confirm('Are you sure you want to confirm Update Details ?');"></td>
        </tr>
        </table>
		</form>
         <script type="text/javascript">
						function formCallback(result, form) 
						{window.status = "valiation callback for form '" + form.id + "': result = " + result;}
						var valid = new Validation('add_employee', {immediate : true, onFormValidate : formCallback});
					</script>
  </div>
</div><!-- container -->
  </body>
</html>