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

if(!isset($_SESSION['user_id'])){
	header("location: ../index.php");
}
if(isset($_REQUEST['timesheetid'])) {
$l = "timesheet-edit.php?timesheet_id=".$_REQUEST['timesheetid']."&token=".$_REQUEST['token'];
header("location: $l");
}

if(isset($_GET['week'])){
mysql_select_db($database_oprmConn, $oprmConn);
$query_getWeek = "SELECT  DISTINCT (project_id) FROM weby_timesheets WHERE task_week = '$_GET[week]' and task_year = '$_GET[year]' and user_id = '$_SESSION[user_id]' and status in ('I', 'B') ORDER BY project_id ASC";
$getWeek = mysql_query($query_getWeek, $oprmConn) or die(mysql_error());
$row_getWeek = mysql_fetch_assoc($getWeek);
$totalRows_getWeek = mysql_num_rows($getWeek);
}
$ipaddress = $_SERVER['REMOTE_ADDR'];

if(isset($_POST['save'])){ 
$count = $_GET['count'];
$i=0;
$week_number = $_POST['week'];
$year = $_POST['year'];
for($m = 0; $m <= $count; $m++){
if($m > 0){	$varprj = "project".$m; $varclient = "client".$m; } else if($m == 0){ $varprj = "project"; $varclient = "client"; }
$project = $_POST[$varprj]; $client = $_POST[$varclient];
if(($project != 0) && ($client != '')){
$user = "$_SESSION[user_id]";

mysql_select_db($database_oprmConn, $oprmConn);
$query_PendingGalleries = "SELECT * FROM weby_timesheets WHERE project_id = '$project' AND task_week = '$week_number' AND task_year = '$year' AND user_id = '$user'";
$PendingGalleries = mysql_query($query_PendingGalleries, $oprmConn) or die(mysql_error());
$row_PendingGalleries = mysql_fetch_assoc($PendingGalleries);
$totalRows_PendingGalleries = mysql_num_rows($PendingGalleries);
	for($w=1; $w<=7; $w++){
$dtt = date('Y-m-d', strtotime($year."W".$week_number.$w));
if($m > 0){ $vart1 = "total_hrs".$w.$m; }
else if($m == 0){ $vart1 = "total_hrs".$w; }
$total_hrs= $_POST[$vart1];
$pt = $project;
$user_id = $_SESSION['user_id'];							
$token = rand(15420,999898);				
$status = "I";
//echo $pt.'<br>'.$total_hrs.'<br>'.$status.'<br>'.$user_id.'<br>'.$week_number.'<br>'.$year.'<br>'.$dtt.'<br>';

mysql_select_db($database_oprmConn, $oprmConn);
$query_getFirst = "SELECT * FROM weby_timesheets WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' AND status in ('I', 'B')";
$getFirst = mysql_query($query_getFirst, $oprmConn) or die(mysql_error());
$row_getFirst = mysql_fetch_assoc($getFirst);
$totalRows_getFirst = mysql_num_rows($getFirst);
if($totalRows_getFirst > 0){
mysql_select_db($database_oprmConn, $oprmConn);
$query_Recordset1 = "UPDATE weby_timesheets SET project_id = '$pt', client_id = '$client', total_hrs = '$total_hrs', ip_address = '$ipaddress', status = '$status', updated_by = '$user_id', token = '$token' WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' and status in ('I', 'B')";
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
} else if($totalRows_getFirst == 0){
mysql_select_db($database_oprmConn, $oprmConn);
$query_getEdit = "SELECT * FROM weby_timesheets WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' AND status in ('A', 'Q')";
$getEdit = mysql_query($query_getEdit, $oprmConn) or die(mysql_error());

$row_getEdit = mysql_fetch_assoc($getEdit);



$totalRows_getEdit = mysql_num_rows($getEdit);

if($totalRows_getEdit == 0){
mysql_select_db($database_oprmConn, $oprmConn);
$qu = "INSERT INTO weby_timesheets (user_id,project_id,client_id,total_hrs,task_week,task_year,ip_address,status,created_by,created_date,updated_by,token) VALUES ('$user_id','$pt','$client','$total_hrs','$week_number','$year','$ipaddress','$status','$user_id','$dtt','$user_id','$token')";
$query_getProj = $qu;
$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());
}
}
$msg = "Timesheet Saved to Drafts Successfully";
header("location: timesheet.php?msgdr=".$msg."");
}
} else if($project == 0){
$msg = "No Project Selected";
header("location: timesheet-view.php?week=$week_number&year=$year&msgdg=".$msg."");
} else if($client == ''){
$msg = "No Client Selected";
header("location: timesheet-view.php?week=$week_number&year=$year&msgdg=".$msg."");
}
}

}
if(isset($_POST['submit'])){
	$count = $_GET['count'];
$i=0;
$week_number = $_POST['week'];
$year = $_POST['year'];
for($m = 0; $m <= $count; $m++){
if($m > 0){	$varprj = "project".$m; $varclient = "client".$m; } else if($m == 0){ $varprj = "project"; $varclient = "client"; }
$project = $_POST[$varprj]; $client = $_POST[$varclient];
if(($project != 0) && ($client != '')){
$user = $_SESSION['user_id'];
	for($w=1; $w<=7; $w++){
$dtt = date('Y-m-d', strtotime($year."W".$week_number.$w));
if($m > 0){ $vart1 = "total_hrs".$w.$m; }
else if($m == 0){ $vart1 = "total_hrs".$w; }
$total_hrs= $_POST[$vart1];
$pt = $project;
$d = date("Y-m-d",strtotime($_POST['date'])); 
$user_id = $_SESSION['user_id'];
$token = rand(15420,999898);
$status = "A";
//echo $pt.'<br>'.$total_hrs.'<br>'.$status.'<br>'.$user_id.'<br>'.$week_number.'<br>'.$year.'<br>'.$dtt.'<br>';

mysql_select_db($database_oprmConn, $oprmConn);
$query_getFirst = "SELECT * FROM weby_timesheets WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' AND status in ('I', 'B')";
$getFirst = mysql_query($query_getFirst, $oprmConn) or die(mysql_error());
$row_getFirst = mysql_fetch_assoc($getFirst);
$totalRows_getFirst = mysql_num_rows($getFirst);
if($totalRows_getFirst > 0){
	mysql_select_db($database_oprmConn, $oprmConn);		
$query_Recordset1 = "UPDATE weby_timesheets SET project_id = '$pt', client_id = '$client', total_hrs = '$total_hrs', ip_address = '$ipaddress', status = '$status', updated_by = '$user_id', token = '$token' WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' and status in ('I', 'B')"; 
$Recordset1 = mysql_query($query_Recordset1, $oprmConn) or die(mysql_error());
} else if($totalRows_getFirst == 0){
mysql_select_db($database_oprmConn, $oprmConn);
$query_getEdit = "SELECT * FROM weby_timesheets WHERE task_week = '$week_number' AND task_year = '$year' AND created_date = '$dtt' AND project_id = '$pt' AND user_id = '$user_id' AND status in ('A', 'Q')";
$getEdit = mysql_query($query_getEdit, $oprmConn) or die(mysql_error());
$row_getEdit = mysql_fetch_assoc($getEdit);
$totalRows_getEdit = mysql_num_rows($getEdit);

if($totalRows_getEdit == 0){
	 mysql_select_db($database_oprmConn, $oprmConn);
$qu = "INSERT INTO weby_timesheets (user_id,project_id,client_id,total_hrs,task_week,task_year,ip_address,status,created_by,created_date,updated_by,token) VALUES ('$user_id','$pt','$client','$total_hrs','$week_number','$year','$ipaddress','$status','$user_id','$dtt','$user_id','$token')";				
$query_getProj = $qu;
$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());
}
}

/*mysql_select_db($database_oprmConn, $oprmConn);
$q = "select max(timesheet_id) as tid FROM weby_timesheets where user_id = '$_SESSION[user_id]'";
mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj12 = $q;
$getProj12 = mysql_query($query_getProj12, $oprmConn) or die(mysql_error());
$row_getTime12 = mysql_fetch_assoc($getProj12);
$totalRows_getProj12 = mysql_num_rows($getProj12);
$tid = $row_getTime12['tid'];*/
$tid = $row_getFirst['timesheet_id'];
mysql_select_db($database_oprmConn, $oprmConn);
$q = "SELECT weby_profiles.full_name,weby_timesheets.created_date, weby_timesheets.timesheet_id, weby_timesheets.project_id, weby_timesheets.total_hrs, weby_timesheets.hr_rate, weby_timesheets.total_amount, weby_timesheets.task_week, weby_timesheets.status, weby_projects.project_name, weby_users.email_address FROM weby_timesheets, weby_profiles, weby_projects , weby_users WHERE weby_timesheets.timesheet_id = '$tid ' and weby_timesheets.user_id = weby_profiles.user_id and weby_users.user_id = weby_profiles.user_id AND weby_profiles.user_id =weby_timesheets.user_id AND weby_projects.projetc_id = weby_timesheets.project_id";
mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj = $q;
$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());
$row_getTime = mysql_fetch_assoc($getProj);
$totalRows_getProj = mysql_num_rows($getProj);
mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj22 = "select email_address FROM weby_users where user_role = 1";
$getProj22 = mysql_query($query_getProj22, $oprmConn) or die(mysql_error());
$row_getProj22 = mysql_fetch_assoc($getProj22);
$totalRows_getProj22 = mysql_num_rows($getProj22);
 $s = "InActive";
	   if($row_getTime['status']=="A")
	   $s = "Approved";
	   if($row_getTime['status']=="P")
	   $s = "Pending";
	   if($row_getTime['status']=="D")
	$s = "Deleted";
	
require_once('timesheet-view-mail.php');

		$msg = "Timesheet Submited Successfully";
header("location: timesheet.php?&msg=".$msg."");
}
} else  if($project == 0){
$msg = "No Project Selected";
header("location: timesheet-edit.php?week=$week_number&year=$year&msgdg=".$msg."");
} else  if($client == ''){
$msg = "No Client Selected";
header("location: timesheet-edit.php?week=$week_number&year=$year&msgdg=".$msg."");
}
}

}

