- remove global variables

- more documentation
This commit is contained in:
steinm 2010-11-24 15:43:08 +00:00
parent b3a79e21ff
commit 2581f438e4
2 changed files with 753 additions and 789 deletions

View File

@ -21,30 +21,28 @@
| Group-Klasse |
\**********************************************************************/
class LetoDMS_Group
{
class LetoDMS_Group {
var $_id;
var $_name;
var $_dms;
function LetoDMS_Group($id, $name, $comment)
{
function LetoDMS_Group($id, $name, $comment) { /* {{{ */
$this->_id = $id;
$this->_name = $name;
$this->_comment = $comment;
}
$this->_dms = null;
} /* }}} */
function setDMS($dms) {
function setDMS($dms) { /* {{{ */
$this->_dms = $dms;
}
} /* }}} */
function getID() { return $this->_id; }
function getName() { return $this->_name; }
function setName($newName)
{
global $db;
function setName($newName) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblGroups SET name = '" . $newName . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
@ -52,13 +50,12 @@ class LetoDMS_Group
$this->_name = $newName;
return true;
}
} /* }}} */
function getComment() { return $this->_comment; }
function setComment($newComment)
{
global $db;
function setComment($newComment) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblGroups SET comment = '" . $newComment . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
@ -66,14 +63,12 @@ class LetoDMS_Group
$this->_comment = $newComment;
return true;
}
} /* }}} */
function getUsers()
{
global $db;
function getUsers() { /* {{{ */
$db = $this->_dms->getDB();
if (!isset($this->_users))
{
if (!isset($this->_users)) {
$queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
"WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'";
@ -83,18 +78,16 @@ class LetoDMS_Group
$this->_users = array();
foreach ($resArr as $row)
{
foreach ($resArr as $row) {
$user = new LetoDMS_User($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $row["isAdmin"]);
array_push($this->_users, $user);
}
}
return $this->_users;
}
} /* }}} */
function addUser($user,$asManager=false)
{
global $db;
function addUser($user,$asManager=false) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "INSERT INTO tblGroupMembers (groupID, userID, manager) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )";
$res = $db->getResult($queryStr);
@ -103,11 +96,10 @@ class LetoDMS_Group
unset($this->_users);
return true;
}
} /* }}} */
function removeUser($user)
{
global $db;
function removeUser($user) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "DELETE FROM tblGroupMembers WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
$res = $db->getResult($queryStr);
@ -115,21 +107,19 @@ class LetoDMS_Group
if ($res) return false;
unset($this->_users);
return true;
}
} /* }}} */
// $asManager=false: verify if user is in group
// $asManager=true : verify if user is in group as manager
function isMember($user,$asManager=false)
{
if (isset($this->_users)&&!$asManager)
{
function isMember($user,$asManager=false) { /* {{{ */
if (isset($this->_users)&&!$asManager) {
foreach ($this->_users as $usr)
if ($usr->getID() == $user->getID())
return true;
return false;
}
global $db;
$db = $this->_dms->getDB();
if ($asManager) $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID() . " AND manager = 1";
else $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID();
@ -139,11 +129,10 @@ class LetoDMS_Group
if (count($resArr) != 1) return false;
return true;
}
} /* }}} */
function toggleManager($user)
{
global $db;
function toggleManager($user) { /* {{{ */
$db = $this->_dms->getDB();
if (!$this->isMember($user)) return false;
@ -152,7 +141,7 @@ class LetoDMS_Group
if (!$db->getResult($queryStr)) return false;
return true;
}
} /* }}} */
/**
* Entfernt die Gruppe aus dem System.
@ -160,9 +149,9 @@ class LetoDMS_Group
* muss dafür gesorgt werden, dass die Gruppe nirgendwo mehr auftaucht. D.h. auch die Tabellen tblACLs,
* tblNotify und tblGroupMembers müssen berücksichtigt werden.
*/
function remove()
{
GLOBAl $db, $user;
function remove() { /* {{{ */
$db = $this->_dms->getDB();
$user = $this->_dms->user;
$queryStr = "DELETE FROM tblGroups WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
@ -201,10 +190,10 @@ class LetoDMS_Group
}
return true;
}
} /* }}} */
function getReviewStatus($documentID=null, $version=null) {
global $db;
function getReviewStatus($documentID=null, $version=null) { /* {{{ */
$db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttreviewid")) {
return false;
@ -232,10 +221,10 @@ class LetoDMS_Group
$status[] = $res;
}
return $status;
}
} /* }}} */
function getApprovalStatus($documentID=null, $version=null) {
global $db;
function getApprovalStatus($documentID=null, $version=null) { /* {{{ */
$db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttapproveid")) {
return false;
@ -264,6 +253,6 @@ class LetoDMS_Group
}
return $status;
}
} /* }}} */
}
?>

