<?PHP
// Pushok's SEMA (Small Enterprise Management Application)
//
// Copyright (C) 2004 Pushok Software http://www.pushok.com
//
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
class web_TimeBTrack extends web_Layout
{
function formatTime($iTime) {
$h = floor($iTime / 3600);
$iTime -= $h*3600;
if (strlen($h)==1)
$h = "0$h";
$m = floor($iTime / 60);
$iTime -= $m*60;
if (strlen($m)==1)
$m = "0$m";
$s = $iTime;
if (strlen($s)==1)
$s = "0$s";
return "$h:$m:$s";
}
function Info()
{
?>
<script language="JavaScript">
function Change(id, date)
{
update.id.value = id;
update.date.value = date;
update.submit();
}
</script>
<?PHP
$arContacts = null;
if (!isset($_SESSION['time_board']))
$_SESSION['time_board'] = null;
if (!isset($_SESSION['time_board']['contacts']) && !count($_SESSION['time_board']['contacts'])) {
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_SHORTINFO", $oIn = array('idcontact_current'=>$_SESSION['iduser']), $arContacts);
foreach ($arContacts['contacts'] as $key => $val) {
$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$key, 'type'=>ID_SEMA_CONTACT, 'mask'=>'R');
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
if ( !(isset($_oOut['result']) && $_oOut['result']) )
unset($arContacts['contacts'][$key]);
}
$_SESSION['time_board']['contacts'] = $arContacts;
} else
$arContacts = $_SESSION['time_board']['contacts'];
$this->formStart("", "filter");
echo "<FORM method=get name=filter>";
echo "<INPUT type=\"hidden\" name=\"idform\" value=\"FM_TBOARD_SEARCH\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"action\" value=\"filter\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"redirect\" value=\"page@@/web/time_board/time_board_main.php\"></INPUT>\n";
// fill filter with default values
if ( !isset($_SESSION['last_filter']) || $_SESSION['last_filter']['idform'] != "FM_TBOARD_SEARCH" )
$_SESSION['last_filter'] = array('idform'=>"FM_TBOARD_SEARCH", 'start'=>date("Y-m-01"), 'end'=>date("Y-m-d"),
'idworker'=>0);
$arContacts['contacts'][0] = "All";
$sFieldValue = 0;
if (isset($_SESSION['last_filter']['idworker']))
$sFieldValue = $_SESSION['last_filter']['idworker'];
$this->formInputItem(_LW("Worker"),"select","idworker",$sFieldValue,$arContacts['contacts']);
$sFieldValue = date("Y-m-01");
if (isset($_SESSION['last_filter']['start']))
$sFieldValue = $_SESSION['last_filter']['start'];
$this->formInputItem(_LW("Start"), "date", "start", $sFieldValue);
$sFieldValue = date("Y-m-d");
if (isset($_SESSION['last_filter']['end']))
$sFieldValue = $_SESSION['last_filter']['end'];
$this->formInputItem(_LW("End"), "date", "end", $sFieldValue);
$this->formInputItem("", "button", "", _LW("Refresh"), array('onclick'=>"onclick=\"document.filter.submit();\""));
echo "</FORM>\n";
$this->formEnd();
$oIn = array('idcontact_current' => $_SESSION['iduser'], 'bdate'=>$_SESSION['last_filter']['start'],
'edate'=>$_SESSION['last_filter']['end'], 'idworker'=>$_SESSION['last_filter']['idworker']);
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_SEARCH", $oIn, $arTbT);
// check can user modify time and type of day or not
$bHasAccess = false;
$_oIn = array('idcontact'=>$_SESSION['iduser'], 'idobject'=>$_SESSION['last_filter']['idworker'], 'type'=>ID_SEMA_CONTACT, 'mask'=>'4');
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_CONTACT_HAS_MASK", $_oIn, $_oOut);
if ( isset($_oOut['result']) && $_oOut['result'] )
$bHasAccess = true;
////////////////////////////////////////////////////////////////////////////////////////////
// show some special info about user work time
$arTimebTimeb = array();
$arTimebTrack = array();
if ($_SESSION['last_filter']['idworker'] != 0) {
$this->formStart(_LW("Detailed time board for")." ".$arContacts['contacts'][$_SESSION['last_filter']['idworker']]);
$this->formSection(_LW("Statistics"));
$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idworker'=>$_SESSION['last_filter']['idworker'],
'bdate'=>$_SESSION['last_filter']['start'], 'edate'=>$_SESSION['last_filter']['end']);
// count necessary work time for some user
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_GETWORKDAY", $_oIn, $oTbWDay);
$nNecessaryTime = 0;
if (isset($oTbWDay['tbt']))
foreach ($oTbWDay['tbt'] as $key => $val) {
list($h, $m, $s) = split(":", $val['time']);
$nNecessaryTime += $h*3600 + $m*60 + $s;
$arTimebTimeb[$val['date']] = array('date'=>$val['date'], 'type'=>$val['type'], 'time'=>$val['time'], 'id'=>$val['id']);
}
// show necessary time
$this->formItem(_LW("Base time"),"string",$this->formatTime($nNecessaryTime));
// count real work time for some user
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TBOARD_SEARCH", $_oIn, $oTbT);
$nRealTime = 0;
if (isset($oTbT['tbt']))
foreach ($oTbT['tbt'] as $key => $val) {
$nRealTime += $val['time'];
if (!isset($arTimebTrack[$val['date']]))
$arTimebTrack[$val['date']] = array();
array_push($arTimebTrack[$val['date']], array('id'=>$val['id'], 'start'=>$val['start'], 'end'=>$val['end'],
'time'=>$val['time']));
}
// show real time
$this->formItem(_LW("Booked time"),"string",$this->formatTime($nRealTime));
// count result time for current user
$diff = $nNecessaryTime-$nRealTime;
$sStatus = "";
if ($diff > 0)
$sStatus = _LW("undertime")." (".$this->formatTime(abs($diff)).")";
elseif ($diff < 0)
$sStatus = _LW("overtime")." (".$this->formatTime(abs($diff)).")";
else
$sStatus = _LW("exact match");
$this->formItem(_LW("Result time"),"string",$sStatus);
$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idworker'=>$_SESSION['last_filter']['idworker'],
'start'=>$_SESSION['last_filter']['start'], 'end'=>$_SESSION['last_filter']['end']);
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TIMETRACK_SEARCH", $_oIn, $arTT);
if (isset($arTT['tt'])) {
foreach ($arTT['tt'] as $key => $val)
$nTTsTime += $val['work_volume'];
$this->formItem(_LW("Time tracks' time"),"string",$nTTsTime);
}
$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idworker'=>$_SESSION['last_filter']['idworker'],
'bdate'=>$_SESSION['last_filter']['start'], 'edate'=>$_SESSION['last_filter']['end']);
// show time necessary for tasks
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TASK_SEARCH", $_oIn, $arTasks);
if (isset($arTasks['tasks'])) {
$nTasksTime = 0;
$nTTsTime = 0;
$arParents = array();
foreach ($arTasks['tasks'] as $key => $val) {
$nTasksTime += $val['work_time'];
array_push($arParents, $key);
}
$this->formItem(_LW("Tasks' time"),"string",$nTasksTime);
$_oIn = array('idcontact_current'=>$_SESSION['iduser'], 'idworker'=>$_SESSION['last_filter']['idworker'],
'start'=>$_SESSION['last_filter']['start'], 'end'=>$_SESSION['last_filter']['end'], 'idparent'=>$arParents);
$GLOBALS['LIB_DISPATCHER']->ProcessMessage("LM_TIMETRACK_SEARCH", $_oIn, $arTT);
if (isset($arTT['tt'])) {
foreach ($arTT['tt'] as $key => $val)
$nTTsTime += $val['work_volume'];
$this->formItem(_LW("Time tracks' time"),"string",$nTTsTime);
}
}
$this->formSectionEnd();
$this->formSection(_LW("Detail records"));
}
else
$this->formStart(_LW("Time board records"));
$this->formItem("", "subitem");
echo "<FORM method=post name=update>";
echo "<INPUT type=\"hidden\" name=\"idform\" value=\"FM_TBOARD_MAIN\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"action\" value=\"filter\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"onsuccess\" value=\"?page=/web/time_board/time_board_main.php\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"onerror\" value=\"?page=/web/time_board/time_board_main.php\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"idworker\" value=\"".$_SESSION['last_filter']['idworker']."\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"id\"></INPUT>\n";
echo "<INPUT type=\"hidden\" name=\"date\"></INPUT>\n";
$this->tableStart();
$arHeader = array();
if ($_SESSION['last_filter']['idworker'] != 0) {
array_push($arHeader, array('value'=>_LW('Date'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Norm'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Tracks'), 'colspan'=>0, 'align'=>'left'));
} else {
array_push($arHeader, array('value'=>_LW('Id'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Date'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Start'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('End'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Worker'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Work volume'), 'colspan'=>0, 'align'=>'left'));
array_push($arHeader, array('value'=>_LW('Action'), 'colspan'=>0, 'align'=>'left'));
}
$this->tableHeader($arHeader);
if ($_SESSION['last_filter']['idworker'] == 0) {
if ( count($arTbT['tbt']) )
foreach ( $arTbT['tbt'] as $nIdTbT => $arTbTInfo )
if (isset($arContacts['contacts'][$arTbTInfo['idworker']])) {
$this->tableRow();
$this->tableCol($this->singleItem("string",$arTbTInfo['id']));
$this->tableCol($this->singleItem("date",$arTbTInfo['date']));
$this->tableCol($this->singleItem("string",$arTbTInfo['start']));
$this->tableCol($this->singleItem("string",$arTbTInfo['end']));
$this->tableCol($this->singleItem("string",$arContacts['contacts'][$arTbTInfo['idworker']]));
$this->tableCol($this->singleItem("string",$this->formatTime($arTbTInfo['time'])));
$_oIn=array('idobject'=>$arTbTInfo['id'], 'type'=>ID_SEMA_TBOARD, 'idworker'=>$arTbTInfo['idworker']);
$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_ACTION_MENU_CREATE", $_oIn, $_oOut=array());
$this->tableCol();
if ( count($_oOut) ) {
krsort($_oOut);
foreach ( $_oOut as $nPriority=>$arMenues)
foreach ( $arMenues as $sName => $arData )
echo $this->singleItem("action",$sName,$arData);
}
}
} else {
$nDateStart = strtotime($_SESSION['last_filter']['start']);
$nDateEnd = strtotime($_SESSION['last_filter']['end']);
while ($nDateStart <= $nDateEnd) {
$this->tableRow();
$dtDay = date("Y-m-d", $nDateStart);
$this->tableCol($dtDay);
$arWorkDays = array('Empty'=>'Empty', 'Normal'=>'Normal','Ill'=>'Ill', 'Holiday'=>'Holiday', 'Shortday'=>'Shortday');
if ($bHasAccess) {
if (isset($arTimebTimeb[$dtDay])) {
$id = $arTimebTimeb[$dtDay]['id'];
$params = $arWorkDays;
$params['script'] = "onchange=\"Change('$id', '$dtDay');\"";
$this->tableCol($this->singleInputItem("", "edit", "time_$id", $arTimebTimeb[$dtDay]['time'], array('size'=>6, 'readonly'=>'')).
$this->singleInputItem("", "select", "type_$id", $arTimebTimeb[$dtDay]['type'], $params));
} else {
$params = $arWorkDays;
$params['script'] = "onchange=\"Change('$dtDay', '$dtDay');\"";
$this->tableCol($this->singleInputItem("", "edit", "time_$dtDay", "00:00:00", array('size'=>6, 'readonly'=>'')).
$this->singleInputItem("", "select", "type_$dtDay", "Empty", $params));
}
} else {
if (isset($arTimebTimeb[$dtDay]))
$this->tableCol($arTimebTimeb[$dtDay]['time']." ".$arTimebTimeb[$dtDay]['type']);
else
$this->tableCol("00:00:00 Empty");
}
$this->tableCol();
if (isset($arTimebTrack[$dtDay])) {
foreach ($arTimebTrack[$dtDay] as $key => $val) {
echo "=> ".$val['start']." - ".$val['end']." = ".$this->formatTime($val['time'])." ";
$_oIn=array('idobject'=>$val['id'], 'type'=>ID_SEMA_TBOARD, 'idworker'=>$_SESSION['last_filter']['idworker']);
$GLOBALS['WEB_DISPATCHER']->ProcessMessage("WM_ACTION_MENU_CREATE", $_oIn, $_oOut=array());
if ( count($_oOut) ) {
krsort($_oOut);
foreach ( $_oOut as $nPriority=>$arMenues)
foreach ( $arMenues as $sName => $arData )
echo $this->singleItem("action",$sName,$arData);
}
echo "<BR>";
}
}
// next day ;)
$nDateStart += 86400;
}
//
}
$this->tableEnd();
echo "</FORM>\n";
$this->formEnd();
?>
<?PHP
}
}
$oPage = new web_TimeBTrack;
$oPage->m_windowHeader = _LW("Time board");
$oPage->WebStack("time_board_main.php", $oPage->m_windowHeader, $oPage->m_windowHeader, web_GetPageGetParams());
if ( !isset($_SESSION['iduser']) )
web_RedirectRelative("sema.php");
$oPage->m_menuFLvl = "Time board";
$oPage->RenderPage();
?>