?>
<?php



if (!function_exists("GetSQLValueString")) {


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 


{


  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);


  switch ($theType) {

 case "text":


      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";


      break;    


    case "long":
  case "int":



      $theValue = ($theValue != "") ? intval($theValue) : "NULL";



      break;




    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";




      break;



    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;


    case "defined":



      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;


      break;





  }




  return $theValue;

}



}


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, weby_profiles.hr_rate FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id and weby_users.user_id = '$_SESSION[user_id]'";




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


$row_getRes = mysql_fetch_assoc($getRes);


$totalRows_getRes = mysql_num_rows($getRes);


mysql_select_db($database_oprmConn, $oprmConn);



$query_getProj = "SELECT * FROM weby_projects WHERE weby_projects.status = 'A' AND weby_projects.projetc_id in (select distinct project_id FROM weby_users_projects where status = 'A' and user_id = '$_SESSION[user_id]')";


$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());



$row_getProj = mysql_fetch_assoc($getProj);



$totalRows_getProj = mysql_num_rows($getProj);


mysql_select_db($database_oprmConn, $oprmConn);





$query_getTotalproj = "SELECT * FROM weby_users_projects WHERE user_id = '$_SESSION[user_id]' AND status = 'A'";





$getTotalproj = mysql_query($query_getTotalproj, $oprmConn) or die(mysql_error());















