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

if(!isset($_SESSION['user_id'])){
	header("location: ../index.php");
}



if($_SESSION['role_id']!=2) {



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'])){
//get ipaddress
mysql_select_db($database_oprmConn, $oprmConn);
$query_getipaddr = "SELECT  * FROM weby_timesheets WHERE task_week = '$_GET[week]' and task_year = '$_GET[year]' and user_id = '$_GET[uid]' and status in ('A', 'Q') ORDER BY created_date ASC";
$getipaddr = mysql_query($query_getipaddr, $oprmConn) or die(mysql_error());
$row_getipaddr = mysql_fetch_assoc($getipaddr);
$totalRows_getipaddr = mysql_num_rows($getipaddr);


	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 ('A', 'Q')";



$getWeek = mysql_query($query_getWeek, $oprmConn) or die(mysql_error());



$row_getWeek = mysql_fetch_assoc($getWeek);



$totalRows_getWeek = mysql_num_rows($getWeek);



}







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">



/*//function addItem(div)



//{



//for(var i = 0; i < 3; i++) {



//var ediv=document.getElementById(div);



//var temp=ediv.innerHTML;



//var newdiv = document.createElement('div');



//var divIdName=div+i;//i hav taken 1 for sample for adding id to the div



//newdiv.setAttribute('id',divIdName);



//newdiv.innerHTML =temp;



//ediv.appendChild(newdiv);



//}



//cnt}*/



window.gcount = <?php echo $totalRows_getWeek-1;?>;



jQuery(function($){



	var $repeater0 = $('#repeater0');



	var $project = $('#project');



	var $selectproj = $('#selectproj');



	var $field_item = $('#field_item');



	/* var $cproject = $('#cproject');*/



	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 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 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 pidname = 'project' + (++count);*/



var field_itemid = 'field_item' + count;



/*var cprojectid = 'cproject' + count;*/



var projectid = 'project' + 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;



/*alert(count);



//$repeater0.html( parseInt($repeater0.html()) + 1 )



//$repeater0.parent().append($repeater0.clone().attr({id: idname}));*/



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('#'+cprojecto).attr('checked', 'checked');



//$repeater.find('#'+cprojecto).attr('name', cprojectid);



//$repeater.find('#'+cprojecto).attr('id', cprojectid);*/



$repeater.find('#'+projectido).attr('name', projectid);



$repeater.find('#'+projectido).attr('id', projectid);



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







/*$('#repeater0').html(function(count, id) { return +id+1 });*/



	});



	



});



	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;



/*var pidname = 'project' + (++count);



//alert(count);



//$repeater0.html( parseInt($repeater0.html()) + 1 )



//$repeater0.parent().append($repeater0.clone().attr({id: idname}));*/



try{



$('#'+idname).remove();



}catch(err){alert(err);}



}



/*$('#repeater0').html(function(count, id) { return +id+1 });*/



	});



	



});



	



</script>



<script language="JavaScript">



function setVisibility(id, visibility) {



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



}



</script>



<!--<script>



$(function() {



$( "#date" ).datepicker();



  });



function MM_validateForm() { //v4.0



  if (document.getElementById){



var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;



for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);



  if (val) { nm=val.name; if ((val=val.value)!="") {



if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');



  if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';



} else if (test!='R') { num = parseFloat(val);



  if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';



  if (test.indexOf('inRange') != -1) { p=test.indexOf(':');



    min=test.substring(8,p); max=test.substring(p+1);



    if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';



  } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }



} if (errors) alert('The following error(s) occurred:\n'+errors);



document.MM_returnValue = (errors == '');



} }



function calBill(){



document.getElementById("total_cost").value = document.getElementById("total_hrs").value * <?php echo $row_getRes['hr_rate']; ?>;



}



</script>-->







<script>



