<? include("si_confi.php"); ?>
<? include("ad_head.php"); ?>
  <div class="container">
  <? include("mn_option.php");?>
<?
if(isset($_REQUEST['submit_emp']))
{
	$emp_id=$_REQUEST['emp_id'];
    $title=$_REQUEST['title'];
	
	$filen=$_FILES['filen']['name'];
	$select_macid=mysql_query("select max(id) AS ID from `certificate_mng`");
	$get_maxid=mysql_fetch_array($select_macid);
	$maxidd=$get_maxid['ID']+1;
	$upload_directory="emp_certificate/";
	$filenamee="$upload_directory$maxidd$filen";
	move_uploaded_file($_FILES['filen']['tmp_name'],$filenamee);
	
	
	$insert_employeee_details=mysql_query("insert into `certificate_mng` (`emp_id`,`title`,`filen`) values ('$emp_id','$title','$filenamee')");
	?><script>window.location="ad_certfi.php?ad=suc";</script><?
}
 ?>

<? if($_REQUEST['ad']=='suc'){ ?>
  <div class="success" style="width:92%;margin:0 auto;margin-top:9px;">Details Added successfully.</div><? } ?>
  

   <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>Add Certificates</h2>
   
   
<SCRIPT LANGUAGE="JavaScript">
function validate()
{
var extensions = new Array("pdf");
var image_file = document.form.filen.value;
var image_length = document.form.filen.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
for (i = 0; i < extensions.length; i++){if(extensions[i] == final_ext){return true; }}
alert("You must upload an image file with one of the following extensions: "+ extensions.join(', ') +".");
return false;}
</SCRIPT>
 
 
 
  <form method="post" enctype="multipart/form-data" name="form" id="add_certi" onSubmit="return validate();" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="validation.js"></script>
        <table cellpadding="9" id="add_certi">
        <tr>
        <td valign="top">Employee ID</td>
        <td>
        <select name="emp_id" class="validate-selection">
        <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" class="required"></td>
        </tr>
         <tr>
        <td valign="top">Title</td>
        <td><input type="text" name="title" class="required"></td>
        </tr>
        <td valign="top">&nbsp;</td>
        <td><input type="submit" name="submit_emp" onClick="return confirm('Are you sure you want to confirm add 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_certi', {immediate : true, onFormValidate : formCallback});
					</script>
  </div>
</div><!-- container -->
  </body>
</html>