getAclFromTypeName($typeName, $forceTblAclInit = ('1' == V::get('_force', '', $_GET))); $forceFilterInit = array(); $filterInit = new stdClass(); $filterInit->currSortCol = 'ID'; $filterInit->currSortFlip = 'desc'; foreach ($_GET as $k => $v) { if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix $filterInit->$k = $v; } else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix $filterInit->$k = $v; } else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix $fldName = substr($k, 3); $forceFilterInit[$fldName] = $v; } } $tbl = new TableAjax($acl); $tblLabel = $typeName; if ('p5_default_db:' == substr($typeName, 0, 14)) { $tblLabel = array(); $zasobObj = ProcesHelper::getZasobTableInfo($acl->getID()); if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje"); if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL; if (!empty($zasobObj->OPIS)) $tblLabel []= $zasobObj->OPIS; $tblLabel = implode(" - ", $tblLabel); } if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms Lib::loadClass('DebugExecutionTime'); $dbgExecTime = new DebugExecutionTime(); $dbgExecTime->activate(); $dbgExecTime->log('start'); UI::startContainer(['style'=>'border:1px solid red']); UI::tag('p', null, "TEST - load perms from db"); $idTable = $acl->getID(); UI::tag('p', null, "DBG idTable({$idTable})"); $dbgExecTime->log('before sql'); $aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}"); $dbgExecTime->log('after sql', ['sql']); UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]); $csvIdProces = array(); foreach ($aclTableRows as $row) { if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES']; } $csvIdProces = implode(",", $csvIdProces); UI::tag('p', null, "DBG csvIdProces({$csvIdProces})"); if (!empty($csvIdProces)) { $userLogin = User::getLogin(); $dbgExecTime->log('before sql'); $rows = DB::getPDO()->fetchAll("select ID_PROCES from `CRM_PROCES_idx_USER_to_PROCES_VIEW` where ADM_ACCOUNT = '{$userLogin}' and ID_PROCES in({$csvIdProces}) group by ID_PROCES"); $dbgExecTime->log('after sql', ['sql']); UI::table(['caption' => "from CRM_PROCES_idx_USER_to_PROCES_VIEW", 'rows' => $rows]); $userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES']; $userTablePerms = array(); foreach ($aclTableRows as $row) { if (!in_array($row['ID_PROCES'], $userIdProces)) continue; if (array_key_exists($row['CELL_NAME'], $userTablePerms)) { $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V']; $userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E']; } else { $userTablePerms[ $row['CELL_NAME'] ] = $row; unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]); unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]); unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]); } } UI::table(['caption' => "\$userTablePerms", 'rows' => $userTablePerms]); } else UI::alert('warning', "brak \$csvIdProces"); $dbgExecTime->printDebug(); UI::endContainer(); } $tbl->setLabel($tblLabel); $tbl->setFilterInit($filterInit); if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit); $tbl->addRowFunction('edit'); $tbl->addRowFunction('hist'); $tbl->addRowFunction('files'); $tbl->addRowFunction('cp'); $tbl->addRowFunction('msgs'); echo $tbl->render(); } catch (Exception $e) { UI::startContainer(); UI::alert('danger', "Wystąpiły błędy! " . $e->getMessage()); UI::endContainer(); } UI::dol(); } /** * @param string $typeName - 'p5_default_db:TEST_PERMS' */ public function getAclFromTypeName($typeName, $forceTblAclInit) { $userAcl = User::getAcl(); $userAcl->fetchGroups(); $typeEx = explode(':', $typeName); if (2 != count($typeEx)) throw new Exception("Could not get acl for '{$typeName}' - syntax error"); if ('p5_' != substr($typeEx[0], 0, 3)) throw new Exception("Could not get acl for '{$typeName}' - prefix error"); $sourceName = substr($typeEx[0], 3); $objName = $typeEx[1]; $acl = $userAcl->getObjectAcl($sourceName, $objName); if (!$acl) throw new Exception("Could not get acl for '{$typeName}'"); $acl->init($forceTblAclInit); return $acl; } }