<?php

/***************************************************************************
 *   copyright            : (C) 2010 PCRepairTracker.com
 *   email                : info@pcrepairtracker.com
 *   This program is a copyrighted work.
 *   Please see the license.txt file for details
 *
 ***************************************************************************/

if (array_key_exists('func',$_REQUEST)) {
$func = $_REQUEST['func'];
} else {
$func = "";
}


function dailystatus() {
require_once("validate.php");

require("deps.php");

require_once("common.php");

require_once("header.php");

if (function_exists('date_default_timezone_set')) {
date_default_timezone_set("$pcrt_timezone");
}


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

if(!isset($pcrt_workweekstart)) {
$pcrt_weekstart = "Sunday";
}

if ($pcrt_workweekstart == "Sunday") {

if(date("w") == 0) {
$thedate2 = date("Y-m-d");
} else {
$thedate2 = date("Y-m-d",strtotime("last Sunday"));
}

} else {

if(date("N") == 1) {
$thedate2 = date("Y-m-d");
} else {
$thedate2 = date("Y-m-d",strtotime("last Monday"));
}

}



if(perm_check("2")) {

start_blue_box(pcrtlang("Time Reports"));



echo "<form action=reports.php?func=timereport method=post><br><font class=text16bu>".pcrtlang("This Week")."&nbsp;</font><br><br>";
echo "<table><tr><td><font class=text12b>".pcrtlang("Location").":</font></td><td><select name=location>";
$rs_fl = "SELECT * FROM locations";
$rs_resultfl = mysqli_query($rs_connect, $rs_fl);
while ($rs_result_fl1 = mysqli_fetch_object($rs_resultfl)) {
$locname = "$rs_result_fl1->locname";
$locid = "$rs_result_fl1->locid";
if(in_array("$locid", $locpermsthisuser)) {
if ($locid == $defloc) {
echo "<option selected value=$locid>$locname</option>";
} else {
echo "<option value=$locid>$locname</option>";
}
}

}
echo "</select></td><td></td></tr>";

###

echo "<tr><td><font class=text12b>".pcrtlang("Employee").":</font></td><td><select name=employee>";
echo "<option selected value=all style=\"font-weight:bold;\">".pcrtlang("All Active Employees")."</option>";
$rs_fe = "SELECT * FROM employees WHERE isactive = '1' AND location = '$defloc' ORDER BY employeename ASC";
$rs_resultfe = mysqli_query($rs_connect, $rs_fe);
while ($rs_result_fee = mysqli_fetch_object($rs_resultfe)) {
$ename2 = "$rs_result_fee->employeename";
$ecn2 = "$rs_result_fee->clocknumber";
$locationid2 = "$rs_result_fee->location";
$deptid2 = "$rs_result_fee->deptid";

if(in_array("$locationid2", $locpermsthisuser)) {
if(in_array("$deptid2", $deptpermsthisuser)) {
echo "<option value=$ecn2>$ename2</option>";
}
}
}
echo "</select></td><td></td></tr>";


###

echo "<tr><td><font class=text12b>".pcrtlang("Department").":</font></td><td><select name=department>";
echo "<option selected value=0>".pcrtlang("All Departments")."</option>";
$rs_fd = "SELECT * FROM departments ORDER BY deptcode";
$rs_resultfd = mysqli_query($rs_connect, $rs_fd);
while ($rs_result_fdd = mysqli_fetch_object($rs_resultfd)) {
$deptname = "$rs_result_fdd->deptname";
$deptid = "$rs_result_fdd->deptid";
$deptcode = "$rs_result_fdd->deptcode";
if(in_array("$deptid", $deptpermsthisuser)) {
echo "<option value=$deptid>$deptcode - $deptname</option>";
}
}
echo "</select></td></tr>";


###

echo "<tr><td><font class=text12b>".pcrtlang("Detailed")."?:</font></td><td><input type=checkbox name=detailed value=\"yes\"></td><td>";

echo "<tr><td><font class=text12b>".pcrtlang("Enter From Date").":</font></td><td><input id=dayfrom type=text class=textbox name=dayfrom value=\"$thedate2\"></td><td></td></tr>";
echo "<tr><td><font class=text12b>".pcrtlang("Enter To Date").":</font></td><td><input id=dayto type=text class=textbox name=dayto value=\"$thedate\"></td><td>";
echo "<input type=hidden name=active value=\"1\"><input class=button type=submit value=\"".pcrtlang("Show Report")."\"></form></td></tr></table>";
echo "<br>";

if(!isset($pcrt_weekstart)) {
$pcrt_weekstart = "Sunday";
}
if ($pcrt_weekstart == "Sunday") {
echo "<script type=\"text/javascript\" src=\"jq/datepickr.js\"></script>";
} else {
echo "<script type=\"text/javascript\" src=\"jq/datepickr2.js\"></script>";
}



?>

<script type="text/javascript">
new datepickr('dayfrom', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayfrom").value });
</script>

<?php

if(!isset($pcrt_weekstart)) {
$pcrt_weekstart = "Sunday";
}
if ($pcrt_weekstart == "Sunday") {
echo "<script type=\"text/javascript\" src=\"jq/datepickr.js\"></script>";
} else {
echo "<script type=\"text/javascript\" src=\"jq/datepickr2.js\"></script>";
}




?>

<script type="text/javascript">
new datepickr('dayto', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayto").value });
</script>
<?php


if ($pcrt_workweekstart == "Sunday") {
$lthedate = date("Y-m-d",strtotime("last Saturday"));
$lthedate2 = date("Y-m-d",strtotime("last Saturday") - 518400);
} else {
$lthedate = date("Y-m-d",strtotime("last Sunday"));
$lthedate2 = date("Y-m-d",strtotime("last Sunday") - 518400);
}


echo "<form action=reports.php?func=timereport method=post><font class=text16bu>".pcrtlang("Last Week")."&nbsp;</font><br><br>";
echo "<table><tr><td><font class=text12b>".pcrtlang("Location").":</font></td><td><select name=location>";
$lrs_fl = "SELECT * FROM locations";
$lrs_resultfl = mysqli_query($rs_connect, $lrs_fl);
while ($lrs_result_fl1 = mysqli_fetch_object($lrs_resultfl)) {
$llocname = "$lrs_result_fl1->locname";
$llocid = "$lrs_result_fl1->locid";

if(in_array("$llocid", $locpermsthisuser)) {
if ($llocid == $defloc) {
echo "<option selected value=$llocid>$llocname</option>";
} else {
echo "<option value=$llocid>$llocname</option>";
}
}
}
echo "</select></td><td></td></tr>";




echo "<tr><td><font class=text12b>".pcrtlang("Employee").":</font></td><td><select name=employee>";
echo "<option selected value=all style=\"font-weight:bold;\">".pcrtlang("All Active Employees")."</option>";
$rs_fe = "SELECT * FROM employees WHERE isactive = '1' AND location = '$defloc' ORDER BY employeename ASC";
$rs_resultfe = mysqli_query($rs_connect, $rs_fe);
while ($rs_result_fee = mysqli_fetch_object($rs_resultfe)) {
$ename2 = "$rs_result_fee->employeename";
$ecn2 = "$rs_result_fee->clocknumber";
$locationid2 = "$rs_result_fee->location";
$deptid2 = "$rs_result_fee->deptid";

if(in_array("$locationid2", $locpermsthisuser)) {
if(in_array("$deptid2", $deptpermsthisuser)) {
echo "<option value=$ecn2>$ename2</option>";
}
}
}
echo "</select></td><td></td></tr>";

###

echo "<tr><td><font class=text12b>".pcrtlang("Department").":</font></td><td><select name=department>";
echo "<option selected value=0>".pcrtlang("All Departments")."</option>";
$rs_fd = "SELECT * FROM departments ORDER BY deptcode";
$rs_resultfd = mysqli_query($rs_connect, $rs_fd);
while ($rs_result_fdd = mysqli_fetch_object($rs_resultfd)) {
$deptname = "$rs_result_fdd->deptname";
$deptid = "$rs_result_fdd->deptid";
$deptcode = "$rs_result_fdd->deptcode";
if(in_array("$deptid", $deptpermsthisuser)) {
echo "<option value=$deptid>$deptcode - $deptname</option>";
}
}
echo "</select></td></tr>";


###



echo "<tr><td><font class=text12b>".pcrtlang("Detailed")."?:</font></td><td><input type=checkbox name=detailed value=\"yes\"></td><td>";

echo "<tr><td><font class=text12b>".pcrtlang("Enter From Date").":</font></td><td><input id=dayfrom2 type=text class=textbox name=dayfrom value=\"$lthedate2\"></td><td></td></tr>";
echo "<tr><td><font class=text12b>".pcrtlang("Enter To Date").":</font></td><td><input id=dayto2 type=text class=textbox name=dayto value=\"$lthedate\"></td><td>";

echo "<input type=hidden name=active value=\"1\"><input class=button type=submit value=\"".pcrtlang("Show Report")."\"></form></td></tr></table>";

if(!isset($pcrt_weekstart)) {
$pcrt_weekstart = "Sunday";
}
if ($pcrt_weekstart == "Sunday") {
echo "<script type=\"text/javascript\" src=\"jq/datepickr.js\"></script>";
} else {
echo "<script type=\"text/javascript\" src=\"jq/datepickr2.js\"></script>";
}



?>


<script type="text/javascript">
new datepickr('dayfrom2', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayfrom2").value });
</script>

<?php

if(!isset($pcrt_weekstart)) {
$pcrt_weekstart = "Sunday";
}
if ($pcrt_weekstart == "Sunday") {
echo "<script type=\"text/javascript\" src=\"jq/datepickr.js\"></script>";
} else {
echo "<script type=\"text/javascript\" src=\"jq/datepickr2.js\"></script>";
}

?>


<script type="text/javascript">
new datepickr('dayto2', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayto2").value });
</script>
<?php



echo "<br>";
######################
if(perm_check("4")) {


echo "<form action=reports.php?func=timereport method=post><br><font class=text16bu>".pcrtlang("Inactive Employees")."&nbsp;</font><br><br>";
echo "<table><tr><td><font class=text12b>".pcrtlang("Location").":</font></td><td><select name=location>";
$rs_fl = "SELECT * FROM locations";
$rs_resultfl = mysqli_query($rs_connect, $rs_fl);
while ($rs_result_fl1 = mysqli_fetch_object($rs_resultfl)) {
$locname = "$rs_result_fl1->locname";
$locid = "$rs_result_fl1->locid";
if(in_array("$locid", $locpermsthisuser)) {
if ($locid == $defloc) {
echo "<option selected value=$locid>$locname</option>";
} else {
echo "<option value=$locid>$locname</option>";
}
}

}
echo "</select></td><td></td></tr>";

###

echo "<tr><td><font class=text12b>".pcrtlang("Employee").":</font></td><td><select name=employee>";
echo "<option selected value=all style=\"font-weight:bold;\">".pcrtlang("All Inactive Employees")."</option>";
$rs_fe = "SELECT * FROM employees WHERE isactive = '0' AND location = '$defloc' ORDER BY employeename ASC";
$rs_resultfe = mysqli_query($rs_connect, $rs_fe);
while ($rs_result_fee = mysqli_fetch_object($rs_resultfe)) {
$ename2 = "$rs_result_fee->employeename";
$ecn2 = "$rs_result_fee->clocknumber";
$locationid2 = "$rs_result_fee->location";
$deptid2 = "$rs_result_fee->deptid";

if(in_array("$locationid2", $locpermsthisuser)) {
if(in_array("$deptid2", $deptpermsthisuser)) {
echo "<option value=$ecn2>$ename2</option>";
}
}
}
echo "</select></td><td></td></tr>";


###

echo "<tr><td><font class=text12b>".pcrtlang("Department").":</font></td><td><select name=department>";
echo "<option selected value=0>".pcrtlang("All Departments")."</option>";
$rs_fd = "SELECT * FROM departments ORDER BY deptcode";
$rs_resultfd = mysqli_query($rs_connect, $rs_fd);
while ($rs_result_fdd = mysqli_fetch_object($rs_resultfd)) {
$deptname = "$rs_result_fdd->deptname";
$deptid = "$rs_result_fdd->deptid";
$deptcode = "$rs_result_fdd->deptcode";
if(in_array("$deptid", $deptpermsthisuser)) {
echo "<option value=$deptid>$deptcode - $deptname</option>";
}
}
echo "</select></td></tr>";


###

echo "<tr><td><font class=text12b>".pcrtlang("Detailed")."?:</font></td><td><input type=checkbox name=detailed value=\"yes\"></td><td>";

echo "<tr><td><font class=text12b>".pcrtlang("Enter From Date").":</font></td><td><input id=dayfrom3 type=text class=textbox name=dayfrom value=\"$thedate2\"></td><td></td></tr>";
echo "<tr><td><font class=text12b>".pcrtlang("Enter To Date").":</font></td><td><input id=dayto3 type=text class=textbox name=dayto value=\"$thedate\"></td><td>";
echo "<input type=hidden name=active value=\"0\"><input class=button type=submit value=\"Show Report\"></form></td></tr></table>";


if(!isset($pcrt_weekstart)) {
$pcrt_weekstart = "Sunday";
}
if ($pcrt_weekstart == "Sunday") {
echo "<script type=\"text/javascript\" src=\"jq/datepickr.js\"></script>";
} else {
echo "<script type=\"text/javascript\" src=\"jq/datepickr2.js\"></script>";
}




?>



<script type="text/javascript">
new datepickr('dayfrom3', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayfrom3").value });
</script>


<script type="text/javascript">
new datepickr('dayto3', { dateFormat: 'Y-m-d', theCurrentDate: document.getElementById("dayto3").value });
</script>
<?php


echo "<br>";



}
####################






echo "<form action=reports.php?func=clocklist method=post><br><font class=text16bu>".pcrtlang("Clock Number List")."&nbsp;</font><br><br>";
echo "<table><tr><td><font class=text12b>".pcrtlang("Location").":</font></td><td><select name=location>";
$rs_fl = "SELECT * FROM locations";
$rs_resultfl = mysqli_query($rs_connect, $rs_fl);
while ($rs_result_fl1 = mysqli_fetch_object($rs_resultfl)) {
$locname = "$rs_result_fl1->locname";
$locid = "$rs_result_fl1->locid";
if(in_array("$locid", $locpermsthisuser)) {
if ($locid == $defloc) {
echo "<option selected value=$locid>$locname</option>";
} else {
echo "<option value=$locid>$locname</option>";
}
}

}
echo "</select></td><td></td></tr>";
echo "<tr><td><font class=text12b>".pcrtlang("Department").":</font></td><td><select name=department>";
echo "<option selected value=0>".pcrtlang("All Departments")."</option>";
$rs_fd = "SELECT * FROM departments ORDER BY deptcode";
$rs_resultfd = mysqli_query($rs_connect, $rs_fd);
while ($rs_result_fdd = mysqli_fetch_object($rs_resultfd)) {
$deptname = "$rs_result_fdd->deptname";
$deptid = "$rs_result_fdd->deptid";
$deptcode = "$rs_result_fdd->deptcode";
if(in_array("$deptid", $deptpermsthisuser)) {
echo "<option value=$deptid>$deptcode - $deptname</option>";
}
}
echo "</select></td></tr>";
echo "<tr><td><input class=button type=submit value=\"".pcrtlang("Show Report")."\"></form></td></tr></table>";



}

stop_box();





require("footer.php");


}



######

switch($func) {
                                                                                                    
    default:
    dailystatus();
    break;
                                
    case "dailystatus":
    dailystatus();
    break;


}

?>

