Users.php 39 KB

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