Users.php 38 KB

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