- lots of documentation

- replace more global variables
This commit is contained in:
steinm 2010-11-16 09:10:39 +00:00
parent 2c99342376
commit 181c2c7e50

View File

@ -18,12 +18,16 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/**********************************************************************\ /**
| Folder-Klasse | * Class to represent the complete document management
\**********************************************************************/ *
* @category DMS
class LetoDMS_Folder * @package LetoDMS
{ * @author Markus Westphal, Malcolm Cowe, Matteo Lucarelli, Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, 2010 Uwe Steinmann
* @version Release: @package_version@
*/
class LetoDMS_Folder {
var $_id; var $_id;
var $_name; var $_name;
var $_parentID; var $_parentID;
@ -35,8 +39,7 @@ class LetoDMS_Folder
var $_notifier; var $_notifier;
var $_dms; var $_dms;
function LetoDMS_Folder($id, $name, $parentID, $comment, $ownerID, $inheritAccess, $defaultAccess, $sequence) function LetoDMS_Folder($id, $name, $parentID, $comment, $ownerID, $inheritAccess, $defaultAccess, $sequence) { /* {{{ */
{
$this->_id = $id; $this->_id = $id;
$this->_name = $name; $this->_name = $name;
$this->_parentID = $parentID; $this->_parentID = $parentID;
@ -47,18 +50,47 @@ class LetoDMS_Folder
$this->_sequence = $sequence; $this->_sequence = $sequence;
$this->_notifier = null; $this->_notifier = null;
$this->_dms = null; $this->_dms = null;
} } /* }}} */
function setDMS($dms) { /*
* Set dms this folder belongs to.
*
* Each folder needs a reference to the dms it belongs to. It will be
* set when the folder is created by LetoDMS::getFolder(). The dms has a
* references to the currently logged in user and the database connection.
*
* @param object $dms reference to dms
*/
function setDMS($dms) { /* {{{ */
$this->_dms = $dms; $this->_dms = $dms;
} /* }}} */
function setNotifier($notifier) {
$this->_notifier = $notifier;
} }
/*
* Get the internal id of the folder.
*
* @return integer id of folder
*/
function getID() { return $this->_id; } function getID() { return $this->_id; }
/*
* Get the name of the folder.
*
* @return string name of folder
*/
function getName() { return $this->_name; } function getName() { return $this->_name; }
function setName($newName) { /*
GLOBAL $db, $user; * Set the name of the folder.
*
* @param string $newName set a new name of the folder
*/
function setName($newName) { /* {{{ */
GLOBAL $user;
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblFolders SET name = '" . $newName . "' WHERE id = ". $this->_id; $queryStr = "UPDATE tblFolders SET name = '" . $newName . "' WHERE id = ". $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
@ -88,12 +120,13 @@ class LetoDMS_Folder
$this->_name = $newName; $this->_name = $newName;
return true; return true;
} } /* }}} */
function getComment() { return $this->_comment; } function getComment() { return $this->_comment; }
function setComment($newComment) { function setComment($newComment) { /* {{{ */
GLOBAL $db, $user; GLOBAL $user;
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblFolders SET comment = '" . $newComment . "' WHERE id = ". $this->_id; $queryStr = "UPDATE tblFolders SET comment = '" . $newComment . "' WHERE id = ". $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
@ -121,13 +154,10 @@ class LetoDMS_Folder
$this->_comment = $newComment; $this->_comment = $newComment;
return true; return true;
} } /* }}} */
function getParent() function getParent() { /* {{{ */
{ if ($this->_id == $this->_dms->rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) {
global $settings;
if ($this->_id == $settings->_rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) {
return false; return false;
} }
@ -135,12 +165,13 @@ class LetoDMS_Folder
$this->_parent = $this->_dms->getFolder($this->_parentID); $this->_parent = $this->_dms->getFolder($this->_parentID);
} }
return $this->_parent; return $this->_parent;
} } /* }}} */
function setParent($newParent) { function setParent($newParent) { /* {{{ */
global $db, $user, $settings; global $user;
$db = $this->_dms->getDB();
if ($this->_id == $settings->_rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) { if ($this->_id == $this->_dms->rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) {
return false; return false;
} }
@ -194,17 +225,17 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
function getOwner() function getOwner() { /* {{{ */
{
if (!isset($this->_owner)) if (!isset($this->_owner))
$this->_owner = $this->_dms->getUser($this->_ownerID); $this->_owner = $this->_dms->getUser($this->_ownerID);
return $this->_owner; return $this->_owner;
} } /* }}} */
function setOwner($newOwner) { function setOwner($newOwner) { /* {{{ */
GLOBAL $db, $user; GLOBAL $user;
$db = $this->_dms->getDB();
$oldOwner = $this->getOwner(); $oldOwner = $this->getOwner();
@ -237,22 +268,21 @@ class LetoDMS_Folder
$this->_ownerID = $newOwner->getID(); $this->_ownerID = $newOwner->getID();
$this->_owner = $newOwner; $this->_owner = $newOwner;
return true; return true;
} } /* }}} */
function getDefaultAccess() function getDefaultAccess() { /* {{{ */
{ if ($this->inheritsAccess()) {
if ($this->inheritsAccess())
{
$res = $this->getParent(); $res = $this->getParent();
if (!$res) return false; if (!$res) return false;
return $this->_parent->getDefaultAccess(); return $this->_parent->getDefaultAccess();
} }
return $this->_defaultAccess; return $this->_defaultAccess;
} } /* }}} */
function setDefaultAccess($mode) { function setDefaultAccess($mode) { /* {{{ */
GLOBAL $db, $user; GLOBAL $user;
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblFolders set defaultAccess = " . $mode . " WHERE id = " . $this->_id; $queryStr = "UPDATE tblFolders set defaultAccess = " . $mode . " WHERE id = " . $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
@ -293,12 +323,13 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
function inheritsAccess() { return $this->_inheritAccess; } function inheritsAccess() { return $this->_inheritAccess; }
function setInheritAccess($inheritAccess) { function setInheritAccess($inheritAccess) { /* {{{ */
GLOBAL $db, $user; GLOBAL $user;
$db = $this->_dms->getDB();
$inheritAccess = ($inheritAccess) ? "1" : "0"; $inheritAccess = ($inheritAccess) ? "1" : "0";
@ -341,13 +372,12 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
function getSequence() { return $this->_sequence; } function getSequence() { return $this->_sequence; }
function setSequence($seq) function setSequence($seq) { /* {{{ */
{ $db = $this->_dms->getDB();
GLOBAL $db;
$queryStr = "UPDATE tblFolders SET sequence = " . $seq . " WHERE id = " . $this->_id; $queryStr = "UPDATE tblFolders SET sequence = " . $seq . " WHERE id = " . $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
@ -355,13 +385,12 @@ class LetoDMS_Folder
$this->_sequence = $seq; $this->_sequence = $seq;
return true; return true;
} } /* }}} */
function getSubFolders($orderby="") { function getSubFolders($orderby="") { /* {{{ */
GLOBAL $db; $db = $this->_dms->getDB();
if (!isset($this->_subFolders)) if (!isset($this->_subFolders)) {
{
if ($orderby=="n") $queryStr = "SELECT * FROM tblFolders WHERE parent = " . $this->_id . " ORDER BY name"; if ($orderby=="n") $queryStr = "SELECT * FROM tblFolders WHERE parent = " . $this->_id . " ORDER BY name";
else $queryStr = "SELECT * FROM tblFolders WHERE parent = " . $this->_id . " ORDER BY sequence"; else $queryStr = "SELECT * FROM tblFolders WHERE parent = " . $this->_id . " ORDER BY sequence";
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
@ -375,10 +404,11 @@ class LetoDMS_Folder
} }
return $this->_subFolders; return $this->_subFolders;
} } /* }}} */
function addSubFolder($name, $comment, $owner, $sequence) { function addSubFolder($name, $comment, $owner, $sequence) { /* {{{ */
GLOBAL $db, $user; GLOBAL $user;
$db = $this->_dms->getDB();
//inheritAccess = true, defaultAccess = M_READ //inheritAccess = true, defaultAccess = M_READ
$queryStr = "INSERT INTO tblFolders (name, parent, comment, owner, inheritAccess, defaultAccess, sequence) ". $queryStr = "INSERT INTO tblFolders (name, parent, comment, owner, inheritAccess, defaultAccess, sequence) ".
@ -410,13 +440,15 @@ class LetoDMS_Folder
} }
return $newFolder; return $newFolder;
} } /* }}} */
/** /*
* Gibt ein Array mit allen Eltern, "Großelter" usw bis zum RootFolder zurück * Returns a array of all parents, grand parent, etc. up to root folder.
* Der Ordner selbst ist das letzte Element dieses Arrays * The folder itself is the last element of the array.
*
* @return array Array of parents
*/ */
function getPath() { function getPath() { /* {{{ */
if (!isset($this->_parentID) || ($this->_parentID == "") || ($this->_parentID == 0)) { if (!isset($this->_parentID) || ($this->_parentID == "") || ($this->_parentID == 0)) {
return array($this); return array($this);
} }
@ -430,9 +462,9 @@ class LetoDMS_Folder
array_push($path, $this); array_push($path, $this);
return $path; return $path;
} }
} } /* }}} */
function getFolderPathHTML($tagAll=false) { function getFolderPathHTML($tagAll=false) { /* {{{ */
$path = $this->getPath(); $path = $this->getPath();
$txtpath = ""; $txtpath = "";
for ($i = 0; $i < count($path); $i++) { for ($i = 0; $i < count($path); $i++) {
@ -446,9 +478,9 @@ class LetoDMS_Folder
} }
} }
return $txtpath; return $txtpath;
} } /* }}} */
function getFolderPathPlain() { function getFolderPathPlain() { /* {{{ */
$path=""; $path="";
$folderPath = $this->getPath(); $folderPath = $this->getPath();
for ($i = 0; $i < count($folderPath); $i++) { for ($i = 0; $i < count($folderPath); $i++) {
@ -457,33 +489,27 @@ class LetoDMS_Folder
$path .= " / "; $path .= " / ";
} }
return $path; return $path;
} } /* }}} */
/** /**
* Überprüft, ob dieser Ordner ein Unterordner von $folder ist * Überprüft, ob dieser Ordner ein Unterordner von $folder ist
*/ */
function isDescendant($folder) function isDescendant($folder) { /* {{{ */
{
if ($this->_parentID == $folder->getID()) if ($this->_parentID == $folder->getID())
return true; return true;
else if (isset($this->_parentID)) elseif (isset($this->_parentID)) {
{
$res = $this->getParent(); $res = $this->getParent();
if (!$res) return false; if (!$res) return false;
return $this->_parent->isDescendant($folder); return $this->_parent->isDescendant($folder);
} } else
else
return false; return false;
} } /* }}} */
function getDocuments($orderby="") function getDocuments($orderby="") { /* {{{ */
{ $db = $this->_dms->getDB();
GLOBAL $db;
if (!isset($this->_documents))
{
if (!isset($this->_documents)) {
if ($orderby=="n") $queryStr = "SELECT * FROM tblDocuments WHERE folder = " . $this->_id . " ORDER BY name"; if ($orderby=="n") $queryStr = "SELECT * FROM tblDocuments WHERE folder = " . $this->_id . " ORDER BY name";
else $queryStr = "SELECT * FROM tblDocuments WHERE folder = " . $this->_id . " ORDER BY sequence"; else $queryStr = "SELECT * FROM tblDocuments WHERE folder = " . $this->_id . " ORDER BY sequence";
@ -498,12 +524,12 @@ class LetoDMS_Folder
} }
} }
return $this->_documents; return $this->_documents;
} } /* }}} */
// $comment will be used for both document and version leaving empty the version_comment // $comment will be used for both document and version leaving empty the version_comment
function addDocument($name, $comment, $expires, $owner, $keywords, $tmpFile, $orgFileName, $fileType, $mimeType, $sequence, $reviewers=array(), $approvers=array(),$reqversion,$version_comment="") function addDocument($name, $comment, $expires, $owner, $keywords, $tmpFile, $orgFileName, $fileType, $mimeType, $sequence, $reviewers=array(), $approvers=array(),$reqversion,$version_comment="") { /* {{{ */
{ GLOBAL $user;
GLOBAL $db, $user; $db = $this->_dms->getDB();
$expires = (!$expires) ? 0 : $expires; $expires = (!$expires) ? 0 : $expires;
@ -528,8 +554,7 @@ class LetoDMS_Folder
$res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion,FALSE); $res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion,FALSE);
else $res = $document->addContent($comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion,FALSE); else $res = $document->addContent($comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers,$reqversion,FALSE);
if (is_bool($res) && !$res) if (is_bool($res) && !$res) {
{
$queryStr = "DELETE FROM tblDocuments WHERE id = " . $document->getID(); $queryStr = "DELETE FROM tblDocuments WHERE id = " . $document->getID();
$db->getResult($queryStr); $db->getResult($queryStr);
return false; return false;
@ -557,14 +582,14 @@ class LetoDMS_Folder
} }
return array($document, $res); return array($document, $res);
} } /* }}} */
function remove($send_email=TRUE) { /* {{{ */
function remove($send_email=TRUE) { global $user;
global $db, $user, $settings; $db = $this->_dms->getDB();
// Do not delete the root folder. // Do not delete the root folder.
if ($this->_id == $settings->_rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) { if ($this->_id == $this->_dms->rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) {
return false; return false;
} }
@ -574,14 +599,12 @@ class LetoDMS_Folder
$res = $this->getDocuments(); $res = $this->getDocuments();
if (is_bool($res) && !$res) return false; if (is_bool($res) && !$res) return false;
foreach ($this->_subFolders as $subFolder) foreach ($this->_subFolders as $subFolder) {
{
$res = $subFolder->remove(FALSE); $res = $subFolder->remove(FALSE);
if (!$res) return false; if (!$res) return false;
} }
foreach ($this->_documents as $document) foreach ($this->_documents as $document) {
{
$res = $document->remove(FALSE); $res = $document->remove(FALSE);
if (!$res) return false; if (!$res) return false;
} }
@ -595,7 +618,7 @@ class LetoDMS_Folder
return false; return false;
// Send notification to subscribers. // Send notification to subscribers.
if ($send_email && $this->_notifier){ if ($send_email && $this->_notifier) {
$this->getNotifyList(); $this->getNotifyList();
$subject = "###SITENAME###: ".$this->_name." - ".getMLText("folder_deleted_email"); $subject = "###SITENAME###: ".$this->_name." - ".getMLText("folder_deleted_email");
@ -620,22 +643,18 @@ class LetoDMS_Folder
return false; return false;
return true; return true;
} } /* }}} */
function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */
$db = $this->_dms->getDB();
function getAccessList($mode = M_ANY, $op = O_EQ) if ($this->inheritsAccess()) {
{
GLOBAL $db;
if ($this->inheritsAccess())
{
$res = $this->getParent(); $res = $this->getParent();
if (!$res) return false; if (!$res) return false;
return $this->_parent->getAccessList($mode, $op); return $this->_parent->getAccessList($mode, $op);
} }
if (!isset($this->_accessList[$mode])) if (!isset($this->_accessList[$mode])) {
{
if ($op!=O_GTEQ && $op!=O_LTEQ && $op!=O_EQ) { if ($op!=O_GTEQ && $op!=O_LTEQ && $op!=O_EQ) {
return false; return false;
} }
@ -650,8 +669,7 @@ class LetoDMS_Folder
return false; return false;
$this->_accessList[$mode] = array("groups" => array(), "users" => array()); $this->_accessList[$mode] = array("groups" => array(), "users" => array());
foreach ($resArr as $row) foreach ($resArr as $row) {
{
if ($row["userID"] != -1) if ($row["userID"] != -1)
array_push($this->_accessList[$mode]["users"], new LetoDMS_UserAccess($row["userID"], $row["mode"])); array_push($this->_accessList[$mode]["users"], new LetoDMS_UserAccess($row["userID"], $row["mode"]));
else //if ($row["groupID"] != -1) else //if ($row["groupID"] != -1)
@ -660,11 +678,10 @@ class LetoDMS_Folder
} }
return $this->_accessList[$mode]; return $this->_accessList[$mode];
} } /* }}} */
function clearAccessList() function clearAccessList() { /* {{{ */
{ $db = $this->_dms->getDB();
GLOBAL $db;
$queryStr = "DELETE FROM tblACLs WHERE targetType = " . T_FOLDER . " AND target = " . $this->_id; $queryStr = "DELETE FROM tblACLs WHERE targetType = " . T_FOLDER . " AND target = " . $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
@ -672,10 +689,10 @@ class LetoDMS_Folder
unset($this->_accessList); unset($this->_accessList);
return true; return true;
} } /* }}} */
function addAccess($mode, $userOrGroupID, $isUser) { function addAccess($mode, $userOrGroupID, $isUser) { /* {{{ */
GLOBAL $db; $db = $this->_dms->getDB();
$userOrGroup = ($isUser) ? "userID" : "groupID"; $userOrGroup = ($isUser) ? "userID" : "groupID";
@ -692,10 +709,10 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
function changeAccess($newMode, $userOrGroupID, $isUser) { function changeAccess($newMode, $userOrGroupID, $isUser) { /* {{{ */
GLOBAL $db; $db = $this->_dms->getDB();
$userOrGroup = ($isUser) ? "userID" : "groupID"; $userOrGroup = ($isUser) ? "userID" : "groupID";
@ -711,10 +728,10 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
function removeAccess($userOrGroupID, $isUser) { function removeAccess($userOrGroupID, $isUser) { /* {{{ */
GLOBAL $db; $db = $this->_dms->getDB();
$userOrGroup = ($isUser) ? "userID" : "groupID"; $userOrGroup = ($isUser) ? "userID" : "groupID";
@ -731,7 +748,7 @@ class LetoDMS_Folder
} }
return true; return true;
} } /* }}} */
/* /*
* Liefert die Art der Zugriffsberechtigung für den User $user; Mögliche Rechte: n (keine), r (lesen), w (schreiben+lesen), a (alles) * Liefert die Art der Zugriffsberechtigung für den User $user; Mögliche Rechte: n (keine), r (lesen), w (schreiben+lesen), a (alles)
@ -740,19 +757,15 @@ class LetoDMS_Folder
* Wird bei den ACLs nicht gefunden, wird die Standard-Berechtigung zurückgegeben. * Wird bei den ACLs nicht gefunden, wird die Standard-Berechtigung zurückgegeben.
* Ach ja: handelt es sich bei $user um den Besitzer ist die Berechtigung automatisch "a". * Ach ja: handelt es sich bei $user um den Besitzer ist die Berechtigung automatisch "a".
*/ */
function getAccessMode($user) function getAccessMode($user) { /* {{{ */
{ /* Admins have full access */
GLOBAL $settings;
//Admin??
if ($user->isAdmin()) return M_ALL; if ($user->isAdmin()) return M_ALL;
//Besitzer ?? /* User has full access if he/she is the owner of the document */
if ($user->getID() == $this->_ownerID) return M_ALL; if ($user->getID() == $this->_ownerID) return M_ALL;
//Gast-Benutzer?? /* Guest has read access by default, if guest login is allowed at all */
if (($user->getID() == $settings->_guestID) && ($settings->_enableGuestLogin)) if (($user->getID() == $this->_dms->guestID) && ($this->_dms->enableGuestLogin)) {
{
$mode = $this->getDefaultAccess(); $mode = $this->getDefaultAccess();
if ($mode >= M_READ) return M_READ; if ($mode >= M_READ) return M_READ;
else return M_NONE; else return M_NONE;
@ -773,28 +786,24 @@ class LetoDMS_Folder
} }
*/ */
//ACLs durchforsten /* check ACLs */
$accessList = $this->getAccessList(); $accessList = $this->getAccessList();
if (!$accessList) return false; if (!$accessList) return false;
foreach ($accessList["users"] as $userAccess) foreach ($accessList["users"] as $userAccess) {
{ if ($userAccess->getUserID() == $user->getID()) {
if ($userAccess->getUserID() == $user->getID())
{
return $userAccess->getMode(); return $userAccess->getMode();
} }
} }
foreach ($accessList["groups"] as $groupAccess) foreach ($accessList["groups"] as $groupAccess) {
{ if ($user->isMemberOfGroup($groupAccess->getGroup())) {
if ($user->isMemberOfGroup($groupAccess->getGroup()))
{
return $groupAccess->getMode(); return $groupAccess->getMode();
} }
} }
return $this->getDefaultAccess(); return $this->getDefaultAccess();
} } /* }}} */
function getGroupAccessMode($group) { function getGroupAccessMode($group) { /* {{{ */
$highestPrivileged = M_NONE; $highestPrivileged = M_NONE;
$foundInACL = false; $foundInACL = false;
@ -816,13 +825,11 @@ class LetoDMS_Folder
//Standard-Berechtigung verwenden //Standard-Berechtigung verwenden
return $this->getDefaultAccess(); return $this->getDefaultAccess();
} } /* }}} */
function getNotifyList() function getNotifyList() { /* {{{ */
{ if (!isset($this->_notifyList)) {
if (!isset($this->_notifyList)) $db = $this->_dms->getDB();
{
GLOBAL $db;
$queryStr ="SELECT * FROM tblNotify WHERE targetType = " . T_FOLDER . " AND target = " . $this->_id; $queryStr ="SELECT * FROM tblNotify WHERE targetType = " . T_FOLDER . " AND target = " . $this->_id;
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
@ -839,34 +846,36 @@ class LetoDMS_Folder
} }
} }
return $this->_notifyList; return $this->_notifyList;
} } /* }}} */
function addNotify($userOrGroupID, $isUser) { /*
* Adds notify for a user or group to folder
// Return values: *
// -1: Invalid User/Group ID. * @param integer $userOrGroupID
// -2: Target User / Group does not have read access. * @param boolean $isUser true if $userOrGroupID is a user id otherwise false
// -3: User is already subscribed. * @return integer error code
// -4: Database / internal error. * -1: Invalid User/Group ID.
// 0: Update successful. * -2: Target User / Group does not have read access.
* -3: User is already subscribed.
GLOBAL $db, $settings, $user; * -4: Database / internal error.
* 0: Update successful.
*/
function addNotify($userOrGroupID, $isUser) { /* {{{ */
GLOBAL $user;
$db = $this->_dms->getDB();
$userOrGroup = ($isUser) ? "userID" : "groupID"; $userOrGroup = ($isUser) ? "userID" : "groupID";
// /* Verify that user / group exists */
// Verify that user / group exists.
//
$obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID)); $obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID));
if (!is_object($obj)) { if (!is_object($obj)) {
return -1; return -1;
} }
// /* Verify that the requesting user has permission to add the target to
// Verify that the requesting user has permission to add the target to * the notification system.
// the notification system. */
// if ($user->getID() == $this->_dms->guestID) {
if ($user->getID() == $settings->_guestID) {
return -2; return -2;
} }
if (!$user->isAdmin()) { if (!$user->isAdmin()) {
@ -975,21 +984,24 @@ class LetoDMS_Folder
unset($this->_notifyList); unset($this->_notifyList);
return 0; return 0;
} } /* }}} */
function removeNotify($userOrGroupID, $isUser) { /*
* Removes notify for a user or group to folder
*
* @param integer $userOrGroupID
* @param boolean $isUser true if $userOrGroupID is a user id otherwise false
* @return integer error code
* -1: Invalid User/Group ID.
* -3: User is not subscribed.
* -4: Database / internal error.
* 0: Update successful.
*/
function removeNotify($userOrGroupID, $isUser) { /* {{{ */
GLOBAL $user;
$db = $this->_dms->getDB();
// Return values: /* Verify that user / group exists. */
// -1: Invalid User/Group ID.
// -3: User is not subscribed. No action taken.
// -4: Database / internal error.
// 0: Update successful.
GLOBAL $db, $settings, $user;
//
// Verify that user / group exists.
//
$obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID)); $obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID));
if (!is_object($obj)) { if (!is_object($obj)) {
return -1; return -1;
@ -997,11 +1009,10 @@ class LetoDMS_Folder
$userOrGroup = ($isUser) ? "userID" : "groupID"; $userOrGroup = ($isUser) ? "userID" : "groupID";
// /* Verify that the requesting user has permission to add the target to
// Verify that the requesting user has permission to add the target to * the notification system.
// the notification system. */
// if ($user->getID() == $this->_dms->guestID) {
if ($user->getID() == $settings->_guestID) {
return -2; return -2;
} }
if (!$user->isAdmin()) { if (!$user->isAdmin()) {
@ -1065,10 +1076,10 @@ class LetoDMS_Folder
unset($this->_notifyList); unset($this->_notifyList);
return 0; return 0;
} } /* }}} */
function getApproversList() { function getApproversList() { /* {{{ */
GLOBAL $db, $settings; $db = $this->_dms->getDB();
if (!isset($this->_approversList)) { if (!isset($this->_approversList)) {
$this->_approversList = array("groups" => array(), "users" => array()); $this->_approversList = array("groups" => array(), "users" => array());
@ -1090,7 +1101,7 @@ class LetoDMS_Folder
$groupIDs .= (strlen($groupIDs)==0 ? "" : ", ") . $group->getGroupID(); $groupIDs .= (strlen($groupIDs)==0 ? "" : ", ") . $group->getGroupID();
} }
foreach ($tmpList["users"] as $user) { foreach ($tmpList["users"] as $user) {
if ($user->getUserID()!=$settings->_guestID) { if ($user->getUserID()!=$this->_dms->guestID) {
$userIDs .= (strlen($userIDs)==0 ? "" : ", ") . $user->getUserID(); $userIDs .= (strlen($userIDs)==0 ? "" : ", ") . $user->getUserID();
} }
} }
@ -1105,11 +1116,11 @@ class LetoDMS_Folder
$queryStr = "(SELECT `tblUsers`.* FROM `tblUsers` ". $queryStr = "(SELECT `tblUsers`.* FROM `tblUsers` ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ". "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
"WHERE `tblGroupMembers`.`groupID` IN (". $groupIDs .") ". "WHERE `tblGroupMembers`.`groupID` IN (". $groupIDs .") ".
"AND `tblUsers`.`id` !='".$settings->_guestID."')"; "AND `tblUsers`.`id` !='".$this->_dms->guestID."')";
} }
$queryStr .= (strlen($queryStr)==0 ? "" : " UNION "). $queryStr .= (strlen($queryStr)==0 ? "" : " UNION ").
"(SELECT `tblUsers`.* FROM `tblUsers` ". "(SELECT `tblUsers`.* FROM `tblUsers` ".
"WHERE (`tblUsers`.`id` !='".$settings->_guestID."') ". "WHERE (`tblUsers`.`id` !='".$this->_dms->guestID."') ".
"AND ((`tblUsers`.`id` = ". $this->_ownerID . ") ". "AND ((`tblUsers`.`id` = ". $this->_ownerID . ") ".
"OR (`tblUsers`.`isAdmin` = 1)". "OR (`tblUsers`.`isAdmin` = 1)".
(strlen($userIDs) == 0 ? "" : " OR (`tblUsers`.`id` IN (". $userIDs ."))"). (strlen($userIDs) == 0 ? "" : " OR (`tblUsers`.`id` IN (". $userIDs ."))").
@ -1120,7 +1131,7 @@ class LetoDMS_Folder
$queryStr = "(SELECT `tblUsers`.* FROM `tblUsers` ". $queryStr = "(SELECT `tblUsers`.* FROM `tblUsers` ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ". "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
"WHERE `tblGroupMembers`.`groupID` NOT IN (". $groupIDs .")". "WHERE `tblGroupMembers`.`groupID` NOT IN (". $groupIDs .")".
"AND `tblUsers`.`id` != '".$settings->_guestID."' ". "AND `tblUsers`.`id` != '".$this->_dms->guestID."' ".
(strlen($userIDs) == 0 ? ")" : " AND (`tblUsers`.`id` NOT IN (". $userIDs .")))"); (strlen($userIDs) == 0 ? ")" : " AND (`tblUsers`.`id` NOT IN (". $userIDs .")))");
} }
$queryStr .= (strlen($queryStr)==0 ? "" : " UNION "). $queryStr .= (strlen($queryStr)==0 ? "" : " UNION ").
@ -1129,14 +1140,14 @@ class LetoDMS_Folder
"OR (`tblUsers`.`isAdmin` = 1))". "OR (`tblUsers`.`isAdmin` = 1))".
"UNION ". "UNION ".
"(SELECT `tblUsers`.* FROM `tblUsers` ". "(SELECT `tblUsers`.* FROM `tblUsers` ".
"WHERE `tblUsers`.`id` != '".$settings->_guestID."' ". "WHERE `tblUsers`.`id` != '".$this->_dms->guestID."' ".
(strlen($userIDs) == 0 ? ")" : " AND (`tblUsers`.`id` NOT IN (". $userIDs .")))"). (strlen($userIDs) == 0 ? ")" : " AND (`tblUsers`.`id` NOT IN (". $userIDs .")))").
" ORDER BY `login`"; " ORDER BY `login`";
} }
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (!is_bool($resArr)) { if (!is_bool($resArr)) {
foreach ($resArr as $row) { foreach ($resArr as $row) {
if ((!$settings->_enableAdminRevApp) && ($row["id"]==$settings->_adminID)) continue; if ((!$this->_dms->enableAdminRevApp) && ($row["id"]==$this->_dms->adminID)) continue;
$this->_approversList["users"][] = new LetoDMS_User($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $row["isAdmin"]); $this->_approversList["users"][] = new LetoDMS_User($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $row["isAdmin"]);
} }
} }
@ -1168,7 +1179,7 @@ class LetoDMS_Folder
} }
} }
return $this->_approversList; return $this->_approversList;
} } /* }}} */
} }
?> ?>