UserAcl.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <?php
  2. Lib::loadClass('DB');
  3. Lib::loadClass('UsersHelper');
  4. Lib::loadClass('ProcesHelper');
  5. Lib::loadClass('TableAcl');
  6. Lib::loadClass('SchemaReader');
  7. class UserAcl {
  8. var $_user_id;
  9. var $_use_cache = false;
  10. /**
  11. * User groups (cached)
  12. */
  13. var $_groups = array();
  14. var $_proces_ids = array();
  15. var $_proces_tree_flat = array();
  16. var $_proces_used_ids = array();
  17. var $_proces_used_map = array();
  18. var $_proces_init_used_ids = array();
  19. function __construct($user_id, $use_cache = false) {
  20. $this->_user_id = $user_id;
  21. $this->_use_cache = $use_cache;
  22. $this->_cache_init();
  23. }
  24. function fetchGroups() {
  25. if ($this->_user_id < 0) return false;
  26. if (!empty($this->_groups)) {
  27. return $this->_groups;
  28. }
  29. $this->_groups = $this->_cache_read('_groups');
  30. if ($this->_groups != null) {
  31. return $this->_groups;
  32. }
  33. $this->_groups = array();
  34. $this->_groups = UsersHelper::get_group_by_user($this->_user_id);
  35. $this->_cache_save('_groups', $this->_groups);
  36. return $this->_groups;
  37. }
  38. function getProcesIds() {
  39. if (!empty($this->_proces_ids)) {
  40. return $this->_proces_ids;
  41. }
  42. $db = DB::getDB();
  43. $groups = $this->fetchGroups();
  44. if (empty($groups)) {
  45. return false;
  46. }
  47. $sql = "select p.`ID`
  48. from `CRM_PROCES` as p
  49. left join `CRM_WSKAZNIK` as w on(p.`ID`=w.`ID_PROCES`)
  50. where
  51. w.`ID_ZASOB` in(" . implode(",", array_keys($groups)) . ")
  52. and w.`A_STATUS` in('NORMAL', 'WAITING')
  53. and p.`A_STATUS` in('NORMAL', 'WAITING')
  54. ";
  55. $res = $db->query($sql);
  56. while ($r = $db->fetch($res)) {
  57. $this->_proces_ids [$r->ID] = true;
  58. }
  59. $this->_proces_ids = array_keys($this->_proces_ids);
  60. return $this->_proces_ids;
  61. }
  62. function getProcesTree() {
  63. if (!empty($this->_proces_tree_flat)) {
  64. return $this->_proces_tree_flat;
  65. }
  66. $db = DB::getDB();
  67. $sql = "select p.`ID`, p.`PARENT_ID`
  68. from `CRM_PROCES` as p
  69. where p.`A_STATUS` in('WAITING','NORMAL')
  70. union
  71. select p.`IF_TRUE_GOTO` as ID, p.`ID` as PARENT_ID
  72. from `CRM_PROCES` as p
  73. where p.`A_STATUS` in('WAITING','NORMAL')
  74. and p.IF_TRUE_GOTO>0
  75. and p.IF_TRUE_GOTO_FLAG='GOTO_AND_RETURN'
  76. ";
  77. // union select '83','122' union select p.`ID` as ID, p.`IF_TRUE_GOTO` as PARENT_ID from `CRM_PROCES` as p where p.`A_STATUS` in('WAITING','NORMAL') and p.IF_TRUE_GOTO>0
  78. //union select '83','122'
  79. //union select '83','2025'
  80. $res = $db->query($sql);
  81. while ($r = $db->fetch($res)) {
  82. $this->_proces_tree_flat[$r->PARENT_ID][] = $r->ID;
  83. }
  84. return $this->_proces_tree_flat;
  85. }
  86. private function _createUsedProcesMap() {// TODO: RM
  87. if (!empty($this->_proces_used_ids)) {
  88. return;
  89. }
  90. $this->_proces_used_ids = $this->_cache_read('_proces_used_ids');
  91. $this->_proces_used_map = $this->_cache_read('_proces_used_map');
  92. if ($this->_proces_used_ids != null && $this->_proces_used_map != null) {
  93. return;
  94. }
  95. $this->_proces_used_ids = array();// find path from proces_id connected with user to the end of process
  96. $this->_proces_used_map = array();
  97. $dbg = false;
  98. $ID_PROCESOW_USERA = $this->getProcesIds();
  99. if (empty($ID_PROCESOW_USERA)) {
  100. return;
  101. }
  102. $CRM_PROCESS_TREE = $this->getProcesTree();
  103. // ! rekursywnie szukam sciezek procesow powiazanych dla usera procesow
  104. foreach ($ID_PROCESOW_USERA as $proces_id) {
  105. $this->_proces_used_ids[$proces_id] = true;
  106. if ($dbg) echo '<div style="border:1px solid blue;background-color:#eee;">' . "<b>find_rec(CRM_PROCESS_TREE, {$proces_id}, 'init') {</b>\n";
  107. $CRM_PROCES_USERA_UZYTY_FIND = array();
  108. $this->find_in_tree_parent_rec($CRM_PROCESS_TREE, $proces_id, $CRM_PROCES_USERA_UZYTY_FIND, $dbg);
  109. if ($dbg) echo '</div>';
  110. $this->_proces_used_ids[$proces_id] = true;//trzeba dodac sam proces, bo go brakuje w indeksach
  111. $this->_proces_used_map[$proces_id][] = $proces_id;//trzeba dodac sam proces, bo go brakowalo w indeksach
  112. if (is_array($CRM_PROCES_USERA_UZYTY_FIND)) {
  113. foreach ($CRM_PROCES_USERA_UZYTY_FIND as $INDEX => $proces_id_found ) {
  114. $this->_proces_used_ids[$proces_id_found] = true;
  115. $this->_proces_used_map[$proces_id][] = $proces_id_found;//tworze mape procesow od glownego w dol
  116. }
  117. }
  118. }
  119. $this->_proces_used_ids = array_keys($this->_proces_used_ids);
  120. $this->_cache_save('_proces_used_ids', $this->_proces_used_ids);
  121. $this->_cache_save('_proces_used_map', $this->_proces_used_map);
  122. }
  123. public function getUsedProcesMap() {// TODO: RM, used in ProcesMenu (testy) - use view instead
  124. $this->_createUsedProcesMap();
  125. return $this->_proces_used_map;
  126. }
  127. public function getUsedProcesIds($procesID = null) {// TODO: RM, used in ProcesMenu
  128. $this->_createUsedProcesMap();
  129. $usedProcesListIds = $this->_proces_used_ids;
  130. if ($procesID > 0) {
  131. $map = $this->getUsedProcesMap();
  132. if (!array_key_exists($procesID, $map)) {
  133. return false;
  134. }
  135. $usedProcesListIds = $map[$procesID];
  136. }
  137. return $usedProcesListIds;
  138. }
  139. public function getUsedProcesInitIds($zasobId = 0) {// TODO: RM, used in ProcesMenu
  140. if ($zasobId > 0) {
  141. $pInitListRaw = $this->getProcesInitList($zasobId);
  142. if (!empty($pInitListRaw)) {
  143. $pInitListRaw = array_values($pInitListRaw);
  144. $pInitListRaw = array_unique($pInitListRaw);
  145. }
  146. return $pInitListRaw;
  147. } else {
  148. $usedProcesInitList = $this->getUsedProcesInitList();
  149. return array_keys($usedProcesInitList);
  150. }
  151. }
  152. public function getUsedProcesInitList() {// TODO: RM, used in ProcesMenu
  153. if (!empty($this->_proces_init_used)) {
  154. return $this->_proces_init_used;
  155. }
  156. $map = $this->getUsedProcesMap();
  157. if (!empty($map)) {
  158. $db = DB::getDB();
  159. $sql = "select `ID`, `DESC`
  160. from `CRM_PROCES`
  161. where `TYPE`='PROCES_INIT' and `ID` in (" . implode(",", array_keys($map)) . ") ";
  162. $res = $db->query($sql);
  163. while ($r = $db->fetch($res)) {
  164. $this->_proces_init_used[$r->ID] = $r->DESC;
  165. }
  166. }
  167. return $this->_proces_init_used;
  168. }
  169. function find_in_tree_parent_rec(&$tree, $parent_id, &$ret_array = array(), $dbg = false, $rec_limit = 1) {// TODO: RM used in _createUsedProcesMap
  170. if ($dbg) { echo '<p style="margin:0;">' . "find_in_tree_parent_rec(tree, $parent_id, ret, $dbg, $rec_limit) find_in_tree_parent_rec_return: [" . implode(', ', $find_in_tree_parent_rec_return) . "] found(" . in_array($parent_id, $ret_array) . ")" .'</p>'; }
  171. if (isset($tree[$parent_id])) {
  172. foreach ($tree[$parent_id] as $IND => $CHILD) {
  173. if (in_array($CHILD, $ret_array)) {
  174. continue;
  175. }
  176. $ret_array[] = $CHILD;
  177. if ($dbg) { echo '<p style="margin:0;">' . "-- find_in_tree_parent_rec(tree, $parent_id, ret, $dbg, $rec_limit) crm_proces_usera_uzyty: [" . implode(', ', $ret_array) . "]" .'</p>'; }
  178. // TODO: $ret_array będize mial tylko wartosci z ostatniego wyszukiwania
  179. $this->find_in_tree_parent_rec($tree, $CHILD, $ret_array, $dbg, $rec_limit);
  180. }
  181. }
  182. }
  183. function _cache_init() {
  184. if (!$this->_use_cache) return;
  185. if (!isset($_SESSION['UserAcl_cache'])) {
  186. $_SESSION['UserAcl_cache'] = array();
  187. }
  188. else {
  189. $user_id = V::get('_user_id', 0, $_SESSION['UserAcl_cache'], 'int');
  190. if ($user_id > 0) {
  191. if ($user_id != $this->_user_id) {
  192. // clean cache if another user
  193. $_SESSION['UserAcl_cache'] = array();
  194. }
  195. }
  196. }
  197. }
  198. function _cache_clear() {
  199. if (!$this->_use_cache) return;
  200. $_SESSION['UserAcl_cache'] = array();
  201. }
  202. /**
  203. * Read data from cache.
  204. */
  205. function _cache_read($key) {
  206. if (!$this->_use_cache) return null;
  207. if (array_key_exists($key, $_SESSION['UserAcl_cache'])) {
  208. return $_SESSION['UserAcl_cache'][$key];
  209. }
  210. return null;
  211. }
  212. /**
  213. * Save data in cache.
  214. */
  215. function _cache_save($key, $value) {
  216. if (!$this->_use_cache) return;
  217. if ($key == 'foundTables') {
  218. $tblIds = array();
  219. foreach ($value as $idTable => $tableConfig) {
  220. $tblIds[] = $idTable;
  221. $vTableAcl = TableAcl::buildInstance($idTable, $tableConfig);
  222. }
  223. $value = $tblIds;
  224. }
  225. $_SESSION['UserAcl_cache'][$key] = $value;
  226. }
  227. public function getUrls() {
  228. $urls = $this->_cache_read('foundUrls');// TODO: old ['MENU_SELECT_PROCES_DATA']['MENU_COLUMN']
  229. if (empty($urls)) $urls = array();
  230. return $urls;
  231. }
  232. public function getObjectAcl($sourceName, $objName) {
  233. if ('default_db' == $sourceName) {
  234. $zasobTblInfo = ProcesHelper::getZasobTableInfoByUri("{$sourceName}/{$objName}");
  235. if ($zasobTblInfo) {
  236. if ($this->hasTableAcl($zasobTblInfo->ID)) {
  237. return $this->getTableAcl($zasobTblInfo->ID);
  238. }
  239. }
  240. }
  241. else {
  242. throw new HttpException("Not Implemented", 501);
  243. }
  244. return false;
  245. }
  246. public function getTablesAcl() {// TODO: read from `CRM_PROCES_idx_TABLE_TO_USER_VIEW`
  247. $tbls = array();
  248. $tblIds = $this->_cache_read('foundTables');
  249. foreach ($tblIds as $vTableID) {
  250. $tbls[$vTableID] = TableAcl::getInstance($vTableID);
  251. }
  252. return $tbls;
  253. }
  254. public function hasTableAcl($tableID) {// TODO: read from `CRM_PROCES_idx_TABLE_TO_USER_VIEW`
  255. $tbls = $this->_cache_read('foundTables');
  256. return (is_array($tbls) && in_array($tableID, $tbls));
  257. }
  258. public function getTableAcl($tableID) {
  259. return TableAcl::getInstance($tableID);
  260. }
  261. public function getProcesInitList($tblId) {
  262. if ($tblId > 0) {
  263. $map = $this->_cache_read('foundMap');
  264. if (is_array($map) && array_key_exists($tblId, $map)) {
  265. return $map[$tblId];
  266. }
  267. }
  268. return null;
  269. }
  270. /**
  271. * Check if perms are only for one proces.
  272. * @returns int or false
  273. */
  274. public function getPermsFiltrProcesId() {// TODO: RMME mved to getFilterIdProces
  275. return $this->getFilterIdProces();
  276. }
  277. public function getFilterIdProces() {
  278. $procesID = $this->_cache_read('permsByProcesID');
  279. return ($procesID > 0)? $procesID : false;
  280. }
  281. public function fetchAllPerms($force = false) {
  282. $this->_fetchPerms('All', $force);
  283. }
  284. public function fetchProcesPerms($procesID, $force = false) {
  285. $this->_fetchPerms($procesID, $force);
  286. }
  287. /**
  288. * @param $type - 'All', $procesID
  289. */
  290. private function _fetchPerms($type, $force = false) {
  291. $db = DB::getDB();
  292. $procesID = 0;// if 0 - All, alse perms by procesID
  293. $foundUrls = array();
  294. $foundTbls = array();
  295. if ($force) {
  296. $this->_cache_clear();
  297. }
  298. $schemaReader = new SchemaReader();
  299. if ($type == 'All') {
  300. $schemaReader->getAll();
  301. } else if (is_numeric($type) && $type > 0) {
  302. $procesID = (int)$type;
  303. }
  304. {// TODO: fetch from schema files
  305. if ($schemaReader->hasProcessConfigs()) {
  306. foreach ($schemaReader->getProcessConfigs() as $process) {
  307. DBG::_('DBG_SCH', '1', "process", $process, __CLASS__, __FUNCTION__, __LINE__ );
  308. if ($process->hasAccess()) {
  309. $tables = $process->getTables();
  310. DBG::_('DBG_SCH', '1', "tables", $tables, __CLASS__, __FUNCTION__, __LINE__ );
  311. foreach ($tables as $vTable) {
  312. $tblUri = $vTable->getUri();
  313. $zasobTblInfo = ProcesHelper::getZasobTableInfoByUri($tblUri);
  314. DBG::_('DBG_SCH', '1', "table(" . $vTable->getLabel() . ")", $zasobTblInfo, __CLASS__, __FUNCTION__, __LINE__ );
  315. if ($zasobTblInfo) {
  316. $idTable = $zasobTblInfo->ID;
  317. // TODO: use $vTableAcl = TableAcl::buildInstance($idTable, $tableConfig);
  318. // TODO: then $vTableAcl->init();// to save table fields
  319. if (!array_key_exists($idTable, $foundTbls)) {
  320. $tableConfig = array();
  321. $tableConfig['ID_TABLE'] = $idTable;
  322. $tableConfig['db'] = $zasobTblInfo->P__ID;
  323. $tableConfig['name'] = $zasobTblInfo->DESC;
  324. $tableConfig['label'] = $zasobTblInfo->DESC_PL;
  325. $tableConfig['opis'] = $zasobTblInfo->OPIS;
  326. $foundTbls[$idTable] = $tableConfig;
  327. }
  328. $tableAcl = TableAcl::buildInstance($idTable, $foundTbls[$idTable]);
  329. $fieldsConfig = array();
  330. $fldsInfo = ProcesHelper::getZasobTableFieldsInfo($idTable);
  331. foreach ($vTable->getFields() as $field) {
  332. $fldInfo = V::get($field->getName(), null, $fldsInfo);
  333. if ($fldInfo) {
  334. if (!array_key_exists($fldInfo->ID, $fieldsConfig)) {//if (!$tableAcl->hasField($fldInfo->ID)) {
  335. $fieldsConfig[$fldInfo->ID] = array();
  336. $fieldsConfig[$fldInfo->ID]['ID_CELL'] = $fldInfo->ID;
  337. $fieldsConfig[$fldInfo->ID]['CELL_NAME'] = $fldInfo->DESC;
  338. $fieldsConfig[$fldInfo->ID]['CELL_DESC'] = $fldInfo->OPIS;
  339. $fieldsConfig[$fldInfo->ID]['SORT_PRIO'] = $fldInfo->SORT_PRIO;
  340. $fieldsConfig[$fldInfo->ID]['CELL_LABEL'] = $fldInfo->DESC_PL;
  341. $fieldsConfig[$fldInfo->ID]['FORM_TREAT'] = '';
  342. //$tableAcl->addField($fldInfo->ID, $fldInfo->DESC, $fldInfo->OPIS, $fldInfo->SORT_PRIO, $fldInfo->DESC_PL);
  343. }
  344. // TODO: $field->getPerms() -> PERM_R, PERM_W, ... etc.?
  345. $fieldsConfig[$fldInfo->ID]['FORM_TREAT'] .= $field->getPerms();//$tableAcl->setFieldPerms($fldInfo->ID, $field->getPerms());
  346. }
  347. }
  348. $tableAcl->initFieldsFromConfig($fieldsConfig);
  349. DBG::_('DBG_SCH', '1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
  350. $tableAcl->save();
  351. DBG::_('DBG_SCH', '1', "tableAcl({$idTable})", $tableAcl, __CLASS__, __FUNCTION__, __LINE__);
  352. }
  353. }
  354. }
  355. }
  356. } else {
  357. DBG::_('DBG_SCH', '1', "NO \$schemaReader->hasProcessConfigs()", null, __CLASS__, __FUNCTION__, __LINE__);
  358. }
  359. DBG::_('DBG_SCH', '1', "foundTbls", $foundTbls, __CLASS__, __FUNCTION__, __LINE__);
  360. }// fetch from schema files
  361. $this->setFilterIdProces($procesID);//$this->_cache_save('permsByProcesID', $procesID);
  362. if (1) {
  363. $sqlIdProcesListSql = $this->getUsedUserProcesIdsSql();
  364. $userAccessForTables = array();
  365. $sql = <<<SQL
  366. select tpvg.`ID_TABLE`
  367. , tpvg.`ID_DATABASE` as `db`
  368. , tpvg.`TABLE_NAME` as `name`
  369. , tpvg.`TABLE_LABEL` as `label`
  370. , tpvg.`TABLE_DESCRIPTION` as `opis`
  371. from `CRM_PROCES_idx_TABLE_TO_PROCES_GROUPED_VIEW` as tpvg
  372. where tpvg.`ID_PROCES` in({$sqlIdProcesListSql})
  373. group by tpvg.`ID_TABLE`
  374. SQL;
  375. //echo'<pre>$userAccessForTables - $sql ';print_r($sql);echo'</pre>';
  376. $db = DB::getDB();
  377. $res = $db->query($sql);
  378. while ($h = $db->fetch_assoc($res)) {
  379. $userAccessForTables[$h['ID_TABLE']] = $h;
  380. }
  381. DBG::_('DBG_SCH', '1', "userAccessForTables", $userAccessForTables, __CLASS__, __FUNCTION__, __LINE__ );
  382. foreach ($userAccessForTables as $idTable => $tableConfig) {
  383. if (!array_key_exists($idTable, $foundTbls)) {
  384. $foundTbls[$idTable] = $tableConfig;
  385. }
  386. }
  387. $userAccessForUrls = array();
  388. $sql = <<<SQL
  389. select upvg.`ID_URL`
  390. , upvg.`URL_LINK` as `link`
  391. , upvg.`URL_LABEL` as `label`
  392. , upvg.`URL_DESC` as `opis`
  393. from `CRM_PROCES_idx_URL_TO_PROCES_VIEW` as upvg
  394. where upvg.`ID_PROCES` in({$sqlIdProcesListSql})
  395. group by upvg.`ID_URL`
  396. SQL;
  397. //echo'<pre>$userAccessForUrls - $sql ';print_r($sql);echo'</pre>';
  398. $db = DB::getDB();
  399. $res = $db->query($sql);
  400. while ($h = $db->fetch_assoc($res)) {
  401. $userAccessForUrls[$h['ID_URL']] = $h;
  402. }
  403. //echo'<pre>$userAccessForUrls ';print_r($userAccessForUrls);echo'</pre>';
  404. //TODO: $foundUrls = $userAccessForUrls;
  405. }
  406. $this->_cache_save('foundUrls', $foundUrls);
  407. $this->_cache_save('foundTables', $foundTbls);
  408. }
  409. public function setFilterIdProces($procesID) {
  410. $this->_cache_save('permsByProcesID', $procesID);
  411. }
  412. public function getPermsForTable($idTable) {
  413. $sqlIdProcesListSql = $this->getUsedUserProcesIdsSql();
  414. $tableCellToProcesSql = <<<SQL
  415. select z.`ID` as `ID_CELL`
  416. , z.`DESC` as `CELL_NAME`
  417. , z.`DESC_PL` as `CELL_LABEL`
  418. , z.`OPIS` as `CELL_DESC`
  419. , z.`SORT_PRIO` as `SORT_PRIO`
  420. , zp.`ID` as `ID_TABLE`
  421. -- , zp.`DESC` as `TABLE_NAME`
  422. -- , wsk.`ID_PROCES` as `ID_PROCES`
  423. , sum(IF(przyp.`FORM_TREAT` & 2, 1, 0)) as PERM_R
  424. , sum(IF(przyp.`FORM_TREAT` & 4, 1, 0)) as PERM_W
  425. , sum(IF(przyp.`FORM_TREAT` & 8, 1, 0)) as PERM_X
  426. , sum(IF(przyp.`FORM_TREAT` & 16, 1, 0)) as PERM_C
  427. , sum(IF(przyp.`FORM_TREAT` & 32, 1, 0)) as PERM_S
  428. , sum(IF(przyp.`FORM_TREAT` & 64, 1, 0)) as PERM_O
  429. , sum(IF(przyp.`FORM_TREAT` & 128, 1, 0)) as PERM_V
  430. , sum(IF(przyp.`FORM_TREAT` & 256, 1, 0)) as PERM_E
  431. from `CRM_LISTA_ZASOBOW` z
  432. join `CRM_LISTA_ZASOBOW` zp on(zp.`ID`=z.`PARENT_ID` and zp.`TYPE`='TABELA' and zp.`A_STATUS` in('WAITING','NORMAL'))
  433. join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=z.`ID` and wsk.`A_STATUS` in('WAITING','NORMAL'))
  434. join `CRM_PROCES` p on(p.`ID`=wsk.`ID_PROCES` and p.`A_STATUS` in('WAITING','NORMAL'))
  435. join `CRM_PRZYPADEK` as przyp on (przyp.`ID`=wsk.`ID_PRZYPADEK`)
  436. where z.`TYPE`='KOMORKA'
  437. and z.`A_STATUS` in('WAITING','NORMAL')
  438. and zp.`ID`='{$idTable}'
  439. and wsk.`ID_PROCES` in({$sqlIdProcesListSql})
  440. -- group by z.`ID`, wsk.`ID_PROCES`
  441. group by z.`ID`
  442. order by z.`SORT_PRIO`
  443. SQL;
  444. //echo'<pre>UserAcl::getPermsForTable('.$idTable.')::$tableCellToProcesSql ';print_r($tableCellToProcesSql);echo'</pre>';
  445. $userPermsForTable = array();
  446. $db = DB::getDB();
  447. $res = $db->query($tableCellToProcesSql);
  448. while ($h = $db->fetch_assoc($res)) {
  449. $idCell = $h['ID_CELL'];
  450. $userPermsForTable[$idCell] = $h;
  451. }
  452. return $userPermsForTable;
  453. }
  454. public function getUsedUserGroupIds() {
  455. $idUserGroupList = User::getGroupsIds();
  456. // TODO: acl filtr by group ids
  457. return $idUserGroupList;
  458. }
  459. public function getUsedUserProcesIdsSql() {
  460. $filterIdProces = $this->getFilterIdProces();
  461. if ($filterIdProces > 0) {
  462. return <<<SQL
  463. select i.`ID_PROCES`
  464. from `CRM_PROCES_idx` i
  465. where i.`idx_PROCES_INIT_ID`='{$filterIdProces}'
  466. SQL;
  467. }
  468. $idUserGroupList = $this->getUsedUserGroupIds();
  469. $sqlIdUserGroupList = implode(",", $idUserGroupList);
  470. // TODO: acl filtr by proces id
  471. return <<<SQL
  472. select gi.`ID_PROCES`
  473. from `CRM_PROCES_idx_GROUP_to_PROCES` gi
  474. where gi.`ID_GROUP` in({$sqlIdUserGroupList})
  475. SQL;
  476. }
  477. }