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


mysql_select_db($database_oprmConn, $oprmConn);

$date = date("Y-m-d"); $datetime = date('Y-m-d H:i:s');
$time_stamp = date('Y-m-d H:i:s');

if(isset($_POST['payslip_id']) && !empty($_POST['payslip_id'])){
  // continue
}
else{
    header("Location: payslips-list");
}
$payslip_id = $_POST['payslip_id'];

$query_get_payslip = "SELECT * FROM weby_payslips WHERE payslip_id = '$payslip_id'";
$run_get_payslip = mysql_query($query_get_payslip, $oprmConn) or die(mysql_error());
$row_payslip = mysql_fetch_assoc($run_get_payslip);
$rows_payslips = mysql_num_rows($run_get_payslip);
if($rows_payslips > 0){
  // continue
}
else{
    header("Location: payslips-list");
}

if(isset($_POST['payslip_month']) && !empty($_POST['payslip_month'])){

    if(isset($row_payslip['payslip_file'])){
      $payslip_file = $row_payslip['payslip_file'];
    }
    else{
      $payslip_file = '';
    }

    if($_FILES["payslip_file"]["name"] != ''){
        
        $allowedExts = array("pdf", "jpeg", "jpg", "png","tiff", "rtf", "docs", "docx", "doc", "mov", "mp3", "mp4", "vob", "txt", "rtf", "csv", "xls", "xlsx", "csv", "PDF", "JPEG", "JPG", "PNG","TIFF", "RTF", "DOCS", "DOCX", "DOC", "MOV", "MP3", "MP4", "VOB", "TXT", "RTF", "CSV", "XLS", "XLSX", "CSV");

        $path1 = "../payslips/";

        $extension1 = explode(".", $_FILES["payslip_file"]["name"]);

        $extension = end($extension1);    

        if (($_FILES["payslip_file"]["size"] < 10000000000) && in_array($extension, $allowedExts)) {

          if ($_FILES["payslip_file"]["error"] == 0) {

            $tkn = rand(0001,9999);

            $name = basename($_FILES["payslip_file"]["name"], ".".$extension);

            $filename = $name."_".$tkn.".".$extension;
            //$filename = $name.".".$extension;

            $payslip_file = $fullpath = '/payslips/'.$filename;
            $file_path = dirname(__DIR__) . '/payslips/' . $filename;
            $file_path = str_replace('//', '/', $file_path);
            move_uploaded_file($_FILES["payslip_file"]["tmp_name"], "$path1/$filename");
          }
        }

    }

    $query_update_payslip = "UPDATE weby_payslips SET user_id = '$_POST[resource]', payslip_month = '$_POST[payslip_month]', payslip_file = '$payslip_file', number_of_days = '$_POST[number_of_days]', payslip_notes = '$_POST[payslip_notes]', updated_by = '$_SESSION[user_id]', updated_on = '$time_stamp' WHERE payslip_id = '$_POST[payslip_id]'";

    $run_update_payslip = mysql_query($query_update_payslip, $oprmConn) or die(mysql_error());

    header("Location: payslips-list?msguppayslip");

}