View File

@ -33,9 +33,9 @@ class LetoDMS_User {
var $_comment;
var $_isAdmin;
var $_isHidden;
var $_dms;
function LetoDMS_User($id, $login, $pwd, $fullName, $email, $language, $theme, $comment, $isAdmin, $isHidden=0)
{
function LetoDMS_User($id, $login, $pwd, $fullName, $email, $language, $theme, $comment, $isAdmin, $isHidden=0) {
$this->_id = $id;
$this->_login = $login;
$this->_pwd = $pwd;
@ -46,6 +46,7 @@ class LetoDMS_User {
$this->_comment = $comment;
$this->_isAdmin = $isAdmin;
$this->_isHidden = $isHidden;
$this->_dms = null;
}
function setDMS($dms) {
@ -56,9 +57,8 @@ class LetoDMS_User {
function getLogin() { return $this->_login; }
function setLogin($newLogin)
{
GLOBAL $db;
function setLogin($newLogin) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET login ='" . $newLogin . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -67,13 +67,12 @@ class LetoDMS_User {
$this->_login = $newLogin;
return true;
}
} /* }}} */
function getFullName() { return $this->_fullName; }
function setFullName($newFullName)
{
GLOBAL $db;
function setFullName($newFullName) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET fullname = '" . $newFullName . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -82,13 +81,12 @@ class LetoDMS_User {
$this->_fullName = $newFullName;
return true;
}
} /* }}} */
function getPwd() { return $this->_pwd; }
function setPwd($newPwd)
{
GLOBAL $db;
function setPwd($newPwd) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET pwd ='" . $newPwd . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -97,13 +95,12 @@ class LetoDMS_User {
$this->_pwd = $newPwd;
return true;
}
} /* }}} */
function getEmail() { return $this->_email; }
function setEmail($newEmail)
{
GLOBAL $db;
function setEmail($newEmail) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET email ='" . $newEmail . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -112,13 +109,12 @@ class LetoDMS_User {
$this->_email = $newEmail;
return true;
}
} /* }}} */
function getLanguage() { return $this->_language; }
function setLanguage($newLanguage)
{
GLOBAL $db;
function setLanguage($newLanguage) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET language ='" . $newLanguage . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -127,13 +123,12 @@ class LetoDMS_User {
$this->_language = $newLanguage;
return true;
}
} /* }}} */
function getTheme() { return $this->_theme; }
function setTheme($newTheme)
{
GLOBAL $db;
function setTheme($newTheme) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET theme ='" . $newTheme . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -142,13 +137,12 @@ class LetoDMS_User {
$this->_theme = $newTheme;
return true;
}
} /* }}} */
function getComment() { return $this->_comment; }
function setComment($newComment)
{
GLOBAL $db;
function setComment($newComment) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblUsers SET comment ='" . $newComment . "' WHERE id = " . $this->_id;
$res = $db->getResult($queryStr);
@ -157,13 +151,12 @@ class LetoDMS_User {
$this->_comment = $newComment;
return true;
}
} /* }}} */
function isAdmin() { return $this->_isAdmin; }
function setAdmin($isAdmin)
{
GLOBAL $db;
function setAdmin($isAdmin) { /* {{{ */
$db = $this->_dms->getDB();
$isAdmin = ($isAdmin) ? "1" : "0";
$queryStr = "UPDATE tblUsers SET isAdmin = " . $isAdmin . " WHERE id = " . $this->_id;
@ -172,13 +165,12 @@ class LetoDMS_User {
$this->_isAdmin = $isAdmin;
return true;
}
} /* }}} */
function isHidden() { return $this->_isHidden; }
function setHidden($isHidden)
{
GLOBAL $db;
function setHidden($isHidden) { /* {{{ */
$db = $this->_dms->getDB();
$isHidden = ($isHidden) ? "1" : "0";
$queryStr = "UPDATE tblUsers SET hidden = " . $isHidden . " WHERE id = " . $this->_id;
@ -187,7 +179,7 @@ class LetoDMS_User {
$this->_isHidden = $isAdmin;
return true;
}
} /* }}} */
/**
* Remove the user and also remove all its keywords, notifies, etc.
@ -199,7 +191,8 @@ class LetoDMS_User {
* @return boolean true on success or false in case of an error
*/
function remove( $assignToUser=null ) { /* {{{ */
GLOBAL $db, $user;
$db = $this->_dms->getDB();
$user = $this->_dms->user;
/* Records like folders and documents that formely have belonged to
* the user will assign to another user. If no such user is set,
@ -336,7 +329,7 @@ class LetoDMS_User {
} /* }}} */
function getGroups() { /* {{{ */
GLOBAL $db;
$db = $this->_dms->getDB();
if (!isset($this->_groups))
{
@ -372,9 +365,8 @@ class LetoDMS_User {
* @return boolean true if user has a picture of itself
*/
function hasImage() { /* {{{ */
if (!isset($this->_hasImage))
{
GLOBAL $db;
if (!isset($this->_hasImage)) {
$db = $this->_dms->getDB();
$queryStr = "SELECT COUNT(*) AS num FROM tblUserImages WHERE userID = " . $this->_id;
$resArr = $db->getResultArray($queryStr);
@ -388,20 +380,8 @@ class LetoDMS_User {
return $this->_hasImage;
} /* }}} */
/* FIXME: This function should not be a method of the class but rather
* implemented in the calling application
*/
function getImageURL() { /* {{{ */
GLOBAL $settings;
// if (!$this->hasImage())
// return false;
return $settings->_httpRoot . "out/out.UserImage.php?userid=" . $this->_id;
} /* }}} */
function setImage($tmpfile, $mimeType)
{
GLOBAL $db;
function setImage($tmpfile, $mimeType) { /* {{{ */
$db = $this->_dms->getDB();
$fp = fopen($tmpfile, "rb");
if (!$fp) return false;
@ -417,10 +397,10 @@ class LetoDMS_User {
$this->_hasImage = true;
return true;
}
} /* }}} */
function getReviewStatus($documentID=null, $version=null) {
GLOBAL $db;
function getReviewStatus($documentID=null, $version=null) { /* {{{ */
$db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttreviewid")) {
return false;
@ -470,10 +450,10 @@ class LetoDMS_User {
$status["grpstatus"][] = $res;
}
return $status;
}
} /* }}} */
function getApprovalStatus($documentID=null, $version=null) {
GLOBAL $db;
function getApprovalStatus($documentID=null, $version=null) { /* {{{ */
$db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttapproveid")) {
return false;
@ -523,31 +503,28 @@ class LetoDMS_User {
$status["grpstatus"][] = $res;
}
return $status;
}
} /* }}} */
function getMandatoryReviewers()
{
GLOBAL $db;
function getMandatoryReviewers() { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "SELECT * FROM tblMandatoryReviewers WHERE userID = " . $this->_id;
$resArr = $db->getResultArray($queryStr);
return $resArr;
}
} /* }}} */
function getMandatoryApprovers()
{
GLOBAL $db;
function getMandatoryApprovers() { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "SELECT * FROM tblMandatoryApprovers WHERE userID = " . $this->_id;
$resArr = $db->getResultArray($queryStr);
return $resArr;
}
} /* }}} */
function setMandatoryReviewer($id, $isgroup=false)
{
GLOBAL $db;
function setMandatoryReviewer($id, $isgroup=false) { /* {{{ */
$db = $this->_dms->getDB();
if ($isgroup){
@ -570,11 +547,10 @@ class LetoDMS_User {
if (is_bool($resArr) && !$resArr) return false;
}
}
} /* }}} */
function setMandatoryApprover($id, $isgroup=false)
{
GLOBAL $db;
function setMandatoryApprover($id, $isgroup=false) { /* {{{ */
$db = $this->_dms->getDB();
if ($isgroup){
@ -596,20 +572,19 @@ class LetoDMS_User {
$resArr = $db->getResult($queryStr);
if (is_bool($resArr) && !$resArr) return false;
}
}
} /* }}} */
function delMandatoryReviewers()
{
GLOBAL $db;
function delMandatoryReviewers() { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "DELETE FROM tblMandatoryReviewers WHERE userID = " . $this->_id;
if (!$db->getResult($queryStr)) return false;
}
} /* }}} */
function delMandatoryApprovers() { /* {{{ */
$db = $this->_dms->getDB();
function delMandatoryApprovers()
{
GLOBAL $db;
$queryStr = "DELETE FROM tblMandatoryApprovers WHERE userID = " . $this->_id;
if (!$db->getResult($queryStr)) return false;
}
} /* }}} */
}
?>