- 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

@ -1,269 +1,258 @@
<?php <?php
// MyDMS. Document Management System // MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal // Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe // Copyright (C) 2006-2008 Malcolm Cowe
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// 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.
/**********************************************************************\ /**********************************************************************\
| Group-Klasse | | Group-Klasse |
\**********************************************************************/ \**********************************************************************/
class LetoDMS_Group class LetoDMS_Group {
{ var $_id;
var $_id; var $_name;
var $_name;
var $_dms; var $_dms;
function LetoDMS_Group($id, $name, $comment)
{
$this->_id = $id;
$this->_name = $name;
$this->_comment = $comment;
}
function setDMS($dms) { function LetoDMS_Group($id, $name, $comment) { /* {{{ */
$this->_id = $id;
$this->_name = $name;
$this->_comment = $comment;
$this->_dms = null;
} /* }}} */
function setDMS($dms) { /* {{{ */
$this->_dms = $dms; $this->_dms = $dms;
} } /* }}} */
function getID() { return $this->_id; } function getID() { return $this->_id; }
function getName() { return $this->_name; }
function setName($newName)
{
global $db;
$queryStr = "UPDATE tblGroups SET name = '" . $newName . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_name = $newName;
return true;
}
function getComment() { return $this->_comment; }
function setComment($newComment)
{
global $db;
$queryStr = "UPDATE tblGroups SET comment = '" . $newComment . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_comment = $newComment;
return true;
}
function getUsers()
{
global $db;
if (!isset($this->_users))
{
$queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
"WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'";
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
$this->_users = array();
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;
$queryStr = "INSERT INTO tblGroupMembers (groupID, userID, manager) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )"; function getName() { return $this->_name; }
function setName($newName) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblGroups SET name = '" . $newName . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_name = $newName;
return true;
} /* }}} */
function getComment() { return $this->_comment; }
function setComment($newComment) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblGroups SET comment = '" . $newComment . "' WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_comment = $newComment;
return true;
} /* }}} */
function getUsers() { /* {{{ */
$db = $this->_dms->getDB();
if (!isset($this->_users)) {
$queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
"WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'";
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
$this->_users = array();
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) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "INSERT INTO tblGroupMembers (groupID, userID, manager) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )";
$res = $db->getResult($queryStr); $res = $db->getResult($queryStr);
if ($res) return false; if ($res) return false;
unset($this->_users); unset($this->_users);
return true; return true;
} } /* }}} */
function removeUser($user) function removeUser($user) { /* {{{ */
{ $db = $this->_dms->getDB();
global $db;
$queryStr = "DELETE FROM tblGroupMembers WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
$queryStr = "DELETE FROM tblGroupMembers WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
$res = $db->getResult($queryStr); $res = $db->getResult($queryStr);
if ($res) return false; if ($res) return false;
unset($this->_users); unset($this->_users);
return true; return true;
} } /* }}} */
// $asManager=false: verify if user is in group // $asManager=false: verify if user is in group
// $asManager=true : verify if user is in group as manager // $asManager=true : verify if user is in group as manager
function isMember($user,$asManager=false) function isMember($user,$asManager=false) { /* {{{ */
{ if (isset($this->_users)&&!$asManager) {
if (isset($this->_users)&&!$asManager) foreach ($this->_users as $usr)
{ if ($usr->getID() == $user->getID())
foreach ($this->_users as $usr) return true;
if ($usr->getID() == $user->getID()) return false;
return true; }
return false;
} $db = $this->_dms->getDB();
if ($asManager) $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID() . " AND manager = 1";
global $db;
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(); else $queryStr = "SELECT * FROM tblGroupMembers WHERE groupID = " . $this->_id . " AND userID = " . $user->getID();
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false) return false; if (is_bool($resArr) && $resArr == false) return false;
if (count($resArr) != 1) return false; if (count($resArr) != 1) return false;
return true;
}
function toggleManager($user)
{
global $db;
if (!$this->isMember($user)) return false;
if ($this->isMember($user,true)) $queryStr = "UPDATE tblGroupMembers SET manager = 0 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
else $queryStr = "UPDATE tblGroupMembers SET manager = 1 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
if (!$db->getResult($queryStr)) return false;
return true; return true;
} } /* }}} */
/** function toggleManager($user) { /* {{{ */
* Entfernt die Gruppe aus dem System. $db = $this->_dms->getDB();
* Dies ist jedoch nicht mit einem Löschen des entsprechenden Eintrags aus tblGroups geschehen - vielmehr
* muss dafür gesorgt werden, dass die Gruppe nirgendwo mehr auftaucht. D.h. auch die Tabellen tblACLs, if (!$this->isMember($user)) return false;
* tblNotify und tblGroupMembers müssen berücksichtigt werden.
*/ if ($this->isMember($user,true)) $queryStr = "UPDATE tblGroupMembers SET manager = 0 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
function remove() else $queryStr = "UPDATE tblGroupMembers SET manager = 1 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
{
GLOBAl $db, $user; if (!$db->getResult($queryStr)) return false;
return true;
$queryStr = "DELETE FROM tblGroups WHERE id = " . $this->_id; } /* }}} */
if (!$db->getResult($queryStr))
return false; /**
$queryStr = "DELETE FROM tblGroupMembers WHERE groupID = " . $this->_id; * Entfernt die Gruppe aus dem System.
if (!$db->getResult($queryStr)) * Dies ist jedoch nicht mit einem Löschen des entsprechenden Eintrags aus tblGroups geschehen - vielmehr
return false; * muss dafür gesorgt werden, dass die Gruppe nirgendwo mehr auftaucht. D.h. auch die Tabellen tblACLs,
$queryStr = "DELETE FROM tblACLs WHERE groupID = " . $this->_id; * tblNotify und tblGroupMembers müssen berücksichtigt werden.
if (!$db->getResult($queryStr)) */
return false; function remove() { /* {{{ */
$queryStr = "DELETE FROM tblNotify WHERE groupID = " . $this->_id; $db = $this->_dms->getDB();
if (!$db->getResult($queryStr)) $user = $this->_dms->user;
$queryStr = "DELETE FROM tblGroups WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false; return false;
$queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerGroupID = " . $this->_id; $queryStr = "DELETE FROM tblGroupMembers WHERE groupID = " . $this->_id;
if (!$db->getResult($queryStr)) if (!$db->getResult($queryStr))
return false;
$queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverGroupID = " . $this->_id;
if (!$db->getResult($queryStr))
return false; return false;
$queryStr = "DELETE FROM tblACLs WHERE groupID = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$queryStr = "DELETE FROM tblNotify WHERE groupID = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$queryStr = "DELETE FROM tblMandatoryReviewers WHERE reviewerGroupID = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$queryStr = "DELETE FROM tblMandatoryApprovers WHERE approverGroupID = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
// TODO : update document status if reviewer/approver has been deleted // TODO : update document status if reviewer/approver has been deleted
$reviewStatus = $this->getReviewStatus(); $reviewStatus = $this->getReviewStatus();
foreach ($reviewStatus as $r) { foreach ($reviewStatus as $r) {
$queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ". $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $r["reviewID"] ."', '-2', 'Review group removed from process', NOW(), '". $user->getID() ."')"; "VALUES ('". $r["reviewID"] ."', '-2', 'Review group removed from process', NOW(), '". $user->getID() ."')";
$res=$db->getResult($queryStr); $res=$db->getResult($queryStr);
} }
$approvalStatus = $this->getApprovalStatus(); $approvalStatus = $this->getApprovalStatus();
foreach ($approvalStatus as $a) { foreach ($approvalStatus as $a) {
$queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ". $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $a["approveID"] ."', '-2', 'Approval group removed from process', NOW(), '". $user->getID() ."')"; "VALUES ('". $a["approveID"] ."', '-2', 'Approval group removed from process', NOW(), '". $user->getID() ."')";
$res=$db->getResult($queryStr); $res=$db->getResult($queryStr);
} }
return true; return true;
} } /* }}} */
function getReviewStatus($documentID=null, $version=null) { function getReviewStatus($documentID=null, $version=null) { /* {{{ */
global $db; $db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttreviewid")) { if (!$db->createTemporaryTable("ttreviewid")) {
return false; return false;
} }
$status = array(); $status = array();
// See if the group is assigned as a reviewer. // See if the group is assigned as a reviewer.
$queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ". $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ".
"`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ". "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ".
"`tblDocumentReviewLog`.`userID` ". "`tblDocumentReviewLog`.`userID` ".
"FROM `tblDocumentReviewers` ". "FROM `tblDocumentReviewers` ".
"LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ". "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ".
"LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ". "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ".
"WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ". "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ".
($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' "). ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". $documentID ."' ").
($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' "). ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". $version ."' ").
"AND `tblDocumentReviewers`.`type`='1' ". "AND `tblDocumentReviewers`.`type`='1' ".
"AND `tblDocumentReviewers`.`required`='". $this->_id ."' "; "AND `tblDocumentReviewers`.`required`='". $this->_id ."' ";
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false) if (is_bool($resArr) && $resArr == false)
return false; return false;
if (count($resArr)>0) { if (count($resArr)>0) {
foreach ($resArr as $res) foreach ($resArr as $res)
$status[] = $res; $status[] = $res;
} }
return $status; return $status;
} } /* }}} */
function getApprovalStatus($documentID=null, $version=null) { function getApprovalStatus($documentID=null, $version=null) { /* {{{ */
global $db; $db = $this->_dms->getDB();
if (!$db->createTemporaryTable("ttapproveid")) { if (!$db->createTemporaryTable("ttapproveid")) {
return false; return false;
} }
$status = array(); $status = array();
// See if the group is assigned as an approver. // See if the group is assigned as an approver.
$queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ". $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ".
"`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ". "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ".
"`tblDocumentApproveLog`.`userID` ". "`tblDocumentApproveLog`.`userID` ".
"FROM `tblDocumentApprovers` ". "FROM `tblDocumentApprovers` ".
"LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ". "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ".
"LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ". "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ".
"WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ". "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ".
($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' "). ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". $documentID ."' ").
($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' "). ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". $version ."' ").
"AND `tblDocumentApprovers`.`type`='1' ". "AND `tblDocumentApprovers`.`type`='1' ".
"AND `tblDocumentApprovers`.`required`='". $this->_id ."' "; "AND `tblDocumentApprovers`.`required`='". $this->_id ."' ";
$resArr = $db->getResultArray($queryStr); $resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false) if (is_bool($resArr) && $resArr == false)
return false; return false;
if (count($resArr)>0) { if (count($resArr)>0) {
foreach ($resArr as $res) foreach ($resArr as $res)
$status[] = $res; $status[] = $res;
} }
return $status; return $status;
} } /* }}} */
} }
?> ?>

File diff suppressed because it is too large Load Diff