superedit-GROUP_ADD_NESTEDGROUPS.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <?php
  2. /**
  3. * @param $_GET['groupID'] - id grupy - zasob typu: 'STANOWISKO', 'PODMIOT', 'DZIAL'
  4. *
  5. * example:
  6. * index.php?MENU_INIT=GROUP_ADD_NESTEDGROUPS&groupID=13
  7. */
  8. function GROUP_ADD_NESTEDGROUPS() {
  9. Lib::loadClass('UserStorage');
  10. $linkTypeIdNestedGroups = 5;
  11. $taskMsgs = array();
  12. $taskErrors = array();
  13. $task = V::get('_task', '', $_REQUEST);
  14. switch ($task) {
  15. case 'FRM_RM_PARENT_GROUP': {
  16. $groupID = V::get('groupID', 0, $_GET, 'int');
  17. $rmParentGroupID = V::get('rmParentGroupID', 0, $_POST, 'int');
  18. if (!$groupID || !$rmParentGroupID) {
  19. $taskErrors[] = 'Wrong param group id or remove group id!';
  20. }
  21. else {
  22. $usrStorageDB = UserStorage::getStorage('DB');
  23. $group = $usrStorageDB->getGroupWithoutNested($groupID);
  24. $parentGroup = $usrStorageDB->getGroupWithoutNested($rmParentGroupID);
  25. if ($group && $parentGroup) {
  26. $removed = $usrStorageDB->removeParentGroup($groupID, $parentGroup);
  27. if ($removed) {
  28. $taskMsgs[] = "Usunięto grupę nadrzędną [{$rmParentGroupID}] do grupy [{$groupID}]";
  29. } else {
  30. $taskErrors[] = "Nie udało się usunąć grupy nadrzędnej [{$rmParentGroupID}] do grupy [{$groupID}]";
  31. }
  32. }
  33. }
  34. break;
  35. }
  36. case 'FRM_RM_NESTED_GROUP': {
  37. $groupID = V::get('groupID', 0, $_GET, 'int');
  38. $rmNestedGroupID = V::get('rmNestedGroupID', 0, $_POST, 'int');
  39. if (!$groupID || !$rmNestedGroupID) {
  40. $taskErrors[] = 'Wrong param group id or remove group id!';
  41. }
  42. else {
  43. $usrStorageDB = UserStorage::getStorage('DB');
  44. $group = $usrStorageDB->getGroupWithoutNested($groupID);
  45. $nestedGroup = $usrStorageDB->getGroupWithoutNested($rmNestedGroupID);
  46. if ($group && $nestedGroup) {
  47. $removed = $usrStorageDB->removeNestedGroup($groupID, $nestedGroup);
  48. if ($removed) {
  49. $taskMsgs[] = "Usunięto grupę zagnieżdżoną [{$rmNestedGroupID}] z grupy [{$groupID}]";
  50. } else {
  51. $taskErrors[] = "Nie udało się usunąć grupy zagnieżdżonej [{$rmNestedGroupID}] z grupy [{$groupID}]";
  52. }
  53. }
  54. }
  55. break;
  56. }
  57. case 'FRM_ADD_GROUP': {
  58. if(V::get('DBG_NG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">post (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_POST);echo'</pre>';}
  59. // [addParentGroupID] => 372
  60. // [addNestedGroupID] => 372
  61. $groupID = V::get('groupID', 0, $_GET, 'int');
  62. if ($groupID > 0) {
  63. $usrStorageDB = UserStorage::getStorage('DB');
  64. $group = $usrStorageDB->getGroupWithoutNested($groupID);
  65. $addParentGroupID = V::get('addParentGroupID', 0, $_POST, 'int');
  66. $addNestedGroupID = V::get('addNestedGroupID', 0, $_POST, 'int');
  67. if ($addParentGroupID > 0) {
  68. $group = $usrStorageDB->getGroupWithoutNested($groupID);
  69. $parentGroup = $usrStorageDB->getGroupWithoutNested($addParentGroupID);
  70. if ($group && $parentGroup) {
  71. $added = $usrStorageDB->addParentGroup($groupID, $parentGroup);
  72. if ($added) {
  73. $taskMsgs[] = "Dodano grupę nadrzędną [{$addParentGroupID}] do grupy [{$groupID}]";
  74. } else {
  75. $taskErrors[] = "Nie udało się dodać grupy nadrzędnej [{$addParentGroupID}] do grupy [{$groupID}]";
  76. }
  77. }
  78. }
  79. else if ($addNestedGroupID > 0) {
  80. $group = $usrStorageDB->getGroupWithoutNested($groupID);
  81. $nestedGroup = $usrStorageDB->getGroupWithoutNested($addNestedGroupID);
  82. if ($group && $nestedGroup) {
  83. $added = $usrStorageDB->addNestedGroup($groupID, $nestedGroup);
  84. if ($added) {
  85. $taskMsgs[] = "Dodano grupę zagnieżdżoną [{$addNestedGroupID}] do grupy [{$groupID}]";
  86. } else {
  87. $taskErrors[] = "Nie udało się dodać grupy zagnieżdżonej [{$addNestedGroupID}] do grupy [{$groupID}]";
  88. }
  89. }
  90. }
  91. }
  92. break;
  93. }
  94. case 'TYPESPECIAL': {
  95. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  96. header("Content-type: application/json");
  97. $fld = V::get('fld', '', $_GET);
  98. switch ($fld) {
  99. case 'addParentGroupID':
  100. case 'addNestedGroupID': {
  101. Lib::loadClass('TypespecialVariable');
  102. $typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
  103. $query = V::get('q', '', $_REQUEST);
  104. $rawRows = null;
  105. $rows = $typeSpecialNestedGroups->getValuesWithExports($query);
  106. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
  107. foreach ($rows as $kID => $vItem) {
  108. $itemJson = new stdClass();
  109. $itemJson->id = $vItem->id;
  110. $itemJson->name = $vItem->param_out;
  111. if (!empty($vItem->exports)) {
  112. $itemJson->exports = $vItem->exports;
  113. }
  114. $jsonData[] = $itemJson;
  115. }
  116. echo json_encode($jsonData);
  117. break;
  118. }
  119. }
  120. exit;
  121. }
  122. }
  123. SE_Layout::menu();
  124. Lib::loadClass('UserActivity');
  125. Lib::loadClass('ProcesHelper');
  126. $zasobID = ProcesHelper::getZasobTableID('ITEM_LINKS');
  127. if ($zasobID <= 0) {
  128. echo UserActivity::showListInContainer();
  129. return;
  130. }
  131. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  132. if (!$zasobObj) {
  133. echo '<div class="alert alert-error">' . "Zasob TABELA ID={$zasobID} nie istnieje" . '</div>';
  134. echo UserActivity::showSimpleList();
  135. return;
  136. }
  137. $groupID = V::get('groupID', 0, $_GET, 'int');
  138. if (!$groupID) {
  139. echo '<div class="alert alert-error">Wrong param group id!</div>';
  140. return;
  141. }
  142. if (V::get('_testUsrGroupsLdapLvl0', '', $_GET)) {
  143. Lib::loadClass('UsersLdapHelper');
  144. $usrLogin = User::getLogin();
  145. $groups = array(); $groupsLvl3 = array();
  146. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 0);
  147. foreach ($groupsNetwork as $vGroup) {
  148. $groups[$vGroup->cn] = $vGroup->appleUID;
  149. }
  150. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;font-size:10px;">groups ldap lvl 0 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groups);echo'</pre>';
  151. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
  152. foreach ($groupsNetwork as $vGroup) {
  153. $groupsLvl3[$vGroup->cn] = $vGroup->appleUID;
  154. }
  155. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;font-size:10px;">groups ldap lvl 3 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupsLvl3);echo'</pre>';
  156. }
  157. Lib::loadClass('UserStorage');
  158. $usrStorageDB = UserStorage::getStorage('DB');
  159. if (!$usrStorageDB) {
  160. echo '<div class="alert alert-error">Error storage not exists!</div>';
  161. return;
  162. }
  163. $group = $usrStorageDB->getGroup($groupID);
  164. if (!$group) {
  165. echo '<div class="alert alert-error">' . "Grupa {$groupID} nie istnieje." . '</div>';
  166. return;
  167. }
  168. $group->parentGroups = $usrStorageDB->fetchParentGroups($groupID);
  169. if(V::get('DBG_NG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$group (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($group);echo'</pre>';}
  170. UserActivity::add($zasobID);
  171. $userAcl = User::getAcl();
  172. $userAcl->fetchGroups();
  173. if (!$userAcl->hasTableAcl($zasobObj->ID)) {
  174. echo '<div class="alert alert-error">' . "Brak uprawnień do tabeli ID={$zasobObj->ID}" . '</div>';
  175. echo UserActivity::showSimpleList();
  176. return;
  177. }
  178. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  179. $forceTblAclInit = ('1' == V::get('_force', '', $_GET));
  180. $tblAcl->init($forceTblAclInit);
  181. Lib::loadClass('TableAjax');
  182. $forceFilterInit = array();
  183. $filterInit = new stdClass();
  184. $filterInit->currSortCol = 'ID';
  185. $filterInit->currSortFlip = 'desc';
  186. foreach ($_GET as $k => $v) {
  187. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  188. $filterInit->$k = $v;
  189. }
  190. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  191. $filterInit->$k = $v;
  192. }
  193. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  194. $fldName = substr($k, 3);
  195. $forceFilterInit[$fldName] = $v;
  196. }
  197. }
  198. $tblZasobyID = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
  199. $forceFilterInit['TABLE_1_NAME'] = 'CRM_LISTA_ZASOBOW';
  200. $forceFilterInit['TABLE_1_ZASOB_ID'] = $tblZasobyID;
  201. $forceFilterInit['TABLE_1_ID'] = $group->zasobID;
  202. $forceFilterInit['TABLE_2_NAME'] = 'CRM_LISTA_ZASOBOW';
  203. $forceFilterInit['TABLE_2_ZASOB_ID'] = $tblZasobyID;
  204. $forceFilterInit['LINKS_TYPE_ID'] = $linkTypeIdNestedGroups;
  205. $tbl = new TableAjax($tblAcl);
  206. $tbl->setLabel($zasobObj->OPIS);
  207. $tbl->setFilterInit($filterInit);
  208. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  209. $tbl->addRowFunction('edit');
  210. $tbl->addRowFunction('hist');
  211. $tbl->addRowFunction('files');
  212. $tbl->addRowFunction('cp');
  213. $tbl->showProcesInit(false);// hide Proces filter field
  214. Lib::loadClass('TypespecialVariable');
  215. $typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
  216. $groupUsers = array();
  217. $groupNestedUsers = array();
  218. $tblUsrsZasobId = ProcesHelper::getZasobTableID('ADMIN_USERS');
  219. if ($group->zasobID > 0) {
  220. $groupUsers = UsersHelper::getUsersByGroupId($groupID);
  221. $groupNestedUsers = UsersHelper::getUsersByGroupsIds(array_keys($group->nestedGroups), array_keys($groupUsers));
  222. }
  223. ?>
  224. <style type="text/css">
  225. .frm-groups .selectize-control { float:left; }
  226. .conn_groups {}
  227. .conn_groups .conn_groups-list {}
  228. .conn_groups .conn_groups-list .conn_groups-list_item { line-height:22px; }
  229. .conn_groups .conn_groups-list .conn_groups-list_item form { display:inline; margin:0; }
  230. .conn_groups .conn_groups-list_item-rmBtn { display:inline; margin:0; padding:0 6px; border:none; opacity:0.4; }
  231. .conn_groups .conn_groups-list_item-editBtn { margin:0 6px; padding:0; border:none; opacity:0.4; }
  232. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { display:inline; opacity:1; }
  233. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-editBtn { opacity:1; }
  234. .users-with-perms {}
  235. .users-with-perms address { padding:0 6px; border:1px solid #eee; }
  236. .users-with-perms address:hover { border-color:#333; }
  237. </style>
  238. <div class="container conn_groups">
  239. <h3>Grupy uprawnień
  240. <!-- <em style="color:#ccc;">(Nested Groups)</em> -->
  241. </h3>
  242. <p>
  243. <b>Zasób [<?php echo $groupID; ?>]</b>: <?php echo $group->type; ?> <?php echo $group->zasobDESC; ?>
  244. <a class="btn btn-mini btn-primary" href="index.php?MENU_INIT=SYNC_LDAP_PERMS&syncGroup=<?php echo $groupID; ?>">synchronizuj do LDAP</a>
  245. </p>
  246. <br>
  247. <div class="row">
  248. <div class="span6">
  249. <?php if (!empty($taskErrors)) : ?>
  250. <div class="alert alert-error">
  251. <button type="button" class="close" data-dismiss="alert">×</button>
  252. <?php echo implode('<br>', $taskErrors); ?>
  253. </div>
  254. <?php endif; ?>
  255. <?php if (!empty($taskMsgs)) : ?>
  256. <div class="alert alert-success">
  257. <button type="button" class="close" data-dismiss="alert">×</button>
  258. <?php echo implode('<br>', $taskMsgs); ?>
  259. </div>
  260. <?php endif; ?>
  261. <!-- <p><b>Grupy posiadające dostęp do rekordów grupy [<?php echo $group->zasobID; ?>] <?php echo $group->zasobDESC; ?></b> <em>(<?php echo (!empty($group->parentGroups))? count($group->parentGroups) : 0; ?>)</em>:
  262. </p> -->
  263. <blockquote>
  264. <!-- <h5>Ustal grupy, które będą miały uprawnienia do rekordów dostępnych dla
  265. [<?php echo $group->zasobID; ?>] <?php echo $group->zasobDESC; ?>
  266. </h5>
  267. <small>np. grupy podrzędnych pracowników.</small> -->
  268. <h5>Udostępnij rekordy innym grupom</h5>
  269. <small>np. przełożonemu.</small>
  270. </blockquote>
  271. <ul class="conn_groups-list">
  272. <?php if (!empty($group->nestedGroups)) : ?>
  273. <?php foreach ($group->nestedGroups as $vNestedGroup) : ?>
  274. <li class="conn_groups-list_item">
  275. [<?php echo $vNestedGroup->zasobID; ?>]
  276. <?php echo $vNestedGroup->type; ?>
  277. <?php echo $vNestedGroup->zasobDESC; ?>
  278. <a href="index.php?MENU_INIT=GROUP_ADD_NESTEDGROUPS&groupID=<?php echo $vNestedGroup->zasobID; ?>" class="ico-pencil conn_groups-list_item-editBtn" title="Edytuj grupę"> </a>
  279. <form action="" method="POST" class="form-inline frm-groups">
  280. <input type="hidden" name="_task" value="FRM_RM_NESTED_GROUP">
  281. <button name="rmNestedGroupID" value="<?php echo $vNestedGroup->zasobID; ?>" class="btn-link btn-small conn_groups-list_item-rmBtn" title="usuń grupę"><i class="ico-remove"></i></button>
  282. </form>
  283. </li>
  284. <?php endforeach; ?>
  285. <?php endif; ?>
  286. <?php if ($typeSpecialNestedGroups) : ?>
  287. <li>
  288. <form action="" method="POST" class="form-inline frm-groups">
  289. <input type="hidden" name="_task" value="FRM_ADD_GROUP">
  290. <?php
  291. $fName = 'addNestedGroupID';
  292. $fldParams = array();
  293. $fldParams['allowCreate'] = false;
  294. $fldParams['ajaxDataUrlBase'] = "index.php?FUNCTION_INIT=" . __FUNCTION__ . "&HEADER_NOT_INIT=YES&_task=TYPESPECIAL&fld={$fName}";
  295. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  296. echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  297. ?>
  298. <button class="btn">dodaj</button>
  299. </form>
  300. </li>
  301. <?php endif; ?>
  302. </ul>
  303. <!-- <p><b>Grupy do rekordów, których posiada dostęp grupa [<?php echo $group->zasobID; ?>] <?php echo $group->zasobDESC; ?></b> <em>(<?php echo (!empty($group->parentGroups))? count($group->parentGroups) : 0; ?>)</em>:
  304. </p> -->
  305. <blockquote>
  306. <h5>Grupy, które udostępniają rekordy</h5>
  307. <small>np. grupy podrzędnych pracowników lub dział, podmiot.</small>
  308. </blockquote>
  309. <ul class="conn_groups-list">
  310. <?php if (!empty($group->parentGroups)) : ?>
  311. <?php foreach ($group->parentGroups as $vParentGroup) : ?>
  312. <li class="conn_groups-list_item">
  313. [<?php echo $vParentGroup->zasobID; ?>]
  314. <?php // if ('DZIAL' == $vParentGroup->type) : ?>
  315. <?php echo $vParentGroup->type; ?>
  316. <?php // endif; ?>
  317. <?php echo $vParentGroup->zasobDESC; ?>
  318. <a href="index.php?MENU_INIT=GROUP_ADD_NESTEDGROUPS&groupID=<?php echo $vParentGroup->zasobID; ?>" class="ico-pencil conn_groups-list_item-editBtn" title="Edytuj grupę"> </a>
  319. <form action="" method="POST" class="form-inline frm-groups">
  320. <input type="hidden" name="_task" value="FRM_RM_PARENT_GROUP">
  321. <button name="rmParentGroupID" value="<?php echo $vParentGroup->zasobID; ?>" class="btn-link btn-small conn_groups-list_item-rmBtn" title="usuń grupę"><i class="ico-remove"></i></button>
  322. </form>
  323. </li>
  324. <?php endforeach; ?>
  325. <?php endif; ?>
  326. <?php if ($typeSpecialNestedGroups) : ?>
  327. <li>
  328. <form action="" method="POST" class="form-inline frm-groups">
  329. <input type="hidden" name="_task" value="FRM_ADD_GROUP">
  330. <?php
  331. $fName = 'addParentGroupID';
  332. $fldParams = array();
  333. $fldParams['allowCreate'] = false;
  334. $fldParams['ajaxDataUrlBase'] = "index.php?FUNCTION_INIT=" . __FUNCTION__ . "&HEADER_NOT_INIT=YES&_task=TYPESPECIAL&fld={$fName}";
  335. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  336. echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  337. ?>
  338. <button class="btn">dodaj</button>
  339. </form>
  340. </li>
  341. <?php endif; ?>
  342. </ul>
  343. </div>
  344. <div class="span6 users-with-perms">
  345. <h5>Użytkownicy:</h5>
  346. <?php if (empty($groupUsers)) : ?>
  347. <div class="alert">Brak użytkowników przypisanych bezpośrednio do grupy</div>
  348. <?php else : ?>
  349. <div class="row">
  350. <?php foreach ($groupUsers as $usr) : ?>
  351. <div class="span3">
  352. <address>
  353. <strong><?php echo $usr->ADM_NAME; ?></strong>
  354. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $tblUsrsZasobId; ?>#EDIT/<?php echo $usr->ID; ?>" class="ico-pencil" title="Edytuj rekord"> </a>
  355. <br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
  356. <?php if (!empty($usr->ADM_PHONE)) : ?>
  357. <br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
  358. <?php endif; ?>
  359. <?php if (!empty($usr->EMAIL)) : ?>
  360. <br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
  361. <?php endif; ?>
  362. </address>
  363. </div>
  364. <?php endforeach; ?>
  365. </div>
  366. <?php endif; ?>
  367. <h5>Użytwkonicy z uprawnieniami do rekordów</h5>
  368. <?php if (empty($groupNestedUsers)) : ?>
  369. <div class="alert">Brak</div>
  370. <?php else : ?>
  371. <div class="row">
  372. <?php foreach ($groupNestedUsers as $usr) : ?>
  373. <div class="span3">
  374. <address>
  375. <strong><?php echo $usr->ADM_NAME; ?></strong>
  376. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $tblUsrsZasobId; ?>#EDIT/<?php echo $usr->ID; ?>" class="ico-pencil" title="Edytuj rekord"> </a>
  377. <br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
  378. <?php if (!empty($usr->ADM_PHONE)) : ?>
  379. <br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
  380. <?php endif; ?>
  381. <?php if (!empty($usr->EMAIL)) : ?>
  382. <br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
  383. <?php endif; ?>
  384. </address>
  385. </div>
  386. <?php endforeach; ?>
  387. </div>
  388. <?php endif; ?>
  389. </div>
  390. </div>
  391. </div>
  392. <?php
  393. echo $tbl->render();
  394. }