Users.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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. $syncUrl = Router::getRoute('ViewTableAjax')->getLink('', [ 'namespace' => $tblAcl->getNamespace() ]);
  598. $tbl->setRootUrl( $syncUrl );
  599. $tbl->setSyncUrl( $syncUrl );
  600. $tbl->showProcesInitFiltr = Router::getRoute('ViewTableAjax')->getLink("procesInitFiltrAjax", [ 'namespace' => $tblAcl->getNamespace() ]);
  601. $tbl->showTableTools = Router::getRoute('ViewTableAjax')->getLink("tableToolsAjax", [ 'namespace' => $tblAcl->getNamespace() ]);
  602. $tbl->useUserTableFilter = Router::getRoute('ViewTableAjax')->getLink("getUserTableFilterAjax");
  603. $tbl->setLabel($zasobObj->OPIS);
  604. $tbl->setFilterInit($filterInit);
  605. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  606. $tbl->addRowFunction('edit');
  607. $tbl->addRowFunction('hist');
  608. $tbl->addRowFunction('files');
  609. $tbl->addRowFunction('cp');
  610. echo $tbl->render();
  611. }
  612. }
  613. public function sortStanowiskaByType($a, $b) {
  614. if ($a->group->type != $a->group->type) {
  615. if ($a->group->type == 'network') {
  616. return 1;
  617. }
  618. else if ($a->group->type == 'local') {
  619. return -1;
  620. }
  621. }
  622. return 0;
  623. }
  624. public function removeUserGroup($usrLogin, $idProfileToRemove) {
  625. if (!$usrLogin) throw new Exception("Wrong param user login!");
  626. if (!$idProfileToRemove) throw new Exception("Wrong param id profile to remove!");
  627. $usrStorageDB = UserStorageFactory::getStorage('DB');
  628. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  629. $profile = $usrStorageDB->getProfileById($idProfileToRemove);
  630. if (!$profile) throw new Exception("Error profile not exists!");
  631. $usrStorageDB->removeUserGroupByProfileId($usrLogin, $profile->group, $idProfileToRemove);
  632. }
  633. public function addUserGroup($usrLogin, $idGroup, $idTelboxes) {
  634. DBG::_('DBG_NG', '>0', 'post', $_POST, __CLASS__, __FUNCTION__, __LINE__);
  635. if (!$usrLogin) throw new Exception("Wrong param user login!");
  636. $usrStorageDB = UserStorageFactory::getStorage('DB');
  637. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  638. $usr = $usrStorageDB->getUser($usrLogin);
  639. if (!$usr) throw new Exception("Użytkownik {$usrLogin} nie istnieje.");
  640. if ($idGroup > 0) {
  641. $groupToAdd = $usrStorageDB->getGroupWithoutNested($idGroup);
  642. if (!$groupToAdd) throw new Exception("Grupa [{$idGroup}] nie istnieje");
  643. $added = $usrStorageDB->addUserGroup($usrLogin, $groupToAdd, $idTelboxes);
  644. }
  645. }
  646. 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) {
  647. DBG::_('DBG_NG', '>0', 'post', $_POST, __CLASS__, __FUNCTION__, __LINE__);
  648. if (!$usrLogin) throw new Exception("Wrong param user login!");
  649. $usrStorageDB = UserStorageFactory::getStorage('DB');
  650. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  651. $usr = $usrStorageDB->getUser($usrLogin);
  652. if ($usr) throw new Exception("Użytkownik {$usrLogin} już istnieje.");
  653. if (!$usr) {
  654. $acl = ACL::getStorageByNamespace("default_db/ADMIN_USERS/ADMIN_USERS");
  655. $usr = $acl->addItem([
  656. 'ADM_ACCOUNT' => $usrLogin,
  657. 'ADM_ADMIN_LEVEL' => $ADM_ADMIN_LEVEL,
  658. 'ADM_NAME' => $ADM_NAME,
  659. 'ADM_ADMIN_DESC' => $ADM_ADMIN_DESC,
  660. 'EMPLOYEE_TYPE' => $EMPLOYEE_TYPE,
  661. 'ADM_PASSWD' => $ADM_PASSWD,
  662. 'A_ADM_COMPANY' => $A_ADM_COMPANY,
  663. 'A_CLASSIFIED' => $A_CLASSIFIED
  664. ]);
  665. if (!$usr) throw new Exception("Nie udało się utworzyć wpisu użytkownika");
  666. if ($idGroup > 0) {
  667. $groupToAdd = $usrStorageDB->getGroupWithoutNested($idGroup);
  668. if (!$groupToAdd) throw new Exception("Grupa [{$idGroup}] nie istnieje");
  669. $added = $usrStorageDB->addUserGroup($usrLogin, $groupToAdd, $idTelboxes);
  670. }
  671. }
  672. }
  673. public function typeSpecialIdGroupAction() {
  674. header("Content-type: application/json");
  675. $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
  676. $query = V::get('q', '', $_REQUEST);
  677. $rawRows = null;
  678. $rows = $typeSpecialUserGroups->getValuesWithExports($query);
  679. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  680. foreach ($rows as $kID => $vItem) {
  681. $itemJson = new stdClass();
  682. $itemJson->id = $vItem->id;
  683. $itemJson->name = $vItem->param_out;
  684. if (!empty($vItem->exports)) {
  685. $itemJson->exports = $vItem->exports;
  686. }
  687. $jsonData[] = $itemJson;
  688. }
  689. echo json_encode($jsonData);
  690. }
  691. public function typeSpecialIdTelboxesAction() {
  692. header("Content-type: application/json");
  693. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
  694. $query = V::get('q', '', $_REQUEST);
  695. $rawRows = null;
  696. $rows = $typeSpecialTelboxes->getValuesWithExports($query);
  697. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  698. foreach ($rows as $kID => $vItem) {
  699. $itemJson = new stdClass();
  700. $itemJson->id = $vItem->id;
  701. $itemJson->name = $vItem->param_out;
  702. if (!empty($vItem->exports)) {
  703. $itemJson->exports = $vItem->exports;
  704. }
  705. $jsonData[] = $itemJson;
  706. }
  707. echo json_encode($jsonData);
  708. }
  709. public function syncGroupAction() {
  710. $idGroup = V::get('idGroup', 0, $_GET, 'int');
  711. $group = null;
  712. UI::gora();
  713. UI::menu();
  714. echo '<div class="container">';
  715. try {
  716. if (!$idGroup) throw new Exception("Brak numeru grupy!");
  717. $usrStorageDB = UserStorageFactory::getStorage('DB');
  718. if ($usrStorageDB) $group = $usrStorageDB->getGroup($idGroup);
  719. echo UI::h('h4', [], "Synchronizacja grupy do bazy LDAP");
  720. echo UI::h('blockquote', [], [
  721. "Grupa [{$idGroup}]: ",
  722. ($group)
  723. ? "<code>{$group->type}</code> {$group->zasobDESC} "
  724. : "",
  725. UI::h('a', [
  726. 'class' => "btn btn-xs btn-link",
  727. 'href' => "index.php?_route=ViewTableAjax&namespace=default_db/CRM_LISTA_ZASOBOW#EDIT/{$idGroup}",
  728. 'title' => "Edytuj rekord",
  729. ], "<i class=\"glyphicon glyphicon-pencil\"></i> edytuj"),
  730. UI::h('a', [ 'class' => "btn btn-xs btn-link",
  731. 'href' => $this->getLink('nestedGroups', [ 'idGroup' => $idGroup ]),
  732. ], "<i class=\"glyphicon glyphicon-random\"></i> ustal powiązania między grupami uprawnień"),
  733. ]);
  734. $this->syncGroup($idGroup);
  735. } catch (Exception $e) {
  736. DBG::log($e);
  737. UI::alert('danger', $e->getMessage());
  738. }
  739. echo '</div>'; // .container
  740. UI::dol();
  741. }
  742. public function syncGroup($idGroup) {
  743. $usrStorageDB = UserStorageFactory::getStorage('DB');
  744. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  745. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  746. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  747. $groupFrom = $usrStorageDB->getGroup($idGroup);
  748. if (!$groupFrom) {
  749. $db = DB::getDB();
  750. $zasob = $db->get_by_id('CRM_LISTA_ZASOBOW', $idGroup);
  751. if (!$zasob) {
  752. throw new Exception("Zasób {$idGroup} nie istnieje");
  753. } else {
  754. throw new Exception("Zasób {$idGroup} nie jest grupą tylko {$zasob->TYPE}");
  755. }
  756. }
  757. else {
  758. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  759. $syncTodoList = $synUsers->getSyncGroupTodoList($idGroup, $syncNestedGroups = true);
  760. echo (empty($syncTodoList))
  761. ? UI::h('div', [ 'class' => "alert alert-info" ], "Brak zadań do wykonania - grupa zsynchronizowana")
  762. : UI::h('div', [ 'class' => "well" ], [
  763. '<p>Lista zadań do wykonania:</p>',
  764. UI::h('ul', [], array_map(function ($vTask) {
  765. return UI::h('li', [], $vTask);
  766. }, $syncTodoList)),
  767. ])
  768. ;
  769. if ('1' == V::get('_runSync', '', $_POST)) {
  770. $synced = $synUsers->syncGroup($idGroup, $syncNestedGroups = true);
  771. if (!$synced) {
  772. UI::h('danger', "Nie udało się zsynchronizować grupy [{$idGroup}].");
  773. 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>';
  774. }
  775. else {
  776. UI::h('success', "Synchronizacja grupy [{$idGroup}] zakończona powodzeniem.");
  777. }
  778. }
  779. else {
  780. echo UI::h('form', [ 'action' => "", 'method' => "POST" ], [
  781. UI::h('input', [ 'type' => "hidden", 'name' => "_runSync", 'value' => "1" ]),
  782. UI::h('input', [ 'type' => "submit", 'value' => "Synchronizuj", 'class' => "btn btn-primary btn-big" ]),
  783. ]);
  784. }
  785. }
  786. }
  787. public function syncUserAction() {
  788. UI::gora();
  789. UI::menu();
  790. $usrLogin = V::get('usrLogin', '', $_GET);
  791. UI::startContainer();
  792. try {
  793. if (empty($usrLogin)) throw new Exception("Empty user login");
  794. $usrStorageDB = UserStorageFactory::getStorage('DB');
  795. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  796. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  797. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  798. echo UI::h('h4', [], "Synchronizacja do LDAP");
  799. $usrFrom = $usrStorageDB->getUser($usrLogin);
  800. if ($usrFrom) {
  801. echo UI::h('blockquote', [], [
  802. "Użytkownik ",
  803. ($usrFrom->isDisabled) ? '<span class="label label-danger">zablokowany!</span>' : '<span class="label label-info">aktywny</span>',
  804. " [{$usrFrom->primaryKey}] <b>{$usrFrom->name}</b> <code>{$usrFrom->login}</code> ",
  805. UI::h('a', [
  806. 'href' => "index.php?_route=ViewTableAjax&namespace=default_db/ADMIN_USERS#EDIT/{$usrFrom->primaryKey}",
  807. 'class' => "btn btn-xs btn-link",
  808. ], '<span class="glyphicon glyphicon-pencil"></span> edytuj'),
  809. UI::h('a', [
  810. 'href' => "index.php?_route=Users&_task=userGroups&usrLogin={$usrFrom->login}",
  811. 'class' => "btn btn-xs btn-link",
  812. ], '<span class="glyphicon glyphicon-user"></span> ustal stanowisko'),
  813. ]);
  814. }
  815. $this->syncUser($usrLogin, $usrStorageDB, $usrStorageLdap);
  816. } catch (Exception $e) {
  817. DBG::log($e);
  818. UI::alert('danger', $e->getMessage());
  819. }
  820. UI::endContainer();
  821. UI::dol();
  822. }
  823. public function syncUser($userName, $usrStorageDB, $usrStorageLdap,$forceSync=null) {
  824. if (empty($userName)) throw new Exception("Empty user login");
  825. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  826. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  827. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  828. if ('1' == V::get('_runSync', '', $_POST) or $forceSync) {
  829. $synced = $synUsers->syncUser($userName);
  830. if (!$synced) {
  831. UI::alert('danger', "Nie udało się zsynchronizować uprawnień użytkownika {$userName}.");
  832. $errorsList = $synUsers->getErrorsMsgListWithDbg();
  833. if (!empty($errorsList)) {
  834. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  835. echo "Błędy:\n" . implode("\n", $errorsList);
  836. echo '</pre>';
  837. }
  838. }
  839. else {
  840. UI::alert('success', "Synchronizacja uprawnień użytkownika {$userName} zakończona powodzeniem.");
  841. }
  842. }
  843. if ('1' == V::get('_forceSyncAliasList', '', $_POST)) {
  844. $synced = $synUsers->forceSyncUserAliasList($userName);
  845. if (!$synced) {
  846. UI::alert('danger', "Nie udało się poprawić aliasów {$userName}.");
  847. $errorsList = $synUsers->getErrorsMsgListWithDbg();
  848. if (!empty($errorsList)) {
  849. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  850. echo "Błędy:\n" . implode("\n", $errorsList);
  851. echo '</pre>';
  852. }
  853. }
  854. else {
  855. UI::alert('success', "Synchronizacja listy aliasów pocztowych użytkownika {$userName} zakończona powodzeniem.");
  856. }
  857. }
  858. $syncTodoList = $synUsers->getSyncUserTodoList($userName);
  859. echo (empty($syncTodoList))
  860. ? UI::h('div', [ 'class' => "alert alert-info" ], "Brak zadań do wykonania - użytkownik zsynchronizowany")
  861. : UI::h('div', [ 'class' => "well" ], [
  862. '<p>Lista zadań do wykonania:</p>',
  863. UI::h('ul', [], array_map(function ($vTask) {
  864. return UI::h('li', [], $vTask);
  865. }, $syncTodoList)),
  866. ])
  867. ;
  868. echo UI::h('div', [ 'class' => "row" ], [
  869. '<div class="col-md-2">
  870. <form action="" method="POST">
  871. <input type="hidden" name="_runSync" value="1">
  872. <input type="submit" value="Synchronizuj" class="btn btn-primary btn-big">
  873. </form>
  874. </div>',
  875. '<div class="col-md-10" style="text-align: right;">
  876. <form action="" method="POST">
  877. <input type="hidden" name="_forceSyncAliasList" value="1">
  878. W razie problemów z aliasami pocztowymi:
  879. <input type="submit" value="Popraw aliasy" class="btn btn-xs btn-warning">
  880. </form>
  881. </div>',
  882. ]);
  883. }
  884. }