|
|
@@ -4,6 +4,11 @@ Lib::loadClass('RouteBase');
|
|
|
Lib::loadClass('UserStorageFactory');
|
|
|
Lib::loadClass('ProcesHelper');
|
|
|
Lib::loadClass('SyncUsers');
|
|
|
+Lib::loadClass('UsersHelper');
|
|
|
+Lib::loadClass('UsersLdapHelper');
|
|
|
+Lib::loadClass('TypespecialVariable');
|
|
|
+Lib::loadClass('TableAjax');
|
|
|
+Lib::loadClass('UserActivity');
|
|
|
|
|
|
class Route_Users extends RouteBase {
|
|
|
|
|
|
@@ -25,10 +30,276 @@ class Route_Users extends RouteBase {
|
|
|
?>
|
|
|
<ul>
|
|
|
<li><a href="index.php?_route=Users&_task=syncUser&usrLogin=<?php echo $usrLogin; ?>">Sync user <?php echo $usrLogin; ?></a></li>
|
|
|
+ <li><a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrLogin; ?>">Add group <?php echo $usrLogin; ?></a></li>
|
|
|
</ul>
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
+ public function userGroupsAction() {
|
|
|
+ SE_Layout::gora();
|
|
|
+ SE_Layout::menu();
|
|
|
+ $usrLogin = V::get('usrLogin', '', $_GET);
|
|
|
+ echo '<div class="container">';
|
|
|
+ try {
|
|
|
+ if (empty($usrLogin)) throw new Exception("Empty user login");
|
|
|
+ $subTask = V::get('_subTask', '', $_POST);
|
|
|
+ if ('removeUserGroup' == $subTask) {
|
|
|
+ $idProfileToRemove = V::get('idProfileToRemove', 0, $_POST, 'int');
|
|
|
+ $this->removeUserGroup($usrLogin, $idProfileToRemove);
|
|
|
+ ?><div class="alert alert-info">Użytkownik został usunięty z danej grupy</div><?php
|
|
|
+ } else if ('addUserGroup' == $subTask) {
|
|
|
+ $idGroup = V::get('idGroup', 0, $_POST, 'int');
|
|
|
+ $idTelboxes = V::get('addTelboxesID', 0, $_POST, 'int');
|
|
|
+ $this->addUserGroup($usrLogin, $idGroup, $idTelboxes);
|
|
|
+ ?><div class="alert alert-info">Dodano grupę [<?php echo $idGroup; ?>] do użytkownika [<?php echo $usrLogin; ?>]</div><?php
|
|
|
+ }
|
|
|
+ $this->printFormUserGroup($usrLogin);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?>
|
|
|
+ <br><a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrLogin; ?>">wróć</a>
|
|
|
+</div><?php
|
|
|
+ echo UserActivity::showListInContainer();
|
|
|
+ }
|
|
|
+ echo '</div>';// .container
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function printFormUserGroup($usrLogin) {
|
|
|
+ if (empty($usrLogin)) throw new Exception("Empty user login");
|
|
|
+ $usrStorageDB = UserStorageFactory::getStorage('DB');
|
|
|
+ if (!$usrStorageDB) throw new Exception("Storage DB not exists!");
|
|
|
+ $usr = $usrStorageDB->getUser($usrLogin);
|
|
|
+ if (!$usr) throw new Exception("Użytkownik '{$usrLogin}' nie istnieje.");
|
|
|
+ $stanowiska = array();
|
|
|
+ $stanowiska = $usrStorageDB->getUserProfiles($usrLogin, $fetchNested = false);
|
|
|
+ uasort($stanowiska, array($this, 'sortStanowiskaByType'));
|
|
|
+
|
|
|
+ $groups = UsersHelper::getGroupByUser($usr->primaryKey);
|
|
|
+ DBG::_('DBG_SU', '>1', 'groups', $groups, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+
|
|
|
+ $groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
|
|
|
+ DBG::_('DBG_SU', '>1', 'groupsNetwork', $groupsNetwork, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+
|
|
|
+ $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
|
|
|
+ $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
|
|
|
+ $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
|
|
|
+?>
|
|
|
+<style type="text/css">
|
|
|
+.frm-groups .selectize-control { float:left; }
|
|
|
+.conn_groups {}
|
|
|
+ .conn_groups .conn_groups-list {}
|
|
|
+ .conn_groups .conn_groups-list .conn_groups-list_item { line-height:22px; }
|
|
|
+ .conn_groups .conn_groups-list .conn_groups-list_item form { display:inline; margin:0; }
|
|
|
+ .conn_groups .conn_groups-list_item-rmBtn { /*display:none;*/ opacity:0.4; margin:0; padding:0 10px; border:none; }
|
|
|
+ .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { /*display:inline;*/ opacity:1; }
|
|
|
+</style>
|
|
|
+<div class="conn_groups">
|
|
|
+ <h4>Ustalanie stanowiska</h4>
|
|
|
+ <blockquote>
|
|
|
+ Użytkownik [<?php echo $usr->primaryKey; ?>] <b><?php echo $usr->name; ?></b> <code><?php echo $usr->login; ?></code>
|
|
|
+ <?php if ($idZasobUsersTbl > 0) : ?>
|
|
|
+ <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usr->primaryKey; ?>"
|
|
|
+ class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
|
|
|
+ <?php endif; ?>
|
|
|
+ <a href="index.php?_route=Users&_task=syncUser&usrLogin=<?php echo $usr->login; ?>"
|
|
|
+ class="btn btn-xs btn-link"><span class="glyphicon glyphicon-random"></span> synchronizuj do LDAP</a>
|
|
|
+ </blockquote>
|
|
|
+ <?php if (!empty($taskErrors)) : ?>
|
|
|
+ <div class="alert alert-danger">
|
|
|
+ <button type="button" class="close" data-dismiss="alert">×</button>
|
|
|
+ <?php echo implode('<br>', $taskErrors); ?>
|
|
|
+ </div>
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php if (!empty($taskMsgs)) : ?>
|
|
|
+ <div class="alert alert-success">
|
|
|
+ <button type="button" class="close" data-dismiss="alert">×</button>
|
|
|
+ <?php echo implode('<br>', $taskMsgs); ?>
|
|
|
+ </div>
|
|
|
+ <?php endif; ?>
|
|
|
+
|
|
|
+ <h4>Przypisane grupy (<?php echo (!empty($stanowiska))? count($stanowiska) : 0; ?>):</h4>
|
|
|
+ <?php if (!empty($stanowiska)) : ?>
|
|
|
+ <ul class="conn_groups-list">
|
|
|
+ <?php foreach ($stanowiska as $vProfile) : ?>
|
|
|
+ <li class="conn_groups-list_item">
|
|
|
+ <?php echo $vProfile->group->realName; ?>
|
|
|
+ <?php if ($vProfile->localisationId > 0) : ?>
|
|
|
+ (lokalizacja [<?php echo $vProfile->localisationId; ?>])
|
|
|
+ <?php endif; ?>
|
|
|
+ <form class="form-inline frm-groups" action="" method="POST">
|
|
|
+ <input type="hidden" name="_subTask" value="removeUserGroup">
|
|
|
+ <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>
|
|
|
+ </form>
|
|
|
+ </li>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </ul>
|
|
|
+ <?php endif; ?>
|
|
|
+
|
|
|
+ <?php if ($typeSpecialUserGroups && $typeSpecialTelboxes) : ?>
|
|
|
+ <h4>Dodaj grupę:</h4>
|
|
|
+ <form class="form-horizontal" action="" method="POST">
|
|
|
+ <input type="hidden" name="_subTask" value="addUserGroup">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-3 control-label" for="idGroup">Grupa</label>
|
|
|
+ <div class="col-sm-9">
|
|
|
+ <?php
|
|
|
+ $fName = 'idGroup';
|
|
|
+ $fldParams = array();
|
|
|
+ $fldParams['allowCreate'] = false;
|
|
|
+ $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdGroup";
|
|
|
+ //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
|
|
|
+ echo $typeSpecialUserGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
|
|
|
+ ?>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-3 control-label" for="addTelboxesID">Lokalizacja</label>
|
|
|
+ <div class="col-sm-9">
|
|
|
+ <?php
|
|
|
+ $fName = 'addTelboxesID';
|
|
|
+ $fldParams = array();
|
|
|
+ $fldParams['allowCreate'] = false;
|
|
|
+ $fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdTelboxes";
|
|
|
+ //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
|
|
|
+ echo $typeSpecialTelboxes->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
|
|
|
+ ?>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <div class="col-sm-9 col-sm-offset-3">
|
|
|
+ <button type="submit" class="btn btn-xs btn-primary">dodaj grupę</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+ <?php endif; ?>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
+ {// show table crm_auth_profile
|
|
|
+ $idZasobCrmAuthProfile = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
|
|
|
+ if ($idZasobCrmAuthProfile <= 0) throw new Exception("Can not find id zasob 'CRM_AUTH_PROFILE'");
|
|
|
+ $zasobObj = ProcesHelper::getZasobTableInfo($idZasobCrmAuthProfile);
|
|
|
+ if (!$zasobObj) throw new Exception("Zasob TABELA ID={$idZasobCrmAuthProfile} nie istnieje");
|
|
|
+ UserActivity::add($idZasobCrmAuthProfile);
|
|
|
+ $userAcl = User::getAcl();
|
|
|
+ if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ID={$zasobObj->ID}");
|
|
|
+ $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
|
|
|
+ $forceTblAclInit = ('1' == V::get('_force', '', $_GET));
|
|
|
+ $tblAcl->init($forceTblAclInit);
|
|
|
+
|
|
|
+ $forceFilterInit = array();
|
|
|
+ $filterInit = new stdClass();
|
|
|
+ $filterInit->currSortCol = 'ID';
|
|
|
+ $filterInit->currSortFlip = 'desc';
|
|
|
+ foreach ($_GET as $k => $v) {
|
|
|
+ if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
|
|
|
+ $filterInit->$k = $v;
|
|
|
+ }
|
|
|
+ else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
|
|
|
+ $filterInit->$k = $v;
|
|
|
+ }
|
|
|
+ else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
|
|
|
+ $fldName = substr($k, 3);
|
|
|
+ $forceFilterInit[$fldName] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $forceFilterInit['REMOTE_ID'] = $usr->primaryKey;
|
|
|
+ $forceFilterInit['REMOTE_TABLE'] = 'ADMIN_USERS';
|
|
|
+
|
|
|
+ $tbl = new TableAjax($tblAcl);
|
|
|
+ $tbl->setLabel($zasobObj->OPIS);
|
|
|
+ $tbl->setFilterInit($filterInit);
|
|
|
+ if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
|
|
|
+ $tbl->addRowFunction('edit');
|
|
|
+ $tbl->addRowFunction('hist');
|
|
|
+ $tbl->addRowFunction('files');
|
|
|
+ $tbl->addRowFunction('cp');
|
|
|
+ $tbl->showProcesInit(false);// hide Proces filter field
|
|
|
+ echo $tbl->render();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function sortStanowiskaByType($a, $b) {
|
|
|
+ if ($a->group->type != $a->group->type) {
|
|
|
+ if ($a->group->type == 'network') {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else if ($a->group->type == 'local') {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeUserGroup($usrLogin, $idProfileToRemove) {
|
|
|
+ if (!$usrLogin) throw new Exception("Wrong param user login!");
|
|
|
+ if (!$idProfileToRemove) throw new Exception("Wrong param id profile to remove!");
|
|
|
+ $usrStorageDB = UserStorageFactory::getStorage('DB');
|
|
|
+ if (!$usrStorageDB) throw new Exception("Error storage not exists!");
|
|
|
+ $profile = $usrStorageDB->getProfileById($idProfileToRemove);
|
|
|
+ if (!$profile) throw new Exception("Error profile not exists!");
|
|
|
+
|
|
|
+ $usrStorageDB->removeUserGroupByProfileId($usrLogin, $profile->group, $idProfileToRemove);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addUserGroup($usrLogin, $idGroup, $idTelboxes) {
|
|
|
+ DBG::_('DBG_NG', '>0', 'post', $_POST, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ if (!$usrLogin) throw new Exception("Wrong param user login!");
|
|
|
+ $usrStorageDB = UserStorageFactory::getStorage('DB');
|
|
|
+ if (!$usrStorageDB) throw new Exception("Error storage not exists!");
|
|
|
+ $usr = $usrStorageDB->getUser($usrLogin);
|
|
|
+ if (!$usr) throw new Exception("Użytkownik {$usrLogin} nie istnieje.");
|
|
|
+
|
|
|
+ if ($idGroup > 0) {
|
|
|
+ $groupToAdd = $usrStorageDB->getGroupWithoutNested($idGroup);
|
|
|
+ if (!$groupToAdd) throw new Exception("Grupa [{$idGroup}] nie istnieje");
|
|
|
+ $added = $usrStorageDB->addUserGroup($usrLogin, $groupToAdd, $idTelboxes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function typeSpecialIdGroupAction() {
|
|
|
+ header("Content-type: application/json");
|
|
|
+ Lib::loadClass('TypespecialVariable');
|
|
|
+ $typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
|
|
|
+
|
|
|
+ $query = V::get('q', '', $_REQUEST);
|
|
|
+ $rawRows = null;
|
|
|
+ $rows = $typeSpecialUserGroups->getValuesWithExports($query);
|
|
|
+ DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ foreach ($rows as $kID => $vItem) {
|
|
|
+ $itemJson = new stdClass();
|
|
|
+ $itemJson->id = $vItem->id;
|
|
|
+ $itemJson->name = $vItem->param_out;
|
|
|
+ if (!empty($vItem->exports)) {
|
|
|
+ $itemJson->exports = $vItem->exports;
|
|
|
+ }
|
|
|
+ $jsonData[] = $itemJson;
|
|
|
+ }
|
|
|
+ echo json_encode($jsonData);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function typeSpecialIdTelboxesAction() {
|
|
|
+ header("Content-type: application/json");
|
|
|
+
|
|
|
+ Lib::loadClass('TypespecialVariable');
|
|
|
+ $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
|
|
|
+
|
|
|
+ $query = V::get('q', '', $_REQUEST);
|
|
|
+ $rawRows = null;
|
|
|
+ $rows = $typeSpecialTelboxes->getValuesWithExports($query);
|
|
|
+ DBG::_('DBG', '>0', "rows(q={$query})", $rows, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ foreach ($rows as $kID => $vItem) {
|
|
|
+ $itemJson = new stdClass();
|
|
|
+ $itemJson->id = $vItem->id;
|
|
|
+ $itemJson->name = $vItem->param_out;
|
|
|
+ if (!empty($vItem->exports)) {
|
|
|
+ $itemJson->exports = $vItem->exports;
|
|
|
+ }
|
|
|
+ $jsonData[] = $itemJson;
|
|
|
+ }
|
|
|
+ echo json_encode($jsonData);
|
|
|
+ }
|
|
|
+
|
|
|
public function syncUserAction() {
|
|
|
SE_Layout::gora();
|
|
|
SE_Layout::menu();
|
|
|
@@ -42,35 +313,30 @@ class Route_Users extends RouteBase {
|
|
|
if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
|
|
|
if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
|
|
|
|
|
|
- echo '<h4>' . "Synchronizacja użytkownika <code>{$usrLogin}</code>" . '</h4>';
|
|
|
+ echo '<h4>' . "Synchronizacja do LDAP" . '</h4>';
|
|
|
$usrFrom = $usrStorageDB->getUser($usrLogin);
|
|
|
DBG::_('DBG_SU', '>1', 'User from:', $usrFrom, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
if ($usrFrom) {
|
|
|
- $zasobPermsTblId = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
|
|
|
- if ($zasobPermsTblId > 0) {
|
|
|
- // TODO: ?_route=Users&_task=addGroup&usrLogin={$usrFrom->login}
|
|
|
- ?>
|
|
|
- <p>Ustal stanowisko:
|
|
|
- <a href="index.php?MENU_INIT=USER_ADD_GROUP&usrLogin=<?php echo $usrFrom->login; ?>">ustal stanowisko</a>
|
|
|
- </p>
|
|
|
-<?php
|
|
|
- }
|
|
|
- $zasobUsersTblId = ProcesHelper::getZasobTableID('ADMIN_USERS');
|
|
|
- if ($zasobUsersTblId > 0) {
|
|
|
- // /index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=4095#EDIT/4527
|
|
|
- ?>
|
|
|
- <p>Edytuj:
|
|
|
- <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $zasobUsersTblId; ?>#EDIT/<?php echo $usrFrom->primaryKey; ?>">edytuj</a>
|
|
|
- </p>
|
|
|
+ $idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
|
|
|
+ $idZasobPermsTbl = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
|
|
|
+?>
|
|
|
+ <blockquote>
|
|
|
+ Użytkownik [<?php echo $usrFrom->primaryKey; ?>] <b><?php echo $usrFrom->name; ?></b> <code><?php echo $usrFrom->login; ?></code>
|
|
|
+ <?php if ($idZasobUsersTbl > 0) : ?>
|
|
|
+ <a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $idZasobUsersTbl; ?>#EDIT/<?php echo $usrFrom->primaryKey; ?>"
|
|
|
+ class="btn btn-xs btn-link"><span class="glyphicon glyphicon-pencil"></span> edytuj</a>
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php if ($idZasobPermsTbl > 0) : ?>
|
|
|
+ <a href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo $usrFrom->login; ?>"
|
|
|
+ class="btn btn-xs btn-link"><span class="glyphicon glyphicon-user"></span> ustal stanowisko</a>
|
|
|
+ <?php endif; ?>
|
|
|
+ </blockquote>
|
|
|
<?php
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
$this->syncUser($usrLogin, $usrStorageDB, $usrStorageLdap);
|
|
|
} catch (Exception $e) {
|
|
|
- ?>
|
|
|
-<div class="alert alert-danger"><?php echo $e->getMessage(); ?></div>
|
|
|
-<?php
|
|
|
+ ?><div class="alert alert-danger"><?php echo $e->getMessage(); ?></div><?php
|
|
|
}
|
|
|
echo '</div>';// .container
|
|
|
SE_Layout::dol();
|