getFieldListByIdZasob() as $fieldName) {// TODO: use getFieldList // echo"
\$acl->canCreateField({$fieldName}): (".$acl->canCreateField($fieldName).")
"; if ($acl->canCreateField($fieldName)) return true; } return false; } public static function hasGeomFields($acl) { foreach ($acl->getFieldListByIdZasob() as $fieldName) { // echo"\$acl->isGeomField({$fieldName}): (".$acl->isGeomField($fieldName).") \$acl->canReadField({$fieldName}): (".$acl->canReadField($fieldName).")
"; if ($acl->isGeomField($fieldName) && $acl->canReadField($fieldName)) return true; } return false; } // @returns array [ field => string(perms like 'RWX') ] public static function getFieldPerms($acl) {// TODO: fetch perms for given Acl by namespace // TODO:? cache session or only current request (static) $fieldPerms = array(); foreach ($acl->getFields() as $idField => $field) { $fieldPerms[ $field['name'] ] = $field['perms']; } return $fieldPerms; } public static function getExportFieldList($acl) { $exportFields = array(); foreach (self::getFieldPerms($acl) as $fieldName => $perms) { if (false !== strpos($perms, 'E')) { $exportFields[] = $fieldName; } } return $exportFields; } public static function getAclByTypeName($typeName, $forceTblAclInit = false) {// TODO: replace getAclFromTypeName in WFS return self::getAclByNamespace(str_replace(':', '/', $typeName), $forceTblAclInit); } public static function getAclByNamespace($namespace, $forceTblAclInit = false) { $ns = self::parseNamespaceUrl($namespace); $acl = User::getAcl()->getObjectAcl($ns['prefix'], $ns['name']); if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'"); $acl->init($forceTblAclInit); return $acl; } public static function getMoreFunctionsCell($acl, $args) { $id = V::get('primary_key', 0, $args, 'int'); if ($id <= 0) throw new HttpException("404", 404); $record = V::get('record', null, $args); $rowFunList = array(); $tableName = $acl->getName(); $record = ($record)? $record : $acl->getItem($id); if(1){// TODO: fetch $totalMsgs from TableMsgs $msgs = Router::getRoute('Msgs'); $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id); $totalMsgs = count($msgsList); $rowFunc = new stdClass(); $rowFunc->id = 'msgs'; $rowFunc->ico = 'glyphicon glyphicon-envelope'; $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $acl->getID() . '&idRow=' . $id; $rowFunc->title = "Wiadomości ({$totalMsgs})"; $rowFunc->label = "Wiadomości {$totalMsgs}"; $rowFunList[] = $rowFunc; } if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001 $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-eye-open'; $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}"; $rowFunc->title = "Zobacz na drzewie procesów {{$id}}"; $rowFunList[] = $rowFunc; $wskazniki = ProcesHelper::get_wskazniki($id); $connectedZasobyTotal = count($wskazniki); $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-random'; $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}"; $rowFunc->title = "Powiązane zasoby {$connectedZasobyTotal}"; $rowFunList[] = $rowFunc; } if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001 $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-eye-open'; $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}"; $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]"; $rowFunList[] = $rowFunc; // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001 $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-random'; $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}"; $rowFunc->title = "Powiązane procesy (OB)"; $rowFunList[] = $rowFunc; // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001 $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-random'; $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}"; $rowFunc->title = "Powiązane dane (IDS)"; $rowFunList[] = $rowFunc; $groupTypeList = array(); $groupTypeList[] = 'STANOWISKO'; $groupTypeList[] = 'PODMIOT'; $groupTypeList[] = 'DZIAL'; if (in_array($record->TYPE, $groupTypeList)) { $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-retweet'; $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}"; $rowFunc->title = "Synchronizuj do LDAP"; $rowFunList[] = $rowFunc; } } if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml if ($acl->canReadRecord($record) && $acl->canReadObjectField('ADM_ACCOUNT', $record)) { $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-user'; $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT; $rowFunc->title = "Ustal stanowisko"; $rowFunList[] = $rowFunc; $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-retweet'; $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT; $rowFunc->title = "Synchronizuj do LDAP"; $rowFunList[] = $rowFunc; $rowFunc = new stdClass(); $rowFunc->ico = 'glyphicon glyphicon-minus'; $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT; $rowFunc->title = "Ocena pracownika"; $rowFunList[] = $rowFunc; } } if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) { foreach ($urlFunctions as $urlFunction) { // TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id); $rowFunction = array(); $rowFunction['href'] = $urlFunction['baseLink']; $rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction); $rowFunction['label'] = $urlFunction['label']; $rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction); if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target']; if (!empty($urlFunction['cell_id_params'])) { $urlParams = array();// [ "{$urlParamName}={$paramValue}" ] foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) { $paramValue = ''; $fld = $acl->getField($idField); if ($fld) { $fldName = $fld['name']; $paramValue = V::get($fldName, '', $record); $urlParams[] = "{$urlParamName}={$paramValue}"; } } if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams); } $rowFunList[] = $rowFunction; } } return $rowFunList; } public static function getAclList() {// @usage Core_AclHelper::getAclList();// @returns array [ $typeName , ... ] $aclList = array(); // Schema_AccessGroupStorageAcl, load by User::getAcl()->getObjectAcl('default_objects', $objName); // $objClassName = "Schema_{$objName}StorageAcl"; // if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501); // $ grep -r 'class ' SE/se-lib/Schema/*Acl.php // SE/se-lib/Schema/AccessGroupStorageAcl.php:class Schema_AccessGroupStorageAcl extends Core_AclBase // SE/se-lib/Schema/AccessOwnerStorageAcl.php:class Schema_AccessOwnerStorageAcl extends Core_AclBase // SE/se-lib/Schema/FileStorageAcl.php:class Schema_FileStorageAcl extends Core_AclBase // SE/se-lib/Schema/KorespondencjaStorageAcl.php:class Schema_KorespondencjaStorageAcl extends Core_AclBase // SE/se-lib/Schema/TestPermsStorageAcl.php:class Schema_TestPermsStorageAcl extends Core_AclBase $aclList[] = 'default_objects:AccessGroupRead'; $aclList[] = 'default_objects:AccessGroupWrite'; $aclList[] = 'default_objects:AccessOwner'; $aclList[] = 'default_objects:File'; $aclList[] = 'default_objects:Korespondencja'; $aclList[] = 'default_objects:TestPerms'; // TODO: read from Database // $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS $cleanHostName = str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']); if (file_exists(APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php")) { $objList = include APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php"; if (!empty($objList) && is_array($objList)) { foreach ($objList as $objectName) { if (!in_array($objectName, $aclList)) $aclList[] = $objectName; } } } return $aclList; } /** * Parse namespace url into parts. * * @param $namespace - absolute or relative url * @return array: * name: element name * url: url wihtout name * prefix: xml prefix * sourceName: used by engine - maybe to remove (used by Core_AclHelper::getAclByNamespace($namespace)) * * @example - create xmlns attribute: * xmlns:{$ns['prefix']}="{$ns['url']}" * * @example - wfs typeName: * typeName = "{$ns['prefix']}:{$ns['name']}" * * @example 'default_db/TEST_PERMS' => Array: * [name] => TEST_PERMS * [prefix] => default_db * [url] => https://biuro.biall-net.pl/wfs/default_db * [sourceName] => default_db * * @example 'default_objects/AccessOwner' => Array: * [name] => AccessOwner * [prefix] => default_objects * [url] => https://biuro.biall-net.pl/wfs/default_objects * [sourceName] => default_objects * * @example 'default_db/ZALICZKA/Zaliczka' => Array: * [name] => Zaliczka * [prefix] => default_db__x3A__Zaliczka * [url] => https://biuro.biall-net.pl/wfs/default_db/ZALICZKA * [sourceName] => table_objects * */ public static function parseNamespaceUrl($namespace) {// returns assoc array: [ 'name', 'url', 'prefix', 'sourceName' ] // TODO: the same algo like getAclByNamespace($namespace) $baseNsUri = Api_WfsNs::getBaseWfsUri(); if ('http' != substr($namespace, 0, 4)) $namespace = "{$baseNsUri}/{$namespace}";//Request::getHostUri() . '/' . $namespace; $nsUrl = $baseNsUri . '/' . ''; if ("{$baseNsUri}/" != substr($namespace, 0, strlen($baseNsUri) + 1)) throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501); $relativeNsUrl = substr($namespace, strlen($baseNsUri) + 1); // convert '__x3A__' to '/' in url $nsEx = explode('/', str_replace('__x3A__', '/', $relativeNsUrl));// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj} // default_db__x3A__ZALICZKA/Zaliczka => default_db/ZALICZKA/Zaliczka $sourceName = array_shift($nsEx);// remove first element - source name $objName = array_pop($nsEx);// name is always last part from url if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) { if (count($nsEx) > 1) throw new Exception("Nieznany namespace default_db: '{$relativeNsUrl}'", 501); $sourceName = 'default_db'; $nsPrefix = $sourceName; if (1 == count($nsEx)) { $sourceName = 'table_objects';// TODO: another source name to read from simpleSchema @see Core_AclSimpleSchemaBase $nsPrefix = 'default_db__x3A__' . $objName; } // $objName = $nsEx[1];// 'default_db/ZALICZKA:Zaliczka' => ('objects', 'Zaliczka') - possible name conflicts $nsUrl = trim($baseNsUri . '/default_db/' . implode("/", $nsEx), '/'); return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ]; } else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName) { if (count($nsEx) > 1) throw new Exception("Nieznany namespace SystemObjects: '{$relativeNsUrl}'", 501); $sourceName = 'default_objects'; $nsUrl = trim($baseNsUri . '/default_objects/' . implode("/", $nsEx), '/'); $nsPrefix = 'default_objects'; return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ]; } else if ('p5_objects' == $sourceName || 'objects' == $sourceName) { if (count($nsEx) > 1) throw new Exception("Nieznany namespace SystemObjects: '{$relativeNsUrl}'", 501); $sourceName = 'default_objects'; $nsUrl = trim($baseNsUri . '/default_objects/' . implode("/", $nsEx), '/'); $nsPrefix = 'default_objects'; return [ 'name' => $objName, 'prefix' => $nsPrefix, 'url' => $nsUrl, 'sourceName' => $sourceName ]; } else if ('zasob_' == substr($sourceName, 0, 6)) { $dbName = substr($sourceName, 6);// database id throw new Exception("TODO db[{$dbName}] namespace '{$relativeNsUrl}'", 501); } else throw new Exception("Nieznany namespace '{$relativeNsUrl}'", 501); } }