function validateForm() {



  



	var totalhr1 = document.getElementById('total_hrs1').value;



	if (totalhr1 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr2 = document.getElementById('total_hrs2').value;



	if (totalhr2 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr3 = document.getElementById('total_hrs3').value;



	if (totalhr3 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr4 = document.getElementById('total_hrs4').value;



	if (totalhr4 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr5 = document.getElementById('total_hrs5').value;



	if (totalhr5 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr6 = document.getElementById('total_hrs6').value;



	if (totalhr6 == "") {



alert ("Total Hours out");



return false;



}



	var totalhr7 = document.getElementById('total_hrs7').value;



	if (totalhr7 == "") {



alert ("Total Hours out");



return false;



}



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



	}



</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>Timesheet View</h1>    



      <article class="resource_timesheet clear_fix">



        <form method="post" action="#" id="submit_timesheet" name="submit_timesheet" onsubmit="return validateForm()">





		<?php if(isset($_GET['week'])){?>  

        

        <div class="field_item" id="field_item">



            <label id="weekno">Week Number:</label>

			 <label id="weekno"><b><?php echo $_GET['week']; ?></b></label>

             

              <label id="weekth" style="width:140px;">Week Total Hours:</label>

			 <label id="weekth" style="width:40px;"><b><?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 in ('A', 'Q')";

$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>

     <label id="weekth">Status: <?php mysql_select_db($database_oprmConn, $oprmConn);

$query_getstous = "SELECT  * FROM weby_timesheets WHERE task_year = '$_GET[year]' and task_week = '$_GET[week]' and user_id = '$_SESSION[user_id]' and status in ('A', 'Q')";

$getstous = mysql_query($query_getstous, $oprmConn) or die(mysql_error());

$row_getstous = mysql_fetch_assoc($getstous);

$totalRows_getstous = mysql_num_rows($getstous);?><b><?php if($row_getstous['status'] == 'A'){ echo 'Pending'; }?><?php if($row_getstous['status'] == 'Q'){ echo 'Approved'; }?> </b></label></div>

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

                    



                <?php 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]' and status in ('A', 'Q')";

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

$row_getPdtls = mysql_fetch_assoc($getPdtls);

$totalRows_getPdtls = mysql_num_rows($getPdtls); ?>

     

                 <div id="repeater0">



<div class="field_item" id="field_item">
<label id="selectproj">Store Name:</label>
<label id="selectproj"><b> <?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);
echo $row_getprjname['project_name']; ?></b> <br /></label>	
<label id="weekproth" style="width:140px;"> Total Hours:</label>
<label id="weekproth" style="width:40px;"><b><?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>

<div class="field_item" id="field_item">
<label id="selectproj">Client Name:</label>
<label id="selectproj"><b>
<?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 ('A', 'Q') 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' AND client_id = '$row_getcid[client_id]'";
$getclients = mysql_query($query_getclients, $oprmConn) or die(mysql_error());
$row_getclients = mysql_fetch_assoc($getclients);
$totalRows_getclients = mysql_num_rows($getclients);
echo $row_getclients['client_name']; ?></b> <br /></label>	
</div>
       

			<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; ?></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 ('A', 'Q') 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);



			do{ ?>



<span class="item_smallt" style="width:79px; font-size:12px;" ><input type="text" name="total_hrs<?php echo $day;?>" id="total_hrs<?php echo $day;?>" maxlength="4" size="4" value="<?php echo $row_getHors['total_hrs'];?>" readonly="readonly" /></span>







			 



                                  <?php } while ($row_getHors = mysql_fetch_assoc($getHors)); ?>







							 







			  </div>







			</div>



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







			</div>



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







			



                   <!-- <input type="reset" value="Add" class="reset_btn" onclick="javascript:addItem('repeater0');" >-->



                    



                   <?php } while ($row_getWeek = mysql_fetch_assoc($getWeek)); ?>



                



		<input type="reset" value="Back" class="reset_btn" onClick="window.location='timesheet.php';">







						 







		



		



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



		







		<?php } ?>



                



        </form>



            </article>



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



        



    </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="index.php?resourceid=<?php echo $_SESSION[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);*/



?>



