menu();
UI::dol();
}
public function menu() {
$usrLogin = User::getLogin();
?>
';
try {
$idGroup = V::get('idGroup', 0, $_GET, 'int');
if (empty($idGroup)) throw new Exception("Empty group id");
$subTask = V::get('_subTask', '', $_POST);
$successMsg = null;
if ('removeParentGroup' == $subTask) {
$idParentGroupToRemove = V::get('idParentGroupToRemove', 0, $_POST, 'int');
$this->nestedGroupsRemoveParentGroup($idGroup, $idParentGroupToRemove);
$successMsg = "Usunięto grupę nadrzędną [{$idParentGroupToRemove}] do grupy [{$idGroup}]";
} else if ('removeNestedGroup' == $subTask) {
$idNestedGroupToRemove = V::get('idNestedGroupToRemove', 0, $_POST, 'int');
$this->nestedGroupsRemoveNestedGroup($idGroup, $idNestedGroupToRemove);
$successMsg = "Usunięto grupę zagnieżdżoną [{$idNestedGroupToRemove}] do grupy [{$idGroup}]";
} else if ('addParentGroup' == $subTask) {
$idParentGroupToAdd = V::get('idParentGroupToAdd', 0, $_POST, 'int');
$this->nestedGroupsAddParentGroup($idGroup, $idParentGroupToAdd);
$successMsg = "Dodano grupę nadrzędną [{$idParentGroupToAdd}] do grupy [{$idGroup}]";
} else if ('addNestedGroup' == $subTask) {
$idNestedGroupToAdd = V::get('idNestedGroupToAdd', 0, $_POST, 'int');
$this->nestedGroupsAddNestedGroup($idGroup, $idNestedGroupToAdd);
$successMsg = "Dodano grupę zagnieżdżoną [{$idNestedGroupToAdd}] do grupy [{$idGroup}]";
}
if (!empty($successMsg)) {
?>
printFormNestedGroups($idGroup);
} catch (Exception $e) {
?>
';// .container
UI::dol();
}
public function nestedGroupsRemoveParentGroup($idGroup, $idParentGroupToRemove) {
if (!$idGroup) throw new Exception("Wrong param id group!");
if (!$idParentGroupToRemove) throw new Exception("Wrong param id parent group to remove!");
$usrStorageDB = UserStorageFactory::getStorage('DB');
if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
$group = $usrStorageDB->getGroupWithoutNested($idGroup);
if (!$group) throw new Exception("Error: group not exists!");
$parentGroup = $usrStorageDB->getGroupWithoutNested($idParentGroupToRemove);
if (!$parentGroup) throw new Exception("Error: parent group not exists!");
$usrStorageDB->removeParentGroup($idGroup, $idParentGroupToRemove);
}
public function nestedGroupsRemoveNestedGroup($idGroup, $idNestedGroupToRemove) {
if (!$idGroup) throw new Exception("Wrong param id group!");
if (!$idNestedGroupToRemove) throw new Exception("Wrong param id parent group to remove!");
$usrStorageDB = UserStorageFactory::getStorage('DB');
if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
$group = $usrStorageDB->getGroupWithoutNested($idGroup);
if (!$group) throw new Exception("Error: group not exists!");
$nestedGroup = $usrStorageDB->getGroupWithoutNested($idNestedGroupToRemove);
if (!$nestedGroup) throw new Exception("Error: nested group not exists!");
$usrStorageDB->removeNestedGroup($idGroup, $idNestedGroupToRemove);
}
public function nestedGroupsAddParentGroup($idGroup, $idParentGroupToAdd) {
if ($idGroup <= 0) throw new Exception("Wrong param id group");
if ($idParentGroupToAdd <= 0) throw new Exception("Wrong param id parent group to add");
$usrStorageDB = UserStorageFactory::getStorage('DB');
if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
$group = $usrStorageDB->getGroupWithoutNested($idGroup);
if (!$group) throw new Exception("Error: group [{$idGroup}] not exists!");
$parentGroup = $usrStorageDB->getGroupWithoutNested($idParentGroupToAdd);
if (!$parentGroup) throw new Exception("Error: parent group [{$idParentGroupToAdd}] not exists!");
$usrStorageDB->addParentGroup($idGroup, $idParentGroupToAdd);
}
public function nestedGroupsAddNestedGroup($idGroup, $idNestedGroupToAdd) {
if ($idGroup <= 0) throw new Exception("Wrong param id group");
if ($idNestedGroupToAdd <= 0) throw new Exception("Wrong param id parent group to add");
$usrStorageDB = UserStorageFactory::getStorage('DB');
if (!$usrStorageDB) throw new Exception("Error: storage db not exists!");
$group = $usrStorageDB->getGroupWithoutNested($idGroup);
if (!$group) throw new Exception("Error: group not exists!");
$nestedGroup = $usrStorageDB->getGroupWithoutNested($idNestedGroupToAdd);
if (!$nestedGroup) throw new Exception("Error: nested group [{$idNestedGroupToAdd}] not exists!");
$usrStorageDB->addNestedGroup($idGroup, $idNestedGroupToAdd);
}
public function printFormNestedGroups($idGroup) {
$linkTypeIdNestedGroups = 5;
if (!$idGroup) throw new Exception("Wrong param group id!");
$usrStorageDB = UserStorageFactory::getStorage('DB');
if (!$usrStorageDB) throw new Exception("Error storage not exists!");
$group = $usrStorageDB->getGroup($idGroup);
if (!$group) throw new Exception("Grupa {$idGroup} nie istnieje.");
DBG::_('DBG_SU', '>1', 'group', $group, __CLASS__, __FUNCTION__, __LINE__);
{
$idZasob = ProcesHelper::getZasobTableID('ITEM_LINKS');
if ($idZasob <= 0) throw new Exception("Brak zasobu dla tabeli 'ITEM_LINKS'");
$zasobObj = ProcesHelper::getZasobTableInfo($idZasob);
if (!$zasobObj) throw new Exception("Zasob TABELA ID={$idZasob} nie istnieje");
UserActivity::add($idZasob);
$userAcl = User::getAcl();
$userAcl->fetchGroups();
if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ID={$zasobObj->ID}");
}
if (V::get('_testUsrGroupsLdapLvl0', '', $_GET)) {
$usrLogin = User::getLogin();
$groups = array(); $groupsLvl3 = array();
$groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 0);
foreach ($groupsNetwork as $vGroup) {
$groups[$vGroup->cn] = $vGroup->appleUID;
}
DBG::_(true, true, "groups ldap lvl 0", $groups, __CLASS__, __FUNCTION__, __LINE__);
$groupsNetwork = UsersLdapHelper::getUserGroups($usrLogin, 3);
foreach ($groupsNetwork as $vGroup) {
$groupsLvl3[$vGroup->cn] = $vGroup->appleUID;
}
DBG::_(true, true, "groups ldap lvl 3", $groupsLvl3, __CLASS__, __FUNCTION__, __LINE__);
}
$group->getParentGroups();
DBG::_('DBG_NG', '>1', "group with nested", $group, __CLASS__, __FUNCTION__, __LINE__);
$typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
$groupUsers = array();
$groupNestedUsers = array();
$idZasobTableUsers = ProcesHelper::getZasobTableID('ADMIN_USERS');
if ($group->zasobID > 0) {
$groupUsers = UsersHelper::getUsersByGroupId($idGroup);
$groupNestedUsers = UsersHelper::getUsersByGroupsIds(array_keys($group->nestedGroups), array_keys($groupUsers));
}
$idZasobTableZasoby = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
?>
Grupy uprawnień
Grupa []: type; ?> zasobDESC; ?>
edytuj
synchronizuj do LDAP
Udostępnij rekordy innym grupom
np. przełożonemu.
nestedGroups)) : ?>
nestedGroups as $vNestedGroup) : ?>
-
[zasobID; ?>]
type; ?>
zasobDESC; ?>
-
Grupy, które udostępniają rekordy
np. grupy podrzędnych pracowników lub dział, podmiot.
parentGroups)) : ?>
parentGroups as $vParentGroup) : ?>
-
[zasobID; ?>]
type) : ?>
type; ?>
zasobDESC; ?>
-
Użytkownicy:
Brak użytkowników przypisanych bezpośrednio do grupy
ADM_NAME; ?>
EMPLOYEE_TYPE; ?>
ADM_PHONE)) : ?>
Tel.: ADM_PHONE; ?>
EMAIL)) : ?>
EMAIL; ?>
Użytkownicy z uprawnieniami do rekordów
Brak
ADM_NAME; ?>
EMPLOYEE_TYPE; ?>
ADM_PHONE)) : ?>
Tel.: ADM_PHONE; ?>
EMAIL)) : ?>
EMAIL; ?>
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;
}
}
$tblZasobyID = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
$forceFilterInit['TABLE_1_NAME'] = 'CRM_LISTA_ZASOBOW';
$forceFilterInit['TABLE_1_ZASOB_ID'] = $tblZasobyID;
$forceFilterInit['TABLE_1_ID'] = $group->zasobID;
$forceFilterInit['TABLE_2_NAME'] = 'CRM_LISTA_ZASOBOW';
$forceFilterInit['TABLE_2_ZASOB_ID'] = $tblZasobyID;
$forceFilterInit['LINKS_TYPE_ID'] = $linkTypeIdNestedGroups;
$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');
echo $tbl->render();
}
}
public function typeSpecialIdNestedGroupAction() {
header("Content-type: application/json");
$typeSpecialNestedGroups = TypespecialVariable::getInstance(-1, '__NESTED_GROUPS');
$query = V::get('q', '', $_REQUEST);
$rawRows = null;
$rows = $typeSpecialNestedGroups->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 userGroupsAction() {
UI::gora();
UI::menu();
$usrLogin = V::get('usrLogin', '', $_GET);
echo '
';
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);
?>
Użytkownik został usunięty z danej grupy
addUserGroup($usrLogin, $idGroup, $idTelboxes);
?>
Dodano grupę [] do użytkownika []
printFormUserGroup($usrLogin);
} catch (Exception $e) {
?>
';// .container
UI::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');
?>
Ustalanie stanowiska
Użytkownik
isDisabled) : ?>
zablokowany!
aktywny
[primaryKey; ?>] name; ?> login; ?>
0) : ?>
edytuj
synchronizuj do LDAP
Przypisane grupy ():
-
group->realName; ?>
localisationId > 0) : ?>
(lokalizacja [localisationId; ?>])
Dodaj grupę:
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');
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");
$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");
$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 syncGroupAction() {
$idGroup = V::get('idGroup', 0, $_GET, 'int');
$group = null;
UI::gora();
UI::menu();
echo '
';
try {
if (!$idGroup) throw new Exception("Brak numeru grupy!");
$idZasobTableZasoby = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
$usrStorageDB = UserStorageFactory::getStorage('DB');
if ($usrStorageDB) $group = $usrStorageDB->getGroup($idGroup);
?>
Synchronizacja grupy do bazy LDAP
Grupa []:
type; ?> zasobDESC; ?>
edytuj
ustal powiązania między grupami uprawnień
syncGroup($idGroup);
} catch (Exception $e) {
?>
getMessage(); ?>
';// .container
UI::dol();
}
public function syncGroup($idGroup) {
$usrStorageDB = UserStorageFactory::getStorage('DB');
$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
$groupFrom = $usrStorageDB->getGroup($idGroup);
if (!$groupFrom) {
$db = DB::getDB();
$zasob = $db->get_by_id('CRM_LISTA_ZASOBOW', $idGroup);
if (!$zasob) {
throw new Exception("Zasób {$idGroup} nie istnieje");
} else {
throw new Exception("Zasób {$idGroup} nie jest grupą tylko {$zasob->TYPE}");
}
}
else {
$synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
$syncTodoList = $synUsers->getSyncGroupTodoList($idGroup, $syncNestedGroups = true);
?>
Brak zadań do wykonania - grupa zsynchronizowana
Lista zadań do wykonania:
syncGroup($idGroup, $syncNestedGroups = true);
if (!$synced) {
?>
Nie udało się zsynchronizować grupy [].
errors: (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($synUsers->getErrorsMsgListWithDbg());echo'';
}
else {
?>
Synchronizacja grupy [] zakończona powodzeniem.
';
try {
if (empty($usrLogin)) throw new Exception("Empty user login");
$usrStorageDB = UserStorageFactory::getStorage('DB');
$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
echo '
' . "Synchronizacja do LDAP" . '
';
$usrFrom = $usrStorageDB->getUser($usrLogin);
DBG::_('DBG_SU', '>1', 'User from:', $usrFrom, __CLASS__, __FUNCTION__, __LINE__);
if ($usrFrom) {
$idZasobUsersTbl = ProcesHelper::getZasobTableID('ADMIN_USERS');
$idZasobPermsTbl = ProcesHelper::getZasobTableID('CRM_AUTH_PROFILE');
?>
Użytkownik
isDisabled) : ?>
zablokowany!
aktywny
[primaryKey; ?>] name; ?> login; ?>
0) : ?>
edytuj
0) : ?>
ustal stanowisko
syncUser($usrLogin, $usrStorageDB, $usrStorageLdap);
} catch (Exception $e) {
?>
getMessage(); ?>
';// .container
UI::dol();
}
public function syncUser($userName, $usrStorageDB, $usrStorageLdap,$forceSync=null) {
if (empty($userName)) throw new Exception("Empty user login");
if (!$usrStorageDB) throw new Exception("Error storage DB not exists");
if (!$usrStorageLdap) throw new Exception("Error storage Ldap not exists");
$synUsers = new SyncUsers($usrStorageDB, $usrStorageLdap);
if ('1' == V::get('_runSync', '', $_POST) or $forceSync) {
$synced = $synUsers->syncUser($userName);
if (!$synced) {
UI::alert('danger', "Nie udało się zsynchronizować uprawnień użytkownika {$userName}.");
$errorsList = $synUsers->getErrorsMsgListWithDbg();
if (!empty($errorsList)) {
echo'
';
echo "Błędy:\n" . implode("\n", $errorsList);
echo '';
}
}
else {
UI::alert('success', "Synchronizacja uprawnień użytkownika {$userName} zakończona powodzeniem.");
}
}
if ('1' == V::get('_forceSyncAliasList', '', $_POST)) {
$synced = $synUsers->forceSyncUserAliasList($userName);
if (!$synced) {
UI::alert('danger', "Nie udało się poprawić aliasów {$userName}.");
$errorsList = $synUsers->getErrorsMsgListWithDbg();
if (!empty($errorsList)) {
echo'
';
echo "Błędy:\n" . implode("\n", $errorsList);
echo '';
}
}
else {
UI::alert('success', "Synchronizacja listy aliasów pocztowych użytkownika {$userName} zakończona powodzeniem.");
}
}
$syncTodoList = $synUsers->getSyncUserTodoList($userName);
?>
Brak zadań do wykonania - użytkownik zsynchronizowany
Lista zadań do wykonania: