2010-11-18 13:53:26 +00:00
< ? php
2010-12-06 20:00:18 +00:00
/**
* Implementation of a document in the document management system
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-12-06 20:00:18 +00:00
* @ license GPL2
* @ 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 @
*/
2010-11-18 13:53:26 +00:00
2010-12-06 20:00:18 +00:00
/**
* The different states a document can be in
*/
2012-10-23 09:16:38 +00:00
/*
* Document is in review state . A document is in review state when
* it needs to be reviewed by a user or group .
*/
2010-11-18 13:53:26 +00:00
define ( " S_DRAFT_REV " , 0 );
2012-10-23 09:16:38 +00:00
/*
* Document is in approval state . A document is in approval state when
* it needs to be approved by a user or group .
*/
2010-11-18 13:53:26 +00:00
define ( " S_DRAFT_APP " , 1 );
2012-10-23 09:16:38 +00:00
/*
* Document is released . A document is in release state either when
* it needs no review or approval after uploaded or has been reviewed
2015-04-22 08:31:36 +00:00
* and / or approved .
2012-10-23 09:16:38 +00:00
*/
2010-11-18 13:53:26 +00:00
define ( " S_RELEASED " , 2 );
2012-10-23 09:16:38 +00:00
2013-01-24 08:29:58 +00:00
/*
* Document is in workflow . A document is in workflow if a workflow
* has been started and has not reached a final state .
*/
define ( " S_IN_WORKFLOW " , 3 );
2015-04-22 08:31:36 +00:00
/*
* Document is in a revision workflow . A revision workflow is started
* some time after the document has been released .
*/
define ( " S_IN_REVISION " , 4 );
2015-06-02 08:00:15 +00:00
/*
* Document is in draft status . Being in draft means that the document
* is still worked on . This status is mainly for uploading documents
* which aren ' t fully complete but needs to accessible for the public ,
* e . g . in order to colaborate on them .
*/
define ( " S_DRAFT " , 5 );
2012-10-23 09:16:38 +00:00
/*
* Document was rejected . A document is in rejected state when
* the review failed or approval was not given .
*/
2010-11-18 13:53:26 +00:00
define ( " S_REJECTED " , - 1 );
2012-10-23 09:16:38 +00:00
/*
* Document is obsolete . A document can be obsoleted once it was
* released .
*/
2010-11-18 13:53:26 +00:00
define ( " S_OBSOLETE " , - 2 );
2012-10-23 09:16:38 +00:00
/*
* Document is expired . A document expires when the expiration date
* is reached
*/
2010-11-18 13:53:26 +00:00
define ( " S_EXPIRED " , - 3 );
2015-05-11 07:29:34 +00:00
/**
* The different states a workflow log can be in . This is used in
* all tables tblDocumentXXXLog
*/
/*
* workflow is in a neutral status waiting for action of user
*/
define ( " S_LOG_WAITING " , 0 );
/*
* workflow has been successful ended . The document content has been
* approved , reviewed , aknowledged or revised
*/
define ( " S_LOG_ACCEPTED " , 1 );
/*
* workflow has been unsuccessful ended . The document content has been
* rejected
*/
define ( " S_LOG_REJECTED " , - 1 );
/*
* user has been removed from workflow . This can be for different reasons
* 1. the user has been actively removed from the workflow , 2. the user has
* been deleted .
*/
define ( " S_LOG_USER_REMOVED " , - 2 );
/*
* workflow is sleeping until reactivation . The workflow has been set up
* but not started . This is only valid for the revision workflow , which
* may run over and over again .
*/
define ( " S_LOG_SLEEPING " , - 3 );
2010-11-18 13:53:26 +00:00
/**
2010-12-06 20:00:18 +00:00
* Class to represent a document in the document management system
2010-11-18 13:53:26 +00:00
*
2013-02-14 11:10:53 +00:00
* A document in SeedDMS is similar to files in a regular file system .
2011-01-20 14:26:02 +00:00
* Documents may have any number of content elements
2013-02-14 11:10:53 +00:00
* ({ @ link SeedDMS_Core_DocumentContent }) . These content elements are often
2011-01-20 14:26:02 +00:00
* called versions ordered in a timely manner . The most recent content element
* is the current version .
*
* Documents can be linked to other documents and can have attached files .
* The document content can be anything that can be stored in a regular
* file .
*
2010-11-18 13:53:26 +00:00
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-12-06 20:00:18 +00:00
* @ 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
2010-11-18 13:53:26 +00:00
* @ version Release : @ package_version @
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
2010-12-06 20:00:18 +00:00
/**
* @ var string name of document
*/
2013-01-24 08:29:58 +00:00
protected $_name ;
2010-12-06 20:00:18 +00:00
/**
* @ var string comment of document
*/
2013-01-24 08:29:58 +00:00
protected $_comment ;
2010-12-06 20:00:18 +00:00
2010-12-10 13:40:13 +00:00
/**
* @ var integer unix timestamp of creation date
*/
2013-01-24 08:29:58 +00:00
protected $_date ;
2010-12-10 13:40:13 +00:00
2010-12-06 20:00:18 +00:00
/**
* @ var integer id of user who is the owner
*/
2013-01-24 08:29:58 +00:00
protected $_ownerID ;
2010-12-06 20:00:18 +00:00
/**
* @ var integer id of folder this document belongs to
*/
2013-01-24 08:29:58 +00:00
protected $_folderID ;
2010-12-06 20:00:18 +00:00
/**
* @ var integer timestamp of expiration date
*/
2013-01-24 08:29:58 +00:00
protected $_expires ;
2010-12-06 20:00:18 +00:00
/**
* @ var boolean true if access is inherited , otherwise false
*/
2013-01-24 08:29:58 +00:00
protected $_inheritAccess ;
2010-12-10 13:40:13 +00:00
/**
* @ var integer default access if access rights are not inherited
*/
2013-01-24 08:29:58 +00:00
protected $_defaultAccess ;
2010-12-06 20:00:18 +00:00
2013-02-11 13:55:51 +00:00
/**
* @ var array list of notifications for users and groups
*/
protected $_readAccessList ;
2011-01-20 12:48:06 +00:00
/**
* @ var array list of notifications for users and groups
*/
2013-01-24 08:29:58 +00:00
public $_notifyList ;
2011-01-20 12:48:06 +00:00
2010-12-06 20:00:18 +00:00
/**
* @ var boolean true if document is locked , otherwise false
*/
2013-01-24 08:29:58 +00:00
protected $_locked ;
2010-12-06 20:00:18 +00:00
/**
* @ var string list of keywords
*/
2013-01-24 08:29:58 +00:00
protected $_keywords ;
2010-12-06 20:00:18 +00:00
2011-03-10 14:28:21 +00:00
/**
* @ var array list of categories
*/
2013-01-24 08:29:58 +00:00
protected $_categories ;
2011-03-10 14:28:21 +00:00
2010-12-06 20:00:18 +00:00
/**
2010-12-10 13:40:13 +00:00
* @ var integer position of document within the parent folder
2010-12-06 20:00:18 +00:00
*/
2013-01-24 08:29:58 +00:00
protected $_sequence ;
2010-12-06 20:00:18 +00:00
2013-02-14 11:10:53 +00:00
function SeedDMS_Core_Document ( $id , $name , $comment , $date , $expires , $ownerID , $folderID , $inheritAccess , $defaultAccess , $locked , $keywords , $sequence ) { /* {{{ */
2012-10-09 09:54:07 +00:00
parent :: __construct ( $id );
2010-11-18 13:53:26 +00:00
$this -> _name = $name ;
$this -> _comment = $comment ;
$this -> _date = $date ;
$this -> _expires = $expires ;
$this -> _ownerID = $ownerID ;
$this -> _folderID = $folderID ;
$this -> _inheritAccess = $inheritAccess ;
$this -> _defaultAccess = $defaultAccess ;
$this -> _locked = ( $locked == null || $locked == '' ? - 1 : $locked );
$this -> _keywords = $keywords ;
$this -> _sequence = $sequence ;
2011-03-10 14:28:21 +00:00
$this -> _categories = array ();
2011-01-20 12:48:06 +00:00
$this -> _notifyList = array ();
2010-11-16 09:09:07 +00:00
} /* }}} */
2010-11-12 22:47:41 +00:00
2014-12-08 13:32:47 +00:00
public static function getInstance ( $id , $dms ) { /* {{{ */
$db = $dms -> getDB ();
$queryStr = " SELECT * FROM tblDocuments WHERE id = " . ( int ) $id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
$resArr = $resArr [ 0 ];
// New Locking mechanism uses a separate table to track the lock.
$queryStr = " SELECT * FROM tblDocumentLocks WHERE document = " . ( int ) $id ;
$lockArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $lockArr ) && $lockArr == false ) || ( count ( $lockArr ) == 0 )) {
// Could not find a lock on the selected document.
$lock = - 1 ;
}
else {
// A lock has been identified for this document.
$lock = $lockArr [ 0 ][ " userID " ];
}
2015-07-15 14:57:26 +00:00
$classname = $dms -> getClassname ( 'document' );
$document = new $classname ( $resArr [ " id " ], $resArr [ " name " ], $resArr [ " comment " ], $resArr [ " date " ], $resArr [ " expires " ], $resArr [ " owner " ], $resArr [ " folder " ], $resArr [ " inheritAccess " ], $resArr [ " defaultAccess " ], $lock , $resArr [ " keywords " ], $resArr [ " sequence " ]);
2014-12-08 13:32:47 +00:00
$document -> setDMS ( $dms );
return $document ;
} /* }}} */
2010-11-18 13:53:26 +00:00
/*
2010-12-22 19:49:20 +00:00
* Return the directory of the document in the file system relativ
2010-11-18 13:53:26 +00:00
* to the contentDir
*
* @ return string directory of document
*/
function getDir () { /* {{{ */
2012-03-22 07:03:10 +00:00
if ( $this -> _dms -> maxDirID ) {
$dirid = ( int ) (( $this -> _id - 1 ) / $this -> _dms -> maxDirID ) + 1 ;
2011-12-08 19:30:27 +00:00
return $dirid . " / " . $this -> _id . " / " ;
} else {
return $this -> _id . " / " ;
}
2010-11-16 09:09:07 +00:00
} /* }}} */
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
/*
* Return the name of the document
*
* @ return string name of document
*/
function getName () { return $this -> _name ; }
/*
* Set the name of the document
*
* @ param $newName string new name of document
*/
function setName ( $newName ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocuments SET name = " . $db -> qstr ( $newName ) . " WHERE id = " . $this -> _id ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _name = $newName ;
return true ;
} /* }}} */
/*
* Return the comment of the document
*
* @ return string comment of document
*/
function getComment () { return $this -> _comment ; }
/*
* Set the comment of the document
*
* @ param $newComment string new comment of document
*/
function setComment ( $newComment ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocuments SET comment = " . $db -> qstr ( $newComment ) . " WHERE id = " . $this -> _id ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _comment = $newComment ;
return true ;
} /* }}} */
function getKeywords () { return $this -> _keywords ; }
function setKeywords ( $newKeywords ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocuments SET keywords = " . $db -> qstr ( $newKeywords ) . " WHERE id = " . $this -> _id ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _keywords = $newKeywords ;
return true ;
} /* }}} */
2011-10-27 09:33:48 +00:00
/**
* Retrieve a list of all categories this document belongs to
*
* @ return array list of category objects
*/
function getCategories () { /* {{{ */
2011-03-10 14:28:21 +00:00
$db = $this -> _dms -> getDB ();
if ( ! $this -> _categories ) {
$queryStr = " SELECT * FROM tblCategory where id in (select categoryID from tblDocumentCategory where documentID = " . $this -> _id . " ) " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
foreach ( $resArr as $row ) {
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_DocumentCategory ( $row [ 'id' ], $row [ 'name' ]);
2011-03-10 14:28:21 +00:00
$cat -> setDMS ( $this -> _dms );
$this -> _categories [] = $cat ;
}
}
return $this -> _categories ;
2011-10-27 09:33:48 +00:00
} /* }}} */
2011-03-10 14:28:21 +00:00
2011-10-27 09:33:48 +00:00
/**
* Set a list of categories for the document
* This function will delete currently assigned categories and sets new
* categories .
*
* @ param array $newCategories list of category objects
*/
2011-03-10 14:28:21 +00:00
function setCategories ( $newCategories ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2012-10-22 13:33:30 +00:00
$db -> startTransaction ();
2011-03-10 14:28:21 +00:00
$queryStr = " DELETE from tblDocumentCategory WHERE documentID = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2011-03-10 14:28:21 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2011-03-10 14:28:21 +00:00
foreach ( $newCategories as $cat ) {
$queryStr = " INSERT INTO tblDocumentCategory (categoryID, documentID) VALUES ( " . $cat -> getId () . " , " . $this -> _id . " ) " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2011-03-10 14:28:21 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2011-03-10 14:28:21 +00:00
}
2012-10-22 13:33:30 +00:00
$db -> commitTransaction ();
2011-03-10 14:28:21 +00:00
$this -> _categories = $newCategories ;
return true ;
} /* }}} */
2010-12-10 13:40:13 +00:00
/**
2011-10-27 09:33:48 +00:00
* Return creation date of the document
2010-12-10 13:40:13 +00:00
*
* @ return integer unix timestamp of creation date
*/
2010-11-18 13:53:26 +00:00
function getDate () { /* {{{ */
return $this -> _date ;
} /* }}} */
2015-07-31 13:34:07 +00:00
/**
* Set creation date of the document
*
* @ param integer $date timestamp of creation date . If false then set it
* to the current timestamp
* @ return boolean true on success
*/
function setDate ( $date ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( ! $date )
$date = time ();
2015-08-04 05:38:45 +00:00
else {
if ( ! is_numeric ( $date ))
return false ;
}
2015-07-31 13:34:07 +00:00
2015-08-04 05:38:45 +00:00
$queryStr = " UPDATE tblDocuments SET date = " . ( int ) $date . " WHERE id = " . $this -> _id ;
2015-07-31 13:34:07 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _date = $date ;
return true ;
} /* }}} */
2011-10-27 09:33:48 +00:00
/**
* Return the parent folder of the document
*
* @ return object parent folder
*/
2015-06-29 08:28:10 +00:00
function getParent () { /* {{{ */
return self :: getFolder ();
} /* }}} */
2010-11-18 13:53:26 +00:00
function getFolder () { /* {{{ */
if ( ! isset ( $this -> _folder ))
$this -> _folder = $this -> _dms -> getFolder ( $this -> _folderID );
return $this -> _folder ;
} /* }}} */
2010-11-30 09:27:37 +00:00
/**
* Set folder of a document
*
* This function basically moves a document from a folder to another
* folder .
*
* @ param object $newFolder
* @ return boolean false in case of an error , otherwise true
*/
2010-11-18 13:53:26 +00:00
function setFolder ( $newFolder ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " UPDATE tblDocuments SET folder = " . $newFolder -> getID () . " WHERE id = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _folderID = $newFolder -> getID ();
$this -> _folder = $newFolder ;
// Make sure that the folder search path is also updated.
$path = $newFolder -> getPath ();
$flist = " " ;
foreach ( $path as $f ) {
$flist .= " : " . $f -> getID ();
}
if ( strlen ( $flist ) > 1 ) {
$flist .= " : " ;
}
$queryStr = " UPDATE tblDocuments SET folderList = ' " . $flist . " ' WHERE id = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
return true ;
} /* }}} */
2010-12-16 09:28:34 +00:00
/**
* Return owner of document
*
2013-02-14 11:10:53 +00:00
* @ return object owner of document as an instance of { @ link SeedDMS_Core_User }
2010-12-16 09:28:34 +00:00
*/
2010-11-18 13:53:26 +00:00
function getOwner () { /* {{{ */
if ( ! isset ( $this -> _owner ))
$this -> _owner = $this -> _dms -> getUser ( $this -> _ownerID );
return $this -> _owner ;
} /* }}} */
2010-12-16 09:28:34 +00:00
/**
* Set owner of a document
*
* @ param object $newOwner new owner
* @ return boolean true if successful otherwise false
*/
2010-11-18 13:53:26 +00:00
function setOwner ( $newOwner ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2015-04-17 18:05:34 +00:00
$oldOwner = self :: getOwner ();
$db -> startTransaction ();
2010-11-18 13:53:26 +00:00
$queryStr = " UPDATE tblDocuments set owner = " . $newOwner -> getID () . " WHERE id = " . $this -> _id ;
2015-04-17 18:05:34 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
/* FIXME: Update also all locks and checkouts done by the previous owner */
/*
$queryStr = " UPDATE tblDocumentLocks set userID = " . $newOwner -> getID () . " WHERE document = " . $this -> _id . " AND userID = " . $oldOwner -> getID ();
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2015-04-17 18:05:34 +00:00
}
$queryStr = " UPDATE tblDocumentCheckOuts set userID = " . $newOwner -> getID () . " WHERE document = " . $this -> _id . " AND userID = " . $oldOwner -> getID ();
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
*/
$db -> commitTransaction ();
2010-11-18 13:53:26 +00:00
$this -> _ownerID = $newOwner -> getID ();
$this -> _owner = $newOwner ;
return true ;
} /* }}} */
function getDefaultAccess () { /* {{{ */
if ( $this -> inheritsAccess ()) {
$res = $this -> getFolder ();
if ( ! $res ) return false ;
return $this -> _folder -> getDefaultAccess ();
}
return $this -> _defaultAccess ;
} /* }}} */
2015-06-19 10:52:49 +00:00
/**
* Set default access mode
*
* This method sets the default access mode and also removes all notifiers which
* will not have read access anymore .
*
* @ param integer $mode access mode
2015-06-19 13:02:37 +00:00
* @ param boolean $noclean set to true if notifier list shall not be clean up
2015-06-19 10:52:49 +00:00
*/
2015-06-19 13:02:37 +00:00
function setDefaultAccess ( $mode , $noclean = " false " ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocuments set defaultAccess = " . ( int ) $mode . " WHERE id = " . $this -> _id ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _defaultAccess = $mode ;
2010-11-12 22:47:41 +00:00
2015-06-19 13:02:37 +00:00
if ( ! $noclean )
self :: cleanNotifyList ();
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
function inheritsAccess () { return $this -> _inheritAccess ; }
2010-12-22 13:18:02 +00:00
/**
* Set inherited access mode
* Setting inherited access mode will set or unset the internal flag which
* controls if the access mode is inherited from the parent folder or not .
* It will not modify the
* access control list for the current object . It will remove all
* notifications of users which do not even have read access anymore
* after setting or unsetting inherited access .
*
* @ param boolean $inheritAccess set to true for setting and false for
* unsetting inherited access mode
2015-06-19 13:02:37 +00:00
* @ param boolean $noclean set to true if notifier list shall not be clean up
2010-12-22 13:18:02 +00:00
* @ return boolean true if operation was successful otherwise false
*/
2015-06-19 13:02:37 +00:00
function setInheritAccess ( $inheritAccess , $noclean = false ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " UPDATE tblDocuments SET inheritAccess = " . ( $inheritAccess ? " 1 " : " 0 " ) . " WHERE id = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _inheritAccess = ( $inheritAccess ? " 1 " : " 0 " );
2015-06-19 13:02:37 +00:00
if ( ! $noclean )
self :: cleanNotifyList ();
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2010-11-12 22:47:41 +00:00
2011-10-27 09:33:48 +00:00
/**
* Check if document expires
*
* @ return boolean true if document has expiration date set , otherwise false
*/
2010-11-18 13:53:26 +00:00
function expires () { /* {{{ */
if ( intval ( $this -> _expires ) == 0 )
return false ;
else
return true ;
} /* }}} */
2010-11-12 22:47:41 +00:00
2011-10-27 09:33:48 +00:00
/**
* Get expiration time of document
*
* @ return integer / boolean expiration date as unix timestamp or false
*/
2010-11-18 13:53:26 +00:00
function getExpires () { /* {{{ */
if ( intval ( $this -> _expires ) == 0 )
return false ;
else
return $this -> _expires ;
} /* }}} */
2010-11-12 22:47:41 +00:00
2011-10-27 09:33:48 +00:00
/**
* Set expiration date as unix timestamp
*
* @ param integer unix timestamp of expiration date
*/
2010-11-18 13:53:26 +00:00
function setExpires ( $expires ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$expires = ( ! $expires ) ? 0 : $expires ;
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
if ( $expires == $this -> _expires ) {
// No change is necessary.
return true ;
}
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocuments SET expires = " . ( int ) $expires . " WHERE id = " . $this -> _id ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _expires = $expires ;
return true ;
} /* }}} */
2010-12-22 13:18:02 +00:00
/**
* Check if the document has expired
*
* @ return boolean true if document has expired otherwise false
*/
2010-11-18 13:53:26 +00:00
function hasExpired () { /* {{{ */
2010-10-29 13:19:51 +00:00
if ( intval ( $this -> _expires ) == 0 ) return false ;
if ( time () > $this -> _expires + 24 * 60 * 60 ) return true ;
return false ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-11-30 09:27:37 +00:00
2013-01-24 08:29:58 +00:00
/**
* Check if the document has expired and set the status accordingly
* It will also recalculate the status if the current status is
* set to S_EXPIRED but the document isn ' t actually expired .
2013-01-28 10:14:13 +00:00
* The method will update the document status log database table
* if needed .
* FIXME : some left over reviewers / approvers are in the way if
2013-04-30 15:42:07 +00:00
* no workflow is set and traditional workflow mode is on . In that
2013-01-28 10:14:13 +00:00
* case the status is set to S_DRAFT_REV or S_DRAFT_APP
2013-01-24 08:29:58 +00:00
*
* @ return boolean true if status has changed
*/
2010-11-18 13:53:26 +00:00
function verifyLastestContentExpriry (){ /* {{{ */
2010-10-29 13:19:51 +00:00
$lc = $this -> getLatestContent ();
2011-07-20 07:14:55 +00:00
if ( $lc ) {
$st = $lc -> getStatus ();
2010-11-30 09:27:37 +00:00
2015-05-11 07:29:34 +00:00
if (( $st [ " status " ] == S_DRAFT_REV || $st [ " status " ] == S_DRAFT_APP || $st [ " status " ] == S_IN_WORKFLOW || $st [ " status " ] == S_RELEASED || $st [ " status " ] == S_IN_REVISION ) && $this -> hasExpired ()){
2013-01-28 10:14:13 +00:00
return $lc -> setStatus ( S_EXPIRED , " " , $this -> getOwner ());
2011-07-20 07:14:55 +00:00
}
2013-01-28 10:14:13 +00:00
elseif ( $st [ " status " ] == S_EXPIRED && ! $this -> hasExpired () ){
2011-07-20 16:44:38 +00:00
$lc -> verifyStatus ( true , $this -> getOwner ());
2011-07-20 07:14:55 +00:00
return true ;
}
2010-10-29 13:19:51 +00:00
}
return false ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-11-30 09:27:37 +00:00
2015-05-12 17:07:59 +00:00
/**
* Check if latest content of the document has a schedult
* revision workflow .
* The method will update the document status log database table
* if needed .
*
* @ param object $user user requesting the possible automatic change
* @ param string $next next date for review
* @ return boolean true if status has changed
*/
function checkForDueRevisionWorkflow ( $user , $next = '' ){ /* {{{ */
$lc = $this -> getLatestContent ();
if ( $lc ) {
$st = $lc -> getStatus ();
if ( $st [ " status " ] == S_RELEASED ) {
if ( $lc -> getRevisionDate () && $lc -> getRevisionDate () <= date ( 'Y-m-d 00:00:00' )) {
if ( $lc -> startRevision ( $user , 'Automatic start of revision workflow' )) {
if ( $next ) {
$tmp = explode ( '-' , substr ( $next , 0 , 10 ));
if ( checkdate ( $tmp [ 1 ], $tmp [ 2 ], $tmp [ 0 ]))
$lc -> setRevisionDate ( $next );
} else {
$lc -> setRevisionDate ( false );
}
return true ;
}
}
}
}
return false ;
} /* }}} */
2010-12-22 13:18:02 +00:00
/**
* Check if document is locked
*
* @ return boolean true if locked otherwise false
*/
2010-11-18 13:53:26 +00:00
function isLocked () { return $this -> _locked != - 1 ; }
2010-10-29 13:19:51 +00:00
2010-12-22 13:18:02 +00:00
/**
* Lock or unlock document
*
* @ param $falseOrUser user object for locking or false for unlocking
* @ return boolean true if operation was successful otherwise false
*/
2010-11-18 13:53:26 +00:00
function setLocked ( $falseOrUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$lockUserID = - 1 ;
if ( is_bool ( $falseOrUser ) && ! $falseOrUser ) {
$queryStr = " DELETE FROM tblDocumentLocks WHERE document = " . $this -> _id ;
}
else if ( is_object ( $falseOrUser )) {
$queryStr = " INSERT INTO tblDocumentLocks (document, userID) VALUES ( " . $this -> _id . " , " . $falseOrUser -> getID () . " ) " ;
$lockUserID = $falseOrUser -> getID ();
}
else {
return false ;
}
if ( ! $db -> getResult ( $queryStr )) {
return false ;
2010-10-29 13:19:51 +00:00
}
2010-11-18 13:53:26 +00:00
unset ( $this -> _lockingUser );
$this -> _locked = $lockUserID ;
return true ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2010-12-22 13:18:02 +00:00
/**
* Get the user currently locking the document
*
* @ return object user have a lock
*/
2010-11-18 13:53:26 +00:00
function getLockingUser () { /* {{{ */
if ( ! $this -> isLocked ())
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! isset ( $this -> _lockingUser ))
$this -> _lockingUser = $this -> _dms -> getUser ( $this -> _locked );
return $this -> _lockingUser ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2015-04-17 18:08:06 +00:00
/**
* Check if document is checked out
*
* @ return boolean true if checked out otherwise false
*/
function isCheckedOut () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM tblDocumentCheckOuts WHERE document = " . ( int ) $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && $resArr == false ) || ( count ( $resArr ) == 0 )) {
// Could not find a check out for the selected document.
return false ;
} else {
// A check out has been identified for this document.
return true ;
}
} /* }}} */
/**
* Get checkout info for document
*
2015-04-23 09:26:00 +00:00
* @ return array / boolean record from table tblDocumentCheckOuts or false
* in case of an error .
2015-04-17 18:08:06 +00:00
*/
function getCheckOutInfo () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM tblDocumentCheckOuts WHERE document = " . ( int ) $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && $resArr == false ) || ( count ( $resArr ) == 0 )) {
// Could not find a check out for the selected document.
return false ;
} else {
// A check out has been identified for this document.
return $resArr [ 0 ];
}
} /* }}} */
/**
* Check out document
*
* Creates a check out record for the document and copies the latest
* version of the document into the given checkout dir .
*
* @ param object $user object of user doing the checkout
* @ param string $checkoutdir directory where the file will be placed
* @ return object object of class SeedDMS_Core_DocumentCheckOut
*/
function checkOut ( $user , $checkoutdir ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( self :: isCheckedOut ())
return false ;
/* Check if checkout dir is writable */
if ( ! file_exists ( $checkoutdir )) {
return false ;
}
$db -> startTransaction ();
$lc = self :: getLatestContent ();
$filename = $checkoutdir . " / " . $lc -> getOriginalFileName ();
$queryStr = " INSERT INTO tblDocumentCheckOuts (document, version, userID, date, filename) VALUES ( " . $this -> _id . " , " . $lc -> getVersion () . " , " . $user -> getID () . " , CURRENT_TIMESTAMP, " . $db -> qstr ( $filename ) . " ) " ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
/* Try to copy the file */
$err = SeedDMS_Core_File :: copyFile ( $this -> _dms -> contentDir . $this -> getDir () . $lc -> getFileName (), $filename );
if ( ! $err ) {
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
return true ;
} /* }}} */
/**
* Check in document
*
* Τ his function is similar to SeedDMS_Core_Document :: addContent ()
* but reads the content from the file was previously checked out .
* Internal this method calls
* SeedDMS_Core_Document :: addContent () but takes over the original
* filename , filetype and mimetype from the checked out version .
* No matter in which state the current checked out file is , the
* document will be checked back in afterwards .
*
* @ param string $comment
* @ param object $user
* @ param array $reviewers
* @ param array $approvers
* @ param integer $version
* @ param array $attributes
* @ param object $workflow
2015-06-24 18:34:40 +00:00
* @ param integer $initstate intial document status
2015-04-17 18:08:06 +00:00
* @ return boolean | object false in case of error , true if no error occurs but
* the document remains unchanged ( because the checked out file has not
* changed or it has disappeared and couldnt ' t be checked in ), or
* an instance of class SeedDMS_Core_AddContentResultSet if the document
* was updated .
*/
2015-06-24 18:34:40 +00:00
function checkIn ( $comment , $user , $reviewers = array (), $approvers = array (), $version = 0 , $attributes = array (), $workflow = null , $initstate = S_RELEASED ) { /* {{{ */
2015-04-17 18:08:06 +00:00
$db = $this -> _dms -> getDB ();
$info = self :: getCheckOutInfo ();
$lc = self :: getLatestContent ();
/* If file doesn't exist anymore, then just remove the record from the db */
if ( ! file_exists ( $info [ 'filename' ])) {
$queryStr = " DELETE FROM tblDocumentCheckOuts WHERE document = " . $this -> _id ;
$db -> getResult ( $queryStr );
return true ;
}
/* Check if version of checked out file is equal to current version */
if ( $lc -> getVersion () != $info [ 'version' ]) {
return true ;
}
if ( $user -> getID () != $info [ 'userID' ]) {
return true ;
}
$content = true ;
/* Do not create a new version if the file was unchanged */
$checksum = SeedDMS_Core_File :: checksum ( $info [ 'filename' ]);
if ( $checksum != $lc -> getChecksum ()) {
2015-06-24 18:34:40 +00:00
$content = $this -> addContent ( $comment , $user , $info [ 'filename' ], $lc -> getOriginalFileName (), $lc -> getFileType (), $lc -> getMimeType (), $reviewers , $approvers , $version , $attributes , $workflow , $initstate );
2015-04-23 09:48:01 +00:00
if ( $content ) {
if ( ! $this -> _dms -> forceRename ) {
SeedDMS_Core_File :: removeFile ( $info [ 'filename' ]);
}
$queryStr = " DELETE FROM tblDocumentCheckOuts WHERE document = " . $this -> _id ;
$db -> getResult ( $queryStr );
return $content ;
} else {
return false ;
}
} else {
SeedDMS_Core_File :: removeFile ( $info [ 'filename' ]);
$queryStr = " DELETE FROM tblDocumentCheckOuts WHERE document = " . $this -> _id ;
$db -> getResult ( $queryStr );
return true ;
2015-04-17 18:08:06 +00:00
}
} /* }}} */
/**
* Cancel check out of document
*
* This function will cancel a check out in progress by removing
* the check out record from the database and removing the file
* from the check out folder .
*
* @ return boolean true if cancelation was successful
*/
function cancelCheckOut () { /* {{{ */
$db = $this -> _dms -> getDB ();
$info = self :: getCheckOutInfo ();
if ( $info ) {
SeedDMS_Core_File :: removeFile ( $info [ 'filename' ]);
$queryStr = " DELETE FROM tblDocumentCheckOuts WHERE document = " . $this -> _id ;
$db -> getResult ( $queryStr );
}
return true ;
} /* }}} */
/**
* Return the check out status of the document
*
* This method returns the checkout status of a previosly checked out
* document .
*
* @ return int 1 = The checked out file doesn ' t exists anymore ,
* 2 = The checked out version doesn ' t exists anymore
* 3 = The checked out file has not been modified yet
* 4 = new check out record in database found
* 0 = The checked out file is modified and check in will create a new version
*/
function checkOutStatus () { /* {{{ */
$info = self :: getCheckOutInfo ();
if ( ! $info )
return 4 ;
$lc = self :: getLatestContent ();
/* If file doesn't exist anymore, then just remove the record from the db */
if ( ! file_exists ( $info [ 'filename' ])) {
return 1 ;
}
/* Check if version of checked out file is equal to current version */
if ( $lc -> getVersion () != $info [ 'version' ]) {
return 2 ;
}
$checksum = SeedDMS_Core_File :: checksum ( $info [ 'filename' ]);
if ( $checksum == $lc -> getChecksum ()) {
return 3 ;
}
return 0 ;
} /* }}} */
2010-11-18 13:53:26 +00:00
function getSequence () { return $this -> _sequence ; }
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
function setSequence ( $seq ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " UPDATE tblDocuments SET sequence = " . $seq . " WHERE id = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _sequence = $seq ;
return true ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2010-12-22 13:18:02 +00:00
/**
2012-01-12 17:02:30 +00:00
* Delete all entries for this document from the access control list
2010-12-22 13:18:02 +00:00
*
2015-06-19 13:24:19 +00:00
* @ param boolean $noclean set to true if notifier list shall not be clean up
2010-12-22 13:18:02 +00:00
* @ return boolean true if operation was successful otherwise false
*/
2015-06-19 13:24:19 +00:00
function clearAccessList ( $noclean = false ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblACLs WHERE targetType = " . T_DOCUMENT . " AND target = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
unset ( $this -> _accessList );
2015-06-19 13:24:19 +00:00
if ( ! $noclean )
self :: cleanNotifyList ();
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2010-11-25 21:09:52 +00:00
/**
* Returns a list of access privileges
*
2012-01-12 17:02:30 +00:00
* If the document inherits the access privileges from the parent folder
* those will be returned .
* $mode and $op can be set to restrict the list of returned access
* privileges . If $mode is set to M_ANY no restriction will apply
* regardless of the value of $op . The returned array contains a list
2013-02-14 11:10:53 +00:00
* of { @ link SeedDMS_Core_UserAccess } and
* { @ link SeedDMS_Core_GroupAccess } objects . Even if the document
2012-05-08 08:04:50 +00:00
* has no access list the returned array contains the two elements
* 'users' and 'groups' which are than empty . The methode returns false
* if the function fails .
2012-01-12 17:02:30 +00:00
*
* @ param integer $mode access mode ( defaults to M_ANY )
* @ param integer $op operation ( defaults to O_EQ )
2015-06-29 08:28:10 +00:00
* @ return array multi dimensional array or false in case of an error
2010-11-25 21:09:52 +00:00
*/
2010-11-18 13:53:26 +00:00
function getAccessList ( $mode = M_ANY , $op = O_EQ ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( $this -> inheritsAccess ()) {
$res = $this -> getFolder ();
if ( ! $res ) return false ;
2015-06-29 08:28:10 +00:00
$pacl = $res -> getAccessList ( $mode , $op );
return $pacl ;
} else {
$pacl = array ( " groups " => array (), " users " => array ());
2010-11-18 13:53:26 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! isset ( $this -> _accessList [ $mode ])) {
if ( $op != O_GTEQ && $op != O_LTEQ && $op != O_EQ ) {
return false ;
}
$modeStr = " " ;
if ( $mode != M_ANY ) {
2011-12-01 21:20:58 +00:00
$modeStr = " AND mode " . $op . ( int ) $mode ;
2010-11-18 13:53:26 +00:00
}
$queryStr = " SELECT * FROM tblACLs WHERE targetType = " . T_DOCUMENT .
" AND target = " . $this -> _id . $modeStr . " ORDER BY targetType " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _accessList [ $mode ] = array ( " groups " => array (), " users " => array ());
2010-11-25 21:09:52 +00:00
foreach ( $resArr as $row ) {
2010-11-18 13:53:26 +00:00
if ( $row [ " userID " ] != - 1 )
2013-02-14 11:10:53 +00:00
array_push ( $this -> _accessList [ $mode ][ " users " ], new SeedDMS_Core_UserAccess ( $this -> _dms -> getUser ( $row [ " userID " ]), $row [ " mode " ]));
2010-11-18 13:53:26 +00:00
else //if ($row["groupID"] != -1)
2013-02-14 11:10:53 +00:00
array_push ( $this -> _accessList [ $mode ][ " groups " ], new SeedDMS_Core_GroupAccess ( $this -> _dms -> getGroup ( $row [ " groupID " ]), $row [ " mode " ]));
2010-11-12 22:47:41 +00:00
}
2010-10-29 13:19:51 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return $this -> _accessList [ $mode ];
2015-06-29 08:28:10 +00:00
return SeedDMS_Core_DMS :: mergeAccessLists ( $pacl , $this -> _accessList [ $mode ]);
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-12-22 13:18:02 +00:00
/**
* Add access right to folder
* This function may change in the future . Instead of passing the a flag
* and a user / group id a user or group object will be expected .
*
* @ param integer $mode access mode
* @ param integer $userOrGroupID id of user or group
* @ param integer $isUser set to 1 if $userOrGroupID is the id of a
* user
*/
2010-11-18 13:53:26 +00:00
function addAccess ( $mode , $userOrGroupID , $isUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$userOrGroup = ( $isUser ) ? " userID " : " groupID " ;
2010-11-30 09:27:37 +00:00
$queryStr = " INSERT INTO tblACLs (target, targetType, " . $userOrGroup . " , mode) VALUES
2011-12-01 21:20:58 +00:00
( " . $this->_id . " , " .T_DOCUMENT. " , " . (int) $userOrGroupID . " , " .(int) $mode . " ) " ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
unset ( $this -> _accessList );
// Update the notify list, if necessary.
if ( $mode == M_NONE ) {
$this -> removeNotify ( $userOrGroupID , $isUser );
}
2010-10-29 13:19:51 +00:00
return true ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-12-22 13:18:02 +00:00
/**
* Change access right of document
* This function may change in the future . Instead of passing the a flag
* and a user / group id a user or group object will be expected .
*
* @ param integer $newMode access mode
* @ param integer $userOrGroupID id of user or group
* @ param integer $isUser set to 1 if $userOrGroupID is the id of a
* user
*/
2010-11-18 13:53:26 +00:00
function changeAccess ( $newMode , $userOrGroupID , $isUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$userOrGroup = ( $isUser ) ? " userID " : " groupID " ;
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblACLs SET mode = " . ( int ) $newMode . " WHERE targetType = " . T_DOCUMENT . " AND target = " . $this -> _id . " AND " . $userOrGroup . " = " . ( int ) $userOrGroupID ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
unset ( $this -> _accessList );
// Update the notify list, if necessary.
if ( $newMode == M_NONE ) {
$this -> removeNotify ( $userOrGroupID , $isUser );
}
return true ;
} /* }}} */
2011-10-27 09:33:48 +00:00
/**
* Remove access rights for a user or group
*
* @ param integer $userOrGroupID ID of user or group
* @ param boolean $isUser true if $userOrGroupID is a user id , false if it
* is a group id .
* @ return boolean true on success , otherwise false
*/
2010-11-18 13:53:26 +00:00
function removeAccess ( $userOrGroupID , $isUser ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$userOrGroup = ( $isUser ) ? " userID " : " groupID " ;
2011-12-01 21:20:58 +00:00
$queryStr = " DELETE FROM tblACLs WHERE targetType = " . T_DOCUMENT . " AND target = " . $this -> _id . " AND " . $userOrGroup . " = " . ( int ) $userOrGroupID ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
unset ( $this -> _accessList );
2011-10-27 09:33:48 +00:00
// Update the notify list, if the user looses access rights.
2010-11-18 13:53:26 +00:00
$mode = ( $isUser ? $this -> getAccessMode ( $this -> _dms -> getUser ( $userOrGroupID )) : $this -> getGroupAccessMode ( $this -> _dms -> getGroup ( $userOrGroupID )));
if ( $mode == M_NONE ) {
$this -> removeNotify ( $userOrGroupID , $isUser );
}
return true ;
} /* }}} */
2010-11-25 21:09:52 +00:00
/**
* Returns the greatest access privilege for a given user
*
2012-05-08 08:04:50 +00:00
* This function returns the access mode for a given user . An administrator
* and the owner of the folder has unrestricted access . A guest user has
* read only access or no access if access rights are further limited
* by access control lists . All other users have access rights according
* to the access control lists or the default access . This function will
* recursive check for access rights of parent folders if access rights
* are inherited .
*
* The function searches the access control list for entries of
2010-11-25 21:09:52 +00:00
* user $user . If it finds more than one entry it will return the
2012-05-08 08:04:50 +00:00
* one allowing the greatest privileges , but user rights will always
* precede group rights . If there is no entry in the
2010-11-25 21:09:52 +00:00
* access control list , it will return the default access mode .
* The function takes inherited access rights into account .
* For a list of possible access rights see @ file inc . AccessUtils . php
*
2013-02-14 11:10:53 +00:00
* @ param $user object instance of class SeedDMS_Core_User
2010-11-25 21:09:52 +00:00
* @ return integer access mode
2010-11-18 13:53:26 +00:00
*/
function getAccessMode ( $user ) { /* {{{ */
2012-08-28 07:29:39 +00:00
if ( ! $user )
return M_NONE ;
2010-11-25 21:09:52 +00:00
/* Administrators have unrestricted access */
2010-11-18 13:53:26 +00:00
if ( $user -> isAdmin ()) return M_ALL ;
2010-11-30 09:27:37 +00:00
2010-11-25 21:09:52 +00:00
/* The owner of the document has unrestricted access */
2010-11-18 13:53:26 +00:00
if ( $user -> getID () == $this -> _ownerID ) return M_ALL ;
2010-11-30 09:27:37 +00:00
2010-11-25 21:09:52 +00:00
/* Check ACLs */
2010-11-18 13:53:26 +00:00
$accessList = $this -> getAccessList ();
if ( ! $accessList ) return false ;
2010-11-30 09:27:37 +00:00
2010-11-25 21:09:52 +00:00
foreach ( $accessList [ " users " ] as $userAccess ) {
if ( $userAccess -> getUserID () == $user -> getID ()) {
2015-08-19 06:21:15 +00:00
$mode = $userAccess -> getMode ();
if ( $user -> isGuest ()) {
if ( $mode >= M_READ ) $mode = M_READ ;
}
return $mode ;
2010-11-18 13:53:26 +00:00
}
}
2015-08-19 06:21:15 +00:00
2012-05-08 08:04:50 +00:00
/* Get the highest right defined by a group */
2015-08-19 06:21:15 +00:00
if ( $accessList [ 'groups' ]) {
$mode = 0 ;
foreach ( $accessList [ " groups " ] as $groupAccess ) {
if ( $user -> isMemberOfGroup ( $groupAccess -> getGroup ())) {
if ( $groupAccess -> getMode () > $mode )
$mode = $groupAccess -> getMode ();
}
2010-11-18 13:53:26 +00:00
}
2015-08-19 06:21:15 +00:00
if ( $mode ) {
if ( $user -> isGuest ()) {
if ( $mode >= M_READ ) $mode = M_READ ;
}
return $mode ;
}
}
$mode = $this -> getDefaultAccess ();
if ( $user -> isGuest ()) {
if ( $mode >= M_READ ) $mode = M_READ ;
2010-11-18 13:53:26 +00:00
}
2015-08-19 06:21:15 +00:00
return $mode ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-11-25 21:09:52 +00:00
/**
* Returns the greatest access privilege for a given group
*
* This function searches the access control list for entries of
* group $group . If it finds more than one entry it will return the
* one allowing the greatest privileges . If there is no entry in the
* access control list , it will return the default access mode .
* The function takes inherited access rights into account .
* For a list of possible access rights see @ file inc . AccessUtils . php
*
2013-02-14 11:10:53 +00:00
* @ param $group object instance of class SeedDMS_Core_Group
2010-11-25 21:09:52 +00:00
* @ return integer access mode
*/
2010-11-18 13:53:26 +00:00
function getGroupAccessMode ( $group ) { /* {{{ */
$highestPrivileged = M_NONE ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
//ACLs durchforsten
$foundInACL = false ;
$accessList = $this -> getAccessList ();
if ( ! $accessList )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
foreach ( $accessList [ " groups " ] as $groupAccess ) {
if ( $groupAccess -> getGroupID () == $group -> getID ()) {
$foundInACL = true ;
if ( $groupAccess -> getMode () > $highestPrivileged )
$highestPrivileged = $groupAccess -> getMode ();
2011-12-01 21:20:58 +00:00
if ( $highestPrivileged == M_ALL ) // max access right -> skip the rest
2010-11-18 13:53:26 +00:00
return $highestPrivileged ;
}
}
if ( $foundInACL )
return $highestPrivileged ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
//Standard-Berechtigung verwenden
return $this -> getDefaultAccess ();
} /* }}} */
2010-11-25 21:09:52 +00:00
/**
* Returns a list of all notifications
*
* The returned list has two elements called 'users' and 'groups' . Each one
2013-02-14 11:10:53 +00:00
* is an array itself countaining objects of class SeedDMS_Core_User and
* SeedDMS_Core_Group .
2010-11-25 21:09:52 +00:00
*
2013-01-28 10:14:13 +00:00
* @ param integer $type type of notification ( not yet used )
2010-11-25 21:09:52 +00:00
* @ return array list of notifications
*/
2013-02-06 13:52:11 +00:00
function getNotifyList ( $type = 0 ) { /* {{{ */
2011-01-28 07:32:06 +00:00
if ( empty ( $this -> _notifyList )) {
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " SELECT * FROM tblNotify WHERE targetType = " . T_DOCUMENT . " AND target = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _notifyList = array ( " groups " => array (), " users " => array ());
foreach ( $resArr as $row )
{
if ( $row [ " userID " ] != - 1 )
array_push ( $this -> _notifyList [ " users " ], $this -> _dms -> getUser ( $row [ " userID " ]) );
else //if ($row["groupID"] != -1)
array_push ( $this -> _notifyList [ " groups " ], $this -> _dms -> getGroup ( $row [ " groupID " ]) );
}
}
return $this -> _notifyList ;
} /* }}} */
2015-06-19 13:02:37 +00:00
/**
* Make sure only users / groups with read access are in the notify list
*
*/
function cleanNotifyList () { /* {{{ */
// If any of the notification subscribers no longer have read access,
// remove their subscription.
if ( empty ( $this -> _notifyList ))
$this -> getNotifyList ();
/* Make a copy of both notifier lists because removeNotify will empty
* $this -> _notifyList and the second foreach will not work anymore .
*/
$nusers = $this -> _notifyList [ " users " ];
$ngroups = $this -> _notifyList [ " groups " ];
foreach ( $nusers as $u ) {
if ( $this -> getAccessMode ( $u ) < M_READ ) {
$this -> removeNotify ( $u -> getID (), true );
}
}
foreach ( $ngroups as $g ) {
if ( $this -> getGroupAccessMode ( $g ) < M_READ ) {
$this -> removeNotify ( $g -> getID (), false );
}
}
} /* }}} */
2010-11-25 21:09:52 +00:00
/**
* Add a user / group to the notification list
2010-12-22 13:18:02 +00:00
* This function does not check if the currently logged in user
* is allowed to add a notification . This must be checked by the calling
* application .
2010-11-25 21:09:52 +00:00
*
* @ param $userOrGroupID integer id of user or group to add
* @ param $isUser integer 1 if $userOrGroupID is a user ,
* 0 if $userOrGroupID is a group
* @ return integer 0 : Update successful .
* - 1 : Invalid User / Group ID .
* - 2 : Target User / Group does not have read access .
* - 3 : User is already subscribed .
* - 4 : Database / internal error .
*/
2011-10-27 09:33:48 +00:00
function addNotify ( $userOrGroupID , $isUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
$userOrGroup = ( $isUser ? " userID " : " groupID " );
/* Verify that user / group exists. */
$obj = ( $isUser ? $this -> _dms -> getUser ( $userOrGroupID ) : $this -> _dms -> getGroup ( $userOrGroupID ));
if ( ! is_object ( $obj )) {
return - 1 ;
}
/* Verify that the requesting user has permission to add the target to
* the notification system .
*/
2010-11-25 21:09:52 +00:00
/*
* The calling application should enforce the policy on who is allowed
* to add someone to the notification system . If is shall remain here
* the currently logged in user should be passed to this function
*
GLOBAL $user ;
2010-12-03 07:27:27 +00:00
if ( $user -> isGuest ()) {
2010-11-18 13:53:26 +00:00
return - 2 ;
}
if ( ! $user -> isAdmin ()) {
if ( $isUser ) {
if ( $user -> getID () != $obj -> getID ()) {
return - 2 ;
}
}
else {
if ( ! $obj -> isMember ( $user )) {
return - 2 ;
}
}
}
2010-11-25 21:09:52 +00:00
*/
2010-11-18 13:53:26 +00:00
2010-11-25 21:09:52 +00:00
/* Verify that target user / group has read access to the document. */
2010-11-18 13:53:26 +00:00
if ( $isUser ) {
// Users are straightforward to check.
if ( $this -> getAccessMode ( $obj ) < M_READ ) {
return - 2 ;
}
}
else {
// Groups are a little more complex.
if ( $this -> getDefaultAccess () >= M_READ ) {
// If the default access is at least READ-ONLY, then just make sure
// that the current group has not been explicitly excluded.
$acl = $this -> getAccessList ( M_NONE , O_EQ );
$found = false ;
foreach ( $acl [ " groups " ] as $group ) {
if ( $group -> getGroupID () == $userOrGroupID ) {
$found = true ;
break ;
}
}
if ( $found ) {
return - 2 ;
}
}
else {
// The default access is restricted. Make sure that the group has
// been explicitly allocated access to the document.
$acl = $this -> getAccessList ( M_READ , O_GTEQ );
if ( is_bool ( $acl )) {
return - 4 ;
}
$found = false ;
foreach ( $acl [ " groups " ] as $group ) {
if ( $group -> getGroupID () == $userOrGroupID ) {
$found = true ;
break ;
}
}
if ( ! $found ) {
return - 2 ;
}
}
}
2010-11-25 21:09:52 +00:00
/* Check to see if user/group is already on the list. */
2010-11-18 13:53:26 +00:00
$queryStr = " SELECT * FROM `tblNotify` WHERE `tblNotify`.`target` = ' " . $this -> _id . " ' " .
" AND `tblNotify`.`targetType` = ' " . T_DOCUMENT . " ' " .
2011-12-01 21:20:58 +00:00
" AND `tblNotify`.` " . $userOrGroup . " ` = ' " . ( int ) $userOrGroupID . " ' " ;
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr )) {
return - 4 ;
}
if ( count ( $resArr ) > 0 ) {
return - 3 ;
}
2011-12-01 21:20:58 +00:00
$queryStr = " INSERT INTO tblNotify (target, targetType, " . $userOrGroup . " ) VALUES ( " . $this -> _id . " , " . T_DOCUMENT . " , " . ( int ) $userOrGroupID . " ) " ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return - 4 ;
unset ( $this -> _notifyList );
return 0 ;
} /* }}} */
2010-11-25 21:09:52 +00:00
/**
* Remove a user or group from the notification list
2010-12-22 13:18:02 +00:00
* This function does not check if the currently logged in user
* is allowed to remove a notification . This must be checked by the calling
* application .
2010-11-25 21:09:52 +00:00
*
* @ param $userOrGroupID id of user or group
* @ param $isUser boolean true if a user is passed in $userOrGroupID , false
* if a group is passed in $userOrGroupID
2013-01-28 10:14:13 +00:00
* @ param $type type of notification ( 0 will delete all ) Not used yet !
2010-11-25 21:09:52 +00:00
* @ return integer 0 if operation was succesful
* - 1 if the userid / groupid is invalid
* - 3 if the user / group is already subscribed
* - 4 in case of an internal database error
*/
2013-01-28 10:14:13 +00:00
function removeNotify ( $userOrGroupID , $isUser , $type = 0 ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-25 21:09:52 +00:00
/* Verify that user / group exists. */
2010-11-18 13:53:26 +00:00
$obj = ( $isUser ? $this -> _dms -> getUser ( $userOrGroupID ) : $this -> _dms -> getGroup ( $userOrGroupID ));
if ( ! is_object ( $obj )) {
return - 1 ;
}
$userOrGroup = ( $isUser ) ? " userID " : " groupID " ;
2010-11-25 21:09:52 +00:00
/* Verify that the requesting user has permission to add the target to
* the notification system .
*/
/*
* The calling application should enforce the policy on who is allowed
* to add someone to the notification system . If is shall remain here
* the currently logged in user should be passed to this function
*
GLOBAL $user ;
2010-12-03 07:27:27 +00:00
if ( $user -> isGuest ()) {
2010-11-18 13:53:26 +00:00
return - 2 ;
}
if ( ! $user -> isAdmin ()) {
if ( $isUser ) {
if ( $user -> getID () != $obj -> getID ()) {
return - 2 ;
}
}
else {
if ( ! $obj -> isMember ( $user )) {
return - 2 ;
}
}
}
2010-11-25 21:09:52 +00:00
*/
2010-11-18 13:53:26 +00:00
2010-11-25 21:09:52 +00:00
/* Check to see if the target is in the database. */
2010-11-18 13:53:26 +00:00
$queryStr = " SELECT * FROM `tblNotify` WHERE `tblNotify`.`target` = ' " . $this -> _id . " ' " .
" AND `tblNotify`.`targetType` = ' " . T_DOCUMENT . " ' " .
2011-12-01 21:20:58 +00:00
" AND `tblNotify`.` " . $userOrGroup . " ` = ' " . ( int ) $userOrGroupID . " ' " ;
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr )) {
return - 4 ;
}
if ( count ( $resArr ) == 0 ) {
return - 3 ;
}
2011-12-01 21:20:58 +00:00
$queryStr = " DELETE FROM tblNotify WHERE target = " . $this -> _id . " AND targetType = " . T_DOCUMENT . " AND " . $userOrGroup . " = " . ( int ) $userOrGroupID ;
2013-01-28 10:14:13 +00:00
/* If type is given then delete only those notifications */
if ( $type )
$queryStr .= " AND `type` = " . ( int ) $type ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return - 4 ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
unset ( $this -> _notifyList );
return 0 ;
} /* }}} */
2010-11-30 09:27:37 +00:00
/**
* Add content to a document
*
* Each document may have any number of content elements attached to it .
* Each content element has a version number . Newer versions ( greater
* version number ) replace older versions .
*
* @ param string $comment comment
* @ param object $user user who shall be the owner of this content
* @ param string $tmpFile file containing the actuall content
* @ param string $orgFileName original file name
2014-11-27 12:40:58 +00:00
* @ param string $fileType
2010-11-30 09:27:37 +00:00
* @ param string $mimeType MimeType of the content
* @ param array $reviewers list of reviewers
* @ param array $approvers list of approvers
* @ param integer $version version number of content or 0 if next higher version shall be used .
2012-10-09 09:54:07 +00:00
* @ param array $attributes list of version attributes . The element key
* must be the id of the attribute definition .
2014-11-27 12:40:58 +00:00
* @ param object $workflow
2015-06-24 18:34:40 +00:00
* @ param integer $initstate intial document status
2010-11-30 09:27:37 +00:00
* @ return bool / array false in case of an error or a result set
*/
2015-06-02 08:00:15 +00:00
function addContent ( $comment , $user , $tmpFile , $orgFileName , $fileType , $mimeType , $reviewers = array (), $approvers = array (), $version = 0 , $attributes = array (), $workflow = null , $initstate = S_RELEASED ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
// the doc path is id/version.filetype
$dir = $this -> getDir ();
2010-11-30 09:27:37 +00:00
/* The version field in table tblDocumentContent used to be auto
* increment but that requires the field to be primary as well if
* innodb is used . That ' s why the version is now determined here .
*/
if (( int ) $version < 1 ) {
$queryStr = " SELECT MAX(version) as m from tblDocumentContent where document = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $res )
return false ;
2010-11-18 13:53:26 +00:00
2010-11-30 09:27:37 +00:00
$version = $resArr [ 0 ][ 'm' ] + 1 ;
2010-11-18 13:53:26 +00:00
}
2013-02-14 11:10:53 +00:00
$filesize = SeedDMS_Core_File :: fileSize ( $tmpFile );
$checksum = SeedDMS_Core_File :: checksum ( $tmpFile );
2012-10-22 13:33:30 +00:00
2012-12-19 10:26:44 +00:00
$db -> startTransaction ();
2013-02-08 15:04:49 +00:00
$queryStr = " INSERT INTO tblDocumentContent (document, version, comment, date, createdBy, dir, orgFileName, fileType, mimeType, fileSize, checksum) VALUES " .
2015-09-22 05:50:36 +00:00
" ( " . $this -> _id . " , " . ( int ) $version . " , " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentTimestamp () . " , " . $user -> getID () . " , " . $db -> qstr ( $dir ) . " , " . $db -> qstr ( $orgFileName ) . " , " . $db -> qstr ( $fileType ) . " , " . $db -> qstr ( $mimeType ) . " , " . $filesize . " , " . $db -> qstr ( $checksum ) . " ) " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-30 09:27:37 +00:00
2012-10-09 09:54:07 +00:00
$contentID = $db -> getInsertID ();
2010-11-18 13:53:26 +00:00
// copy file
2013-02-14 11:10:53 +00:00
if ( ! SeedDMS_Core_File :: makeDir ( $this -> _dms -> contentDir . $dir )) {
2012-10-22 13:33:30 +00:00
$db -> rollbackTransaction ();
return false ;
}
2014-11-24 14:08:37 +00:00
if ( $this -> _dms -> forceRename )
$err = SeedDMS_Core_File :: renameFile ( $tmpFile , $this -> _dms -> contentDir . $dir . $version . $fileType );
else
$err = SeedDMS_Core_File :: copyFile ( $tmpFile , $this -> _dms -> contentDir . $dir . $version . $fileType );
if ( ! $err ) {
2012-10-22 13:33:30 +00:00
$db -> rollbackTransaction ();
return false ;
}
2010-11-18 13:53:26 +00:00
unset ( $this -> _content );
unset ( $this -> _latestContent );
2015-09-22 05:50:36 +00:00
$content = $this -> getLatestContent ( $contentID );
// $content = new SeedDMS_Core_DocumentContent($contentID, $this, $version, $comment, $date, $user->getID(), $dir, $orgFileName, $fileType, $mimeType, $filesize, $checksum);
2013-01-24 08:29:58 +00:00
if ( $workflow )
2013-01-24 16:46:12 +00:00
$content -> setWorkflow ( $workflow , $user );
2013-02-14 11:10:53 +00:00
$docResultSet = new SeedDMS_Core_AddContentResultSet ( $content );
2015-05-21 20:09:33 +00:00
$docResultSet -> setDMS ( $this -> _dms );
2012-10-09 09:54:07 +00:00
if ( $attributes ) {
foreach ( $attributes as $attrdefid => $attribute ) {
if ( trim ( $attribute ))
if ( ! $content -> setAttributeValue ( $this -> _dms -> getAttributeDefinition ( $attrdefid ), $attribute )) {
$this -> removeContent ( $content );
2012-10-22 13:33:30 +00:00
$db -> rollbackTransaction ();
2012-10-09 09:54:07 +00:00
return false ;
}
}
}
2010-11-18 13:53:26 +00:00
// TODO - verify
2013-01-24 08:29:58 +00:00
if ( $this -> _dms -> enableConverting && in_array ( $docResultSet -> getContent () -> getFileType (), array_keys ( $this -> _dms -> convertFileTypes )))
$docResultSet -> getContent () -> convert (); // Even if if fails, do not return false
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentStatus` (`documentID`, `version`) " .
2011-12-01 21:20:58 +00:00
" VALUES ( " . $this -> _id . " , " . ( int ) $version . " ) " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$this -> removeContent ( $content );
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$statusID = $db -> getInsertID ();
// Add reviewers into the database. Reviewers must review the document
// and submit comments, if appropriate. Reviewers can also recommend that
// a document be rejected.
$pendingReview = false ;
$reviewRes = array ();
foreach ( array ( " i " , " g " ) as $i ){
if ( isset ( $reviewers [ $i ])) {
foreach ( $reviewers [ $i ] as $reviewerID ) {
$reviewer = ( $i == " i " ? $this -> _dms -> getUser ( $reviewerID ) : $this -> _dms -> getGroup ( $reviewerID ));
2013-01-24 08:29:58 +00:00
$res = ( $i == " i " ? $docResultSet -> getContent () -> addIndReviewer ( $reviewer , $user , true ) : $docResultSet -> getContent () -> addGrpReviewer ( $reviewer , $user , true ));
2010-11-18 13:53:26 +00:00
$docResultSet -> addReviewer ( $reviewer , $i , $res );
// If no error is returned, or if the error is just due to email
// failure, mark the state as "pending review".
if ( $res == 0 || $res =- 3 || $res =- 4 ) {
$pendingReview = true ;
}
}
}
}
// Add approvers to the database. Approvers must also review the document
// and make a recommendation on its release as an approved version.
$pendingApproval = false ;
$approveRes = array ();
foreach ( array ( " i " , " g " ) as $i ){
if ( isset ( $approvers [ $i ])) {
foreach ( $approvers [ $i ] as $approverID ) {
$approver = ( $i == " i " ? $this -> _dms -> getUser ( $approverID ) : $this -> _dms -> getGroup ( $approverID ));
2013-05-07 18:16:09 +00:00
$res = ( $i == " i " ? $docResultSet -> getContent () -> addIndApprover ( $approver , $user , true ) : $docResultSet -> getContent () -> addGrpApprover ( $approver , $user , ! $pendingReview ));
2010-11-18 13:53:26 +00:00
$docResultSet -> addApprover ( $approver , $i , $res );
if ( $res == 0 || $res =- 3 || $res =- 4 ) {
$pendingApproval = true ;
}
}
}
}
// If there are no reviewers or approvers, the document is automatically
// promoted to the released state.
if ( $pendingReview ) {
$status = S_DRAFT_REV ;
$comment = " " ;
}
2013-01-24 08:29:58 +00:00
elseif ( $pendingApproval ) {
2010-11-18 13:53:26 +00:00
$status = S_DRAFT_APP ;
$comment = " " ;
}
2013-01-24 08:29:58 +00:00
elseif ( $workflow ) {
$status = S_IN_WORKFLOW ;
$comment = " , workflow: " . $workflow -> getName ();
2015-06-02 08:00:15 +00:00
} elseif ( $initstate == S_DRAFT ) {
$status = $initstate ;
$comment = " " ;
2013-01-24 08:29:58 +00:00
} else {
2010-11-18 13:53:26 +00:00
$status = S_RELEASED ;
2013-01-24 08:29:58 +00:00
$comment = " " ;
2010-11-18 13:53:26 +00:00
}
$queryStr = " INSERT INTO `tblDocumentStatusLog` (`statusID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $statusID . " ', ' " . $status . " ', 'New document content submitted " . $comment . " ', " . $db -> getCurrentDatetime () . " , ' " . $user -> getID () . " ') " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$docResultSet -> setStatus ( $status , $comment , $user );
2012-10-22 13:33:30 +00:00
$db -> commitTransaction ();
2010-11-18 13:53:26 +00:00
return $docResultSet ;
} /* }}} */
2014-11-27 12:40:58 +00:00
/**
* Replace a version of a document
*
* Each document may have any number of content elements attached to it .
* This function replaces the file content of a given version .
* Using this function is highly discourage , because it undermines the
* idea of keeping all versions of a document as originally saved .
* Content will only be replaced if the mimetype , filetype , user and
* original filename are identical to the version being updated .
*
* This function was introduced for the webdav server because any saving
* of a document created a new version .
*
* @ param object $user user who shall be the owner of this content
* @ param string $tmpFile file containing the actuall content
* @ param string $orgFileName original file name
* @ param string $fileType
* @ param string $mimeType MimeType of the content
* @ param integer $version version number of content or 0 if next higher version shall be used .
* @ return bool / array false in case of an error or a result set
*/
function replaceContent ( $version , $user , $tmpFile , $orgFileName , $fileType , $mimeType ) { /* {{{ */
$db = $this -> _dms -> getDB ();
// the doc path is id/version.filetype
$dir = $this -> getDir ();
/* If $version < 1 than replace the content of the latest version .
*/
if (( int ) $version < 1 ) {
$queryStr = " SELECT MAX(version) as m from tblDocumentContent where document = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $res )
return false ;
$version = $resArr [ 0 ][ 'm' ];
}
$content = $this -> getContentByVersion ( $version );
if ( ! $content )
return false ;
/* Check if $user, $orgFileName, $fileType and $mimetype are the same */
if ( $user -> getID () != $content -> getUser () -> getID ()) {
return false ;
}
if ( $orgFileName != $content -> getOriginalFileName ()) {
return false ;
}
if ( $fileType != $content -> getFileType ()) {
return false ;
}
if ( $mimeType != $content -> getMimeType ()) {
return false ;
}
$filesize = SeedDMS_Core_File :: fileSize ( $tmpFile );
$checksum = SeedDMS_Core_File :: checksum ( $tmpFile );
$db -> startTransaction ();
2015-09-22 05:50:36 +00:00
$queryStr = " UPDATE tblDocumentContent set date= " . $db -> getCurrentTimestamp () . " , fileSize= " . $filesize . " , checksum= " . $db -> qstr ( $checksum ) . " WHERE id= " . $content -> getID ();
2014-11-27 12:40:58 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
// copy file
if ( ! SeedDMS_Core_File :: copyFile ( $tmpFile , $this -> _dms -> contentDir . $dir . $version . $fileType )) {
$db -> rollbackTransaction ();
return false ;
}
unset ( $this -> _content );
unset ( $this -> _latestContent );
$db -> commitTransaction ();
return true ;
} /* }}} */
2010-11-30 09:27:37 +00:00
/**
* Return all content elements of a document
*
* This functions returns an array of content elements ordered by version
*
2013-02-14 11:10:53 +00:00
* @ return array list of objects of class SeedDMS_Core_DocumentContent
2010-11-30 09:27:37 +00:00
*/
2010-11-18 13:53:26 +00:00
function getContent () { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! isset ( $this -> _content )) {
$queryStr = " SELECT * FROM tblDocumentContent WHERE document = " . $this -> _id . " ORDER BY version " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $res )
2010-10-29 13:19:51 +00:00
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _content = array ();
foreach ( $resArr as $row )
2015-05-21 20:09:33 +00:00
array_push ( $this -> _content , new SeedDMS_Core_DocumentContent ( $row [ " id " ], $this , $row [ " version " ], $row [ " comment " ], $row [ " date " ], $row [ " createdBy " ], $row [ " dir " ], $row [ " orgFileName " ], $row [ " fileType " ], $row [ " mimeType " ], $row [ 'fileSize' ], $row [ 'checksum' ], $row [ 'revisiondate' ]));
2010-10-29 13:19:51 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return $this -> _content ;
} /* }}} */
2010-11-30 09:27:37 +00:00
/**
* Return the content element of a document with a given version number
*
* @ param integer $version version number of content element
2013-02-14 11:10:53 +00:00
* @ return object object of class SeedDMS_Core_DocumentContent
2010-11-30 09:27:37 +00:00
*/
2010-11-18 13:53:26 +00:00
function getContentByVersion ( $version ) { /* {{{ */
if ( ! is_numeric ( $version )) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( isset ( $this -> _content )) {
foreach ( $this -> _content as $revision ) {
if ( $revision -> getVersion () == $version )
return $revision ;
}
return false ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
$queryStr = " SELECT * FROM tblDocumentContent WHERE document = " . $this -> _id . " AND version = " . ( int ) $version ;
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $res )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$resArr = $resArr [ 0 ];
2015-05-11 07:29:34 +00:00
return new SeedDMS_Core_DocumentContent ( $resArr [ " id " ], $this , $resArr [ " version " ], $resArr [ " comment " ], $resArr [ " date " ], $resArr [ " createdBy " ], $resArr [ " dir " ], $resArr [ " orgFileName " ], $resArr [ " fileType " ], $resArr [ " mimeType " ], $resArr [ 'fileSize' ], $resArr [ 'checksum' ], $resArr [ 'revisiondate' ]);
2010-11-18 13:53:26 +00:00
} /* }}} */
function getLatestContent () { /* {{{ */
if ( ! isset ( $this -> _latestContent )) {
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM tblDocumentContent WHERE document = " . $this -> _id . " ORDER BY version DESC LIMIT 0,1 " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$resArr = $resArr [ 0 ];
2015-05-11 07:29:34 +00:00
$this -> _latestContent = new SeedDMS_Core_DocumentContent ( $resArr [ " id " ], $this , $resArr [ " version " ], $resArr [ " comment " ], $resArr [ " date " ], $resArr [ " createdBy " ], $resArr [ " dir " ], $resArr [ " orgFileName " ], $resArr [ " fileType " ], $resArr [ " mimeType " ], $resArr [ 'fileSize' ], $resArr [ 'checksum' ], $resArr [ 'revisiondate' ]);
2010-11-18 13:53:26 +00:00
}
return $this -> _latestContent ;
} /* }}} */
function removeContent ( $version ) { /* {{{ */
$db = $this -> _dms -> getDB ();
if ( file_exists ( $this -> _dms -> contentDir . $version -> getPath () ))
2013-02-14 11:10:53 +00:00
if ( ! SeedDMS_Core_File :: removeFile ( $this -> _dms -> contentDir . $version -> getPath () ))
2010-11-18 13:53:26 +00:00
return false ;
2010-11-30 09:27:37 +00:00
2012-10-22 13:33:30 +00:00
$db -> startTransaction ();
2010-11-18 13:53:26 +00:00
$status = $version -> getStatus ();
$stID = $status [ " statusID " ];
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblDocumentContent WHERE `document` = " . $this -> getID () . " AND `version` = " . $version -> _version ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-30 09:27:37 +00:00
2012-10-09 09:54:07 +00:00
$queryStr = " DELETE FROM tblDocumentContentAttributes WHERE content = " . $version -> getId ();
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2012-10-09 09:54:07 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2012-10-09 09:54:07 +00:00
2015-06-26 10:21:48 +00:00
$queryStr = " DELETE FROM `tblTransmittalItems` WHERE `document` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM `tblDocumentStatusLog` WHERE `statusID` = ' " . $stID . " ' " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM `tblDocumentStatus` WHERE `documentID` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-12 22:47:41 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
$status = $version -> getReviewStatus ();
$stList = " " ;
foreach ( $status as $st ) {
$stList .= ( strlen ( $stList ) == 0 ? " " : " , " ) . " ' " . $st [ " reviewID " ] . " ' " ;
2015-06-11 19:28:04 +00:00
$queryStr = " SELECT * FROM tblDocumentReviewLog WHERE reviewID = " . $st [ 'reviewID' ];
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr )) {
$db -> rollbackTransaction ();
return false ;
}
foreach ( $resArr as $res ) {
$file = $this -> _dms -> contentDir . $this -> getDir () . 'r' . $res [ 'reviewLogID' ];
if ( file_exists ( $file ))
SeedDMS_Core_File :: removeFile ( $file );
}
2010-11-18 13:53:26 +00:00
}
2012-10-09 09:54:07 +00:00
2010-11-18 13:53:26 +00:00
if ( strlen ( $stList ) > 0 ) {
$queryStr = " DELETE FROM `tblDocumentReviewLog` WHERE `tblDocumentReviewLog`.`reviewID` IN ( " . $stList . " ) " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
}
$queryStr = " DELETE FROM `tblDocumentReviewers` WHERE `documentID` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$status = $version -> getApprovalStatus ();
$stList = " " ;
foreach ( $status as $st ) {
$stList .= ( strlen ( $stList ) == 0 ? " " : " , " ) . " ' " . $st [ " approveID " ] . " ' " ;
2015-06-11 19:28:04 +00:00
$queryStr = " SELECT * FROM tblDocumentApproveLog WHERE approveID = " . $st [ 'approveID' ];
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr )) {
$db -> rollbackTransaction ();
return false ;
}
foreach ( $resArr as $res ) {
$file = $this -> _dms -> contentDir . $this -> getDir () . 'a' . $res [ 'approveLogID' ];
if ( file_exists ( $file ))
SeedDMS_Core_File :: removeFile ( $file );
}
2010-11-18 13:53:26 +00:00
}
2015-06-11 19:28:04 +00:00
2010-11-18 13:53:26 +00:00
if ( strlen ( $stList ) > 0 ) {
$queryStr = " DELETE FROM `tblDocumentApproveLog` WHERE `tblDocumentApproveLog`.`approveID` IN ( " . $stList . " ) " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
}
$queryStr = " DELETE FROM `tblDocumentApprovers` WHERE `documentID` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
2015-06-26 10:21:48 +00:00
/* Remove all receipts of document version .
* This implmentation is different from the above for removing approvals
* and reviews . It doesn ' t use getReceiptStatus () but reads the database
*/
$queryStr = " SELECT * FROM tblDocumentRecipients WHERE documentID = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr )) {
$db -> rollbackTransaction ();
return false ;
}
$stList = array ();
foreach ( $resArr as $res ) {
$stList [] = $res [ 'receiptID' ];
}
if ( $stList ) {
$queryStr = " DELETE FROM `tblDocumentReceiptLog` WHERE `receiptID` IN ( " . implode ( ',' , $stList ) . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " DELETE FROM `tblDocumentRecipients` WHERE `receiptID` IN ( " . implode ( ',' , $stList ) . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
/* Remove all revisions of document version .
* This implmentation is different from the above for removing approvals
* and reviews . It doesn ' t use getRevisionStatus () but reads the database
*/
$queryStr = " SELECT * FROM tblDocumentRevisors WHERE documentID = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr )) {
$db -> rollbackTransaction ();
return false ;
}
$stList = array ();
foreach ( $resArr as $res ) {
$stList [] = $res [ 'revisionID' ];
}
if ( $stList ) {
$queryStr = " DELETE FROM `tblDocumentRevisionLog` WHERE `revisionID` IN ( " . implode ( ',' , $stList ) . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " DELETE FROM `tblDocumentRevisors` WHERE `revisionID` IN ( " . implode ( ',' , $stList ) . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
2013-01-24 08:29:58 +00:00
$queryStr = " DELETE FROM `tblWorkflowDocumentContent` WHERE `document` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2015-03-27 16:15:21 +00:00
$queryStr = " DELETE FROM `tblWorkflowLog` WHERE `document` = ' " . $this -> getID () . " ' AND `version` = ' " . $version -> _version . " ' " ;
2013-01-24 08:29:58 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2012-10-22 13:33:30 +00:00
$db -> commitTransaction ();
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2013-04-10 13:39:50 +00:00
/**
* Return a certain document link
*
* @ param integer $linkID id of link
* @ return object instance of SeedDMS_Core_DocumentLink or false in case of
* an error .
*/
2010-11-18 13:53:26 +00:00
function getDocumentLink ( $linkID ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! is_numeric ( $linkID )) return false ;
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " SELECT * FROM tblDocumentLinks WHERE document = " . $this -> _id . " AND id = " . ( int ) $linkID ;
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr ) || count ( $resArr ) == 0 )
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$resArr = $resArr [ 0 ];
$document = $this -> _dms -> getDocument ( $resArr [ " document " ]);
$target = $this -> _dms -> getDocument ( $resArr [ " target " ]);
2013-02-14 11:10:53 +00:00
return new SeedDMS_Core_DocumentLink ( $resArr [ " id " ], $document , $target , $resArr [ " userID " ], $resArr [ " public " ]);
2010-11-18 13:53:26 +00:00
} /* }}} */
2013-04-10 13:39:50 +00:00
/**
* Return all document links
*
2014-03-18 06:03:40 +00:00
* The list may contain all links to other documents , even those which
* may not be visible by certain users , unless you pass appropriate
* parameters to filter out public links and those created by
* the given user . The application may call
2013-04-10 13:39:50 +00:00
* SeedDMS_Core_DMS :: filterDocumentLinks () afterwards .
*
2014-03-18 06:03:40 +00:00
* @ param boolean $publiconly return on publically visible links
* @ param object $user return also private links of this user
2013-04-10 13:39:50 +00:00
* @ return array list of objects of class SeedDMS_Core_DocumentLink
*/
2014-03-18 06:03:40 +00:00
function getDocumentLinks ( $publiconly = false , $user = null ) { /* {{{ */
2010-11-18 13:53:26 +00:00
if ( ! isset ( $this -> _documentLinks )) {
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " SELECT * FROM tblDocumentLinks WHERE document = " . $this -> _id ;
2014-03-18 06:03:40 +00:00
$tmp = array ();
if ( $publiconly )
$tmp [] = " public=1 " ;
if ( $user )
$tmp [] = " userID= " . $user -> getID ();
if ( $tmp ) {
$queryStr .= " AND ( " . implode ( " OR " , $tmp ) . " ) " ;
}
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$this -> _documentLinks = array ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
foreach ( $resArr as $row ) {
$target = $this -> _dms -> getDocument ( $row [ " target " ]);
2013-02-14 11:10:53 +00:00
array_push ( $this -> _documentLinks , new SeedDMS_Core_DocumentLink ( $row [ " id " ], $this , $target , $row [ " userID " ], $row [ " public " ]));
2010-11-18 13:53:26 +00:00
}
}
return $this -> _documentLinks ;
} /* }}} */
2014-03-18 06:03:40 +00:00
/**
* Return all document having a link on this document
*
* The list contains all documents which have a link to the current
* document . The list contains even those documents which
* may not be accessible by the user , unless you pass appropriate
* parameters to filter out public links and those created by
* the given user .
* This functions is basically the reverse of
* SeedDMS_Core_Document :: getDocumentLinks ()
*
* The application may call
* SeedDMS_Core_DMS :: filterDocumentLinks () afterwards .
*
* @ param boolean $publiconly return on publically visible links
* @ param object $user return also private links of this user
* @ return array list of objects of class SeedDMS_Core_DocumentLink
*/
function getReverseDocumentLinks ( $publiconly = false , $user = null ) { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT * FROM tblDocumentLinks WHERE target = " . $this -> _id ;
$tmp = array ();
if ( $publiconly )
$tmp [] = " public=1 " ;
if ( $user )
$tmp [] = " userID= " . $user -> getID ();
if ( $tmp ) {
$queryStr .= " AND ( " . implode ( " OR " , $tmp ) . " ) " ;
}
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$links = array ();
foreach ( $resArr as $row ) {
$document = $this -> _dms -> getDocument ( $row [ " document " ]);
array_push ( $links , new SeedDMS_Core_DocumentLink ( $row [ " id " ], $document , $this , $row [ " userID " ], $row [ " public " ]));
}
return $links ;
} /* }}} */
2010-11-18 13:53:26 +00:00
function addDocumentLink ( $targetID , $userID , $public ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$public = ( $public ) ? " 1 " : " 0 " ;
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " INSERT INTO tblDocumentLinks(document, target, userID, public) VALUES ( " . $this -> _id . " , " . ( int ) $targetID . " , " . ( int ) $userID . " , " . ( int ) $public . " ) " ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
unset ( $this -> _documentLinks );
return true ;
} /* }}} */
function removeDocumentLink ( $linkID ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
if ( ! is_numeric ( $linkID )) return false ;
$queryStr = " DELETE FROM tblDocumentLinks WHERE document = " . $this -> _id . " AND id = " . ( int ) $linkID ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr )) return false ;
unset ( $this -> _documentLinks );
return true ;
} /* }}} */
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
function getDocumentFile ( $ID ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! is_numeric ( $ID )) return false ;
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " SELECT * FROM tblDocumentFiles WHERE document = " . $this -> _id . " AND id = " . ( int ) $ID ;
2010-11-18 13:53:26 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if (( is_bool ( $resArr ) && ! $resArr ) || count ( $resArr ) == 0 ) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
return new SeedDMS_Core_DocumentFile ( $resArr [ " id " ], $this , $resArr [ " userID " ], $resArr [ " comment " ], $resArr [ " date " ], $resArr [ " dir " ], $resArr [ " fileType " ], $resArr [ " mimeType " ], $resArr [ " orgFileName " ], $resArr [ " name " ]);
2010-11-18 13:53:26 +00:00
} /* }}} */
function getDocumentFiles () { /* {{{ */
if ( ! isset ( $this -> _documentFiles )) {
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " SELECT * FROM tblDocumentFiles WHERE document = " . $this -> _id . " ORDER BY `date` DESC " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$this -> _documentFiles = array ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
foreach ( $resArr as $row ) {
2013-02-14 11:10:53 +00:00
array_push ( $this -> _documentFiles , new SeedDMS_Core_DocumentFile ( $row [ " id " ], $this , $row [ " userID " ], $row [ " comment " ], $row [ " date " ], $row [ " dir " ], $row [ " fileType " ], $row [ " mimeType " ], $row [ " orgFileName " ], $row [ " name " ]));
2010-11-18 13:53:26 +00:00
}
}
2010-11-30 09:27:37 +00:00
return $this -> _documentFiles ;
2010-11-18 13:53:26 +00:00
} /* }}} */
function addDocumentFile ( $name , $comment , $user , $tmpFile , $orgFileName , $fileType , $mimeType ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$dir = $this -> getDir ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO tblDocumentFiles (comment, date, dir, document, fileType, mimeType, orgFileName, userID, name) VALUES " .
2015-09-22 05:50:36 +00:00
" ( " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentTimestamp () . " , " . $db -> qstr ( $dir ) . " , " . $this -> _id . " , " . $db -> qstr ( $fileType ) . " , " . $db -> qstr ( $mimeType ) . " , " . $db -> qstr ( $orgFileName ) . " , " . $user -> getID () . " , " . $db -> qstr ( $name ) . " ) " ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr )) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$id = $db -> getInsertID ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$file = $this -> getDocumentFile ( $id );
if ( is_bool ( $file ) && ! $file ) return false ;
// copy file
2013-02-14 11:10:53 +00:00
if ( ! SeedDMS_Core_File :: makeDir ( $this -> _dms -> contentDir . $dir )) return false ;
2014-11-24 14:08:37 +00:00
if ( $this -> _dms -> forceRename )
$err = SeedDMS_Core_File :: renameFile ( $tmpFile , $this -> _dms -> contentDir . $file -> getPath ());
else
$err = SeedDMS_Core_File :: copyFile ( $tmpFile , $this -> _dms -> contentDir . $file -> getPath ());
if ( ! $err ) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
function removeDocumentFile ( $ID ) { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
if ( ! is_numeric ( $ID )) return false ;
2010-11-18 13:53:26 +00:00
$file = $this -> getDocumentFile ( $ID );
if ( is_bool ( $file ) && ! $file ) return false ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( file_exists ( $this -> _dms -> contentDir . $file -> getPath () )){
2013-02-14 11:10:53 +00:00
if ( ! SeedDMS_Core_File :: removeFile ( $this -> _dms -> contentDir . $file -> getPath () ))
2010-11-18 13:53:26 +00:00
return false ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$name = $file -> getName ();
$comment = $file -> getcomment ();
2010-11-30 09:27:37 +00:00
2011-12-01 21:20:58 +00:00
$queryStr = " DELETE FROM tblDocumentFiles WHERE document = " . $this -> getID () . " AND id = " . ( int ) $ID ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
unset ( $this -> _documentFiles );
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2012-10-22 13:33:30 +00:00
/**
* Remove a document completly
*
2013-01-24 08:29:58 +00:00
* This methods calls the callback 'onPreRemoveDocument' before removing
* the document . The current document will be passed as the second
* parameter to the callback function . After successful deletion the
* 'onPostRemoveDocument' callback will be used . The current document id
* will be passed as the second parameter . If onPreRemoveDocument fails
* the whole function will fail and the document will not be deleted .
* The return value of 'onPostRemoveDocument' will be disregarded .
*
2012-10-22 13:33:30 +00:00
* @ return boolean true on success , otherwise false
*/
2010-11-18 13:53:26 +00:00
function remove () { /* {{{ */
$db = $this -> _dms -> getDB ();
2010-11-30 09:27:37 +00:00
2013-01-24 08:29:58 +00:00
/* Check if 'onPreRemoveDocument' callback is set */
if ( isset ( $this -> _dms -> callbacks [ 'onPreRemoveDocument' ])) {
$callback = $this -> _dms -> callbacks [ 'onPreRemoveDocument' ];
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $this )) {
return false ;
}
}
2010-11-18 13:53:26 +00:00
$res = $this -> getContent ();
if ( is_bool ( $res ) && ! $res ) return false ;
2012-10-22 13:33:30 +00:00
$db -> startTransaction ();
2010-11-18 13:53:26 +00:00
// FIXME: call a new function removeContent instead
2012-10-22 13:33:30 +00:00
foreach ( $this -> _content as $version ) {
if ( ! $this -> removeContent ( $version )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
}
2010-11-18 13:53:26 +00:00
// remove document file
$res = $this -> getDocumentFiles ();
2012-10-22 13:33:30 +00:00
if ( is_bool ( $res ) && ! $res ) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
foreach ( $res as $documentfile )
2012-10-22 13:33:30 +00:00
if ( ! $this -> removeDocumentFile ( $documentfile -> getId ())) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
// TODO: versioning file?
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( file_exists ( $this -> _dms -> contentDir . $this -> getDir () ))
2013-02-14 11:10:53 +00:00
if ( ! SeedDMS_Core_File :: removeDir ( $this -> _dms -> contentDir . $this -> getDir () )) {
2012-10-22 13:33:30 +00:00
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblDocuments WHERE id = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2012-10-09 09:54:07 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2012-10-09 09:54:07 +00:00
$queryStr = " DELETE FROM tblDocumentAttributes WHERE document = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblACLs WHERE target = " . $this -> _id . " AND targetType = " . T_DOCUMENT ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblDocumentLinks WHERE document = " . $this -> _id . " OR target = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblDocumentLocks WHERE document = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2015-04-17 18:08:06 +00:00
$queryStr = " DELETE FROM tblDocumentCheckOuts WHERE document = " . $this -> _id ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
2010-11-18 13:53:26 +00:00
$queryStr = " DELETE FROM tblDocumentFiles WHERE document = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2011-03-10 14:28:21 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2011-03-10 14:28:21 +00:00
$queryStr = " DELETE FROM tblDocumentCategory WHERE documentID = " . $this -> _id ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
// Delete the notification list.
$queryStr = " DELETE FROM tblNotify WHERE target = " . $this -> _id . " AND targetType = " . T_DOCUMENT ;
2012-10-22 13:33:30 +00:00
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
2010-11-18 13:53:26 +00:00
return false ;
2012-10-22 13:33:30 +00:00
}
2010-11-18 13:53:26 +00:00
2012-10-22 13:33:30 +00:00
$db -> commitTransaction ();
2013-01-24 08:29:58 +00:00
/* Check if 'onPostRemoveDocument' callback is set */
if ( isset ( $this -> _dms -> callbacks [ 'onPostRemoveDocument' ])) {
$callback = $this -> _dms -> callbacks [ 'onPostRemoveDocument' ];
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $this -> _id )) {
}
}
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2013-02-11 13:55:51 +00:00
/**
* Get List of users and groups which have read access on the document
2014-03-18 06:03:40 +00:00
* The list will not include any guest users ,
* administrators and the owner of the folder unless $listadmin resp .
* $listowner is set to true .
2013-02-11 13:55:51 +00:00
*
* This function is deprecated . Use
2013-02-14 11:10:53 +00:00
* { @ see SeedDMS_Core_Document :: getReadAccessList ()} instead .
2013-02-11 13:55:51 +00:00
*/
2010-11-18 13:53:26 +00:00
function getApproversList () { /* {{{ */
2013-02-27 08:06:45 +00:00
return $this -> getReadAccessList ( 0 , 0 );
2013-02-11 13:55:51 +00:00
} /* }}} */
2013-02-27 08:06:45 +00:00
/**
* Returns a list of groups and users with read access on the document
*
* @ param boolean $listadmin if set to true any admin will be listed too
* @ param boolean $listowner if set to true the owner will be listed too
*
* @ return array list of users and groups
*/
function getReadAccessList ( $listadmin = 0 , $listowner = 0 ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _dms -> getDB ();
2013-02-11 13:55:51 +00:00
if ( ! isset ( $this -> _readAccessList )) {
$this -> _readAccessList = array ( " groups " => array (), " users " => array ());
2010-11-18 13:53:26 +00:00
$userIDs = " " ;
$groupIDs = " " ;
$defAccess = $this -> getDefaultAccess ();
if ( $defAccess < M_READ ) {
// Get the list of all users and groups that are listed in the ACL as
// having read access to the document.
$tmpList = $this -> getAccessList ( M_READ , O_GTEQ );
}
else {
// Get the list of all users and groups that DO NOT have read access
// to the document.
$tmpList = $this -> getAccessList ( M_NONE , O_LTEQ );
}
2013-02-11 13:55:51 +00:00
foreach ( $tmpList [ " groups " ] as $groupAccess ) {
$groupIDs .= ( strlen ( $groupIDs ) == 0 ? " " : " , " ) . $groupAccess -> getGroupID ();
2010-11-18 13:53:26 +00:00
}
2013-02-11 13:55:51 +00:00
foreach ( $tmpList [ " users " ] as $userAccess ) {
$user = $userAccess -> getUser ();
2013-02-27 08:06:45 +00:00
if ( ! $listadmin && $user -> isAdmin ()) continue ;
if ( ! $listowner && $user -> getID () == $this -> _ownerID ) continue ;
2013-02-11 13:55:51 +00:00
if ( $user -> isGuest ()) continue ;
$userIDs .= ( strlen ( $userIDs ) == 0 ? " " : " , " ) . $userAccess -> getUserID ();
2010-11-18 13:53:26 +00:00
}
// Construct a query against the users table to identify those users
// that have read access to this document, either directly through an
// ACL entry, by virtue of ownership or by having administrative rights
// on the database.
$queryStr = " " ;
2013-02-11 13:55:51 +00:00
/* If default access is less then read , $userIDs and $groupIDs contains
* a list of user with read access
*/
2010-11-18 13:53:26 +00:00
if ( $defAccess < M_READ ) {
if ( strlen ( $groupIDs ) > 0 ) {
2013-02-11 13:55:51 +00:00
$queryStr = " SELECT `tblUsers`.* FROM `tblUsers` " .
2010-11-18 13:53:26 +00:00
" LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` " .
" WHERE `tblGroupMembers`.`groupID` IN ( " . $groupIDs . " ) " .
2013-02-14 11:10:53 +00:00
" AND `tblUsers`.`role` != " . SeedDMS_Core_User :: role_guest . " UNION " ;
2010-11-18 13:53:26 +00:00
}
2013-02-11 13:55:51 +00:00
$queryStr .=
" SELECT `tblUsers`.* FROM `tblUsers` " .
2013-02-14 11:10:53 +00:00
" WHERE (`tblUsers`.`role` != " . SeedDMS_Core_User :: role_guest . " ) " .
2010-11-18 13:53:26 +00:00
" AND ((`tblUsers`.`id` = " . $this -> _ownerID . " ) " .
2013-02-14 11:10:53 +00:00
" OR (`tblUsers`.`role` = " . SeedDMS_Core_User :: role_admin . " ) " .
2010-11-18 13:53:26 +00:00
( strlen ( $userIDs ) == 0 ? " " : " OR (`tblUsers`.`id` IN ( " . $userIDs . " )) " ) .
2013-02-11 13:55:51 +00:00
" ) ORDER BY `login` " ;
2010-11-18 13:53:26 +00:00
}
2013-02-11 13:55:51 +00:00
/* If default access is equal or greate then read , $userIDs and
* $groupIDs contains a list of user without read access
*/
2010-11-18 13:53:26 +00:00
else {
if ( strlen ( $groupIDs ) > 0 ) {
2013-02-11 13:55:51 +00:00
$queryStr = " SELECT `tblUsers`.* FROM `tblUsers` " .
2010-11-18 13:53:26 +00:00
" LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` " .
" WHERE `tblGroupMembers`.`groupID` NOT IN ( " . $groupIDs . " ) " .
2013-02-14 11:10:53 +00:00
" AND `tblUsers`.`role` != " . SeedDMS_Core_User :: role_guest . " " .
2013-02-11 13:55:51 +00:00
( strlen ( $userIDs ) == 0 ? " " : " AND (`tblUsers`.`id` NOT IN ( " . $userIDs . " )) " ) . " UNION " ;
2010-11-18 13:53:26 +00:00
}
2013-02-11 13:55:51 +00:00
$queryStr .=
" SELECT `tblUsers`.* FROM `tblUsers` " .
2010-11-18 13:53:26 +00:00
" WHERE (`tblUsers`.`id` = " . $this -> _ownerID . " ) " .
2013-02-14 11:10:53 +00:00
" OR (`tblUsers`.`role` = " . SeedDMS_Core_User :: role_admin . " ) " .
2010-11-18 13:53:26 +00:00
" UNION " .
2013-02-11 13:55:51 +00:00
" SELECT `tblUsers`.* FROM `tblUsers` " .
2013-02-14 11:10:53 +00:00
" WHERE `tblUsers`.`role` != " . SeedDMS_Core_User :: role_guest . " " .
2013-02-11 13:55:51 +00:00
( strlen ( $userIDs ) == 0 ? " " : " AND (`tblUsers`.`id` NOT IN ( " . $userIDs . " )) " ) .
2012-09-11 12:59:47 +00:00
" ORDER BY `login` " ;
2010-11-18 13:53:26 +00:00
}
$resArr = $db -> getResultArray ( $queryStr );
if ( ! is_bool ( $resArr )) {
foreach ( $resArr as $row ) {
2010-11-22 14:51:44 +00:00
$user = $this -> _dms -> getUser ( $row [ 'id' ]);
2013-02-27 08:06:45 +00:00
if ( ! $listadmin && $user -> isAdmin ()) continue ;
if ( ! $listowner && $user -> getID () == $this -> _ownerID ) continue ;
2013-02-11 13:55:51 +00:00
$this -> _readAccessList [ " users " ][] = $user ;
2010-11-18 13:53:26 +00:00
}
}
// Assemble the list of groups that have read access to the document.
$queryStr = " " ;
if ( $defAccess < M_READ ) {
if ( strlen ( $groupIDs ) > 0 ) {
$queryStr = " SELECT `tblGroups`.* FROM `tblGroups` " .
" WHERE `tblGroups`.`id` IN ( " . $groupIDs . " ) " ;
}
}
else {
if ( strlen ( $groupIDs ) > 0 ) {
$queryStr = " SELECT `tblGroups`.* FROM `tblGroups` " .
" WHERE `tblGroups`.`id` NOT IN ( " . $groupIDs . " ) " ;
}
else {
$queryStr = " SELECT `tblGroups`.* FROM `tblGroups` " ;
}
}
if ( strlen ( $queryStr ) > 0 ) {
$resArr = $db -> getResultArray ( $queryStr );
if ( ! is_bool ( $resArr )) {
foreach ( $resArr as $row ) {
2011-02-08 09:00:07 +00:00
$group = $this -> _dms -> getGroup ( $row [ " id " ]);
2013-02-11 13:55:51 +00:00
$this -> _readAccessList [ " groups " ][] = $group ;
2010-11-18 13:53:26 +00:00
}
}
}
}
2013-02-11 13:55:51 +00:00
return $this -> _readAccessList ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2011-11-28 14:03:01 +00:00
/**
* Get the internally used folderList which stores the ids of folders from
* the root folder to the parent folder .
*
* @ return string column separated list of folder ids
*/
function getFolderList () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT folderList FROM tblDocuments where id = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
return $resArr [ 0 ][ 'folderList' ];
} /* }}} */
/**
* Checks the internal data of the document and repairs it .
* Currently , this function only repairs an incorrect folderList
*
* @ return boolean true on success , otherwise false
*/
function repair () { /* {{{ */
$db = $this -> _dms -> getDB ();
$curfolderlist = $this -> getFolderList ();
// calculate the folderList of the folder
$parent = $this -> getFolder ();
$pathPrefix = " " ;
$path = $parent -> getPath ();
foreach ( $path as $f ) {
$pathPrefix .= " : " . $f -> getID ();
}
if ( strlen ( $pathPrefix ) > 1 ) {
$pathPrefix .= " : " ;
}
if ( $curfolderlist != $pathPrefix ) {
$queryStr = " UPDATE tblDocuments SET folderList=' " . $pathPrefix . " ' WHERE id = " . $this -> _id ;
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
}
return true ;
} /* }}} */
2013-02-06 13:52:11 +00:00
/**
* Calculate the disk space including all versions of the document
*
* This is done by using the internal database field storing the
* filesize of a document version .
*
* @ return integer total disk space in Bytes
*/
function getUsedDiskSpace () { /* {{{ */
$db = $this -> _dms -> getDB ();
$queryStr = " SELECT SUM(filesize) sum FROM tblDocumentContent WHERE document = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
return $resArr [ 0 ][ 'sum' ];
} /* }}} */
2015-09-16 19:19:46 +00:00
/**
* Returns a list of events happend during the life of the document
*
* This includes the creation of new versions , approval and reviews , etc .
*
* @ return array list of events
*/
function getTimeline () { /* {{{ */
$db = $this -> _dms -> getDB ();
$timeline = array ();
$queryStr = " SELECT * FROM tblDocumentContent WHERE document = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
foreach ( $resArr as $row ) {
$date = date ( 'Y-m-d H:i:s' , $row [ 'date' ]);
2015-09-21 14:46:17 +00:00
$timeline [] = array ( 'date' => $date , 'msg' => 'Added version ' . $row [ 'version' ], 'type' => 'add_version' , 'version' => $row [ 'version' ], 'document' => $this , 'params' => array ( $row [ 'version' ]));
2015-09-16 19:19:46 +00:00
}
$queryStr = " SELECT * FROM tblDocumentFiles WHERE document = " . $this -> _id ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
foreach ( $resArr as $row ) {
$date = date ( 'Y-m-d H:i:s' , $row [ 'date' ]);
2015-09-21 14:46:17 +00:00
$timeline [] = array ( 'date' => $date , 'msg' => 'Added attachment "' . $row [ 'name' ] . '"' , 'document' => $this , 'type' => 'add_file' );
2015-09-16 19:19:46 +00:00
}
$queryStr =
" SELECT `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, " .
" `tblDocumentStatusLog`.`comment`, `tblDocumentStatusLog`.`date`, " .
" `tblDocumentStatusLog`.`userID` " .
" FROM `tblDocumentStatus` " .
" LEFT JOIN `tblDocumentStatusLog` USING (`statusID`) " .
" WHERE `tblDocumentStatus`.`documentID` = ' " . $this -> _id . " ' " .
" ORDER BY `tblDocumentStatusLog`.`statusLogID` DESC " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
foreach ( $resArr as $row ) {
$date = $row [ 'date' ];
2015-09-21 14:46:17 +00:00
$timeline [] = array ( 'date' => $date , 'msg' => 'Version ' . $row [ 'version' ] . ': Status change to ' . $row [ 'status' ], 'type' => 'status_change' , 'version' => $row [ 'version' ], 'document' => $this , 'status' => $row [ 'status' ], 'params' => array ( $row [ 'version' ], $row [ 'status' ]));
2015-09-16 19:19:46 +00:00
}
return $timeline ;
} /* }}} */
2010-11-18 13:53:26 +00:00
} /* }}} */
/**
2010-11-30 12:23:46 +00:00
* Class to represent content of a document
*
* Each document has content attached to it , often called a 'version' of the
* document . The document content represents a file on the disk with some
* meta data stored in the database . A document content has a version number
* which is incremented with each replacement of the old content . Old versions
* are kept unless they are explicitly deleted by
2013-02-14 11:10:53 +00:00
* { @ link SeedDMS_Core_Document :: removeContent ()} .
2010-11-30 12:23:46 +00:00
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ 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 @
2010-11-18 13:53:26 +00:00
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
/**
* Recalculate the status of a document
* The methods checks the review and approval status and sets the
* status of the document accordingly .
2013-01-28 10:14:13 +00:00
* If status is S_RELEASED and version has workflow set status
* to S_IN_WORKFLOW
2013-01-24 08:29:58 +00:00
* If status is S_RELEASED and there are reviewers set status S_DRAFT_REV
* If status is S_RELEASED or S_DRAFT_REV and there are approvers set
* status S_DRAFT_APP
* If status is draft and there are no approver and no reviewers set
* status to S_RELEASED
* The status of a document with the current status S_OBSOLETE , S_REJECTED ,
* or S_EXPIRED will not be changed unless the parameter
* $ignorecurrentstatus is set to true .
2015-05-04 06:27:20 +00:00
* This method will call { @ see SeedDMS_Core_DocumentContent :: setStatus ()}
* which checks if the state has actually changed . This is , why this
* function can be called at any time without harm to the status log .
2013-01-24 08:29:58 +00:00
*
* @ param boolean $ignorecurrentstatus ignore the current status and
* recalculate a new status in any case
* @ param object $user the user initiating this method
2015-05-04 06:27:20 +00:00
* @ param string $msg message stored in status log when status is set
2013-01-24 08:29:58 +00:00
*/
2015-05-04 06:27:20 +00:00
function verifyStatus ( $ignorecurrentstatus = false , $user = null , $msg = '' ) { /* {{{ */
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
unset ( $this -> _status );
$st = $this -> getStatus ();
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! $ignorecurrentstatus && ( $st [ " status " ] == S_OBSOLETE || $st [ " status " ] == S_REJECTED || $st [ " status " ] == S_EXPIRED )) return ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$pendingReview = false ;
unset ( $this -> _reviewStatus ); // force to be reloaded from DB
2012-09-13 13:59:35 +00:00
$reviewStatus = $this -> getReviewStatus ();
2010-11-18 13:53:26 +00:00
if ( is_array ( $reviewStatus ) && count ( $reviewStatus ) > 0 ) {
foreach ( $reviewStatus as $r ){
2010-11-30 09:27:37 +00:00
if ( $r [ " status " ] == 0 ){
2010-11-18 13:53:26 +00:00
$pendingReview = true ;
break ;
}
}
}
2010-11-30 09:27:37 +00:00
$pendingApproval = false ;
2010-11-18 13:53:26 +00:00
unset ( $this -> _approvalStatus ); // force to be reloaded from DB
2012-09-13 13:59:35 +00:00
$approvalStatus = $this -> getApprovalStatus ();
2010-11-18 13:53:26 +00:00
if ( is_array ( $approvalStatus ) && count ( $approvalStatus ) > 0 ) {
foreach ( $approvalStatus as $a ){
if ( $a [ " status " ] == 0 ){
$pendingApproval = true ;
break ;
}
}
}
2015-05-11 07:29:34 +00:00
$pendingRevision = false ;
unset ( $this -> _revisionStatus ); // force to be reloaded from DB
$revsisionStatus = $this -> getRevisionStatus ();
if ( is_array ( $revsisionStatus ) && count ( $revsisionStatus ) > 0 ) {
foreach ( $revsisionStatus as $a ){
if ( $a [ " status " ] == 0 ){
$pendingRevision = true ;
break ;
}
}
}
2012-10-09 09:54:07 +00:00
2013-01-28 10:14:13 +00:00
unset ( $this -> _workflow ); // force to be reloaded from DB
2015-05-04 06:38:46 +00:00
if ( $this -> getWorkflow ()) $this -> setStatus ( S_IN_WORKFLOW , $msg , $user );
elseif ( $pendingReview ) $this -> setStatus ( S_DRAFT_REV , $msg , $user );
elseif ( $pendingApproval ) $this -> setStatus ( S_DRAFT_APP , $msg , $user );
2015-05-11 07:29:34 +00:00
elseif ( $pendingRevision ) $this -> setStatus ( S_IN_REVISION , $msg , $user );
2015-05-04 06:38:46 +00:00
else $this -> setStatus ( S_RELEASED , $msg , $user );
2010-11-18 13:53:26 +00:00
} /* }}} */
2015-05-11 07:29:34 +00:00
function SeedDMS_Core_DocumentContent ( $id , $document , $version , $comment , $date , $userID , $dir , $orgFileName , $fileType , $mimeType , $fileSize = 0 , $checksum = '' , $revisionDate = null ) { /* {{{ */
2012-10-09 09:54:07 +00:00
parent :: __construct ( $id );
2010-11-18 13:53:26 +00:00
$this -> _document = $document ;
2011-12-01 21:20:58 +00:00
$this -> _version = ( int ) $version ;
2010-11-18 13:53:26 +00:00
$this -> _comment = $comment ;
$this -> _date = $date ;
2011-12-01 21:20:58 +00:00
$this -> _userID = ( int ) $userID ;
2010-11-18 13:53:26 +00:00
$this -> _dir = $dir ;
$this -> _orgFileName = $orgFileName ;
$this -> _fileType = $fileType ;
$this -> _mimeType = $mimeType ;
2012-10-09 09:54:07 +00:00
$this -> _dms = $document -> _dms ;
2012-12-19 10:26:44 +00:00
if ( ! $fileSize ) {
2013-02-14 11:10:53 +00:00
$this -> _fileSize = SeedDMS_Core_File :: fileSize ( $this -> _dms -> contentDir . $this -> getPath ());
2012-12-19 10:26:44 +00:00
} else {
$this -> _fileSize = $fileSize ;
}
2013-02-08 15:04:49 +00:00
$this -> _checksum = $checksum ;
2013-01-24 08:29:58 +00:00
$this -> _workflow = null ;
$this -> _workflowState = null ;
2015-05-11 07:29:34 +00:00
$this -> _revisionDate = $revisionDate ;
2010-11-18 13:53:26 +00:00
} /* }}} */
function getVersion () { return $this -> _version ; }
function getComment () { return $this -> _comment ; }
function getDate () { return $this -> _date ; }
function getOriginalFileName () { return $this -> _orgFileName ; }
function getFileType () { return $this -> _fileType ; }
2012-12-19 10:26:44 +00:00
function getFileName (){ return $this -> _version . $this -> _fileType ; }
2010-11-18 13:53:26 +00:00
function getDir () { return $this -> _dir ; }
function getMimeType () { return $this -> _mimeType ; }
2015-05-11 07:29:34 +00:00
function getRevisionDate () { return $this -> _revisionDate ; }
2012-10-09 09:54:07 +00:00
function getDocument () { return $this -> _document ; }
2010-11-18 13:53:26 +00:00
function getUser () { /* {{{ */
if ( ! isset ( $this -> _user ))
$this -> _user = $this -> _document -> _dms -> getUser ( $this -> _userID );
return $this -> _user ;
} /* }}} */
2012-10-09 09:54:07 +00:00
2012-03-28 06:32:14 +00:00
function getPath () { return $this -> _document -> getDir () . $this -> _version . $this -> _fileType ; }
2010-11-30 09:27:37 +00:00
2015-05-11 07:29:34 +00:00
function setRevisionDate ( $date = false ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $date )
2015-05-12 17:07:59 +00:00
$queryStr = " UPDATE tblDocumentContent SET revisiondate = null WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
elseif ( $date == 'now' )
$queryStr = " UPDATE tblDocumentContent SET revisiondate = CURRENT_TIMESTAMP WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
else
$queryStr = " UPDATE tblDocumentContent SET revisiondate = " . $db -> qstr ( $date ) . " WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
2015-05-11 07:29:34 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _revisionDate = $date ;
return true ;
} /* }}} */
2013-02-08 15:04:49 +00:00
function setDate ( $date = false ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $date )
$date = time ();
2015-09-22 05:50:36 +00:00
else {
if ( ! is_numeric ( $date ))
return false ;
}
2013-02-08 15:04:49 +00:00
$queryStr = " UPDATE tblDocumentContent SET date = " . ( int ) $date . " WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _date = $date ;
return true ;
} /* }}} */
2013-01-24 08:29:58 +00:00
function getFileSize () { /* {{{ */
2012-12-19 10:26:44 +00:00
return $this -> _fileSize ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2012-12-19 10:26:44 +00:00
2013-02-08 15:04:49 +00:00
/**
* Set file size by reading the file
*/
2013-01-24 08:29:58 +00:00
function setFileSize () { /* {{{ */
2013-02-14 11:10:53 +00:00
$filesize = SeedDMS_Core_File :: fileSize ( $this -> _dms -> contentDir . $this -> _document -> getDir () . $this -> getFileName ());
2013-02-08 15:04:49 +00:00
if ( $filesize === false )
2012-12-19 10:26:44 +00:00
return false ;
$db = $this -> _document -> _dms -> getDB ();
$queryStr = " UPDATE tblDocumentContent SET fileSize = " . $filesize . " where `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _fileSize = $filesize ;
return true ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2012-12-19 10:26:44 +00:00
2013-02-08 15:04:49 +00:00
function getChecksum () { /* {{{ */
return $this -> _checksum ;
} /* }}} */
/**
* Set checksum by reading the file
*/
function setChecksum () { /* {{{ */
2013-02-14 11:10:53 +00:00
$checksum = SeedDMS_Core_File :: checksum ( $this -> _dms -> contentDir . $this -> _document -> getDir () . $this -> getFileName ());
2013-02-08 15:04:49 +00:00
if ( $checksum === false )
return false ;
$db = $this -> _document -> _dms -> getDB ();
$queryStr = " UPDATE tblDocumentContent SET checksum = " . $db -> qstr ( $checksum ) . " where `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _checksum = $checksum ;
return true ;
} /* }}} */
2010-11-18 13:53:26 +00:00
function setComment ( $newComment ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
$queryStr = " UPDATE tblDocumentContent SET comment = " . $db -> qstr ( $newComment ) . " WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version ;
2010-11-18 13:53:26 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
$this -> _comment = $newComment ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2012-12-13 21:24:27 +00:00
/**
* This function is deprecated
*/
2010-11-18 13:53:26 +00:00
function convert () { /* {{{ */
2011-01-28 07:32:06 +00:00
if ( file_exists ( $this -> _document -> _dms -> contentDir . $this -> _document -> getID () . '/' . " index.html " ))
2010-11-18 13:53:26 +00:00
return true ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! in_array ( $this -> _fileType , array_keys ( $this -> _document -> _dms -> convertFileTypes )))
return false ;
2010-11-30 09:27:37 +00:00
2011-01-28 07:32:06 +00:00
$source = $this -> _document -> _dms -> contentDir . $this -> _document -> getID () . '/' . $this -> getFileName ();
$target = $this -> _document -> _dms -> contentDir . $this -> _document -> getID () . '/' . " index.html " ;
2010-11-18 13:53:26 +00:00
// $source = str_replace("/", "\\", $source);
// $target = str_replace("/", "\\", $target);
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$command = $this -> _document -> _dms -> convertFileTypes [ $this -> _fileType ];
$command = str_replace ( " { SOURCE} " , " \" $source\ " " , $command );
$command = str_replace ( " { TARGET} " , " \" $target\ " " , $command );
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$output = array ();
$res = 0 ;
exec ( $command , $output , $res );
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( $res != 0 ) {
print ( implode ( " \n " , $output ));
return false ;
}
return true ;
} /* }}} */
/* FIXME : this function should not be part of the DMS . It lies in the duty
2012-12-19 10:26:44 +00:00
* of the application whether a file can be viewed online or not .
2010-11-18 13:53:26 +00:00
*/
function viewOnline () { /* {{{ */
2010-11-25 21:09:52 +00:00
if ( ! isset ( $this -> _document -> _dms -> _viewOnlineFileTypes ) || ! is_array ( $this -> _document -> _dms -> _viewOnlineFileTypes )) {
2010-11-18 13:53:26 +00:00
return false ;
}
2010-11-25 21:09:52 +00:00
if ( in_array ( strtolower ( $this -> _fileType ), $this -> _document -> _dms -> _viewOnlineFileTypes ))
2010-11-18 13:53:26 +00:00
return true ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( $this -> _document -> _dms -> enableConverting && in_array ( $this -> _fileType , array_keys ( $this -> _document -> _dms -> convertFileTypes )))
if ( $this -> wasConverted ()) return true ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
return false ;
} /* }}} */
function wasConverted () { /* {{{ */
2011-01-28 07:32:06 +00:00
return file_exists ( $this -> _document -> _dms -> contentDir . $this -> _document -> getID () . '/' . " index.html " );
2010-11-18 13:53:26 +00:00
} /* }}} */
2012-12-13 21:24:27 +00:00
/**
* This function is deprecated
*/
2010-11-18 13:53:26 +00:00
function getURL () { /* {{{ */
if ( ! $this -> viewOnline ()) return false ;
2010-11-30 09:27:37 +00:00
2010-11-25 21:09:52 +00:00
if ( in_array ( strtolower ( $this -> _fileType ), $this -> _document -> _dms -> _viewOnlineFileTypes ))
2010-11-18 13:53:26 +00:00
return " / " . $this -> _document -> getID () . " / " . $this -> _version . " / " . $this -> getOriginalFileName ();
else
return " / " . $this -> _document -> getID () . " / " . $this -> _version . " /index.html " ;
} /* }}} */
2011-10-12 06:18:28 +00:00
/**
* Get the latest status of the content
*
2013-01-28 10:14:13 +00:00
* The status of the content reflects its current review , approval or workflow
2011-10-12 06:18:28 +00:00
* state . A status can be a negative or positive number or 0. A negative
* numbers indicate a missing approval , review or an obsolete content .
2013-01-28 10:14:13 +00:00
* Positive numbers indicate some kind of approval or workflow being
* active , but not necessarily a release .
2011-10-12 06:18:28 +00:00
* S_DRAFT_REV , 0
* S_DRAFT_APP , 1
* S_RELEASED , 2
2013-01-28 10:14:13 +00:00
* S_IN_WORKFLOW , 3
2015-05-11 07:29:34 +00:00
* S_IN_REVISION , 4
2011-10-12 06:18:28 +00:00
* S_REJECTED , - 1
* S_OBSOLETE , - 2
* S_EXPIRED , - 3
* When a content is inserted and does not need approval nor review ,
* then its status is set to S_RELEASED immediately . Any change of
* the status is monitored in the table tblDocumentStatusLog . This
* function will always return the latest entry for the content .
2015-06-01 15:33:12 +00:00
*
* @ return array latest record from tblDocumentStatusLog
2011-10-12 06:18:28 +00:00
*/
2015-06-01 15:33:12 +00:00
function getStatus () { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
// Retrieve the current overall status of the content represented by
// this object.
if ( ! isset ( $this -> _status )) {
2011-10-12 06:18:28 +00:00
$queryStr =
" SELECT `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, " .
" `tblDocumentStatusLog`.`comment`, `tblDocumentStatusLog`.`date`, " .
" `tblDocumentStatusLog`.`userID` " .
" FROM `tblDocumentStatus` " .
" LEFT JOIN `tblDocumentStatusLog` USING (`statusID`) " .
" WHERE `tblDocumentStatus`.`documentID` = ' " . $this -> _document -> getID () . " ' " .
" AND `tblDocumentStatus`.`version` = ' " . $this -> _version . " ' " .
2015-06-01 15:33:12 +00:00
" ORDER BY `tblDocumentStatusLog`.`statusLogID` DESC LIMIT 1 " ;
2011-10-12 06:18:28 +00:00
2010-11-18 13:53:26 +00:00
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
if ( count ( $res ) != 1 )
return false ;
$this -> _status = $res [ 0 ];
}
return $this -> _status ;
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Get current and former states of the document content
*
* @ param integer $limit if not set all log entries will be returned
* @ return array list of status changes
*/
function getStatusLog ( $limit = 0 ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! is_numeric ( $limit )) return false ;
$queryStr =
" SELECT `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, " .
" `tblDocumentStatusLog`.`comment`, `tblDocumentStatusLog`.`date`, " .
" `tblDocumentStatusLog`.`userID` " .
" FROM `tblDocumentStatus` " .
" LEFT JOIN `tblDocumentStatusLog` USING (`statusID`) " .
" WHERE `tblDocumentStatus`.`documentID` = ' " . $this -> _document -> getID () . " ' " .
" AND `tblDocumentStatus`.`version` = ' " . $this -> _version . " ' " .
" ORDER BY `tblDocumentStatusLog`.`statusLogID` DESC " ;
if ( $limit )
$queryStr .= " LIMIT " . ( int ) $limit ;
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
return $res ;
} /* }}} */
2011-10-12 06:18:28 +00:00
/**
* Set the status of the content
* Setting the status means to add another entry into the table
2013-02-06 13:52:11 +00:00
* tblDocumentStatusLog . The method returns also false if the status
* is already set on the value passed to the method .
2011-10-12 06:18:28 +00:00
*
* @ param integer $status new status of content
* @ param string $comment comment for this status change
* @ param object $updateUser user initiating the status change
* @ return boolean true on success , otherwise false
*/
2015-07-31 13:30:35 +00:00
function setStatus ( $status , $comment , $updateUser , $date = '' ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
if ( ! is_numeric ( $status )) return false ;
2010-11-22 14:51:44 +00:00
/* return an error if $updateuser is not set */
if ( ! $updateUser )
return false ;
2010-11-18 13:53:26 +00:00
// If the supplied value lies outside of the accepted range, return an
// error.
2015-06-02 08:00:15 +00:00
if ( $status < - 3 || $status > 5 ) {
2010-11-18 13:53:26 +00:00
return false ;
}
// Retrieve the current overall status of the content represented by
// this object, if it hasn't been done already.
if ( ! isset ( $this -> _status )) {
$this -> getStatus ();
}
if ( $this -> _status [ " status " ] == $status ) {
return false ;
}
2015-07-31 13:30:35 +00:00
if ( $date )
$ddate = $db -> qstr ( $date );
else
2015-09-22 05:50:36 +00:00
$ddate = $db -> getCurrentDatetime ();
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentStatusLog` (`statusID`, `status`, `comment`, `date`, `userID`) " .
2015-07-31 13:30:35 +00:00
" VALUES (' " . $this -> _status [ " statusID " ] . " ', ' " . ( int ) $status . " ', " . $db -> qstr ( $comment ) . " , " . $ddate . " , ' " . $updateUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
2015-05-30 05:33:28 +00:00
unset ( $this -> _status );
2010-11-18 13:53:26 +00:00
return true ;
} /* }}} */
2015-07-31 13:30:35 +00:00
/**
* Rewrites the complete status log
*
* Attention : this function is highly dangerous .
* It removes an existing status log and rewrites it .
* This method was added for importing an xml dump .
*
* @ param array $statuslog new status log with the newest log entry first .
* @ return boolean true on success , otherwise false
*/
function rewriteStatusLog ( $statuslog ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$queryStr = " SELECT `tblDocumentStatus`.* FROM `tblDocumentStatus` WHERE `tblDocumentStatus`.`documentID` = ' " . $this -> _document -> getID () . " ' AND `tblDocumentStatus`.`version` = ' " . $this -> _version . " ' " ;
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
$statusID = $res [ 0 ][ 'statusID' ];
$db -> startTransaction ();
/* First, remove the old entries */
$queryStr = " DELETE from `tblDocumentStatusLog` where `statusID`= " . $statusID ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
/* Second, insert the new entries */
$statuslog = array_reverse ( $statuslog );
foreach ( $statuslog as $log ) {
if ( ! SeedDMS_Core_DMS :: checkDate ( $log [ 'date' ], 'Y-m-d H:i:s' )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " INSERT INTO `tblDocumentStatusLog` (`statusID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $statusID . " ', ' " . ( int ) $log [ 'status' ] . " ', " . $db -> qstr ( $log [ 'comment' ]) . " , " . $db -> qstr ( $log [ 'date' ]) . " , " . $log [ 'user' ] -> getID () . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Returns the access mode similar to a document
* There is no real access mode for document content , so this is more
* like a virtual access mode , derived from the status or workflow
* of the document content . The idea is to return an access mode
* M_NONE if the user is still in a workflow or under review / approval .
* In such a case only those user involved in the workflow / review / approval
* process should be allowed to see the document . This method could
* be called by any function that returns the content e . g . getLatestContent ()
2013-02-14 11:10:53 +00:00
* It may as well be used by SeedDMS_Core_Document :: getAccessMode () to
2013-01-24 08:29:58 +00:00
* prevent access on the whole document if there is just one version .
* The return value is planed to be either M_NONE or M_READ .
*
* @ param object $user
* @ return integer mode
*/
function getAccessMode ( $u ) { /* {{{ */
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( $this -> _workflow ) {
if ( ! $this -> _workflowState )
$this -> getWorkflowState ();
$transitions = $this -> _workflow -> getNextTransitions ( $this -> _workflowState );
foreach ( $transitions as $transition ) {
if ( $this -> triggerWorkflowTransitionIsAllowed ( $u , $transition ))
return M_READ ;
}
return M_NONE ;
}
return M_READ ;
} /* }}} */
2011-10-16 19:52:42 +00:00
/**
* Get the current review status of the document content
2013-10-06 06:09:37 +00:00
* The review status is a list of reviews and its current status
2011-10-16 19:52:42 +00:00
*
* @ param integer $limit the number of recent status changes per reviewer
* @ return array list of review status
*/
2011-10-12 06:18:28 +00:00
function getReviewStatus ( $limit = 1 ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
if ( ! is_numeric ( $limit )) return false ;
2010-11-18 13:53:26 +00:00
// Retrieve the current status of each assigned reviewer for the content
// represented by this object.
2013-10-06 06:09:37 +00:00
// FIXME: caching was turned off to make list of review log in ViewDocument
// possible
if ( 1 || ! isset ( $this -> _reviewStatus )) {
2011-10-16 19:52:42 +00:00
/* First get a list of all reviews for this document content */
2011-10-12 06:18:28 +00:00
$queryStr =
2012-02-13 08:34:19 +00:00
" SELECT reviewID FROM tblDocumentReviewers WHERE `version`=' " . $this -> _version
2011-10-16 19:52:42 +00:00
. " ' AND `documentID` = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
2010-11-18 13:53:26 +00:00
return false ;
2011-10-16 19:52:42 +00:00
$this -> _reviewStatus = array ();
if ( $recs ) {
foreach ( $recs as $rec ) {
$queryStr =
2012-10-09 09:54:07 +00:00
" SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`reviewLogID`, `tblDocumentReviewLog`.`status`, " .
2011-10-16 19:52:42 +00:00
" `tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, " .
" `tblDocumentReviewLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` " .
" FROM `tblDocumentReviewers` " .
" LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) " .
" LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentReviewers`.`required` " .
" LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentReviewers`.`required` " .
2012-02-13 08:34:19 +00:00
" WHERE `tblDocumentReviewers`.`reviewID` = ' " . $rec [ 'reviewID' ] . " ' " .
2011-12-01 21:20:58 +00:00
" ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC LIMIT " . ( int ) $limit ;
2011-10-16 19:52:42 +00:00
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
unset ( $this -> _reviewStatus );
return false ;
}
2015-06-11 19:28:04 +00:00
foreach ( $res as & $t ) {
$filename = $this -> _dms -> contentDir . $this -> _document -> getDir () . 'r' . $t [ 'reviewLogID' ];
if ( file_exists ( $filename ))
$t [ 'file' ] = $filename ;
else
$t [ 'file' ] = '' ;
}
2011-10-16 19:52:42 +00:00
$this -> _reviewStatus = array_merge ( $this -> _reviewStatus , $res );
}
}
2010-11-18 13:53:26 +00:00
}
return $this -> _reviewStatus ;
} /* }}} */
2015-08-04 05:38:45 +00:00
/**
* Rewrites the complete review log
*
* Attention : this function is highly dangerous .
* It removes an existing review log and rewrites it .
* This method was added for importing an xml dump .
*
* @ param array $reviewlog new status log with the newest log entry first .
* @ return boolean true on success , otherwise false
*/
function rewriteReviewLog ( $reviewers ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$queryStr = " SELECT `tblDocumentReviewers`.* FROM `tblDocumentReviewers` WHERE `tblDocumentReviewers`.`documentID` = ' " . $this -> _document -> getID () . " ' AND `tblDocumentReviewers`.`version` = ' " . $this -> _version . " ' " ;
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
$db -> startTransaction ();
if ( $res ) {
foreach ( $res as $review ) {
$reviewID = $review [ 'reviewID' ];
/* First, remove the old entries */
$queryStr = " DELETE from `tblDocumentReviewLog` where `reviewID`= " . $reviewID ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " DELETE from `tblDocumentReviewers` where `reviewID`= " . $reviewID ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
}
/* Second, insert the new entries */
foreach ( $reviewers as $review ) {
$queryStr = " INSERT INTO `tblDocumentReviewers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', " . $review [ 'type' ] . " , " . $review [ 'required' ] -> getID () . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$reviewID = $db -> getInsertID ();
$reviewlog = array_reverse ( $review [ 'logs' ]);
foreach ( $reviewlog as $log ) {
if ( ! SeedDMS_Core_DMS :: checkDate ( $log [ 'date' ], 'Y-m-d H:i:s' )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $reviewID . " ', ' " . ( int ) $log [ 'status' ] . " ', " . $db -> qstr ( $log [ 'comment' ]) . " , " . $db -> qstr ( $log [ 'date' ]) . " , " . $log [ 'user' ] -> getID () . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2013-10-06 06:09:37 +00:00
/**
* Get the current approval status of the document content
* The approval status is a list of approvals and its current status
*
* @ param integer $limit the number of recent status changes per approver
* @ return array list of approval status
*/
2011-10-12 06:18:28 +00:00
function getApprovalStatus ( $limit = 1 ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2011-12-01 21:20:58 +00:00
if ( ! is_numeric ( $limit )) return false ;
2010-11-18 13:53:26 +00:00
// Retrieve the current status of each assigned approver for the content
// represented by this object.
2013-10-06 06:09:37 +00:00
// FIXME: caching was turned off to make list of approval log in ViewDocument
// possible
if ( 1 || ! isset ( $this -> _approvalStatus )) {
2011-10-16 19:52:42 +00:00
/* First get a list of all approvals for this document content */
2011-10-12 06:18:28 +00:00
$queryStr =
2013-03-12 07:47:57 +00:00
" SELECT approveID FROM tblDocumentApprovers WHERE `version`=' " . $this -> _version
2011-10-16 19:52:42 +00:00
. " ' AND `documentID` = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
2010-11-18 13:53:26 +00:00
return false ;
2011-10-16 19:52:42 +00:00
$this -> _approvalStatus = array ();
if ( $recs ) {
foreach ( $recs as $rec ) {
$queryStr =
2015-06-12 10:43:54 +00:00
" SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`approveLogID`, `tblDocumentApproveLog`.`status`, " .
2011-10-16 19:52:42 +00:00
" `tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, " .
" `tblDocumentApproveLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` " .
" FROM `tblDocumentApprovers` " .
" LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) " .
" LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentApprovers`.`required` " .
" LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentApprovers`.`required` " .
2013-03-12 07:47:57 +00:00
" WHERE `tblDocumentApprovers`.`approveID` = ' " . $rec [ 'approveID' ] . " ' " .
2015-06-12 10:43:54 +00:00
" ORDER BY `tblDocumentApproveLog`.`approveLogID` DESC LIMIT " . ( int ) $limit ;
2011-10-16 19:52:42 +00:00
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
unset ( $this -> _approvalStatus );
return false ;
}
2015-06-11 19:28:04 +00:00
foreach ( $res as & $t ) {
2015-06-12 10:43:54 +00:00
$filename = $this -> _dms -> contentDir . $this -> _document -> getDir () . 'a' . $t [ 'approveLogID' ];
2015-06-11 19:28:04 +00:00
if ( file_exists ( $filename ))
$t [ 'file' ] = $filename ;
else
$t [ 'file' ] = '' ;
}
2011-10-16 19:52:42 +00:00
$this -> _approvalStatus = array_merge ( $this -> _approvalStatus , $res );
}
}
2010-11-18 13:53:26 +00:00
}
return $this -> _approvalStatus ;
} /* }}} */
2015-08-04 05:38:45 +00:00
/**
* Rewrites the complete approval log
*
* Attention : this function is highly dangerous .
* It removes an existing review log and rewrites it .
* This method was added for importing an xml dump .
*
* @ param array $reviewlog new status log with the newest log entry first .
* @ return boolean true on success , otherwise false
*/
function rewriteApprovalLog ( $reviewers ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$queryStr = " SELECT `tblDocumentApprovers`.* FROM `tblDocumentApprovers` WHERE `tblDocumentApprovers`.`documentID` = ' " . $this -> _document -> getID () . " ' AND `tblDocumentApprovers`.`version` = ' " . $this -> _version . " ' " ;
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return false ;
$db -> startTransaction ();
if ( $res ) {
foreach ( $res as $review ) {
$reviewID = $review [ 'reviewID' ];
/* First, remove the old entries */
$queryStr = " DELETE from `tblDocumentApproveLog` where `approveID`= " . $reviewID ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " DELETE from `tblDocumentApprovers` where `approveID`= " . $reviewID ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
}
/* Second, insert the new entries */
foreach ( $reviewers as $review ) {
$queryStr = " INSERT INTO `tblDocumentApprovers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', " . $review [ 'type' ] . " , " . $review [ 'required' ] -> getID () . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$reviewID = $db -> getInsertID ();
$reviewlog = array_reverse ( $review [ 'logs' ]);
foreach ( $reviewlog as $log ) {
if ( ! SeedDMS_Core_DMS :: checkDate ( $log [ 'date' ], 'Y-m-d H:i:s' )) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $reviewID . " ', ' " . ( int ) $log [ 'status' ] . " ', " . $db -> qstr ( $log [ 'comment' ]) . " , " . $db -> qstr ( $log [ 'date' ]) . " , " . $log [ 'user' ] -> getID () . " ) " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
}
$db -> commitTransaction ();
return true ;
} /* }}} */
2015-04-20 11:43:40 +00:00
/**
* Get the current receipt status of the document content
* The receipt status is a list of receipts
*
2015-05-12 17:07:59 +00:00
* @ param integer $limit maximum number of status changes per receiver
2015-04-20 11:43:40 +00:00
* @ return array list of receipts
*/
2015-04-20 16:33:42 +00:00
function getReceiptStatus ( $limit = 1 ) { /* {{{ */
2015-04-20 11:43:40 +00:00
$db = $this -> _document -> _dms -> getDB ();
if ( ! is_numeric ( $limit )) return false ;
// Retrieve the current status of each assigned reviewer for the content
// represented by this object.
// FIXME: caching was turned off to make list of review log in ViewDocument
// possible
if ( 1 || ! isset ( $this -> _receiptStatus )) {
/* First get a list of all receipts for this document content */
$queryStr =
" SELECT receiptID FROM tblDocumentRecipients WHERE `version`=' " . $this -> _version
. " ' AND `documentID` = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
return false ;
2015-04-20 16:33:42 +00:00
$this -> _receiptStatus = array ();
2015-04-20 11:43:40 +00:00
if ( $recs ) {
foreach ( $recs as $rec ) {
$queryStr =
" SELECT `tblDocumentRecipients`.*, `tblDocumentReceiptLog`.`receiptLogID`, " .
2015-04-20 16:33:42 +00:00
" `tblDocumentReceiptLog`.`status`, " .
" `tblDocumentReceiptLog`.`comment`, " .
2015-04-20 11:43:40 +00:00
" `tblDocumentReceiptLog`.`date`, " .
" `tblDocumentReceiptLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` " .
2015-04-20 16:33:42 +00:00
" FROM `tblDocumentRecipients` " .
" LEFT JOIN `tblDocumentReceiptLog` USING (`receiptID`) " .
" LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentRecipients`.`required` " .
" LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentRecipients`.`required` " .
" WHERE `tblDocumentRecipients`.`receiptID` = ' " . $rec [ 'receiptID' ] . " ' " .
" ORDER BY `tblDocumentReceiptLog`.`receiptLogID` DESC LIMIT " . ( int ) $limit ;
2015-04-20 11:43:40 +00:00
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
unset ( $this -> _receiptStatus );
return false ;
}
$this -> _receiptStatus = array_merge ( $this -> _receiptStatus , $res );
}
}
}
return $this -> _receiptStatus ;
} /* }}} */
2015-04-22 08:31:36 +00:00
/**
* Get the current revision status of the document content
* The revision status is a list of revisions
*
2015-05-12 17:07:59 +00:00
* @ param integer $limit maximum number of records per revisor
2015-04-22 08:31:36 +00:00
* @ return array list of revisions
*/
function getRevisionStatus ( $limit = 1 ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! is_numeric ( $limit )) return false ;
// Retrieve the current status of each assigned reviewer for the content
// represented by this object.
// FIXME: caching was turned off to make list of review log in ViewDocument
// possible
if ( 1 || ! isset ( $this -> _revisionStatus )) {
/* First get a list of all revisions for this document content */
$queryStr =
2015-05-11 07:29:34 +00:00
" SELECT revisionID FROM tblDocumentRevisors WHERE `version`=' " . $this -> _version
2015-04-22 08:31:36 +00:00
. " ' AND `documentID` = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
return false ;
$this -> _revisionStatus = array ();
if ( $recs ) {
foreach ( $recs as $rec ) {
$queryStr =
2015-05-11 07:29:34 +00:00
" SELECT `tblDocumentRevisors`.*, `tblDocumentRevisionLog`.`revisionLogID`, " .
2015-04-22 08:31:36 +00:00
" `tblDocumentRevisionLog`.`status`, " .
" `tblDocumentRevisionLog`.`comment`, " .
" `tblDocumentRevisionLog`.`date`, " .
" `tblDocumentRevisionLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` " .
2015-05-11 07:29:34 +00:00
" FROM `tblDocumentRevisors` " .
2015-04-22 08:31:36 +00:00
" LEFT JOIN `tblDocumentRevisionLog` USING (`revisionID`) " .
2015-05-11 07:29:34 +00:00
" LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentRevisors`.`required` " .
" LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentRevisors`.`required` " .
" WHERE `tblDocumentRevisors`.`revisionID` = ' " . $rec [ 'revisionID' ] . " ' " .
2015-04-22 08:31:36 +00:00
" ORDER BY `tblDocumentRevisionLog`.`revisionLogID` DESC LIMIT " . ( int ) $limit ;
$res = $db -> getResultArray ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
unset ( $this -> _revisionStatus );
return false ;
}
$this -> _revisionStatus = array_merge ( $this -> _revisionStatus , $res );
}
}
}
return $this -> _revisionStatus ;
} /* }}} */
2015-05-11 07:29:34 +00:00
function addIndReviewer ( $user , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
$userID = $user -> getID ();
2013-02-11 13:55:51 +00:00
// Get the list of users and groups with read access to this document.
2013-05-07 18:16:09 +00:00
if ( $this -> _document -> getAccessMode ( $user ) < M_READ ) {
return - 2 ;
}
2010-11-18 13:53:26 +00:00
// Check to see if the user has already been added to the review list.
$reviewStatus = $user -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
2013-02-06 13:52:11 +00:00
$indstatus = false ;
if ( count ( $reviewStatus [ " indstatus " ]) > 0 ) {
$indstatus = array_pop ( $reviewStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] !=- 2 ) {
// User is already on the list of reviewers; return an error.
return - 3 ;
}
2010-11-18 13:53:26 +00:00
}
// Add the user into the review database.
2013-02-06 13:52:11 +00:00
if ( ! $indstatus || ( $indstatus && $indstatus [ " status " ] !=- 2 )) {
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '0', ' " . $userID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
$reviewID = $db -> getInsertID ();
}
else {
2015-04-20 16:33:42 +00:00
$reviewID = isset ( $indstatus [ " reviewID " ]) ? $indstatus [ " reviewID " ] : NULL ;
2010-11-18 13:53:26 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $reviewID . " ', '0', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
// Add reviewer to event notification table.
//$this->_document->addNotify($userID, true);
return 0 ;
} /* }}} */
2011-10-12 06:18:28 +00:00
function addGrpReviewer ( $group , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
$groupID = $group -> getID ();
2013-02-11 13:55:51 +00:00
// Get the list of users and groups with read access to this document.
if ( ! isset ( $this -> _readAccessList )) {
2010-11-18 13:53:26 +00:00
// TODO: error checking.
2013-02-11 13:55:51 +00:00
$this -> _readAccessList = $this -> _document -> getReadAccessList ();
2010-11-18 13:53:26 +00:00
}
$approved = false ;
2013-02-11 13:55:51 +00:00
foreach ( $this -> _readAccessList [ " groups " ] as $appGroup ) {
2010-11-18 13:53:26 +00:00
if ( $groupID == $appGroup -> getID ()) {
$approved = true ;
break ;
}
}
if ( ! $approved ) {
return - 2 ;
}
// Check to see if the group has already been added to the review list.
$reviewStatus = $group -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
if ( count ( $reviewStatus ) > 0 && $reviewStatus [ 0 ][ " status " ] !=- 2 ) {
// Group is already on the list of reviewers; return an error.
return - 3 ;
}
// Add the group into the review database.
if ( ! isset ( $reviewStatus [ 0 ][ " status " ]) || ( isset ( $reviewStatus [ 0 ][ " status " ]) && $reviewStatus [ 0 ][ " status " ] !=- 2 )) {
$queryStr = " INSERT INTO `tblDocumentReviewers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '1', ' " . $groupID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
$reviewID = $db -> getInsertID ();
}
else {
$reviewID = isset ( $reviewStatus [ 0 ][ " reviewID " ]) ? $reviewStatus [ 0 ][ " reviewID " ] : NULL ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $reviewID . " ', '0', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
// Add reviewer to event notification table.
//$this->_document->addNotify($groupID, false);
return 0 ;
} /* }}} */
2013-02-11 07:42:38 +00:00
/**
* Add a review to the document content
*
* This method will add an entry to the table tblDocumentReviewLog .
* It will first check if the user is ment to review the document version .
* It not the return value is - 3.
* Next it will check if the users has been removed from the list of
* reviewers . In that case - 4 will be returned .
* If the given review status has been set by the user before , it cannot
* be set again and 0 will be returned . І f the review could be succesfully
2013-09-27 06:23:11 +00:00
* added , the review log id will be returned .
2013-02-11 07:42:38 +00:00
*
2013-02-14 11:10:53 +00:00
* @ see SeedDMS_Core_DocumentContent :: setApprovalByInd ()
2013-02-11 07:42:38 +00:00
* @ param object $user user doing the review
* @ param object $requestUser user asking for the review , this is mostly
* the user currently logged in .
* @ param integer $status status of review
* @ param string $comment comment for review
* @ return integer new review log id
*/
2015-06-11 19:28:04 +00:00
function setReviewByInd ( $user , $requestUser , $status , $comment , $file = '' ) { /* {{{ */
2011-10-16 19:52:42 +00:00
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the review list.
$reviewStatus = $user -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
if ( count ( $reviewStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to review this document. No action required.
// Return an error.
return - 3 ;
}
2013-02-06 13:52:11 +00:00
$indstatus = array_pop ( $reviewStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] ==- 2 ) {
2011-10-16 19:52:42 +00:00
// User has been deleted from reviewers
return - 4 ;
}
// Check if the status is really different from the current status
2013-02-06 13:52:11 +00:00
if ( $indstatus [ " status " ] == $status )
2011-10-16 19:52:42 +00:00
return 0 ;
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`,
`comment` , `date` , `userID` ) " .
2013-02-06 13:52:11 +00:00
" VALUES (' " . $indstatus [ " reviewID " ] . " ', ' " .
2015-09-22 05:50:36 +00:00
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentDatetime () . " , ' " .
2011-10-16 19:52:42 +00:00
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
2015-06-11 19:28:04 +00:00
$reviewLogID = $db -> getInsertID ();
if ( $file ) {
SeedDMS_Core_File :: copyFile ( $file , $this -> _dms -> contentDir . $this -> _document -> getDir () . 'r' . $reviewLogID );
2012-10-09 09:54:07 +00:00
}
2015-06-11 19:28:04 +00:00
return $reviewLogID ;
2011-10-16 19:52:42 +00:00
} /* }}} */
2013-02-11 07:42:38 +00:00
/**
* Add a review to the document content
*
* This method is similar to
2013-02-14 11:10:53 +00:00
* { @ see SeedDMS_Core_DocumentContent :: setReviewByInd ()} but adds a review
2013-02-11 07:42:38 +00:00
* for a group instead of a user .
*
* @ param object $group group doing the review
* @ param object $requestUser user asking for the review , this is mostly
* the user currently logged in .
* @ param integer $status status of review
* @ param string $comment comment for review
* @ return integer new review log id
*/
2015-06-11 19:28:04 +00:00
function setReviewByGrp ( $group , $requestUser , $status , $comment , $file = '' ) { /* {{{ */
2011-10-16 19:52:42 +00:00
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the review list.
$reviewStatus = $group -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
if ( count ( $reviewStatus ) == 0 ) {
// User is not assigned to review this document. No action required.
// Return an error.
return - 3 ;
}
if ( $reviewStatus [ 0 ][ " status " ] ==- 2 ) {
// Group has been deleted from reviewers
return - 4 ;
}
// Check if the status is really different from the current status
if ( $reviewStatus [ 0 ][ " status " ] == $status )
return 0 ;
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $reviewStatus [ 0 ][ " reviewID " ] . " ', ' " .
2015-09-22 05:50:36 +00:00
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentDatetime () . " , ' " .
2011-10-16 19:52:42 +00:00
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
2012-10-09 09:54:07 +00:00
else {
$reviewLogID = $db -> getInsertID ();
2015-06-11 19:28:04 +00:00
if ( $file ) {
SeedDMS_Core_File :: copyFile ( $file , $this -> _dms -> contentDir . $this -> _document -> getDir () . 'r' . $reviewLogID );
}
2012-10-09 09:54:07 +00:00
return $reviewLogID ;
}
2011-10-16 19:52:42 +00:00
} /* }}} */
2015-05-11 07:29:34 +00:00
function addIndApprover ( $user , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
$userID = $user -> getID ();
2013-02-11 13:55:51 +00:00
// Get the list of users and groups with read access to this document.
2013-05-07 18:16:09 +00:00
if ( $this -> _document -> getAccessMode ( $user ) < M_READ ) {
return - 2 ;
2010-11-18 13:53:26 +00:00
}
// Check to see if the user has already been added to the approvers list.
$approvalStatus = $user -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
2013-02-06 13:52:11 +00:00
$indstatus = false ;
if ( count ( $approvalStatus [ " indstatus " ]) > 0 ) {
$indstatus = array_pop ( $approvalStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] !=- 2 ) {
// User is already on the list of approverss; return an error.
return - 3 ;
}
2010-11-18 13:53:26 +00:00
}
2010-11-12 22:47:41 +00:00
2013-04-30 06:01:17 +00:00
if ( ! $indstatus || ( isset ( $indstatus [ " status " ]) && $indstatus [ " status " ] !=- 2 )) {
2010-11-18 13:53:26 +00:00
// Add the user into the approvers database.
$queryStr = " INSERT INTO `tblDocumentApprovers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '0', ' " . $userID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
2010-11-12 22:47:41 +00:00
}
2010-11-18 13:53:26 +00:00
$approveID = $db -> getInsertID ();
}
else {
2013-02-06 13:52:11 +00:00
$approveID = isset ( $indstatus [ " approveID " ]) ? $indstatus [ " approveID " ] : NULL ;
2010-10-29 13:19:51 +00:00
}
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $approveID . " ', '0', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
2010-10-29 13:19:51 +00:00
}
2012-10-09 09:54:07 +00:00
$approveLogID = $db -> getInsertID ();
return $approveLogID ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-11-12 22:47:41 +00:00
2011-10-12 06:18:28 +00:00
function addGrpApprover ( $group , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
$groupID = $group -> getID ();
2010-10-29 13:19:51 +00:00
2013-02-11 13:55:51 +00:00
// Get the list of users and groups with read access to this document.
if ( ! isset ( $this -> _readAccessList )) {
2010-11-18 13:53:26 +00:00
// TODO: error checking.
2013-02-11 13:55:51 +00:00
$this -> _readAccessList = $this -> _document -> getReadAccessList ();
2010-10-29 13:19:51 +00:00
}
2010-11-18 13:53:26 +00:00
$approved = false ;
2013-02-11 13:55:51 +00:00
foreach ( $this -> _readAccessList [ " groups " ] as $appGroup ) {
2010-11-18 13:53:26 +00:00
if ( $groupID == $appGroup -> getID ()) {
$approved = true ;
break ;
2010-10-29 13:19:51 +00:00
}
}
2010-11-18 13:53:26 +00:00
if ( ! $approved ) {
return - 2 ;
}
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
// Check to see if the group has already been added to the approver list.
$approvalStatus = $group -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
if ( count ( $approvalStatus ) > 0 && $approvalStatus [ 0 ][ " status " ] !=- 2 ) {
// Group is already on the list of approvers; return an error.
return - 3 ;
}
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
// Add the group into the approver database.
if ( ! isset ( $approvalStatus [ 0 ][ " status " ]) || ( isset ( $approvalStatus [ 0 ][ " status " ]) && $approvalStatus [ 0 ][ " status " ] !=- 2 )) {
$queryStr = " INSERT INTO `tblDocumentApprovers` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '1', ' " . $groupID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
2010-11-12 22:47:41 +00:00
}
2010-11-18 13:53:26 +00:00
$approveID = $db -> getInsertID ();
}
else {
$approveID = isset ( $approvalStatus [ 0 ][ " approveID " ]) ? $approvalStatus [ 0 ][ " approveID " ] : NULL ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $approveID . " ', '0', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
2010-10-29 13:19:51 +00:00
}
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
// Add approver to event notification table.
//$this->_document->addNotify($groupID, false);
2010-10-29 13:19:51 +00:00
2012-10-09 09:54:07 +00:00
$approveLogID = $db -> getInsertID ();
return $approveLogID ;
2010-11-18 13:53:26 +00:00
} /* }}} */
2010-10-29 13:19:51 +00:00
2011-10-16 19:52:42 +00:00
/**
* Sets approval status of a document content for a user
2013-09-27 06:23:11 +00:00
*
2011-10-16 19:52:42 +00:00
* This function can be used to approve or reject a document content , or
2013-09-27 06:23:11 +00:00
* to reset its approval state . In most cases this function will be
* called by an user , but an admin may set the approval for
2011-10-16 19:52:42 +00:00
* somebody else .
* It is first checked if the user is in the list of approvers at all .
* Then it is check if the approval status is already - 2. In both cases
* the function returns with an error .
*
2013-02-14 11:10:53 +00:00
* @ see SeedDMS_Core_DocumentContent :: setReviewByInd ()
2011-10-16 19:52:42 +00:00
* @ param object $user user in charge for doing the approval
* @ param object $requestUser user actually calling this function
* @ param integer $status the status of the approval , possible values are
* 0 = unprocessed ( maybe used to reset a status )
* 1 = approved ,
* - 1 = rejected ,
* - 2 = user is deleted ( use { link
2013-02-14 11:10:53 +00:00
* SeedDMS_Core_DocumentContent :: delIndApprover } instead )
2011-10-16 19:52:42 +00:00
* @ param string $comment approval comment
* @ return integer 0 on success , < 0 in case of an error
*/
2015-06-11 19:28:04 +00:00
function setApprovalByInd ( $user , $requestUser , $status , $comment , $file = '' ) { /* {{{ */
2011-10-16 19:52:42 +00:00
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the approval list.
$approvalStatus = $user -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
if ( count ( $approvalStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to approve this document. No action required.
// Return an error.
return - 3 ;
}
2013-02-06 13:52:11 +00:00
$indstatus = array_pop ( $approvalStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] ==- 2 ) {
2011-10-16 19:52:42 +00:00
// User has been deleted from approvers
return - 4 ;
}
// Check if the status is really different from the current status
2013-02-06 13:52:11 +00:00
if ( $indstatus [ " status " ] == $status )
2011-10-16 19:52:42 +00:00
return 0 ;
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`,
`comment` , `date` , `userID` ) " .
2013-02-06 13:52:11 +00:00
" VALUES (' " . $indstatus [ " approveID " ] . " ', ' " .
2015-09-22 05:50:36 +00:00
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentDatetime () . " , ' " .
2011-10-16 19:52:42 +00:00
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
2015-06-11 19:28:04 +00:00
$approveLogID = $db -> getInsertID ();
if ( $file ) {
SeedDMS_Core_File :: copyFile ( $file , $this -> _dms -> contentDir . $this -> _document -> getDir () . 'a' . $approveLogID );
}
2015-06-12 10:43:54 +00:00
return $approveLogID ;
2011-10-16 19:52:42 +00:00
} /* }}} */
/**
* Sets approval status of a document content for a group
* The functions behaves like
2013-02-14 11:10:53 +00:00
* { link SeedDMS_Core_DocumentContent :: setApprovalByInd } but does it for
2011-10-16 19:52:42 +00:00
* group instead of a user
*/
2015-06-11 19:28:04 +00:00
function setApprovalByGrp ( $group , $requestUser , $status , $comment , $file = '' ) { /* {{{ */
2011-10-16 19:52:42 +00:00
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the approval list.
$approvalStatus = $group -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
if ( count ( $approvalStatus ) == 0 ) {
// User is not assigned to approve this document. No action required.
// Return an error.
return - 3 ;
}
if ( $approvalStatus [ 0 ][ " status " ] ==- 2 ) {
// Group has been deleted from approvers
return - 4 ;
}
// Check if the status is really different from the current status
if ( $approvalStatus [ 0 ][ " status " ] == $status )
return 0 ;
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $approvalStatus [ 0 ][ " approveID " ] . " ', ' " .
2015-09-22 05:50:36 +00:00
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , " . $db -> getCurrentDatetime () . " , ' " .
2011-10-16 19:52:42 +00:00
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
2015-06-11 19:28:04 +00:00
$approveLogID = $db -> getInsertID ();
if ( $file ) {
SeedDMS_Core_File :: copyFile ( $file , $this -> _dms -> contentDir . $this -> _document -> getDir () . 'a' . $approveLogID );
}
2015-06-12 10:43:54 +00:00
return $approveLogID ;
2011-10-16 19:52:42 +00:00
} /* }}} */
2015-05-11 07:29:34 +00:00
function addIndRecipient ( $user , $requestUser ) { /* {{{ */
2015-04-20 11:43:40 +00:00
$db = $this -> _document -> _dms -> getDB ();
$userID = $user -> getID ();
// Get the list of users and groups with read access to this document.
if ( $this -> _document -> getAccessMode ( $user ) < M_READ ) {
return - 2 ;
}
// Check to see if the user has already been added to the receipt list.
2015-04-20 16:33:42 +00:00
$receiptStatus = $user -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
2015-04-20 11:43:40 +00:00
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
$indstatus = false ;
if ( count ( $receiptStatus [ " indstatus " ]) > 0 ) {
$indstatus = array_pop ( $receiptStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] !=- 2 ) {
// User is already on the list of recipients; return an error.
return - 3 ;
}
}
// Add the user into the recipients database.
if ( ! $indstatus || ( $indstatus && $indstatus [ " status " ] !=- 2 )) {
$queryStr = " INSERT INTO `tblDocumentRecipients` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '0', ' " . $userID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
$receiptID = $db -> getInsertID ();
}
else {
2015-04-20 16:33:42 +00:00
$receiptID = isset ( $indstatus [ " receiptID " ]) ? $indstatus [ " receiptID " ] : NULL ;
2015-04-20 11:43:40 +00:00
}
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $receiptID . " ', '0', '', CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
// Add recipient to event notification table.
//$this->_document->addNotify($userID, true);
return 0 ;
} /* }}} */
function addGrpRecipient ( $group , $requestUser ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$groupID = $group -> getID ();
// Get the list of users and groups with read access to this document.
if ( ! isset ( $this -> _readAccessList )) {
// TODO: error checking.
$this -> _readAccessList = $this -> _document -> getReadAccessList ();
}
$approved = false ;
foreach ( $this -> _readAccessList [ " groups " ] as $appGroup ) {
if ( $groupID == $appGroup -> getID ()) {
$approved = true ;
break ;
}
}
if ( ! $approved ) {
return - 2 ;
}
// Check to see if the group has already been added to the review list.
$receiptStatus = $group -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
2015-04-20 16:33:42 +00:00
$status = false ;
if ( count ( $receiptStatus [ " status " ]) > 0 ) {
$status = array_pop ( $receiptStatus [ " status " ]);
if ( $status [ " status " ] !=- 2 ) {
// User is already on the list of recipients; return an error.
return - 3 ;
}
2015-04-20 11:43:40 +00:00
}
// Add the group into the recipients database.
2015-04-20 16:33:42 +00:00
if ( ! $status || ( $status && $status [ " status " ] !=- 2 )) {
2015-04-20 11:43:40 +00:00
$queryStr = " INSERT INTO `tblDocumentRecipients` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', '1', ' " . $groupID . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
$receiptID = $db -> getInsertID ();
}
else {
2015-04-20 16:33:42 +00:00
$receiptID = isset ( $status [ " receiptID " ]) ? $status [ " receiptID " ] : NULL ;
2015-04-20 11:43:40 +00:00
}
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $receiptID . " ', '0', '', CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
return 0 ;
} /* }}} */
2015-05-11 07:29:34 +00:00
/**
* Add an individual revisor to the document content
*
* This function adds a user as a revisor but doesn ' t start the
* revision workflow by default . This behaviour is different from all
* other workflows ( approval , review , receipt ), because it doesn ' t add
* the initial entry in the revision log , which starts the workflow .
* It just adds the revisors to the content . The workflow is started
* at a later point in time by adding the first entry in the revision log .
*
* @ param object $user user to be added as a revisor
* @ param object $requestUser user requesting the addition
* @ return integer 0 if successful otherwise a value < 0
*/
function addRevisor ( $object , $requestUser ) { /* {{{ */
$dms = $this -> _document -> _dms ;
$db = $dms -> getDB ();
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
/* getRevisionStatus () returns an array with either an element
* 'indstatus' ( user ) or 'status' ( group ) containing the revision log
*/
if ( get_class ( $object ) == $dms -> getClassname ( 'user' )) {
$field = 'indstatus' ;
$type = 0 ;
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
// Get the list of users and groups with read access to this document.
if ( $this -> _document -> getAccessMode ( $object ) < M_READ ) {
return - 2 ;
}
} elseif ( get_class ( $object ) == $dms -> getClassname ( 'group' )) {
$field = 'status' ;
$type = 1 ;
// Get the list of users and groups with read access to this document.
if ( $this -> _document -> getGroupAccessMode ( $object ) < M_READ ) {
return - 2 ;
}
} else {
return - 1 ;
2015-04-22 08:31:36 +00:00
}
2015-05-11 07:29:34 +00:00
// Check to see if the user has already been added to the revisor list.
$revisionStatus = $object -> getRevisionStatus ( $this -> _document -> getID (), $this -> _version );
2015-04-22 08:31:36 +00:00
if ( is_bool ( $revisionStatus ) && ! $revisionStatus ) {
return - 1 ;
}
2015-05-11 07:29:34 +00:00
/* There are two cases : 1. the user has not been added at all or 2.
* the user was added before but has been removed later . In both
* cases the user may be added . In case 2. 'indstatus' will be set
* and the last status is - 2. If it is not - 2 , then the user is still
* in the process and cannot be added again .
*/
2015-04-22 08:31:36 +00:00
$indstatus = false ;
2015-05-11 07:29:34 +00:00
if ( isset ( $revisionStatus [ $field ])) {
if ( count ( $revisionStatus [ $field ]) > 0 ) {
$indstatus = array_pop ( $revisionStatus [ $field ]);
if ( $indstatus [ " status " ] != S_LOG_USER_REMOVED ) {
// User is already on the list of recipients; return an error.
return - 3 ;
}
2015-04-22 08:31:36 +00:00
}
}
2015-05-11 07:29:34 +00:00
// Add the user into the revisors database.
if ( ! $indstatus ) {
$queryStr = " INSERT INTO `tblDocumentRevisors` (`documentID`, `version`, `type`, `required`) " .
" VALUES (' " . $this -> _document -> getID () . " ', ' " . $this -> _version . " ', ' " . $type . " ', ' " . $object -> getID () . " ') " ;
2015-04-22 08:31:36 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
$revisionID = $db -> getInsertID ();
2015-05-11 07:29:34 +00:00
} else {
2015-04-22 08:31:36 +00:00
$revisionID = isset ( $indstatus [ " revisionID " ]) ? $indstatus [ " revisionID " ] : NULL ;
}
$queryStr = " INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`, `comment`, `date`, `userID`) " .
2015-05-11 07:29:34 +00:00
" VALUES (' " . $revisionID . " ', ' " . S_LOG_SLEEPING . " ', '', CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
2015-04-22 08:31:36 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
return 0 ;
} /* }}} */
2015-05-11 07:29:34 +00:00
function addIndRevisor ( $user , $requestUser , $donotstart = true ) { /* {{{ */
return self :: addRevisor ( $user , $requestUser , $donotstart );
} /* }}} */
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
function addGrpRevisor ( $group , $requestUser , $donotstart = true ) { /* {{{ */
return self :: addRevisor ( $group , $requestUser , $donotstart );
2015-04-22 08:31:36 +00:00
} /* }}} */
2015-04-20 11:43:40 +00:00
/**
* Add a receipt to the document content
*
* This method will add an entry to the table tblDocumentReceiptLog .
* It will first check if the user is ment to receipt the document version .
2015-05-11 07:29:34 +00:00
* If not the return value is - 3.
* Next it will check if the user has been removed from the list of
2015-04-20 11:43:40 +00:00
* recipients . In that case - 4 will be returned .
* If the given receipt has been set by the user before , it cannot
2015-05-11 07:29:34 +00:00
* be set again and 0 will be returned . І f the receipt could be succesfully
* added , the receiptview log id will be returned .
2015-04-20 11:43:40 +00:00
*
* @ see SeedDMS_Core_DocumentContent :: setApprovalByInd ()
* @ param object $user user doing the receipt
* @ param object $requestUser user asking for the receipt , this is mostly
* @ param integer $status the status of the receipt , possible values are
2015-05-11 07:29:34 +00:00
* 0 = unprocessed ( may be used to reset a status )
2015-04-20 11:43:40 +00:00
* 1 = received ,
2015-05-11 07:29:34 +00:00
* - 1 = rejected ,
2015-04-20 11:43:40 +00:00
* - 2 = user is deleted ( use { link
* SeedDMS_Core_DocumentContent :: delIndRecipient } instead )
* the user currently logged in .
* @ return integer new receipt log id
*/
function setReceiptByInd ( $user , $requestUser , $status , $comment ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the review list.
$receiptStatus = $user -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
if ( count ( $receiptStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return - 3 ;
}
$indstatus = array_pop ( $receiptStatus [ " indstatus " ]);
2015-05-11 07:29:34 +00:00
if ( $indstatus [ " status " ] == S_LOG_USER_REMOVED ) {
2015-04-20 11:43:40 +00:00
// User has been deleted from recipients
return - 4 ;
}
// Check if the status is really different from the current status
if ( $indstatus [ " status " ] == $status )
return 0 ;
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $indstatus [ " receiptID " ] . " ', ' " .
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , CURRENT_TIMESTAMP, ' " .
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
else {
$receiptLogID = $db -> getInsertID ();
return $receiptLogID ;
}
} /* }}} */
/**
* Add a receipt to the document content
*
* This method is similar to
* { @ see SeedDMS_Core_DocumentContent :: setReceiptByInd ()} but adds a receipt
* for a group instead of a user .
*
* @ param object $group group doing the receipt
* @ param object $requestUser user asking for the receipt , this is mostly
* the user currently logged in .
* @ return integer new receipt log id
*/
function setReceiptByGrp ( $group , $requestUser , $status , $comment ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
// Check to see if the user can be removed from the recipient list.
$receiptStatus = $group -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
if ( count ( $receiptStatus ) == 0 ) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return - 3 ;
}
if ( $receiptStatus [ 0 ][ " status " ] ==- 2 ) {
// Group has been deleted from recipients
return - 4 ;
}
// Check if the status is really different from the current status
if ( $receiptStatus [ 0 ][ " status " ] == $status )
return 0 ;
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`recipientsID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $receiptStatus [ 0 ][ " recipientsID " ] . " ', ' " .
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , CURRENT_TIMESTAMP, ' " .
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
else {
$receiptLogID = $db -> getInsertID ();
return $receiptLogID ;
}
} /* }}} */
2015-04-22 08:31:36 +00:00
/**
* Add a revision to the document content
*
* This method will add an entry to the table tblDocumentRevisionLog .
* It will first check if the user is ment to revision the document version .
2015-05-11 07:29:34 +00:00
* If not the return value is - 3.
* Next it will check if the user has been removed from the list of
2015-04-22 08:31:36 +00:00
* recipients . In that case - 4 will be returned .
* If the given revision has been set by the user before , it cannot
2015-05-11 07:29:34 +00:00
* be set again and 0 will be returned . І f the revision could be succesfully
* added , the revision log id will be returned .
2015-04-22 08:31:36 +00:00
*
* @ see SeedDMS_Core_DocumentContent :: setApprovalByInd ()
* @ param object $user user doing the revision
* @ param object $requestUser user asking for the revision , this is mostly
2015-05-11 07:29:34 +00:00
* the user currently logged in .
2015-04-22 08:31:36 +00:00
* @ param integer $status the status of the revision , possible values are
2015-05-11 07:29:34 +00:00
* 0 = unprocessed ( may be used to reset a status )
2015-04-22 08:31:36 +00:00
* 1 = received ,
* - 2 = user is deleted ( use { link
* SeedDMS_Core_DocumentContent :: delIndRecipient } instead )
2015-05-11 07:29:34 +00:00
* - 3 = workflow revision is sleeping
* @ return integer new revision log id , 0 , or a value < 0. 0 means the
* status has not changed because the new status is equal the current
* status . A value < 0 indicate
* an error . - 1 : internal error , - 3 : user may not revise this document
* - 4 : the user has been removed from the list of revisors ,
* - 5 : the revision has not been started at all .
2015-04-22 08:31:36 +00:00
*/
2015-05-11 07:29:34 +00:00
function setRevision ( $object , $requestUser , $status , $comment ) { /* {{{ */
$dms = $this -> _document -> _dms ;
$db = $dms -> getDB ();
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
/* getRevisionStatus () returns an array with either an element
* 'indstatus' ( user ) or 'status' ( group ) containing the revision log
*/
if ( get_class ( $object ) == $dms -> getClassname ( 'user' )) {
$field = 'indstatus' ;
} elseif ( get_class ( $object ) == $dms -> getClassname ( 'group' )) {
$field = 'status' ;
} else {
return - 1 ;
}
// Check to see if the user/group can be removed from the review list.
$revisionStatus = $object -> getRevisionStatus ( $this -> _document -> getID (), $this -> _version );
2015-04-22 08:31:36 +00:00
if ( is_bool ( $revisionStatus ) && ! $revisionStatus ) {
return - 1 ;
}
2015-05-11 07:29:34 +00:00
if ( ! isset ( $revisionStatus [ $field ])) {
2015-04-22 08:31:36 +00:00
// User is not assigned to revision this document. No action required.
// Return an error.
return - 3 ;
}
2015-05-11 07:29:34 +00:00
$indstatus = array_pop ( $revisionStatus [ $field ]);
/* check if revision workflow has been started already */
2015-06-01 12:01:23 +00:00
if ( $indstatus [ 'status' ] == S_LOG_SLEEPING && ( $status == S_LOG_REJECTED || $status == S_LOG_ACCEPTED ))
2015-05-11 07:29:34 +00:00
return - 5 ;
if ( $indstatus [ " status " ] == - 2 ) {
2015-04-22 08:31:36 +00:00
// User has been deleted from recipients
return - 4 ;
}
// Check if the status is really different from the current status
if ( $indstatus [ " status " ] == $status )
return 0 ;
$queryStr = " INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`,
2015-05-11 07:29:34 +00:00
`comment` , `date` , `userID` ) " .
2015-04-22 08:31:36 +00:00
" VALUES (' " . $indstatus [ " revisionID " ] . " ', ' " .
( int ) $status . " ', " . $db -> qstr ( $comment ) . " , CURRENT_TIMESTAMP, ' " .
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res )
return - 1 ;
else {
$revisionLogID = $db -> getInsertID ();
return $revisionLogID ;
}
} /* }}} */
2015-05-11 07:29:34 +00:00
function setRevisionByInd ( $user , $requestUser , $status , $comment ) { /* {{{ */
return self :: setRevision ( $user , $requestUser , $status , $comment );
} /* }}} */
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
function setRevisionByGrp ( $group , $requestUser , $status , $comment ) { /* {{{ */
return self :: setRevision ( $group , $requestUser , $status , $comment );
} /* }}} */
2015-04-22 08:31:36 +00:00
2011-10-12 06:18:28 +00:00
function delIndReviewer ( $user , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
$userID = $user -> getID ();
// Check to see if the user can be removed from the review list.
$reviewStatus = $user -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
if ( count ( $reviewStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to review this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2010-11-18 13:53:26 +00:00
}
2013-02-06 13:52:11 +00:00
$indstatus = array_pop ( $reviewStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] != 0 ) {
2010-11-18 13:53:26 +00:00
// User has already submitted a review or has already been deleted;
// return an error.
return - 3 ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $indstatus [ " reviewID " ] . " ', '-2', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
return 0 ;
} /* }}} */
2010-11-12 22:47:41 +00:00
2011-10-12 06:18:28 +00:00
function delGrpReviewer ( $group , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2010-11-12 22:47:41 +00:00
2010-11-18 13:53:26 +00:00
$groupID = $group -> getID ();
// Check to see if the user can be removed from the review list.
$reviewStatus = $group -> getReviewStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $reviewStatus ) && ! $reviewStatus ) {
return - 1 ;
}
if ( count ( $reviewStatus ) == 0 ) {
// User is not assigned to review this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2010-11-18 13:53:26 +00:00
}
if ( $reviewStatus [ 0 ][ " status " ] != 0 ) {
// User has already submitted a review or has already been deleted;
// return an error.
return - 3 ;
2010-10-29 13:19:51 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $reviewStatus [ 0 ][ " reviewID " ] . " ', '-2', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
return 0 ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2011-10-12 06:18:28 +00:00
function delIndApprover ( $user , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
$userID = $user -> getID ();
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
// Check to see if the user can be removed from the approval list.
$approvalStatus = $user -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
if ( count ( $approvalStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to approve this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2010-11-18 13:53:26 +00:00
}
2013-02-06 13:52:11 +00:00
$indstatus = array_pop ( $approvalStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] != 0 ) {
2010-11-18 13:53:26 +00:00
// User has already submitted an approval or has already been deleted;
// return an error.
return - 3 ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $indstatus [ " approveID " ] . " ', '-2', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
return 0 ;
} /* }}} */
2010-10-29 13:19:51 +00:00
2011-10-12 06:18:28 +00:00
function delGrpApprover ( $group , $requestUser ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$db = $this -> _document -> _dms -> getDB ();
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
$groupID = $group -> getID ();
2010-10-29 13:19:51 +00:00
2010-11-18 13:53:26 +00:00
// Check to see if the user can be removed from the approver list.
$approvalStatus = $group -> getApprovalStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $approvalStatus ) && ! $approvalStatus ) {
return - 1 ;
}
if ( count ( $approvalStatus ) == 0 ) {
// User is not assigned to approve this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2010-11-18 13:53:26 +00:00
}
if ( $approvalStatus [ 0 ][ " status " ] != 0 ) {
// User has already submitted an approval or has already been deleted;
// return an error.
return - 3 ;
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
$queryStr = " INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) " .
2015-09-22 05:50:36 +00:00
" VALUES (' " . $approvalStatus [ 0 ][ " approveID " ] . " ', '-2', '', " . $db -> getCurrentDatetime () . " , ' " . $requestUser -> getID () . " ') " ;
2010-11-18 13:53:26 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
return 0 ;
} /* }}} */
2012-12-13 21:24:27 +00:00
2015-04-20 11:43:40 +00:00
function delIndRecipient ( $user , $requestUser ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$userID = $user -> getID ();
// Check to see if the user can be removed from the recipient list.
2015-04-22 08:31:36 +00:00
$revisionStatus = $user -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
2015-04-20 11:43:40 +00:00
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
if ( count ( $receiptStatus [ " indstatus " ]) == 0 ) {
// User is not assigned to receipt this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2015-04-20 11:43:40 +00:00
}
$indstatus = array_pop ( $receiptStatus [ " indstatus " ]);
if ( $indstatus [ " status " ] != 0 ) {
// User has already submitted a receipt or has already been deleted;
// return an error.
return - 3 ;
}
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $indstatus [ " receiptID " ] . " ', '-2', '', CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
return 0 ;
} /* }}} */
function delGrpRecipient ( $group , $requestUser ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$groupID = $group -> getID ();
// Check to see if the user can be removed from the recipient list.
$receiptStatus = $group -> getReceiptStatus ( $this -> _document -> getID (), $this -> _version );
if ( is_bool ( $receiptStatus ) && ! $receiptStatus ) {
return - 1 ;
}
2015-04-20 16:33:42 +00:00
if ( count ( $receiptStatus [ " status " ]) == 0 ) {
2015-04-20 11:43:40 +00:00
// User is not assigned to receipt this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2015-04-20 11:43:40 +00:00
}
2015-04-20 16:33:42 +00:00
$status = array_pop ( $receiptStatus [ " status " ]);
if ( $tatus [ " status " ] != 0 ) {
2015-04-20 11:43:40 +00:00
// User has already submitted a receipt or has already been deleted;
// return an error.
return - 3 ;
}
$queryStr = " INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) " .
2015-04-20 16:33:42 +00:00
" VALUES (' " . $status [ " receiptID " ] . " ', '-2', '', CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
2015-04-20 11:43:40 +00:00
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
return 0 ;
} /* }}} */
2015-05-11 07:29:34 +00:00
/**
* Removes a user from the revision workflow
*
* This methods behaves differently from one in the other workflows , e . g .
* { @ see SeedDMS_Core_DocumentContent :: delIndReviewer }, because it
* also takes into account if the workflow has been started already .
* A workflow has been started , when there are entries in the revision log .
* If the revision workflow has not been started , then the user will
* be silently removed from the list of revisors . If the workflow has
* started already , then log entry will indicated the removal of the
* user ( just as it is done with the other workflows )
*
* @ param object $object user / group which is to be removed
* @ param object $requestUser user requesting the removal
* @ return integer 0 if removal was successfull , - 1 if an internal error
* occured , - 3 if the user is not in the list of revisors
*
*/
function delRevisor ( $object , $requestUser , $msg = '' ) { /* {{{ */
$dms = $this -> _document -> _dms ;
$db = $dms -> getDB ();
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
/* getRevisionStatus () returns an array with either an element
* 'indstatus' ( user ) or 'status' ( group ) containing the revision log
*/
if ( get_class ( $object ) == $dms -> getClassname ( 'user' )) {
$field = 'indstatus' ;
$type = 0 ;
} elseif ( get_class ( $object ) == $dms -> getClassname ( 'group' )) {
$field = 'status' ;
$type = 1 ;
} else {
return - 1 ;
}
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
// Check to see if the user/group can be removed from the revisor list.
$revisionStatus = $object -> getRevisionStatus ( $this -> _document -> getID (), $this -> _version );
2015-04-22 08:31:36 +00:00
if ( is_bool ( $revisionStatus ) && ! $revisionStatus ) {
return - 1 ;
}
2015-05-11 07:29:34 +00:00
if ( ! isset ( $revisionStatus [ $field ])) {
2015-04-22 08:31:36 +00:00
// User is not assigned to revision this document. No action required.
// Return an error.
2015-05-11 07:29:34 +00:00
return - 2 ;
2015-04-22 08:31:36 +00:00
}
2015-05-11 07:29:34 +00:00
/* If the revision log doesn ' t contain an entry yet , then remove the
* user / group from the list of revisors . The first case should not happen .
*/
if ( count ( $revisionStatus [ $field ]) == 0 ) {
$queryStr = " DELETE from tblDocumentRevisors WHERE `documentID` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version . " AND `type` = " . $type . " AND `required` = " . $object -> getID ();
echo $queryStr ;
if ( ! $db -> getResult ( $queryStr )) {
return - 1 ;
}
} else {
$indstatus = array_pop ( $revisionStatus [ $field ]);
if ( $indstatus [ " status " ] != S_LOG_WAITING && $indstatus [ " status " ] != S_LOG_SLEEPING ) {
// User has already submitted a revision or has already been deleted;
// return an error.
return - 3 ;
}
$queryStr = " INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`, `comment`, `date`, `userID`) " .
" VALUES (' " . $indstatus [ " revisionID " ] . " ', ' " . S_LOG_USER_REMOVED . " ', " . $db -> qstr ( $msg ) . " , CURRENT_TIMESTAMP, ' " . $requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
return - 1 ;
}
2015-04-22 08:31:36 +00:00
}
return 0 ;
} /* }}} */
2015-05-11 07:29:34 +00:00
function delIndRevisor ( $user , $requestUser , $msg = '' ) { /* {{{ */
return self :: delRevisor ( $user , $requestUser , $msg );
} /* }}} */
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
function delGrpRevisor ( $group , $requestUser , $msg = '' ) { /* {{{ */
return self :: delRevisor ( $group , $requestUser , $msg );
} /* }}} */
2015-04-22 08:31:36 +00:00
2015-05-11 07:29:34 +00:00
/**
* Start a new revision workflow
*
* This function starts a new revision unless there are users / groups
* having finished the previous revision . This means the log status
* must be S_LOG_SLEEPING or the user / group was removed ( S_LOG_USER_REMOVED )
*
* @ param object $requestUser user requesting the revision start
* @ param string $msg message saved for the initial log message
*/
function startRevision ( $requestUser , $msg = '' ) { /* {{{ */
$dms = $this -> _document -> _dms ;
$db = $dms -> getDB ();
$revisionStatus = self :: getRevisionStatus ();
if ( ! $revisionStatus )
return false ;
/* A new revision may only be started if we are not in the middle of
* revision or the user / group has been removed from the workflow
*/
foreach ( $revisionStatus as $status ) {
if ( $status [ 'status' ] != S_LOG_SLEEPING && $status [ 'status' ] != S_LOG_USER_REMOVED )
return false ;
2015-04-22 08:31:36 +00:00
}
2015-05-12 17:07:59 +00:00
/* Make sure all Logs will be set to the right status , in order to
* prevent inconsistent states . Actually it could be a feature to
* force only some users / groups to revise the document , but for now
* this may not be possible .
*/
2015-05-11 07:29:34 +00:00
$db -> startTransaction ();
foreach ( $revisionStatus as $status ) {
if ( $status [ 'status' ] == S_LOG_SLEEPING ) {
$queryStr = " INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $status [ " revisionID " ] . " ', " .
S_LOG_WAITING . " , " . $db -> qstr ( $msg ) . " , CURRENT_TIMESTAMP, ' " .
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
$db -> rollbackTransaction ();
return false ;
}
}
2015-04-22 08:31:36 +00:00
}
2015-05-12 17:07:59 +00:00
if ( ! $this -> setStatus ( S_IN_REVISION , " Started revision " , $requestUser )) {
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
return true ;
} /* }}} */
/**
* Finish a revision workflow
*
* This function ends a revision This means the log status
* is set back S_LOG_SLEEPING and the document status is set as
* passed to the method . The function doesn ' t not check if all
* users / groups has made it vote already .
*
* @ param object $requestUser user requesting the revision start
* @ param integer $docstatus document status
* @ param string $msg message saved in revision log
* @ param string $msg message saved in document status log
*/
function finishRevision ( $requestUser , $docstatus , $msg = '' , $docmsg = '' ) { /* {{{ */
$dms = $this -> _document -> _dms ;
$db = $dms -> getDB ();
$revisionStatus = self :: getRevisionStatus ();
if ( ! $revisionStatus )
return false ;
/* A revision may only be finished if it wasn ' t finished already
*/
foreach ( $revisionStatus as $status ) {
if ( $status [ 'status' ] == S_LOG_SLEEPING )
return false ;
}
/* Make sure all Logs will be set to the right status , in order to
* prevent inconsistent states . Actually it could be a feature to
* end only some users / groups to revise the document , but for now
* this may not be possible .
*/
$db -> startTransaction ();
foreach ( $revisionStatus as $status ) {
if ( $status [ 'status' ] != S_LOG_SLEEPING && $status [ 'status' ] != S_LOG_USER_REMOVED ) {
$queryStr = " INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`,
`comment` , `date` , `userID` ) " .
" VALUES (' " . $status [ " revisionID " ] . " ', " .
S_LOG_SLEEPING . " , " . $db -> qstr ( $msg ) . " , CURRENT_TIMESTAMP, ' " .
$requestUser -> getID () . " ') " ;
$res = $db -> getResult ( $queryStr );
if ( is_bool ( $res ) && ! $res ) {
$db -> rollbackTransaction ();
return false ;
}
}
}
if ( ! $this -> setStatus ( $docstatus , $docmsg , $requestUser )) {
$db -> rollbackTransaction ();
return false ;
}
2015-05-11 07:29:34 +00:00
$db -> commitTransaction ();
return true ;
2015-04-22 08:31:36 +00:00
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Set state of workflow assigned to the document content
*
* @ param object $state
*/
function setWorkflowState ( $state ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( $this -> _workflow ) {
$queryStr = " UPDATE tblWorkflowDocumentContent set state= " . $state -> getID () . " WHERE workflow= " . intval ( $this -> _workflow -> getID ()) . " AND document= " . intval ( $this -> _document -> getID ()) . " AND version= " . intval ( $this -> _version ) . " " ;
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
$this -> _workflowState = $state ;
return true ;
}
return false ;
} /* }}} */
/**
* Get state of workflow assigned to the document content
*
2013-02-14 11:10:53 +00:00
* @ return object / boolean an object of class SeedDMS_Core_Workflow_State
2013-01-24 08:29:58 +00:00
* or false in case of error , e . g . the version has not a workflow
*/
function getWorkflowState () { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
if ( ! $this -> _workflowState ) {
$queryStr =
" SELECT b.* FROM tblWorkflowDocumentContent a LEFT JOIN tblWorkflowStates b ON a.state = b.id WHERE workflow= " . intval ( $this -> _workflow -> getID ())
. " AND a.version=' " . $this -> _version
. " ' AND a.document = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
return false ;
2013-02-14 11:10:53 +00:00
$this -> _workflowState = new SeedDMS_Core_Workflow_State ( $recs [ 0 ][ 'id' ], $recs [ 0 ][ 'name' ], $recs [ 0 ][ 'maxtime' ], $recs [ 0 ][ 'precondfunc' ], $recs [ 0 ][ 'documentstatus' ]);
2013-01-24 08:29:58 +00:00
$this -> _workflowState -> setDMS ( $this -> _document -> _dms );
}
return $this -> _workflowState ;
} /* }}} */
/**
* Assign a workflow to a document
*
* @ param object $workflow
*/
function setWorkflow ( $workflow , $user ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$this -> getWorkflow ();
if ( $workflow && is_object ( $workflow )) {
2013-02-06 13:52:11 +00:00
$db -> startTransaction ();
2013-01-24 08:29:58 +00:00
$initstate = $workflow -> getInitState ();
2015-09-22 05:50:36 +00:00
$queryStr = " INSERT INTO tblWorkflowDocumentContent (workflow, document, version, state, date) VALUES ( " . $workflow -> getID () . " , " . $this -> _document -> getID () . " , " . $this -> _version . " , " . $initstate -> getID () . " , " . $db -> getCurrentDatetime () . " ) " ;
2013-01-24 08:29:58 +00:00
if ( ! $db -> getResult ( $queryStr )) {
2013-02-06 13:52:11 +00:00
$db -> rollbackTransaction ();
2013-01-24 08:29:58 +00:00
return false ;
}
$this -> _workflow = $workflow ;
2013-02-06 13:52:11 +00:00
if ( ! $this -> setStatus ( S_IN_WORKFLOW , " Added workflow ' " . $workflow -> getName () . " ' " , $user )) {
$db -> rollbackTransaction ();
return false ;
}
$db -> commitTransaction ();
2013-01-24 08:29:58 +00:00
return true ;
}
return true ;
} /* }}} */
/**
* Get workflow assigned to the document content
*
2013-03-15 16:59:23 +00:00
* The method returns the last workflow if one was assigned .
* If a the document version is in a sub workflow , it will have
* a never date and therefore will be found first .
2013-01-24 08:29:58 +00:00
*
2013-02-14 11:10:53 +00:00
* @ return object / boolean an object of class SeedDMS_Core_Workflow
2013-01-24 08:29:58 +00:00
* or false in case of error , e . g . the version has not a workflow
*/
function getWorkflow () { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! isset ( $this -> _workflow )) {
$queryStr =
" SELECT b.* FROM tblWorkflowDocumentContent a LEFT JOIN tblWorkflows b ON a.workflow = b.id WHERE a.`version`=' " . $this -> _version
. " ' AND a.`document` = ' " . $this -> _document -> getID () . " ' "
2013-03-15 16:59:23 +00:00
. " ORDER BY date DESC LIMIT 1 " ;
2013-01-24 08:29:58 +00:00
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
return false ;
if ( ! $recs )
return false ;
2013-02-14 11:10:53 +00:00
$this -> _workflow = new SeedDMS_Core_Workflow ( $recs [ 0 ][ 'id' ], $recs [ 0 ][ 'name' ], $this -> _document -> _dms -> getWorkflowState ( $recs [ 0 ][ 'initstate' ]));
2013-01-24 08:29:58 +00:00
$this -> _workflow -> setDMS ( $this -> _document -> _dms );
}
return $this -> _workflow ;
} /* }}} */
/**
* Restart workflow from its initial state
*
* @ return boolean true if workflow could be restarted
* or false in case of error
*/
function rewindWorkflow () { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$this -> getWorkflow ();
if ( ! isset ( $this -> _workflow )) {
return true ;
}
$db -> startTransaction ();
$queryStr = " DELETE from tblWorkflowLog WHERE `document` = " . $this -> _document -> getID () . " AND `version` = " . $this -> _version . " AND `workflow` = " . $this -> _workflow -> getID ();
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$this -> setWorkflowState ( $this -> _workflow -> getInitState ());
$db -> commitTransaction ();
return true ;
} /* }}} */
/**
* Remove workflow
*
* Fully removing a workflow including entries in the workflow log is
* only allowed if the workflow is still its initial state .
* At a later point of time only unlinking the document from the
* workflow is allowed . It will keep any log entries .
* A workflow is unlinked from a document when enterNextState ()
* succeeds .
*
* @ param object $user user doing initiating the removal
* @ param boolean $unlink if true , just unlink the workflow from the
* document but do not remove the workflow log . The $unlink
* flag has been added to detach the workflow from the document
* when it has reached a valid end state
2013-02-14 11:10:53 +00:00
( see SeedDMS_Core_DocumentContent :: enterNextState ())
2013-01-24 08:29:58 +00:00
* @ return boolean true if workflow could be removed
* or false in case of error
*/
function removeWorkflow ( $user , $unlink = false ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
$this -> getWorkflow ();
if ( ! isset ( $this -> _workflow )) {
return true ;
}
2013-02-14 11:10:53 +00:00
if ( SeedDMS_Core_DMS :: checkIfEqual ( $this -> _workflow -> getInitState (), $this -> getWorkflowState ()) || $unlink == true ) {
2013-01-24 08:29:58 +00:00
$db -> startTransaction ();
$queryStr =
" DELETE FROM tblWorkflowDocumentContent WHERE "
. " `version`=' " . $this -> _version . " ' "
. " AND `document` = ' " . $this -> _document -> getID () . " ' "
. " AND `workflow` = ' " . $this -> _workflow -> getID () . " ' " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
if ( ! $unlink ) {
$queryStr =
" DELETE FROM tblWorkflowLog WHERE "
. " `version`=' " . $this -> _version . " ' "
. " AND `document` = ' " . $this -> _document -> getID () . " ' "
. " AND `workflow` = ' " . $this -> _workflow -> getID () . " ' " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
}
$this -> _workflow = null ;
$this -> _workflowState = null ;
2015-05-04 06:27:20 +00:00
$this -> verifyStatus ( false , $user , 'Workflow removed' );
2013-01-24 08:29:58 +00:00
$db -> commitTransaction ();
}
return true ;
} /* }}} */
/**
* Run a sub workflow
*
* @ param object $subworkflow
*/
function getParentWorkflow () { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
/* document content must be in a workflow */
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
$queryStr =
" SELECT * FROM tblWorkflowDocumentContent WHERE "
. " `version`=' " . $this -> _version . " ' "
. " AND `document` = ' " . $this -> _document -> getID () . " ' "
. " AND `workflow` = ' " . $this -> _workflow -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs )
return false ;
if ( ! $recs )
return false ;
if ( $recs [ 0 ][ 'parentworkflow' ])
return $this -> _document -> _dms -> getWorkflow ( $recs [ 0 ][ 'parentworkflow' ]);
return false ;
} /* }}} */
/**
* Run a sub workflow
*
* @ param object $subworkflow
*/
function runSubWorkflow ( $subworkflow ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
/* document content must be in a workflow */
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
/* The current workflow state must match the sub workflows initial state */
if ( $subworkflow -> getInitState () -> getID () != $this -> _workflowState -> getID ())
return false ;
if ( $subworkflow ) {
$initstate = $subworkflow -> getInitState ();
2015-09-22 05:50:36 +00:00
$queryStr = " INSERT INTO tblWorkflowDocumentContent (parentworkflow, workflow, document, version, state, date) VALUES ( " . $this -> _workflow -> getID () . " , " . $subworkflow -> getID () . " , " . $this -> _document -> getID () . " , " . $this -> _version . " , " . $initstate -> getID () . " , " . $db -> getCurrentDatetime () . " ) " ;
2013-01-24 08:29:58 +00:00
if ( ! $db -> getResult ( $queryStr )) {
return false ;
}
$this -> _workflow = $subworkflow ;
return true ;
}
return true ;
} /* }}} */
/**
* Return from sub workflow to parent workflow .
* The method will trigger the given transition
*
* FIXME : Needs much better checking if this is allowed
*
* @ param object $user intiating the return
* @ param object $transtion to trigger
* @ param string comment for the transition trigger
*/
function returnFromSubWorkflow ( $user , $transition = null , $comment = '' ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
/* document content must be in a workflow */
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
if ( isset ( $this -> _workflow )) {
$db -> startTransaction ();
$queryStr =
" SELECT * FROM tblWorkflowDocumentContent WHERE workflow= " . intval ( $this -> _workflow -> getID ())
. " AND `version`=' " . $this -> _version
. " ' AND `document` = ' " . $this -> _document -> getID () . " ' " ;
$recs = $db -> getResultArray ( $queryStr );
if ( is_bool ( $recs ) && ! $recs ) {
$db -> rollbackTransaction ();
return false ;
}
if ( ! $recs ) {
$db -> rollbackTransaction ();
return false ;
}
$queryStr = " DELETE FROM `tblWorkflowDocumentContent` WHERE `workflow` = " . intval ( $this -> _workflow -> getID ()) . " AND `document` = ' " . $this -> _document -> getID () . " ' AND `version` = ' " . $this -> _version . " ' " ;
if ( ! $db -> getResult ( $queryStr )) {
$db -> rollbackTransaction ();
return false ;
}
$this -> _workflow = $this -> _document -> _dms -> getWorkflow ( $recs [ 0 ][ 'parentworkflow' ]);
$this -> _workflow -> setDMS ( $this -> _document -> _dms );
if ( $transition ) {
echo " Trigger transition " ;
if ( false === $this -> triggerWorkflowTransition ( $user , $transition , $comment )) {
$db -> rollbackTransaction ();
return false ;
}
}
$db -> commitTransaction ();
}
return $this -> _workflow ;
} /* }}} */
/**
* Check if the user is allowed to trigger the transition
* A user is allowed if either the user itself or
* a group of which the user is a member of is registered for
* triggering a transition . This method does not change the workflow
* state of the document content .
*
* @ param object $user
* @ return boolean true if user may trigger transaction
*/
function triggerWorkflowTransitionIsAllowed ( $user , $transition ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
if ( ! $this -> _workflowState )
$this -> getWorkflowState ();
/* Check if the user has already triggered the transition */
$queryStr =
" SELECT * FROM tblWorkflowLog WHERE `version`=' " . $this -> _version . " ' AND `document` = ' " . $this -> _document -> getID () . " ' AND `workflow` = " . $this -> _workflow -> getID () . " AND userid = " . $user -> getID ();
$queryStr .= " AND `transition` = " . $transition -> getID ();
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
if ( count ( $resArr ))
return false ;
/* Get all transition users allowed to trigger the transition */
$transusers = $transition -> getUsers ();
if ( $transusers ) {
foreach ( $transusers as $transuser ) {
if ( $user -> getID () == $transuser -> getUser () -> getID ())
return true ;
}
}
/* Get all transition groups whose members are allowed to trigger
* the transition */
$transgroups = $transition -> getGroups ();
if ( $transgroups ) {
foreach ( $transgroups as $transgroup ) {
$group = $transgroup -> getGroup ();
if ( $group -> isMember ( $user ))
return true ;
}
}
return false ;
} /* }}} */
/**
* Check if all conditions are met to change the workflow state
* of a document content ( run the transition ) .
* The conditions are met if all explicitly set users and a sufficient
* number of users of the groups have acknowledged the content .
*
* @ return boolean true if transaction maybe executed
*/
function executeWorkflowTransitionIsAllowed ( $transition ) { /* {{{ */
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
if ( ! $this -> _workflowState )
$this -> getWorkflowState ();
/* Get the Log of transition triggers */
$entries = $this -> getWorkflowLog ( $transition );
if ( ! $entries )
return false ;
/* Get all transition users allowed to trigger the transition
* $allowedusers is a list of all users allowed to trigger the
* transition
*/
$transusers = $transition -> getUsers ();
$allowedusers = array ();
foreach ( $transusers as $transuser ) {
$a = $transuser -> getUser ();
$allowedusers [ $a -> getID ()] = $a ;
}
/* Get all transition groups whose members are allowed to trigger
* the transition */
$transgroups = $transition -> getGroups ();
foreach ( $entries as $entry ) {
$loguser = $entry -> getUser ();
/* Unset each allowed user if it was found in the log */
if ( isset ( $allowedusers [ $loguser -> getID ()]))
unset ( $allowedusers [ $loguser -> getID ()]);
/* Also check groups if required . Count the group membership of
* each user in the log in the array $gg
*/
if ( $transgroups ) {
$loggroups = $loguser -> getGroups ();
foreach ( $loggroups as $loggroup ) {
if ( ! isset ( $gg [ $loggroup -> getID ()]))
$gg [ $loggroup -> getID ()] = 1 ;
else
$gg [ $loggroup -> getID ()] ++ ;
}
}
}
/* If there are allowed users left , then there some users still
* need to trigger the transition .
*/
if ( $allowedusers )
return false ;
if ( $transgroups ) {
foreach ( $transgroups as $transgroup ) {
$group = $transgroup -> getGroup ();
$minusers = $transgroup -> getNumOfUsers ();
if ( ! isset ( $gg [ $group -> getID ()]))
return false ;
if ( $gg [ $group -> getID ()] < $minusers )
return false ;
}
}
return true ;
} /* }}} */
/**
* Trigger transition
*
* This method will be deprecated
*
* The method will first check if the user is allowed to trigger the
* transition . If the user is allowed , an entry in the workflow log
* will be added , which is later used to check if the transition
* can actually be processed . The method will finally call
* executeWorkflowTransitionIsAllowed () which checks all log entries
* and does the transitions post function if all users and groups have
* triggered the transition . Finally enterNextState () is called which
* will try to enter the next state .
*
* @ param object $user
* @ param object $transition
* @ param string $comment user comment
* @ return boolean / object next state if transition could be triggered and
* then next state could be entered ,
* true if the transition could just be triggered or
* false in case of an error
*/
function triggerWorkflowTransition ( $user , $transition , $comment = '' ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
if ( ! $this -> _workflowState )
$this -> getWorkflowState ();
if ( ! $this -> _workflowState )
return false ;
/* Check if the user is allowed to trigger the transition .
*/
if ( ! $this -> triggerWorkflowTransitionIsAllowed ( $user , $transition ))
return false ;
$state = $this -> _workflowState ;
2015-09-22 05:50:36 +00:00
$queryStr = " INSERT INTO tblWorkflowLog (document, version, workflow, userid, transition, date, comment) VALUES ( " . $this -> _document -> getID () . " , " . $this -> _version . " , " . ( int ) $this -> _workflow -> getID () . " , " . ( int ) $user -> getID () . " , " . ( int ) $transition -> getID () . " , " . $db -> getCurrentDatetime () . " , " . $db -> qstr ( $comment ) . " ) " ;
2013-01-24 08:29:58 +00:00
if ( ! $db -> getResult ( $queryStr ))
return false ;
/* Check if this transition is processed . Run the post function in
* that case . A transition is processed when all users and groups
* have triggered it .
*/
if ( $this -> executeWorkflowTransitionIsAllowed ( $transition )) {
/* run post function of transition */
// echo "run post function of transition ".$transition->getID()."<br />";
}
/* Go into the next state . This will only succeed if the pre condition
* function of that states succeeds .
*/
$nextstate = $transition -> getNextState ();
if ( $this -> enterNextState ( $user , $nextstate )) {
return $nextstate ;
}
return true ;
} /* }}} */
/**
* Enter next state of workflow if possible
*
* The method will check if one of the following states in the workflow
* can be reached .
* It does it by running
* the precondition function of that state . The precondition function
* gets a list of all transitions leading to the state . It will
* determine , whether the transitions has been triggered and if that
* is sufficient to enter the next state . If no pre condition function
* is set , then 1 of n transtions are enough to enter the next state .
*
* If moving in the next state is possible and this state has a
* corresponding document state , then the document state will be
* updated and the workflow will be detached from the document .
*
* @ param object $user
* @ param object $nextstate
* @ return boolean true if the state could be reached
* false if not
*/
function enterNextState ( $user , $nextstate ) { /* {{{ */
/* run the pre condition of the next state . If it is not set
* the next state will be reached if one of the transitions
* leading to the given state can be processed .
*/
if ( $nextstate -> getPreCondFunc () == '' ) {
$transitions = $this -> _workflow -> getPreviousTransitions ( $nextstate );
foreach ( $transitions as $transition ) {
// echo "transition ".$transition->getID()." led to state ".$nextstate->getName()."<br />";
if ( $this -> executeWorkflowTransitionIsAllowed ( $transition )) {
// echo "stepping into next state<br />";
$this -> setWorkflowState ( $nextstate );
/* Check if the new workflow state has a mapping into a
* document state . If yes , set the document state will
* be updated and the workflow will be removed from the
* document .
*/
$docstate = $nextstate -> getDocumentStatus ();
if ( $docstate == S_RELEASED || $docstate == S_REJECTED ) {
$this -> setStatus ( $docstate , " Workflow has ended " , $user );
/* Detach the workflow from the document , but keep the
* workflow log
*/
$this -> removeWorkflow ( $user , true );
return true ;
}
/* make sure the users and groups allowed to trigger the next
* transitions are also allowed to read the document
*/
$transitions = $this -> _workflow -> getNextTransitions ( $nextstate );
foreach ( $transitions as $tran ) {
// echo "checking access for users/groups allowed to trigger transition ".$tran->getID()."<br />";
$transusers = $tran -> getUsers ();
foreach ( $transusers as $transuser ) {
$u = $transuser -> getUser ();
// echo $u->getFullName()."<br />";
if ( $this -> _document -> getAccessMode ( $u ) < M_READ ) {
$this -> _document -> addAccess ( M_READ , $u -> getID (), 1 );
// echo "granted read access<br />";
} else {
// echo "has already access<br />";
}
}
$transgroups = $tran -> getGroups ();
foreach ( $transgroups as $transgroup ) {
$g = $transgroup -> getGroup ();
// echo $g->getName()."<br />";
if ( $this -> _document -> getGroupAccessMode ( $g ) < M_READ ) {
$this -> _document -> addAccess ( M_READ , $g -> getID (), 0 );
// echo "granted read access<br />";
} else {
// echo "has already access<br />";
}
}
}
return ( true );
} else {
// echo "transition not ready for process now<br />";
}
}
return false ;
} else {
}
} /* }}} */
/**
* Get the so far logged operations on the document content within the
* workflow
*
* @ return array list of operations
*/
function getWorkflowLog ( $transition = null ) { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
2013-03-08 13:20:27 +00:00
/*
2013-01-24 08:29:58 +00:00
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
2013-03-08 13:20:27 +00:00
*/
2013-01-24 08:29:58 +00:00
$queryStr =
2013-03-08 13:20:27 +00:00
" SELECT * FROM tblWorkflowLog WHERE `version`=' " . $this -> _version . " ' AND `document` = ' " . $this -> _document -> getID () . " ' " ; // AND `workflow` = ". $this->_workflow->getID();
2013-01-24 08:29:58 +00:00
if ( $transition )
$queryStr .= " AND `transition` = " . $transition -> getID ();
$queryStr .= " ORDER BY `date` " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$workflowlogs = array ();
for ( $i = 0 ; $i < count ( $resArr ); $i ++ ) {
2013-03-08 13:20:27 +00:00
$workflow = $this -> _document -> _dms -> getWorkflow ( $resArr [ $i ][ " workflow " ]);
$workflowlog = new SeedDMS_Core_Workflow_Log ( $resArr [ $i ][ " id " ], $this -> _document -> _dms -> getDocument ( $resArr [ $i ][ " document " ]), $resArr [ $i ][ " version " ], $workflow , $this -> _document -> _dms -> getUser ( $resArr [ $i ][ " userid " ]), $workflow -> getTransition ( $resArr [ $i ][ " transition " ]), $resArr [ $i ][ " date " ], $resArr [ $i ][ " comment " ]);
2013-01-24 08:29:58 +00:00
$workflowlog -> setDMS ( $this );
$workflowlogs [ $i ] = $workflowlog ;
}
return $workflowlogs ;
} /* }}} */
/**
* Get the latest logged transition for the document content within the
* workflow
*
* @ return array list of operations
*/
function getLastWorkflowTransition () { /* {{{ */
$db = $this -> _document -> _dms -> getDB ();
if ( ! $this -> _workflow )
$this -> getWorkflow ();
if ( ! $this -> _workflow )
return false ;
$queryStr =
" SELECT * FROM tblWorkflowLog WHERE `version`=' " . $this -> _version . " ' AND `document` = ' " . $this -> _document -> getID () . " ' AND `workflow` = " . $this -> _workflow -> getID ();
$queryStr .= " ORDER BY `id` DESC LIMIT 1 " ;
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$workflowlogs = array ();
$i = 0 ;
2013-02-14 11:10:53 +00:00
$workflowlog = new SeedDMS_Core_Workflow_Log ( $resArr [ $i ][ " id " ], $this -> _document -> _dms -> getDocument ( $resArr [ $i ][ " document " ]), $resArr [ $i ][ " version " ], $this -> _workflow , $this -> _document -> _dms -> getUser ( $resArr [ $i ][ " userid " ]), $this -> _workflow -> getTransition ( $resArr [ $i ][ " transition " ]), $resArr [ $i ][ " date " ], $resArr [ $i ][ " comment " ]);
2013-01-24 08:29:58 +00:00
$workflowlog -> setDMS ( $this );
return $workflowlog ;
} /* }}} */
2013-04-18 11:36:11 +00:00
/**
* Check if the document content needs an action by a user
*
* This method will return true if document content is in a transition
* which can be triggered by the given user .
*
* @ param SeedDMS_Core_User $user
* @ return boolean true is action is needed
*/
function needsWorkflowAction ( $user ) { /* {{{ */
$needwkflaction = false ;
if ( $this -> _workflow ) {
if ( ! $this -> _workflowState )
$this -> getWorkflowState ();
$workflowstate = $this -> _workflowState ;
$transitions = $this -> _workflow -> getNextTransitions ( $workflowstate );
foreach ( $transitions as $transition ) {
if ( $this -> triggerWorkflowTransitionIsAllowed ( $user , $transition )) {
$needwkflaction = true ;
}
}
}
return $needwkflaction ;
} /* }}} */
2010-11-12 22:47:41 +00:00
} /* }}} */
2010-11-04 07:57:17 +00:00
2010-11-30 12:23:46 +00:00
/**
* Class to represent a link between two document
*
* Document links are to establish a reference from one document to
* another document . The owner of the document link may not be the same
* as the owner of one of the documents .
2013-02-14 11:10:53 +00:00
* Use { @ link SeedDMS_Core_Document :: addDocumentLink ()} to add a reference
2010-11-30 12:23:46 +00:00
* to another document .
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ 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 @
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_DocumentLink { /* {{{ */
2013-01-24 08:29:58 +00:00
/**
* @ var integer internal id of document link
*/
protected $_id ;
/**
* @ var object reference to document this link belongs to
*/
protected $_document ;
/**
* @ var object reference to target document this link points to
*/
protected $_target ;
/**
* @ var integer id of user who is the owner of this link
*/
protected $_userID ;
/**
* @ var integer 1 if this link is public , or 0 if is only visible to the owner
*/
protected $_public ;
2010-11-18 13:53:26 +00:00
2013-02-14 11:10:53 +00:00
function SeedDMS_Core_DocumentLink ( $id , $document , $target , $userID , $public ) {
2010-11-18 13:53:26 +00:00
$this -> _id = $id ;
$this -> _document = $document ;
$this -> _target = $target ;
$this -> _userID = $userID ;
$this -> _public = $public ;
}
function getID () { return $this -> _id ; }
function getDocument () {
return $this -> _document ;
}
function getTarget () {
return $this -> _target ;
}
function getUser () {
if ( ! isset ( $this -> _user ))
$this -> _user = $this -> _document -> _dms -> getUser ( $this -> _userID );
return $this -> _user ;
}
function isPublic () { return $this -> _public ; }
2010-11-12 22:47:41 +00:00
} /* }}} */
2010-10-29 13:19:51 +00:00
2010-11-30 12:23:46 +00:00
/**
* Class to represent a file attached to a document
*
* Beside the regular document content arbitrary files can be attached
* to a document . This is a similar concept as attaching files to emails .
* The owner of the attached file and the document may not be the same .
2013-02-14 11:10:53 +00:00
* Use { @ link SeedDMS_Core_Document :: addDocumentFile ()} to attach a file .
2010-11-30 12:23:46 +00:00
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ 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 @
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_DocumentFile { /* {{{ */
2013-01-24 08:29:58 +00:00
/**
* @ var integer internal id of document file
*/
protected $_id ;
/**
* @ var object reference to document this file belongs to
*/
protected $_document ;
/**
* @ var integer id of user who is the owner of this link
*/
protected $_userID ;
/**
* @ var string comment for the attached file
*/
protected $_comment ;
/**
* @ var string date when the file was attached
*/
protected $_date ;
/**
* @ var string directory where the file is stored . This is the
* document id with a proceding '/' .
* FIXME : looks like this isn ' t used anymore . The file path is
* constructed by getPath ()
*/
protected $_dir ;
/**
* @ var string extension of the original file name with a leading '.'
*/
protected $_fileType ;
/**
* @ var string mime type of the file
*/
protected $_mimeType ;
2015-05-11 07:29:34 +00:00
/**
* @ var string date when revision starts
*/
protected $_revisionDate ;
2013-01-24 08:29:58 +00:00
/**
* @ var string name of the file that was originally uploaded
*/
protected $_orgFileName ;
/**
* @ var string name of the file as given by the user
*/
protected $_name ;
2010-11-18 13:53:26 +00:00
2013-02-14 11:10:53 +00:00
function SeedDMS_Core_DocumentFile ( $id , $document , $userID , $comment , $date , $dir , $fileType , $mimeType , $orgFileName , $name ) {
2010-11-18 13:53:26 +00:00
$this -> _id = $id ;
$this -> _document = $document ;
$this -> _userID = $userID ;
$this -> _comment = $comment ;
$this -> _date = $date ;
$this -> _dir = $dir ;
$this -> _fileType = $fileType ;
$this -> _mimeType = $mimeType ;
$this -> _orgFileName = $orgFileName ;
2010-10-29 13:19:51 +00:00
$this -> _name = $name ;
2010-11-18 13:53:26 +00:00
}
function getID () { return $this -> _id ; }
function getDocument () { return $this -> _document ; }
function getUserID () { return $this -> _userID ; }
function getComment () { return $this -> _comment ; }
function getDate () { return $this -> _date ; }
function getDir () { return $this -> _dir ; }
function getFileType () { return $this -> _fileType ; }
function getMimeType () { return $this -> _mimeType ; }
function getOriginalFileName () { return $this -> _orgFileName ; }
2010-10-29 13:19:51 +00:00
function getName () { return $this -> _name ; }
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
function getUser () {
if ( ! isset ( $this -> _user ))
$this -> _user = $this -> _document -> _dms -> getUser ( $this -> _userID );
return $this -> _user ;
2010-10-29 13:19:51 +00:00
}
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
function getPath () {
2012-04-11 11:30:58 +00:00
return $this -> _document -> getDir () . " f " . $this -> _id . $this -> _fileType ;
2010-11-18 13:53:26 +00:00
}
2010-11-12 22:47:41 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
//
// Perhaps not the cleanest object ever devised, it exists to encapsulate all
// of the data generated during the addition of new content to the database.
// The object stores a copy of the new DocumentContent object, the newly assigned
// reviewers and approvers and the status.
//
2010-11-30 12:23:46 +00:00
/**
* Class to represent a list of document contents
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ 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 @
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_AddContentResultSet { /* {{{ */
2010-11-30 09:27:37 +00:00
2013-01-24 08:29:58 +00:00
protected $_indReviewers ;
protected $_grpReviewers ;
protected $_indApprovers ;
protected $_grpApprovers ;
protected $_content ;
protected $_status ;
2010-11-18 13:53:26 +00:00
2015-05-21 20:09:33 +00:00
/**
* @ var object back reference to document management system
*/
protected $_dms ;
2013-02-14 11:10:53 +00:00
function SeedDMS_Core_AddContentResultSet ( $content ) { /* {{{ */
2010-11-18 13:53:26 +00:00
$this -> _content = $content ;
$this -> _indReviewers = null ;
$this -> _grpReviewers = null ;
$this -> _indApprovers = null ;
$this -> _grpApprovers = null ;
$this -> _status = null ;
2015-05-21 20:09:33 +00:00
$this -> _dms = null ;
} /* }}} */
/*
* Set dms this object belongs to .
*
* Each object needs a reference to the dms it belongs to . It will be
* set when the object is created .
* 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 ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function addReviewer ( $reviewer , $type , $status ) { /* {{{ */
2015-05-11 07:29:34 +00:00
$dms = $this -> _dms ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! is_object ( $reviewer ) || ( strcasecmp ( $type , " i " ) && strcasecmp ( $type , " g " )) && ! is_integer ( $status )){
return false ;
}
if ( ! strcasecmp ( $type , " i " )) {
2015-05-11 07:29:34 +00:00
if ( strcasecmp ( get_class ( $reviewer ), $dms -> getClassname ( " user " ))) {
2010-11-18 13:53:26 +00:00
return false ;
}
if ( $this -> _indReviewers == null ) {
$this -> _indReviewers = array ();
}
$this -> _indReviewers [ $status ][] = $reviewer ;
}
if ( ! strcasecmp ( $type , " g " )) {
2015-05-11 07:29:34 +00:00
if ( strcasecmp ( get_class ( $reviewer ), $dms -> getClassname ( " group " ))) {
2010-11-18 13:53:26 +00:00
return false ;
}
if ( $this -> _grpReviewers == null ) {
$this -> _grpReviewers = array ();
}
$this -> _grpReviewers [ $status ][] = $reviewer ;
}
return true ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function addApprover ( $approver , $type , $status ) { /* {{{ */
2015-05-11 07:29:34 +00:00
$dms = $this -> _dms ;
2010-11-30 09:27:37 +00:00
2010-11-18 13:53:26 +00:00
if ( ! is_object ( $approver ) || ( strcasecmp ( $type , " i " ) && strcasecmp ( $type , " g " )) && ! is_integer ( $status )){
return false ;
}
if ( ! strcasecmp ( $type , " i " )) {
2015-05-11 07:29:34 +00:00
if ( strcasecmp ( get_class ( $approver ), $dms -> getClassname ( " user " ))) {
2010-11-18 13:53:26 +00:00
return false ;
}
if ( $this -> _indApprovers == null ) {
$this -> _indApprovers = array ();
}
$this -> _indApprovers [ $status ][] = $approver ;
}
if ( ! strcasecmp ( $type , " g " )) {
2015-05-11 07:29:34 +00:00
if ( strcasecmp ( get_class ( $approver ), $dms -> getClassname ( " group " ))) {
2010-11-18 13:53:26 +00:00
return false ;
}
if ( $this -> _grpApprovers == null ) {
$this -> _grpApprovers = array ();
}
$this -> _grpApprovers [ $status ][] = $approver ;
}
return true ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function setStatus ( $status ) { /* {{{ */
2010-11-18 13:53:26 +00:00
if ( ! is_integer ( $status )) {
return false ;
}
if ( $status <- 3 || $status > 2 ) {
return false ;
}
$this -> _status = $status ;
return true ;
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function getStatus () { /* {{{ */
2010-11-18 13:53:26 +00:00
return $this -> _status ;
2013-01-24 08:29:58 +00:00
} /* }}} */
function getContent () { /* {{{ */
return $this -> _content ;
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function getReviewers ( $type ) { /* {{{ */
2010-11-18 13:53:26 +00:00
if ( strcasecmp ( $type , " i " ) && strcasecmp ( $type , " g " )) {
return false ;
}
if ( ! strcasecmp ( $type , " i " )) {
return ( $this -> _indReviewers == null ? array () : $this -> _indReviewers );
}
else {
return ( $this -> _grpReviewers == null ? array () : $this -> _grpReviewers );
}
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-18 13:53:26 +00:00
2013-01-24 08:29:58 +00:00
function getApprovers ( $type ) { /* {{{ */
2010-11-18 13:53:26 +00:00
if ( strcasecmp ( $type , " i " ) && strcasecmp ( $type , " g " )) {
return false ;
}
if ( ! strcasecmp ( $type , " i " )) {
return ( $this -> _indApprovers == null ? array () : $this -> _indApprovers );
}
else {
return ( $this -> _grpApprovers == null ? array () : $this -> _grpApprovers );
}
2013-01-24 08:29:58 +00:00
} /* }}} */
2010-11-12 22:47:41 +00:00
} /* }}} */
2010-10-29 13:19:51 +00:00
?>