Users.php 37 KB

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