|
@@ -6,10 +6,7 @@ Lib::loadClass('ObjectGroupDB');
|
|
|
|
|
|
|
|
class UserStorageDB extends UserStorageBase {
|
|
class UserStorageDB extends UserStorageBase {
|
|
|
|
|
|
|
|
- private $_db;
|
|
|
|
|
-
|
|
|
|
|
- public function __construct($db) {
|
|
|
|
|
- $this->_db = $db;
|
|
|
|
|
|
|
+ public function __construct() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -26,11 +23,10 @@ class UserStorageDB extends UserStorageBase {
|
|
|
* $usr->isDisabled true, false or null if not set
|
|
* $usr->isDisabled true, false or null if not set
|
|
|
*/
|
|
*/
|
|
|
public function getUser($usrLogin) {
|
|
public function getUser($usrLogin) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
if (empty($usrLogin)) return false;
|
|
if (empty($usrLogin)) return false;
|
|
|
|
|
|
|
|
- $user = null;
|
|
|
|
|
- $sql = "SELECT a.`ID` as primaryKey
|
|
|
|
|
|
|
+ $user = DB::getPDO()->fetchFirstAsObject("
|
|
|
|
|
+ SELECT a.`ID` as primaryKey
|
|
|
, a.`ADM_ACCOUNT` as login
|
|
, a.`ADM_ACCOUNT` as login
|
|
|
, a.`ADM_PASSWD` as password
|
|
, a.`ADM_PASSWD` as password
|
|
|
, a.`ADM_NAME` as name
|
|
, a.`ADM_NAME` as name
|
|
@@ -46,13 +42,12 @@ class UserStorageDB extends UserStorageBase {
|
|
|
-- , a.`ADM_NIP` -- NIP
|
|
-- , a.`ADM_NIP` -- NIP
|
|
|
-- , a.`ADM_PESEL` -- nr. PESEL
|
|
-- , a.`ADM_PESEL` -- nr. PESEL
|
|
|
from `ADMIN_USERS` as a
|
|
from `ADMIN_USERS` as a
|
|
|
- where a.`ADM_ACCOUNT`='{$usrLogin}'
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $user = $this->_buildUserFromRow($r);
|
|
|
|
|
- }
|
|
|
|
|
- return $user;
|
|
|
|
|
|
|
+ where a.`ADM_ACCOUNT` = :login
|
|
|
|
|
+ ", [
|
|
|
|
|
+ ':login' => $usrLogin,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return ($user) ? $this->_buildUserFromRow($user) : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function _buildUserFromRow($r) {
|
|
private function _buildUserFromRow($r) {
|
|
@@ -112,71 +107,59 @@ class UserStorageDB extends UserStorageBase {
|
|
|
* (optional) $group->zasobDESC
|
|
* (optional) $group->zasobDESC
|
|
|
*/
|
|
*/
|
|
|
public function getGroup($idGroup) {
|
|
public function getGroup($idGroup) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
if ($idGroup <= 0) return false;
|
|
if ($idGroup <= 0) return false;
|
|
|
|
|
|
|
|
- $group = null;
|
|
|
|
|
- $sql = "SELECT z.`ID`
|
|
|
|
|
|
|
+ $group = DB::getPDO()->fetchFirstAsObject("
|
|
|
|
|
+ SELECT z.`ID`
|
|
|
, z.`DESC`
|
|
, z.`DESC`
|
|
|
, z.`TYPE`
|
|
, z.`TYPE`
|
|
|
-- , IF(a.`A_STATUS`='NORMAL', 0, 1) as isDisabled
|
|
-- , IF(a.`A_STATUS`='NORMAL', 0, 1) as isDisabled
|
|
|
from `CRM_LISTA_ZASOBOW` as z
|
|
from `CRM_LISTA_ZASOBOW` as z
|
|
|
- where z.`ID`='{$idGroup}'
|
|
|
|
|
- and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $group = $this->_buildGroupFromRow($r, $fetchNested = true);
|
|
|
|
|
- }
|
|
|
|
|
- return $group;
|
|
|
|
|
|
|
+ where z.`ID` = '{$idGroup}'
|
|
|
|
|
+ and z.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ ");
|
|
|
|
|
+
|
|
|
|
|
+ return ($group) ? $this->_buildGroupFromRow($group, $fetchNested = true) : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getGroupWithoutNested($idGroup) {
|
|
public function getGroupWithoutNested($idGroup) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
if ($idGroup <= 0) return false;
|
|
if ($idGroup <= 0) return false;
|
|
|
|
|
|
|
|
- $group = null;
|
|
|
|
|
- $sql = "SELECT z.`ID`
|
|
|
|
|
|
|
+ $group = DB::getPDO()->fetchFirstAsObject("
|
|
|
|
|
+ SELECT z.`ID`
|
|
|
, z.`DESC`
|
|
, z.`DESC`
|
|
|
, z.`TYPE`
|
|
, z.`TYPE`
|
|
|
- -- , IF(a.`A_STATUS`='NORMAL', 0, 1) as isDisabled
|
|
|
|
|
|
|
+ -- , IF(a.`A_STATUS` = 'NORMAL', 0, 1) as isDisabled
|
|
|
from `CRM_LISTA_ZASOBOW` as z
|
|
from `CRM_LISTA_ZASOBOW` as z
|
|
|
- where z.`ID`='{$idGroup}'
|
|
|
|
|
- and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $group = $this->_buildGroupFromRow($r, $fetchNested = false);
|
|
|
|
|
- }
|
|
|
|
|
- return $group;
|
|
|
|
|
|
|
+ where z.`ID` = '{$idGroup}'
|
|
|
|
|
+ and z.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ ");
|
|
|
|
|
+
|
|
|
|
|
+ return ($group) ? $this->_buildGroupFromRow($group, $fetchNested = false) : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function fetchNestedGroups($idGroup) {
|
|
public function fetchNestedGroups($idGroup) {
|
|
|
- if (!$this->_db) return null;
|
|
|
|
|
if ($idGroup <= 0) return null;
|
|
if ($idGroup <= 0) return null;
|
|
|
- $groups = array();
|
|
|
|
|
- $sql = "SELECT l.`TABLE_2_ID` as groupID
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return array_map(function ($item) {
|
|
|
|
|
+ return $this->_buildGroupFromRow((object)$item, $fetchNested = false);
|
|
|
|
|
+ }, DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ SELECT l.`TABLE_2_ID` as groupID
|
|
|
, z2.`ID`
|
|
, z2.`ID`
|
|
|
, z2.`DESC`
|
|
, z2.`DESC`
|
|
|
, z2.`TYPE`
|
|
, z2.`TYPE`
|
|
|
from `ITEM_LINKS` as 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`='{$idGroup}'
|
|
|
|
|
- and l.`TABLE_2_ID`>0
|
|
|
|
|
- and l.`LINKS_TYPE_ID`=5
|
|
|
|
|
- and l.`TABLE_1_NAME`='CRM_LISTA_ZASOBOW'
|
|
|
|
|
- and l.`A_STATUS` in('NORMAL')
|
|
|
|
|
- and l.`TABLE_2_NAME`='CRM_LISTA_ZASOBOW'
|
|
|
|
|
- and z1.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- and z2.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $groups[$r->groupID] = $this->_buildGroupFromRow($r, $fetchNested = false);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $groups;
|
|
|
|
|
|
|
+ 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` = '{$idGroup}'
|
|
|
|
|
+ and l.`TABLE_2_ID` > 0
|
|
|
|
|
+ and l.`LINKS_TYPE_ID` = 5
|
|
|
|
|
+ and l.`TABLE_1_NAME` = 'CRM_LISTA_ZASOBOW'
|
|
|
|
|
+ and l.`A_STATUS` in ( 'NORMAL' )
|
|
|
|
|
+ and l.`TABLE_2_NAME` = 'CRM_LISTA_ZASOBOW'
|
|
|
|
|
+ and z1.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ and z2.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ ", 'groupID'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getParentGroups(ObjectGroup $group) {
|
|
public function getParentGroups(ObjectGroup $group) {
|
|
@@ -184,58 +167,53 @@ class UserStorageDB extends UserStorageBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function fetchParentGroups($idGroup) {
|
|
public function fetchParentGroups($idGroup) {
|
|
|
- if (!$this->_db) return null;
|
|
|
|
|
if ($idGroup <= 0) return null;
|
|
if ($idGroup <= 0) return null;
|
|
|
- $groups = array();
|
|
|
|
|
- $sql = "SELECT l.`TABLE_1_ID` as groupID
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return array_map(function ($item) {
|
|
|
|
|
+ return $this->_buildGroupFromRow((object)$item, $fetchNested = false);
|
|
|
|
|
+ }, DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ SELECT l.`TABLE_1_ID` as groupID
|
|
|
, z1.`ID`
|
|
, z1.`ID`
|
|
|
, z1.`DESC`
|
|
, z1.`DESC`
|
|
|
, z1.`TYPE`
|
|
, z1.`TYPE`
|
|
|
from `ITEM_LINKS` as 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`>0
|
|
|
|
|
- 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')
|
|
|
|
|
- and l.`TABLE_2_NAME`='CRM_LISTA_ZASOBOW'
|
|
|
|
|
- and z1.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- and z2.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $groups[$r->groupID] = $this->_buildGroupFromRow($r, $fetchNested = false);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $groups;
|
|
|
|
|
|
|
+ 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` = '{$idGroup}'
|
|
|
|
|
+ and l.`LINKS_TYPE_ID` = 5
|
|
|
|
|
+ and l.`TABLE_1_NAME` = 'CRM_LISTA_ZASOBOW'
|
|
|
|
|
+ and l.`A_STATUS` in ( 'NORMAL' )
|
|
|
|
|
+ and l.`TABLE_2_NAME` = 'CRM_LISTA_ZASOBOW'
|
|
|
|
|
+ and z1.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ and z2.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ ", 'groupID'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function _getGroupConnection($idParentGroup, $idGroup) {
|
|
private function _getGroupConnection($idParentGroup, $idGroup) {
|
|
|
- if (!$this->_db) return null;
|
|
|
|
|
if ($idParentGroup <= 0) return null;
|
|
if ($idParentGroup <= 0) return null;
|
|
|
if ($idGroup <= 0) return null;
|
|
if ($idGroup <= 0) return null;
|
|
|
- $sql = "SELECT l.*
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $listItems = array_map(function ($item) {
|
|
|
|
|
+ return (object)$item;
|
|
|
|
|
+ }, DB::getPDO()->fetchAll("
|
|
|
|
|
+ SELECT l.*
|
|
|
from `ITEM_LINKS` as 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`='{$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'
|
|
|
|
|
- and z1.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- and z2.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- return $r;
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ 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` = '{$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'
|
|
|
|
|
+ and z1.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ and z2.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
|
|
|
|
|
+ "));
|
|
|
|
|
+
|
|
|
|
|
+ return (!empty($listItems)) ? $listItems : null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function _setGroupConnection($idParentGroup, $idGroup, $errorMsg = 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 ($idGroup <= 0) throw new Exception("Wrong param id group!");
|
|
|
if ($idParentGroup <= 0) throw new Exception("Wrong param id parent 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}]";
|
|
if (!$errorMsg) $errorMsg = "Nie udało się utworzyć połączenia grup [{$idGroup}] i [{$idParentGroup}]";
|
|
@@ -248,7 +226,7 @@ class UserStorageDB extends UserStorageBase {
|
|
|
$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
|
|
$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
|
|
|
if ($connObj) {
|
|
if ($connObj) {
|
|
|
$connObj->A_STATUS = 'NORMAL';
|
|
$connObj->A_STATUS = 'NORMAL';
|
|
|
- $affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
|
|
|
|
+ $affected = DB::getDB()->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
if ($affected <= 0) throw new Exception($errorMsg);
|
|
if ($affected <= 0) throw new Exception($errorMsg);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -262,13 +240,12 @@ class UserStorageDB extends UserStorageBase {
|
|
|
$sqlObj->LINKS_TYPE_ID = 5;// NestedGroups
|
|
$sqlObj->LINKS_TYPE_ID = 5;// NestedGroups
|
|
|
$sqlObj->A_STATUS = 'NORMAL';
|
|
$sqlObj->A_STATUS = 'NORMAL';
|
|
|
|
|
|
|
|
- $idCreatedRow = $this->_db->ADD_NEW_OBJ('ITEM_LINKS', $sqlObj);
|
|
|
|
|
|
|
+ $idCreatedRow = DB::getDB()->ADD_NEW_OBJ('ITEM_LINKS', $sqlObj);
|
|
|
if ($idCreatedRow <= 0) throw new Exception($errorMsg);
|
|
if ($idCreatedRow <= 0) throw new Exception($errorMsg);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function addNestedGroup($idGroup, $idNestedGroup) {
|
|
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 ($idGroup <= 0) throw new Exception("Wrong param id group!");
|
|
|
if ($idNestedGroup <= 0) throw new Exception("Wrong param id nested 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}]";
|
|
$errorMsg = "Nie udało się dodać grupy zagnieżdżonej [{$idNestedGroup}] do grupy [{$idGroup}]";
|
|
@@ -276,7 +253,6 @@ class UserStorageDB extends UserStorageBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function addParentGroup($idGroup, $idParentGroup) {
|
|
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 ($idGroup <= 0) throw new Exception("Wrong param id group!");
|
|
|
if ($idParentGroup <= 0) throw new Exception("Wrong param id parent 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}]";
|
|
$errorMsg = "Nie udało się dodać grupy nadrzędnej [{$idParentGroup}] do grupy [{$idGroup}]";
|
|
@@ -284,14 +260,13 @@ class UserStorageDB extends UserStorageBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function removeNestedGroup($idGroup, $idNestedGroup) {
|
|
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 ($idGroup <= 0) throw new Exception("Wrong param id group!");
|
|
|
if ($idNestedGroup <= 0) throw new Exception("Wrong param id nested group!");
|
|
if ($idNestedGroup <= 0) throw new Exception("Wrong param id nested group!");
|
|
|
|
|
|
|
|
$connObj = $this->_getGroupConnection($idGroup, $idNestedGroup);
|
|
$connObj = $this->_getGroupConnection($idGroup, $idNestedGroup);
|
|
|
if ($connObj) {
|
|
if ($connObj) {
|
|
|
$connObj->A_STATUS = 'DELETED';
|
|
$connObj->A_STATUS = 'DELETED';
|
|
|
- $affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
|
|
|
|
+ $affected = DB::getDB()->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
if ($affected <= 0) {
|
|
if ($affected <= 0) {
|
|
|
throw new Exception("Nie udało się usunąć grupy zagnieżdżonej '{$kGroupID}' do grupy '{$groupID}' w bazie danych");
|
|
throw new Exception("Nie udało się usunąć grupy zagnieżdżonej '{$kGroupID}' do grupy '{$groupID}' w bazie danych");
|
|
|
}
|
|
}
|
|
@@ -299,14 +274,13 @@ class UserStorageDB extends UserStorageBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function removeParentGroup($idGroup, $idParentGroup) {
|
|
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 ($idGroup <= 0) throw new Exception("Wrong param id group!");
|
|
|
if ($idParentGroup <= 0) throw new Exception("Wrong param id parent group!");
|
|
if ($idParentGroup <= 0) throw new Exception("Wrong param id parent group!");
|
|
|
|
|
|
|
|
$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
|
|
$connObj = $this->_getGroupConnection($idParentGroup, $idGroup);
|
|
|
if ($connObj) {
|
|
if ($connObj) {
|
|
|
$connObj->A_STATUS = 'DELETED';
|
|
$connObj->A_STATUS = 'DELETED';
|
|
|
- $affected = $this->_db->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
|
|
|
|
+ $affected = DB::getDB()->UPDATE_OBJ('ITEM_LINKS', $connObj);
|
|
|
if ($affected <= 0) {
|
|
if ($affected <= 0) {
|
|
|
throw new Exception("Nie udało się usunąć grupy nadrzędnej [{$idParentGroupToRemove}] do grupy [{$idGroup}]");
|
|
throw new Exception("Nie udało się usunąć grupy nadrzędnej [{$idParentGroupToRemove}] do grupy [{$idGroup}]");
|
|
|
}
|
|
}
|
|
@@ -336,7 +310,8 @@ class UserStorageDB extends UserStorageBase {
|
|
|
} else {
|
|
} else {
|
|
|
$sqlStatus = 'NORMAL';
|
|
$sqlStatus = 'NORMAL';
|
|
|
}
|
|
}
|
|
|
- $sql = "update `ADMIN_USERS`
|
|
|
|
|
|
|
+ $sql = "
|
|
|
|
|
+ update `ADMIN_USERS`
|
|
|
set `A_STATUS`='{$sqlStatus}'
|
|
set `A_STATUS`='{$sqlStatus}'
|
|
|
where
|
|
where
|
|
|
`ADM_ACCOUNT`='{$usrLogin}'
|
|
`ADM_ACCOUNT`='{$usrLogin}'
|
|
@@ -355,31 +330,26 @@ class UserStorageDB extends UserStorageBase {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function _getUserGroupsAll($usrLogin) {
|
|
public function _getUserGroupsAll($usrLogin) {
|
|
|
- $groups = array();
|
|
|
|
|
-
|
|
|
|
|
$sql_select = array();
|
|
$sql_select = array();
|
|
|
$sql_select[] = "z.`ID`";
|
|
$sql_select[] = "z.`ID`";
|
|
|
$sql_select[] = "z.`DESC`";
|
|
$sql_select[] = "z.`DESC`";
|
|
|
$sql_select[] = "z.`TYPE`";
|
|
$sql_select[] = "z.`TYPE`";
|
|
|
//$sql_select[] = "z.`OPIS`";
|
|
//$sql_select[] = "z.`OPIS`";
|
|
|
$sql_select[] = "z.`A_LDAP_GID`";
|
|
$sql_select[] = "z.`A_LDAP_GID`";
|
|
|
-
|
|
|
|
|
$sql_select = implode(', ', $sql_select);
|
|
$sql_select = implode(', ', $sql_select);
|
|
|
- $sql = "select {$sql_select}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return array_map(function ($item) {
|
|
|
|
|
+ return $this->_buildGroupFromRow((object)$item);
|
|
|
|
|
+ }, DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ select {$sql_select}
|
|
|
from `CRM_AUTH_PROFILE` as up
|
|
from `CRM_AUTH_PROFILE` as up
|
|
|
- join `ADMIN_USERS` as a on(a.`ID`=up.`REMOTE_ID` and up.`REMOTE_TABLE`='ADMIN_USERS')
|
|
|
|
|
- join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
|
|
|
|
|
|
|
+ join `ADMIN_USERS` as a on ( a.`ID` = up.`REMOTE_ID` and up.`REMOTE_TABLE` = 'ADMIN_USERS' )
|
|
|
|
|
+ join `CRM_LISTA_ZASOBOW` as z on ( z.`ID` = up.`ID_ZASOB` )
|
|
|
where
|
|
where
|
|
|
- a.`ADM_ACCOUNT`='{$usrLogin}'
|
|
|
|
|
- and up.`A_STATUS` in('WAITING', 'NORMAL')
|
|
|
|
|
- and z.`TYPE` in('STANOWISKO','DZIAL','PODMIOT')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $groups[$r->ID] = $this->_buildGroupFromRow($r);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return $groups;
|
|
|
|
|
|
|
+ a.`ADM_ACCOUNT` = '{$usrLogin}'
|
|
|
|
|
+ and up.`A_STATUS` in ( 'WAITING', 'NORMAL' )
|
|
|
|
|
+ and z.`TYPE` in ( 'STANOWISKO', 'DZIAL', 'PODMIOT' )
|
|
|
|
|
+ ", 'ID'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function _getUserGroupsBelow($groups) {// TODO: fetch groups below
|
|
private function _getUserGroupsBelow($groups) {// TODO: fetch groups below
|
|
@@ -555,7 +525,6 @@ class UserStorageDB extends UserStorageBase {
|
|
|
*/
|
|
*/
|
|
|
public function getProfileById($profileID) {
|
|
public function getProfileById($profileID) {
|
|
|
if (!$profileID) return false;
|
|
if (!$profileID) return false;
|
|
|
- $profile = null;
|
|
|
|
|
|
|
|
|
|
$sql_select = array();
|
|
$sql_select = array();
|
|
|
$sql_select[] = "z.`ID`";
|
|
$sql_select[] = "z.`ID`";
|
|
@@ -569,24 +538,26 @@ class UserStorageDB extends UserStorageBase {
|
|
|
$sql_select[] = "a.`ID` as usrId";
|
|
$sql_select[] = "a.`ID` as usrId";
|
|
|
|
|
|
|
|
$sql_select = implode(', ', $sql_select);
|
|
$sql_select = implode(', ', $sql_select);
|
|
|
- $sql = "select {$sql_select}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $r = DB::getPDO()->fetchFirstAsObject("
|
|
|
|
|
+ select {$sql_select}
|
|
|
from `CRM_AUTH_PROFILE` as up
|
|
from `CRM_AUTH_PROFILE` as up
|
|
|
- join `ADMIN_USERS` as a on(a.`ID`=up.`REMOTE_ID` and up.`REMOTE_TABLE`='ADMIN_USERS')
|
|
|
|
|
- join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
|
|
|
|
|
|
|
+ join `ADMIN_USERS` as a on ( a.`ID` = up.`REMOTE_ID` and up.`REMOTE_TABLE` = 'ADMIN_USERS' )
|
|
|
|
|
+ join `CRM_LISTA_ZASOBOW` as z on ( z.`ID` = up.`ID_ZASOB` )
|
|
|
where
|
|
where
|
|
|
- up.`ID`='{$profileID}'
|
|
|
|
|
- and up.`A_STATUS` in('WAITING', 'NORMAL')
|
|
|
|
|
- and z.`TYPE` in('STANOWISKO','DZIAL','PODMIOT')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $profile = new stdClass();
|
|
|
|
|
- $profile->profileId = $r->profileId;
|
|
|
|
|
- $profile->localisationId = $r->localisationId;
|
|
|
|
|
- $profile->usrId = $r->usrId;
|
|
|
|
|
- $profile->usrLogin = $r->usrLogin;
|
|
|
|
|
- $profile->group = $this->_buildGroupFromRow($r);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ up.`ID` = '{$profileID}'
|
|
|
|
|
+ and up.`A_STATUS` in ( 'WAITING', 'NORMAL' )
|
|
|
|
|
+ and z.`TYPE` in ( 'STANOWISKO', 'DZIAL', 'PODMIOT' )
|
|
|
|
|
+ ");
|
|
|
|
|
+
|
|
|
|
|
+ if (!$r) return null;
|
|
|
|
|
+
|
|
|
|
|
+ $profile = new stdClass();
|
|
|
|
|
+ $profile->profileId = $r->profileId;
|
|
|
|
|
+ $profile->localisationId = $r->localisationId;
|
|
|
|
|
+ $profile->usrId = $r->usrId;
|
|
|
|
|
+ $profile->usrLogin = $r->usrLogin;
|
|
|
|
|
+ $profile->group = $this->_buildGroupFromRow($r);
|
|
|
|
|
|
|
|
return $profile;
|
|
return $profile;
|
|
|
}
|
|
}
|
|
@@ -617,27 +588,26 @@ class UserStorageDB extends UserStorageBase {
|
|
|
$sql_select[] = "a.`ID` as usrId";
|
|
$sql_select[] = "a.`ID` as usrId";
|
|
|
|
|
|
|
|
$sql_select = implode(', ', $sql_select);
|
|
$sql_select = implode(', ', $sql_select);
|
|
|
- $sql = "select {$sql_select}
|
|
|
|
|
- from `CRM_AUTH_PROFILE` as up
|
|
|
|
|
- join `ADMIN_USERS` as a on(a.`ID`=up.`REMOTE_ID` and up.`REMOTE_TABLE`='ADMIN_USERS')
|
|
|
|
|
- join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
|
|
|
|
|
- where
|
|
|
|
|
- a.`ADM_ACCOUNT`='{$usrLogin}'
|
|
|
|
|
- and up.`A_STATUS` in('WAITING', 'NORMAL')
|
|
|
|
|
- and z.`TYPE` in('STANOWISKO','DZIAL','PODMIOT')
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- while ($r = $this->_db->fetch($res)) {
|
|
|
|
|
|
|
+ return array_map(function ($item) {
|
|
|
|
|
+ $r = (object)$item;
|
|
|
$profile = new stdClass();
|
|
$profile = new stdClass();
|
|
|
$profile->profileId = $r->profileId;
|
|
$profile->profileId = $r->profileId;
|
|
|
$profile->localisationId = $r->localisationId;
|
|
$profile->localisationId = $r->localisationId;
|
|
|
$profile->usrId = $r->usrId;
|
|
$profile->usrId = $r->usrId;
|
|
|
$profile->usrLogin = $r->usrLogin;
|
|
$profile->usrLogin = $r->usrLogin;
|
|
|
$profile->group = $this->_buildGroupFromRow($r);
|
|
$profile->group = $this->_buildGroupFromRow($r);
|
|
|
- $profiles[] = $profile;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- return $profiles;
|
|
|
|
|
|
|
+ return $profile;
|
|
|
|
|
+ }, DB::getPDO()->fetchAll("
|
|
|
|
|
+ select {$sql_select}
|
|
|
|
|
+ from `CRM_AUTH_PROFILE` as up
|
|
|
|
|
+ join `ADMIN_USERS` as a on ( a.`ID` = up.`REMOTE_ID` and up.`REMOTE_TABLE` = 'ADMIN_USERS' )
|
|
|
|
|
+ join `CRM_LISTA_ZASOBOW` as z on ( z.`ID` = up.`ID_ZASOB` )
|
|
|
|
|
+ where
|
|
|
|
|
+ a.`ADM_ACCOUNT` = '{$usrLogin}'
|
|
|
|
|
+ and up.`A_STATUS` in ( 'WAITING', 'NORMAL' )
|
|
|
|
|
+ and z.`TYPE` in ( 'STANOWISKO', 'DZIAL', 'PODMIOT' )
|
|
|
|
|
+ "));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -645,53 +615,52 @@ class UserStorageDB extends UserStorageBase {
|
|
|
* Only in UserStorageDB
|
|
* Only in UserStorageDB
|
|
|
*/
|
|
*/
|
|
|
public function removeUserGroupByProfileId($usrLogin, $group, $profileID) {
|
|
public function removeUserGroupByProfileId($usrLogin, $group, $profileID) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
if (!$usrLogin || !$profileID || !$group || !$group->zasobID) return false;
|
|
if (!$usrLogin || !$profileID || !$group || !$group->zasobID) return false;
|
|
|
$usrDB = $this->getUser($usrLogin);
|
|
$usrDB = $this->getUser($usrLogin);
|
|
|
if (!$usrDB) return false;
|
|
if (!$usrDB) return false;
|
|
|
|
|
|
|
|
- $sql = "delete from `CRM_AUTH_PROFILE`
|
|
|
|
|
|
|
+ DB::getPDO()->execSql("
|
|
|
|
|
+ delete from `CRM_AUTH_PROFILE`
|
|
|
where
|
|
where
|
|
|
- `ID_ZASOB`='{$group->zasobID}'
|
|
|
|
|
- and `REMOTE_ID`='{$usrDB->primaryKey}'
|
|
|
|
|
- and `REMOTE_TABLE`='ADMIN_USERS'
|
|
|
|
|
- and `ID`='{$profileID}'
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
|
|
+ `ID_ZASOB` = '{$group->zasobID}'
|
|
|
|
|
+ and `REMOTE_ID` = '{$usrDB->primaryKey}'
|
|
|
|
|
+ and `REMOTE_TABLE` = 'ADMIN_USERS'
|
|
|
|
|
+ and `ID` = '{$profileID}'
|
|
|
|
|
+ ");
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setSyncUserDate($usrLogin) {
|
|
public function setSyncUserDate($usrLogin) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
- $sql = "update `ADMIN_USERS` set `A_SYNC_LDAP_DATE`=NOW() where `ADM_ACCOUNT`='{$usrLogin}' ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
|
|
+ DB::getPDO()->execSql("
|
|
|
|
|
+ update `ADMIN_USERS`
|
|
|
|
|
+ set `A_SYNC_LDAP_DATE` = NOW()
|
|
|
|
|
+ where `ADM_ACCOUNT` = '{$usrLogin}'
|
|
|
|
|
+ ");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setSyncGroupDate($idGroup) {
|
|
public function setSyncGroupDate($idGroup) {
|
|
|
- if (!$this->_db) return false;
|
|
|
|
|
if ($idGroup <= 0) return false;
|
|
if ($idGroup <= 0) return false;
|
|
|
- $sql = "update `CRM_LISTA_ZASOBOW` set `A_SYNC_LDAP_DATE`=NOW() where `ID`='{$idGroup}' ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ DB::getPDO()->execSql("
|
|
|
|
|
+ update `CRM_LISTA_ZASOBOW`
|
|
|
|
|
+ set `A_SYNC_LDAP_DATE` = NOW()
|
|
|
|
|
+ where `ID` = '{$idGroup}'
|
|
|
|
|
+ ");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function isPasswordChanged($usrLogin) {
|
|
public function isPasswordChanged($usrLogin) {
|
|
|
- $cnt = 0;
|
|
|
|
|
- $sql = "
|
|
|
|
|
- SELECT
|
|
|
|
|
- -- h.`ADM_PASSWD`,
|
|
|
|
|
- count(1) as cnt
|
|
|
|
|
- FROM `ADMIN_USERS` as u
|
|
|
|
|
- JOIN `ADMIN_USERS_HIST` as h on(h.`ID_USERS2`=u.`ID`)
|
|
|
|
|
- WHERE u.`ADM_ACCOUNT`='{$usrLogin}'
|
|
|
|
|
- AND h.`A_RECORD_CREATE_DATE`>u.`A_SYNC_LDAP_DATE`
|
|
|
|
|
- AND h.`ADM_PASSWD`!='N/S;'
|
|
|
|
|
- AND h.`ADM_PASSWD`!=''
|
|
|
|
|
- -- GROUP BY h.`ADM_PASSWD`
|
|
|
|
|
- ";
|
|
|
|
|
- $res = $this->_db->query($sql);
|
|
|
|
|
- if ($r = $this->_db->fetch($res)) {
|
|
|
|
|
- $cnt = $r->cnt;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $cnt = DB::getPDO()->fetchValue("
|
|
|
|
|
+ SELECT count(1) as cnt
|
|
|
|
|
+ , h.`ADM_PASSWD`
|
|
|
|
|
+ FROM `ADMIN_USERS` as u
|
|
|
|
|
+ JOIN `ADMIN_USERS_HIST` as h on ( h.`ID_USERS2` = u.`ID` )
|
|
|
|
|
+ WHERE u.`ADM_ACCOUNT` = '{$usrLogin}'
|
|
|
|
|
+ AND h.`A_RECORD_CREATE_DATE` > u.`A_SYNC_LDAP_DATE`
|
|
|
|
|
+ AND h.`ADM_PASSWD` != 'N/S;'
|
|
|
|
|
+ AND h.`ADM_PASSWD` != ''
|
|
|
|
|
+ -- GROUP BY h.`ADM_PASSWD`
|
|
|
|
|
+ ");
|
|
|
|
|
+
|
|
|
return ($cnt > 0);
|
|
return ($cnt > 0);
|
|
|
}
|
|
}
|
|
|
|
|
|