$row_getTotalproj = mysql_fetch_assoc($getTotalproj);















$totalRows_getTotalproj = mysql_num_rows($getTotalproj);

?>

<!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 - Tool Resource Time sheet</title>
<style>
.act_timesheet {
	background: #373938;
	color: #fff;
}
</style>
<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>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script src="../../js/jquery.flexslider.js"></script>
<script language="JavaScript">
window.gcount = <?php echo $totalRows_getWeek-1;?>;
jQuery(function($){
	var $repeater0 = $('#repeater0');
	var $project = $('#project');
	var $selectproj = $('#selectproj');
	var $selectclient = $('#selectclient');
	var $field_item = $('#field_item');
	var total_hrs1 = $('#total_hrs1');
	var total_hrs2 = $('#total_hrs2');
	var total_hrs3 = $('#total_hrs3');
	var total_hrs4 = $('#total_hrs4');
	var total_hrs5 = $('#total_hrs5');
	var total_hrs6 = $('#total_hrs6');
	var total_hrs7 = $('#total_hrs7');

	$('#addemail').click(function(e){
e.preventDefault();
		if(gcount != 0){
		//var cprojecto = 'cproject' + gcount;
		var field_itemido = 'field_item' + gcount;
		var projectido = 'project' + gcount;
		var clientido = 'client' + gcount;
		var total_hrs1o = 'total_hrs1' + gcount;
		var total_hrs2o = 'total_hrs2' + gcount;
		var total_hrs3o = 'total_hrs3' + gcount;
		var total_hrs4o = 'total_hrs4' + gcount;
		var total_hrs5o = 'total_hrs5' + gcount;
		var total_hrs6o = 'total_hrs6' + gcount;
		var total_hrs7o = 'total_hrs7' + gcount;
		var ro = 'repeater0' + gcount;
		var $repeatero = $('#'+ro);
		} else {
		var field_itemido = 'field_item';
		//var cprojecto = 'cproject';
		var projectido = 'project';
		var clientido = 'client';
		var total_hrs1o = 'total_hrs1';
		var total_hrs2o = 'total_hrs2';
		var total_hrs3o = 'total_hrs3';
		var total_hrs4o = 'total_hrs4';
		var total_hrs5o = 'total_hrs5';
		var total_hrs6o = 'total_hrs6';
		var total_hrs7o = 'total_hrs7';
		var ro = 'repeater0';
		var $repeatero = $('#'+ro);
		}

		var count = gcount + 1;
		gcount = count;
<?php $dr = $totalRows_getTotalproj-$totalRows_getWeek; ?>
if(count > <?php if($dr > 0){ echo $totalRows_getTotalproj-1; } else{ echo $dr;}?>){
	alert("That's enough already!");
	return;
	}
	var idname = 'repeater0' + count;
	var field_itemid = 'field_item' + count;
	var projectid = 'project' + count;
	var clientid = 'client' + count;
	var selectprojid = 'selectproj' + count;
	var total_hrs1id = 'total_hrs1' + count;
	var total_hrs2id = 'total_hrs2' + count;
	var total_hrs3id = 'total_hrs3' + count;
	var total_hrs4id = 'total_hrs4' + count;
	var total_hrs5id = 'total_hrs5' + count;
	var total_hrs6id = 'total_hrs6' + count;
	var total_hrs7id = 'total_hrs7' + count;
	try{
$repeater0.append($repeatero.clone().attr({id: idname}));
$repeater = $("body").find('#'+idname);
$repeater.find('#'+field_itemido).attr('name', field_itemid);
$repeater.find('#'+field_itemido).attr('id', field_itemid);
$repeater.find('#'+projectido).attr('name', projectid);
$repeater.find('#'+projectido).attr('id', projectid);
$repeater.find('#'+clientido).attr('name', clientid);
$repeater.find('#'+clientido).attr('id', clientid);
$repeater.find('#'+total_hrs1o).attr('name', total_hrs1id);
$repeater.find('#'+total_hrs1o).attr('id', total_hrs1id);
$repeater.find('#'+total_hrs2o).attr('name', total_hrs2id);
$repeater.find('#'+total_hrs2o).attr('id', total_hrs2id);
$repeater.find('#'+total_hrs3o).attr('name', total_hrs3id);
$repeater.find('#'+total_hrs3o).attr('id', total_hrs3id);
$repeater.find('#'+total_hrs4o).attr('name', total_hrs4id);
$repeater.find('#'+total_hrs4o).attr('id', total_hrs4id);
$repeater.find('#'+total_hrs5o).attr('name', total_hrs5id);
$repeater.find('#'+total_hrs5o).attr('id', total_hrs5id);
$repeater.find('#'+total_hrs6o).attr('name', total_hrs6id);
$repeater.find('#'+total_hrs6o).attr('id', total_hrs6id);
$repeater.find('#'+total_hrs7o).attr('name', total_hrs7id);
$repeater.find('#'+total_hrs7o).attr('id', total_hrs7id);
	}catch(err){alert(err);}
});
});
	jQuery(function($){
$('#removeButton').click(function(e){
e.preventDefault();
var count = gcount;
if(count == 0){
alert("Can not remove all projects!");
return;
} else {
	gcount = count - 1;
var idname = 'repeater0' + count;
	try{
		$('#'+idname).remove();
		}catch(err){alert(err);}
		}
	});
});

