_user_id = User::getID();
if (User::isAdmin()) {
$this->_user_id = V::get('_user_id', 0, $_REQUEST, 'int');
if (!$this->_user_id) {
$this->_user_id = User::getID();
$this->_acl = User::getAcl();
} else {
$this->_acl = UsersHelper::getUserAcl($this->_user_id);
}
} else {
$this->_acl = User::getAcl();
}
if (!$this->_acl) {
die('Error Acl');
}
if ('1' == V::get('_CLEAN_CACHE', '', $_REQUEST)) {
$this->_cleanTestsCache();
}
$this->_generateTestResults();
}
static function getInstance() {
static $_instance = null;
if (!$_instance) {
$_instance = new ProcesMenu();
}
return $_instance;
}
function show() {
static $_menu_showed = false;
if (!$_menu_showed) {
$actionName = V::get('_action', 'menu', $_REQUEST);
// podglad testów pracownika
if (User::isAdmin() && $this->_user_id != User::getID()) {
$actionName = 'showMyTests';
}
$actionName .= 'Action';
if (method_exists($this, $actionName)) {
$this->{$actionName}();
}
//$this->show_menu_with_process();
$_menu_showed = true;
}
}
/**
* @return Array
*/
function getUserTests() {
if ($this->_user_id <= 0) {
throw new Exception("User id not set");
}
$testy_arr = array();
$ses_cache_key = 'CRM_PROCES_USERA_WYKONANE_TESTY-' . $this->_user_id;
if (!$this->_isTestsInCache()) {
$usedProcesInitIds = $this->_acl->getUserProcesInitIds();
DBG::_('DBG_PM', '1', "usedProcesInitIds", $usedProcesInitIds, __CLASS__, __FUNCTION__, __LINE__ );
if (!empty($usedProcesInitIds)) {
$testy_arr = ProcesTestyHelper::get_tetsy_stats($this->_user_id, 0, $usedProcesInitIds);
// check if tests are actual - proces steps may change
if (!empty($testy_arr)) {
foreach ($usedProcesInitIds as $k_proces_id) {
$last_test = null;
foreach ($testy_arr as $k_ind => $v_test) {
if ($v_test->ID_PROCES_INIT == $k_proces_id) {
$last_test = $v_test;
$last_test->test_ind = $k_ind;
break;
}
}
if (!$last_test || $last_test->TEST_END == '0000-00-00') {
continue;
}
$max_update_date = $this->_acl->getProcesMaxUpdateDate($k_proces_id);
if ($max_update_date) {
$max_update_date = substr($max_update_date, 0, 10);
$test_end = substr($last_test->TEST_END, 0, 10);
DBG::_('DBG_PM', '1', "P_INIT({$k_proces_id}) max_update_date({$max_update_date}) TEST_END({$last_test->TEST_END}) not actual(" . ($max_update_date > $last_test->TEST_END) . ")", $last_test, __CLASS__, __FUNCTION__, __LINE__ );
if ($max_update_date > $test_end) {
$testy_arr[$last_test->test_ind]->unactual = $max_update_date;
$testy_arr[$last_test->test_ind]->unactualId = $last_test->ID;
}
}
}
}
}
$this->_setTestsCache($testy_arr);
}
return $this->_getTestsFromCache();
}
private function _cleanTestsCache() {
$ses_cache_key = "CRM_PROCES_USERA_WYKONANE_TESTY-{$this->_user_id}";
unset($_SESSION[$ses_cache_key]);
}
private function _isTestsInCache() {
$ses_cache_key = "CRM_PROCES_USERA_WYKONANE_TESTY-{$this->_user_id}";
return isset($_SESSION[$ses_cache_key]);
}
private function _getTestsFromCache() {
$ses_cache_key = "CRM_PROCES_USERA_WYKONANE_TESTY-{$this->_user_id}";
return $_SESSION[$ses_cache_key];
}
private function _setTestsCache($tests) {
$ses_cache_key = "CRM_PROCES_USERA_WYKONANE_TESTY-{$this->_user_id}";
$_SESSION[$ses_cache_key] = $tests;
}
function setError($error) {
$this->error[] = $error;
}
function ifError() {// TODO: RMME
if (!empty($this->error)) {
return true;
}
else {
DEBUG_S(-1,'Wydarzyły się błędy uniemożliwiające kontynuacje pracy modułu',$this->error,__FILE__,__FUNCTION__,__LINE__);
die();
return false;
}
}
function showMyTestsAction() {
$this->menuAction();
$userAcl = User::getAcl();
$procesyInitGroup = $this->getUsedProcesInitGroupedList();
if (empty($procesyInitGroup)) {
echo '
' . "Brak przypisanych procesów." . '
';
return;
}
?>
sub as $proces_id => $proces_desc) : ?>
get_ocena_testu($proces_id, 'TEORETYCZNY');
$wynik_teoretyczny_value = $this->get_ocena_testu_value($proces_id, 'TEORETYCZNY');
if ($wynik_teoretyczny == 'BRAK_PYTAN') {
$wynik_teoretyczny_value = '';
}
$wynik_praktyczny = $this->get_ocena_testu($proces_id, 'PRAKTYCZNY');
$wynik_unactual = $this->isTestUnactual($proces_id, 'TEORETYCZNY');
?>
= 4) : $i = 0; ?>
_acl->getUserProcesInitList();
if (empty($procesyInitList)) {
return;
}
$sqlProcesyInitIds = implode(",", array_keys($procesyInitList));
$sql = "select p.`ID`, p.`PARENT_ID`, pp.`DESC` as pp__DESC
from `CRM_PROCES` as p
join `CRM_PROCES` as pp on(pp.`ID`=p.`PARENT_ID`)
where p.`ID` in({$sqlProcesyInitIds})
";
$groupedProcesyInit = array();
$db = DB::getDB();
$res = $db->query($sql);
while ($r = $db->fetch($res)) {
if (!array_key_exists($r->PARENT_ID, $procesyInitGroup)) {
$procesyInitGroup[$r->PARENT_ID] = (object)array('nr'=>$r->PARENT_ID, 'label'=>$r->pp__DESC, 'sub'=>array());
}
$procesyInitGroup[$r->PARENT_ID]->sub[$r->ID] = $procesyInitList[$r->ID];
$groupedProcesyInit[] = $r->ID;
}
$ungroupedProcesyInit = array_diff(array_keys($procesyInitList), $groupedProcesyInit);
if (!empty($ungroupedProcesyInit)) {
$procesyInitGroup[$r->PARENT_ID] = (object)array('nr'=>null, 'label'=>"Pozostałe", 'sub'=>array());
foreach ($ungroupedProcesyInit as $nr) {
$procesyInitGroup[$r->PARENT_ID]->sub[$nr] = $procesyInitList[$nr];
}
}
return $procesyInitGroup;
}
function menuAction() {
$testy_teoretyczne = $this->get_actual_tests_count('TEORETYCZNY');
$testy_praktyczne = $this->get_actual_tests_count('PRAKTYCZNY');
$procesy_init_arr = $this->_acl->getUserProcesInitIds();
$proces_cnt = count($procesy_init_arr);
$testy_ok = $this->get_actual_tests_count();
$MojeTestyTitle = "Ilość Procesów: {$proces_cnt}, Aktualnych testów: {$testy_ok}, Teoretycznych: {$testy_teoretyczne}, Praktycznych: {$testy_praktyczne}";
$userAcl = User::getAcl();
$tbls = [];
$urls = [];
$outUrls = array();
$outMenus = array();// typeName => label (order by label)
$typeNameToIdZasob = array();// $typeName => $idZasob
if ($userAcl->getPermsFiltrProcesId()) { // TODO: fetch menu from ajax - fix menuStore
$tbls = $userAcl->getTablesAcl();
$urls = $userAcl->getUrls();
if (!empty($urls)) {
foreach ($urls as $kZasobID => $vTitle) {
$outUrls[$kZasobID] = $vTitle;
}
}
asort($outUrls);
$rawOutMenus = array();
$labelsOutMenus = array();
$outBtnsMenus = array();
// DBG::nicePrint($tbls, '$tbls');
if (!empty($tbls)) {
foreach ($tbls as $kZasobID => $vTblAcl) {
if (null == $vTblAcl) continue;
$tblName = $vTblAcl->getName();
$typeName = "p5_default_db:{$tblName}";
$labelsOutMenus[$typeName] = $vTblAcl->getLongLabel(); // TODO: legacy
$rawOutMenus[$typeName] = strtolower($vTblAcl->getLongRawLabel());
$typeNameToIdZasob[$typeName] = $kZasobID;
// if ($userAcl->getPermsFiltrProcesId()) {
$outBtnsMenus[$typeName] = $vTblAcl->getRawLabel();
// }
}
}
asort($rawOutMenus);
foreach ($rawOutMenus as $typeName => $rawLongLabel) $outMenus[$typeName] = $labelsOutMenus[$typeName]; // TODO: mv to localStorage
if ($userAcl->getPermsFiltrProcesId()) {
asort($outBtnsMenus);
}
}
$active = '';
$script_name = V::get('SCRIPT_NAME', '', $_SERVER);
if (false !== strpos($script_name, 'index.php')) {
$route = V::get('_route', '', $_GET);
if (!empty($route)) {
if ('p5_default_db:KONTAKTY_view' == V::get('typeName', '', $_GET)) $active = 'kontakty';
else if ('default_db/KONTAKTY_view' == V::get('namespace', '', $_GET)) $active = 'kontakty';
} else {
$menu_init = V::get('MENU_INIT', '', $_GET);
switch ($menu_init) {
case 'VIEWTABLE_AJAX': $active = 'menu'; break;
default: {
$fun_init = V::get('FUNCTION_INIT', '', $_GET);
switch ($fun_init) {
case 'MENU_SELECT_PROCES': $active = 'testy'; break;
case 'PRZYPOMNIJ_FUNC': $active = 'przypomnij'; break;
case 'PRZYPOMNIJ': $active = 'przypomnij'; break;
default:
}
}
}
}
}
else if (false !== strpos($script_name, 'procesy5.php')) {
$task = V::get('task', '', $_GET);
switch ($task) {
case 'CRM_PROCES': $active = 'procesy'; break;
case 'CRM_LISTA_ZASOBOW': $active = 'zasoby'; break;
case 'CRM_WYSWIETL_OBOWIAZKI': $active = 'obowiazki'; break;
case 'CRM_TESTY': $active = 'testy'; break;
case 'CRM_TESTY_WYNIKI': $active = 'testy'; break;
case 'CRM_TESTY__LIST': $active = 'testy'; break;
case 'CRM_TESTY__ADD_TEST': $active = 'testy'; break;
case 'CRM_TESTY__ADD_KANDYDAT': $active = 'testy'; break;
case 'CRM_SEARCH': $active = 'search'; break;
default:
// testy_moje ?FUNCTION_INIT=MENU_SELECT_PROCES&MENU_SELECT_PROCES=show_menu_with_process => _action=showMyTests
}
}
/*
* $_SESSION['USER_PROFILE'][section][key] = val;
*/
$userGroupIdsCSV = User::getGroupsIds();
$userGroupIdsCSV = implode(',', $userGroupIdsCSV);
$typeSpecialZasob = TypespecialVariable::getInstance(-1, '__ZASOB');
$treeZasobyFilter = FilterFactory::build('CRM_LISTA_ZASOBOW');
$lastZasobyFiltrIds = $treeZasobyFilter->get_arg('filtr_id');
$typeSpecialProces = TypespecialVariable::getInstance(-1, '__PROCES');
$treeProcesyFilter = FilterFactory::build('CRM_PROCES');
$lastProcesyFiltrIds = $treeProcesyFilter->get_arg('filtr_id');
$menuProcesViewedTblId = 0;
$menuProcesViewedAclIsObject = false;
if ('ViewTableAjax' == V::get('_route', '', $_REQUEST)) {
$namespace = V::get('namespace', '', $_REQUEST, 'word');
if (!$namespace) {
$typeName = V::get('typeName', '', $_REQUEST, 'word');
if ($typeName) {
$namespace = str_replace(['__x3A__', ':'], '/', $typeName);
}
}
if ($namespace) {
$menuProcesViewedAclIsObject = (
'default_db/' === substr($namespace, 0, strlen('default_db/'))
&& strpos(substr($namespace, strlen('default_db/')), '/') > 0
);
$zasobTableName = (
'default_db/' === substr($namespace, 0, strlen('default_db/'))
&& false === strpos(substr($namespace, strlen('default_db/')), '/')
)
? substr($namespace, strlen('default_db/'))
: $namespace;
if ($zasobTableName) {
$dbID = DB::getPDO()->getZasobId();
$menuProcesViewedTblId = DB::getPDO()->fetchValue("
select z.ID
from CRM_LISTA_ZASOBOW z
where z.`DESC` = '{$zasobTableName}'
and z.A_STATUS not in ('DELETED')
and z.`TYPE` = 'TABELA'
and z.PARENT_ID = '{$dbID}'
");
}
}
}
else if ('VIEWTABLE_AJAX' == V::get('MENU_INIT', '', $_REQUEST)) {
$menuProcesViewedTblId = V::get('ZASOB_ID', 0, $_REQUEST, 'int');
}
UI::loadTemplate('menuMain', [
'active' => $active,
'outMenus' => $outMenus,
'outBtnsMenus' => $outBtnsMenus,
'outUrls' => $outUrls,
'typeNameToIdZasob' => $typeNameToIdZasob,
'lastProcesyFiltrIds' => $lastProcesyFiltrIds,
'menuProcesViewedTblId' => $menuProcesViewedTblId,
'userAcl__getPermsFiltrProcesId' => $userAcl->getPermsFiltrProcesId(),
'typeSpecialProces' => $typeSpecialProces,
'lastZasobyFiltrIds' => $lastZasobyFiltrIds,
'userGroupIdsCSV' => $userGroupIdsCSV,
'menuProcesViewedAclIsObject' => $menuProcesViewedAclIsObject,
'namespace' => $namespace,
'typeSpecialZasob' => $typeSpecialZasob,
'MojeTestyTitle' => $MojeTestyTitle,
'testy_ok' => $testy_ok,
'proces_cnt' => $proces_cnt,
'testy_teoretyczne' => $testy_teoretyczne,
'testy_praktyczne' => $testy_praktyczne,
'typeSpecialUserId' => (User::isAdmin()) ? TypespecialVariable::getInstance(-1, '__USER_ID') : null,
'idFiltrProcesID' => $userAcl->getPermsFiltrProcesId(),
]);
}
/**
* Generates wyniki
*/
private function _generateTestResults() {
$this->_wynik_testu = array();// WYNIK_TESTU_PROCESU
$this->_wynik_testu_unactual = array();
$this_CRM_PROCES_USERA_WYKONANE_TESTY = $this->getUserTests();
foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $v_test) {
if (isset($this->_wynik_testu[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE])) {
continue;// only first
}
$this->_wynik_testu[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE] = $v_test->OCENA;
if (!empty($v_test->unactual)) {
$x_test = new stdClass();
$x_test->TEST_END = substr($v_test->TEST_END, 0, 10);
$x_test->unactual = substr($v_test->unactual, 0, 10);
$x_test->unactualId = $v_test->unactualId;
$this->_wynik_testu_unactual[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE] = $x_test;
}
}
}
function get_ocena_testu($proces_id, $typ) {
$ocena = $this->get_ocena_testu_value($proces_id, $typ);
if (!$ocena) {
return 'BRAK_TESTU';
}
else if ($ocena == -1) {
return 'BRAK_PYTAN';
}
else if ($ocena == 3) {
return 'IDEALNY';
}
else if ($ocena < 2) {
return 'NIEDOSTATECZNY';
}
else if($ocena < 2.5) {
return 'DOSTATECZNY';
}
else {
return 'DOBRY';
}
}
function get_ocena_testu_value($proces_id, $typ) {
if (isset($this->_wynik_testu[$proces_id][$typ])) {
return $this->_wynik_testu[$proces_id][$typ];
}
return null;
}
function isTestUnactual($proces_id, $typ) {
if (isset($this->_wynik_testu_unactual[$proces_id][$typ])) {
return $this->_wynik_testu_unactual[$proces_id][$typ];
}
return false;
}
function get_actual_tests_count($type = null) {
$this_CRM_PROCES_USERA_WYKONANE_TESTY = $this->getUserTests();
if ($type == 'TEORETYCZNY') {
$testy_teoretyczne = 0;
foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $int => $v_test) {
if ($v_test->TEST_TYPE=='TEORETYCZNY') {
if ($v_test->OCENA > 2.5) $testy_teoretyczne++;
}
}
return $testy_teoretyczne;
}
else if ($type == 'PRAKTYCZNY') {
$testy_praktyczne = 0;
foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $int => $v_test) {
if ($v_test->TEST_TYPE=='PRAKTYCZNY') {
if ($v_test->OCENA > 2.5) $testy_praktyczne++;
}
}
return $testy_praktyczne;
}
else if ($type == null) {
return count($this_CRM_PROCES_USERA_WYKONANE_TESTY);
}
return 0;
}
/**
* URL: _action=setPermsAll
*/
function setPermsAllAction() {
$userAcl = User::getAcl();
$userAcl->fetchAllPerms(true);
$this->menuAction();
}
/**
* URL: _action=setPermsByProces
*/
function setPermsByProcesAction() {
$procesID = V::get('id_proces', 0, $_GET, 'int');
if ($procesID <= 0) {
echo '' . "Brak ID Procesu" . '
';
return;
}
$userAcl = User::getAcl();
if ($userAcl->getPermsFiltrProcesId() == $procesID) {
$this->menuAction();
echo '' . "Filtr procesu nr {$procesID} jest już uruchomiony" . '
';
return;
}
$userAcl = User::getAcl();
if (!$userAcl->canExecuteProcesInit($procesID)) {
$this->menuAction();
echo '' . "Brak uprawnień do uruchomienia filtra procesu" . '
';
SE_Layout::dol();
exit;
}
$userAcl->fetchProcesPerms($procesID, true);
$this->menuAction();
}
function move_test_from_kandydat_to_pracownik($id_kanydata, $id_pracownika) {
//4673->4680
//$sql='update CRM_TESTY set A_RECORD_CREATE_AUTHOR='smagielm' where A_RECORD_CREATE_AUTHOR='Kandydat.4673';
//$sql='update CRM_TESTY set A_RECORD_UPDATE_AUTHOR='smagielm' where A_RECORD_UPDATE_AUTHOR='Kandydat.4673';
//$sql="update CRM_TESTY set ID_TESTER='4680' where ID_TESTER='4673'";
}
}