Users.php 41 KB

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