</script>
<script language="JavaScript">







function setVisibility(id, visibility) {







document.getElementById(id).style.display = visibility;







}







</script>
<script>







function validateForm() {



		document.getElementById('submit_timesheet').action='timesheet-edit.php?'+"count="+gcount;



var total1 = 0;

	var total2 = 0;

	var total3 = 0;

	var total4 = 0;

	var total5 = 0;

	var total6 = 0;

	var total7 = 0;

	

	<?php for($i=0;$i<=$totalRows_getTotalproj;$i++) { ?>

<?php if($i==0){ echo $i=''; } ?>

var totalhr1 = parseFloat(document.getElementById('total_hrs1<?php echo $i; ?>').value);

	

	 total1 = total1 + totalhr1;

	

	var totalhr2 = parseFloat(document.getElementById('total_hrs2<?php echo $i; ?>').value);



	total2 = total2 + totalhr2;



	var totalhr3 = parseFloat(document.getElementById('total_hrs3<?php echo $i; ?>').value);



	total3 = total3 + totalhr3;



	var totalhr4 = parseFloat(document.getElementById('total_hrs4<?php echo $i; ?>').value);



	total4 = total4 + totalhr4;



	var totalhr5 = parseFloat(document.getElementById('total_hrs5<?php echo $i; ?>').value);



	total5 = total5 + totalhr5;



	var totalhr6 = parseFloat(document.getElementById('total_hrs6<?php echo $i; ?>').value);



	total6 = total6 + totalhr6;



	var totalhr7 = parseFloat(document.getElementById('total_hrs7<?php echo $i; ?>').value);

	

	total7 = total7 + totalhr7;

	

	if (total1 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }



	if (total2 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }



	if (total3 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }



	if (total4 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }



	if (total5 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }

	

	if (total6 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }

	

	if (total7 > 24) {

        alert ("Effort totals per day should be less than 24hrs");

        return false;

    }	

	

<?php } ?>



	}















