Просмотр исходного кода

mv GROUP_ADD_NESTEDGROUPS to route Users

Piotr Labudda 10 лет назад
Родитель
Сommit
84f91ee3ef
3 измененных файлов с 469 добавлено и 87 удалено
  1. 403 18
      SE/se-lib/Route/Users.php
  2. 8 8
      SE/se-lib/SyncUsers.php
  3. 58 61
      SE/se-lib/UserStorageDB.php

+ 403 - 18
SE/se-lib/Route/Users.php

@@ -28,11 +28,410 @@ class Route_Users extends RouteBase {
 	public function menu() {
 		$usrLogin = User::getLogin();
 		?>
-<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>
+<div class="container">
+	<h3>Użytkownicy i grupy</h3>
+	<ul>
+		<li>
+			<form class="form-inline" action="index.php" method="GET">
+				<input type="hidden" name="_route" value="Users">
+				<input type="hidden" name="_task" value="syncUser">
+				<label for="usrLogin">login: </label>
+				<input type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
+				<input type="submit" value="Synchronizuj do bazy LDAP" class="btn btn-xs btn-default">
+			</form>
+		</li>
+		<li>
+			<form class="form-inline" action="index.php" method="GET">
+				<input type="hidden" name="_route" value="Users">
+				<input type="hidden" name="_task" value="userGroups">
+				<label for="usrLogin">login: </label>
+				<input type="text" name="usrLogin" value="<?php echo $usrLogin; ?>">
+				<input type="submit" value="Dodaj grupy" class="btn btn-xs btn-default">
+			</form>
+		</li>
+		<li>
+			<form class="form-inline" action="index.php" method="GET">
+				<input type="hidden" name="_route" value="Users">
+				<input type="hidden" name="_task" value="nestedGroups">
+				<label for="idGroup">id grupy: </label>
+				<input type="text" name="idGroup" value="">
+				<input type="submit" value="Grupy uprawnień" class="btn btn-xs btn-default">
+			</form>
+		</li>
+	</ul>
+</div>
+<?php
+	}
+
+	public function nestedGroupsAction() {
+		SE_Layout::gora();
+		SE_Layout::menu();
+		echo '<div class="container">';
+		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)) {
+				?><div class="alert alert-success"><?php echo $successMsg; ?></div><?php
+			}
+			$this->printFormNestedGroups($idGroup);
+		} catch (Exception $e) {
+			?><div class="alert alert-danger"><?php echo $e->getMessage(); ?>
+	<br><a href="index.php?_route=Users">wróć</a>
+</div><?php
+			echo UserActivity::showListInContainer();
+		}
+		echo '</div>';// .container
+		SE_Layout::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));
+		}
+
+?>
+<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:inline; margin:0; padding:0 6px; border:none; opacity:0.4; }
+  .conn_groups .conn_groups-list_item-editBtn {  margin:0 6px; padding:0; border:none; opacity:0.4; }
+  .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-rmBtn { display:inline; opacity:1; }
+  .conn_groups .conn_groups-list_item:hover .conn_groups-list_item-editBtn { opacity:1; }
+.users-with-perms {}
+ .users-with-perms address { padding:0 6px; border:1px solid #eee; }
+ .users-with-perms address:hover { border-color:#333; }
+</style>
+<div class="container conn_groups">
+	<h3>Grupy uprawnień
+		<!-- <em style="color:#ccc;">(Nested Groups)</em> -->
+	</h3>
+	<p>
+		<b>Zasób [<?php echo $idGroup; ?>]</b>: <?php echo $group->type; ?> <?php echo $group->zasobDESC; ?>
+		<a class="btn btn-xs btn-primary" href="index.php?MENU_INIT=SYNC_LDAP_PERMS&syncGroup=<?php echo $idGroup; ?>">synchronizuj do LDAP</a>
+	</p>
+
+	<br>
+
+	<div class="row">
+		<div class="col-md-6">
+<!--			<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>:
+				</p> -->
+			<blockquote>
+<!--				<h5>Ustal grupy, które będą miały uprawnienia do rekordów dostępnych dla
+					[<?php echo $group->zasobID; ?>] <?php echo $group->zasobDESC; ?>
+				</h5>
+				<small>np. grupy podrzędnych pracowników.</small> -->
+				<h5>Udostępnij rekordy innym grupom</h5>
+				<small>np. przełożonemu.</small>
+			</blockquote>
+			<ul class="conn_groups-list">
+				<?php if (!empty($group->nestedGroups)) : ?>
+					<?php foreach ($group->nestedGroups as $vNestedGroup) : ?>
+						<li class="conn_groups-list_item">
+							[<?php echo $vNestedGroup->zasobID; ?>]
+							<?php echo $vNestedGroup->type; ?>
+							<?php echo $vNestedGroup->zasobDESC; ?>
+							<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>
+							<form action="" method="POST" class="form-inline frm-groups">
+								<input type="hidden" name="_subTask" value="removeNestedGroup">
+								<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>
+							</form>
+						</li>
+					<?php endforeach; ?>
+				<?php endif; ?>
+				<?php if ($typeSpecialNestedGroups) : ?>
+					<li>
+						<form action="" method="POST" class="form-inline frm-groups">
+							<input type="hidden" name="_subTask" value="addNestedGroup">
+							<?php
+								$fName = 'idNestedGroupToAdd';
+								$fldParams = array();
+								$fldParams['allowCreate'] = false;
+								$fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdNestedGroup";
+								//$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
+								echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
+							?>
+							<button class="btn">dodaj</button>
+						</form>
+					</li>
+				<?php endif; ?>
+			</ul>
+
+<!--			<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>:
+			</p> -->
+			<blockquote>
+				<h5>Grupy, które udostępniają rekordy</h5>
+				<small>np. grupy podrzędnych pracowników lub dział, podmiot.</small>
+			</blockquote>
+			<ul class="conn_groups-list">
+				<?php if (!empty($group->parentGroups)) : ?>
+					<?php foreach ($group->parentGroups as $vParentGroup) : ?>
+						<li class="conn_groups-list_item">
+							[<?php echo $vParentGroup->zasobID; ?>]
+							<?php // if ('DZIAL' == $vParentGroup->type) : ?>
+								<?php echo $vParentGroup->type; ?>
+							<?php // endif; ?>
+							<?php echo $vParentGroup->zasobDESC; ?>
+							<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>
+							<form action="" method="POST" class="form-inline frm-groups">
+								<input type="hidden" name="_subTask" value="removeParentGroup">
+								<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>
+							</form>
+						</li>
+					<?php endforeach; ?>
+				<?php endif; ?>
+
+				<?php if ($typeSpecialNestedGroups) : ?>
+					<li>
+						<form action="" method="POST" class="form-inline frm-groups">
+							<input type="hidden" name="_subTask" value="addParentGroup">
+							<?php
+								$fName = 'idParentGroupToAdd';
+								$fldParams = array();
+								$fldParams['allowCreate'] = false;
+								$fldParams['ajaxDataUrlBase'] = "index.php?_route=Users&_task=typeSpecialIdNestedGroup";
+								//$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
+								echo $typeSpecialNestedGroups->showFormItem($tblID = -1, $fName, $selValue = '', $fldParams);
+							?>
+							<button class="btn">dodaj</button>
+						</form>
+					</li>
+				<?php endif; ?>
+			</ul>
+
+		</div>
+		<div class="col-md-6 users-with-perms">
+
+			<h5>Użytkownicy:</h5>
+			<?php if (empty($groupUsers)) : ?>
+				<div class="alert">Brak użytkowników przypisanych bezpośrednio do grupy</div>
+			<?php else : ?>
+				<div class="row">
+				<?php foreach ($groupUsers as $usr) : ?>
+					<div class="col-md-6">
+						<address>
+							<strong><?php echo $usr->ADM_NAME; ?></strong>
+							<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>
+
+							<br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
+
+							<?php if (!empty($usr->ADM_PHONE)) : ?>
+								<br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
+							<?php endif; ?>
+
+							<?php if (!empty($usr->EMAIL)) : ?>
+								<br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
+							<?php endif; ?>
+						</address>
+					</div>
+				<?php endforeach; ?>
+				</div>
+			<?php endif; ?>
+
+			<h5>Użytwkonicy z uprawnieniami do rekordów</h5>
+			<?php if (empty($groupNestedUsers)) : ?>
+				<div class="alert">Brak</div>
+			<?php else : ?>
+				<div class="row">
+				<?php foreach ($groupNestedUsers as $usr) : ?>
+					<div class="col-md-6">
+						<address>
+							<strong><?php echo $usr->ADM_NAME; ?></strong>
+							<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>
+
+							<br><em><?php echo $usr->EMPLOYEE_TYPE; ?></em>
+
+							<?php if (!empty($usr->ADM_PHONE)) : ?>
+								<br><abbr title="Telefon">Tel.:</abbr> <?php echo $usr->ADM_PHONE; ?>
+							<?php endif; ?>
+
+							<?php if (!empty($usr->EMAIL)) : ?>
+								<br><a href="mailto:<?php echo $usr->EMAIL; ?>"><?php echo $usr->EMAIL; ?></a>
+							<?php endif; ?>
+						</address>
+					</div>
+				<?php endforeach; ?>
+				</div>
+			<?php endif; ?>
+
+		</div>
+	</div>
+</div>
 <?php
+		{// render table
+			$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;
+				}
+			}
+
+			$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');
+			$tbl->showProcesInit(false);// hide Proces filter field
+			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() {
@@ -104,18 +503,6 @@ class Route_Users extends RouteBase {
 		<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)) : ?>
@@ -259,7 +646,6 @@ class Route_Users extends RouteBase {
 
 	public function typeSpecialIdGroupAction() {
 		header("Content-type: application/json");
-		Lib::loadClass('TypespecialVariable');
 		$typeSpecialUserGroups = TypespecialVariable::getInstance(-1, '__USER_GROUPS');
 
 		$query = V::get('q', '', $_REQUEST);
@@ -281,7 +667,6 @@ class Route_Users extends RouteBase {
 	public function typeSpecialIdTelboxesAction() {
 		header("Content-type: application/json");
 
-		Lib::loadClass('TypespecialVariable');
 		$typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES');
 
 		$query = V::get('q', '', $_REQUEST);

+ 8 - 8
SE/se-lib/SyncUsers.php

@@ -415,12 +415,10 @@ class SyncUsers {
 			if (!empty($groupsTodo)) {
 				foreach ($groupsTodo as $kGroupID => $vBool) {
 					if ($vBool) {
-						$added = $this->_toStorage->addNestedGroup($groupID, $kGroupID);
-						if (!$added) throw new Exception("Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage");
+						$this->_toStorage->addNestedGroup($groupID, $kGroupID);
 					}
 					else {
-						$removed = $this->_toStorage->removeNestedGroup($groupID, $kGroupID);
-						if (!$removed) throw new Exception("Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage");
+						$this->_toStorage->removeNestedGroup($groupID, $kGroupID);
 					}
 				}
 			}
@@ -489,8 +487,9 @@ class SyncUsers {
 				foreach ($groupsTodo as $kGroupID => $vBool) {
 					if ($vBool) {
 						//$syncTodoList[] = "Add parent group '{$kGroupID}' to group '{$groupID}' in toStorage";// == add $groupID to $kGroupID
-						$added = $this->_toStorage->addNestedGroup($kGroupID, $groupID);
-						if (!$added) {
+						$this->_toStorage->addNestedGroup($kGroupID, $groupID);
+						// TODO: add try catch to prevent resend exception
+						if (0) {
 							$this->setError(1, "Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
 						}
 					}
@@ -498,8 +497,9 @@ class SyncUsers {
 						$groupTest = $this->_fromStorage->getGroup($kGroupID);
 						if ($groupTest) {
 							//$syncTodoList[] = "Remove parent group '{$kGroupID}' from group '{$groupID}' in toStorage";// == remove $groupID from $kGroupID
-							$removed = $this->_toStorage->removeNestedGroup($kGroupID, $groupID);
-							if (!$removed) {
+							$this->_toStorage->removeNestedGroup($kGroupID, $groupID);
+							// TODO: add try catch to prevent resend exception
+							if (0) {
 								$this->setError(1, "Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
 							}
 						} else {

+ 58 - 61
SE/se-lib/UserStorageDB.php

@@ -94,9 +94,9 @@ class UserStorageDB extends UserStorageBase {
 	 *   $group->zasobID
 	 *   (optional) $group->zasobDESC
 	 */
-	public function getGroup($groupID) {
+	public function getGroup($idGroup) {
 		if (!$this->_db) return false;
-		if ($groupID <= 0) return false;
+		if ($idGroup <= 0) return false;
 
 		$group = null;
 		$sql = "SELECT z.`ID`
@@ -104,7 +104,7 @@ class UserStorageDB extends UserStorageBase {
 				, z.`TYPE`
 		--		, IF(a.`A_STATUS`='NORMAL', 0, 1) as isDisabled
 			from `CRM_LISTA_ZASOBOW` as z
-			where z.`ID`='{$groupID}'
+			where z.`ID`='{$idGroup}'
 				and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
 		";
 		$res = $this->_db->query($sql);
@@ -114,9 +114,9 @@ class UserStorageDB extends UserStorageBase {
 		return $group;
 	}
 
-	public function getGroupWithoutNested($groupID) {
+	public function getGroupWithoutNested($idGroup) {
 		if (!$this->_db) return false;
-		if ($groupID <= 0) return false;
+		if ($idGroup <= 0) return false;
 
 		$group = null;
 		$sql = "SELECT z.`ID`
@@ -124,7 +124,7 @@ class UserStorageDB extends UserStorageBase {
 				, z.`TYPE`
 		--		, IF(a.`A_STATUS`='NORMAL', 0, 1) as isDisabled
 			from `CRM_LISTA_ZASOBOW` as z
-			where z.`ID`='{$groupID}'
+			where z.`ID`='{$idGroup}'
 				and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
 		";
 		$res = $this->_db->query($sql);
@@ -134,9 +134,9 @@ class UserStorageDB extends UserStorageBase {
 		return $group;
 	}
 
-	public function fetchNestedGroups($groupID) {
+	public function fetchNestedGroups($idGroup) {
 		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
+		if ($idGroup <= 0) return null;
 		$groups = array();
 		$sql = "SELECT l.`TABLE_2_ID` as groupID
 				, z2.`ID`
@@ -145,7 +145,7 @@ class UserStorageDB extends UserStorageBase {
 			from `ITEM_LINKS` as l
 				join `CRM_LISTA_ZASOBOW` as z1 on(z1.`ID`=l.`TABLE_1_ID`)
 				join `CRM_LISTA_ZASOBOW` as z2 on(z2.`ID`=l.`TABLE_2_ID`)
-			where l.`TABLE_1_ID`='{$groupID}'
+			where l.`TABLE_1_ID`='{$idGroup}'
 				and l.`TABLE_2_ID`>0
 				and l.`LINKS_TYPE_ID`=5
 				and l.`TABLE_1_NAME`='CRM_LISTA_ZASOBOW'
@@ -166,9 +166,9 @@ class UserStorageDB extends UserStorageBase {
 		return $this->fetchParentGroups($group->primaryKey);
 	}
 
-	public function fetchParentGroups($groupID) {
+	public function fetchParentGroups($idGroup) {
 		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
+		if ($idGroup <= 0) return null;
 		$groups = array();
 		$sql = "SELECT l.`TABLE_1_ID` as groupID
 				, z1.`ID`
@@ -178,7 +178,7 @@ class UserStorageDB extends UserStorageBase {
 				join `CRM_LISTA_ZASOBOW` as z1 on(z1.`ID`=l.`TABLE_1_ID`)
 				join `CRM_LISTA_ZASOBOW` as z2 on(z2.`ID`=l.`TABLE_2_ID`)
 			where l.`TABLE_1_ID`>0
-				and l.`TABLE_2_ID`='{$groupID}'
+				and l.`TABLE_2_ID`='{$idGroup}'
 				and l.`LINKS_TYPE_ID`=5
 				and l.`TABLE_1_NAME`='CRM_LISTA_ZASOBOW'
 				and l.`A_STATUS` in('NORMAL')
@@ -194,16 +194,16 @@ class UserStorageDB extends UserStorageBase {
 		return $groups;
 	}
 
-	private function _getGroupConnection($parentGroupID, $groupID) {
+	private function _getGroupConnection($idParentGroup, $idGroup) {
 		if (!$this->_db) return null;
-		if ($parentGroupID <= 0) return null;
-		if ($groupID <= 0) return null;
+		if ($idParentGroup <= 0) return null;
+		if ($idGroup <= 0) return null;
 		$sql = "SELECT l.*
 			from `ITEM_LINKS` as l
 				join `CRM_LISTA_ZASOBOW` as z1 on(z1.`ID`=l.`TABLE_1_ID`)
 				join `CRM_LISTA_ZASOBOW` as z2 on(z2.`ID`=l.`TABLE_2_ID`)
-			where l.`TABLE_1_ID`='{$parentGroupID}'
-				and l.`TABLE_2_ID`='{$groupID}'
+			where l.`TABLE_1_ID`='{$idParentGroup}'
+				and l.`TABLE_2_ID`='{$idGroup}'
 				and l.`LINKS_TYPE_ID`=5
 				and l.`TABLE_1_NAME`='CRM_LISTA_ZASOBOW'
 				and l.`TABLE_2_NAME`='CRM_LISTA_ZASOBOW'
@@ -217,27 +217,27 @@ class UserStorageDB extends UserStorageBase {
 		return null;
 	}
 
-	private function _setGroupConnection($parentGroupID, $groupID) {
-		if (!$this->_db) return null;
-		if ($groupID <= 0 || $parentGroupID <= 0) return null;
+	private function _setGroupConnection($idParentGroup, $idGroup, $errorMsg = null) {
+		if (!$this->_db) throw new Exception("Error: no DB!");
+		if ($idGroup <= 0) throw new Exception("Wrong param id group!");
+		if ($idParentGroup <= 0) throw new Exception("Wrong param id parent group!");
+		if (!$errorMsg) $errorMsg = "Nie udało się utworzyć połączenia grup [{$idGroup}] i [{$idParentGroup}]";
 
 		$tblName = 'CRM_LISTA_ZASOBOW';
 		Lib::loadClass('ProcesHelper');
 		$tblZasobyID = ProcesHelper::getZasobTableID($tblName);
-		if (!$tblZasobyID) return false;
+		if (!$tblZasobyID) throw new Exception("Cannot find zasob id for table Zasoby!");
 
-		$connObj = $this->_getGroupConnection($parentGroupID, $groupID);
+		$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
 		if ($connObj) {
 			$connObj->A_STATUS = 'NORMAL';
 			$affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
-			if ($affected > 0) {
-				return true;
-			}
+			if ($affected <= 0) throw new Exception($errorMsg);
 		}
 		else {
 			$sqlObj = new stdClass();
-			$sqlObj->TABLE_1_ID = $parentGroupID;
-			$sqlObj->TABLE_2_ID = $groupID;
+			$sqlObj->TABLE_1_ID = $idParentGroup;
+			$sqlObj->TABLE_2_ID = $idGroup;
 			$sqlObj->TABLE_1_NAME = $tblName;
 			$sqlObj->TABLE_2_NAME = $tblName;
 			$sqlObj->TABLE_1_ZASOB_ID = $tblZasobyID;
@@ -245,58 +245,55 @@ class UserStorageDB extends UserStorageBase {
 			$sqlObj->LINKS_TYPE_ID = 5;// NestedGroups
 			$sqlObj->A_STATUS = 'NORMAL';
 
-			$rowID = $this->_db->ADD_NEW_OBJ('ITEM_LINKS', $sqlObj);
-			if ($rowID > 0) {
-				return true;
-			}
+			$idCreatedRow = $this->_db->ADD_NEW_OBJ('ITEM_LINKS', $sqlObj);
+			if ($idCreatedRow <= 0) throw new Exception($errorMsg);
 		}
-		return false;
 	}
 
-	public function addNestedGroup($groupID, $nestedGroupID) {
-		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
-		if ($nestedGroupID <= 0) return null;
-		return $this->_setGroupConnection($groupID, $nestedGroupID);
+	public function addNestedGroup($idGroup, $idNestedGroup) {
+		if (!$this->_db) throw new Exception("Error: no DB!");
+		if ($idGroup <= 0) throw new Exception("Wrong param id group!");
+		if ($idNestedGroup <= 0) throw new Exception("Wrong param id nested group!");
+		$errorMsg = "Nie udało się dodać grupy zagnieżdżonej [{$idNestedGroup}] do grupy [{$idGroup}]";
+		return $this->_setGroupConnection($idGroup, $idNestedGroup, $errorMsg);
 	}
 
-	public function addParentGroup($groupID, $parentGroupID) {
-		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
-		if ($parentGroupID <= 0) return null;
-		return $this->_setGroupConnection($parentGroupID, $groupID);
+	public function addParentGroup($idGroup, $idParentGroup) {
+		if (!$this->_db) throw new Exception("Error: no DB!");
+		if ($idGroup <= 0) throw new Exception("Wrong param id group!");
+		if ($idParentGroup <= 0) throw new Exception("Wrong param id parent group!");
+		$errorMsg = "Nie udało się dodać grupy nadrzędnej [{$idParentGroup}] do grupy [{$idGroup}]";
+		return $this->_setGroupConnection($idParentGroup, $idGroup, $errorMsg);
 	}
 
-	public function removeNestedGroup($groupID, $nestedGroupID) {
-		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
-		if ($nestedGroupID <= 0) return null;
+	public function removeNestedGroup($idGroup, $idNestedGroup) {
+		if (!$this->_db) throw new Exception("Error: no DB!");
+		if ($idGroup <= 0) throw new Exception("Wrong param id group!");
+		if ($idNestedGroup <= 0) throw new Exception("Wrong param id nested group!");
 
-		$connObj = $this->_getGroupConnection($groupID, $nestedGroupID);
+		$connObj = $this->_getGroupConnection($idGroup, $idNestedGroup);
 		if ($connObj) {
 			$connObj->A_STATUS = 'DELETED';
 			$affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
-			if ($affected > 0) {
-				return true;
+			if ($affected <= 0) {
+				throw new Exception("Nie udało się usunąć grupy zagnieżdżonej '{$kGroupID}' do grupy '{$groupID}' w bazie danych");
 			}
 		}
-		return false;
 	}
 
-	public function removeParentGroup($groupID, $parentGroupID) {
-		if (!$this->_db) return null;
-		if ($groupID <= 0) return null;
-		if ($parentGroupID <= 0) return null;
+	public function removeParentGroup($idGroup, $idParentGroup) {
+		if (!$this->_db) throw new Exception("Error: no DB!");
+		if ($idGroup <= 0) throw new Exception("Wrong param id group!");
+		if ($idParentGroup <= 0) throw new Exception("Wrong param id parent group!");
 
-		$connObj = $this->_getGroupConnection($parentGroupID, $groupID);
+		$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
 		if ($connObj) {
 			$connObj->A_STATUS = 'DELETED';
 			$affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
-			if ($affected > 0) {
-				return true;
+			if ($affected <= 0) {
+				throw new Exception("Nie udało się usunąć grupy nadrzędnej [{$idParentGroupToRemove}] do grupy [{$idGroup}]");
 			}
 		}
-		return false;
 	}
 
 	/**
@@ -630,10 +627,10 @@ class UserStorageDB extends UserStorageBase {
 		$res = $this->_db->query($sql);
 	}
 
-	public function setSyncGroupDate($groupID) {
+	public function setSyncGroupDate($idGroup) {
 		if (!$this->_db) return false;
-		if ($groupID <= 0) return false;
-		$sql = "update `CRM_LISTA_ZASOBOW` set `A_SYNC_LDAP_DATE`=NOW() where `ID`='{$groupID}' ";
+		if ($idGroup <= 0) return false;
+		$sql = "update `CRM_LISTA_ZASOBOW` set `A_SYNC_LDAP_DATE`=NOW() where `ID`='{$idGroup}' ";
 		$res = $this->_db->query($sql);
 	}