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

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

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

if(isset($_GET['created_by']) && ($_GET['created_by'] == 'ALL')){
	$url="updates.php"; header("Location:$url");
}
	
$maxRows_gettasklist = 20;
$pageNum_gettasklist = 0;
if (isset($_GET['pageNum_gettasklist'])) {
  $pageNum_gettasklist = $_GET['pageNum_gettasklist'];
}
$startRow_gettasklist = $pageNum_gettasklist * $maxRows_gettasklist;

//$maxRows_gettasklist = 10;
//	$pageNum_gettasklist = 0;
//	if (isset($_GET['pageNum_gettasklist'])) {
//	  $pageNum_gettasklist = $_GET['pageNum_gettasklist'];
//	}
//	$startRow_gettasklist = $pageNum_gettasklist * $maxRows_gettasklist;

//select configuration data
mysql_select_db($database_oprmConn, $oprmConn);
if(!isset($_GET['created_by']) && ($_GET['created_by'] != "ALL")){
$query_gettasklist = "SELECT * FROM weby_tasks WHERE  status != 'D' AND resource_id = '$_SESSION[user_id]'  order by start_date desc";
} else { $ruid = $_GET['created_by'];
$query_gettasklist = "SELECT * FROM weby_tasks WHERE  status != 'D' AND resource_id = '$ruid' order by start_date desc";
}
$gettasklist = mysql_query($query_gettasklist, $oprmConn) or die(mysql_error());
$row_gettasklist = mysql_fetch_assoc($gettasklist);
$totalRows_gettasklist = mysql_num_rows($gettasklist);

if (isset($_GET['totalRows_gettasklist'])) {
	  $totalRows_gettasklist = $_GET['totalRows_gettasklist'];
	} else {
	  $all_gettasklist = mysql_query($query_gettasklist);
	  $totalRows_gettasklist = mysql_num_rows($all_gettasklist);
	}
	$totalPages_gettasklist = ceil($totalRows_gettasklist/$maxRows_gettasklist)-1;

$queryString_gettasklist = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_gettasklist") == false && 
        stristr($param, "totalRows_gettasklist") == false) {
      array_push($newParams, $param);
    }
  }
}



