Users.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('UserStorageFactory');
  4. Lib::loadClass('ProcesHelper');
  5. Lib::loadClass('SyncUsers');
  6. Lib::loadClass('UsersHelper');
  7. Lib::loadClass('UsersLdapHelper');
  8. Lib::loadClass('TypespecialVariable');
  9. Lib::loadClass('TableAjax');
  10. Lib::loadClass('UserActivity');
  11. class Route_Users extends RouteBase {
  12. public function handleAuth() {
  13. if (!User::logged()) {
  14. throw new HttpException('Unauthorized', 401);
  15. }
  16. }
  17. public function defaultAction() {
  18. SE_Layout::gora();
  19. SE_Layout::menu();
  20. $this->menu();
  21. SE_Layout::dol();
  22. }
  23. public function menu() {
  24. $usrLogin = User::getLogin();
  25. ?>
  26. <div class="container">
  27. <h3>Użytkownicy i grupy</h3>
  28. <ul>
  29. <li>
  30. <form class="form-inline" action="index.php" method="GET">
  31. <input type="hidden" name="_route" value="Users">
  32. <input type="hidden" name="_task" value="syncUser">
  33. <label for="usrLogin">login: </label>
  34. <input type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
  35. <input type="submit" value="Synchronizuj do bazy LDAP" class="btn btn-xs btn-default">
  36. </form>
  37. </li>
  38. <li>
  39. <form class="form-inline" action="index.php" method="GET">
  40. <input type="hidden" name="_route" value="Users">
  41. <input type="hidden" name="_task" value="userGroups">
  42. <label for="usrLogin">login: </label>
  43. <input type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
  44. <input type="submit" value="Dodaj grupy" class="btn btn-xs btn-default">
  45. </form>
  46. </li>
  47. <li>
  48. <form class="form-inline" action="index.php" method="GET">
  49. <input type="hidden" name="_route" value="Users">
  50. <input type="hidden" name="_task" value="nestedGroups">
  51. <label for="idGroup">id grupy: </label>
  52. <input type="text" name="idGroup" value="">
  53. <input type="submit" value="Grupy uprawnień" class="btn btn-xs btn-default">
  54. </form>
  55. </li>
  56. </ul>
  57. </div>
  58. <?php
  59. }
  60. public function nestedGroupsAction() {
  61. SE_Layout::gora();
  62. SE_Layout::menu();
  63. echo '<div class="container">';
  64. try {
  65. $idGroup = V::get('idGroup', 0, $_GET, 'int');
  66. if (empty($idGroup)) throw new Exception("Empty group id");
  67. $subTask = V::get('_subTask', '', $_POST);
  68. $successMsg = null;
  69. if ('removeParentGroup' == $subTask) {
  70. $idParentGroupToRemove = V::get('idParentGroupToRemove', 0, $_POST, 'int');
  71. $this->nestedGroupsRemoveParentGroup($idGroup, $idParentGroupToRemove);
  72. $successMsg = "Usunięto grupę nadrzędną [{$idParentGroupToRemove}] do grupy [{$idGroup}]";
  73. } else if ('removeNestedGroup' == $subTask) {
  74. $idNestedGroupToRemove = V::get('idNestedGroupToRemove', 0, $_POST, 'int');
  75. $this->nestedGroupsRemoveNestedGroup($idGroup, $idNestedGroupToRemove);
  76. $successMsg = "Usunięto grupę zagnieżdżoną [{$idNestedGroupToRemove}] do grupy [{$idGroup}]";
  77. } else if ('addParentGroup' == $subTask) {
  78. $idParentGroupToAdd = V::get('idParentGroupToAdd', 0, $_POST, 'int');
  79. $this->nestedGroupsAddParentGroup($idGroup, $idParentGroupToAdd);
  80. $successMsg = "Dodano grupę nadrzędną [{$idParentGroupToAdd}] do grupy [{$idGroup}]";
  81. } else if ('addNestedGroup' == $subTask) {
  82. $idNestedGroupToAdd = V::get('idNestedGroupToAdd', 0, $_POST, 'int');
  83. $this->nestedGroupsAddNestedGroup($idGroup, $idNestedGroupToAdd);
  84. $successMsg = "Dodano grupę zagnieżdżoną [{$idNestedGroupToAdd}] do grupy [{$idGroup}]";
  85. }
  86. if (!empty($successMsg)) {
  87. ?><div class="alert alert-success"><?php echo $successMsg; ?></div><?php
  88. }
  89. $this->printFormNestedGroups($idGroup);
  90. } catch (Exception $e) {
  91. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?>
  92. <br><a href="index.php?_route=Users">wróć</a>
  93. </div><?php
  94. echo UserActivity::showListInContainer();
  95. }
  96. echo '</div>';// .container
  97. SE_Layout::dol();
  98. }
  99. public function nestedGroupsRemoveParentGroup($idGroup, $idParentGroupToRemove) {
  100. if (!$idGroup) throw new Exception("Wrong param id group!");
  101. if (!$idParentGroupToRemove) throw new Exception("Wrong param id parent group to remove!");
  102. $usrStorageDB = UserStorageFactory::getStorage('DB');
  103. if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
  104. $group = $usrStorageDB->getGroupWithoutNested($idGroup);
  105. if (!$group) throw new Exception("Error: group not exists!");
  106. $parentGroup = $usrStorageDB->getGroupWithoutNested($idParentGroupToRemove);
  107. if (!$parentGroup) throw new Exception("Error: parent group not exists!");
  108. $usrStorageDB->removeParentGroup($idGroup, $idParentGroupToRemove);
  109. }
  110. public function nestedGroupsRemoveNestedGroup($idGroup, $idNestedGroupToRemove) {
  111. if (!$idGroup) throw new Exception("Wrong param id group!");
  112. if (!$idNestedGroupToRemove) throw new Exception("Wrong param id parent group to remove!");
  113. $usrStorageDB = UserStorageFactory::getStorage('DB');
  114. if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
  115. $group = $usrStorageDB->getGroupWithoutNested($idGroup);
  116. if (!$group) throw new Exception("Error: group not exists!");
  117. $nestedGroup = $usrStorageDB->getGroupWithoutNested($idNestedGroupToRemove);
  118. if (!$nestedGroup) throw new Exception("Error: nested group not exists!");
  119. $usrStorageDB->removeNestedGroup($idGroup, $idNestedGroupToRemove);
  120. }
  121. public function nestedGroupsAddParentGroup($idGroup, $idParentGroupToAdd) {
  122. if ($idGroup <= 0) throw new Exception("Wrong param id group");
  123. if ($idParentGroupToAdd <= 0) throw new Exception("Wrong param id parent group to add");
  124. $usrStorageDB = UserStorageFactory::getStorage('DB');
  125. if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
  126. $group = $usrStorageDB->getGroupWithoutNested($idGroup);
  127. if (!$group) throw new Exception("Error: group [{$idGroup}] not exists!");
  128. $parentGroup = $usrStorageDB->getGroupWithoutNested($idParentGroupToAdd);
  129. if (!$parentGroup) throw new Exception("Error: parent group [{$idParentGroupToAdd}] not exists!");
  130. $usrStorageDB->addParentGroup($idGroup, $idParentGroupToAdd);
  131. }
  132. public function nestedGroupsAddNestedGroup($idGroup, $idNestedGroupToAdd) {
  133. if ($idGroup <= 0) throw new Exception("Wrong param id group");
  134. if ($idNestedGroupToAdd <= 0) throw new Exception("Wrong param id parent group to add");
  135. $usrStorageDB = UserStorageFactory::getStorage('DB');
  136. if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
  137. $group = $usrStorageDB->getGroupWithoutNested($idGroup);
  138. if (!$group) throw new Exception("Error: group not exists!");
  139. $nestedGroup = $usrStorageDB->getGroupWithoutNested($idNestedGroupToAdd);
  140. if (!$nestedGroup) throw new Exception("Error: nested group [{$idNestedGroupToAdd}] not exists!");
  141. $usrStorageDB->addNestedGroup($idGroup, $idNestedGroupToAdd);
  142. }
  143. public function printFormNestedGroups($idGroup) {
  144. $linkTypeIdNestedGroups = 5;
  145. if (!$idGroup) throw new Exception("Wrong param group id!");
  146. $usrStorageDB = UserStorageFactory::getStorage('DB');
  147. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  148. $group = $usrStorageDB->getGroup($idGroup);
  149. if (!$group) throw new Exception("Grupa {$idGroup} nie istnieje.");
  150. DBG::_('DBG_SU', '>1', 'group', $group, __CLASS__, __FUNCTION__, __LINE__);
  151. {
  152. $idZasob = ProcesHelper::getZasobTableID('ITEM_LINKS');
  153. if ($idZasob <= 0) throw new Exception("Brak zasobu dla tabeli 'ITEM_LINKS'");
  154. $zasobObj = ProcesHelper::getZasobTableInfo($idZasob);
  155. if (!$zasobObj) throw new Exception("Zasob TABELA ID={$idZasob} nie istnieje");
  156. UserActivity::add($idZasob);
  157. $userAcl = User::getAcl();
  158. $userAcl->fetchGroups();
  159. if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ID={$zasobObj->ID}");
  160. }
  161. if (V::get('_testUsrGroupsLdapLvl0', '', $_GET)) {
  162. $usrLogin = User::getLogin();
  163. $groups = array(); $groupsLvl3 = array();
  164. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 0);
  165. foreach ($groupsNetwork as $vGroup) {
  166. $groups[$vGroup->cn] = $vGroup->appleUID;
  167. }
  168. DBG::_(true, true, "groups ldap lvl 0", $groups, __CLASS__, __FUNCTION__, __LINE__);
  169. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
  170. foreach ($groupsNetwork as $vGroup) {
  171. $groupsLvl3[$vGroup->cn] = $vGroup->appleUID;
  172. }
  173. DBG::_(true, true, "groups ldap lvl 3", $groupsLvl3, __CLASS__, __FUNCTION__, __LINE__);
  174. }
  175. $group->getParentGroups();
  176. DBG::_('DBG_NG', '>1', "group with nested", $group, __CLASS__, __FUNCTION__, __LINE__);
  177. $typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
  178. $groupUsers = array();
  179. $groupNestedUsers = array();
  180. $idZasobTableUsers = ProcesHelper::getZasobTableID('ADMIN_USERS');
  181. if ($group->zasobID > 0) {
  182. $groupUsers = UsersHelper::getUsersByGroupId($idGroup);
  183. $groupNestedUsers = UsersHelper::getUsersByGroupsIds(array_keys($group->nestedGroups), array_keys($groupUsers));
  184. }
  185. ?>
  186. <style type="text/css">
  187. .frm-groups .selectize-control { float:left; }
  188. .conn_groups {}
  189. .conn_groups .conn_groups-list {}
  190. .conn_groups .conn_groups-list .conn_groups-list_item { line-height:22px; }
  191. .conn_groups .conn_groups-list .conn_groups-list_item form { display:inline; margin:0; }
  192. .conn_groups .conn_groups-list_item-rmBtn { display:inline; margin:0; padding:0 6px; border:none; opacity:0.4; }
  193. .conn_groups .conn_groups-list_item-editBtn { margin:0 6px; padding:0; border:none; opacity:0.4; }
  194. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { display:inline; opacity:1; }
  195. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-editBtn { opacity:1; }
  196. .users-with-perms {}
  197. .users-with-perms address { padding:0 6px; border:1px solid #eee; }
  198. .users-with-perms address:hover { border-color:#333; }
  199. </style>
  200. <div class="container conn_groups">
  201. <h3>Grupy uprawnień
  202. <!-- <em style="color:#ccc;">(Nested Groups)</em> -->
  203. </h3>
  204. <p>
  205. <b>Zasób [<?php echo $idGroup; ?>]</b>: <?php echo $group->type; ?> <?php echo $group->zasobDESC; ?>
  206. <a class="btn btn-xs btn-primary" href="index.php?MENU_INIT=SYNC_LDAP_PERMS&syncGroup=<?php echo $idGroup; ?>">synchronizuj do LDAP</a>
  207. </p>
  208. <br>
  209. <div class="row">
  210. <div class="col-md-6">
  211. <!-- <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>:
  212. </p> -->
  213. <blockquote>
  214. <!-- <h5>Ustal grupy, które będą miały uprawnienia do rekordów dostępnych dla
  215. [<?php echo $group->zasobID; ?>] <?php echo $group->zasobDESC; ?>
  216. </h5>
  217. <small>np. grupy podrzędnych pracowników.</small> -->
  218. <h5>Udostępnij rekordy innym grupom</h5>
  219. <small>np. przełożonemu.</small>
  220. </blockquote>
  221. <ul class="conn_groups-list">
  222. <?php if (!empty($group->nestedGroups)) : ?>
  223. <?php foreach ($group->nestedGroups as $vNestedGroup) : ?>
  224. <li class="conn_groups-list_item">
  225. [<?php echo $vNestedGroup->zasobID; ?>]
  226. <?php echo $vNestedGroup->type; ?>
  227. <?php echo $vNestedGroup->zasobDESC; ?>
  228. <a href="index.php?_route=Users&_task=nestedGroups&idGroup=<?php echo $vNestedGroup->zasobID; ?>" class="glyphicon glyphicon-pencil conn_groups-list_item-editBtn" title="Edytuj grupę"> </a>
  229. <form action="" method="POST" class="form-inline frm-groups">
  230. <input type="hidden" name="_subTask" value="removeNestedGroup">
  231. <button name="idNestedGroupToRemove" value="<?php echo $vNestedGroup->zasobID; ?>" class="btn-link btn-sm conn_groups-list_item-rmBtn" title="usuń grupę"><i class="glyphicon glyphicon-remove"></i></button>
  232. </form>
  233. </li>
  234. <?php endforeach; ?>
  235. <?php endif; ?>
  236. <?php if ($typeSpecialNestedGroups) : ?>
  237. <li>
  238. <form action="" method="POST" class="form-inline frm-groups">
  239. <input type="hidden" name="_subTask" value="addNestedGroup">
  240. <?php
  241. $fName = 'idNestedGroupToAdd';
  242. $fldParams = array();
  243. $fldParams['allowCreate'] = false;
  244. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdNestedGroup";
  245. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  246. echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  247. ?>
  248. <button class="btn">dodaj</button>
  249. </form>
  250. </li>
  251. <?php endif; ?>
  252. </ul>
  253. <!-- <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>:
  254. </p> -->
  255. <blockquote>
  256. <h5>Grupy, które udostępniają rekordy</h5>
  257. <small>np. grupy podrzędnych pracowników lub dział, podmiot.</small>
  258. </blockquote>
  259. <ul class="conn_groups-list">
  260. <?php if (!empty($group->parentGroups)) : ?>
  261. <?php foreach ($group->parentGroups as $vParentGroup) : ?>
  262. <li class="conn_groups-list_item">
  263. [<?php echo $vParentGroup->zasobID; ?>]
  264. <?php // if ('DZIAL' == $vParentGroup->type) : ?>
  265. <?php echo $vParentGroup->type; ?>
  266. <?php // endif; ?>
  267. <?php echo $vParentGroup->zasobDESC; ?>
  268. <a href="index.php?_route=Users&_task=nestedGroups&idGroup=<?php echo $vParentGroup->zasobID; ?>" class="glyphicon glyphicon-pencil conn_groups-list_item-editBtn" title="Edytuj grupę"> </a>
  269. <form action="" method="POST" class="form-inline frm-groups">
  270. <input type="hidden" name="_subTask" value="removeParentGroup">
  271. <button name="idParentGroupToRemove" value="<?php echo $vParentGroup->zasobID; ?>" class="btn-link btn-sm conn_groups-list_item-rmBtn" title="usuń grupę"><i class="glyphicon glyphicon-remove"></i></button>
  272. </form>
  273. </li>
  274. <?php endforeach; ?>
  275. <?php endif; ?>
  276. <?php if ($typeSpecialNestedGroups) : ?>
  277. <li>
  278. <form action="" method="POST" class="form-inline frm-groups">
  279. <input type="hidden" name="_subTask" value="addParentGroup">
  280. <?php
  281. $fName = 'idParentGroupToAdd';
  282. $fldParams = array();
  283. $fldParams['allowCreate'] = false;
  284. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdNestedGroup";
  285. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  286. echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  287. ?>
  288. <button class="btn">dodaj</button>
  289. </form>
  290. </li>
  291. <?php endif; ?>
  292. </ul>
  293. </div>
  294. <div class="col-md-6 users-with-perms">
  295. <h5>Użytkownicy:</h5>
  296. <?php if (empty($groupUsers)) : ?>
  297. <div class="alert">Brak użytkowników przypisanych bezpośrednio do grupy</div>
  298. <?php else : ?>
  299. <div class="row">
  300. <?php foreach ($groupUsers as $usr) : ?>
  301. <div class="col-md-6">
  302. <address>
  303. <strong><?php echo $usr->ADM_NAME; ?></strong>
  304. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobTableUsers; ?>#EDIT/<?php echo $usr->ID; ?>" class="glyphicon glyphicon-pencil" title="Edytuj rekord"> </a>
  305. <br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
  306. <?php if (!empty($usr->ADM_PHONE)) : ?>
  307. <br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
  308. <?php endif; ?>
  309. <?php if (!empty($usr->EMAIL)) : ?>
  310. <br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
  311. <?php endif; ?>
  312. </address>
  313. </div>
  314. <?php endforeach; ?>
  315. </div>
  316. <?php endif; ?>
  317. <h5>Użytwkonicy z uprawnieniami do rekordów</h5>
  318. <?php if (empty($groupNestedUsers)) : ?>
  319. <div class="alert">Brak</div>
  320. <?php else : ?>
  321. <div class="row">
  322. <?php foreach ($groupNestedUsers as $usr) : ?>
  323. <div class="col-md-6">
  324. <address>
  325. <strong><?php echo $usr->ADM_NAME; ?></strong>
  326. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobTableUsers; ?>#EDIT/<?php echo $usr->ID; ?>" class="glyphicon glyphicon-pencil" title="Edytuj rekord"> </a>
  327. <br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
  328. <?php if (!empty($usr->ADM_PHONE)) : ?>
  329. <br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
  330. <?php endif; ?>
  331. <?php if (!empty($usr->EMAIL)) : ?>
  332. <br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
  333. <?php endif; ?>
  334. </address>
  335. </div>
  336. <?php endforeach; ?>
  337. </div>
  338. <?php endif; ?>
  339. </div>
  340. </div>
  341. </div>
  342. <?php
  343. {// render table
  344. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  345. $forceTblAclInit = ('1' == V::get('_force', '', $_GET));
  346. $tblAcl->init($forceTblAclInit);
  347. $forceFilterInit = array();
  348. $filterInit = new stdClass();
  349. $filterInit->currSortCol = 'ID';
  350. $filterInit->currSortFlip = 'desc';
  351. foreach ($_GET as $k => $v) {
  352. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  353. $filterInit->$k = $v;
  354. }
  355. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  356. $filterInit->$k = $v;
  357. }
  358. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  359. $fldName = substr($k, 3);
  360. $forceFilterInit[$fldName] = $v;
  361. }
  362. }
  363. $tblZasobyID = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
  364. $forceFilterInit['TABLE_1_NAME'] = 'CRM_LISTA_ZASOBOW';
  365. $forceFilterInit['TABLE_1_ZASOB_ID'] = $tblZasobyID;
  366. $forceFilterInit['TABLE_1_ID'] = $group->zasobID;
  367. $forceFilterInit['TABLE_2_NAME'] = 'CRM_LISTA_ZASOBOW';
  368. $forceFilterInit['TABLE_2_ZASOB_ID'] = $tblZasobyID;
  369. $forceFilterInit['LINKS_TYPE_ID'] = $linkTypeIdNestedGroups;
  370. $tbl = new TableAjax($tblAcl);
  371. $tbl->setLabel($zasobObj->OPIS);
  372. $tbl->setFilterInit($filterInit);
  373. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  374. $tbl->addRowFunction('edit');
  375. $tbl->addRowFunction('hist');
  376. $tbl->addRowFunction('files');
  377. $tbl->addRowFunction('cp');
  378. $tbl->showProcesInit(false);// hide Proces filter field
  379. echo $tbl->render();
  380. }
  381. }
  382. public function typeSpecialIdNestedGroupAction() {
  383. header("Content-type: application/json");
  384. $typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
  385. $query = V::get('q', '', $_REQUEST);
  386. $rawRows = null;
  387. $rows = $typeSpecialNestedGroups->getValuesWithExports($query);
  388. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  389. foreach ($rows as $kID => $vItem) {
  390. $itemJson = new stdClass();
  391. $itemJson->id = $vItem->id;
  392. $itemJson->name = $vItem->param_out;
  393. if (!empty($vItem->exports)) {
  394. $itemJson->exports = $vItem->exports;
  395. }
  396. $jsonData[] = $itemJson;
  397. }
  398. echo json_encode($jsonData);
  399. }
  400. public function userGroupsAction() {
  401. SE_Layout::gora();
  402. SE_Layout::menu();
  403. $usrLogin = V::get('usrLogin', '', $_GET);
  404. echo '<div class="container">';
  405. try {
  406. if (empty($usrLogin)) throw new Exception("Empty user login");
  407. $subTask = V::get('_subTask', '', $_POST);
  408. if ('removeUserGroup' == $subTask) {
  409. $idProfileToRemove = V::get('idProfileToRemove', 0, $_POST, 'int');
  410. $this->removeUserGroup($usrLogin, $idProfileToRemove);
  411. ?><div class="alert alert-info">Użytkownik został usunięty z danej grupy</div><?php
  412. } else if ('addUserGroup' == $subTask) {
  413. $idGroup = V::get('idGroup', 0, $_POST, 'int');
  414. $idTelboxes = V::get('addTelboxesID', 0, $_POST, 'int');
  415. $this->addUserGroup($usrLogin, $idGroup, $idTelboxes);
  416. ?><div class="alert alert-info">Dodano grupę [<?php echo $idGroup; ?>] do użytkownika [<?php echo $usrLogin; ?>]</div><?php
  417. }
  418. $this->printFormUserGroup($usrLogin);
  419. } catch (Exception $e) {
  420. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?>
  421. <br><a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrLogin; ?>">wróć</a>
  422. </div><?php
  423. echo UserActivity::showListInContainer();
  424. }
  425. echo '</div>';// .container
  426. SE_Layout::dol();
  427. }
  428. public function printFormUserGroup($usrLogin) {
  429. if (empty($usrLogin)) throw new Exception("Empty user login");
  430. $usrStorageDB = UserStorageFactory::getStorage('DB');
  431. if (!$usrStorageDB) throw new Exception("Storage DB not exists!");
  432. $usr = $usrStorageDB->getUser($usrLogin);
  433. if (!$usr) throw new Exception("Użytkownik '{$usrLogin}' nie istnieje.");
  434. $stanowiska = array();
  435. $stanowiska = $usrStorageDB->getUserProfiles($usrLogin, $fetchNested = false);
  436. uasort($stanowiska, array($this, 'sortStanowiskaByType'));
  437. $groups = UsersHelper::getGroupByUser($usr->primaryKey);
  438. DBG::_('DBG_SU', '>1', 'groups', $groups, __CLASS__, __FUNCTION__, __LINE__);
  439. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
  440. DBG::_('DBG_SU', '>1', 'groupsNetwork', $groupsNetwork, __CLASS__, __FUNCTION__, __LINE__);
  441. $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
  442. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
  443. $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
  444. ?>
  445. <style type="text/css">
  446. .frm-groups .selectize-control { float:left; }
  447. .conn_groups {}
  448. .conn_groups .conn_groups-list {}
  449. .conn_groups .conn_groups-list .conn_groups-list_item { line-height:22px; }
  450. .conn_groups .conn_groups-list .conn_groups-list_item form { display:inline; margin:0; }
  451. .conn_groups .conn_groups-list_item-rmBtn { /*display:none;*/ opacity:0.4; margin:0; padding:0 10px; border:none; }
  452. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { /*display:inline;*/ opacity:1; }
  453. </style>
  454. <div class="conn_groups">
  455. <h4>Ustalanie stanowiska</h4>
  456. <blockquote>
  457. Użytkownik [<?php echo $usr->primaryKey; ?>] <b><?php echo $usr->name; ?></b> <code><?php echo $usr->login; ?></code>
  458. <?php if ($idZasobUsersTbl > 0) : ?>
  459. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usr->primaryKey; ?>"
  460. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
  461. <?php endif; ?>
  462. <a href="index.php?_route=Users&_task=syncUser&usrLogin=<?php echo $usr->login; ?>"
  463. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-random"></span> synchronizuj do LDAP</a>
  464. </blockquote>
  465. <h4>Przypisane grupy (<?php echo (!empty($stanowiska))? count($stanowiska) : 0; ?>):</h4>
  466. <?php if (!empty($stanowiska)) : ?>
  467. <ul class="conn_groups-list">
  468. <?php foreach ($stanowiska as $vProfile) : ?>
  469. <li class="conn_groups-list_item">
  470. <?php echo $vProfile->group->realName; ?>
  471. <?php if ($vProfile->localisationId > 0) : ?>
  472. (lokalizacja [<?php echo $vProfile->localisationId; ?>])
  473. <?php endif; ?>
  474. <form class="form-inline frm-groups" action="" method="POST">
  475. <input type="hidden" name="_subTask" value="removeUserGroup">
  476. <button name="idProfileToRemove" value="<?php echo $vProfile->profileId; ?>" class="btn-link btn-sm conn_groups-list_item-rmBtn" title="usuń grupę" onclick="return confirm('Czy jesteś pewien że chcesz usunąć przypisanie do grupy <?php echo $vProfile->group->realName; ?>?');"><i class="glyphicon glyphicon-remove"></i></button>
  477. </form>
  478. </li>
  479. <?php endforeach; ?>
  480. </ul>
  481. <?php endif; ?>
  482. <?php if ($typeSpecialUserGroups && $typeSpecialTelboxes) : ?>
  483. <h4>Dodaj grupę:</h4>
  484. <form class="form-horizontal" action="" method="POST">
  485. <input type="hidden" name="_subTask" value="addUserGroup">
  486. <div class="form-group">
  487. <label class="col-sm-3 control-label" for="idGroup">Grupa</label>
  488. <div class="col-sm-9">
  489. <?php
  490. $fName = 'idGroup';
  491. $fldParams = array();
  492. $fldParams['allowCreate'] = false;
  493. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdGroup";
  494. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  495. echo $typeSpecialUserGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  496. ?>
  497. </div>
  498. </div>
  499. <div class="form-group">
  500. <label class="col-sm-3 control-label" for="addTelboxesID">Lokalizacja</label>
  501. <div class="col-sm-9">
  502. <?php
  503. $fName = 'addTelboxesID';
  504. $fldParams = array();
  505. $fldParams['allowCreate'] = false;
  506. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdTelboxes";
  507. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  508. echo $typeSpecialTelboxes->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  509. ?>
  510. </div>
  511. </div>
  512. <div class="form-group">
  513. <div class="col-sm-9 col-sm-offset-3">
  514. <button type="submit" class="btn btn-xs btn-primary">dodaj grupę</button>
  515. </div>
  516. </div>
  517. </form>
  518. <?php endif; ?>
  519. </div>
  520. <?php
  521. {// show table crm_auth_profile
  522. $idZasobCrmAuthProfile = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
  523. if ($idZasobCrmAuthProfile <= 0) throw new Exception("Can not find id zasob 'CRM_AUTH_PROFILE'");
  524. $zasobObj = ProcesHelper::getZasobTableInfo($idZasobCrmAuthProfile);
  525. if (!$zasobObj) throw new Exception("Zasob TABELA ID={$idZasobCrmAuthProfile} nie istnieje");
  526. UserActivity::add($idZasobCrmAuthProfile);
  527. $userAcl = User::getAcl();
  528. if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ID={$zasobObj->ID}");
  529. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  530. $forceTblAclInit = ('1' == V::get('_force', '', $_GET));
  531. $tblAcl->init($forceTblAclInit);
  532. $forceFilterInit = array();
  533. $filterInit = new stdClass();
  534. $filterInit->currSortCol = 'ID';
  535. $filterInit->currSortFlip = 'desc';
  536. foreach ($_GET as $k => $v) {
  537. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  538. $filterInit->$k = $v;
  539. }
  540. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  541. $filterInit->$k = $v;
  542. }
  543. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  544. $fldName = substr($k, 3);
  545. $forceFilterInit[$fldName] = $v;
  546. }
  547. }
  548. $forceFilterInit['REMOTE_ID'] = $usr->primaryKey;
  549. $forceFilterInit['REMOTE_TABLE'] = 'ADMIN_USERS';
  550. $tbl = new TableAjax($tblAcl);
  551. $tbl->setLabel($zasobObj->OPIS);
  552. $tbl->setFilterInit($filterInit);
  553. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  554. $tbl->addRowFunction('edit');
  555. $tbl->addRowFunction('hist');
  556. $tbl->addRowFunction('files');
  557. $tbl->addRowFunction('cp');
  558. $tbl->showProcesInit(false);// hide Proces filter field
  559. echo $tbl->render();
  560. }
  561. }
  562. public function sortStanowiskaByType($a, $b) {
  563. if ($a->group->type != $a->group->type) {
  564. if ($a->group->type == 'network') {
  565. return 1;
  566. }
  567. else if ($a->group->type == 'local') {
  568. return -1;
  569. }
  570. }
  571. return 0;
  572. }
  573. public function removeUserGroup($usrLogin, $idProfileToRemove) {
  574. if (!$usrLogin) throw new Exception("Wrong param user login!");
  575. if (!$idProfileToRemove) throw new Exception("Wrong param id profile to remove!");
  576. $usrStorageDB = UserStorageFactory::getStorage('DB');
  577. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  578. $profile = $usrStorageDB->getProfileById($idProfileToRemove);
  579. if (!$profile) throw new Exception("Error profile not exists!");
  580. $usrStorageDB->removeUserGroupByProfileId($usrLogin, $profile->group, $idProfileToRemove);
  581. }
  582. public function addUserGroup($usrLogin, $idGroup, $idTelboxes) {
  583. DBG::_('DBG_NG', '>0', 'post', $_POST, __CLASS__, __FUNCTION__, __LINE__);
  584. if (!$usrLogin) throw new Exception("Wrong param user login!");
  585. $usrStorageDB = UserStorageFactory::getStorage('DB');
  586. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  587. $usr = $usrStorageDB->getUser($usrLogin);
  588. if (!$usr) throw new Exception("Użytkownik {$usrLogin} nie istnieje.");
  589. if ($idGroup > 0) {
  590. $groupToAdd = $usrStorageDB->getGroupWithoutNested($idGroup);
  591. if (!$groupToAdd) throw new Exception("Grupa [{$idGroup}] nie istnieje");
  592. $added = $usrStorageDB->addUserGroup($usrLogin, $groupToAdd, $idTelboxes);
  593. }
  594. }
  595. public function typeSpecialIdGroupAction() {
  596. header("Content-type: application/json");
  597. $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
  598. $query = V::get('q', '', $_REQUEST);
  599. $rawRows = null;
  600. $rows = $typeSpecialUserGroups->getValuesWithExports($query);
  601. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  602. foreach ($rows as $kID => $vItem) {
  603. $itemJson = new stdClass();
  604. $itemJson->id = $vItem->id;
  605. $itemJson->name = $vItem->param_out;
  606. if (!empty($vItem->exports)) {
  607. $itemJson->exports = $vItem->exports;
  608. }
  609. $jsonData[] = $itemJson;
  610. }
  611. echo json_encode($jsonData);
  612. }
  613. public function typeSpecialIdTelboxesAction() {
  614. header("Content-type: application/json");
  615. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
  616. $query = V::get('q', '', $_REQUEST);
  617. $rawRows = null;
  618. $rows = $typeSpecialTelboxes->getValuesWithExports($query);
  619. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  620. foreach ($rows as $kID => $vItem) {
  621. $itemJson = new stdClass();
  622. $itemJson->id = $vItem->id;
  623. $itemJson->name = $vItem->param_out;
  624. if (!empty($vItem->exports)) {
  625. $itemJson->exports = $vItem->exports;
  626. }
  627. $jsonData[] = $itemJson;
  628. }
  629. echo json_encode($jsonData);
  630. }
  631. public function syncGroupAction() {
  632. $idGroup = V::get('idGroup', 0, $_GET, 'int');
  633. SE_Layout::gora();
  634. SE_Layout::menu();
  635. echo '<div class="container">';
  636. try {
  637. if (!$idGroup) throw new Exception("Brak numeru grupy!");
  638. ?>
  639. <h4>Synchronizacja grupy do bazy LDAP</h4>
  640. <blockquote>
  641. Grupa [<?php echo $idGroup; ?>]
  642. <a class="btn btn-link" href="index.php?MENU_INIT=GROUP_ADD_NESTEDGROUPS&groupID=<?php echo $idGroup; ?>">ustal powiązania między grupami uprawnień</a></p>
  643. </blockquote>
  644. <?php
  645. $this->syncGroup($idGroup);
  646. } catch (Exception $e) {
  647. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?></div><?php
  648. }
  649. echo '</div>';// .container
  650. SE_Layout::dol();
  651. }
  652. public function syncGroup($idGroup) {
  653. $usrStorageDB = UserStorageFactory::getStorage('DB');
  654. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  655. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  656. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  657. $groupFrom = $usrStorageDB->getGroup($idGroup);
  658. if (!$groupFrom) {
  659. $db = DB::getDB();
  660. $zasob = $db->get_by_id('CRM_LISTA_ZASOBOW', $idGroup);
  661. if (!$zasob) {
  662. throw new Exception("Zasób {$idGroup} nie istnieje");
  663. } else {
  664. throw new Exception("Zasób {$idGroup} nie jest grupą tylko {$zasob->TYPE}");
  665. }
  666. }
  667. else {
  668. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  669. $syncTodoList = $synUsers->getSyncGroupTodoList($idGroup, $syncNestedGroups = true);
  670. ?>
  671. <?php if (empty($syncTodoList)) : ?>
  672. <div class="alert alert-info">Brak zadań do wykonania - grupa zsynchronizowana</div>
  673. <?php else : ?>
  674. <div class="well">
  675. <p>Lista zadań do wykonania:</p>
  676. <ul>
  677. <?php foreach ($syncTodoList as $vTask) : ?>
  678. <li><?php echo $vTask; ?></li>
  679. <?php endforeach; ?>
  680. </ul>
  681. </div>
  682. <?php endif; ?>
  683. <?php
  684. if ('1' == V::get('_runSync', '', $_POST)) {
  685. $synced = $synUsers->syncGroup($idGroup, $syncNestedGroups = true);
  686. if (!$synced) {
  687. ?>
  688. <div class="alert alert-danger">
  689. Nie udało się zsynchronizować grupy [<?php echo $idGroup; ?>].
  690. </div>
  691. <?php
  692. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none;">errors: (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($synUsers->getErrorsMsgListWithDbg());echo'</pre>';
  693. }
  694. else {
  695. ?>
  696. <div class="alert alert-success">
  697. Synchronizacja grupy [<?php echo $idGroup; ?>] zakończona powodzeniem.
  698. </div>
  699. <?php
  700. }
  701. }
  702. else {
  703. ?>
  704. <form action="" method="POST">
  705. <input type="hidden" name="_runSync" value="1">
  706. <input type="submit" value="Synchronizuj" class="btn btn-primary btn-big">
  707. </form>
  708. <?php
  709. }
  710. }
  711. }
  712. public function syncUserAction() {
  713. SE_Layout::gora();
  714. SE_Layout::menu();
  715. $usrLogin = V::get('usrLogin', '', $_GET);
  716. echo '<div class="container">';
  717. try {
  718. if (empty($usrLogin)) throw new Exception("Empty user login");
  719. $usrStorageDB = UserStorageFactory::getStorage('DB');
  720. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  721. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  722. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  723. echo '<h4>' . "Synchronizacja do LDAP" . '</h4>';
  724. $usrFrom = $usrStorageDB->getUser($usrLogin);
  725. DBG::_('DBG_SU', '>1', 'User from:', $usrFrom, __CLASS__, __FUNCTION__, __LINE__);
  726. if ($usrFrom) {
  727. $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
  728. $idZasobPermsTbl = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
  729. ?>
  730. <blockquote>
  731. Użytkownik [<?php echo $usrFrom->primaryKey; ?>] <b><?php echo $usrFrom->name; ?></b> <code><?php echo $usrFrom->login; ?></code>
  732. <?php if ($idZasobUsersTbl > 0) : ?>
  733. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usrFrom->primaryKey; ?>"
  734. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
  735. <?php endif; ?>
  736. <?php if ($idZasobPermsTbl > 0) : ?>
  737. <a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrFrom->login; ?>"
  738. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-user"></span> ustal stanowisko</a>
  739. <?php endif; ?>
  740. </blockquote>
  741. <?php
  742. }
  743. $this->syncUser($usrLogin, $usrStorageDB, $usrStorageLdap);
  744. } catch (Exception $e) {
  745. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?></div><?php
  746. }
  747. echo '</div>';// .container
  748. SE_Layout::dol();
  749. }
  750. public function syncUser($userName, $usrStorageDB, $usrStorageLdap) {
  751. if (empty($userName)) throw new Exception("Empty user login");
  752. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  753. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  754. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  755. $syncTodoList = $synUsers->getSyncUserTodoList($userName);
  756. ?>
  757. <?php if (empty($syncTodoList)) : ?>
  758. <div class="alert alert-info">Brak zadań do wykonania - użytkownik zsynchronizowany</div>
  759. <?php else : ?>
  760. <div class="well">
  761. <p>Lista zadań do wykonania:</p>
  762. <ul>
  763. <?php foreach ($syncTodoList as $vTask) : ?>
  764. <li><?php echo $vTask; ?></li>
  765. <?php endforeach; ?>
  766. </ul>
  767. </div>
  768. <?php endif; ?>
  769. <?php
  770. if ('1' == V::get('_runSync', '', $_POST)) {
  771. $synced = $synUsers->syncUser($userName, $syncGroups = true, $syncDisabled = true);
  772. if (!$synced) {
  773. ?>
  774. <div class="alert alert-danger">
  775. Nie udało się zsynchronizować uprawnień użytkownika <?php echo $userName; ?>.
  776. </div>
  777. <?php
  778. $errorsList = $synUsers->getErrorsMsgListWithDbg();
  779. if (!empty($errorsList)) {
  780. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  781. echo "Błędy:\n" . implode("\n", $errorsList);
  782. echo '</pre>';
  783. }
  784. }
  785. else {
  786. ?>
  787. <div class="alert alert-success">
  788. Synchronizacja uprawnień użytkownika <?php echo $userName; ?> zakończona powodzeniem.
  789. </div>
  790. <?php
  791. }
  792. }
  793. else {
  794. ?>
  795. <form action="" method="POST">
  796. <input type="hidden" name="_runSync" value="1">
  797. <input type="submit" value="Synchronizuj" class="btn btn-primary btn-big">
  798. </form>
  799. <?php
  800. }
  801. }
  802. }