فهرست منبع

Sync Parent Groups; Refactor: Sync Users and Groups

Piotr Labudda 11 سال پیش
والد
کامیت
6a35bacbd6

+ 1 - 1
SE/VERSION

@@ -1 +1 @@
-3.9.7.12
+3.9.7.13

+ 3 - 3
SE/index.php

@@ -11,9 +11,9 @@ session_start();
 
 date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
 
-error_reporting(1);
-ini_set('error_reporting', 1);
-ini_set('display_startup_errors','1'); 
+error_reporting(E_ERROR | E_RECOVERABLE_ERROR);
+ini_set('error_reporting', E_ERROR | E_RECOVERABLE_ERROR);
+ini_set('display_startup_errors','1');
 //display_startup_errors(0);
 
 #TEST $_SESSION['DEBUG'] = 3;// TODO: TEST

+ 36 - 0
SE/se-lib/ObjectGroup.php

@@ -0,0 +1,36 @@
+<?php
+
+/**
+ *   $group->primaryKey
+ *   $group->realName		realName eg. "[123] Grupa 123"
+ *   $group->nestedGroups
+ *   $group->type			'STANOWISKO','PODMIOT','DZIAL','local','network'
+ *   (optional) $group->zasobID
+ *   (optional) $group->zasobDESC
+ */
+class ObjectGroup {
+
+	public $primaryKey;
+	public $realName;
+	public $type;// 'STANOWISKO','PODMIOT','DZIAL','local','network'
+	//     'local' - access groups like com.apple.access_mail
+	//     'network' - network group: workgroup
+	public $nestedGroups;
+	public $parentGroups = null;
+	public $zasobID;// (optional)
+	public $zasobDESC;// (optional)
+
+	protected $_storage;
+
+	public function __construct($storage) {
+		$this->_storage = $storage;
+	}
+
+	public function getParentGroups() {
+		if (null === $this->parentGroups) {
+			$this->parentGroups = $this->_storage->getParentGroups($this);
+		}
+		return $this->parentGroups;
+	}
+
+}

+ 15 - 0
SE/se-lib/ObjectGroupDB.php

@@ -0,0 +1,15 @@
+<?php
+
+Lib::loadClass('ObjectGroup');
+
+/**
+ *   $group->primaryKey
+ *   $group->realName		realName eg. "[123] Grupa 123"
+ *   $group->nestedGroups
+ *   $group->type			'STANOWISKO','PODMIOT','DZIAL','local','network'
+ *   (optional) $group->zasobID
+ *   (optional) $group->zasobDESC
+ */
+class ObjectGroupDB extends ObjectGroup {
+
+}

+ 25 - 0
SE/se-lib/ObjectGroupLdap.php

@@ -0,0 +1,25 @@
+<?php
+
+Lib::loadClass('ObjectGroup');
+
+/**
+ *   $group->primaryKey
+ *   $group->realName		realName eg. "[123] Grupa 123"
+ *   $group->nestedGroups
+ *   $group->type			'STANOWISKO','PODMIOT','DZIAL','local','network'
+ *   (optional) $group->zasobID
+ *   (optional) $group->zasobDESC
+ */
+class ObjectGroupLdap extends ObjectGroup {
+
+	private $_ldapUID;
+
+	public function setLdapUID($ldapUID) {
+		$this->_ldapUID = $ldapUID;
+	}
+
+	public function getLdapUID() {
+		return $this->_ldapUID;
+	}
+
+}

+ 22 - 0
SE/se-lib/ObjectUser.php

@@ -0,0 +1,22 @@
+<?php
+
+class ObjectUser {
+
+	public $primaryKey;
+	public $login;
+	public $password;// optional (required in createUser)
+	public $name;
+	public $email;
+	public $phone;
+	public $homeEmail;
+	public $homePhone;
+	public $employeeType;// 'Pracownik','Kandydat','Partner','Anonymous'
+	public $isDisabled;// 1, 0 or null if not set
+
+	protected $_storage;
+
+	public function __construct($storage) {
+		$this->_storage = $storage;
+	}
+
+}

+ 7 - 0
SE/se-lib/ObjectUserDB.php

@@ -0,0 +1,7 @@
+<?php
+
+Lib::loadClass('ObjectUser');
+
+class ObjectUserDB extends ObjectUser {
+
+}

+ 7 - 0
SE/se-lib/ObjectUserLdap.php

@@ -0,0 +1,7 @@
+<?php
+
+Lib::loadClass('ObjectUser');
+
+class ObjectUserLdap extends ObjectUser {
+
+}

+ 166 - 22
SE/se-lib/SyncUsers.php

