AclHelper.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. Lib::loadClass('Api_WfsNs');
  3. Lib::loadClass('ProcesHelper');
  4. Lib::loadClass('Router');
  5. Lib::loadClass('Route_UrlAction');
  6. class Core_AclHelper {// Helper class for Acl
  7. public static function hasCreatePerms($acl) {
  8. foreach ($acl->getFieldListByIdZasob() as $fieldName) {// TODO: use getFieldList
  9. // echo"<p>\$acl->canCreateField({$fieldName}): (".$acl->canCreateField($fieldName).")</p>";
  10. if ($acl->canCreateField($fieldName)) return true;
  11. }
  12. return false;
  13. }
  14. public static function hasGeomFields($acl) {
  15. foreach ($acl->getFieldListByIdZasob() as $fieldName) {
  16. // echo"<p>\$acl->isGeomField({$fieldName}): (".$acl->isGeomField($fieldName).") \$acl->canReadField({$fieldName}): (".$acl->canReadField($fieldName).")</p>";
  17. if ($acl->isGeomField($fieldName) && $acl->canReadField($fieldName)) return true;
  18. }
  19. return false;
  20. }
  21. public static function getAclByNamespace($namespace, $forceTblAclInit = false) {
  22. if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
  23. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  24. if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
  25. $schemaNs = substr($namespace, strlen($baseNsUri) + 1);
  26. $ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj}
  27. $sourceName = array_shift($ns);// remove first element - source name
  28. if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
  29. $sourceName = 'default_db';
  30. $objName = $ns[0];
  31. if (1 == count($ns)) {
  32. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  33. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  34. $acl->init($forceTblAclInit);
  35. return $acl;
  36. }
  37. else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
  38. }
  39. else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
  40. $sourceName = 'objects';
  41. $objName = $ns[0];
  42. if (1 == count($ns)) {
  43. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  44. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  45. $acl->init($forceTblAclInit);
  46. return $acl;
  47. }
  48. else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
  49. }
  50. else if ('zasob_' == substr($sourceName, 0, 6)) {
  51. $dbName = substr($sourceName, 6);
  52. throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
  53. }
  54. else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
  55. }
  56. else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
  57. throw new HttpException("TODO L.".__LINE__." ns({$namespace})", 501);
  58. }
  59. public static function getMoreFunctionsCell($acl, $args) {
  60. $id = V::get('primary_key', 0, $args, 'int');
  61. if ($id <= 0) throw new HttpException("404", 404);
  62. $record = V::get('record', null, $args);
  63. $rowFunList = array();
  64. $tableName = $acl->getName();
  65. $record = ($record)? $record : $acl->getItem($id);
  66. if(1){// TODO: fetch $totalMsgs from TableMsgs
  67. $msgs = Router::getRoute('Msgs');
  68. $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
  69. $totalMsgs = count($msgsList);
  70. $rowFunc = new stdClass();
  71. $rowFunc->id = 'msgs';
  72. $rowFunc->ico = 'glyphicon glyphicon-envelope';
  73. $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $acl->getID() . '&idRow=' . $id;
  74. $rowFunc->title = "Wiadomości ({$totalMsgs})";
  75. $rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
  76. $rowFunList[] = $rowFunc;
  77. }
  78. if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class
  79. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  80. $rowFunc = new stdClass();
  81. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  82. $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
  83. $rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
  84. $rowFunList[] = $rowFunc;
  85. $wskazniki = ProcesHelper::get_wskazniki($id);
  86. $connectedZasobyTotal = count($wskazniki);
  87. $rowFunc = new stdClass();
  88. $rowFunc->ico = 'glyphicon glyphicon-random';
  89. $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
  90. $rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
  91. $rowFunList[] = $rowFunc;
  92. }
  93. if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class
  94. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  95. $rowFunc = new stdClass();
  96. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  97. $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
  98. $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
  99. $rowFunList[] = $rowFunc;
  100. // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
  101. $rowFunc = new stdClass();
  102. $rowFunc->ico = 'glyphicon glyphicon-random';
  103. $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
  104. $rowFunc->title = "Powiązane procesy (OB)";
  105. $rowFunList[] = $rowFunc;
  106. // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
  107. $rowFunc = new stdClass();
  108. $rowFunc->ico = 'glyphicon glyphicon-random';
  109. $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
  110. $rowFunc->title = "Powiązane dane (IDS)";
  111. $rowFunList[] = $rowFunc;
  112. $groupTypeList = array();
  113. $groupTypeList[] = 'STANOWISKO';
  114. $groupTypeList[] = 'PODMIOT';
  115. $groupTypeList[] = 'DZIAL';
  116. if (in_array($record->TYPE, $groupTypeList)) {
  117. $rowFunc = new stdClass();
  118. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  119. $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
  120. $rowFunc->title = "Synchronizuj do LDAP";
  121. $rowFunList[] = $rowFunc;
  122. }
  123. }
  124. if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml
  125. if ($acl->canReadRecord($record) && $acl->canReadObjectField('ADM_ACCOUNT', $record)) {
  126. $rowFunc = new stdClass();
  127. $rowFunc->ico = 'glyphicon glyphicon-user';
  128. $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
  129. $rowFunc->title = "Ustal stanowisko";
  130. $rowFunList[] = $rowFunc;
  131. $rowFunc = new stdClass();
  132. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  133. $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
  134. $rowFunc->title = "Synchronizuj do LDAP";
  135. $rowFunList[] = $rowFunc;
  136. $rowFunc = new stdClass();
  137. $rowFunc->ico = 'glyphicon glyphicon-minus';
  138. $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
  139. $rowFunc->title = "Ocena pracownika";
  140. $rowFunList[] = $rowFunc;
  141. }
  142. }
  143. if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
  144. foreach ($urlFunctions as $urlFunction) {
  145. // TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id);
  146. $rowFunction = array();
  147. $rowFunction['href'] = $urlFunction['baseLink'];
  148. $rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction);
  149. $rowFunction['label'] = $urlFunction['label'];
  150. $rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
  151. if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target'];
  152. if (!empty($urlFunction['cell_id_params'])) {
  153. $urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
  154. foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
  155. $paramValue = '';
  156. $fld = $acl->getField($idField);
  157. if ($fld) {
  158. $fldName = $fld['name'];
  159. $paramValue = V::get($fldName, '', $record);
  160. $urlParams[] = "{$urlParamName}={$paramValue}";
  161. }
  162. }
  163. if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
  164. }
  165. $rowFunList[] = $rowFunction;
  166. }
  167. }
  168. return $rowFunList;
  169. }
  170. }