/*if(isset($_POST['task_sub'])){

$start_date = date('Y-m-d', strtotime($_POST['start_date']));

$end_date = date('Y-m-d', strtotime($_POST['end_date']));

mysql_select_db($database_oprmConn, $oprmConn);

$query_getannounce = "INSERT INTO weby_tasks` (`subject`, `start_date`,`resource_id`, `project_id`, `task_details`, `status`, `created_by`, `created_date`) VALUES ('$_POST[task_sub]', '$start_date', '$_POST[resource]', '$_POST[project]', '$_POST[task_msg]', 'A', '$_SESSION[user_id]', '$date')";

$getannounce = mysql_query($query_getannounce, $oprmConn) or die(mysql_error());

//$created_on=date('Y-m-d H:i:s', strtotime($_POST['mdate']));

mysql_select_db($database_oprmConn, $oprmConn);

$query_getaddmsg = "INSERT INTO weby_messages` (`parent_msg_id`, `sender_id`, `receiver_id`, `subject`, `message`, `sender_status`, `receiver_status`, `sender_show`, `receiver_show`, `sender_list_status`, `receiver_list_status`, `sender_saved_list_status`, `receiver_saved_list_status`, `created_on`, `created_by`, `updated_by`) VALUES ('0', '$_SESSION[user_id]', '$_POST[resource]', '$_POST[task_sub]', '$_POST[task_msg]', 'P', 'P', 'Y', 'N', 'S', 'I', 'S', 'I', '$datetime', '$_SESSION[user_id]', '$_SESSION[user_id]')";

$getaddmsg = mysql_query($query_getaddmsg, $oprmConn) or die(mysql_error());

	

$resource = $_POST['resource'];

$tasksubject = $_POST['task_sub'];

$taskmsg = $_POST['task_msg'];

mysql_select_db($database_oprmConn, $oprmConn);

$query_getresourcemail = "SELECT * FROM weby_users WHERE status = 'A' AND user_id = '$resource'";

$getresourcemail = mysql_query($query_getresourcemail, $oprmConn) or die(mysql_error());

$row_getresourcemail = mysql_fetch_assoc($getresourcemail);

$totalRows_getresourcemail = mysql_num_rows($getresourcemail);

if($totalRows_getresourcemail>0){

	$user_email = $row_getresourcemail['email_address'];

    $headers = 'MIME-Version: 1.0' . "\r\n";

       $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

       $headers .= "From: SS WEB TECHNOLOGIES<mailsend@tools.indusltd.com>" . "\r\n" ;

	$subject = "$tasksubject";

	$body = "$taskmsg";

	mail($user_email, $subject, $body, $headers);



} header("Location: updates?msgcrttask");

}*/





/*$maxRows_getTimeSheet = 10;

$pageNum_getTimeSheet = 0;

if (isset($_GET['pageNum_getTimeSheet'])) {

  $pageNum_getTimeSheet = $_GET['pageNum_getTimeSheet'];

}

$startRow_getTimeSheet = $pageNum_getTimeSheet * $maxRows_getTimeSheet;



mysql_select_db($database_oprmConn, $oprmConn);

$query_getTimeSheet = "SELECT weby_timesheets.timesheet_id, weby_timesheets.user_id, weby_timesheets.total_hrs, weby_timesheets.hr_rate, weby_timesheets.total_amount, weby_profiles.full_name, weby_projects.project_name, weby_timesheets.created_date, weby_timesheetstatus.status_label FROM weby_timesheets, weby_profiles, weby_projects, weby_timesheetstatus WHERE weby_timesheets.created_by = weby_profiles.user_id  AND weby_projects.projetc_id = weby_timesheets.project_id AND weby_timesheetstatus.status = 'A'  AND weby_timesheetstatus.status_key = weby_timesheets.status AND weby_timesheetstatus.status_label!= 'Deleted' order by weby_timesheets.updated_date desc";

$query_limit_getTimeSheet = sprintf("%s LIMIT %d, %d", $query_getTimeSheet, $startRow_getTimeSheet, $maxRows_getTimeSheet);

$getTimeSheet = mysql_query($query_limit_getTimeSheet, $oprmConn) or die(mysql_error());

$row_getTimeSheet = mysql_fetch_assoc($getTimeSheet);



if (isset($_GET['totalRows_getTimeSheet'])) {

  $totalRows_getTimeSheet = $_GET['totalRows_getTimeSheet'];

} else {

  $all_getTimeSheet = mysql_query($query_getTimeSheet);

  $totalRows_getTimeSheet = mysql_num_rows($all_getTimeSheet);

}

$totalPages_getTimeSheet = ceil($totalRows_getTimeSheet/$maxRows_getTimeSheet)-1;



$maxRows_getRes = 2;

$pageNum_getRes = 0;

if (isset($_GET['pageNum_getRes'])) {

  $pageNum_getRes = $_GET['pageNum_getRes'];

}

$startRow_getRes = $pageNum_getRes * $maxRows_getRes;



mysql_select_db($database_oprmConn, $oprmConn);*/