$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 = 5;
$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 - Updates</title>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/colorbox.css"> 
<!-- IE Fix for HTML5 Tags -->
<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]-->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 
<style>
.act_updates  { 
background: #373938;
  color: #fff;}
  .timesheet_table .x-item_wide{
	  width:170px;
	  display:inline-table;
  }
  .timesheet_table .x-big_wide{
	  width:270px;
	  display:inline-table;
  }
.timesheet_table .item_wide:last-child{
	float:right;
}
.timesheet_table .column_title {
	color:#fff;
}
.view_annonce input{
	    margin: 0;
    padding: 0;
    outline: none;
    cursor: pointer;
    background: none;
    color: #428BCA;
    font-weight: bold;
}
.timesheet_table .x-item_wide {
    width: 155px;
    display: inline-table;
}
</style>
<script>
function redirect(){
var created_by = document.getElementById('created_by').options[document.getElementById('created_by').selectedIndex].value;
window.location = "updates.php?created_by="+created_by+"";
}
</script>
<?php if(isset($_GET['msgcrttask'])) { $msgcrttask = "Task created successfully"; ?><script>alert("<?php echo $msgcrttask; ?>");</script><?php } ?>
	
<?php if(isset($_GET['msguptask'])) { $msguptask = "Task updated successfully"; ?><script>alert("<?php echo $msguptask; ?>");</script><?php } ?>
	
<?php if(isset($_GET['msgdeltask'])) { $msgdeltask = "Task deleted successfully"; ?><script>alert("<?php echo $msgdeltask; ?>");</script><?php } ?>
</head>

<body>

<!-- Wrapper Starts -->

<div class="wrapper">

  <?php  require_once('../includes/header.php'); ?>
  <?php  require_once('../includes/tools-menu.php'); ?>
  <!-- Content Goes here --> 
  
  <!-- Content Goes here -->
  
  <article class="inside_wrapper clear_fix"> 
    
    <!-- Main Content Goes here -->
    
    <section class="main_content" style="width:100%">
      <h1 style="float:left">Task Updates</h1>
      <!-- div class="add_announce"><a href="create-task">Create Task</a></div -->
	  <div class="welcome_box1 welcome_2box" >




</div>
      
      
      <div class="timesheet_table clear_fix" style="width:915px;">
        <div class="column_title" >
        <span class="item_wide" style="width:180px;">Subject </span>
		<span class="item_wide" style="width:180px;">Resource</span>
        <span class="item_wide" style="width:165px;">Project</span>
		<span class="x-item_wide" style="width:120px;">Start Date</span>
		<span class="item_wide" style="width:140px;">Status</span> 
        <span class="item_wide" style="width:100px;"></span>
        </div>
        <?php if($totalRows_gettasklist > 0) { do { ?>
    <div class="row <?php if($n==0) { echo "yellow"; $n=1; } else $n=0; ?>">
	<span class="item_wide" style="width:180px;">
	<?php echo substr($row_gettasklist['subject'], 0,50).'...'; ?></span>
	
	<span class="item_wide" style="width:180px;">
	<?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getresource = "SELECT 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' AND weby_profiles.user_id = '$row_gettasklist[resource_id]'";
$getresource = mysql_query($query_getresource, $oprmConn) or die(mysql_error());
$row_getresource = mysql_fetch_assoc($getresource);
$totalRows_getresource = mysql_num_rows($getresource);
echo $row_getresource['full_name']; ?></span>

	<span class="item_wide" style="width:165px;">
	<?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getProject = "SELECT * FROM weby_projects WHERE weby_projects.projetc_id = '$row_gettasklist[project_id]'";
$getProject  = mysql_query($query_getProject , $oprmConn) or die(mysql_error());
$row_getProject  = mysql_fetch_assoc($getProject );
$totalRows_getProject  = mysql_num_rows($getProject );
echo $row_getProject ['project_name']; ?></span>
	
	<span class="x-item_wide" style="width:120px;"><?php echo date("jS M Y", strtotime($row_gettasklist['start_date'])); ?></span>
	
	<span class="item_wide" style="width:140px;">
    <?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getStatus = "SELECT * FROM weby_tasks_status WHERE weby_tasks_status_key = '$row_gettasklist[status]'";
$getStatus = mysql_query($query_getStatus, $oprmConn) or die(mysql_error());
$row_getStatus = mysql_fetch_assoc($getStatus);
$totalRows_ggetStatus = mysql_num_rows($getStatus);
echo $row_getStatus['weby_tasks_status']; ?>
    
    </span>
	
	<span class="item_wide" style="width:100px;">
	<form action="view-task" method="post" class="view_annonce"> <input type="hidden" name="tid" id="tid" value="<?php echo $row_gettasklist['task_id']; ?>"><input type="submit" value="View" /></form>
	<form class="delete_annonce" action="delete-task" method="post">
	<!--<input type="hidden" name="dtid" id="dtid" value="<?php echo $row_gettasklist['task_id']; ?>"><!-- input type="submit" value="Delete" name="delete" id="delete" class="exit" onclick="return confirm('Are you sure you want to delete task?')"/ --></form></span> </div>
    <?php } while ($row_gettasklist = mysql_fetch_assoc($gettasklist)); ?>
	
        <div class="nav-right">
<table border="0" align="center" cellpadding="2" style="clear:both">
<tr><td colspan="4" align="center"><?php echo ($startRow_gettasklist + 1) ?> to <?php echo min($startRow_gettasklist + $maxRows_gettasklist, $totalRows_gettasklist) ?> of <?php echo $totalRows_gettasklist ?></td></tr>

<tr><td align="center"><?php if ($pageNum_gettasklist > 0) { // Show if not first page ?><a href="<?php printf("%s?pageNum_gettasklist=%d%s", $currentPage, 0, $queryString_gettasklist); ?>">&lt;&lt; START</a><?php } // Show if not first page ?></td>

<td align="center"><?php if ($pageNum_gettasklist > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_gettasklist=%d%s", $currentPage, max(0, $pageNum_gettasklist - 1), $queryString_gettasklist); ?>">&lt; PREVIOUS</a>
<?php } // Show if not first page ?></td>

<td align="center"><?php if ($pageNum_gettasklist < $totalPages_gettasklist) { // Show if not last page ?><a href="<?php printf("%s?pageNum_gettasklist=%d%s", $currentPage, min($totalPages_gettasklist, $pageNum_gettasklist + 1), $queryString_gettasklist); ?>">NEXT &gt;</a><?php } // Show if not last page ?></td>

<td align="center"><?php if ($pageNum_gettasklist < $totalPages_gettasklist) { // Show if not last page ?><a href="<?php printf("%s?pageNum_gettasklist=%d%s", $currentPage, $totalPages_gettasklist, $queryString_gettasklist); ?>">LAST &gt;&gt;</a>
<?php } // Show if not last page ?></td>
	</tr>
</table>
</div>
    <?php } else echo "<div class='no-rows'>No Updates found</div>";?>
      </div>
            
    </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>
