<?php require_once('../Connections/oprmConn.php'); ?>
<?php include('check-admin-session.php'); ?>
<?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;
}
}

$maxRows_getTimeSheet = 2;
$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 distinct 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_profiles.profile_pic, weby_profiles.job_title, weby_profiles.skill_set FROM weby_timesheets, weby_profiles, weby_projects, weby_users_projects WHERE weby_timesheets.user_id = weby_profiles.user_id  AND weby_projects.projetc_id = weby_timesheets.project_id and weby_profiles.user_id = weby_users_projects.user_id and weby_users_projects.project_id = weby_projects.projetc_id AND weby_timesheets.status ='Q' GROUP BY weby_timesheets.task_week,weby_timesheets.task_year 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;
$key1 = explode(',',$_REQUEST['key']);
$skey = "";
foreach ($key1 as $key => $value) {
$skey .= "weby_profiles.skill_set like '%".$value."%' or ";
$skey .= "weby_profiles.full_name like '%".$value."%' or ";
}
//$skey .= "weby_profiles.skill_set like '%something else%'";
$skey .= "weby_profiles.full_name like '%something else%'";
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, weby_users.status, weby_profiles.hr_rate FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id AND weby_users.status in ('A','P') AND weby_profiles.status = 'A' and ($skey)";
//exit();
$getRes1 = mysql_query($query_getRes1, $oprmConn) or die(mysql_error());
$row_getRes1 = mysql_fetch_assoc($getRes1);
$totalRows_getRes1 = mysql_num_rows($getRes1);

mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj = "SELECT * FROM weby_projects WHERE weby_projects.status = 'A'";
$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());
$row_getProj = mysql_fetch_assoc($getProj);
$totalRows_getProj = mysql_num_rows($getProj);
?><!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-Admin Resource List</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]-->
    <style>
.act_resource { background: #373938;
  color: #fff;}
</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">
    <h1>Resources Search</h1>
    <!--<div class="welcome_box">
      <div class="timesheet_type">
        <div class="welcome_txt arrow">Welcome Admin
          <ul>
              <li><a href="index.php">Dashboard</a></li>
            <li><a href="project-list.php">Projects</a></li>
            <li><a href="resources-list.php">Resources</a></li>
            <li><a href="profile.php">Profile</a></li>
            <li><a href="logout.php">Logout</a></li>
          </ul>
        </div>
      </div>
    </div>-->
    <p class="search">Your Search Result for '<strong><?php echo $_REQUEST['key']; ?></strong>'</p>
    <!-- search Goes here -->
    <!--<div class="view_by">
      <select class="view_select">
        <option>ALL</option>
        <option>ALL</option>
      </select>
      <h4>View by</h4>
    </div>-->
    
    <div class="search_box">
      <form action="resources-list.php" method="post" id="search">
        <input name="search" type="text" size="30" />
        <input name="submit" type="submit" value="Search" />
      </form>
    </div>
    <div class="clear-fix">&nbsp;</div>
    <article class="resource_list clear_fix"><?php  $odd=1; ?>
    <?php if($totalRows_getRes1>0) { do { ?>
    <div class="resource_item <?php  if($odd==1){ echo "odd"; $odd=0; } else{ $odd=1; } ?> <?php if($row_getRes1['status']=="A") echo "active"; ?>">
      <div class="img_wrap"><img src="/RM/images/<?php if(!empty($row_getRes1['profile_pic'])) echo $row_getRes1['profile_pic']; else echo "black-img.jpg";?>" width="68"></div>
      <p class="resource_title"><?php echo $row_getRes1['full_name']; ?><span class="desig"><br>
          <?php echo $row_getRes1['job_title']; ?></span></p>
      <p class="resource_desc"><?php echo $row_getRes1['skill_set']; ?></p>
      <div class="resource_details"> <span class="reource_label">Current Project: </span>
          <p style="font-size:13px;">
            <?php 
					  mysql_select_db($database_oprmConn, $oprmConn);
$query_getProf = "SELECT b.project_name FROM weby_users_projects a, weby_projects b WHERE a.user_id = '$row_getRes1[user_id]' AND a.project_id = b.projetc_id and a.status = 'A' AND a.project_id NOT IN ('10', '11')";
$getProf = mysql_query($query_getProf, $oprmConn) or die(mysql_error());
$row_getProf = mysql_fetch_assoc($getProf);
$totalRows_getProf = mysql_num_rows($getProf);
if($totalRows_getProf>0) {
 ?>
            <?php do { ?>
              <?php echo $row_getProf['project_name']; ?><br />

              <?php } while ($row_getProf = mysql_fetch_assoc($getProf)); ?>
           
            <?php } else { echo " <strong>No Project Assigned</strong>"; } ?>
          </p>
      </div>
     <!-- <div class="resource_details"> <span class="reource_label">Rate: </span>
          <h4>&pound; <?php echo $row_getRes1['hr_rate']; ?></h4>
      </div>-->
     <div class="edit_links"> <a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?>" class="view"></a> <a href="resources-view.php?user_id=<?php echo $row_getRes1['user_id']; ?>" class="edit"></a> </div></div>
    <?php } while ($row_getRes1 = mysql_fetch_assoc($getRes1)); } else echo "No records found"; ?>
    </article>
    </section>
    <!-- Sidebar Goes here -->
    <aside class="sidebar">
      <?php include("timesheet.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($getRes1);

mysql_free_result($getProf);
?>