/*$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_users.status = 'P' AND weby_profiles.user_id = weby_users.user_id";

$query_limit_getRes = sprintf("%s LIMIT %d, %d", $query_getRes, $startRow_getRes, $maxRows_getRes);

$getRes = mysql_query($query_limit_getRes, $oprmConn) or die(mysql_error());

$row_getRes = mysql_fetch_assoc($getRes);



if (isset($_GET['totalRows_getRes'])) {

  $totalRows_getRes = $_GET['totalRows_getRes'];

} else {

  $all_getRes = mysql_query($query_getRes);

  $totalRows_getRes = mysql_num_rows($all_getRes);

}

$totalPages_getRes = ceil($totalRows_getRes/$maxRows_getRes)-1;



$maxRows_getRes1 = 2;

$pageNum_getRes1 = 0;

if (isset($_GET['pageNum_getRes1'])) {

  $pageNum_getRes1 = $_GET['pageNum_getRes1'];

}

$startRow_getRes1 = $pageNum_getRes1 * $maxRows_getRes1;



mysql_select_db($database_oprmConn, $oprmConn);

$query_getRes1 = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic FROM weby_users, weby_profiles WHERE weby_profiles.status = 'A' AND weby_users.status = 'A' AND weby_users.user_role <> 1 AND weby_profiles.user_id = weby_users.user_id order by weby_profiles.profile_id desc";

$query_limit_getRes1 = sprintf("%s LIMIT %d, %d", $query_getRes1, $startRow_getRes1, $maxRows_getRes1);

$getRes1 = mysql_query($query_limit_getRes1, $oprmConn) or die(mysql_error());

$row_getRes1 = mysql_fetch_assoc($getRes1);



if (isset($_GET['totalRows_getRes1'])) {

  $totalRows_getRes1 = $_GET['totalRows_getRes1'];

} else {

  $all_getRes1 = mysql_query($query_getRes1);

  $totalRows_getRes1 = mysql_num_rows($all_getRes1);

}

$totalPages_getRes1 = ceil($totalRows_getRes1/$maxRows_getRes1)-1;*/

 ?>

<!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. - View Payslip</title>

<link rel="stylesheet" href="../css/style.css" type="text/css">

    <!-- IE Fix for HTML5 Tags -->

    <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 

	<![endif]-->

<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.min.js "></script>

<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

<script>

$(function() {

$("#start_date").datepicker({ dateFormat: 'dd-mm-yy' });

$("#end_date").datepicker({ dateFormat: 'dd-mm-yy' });

});

</script>

<!--<script src="/js/jquery.datetimepicker.full.js"></script>

<link rel="stylesheet" type="text/css" href="/css/jquery.datetimepicker.css"/>

<script>

$(function(){ $('#mdate').datetimepicker({ format:'Y-m-d H:i a', formatTime:'H:i a', formatDate:'yy-mm-dd', step:10 }); });

</script>-->

<script type="text/javascript">

/*function validateForm() {	

	var task_sub = document.getElementById('task_sub').value;

	if((task_sub == "")||(task_sub == null)){

        alert("Please enter task subject");

		return false;

	}

	var start_date = document.getElementById('start_date').value;

	if((start_date == "")||(start_date == null)){

        alert("Please enter start date");

	return false;

	}

	var end_date = document.getElementById('project').value;

	if((end_date == "")||(end_date == null)){

        alert("Please select Project");

	return false;

	}

	var resource = document.getElementById('resource').options[document.getElementById('resource').selectedIndex].value;

	if(resource==0){

		alert("Please select resource");

		return false;

	}

	var task_msg = document.getElementById('task_msg').value;

	if((task_msg == "")||(task_msg == null)){

        alert("Please enter task massage");

		return false;

	}

}*/

</script>

     <style>

