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

include('check-admin-session.php');

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



if(!isset($_REQUEST['tid'])){

	header("Location: updates");

}



if(isset($_REQUEST['tid'])){

	//check task id

mysql_select_db($database_oprmConn, $oprmConn);

//AG COMMENTED $query_checktaskid = "SELECT * FROM weby_tasks WHERE status IN ('A','C') AND task_id = '$_REQUEST[tid]'";

$query_checktaskid = "SELECT * FROM weby_tasks WHERE status != 'D' AND task_id = '$_REQUEST[tid]'";

$checktaskid = mysql_query($query_checktaskid, $oprmConn) or die(mysql_error());

$row_checktaskid = mysql_fetch_assoc($checktaskid);

$totalRows_checktaskid = mysql_num_rows($checktaskid);

if($totalRows_checktaskid==0){

	header("Location: updates");

}



if($_POST['submit']){



$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_getupdatetask = "UPDATE weby_tasks set subject = '$_POST[task_sub]', start_date = '$start_date', resource_id = '$_POST[resource]', project_id = '$_POST[project]', task_details = '$_POST[task_msg]', status = '$_POST[status]', updated_by = '$_SESSION[user_id]' WHERE task_id = '$_POST[tid]'";

$getupdatetask = mysql_query($query_getupdatetask, $oprmConn) or die(mysql_error());


if($row_checktaskid['status'] != $_POST['status']){
  // get status:
  $status = '';

  $query_getStatus = "SELECT * FROM weby_tasks_status where status = 'A'";

  $getStatus = mysql_query($query_getStatus, $oprmConn) or die(mysql_error());

  $row_getStatus = mysql_fetch_assoc($getStatus);

  $totalRows_getStatus = mysql_num_rows($getStatus);

  if($totalRows_getStatus > 0){ 
    do{ 

      if($row_checktaskid['status']==$row_getStatus['weby_tasks_status_key']){
        $status = $row_getStatus['weby_tasks_status'];
        break;
      }

    } while($row_getStatus = mysql_fetch_assoc($getStatus)); 
  } 

  $subject = $_POST['task_sub'] . ' : Status changed to ' . $status;
  $body = $_POST['task_msg'];
  $file_path = false;

  $resource_id = $_POST['resource'];

  $q = "SELECT * FROM weby_users WHERE (user_id = '$resource_id' OR user_role = '1') AND status = 'A'";
  $r = mysql_query($q, $oprmConn) or die(mysql_error());

  $d = mysql_fetch_assoc($r);

  $nr = mysql_num_rows($r);
  if($nr > 0){
    do{

      $user_email = $d['email_address'];

      include_once '../../PHPMailer/PHPMailerAutoload.php';
      //mail_send($user_email, $subject, $body, $file_path);
    }while($d = mysql_fetch_assoc($r)); 
  }


}



header("Location: updates?msguptask");

}

}



$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 Task</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 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('end_date').value;

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

        alert("Please enter end date");

	return false;

	}

	if(new Date(start_date) > new Date(end_date)){

		alert("Please enter end date after start date");

	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;

  }

  .show_task{

	 width: 350px !important;

  }

   .show_head_task{

	   font-weight: bold;

  }

</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 Task</h1>

    <form name="create_client_form" action="" method="POST" id="create_announcement" onsubmit="return validateForm()">

<input type="hidden" name="tid" id="tid" value="<?php echo $row_checktaskid['task_id']; ?>"/>

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

    <input type="text" name="task_sub" id="task_sub" class="task_sub" value="<?php echo $row_checktaskid['subject']; ?>"></div>

	

	<div class="field_item"><label for="project_name">Start date :</label>

    <input type="text" name="start_date" id="start_date" class="task_sub" value="<?php echo date('d-m-Y', strtotime($row_checktaskid['start_date'])); ?>"> (DD-MM-YYYY)</div>

	

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

    <input type="text" name="end_date" id="end_date" class="task_sub" value="<?php //echo date('d-m-Y', strtotime($row_checktaskid['end_date'])); ?>"> (DD-MM-YYYY)</div -->

	

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

    <select name="resource" id="resource">

	<option value="0">Select Resource</option>

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

$query_getresource = "SELECT weby_users.user_id, weby_profiles.full_name FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id AND weby_users.status = 'A' AND weby_profiles.status = 'A' AND weby_users.user_role != '1'";

$getresource = mysql_query($query_getresource, $oprmConn) or die(mysql_error());

$row_getresource = mysql_fetch_assoc($getresource);

$totalRows_getresource = mysql_num_rows($getresource);

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

<option value="<?php echo $row_getresource['user_id']; ?>" <?php if($row_checktaskid['resource_id']==$row_getresource['user_id']){ ?> selected <?php } ?>><?php echo $row_getresource['full_name']; ?></option>

<?php } while($row_getresource = mysql_fetch_assoc($getresource)); } ?>

	</select></div>

    

        	<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 if($row_checktaskid['project_id']==$row_getprojects['projetc_id']){ ?> selected <?php } ?> ><?php echo $row_getprojects['project_name']; ?></option>

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

	</select></div>

    

                    

	<div class="field_item"><label for="client_name">Task Notes:  (Append notes on top to existing notes with a date, do not over write)</label>

    <textarea name="task_msg" id="task_msg" class="task_msg"><?php echo $row_checktaskid['task_details']; ?></textarea></div>

	

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

    <select name="status" id="status">

	

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

$query_getStatus = "SELECT * FROM weby_tasks_status where status = 'A'";

$getStatus = mysql_query($query_getStatus, $oprmConn) or die(mysql_error());

$row_getStatus = mysql_fetch_assoc($getStatus);

$totalRows_getStatus = mysql_num_rows($getStatus);

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

<option value="<?php echo $row_getStatus['weby_tasks_status_key']; ?>" <?php if($row_checktaskid['status']==$row_getStatus['weby_tasks_status_key']){ ?> selected <?php } ?> ><?php echo $row_getStatus['weby_tasks_status']; ?></option>

<?php } while($row_getStatus = mysql_fetch_assoc($getStatus)); } ?>

	</select></div>

    

	<div class="action_items">

    <input name="submit" id="submit" type="submit" class="save_btn" value="Update">

    <input type="button" value="Cancel" class="reset_btn"  onClick="window.location= 'updates'"></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);



?>