</script>
</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">
      <h1>Edit Time sheet</h1>
      <article class="resource_timesheet clear_fix">
        <form method="post" action="#" id="submit_timesheet" name="submit_timesheet" onsubmit="return validateForm()">
          <div class="field_item">
          <label>Week:</label>
          <?php	echo '<select name="week" id="week" onChange="redirect();">';

						//echo '<option value="0">Select Week</option> ';



						$i = 1;

						$pweek = date('W');

						$year = $_GET['year'];

						

						while($i<=52)

						{

							if($i<10){

							$year = $_GET['year'];



								//$padi = '0'.$i;

								$value = "value='0".$i."'";

							}

							else {

								$year = $_GET['year'];

								//$padi = $i;

								$value = "value='".$i."'";	

							}



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



								if($i<10){



									$gwk = $i;

									$gwk = sprintf("%02s", $i);



								}



								if($i>=10){

									$gwk = $i;

								}

								if($i == $_GET['week'])	{



									$year = $_GET['year'];

									//$year = $_GET['year'];



									$dwk = date('d M, Y', strtotime($year."W".$gwk.'7'));



									echo '<option '.$value.' selected="selected">'.'W/e '.$dwk.'</option>';



								}



							}



							$i++;



						}

$query_MAXHrs = "SELECT  weekly_hrs FROM weby_users WHERE  user_id = '$_SESSION[user_id]'";

