<?php
require_once('../Connections/oprmConn.php'); $up = "File";
//$allowedExts = array("gif", "jpeg", "jpg", "png");
$col = "";
if(isset($_REQUEST['uptype'])) {
if($_REQUEST['uptype']=="1") {
$up = "Profile Image";
//$allowedExts = array("gif", "jpeg", "jpg", "png");
$col = "profile_pic";
}
if($_REQUEST['uptype']=="2") {
$up = "CV";
//$allowedExts = array("PDF", "doc", "docx");
$col = "cv_file";
}
if($_REQUEST['uptype']=="3") {
$up = "Passport";
//$allowedExts = array("PDF", "doc", "docx", "gif", "jpeg", "jpg", "png");
$col = "passport_file";
}
if($_REQUEST['uptype']=="4") {
$up = "Holiday Sheet";
//$allowedExts = array("PDF","xls","xlsx");
$col = "holiday_sheet";
}
if($_REQUEST['uptype']=="5") {
$up = "Other Documents";
//$allowedExts = array("PDF", "doc", "docx","xls","xlsx");
$col = "other_docs";
}
if($_REQUEST['uptype']=="6") {
$up = "Visa";
//$allowedExts = array("PDF", "doc", "docx", "gif", "jpeg", "jpg", "png");
$col = "visa_file";
}
}
if(isset($_POST['ut'])) {
if($_REQUEST['uptype']=="1") {
$up = "Profile Image";
$allowedExts = array("gif", "jpeg", "jpg", "png");
$col = "profile_pic";
}
if($_REQUEST['uptype']=="2") {
$up = "CV";
$allowedExts = array("pdf", "doc", "docx");
$col = "cv_file";
}
if($_REQUEST['uptype']=="3") {
$up = "Passport";
$allowedExts = array("pdf", "doc", "docx", "gif", "jpeg", "jpg", "png");
$col = "passport_file";
}
if($_REQUEST['uptype']=="4") {
$up = "Holiday Sheet";
$allowedExts = array("pdf","xls","xlsx");
$col = "holiday_sheet";
}
if($_REQUEST['uptype']=="5") {
$up = "Other Documents";
$allowedExts = array("pdf", "doc", "docx","xls","xlsx");
$col = "other_docs";
}
if($_REQUEST['uptype']=="6") {
$up = "Visa";
$allowedExts = array("pdf", "doc", "docx", "gif", "jpeg", "jpg", "png");
$col = "visa_file";
}
$path1 = "../images/"; /* "/RM/images/"; */
$date = date('Y-m-d H:i:s');

$extension1 = explode(".", $_FILES["file"]["name"]);
$extension = end($extension1);
if (($_FILES["file"]["size"] < 10000000) && in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
	$msg = "i";
    }
  else
    {
	//$ts = date("YdmHis").".".$extension;
	$tkn = rand(0001,9999);
	//$ts = date("YdmHis").".".$extension;
	//$ts = $_FILES["file"]["name"].".".$extension;
	$name = basename($_FILES["file"]["name"], ".".$extension);
	
	//$ts = $tkn."_".$_FILES["file"]["name"];
	$ts = $name."_".$tkn.".".$extension;
    move_uploaded_file($_FILES["file"]["tmp_name"],
      "$path1/$ts");
	//	}
	// update the data base
	mysql_select_db($database_oprmConn, $oprmConn);
	if(isset($_REQUEST['user_id']))
$query_Recordset1 = "update weby_profiles set $col = '$ts' WHERE weby_profiles.user_id = '$_REQUEST[user_id]'";
else
$query_Recordset1 = "update weby_profiles set $col = '$ts' WHERE weby_profiles.user_id = '$_SESSION[user_id]'";
//echo $query_Recordset1; exit();
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
	//
	    $msg = "s";
		
}
} else {
		$msg = "i";
}
$redir = "Location: upload.php?msg=".$msg."&page=5&ut=".$_REQUEST['ut'];
header($redir);
}

?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SS WEB TECHNOLOGIES: Upload</title>
 <link rel="stylesheet" href="../css/style.css" type="text/css">
   <link rel="stylesheet" href="../css/style.css" type="text/css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<style>
   BODY{ 
  BACKGROUND-COLOR:#fff;
MARGIN:30PX 15PX 15PX 15PX;
  }
  .featured{
	  padding:10px;
  }
 </style>
<script type="text/javascript">
function refreshParent() 
{
    window.opener.location.reload(true);
}
</script>
<script type="text/javascript">

function closeWin() {
    UPLOAD.close();
}


function refreshParent() 
{
    window.opener.location.reload(true);
}
</script>
</head>

<body onunload="avascript:refreshParent()"><div class="featured yellow">
<font color='red'>
<?php if(isset($_REQUEST['msg'])) { if($_REQUEST['msg']=="s") echo "<h4> File uploaded successfully. Please <u><a href=\"#\" onclick=\"window.close(); return false\">close</a></u> this window.</h4>";
									if($_REQUEST['msg']=="i") echo "<font color='red'><h4> invalid File uploaded. <a href='upload.php?uptype=$_REQUEST[ut]'>Click</a> here to try one more time </h4></font>";
 } ?>
 </font>
<?php if(!isset($_REQUEST['msg'])) {  ?>
<form id="form1" name="form1" method="post" action="#" enctype="multipart/form-data">
  <table width="100%" border="0">
    <tr>
      <td colspan="2">Upload the <?php echo $up; ?> Here</td>
    </tr>
    <tr>
      <td width="14%" height="30" align="left" valign="middle">File:
      <input type="hidden" name="ut" id="ut" value="<?php echo $_REQUEST['uptype']; ?>" />
      <?php if(isset($_REQUEST['user_id'])) { ?><input type="hidden" name="user_id" id="user_id" value="<?php echo $_REQUEST['user_id']; ?>" /><?php } ?></td>
      <td width="86%" height="30" align="left" valign="middle"><label>
        <input type="file" name="file" id="file" />
      </label></td>
    </tr>
    <tr>
      <td><label>
        <input type="submit" name="button" id="button" value="Upload" />
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<?php } ?></div>
</body>

</html>
