Users.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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. ?><div class="alert alert-info">Użytkownik został usunięty z danej grupy</div><?php
  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. ?><div class="alert alert-info">Dodano grupę [<?php echo $idGroup; ?>] do użytkownika [<?php echo $usrLogin; ?>]</div><?php
  453. }
  454. $this->printFormUserGroup($usrLogin);
  455. } catch (Exception $e) {
  456. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?>
  457. <br><a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrLogin; ?>">wróć</a>
  458. </div><?php
  459. echo UserActivity::showListInContainer();
  460. }
  461. echo '</div>';// .container
  462. UI::dol();
  463. }
  464. public function printFormUserGroup($usrLogin) {
  465. if (empty($usrLogin)) throw new Exception("Empty user login");
  466. $usrStorageDB = UserStorageFactory::getStorage('DB');
  467. if (!$usrStorageDB) throw new Exception("Storage DB not exists!");
  468. $usr = $usrStorageDB->getUser($usrLogin);
  469. if (!$usr) throw new Exception("Użytkownik '{$usrLogin}' nie istnieje.");
  470. $stanowiska = array();
  471. $stanowiska = $usrStorageDB->getUserProfiles($usrLogin, $fetchNested = false);
  472. uasort($stanowiska, array($this, 'sortStanowiskaByType'));
  473. $groups = UsersHelper::getGroupByUser($usr->primaryKey);
  474. DBG::_('DBG_SU', '>1', 'groups', $groups, __CLASS__, __FUNCTION__, __LINE__);
  475. $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
  476. DBG::_('DBG_SU', '>1', 'groupsNetwork', $groupsNetwork, __CLASS__, __FUNCTION__, __LINE__);
  477. $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
  478. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
  479. $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
  480. ?>
  481. <style type="text/css">
  482. .frm-groups .selectize-control { float:left; }
  483. .conn_groups {}
  484. .conn_groups .conn_groups-list {}
  485. .conn_groups .conn_groups-list .conn_groups-list_item { line-height:22px; }
  486. .conn_groups .conn_groups-list .conn_groups-list_item form { display:inline; margin:0; }
  487. .conn_groups .conn_groups-list_item-rmBtn { /*display:none;*/ opacity:0.4; margin:0; padding:0 10px; border:none; }
  488. .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { /*display:inline;*/ opacity:1; }
  489. </style>
  490. <div class="conn_groups">
  491. <h4>Ustalanie stanowiska</h4>
  492. <blockquote>
  493. Użytkownik
  494. <?php if ($usr->isDisabled) : ?>
  495. <span class="label label-danger">zablokowany!</span>
  496. <?php else : ?>
  497. <span class="label label-info">aktywny</span>
  498. <?php endif; ?>
  499. [<?php echo $usr->primaryKey; ?>] <b><?php echo $usr->name; ?></b> <code><?php echo $usr->login; ?></code>
  500. <?php if ($idZasobUsersTbl > 0) : ?>
  501. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usr->primaryKey; ?>"
  502. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
  503. <?php endif; ?>
  504. <a href="index.php?_route=Users&_task=syncUser&usrLogin=<?php echo $usr->login; ?>"
  505. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-retweet"></span> synchronizuj do LDAP</a>
  506. </blockquote>
  507. <h4>Przypisane grupy (<?php echo (!empty($stanowiska))? count($stanowiska) : 0; ?>):</h4>
  508. <?php if (!empty($stanowiska)) : ?>
  509. <ul class="conn_groups-list">
  510. <?php foreach ($stanowiska as $vProfile) : ?>
  511. <li class="conn_groups-list_item">
  512. <?php echo $vProfile->group->realName; ?>
  513. <?php if ($vProfile->localisationId > 0) : ?>
  514. (lokalizacja [<?php echo $vProfile->localisationId; ?>])
  515. <?php endif; ?>
  516. <form class="form-inline frm-groups" action="" method="POST">
  517. <input type="hidden" name="_subTask" value="removeUserGroup">
  518. <button name="idProfileToRemove" value="<?php echo $vProfile->profileId; ?>" class="btn-link btn-sm conn_groups-list_item-rmBtn" title="usuń grupę" onclick="return confirm('Czy jesteś pewien że chcesz usunąć przypisanie do grupy <?php echo $vProfile->group->realName; ?>?');"><i class="glyphicon glyphicon-remove"></i></button>
  519. </form>
  520. </li>
  521. <?php endforeach; ?>
  522. </ul>
  523. <?php endif; ?>
  524. <?php if ($typeSpecialUserGroups && $typeSpecialTelboxes) : ?>
  525. <h4>Dodaj grupę:</h4>
  526. <form class="form-horizontal" action="" method="POST">
  527. <input type="hidden" name="_subTask" value="addUserGroup">
  528. <div class="form-group">
  529. <label class="col-sm-3 control-label" for="idGroup">Grupa</label>
  530. <div class="col-sm-9">
  531. <?php
  532. $fName = 'idGroup';
  533. $fldParams = array();
  534. $fldParams['allowCreate'] = false;
  535. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdGroup";
  536. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  537. echo $typeSpecialUserGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  538. ?>
  539. </div>
  540. </div>
  541. <div class="form-group">
  542. <label class="col-sm-3 control-label" for="addTelboxesID">Lokalizacja</label>
  543. <div class="col-sm-9">
  544. <?php
  545. $fName = 'addTelboxesID';
  546. $fldParams = array();
  547. $fldParams['allowCreate'] = false;
  548. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdTelboxes";
  549. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  550. echo $typeSpecialTelboxes->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
  551. ?>
  552. </div>
  553. </div>
  554. <div class="form-group">
  555. <div class="col-sm-9 col-sm-offset-3">
  556. <button type="submit" class="btn btn-xs btn-primary">dodaj grupę</button>
  557. </div>
  558. </div>
  559. </form>
  560. <?php endif; ?>
  561. </div>
  562. <?php
  563. {// show table crm_auth_profile
  564. $idZasobCrmAuthProfile = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
  565. if ($idZasobCrmAuthProfile <= 0) throw new Exception("Can not find id zasob 'CRM_AUTH_PROFILE'");
  566. $zasobObj = ProcesHelper::getZasobTableInfo($idZasobCrmAuthProfile);
  567. if (!$zasobObj) throw new Exception("Zasob TABELA ID={$idZasobCrmAuthProfile} nie istnieje");
  568. UserActivity::add($idZasobCrmAuthProfile);
  569. $userAcl = User::getAcl();
  570. if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ID={$zasobObj->ID}");
  571. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  572. $forceTblAclInit = ('1' == V::get('_force', '', $_GET));
  573. $tblAcl->init($forceTblAclInit);
  574. $forceFilterInit = array();
  575. $filterInit = new stdClass();
  576. $filterInit->currSortCol = 'ID';
  577. $filterInit->currSortFlip = 'desc';
  578. foreach ($_GET as $k => $v) {
  579. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
  580. $filterInit->$k = $v;
  581. }
  582. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
  583. $filterInit->$k = $v;
  584. }
  585. else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  586. $fldName = substr($k, 3);
  587. $forceFilterInit[$fldName] = $v;
  588. }
  589. }
  590. $forceFilterInit['REMOTE_ID'] = $usr->primaryKey;
  591. $forceFilterInit['REMOTE_TABLE'] = 'ADMIN_USERS';
  592. $tbl = new TableAjax($tblAcl);
  593. $tbl->setLabel($zasobObj->OPIS);
  594. $tbl->setFilterInit($filterInit);
  595. if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
  596. $tbl->addRowFunction('edit');
  597. $tbl->addRowFunction('hist');
  598. $tbl->addRowFunction('files');
  599. $tbl->addRowFunction('cp');
  600. echo $tbl->render();
  601. }
  602. }
  603. public function sortStanowiskaByType($a, $b) {
  604. if ($a->group->type != $a->group->type) {
  605. if ($a->group->type == 'network') {
  606. return 1;
  607. }
  608. else if ($a->group->type == 'local') {
  609. return -1;
  610. }
  611. }
  612. return 0;
  613. }
  614. public function removeUserGroup($usrLogin, $idProfileToRemove) {
  615. if (!$usrLogin) throw new Exception("Wrong param user login!");
  616. if (!$idProfileToRemove) throw new Exception("Wrong param id profile to remove!");
  617. $usrStorageDB = UserStorageFactory::getStorage('DB');
  618. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  619. $profile = $usrStorageDB->getProfileById($idProfileToRemove);
  620. if (!$profile) throw new Exception("Error profile not exists!");
  621. $usrStorageDB->removeUserGroupByProfileId($usrLogin, $profile->group, $idProfileToRemove);
  622. }
  623. public function addUserGroup($usrLogin, $idGroup, $idTelboxes) {
  624. DBG::_('DBG_NG', '>0', 'post', $_POST, __CLASS__, __FUNCTION__, __LINE__);
  625. if (!$usrLogin) throw new Exception("Wrong param user login!");
  626. $usrStorageDB = UserStorageFactory::getStorage('DB');
  627. if (!$usrStorageDB) throw new Exception("Error storage not exists!");
  628. $usr = $usrStorageDB->getUser($usrLogin);
  629. if (!$usr) throw new Exception("Użytkownik {$usrLogin} nie istnieje.");
  630. if ($idGroup > 0) {
  631. $groupToAdd = $usrStorageDB->getGroupWithoutNested($idGroup);
  632. if (!$groupToAdd) throw new Exception("Grupa [{$idGroup}] nie istnieje");
  633. $added = $usrStorageDB->addUserGroup($usrLogin, $groupToAdd, $idTelboxes);
  634. }
  635. }
  636. public function typeSpecialIdGroupAction() {
  637. header("Content-type: application/json");
  638. $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
  639. $query = V::get('q', '', $_REQUEST);
  640. $rawRows = null;
  641. $rows = $typeSpecialUserGroups->getValuesWithExports($query);
  642. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  643. foreach ($rows as $kID => $vItem) {
  644. $itemJson = new stdClass();
  645. $itemJson->id = $vItem->id;
  646. $itemJson->name = $vItem->param_out;
  647. if (!empty($vItem->exports)) {
  648. $itemJson->exports = $vItem->exports;
  649. }
  650. $jsonData[] = $itemJson;
  651. }
  652. echo json_encode($jsonData);
  653. }
  654. public function typeSpecialIdTelboxesAction() {
  655. header("Content-type: application/json");
  656. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
  657. $query = V::get('q', '', $_REQUEST);
  658. $rawRows = null;
  659. $rows = $typeSpecialTelboxes->getValuesWithExports($query);
  660. DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
  661. foreach ($rows as $kID => $vItem) {
  662. $itemJson = new stdClass();
  663. $itemJson->id = $vItem->id;
  664. $itemJson->name = $vItem->param_out;
  665. if (!empty($vItem->exports)) {
  666. $itemJson->exports = $vItem->exports;
  667. }
  668. $jsonData[] = $itemJson;
  669. }
  670. echo json_encode($jsonData);
  671. }
  672. public function syncGroupAction() {
  673. $idGroup = V::get('idGroup', 0, $_GET, 'int');
  674. $group = null;
  675. UI::gora();
  676. UI::menu();
  677. echo '<div class="container">';
  678. try {
  679. if (!$idGroup) throw new Exception("Brak numeru grupy!");
  680. $idZasobTableZasoby = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
  681. $usrStorageDB = UserStorageFactory::getStorage('DB');
  682. if ($usrStorageDB) $group = $usrStorageDB->getGroup($idGroup);
  683. ?>
  684. <h4>Synchronizacja grupy do bazy LDAP</h4>
  685. <blockquote>
  686. Grupa [<?php echo $idGroup; ?>]:
  687. <?php if ($group) : ?>
  688. <code><?php echo $group->type; ?></code> <?php echo $group->zasobDESC; ?>
  689. <?php endif; ?>
  690. <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>
  691. <a class="btn btn-xs btn-link" href="index.php?_route=Users&_task=nestedGroups&idGroup=<?php echo $idGroup; ?>"><i class="glyphicon glyphicon-random"></i> ustal powiązania między grupami uprawnień</a>
  692. </blockquote>
  693. <?php
  694. $this->syncGroup($idGroup);
  695. } catch (Exception $e) {
  696. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?></div><?php
  697. }
  698. echo '</div>';// .container
  699. UI::dol();
  700. }
  701. public function syncGroup($idGroup) {
  702. $usrStorageDB = UserStorageFactory::getStorage('DB');
  703. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  704. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  705. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  706. $groupFrom = $usrStorageDB->getGroup($idGroup);
  707. if (!$groupFrom) {
  708. $db = DB::getDB();
  709. $zasob = $db->get_by_id('CRM_LISTA_ZASOBOW', $idGroup);
  710. if (!$zasob) {
  711. throw new Exception("Zasób {$idGroup} nie istnieje");
  712. } else {
  713. throw new Exception("Zasób {$idGroup} nie jest grupą tylko {$zasob->TYPE}");
  714. }
  715. }
  716. else {
  717. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  718. $syncTodoList = $synUsers->getSyncGroupTodoList($idGroup, $syncNestedGroups = true);
  719. ?>
  720. <?php if (empty($syncTodoList)) : ?>
  721. <div class="alert alert-info">Brak zadań do wykonania - grupa zsynchronizowana</div>
  722. <?php else : ?>
  723. <div class="well">
  724. <p>Lista zadań do wykonania:</p>
  725. <ul>
  726. <?php foreach ($syncTodoList as $vTask) : ?>
  727. <li><?php echo $vTask; ?></li>
  728. <?php endforeach; ?>
  729. </ul>
  730. </div>
  731. <?php endif; ?>
  732. <?php
  733. if ('1' == V::get('_runSync', '', $_POST)) {
  734. $synced = $synUsers->syncGroup($idGroup, $syncNestedGroups = true);
  735. if (!$synced) {
  736. ?>
  737. <div class="alert alert-danger">
  738. Nie udało się zsynchronizować grupy [<?php echo $idGroup; ?>].
  739. </div>
  740. <?php
  741. 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>';
  742. }
  743. else {
  744. ?>
  745. <div class="alert alert-success">
  746. Synchronizacja grupy [<?php echo $idGroup; ?>] zakończona powodzeniem.
  747. </div>
  748. <?php
  749. }
  750. }
  751. else {
  752. ?>
  753. <form action="" method="POST">
  754. <input type="hidden" name="_runSync" value="1">
  755. <input type="submit" value="Synchronizuj" class="btn btn-primary btn-big">
  756. </form>
  757. <?php
  758. }
  759. }
  760. }
  761. public function syncUserAction() {
  762. UI::gora();
  763. UI::menu();
  764. $usrLogin = V::get('usrLogin', '', $_GET);
  765. echo '<div class="container">';
  766. try {
  767. if (empty($usrLogin)) throw new Exception("Empty user login");
  768. $usrStorageDB = UserStorageFactory::getStorage('DB');
  769. $usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
  770. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  771. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  772. echo '<h4>' . "Synchronizacja do LDAP" . '</h4>';
  773. $usrFrom = $usrStorageDB->getUser($usrLogin);
  774. DBG::_('DBG_SU', '>1', 'User from:', $usrFrom, __CLASS__, __FUNCTION__, __LINE__);
  775. if ($usrFrom) {
  776. $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
  777. $idZasobPermsTbl = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
  778. ?>
  779. <blockquote>
  780. Użytkownik
  781. <?php if ($usrFrom->isDisabled) : ?>
  782. <span class="label label-danger">zablokowany!</span>
  783. <?php else : ?>
  784. <span class="label label-info">aktywny</span>
  785. <?php endif; ?>
  786. [<?php echo $usrFrom->primaryKey; ?>] <b><?php echo $usrFrom->name; ?></b> <code><?php echo $usrFrom->login; ?></code>
  787. <?php if ($idZasobUsersTbl > 0) : ?>
  788. <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usrFrom->primaryKey; ?>"
  789. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
  790. <?php endif; ?>
  791. <?php if ($idZasobPermsTbl > 0) : ?>
  792. <a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrFrom->login; ?>"
  793. class="btn btn-xs btn-link"><span class="glyphicon glyphicon-user"></span> ustal stanowisko</a>
  794. <?php endif; ?>
  795. </blockquote>
  796. <?php
  797. }
  798. $this->syncUser($usrLogin, $usrStorageDB, $usrStorageLdap);
  799. } catch (Exception $e) {
  800. ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?></div><?php
  801. }
  802. echo '</div>';// .container
  803. UI::dol();
  804. }
  805. public function syncUser($userName, $usrStorageDB, $usrStorageLdap,$forceSync=null) {
  806. if (empty($userName)) throw new Exception("Empty user login");
  807. if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
  808. if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
  809. $synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
  810. if ('1' == V::get('_runSync', '', $_POST) or $forceSync) {
  811. $synced = $synUsers->syncUser($userName);
  812. if (!$synced) {
  813. UI::alert('danger', "Nie udało się zsynchronizować uprawnień użytkownika {$userName}.");
  814. $errorsList = $synUsers->getErrorsMsgListWithDbg();
  815. if (!empty($errorsList)) {
  816. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  817. echo "Błędy:\n" . implode("\n", $errorsList);
  818. echo '</pre>';
  819. }
  820. }
  821. else {
  822. UI::alert('success', "Synchronizacja uprawnień użytkownika {$userName} zakończona powodzeniem.");
  823. }
  824. }
  825. if ('1' == V::get('_forceSyncAliasList', '', $_POST)) {
  826. $synced = $synUsers->forceSyncUserAliasList($userName);
  827. if (!$synced) {
  828. UI::alert('danger', "Nie udało się poprawić aliasów {$userName}.");
  829. $errorsList = $synUsers->getErrorsMsgListWithDbg();
  830. if (!empty($errorsList)) {
  831. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">';
  832. echo "Błędy:\n" . implode("\n", $errorsList);
  833. echo '</pre>';
  834. }
  835. }
  836. else {
  837. UI::alert('success', "Synchronizacja listy aliasów pocztowych użytkownika {$userName} zakończona powodzeniem.");
  838. }
  839. }
  840. $syncTodoList = $synUsers->getSyncUserTodoList($userName);
  841. ?>
  842. <?php if (empty($syncTodoList)) : ?>
  843. <div class="alert alert-info">Brak zadań do wykonania - użytkownik zsynchronizowany</div>
  844. <?php else : ?>
  845. <div class="well">
  846. <p>Lista zadań do wykonania:</p>
  847. <ul>
  848. <?php foreach ($syncTodoList as $vTask) : ?>
  849. <li><?php echo $vTask; ?></li>
  850. <?php endforeach; ?>
  851. </ul>
  852. </div>
  853. <?php endif; ?>
  854. <div class="row">
  855. <div class="col-md-2">
  856. <form action="" method="POST">
  857. <input type="hidden" name="_runSync" value="1">
  858. <input type="submit" value="Synchronizuj" class="btn btn-primary btn-big">
  859. </form>
  860. </div>
  861. <div class="col-md-10" style="text-align: right;">
  862. <form action="" method="POST">
  863. <input type="hidden" name="_forceSyncAliasList" value="1">
  864. W razie problemów z aliasami pocztowymi:
  865. <input type="submit" value="Popraw aliasy" class="btn btn-xs btn-warning">
  866. </form>
  867. </div>
  868. </div>
  869. <?php
  870. }
  871. }