$MAXHrs = mysql_query($query_MAXHrs, $oprmConn) or die(mysql_error());

$row_MAXHrs = mysql_fetch_assoc($MAXHrs);

$totalRows_MAXHrs = mysql_num_rows($MAXHrs);

                   echo '</select>



                </div>'; ?>
          <input type="hidden" name="year" id="year" value="<?php echo $_GET['year'];?>" />
          <input type="hidden" name="cnt" id="cnt" value="0" />
          <?php if(isset($_GET['week'])){ ?>
          <div class="total_hours">
            <label id="weekth" style="width:160px;">Week Hours: <?php
             mysql_select_db($database_oprmConn, $oprmConn);

$query_getHrs = "SELECT  SUM(`total_hrs`) FROM weby_timesheets WHERE task_year = '$_GET[year]' and task_week = '$_GET[week]' and user_id = '$_SESSION[user_id]' and status!='D'";

$getHrs = mysql_query($query_getHrs, $oprmConn) or die(mysql_error());

$row_getHrs = mysql_fetch_assoc($getHrs);

$totalRows_getHrs = mysql_num_rows($getHrs);



     echo $row_getHrs['SUM(`total_hrs`)']; 
     ?>
     </label>
            <label id="weekth" style="width:160px;"><b>
              <?php

				
     echo 'MAX Hrs Allowed: ' .$row_MAXHrs['weekly_hrs']; ?>
              </b></label>
          </div>
          <div class="clear-fix">&nbsp;</div>
          <?php $n = 0;

		 do { 

				mysql_select_db($database_oprmConn, $oprmConn);

$query_getPdtls = "SELECT  * FROM weby_timesheets WHERE project_id = '$row_getWeek[project_id]' and user_id = '$_SESSION[user_id]'";



$getPdtls = mysql_query($query_getPdtls, $oprmConn) or die(mysql_error());

$row_getPdtls = mysql_fetch_assoc($getPdtls);

$totalRows_getPdtls = mysql_num_rows($getPdtls);



 if($n != 0){$n = $n;} 



 else if($n == 0){$n = '';} 

		?>
          <div>
<div id="repeater0<?php echo $n; ?>">
<div class="field_item" id="field_item">
<input type="hidden" name="asgprj" id="asgprj" value="<?php echo $totalRows_getTotalproj;?>" />
<label id="selectproj">Project Name:</label>
<select name="project<?php echo $n; ?>" id="project<?php echo $n; ?>">
<?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getprjname = "SELECT  * FROM weby_projects WHERE projetc_id = '$row_getWeek[project_id]'";
$getprjname = mysql_query($query_getprjname, $oprmConn) or die(mysql_error());
$row_getprjname = mysql_fetch_assoc($getprjname);
$totalRows_getprjname = mysql_num_rows($getprjname); ?>
<option value="0">Select Project</option>
<?php do{ ?>
<option value="<?php echo $row_getProj['projetc_id']; ?>" <?php if($row_getProj['projetc_id'] == $row_getprjname['projetc_id']){ ?> selected="selected" <?php } ?> > <?php echo $row_getProj['project_name']; ?></option>
<?php } while ($row_getProj = mysql_fetch_assoc($getProj));
$rows = mysql_num_rows($getProj);
if($rows > 0) {
mysql_data_seek($getProj, 0);
$row_getProj = mysql_fetch_assoc($getProj);  }?>
</select>
</div>

<label id="weekproth" style="width:140px;">Project Total Hours: 
<?php mysql_select_db($database_oprmConn, $oprmConn);
$query_getHrs = "SELECT  SUM(`total_hrs`) FROM weby_timesheets WHERE task_year = '$_GET[year]' and task_week = '$_GET[week]' and user_id = '$_SESSION[user_id]' and project_id = '$row_getWeek[project_id]' and status!='D'";
$getHrs = mysql_query($query_getHrs, $oprmConn) or die(mysql_error());
$row_getHrs = mysql_fetch_assoc($getHrs);
$totalRows_getHrs = mysql_num_rows($getHrs);
echo $row_getHrs['SUM(`total_hrs`)']; ?></b></label>

<div class="field_item" id="field_item" style="display:none;">
<label id="selectclient">Select Client:</label>
<select name="client1" id="client1">
<option value="0">Select Client</option>  
<?php //get client id
mysql_select_db($database_oprmConn, $oprmConn);
$query_getcid = "SELECT  * FROM weby_timesheets WHERE project_id = '$row_getWeek[project_id]' and task_week = '$_GET[week]' and task_year = '$_GET[year]' and user_id = '$_SESSION[user_id]' and status in ('I', 'B') ORDER BY created_date ASC";
$getcid = mysql_query($query_getcid, $oprmConn) or die(mysql_error());
$row_getcid = mysql_fetch_assoc($getcid);
$totalRows_getcid = mysql_num_rows($getcid);
mysql_select_db($database_oprmConn, $oprmConn);
$query_getclients = "SELECT * FROM weby_clients WHERE status = 'A'";
$getclients = mysql_query($query_getclients, $oprmConn) or die(mysql_error());
$row_getclients = mysql_fetch_assoc($getclients);
$totalRows_getclients = mysql_num_rows($getclients);
if($totalRows_getclients>0){ do{ ?> 
<option value="<?php echo $row_getclients['client_id']; ?>" <?php if($row_getclients['client_id']==$row_getcid['client_id']){ ?> selected <?php } ?>> <?php echo $row_getclients['client_name']; ?></option>
<?php } while ($row_getclients = mysql_fetch_assoc($getclients)); } ?></select>
</div>
</label>
<input type="hidden" value="0" name="client" id="client">
              <div class="field_item">
                <div class="timesheet_tablet">
                  <div class="column_titlet">
                    <?php $week_number = $_GET['week'];



						$year = $_GET['year'];



						for($day=1; $day<=7; $day++)

						{



							$dwk = date('d-m-Y', strtotime($year."W".$week_number.$day));





							$dayn = date('D',strtotime($year."W".$week_number.$day)); ?>
                    <span class="item_smalltt" style="width:79px; font-size:12px;"><?php echo $dayn; ?></span>
                    <?php } ?>
                  </div>
                  <?php $week_number = $_GET['week'];















						$year = $_GET['year'];















						for($day=1; $day<=7; $day++)















						{















							$dwk = date('d-m-Y', strtotime($year."W".$week_number.$day));















							$dayn = date('D',strtotime($year."W".$week_number.$day));







?>
                  <span class="item_smallt" style="width:79px; font-size:12px;" name="datewk<?php echo $day;?>" id="datewk<?php echo $day;?>"><?php echo $dwk; ?><br />9:00AM-5:00PM</span>
                  <?php } ?>
                </div>
                <div class="timesheet_tablet">
                  <?php 







	mysql_select_db($database_oprmConn, $oprmConn);
$query_getHors = "SELECT  * FROM weby_timesheets WHERE project_id = '$row_getWeek[project_id]' and task_week = '$_GET[week]' and task_year = '$_GET[year]' and user_id = '$_SESSION[user_id]' and status in ('I', 'B') ORDER BY created_date ASC";
$getHors = mysql_query($query_getHors, $oprmConn) or die(mysql_error());
$row_getHors = mysql_fetch_assoc($getHors);
$totalRows_getHors = mysql_num_rows($getHors);
$day = 1;
do{ ?>
<span class="item_smallt" style="width:79px; font-size:12px;" >
<input type="text" name="total_hrs<?php echo $day.$n; ?>" id="total_hrs<?php echo $day.$n; ?>" maxlength="4" size="4" value="<?php echo $row_getHors['total_hrs'];?>" />
<input type="hidden" name="id<?php echo $day.$n; ?>" id="id<?php echo $day.$n; ?>" value="<?php echo $row_getHors['timesheet_id'];?>" />
</span>
<?php $day = $day + 1;







		  } while ($row_getHors = mysql_fetch_assoc($getHors)); ?>
                </div>
              </div>
              <div class="clear-fix">&nbsp;</div>
              
              <!-- <input type="reset" value="Add" class="reset_btn" onclick="javascript:addItem('repeater0');" >--> 
              
            </div>
            <div class="clear-fix">&nbsp;</div>
          </div>
          <?php $n = $n + 1; } while ($row_getWeek = mysql_fetch_assoc($getWeek)); ?>
          <?php if($totalRows_getTotalproj > $totalRows_getWeek){ ?>
          <input type="button" style="margin-left:120px;"id="addemail" class="add" value="Add" />
          <input type="button" class="remove" value="Remove" name="removeButton" id="removeButton"  />
          <?php }?>
          <div class="clear-fix">&nbsp;</div>
          <div class="submt">
            <div class="action_items">
              <input name="save" id="save" type="submit" class="save_btn" onclick="MM_validateForm('datewk','','R','total_hrs','','R','task_details','','R');return document.MM_returnValue" value="Save as Draft">
              <?php // echo $no = date('W').' & '.$_GET['week'];

  if(($_GET['year'] < date('Y'))){ ?>
              <input type="submit" name="submit" id="submit"  onclick="MM_validateForm('datewk','','R','total_hrs','','R','task_details','','R');return document.MM_returnValue" value="Submit to Admin" class="reset_btn">
              <?php } ?>
              <?php // echo $no = date('W').' & '.$_GET['week'];

  if(($_GET['year'] == date('Y')) && ($_GET['week'] < date('W'))){ ?>
              <input type="submit" name="submit" id="submit"  onclick="MM_validateForm('datewk','','R','total_hrs','','R','task_details','','R');return document.MM_returnValue" value="Submit to Admin" class="reset_btn">
              <?php } ?>
              <input type="reset" value="Cancel" class="reset_btn" onClick="window.location='timesheet.php';">
            </div>
          </div>
          <?php } ?>
        </form>
        <div class="clear-fix">&nbsp;</div>
      </article>
    </section>
    
    <!-- Sidebar Goes here -->
    
    <aside class="sidebar">
      <div class="featured clear_fix">
        <h2 class="white_txt">My Profile</h2>
        <div class="profile_box"> <a href="resources-view.php?resourceid=<?php echo $row_getRes['user_id']; ?>"><img src="/RM/images/<?php if(!empty($row_getRes['profile_pic'])) echo $row_getRes['profile_pic']; else echo "black-img.jpg"; ?>" width="68" /></a>
          <p class="profile_title"><a href="resources-view.php?resourceid=<?php echo $row_getRes['user_id']; ?>"><?php echo $row_getRes['full_name']; ?></a><span class="desig"><br />
            <?php echo $row_getRes['job_title']; ?></span></p>
          <p class="profile_desc"><?php echo $row_getRes['skill_set']; ?></p>
          <div class="clear-fix">&nbsp;</div>
        </div>
      </div>
      
      <!--<h3>Recent Activity</h3>-->
      
      <?php #include("recent-ac.php"); ?>
    </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($getRes);







mysql_free_result($getProj);







//mysql_free_result($getTimSh);



?>