@@ -14,7 +14,7 @@ class SyncUsers {
 	/**
 	 * Sync user.
 	 * 
-	 * @returns bool or -int if error @see getSyncUserErrorMsg($errCode);
+	 * @return bool or -int if error @see getSyncUserErrorMsg($errCode);
 	 */
 	public function syncUser($usrLogin, $syncGroups = false, $syncDisabled = false) {
 		$usrFrom = $this->_fromStorage->getUser($usrLogin);
@@ -261,6 +261,7 @@ class SyncUsers {
 		}
 		else if (!$groupTo) {
 			$syncTodoList[] = "Create group {$groupID} in toStorage";
+			return $syncTodoList;
 		}
 		else {
 			$updateData = array();
@@ -273,7 +274,7 @@ class SyncUsers {
 		}
 
 		if ($syncNestedGroups) {
-			if (!empty($groupTo->nestedGroups) && !empty($groupFrom->nestedGroups)) {
+			if (!empty($groupTo->nestedGroups) || !empty($groupFrom->nestedGroups)) {
 				$groupsTodo = array();
 				if (!empty($groupTo->nestedGroups)) {
 					foreach ($groupTo->nestedGroups as $kUid => $vGroup) {
@@ -301,6 +302,44 @@ class SyncUsers {
 					}
 				}
 			}
+
+			$fromParentGroups = $groupFrom->getParentGroups();
+			$toParentGroups = $groupTo->getParentGroups();
+
+			{
+				$groupsTodo = array();
+				if (!empty($toParentGroups)) {
+					foreach ($toParentGroups as $kUid => $vGroup) {
+						$groupsTodo[$kUid] = false;
+					}
+				}
+				if (!empty($fromParentGroups)) {
+					foreach ($fromParentGroups as $kUid => $vGroup) {
+						if (isset($groupsTodo[$kUid])) {
+							unset($groupsTodo[$kUid]);
+						} else {
+							$groupsTodo[$kUid] = true;
+						}
+					}
+				}
+
+				if (!empty($groupsTodo)) {
+					foreach ($groupsTodo as $kGroupID => $vBool) {
+						if ($vBool) {
+							$syncTodoList[] = "Add parent group '{$kGroupID}' to group '{$groupID}' in toStorage";// == add $groupID to $kGroupID
+						}
+						else {
+							$groupTest = $this->_fromStorage->getGroup($kGroupID);
+							if ($groupTest) {
+								$syncTodoList[] = "Remove parent group '{$kGroupID}' from group '{$groupID}' in toStorage";// == remove $groupID from $kGroupID
+							} else {
+								//$syncTodoList[] = "Keep parent group '{$kGroupID}' in group '{$groupID}' in toStorage, because that group dont exists in fromStorage";
+							}
+						}
+					}
+				}
+			}
+
 		}
 
 		return $syncTodoList;
@@ -309,7 +348,7 @@ class SyncUsers {
 	/**
 	 * Sync user.
 	 * 
-	 * @returns bool or -int if error @see getSyncUserErrorMsg($errCode);
+	 * @return bool or -int if error @see getSyncUserErrorMsg($errCode);
 	 */
 	public function syncGroup($groupID, $syncNestedGroups = false) {
 		$groupFrom = $this->_fromStorage->getGroup($groupID);
@@ -337,25 +376,45 @@ class SyncUsers {
 				return false;
 			}
 
+			$groupTo = $this->_toStorage->getGroup($groupID);
+			$synced = $this->syncExistingGroup($groupFrom, $groupTo, $syncNestedGroups);
+			if (!$synced) {
+				return false;
+			}
+
 		}
 		else {// $groupFrom && $groupTo
-
-			$updateData = array();
-			if (empty($groupTo->realName) && $groupFrom->realName != $groupTo->realName) {
-				$updateData['realName'] = $groupFrom->realName;
+			$synced = $this->syncExistingGroup($groupFrom, $groupTo, $syncNestedGroups);
+			if (!$synced) {
+				return false;
 			}
+		}
 
-			//if ($groupFrom->employeeType != $groupTo->employeeType) $updateData['employeeType'] = $groupFrom->employeeType;
-			$updated = $this->_toStorage->updateGroup($groupTo, $updateData);
+		$this->_fromStorage->setSyncGroupDate($groupID);
+		$this->_toStorage->setSyncGroupDate($groupID);
 
-			if (!$updated) {
-				$errors = $this->_toStorage->getRawErrorsList();
-				foreach ($errors as $vErr) {
-					$this->setError($vErr->code, $vErr->msg, $vErr->dbgMsg);
-				}
-				$this->setError(1, "TODO: update group {$groupID} from fromStorage to toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
-				return false;
+		return true;
+	}
+
+	public function syncExistingGroup(ObjectGroup $groupFrom, ObjectGroup $groupTo, $syncNestedGroups = false) {
+		if (!$groupFrom) return false;
+		if (!$groupTo) return false;
+
+		$updateData = array();
+		if (empty($groupTo->realName) && $groupFrom->realName != $groupTo->realName) {
+			$updateData['realName'] = $groupFrom->realName;
+		}
+
+		//if ($groupFrom->employeeType != $groupTo->employeeType) $updateData['employeeType'] = $groupFrom->employeeType;
+		$updated = $this->_toStorage->updateGroup($groupTo, $updateData);
+
+		if (!$updated) {
+			$errors = $this->_toStorage->getRawErrorsList();
+			foreach ($errors as $vErr) {
+				$this->setError($vErr->code, $vErr->msg, $vErr->dbgMsg);
 			}
+			$this->setError(1, "TODO: update group {$groupID} from fromStorage to toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
+			return false;
 		}
 
 		if ($syncNestedGroups) {
@@ -364,11 +423,12 @@ class SyncUsers {
 				$this->setError(1, "Error: sync nested groups for group '{$groupID}' from fromStorage to toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
 				return false;
 			}
+			$synced = $this->syncParentGroups($groupID, $groupFrom, $groupTo);
+			if (!$synced) {
+				$this->setError(1, "Error: sync parent groups for group '{$groupID}' from fromStorage to toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
+				return false;
+			}
 		}
-
-		$this->_fromStorage->setSyncGroupDate($groupID);
-		$this->_toStorage->setSyncGroupDate($groupID);
-
 		return true;
 	}
 
@@ -425,13 +485,13 @@ class SyncUsers {
 			if (!empty($groupsTodo)) {
 				foreach ($groupsTodo as $kGroupID => $vBool) {
 					if ($vBool) {
-						$added = $this->_toStorage->addNestedGroup($groupID, $groupFrom->nestedGroups[$kGroupID]);
+						$added = $this->_toStorage->addNestedGroup($groupID, $kGroupID);
 						if (!$added) {
 							$this->setError(1, "Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
 						}
 					}
 					else {
-						$removed = $this->_toStorage->removeNestedGroup($groupID, $groupTo->nestedGroups[$kGroupID]);
+						$removed = $this->_toStorage->removeNestedGroup($groupID, $kGroupID);
 						if (!$removed) {
 							$this->setError(1, "Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
 						}
@@ -446,6 +506,90 @@ class SyncUsers {
 		return true;
 	}
 
+	public function syncParentGroups($groupID, $groupFrom = null, $groupTo = null) {
+		if (!$groupFrom) $groupFrom = $this->_fromStorage->getGroup($groupID);
+		if (!$groupTo) $groupTo = $this->_toStorage->getGroup($groupID);
+
+		if (V::get('DBG_SU', 0, $_GET, 'int') > 0) {
+			echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupFrom (hasNestedGroups:'.(!empty($groupFrom->nestedGroups)).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupFrom);echo'</pre>';
+			echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupTo (hasNestedGroups:'.(!empty($groupTo->nestedGroups)).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupTo);echo'</pre>';
+		}
+
+		$fromParentGroups = $groupFrom->getParentGroups();
+		$toParentGroups = $groupTo->getParentGroups();
+
+		if (empty($fromParentGroups) && empty($toParentGroups)) {
+			return true;
+		}
+		else {
+
+			/*
+					[nestedGroups] => Array(
+							[2981] => stdClass Object(
+									[primaryKey] => 2981
+									[type] => STANOWISKO
+									[realName] => [2981] Kierownik ds. Rozwoju Biznesu
+									[zasobID] => 2981
+									[zasobDESC] => Kierownik ds. Rozwoju Biznesu
+			*/
+
+			/**
+			 * $groupsTodo - groups todo list:
+			 *   'com.apple.access_mail' => true - add to this group
+			 *   'com.apple.access_mail' => false - remove from this group
+			 */
+
+			$groupsTodo = array();
+			if (!empty($toParentGroups)) {
+				foreach ($toParentGroups as $kUid => $vGroup) {
+					$groupsTodo[$kUid] = false;
+				}
+			}
+			if (!empty($fromParentGroups)) {
+				foreach ($fromParentGroups as $kUid => $vGroup) {
+					if (isset($groupsTodo[$kUid])) {
+						unset($groupsTodo[$kUid]);
+					} else {
+						$groupsTodo[$kUid] = true;
+					}
+				}
+			}
+
+			if (V::get('DBG_SU', 0, $_GET, 'int') > 0) {
+				echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">groupsTodo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($groupsTodo);echo'</pre>';
+			}
+
+			if (!empty($groupsTodo)) {
+				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->setError(1, "Error: group '{$kGroupID}' add to group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
+						}
+					}
+					else {
+						$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->setError(1, "Error: group '{$kGroupID}' remove from group '{$groupID}' in toStorage", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
+							}
+						} else {
+							//$syncTodoList[] = "Keep parent group '{$kGroupID}' in group '{$groupID}' in toStorage, because that group dont exists in fromStorage";
+						}
+					}
+				}
+			}
+		}
+
+		if ($this->hasErrors()) {
+			return false;
+		}
+		return true;
+	}
+
 
 	private function setError($code, $msg, $dbgMsg) {
 		$this->_errors[] = (object)array('code'=>$code, 'msg'=>$msg, 'dbgMsg'=>$dbgMsg);

+ 5 - 4
SE/se-lib/UserStorageBase.php

@@ -67,11 +67,11 @@ class UserStorageBase {
 	public function addUserGroup($usrLogin, $group) {}
 	public function removeUserGroup($usrLogin, $group) {}
 	public function updateGroup($group, $updateData) {}
-	public function addNestedGroup($groupID, $nestedGroup) {}
-	public function removeNestedGroup($groupID, $nestedGroup) {}
+	public function addNestedGroup($groupID, $nestedGroupID) {}
+	public function removeNestedGroup($groupID, $nestedGroupID) {}
 
-	public function addParentGroup($groupID, $parentGroup) {}
-	public function removeParentGroup($groupID, $parentGroup) {}
+	public function addParentGroup($groupID, $parentGroupID) {}
+	public function removeParentGroup($groupID, $parentGroupID) {}
 
 	/**
 	 * Group.
@@ -87,6 +87,7 @@ class UserStorageBase {
 	 *   (optional) $group->zasobDESC
 	 */
 	public function getGroup($groupID) {}
+	public function getParentGroups(ObjectGroup $group) {}
 
 	/**
 	 * Build local group object.

+ 45 - 25
SE/se-lib/UserStorageDB.php

@@ -1,6 +1,8 @@
 <?php
 
 Lib::loadClass('UserStorageBase');
+Lib::loadClass('ObjectUserDB');
+Lib::loadClass('ObjectGroupDB');
 
 class UserStorageDB extends UserStorageBase {
 
@@ -11,7 +13,7 @@ class UserStorageDB extends UserStorageBase {
 	}
 
 	/**
-	 * @returns object $usr
+	 * @return object $usr
 	 *   $usr->primaryKey
 	 *   $usr->login
 	 *   $usr->password					optional (required in createUser)
@@ -48,17 +50,31 @@ class UserStorageDB extends UserStorageBase {
 		";
 		$res = $this->_db->query($sql);
 		if ($r = $this->_db->fetch($res)) {
-			$r->isDisabled = (int)$r->isDisabled;
-			$user = $r;
+			$user = $this->_buildUserFromRow($r);
 		}
 		return $user;
 	}
 
+	private function _buildUserFromRow($r) {
+		$user = new ObjectUserDB($this);
+		$user->primaryKey = $r->primaryKey;
+		$user->login = $r->login;
+		$user->password = $r->password;
+		$user->name = $r->name;
+		$user->email = $r->email;
+		$user->phone = $r->phone;
+		$user->homeEmail = $r->homeEmail;
+		$user->homePhone = $r->homePhone;
+		$user->employeeType = $r->employeeType;
+		$user->isDisabled = (int)$r->isDisabled;
+		return $user;
+	}
+
 	/**
 	 * Build group realName from zasob.
 	 * 
 	 * @param object $zasob {ID, DESC, TYPE}
-	 * @returns string realName
+	 * @return string realName
 	 */
 	protected function _buildRealNameFromZasob($zasob) {
 		$realName = "{$zasob->DESC}";
@@ -70,7 +86,7 @@ class UserStorageDB extends UserStorageBase {
 	/**
 	 * Group.
 	 * 
-	 * @returns object $group
+	 * @return object $group
 	 *   $group->primaryKey
 	 *   $group->realName
 	 *   $group->nestedGroups
@@ -146,6 +162,10 @@ class UserStorageDB extends UserStorageBase {
 		return $groups;
 	}
 
+	public function getParentGroups(ObjectGroupDB $group) {
+		return $this->fetchParentGroups($group->primaryKey);
+	}
+
 	public function fetchParentGroups($groupID) {
 		if (!$this->_db) return null;
 		if ($groupID <= 0) return null;
@@ -233,26 +253,26 @@ class UserStorageDB extends UserStorageBase {
 		return false;
 	}
 
-	public function addNestedGroup($groupID, $nestedGroup) {
+	public function addNestedGroup($groupID, $nestedGroupID) {
 		if (!$this->_db) return null;
 		if ($groupID <= 0) return null;
-		if (empty($nestedGroup->zasobID)) return null;
-		return $this->_setGroupConnection($groupID, $nestedGroup->zasobID);
+		if ($nestedGroupID) return null;
+		return $this->_setGroupConnection($groupID, $nestedGroupID);
 	}
 
-	public function addParentGroup($groupID, $parentGroup) {
+	public function addParentGroup($groupID, $parentGroupID) {
 		if (!$this->_db) return null;
 		if ($groupID <= 0) return null;
-		if (empty($parentGroup->zasobID)) return null;
-		return $this->_setGroupConnection($parentGroup->zasobID, $groupID);
+		if ($parentGroupID <= 0) return null;
+		return $this->_setGroupConnection($parentGroupID, $groupID);
 	}
 
-	public function removeNestedGroup($groupID, $nestedGroup) {
+	public function removeNestedGroup($groupID, $nestedGroupID) {
 		if (!$this->_db) return null;
 		if ($groupID <= 0) return null;
-		if (empty($nestedGroup->zasobID)) return null;
+		if ($nestedGroupID <= 0) return null;
 
-		$connObj = $this->_getGroupConnection($groupID, $nestedGroup->zasobID);
+		$connObj = $this->_getGroupConnection($groupID, $nestedGroupID);
 		if ($connObj) {
 			$connObj->A_STATUS = 'DELETED';
 			$affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
@@ -263,12 +283,12 @@ class UserStorageDB extends UserStorageBase {
 		return false;
 	}
 
-	public function removeParentGroup($groupID, $parentGroup) {
+	public function removeParentGroup($groupID, $parentGroupID) {
 		if (!$this->_db) return null;
 		if ($groupID <= 0) return null;
-		if (empty($parentGroup->zasobID)) return null;
+		if ($parentGroupID <= 0) return null;
 
-		$connObj = $this->_getGroupConnection($parentGroup->zasobID, $groupID);
+		$connObj = $this->_getGroupConnection($parentGroupID, $groupID);
 		if ($connObj) {
 			$connObj->A_STATUS = 'DELETED';
 			$affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
@@ -280,7 +300,7 @@ class UserStorageDB extends UserStorageBase {
 	}
 
 	/**
-	 * @returns bool
+	 * @return bool
 	 */
 	public function isDisabled($usr) {
 		if (null == $usr->isDisabled) {
@@ -290,7 +310,7 @@ class UserStorageDB extends UserStorageBase {
 	}
 
 	/**
-	 * @returns bool
+	 * @return bool
 	 */
 	public function setDisabled($usrLogin, $isDisabled) {
 		if (empty($usrLogin) || null == $isDisabled) {
@@ -375,12 +395,12 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 	 * Build network group object.
 	 * 
 	 * @param object $groupDB {ID, DESC, TYPE} @see _getUserGroupsAll
-	 * @returns object $group @see getGroup
+	 * @return object $group @see getGroup
 	 * 
 	 * Example: _buildGroupFromRow($r) => {@see group}
 	 */
 	private function _buildGroupFromRow($groupDB, $fetchNested = false) {
-		$group = new stdClass();
+		$group = new ObjectGroupDB($this);
 		$group->primaryKey = $groupDB->ID;
 		$group->type = $groupDB->TYPE;
 		$group->realName = $this->_buildRealNameFromZasob($groupDB);
@@ -395,7 +415,7 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 	 * 
 	 * @param bool $fetchNested - contain all groups below connected groups and group PODMIOT from above.
 	 * 
-	 * @returns array with group objects @see getGroup
+	 * @return array with group objects @see getGroup
 	 */
 	public function getUserGroups($usrLogin, $fetchNested = false) {
 		$usrDB = $this->getUser($usrLogin);
@@ -449,7 +469,7 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
 	 * @param optional int $telboxID
-	 * @returns bool
+	 * @return bool
 	 */
 	public function addUserGroup($usrLogin, $group, $telboxID = 0) {
 		if (!$group->zasobID) return false;
@@ -472,7 +492,7 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 	 * Get user and group info by profile ID (CRM_AUTH_PROFILE.ID)
 	 * Only in UserStorageDB
 	 * 
-	 * @returns profile {}
+	 * @return profile {}
 	 *   ID
 	 *   usrId
 	 *   usrLogin
@@ -520,7 +540,7 @@ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:
 	 * Get user and group info by profile ID (CRM_AUTH_PROFILE.ID)
 	 * Only in UserStorageDB
 	 * 
-	 * @returns array of profile {}
+	 * @return array of profile {}
 	 *   ID
 	 *   usrId
 	 *   usrLogin

+ 1 - 1
SE/se-lib/UserStorage.php → SE/se-lib/UserStorageFactory.php

@@ -3,7 +3,7 @@
 Lib::loadClass('UserStorageDB');
 Lib::loadClass('UserStorageMacOSX');
 
-class UserStorage {
+class UserStorageFactory {
 
 	public static function getStorage($clientType) {
 		$usrStorage = null;

+ 54 - 51
SE/se-lib/UserStorageMacOSX.php

@@ -1,6 +1,8 @@
 <?php
 
 Lib::loadClass('UserStorageBase');
+Lib::loadClass('ObjectUserLdap');
+Lib::loadClass('ObjectGroupLdap');
 
 /**
  * Test remove user:
@@ -26,48 +28,35 @@ class UserStorageMacOSX extends UserStorageBase {
 	}
 
 	/**
-	 * @returns object $usr
-	 *   $usr->primaryKey
-	 *   $usr->login
-	 *   $usr->password					optional (required in createUser)
-	 *   $usr->name
-	 *   $usr->email
-	 *   $usr->phone
-	 *   $usr->homeEmail
-	 *   $usr->homePhone
-	 *   $usr->employeeType			'Pracownik','Kandydat','Partner','Anonymous'
-	 *   $usr->isDisabled				1, 0 or null if not set
+	 * @return ObjectUserLdap
 	 */
 	public function getUser($userName) {
 		Lib::loadClass('UsersLdapHelper');
 		$usrLdap = UsersLdapHelper::getUser($userName, true);
 		if (empty($usrLdap[0])) return null;
 
-		$user = new stdClass();
-		$user->primaryKey = V::get('uidNumber', '', $usrLdap[0]);
-		$user->login = V::get('uid', '', $usrLdap[0]);
+		$user = $this->_buildUserFromLdap($usrLdap[0]);
+
+
+		return $user;
+	}
+
+	private function _buildUserFromLdap($usrLdap) {
+		$user = new ObjectUserLdap($this);
+		$user->primaryKey = V::get('uidNumber', '', $usrLdap);
+		$user->login = V::get('uid', '', $usrLdap);
 		$user->password = '';
-		$user->name = V::get('cn', '', $usrLdap[0]);
-		$user->email = V::get('mail', '', $usrLdap[0]);
-		$user->phone = V::get('telephoneNumber', '', $usrLdap[0]);
+		$user->name = V::get('cn', '', $usrLdap);
+		$user->email = V::get('mail', '', $usrLdap);
+		$user->phone = V::get('telephoneNumber', '', $usrLdap);
 		$user->homeEmail = '';
-		$user->homePhone = V::get('homePhone', '', $usrLdap[0]);
-		$user->employeeType = V::get('employeeType', '', $usrLdap[0]);
+		$user->homePhone = V::get('homePhone', '', $usrLdap);
+		$user->employeeType = V::get('employeeType', '', $usrLdap);
 		return $user;
 	}
 
 	/**
-	 * Group.
-	 * 
-	 * @returns object $group
-	 *   $group->primaryKey
-	 *   $group->realName		realName eg. "[123] Grupa 123"
-	 *   $group->nestedGroups
-	 *   $group->type			'STANOWISKO','PODMIOT','DZIAL','local','network'
-	 *     'local' - access groups like com.apple.access_mail
-	 *     'network' - network group: workgroup
-	 *   (optional) $group->zasobID
-	 *   (optional) $group->zasobDESC
+	 * @return ObjectGroupLdap $group
 	 */
 	public function getGroup($groupID) {
 		return $this->_getGroup($groupID, $fetchNested = true);
@@ -91,8 +80,21 @@ class UserStorageMacOSX extends UserStorageBase {
 		return $group;
 	}
 
+	public function getParentGroups(ObjectGroupLdap $group) {
+		Lib::loadClass('UsersLdapHelper');
+		$parentGroups = array();
+		$parentGroupsLdap = UsersLdapHelper::getParentGroupsByAppleUID($group->getLdapUID());
+		foreach ($parentGroupsLdap as $groupLdap) {
+			$group = $this->_buildGroupFromLdap($groupLdap);
+			if ($group->zasobID > 0) {
+				$parentGroups[$group->zasobID] = $group;
+			}
+		}
+		return $parentGroups;
+	}
+
 	/**
-	 * @returns bool
+	 * @return bool
 	 */
 	public function isDisabled($usr) {
 		if (null == $usr->isDisabled) {
@@ -117,7 +119,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	}
 
 	/**
-	 * @returns bool
+	 * @return bool
 	 */
 	public function setDisabled($usrLogin, $isDisabled) {
 		if (empty($usrLogin) || null === $isDisabled) {
@@ -312,7 +314,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param bool $fetchNested - contain all groups below connected groups and group PODMIOT from above.
 	 * 
-	 * @returns array with group objects @see getGroup
+	 * @return array with group objects @see getGroup
 	 */
 	public function getUserGroups($usrLogin, $fetchNested = false) {
 		$groups = array();
@@ -344,12 +346,12 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * Build network group object.
 	 * 
 	 * @param object $groupDB {ID, DESC} @see _getUserGroupsAll
-	 * @returns object $group @see getGroup
+	 * @return object $group @see getGroup
 	 * 
 	 * Example: _buildGroupFromLdap($groupLdap) => {@see getGroup}
 	 */
 	private function _buildGroupFromLdap($groupLdap, $fetchNested = false) {
-		$group = new stdClass();
+		$group = new ObjectGroupLdap($this);
 		$group->primaryKey = $groupLdap->cn;
 		$group->realName = V::get('realName', '', $groupLdap);
 		$group->zasobID = $this->_getGroupIdFromUid($groupLdap->cn);
@@ -358,6 +360,7 @@ class UserStorageMacOSX extends UserStorageBase {
 		if ($fetchNested && !empty($groupLdap->nestedGroups)) {
 			$group->nestedGroups = $this->_fetchNestedGroupsByAppleUids($groupLdap->nestedGroups);
 		}
+		$group->setLdapUID($groupLdap->appleUID);
 		return $group;
 	}
 
@@ -377,7 +380,7 @@ class UserStorageMacOSX extends UserStorageBase {
 
 	/**
 	 * @param string $usrLogin - user login
-	 * @returns array of group objects @see getGroup
+	 * @return array of group objects @see getGroup
 	 */
 	private function _getUserGroupsNetwork($usrLogin) {
 		$groups = array();
@@ -391,7 +394,7 @@ class UserStorageMacOSX extends UserStorageBase {
 
 	/**
 	 * @param string $usrLogin - user login
-	 * @returns array of group objects @see getGroup
+	 * @return array of group objects @see getGroup
 	 */
 	private function _getUserGroupsLocal($usrLogin) {
 		$groups = array();
@@ -481,11 +484,11 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * Create group.
 	 * 
 	 * @param object $group @see getGroup
-	 * @returns bool
+	 * @return bool
 	 * 
 	 * @require $group->zasobID - Allowed only network group based on Zasob.
 	 */
-	public function createGroup($group) {
+	public function createGroup(ObjectGroup $group) {
 		// TEST: $ dscl /LDAPv3/127.0.0.1 -list /Groups PrimaryGroupID
 		if ($group->zasobID <= 0) {
 			$this->setError(1, "Error: create group {$group->primaryKey} {$group->realName} - missing zasobID", '(' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . ')');
@@ -540,7 +543,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 * 
 	 * @require sudoers dla _www
 	 * 
@@ -576,7 +579,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 */
 	private function _removeUserGroupLocal($usrLogin, $group) {
 		if (!$group || empty($group->primaryKey) || empty($usrLogin)) return false;
@@ -641,7 +644,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 */
 	private function _addUserGroupNetwork($usrLogin, $group) {
 		if (!$group || empty($group->primaryKey) || empty($usrLogin)) return false;
@@ -689,7 +692,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 */
 	private function _removeUserGroupNetwork($usrLogin, $group) {
 		if (!$group || empty($group->primaryKey) || empty($usrLogin)) return false;
@@ -710,7 +713,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 */
 	public function addUserGroup($usrLogin, $group) {
 		// $groupUid, $groupName
@@ -728,7 +731,7 @@ class UserStorageMacOSX extends UserStorageBase {
 	 * 
 	 * @param string $usrLogin - user login
 	 * @param object $group - @see getGroup
-	 * @returns bool
+	 * @return bool
 	 */
 	public function removeUserGroup($usrLogin, $group) {
 		if ($group->type == 'local') {
@@ -740,12 +743,12 @@ class UserStorageMacOSX extends UserStorageBase {
 		return false;
 	}
 
-	public function addNestedGroup($groupID, $nestedGroup) {
+	public function addNestedGroup($groupID, $nestedGroupID) {
 		if ($groupID <= 0) return false;
-		if ($nestedGroup->zasobID <= 0) return false;
+		if ($nestedGroupID <= 0) return false;
 
 		$group = $this->_getGroup($groupID);
-		$groupNested = $this->_getGroup($nestedGroup->zasobID);
+		$groupNested = $this->_getGroup($nestedGroupID);
 		if (!$group || !$groupNested) {
 			return false;
 		}
@@ -765,12 +768,12 @@ class UserStorageMacOSX extends UserStorageBase {
 		return true;
 	}
 
-	public function removeNestedGroup($groupID, $nestedGroup) {
+	public function removeNestedGroup($groupID, $nestedGroupID) {
 		if ($groupID <= 0) return false;
-		if ($nestedGroup->zasobID <= 0) return false;
+		if ($nestedGroupID <= 0) return false;
 
 		$group = $this->_getGroup($groupID);
-		$groupNested = $this->_getGroup($nestedGroup->zasobID);
+		$groupNested = $this->_getGroup($nestedGroupID);
 		if (!$group || !$groupNested) {
 			return false;
 		}

+ 87 - 21
SE/se-lib/UsersLdapHelper.php

@@ -6,7 +6,7 @@ class UsersLdapHelper {
 	public static function getUser($userName, $allAttrs = false) {
 		$ldapUsers = array();
 
-		$fetchAttrs = array('uid', 'apple-generateduid', 'givenName', 'uidNumber', 'cn', 'mail');// (givenName, sn) = cn
+		$attrMap = array('uid', 'apple-generateduid', 'givenName', 'uidNumber', 'cn', 'mail');// (givenName, sn) = cn
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -30,7 +30,7 @@ class UsersLdapHelper {
 					}
 				}
 			} else {
-				foreach ($fetchAttrs as $vAttrName) {
+				foreach ($attrMap as $vAttrName) {
 					$vAttrVal = V::get($vAttrName, '', $attrs);
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						$userObj->{$vAttrName} = $vAttrVal[0];
@@ -49,7 +49,7 @@ class UsersLdapHelper {
 	public static function getUsersAll() {
 		$allLdapUsers = array();
 
-		$fetchAttrs = array('uid', 'apple-generateduid', 'givenName', 'uidNumber', 'cn', 'mail');// (givenName, sn) = cn
+		$attrMap = array('uid', 'apple-generateduid', 'givenName', 'uidNumber', 'cn', 'mail');// (givenName, sn) = cn
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -61,7 +61,7 @@ class UsersLdapHelper {
 		while ($entry) {
 			$attrs = $ldap->get_attributes($entry);
 			$userObj = new stdClass();
-			foreach ($fetchAttrs as $vAttrName) {
+			foreach ($attrMap as $vAttrName) {
 				$vAttrVal = V::get($vAttrName, '', $attrs);
 				if (is_array($vAttrVal) && !empty($vAttrVal)) {
 					$userObj->{$vAttrName} = $vAttrVal[0];
@@ -79,7 +79,7 @@ class UsersLdapHelper {
 	public static function getUserGroups($userName, $authLDAPSubGroupDepth = 3) {
 		$userLdapGroups = array();
 
-		$fetchAttrs = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
+		$attrMap = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -114,7 +114,7 @@ class UsersLdapHelper {
 				if(V::get('DBG_L', '', $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">user('.$userName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($attrs);echo'</pre>';}
 
 				$groupObj = new stdClass();
-				foreach ($fetchAttrs as $kAttrName => $vField) {
+				foreach ($attrMap as $kAttrName => $vField) {
 					$vAttrVal = V::get($kAttrName, '', $attrs);
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						$groupObj->{$vField} = $vAttrVal[0];
@@ -151,9 +151,9 @@ class UsersLdapHelper {
 		$allLdapGroups = array();
 		if (empty($appleUids)) return $allLdapGroups;
 
-		$fetchAttrs = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
-		$fetchAttrs['apple-group-realname'] = 'realName';
-		$fetchAttrs['apple-group-nestedgroup'] = 'nestedGroups';
+		$attrMap = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
+		$attrMap['apple-group-realname'] = 'realName';
+		$attrMap['apple-group-nestedgroup'] = 'nestedGroups';
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -172,7 +172,7 @@ class UsersLdapHelper {
 			if ($allAttrs) {
 				for ($i = 0; $i < $attrs['count']; $i++) {
 					$vAttrName = $attrs[$i];
-					$vFldName = V::get($vAttrName, $vAttrName, $fetchAttrs);
+					$vFldName = V::get($vAttrName, $vAttrName, $attrMap);
 					$vAttrVal = $attrs[$vAttrName];
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {
@@ -186,7 +186,7 @@ class UsersLdapHelper {
 					}
 				}
 			} else {
-				foreach ($fetchAttrs as $kAttrName => $vFldName) {
+				foreach ($attrMap as $kAttrName => $vFldName) {
 					$vAttrVal = V::get($kAttrName, '', $attrs);
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {
@@ -215,12 +215,78 @@ class UsersLdapHelper {
 		return $allLdapGroups;
 	}
 
+	public static function getParentGroupsByAppleUID($appleUid, $allAttrs = false) {
+		$allLdapGroups = array();
+		if (!$appleUid) return $allLdapGroups;
+
+		$attrMap = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
+		$attrMap['apple-group-realname'] = 'realName';
+		$attrMap['apple-group-nestedgroup'] = 'nestedGroups';
+
+		Lib::loadClass('LDAP');
+		$ldap = LDAP::getInstance();
+
+		$filters = array();
+		$filter = "(&(objectClass=apple-group)(apple-group-nestedgroup={$appleUid}))";
+		$attributes = array();
+		$res = $ldap->search($filter, 'cn=groups', $attributes);
+		$entry = $ldap->first_entry($res);
+		while ($entry) {
+			$attrs = $ldap->get_attributes($entry);
+
+			$groupObj = new stdClass();
+
+			if ($allAttrs) {
+				for ($i = 0; $i < $attrs['count']; $i++) {
+					$vAttrName = $attrs[$i];
+					$vFldName = V::get($vAttrName, $vAttrName, $attrMap);
+					$vAttrVal = $attrs[$vAttrName];
+					if (is_array($vAttrVal) && !empty($vAttrVal)) {
+						if ($vAttrVal['count'] > 1) {
+							$groupObj->{$vFldName} = array();
+							for ($j = 0; $j < $vAttrVal['count']; $j++) {
+								$groupObj->{$vFldName}[] = $vAttrVal[$j];
+							}
+						} else {
+							$groupObj->{$vFldName} = $vAttrVal[0];
+						}
+					}
+				}
+			} else {
+				foreach ($attrMap as $kAttrName => $vFldName) {
+					$vAttrVal = V::get($kAttrName, '', $attrs);
+					if (is_array($vAttrVal) && !empty($vAttrVal)) {
+						if ($vAttrVal['count'] > 1) {
+							$groupObj->{$vFldName} = array();
+							for ($j = 0; $j < $vAttrVal['count']; $j++) {
+								$groupObj->{$vFldName}[] = $vAttrVal[$j];
+							}
+						} else {
+							$groupObj->{$vFldName} = $vAttrVal[0];
+						}
+					}
+				}
+			}
+
+			if ($groupObj->cn && $groupObj->appleUID) {
+				$allLdapGroups[$groupObj->appleUID] = $groupObj;
+			} else {
+				echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Error: brak cn lub apple-generateduid (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('attrs'=>$attrs, 'groupObj'=>$groupObj));echo'</pre>';
+			}
+
+			$entry = $ldap->next_entry($entry);
+		}
+		$ldap->free_result($res);
+
+		return $allLdapGroups;
+	}
+
 	public static function getGroupsByID($groupID, $allAttrs = false) {
 		$allLdapGroups = array();
 
-		$fetchAttrs = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
-		$fetchAttrs['apple-group-realname'] = 'realName';
-		$fetchAttrs['apple-group-nestedgroup'] = 'nestedGroups';
+		$attrMap = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
+		$attrMap['apple-group-realname'] = 'realName';
+		$attrMap['apple-group-nestedgroup'] = 'nestedGroups';
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -237,7 +303,7 @@ class UsersLdapHelper {
 			if ($allAttrs) {
 				for ($i = 0; $i < $attrs['count']; $i++) {
 					$vAttrName = $attrs[$i];
-					$vFldName = V::get($vAttrName, $vAttrName, $fetchAttrs);
+					$vFldName = V::get($vAttrName, $vAttrName, $attrMap);
 					$vAttrVal = $attrs[$vAttrName];
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {
@@ -251,7 +317,7 @@ class UsersLdapHelper {
 					}
 				}
 			} else {
-				foreach ($fetchAttrs as $kAttrName => $vFldName) {
+				foreach ($attrMap as $kAttrName => $vFldName) {
 					$vAttrVal = V::get($kAttrName, '', $attrs);
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {
@@ -283,9 +349,9 @@ class UsersLdapHelper {
 	public static function getGroupsAll($allAttrs = false) {
 		$allLdapGroups = array();
 
-		$fetchAttrs = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
-		$fetchAttrs['apple-group-realname'] = 'realName';
-		$fetchAttrs['apple-group-nestedgroup'] = 'nestedGroups';
+		$attrMap = array('apple-generateduid'=>'appleUID', 'gidNumber'=>'gidNumber', 'cn'=>'cn');// (givenName, sn) = cn
+		$attrMap['apple-group-realname'] = 'realName';
+		$attrMap['apple-group-nestedgroup'] = 'nestedGroups';
 
 		Lib::loadClass('LDAP');
 		$ldap = LDAP::getInstance();
@@ -302,7 +368,7 @@ class UsersLdapHelper {
 			if ($allAttrs) {
 				for ($i = 0; $i < $attrs['count']; $i++) {
 					$vAttrName = $attrs[$i];
-					$vFldName = V::get($vAttrName, $vAttrName, $fetchAttrs);
+					$vFldName = V::get($vAttrName, $vAttrName, $attrMap);
 					$vAttrVal = $attrs[$vAttrName];
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {
@@ -316,7 +382,7 @@ class UsersLdapHelper {
 					}
 				}
 			} else {
-				foreach ($fetchAttrs as $kAttrName => $vFldName) {
+				foreach ($attrMap as $kAttrName => $vFldName) {
 					$vAttrVal = V::get($kAttrName, '', $attrs);
 					if (is_array($vAttrVal) && !empty($vAttrVal)) {
 						if ($vAttrVal['count'] > 1) {

+ 11 - 11
SE/superedit-GROUP_ADD_NESTEDGROUPS.php

@@ -1,5 +1,7 @@
 <?php
 
+Lib::loadClass('UserStorageFactory');
+
 /**
  * @param $_GET['groupID'] - id grupy - zasob typu: 'STANOWISKO', 'PODMIOT', 'DZIAL'
  * 
@@ -7,7 +9,6 @@
  *   index.php?MENU_INIT=GROUP_ADD_NESTEDGROUPS&groupID=13
  */
 function GROUP_ADD_NESTEDGROUPS() {
-	Lib::loadClass('UserStorage');
 	$linkTypeIdNestedGroups = 5;
 
 	$taskMsgs = array();
@@ -22,11 +23,11 @@ function GROUP_ADD_NESTEDGROUPS() {
 				$taskErrors[] = 'Wrong param group id or remove group id!';
 			}
 			else {
-				$usrStorageDB = UserStorage::getStorage('DB');
+				$usrStorageDB = UserStorageFactory::getStorage('DB');
 				$group = $usrStorageDB->getGroupWithoutNested($groupID);
 				$parentGroup = $usrStorageDB->getGroupWithoutNested($rmParentGroupID);
 				if ($group && $parentGroup) {
-					$removed = $usrStorageDB->removeParentGroup($groupID, $parentGroup);
+					$removed = $usrStorageDB->removeParentGroup($groupID, $rmParentGroupID);
 					if ($removed) {
 						$taskMsgs[] = "Usunięto grupę nadrzędną [{$rmParentGroupID}] do grupy [{$groupID}]";
 					} else {
@@ -43,11 +44,11 @@ function GROUP_ADD_NESTEDGROUPS() {
 				$taskErrors[] = 'Wrong param group id or remove group id!';
 			}
 			else {
-				$usrStorageDB = UserStorage::getStorage('DB');
+				$usrStorageDB = UserStorageFactory::getStorage('DB');
 				$group = $usrStorageDB->getGroupWithoutNested($groupID);
 				$nestedGroup = $usrStorageDB->getGroupWithoutNested($rmNestedGroupID);
 				if ($group && $nestedGroup) {
-					$removed = $usrStorageDB->removeNestedGroup($groupID, $nestedGroup);
+					$removed = $usrStorageDB->removeNestedGroup($groupID, $rmNestedGroupID);
 					if ($removed) {
 						$taskMsgs[] = "Usunięto grupę zagnieżdżoną [{$rmNestedGroupID}] z grupy [{$groupID}]";
 					} else {
@@ -63,7 +64,7 @@ function GROUP_ADD_NESTEDGROUPS() {
 			// [addNestedGroupID] => 372
 			$groupID = V::get('groupID', 0, $_GET, 'int');
 			if ($groupID > 0) {
-				$usrStorageDB = UserStorage::getStorage('DB');
+				$usrStorageDB = UserStorageFactory::getStorage('DB');
 				$group = $usrStorageDB->getGroupWithoutNested($groupID);
 				$addParentGroupID = V::get('addParentGroupID', 0, $_POST, 'int');
 				$addNestedGroupID = V::get('addNestedGroupID', 0, $_POST, 'int');
@@ -71,7 +72,7 @@ function GROUP_ADD_NESTEDGROUPS() {
 					$group = $usrStorageDB->getGroupWithoutNested($groupID);
 					$parentGroup = $usrStorageDB->getGroupWithoutNested($addParentGroupID);
 					if ($group && $parentGroup) {
-						$added = $usrStorageDB->addParentGroup($groupID, $parentGroup);
+						$added = $usrStorageDB->addParentGroup($groupID, $addParentGroupID);
 						if ($added) {
 							$taskMsgs[] = "Dodano grupę nadrzędną [{$addParentGroupID}] do grupy [{$groupID}]";
 						} else {
@@ -83,7 +84,7 @@ function GROUP_ADD_NESTEDGROUPS() {
 					$group = $usrStorageDB->getGroupWithoutNested($groupID);
 					$nestedGroup = $usrStorageDB->getGroupWithoutNested($addNestedGroupID);
 					if ($group && $nestedGroup) {
-						$added = $usrStorageDB->addNestedGroup($groupID, $nestedGroup);
+						$added = $usrStorageDB->addNestedGroup($groupID, $addNestedGroupID);
 						if ($added) {
 							$taskMsgs[] = "Dodano grupę zagnieżdżoną [{$addNestedGroupID}] do grupy [{$groupID}]";
 						} else {
@@ -168,8 +169,7 @@ function GROUP_ADD_NESTEDGROUPS() {
 	}
 
 
-	Lib::loadClass('UserStorage');
-	$usrStorageDB = UserStorage::getStorage('DB');
+	$usrStorageDB = UserStorageFactory::getStorage('DB');
 
 	if (!$usrStorageDB) {
 		echo '<div class="alert alert-error">Error storage not exists!</div>';
@@ -182,7 +182,7 @@ function GROUP_ADD_NESTEDGROUPS() {
 		return;
 	}
 
-	$group->parentGroups = $usrStorageDB->fetchParentGroups($groupID);
+	$group->getParentGroups();
 
 	if(V::get('DBG_NG', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$group (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($group);echo'</pre>';}
 

+ 25 - 19
SE/superedit-SYNC_LDAP_PERMS.php

@@ -41,9 +41,9 @@ function SYNC_LDAP_PERMS() {
 	$DBG = ('1' == V::get('DBG_SLP', '', $_GET));
 
 	if ('' !== ($userName = V::get('syncUsr', '', $_GET))) {// TEST
-		Lib::loadClass('UserStorage');
-		$usrStorageDB = UserStorage::getStorage('DB');
-		$usrStorageLdap = UserStorage::getStorage('MacOSX');
+		Lib::loadClass('UserStorageFactory');
+		$usrStorageDB = UserStorageFactory::getStorage('DB');
+		$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
 
 		if (!$usrStorageDB || !$usrStorageLdap) {
 			echo '<p>Error storage not exists</p>';
@@ -70,11 +70,14 @@ function SYNC_LDAP_PERMS() {
 			<?php if (empty($syncTodoList)) : ?>
 				<div class="alert alert-info">Brak zadań do wykonania - użytkownik zsynchronizowany</div>
 			<?php else : ?>
-				<ul>
-					<?php foreach ($syncTodoList as $vTask) : ?>
-						<li><?php echo $vTask; ?></li>
-					<?php endforeach; ?>
-				</ul>
+				<div class="well">
+					<p>Lista zadań do wykonania:</p>
+					<ul>
+						<?php foreach ($syncTodoList as $vTask) : ?>
+							<li><?php echo $vTask; ?></li>
+						<?php endforeach; ?>
+					</ul>
+				</div>
 			<?php endif; ?>
 			<?php
 
@@ -110,9 +113,9 @@ function SYNC_LDAP_PERMS() {
 	}
 
 	if ('' !== ($userName = V::get('syncUsrDisabled', '', $_GET))) {// TEST
-		Lib::loadClass('UserStorage');
-		$usrStorageDB = UserStorage::getStorage('DB');
-		$usrStorageLdap = UserStorage::getStorage('MacOSX');
+		Lib::loadClass('UserStorageFactory');
+		$usrStorageDB = UserStorageFactory::getStorage('DB');
+		$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
 
 		if (!$usrStorageDB || !$usrStorageLdap) {
 			echo '<p>Error storage not exists</p>';
@@ -188,9 +191,9 @@ function SYNC_LDAP_PERMS() {
 	}
 
 	if (0 < ($syncGroupID = V::get('syncGroup', 0, $_GET, 'int'))) {
-		Lib::loadClass('UserStorage');
-		$usrStorageDB = UserStorage::getStorage('DB');
-		$usrStorageLdap = UserStorage::getStorage('MacOSX');
+		Lib::loadClass('UserStorageFactory');
+		$usrStorageDB = UserStorageFactory::getStorage('DB');
+		$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
 
 		if (!$usrStorageDB || !$usrStorageLdap) {
 			echo '<div class="alert alert-error">' . "Error storage not exists" . '</div>';
@@ -220,11 +223,14 @@ function SYNC_LDAP_PERMS() {
 				<?php if (empty($syncTodoList)) : ?>
 					<div class="alert alert-info">Brak zadań do wykonania - grupa zsynchronizowana</div>
 				<?php else : ?>
-					<ul>
-						<?php foreach ($syncTodoList as $vTask) : ?>
-							<li><?php echo $vTask; ?></li>
-						<?php endforeach; ?>
-					</ul>
+					<div class="well">
+						<p>Lista zadań do wykonania:</p>
+						<ul>
+							<?php foreach ($syncTodoList as $vTask) : ?>
+								<li><?php echo $vTask; ?></li>
+							<?php endforeach; ?>
+						</ul>
+					</div>
 				<?php endif; ?>
 				<?php
 

+ 5 - 5
SE/superedit-USER_ADD_GROUP.php

@@ -7,7 +7,7 @@
  *   index.php?MENU_INIT=USER_ADD_GROUP&usrLogin=test13
  */
 function USER_ADD_GROUP() {
-	Lib::loadClass('UserStorage');
+	Lib::loadClass('UserStorageFactory');
 
 	$taskMsgs = array();
 	$taskErrors = array();
@@ -21,7 +21,7 @@ function USER_ADD_GROUP() {
 				$taskErrors[] = 'Wrong param user login or remove group id!';
 			}
 			else {
-				$usrStorageDB = UserStorage::getStorage('DB');
+				$usrStorageDB = UserStorageFactory::getStorage('DB');
 				if (!$usrStorageDB) {
 					$taskErrors[] =  'Error storage not exists!';
 				} else {
@@ -43,8 +43,8 @@ function USER_ADD_GROUP() {
 				$taskErrors[] = 'Wrong param user login!';
 			}
 			else {
-				Lib::loadClass('UserStorage');
-				$usrStorageDB = UserStorage::getStorage('DB');
+				Lib::loadClass('UserStorageFactory');
+				$usrStorageDB = UserStorageFactory::getStorage('DB');
 				if (!$usrStorageDB) {
 					$taskErrors[] =  'Error storage not exists!';
 				}
@@ -149,7 +149,7 @@ function USER_ADD_GROUP() {
 		return;
 	}
 
-	$usrStorageDB = UserStorage::getStorage('DB');
+	$usrStorageDB = UserStorageFactory::getStorage('DB');
 
 	if (!$usrStorageDB) {
 		echo '<div class="alert alert-error">Error storage not exists!</div>';