<?php

require_once('../Connections/oprmConn.php'); 

if(!isset($_SESSION['user_id']))

{

	header("location: ../index.php");

}

$prid = $_REQUEST['prid'];

$usid = $_SESSION['user_id'];

$d = date("Y-m-d");

mysql_select_db($database_oprmConn, $oprmConn);

$query_PendingGalleries = "SELECT * FROM weby_otherdoc WHERE weby_otherdoc.profile_id=$prid AND weby_otherdoc.status = 'A'";

$PendingGalleries = mysql_query($query_PendingGalleries, $oprmConn) or die(mysql_error());

$row_PendingGalleries = mysql_fetch_assoc($PendingGalleries);

$totalRows_PendingGalleries = mysql_num_rows($PendingGalleries);











$up = "File";

//$allowedExts = array("gif", "jpeg", "jpg", "png");

$col = "";

//if(isset($_REQUEST['uptype'])) {
//
//if($_REQUEST['uptype']=="1") {
//
//$up = "Other Documents";
//
////$allowedExts = array("PDF", "doc", "docx","xls","xlsx");
//
//$col = "other_docs";
//
//}
//
//}

if(isset($_POST['ut'])) {

//if($_REQUEST['uptype']=="1") {

$up = "Other Documents";

$allowedExts = array("pdf", "doc", "docx","xls","xlsx", "gif", "jpeg", "jpg", "png");

$col = "other_docs";

$prid = $_REQUEST['prid'];

//}

$path1 = "../documents/";

$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
    {
		$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);

  

  $q = "INSERT INTO weby_otherdoc set profile_id='$prid', user_id = '$_SESSION[user_id]', other_docs='$ts', created_by='$usid', created_date='$d', updated_by='$usid', status='A'";

mysql_select_db($database_oprmConn, $oprmConn);

$query_Recordset1 = $q;

$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());

 

	/*mysql_select_db($database_oprmConn, $oprmConn);

$query_Recordset1 = "update profiles set $col = '$ts' WHERE profiles.user_id = '$_SESSION[user_id]'";

$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());*/



	//

	/*mysql_select_db($database_oprmConn, $oprmConn);

$query_Recordset2 = "SELECT * FROM otherdoc WHERE otherdoc.profile_id = '$prid'";

$Recordset2 = mysql_query($query_Recordset2, $oprmConn) or die(mysql_error());

$row_Recordset2 = mysql_fetch_assoc($Recordset2);

$totalRows_Recordset2 = mysql_num_rows($Recordset2);





mysql_select_db($database_iitConn, $iitConn);

$query_PendingGalleries = "SELECT *,max(phid) FROM iitlc_gallery,iitlc_gallery_photos WHERE ((iitlc_gallery.status='pending' OR  iitlc_gallery_photos.status='pending') AND (iitlc_gallery.gid=iitlc_gallery_photos.galleryid)) OR (iitlc_gallery.status='pending') GROUP BY iitlc_gallery.gid";

$PendingGalleries = mysql_query($query_PendingGalleries, $iitConn) or die(mysql_error());

$row_PendingGalleries = mysql_fetch_assoc($PendingGalleries);

$totalRows_PendingGalleries = mysql_num_rows($PendingGalleries);

*/

		



	    $msg = "s";

		

}

} else {

		$msg = "i";

}

$redir = "Location: upload_other.php?&prid=$_REQUEST[prid]&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="//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">

<?php if(isset($_REQUEST['msg'])) { if(($_REQUEST['msg']=="s") & ($totalRows_PendingGalleries < 10)) echo "<font color='red'><p> File uploaded successfully. Please <u><a href=\"#\" onclick=\"window.close(); return false\">close</a></u> this window OR <a href='upload_other.php?prid=$prid&uptype=1'><u>Click here</a></u> to upload a new file</p></font>";

									if($_REQUEST['msg']=="i") echo "<font color='red'><p> invalid File uploaded. <a href='upload_other.php?uptype=$_REQUEST[ut]&prid=$_REQUEST[prid]'>Click</a> here to try one more time</p></font>";

 } ?>

 <?php 

 if($totalRows_PendingGalleries < 15) { ?>

<?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"><h3>Upload the <?php echo $up; ?> Here</h3></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']; ?>" />

       <input type="hidden" name="prid" id="prid" value="<?php echo $_REQUEST['prid']; ?>" />

      

      </td>

      <td width="86%" height="30" align="left" valign="middle"><label>

        <input type="file" name="file" id="file" class="save_btn" />

      </label></td>

    </tr>

    <tr><td>&nbsp;</td>

      <td class="action_items">

      

        <input type="submit" name="button" id="button" value="Upload" class="save_btn" />

      </td>

      

      

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

    </tr>

  </table>

</form>

<?php } ?>

<?php } else { echo "Your upload limit of max 10 files reached. Delete one file from your other documents list to upload another one.";} ?></div>

</body>



</html>