.act_updates { background: #373938;

  color: #fff;}

  textarea{

	  height:125px;

  }

  .inside_wrapper input[type="number"]{
    width: 265px;
  }

</style>

</head>



<body>





<!-- Wrapper Starts -->



<div class="wrapper">



    <?php  require_once('../includes/header.php'); ?>

    

<?php  require_once('../includes/tools-menu.php'); ?>

  <!-- Content Goes here -->

    <article class="inside_wrapper clear_fix">

    

    	<!-- Main Content Goes here -->

      <section class="main_content">        

       <div class="admin_container"> 

       <h1>View Payslip</h1>

    <form name="create_client_form" action="" method="POST" id="create_payslip" enctype="multipart/form-data">
      <input type="hidden" name="payslip_id" value="<?php echo $payslip_id; ?>">

    <div class="field_item"><label for="project_name">Salary Month :</label>

      <?php echo $row_payslip['payslip_month']; ?>

	

	<div class="field_item"><label for="project_name">Number of Days :</label>

    <?php echo $row_payslip['number_of_days']; ?>

<div class="field_item"><label for="project_name">Payslip Notes :</label>

    <?php echo $row_payslip['payslip_notes']; ?>
    </div>	

  
  <div class="field_item"><label for="project_name">Payslip File :</label>

    <!-- <input type="file" name="payslip_file" id="payslip_file" class="payslip_file"></div> -->
    <?php 
      if(!empty($row_payslip['payslip_file'])){
        ?>
          &nbsp;&nbsp;&nbsp;&nbsp;<a href="/RM<?php echo $row_payslip['payslip_file']; ?>" download target="_BLANK">Download</a>
        <?php 
      }
    ?>


    

<!--     	<div class="field_item"><label for="project_name">Project :</label>

    <select name="project" id="project">

	<option value="">Select Project</option>

<?php /*mysql_select_db($database_oprmConn, $oprmConn);

$query_getprojects = "SELECT weby_projects.projetc_id, weby_projects.project_name FROM weby_projects where weby_projects.status = 'A'";

$getprojects = mysql_query($query_getprojects, $oprmConn) or die(mysql_error());

$row_getprojects = mysql_fetch_assoc($getprojects);

$totalRows_getprojects = mysql_num_rows($getprojects);

if($totalRows_getprojects > 0){ do{ ?>

<option value="<?php echo $row_getprojects['projetc_id']; ?>"><?php echo $row_getprojects['project_name']; ?></option>

<?php } while($row_getprojects = mysql_fetch_assoc($getprojects)); }*/ ?>

	</select></div> -->

                    

    

	<div class="action_items">

    <!-- <input name="submit" type="submit" class="save_btn" value="Send"> -->

    <input type="button" value="Cancel" class="reset_btn"  onClick="window.location= 'payslips'"></div>

    </form>

    </div>

     

        <!-- /end / -->

        </section>

    

    	<!-- Sidebar Goes here -->

    

    <aside class="sidebar">

      <!-- h2>ACTIVE RESOURCES</h2 -->

      <!-- form action="resources-list.php" method="post" id="act_resource_search">

        <input name="search" class="search" type="text" size="30" />

        <input name="submit" type="submit" class="search-sub" value="Search" />

      </form -->

      <?php //if($totalRows_getRes1>0) { do { ?>

      <!-- div class="profile_box"> <a href="resources-view.php?user_id=<?php //echo $row_getRes1['user_id']; ?>"><img src="/RM/images/<?php //if(!empty($row_getRes1['profile_pic'])) echo $row_getRes1['profile_pic']; else echo "black-img.jpg";?>" width="68" /></a>

        <p class="profile_title"><a href="resources-view.php?user_id=<?php //echo $row_getRes1['user_id']; ?>"><?php //echo $row_getRes1['full_name']; ?></a><span class="desig"><br />

          <?php //echo $row_getRes1['job_title']; ?></span></p>

        <p class="profile_desc"><?php //echo $row_getRes1['skill_set']; ?></p>

        <div class="clear-fix">&nbsp;</div>

      </div -->

      <?php // } while ($row_getRes1 = mysql_fetch_assoc($getRes1)); } else { echo "<div>No Active Resources</div>";} ?>

      

      <!-- p><a href="resources-list.php">View all >></a></p -->

    </aside>

    <div class="clear-fix">&nbsp;</div>

  </article>

  <div class="clear-fix">&nbsp;</div>

  

  <!-- Footer Goes here -->

  

     <?php  require_once('../includes/footer.php'); ?>

    

    

</div>

</body>

</html>

<?php

mysql_free_result($getTimeSheet);



mysql_free_result($getRes);



mysql_free_result($getRes1);



mysql_free_result($getPassEx);

?>