2010-11-12 22:40:12 +00:00
< ? php
2010-11-30 12:23:46 +00:00
/**
* Implementation of the document management system
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ license GPL 2
* @ author Uwe Steinmann < uwe @ steinmann . cx >
2021-09-20 14:31:42 +00:00
* @ copyright 2010 Uwe Steinmann
2010-11-30 12:23:46 +00:00
* @ version Release : @ package_version @
*/
2010-11-12 22:40:12 +00:00
2010-11-30 12:23:46 +00:00
/**
* Include some files
*/
2010-11-22 20:42:19 +00:00
require_once ( " inc.AccessUtils.php " );
2010-11-25 21:04:53 +00:00
require_once ( " inc.FileUtils.php " );
2010-11-27 20:52:03 +00:00
require_once ( " inc.ClassAccess.php " );
2012-10-09 09:53:11 +00:00
require_once ( " inc.ClassObject.php " );
2010-11-12 22:40:12 +00:00
require_once ( " inc.ClassFolder.php " );
require_once ( " inc.ClassDocument.php " );
2010-11-27 20:52:03 +00:00
require_once ( " inc.ClassGroup.php " );
require_once ( " inc.ClassUser.php " );
require_once ( " inc.ClassKeywords.php " );
2010-12-22 19:48:08 +00:00
require_once ( " inc.ClassNotification.php " );
2012-10-09 09:53:11 +00:00
require_once ( " inc.ClassAttribute.php " );
2010-11-12 22:40:12 +00:00
/**
2010-12-22 19:48:08 +00:00
* Class to represent the complete document management system .
* This class is needed to do most of the dms operations . It needs
2013-02-14 11:10:53 +00:00
* an instance of { @ link SeedDMS_Core_DatabaseAccess } to access the
2010-12-22 19:48:08 +00:00
* underlying database . Many methods are factory functions which create
* objects representing the entities in the dms , like folders , documents ,
* users , or groups .
*
2011-01-20 14:26:02 +00:00
* Each dms has its own database for meta data and a data store for document
* content . Both must be specified when creating a new instance of this class .
* All folders and documents are organized in a hierachy like
2010-12-22 19:48:08 +00:00
* a regular file system starting with a { @ link $rootFolderID }
*
* This class does not enforce any access rights on documents and folders
* by design . It is up to the calling application to use the methods
2013-02-14 11:10:53 +00:00
* { @ link SeedDMS_Core_Folder :: getAccessMode ()} and
* { @ link SeedDMS_Core_Document :: getAccessMode ()} and interpret them as desired .
2016-10-05 07:14:03 +00:00
* Though , there are two convenient functions to filter a list of
2011-01-14 19:40:38 +00:00
* documents / folders for which users have access rights for . See
2016-10-05 07:14:03 +00:00
* { @ link filterAccess ()}
* and { @ link filterUsersByAccess ()}
2010-12-22 19:48:08 +00:00
*
2016-10-05 07:14:03 +00:00
* Though , this class has a method to set the currently logged in user
* ({ @ link setUser }), it does not have to be called , because
2013-02-14 11:10:53 +00:00
* there is currently no class within the SeedDMS core which needs the logged
2016-10-05 07:14:03 +00:00
* in user . { @ link SeedDMS_Core_DMS } itself does not do any user authentication .
* It is up to the application using this class .
2010-12-22 19:48:08 +00:00
*
* < code >
* < ? php
* include ( " inc/inc.ClassDMS.php " );
2013-02-14 11:10:53 +00:00
* $db = new SeedDMS_Core_DatabaseAccess ( $type , $hostname , $user , $passwd , $name );
2010-12-22 19:48:08 +00:00
* $db -> connect () or die ( " Could not connect to db-server " );
2013-02-14 11:10:53 +00:00
* $dms = new SeedDMS_Core_DMS ( $db , $contentDir );
2010-12-22 19:48:08 +00:00
* $dms -> setRootFolderID ( 1 );
* ...
* ?>
* </ code >
2010-11-12 22:40:12 +00:00
*
* @ category DMS
2013-02-14 11:10:53 +00:00
* @ package SeedDMS_Core
2010-11-30 12:23:46 +00:00
* @ version @ version @
2010-11-12 22:40:12 +00:00
* @ author Uwe Steinmann < uwe @ steinmann . cx >
* @ copyright Copyright ( C ) 2010 , Uwe Steinmann
* @ version Release : @ package_version @
*/
2013-02-14 11:10:53 +00:00
class SeedDMS_Core_DMS {
2010-11-12 22:40:12 +00:00
/**
2017-10-24 12:00:56 +00:00
* @ var SeedDMS_Core_DatabaseAccess $db reference to database object . This must be an instance
2013-02-14 11:10:53 +00:00
* of { @ link SeedDMS_Core_DatabaseAccess } .
2010-11-12 22:40:12 +00:00
* @ access protected
*/
protected $db ;
2014-12-08 13:34:11 +00:00
/**
* @ var array $classnames list of classnames for objects being instanciate
* by the dms
* @ access protected
*/
protected $classnames ;
2019-08-08 06:39:53 +00:00
/**
* @ var array $decorators list of decorators for objects being instanciate
* by the dms
* @ access protected
*/
protected $decorators ;
2010-11-15 12:01:21 +00:00
/**
2017-10-24 09:53:31 +00:00
* @ var SeedDMS_Core_User $user reference to currently logged in user . This must be
2013-02-14 11:10:53 +00:00
* an instance of { @ link SeedDMS_Core_User } . This variable is currently not
2010-12-22 19:48:08 +00:00
* used . It is set by { @ link setUser } .
* @ access private
2010-11-15 12:01:21 +00:00
*/
2010-12-22 19:48:08 +00:00
private $user ;
2010-11-15 12:01:21 +00:00
2010-11-12 22:40:12 +00:00
/**
2010-11-30 12:23:46 +00:00
* @ var string $contentDir location in the file system where all the
2010-12-22 19:48:08 +00:00
* document data is located . This should be an absolute path .
2010-11-12 22:40:12 +00:00
* @ access public
*/
public $contentDir ;
2010-11-15 21:08:07 +00:00
/**
* @ var integer $rootFolderID ID of root folder
* @ access public
*/
public $rootFolderID ;
2014-11-24 14:07:46 +00:00
/**
* @ var integer $maxDirID maximum number of documents per folder on the
* filesystem . If this variable is set to a value != 0 , the content
* directory will have a two level hierarchy for document storage .
* @ access public
*/
public $maxDirID ;
/**
* @ var boolean $forceRename use renameFile () instead of copyFile () when
* copying the document content into the data store . The default is
* to copy the file . This parameter only affects the methods
* SeedDMS_Core_Document :: addDocument () and
* SeedDMS_Core_Document :: addDocumentFile () . Setting this to true
* may save resources especially for large files .
* @ access public
*/
public $forceRename ;
2016-04-12 05:44:48 +00:00
/**
* @ var array $noReadForStatus list of status without read right
2017-07-05 08:47:23 +00:00
* online . DO NOT USE ANYMORE . SeedDMS_Core_DocumentContent :: getAccessMode ()
* was the only method using it , but it now takes the noReadForStatus info
* from the user ' s role
2016-04-12 05:44:48 +00:00
* @ access public
*/
public $noReadForStatus ;
2020-12-16 15:47:49 +00:00
/**
* @ var boolean $checkWithinRootDir check if folder / document being accessed
* is within the rootdir
* @ access public
*/
public $checkWithinRootDir ;
2011-02-03 15:10:46 +00:00
/**
* @ var string $version version of pear package
* @ access public
*/
public $version ;
2013-01-24 08:29:58 +00:00
/**
* @ var array $callbacks list of methods called when certain operations ,
* like removing a document , are executed . Set a callback with
2013-02-14 11:10:53 +00:00
* { @ link SeedDMS_Core_DMS :: setCallback ()} .
2013-01-24 08:29:58 +00:00
* The key of the array is the internal callback function name . Each
* array element is an array with two elements : the function name
* and the parameter passed to the function .
*
* Currently implemented callbacks are :
*
* onPreRemoveDocument ( $user_param , $document );
* called before deleting a document . If this function returns false
* the document will not be deleted .
*
* onPostRemoveDocument ( $user_param , $document_id );
* called after the successful deletion of a document .
*
* @ access public
*/
public $callbacks ;
2020-03-25 07:04:39 +00:00
/**
* @ var string last error message . This can be set by hooks to pass an
* error message from the hook to the application which has called the
* method containing the hook . For example SeedDMS_Core_Document :: remove ()
* calls the hook 'onPreRemoveDocument' . The hook function can set $dms -> lasterror
* which can than be read when SeedDMS_Core_Document :: remove () fails .
* This variable could be set in any SeedDMS_Core class , but is currently
* only set by hooks .
* @ access public
*/
public $lasterror ;
2018-02-08 08:25:45 +00:00
/**
* @ var SeedDMS_Core_DMS
*/
2020-03-25 07:04:39 +00:00
// public $_dms;
2013-01-24 08:29:58 +00:00
/**
2016-10-05 07:14:03 +00:00
* Checks if two objects are equal by comparing their IDs
2013-01-24 08:29:58 +00:00
*
* The regular php check done by '==' compares all attributes of
2021-09-17 16:21:57 +00:00
* two objects , which is often not required . This method will first check
2016-10-05 07:14:03 +00:00
* if the objects are instances of the same class and than if they
* have the same id .
2013-01-24 08:29:58 +00:00
*
2014-11-19 06:44:54 +00:00
* @ param object $object1 first object to be compared
* @ param object $object2 second object to be compared
2013-01-24 08:29:58 +00:00
* @ return boolean true if objects are equal , otherwise false
*/
static function checkIfEqual ( $object1 , $object2 ) { /* {{{ */
if ( get_class ( $object1 ) != get_class ( $object2 ))
return false ;
if ( $object1 -> getID () != $object2 -> getID ())
return false ;
return true ;
} /* }}} */
2015-03-17 16:45:12 +00:00
/**
2016-10-05 07:14:03 +00:00
* Checks if a list of objects contains a single object by comparing their IDs
2015-03-17 16:45:12 +00:00
*
2015-06-29 08:27:23 +00:00
* This function is only applicable on list containing objects which have
* a method getID () because it is used to check if two objects are equal .
* The regular php check on objects done by '==' compares all attributes of
2015-03-17 16:45:12 +00:00
* two objects , which isn ' t required . The method will first check
* if the objects are instances of the same class .
*
2015-06-29 08:27:23 +00:00
* The result of the function can be 0 which happens if the first element
* of an indexed array matches .
*
2017-10-24 09:53:31 +00:00
* @ param object $object object to look for ( needle )
2015-03-17 16:45:12 +00:00
* @ param array $list list of objects ( haystack )
2015-06-29 08:27:23 +00:00
* @ return boolean / integer index in array if object was found , otherwise false
2015-03-17 16:45:12 +00:00
*/
static function inList ( $object , $list ) { /* {{{ */
2015-06-29 08:27:23 +00:00
foreach ( $list as $i => $item ) {
2015-03-17 16:45:12 +00:00
if ( get_class ( $item ) == get_class ( $object ) && $item -> getID () == $object -> getID ())
2015-06-29 08:27:23 +00:00
return $i ;
2015-03-17 16:45:12 +00:00
}
return false ;
} /* }}} */
2015-07-31 13:30:00 +00:00
/**
* Checks if date conforms to a given format
*
* @ param string $date date to be checked
2016-10-05 07:14:03 +00:00
* @ param string $format format of date . Will default to 'Y-m-d H:i:s' if
* format is not given .
2015-07-31 13:30:00 +00:00
* @ return boolean true if date is in propper format , otherwise false
*/
2015-08-04 05:37:48 +00:00
static function checkDate ( $date , $format = 'Y-m-d H:i:s' ) { /* {{{ */
2015-07-31 13:30:00 +00:00
$d = DateTime :: createFromFormat ( $format , $date );
return $d && $d -> format ( $format ) == $date ;
} /* }}} */
2010-11-22 20:42:19 +00:00
/**
2016-10-05 07:14:03 +00:00
* Filter out objects which are not accessible in a given mode by a user .
*
* The list of objects to be checked can be of any class , but has to have
* a method getAccessMode ( $user ) which checks if the given user has at
2021-09-17 16:21:57 +00:00
* least the access right on the object as passed in $minMode .
* Hence , passing a group instead of user is possible .
2010-11-22 20:42:19 +00:00
*
2016-04-12 05:44:48 +00:00
* This function can be used for documents and folders and calls
* { @ link SeedDMS_Core_Folder :: getAccessMode ()} or
* { @ link SeedDMS_Core_Document :: getAccessMode ()} . A document is also
* filtered out if it has no latest content , which can happen if access
* on documents in a certain state has been restricted .
*
2010-11-22 20:42:19 +00:00
* @ param array $objArr list of objects ( either documents or folders )
* @ param object $user user for which access is checked
2016-10-05 07:14:03 +00:00
* @ param integer $minMode minimum access mode required ( M_ANY , M_NONE ,
* M_READ , M_READWRITE , M_ALL )
2010-11-22 20:42:19 +00:00
* @ return array filtered list of objects
*/
static function filterAccess ( $objArr , $user , $minMode ) { /* {{{ */
if ( ! is_array ( $objArr )) {
return array ();
}
$newArr = array ();
foreach ( $objArr as $obj ) {
2016-04-12 05:44:48 +00:00
if ( $obj -> getAccessMode ( $user ) >= $minMode ) {
2020-01-24 07:53:04 +00:00
$dms = $obj -> getDMS ();
2020-06-05 15:45:31 +00:00
if ( $obj -> isType ( 'document' )) {
2016-04-12 05:44:48 +00:00
if ( $obj -> getLatestContent ())
array_push ( $newArr , $obj );
} else {
array_push ( $newArr , $obj );
}
}
2010-11-22 20:42:19 +00:00
}
return $newArr ;
} /* }}} */
/**
2016-10-05 07:14:03 +00:00
* Filter out users which cannot access an object in a given mode .
*
* The list of users to be checked can be of any class , but has to have
2021-09-17 16:21:57 +00:00
* a method getAccessMode ( $user ) which checks if a user has at least the
* access right as passed in $minMode . Hence , passing a list of groups
* instead of users is possible .
2010-11-22 20:42:19 +00:00
*
* @ param object $obj object that shall be accessed
2021-09-17 16:21:57 +00:00
* @ param array $users list of users / groups which are to check for sufficient
2010-11-22 20:42:19 +00:00
* access rights
* @ param integer $minMode minimum access right on the object for each user
2016-10-05 07:14:03 +00:00
* ( M_ANY , M_NONE , M_READ , M_READWRITE , M_ALL )
2010-11-22 20:42:19 +00:00
* @ return array filtered list of users
*/
static function filterUsersByAccess ( $obj , $users , $minMode ) { /* {{{ */
$newArr = array ();
foreach ( $users as $currUser ) {
if ( $obj -> getAccessMode ( $currUser ) >= $minMode )
array_push ( $newArr , $currUser );
}
return $newArr ;
} /* }}} */
2013-04-10 13:39:05 +00:00
/**
2016-10-05 07:14:03 +00:00
* Filter out document links which can not be accessed by a given user
2013-04-10 13:39:05 +00:00
*
* Returns a filtered list of links which are accessible by the
2016-10-05 07:14:03 +00:00
* given user . A link is only accessible , if it is publically visible ,
* owned by the user , or the accessing user is an administrator .
2013-04-10 13:39:05 +00:00
*
2017-10-24 10:12:38 +00:00
* @ param SeedDMS_Core_DocumentLink [] $links list of objects of type SeedDMS_Core_DocumentLink
2013-04-10 13:39:05 +00:00
* @ param object $user user for which access is being checked
2017-01-16 11:59:02 +00:00
* @ param string $access set if source or target of link shall be checked
* for sufficient access rights . Set to 'source' if the source document
* of a link is to be checked , set to 'target' for the target document .
* If not set , then access right aren ' t checked at all .
2015-06-29 08:27:23 +00:00
* @ return array filtered list of links
2013-04-10 13:39:05 +00:00
*/
2017-01-16 11:59:02 +00:00
static function filterDocumentLinks ( $user , $links , $access = '' ) { /* {{{ */
2013-04-10 13:39:05 +00:00
$tmp = array ();
2017-01-16 11:59:02 +00:00
foreach ( $links as $link ) {
if ( $link -> isPublic () || ( $link -> getUser () -> getID () == $user -> getID ()) || $user -> isAdmin ()){
if ( $access == 'source' ) {
$obj = $link -> getDocument ();
if ( $obj -> getAccessMode ( $user ) >= M_READ )
array_push ( $tmp , $link );
} elseif ( $access == 'target' ) {
$obj = $link -> getTarget ();
if ( $obj -> getAccessMode ( $user ) >= M_READ )
array_push ( $tmp , $link );
} else {
array_push ( $tmp , $link );
}
}
}
2013-04-10 13:39:05 +00:00
return $tmp ;
} /* }}} */
2015-06-29 08:27:23 +00:00
/**
* Merge access lists
*
* Merges two access lists . Objects of the second list will override objects
* in the first list .
*
* @ param array $first list of access rights as returned by
* SeedDMS_Core_Document :: getAccessList () or SeedDMS_Core_Folder :: getAccessList ()
* @ param array $secont list of access rights
* @ return array merged list
*/
static function mergeAccessLists ( $first , $second ) { /* {{{ */
if ( $first && ! $second )
return $first ;
if ( ! $first && $second )
return $second ;
$tmp = array ( 'users' => array (), 'groups' => array ());
if ( ! isset ( $first [ 'users' ]) || ! isset ( $first [ 'groups' ]) ||
! isset ( $second [ 'users' ]) || ! isset ( $second [ 'groups' ]))
return false ;
foreach ( $first [ 'users' ] as $f ) {
$new = $f ;
foreach ( $second [ 'users' ] as $i => $s ) {
if ( $f -> getUserID () == $s -> getUserID ()) {
$new = $s ;
unset ( $second [ 'users' ][ $i ]);
break ;
}
}
array_push ( $tmp [ 'users' ], $new );
}
foreach ( $seconf [ 'users' ] as $f ) {
array_push ( $tmp [ 'users' ], $f );
}
foreach ( $first [ 'groups' ] as $f ) {
$new = $f ;
foreach ( $second [ 'groups' ] as $i => $s ) {
if ( $f -> getGroupID () == $s -> getGroupID ()) {
$new = $s ;
unset ( $second [ 'groups' ][ $i ]);
break ;
}
}
array_push ( $tmp [ 'groups' ], $new );
}
foreach ( $second [ 'groups' ] as $f ) {
array_push ( $tmp [ 'groups' ], $f );
}
return $tmp ;
} /* }}} */
2017-02-20 16:34:43 +00:00
/*
2016-11-24 10:42:37 +00:00
* Filter out document attachments which can not be accessed by a given user
*
* Returns a filtered list of files which are accessible by the
* given user . A file is only accessible , if it is publically visible ,
* owned by the user , or the accessing user is an administrator .
*
* @ param array $files list of objects of type SeedDMS_Core_DocumentFile
* @ param object $user user for which access is being checked
* @ return array filtered list of files
*/
static function filterDocumentFiles ( $user , $files ) { /* {{{ */
$tmp = array ();
2018-01-23 19:50:44 +00:00
if ( $files ) {
foreach ( $files as $file )
if ( $file -> isPublic () || ( $file -> getUser () -> getID () == $user -> getID ()) || $user -> isAdmin () || ( $file -> getDocument () -> getOwner () -> getID () == $user -> getID ()))
array_push ( $tmp , $file );
}
2016-11-24 10:42:37 +00:00
return $tmp ;
} /* }}} */
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedClassInspection */
2010-12-22 19:48:08 +00:00
/**
* Create a new instance of the dms
*
2018-02-08 08:25:45 +00:00
* @ param SeedDMS_Core_DatabaseAccess $db object of class { @ link SeedDMS_Core_DatabaseAccess }
2016-10-05 07:14:03 +00:00
* to access the underlying database
2010-12-22 19:48:08 +00:00
* @ param string $contentDir path in filesystem containing the data store
* all document contents is stored
*/
function __construct ( $db , $contentDir ) { /* {{{ */
2010-11-12 22:40:12 +00:00
$this -> db = $db ;
2010-12-22 19:48:08 +00:00
if ( substr ( $contentDir , - 1 ) == '/' )
$this -> contentDir = $contentDir ;
else
$this -> contentDir = $contentDir . '/' ;
2010-11-15 21:08:07 +00:00
$this -> rootFolderID = 1 ;
2021-09-17 16:22:35 +00:00
$this -> user = null ;
2011-12-08 18:36:57 +00:00
$this -> maxDirID = 0 ; //31998;
2014-11-24 14:07:46 +00:00
$this -> forceRename = false ;
2020-12-16 15:47:49 +00:00
$this -> checkWithinRootDir = false ;
2016-04-12 05:44:48 +00:00
$this -> noReadForStatus = array ();
2018-04-03 09:27:12 +00:00
$this -> user = null ;
2014-12-08 13:34:11 +00:00
$this -> classnames = array ();
$this -> classnames [ 'folder' ] = 'SeedDMS_Core_Folder' ;
$this -> classnames [ 'document' ] = 'SeedDMS_Core_Document' ;
$this -> classnames [ 'documentcontent' ] = 'SeedDMS_Core_DocumentContent' ;
$this -> classnames [ 'user' ] = 'SeedDMS_Core_User' ;
2016-02-24 13:32:55 +00:00
$this -> classnames [ 'role' ] = 'SeedDMS_Core_Role' ;
2014-12-08 13:34:11 +00:00
$this -> classnames [ 'group' ] = 'SeedDMS_Core_Group' ;
2015-04-27 06:24:26 +00:00
$this -> classnames [ 'transmittal' ] = 'SeedDMS_Core_Transmittal' ;
$this -> classnames [ 'transmittalitem' ] = 'SeedDMS_Core_TransmittalItem' ;
2016-04-26 10:06:41 +00:00
$this -> callbacks = array ();
2020-03-25 07:04:39 +00:00
$this -> lasterror = '' ;
2011-02-03 15:10:46 +00:00
$this -> version = '@package_version@' ;
if ( $this -> version [ 0 ] == '@' )
2021-12-11 13:08:19 +00:00
$this -> version = '6.0.18' ;
2010-11-15 21:08:07 +00:00
} /* }}} */
2014-12-08 13:34:11 +00:00
/**
2019-08-08 06:39:53 +00:00
* Return class name of classes instanciated by SeedDMS_Core
2014-12-08 13:34:11 +00:00
*
2017-10-24 11:36:07 +00:00
* This method returns the class name of those objects being instantiated
2014-12-08 13:34:11 +00:00
* by the dms . Each class has an internal place holder , which must be
* passed to function .
*
2017-10-24 11:36:07 +00:00
* @ param string $objectname placeholder ( can be one of 'folder' , 'document' ,
2019-08-08 06:39:53 +00:00
* 'documentcontent' , 'user' , 'group' )
2014-12-08 13:34:11 +00:00
*
2019-08-08 06:39:53 +00:00
* @ return string / boolean name of class or false if object name is invalid
2014-12-08 13:34:11 +00:00
*/
function getClassname ( $objectname ) { /* {{{ */
if ( isset ( $this -> classnames [ $objectname ]))
return $this -> classnames [ $objectname ];
else
return false ;
} /* }}} */
/**
* Set class name of instantiated objects
*
* This method sets the class name of those objects being instatiated
2015-04-14 17:37:06 +00:00
* by the dms . It is mainly used to create a new class ( possible
* inherited from one of the available classes ) implementing new
* features . The method should be called in the postInitDMS hook .
2014-12-08 13:34:11 +00:00
*
2017-10-24 11:36:07 +00:00
* @ param string $objectname placeholder ( can be one of 'folder' , 'document' ,
2014-12-08 13:34:11 +00:00
* 'documentcontent' , 'user' , 'group'
2017-10-24 11:36:07 +00:00
* @ param string $classname name of class
2014-12-08 13:34:11 +00:00
*
* @ return string / boolean name of old class or false if not set
*/
function setClassname ( $objectname , $classname ) { /* {{{ */
if ( isset ( $this -> classnames [ $objectname ]))
$oldclass = $this -> classnames [ $objectname ];
else
$oldclass = false ;
$this -> classnames [ $objectname ] = $classname ;
return $oldclass ;
} /* }}} */
2019-08-08 06:39:53 +00:00
/**
* Return list of decorators
*
* This method returns the list of decorator class names of those objects
* being instantiated
* by the dms . Each class has an internal place holder , which must be
* passed to function .
*
* @ param string $objectname placeholder ( can be one of 'folder' , 'document' ,
* 'documentcontent' , 'user' , 'group' )
*
* @ return array / boolean list of class names or false if object name is invalid
*/
function getDecorators ( $objectname ) { /* {{{ */
if ( isset ( $this -> decorators [ $objectname ]))
return $this -> decorators [ $objectname ];
else
return false ;
} /* }}} */
/**
* Add a decorator
*
* This method adds a single decorator class name to the list of decorators
* of those objects being instantiated
* by the dms . Each class has an internal place holder , which must be
* passed to function .
*
* @ param string $objectname placeholder ( can be one of 'folder' , 'document' ,
* 'documentcontent' , 'user' , 'group' )
*
* @ return boolean true if decorator could be added , otherwise false
*/
function addDecorator ( $objectname , $decorator ) { /* {{{ */
$this -> decorators [ $objectname ][] = $decorator ;
return true ;
} /* }}} */
2014-11-19 06:44:54 +00:00
/**
* Return database where meta data is stored
*
* This method returns the database object as it was set by the first
* parameter of the constructor .
*
2017-10-24 12:00:56 +00:00
* @ return SeedDMS_Core_DatabaseAccess database
2014-11-19 06:44:54 +00:00
*/
2010-11-16 09:07:19 +00:00
function getDB () { /* {{{ */
return $this -> db ;
} /* }}} */
2011-02-03 15:10:46 +00:00
/**
* Return the database version
*
2017-10-24 11:36:07 +00:00
* @ return array | bool
2011-02-03 15:10:46 +00:00
*/
function getDBVersion () { /* {{{ */
$tbllist = $this -> db -> TableList ();
2011-03-23 13:28:17 +00:00
$tbllist = explode ( ',' , strtolower ( join ( ',' , $tbllist )));
2021-09-16 14:05:04 +00:00
if ( ! in_array ( 'tblversion' , $tbllist ))
2011-02-03 15:10:46 +00:00
return false ;
2021-09-17 16:23:25 +00:00
$queryStr = " SELECT * FROM `tblVersion` ORDER BY `major`,`minor`,`subminor` LIMIT 1 " ;
2011-02-03 15:10:46 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
$resArr = $resArr [ 0 ];
return $resArr ;
} /* }}} */
/**
* Check if the version in the database is the same as of this package
* Only the major and minor version number will be checked .
*
2011-11-28 14:03:01 +00:00
* @ return boolean returns false if versions do not match , but returns
* true if version matches or table tblVersion does not exists .
2011-02-03 15:10:46 +00:00
*/
function checkVersion () { /* {{{ */
$tbllist = $this -> db -> TableList ();
2011-03-23 13:28:17 +00:00
$tbllist = explode ( ',' , strtolower ( join ( ',' , $tbllist )));
2021-09-16 14:05:04 +00:00
if ( ! in_array ( 'tblversion' , $tbllist ))
2011-11-28 14:03:01 +00:00
return true ;
2021-09-17 16:23:25 +00:00
$queryStr = " SELECT * FROM `tblVersion` ORDER BY `major`,`minor`,`subminor` LIMIT 1 " ;
2011-02-03 15:10:46 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
$resArr = $resArr [ 0 ];
$ver = explode ( '.' , $this -> version );
if (( $resArr [ 'major' ] != $ver [ 0 ]) || ( $resArr [ 'minor' ] != $ver [ 1 ]))
return false ;
return true ;
} /* }}} */
2010-12-22 19:48:08 +00:00
/**
* Set id of root folder
2021-09-17 16:24:32 +00:00
*
2010-12-22 19:48:08 +00:00
* This function must be called right after creating an instance of
2013-02-14 11:10:53 +00:00
* { @ link SeedDMS_Core_DMS }
2010-12-22 19:48:08 +00:00
*
2021-09-17 16:24:32 +00:00
* The new root folder id will only be set if the folder actually
* exists . In that case the old root folder id will be returned .
* If it does not exists , the method will return false ;
2017-10-24 11:36:07 +00:00
* @ param integer $id id of root folder
2021-09-17 16:24:32 +00:00
* @ return boolean / int old root folder id if new root folder exists , otherwise false
2010-12-22 19:48:08 +00:00
*/
2010-11-15 21:08:07 +00:00
function setRootFolderID ( $id ) { /* {{{ */
2021-09-17 16:24:32 +00:00
if ( $this -> getFolder ( $id )) {
$oldid = $this -> rootFolderID ;
$this -> rootFolderID = $id ;
return $oldid ;
}
return false ;
2010-11-15 21:08:07 +00:00
} /* }}} */
2010-12-22 19:48:08 +00:00
/**
2011-12-08 18:36:57 +00:00
* Set maximum number of subdirectories per directory
*
2014-11-19 06:44:54 +00:00
* The value of maxDirID is quite crucial , because each document is
* stored within a directory in the filesystem . Consequently , there can be
* a maximum number of documents , because depending on the file system
2011-12-08 18:36:57 +00:00
* the maximum number of subdirectories is limited . Since version 3.3 . 0 of
2014-11-19 06:44:54 +00:00
* SeedDMS an additional directory level has been introduced , which
* will be created when maxDirID is not 0. All documents
2011-12-08 18:36:57 +00:00
* from 1 to maxDirID - 1 will be saved in 1 /< docid > , documents from maxDirID
* to 2 * maxDirID - 1 are stored in 2 /< docid > and so on .
*
2014-11-19 06:44:54 +00:00
* Modern file systems like ext4 do not have any restrictions on the number
* of subdirectories anymore . Therefore it is best if this parameter is
* set to 0. Never change this parameter if documents has already been
* created .
*
2011-12-08 18:36:57 +00:00
* This function must be called right after creating an instance of
2013-02-14 11:10:53 +00:00
* { @ link SeedDMS_Core_DMS }
2011-12-08 18:36:57 +00:00
*
2017-10-24 11:36:07 +00:00
* @ param integer $id id of root folder
2011-12-08 18:36:57 +00:00
*/
function setMaxDirID ( $id ) { /* {{{ */
$this -> maxDirID = $id ;
} /* }}} */
/**
2010-12-22 19:48:08 +00:00
* Get root folder
*
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Folder | boolean return the object of the root folder or false if
2010-12-22 19:48:08 +00:00
* the root folder id was not set before with { @ link setRootFolderID } .
*/
2010-12-01 13:36:33 +00:00
function getRootFolder () { /* {{{ */
2010-12-22 19:48:08 +00:00
if ( ! $this -> rootFolderID ) return false ;
2010-12-01 13:36:33 +00:00
return $this -> getFolder ( $this -> rootFolderID );
} /* }}} */
2014-11-24 14:07:46 +00:00
function setForceRename ( $enable ) { /* {{{ */
$this -> forceRename = $enable ;
} /* }}} */
2010-11-15 12:01:21 +00:00
/**
* Set the logged in user
*
2018-04-03 09:27:12 +00:00
* This method tells SeeDMS_Core_DMS the currently logged in user . It must be
* called right after instanciating the class , because some methods in
* SeedDMS_Core_Document () require the currently logged in user .
2010-11-15 12:01:21 +00:00
*
2021-09-17 16:25:23 +00:00
* @ param object $user this muss not be empty and an instance of SeedDMS_Core_User
* @ return bool | object returns the old user object or null on success , otherwise false
2010-11-15 12:01:21 +00:00
*
*/
function setUser ( $user ) { /* {{{ */
2021-09-17 16:25:23 +00:00
if ( ! $user ) {
$olduser = $this -> user ;
$this -> user = null ;
return $olduser ;
}
if ( is_object ( $user ) && ( get_class ( $user ) == $this -> getClassname ( 'user' ))) {
$olduser = $this -> user ;
$this -> user = $user ;
return $olduser ;
}
return false ;
2010-11-15 12:01:21 +00:00
} /* }}} */
2016-04-12 05:44:48 +00:00
/**
* Get the logged in user
*
2018-04-03 09:27:12 +00:00
* Returns the currently logged in user , as set by setUser ()
2016-04-12 05:44:48 +00:00
*
2017-10-28 12:28:12 +00:00
* @ return SeedDMS_Core_User $user
2016-04-12 05:44:48 +00:00
*
*/
function getLoggedInUser () { /* {{{ */
return $this -> user ;
} /* }}} */
2010-11-12 22:40:12 +00:00
/**
* Return a document by its id
*
* This function retrieves a document from the database by its id .
*
* @ param integer $id internal id of document
2021-09-16 14:05:04 +00:00
* @ return SeedDMS_Core_Document instance of { @ link SeedDMS_Core_Document }, null or false
2010-11-12 22:40:12 +00:00
*/
function getDocument ( $id ) { /* {{{ */
2014-12-08 13:34:11 +00:00
$classname = $this -> classnames [ 'document' ];
return $classname :: getInstance ( $id , $this );
2010-11-12 22:40:12 +00:00
} /* }}} */
2010-11-22 14:49:29 +00:00
/**
* Returns all documents of a given user
*
* @ param object $user
* @ return array list of documents
*/
function getDocumentsByUser ( $user ) { /* {{{ */
2013-02-05 09:05:13 +00:00
return $user -> getDocuments ();
2010-11-22 14:49:29 +00:00
} /* }}} */
2012-08-28 07:28:16 +00:00
/**
* Returns all documents locked by a given user
*
* @ param object $user
* @ return array list of documents
*/
function getDocumentsLockedByUser ( $user ) { /* {{{ */
2013-02-05 09:05:13 +00:00
return $user -> getDocumentsLocked ();
2012-08-28 07:28:16 +00:00
} /* }}} */
2017-10-06 15:58:13 +00:00
/**
* Returns all documents which already expired or will expire in the future
*
2020-05-27 10:00:58 +00:00
* The parameter $date will be relative to the start of the day . It can
* be either a number of days ( if an integer is passed ) or a date string
* in the format 'YYYY-MM-DD' .
* If the parameter $date is a negative number or a date in the past , then
* all documents from the start of that date till the end of the current
* day will be returned . If $date is a positive integer or $date is a
2021-09-22 07:39:18 +00:00
* date in the future , then all documents from the start of the current
2020-05-27 10:00:58 +00:00
* day till the end of the day of the given date will be returned .
* Passing 0 or the
* current date in $date , will return all documents expiring the current
* day .
2017-10-06 15:58:13 +00:00
* @ param string $date date in format YYYY - MM - DD or an integer with the number
* of days . A negative value will cover the days in the past .
2020-05-27 10:00:58 +00:00
* @ param SeedDMS_Core_User $user limits the documents on those owned
* by this user
* @ param string $orderby n = name , e = expired
* @ param string $orderdir d = desc or a = asc
* @ param bool $update update status of document if set to true
2018-02-08 08:25:45 +00:00
* @ return bool | SeedDMS_Core_Document []
2017-10-06 15:58:13 +00:00
*/
2020-05-27 10:00:58 +00:00
function getDocumentsExpired ( $date , $user = null , $orderby = 'e' , $orderdir = 'desc' , $update = true ) { /* {{{ */
2017-10-06 15:58:13 +00:00
$db = $this -> getDB ();
2020-05-22 14:25:50 +00:00
if ( ! $db -> createTemporaryTable ( " ttstatid " ) || ! $db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
2020-06-28 11:57:34 +00:00
2020-05-27 10:00:58 +00:00
$tsnow = mktime ( 0 , 0 , 0 ); /* Start of today */
2017-10-06 15:58:13 +00:00
if ( is_int ( $date )) {
2020-05-27 10:00:58 +00:00
$ts = $tsnow + $date * 86400 ;
2017-10-06 15:58:13 +00:00
} elseif ( is_string ( $date )) {
$tmp = explode ( '-' , $date , 3 );
if ( count ( $tmp ) != 3 )
2021-09-22 07:39:18 +00:00
return false ;
if ( ! self :: checkDate ( $date , 'Y-m-d' ))
return false ;
2017-10-06 15:58:13 +00:00
$ts = mktime ( 0 , 0 , 0 , $tmp [ 1 ], $tmp [ 2 ], $tmp [ 0 ]);
} else
return false ;
if ( $ts < $tsnow ) { /* Check for docs expired in the past */
$startts = $ts ;
$endts = $tsnow + 86400 ; /* Use end of day */
2020-05-27 10:00:58 +00:00
$updatestatus = $update ;
2017-10-06 15:58:13 +00:00
} else { /* Check for docs which will expire in the future */
$startts = $tsnow ;
$endts = $ts + 86400 ; /* Use end of day */
$updatestatus = false ;
}
/* Get all documents which have an expiration date . It doesn ' t check for
* the latest status which should be S_EXPIRED , but doesn ' t have to , because
* status may have not been updated after the expiration date has been reached .
**/
$queryStr = " SELECT `tblDocuments`.`id`, `tblDocumentStatusLog`.`status` FROM `tblDocuments` " .
" LEFT JOIN `ttcontentid` ON `ttcontentid`.`document` = `tblDocuments`.`id` " .
" LEFT JOIN `tblDocumentContent` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` AND `tblDocumentContent`.`version` = `ttcontentid`.`maxVersion` " .
" LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID` = `tblDocumentContent`.`document` AND `tblDocumentContent`.`version` = `tblDocumentStatus`.`version` " .
" LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` " .
" LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusLogID` = `ttstatid`.`maxLogID` " ;
$queryStr .=
2020-05-27 10:00:58 +00:00
" WHERE `tblDocuments`.`expires` >= " . $startts . " AND `tblDocuments`.`expires` < " . $endts ;
2017-10-06 15:58:13 +00:00
if ( $user )
$queryStr .=
" AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " ;
$queryStr .=
2020-05-27 10:00:58 +00:00
" ORDER BY " . ( $orderby == 'e' ? " `expires` " : " `name` " ) . " " . ( $orderdir == 'd' ? " DESC " : " ASC " );
2017-10-06 15:58:13 +00:00
$resArr = $db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document[] $documents */
2017-10-06 15:58:13 +00:00
$documents = array ();
foreach ( $resArr as $row ) {
$document = $this -> getDocument ( $row [ " id " ]);
2020-05-27 10:00:58 +00:00
if ( $updatestatus ) {
2017-10-06 15:58:13 +00:00
$document -> verifyLastestContentExpriry ();
2020-05-27 10:00:58 +00:00
}
2017-10-06 15:58:13 +00:00
$documents [] = $document ;
}
return $documents ;
} /* }}} */
2010-12-01 13:36:33 +00:00
/**
* Returns a document by its name
*
* This function searches a document by its name and restricts the search
2020-07-28 16:12:13 +00:00
* to the given folder if passed as the second parameter .
2021-09-22 07:40:25 +00:00
* If there are more than one document with that name , then only the
* one with the highest id will be returned .
2010-12-01 13:36:33 +00:00
*
2021-09-22 07:40:25 +00:00
* @ param string $name Name of the document
* @ param object $folder parent folder of document
* @ return SeedDMS_Core_Document | null | boolean found document or null if not document was found or false in case of an error
2010-12-01 13:36:33 +00:00
*/
function getDocumentByName ( $name , $folder = null ) { /* {{{ */
2021-09-18 15:49:26 +00:00
$name = trim ( $name );
2010-12-01 13:36:33 +00:00
if ( ! $name ) return false ;
$queryStr = " SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` " .
" FROM `tblDocuments` " .
" LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` " .
2011-12-01 21:20:58 +00:00
" WHERE `tblDocuments`.`name` = " . $this -> db -> qstr ( $name );
2010-12-01 13:36:33 +00:00
if ( $folder )
$queryStr .= " AND `tblDocuments`.`folder` = " . $folder -> getID ();
2022-02-18 16:58:39 +00:00
if ( $this -> checkWithinRootDir )
$queryStr .= " AND `tblDocuments`.`folderList` LIKE '%: " . $this -> rootFolderID . " :%' " ;
2021-09-22 07:40:25 +00:00
$queryStr .= " ORDER BY `tblDocuments`.`id` DESC LIMIT 1 " ;
2010-12-01 13:36:33 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
if ( ! $resArr )
2021-09-22 07:40:25 +00:00
return null ;
2010-12-01 13:36:33 +00:00
$row = $resArr [ 0 ];
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document $document */
2015-02-05 06:37:50 +00:00
$document = new $this -> classnames [ 'document' ]( $row [ " id " ], $row [ " name " ], $row [ " comment " ], $row [ " date " ], $row [ " expires " ], $row [ " owner " ], $row [ " folder " ], $row [ " inheritAccess " ], $row [ " defaultAccess " ], $row [ " lockUser " ], $row [ " keywords " ], $row [ " sequence " ]);
2010-12-01 13:36:33 +00:00
$document -> setDMS ( $this );
return $document ;
} /* }}} */
2017-08-28 11:44:42 +00:00
/**
* Returns a document by the original file name of the last version
*
* This function searches a document by the name of the last document
* version and restricts the search
* to given folder if passed as the second parameter .
2021-09-22 07:41:23 +00:00
* If there are more than one document with that name , then only the
* one with the highest id will be returned .
2017-08-28 11:44:42 +00:00
*
2021-09-22 07:41:23 +00:00
* @ param string $name Name of the original file
* @ param object $folder parent folder of document
* @ return SeedDMS_Core_Document | null | boolean found document or null if not document was found or false in case of an error
2017-08-28 11:44:42 +00:00
*/
function getDocumentByOriginalFilename ( $name , $folder = null ) { /* {{{ */
2021-09-22 07:41:23 +00:00
$name = trim ( $name );
2017-08-28 11:44:42 +00:00
if ( ! $name ) return false ;
2020-06-23 07:58:38 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
2017-08-28 11:44:42 +00:00
$queryStr = " SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser` " .
" FROM `tblDocuments` " .
" LEFT JOIN `ttcontentid` ON `ttcontentid`.`document` = `tblDocuments`.`id` " .
" LEFT JOIN `tblDocumentContent` ON `tblDocumentContent`.`document` = `tblDocuments`.`id` AND `tblDocumentContent`.`version` = `ttcontentid`.`maxVersion` " .
" LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` " .
" WHERE `tblDocumentContent`.`orgFileName` = " . $this -> db -> qstr ( $name );
if ( $folder )
$queryStr .= " AND `tblDocuments`.`folder` = " . $folder -> getID ();
2021-09-22 07:41:23 +00:00
$queryStr .= " ORDER BY `tblDocuments`.`id` DESC LIMIT 1 " ;
2017-08-28 11:44:42 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
if ( ! $resArr )
2021-09-22 07:41:23 +00:00
return null ;
2010-12-01 13:36:33 +00:00
$row = $resArr [ 0 ];
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document $document */
2015-02-05 06:37:50 +00:00
$document = new $this -> classnames [ 'document' ]( $row [ " id " ], $row [ " name " ], $row [ " comment " ], $row [ " date " ], $row [ " expires " ], $row [ " owner " ], $row [ " folder " ], $row [ " inheritAccess " ], $row [ " defaultAccess " ], $row [ " lockUser " ], $row [ " keywords " ], $row [ " sequence " ]);
2010-12-01 13:36:33 +00:00
$document -> setDMS ( $this );
return $document ;
} /* }}} */
2013-05-29 18:05:15 +00:00
/**
* Return a document content by its id
*
* This function retrieves a document content from the database by its id .
*
* @ param integer $id internal id of document content
2021-09-22 07:42:31 +00:00
* @ return bool | null | SeedDMS_Core_DocumentContent found document content or null if not document content was found or false in case of an error
2013-05-29 18:05:15 +00:00
*/
function getDocumentContent ( $id ) { /* {{{ */
2018-02-21 11:34:51 +00:00
$classname = $this -> classnames [ 'documentcontent' ];
return $classname :: getInstance ( $id , $this );
2013-05-29 18:05:15 +00:00
} /* }}} */
2017-12-18 07:45:31 +00:00
/**
* Returns all documents with a predefined search criteria
*
* @ param string $listtype type of document list , can be 'AppRevByMe' ,
* 'AppRevOwner' , 'ReceiptByMe' , 'ReviseByMe' , 'LockedByMe' , 'MyDocs'
* @ param object $user user
* @ return array list of documents records
*/
2021-02-05 06:28:46 +00:00
function countTasks ( $listtype , $user = null , $param5 = true ) { /* {{{ */
2018-03-29 14:30:02 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttstatid " ) || ! $this -> db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
2017-12-18 07:45:31 +00:00
$groups = array ();
if ( $user ) {
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
}
2020-05-08 10:42:44 +00:00
$selectStr = " count(distinct ttcontentid.document) c " ;
2017-12-18 07:45:31 +00:00
$queryStr =
" FROM `ttcontentid` " .
" LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID`=`ttcontentid`.`document` AND `tblDocumentStatus`.`version`=`ttcontentid`.`maxVersion` " .
" LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` " .
" LEFT JOIN `tblDocumentStatusLog` ON `ttstatid`.`statusID` = `tblDocumentStatusLog`.`statusID` AND `ttstatid`.`maxLogID` = `tblDocumentStatusLog`.`statusLogID` " ;
switch ( $listtype ) {
case 'ReviewByMe' : // Documents I have to review {{{
if ( ! $this -> db -> createTemporaryTable ( " ttreviewid " )) {
return false ;
}
$queryStr .=
" LEFT JOIN `tblDocumentReviewers` on `ttcontentid`.`document`=`tblDocumentReviewers`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentReviewers`.`version` " .
" LEFT JOIN `ttreviewid` ON `ttreviewid`.`reviewID` = `tblDocumentReviewers`.`reviewID` " .
" LEFT JOIN `tblDocumentReviewLog` ON `tblDocumentReviewLog`.`reviewLogID`=`ttreviewid`.`maxLogID` " ;
$queryStr .= " WHERE (`tblDocumentReviewers`.`type` = 0 AND `tblDocumentReviewers`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentReviewers`.`type` = 1 AND `tblDocumentReviewers`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
$queryStr .= " AND `tblDocumentReviewLog`.`status` = 0 " ;
2021-02-05 06:28:46 +00:00
$docstatarr = array ( S_DRAFT_REV );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " ;
2017-12-18 07:45:31 +00:00
break ; /* }}} */
case 'ApproveByMe' : // Documents I have to approve {{{
if ( ! $this -> db -> createTemporaryTable ( " ttapproveid " )) {
return false ;
}
$queryStr .=
" LEFT JOIN `tblDocumentApprovers` on `ttcontentid`.`document`=`tblDocumentApprovers`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentApprovers`.`version` " .
" LEFT JOIN `ttapproveid` ON `ttapproveid`.`approveID` = `tblDocumentApprovers`.`approveID` " .
" LEFT JOIN `tblDocumentApproveLog` ON `tblDocumentApproveLog`.`approveLogID`=`ttapproveid`.`maxLogID` " ;
2020-05-08 10:42:44 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblDocumentApprovers`.`type` = 0 AND `tblDocumentApprovers`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentApprovers`.`type` = 1 AND `tblDocumentApprovers`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
2017-12-18 07:45:31 +00:00
$queryStr .= " AND `tblDocumentApproveLog`.`status` = 0 " ;
2021-02-05 06:28:46 +00:00
$docstatarr = array ( S_DRAFT_APP );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " ;
2017-12-18 07:45:31 +00:00
break ; /* }}} */
case 'ReceiptByMe' : // Documents I have to receipt {{{
if ( ! $this -> db -> createTemporaryTable ( " ttreceiptid " )) {
return false ;
}
$queryStr .=
" LEFT JOIN `tblDocumentRecipients` on `ttcontentid`.`document`=`tblDocumentRecipients`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRecipients`.`version` " .
" LEFT JOIN `ttreceiptid` ON `ttreceiptid`.`receiptID` = `tblDocumentRecipients`.`receiptID` " .
" LEFT JOIN `tblDocumentReceiptLog` ON `tblDocumentReceiptLog`.`receiptLogID`=`ttreceiptid`.`maxLogID` " ;
2020-05-08 10:42:44 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblDocumentRecipients`.`type` = 0 AND `tblDocumentRecipients`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentRecipients`.`type` = 1 AND `tblDocumentRecipients`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
2017-12-18 07:45:31 +00:00
$queryStr .= " AND `tblDocumentReceiptLog`.`status` = 0 " ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_RELEASED . " ) " ;
break ; /* }}} */
case 'ReviseByMe' : // Documents I have to receipt {{{
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " )) {
return false ;
}
$queryStr .=
" LEFT JOIN `tblDocumentRevisors` on `ttcontentid`.`document`=`tblDocumentRevisors`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRevisors`.`version` " .
" LEFT JOIN `ttrevisionid` ON `ttrevisionid`.`revisionID` = `tblDocumentRevisors`.`revisionID` " .
" LEFT JOIN `tblDocumentRevisionLog` ON `tblDocumentRevisionLog`.`revisionLogID`=`ttrevisionid`.`maxLogID` " ;
2020-05-08 10:42:44 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblDocumentRevisors`.`type` = 0 AND `tblDocumentRevisors`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentRevisors`.`type` = 1 AND `tblDocumentRevisors`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
2017-12-18 07:45:31 +00:00
$queryStr .= " AND `tblDocumentRevisionLog`.`status` = 0 " ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_IN_REVISION . " ) " ;
break ; /* }}} */
2021-02-11 11:24:07 +00:00
case 'SleepingReviseByMe' : // Documents I have to receipt {{{
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " )) {
return false ;
}
$queryStr .=
" LEFT JOIN `tblDocumentRevisors` on `ttcontentid`.`document`=`tblDocumentRevisors`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRevisors`.`version` " .
" LEFT JOIN `ttrevisionid` ON `ttrevisionid`.`revisionID` = `tblDocumentRevisors`.`revisionID` " .
" LEFT JOIN `tblDocumentRevisionLog` ON `tblDocumentRevisionLog`.`revisionLogID`=`ttrevisionid`.`maxLogID` " ;
if ( $user ) {
$queryStr .= " WHERE (`tblDocumentRevisors`.`type` = 0 AND `tblDocumentRevisors`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentRevisors`.`type` = 1 AND `tblDocumentRevisors`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
$queryStr .= " AND `tblDocumentContent`.`revisiondate` IS NOT NULL AND `tblDocumentContent`.`revisiondate` <= " . $this -> db -> getCurrentDatetime ( 14 ) . " " ;
$queryStr .= " AND `tblDocumentRevisionLog`.`status` = -3 " ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_RELEASED . " ) " ;
break ; /* }}} */
2020-05-08 10:42:44 +00:00
case 'NeedsCorrectionOwner' : // Documents that need to be corrected {{{
2018-03-29 14:30:02 +00:00
$queryStr .=
" LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `ttcontentid`.`document` " ;
$queryStr .= " WHERE `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_NEEDS_CORRECTION . " ) " ;
break ; /* }}} */
2020-05-08 10:42:44 +00:00
case 'WorkflowByMe' : // Documents which need my workflow action {{{
2018-03-29 14:30:02 +00:00
2020-05-08 10:42:44 +00:00
$queryStr .=
" LEFT JOIN `tblWorkflowDocumentContent` on `ttcontentid`.`document`=`tblWorkflowDocumentContent`.`document` AND `ttcontentid`.`maxVersion`=`tblWorkflowDocumentContent`.`version` " .
" LEFT JOIN `tblWorkflowTransitions` on `tblWorkflowDocumentContent`.`workflow`=`tblWorkflowTransitions`.`workflow` AND `tblWorkflowDocumentContent`.`state`=`tblWorkflowTransitions`.`state` " .
" LEFT JOIN `tblWorkflowTransitionUsers` on `tblWorkflowTransitionUsers`.`transition` = `tblWorkflowTransitions`.`id` " .
" LEFT JOIN `tblWorkflowTransitionGroups` on `tblWorkflowTransitionGroups`.`transition` = `tblWorkflowTransitions`.`id` " ;
2018-03-29 14:30:02 +00:00
2020-05-08 10:42:44 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblWorkflowTransitionUsers`.`userid` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblWorkflowTransitionGroups`.`groupid` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
2018-03-29 14:30:02 +00:00
}
2020-05-08 10:42:44 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_IN_WORKFLOW . " " ;
break ; // }}}
2017-12-18 07:45:31 +00:00
}
if ( $queryStr ) {
2020-05-08 10:42:44 +00:00
$resArr = $this -> db -> getResultArray ( 'SELECT ' . $selectStr . $queryStr );
2017-12-18 07:45:31 +00:00
if ( is_bool ( $resArr ) && ! $resArr ) {
return false ;
}
} else {
return false ;
}
return $resArr [ 0 ][ 'c' ];
} /* }}} */
2015-04-23 09:24:42 +00:00
/**
* Returns all documents with a predefined search criteria
*
* The records return have the following elements
*
* From Table tblDocuments
* [ id ] => id of document
* [ name ] => name of document
* [ comment ] => comment of document
* [ date ] => timestamp of creation date of document
* [ expires ] => timestamp of expiration date of document
* [ owner ] => user id of owner
* [ folder ] => id of parent folder
* [ folderList ] => column separated list of folder ids , e . g . : 1 : 41 :
* [ inheritAccess ] => 1 if access is inherited
* [ defaultAccess ] => default access mode
* [ locked ] => always - 1 ( TODO : is this field still used ? )
* [ keywords ] => keywords of document
* [ sequence ] => sequence of document
*
* From Table tblDocumentLocks
* [ lockUser ] => id of user locking the document
*
* From Table tblDocumentStatusLog
* [ version ] => latest version of document
* [ statusID ] => id of latest status log
* [ documentID ] => id of document
* [ status ] => current status of document
* [ statusComment ] => comment of current status
* [ statusDate ] => datetime when the status was entered , e . g . 2014 - 04 - 17 21 : 35 : 51
* [ userID ] => id of user who has initiated the status change
*
* From Table tblUsers
* [ ownerName ] => name of owner of document
* [ statusName ] => name of user who has initiated the status change
*
* @ param string $listtype type of document list , can be 'AppRevByMe' ,
2015-07-09 16:25:55 +00:00
* 'AppRevOwner' , 'ReceiptByMe' , 'ReviseByMe' , 'LockedByMe' , 'MyDocs'
2018-02-08 08:25:45 +00:00
* @ param SeedDMS_Core_User $param1 user
2021-02-04 11:25:22 +00:00
* @ param bool | integer | string $param2 if set to true
* 'ReviewByMe' , 'ApproveByMe' , 'AppRevByMe' , 'ReviseByMe' , 'ReceiptByMe'
* will also return documents which the reviewer , approver , etc .
* has already taken care of . If set to false only
2021-04-03 05:53:12 +00:00
* untouched documents will be returned . In case of 'ExpiredOwner' ,
* 'SleepingReviseByMe' this
2021-02-04 11:25:22 +00:00
* parameter contains the number of days ( a negative number is allowed )
* relativ to the current date or a date in format 'yyyy-mm-dd'
* ( even in the past ) .
2016-08-12 10:40:23 +00:00
* @ param string $param3 sort list by this field
* @ param string $param4 order direction
2021-02-04 11:25:22 +00:00
* @ param bool $param5 set to false if expired documents shall not be considered
2018-02-08 08:25:45 +00:00
* @ return array | bool
2015-04-23 09:24:42 +00:00
*/
2021-02-04 11:25:22 +00:00
function getDocumentList ( $listtype , $param1 = null , $param2 = false , $param3 = '' , $param4 = '' , $param5 = true ) { /* {{{ */
2015-04-23 09:24:42 +00:00
/* The following query will get all documents and lots of additional
* information . It requires the two temporary tables ttcontentid and
* ttstatid .
*/
if ( ! $this -> db -> createTemporaryTable ( " ttstatid " ) || ! $this -> db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
2016-08-12 10:40:23 +00:00
/* The following statement retrieves the status of the last version of all
* documents . It must be restricted by further where clauses .
*/
2017-07-17 15:51:38 +00:00
/*
2015-04-23 09:24:42 +00:00
$queryStr = " SELECT `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser`, " .
" `tblDocumentContent`.`version`, `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, " .
" `tblDocumentStatusLog`.`comment` AS `statusComment`, `tblDocumentStatusLog`.`date` as `statusDate`, " .
" `tblDocumentStatusLog`.`userID`, `oTbl`.`fullName` AS `ownerName`, `sTbl`.`fullName` AS `statusName` " .
" FROM `tblDocumentContent` " .
" LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` " .
" LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID` = `tblDocumentContent`.`document` " .
" LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusID` = `tblDocumentStatus`.`statusID` " .
" LEFT JOIN `ttstatid` ON `ttstatid`.`maxLogID` = `tblDocumentStatusLog`.`statusLogID` " .
" LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentStatus`.`version` AND `ttcontentid`.`document` = `tblDocumentStatus`.`documentID` " .
" LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` " .
" LEFT JOIN `tblUsers` AS `oTbl` on `oTbl`.`id` = `tblDocuments`.`owner` " .
" LEFT JOIN `tblUsers` AS `sTbl` on `sTbl`.`id` = `tblDocumentStatusLog`.`userID` " .
" WHERE `ttstatid`.`maxLogID`=`tblDocumentStatusLog`.`statusLogID` " .
" AND `ttcontentid`.`maxVersion` = `tblDocumentContent`.`version` " ;
2017-07-17 15:51:38 +00:00
*/
/* New sql statement which retrieves all documents , its latest version and
* status , the owner and user initiating the latest status .
* It doesn ' t need the where clause anymore . Hence the statement could be
* extended with further left joins .
*/
2020-05-08 05:40:04 +00:00
$selectStr = " `tblDocuments`.*, `tblDocumentLocks`.`userID` as `lockUser`, " .
2017-07-17 15:51:38 +00:00
" `tblDocumentContent`.`version`, `tblDocumentStatus`.*, `tblDocumentStatusLog`.`status`, " .
" `tblDocumentStatusLog`.`comment` AS `statusComment`, `tblDocumentStatusLog`.`date` as `statusDate`, " .
" `tblDocumentStatusLog`.`userID`, `oTbl`.`fullName` AS `ownerName`, `sTbl`.`fullName` AS `statusName` " ;
$queryStr =
" FROM `ttcontentid` " .
" LEFT JOIN `tblDocuments` ON `tblDocuments`.`id` = `ttcontentid`.`document` " .
" LEFT JOIN `tblDocumentContent` ON `tblDocumentContent`.`document` = `ttcontentid`.`document` AND `tblDocumentContent`.`version` = `ttcontentid`.`maxVersion` " .
" LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID`=`ttcontentid`.`document` AND `tblDocumentStatus`.`version`=`ttcontentid`.`maxVersion` " .
" LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` " .
" LEFT JOIN `tblDocumentStatusLog` ON `ttstatid`.`statusID` = `tblDocumentStatusLog`.`statusID` AND `ttstatid`.`maxLogID` = `tblDocumentStatusLog`.`statusLogID` " .
" LEFT JOIN `tblDocumentLocks` ON `ttcontentid`.`document`=`tblDocumentLocks`.`document` " .
" LEFT JOIN `tblUsers` `oTbl` ON `oTbl`.`id` = `tblDocuments`.`owner` " .
" LEFT JOIN `tblUsers` `sTbl` ON `sTbl`.`id` = `tblDocumentStatusLog`.`userID` " ;
// echo $queryStr;
2015-04-23 09:24:42 +00:00
switch ( $listtype ) {
2016-08-12 10:40:23 +00:00
case 'AppRevByMe' : // Documents I have to review/approve {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-04-23 09:24:42 +00:00
$user = $param1 ;
// Get document list for the current user.
$reviewStatus = $user -> getReviewStatus ();
$approvalStatus = $user -> getApprovalStatus ();
2016-08-12 10:40:23 +00:00
2015-04-23 09:24:42 +00:00
// Create a comma separated list of all the documentIDs whose information is
// required.
2015-07-08 16:57:53 +00:00
// Take only those documents into account which hasn't be touched by the user
2015-04-23 09:24:42 +00:00
$dList = array ();
foreach ( $reviewStatus [ " indstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-04-23 09:24:42 +00:00
$dList [] = $st [ " documentID " ];
}
}
foreach ( $reviewStatus [ " grpstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-04-23 09:24:42 +00:00
$dList [] = $st [ " documentID " ];
}
}
foreach ( $approvalStatus [ " indstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-04-23 09:24:42 +00:00
$dList [] = $st [ " documentID " ];
}
}
foreach ( $approvalStatus [ " grpstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-04-23 09:24:42 +00:00
$dList [] = $st [ " documentID " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
2016-08-12 10:40:23 +00:00
2015-04-23 09:24:42 +00:00
if ( strlen ( $docCSV ) > 0 ) {
2021-02-04 11:25:22 +00:00
$docstatarr = array ( S_DRAFT_REV , S_DRAFT_APP );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " .
2015-04-23 09:24:42 +00:00
" AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " .
" ORDER BY `statusDate` DESC " ;
} else {
$queryStr = '' ;
}
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'ReviewByMe' : // Documents I have to review {{{
2017-07-17 15:51:38 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttreviewid " )) {
return false ;
}
2016-08-12 10:40:23 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2017-07-17 15:51:38 +00:00
$groups = array ();
2020-05-08 05:40:04 +00:00
if ( $user ) {
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
}
2017-07-17 15:51:38 +00:00
$selectStr .= " , `tblDocumentReviewLog`.`date` as `duedate` " ;
$queryStr .=
2021-09-27 08:06:07 +00:00
" LEFT JOIN `tblDocumentReviewers` ON `ttcontentid`.`document`=`tblDocumentReviewers`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentReviewers`.`version` " .
2017-07-17 15:51:38 +00:00
" LEFT JOIN `ttreviewid` ON `ttreviewid`.`reviewID` = `tblDocumentReviewers`.`reviewID` " .
2017-07-27 10:32:27 +00:00
" LEFT JOIN `tblDocumentReviewLog` ON `tblDocumentReviewLog`.`reviewLogID`=`ttreviewid`.`maxLogID` " ;
2017-07-17 15:51:38 +00:00
2017-07-18 11:35:01 +00:00
if ( 1 ) {
2020-05-08 05:40:04 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblDocumentReviewers`.`type` = 0 AND `tblDocumentReviewers`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentReviewers`.`type` = 1 AND `tblDocumentReviewers`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
2021-02-04 11:25:22 +00:00
$docstatarr = array ( S_DRAFT_REV );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " ;
2017-07-17 15:51:38 +00:00
if ( ! $param2 )
$queryStr .= " AND `tblDocumentReviewLog`.`status` = 0 " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
2021-02-11 07:36:07 +00:00
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `tblDocumentStatusLog`.`status` " ;
2017-07-17 15:51:38 +00:00
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr .= " WHERE 1=1 " ;
2016-08-12 10:40:23 +00:00
// Get document list for the current user.
$reviewStatus = $user -> getReviewStatus ();
// Create a comma separated list of all the documentIDs whose information is
// required.
// Take only those documents into account which hasn't be touched by the user
// ($st["status"]==0)
$dList = array ();
foreach ( $reviewStatus [ " indstatus " ] as $st ) {
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
$dList [] = $st [ " documentID " ];
}
}
foreach ( $reviewStatus [ " grpstatus " ] as $st ) {
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
$dList [] = $st [ " documentID " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
if ( strlen ( $docCSV ) > 0 ) {
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_DRAFT_REV . " , " . S_EXPIRED . " ) " .
2017-01-10 20:25:15 +00:00
" AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2016-08-12 10:40:23 +00:00
} else {
$queryStr = '' ;
}
2017-07-17 15:51:38 +00:00
}
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'ApproveByMe' : // Documents I have to approve {{{
2017-07-17 15:51:38 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttapproveid " )) {
return false ;
}
2016-08-12 10:40:23 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2017-07-17 15:51:38 +00:00
$groups = array ();
2020-05-08 05:40:04 +00:00
if ( $user ) {
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
}
2017-07-17 15:51:38 +00:00
$selectStr .= " , `tblDocumentApproveLog`.`date` as `duedate` " ;
$queryStr .=
2021-09-27 08:06:07 +00:00
" LEFT JOIN `tblDocumentApprovers` ON `ttcontentid`.`document`=`tblDocumentApprovers`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentApprovers`.`version` " .
2017-07-17 15:51:38 +00:00
" LEFT JOIN `ttapproveid` ON `ttapproveid`.`approveID` = `tblDocumentApprovers`.`approveID` " .
2017-07-27 10:32:27 +00:00
" LEFT JOIN `tblDocumentApproveLog` ON `tblDocumentApproveLog`.`approveLogID`=`ttapproveid`.`maxLogID` " ;
2017-07-17 15:51:38 +00:00
2017-07-18 11:35:01 +00:00
if ( 1 ) {
2020-05-08 05:40:04 +00:00
if ( $user ) {
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE (`tblDocumentApprovers`.`type` = 0 AND `tblDocumentApprovers`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentApprovers`.`type` = 1 AND `tblDocumentApprovers`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
2020-05-08 05:40:04 +00:00
}
2021-02-04 11:25:22 +00:00
$docstatarr = array ( S_DRAFT_APP );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " ;
2017-07-17 15:51:38 +00:00
if ( ! $param2 )
$queryStr .= " AND `tblDocumentApproveLog`.`status` = 0 " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
2021-02-11 07:36:07 +00:00
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `tblDocumentStatusLog`.`status` " ;
2017-07-17 15:51:38 +00:00
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr .= " WHERE 1=1 " ;
2016-08-12 10:40:23 +00:00
// Get document list for the current user.
$approvalStatus = $user -> getApprovalStatus ();
// Create a comma separated list of all the documentIDs whose information is
// required.
// Take only those documents into account which hasn't be touched by the user
// ($st["status"]==0)
$dList = array ();
foreach ( $approvalStatus [ " indstatus " ] as $st ) {
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
$dList [] = $st [ " documentID " ];
}
}
foreach ( $approvalStatus [ " grpstatus " ] as $st ) {
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
$dList [] = $st [ " documentID " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
if ( strlen ( $docCSV ) > 0 ) {
2021-02-04 11:25:22 +00:00
$docstatarr = array ( S_DRAFT_APP );
if ( $param5 )
$docstatarr [] = S_EXPIRED ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $docstatarr ) . " ) " .
2017-01-10 20:25:15 +00:00
" AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2016-08-12 10:40:23 +00:00
} else {
$queryStr = '' ;
}
2017-07-17 15:51:38 +00:00
}
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'ReceiptByMe' : // Documents I have to receipt {{{
2017-07-17 15:51:38 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttreceiptid " )) {
return false ;
}
2015-05-04 04:11:35 +00:00
$user = $param1 ;
2017-07-17 15:51:38 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$groups = array ();
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
$selectStr .= " , `tblDocumentReceiptLog`.`date` as `duedate` " ;
$queryStr .=
" LEFT JOIN `tblDocumentRecipients` on `ttcontentid`.`document`=`tblDocumentRecipients`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRecipients`.`version` " .
" LEFT JOIN `ttreceiptid` ON `ttreceiptid`.`receiptID` = `tblDocumentRecipients`.`receiptID` " .
2017-07-27 10:32:27 +00:00
" LEFT JOIN `tblDocumentReceiptLog` ON `tblDocumentReceiptLog`.`receiptLogID`=`ttreceiptid`.`maxLogID` " ;
2017-07-17 15:51:38 +00:00
if ( 1 ) {
$queryStr .= " WHERE (`tblDocumentRecipients`.`type` = 0 AND `tblDocumentRecipients`.`required` = " . $user -> getID () . " " ;
2017-07-27 10:32:27 +00:00
/* Checking for groups slows down the statement extremly on sqlite */
2017-07-17 15:51:38 +00:00
if ( $groups )
$queryStr .= " OR `tblDocumentRecipients`.`type` = 1 AND `tblDocumentRecipients`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
2017-12-18 07:45:31 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_RELEASED . " " ;
2017-07-17 15:51:38 +00:00
if ( ! $param2 )
$queryStr .= " AND `tblDocumentReceiptLog`.`status` = 0 " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
2021-02-11 07:36:07 +00:00
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `tblDocumentStatusLog`.`status` " ;
2017-07-17 15:51:38 +00:00
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr .= " WHERE 1=1 " ;
2015-05-04 04:11:35 +00:00
// Get document list for the current user.
$receiptStatus = $user -> getReceiptStatus ();
2016-08-12 10:40:23 +00:00
2015-05-04 04:11:35 +00:00
// Create a comma separated list of all the documentIDs whose information is
// required.
2016-08-12 10:40:23 +00:00
// Take only those documents into account which hasn't be touched by the user
// ($st["status"]==0)
2015-05-04 04:11:35 +00:00
$dList = array ();
foreach ( $receiptStatus [ " indstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-05-04 04:11:35 +00:00
$dList [] = $st [ " documentID " ];
}
}
foreach ( $receiptStatus [ " grpstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-05-04 04:11:35 +00:00
$dList [] = $st [ " documentID " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
2016-08-12 10:40:23 +00:00
2015-05-04 04:11:35 +00:00
if ( strlen ( $docCSV ) > 0 ) {
2017-07-17 15:51:38 +00:00
$queryStr .= " AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " ;
// $queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2015-05-12 17:07:26 +00:00
} else {
$queryStr = '' ;
}
2017-07-17 15:51:38 +00:00
}
2016-08-12 10:40:23 +00:00
break ; // }}}
2019-02-14 11:33:50 +00:00
case 'ReviseByMe' : // Documents I have to revise {{{
2017-07-17 15:51:38 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " )) {
return false ;
}
2015-05-12 17:07:26 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2017-07-17 15:51:38 +00:00
$groups = array ();
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
$selectStr .= " , `tblDocumentRevisionLog`.`date` as `duedate` " ;
$queryStr .=
" LEFT JOIN `tblDocumentRevisors` on `ttcontentid`.`document`=`tblDocumentRevisors`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRevisors`.`version` " .
" LEFT JOIN `ttrevisionid` ON `ttrevisionid`.`revisionID` = `tblDocumentRevisors`.`revisionID` " .
2017-07-27 10:32:27 +00:00
" LEFT JOIN `tblDocumentRevisionLog` ON `tblDocumentRevisionLog`.`revisionLogID`=`ttrevisionid`.`maxLogID` " ;
2017-07-17 15:51:38 +00:00
2017-07-18 11:35:01 +00:00
if ( 1 ) {
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE (`tblDocumentRevisors`.`type` = 0 AND `tblDocumentRevisors`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentRevisors`.`type` = 1 AND `tblDocumentRevisors`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
2017-12-18 07:45:31 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_IN_REVISION . " " ;
2017-07-17 15:51:38 +00:00
if ( ! $param2 )
$queryStr .= " AND `tblDocumentRevisionLog`.`status` = 0 " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
2021-02-11 07:36:07 +00:00
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `tblDocumentStatusLog`.`status` " ;
2017-07-17 15:51:38 +00:00
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr .= " WHERE 1=1 " ;
2015-05-12 17:07:26 +00:00
// Get document list for the current user.
$revisionStatus = $user -> getRevisionStatus ();
2016-08-12 10:40:23 +00:00
2015-05-12 17:07:26 +00:00
// Create a comma separated list of all the documentIDs whose information is
// required.
$dList = array ();
foreach ( $revisionStatus [ " indstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-05-12 17:07:26 +00:00
$dList [] = $st [ " documentID " ];
}
}
foreach ( $revisionStatus [ " grpstatus " ] as $st ) {
2015-07-09 16:25:55 +00:00
if (( $st [ " status " ] == 0 || $param2 ) && ! in_array ( $st [ " documentID " ], $dList )) {
2015-05-12 17:07:26 +00:00
$dList [] = $st [ " documentID " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
2016-08-12 10:40:23 +00:00
2015-05-12 17:07:26 +00:00
if ( strlen ( $docCSV ) > 0 ) {
2017-01-10 20:25:15 +00:00
$queryStr .= " AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2015-05-04 04:11:35 +00:00
} else {
$queryStr = '' ;
}
2017-07-17 15:51:38 +00:00
}
2016-08-12 10:40:23 +00:00
break ; // }}}
2021-02-11 11:24:07 +00:00
case 'SleepingReviseByMe' : // Documents I have to revise but are still sleeping {{{
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " )) {
return false ;
}
2021-04-03 05:53:12 +00:00
$dayoffset = 0 ;
if ( is_int ( $param2 )) {
$dayoffset = ( int ) $param2 ;
}
2021-02-11 11:24:07 +00:00
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$groups = array ();
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
$selectStr .= " , `tblDocumentRevisionLog`.`date` as `duedate` " ;
$queryStr .=
" LEFT JOIN `tblDocumentRevisors` on `ttcontentid`.`document`=`tblDocumentRevisors`.`documentID` AND `ttcontentid`.`maxVersion`=`tblDocumentRevisors`.`version` " .
" LEFT JOIN `ttrevisionid` ON `ttrevisionid`.`revisionID` = `tblDocumentRevisors`.`revisionID` " .
" LEFT JOIN `tblDocumentRevisionLog` ON `tblDocumentRevisionLog`.`revisionLogID`=`ttrevisionid`.`maxLogID` " ;
$queryStr .= " WHERE (`tblDocumentRevisors`.`type` = 0 AND `tblDocumentRevisors`.`required` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblDocumentRevisors`.`type` = 1 AND `tblDocumentRevisors`.`required` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
2021-04-03 05:53:12 +00:00
$queryStr .= " AND `tblDocumentContent`.`revisiondate` IS NOT NULL AND `tblDocumentContent`.`revisiondate` <= " . $this -> db -> getCurrentDatetime ( $dayoffset ) . " " ;
2021-02-11 11:24:07 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_RELEASED . " " ;
2021-04-03 05:53:12 +00:00
$queryStr .= " AND `tblDocumentRevisionLog`.`status` = -3 " ;
2021-02-11 11:24:07 +00:00
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `tblDocumentStatusLog`.`status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
break ; // }}}
2019-02-14 11:33:50 +00:00
case 'DueRevision' : // Documents with a due revision, which is not started {{{
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " )) {
return false ;
}
2021-04-03 05:53:12 +00:00
$dayoffset = 0 ;
if ( is_int ( $param2 )) {
$dayoffset = ( int ) $param2 ;
}
2019-02-14 11:33:50 +00:00
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$selectStr .= " , `tblDocumentContent`.`revisiondate` " ;
2021-04-03 05:53:12 +00:00
$queryStr .= " WHERE `tblDocumentContent`.`revisiondate` IS NOT NULL AND `tblDocumentContent`.`revisiondate` <= " . $this -> db -> getCurrentDatetime ( $dayoffset ) . " " ;
2019-02-14 11:33:50 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_RELEASED . " " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
$queryStr .= " , `tblDocumentContent`.`revisiondate` ASC " ;
break ; // }}}
2016-08-12 10:40:23 +00:00
case 'WorkflowByMe' : // Documents I to trigger in Worklflow {{{
2016-02-10 11:30:51 +00:00
$user = $param1 ;
2020-05-08 05:40:04 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
if ( 1 ) {
$groups = array ();
if ( $user ) {
$tmp = $user -> getGroups ();
foreach ( $tmp as $group )
$groups [] = $group -> getID ();
}
$selectStr = 'distinct ' . $selectStr ;
$queryStr .=
2021-09-27 08:06:07 +00:00
" LEFT JOIN `tblWorkflowDocumentContent` ON `ttcontentid`.`document`=`tblWorkflowDocumentContent`.`document` AND `ttcontentid`.`maxVersion`=`tblWorkflowDocumentContent`.`version` " .
" LEFT JOIN `tblWorkflowTransitions` ON `tblWorkflowDocumentContent`.`workflow`=`tblWorkflowTransitions`.`workflow` AND `tblWorkflowDocumentContent`.`state`=`tblWorkflowTransitions`.`state` " .
" LEFT JOIN `tblWorkflowTransitionUsers` ON `tblWorkflowTransitionUsers`.`transition` = `tblWorkflowTransitions`.`id` " .
" LEFT JOIN `tblWorkflowTransitionGroups` ON `tblWorkflowTransitionGroups`.`transition` = `tblWorkflowTransitions`.`id` " ;
2020-05-08 05:40:04 +00:00
if ( $user ) {
$queryStr .= " WHERE (`tblWorkflowTransitionUsers`.`userid` = " . $user -> getID () . " " ;
if ( $groups )
$queryStr .= " OR `tblWorkflowTransitionGroups`.`groupid` IN ( " . implode ( ',' , $groups ) . " ) " ;
$queryStr .= " ) " ;
}
2020-05-08 10:42:44 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` = " . S_IN_WORKFLOW . " " ;
2020-05-08 05:40:04 +00:00
// echo 'SELECT '.$selectStr." ".$queryStr;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else $queryStr .= " ORDER BY `name` " ;
} else {
$queryStr .= " WHERE 1=1 " ;
2016-02-10 11:30:51 +00:00
// Get document list for the current user.
$workflowStatus = $user -> getWorkflowStatus ();
2016-08-12 10:40:23 +00:00
2016-02-10 11:30:51 +00:00
// Create a comma separated list of all the documentIDs whose information is
// required.
$dList = array ();
foreach ( $workflowStatus [ " u " ] as $st ) {
if ( ! in_array ( $st [ " document " ], $dList )) {
$dList [] = $st [ " document " ];
}
}
foreach ( $workflowStatus [ " g " ] as $st ) {
if ( ! in_array ( $st [ " document " ], $dList )) {
$dList [] = $st [ " document " ];
}
}
$docCSV = " " ;
foreach ( $dList as $d ) {
$docCSV .= ( strlen ( $docCSV ) == 0 ? " " : " , " ) . " ' " . $d . " ' " ;
}
2016-08-12 10:40:23 +00:00
2016-02-10 11:30:51 +00:00
if ( strlen ( $docCSV ) > 0 ) {
2016-08-12 10:40:23 +00:00
$queryStr .=
2016-02-10 11:30:51 +00:00
//"AND `tblDocumentStatusLog`.`status` IN (".S_IN_WORKFLOW.", ".S_EXPIRED.") ".
" AND `tblDocuments`.`id` IN ( " . $docCSV . " ) " .
" ORDER BY `statusDate` DESC " ;
} else {
$queryStr = '' ;
}
2020-05-08 05:40:04 +00:00
}
2016-08-12 10:40:23 +00:00
break ; // }}}
2017-01-17 12:44:19 +00:00
case 'AppRevOwner' : // Documents waiting for review/approval/revision I'm owning {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-04-23 09:24:42 +00:00
$user = $param1 ;
2016-08-12 10:40:23 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
2016-08-09 15:14:57 +00:00
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedConstantInspection */
2016-08-09 15:14:57 +00:00
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
2020-06-06 14:15:32 +00:00
" AND `tblDocumentStatusLog`.`status` IN ( " . S_DRAFT_REV . " , " . S_DRAFT_APP . " , " . S_IN_REVISION . " ) " ;
2016-08-09 15:14:57 +00:00
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
// $queryStr .= "AND `tblDocuments`.`owner` = '".$user->getID()."' ".
// "AND `tblDocumentStatusLog`.`status` IN (".S_DRAFT_REV.", ".S_DRAFT_APP.") ".
// "ORDER BY `statusDate` DESC";
2016-08-12 10:40:23 +00:00
break ; // }}}
2017-08-03 10:42:56 +00:00
case 'ReceiveOwner' : // Documents having a reception I'm owning {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2017-01-17 12:44:19 +00:00
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2017-08-03 10:42:56 +00:00
// $qs = 'SELECT DISTINCT `documentID` FROM `tblDocumentRecipients` LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentRecipients`.`version` AND `ttcontentid`.`document` = `tblDocumentRecipients`.`documentID`';
// sql statement without older versions of a document
$qs = 'SELECT DISTINCT `document` as `documentID` FROM `ttcontentid` a LEFT JOIN `tblDocumentRecipients` b on a.`document`=b.`documentID` AND a.`maxVersion`=b.`version` WHERE b.`receiptID` IS NOT NULL' ;
2017-01-17 12:44:19 +00:00
$ra = $this -> db -> getResultArray ( $qs );
if ( is_bool ( $ra ) && ! $ra ) {
return false ;
}
$docs = array ();
foreach ( $ra as $d ) {
$docs [] = $d [ 'documentID' ];
}
2018-01-16 17:04:53 +00:00
if ( $docs ) {
$queryStr .= " AND `tblDocuments`.`id` IN ( " . implode ( ',' , $docs ) . " ) " ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " ;
2018-02-01 11:05:48 +00:00
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_RELEASED . " ) " ;
2018-01-16 17:04:53 +00:00
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr = '' ;
}
break ; // }}}
case 'NoReceiveOwner' : // Documents *not* having a reception I'm owning {{{
$queryStr .= " WHERE 1=1 " ;
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
// $qs = 'SELECT DISTINCT `documentID` FROM `tblDocumentRecipients` LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentRecipients`.`version` AND `ttcontentid`.`document` = `tblDocumentRecipients`.`documentID`';
// sql statement without older versions of a document
$qs = 'SELECT DISTINCT `document` as `documentID` FROM `ttcontentid` a LEFT JOIN `tblDocumentRecipients` b on a.`document`=b.`documentID` AND a.`maxVersion`=b.`version` WHERE b.`receiptID` IS NULL' ;
$ra = $this -> db -> getResultArray ( $qs );
if ( is_bool ( $ra ) && ! $ra ) {
return false ;
}
$docs = array ();
foreach ( $ra as $d ) {
$docs [] = $d [ 'documentID' ];
}
2017-01-17 12:44:19 +00:00
if ( $docs ) {
$queryStr .= " AND `tblDocuments`.`id` IN ( " . implode ( ',' , $docs ) . " ) " ;
2018-01-24 08:01:35 +00:00
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_RELEASED . " ) " ;
2017-01-17 12:44:19 +00:00
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr = '' ;
}
break ; // }}}
2016-08-12 10:40:23 +00:00
case 'RejectOwner' : // Documents that has been rejected and I'm owning {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-07-03 18:52:55 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2018-02-01 11:05:48 +00:00
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " ;
$queryStr .= " AND `tblDocumentStatusLog`.`status` IN ( " . S_REJECTED . " ) " ;
2017-01-10 20:25:15 +00:00
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'LockedByMe' : // Documents locked by me {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-04-23 09:24:42 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2017-03-24 12:29:00 +00:00
$qs = 'SELECT `document` FROM `tblDocumentLocks` WHERE `userID`=' . $user -> getID ();
$ra = $this -> db -> getResultArray ( $qs );
if ( is_bool ( $ra ) && ! $ra ) {
return false ;
}
$docs = array ();
foreach ( $ra as $d ) {
$docs [] = $d [ 'document' ];
}
if ( $docs ) {
$queryStr .= " AND `tblDocuments`.`id` IN ( " . implode ( ',' , $docs ) . " ) " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
} else {
$queryStr = '' ;
}
2016-08-12 10:40:23 +00:00
break ; // }}}
2017-10-27 14:47:09 +00:00
case 'ExpiredOwner' : // Documents expired and owned by me {{{
if ( is_int ( $param2 )) {
$ts = mktime ( 0 , 0 , 0 ) + $param2 * 86400 ;
} elseif ( is_string ( $param2 )) {
$tmp = explode ( '-' , $param2 , 3 );
if ( count ( $tmp ) != 3 )
return false ;
2021-09-22 07:43:12 +00:00
if ( ! self :: checkDate ( $param2 , 'Y-m-d' ))
return false ;
2017-10-27 14:47:09 +00:00
$ts = mktime ( 0 , 0 , 0 , $tmp [ 1 ], $tmp [ 2 ], $tmp [ 0 ]);
} else
$ts = mktime ( 0 , 0 , 0 ) - 365 * 86400 ; /* Start of today - 1 year */
$tsnow = mktime ( 0 , 0 , 0 ); /* Start of today */
if ( $ts < $tsnow ) { /* Check for docs expired in the past */
$startts = $ts ;
$endts = $tsnow + 86400 ; /* Use end of day */
} else { /* Check for docs which will expire in the future */
$startts = $tsnow ;
$endts = $ts + 86400 ; /* Use end of day */
}
$queryStr .=
2021-09-22 07:43:51 +00:00
" WHERE `tblDocuments`.`expires` >= " . $startts . " AND `tblDocuments`.`expires` <= " . $endts . " " ;
2017-10-27 14:47:09 +00:00
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
break ; // }}}
2018-01-28 06:48:29 +00:00
case 'ObsoleteOwner' : // Documents that are obsolete and I'm owning {{{
$queryStr .= " WHERE 1=1 " ;
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_OBSOLETE . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
break ; // }}}
2018-03-01 20:29:12 +00:00
case 'NeedsCorrectionOwner' : // Documents that needs correction and I'm owning {{{
$queryStr .= " WHERE 1=1 " ;
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_NEEDS_CORRECTION . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
break ; // }}}
2018-01-28 06:48:29 +00:00
case 'DraftOwner' : // Documents in draft status and I'm owning {{{
$queryStr .= " WHERE 1=1 " ;
$user = $param1 ;
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_DRAFT . " ) " ;
//$queryStr .= "ORDER BY `statusDate` DESC";
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
break ; // }}}
2016-08-12 10:40:23 +00:00
case 'WorkflowOwner' : // Documents waiting for workflow trigger I'm owning {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2016-02-10 12:33:56 +00:00
$user = $param1 ;
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " .
" AND `tblDocumentStatusLog`.`status` IN ( " . S_IN_WORKFLOW . " ) " .
" ORDER BY `statusDate` DESC " ;
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'MyDocs' : // Documents owned by me {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-04-23 09:24:42 +00:00
$user = $param1 ;
2016-08-12 10:40:23 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
2016-08-09 13:14:17 +00:00
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2015-04-23 09:24:42 +00:00
$queryStr .= " AND `tblDocuments`.`owner` = ' " . $user -> getID () . " ' " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
2016-08-09 13:14:17 +00:00
$queryStr .= " " . $orderdir ;
2016-08-12 10:40:23 +00:00
break ; // }}}
case 'CheckedOutByMe' : // Documents I have checked out {{{
2017-07-17 15:51:38 +00:00
$queryStr .= " WHERE 1=1 " ;
2015-04-23 14:43:19 +00:00
$user = $param1 ;
2017-01-10 20:25:15 +00:00
$orderby = $param3 ;
if ( $param4 == 'desc' )
$orderdir = 'DESC' ;
else
$orderdir = 'ASC' ;
2015-04-23 14:43:19 +00:00
2017-02-13 16:32:22 +00:00
$qs = 'SELECT `document` FROM `tblDocumentCheckOuts` WHERE `userID`=' . $user -> getID ();
2015-04-23 14:43:19 +00:00
$ra = $this -> db -> getResultArray ( $qs );
if ( is_bool ( $ra ) && ! $ra ) {
return false ;
}
$docs = array ();
foreach ( $ra as $d ) {
$docs [] = $d [ 'document' ];
}
2016-08-12 10:40:23 +00:00
2015-04-23 14:43:19 +00:00
if ( $docs ) {
2017-01-10 20:25:15 +00:00
$queryStr .= " AND `tblDocuments`.`id` IN ( " . implode ( ',' , $docs ) . " ) " ;
if ( $orderby == 'e' ) $queryStr .= " ORDER BY `expires` " ;
else if ( $orderby == 'u' ) $queryStr .= " ORDER BY `statusDate` " ;
else if ( $orderby == 's' ) $queryStr .= " ORDER BY `status` " ;
else $queryStr .= " ORDER BY `name` " ;
$queryStr .= " " . $orderdir ;
2015-04-23 14:43:19 +00:00
} else {
$queryStr = '' ;
}
2016-08-12 10:40:23 +00:00
break ; // }}}
2021-09-16 14:05:04 +00:00
default : // {{{
2020-09-03 18:09:41 +00:00
return false ;
break ; // }}}
2015-04-23 09:24:42 +00:00
}
if ( $queryStr ) {
2020-05-08 05:40:04 +00:00
$resArr = $this -> db -> getResultArray ( 'SELECT ' . $selectStr . $queryStr );
2015-04-23 09:24:42 +00:00
if ( is_bool ( $resArr ) && ! $resArr ) {
return false ;
}
2016-11-11 15:20:10 +00:00
/*
$documents = array ();
foreach ( $resArr as $row )
$documents [] = $this -> getDocument ( $row [ " id " ]);
*/
2015-04-23 09:24:42 +00:00
} else {
return array ();
}
return $resArr ;
} /* }}} */
2013-11-27 08:43:33 +00:00
function makeTimeStamp ( $hour , $min , $sec , $year , $month , $day ) { /* {{{ */
2012-10-05 19:45:57 +00:00
$thirtyone = array ( 1 , 3 , 5 , 7 , 8 , 10 , 12 );
$thirty = array ( 4 , 6 , 9 , 11 );
// Very basic check that the terms are valid. Does not fail for illegal
// dates such as 31 Feb.
if ( ! is_numeric ( $hour ) || ! is_numeric ( $min ) || ! is_numeric ( $sec ) || ! is_numeric ( $year ) || ! is_numeric ( $month ) || ! is_numeric ( $day ) || $month < 1 || $month > 12 || $day < 1 || $day > 31 || $hour < 0 || $hour > 23 || $min < 0 || $min > 59 || $sec < 0 || $sec > 59 ) {
return false ;
}
$year = ( int ) $year ;
$month = ( int ) $month ;
$day = ( int ) $day ;
2021-09-16 14:05:04 +00:00
if ( in_array ( $month , $thirtyone )) {
2012-10-05 19:45:57 +00:00
$max = 31 ;
2021-09-16 14:05:04 +00:00
} elseif ( in_array ( $month , $thirty )) {
2012-10-05 19:45:57 +00:00
$max = 30 ;
2021-09-16 14:05:04 +00:00
} else {
2012-10-05 19:45:57 +00:00
$max = (( $year % 4 == 0 ) && ( $year % 100 != 0 || $year % 400 == 0 )) ? 29 : 28 ;
}
2021-09-16 14:05:04 +00:00
// Check again if day of month is valid in the given month
2012-10-05 19:45:57 +00:00
if ( $day > $max ) {
2021-09-16 14:05:04 +00:00
return false ;
2012-10-05 19:45:57 +00:00
}
return mktime ( $hour , $min , $sec , $month , $day , $year );
2013-11-27 08:43:33 +00:00
} /* }}} */
2012-10-05 19:45:57 +00:00
2017-10-24 11:36:07 +00:00
/**
2010-11-12 22:40:12 +00:00
* Search the database for documents
*
2012-10-09 09:53:11 +00:00
* Note : the creation date will be used to check againts the
* date saved with the document
* or folder . The modification date will only be used for documents . It
* is checked against the creation date of the document content . This
* meanѕ that updateѕ of a document will only result in a searchable
* modification if a new version is uploaded .
*
2021-09-22 07:45:06 +00:00
* If the search is filtered by an expiration date , only documents with
* an expiration date will be found . Even if just an end date is given .
*
2017-10-24 11:36:07 +00:00
* @ param string $query seach query with space separated words
* @ param integer $limit number of items in result set
* @ param integer $offset index of first item in result set
* @ param string $logicalmode either AND or OR
* @ param array $searchin list of fields to search in
2021-09-17 16:26:11 +00:00
* 1 = keywords , 2 = name , 3 = comment , 4 = attributes , 5 = id
2017-10-24 11:36:07 +00:00
* @ param SeedDMS_Core_Folder | null $startFolder search in the folder only ( null for root folder )
* @ param SeedDMS_Core_User $owner search for documents owned by this user
* @ param array $status list of status
* @ param array $creationstartdate search for documents created after this date
* @ param array $creationenddate search for documents created before this date
* @ param array $modificationstartdate search for documents modified after this date
* @ param array $modificationenddate search for documents modified before this date
* @ param array $categories list of categories the documents must have assigned
* @ param array $attributes list of attributes . The key of this array is the
2014-11-13 06:53:29 +00:00
* attribute definition id . The value of the array is the value of the
* attribute . If the attribute may have multiple values it must be an array .
2017-10-24 11:36:07 +00:00
* @ param integer $mode decide whether to search for documents / folders
2011-12-06 12:31:20 +00:00
* 0x1 = documents only
* 0x2 = folders only
* 0x3 = both
2021-09-22 07:45:06 +00:00
* @ param array $expirationstartdate search for documents expiring after and on this date
* @ param array $expirationenddate search for documents expiring before and on this date
2017-10-24 11:36:07 +00:00
* @ return array | bool
2010-11-12 22:40:12 +00:00
*/
2016-09-28 19:28:01 +00:00
function search ( $query , $limit = 0 , $offset = 0 , $logicalmode = 'AND' , $searchin = array (), $startFolder = null , $owner = null , $status = array (), $creationstartdate = array (), $creationenddate = array (), $modificationstartdate = array (), $modificationenddate = array (), $categories = array (), $attributes = array (), $mode = 0x3 , $expirationstartdate = array (), $expirationenddate = array (), $reception = array ()) { /* {{{ */
2019-06-26 16:01:53 +00:00
$orderby = '' ;
2021-01-29 13:19:44 +00:00
$revisionstartdate = $revisionenddate = '' ;
2021-05-21 06:51:08 +00:00
$statusstartdate = array ();
$statusenddate = array ();
2019-06-26 11:38:39 +00:00
if ( is_array ( $query )) {
2021-01-29 13:19:44 +00:00
foreach ( array ( 'limit' , 'offset' , 'logicalmode' , 'searchin' , 'startFolder' , 'owner' , 'status' , 'creationstartdate' , 'creationenddate' , 'modificationstartdate' , 'modificationenddate' , 'categories' , 'attributes' , 'mode' , 'revisionstartdate' , 'revisionenddate' , 'expirationstartdate' , 'expirationenddate' , 'reception' ) as $paramname )
2019-06-26 11:38:39 +00:00
${$paramname} = isset ( $query [ $paramname ]) ? $query [ $paramname ] : ${$paramname} ;
2021-03-15 15:07:57 +00:00
foreach ( array ( 'orderby' , 'statusstartdate' , 'statusenddate' ) as $paramname )
2019-06-26 11:38:39 +00:00
${$paramname} = isset ( $query [ $paramname ]) ? $query [ $paramname ] : '' ;
$query = isset ( $query [ 'query' ]) ? $query [ 'query' ] : '' ;
}
2021-09-17 16:27:16 +00:00
/* Ensure $logicalmode has a valid value */
if ( $logicalmode != 'OR' )
$logicalmode = 'AND' ;
2010-11-12 22:40:12 +00:00
// Split the search string into constituent keywords.
$tkeys = array ();
if ( strlen ( $query ) > 0 ) {
2011-04-12 07:19:55 +00:00
$tkeys = preg_split ( " /[ \t \r \n ,]+/ " , $query );
2010-11-12 22:40:12 +00:00
}
2010-12-01 13:36:33 +00:00
2010-11-12 22:40:12 +00:00
// if none is checkd search all
if ( count ( $searchin ) == 0 )
2017-01-18 13:45:40 +00:00
$searchin = array ( 1 , 2 , 3 , 4 , 5 );
2010-11-12 22:40:12 +00:00
2011-11-28 14:03:01 +00:00
/*--------- Do it all over again for folders -------------*/
2013-06-14 14:03:49 +00:00
$totalFolders = 0 ;
2011-12-06 12:31:20 +00:00
if ( $mode & 0x2 ) {
2011-11-28 14:03:01 +00:00
$searchKey = " " ;
2015-02-05 06:37:50 +00:00
$classname = $this -> classnames [ 'folder' ];
2017-02-14 07:57:32 +00:00
$searchFields = $classname :: getSearchFields ( $this , $searchin );
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
if ( count ( $searchFields ) > 0 ) {
2011-11-28 14:03:01 +00:00
foreach ( $tkeys as $key ) {
$key = trim ( $key );
if ( strlen ( $key ) > 0 ) {
2012-02-13 08:31:01 +00:00
$searchKey = ( strlen ( $searchKey ) == 0 ? " " : $searchKey . " " . $logicalmode . " " ) . " ( " . implode ( " like " . $this -> db -> qstr ( " % " . $key . " % " ) . " OR " , $searchFields ) . " like " . $this -> db -> qstr ( " % " . $key . " % " ) . " ) " ;
2011-11-28 14:03:01 +00:00
}
}
}
// Check to see if the search has been restricted to a particular sub-tree in
// the folder hierarchy.
$searchFolder = " " ;
if ( $startFolder ) {
$searchFolder = " `tblFolders`.`folderList` LIKE '%: " . $startFolder -> getID () . " :%' " ;
2020-12-16 15:47:49 +00:00
if ( $this -> checkWithinRootDir )
$searchFolder = '(' . $searchFolder . " AND `tblFolders`.`folderList` LIKE '%: " . $this -> rootFolderID . " :%') " ;
} elseif ( $this -> checkWithinRootDir ) {
$searchFolder = " `tblFolders`.`folderList` LIKE '%: " . $this -> rootFolderID . " :%' " ;
2011-11-28 14:03:01 +00:00
}
// Check to see if the search has been restricted to a particular
// document owner.
$searchOwner = " " ;
if ( $owner ) {
2013-06-07 08:09:32 +00:00
if ( is_array ( $owner )) {
$ownerids = array ();
foreach ( $owner as $o )
$ownerids [] = $o -> getID ();
if ( $ownerids )
$searchOwner = " `tblFolders`.`owner` IN ( " . implode ( ',' , $ownerids ) . " ) " ;
} else {
$searchOwner = " `tblFolders`.`owner` = ' " . $owner -> getId () . " ' " ;
}
2011-11-28 14:03:01 +00:00
}
2014-06-30 05:41:28 +00:00
// Check to see if the search has been restricted to a particular
// attribute.
$searchAttributes = array ();
if ( $attributes ) {
foreach ( $attributes as $attrdefid => $attribute ) {
if ( $attribute ) {
$attrdef = $this -> getAttributeDefinition ( $attrdefid );
2014-11-13 06:53:29 +00:00
if ( $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_folder || $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_all ) {
if ( $valueset = $attrdef -> getValueSet ()) {
if ( $attrdef -> getMultipleValues ()) {
2018-02-22 18:11:25 +00:00
if ( is_string ( $attribute ))
$attribute = array ( $attribute );
2014-11-21 10:35:49 +00:00
$searchAttributes [] = " EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`= " . $attrdefid . " AND (`tblFolderAttributes`.`value` like '% " . $valueset [ 0 ] . implode ( " %' OR `tblFolderAttributes`.`value` like '% " . $valueset [ 0 ], $attribute ) . " %') AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`) " ;
2021-03-12 09:05:17 +00:00
} else {
2014-11-19 15:59:39 +00:00
$searchAttributes [] = " EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`= " . $attrdefid . " AND `tblFolderAttributes`.`value`=' " . $attribute . " ' AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`) " ;
2021-03-12 09:05:17 +00:00
}
} else {
if ( $attrdef -> getType () == SeedDMS_Core_AttributeDefinition :: type_date && is_array ( $attribute )) {
$kkll = [];
if ( ! empty ( $attribute [ 'from' ]))
$kkll [] = " `tblFolderAttributes`.`value`>=' " . $attribute [ 'from' ] . " ' " ;
if ( ! empty ( $attribute [ 'to' ]))
$kkll [] = " `tblFolderAttributes`.`value`<=' " . $attribute [ 'to' ] . " ' " ;
if ( $kkll )
$searchAttributes [] = " EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`= " . $attrdefid . " AND " . implode ( ' AND ' , $kkll ) . " AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`) " ;
} else {
$searchAttributes [] = " EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`= " . $attrdefid . " AND `tblFolderAttributes`.`value` like '% " . $attribute . " %' AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`) " ;
}
}
2014-06-30 05:41:28 +00:00
}
}
}
}
2011-11-28 14:03:01 +00:00
// Is the search restricted to documents created between two specific dates?
$searchCreateDate = " " ;
if ( $creationstartdate ) {
2013-02-14 11:10:53 +00:00
$startdate = SeedDMS_Core_DMS :: makeTimeStamp ( $creationstartdate [ 'hour' ], $creationstartdate [ 'minute' ], $creationstartdate [ 'second' ], $creationstartdate [ 'year' ], $creationstartdate [ " month " ], $creationstartdate [ " day " ]);
2011-11-28 14:03:01 +00:00
if ( $startdate ) {
2021-03-15 15:07:57 +00:00
$searchCreateDate .= " `tblFolders`.`date` >= " . $this -> db -> qstr ( $startdate );
2011-11-28 14:03:01 +00:00
}
}
if ( $creationenddate ) {
2013-02-14 11:10:53 +00:00
$stopdate = SeedDMS_Core_DMS :: makeTimeStamp ( $creationenddate [ 'hour' ], $creationstartdate [ 'minute' ], $creationstartdate [ 'second' ], $creationenddate [ " year " ], $creationenddate [ " month " ], $creationenddate [ " day " ]);
2011-11-28 14:03:01 +00:00
if ( $stopdate ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2011-11-28 14:03:01 +00:00
if ( $startdate )
$searchCreateDate .= " AND " ;
2021-03-15 15:07:57 +00:00
$searchCreateDate .= " `tblFolders`.`date` <= " . $this -> db -> qstr ( $stopdate );
2011-11-28 14:03:01 +00:00
}
}
2015-02-05 06:37:50 +00:00
$searchQuery = " FROM " . $classname :: getSearchTables () . " WHERE 1=1 " ;
2011-11-28 14:03:01 +00:00
if ( strlen ( $searchKey ) > 0 ) {
$searchQuery .= " AND ( " . $searchKey . " ) " ;
}
if ( strlen ( $searchFolder ) > 0 ) {
$searchQuery .= " AND " . $searchFolder ;
}
if ( strlen ( $searchOwner ) > 0 ) {
$searchQuery .= " AND ( " . $searchOwner . " ) " ;
}
if ( strlen ( $searchCreateDate ) > 0 ) {
$searchQuery .= " AND ( " . $searchCreateDate . " ) " ;
}
2014-07-23 18:11:36 +00:00
if ( $searchAttributes ) {
$searchQuery .= " AND ( " . implode ( " AND " , $searchAttributes ) . " ) " ;
}
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
/* Do not search for folders if not at least a search for a key ,
* an owner , or creation date is requested .
*/
2014-07-23 18:11:36 +00:00
if ( $searchKey || $searchOwner || $searchCreateDate || $searchAttributes ) {
2012-09-14 10:47:03 +00:00
// Count the number of rows that the search will produce.
2014-07-24 11:06:45 +00:00
$resArr = $this -> db -> getResultArray ( " SELECT COUNT(*) AS num FROM (SELECT DISTINCT `tblFolders`.id " . $searchQuery . " ) a " );
2012-12-13 21:23:34 +00:00
if ( $resArr && isset ( $resArr [ 0 ]) && is_numeric ( $resArr [ 0 ][ " num " ]) && $resArr [ 0 ][ " num " ] > 0 ) {
2012-09-14 10:47:03 +00:00
$totalFolders = ( integer ) $resArr [ 0 ][ " num " ];
}
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
// If there are no results from the count query, then there is no real need
// to run the full query. TODO: re-structure code to by-pass additional
// queries when no initial results are found.
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
// Only search if the offset is not beyond the number of folders
if ( $totalFolders > $offset ) {
// Prepare the complete search query, including the LIMIT clause.
2017-02-28 08:17:25 +00:00
$searchQuery = " SELECT DISTINCT `tblFolders`.`id` " . $searchQuery . " GROUP BY `tblFolders`.`id` " ;
2011-11-28 14:03:01 +00:00
2019-06-26 11:38:39 +00:00
switch ( $orderby ) {
case 'dd' :
$searchQuery .= " ORDER BY `tblFolders`.`date` DESC " ;
break ;
case 'da' :
case 'd' :
$searchQuery .= " ORDER BY `tblFolders`.`date` " ;
break ;
case 'nd' :
$searchQuery .= " ORDER BY `tblFolders`.`name` DESC " ;
break ;
case 'na' :
$searchQuery .= " ORDER BY `tblFolders`.`name` " ;
break ;
2021-11-08 11:25:06 +00:00
case 'id' :
$searchQuery .= " ORDER BY `tblFolders`.`id` DESC " ;
break ;
case 'ia' :
$searchQuery .= " ORDER BY `tblFolders`.`id` " ;
break ;
default :
break ;
}
2019-07-16 18:16:50 +00:00
if ( $limit ) {
$searchQuery .= " LIMIT " . $limit . " OFFSET " . $offset ;
2019-06-26 11:38:39 +00:00
}
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
// Send the complete search query to the database.
$resArr = $this -> db -> getResultArray ( $searchQuery );
} else {
$resArr = array ();
}
2011-11-28 14:03:01 +00:00
2012-09-14 10:47:03 +00:00
// ------------------- Ausgabe der Ergebnisse ----------------------------
$numResults = count ( $resArr );
if ( $numResults == 0 ) {
$folderresult = array ( 'totalFolders' => $totalFolders , 'folders' => array ());
} else {
foreach ( $resArr as $folderArr ) {
$folders [] = $this -> getFolder ( $folderArr [ 'id' ]);
}
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2012-09-14 10:47:03 +00:00
$folderresult = array ( 'totalFolders' => $totalFolders , 'folders' => $folders );
2011-11-28 14:03:01 +00:00
}
2012-09-14 10:47:03 +00:00
} else {
$folderresult = array ( 'totalFolders' => 0 , 'folders' => array ());
2011-11-28 14:03:01 +00:00
}
} else {
$folderresult = array ( 'totalFolders' => 0 , 'folders' => array ());
}
/*--------- Do it all over again for documents -------------*/
2014-07-24 05:52:43 +00:00
$totalDocs = 0 ;
2011-12-06 12:31:20 +00:00
if ( $mode & 0x1 ) {
$searchKey = " " ;
2010-12-01 13:36:33 +00:00
2017-02-14 07:29:03 +00:00
$classname = $this -> classnames [ 'document' ];
2017-02-14 07:57:32 +00:00
$searchFields = $classname :: getSearchFields ( $this , $searchin );
2012-09-14 10:47:03 +00:00
if ( count ( $searchFields ) > 0 ) {
2011-12-06 12:31:20 +00:00
foreach ( $tkeys as $key ) {
$key = trim ( $key );
if ( strlen ( $key ) > 0 ) {
2012-02-13 08:31:01 +00:00
$searchKey = ( strlen ( $searchKey ) == 0 ? " " : $searchKey . " " . $logicalmode . " " ) . " ( " . implode ( " like " . $this -> db -> qstr ( " % " . $key . " % " ) . " OR " , $searchFields ) . " like " . $this -> db -> qstr ( " % " . $key . " % " ) . " ) " ;
2011-12-06 12:31:20 +00:00
}
2010-11-12 22:40:12 +00:00
}
}
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
// Check to see if the search has been restricted to a particular sub-tree in
// the folder hierarchy.
$searchFolder = " " ;
if ( $startFolder ) {
$searchFolder = " `tblDocuments`.`folderList` LIKE '%: " . $startFolder -> getID () . " :%' " ;
2020-12-16 15:47:49 +00:00
if ( $this -> checkWithinRootDir )
$searchFolder = '(' . $searchFolder . " AND `tblDocuments`.`folderList` LIKE '%: " . $this -> rootFolderID . " :%') " ;
} elseif ( $this -> checkWithinRootDir ) {
$searchFolder = " `tblDocuments`.`folderList` LIKE '%: " . $this -> rootFolderID . " :%' " ;
2011-12-06 12:31:20 +00:00
}
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
// Check to see if the search has been restricted to a particular
// document owner.
$searchOwner = " " ;
if ( $owner ) {
2013-06-07 08:09:32 +00:00
if ( is_array ( $owner )) {
$ownerids = array ();
foreach ( $owner as $o )
$ownerids [] = $o -> getID ();
if ( $ownerids )
$searchOwner = " `tblDocuments`.`owner` IN ( " . implode ( ',' , $ownerids ) . " ) " ;
} else {
$searchOwner = " `tblDocuments`.`owner` = ' " . $owner -> getId () . " ' " ;
}
2011-12-06 12:31:20 +00:00
}
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
// Check to see if the search has been restricted to a particular
// document category.
$searchCategories = " " ;
if ( $categories ) {
$catids = array ();
foreach ( $categories as $category )
$catids [] = $category -> getId ();
$searchCategories = " `tblDocumentCategory`.`categoryID` in ( " . implode ( ',' , $catids ) . " ) " ;
}
2011-03-10 14:27:05 +00:00
2012-10-09 09:53:11 +00:00
// Check to see if the search has been restricted to a particular
// attribute.
$searchAttributes = array ();
if ( $attributes ) {
foreach ( $attributes as $attrdefid => $attribute ) {
if ( $attribute ) {
2020-09-01 12:59:50 +00:00
$lsearchAttributes = [];
2012-10-09 09:53:11 +00:00
$attrdef = $this -> getAttributeDefinition ( $attrdefid );
2014-11-13 06:53:29 +00:00
if ( $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_document || $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_all ) {
if ( $valueset = $attrdef -> getValueSet ()) {
if ( $attrdef -> getMultipleValues ()) {
2018-02-22 18:11:25 +00:00
if ( is_string ( $attribute ))
$attribute = array ( $attribute );
2020-09-01 12:59:50 +00:00
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`= " . $attrdefid . " AND (`tblDocumentAttributes`.`value` like '% " . $valueset [ 0 ] . implode ( " %' OR `tblDocumentAttributes`.`value` like '% " . $valueset [ 0 ], $attribute ) . " %') AND `tblDocumentAttributes`.`document` = `tblDocuments`.`id`) " ;
2014-11-13 06:53:29 +00:00
} else
2020-09-01 12:59:50 +00:00
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`= " . $attrdefid . " AND `tblDocumentAttributes`.`value`=' " . $attribute . " ' AND `tblDocumentAttributes`.`document` = `tblDocuments`.`id`) " ;
2021-03-12 09:05:17 +00:00
} else {
if ( $attrdef -> getType () == SeedDMS_Core_AttributeDefinition :: type_date && is_array ( $attribute )) {
$kkll = [];
if ( ! empty ( $attribute [ 'from' ]))
$kkll [] = " `tblDocumentAttributes`.`value`>=' " . $attribute [ 'from' ] . " ' " ;
if ( ! empty ( $attribute [ 'to' ]))
$kkll [] = " `tblDocumentAttributes`.`value`<=' " . $attribute [ 'to' ] . " ' " ;
if ( $kkll )
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`= " . $attrdefid . " AND " . implode ( ' AND ' , $kkll ) . " AND `tblDocumentAttributes`.`document`=`tblDocuments`.`id`) " ;
} else {
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`= " . $attrdefid . " AND `tblDocumentAttributes`.`value` like '% " . $attribute . " %' AND `tblDocumentAttributes`.`document` = `tblDocuments`.`id`) " ;
}
}
2020-09-01 12:59:50 +00:00
}
if ( $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_documentcontent || $attrdef -> getObjType () == SeedDMS_Core_AttributeDefinition :: objtype_all ) {
2014-11-21 10:35:49 +00:00
if ( $attrdef -> getValueSet ()) {
if ( $attrdef -> getMultipleValues ()) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2018-02-22 18:11:25 +00:00
if ( is_string ( $attribute ))
$attribute = array ( $attribute );
2020-09-01 12:59:50 +00:00
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`= " . $attrdefid . " AND (`tblDocumentContentAttributes`.`value` like '% " . $valueset [ 0 ] . implode ( " %' OR `tblDocumentContentAttributes`.`value` like '% " . $valueset [ 0 ], $attribute ) . " %') AND `tblDocumentContentAttributes`.`content` = `tblDocumentContent`.`id`) " ;
2014-11-21 10:35:49 +00:00
} else {
2020-09-01 12:59:50 +00:00
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`= " . $attrdefid . " AND `tblDocumentContentAttributes`.`value`=' " . $attribute . " ' AND `tblDocumentContentAttributes`.content = `tblDocumentContent`.id) " ;
2014-11-21 10:35:49 +00:00
}
2021-03-12 09:05:17 +00:00
} else {
if ( $attrdef -> getType () == SeedDMS_Core_AttributeDefinition :: type_date && is_array ( $attribute )) {
$kkll = [];
if ( ! empty ( $attribute [ 'from' ]))
$kkll [] = " `tblDocumentContentAttributes`.`value`>=' " . $attribute [ 'from' ] . " ' " ;
if ( ! empty ( $attribute [ 'to' ]))
$kkll [] = " `tblDocumentContentAttributes`.`value`<=' " . $attribute [ 'to' ] . " ' " ;
if ( $kkll )
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`= " . $attrdefid . " AND " . implode ( ' AND ' , $kkll ) . " AND `tblDocumentContentAttributes`.`content`=`tblDocumentContent`.`id`) " ;
} else {
$lsearchAttributes [] = " EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`= " . $attrdefid . " AND `tblDocumentContentAttributes`.`value` like '% " . $attribute . " %' AND `tblDocumentContentAttributes`.content = `tblDocumentContent`.id) " ;
}
}
2012-10-09 09:53:11 +00:00
}
2021-03-12 09:05:17 +00:00
if ( $lsearchAttributes )
$searchAttributes [] = " ( " . implode ( " OR " , $lsearchAttributes ) . " ) " ;
2012-10-09 09:53:11 +00:00
}
}
}
2011-12-06 12:31:20 +00:00
// Is the search restricted to documents created between two specific dates?
$searchCreateDate = " " ;
if ( $creationstartdate ) {
2013-02-14 11:10:53 +00:00
$startdate = SeedDMS_Core_DMS :: makeTimeStamp ( $creationstartdate [ 'hour' ], $creationstartdate [ 'minute' ], $creationstartdate [ 'second' ], $creationstartdate [ 'year' ], $creationstartdate [ " month " ], $creationstartdate [ " day " ]);
2011-12-06 12:31:20 +00:00
if ( $startdate ) {
2021-03-15 15:07:57 +00:00
$searchCreateDate .= " `tblDocuments`.`date` >= " . $this -> db -> qstr ( $startdate );
2011-12-06 12:31:20 +00:00
}
2010-11-12 22:40:12 +00:00
}
2011-12-06 12:31:20 +00:00
if ( $creationenddate ) {
2013-02-14 11:10:53 +00:00
$stopdate = SeedDMS_Core_DMS :: makeTimeStamp ( $creationenddate [ 'hour' ], $creationenddate [ 'minute' ], $creationenddate [ 'second' ], $creationenddate [ " year " ], $creationenddate [ " month " ], $creationenddate [ " day " ]);
2011-12-06 12:31:20 +00:00
if ( $stopdate ) {
2012-10-05 19:45:57 +00:00
if ( $searchCreateDate )
2011-12-06 12:31:20 +00:00
$searchCreateDate .= " AND " ;
2021-03-15 15:07:57 +00:00
$searchCreateDate .= " `tblDocuments`.`date` <= " . $this -> db -> qstr ( $stopdate );
2011-12-06 12:31:20 +00:00
}
2010-11-12 22:40:12 +00:00
}
2012-10-05 19:45:57 +00:00
if ( $modificationstartdate ) {
2013-02-14 11:10:53 +00:00
$startdate = SeedDMS_Core_DMS :: makeTimeStamp ( $modificationstartdate [ 'hour' ], $modificationstartdate [ 'minute' ], $modificationstartdate [ 'second' ], $modificationstartdate [ 'year' ], $modificationstartdate [ " month " ], $modificationstartdate [ " day " ]);
2012-10-05 19:45:57 +00:00
if ( $startdate ) {
if ( $searchCreateDate )
$searchCreateDate .= " AND " ;
$searchCreateDate .= " `tblDocumentContent`.`date` >= " . $startdate ;
}
}
if ( $modificationenddate ) {
2013-02-14 11:10:53 +00:00
$stopdate = SeedDMS_Core_DMS :: makeTimeStamp ( $modificationenddate [ 'hour' ], $modificationenddate [ 'minute' ], $modificationenddate [ 'second' ], $modificationenddate [ " year " ], $modificationenddate [ " month " ], $modificationenddate [ " day " ]);
2012-10-05 19:45:57 +00:00
if ( $stopdate ) {
if ( $searchCreateDate )
$searchCreateDate .= " AND " ;
2021-03-15 15:07:57 +00:00
$searchCreateDate .= " `tblDocumentContent`.`date` <= " . $this -> db -> qstr ( $stopdate );
2012-10-05 19:45:57 +00:00
}
}
2021-01-29 13:19:44 +00:00
$searchRevisionDate = " " ;
if ( $revisionstartdate ) {
$startdate = $revisionstartdate [ 'year' ] . '-' . $revisionstartdate [ " month " ] . '-' . $revisionstartdate [ " day " ];
if ( $startdate ) {
if ( $searchRevisionDate )
$searchRevisionDate .= " AND " ;
$searchRevisionDate .= " `tblDocumentContent`.`revisiondate` >= ' " . $startdate . " ' " ;
}
}
if ( $revisionenddate ) {
$stopdate = $revisionenddate [ " year " ] . '-' . $revisionenddate [ " month " ] . '-' . $revisionenddate [ " day " ];
if ( $stopdate ) {
if ( $searchRevisionDate )
$searchRevisionDate .= " AND " ;
$searchRevisionDate .= " `tblDocumentContent`.`revisiondate` <= ' " . $stopdate . " ' " ;
}
}
2013-01-24 08:29:58 +00:00
$searchExpirationDate = '' ;
if ( $expirationstartdate ) {
2013-02-14 11:10:53 +00:00
$startdate = SeedDMS_Core_DMS :: makeTimeStamp ( $expirationstartdate [ 'hour' ], $expirationstartdate [ 'minute' ], $expirationstartdate [ 'second' ], $expirationstartdate [ 'year' ], $expirationstartdate [ " month " ], $expirationstartdate [ " day " ]);
2013-01-24 08:29:58 +00:00
if ( $startdate ) {
2021-03-15 15:07:57 +00:00
$searchExpirationDate .= " `tblDocuments`.`expires` >= " . $this -> db -> qstr ( $startdate );
2013-01-24 08:29:58 +00:00
}
}
if ( $expirationenddate ) {
2013-02-14 11:10:53 +00:00
$stopdate = SeedDMS_Core_DMS :: makeTimeStamp ( $expirationenddate [ 'hour' ], $expirationenddate [ 'minute' ], $expirationenddate [ 'second' ], $expirationenddate [ " year " ], $expirationenddate [ " month " ], $expirationenddate [ " day " ]);
2013-01-24 08:29:58 +00:00
if ( $stopdate ) {
if ( $searchExpirationDate )
$searchExpirationDate .= " AND " ;
2021-09-22 07:45:06 +00:00
else // do not find documents without an expiration date
$searchExpirationDate .= " `tblDocuments`.`expires` != 0 AND " ;
2021-03-15 15:07:57 +00:00
$searchExpirationDate .= " `tblDocuments`.`expires` <= " . $this -> db -> qstr ( $stopdate );
}
}
$searchStatusDate = '' ;
if ( $statusstartdate ) {
$startdate = $statusstartdate [ 'year' ] . '-' . $statusstartdate [ " month " ] . '-' . $statusstartdate [ " day " ] . ' ' . $statusstartdate [ 'hour' ] . ':' . $statusstartdate [ 'minute' ] . ':' . $statusstartdate [ 'second' ];
if ( $startdate ) {
if ( $searchStatusDate )
$searchStatusDate .= " AND " ;
$searchStatusDate .= " `tblDocumentStatusLog`.`date` >= " . $this -> db -> qstr ( $startdate );
}
}
if ( $statusenddate ) {
$stopdate = $statusenddate [ 'year' ] . '-' . $statusenddate [ " month " ] . '-' . $statusenddate [ " day " ] . ' ' . $statusenddate [ 'hour' ] . ':' . $statusenddate [ 'minute' ] . ':' . $statusenddate [ 'second' ];
if ( $stopdate ) {
if ( $searchStatusDate )
$searchStatusDate .= " AND " ;
$searchStatusDate .= " `tblDocumentStatusLog`.`date` <= " . $this -> db -> qstr ( $stopdate );
2013-01-24 08:29:58 +00:00
}
}
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
// ---------------------- Suche starten ----------------------------------
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
//
// Construct the SQL query that will be used to search the database.
//
2010-12-01 13:36:33 +00:00
2016-11-22 16:58:28 +00:00
if ( ! $this -> db -> createTemporaryTable ( " ttcontentid " ) || ! $this -> db -> createTemporaryTable ( " ttstatid " )) {
2011-12-06 12:31:20 +00:00
return false ;
}
2016-11-22 16:58:28 +00:00
if ( $reception ) {
if ( ! $this -> db -> createTemporaryTable ( " ttreceiptid " )) {
return false ;
}
}
2010-12-01 13:36:33 +00:00
2018-02-21 14:28:27 +00:00
$searchQuery = " FROM `tblDocuments` " .
" LEFT JOIN `tblDocumentContent` ON `tblDocuments`.`id` = `tblDocumentContent`.`document` " .
2012-10-09 09:53:11 +00:00
" LEFT JOIN `tblDocumentAttributes` ON `tblDocuments`.`id` = `tblDocumentAttributes`.`document` " .
" LEFT JOIN `tblDocumentContentAttributes` ON `tblDocumentContent`.`id` = `tblDocumentContentAttributes`.`content` " .
2011-12-06 12:31:20 +00:00
" LEFT JOIN `tblDocumentStatus` ON `tblDocumentStatus`.`documentID` = `tblDocumentContent`.`document` " .
2018-02-21 14:28:27 +00:00
" LEFT JOIN `ttstatid` ON `ttstatid`.`statusID` = `tblDocumentStatus`.`statusID` " .
" LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatusLog`.`statusLogID` = `ttstatid`.`maxLogID` " .
2011-12-06 12:31:20 +00:00
" LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentStatus`.`version` AND `ttcontentid`.`document` = `tblDocumentStatus`.`documentID` " .
" LEFT JOIN `tblDocumentLocks` ON `tblDocuments`.`id`=`tblDocumentLocks`.`document` " .
" LEFT JOIN `tblDocumentCategory` ON `tblDocuments`.`id`=`tblDocumentCategory`.`documentID` " .
2016-11-04 19:28:22 +00:00
// "LEFT JOIN `tblDocumentRecipients` ON `tblDocuments`.`id`=`tblDocumentRecipients`.`documentID` ".
// "LEFT JOIN `tblDocumentReceiptLog` ON `tblDocumentRecipients`.`receiptID`=`tblDocumentReceiptLog`.`receiptID` ".
// "LEFT JOIN `ttreceiptid` ON `ttreceiptid`.`maxLogID` = `tblDocumentReceiptLog`.`receiptLogID` ".
2018-02-14 08:07:03 +00:00
" WHERE " .
2018-02-14 21:00:34 +00:00
// "`ttstatid`.`maxLogID`=`tblDocumentStatusLog`.`statusLogID` AND ".
// "`ttreceiptid`.`maxLogID`=`tblDocumentReceiptLog`.`receiptLogID` AND ".
2018-02-14 08:07:03 +00:00
" `ttcontentid`.`maxVersion` = `tblDocumentContent`.`version` " ;
2010-12-01 13:36:33 +00:00
2011-12-06 12:31:20 +00:00
if ( strlen ( $searchKey ) > 0 ) {
$searchQuery .= " AND ( " . $searchKey . " ) " ;
}
if ( strlen ( $searchFolder ) > 0 ) {
$searchQuery .= " AND " . $searchFolder ;
}
if ( strlen ( $searchOwner ) > 0 ) {
$searchQuery .= " AND ( " . $searchOwner . " ) " ;
}
if ( strlen ( $searchCategories ) > 0 ) {
$searchQuery .= " AND ( " . $searchCategories . " ) " ;
}
if ( strlen ( $searchCreateDate ) > 0 ) {
$searchQuery .= " AND ( " . $searchCreateDate . " ) " ;
}
2021-01-29 13:19:44 +00:00
if ( strlen ( $searchRevisionDate ) > 0 ) {
$searchQuery .= " AND ( " . $searchRevisionDate . " ) " ;
}
2013-01-24 08:29:58 +00:00
if ( strlen ( $searchExpirationDate ) > 0 ) {
$searchQuery .= " AND ( " . $searchExpirationDate . " ) " ;
}
2021-03-15 15:07:57 +00:00
if ( strlen ( $searchStatusDate ) > 0 ) {
$searchQuery .= " AND ( " . $searchStatusDate . " ) " ;
}
2012-10-09 09:53:11 +00:00
if ( $searchAttributes ) {
$searchQuery .= " AND ( " . implode ( " AND " , $searchAttributes ) . " ) " ;
}
2010-11-12 22:40:12 +00:00
2011-12-06 12:31:20 +00:00
// status
if ( $status ) {
$searchQuery .= " AND `tblDocumentStatusLog`.`status` IN ( " . implode ( ',' , $status ) . " ) " ;
}
2016-11-22 16:58:28 +00:00
if ( $reception ) {
$searchReception = array ();
/* still waiting for users/groups to acknownledge reception */
if ( in_array ( " missingaction " , $reception ))
$searchReception [] = " b.`status` IN (0) " ;
/* document has not been acknowledeged by at least one user/group */
if ( in_array ( " hasrejection " , $reception ))
$searchReception [] = " b.`status` IN (-1) " ;
/* document has been acknowledeged by at least one user/group */
if ( in_array ( " hasacknowledge " , $reception ))
$searchReception [] = " b.`status` IN (1) " ;
/* document has been acknowledeged by all users/groups !!! not working !!! */
if ( in_array ( " completeacknowledge " , $reception ))
$searchReception [] = " b.`status` NOT IN (-1, 0) " ;
if ( $searchReception ) {
$searchQuery .= " AND EXISTS (SELECT NULL FROM `tblDocumentRecipients` a LEFT JOIN `tblDocumentReceiptLog` b ON a.`receiptID`=b.`receiptID` LEFT JOIN `ttreceiptid` c ON c.`maxLogID` = b.`receiptLogID` WHERE " ;
$searchQuery .= " c.`maxLogID`=b.`receiptLogID` AND `tblDocuments`.`id` = a.`documentID` " ;
$searchQuery .= " AND ( " . implode ( ' OR ' , $searchReception ) . " )) " ;
}
}
2016-09-28 18:22:16 +00:00
2021-03-15 15:37:07 +00:00
if ( $searchKey || $searchOwner || $searchCategories || $searchCreateDate || $searchRevisionDate || $searchExpirationDate || $searchStatusDate || $searchAttributes || $status ) {
2014-07-23 18:11:36 +00:00
// Count the number of rows that the search will produce.
2017-02-10 07:04:19 +00:00
$resArr = $this -> db -> getResultArray ( " SELECT COUNT(*) AS num FROM (SELECT DISTINCT `tblDocuments`.`id` " . $searchQuery . " ) a " );
2014-07-23 18:11:36 +00:00
$totalDocs = 0 ;
if ( is_numeric ( $resArr [ 0 ][ " num " ]) && $resArr [ 0 ][ " num " ] > 0 ) {
$totalDocs = ( integer ) $resArr [ 0 ][ " num " ];
}
2011-12-06 12:31:20 +00:00
2014-07-23 18:11:36 +00:00
// If there are no results from the count query, then there is no real need
// to run the full query. TODO: re-structure code to by-pass additional
// queries when no initial results are found.
2011-12-06 12:31:20 +00:00
2014-07-23 18:11:36 +00:00
// Prepare the complete search query, including the LIMIT clause.
$searchQuery = " SELECT DISTINCT `tblDocuments`.*, " .
" `tblDocumentContent`.`version`, " .
" `tblDocumentStatusLog`.`status`, `tblDocumentLocks`.`userID` as `lockUser` " . $searchQuery ;
2019-06-26 16:01:53 +00:00
switch ( $orderby ) {
case 'dd' :
$orderbyQuery = " ORDER BY `tblDocuments`.`date` DESC " ;
break ;
case 'da' :
case 'd' :
$orderbyQuery = " ORDER BY `tblDocuments`.`date` " ;
break ;
case 'nd' :
$orderbyQuery = " ORDER BY `tblDocuments`.`name` DESC " ;
break ;
case 'na' :
$orderbyQuery = " ORDER BY `tblDocuments`.`name` " ;
break ;
2021-11-08 11:25:06 +00:00
case 'id' :
$orderbyQuery = " ORDER BY `tblDocuments`.`id` DESC " ;
break ;
case 'ia' :
$orderbyQuery = " ORDER BY `tblDocuments`.`id` " ;
break ;
default :
$orderbyQuery = " " ;
break ;
2019-06-26 16:01:53 +00:00
}
2014-07-23 18:11:36 +00:00
// calculate the remaining entrїes of the current page
// If page is not full yet, get remaining entries
if ( $limit ) {
$remain = $limit - count ( $folderresult [ 'folders' ]);
if ( $remain ) {
if ( $remain == $limit )
$offset -= $totalFolders ;
else
$offset = 0 ;
2019-06-26 16:01:53 +00:00
$searchQuery .= $orderbyQuery ;
2019-06-26 09:47:34 +00:00
2019-07-16 18:16:50 +00:00
if ( $limit )
$searchQuery .= " LIMIT " . $limit . " OFFSET " . $offset ;
2014-07-23 18:11:36 +00:00
// Send the complete search query to the database.
$resArr = $this -> db -> getResultArray ( $searchQuery );
2018-04-12 10:32:32 +00:00
if ( $resArr === false )
return false ;
2014-07-23 18:11:36 +00:00
} else {
$resArr = array ();
}
} else {
2019-06-26 16:01:53 +00:00
$searchQuery .= $orderbyQuery ;
2019-06-26 09:47:34 +00:00
2013-01-24 08:29:58 +00:00
// Send the complete search query to the database.
$resArr = $this -> db -> getResultArray ( $searchQuery );
2018-04-12 10:32:32 +00:00
if ( $resArr === false )
return false ;
2019-06-26 09:47:34 +00:00
}
2011-12-06 12:31:20 +00:00
2014-07-23 18:11:36 +00:00
// ------------------- Ausgabe der Ergebnisse ----------------------------
$numResults = count ( $resArr );
if ( $numResults == 0 ) {
$docresult = array ( 'totalDocs' => $totalDocs , 'docs' => array ());
} else {
foreach ( $resArr as $docArr ) {
$docs [] = $this -> getDocument ( $docArr [ 'id' ]);
}
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2014-07-23 18:11:36 +00:00
$docresult = array ( 'totalDocs' => $totalDocs , 'docs' => $docs );
2011-12-06 12:31:20 +00:00
}
2014-07-23 18:11:36 +00:00
} else {
$docresult = array ( 'totalDocs' => 0 , 'docs' => array ());
2011-12-06 12:31:20 +00:00
}
} else {
$docresult = array ( 'totalDocs' => 0 , 'docs' => array ());
2010-11-12 22:40:12 +00:00
}
2011-12-06 12:31:20 +00:00
2010-11-12 22:40:12 +00:00
if ( $limit ) {
2011-11-28 14:03:01 +00:00
$totalPages = ( integer )(( $totalDocs + $totalFolders ) / $limit );
if ((( $totalDocs + $totalFolders ) % $limit ) > 0 ) {
2010-11-12 22:40:12 +00:00
$totalPages ++ ;
}
} else {
$totalPages = 1 ;
}
2010-12-01 13:36:33 +00:00
2011-11-28 14:03:01 +00:00
return array_merge ( $docresult , $folderresult , array ( 'totalPages' => $totalPages ));
2010-11-12 22:40:12 +00:00
} /* }}} */
/**
* Return a folder by its id
*
* This function retrieves a folder from the database by its id .
*
* @ param integer $id internal id of folder
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Folder instance of SeedDMS_Core_Folder or false
2010-11-12 22:40:12 +00:00
*/
function getFolder ( $id ) { /* {{{ */
2014-12-08 13:34:11 +00:00
$classname = $this -> classnames [ 'folder' ];
return $classname :: getInstance ( $id , $this );
2010-12-01 13:36:33 +00:00
} /* }}} */
/**
* Return a folder by its name
*
2010-12-22 19:48:08 +00:00
* This function retrieves a folder from the database by its name . The
* search covers the whole database . If
* the parameter $folder is not null , it will search for the name
* only within this parent folder . It will not be done recursively .
2010-12-01 13:36:33 +00:00
*
2010-12-22 19:48:08 +00:00
* @ param string $name name of the folder
2017-10-24 11:36:07 +00:00
* @ param SeedDMS_Core_Folder $folder parent folder
* @ return SeedDMS_Core_Folder | boolean found folder or false
2010-12-01 13:36:33 +00:00
*/
function getFolderByName ( $name , $folder = null ) { /* {{{ */
2021-09-18 15:49:26 +00:00
$name = trim ( $name );
2020-12-16 15:47:49 +00:00
$classname = $this -> classnames [ 'folder' ];
return $classname :: getInstanceByName ( $name , $folder , $this );
2010-11-12 22:40:12 +00:00
} /* }}} */
2010-11-15 12:01:21 +00:00
2013-11-27 08:43:33 +00:00
/**
* Returns a list of folders and error message not linked in the tree
*
* This function checks all folders in the database .
*
2017-10-24 11:36:07 +00:00
* @ return array | bool
2013-11-27 08:43:33 +00:00
*/
function checkFolders () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblFolders` " ;
2013-11-27 08:43:33 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr === false )
return false ;
$cache = array ();
foreach ( $resArr as $rec ) {
$cache [ $rec [ 'id' ]] = array ( 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'folderList' => $rec [ 'folderList' ]);
}
$errors = array ();
foreach ( $cache as $id => $rec ) {
if ( ! array_key_exists ( $rec [ 'parent' ], $cache ) && $rec [ 'parent' ] != 0 ) {
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Missing parent' );
2021-09-16 14:05:04 +00:00
}
if ( ! isset ( $errors [ $id ])) {
/* Create the real folderList and compare it with the stored folderList */
$parent = $rec [ 'parent' ];
$fl = [];
while ( $parent ) {
array_unshift ( $fl , $parent );
$parent = $cache [ $parent ][ 'parent' ];
}
if ( $fl )
$flstr = ':' . implode ( ':' , $fl ) . ':' ;
else
$flstr = '' ;
if ( $flstr != $rec [ 'folderList' ])
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Wrong folder list ' . $flstr . '!=' . $rec [ 'folderList' ]);
}
if ( ! isset ( $errors [ $id ])) {
/* This is the old insufficient test which will most likely not be called
* anymore , because the check for a wrong folder list will cache a folder
* list problem anyway .
*/
2013-11-27 08:43:33 +00:00
$tmparr = explode ( ':' , $rec [ 'folderList' ]);
array_shift ( $tmparr );
if ( count ( $tmparr ) != count ( array_unique ( $tmparr ))) {
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Duplicate entry in folder list (' . $rec [ 'folderList' ] . ')' );
}
}
}
return $errors ;
} /* }}} */
/**
* Returns a list of documents and error message not linked in the tree
*
* This function checks all documents in the database .
*
2017-10-24 11:36:07 +00:00
* @ return array | bool
2013-11-27 08:43:33 +00:00
*/
function checkDocuments () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblFolders` " ;
2013-11-27 08:43:33 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr === false )
return false ;
$fcache = array ();
foreach ( $resArr as $rec ) {
$fcache [ $rec [ 'id' ]] = array ( 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'folderList' => $rec [ 'folderList' ]);
}
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblDocuments` " ;
2013-11-27 08:43:33 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr === false )
return false ;
$dcache = array ();
foreach ( $resArr as $rec ) {
$dcache [ $rec [ 'id' ]] = array ( 'name' => $rec [ 'name' ], 'parent' => $rec [ 'folder' ], 'folderList' => $rec [ 'folderList' ]);
}
$errors = array ();
foreach ( $dcache as $id => $rec ) {
if ( ! array_key_exists ( $rec [ 'parent' ], $fcache ) && $rec [ 'parent' ] != 0 ) {
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Missing parent' );
2021-09-16 14:05:04 +00:00
}
if ( ! isset ( $errors [ $id ])) {
/* Create the real folderList and compare it with the stored folderList */
$parent = $rec [ 'parent' ];
$fl = [];
while ( $parent ) {
array_unshift ( $fl , $parent );
$parent = $fcache [ $parent ][ 'parent' ];
}
if ( $fl )
$flstr = ':' . implode ( ':' , $fl ) . ':' ;
if ( $flstr != $rec [ 'folderList' ])
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Wrong folder list ' . $flstr . '!=' . $rec [ 'folderList' ]);
}
if ( ! isset ( $errors [ $id ])) {
2013-11-27 08:43:33 +00:00
$tmparr = explode ( ':' , $rec [ 'folderList' ]);
array_shift ( $tmparr );
if ( count ( $tmparr ) != count ( array_unique ( $tmparr ))) {
$errors [ $id ] = array ( 'id' => $id , 'name' => $rec [ 'name' ], 'parent' => $rec [ 'parent' ], 'msg' => 'Duplicate entry in folder list (' . $rec [ 'folderList' ] . '' );
}
}
}
return $errors ;
} /* }}} */
2010-11-15 12:01:21 +00:00
/**
* Return a user by its id
*
* This function retrieves a user from the database by its id .
*
* @ param integer $id internal id of user
2017-10-24 10:12:38 +00:00
* @ return SeedDMS_Core_User | boolean instance of { @ link SeedDMS_Core_User } or false
2010-11-15 12:01:21 +00:00
*/
function getUser ( $id ) { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'user' ];
return $classname :: getInstance ( $id , $this );
2010-11-15 12:01:21 +00:00
} /* }}} */
/**
* Return a user by its login
*
* This function retrieves a user from the database by its login .
2011-10-07 16:14:31 +00:00
* If the second optional parameter $email is not empty , the user must
2012-01-26 13:23:22 +00:00
* also have the given email .
2010-11-15 12:01:21 +00:00
*
2011-10-07 16:14:31 +00:00
* @ param string $login internal login of user
* @ param string $email email of user
2013-02-14 11:10:53 +00:00
* @ return object instance of { @ link SeedDMS_Core_User } or false
2010-11-15 12:01:21 +00:00
*/
2011-10-07 16:14:31 +00:00
function getUserByLogin ( $login , $email = '' ) { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'user' ];
return $classname :: getInstance ( $login , $this , 'name' , $email );
2011-10-07 16:14:31 +00:00
} /* }}} */
/**
* Return a user by its email
*
* This function retrieves a user from the database by its email .
* It is needed when the user requests a new password .
*
* @ param integer $email email address of user
2013-02-14 11:10:53 +00:00
* @ return object instance of { @ link SeedDMS_Core_User } or false
2011-10-07 16:14:31 +00:00
*/
function getUserByEmail ( $email ) { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'user' ];
return $classname :: getInstance ( $email , $this , 'email' );
2010-11-15 12:01:21 +00:00
} /* }}} */
2011-01-11 09:06:59 +00:00
/**
* Return list of all users
*
2018-02-08 08:25:45 +00:00
* @ param string $orderby
* @ return array of instances of < a href = 'psi_element://SeedDMS_Core_User' > SeedDMS_Core_User </ a > or false
* or false
2011-01-11 09:06:59 +00:00
*/
2012-08-28 07:28:16 +00:00
function getAllUsers ( $orderby = '' ) { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'user' ];
return $classname :: getAllInstances ( $orderby , $this );
2010-11-15 12:01:21 +00:00
} /* }}} */
2010-12-01 13:36:33 +00:00
2011-01-11 09:06:59 +00:00
/**
* Add a new user
*
* @ param string $login login name
* @ param string $pwd password of new user
2018-02-08 08:25:45 +00:00
* @ param $fullName
2011-01-11 09:06:59 +00:00
* @ param string $email Email of new user
* @ param string $language language of new user
2018-02-08 08:25:45 +00:00
* @ param $theme
2011-01-11 09:06:59 +00:00
* @ param string $comment comment of new user
2018-02-08 08:25:45 +00:00
* @ param int | string $role role of new user ( can be 0 = normal , 1 = admin , 2 = guest )
2011-01-11 09:06:59 +00:00
* @ param integer $isHidden hide user in all lists , if this is set login
* is still allowed
2012-08-28 07:28:16 +00:00
* @ param integer $isDisabled disable user and prevent login
2018-02-08 08:25:45 +00:00
* @ param string $pwdexpiration
* @ param int $quota
* @ param null $homefolder
* @ return bool | SeedDMS_Core_User
2011-01-11 09:06:59 +00:00
*/
2021-09-28 13:44:12 +00:00
function addUser ( $login , $pwd , $fullName , $email , $language , $theme , $comment , $role = '3' , $isHidden = 0 , $isDisabled = 0 , $pwdexpiration = '' , $quota = 0 , $homefolder = null ) { /* {{{ */
2012-09-11 12:58:30 +00:00
$db = $this -> db ;
2010-11-15 12:01:21 +00:00
if ( is_object ( $this -> getUserByLogin ( $login ))) {
return false ;
}
2022-02-17 11:29:37 +00:00
if ( ! is_object ( $role )) {
if ( $role == '' )
$role = SeedDMS_Core_Role :: getInstance ( 3 , $this );
else
$role = SeedDMS_Core_Role :: getInstance ( $role , $this );
}
2017-02-28 16:12:27 +00:00
if ( trim ( $pwdexpiration ) == '' || trim ( $pwdexpiration ) == 'never' ) {
2016-08-08 10:49:59 +00:00
$pwdexpiration = 'NULL' ;
2017-02-28 07:00:45 +00:00
} elseif ( trim ( $pwdexpiration ) == 'now' ) {
2017-02-14 10:43:17 +00:00
$pwdexpiration = $db -> qstr ( date ( 'Y-m-d H:i:s' ));
2017-02-28 07:00:45 +00:00
} else {
2016-08-08 10:49:59 +00:00
$pwdexpiration = $db -> qstr ( $pwdexpiration );
2017-02-28 07:00:45 +00:00
}
2022-02-17 11:29:37 +00:00
$queryStr = " INSERT INTO `tblUsers` (`login`, `pwd`, `fullName`, `email`, `language`, `theme`, `comment`, `role`, `hidden`, `disabled`, `pwdExpiration`, `quota`, `homefolder`) VALUES ( " . $db -> qstr ( $login ) . " , " . $db -> qstr ( $pwd ) . " , " . $db -> qstr ( $fullName ) . " , " . $db -> qstr ( $email ) . " , ' " . $language . " ', ' " . $theme . " ', " . $db -> qstr ( $comment ) . " , ' " . intval ( $role -> getId ()) . " ', ' " . intval ( $isHidden ) . " ', ' " . intval ( $isDisabled ) . " ', " . $pwdexpiration . " , ' " . intval ( $quota ) . " ', " . ( $homefolder ? intval ( $homefolder ) : " NULL " ) . " ) " ;
2010-11-15 12:01:21 +00:00
$res = $this -> db -> getResult ( $queryStr );
if ( ! $res )
return false ;
2010-12-01 13:36:33 +00:00
2017-02-11 14:19:36 +00:00
$user = $this -> getUser ( $this -> db -> getInsertID ( 'tblUsers' ));
2016-04-04 05:39:39 +00:00
/* Check if 'onPostAddUser' callback is set */
2020-03-25 07:04:39 +00:00
if ( isset ( $this -> callbacks [ 'onPostAddUser' ])) {
2021-09-17 16:28:01 +00:00
foreach ( $this -> callbacks [ 'onPostAddUser' ] as $callback ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpStatementHasEmptyBodyInspection */
2016-04-26 10:06:41 +00:00
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $user )) {
}
2016-04-04 05:39:39 +00:00
}
}
return $user ;
2010-11-15 12:01:21 +00:00
} /* }}} */
2010-12-22 19:48:08 +00:00
/**
* Get a group by its id
*
* @ param integer $id id of group
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Group | boolean group or false if no group was found
2010-12-22 19:48:08 +00:00
*/
2010-11-15 12:01:21 +00:00
function getGroup ( $id ) { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'group' ];
return $classname :: getInstance ( $id , $this , '' );
2010-11-15 12:01:21 +00:00
} /* }}} */
2010-12-22 19:48:08 +00:00
/**
* Get a group by its name
*
* @ param string $name name of group
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Group | boolean group or false if no group was found
2010-12-22 19:48:08 +00:00
*/
2010-11-15 12:01:21 +00:00
function getGroupByName ( $name ) { /* {{{ */
2021-09-18 15:49:26 +00:00
$name = trim ( $name );
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'group' ];
return $classname :: getInstance ( $name , $this , 'name' );
2010-11-15 21:08:07 +00:00
} /* }}} */
2010-11-30 12:23:46 +00:00
/**
* Get a list of all groups
*
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Group [] array of instances of { @ link SeedDMS_Core_Group }
2010-11-30 12:23:46 +00:00
*/
2010-11-15 21:08:07 +00:00
function getAllGroups () { /* {{{ */
2015-04-14 17:37:06 +00:00
$classname = $this -> classnames [ 'group' ];
return $classname :: getAllInstances ( 'name' , $this );
2010-11-15 12:01:21 +00:00
} /* }}} */
2010-11-30 12:23:46 +00:00
/**
* Create a new user group
*
* @ param string $name name of group
* @ param string $comment comment of group
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Group | boolean instance of { @ link SeedDMS_Core_Group } or false in
2010-11-30 12:23:46 +00:00
* case of an error .
*/
2010-11-15 12:01:21 +00:00
function addGroup ( $name , $comment ) { /* {{{ */
2021-09-18 15:49:26 +00:00
$name = trim ( $name );
2010-11-15 12:01:21 +00:00
if ( is_object ( $this -> getGroupByName ( $name ))) {
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblGroups` (`name`, `comment`) VALUES ( " . $this -> db -> qstr ( $name ) . " , " . $this -> db -> qstr ( $comment ) . " ) " ;
2010-11-15 12:01:21 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
2010-12-01 13:36:33 +00:00
2017-02-11 14:19:36 +00:00
$group = $this -> getGroup ( $this -> db -> getInsertID ( 'tblGroups' ));
2016-04-04 05:39:39 +00:00
/* Check if 'onPostAddGroup' callback is set */
2020-03-25 07:04:39 +00:00
if ( isset ( $this -> callbacks [ 'onPostAddGroup' ])) {
foreach ( $this -> callbacks [ 'onPostAddGroup' ] as $callback ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpStatementHasEmptyBodyInspection */
2016-04-26 10:06:41 +00:00
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $group )) {
}
2016-04-04 05:39:39 +00:00
}
}
return $group ;
2010-11-15 12:01:21 +00:00
} /* }}} */
2016-02-24 13:32:55 +00:00
/**
* Get a role by its id
*
* @ param integer $id id of role
* @ return object / boolean role or false if no role was found
*/
function getRole ( $id ) { /* {{{ */
$classname = $this -> classnames [ 'role' ];
return $classname :: getInstance ( $id , $this );
} /* }}} */
/**
* Get a role by its name
*
* @ param integer $name name of role
* @ return object / boolean role or false if no role was found
*/
function getRoleByName ( $name ) { /* {{{ */
$classname = $this -> classnames [ 'role' ];
return $classname :: getInstance ( $name , $this , 'name' );
} /* }}} */
/**
* Return list of all roles
*
* @ return array of instances of { @ link SeedDMS_Core_Role } or false
*/
function getAllRoles ( $orderby = '' ) { /* {{{ */
$classname = $this -> classnames [ 'role' ];
return $classname :: getAllInstances ( $orderby , $this );
} /* }}} */
/**
* Create a new role
*
* @ param string $name name of role
* @ return object / boolean instance of { @ link SeedDMS_Core_Role } or false in
* case of an error .
*/
function addRole ( $name , $role ) { /* {{{ */
if ( is_object ( $this -> getRoleByName ( $name ))) {
return false ;
}
2017-02-13 11:37:26 +00:00
$queryStr = " INSERT INTO `tblRoles` (`name`, `role`) VALUES ( " . $this -> db -> qstr ( $name ) . " , " . $role . " ) " ;
2016-02-24 13:32:55 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
2017-02-13 11:37:26 +00:00
return $this -> getRole ( $this -> db -> getInsertID ( 'tblRoles' ));
2016-02-24 13:32:55 +00:00
} /* }}} */
2015-04-27 06:24:26 +00:00
/**
* Get a transmittal by its id
*
* @ param integer $id id of transmittal
* @ return object / boolean transmittal or false if no group was found
*/
function getTransmittal ( $id ) { /* {{{ */
$classname = $this -> classnames [ 'transmittal' ];
return $classname :: getInstance ( $id , $this , '' );
} /* }}} */
/**
* Get a transmittal by its name
*
* @ param string $name name of transmittal
* @ return object / boolean transmittal or false if no group was found
*/
function getTransmittalByName ( $name ) { /* {{{ */
$classname = $this -> classnames [ 'transmittal' ];
return $classname :: getInstance ( $name , $this , 'name' );
} /* }}} */
/**
* Return list of all transmittals
*
* @ return array of instances of { @ link SeedDMS_Core_Transmittal } or false
*/
function getAllTransmittals ( $user = null , $orderby = '' ) { /* {{{ */
$classname = $this -> classnames [ 'transmittal' ];
return $classname :: getAllInstances ( $user , $orderby , $this );
} /* }}} */
/**
* Create a new transmittal
*
* @ param string $name name of group
* @ param string $comment comment of group
* @ param object $user user this transmittal belongs to
* @ return object / boolean instance of { @ link SeedDMS_Core_Transmittal } or
* false in case of an error .
*/
function addTransmittal ( $name , $comment , $user ) { /* {{{ */
if ( is_object ( $this -> getTransmittalByName ( $name ))) {
return false ;
}
2017-02-13 11:37:26 +00:00
$queryStr = " INSERT INTO `tblTransmittals` (`name`, `comment`, `userID`) VALUES ( " . $this -> db -> qstr ( $name ) . " , " . $this -> db -> qstr ( $comment ) . " , " . $user -> getID () . " ) " ;
2015-04-27 06:24:26 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
2017-02-13 11:37:26 +00:00
return $this -> getTransmittal ( $this -> db -> getInsertID ( 'tblTransmittals' ));
2015-04-27 06:24:26 +00:00
} /* }}} */
2010-11-27 20:52:03 +00:00
function getKeywordCategory ( $id ) { /* {{{ */
2021-09-17 16:28:40 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2011-03-10 14:27:05 +00:00
return false ;
2010-11-27 20:52:03 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblKeywordCategories` WHERE `id` = " . ( int ) $id ;
2010-11-27 20:52:03 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-18 15:50:32 +00:00
if ( is_bool ( $resArr ) && ! $resArr )
2010-11-27 20:52:03 +00:00
return false ;
2021-09-18 15:50:32 +00:00
if ( count ( $resArr ) != 1 )
return null ;
2010-11-27 20:52:03 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_Keywordcategory ( $resArr [ " id " ], $resArr [ " owner " ], $resArr [ " name " ]);
2010-11-27 20:52:03 +00:00
$cat -> setDMS ( $this );
return $cat ;
} /* }}} */
2012-04-26 20:26:56 +00:00
function getKeywordCategoryByName ( $name , $userID ) { /* {{{ */
2021-09-18 15:50:32 +00:00
if ( ! is_numeric ( $userID ) || $userID < 1 )
return false ;
$name = trim ( $name );
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblKeywordCategories` WHERE `name` = " . $this -> db -> qstr ( $name ) . " AND `owner` = " . ( int ) $userID ;
2010-11-27 20:52:03 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-18 15:50:32 +00:00
if ( is_bool ( $resArr ) && ! $resArr )
2010-11-27 20:52:03 +00:00
return false ;
2021-09-18 15:50:32 +00:00
if ( count ( $resArr ) != 1 )
return null ;
2010-11-27 20:52:03 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_Keywordcategory ( $resArr [ " id " ], $resArr [ " owner " ], $resArr [ " name " ]);
2010-11-27 20:52:03 +00:00
$cat -> setDMS ( $this );
return $cat ;
} /* }}} */
function getAllKeywordCategories ( $userIDs = array ()) { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblKeywordCategories` " ;
2021-09-17 16:29:33 +00:00
/* Ensure $userIDs() will only contain integers > 0 */
$userIDs = array_filter ( array_unique ( array_map ( 'intval' , $userIDs )), function ( $a ) { return $a > 0 ;});
if ( $userIDs ) {
2017-02-10 07:04:19 +00:00
$queryStr .= " WHERE `owner` IN ( " . implode ( ',' , $userIDs ) . " ) " ;
2021-09-17 16:29:33 +00:00
}
2010-11-27 20:52:03 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$categories = array ();
foreach ( $resArr as $row ) {
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_KeywordCategory ( $row [ " id " ], $row [ " owner " ], $row [ " name " ]);
2010-11-27 20:52:03 +00:00
$cat -> setDMS ( $this );
array_push ( $categories , $cat );
}
return $categories ;
} /* }}} */
2012-04-26 20:26:56 +00:00
/**
* This function should be replaced by getAllKeywordCategories ()
2021-09-17 16:31:19 +00:00
*
2018-02-08 08:25:45 +00:00
* @ param $userID
* @ return SeedDMS_Core_KeywordCategory [] | bool
2012-04-26 20:26:56 +00:00
*/
2010-11-27 20:52:03 +00:00
function getAllUserKeywordCategories ( $userID ) { /* {{{ */
2021-09-17 16:31:19 +00:00
if ( ! is_numeric ( $userID ) || $userID < 1 )
2010-11-27 20:52:03 +00:00
return false ;
2021-09-17 16:31:19 +00:00
return self :: getAllKeywordCategories ([ $userID ]);
2010-11-27 20:52:03 +00:00
} /* }}} */
2012-04-26 20:26:56 +00:00
function addKeywordCategory ( $userID , $name ) { /* {{{ */
2021-09-17 16:31:19 +00:00
if ( ! is_numeric ( $userID ) || $userID < 1 )
return false ;
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
2021-09-17 16:31:19 +00:00
return false ;
2012-04-26 20:26:56 +00:00
if ( is_object ( $this -> getKeywordCategoryByName ( $name , $userID ))) {
2010-11-27 20:52:03 +00:00
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblKeywordCategories` (`owner`, `name`) VALUES ( " . ( int ) $userID . " , " . $this -> db -> qstr ( $name ) . " ) " ;
2010-11-27 20:52:03 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
2017-02-11 14:19:36 +00:00
$category = $this -> getKeywordCategory ( $this -> db -> getInsertID ( 'tblKeywordCategories' ));
2016-04-04 05:39:39 +00:00
/* Check if 'onPostAddKeywordCategory' callback is set */
2020-03-25 07:04:39 +00:00
if ( isset ( $this -> callbacks [ 'onPostAddKeywordCategory' ])) {
foreach ( $this -> callbacks [ 'onPostAddKeywordCategory' ] as $callback ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpStatementHasEmptyBodyInspection */
2016-04-26 10:06:41 +00:00
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $category )) {
}
2016-04-04 05:39:39 +00:00
}
}
return $category ;
2010-11-27 20:52:03 +00:00
} /* }}} */
2011-03-10 14:27:05 +00:00
function getDocumentCategory ( $id ) { /* {{{ */
2021-09-17 16:58:29 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2011-03-10 14:27:05 +00:00
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblCategory` WHERE `id` = " . ( int ) $id ;
2011-03-10 14:27:05 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-27 08:07:19 +00:00
if ( is_bool ( $resArr ) && ! $resArr )
2011-03-10 14:27:05 +00:00
return false ;
2021-09-27 08:07:19 +00:00
if ( count ( $resArr ) != 1 )
return null ;
2011-03-10 14:27:05 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_DocumentCategory ( $resArr [ " id " ], $resArr [ " name " ]);
2011-03-10 14:27:05 +00:00
$cat -> setDMS ( $this );
return $cat ;
} /* }}} */
function getDocumentCategories () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblCategory` order by `name` " ;
2011-03-10 14:27:05 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
$categories = array ();
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:27:05 +00:00
$cat -> setDMS ( $this );
array_push ( $categories , $cat );
}
return $categories ;
} /* }}} */
2011-07-20 16:47:09 +00:00
/**
* Get a category by its name
*
* The name of a category is by default unique .
*
* @ param string $name human readable name of category
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_DocumentCategory | boolean instance of { @ link SeedDMS_Core_DocumentCategory }
2011-07-20 16:47:09 +00:00
*/
2011-03-10 14:27:05 +00:00
function getDocumentCategoryByName ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
2013-02-11 07:46:02 +00:00
if ( ! $name ) return false ;
2011-03-10 14:27:05 +00:00
2021-09-27 08:06:07 +00:00
$queryStr = " SELECT * FROM `tblCategory` WHERE `name`= " . $this -> db -> qstr ( $name );
2011-03-10 14:27:05 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2011-07-22 20:48:31 +00:00
if ( ! $resArr )
2011-03-10 14:27:05 +00:00
return false ;
2011-07-20 16:47:09 +00:00
$row = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$cat = new SeedDMS_Core_DocumentCategory ( $row [ " id " ], $row [ " name " ]);
2011-07-20 16:47:09 +00:00
$cat -> setDMS ( $this );
2011-03-10 14:27:05 +00:00
2011-07-20 16:47:09 +00:00
return $cat ;
2011-03-10 14:27:05 +00:00
} /* }}} */
function addDocumentCategory ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
2021-09-17 16:59:06 +00:00
return false ;
2011-03-10 14:27:05 +00:00
if ( is_object ( $this -> getDocumentCategoryByName ( $name ))) {
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblCategory` (`name`) VALUES ( " . $this -> db -> qstr ( $name ) . " ) " ;
2011-03-10 14:27:05 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
2017-02-11 14:19:36 +00:00
$category = $this -> getDocumentCategory ( $this -> db -> getInsertID ( 'tblCategory' ));
2016-04-04 05:39:39 +00:00
/* Check if 'onPostAddDocumentCategory' callback is set */
2020-03-25 07:04:39 +00:00
if ( isset ( $this -> callbacks [ 'onPostAddDocumentCategory' ])) {
foreach ( $this -> callbacks [ 'onPostAddDocumentCategory' ] as $callback ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpStatementHasEmptyBodyInspection */
2016-04-26 10:06:41 +00:00
if ( ! call_user_func ( $callback [ 0 ], $callback [ 1 ], $category )) {
}
2016-04-04 05:39:39 +00:00
}
}
return $category ;
2011-03-10 14:27:05 +00:00
} /* }}} */
2010-12-21 17:41:05 +00:00
/**
* Get all notifications for a group
*
2016-02-05 15:48:32 +00:00
* deprecated : User { @ link SeedDMS_Core_Group :: getNotifications ()}
*
2010-12-22 19:48:08 +00:00
* @ param object $group group for which notifications are to be retrieved
* @ param integer $type type of item ( T_DOCUMENT or T_FOLDER )
* @ return array array of notifications
2010-12-21 17:41:05 +00:00
*/
function getNotificationsByGroup ( $group , $type = 0 ) { /* {{{ */
2016-02-05 15:48:32 +00:00
return $group -> getNotifications ( $type );
2010-12-21 17:41:05 +00:00
} /* }}} */
/**
* Get all notifications for a user
*
2016-02-05 15:48:32 +00:00
* deprecated : User { @ link SeedDMS_Core_User :: getNotifications ()}
*
2010-12-22 19:48:08 +00:00
* @ param object $user user for which notifications are to be retrieved
* @ param integer $type type of item ( T_DOCUMENT or T_FOLDER )
* @ return array array of notifications
2010-12-21 17:41:05 +00:00
*/
2012-04-26 20:26:56 +00:00
function getNotificationsByUser ( $user , $type = 0 ) { /* {{{ */
2016-02-05 15:48:32 +00:00
return $user -> getNotifications ( $type );
2010-12-21 17:41:05 +00:00
} /* }}} */
2011-10-10 14:08:24 +00:00
/**
* Create a token to request a new password .
* This function will not delete the password but just creates an entry
* in tblUserRequestPassword indicating a password request .
*
2018-02-08 08:25:45 +00:00
* @ param SeedDMS_Core_User $user
* @ return string | boolean hash value of false in case of an error
2011-10-10 14:08:24 +00:00
*/
function createPasswordRequest ( $user ) { /* {{{ */
$hash = md5 ( uniqid ( time ()));
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblUserPasswordRequest` (`userID`, `hash`, `date`) VALUES ( " . $user -> getId () . " , " . $this -> db -> qstr ( $hash ) . " , " . $this -> db -> getCurrentDatetime () . " ) " ;
2011-10-10 14:08:24 +00:00
$resArr = $this -> db -> getResult ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr ) return false ;
return $hash ;
} /* }}} */
/**
* Check if hash for a password request is valid .
* This function searches a previously create password request and
* returns the user .
*
* @ param string $hash
2018-02-08 08:25:45 +00:00
* @ return bool | SeedDMS_Core_User
2011-10-10 14:08:24 +00:00
*/
function checkPasswordRequest ( $hash ) { /* {{{ */
/* Get the password request from the database */
2021-09-27 08:06:07 +00:00
$queryStr = " SELECT * FROM `tblUserPasswordRequest` WHERE `hash`= " . $this -> db -> qstr ( $hash );
2011-10-10 14:08:24 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && ! $resArr )
return false ;
if ( count ( $resArr ) != 1 )
return false ;
$resArr = $resArr [ 0 ];
return $this -> getUser ( $resArr [ 'userID' ]);
} /* }}} */
/**
* Delete a password request
*
* @ param string $hash
2018-02-08 08:25:45 +00:00
* @ return bool
2011-10-10 14:08:24 +00:00
*/
function deletePasswordRequest ( $hash ) { /* {{{ */
/* Delete the request, so nobody can use it a second time */
2017-02-10 07:04:19 +00:00
$queryStr = " DELETE FROM `tblUserPasswordRequest` WHERE `hash`= " . $this -> db -> qstr ( $hash );
2011-10-10 14:08:24 +00:00
if ( ! $this -> db -> getResult ( $queryStr ))
return false ;
return true ;
2012-10-09 09:53:11 +00:00
} /* }}} */
/**
* Return a attribute definition by its id
*
* This function retrieves a attribute definitionr from the database by
* its id .
*
* @ param integer $id internal id of attribute defintion
2017-10-24 10:12:38 +00:00
* @ return bool | SeedDMS_Core_AttributeDefinition or false
2012-10-09 09:53:11 +00:00
*/
function getAttributeDefinition ( $id ) { /* {{{ */
2021-09-27 08:07:19 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2012-10-09 09:53:11 +00:00
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblAttributeDefinitions` WHERE `id` = " . ( int ) $id ;
2012-10-09 09:53:11 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-27 08:07:19 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return null ;
2012-10-09 09:53:11 +00:00
$resArr = $resArr [ 0 ];
2013-05-28 07:01:04 +00:00
$attrdef = new SeedDMS_Core_AttributeDefinition ( $resArr [ " id " ], $resArr [ " name " ], $resArr [ " objtype " ], $resArr [ " type " ], $resArr [ " multiple " ], $resArr [ " minvalues " ], $resArr [ " maxvalues " ], $resArr [ " valueset " ], $resArr [ " regex " ]);
2012-10-09 09:53:11 +00:00
$attrdef -> setDMS ( $this );
return $attrdef ;
} /* }}} */
/**
* Return a attribute definition by its name
*
* This function retrieves an attribute def . from the database by its name .
*
* @ param string $name internal name of attribute def .
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_AttributeDefinition | boolean instance of { @ link SeedDMS_Core_AttributeDefinition } or false
2012-10-09 09:53:11 +00:00
*/
function getAttributeDefinitionByName ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
2013-02-11 07:46:02 +00:00
if ( ! $name ) return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblAttributeDefinitions` WHERE `name` = " . $this -> db -> qstr ( $name );
2012-10-09 09:53:11 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-27 08:07:19 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return null ;
2012-10-09 09:53:11 +00:00
$resArr = $resArr [ 0 ];
2013-05-28 07:01:04 +00:00
$attrdef = new SeedDMS_Core_AttributeDefinition ( $resArr [ " id " ], $resArr [ " name " ], $resArr [ " objtype " ], $resArr [ " type " ], $resArr [ " multiple " ], $resArr [ " minvalues " ], $resArr [ " maxvalues " ], $resArr [ " valueset " ], $resArr [ " regex " ]);
2012-10-09 09:53:11 +00:00
$attrdef -> setDMS ( $this );
return $attrdef ;
} /* }}} */
/**
* Return list of all attributes definitions
*
* @ param integer $objtype select those attributes defined for an object type
2018-02-08 08:25:45 +00:00
* @ return bool | SeedDMS_Core_AttributeDefinition [] of instances of < a href = 'psi_element://SeedDMS_Core_AttributeDefinition' > SeedDMS_Core_AttributeDefinition </ a > or false
* or false
2012-10-09 09:53:11 +00:00
*/
function getAllAttributeDefinitions ( $objtype = 0 ) { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblAttributeDefinitions` " ;
2012-10-09 09:53:11 +00:00
if ( $objtype ) {
if ( is_array ( $objtype ))
2017-02-10 07:04:19 +00:00
$queryStr .= ' WHERE `objtype` in (\'' . implode ( " ',' " , $objtype ) . '\')' ;
2012-10-09 09:53:11 +00:00
else
2017-02-10 07:04:19 +00:00
$queryStr .= ' WHERE `objtype`=' . intval ( $objtype );
2012-10-09 09:53:11 +00:00
}
2017-02-10 07:04:19 +00:00
$queryStr .= ' ORDER BY `name`' ;
2012-10-09 09:53:11 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_AttributeDefinition[] $attrdefs */
2012-10-09 09:53:11 +00:00
$attrdefs = array ();
for ( $i = 0 ; $i < count ( $resArr ); $i ++ ) {
2013-05-28 07:01:04 +00:00
$attrdef = new SeedDMS_Core_AttributeDefinition ( $resArr [ $i ][ " id " ], $resArr [ $i ][ " name " ], $resArr [ $i ][ " objtype " ], $resArr [ $i ][ " type " ], $resArr [ $i ][ " multiple " ], $resArr [ $i ][ " minvalues " ], $resArr [ $i ][ " maxvalues " ], $resArr [ $i ][ " valueset " ], $resArr [ $i ][ " regex " ]);
2012-10-09 09:53:11 +00:00
$attrdef -> setDMS ( $this );
$attrdefs [ $i ] = $attrdef ;
}
return $attrdefs ;
} /* }}} */
/**
* Add a new attribute definition
*
* @ param string $name name of attribute
2018-02-08 08:25:45 +00:00
* @ param $objtype
2012-10-09 09:53:11 +00:00
* @ param string $type type of attribute
2018-02-08 08:25:45 +00:00
* @ param bool | int $multiple set to 1 if attribute has multiple attributes
2012-10-09 09:53:11 +00:00
* @ param integer $minvalues minimum number of values
* @ param integer $maxvalues maximum number of values if multiple is set
* @ param string $valueset list of allowed values ( csv format )
2018-02-08 08:25:45 +00:00
* @ param string $regex
* @ return bool | SeedDMS_Core_User
2012-10-09 09:53:11 +00:00
*/
2013-05-28 07:01:04 +00:00
function addAttributeDefinition ( $name , $objtype , $type , $multiple = 0 , $minvalues = 0 , $maxvalues = 1 , $valueset = '' , $regex = '' ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
return false ;
2012-10-09 09:53:11 +00:00
if ( is_object ( $this -> getAttributeDefinitionByName ( $name ))) {
return false ;
}
2021-09-18 15:50:32 +00:00
if ( ! $objtype )
return false ;
2012-10-09 09:53:11 +00:00
if ( ! $type )
return false ;
2016-10-07 09:38:04 +00:00
if ( trim ( $valueset )) {
$valuesetarr = array_map ( 'trim' , explode ( $valueset [ 0 ], substr ( $valueset , 1 )));
$valueset = $valueset [ 0 ] . implode ( $valueset [ 0 ], $valuesetarr );
} else {
$valueset = '' ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblAttributeDefinitions` (`name`, `objtype`, `type`, `multiple`, `minvalues`, `maxvalues`, `valueset`, `regex`) VALUES ( " . $this -> db -> qstr ( $name ) . " , " . intval ( $objtype ) . " , " . intval ( $type ) . " , " . intval ( $multiple ) . " , " . intval ( $minvalues ) . " , " . intval ( $maxvalues ) . " , " . $this -> db -> qstr ( $valueset ) . " , " . $this -> db -> qstr ( $regex ) . " ) " ;
2012-10-09 09:53:11 +00:00
$res = $this -> db -> getResult ( $queryStr );
if ( ! $res )
return false ;
2017-02-11 14:19:36 +00:00
return $this -> getAttributeDefinition ( $this -> db -> getInsertID ( 'tblAttributeDefinitions' ));
2012-10-09 09:53:11 +00:00
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Return list of all workflows
*
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow [] | bool of instances of { @ link SeedDMS_Core_Workflow } or false
2013-01-24 08:29:58 +00:00
*/
function getAllWorkflows () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflows` ORDER BY `name` " ;
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowStates` ORDER BY `name` " ;
2013-01-24 08:29:58 +00:00
$ressArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $ressArr ) && $ressArr == false )
return false ;
for ( $i = 0 ; $i < count ( $ressArr ); $i ++ ) {
2013-02-14 11:10:53 +00:00
$wkfstates [ $ressArr [ $i ][ " id " ]] = new SeedDMS_Core_Workflow_State ( $ressArr [ $i ][ " id " ], $ressArr [ $i ][ " name " ], $ressArr [ $i ][ " maxtime " ], $ressArr [ $i ][ " precondfunc " ], $ressArr [ $i ][ " documentstatus " ]);
2013-01-24 08:29:58 +00:00
}
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Workflow[] $workflows */
2013-01-24 08:29:58 +00:00
$workflows = array ();
for ( $i = 0 ; $i < count ( $resArr ); $i ++ ) {
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2016-09-06 08:10:17 +00:00
$workflow = new SeedDMS_Core_Workflow ( $resArr [ $i ][ " id " ], $resArr [ $i ][ " name " ], $wkfstates [ $resArr [ $i ][ " initstate " ]], $resArr [ $i ][ " layoutdata " ]);
2013-01-24 08:29:58 +00:00
$workflow -> setDMS ( $this );
$workflows [ $i ] = $workflow ;
}
return $workflows ;
} /* }}} */
/**
* Return workflow by its Id
*
2014-11-19 06:44:54 +00:00
* @ param integer $id internal id of workflow
2021-09-18 15:50:32 +00:00
* @ return SeedDMS_Core_Workflow | bool of instances of { @ link SeedDMS_Core_Workflow }, null if no workflow was found or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflow ( $id ) { /* {{{ */
2021-09-27 08:08:20 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2021-09-18 15:50:32 +00:00
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflows` WHERE `id`= " . intval ( $id );
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( ! $resArr )
2021-09-18 15:50:32 +00:00
return null ;
2013-01-24 08:29:58 +00:00
$initstate = $this -> getWorkflowState ( $resArr [ 0 ][ 'initstate' ]);
2016-08-31 09:54:15 +00:00
$workflow = new SeedDMS_Core_Workflow ( $resArr [ 0 ][ " id " ], $resArr [ 0 ][ " name " ], $initstate , $resArr [ 0 ][ " layoutdata " ]);
2013-01-24 08:29:58 +00:00
$workflow -> setDMS ( $this );
return $workflow ;
} /* }}} */
/**
* Return workflow by its name
*
2014-11-19 06:44:54 +00:00
* @ param string $name name of workflow
2021-09-18 15:50:32 +00:00
* @ return SeedDMS_Core_Workflow | bool of instances of { @ link SeedDMS_Core_Workflow } or null if no workflow was found or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflowByName ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
2013-02-11 07:46:02 +00:00
if ( ! $name ) return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflows` WHERE `name`= " . $this -> db -> qstr ( $name );
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( ! $resArr )
2021-09-18 15:50:32 +00:00
return null ;
2013-01-24 08:29:58 +00:00
$initstate = $this -> getWorkflowState ( $resArr [ 0 ][ 'initstate' ]);
2016-08-31 09:54:15 +00:00
$workflow = new SeedDMS_Core_Workflow ( $resArr [ 0 ][ " id " ], $resArr [ 0 ][ " name " ], $initstate , $resArr [ 0 ][ " layoutdata " ]);
2013-01-24 08:29:58 +00:00
$workflow -> setDMS ( $this );
return $workflow ;
} /* }}} */
2014-11-19 06:44:54 +00:00
/**
* Add a new workflow
*
* @ param string $name name of workflow
2018-02-08 08:25:45 +00:00
* @ param SeedDMS_Core_Workflow_State $initstate initial state of workflow
* @ return bool | SeedDMS_Core_Workflow
2014-11-19 06:44:54 +00:00
*/
2013-01-24 08:29:58 +00:00
function addWorkflow ( $name , $initstate ) { /* {{{ */
$db = $this -> db ;
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
return false ;
2013-01-24 08:29:58 +00:00
if ( is_object ( $this -> getWorkflowByName ( $name ))) {
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblWorkflows` (`name`, `initstate`) VALUES ( " . $db -> qstr ( $name ) . " , " . $initstate -> getID () . " ) " ;
2013-01-24 08:29:58 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
2017-02-11 14:19:36 +00:00
return $this -> getWorkflow ( $db -> getInsertID ( 'tblWorkflows' ));
2013-01-24 08:29:58 +00:00
} /* }}} */
/**
* Return a workflow state by its id
*
* This function retrieves a workflow state from the database by its id .
*
* @ param integer $id internal id of workflow state
2017-10-24 11:36:07 +00:00
* @ return bool | SeedDMS_Core_Workflow_State or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflowState ( $id ) { /* {{{ */
2021-09-27 08:08:20 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2013-01-24 08:29:58 +00:00
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowStates` WHERE `id` = " . ( int ) $id ;
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-18 15:50:32 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return null ;
2013-01-24 08:29:58 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$state = new SeedDMS_Core_Workflow_State ( $resArr [ " id " ], $resArr [ " name " ], $resArr [ " maxtime " ], $resArr [ " precondfunc " ], $resArr [ " documentstatus " ]);
2013-01-24 08:29:58 +00:00
$state -> setDMS ( $this );
return $state ;
} /* }}} */
/**
* Return workflow state by its name
*
2013-01-24 16:43:39 +00:00
* @ param string $name name of workflow state
2017-10-24 11:36:07 +00:00
* @ return bool | SeedDMS_Core_Workflow_State or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflowStateByName ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
2013-02-11 07:46:02 +00:00
if ( ! $name ) return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowStates` WHERE `name`= " . $this -> db -> qstr ( $name );
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( ! $resArr )
2021-09-18 15:50:32 +00:00
return null ;
2013-01-24 08:29:58 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$state = new SeedDMS_Core_Workflow_State ( $resArr [ " id " ], $resArr [ " name " ], $resArr [ " maxtime " ], $resArr [ " precondfunc " ], $resArr [ " documentstatus " ]);
2013-01-24 08:29:58 +00:00
$state -> setDMS ( $this );
return $state ;
} /* }}} */
/**
* Return list of all workflow states
*
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_State [] | bool of instances of { @ link SeedDMS_Core_Workflow_State } or false
2013-01-24 08:29:58 +00:00
*/
function getAllWorkflowStates () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowStates` ORDER BY `name` " ;
2013-01-24 08:29:58 +00:00
$ressArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $ressArr ) && $ressArr == false )
return false ;
$wkfstates = array ();
for ( $i = 0 ; $i < count ( $ressArr ); $i ++ ) {
2013-02-14 11:10:53 +00:00
$wkfstate = new SeedDMS_Core_Workflow_State ( $ressArr [ $i ][ " id " ], $ressArr [ $i ][ " name " ], $ressArr [ $i ][ " maxtime " ], $ressArr [ $i ][ " precondfunc " ], $ressArr [ $i ][ " documentstatus " ]);
2013-01-24 08:29:58 +00:00
$wkfstate -> setDMS ( $this );
$wkfstates [ $i ] = $wkfstate ;
}
return $wkfstates ;
} /* }}} */
2013-01-24 16:43:39 +00:00
/**
* Add new workflow state
*
* @ param string $name name of workflow state
* @ param integer $docstatus document status when this state is reached
2017-10-24 11:36:07 +00:00
* @ return bool | SeedDMS_Core_Workflow_State
2013-01-24 16:43:39 +00:00
*/
2013-01-24 08:29:58 +00:00
function addWorkflowState ( $name , $docstatus ) { /* {{{ */
$db = $this -> db ;
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
return false ;
2013-01-24 08:29:58 +00:00
if ( is_object ( $this -> getWorkflowStateByName ( $name ))) {
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblWorkflowStates` (`name`, `documentstatus`) VALUES ( " . $db -> qstr ( $name ) . " , " . ( int ) $docstatus . " ) " ;
2013-01-24 08:29:58 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
2017-02-11 14:19:36 +00:00
return $this -> getWorkflowState ( $db -> getInsertID ( 'tblWorkflowStates' ));
2013-01-24 08:29:58 +00:00
} /* }}} */
/**
* Return a workflow action by its id
*
* This function retrieves a workflow action from the database by its id .
*
2013-01-24 16:43:39 +00:00
* @ param integer $id internal id of workflow action
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_Action | bool instance of { @ link SeedDMS_Core_Workflow_Action } or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflowAction ( $id ) { /* {{{ */
2021-09-27 08:08:20 +00:00
if ( ! is_numeric ( $id ) || $id < 1 )
2013-01-24 08:29:58 +00:00
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowActions` WHERE `id` = " . ( int ) $id ;
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-18 15:50:32 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return null ;
2013-01-24 08:29:58 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$action = new SeedDMS_Core_Workflow_Action ( $resArr [ " id " ], $resArr [ " name " ]);
2013-01-24 08:29:58 +00:00
$action -> setDMS ( $this );
return $action ;
} /* }}} */
2013-01-24 16:43:39 +00:00
/**
* Return a workflow action by its name
*
* This function retrieves a workflow action from the database by its name .
*
* @ param string $name name of workflow action
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_Action | bool instance of { @ link SeedDMS_Core_Workflow_Action } or false
2013-01-24 16:43:39 +00:00
*/
function getWorkflowActionByName ( $name ) { /* {{{ */
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
2013-02-11 07:46:02 +00:00
if ( ! $name ) return false ;
2013-01-24 16:43:39 +00:00
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowActions` WHERE `name` = " . $this -> db -> qstr ( $name );
2013-01-24 16:43:39 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-18 15:50:32 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
if ( count ( $resArr ) != 1 )
return null ;
2013-01-24 16:43:39 +00:00
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$action = new SeedDMS_Core_Workflow_Action ( $resArr [ " id " ], $resArr [ " name " ]);
2013-01-24 16:43:39 +00:00
$action -> setDMS ( $this );
return $action ;
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Return list of workflow action
*
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_Action [] | bool list of instances of { @ link SeedDMS_Core_Workflow_Action } or false
2013-01-24 08:29:58 +00:00
*/
function getAllWorkflowActions () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowActions` " ;
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false )
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Workflow_Action[] $wkfactions */
2013-01-24 08:29:58 +00:00
$wkfactions = array ();
for ( $i = 0 ; $i < count ( $resArr ); $i ++ ) {
2013-02-14 11:10:53 +00:00
$action = new SeedDMS_Core_Workflow_Action ( $resArr [ $i ][ " id " ], $resArr [ $i ][ " name " ]);
2013-01-24 08:29:58 +00:00
$action -> setDMS ( $this );
$wkfactions [ $i ] = $action ;
}
return $wkfactions ;
} /* }}} */
2013-01-24 16:43:39 +00:00
/**
* Add new workflow action
*
* @ param string $name name of workflow action
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_Action | bool
2013-01-24 16:43:39 +00:00
*/
function addWorkflowAction ( $name ) { /* {{{ */
$db = $this -> db ;
2021-09-18 15:50:32 +00:00
$name = trim ( $name );
if ( ! $name )
return false ;
2013-01-24 16:43:39 +00:00
if ( is_object ( $this -> getWorkflowActionByName ( $name ))) {
return false ;
}
2017-02-10 07:04:19 +00:00
$queryStr = " INSERT INTO `tblWorkflowActions` (`name`) VALUES ( " . $db -> qstr ( $name ) . " ) " ;
2013-01-24 16:43:39 +00:00
$res = $db -> getResult ( $queryStr );
if ( ! $res )
return false ;
2017-02-11 14:19:36 +00:00
return $this -> getWorkflowAction ( $db -> getInsertID ( 'tblWorkflowActions' ));
2013-01-24 16:43:39 +00:00
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Return a workflow transition by its id
*
* This function retrieves a workflow transition from the database by its id .
*
* @ param integer $id internal id of workflow transition
2017-10-24 11:36:07 +00:00
* @ return SeedDMS_Core_Workflow_Transition | bool instance of { @ link SeedDMS_Core_Workflow_Transition } or false
2013-01-24 08:29:58 +00:00
*/
function getWorkflowTransition ( $id ) { /* {{{ */
if ( ! is_numeric ( $id ))
return false ;
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblWorkflowTransitions` WHERE `id` = " . ( int ) $id ;
2013-01-24 08:29:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( is_bool ( $resArr ) && $resArr == false ) return false ;
if ( count ( $resArr ) != 1 ) return false ;
$resArr = $resArr [ 0 ];
2013-02-14 11:10:53 +00:00
$transition = new SeedDMS_Core_Workflow_Transition ( $resArr [ " id " ], $this -> getWorkflow ( $resArr [ " workflow " ]), $this -> getWorkflowState ( $resArr [ " state " ]), $this -> getWorkflowAction ( $resArr [ " action " ]), $this -> getWorkflowState ( $resArr [ " nextstate " ]), $resArr [ " maxtime " ]);
2013-01-24 08:29:58 +00:00
$transition -> setDMS ( $this );
return $transition ;
} /* }}} */
2017-01-25 08:52:48 +00:00
/**
* Return all documents waiting for or in reception
*
* This function retrieves all documents and its version which are waiting for
* reception
*
* @ return object instance of { @ link SeedDMS_Core_DocumentContent } or false
*/
function getDocumentsInReception () { /* {{{ */
if ( ! $this -> db -> createTemporaryTable ( " ttreceiptid " ) || ! $this -> db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
$queryStr =
" SELECT `tblDocumentRecipients`.* FROM `tblDocumentRecipients` LEFT JOIN `ttreceiptid` ON `tblDocumentRecipients`.`receiptID` = `ttreceiptid`.`receiptID` LEFT JOIN `tblDocumentReceiptLog` ON `ttreceiptid`.`maxLogID` = `tblDocumentReceiptLog`.`receiptLogID` LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion`=`tblDocumentRecipients`.`version` AND `ttcontentid`.`document`=`tblDocumentRecipients`.`documentID` WHERE `tblDocumentReceiptLog`.`status`=0 AND `ttcontentid`.`maxVersion` IS NOT NULL " ;
$resArr = $this -> db -> getResultArray ( $queryStr );
return $resArr ;
} /* }}} */
/**
* Return all documents waiting for or in revision
*
* This function retrieves all documents and its version which are waiting for
* revision or already in revision
*
* @ return object instance of { @ link SeedDMS_Core_DocumentContent } or false
*/
function getDocumentsInRevision () { /* {{{ */
if ( ! $this -> db -> createTemporaryTable ( " ttrevisionid " ) || ! $this -> db -> createTemporaryTable ( " ttcontentid " )) {
return false ;
}
$queryStr =
" SELECT `tblDocumentRevisors`.* FROM `tblDocumentRevisors` LEFT JOIN `ttrevisionid` ON `tblDocumentRevisors`.`revisionID` = `ttrevisionid`.`revisionID` LEFT JOIN `tblDocumentRevisionLog` ON `ttrevisionid`.`maxLogID` = `tblDocumentRevisionLog`.`revisionLogID` LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion`=`tblDocumentRevisors`.`version` AND `ttcontentid`.`document`=`tblDocumentRevisors`.`documentID` WHERE `tblDocumentRevisionLog`.`status` in (0, -3) AND `ttcontentid`.`maxVersion` IS NOT NULL " ;
$resArr = $this -> db -> getResultArray ( $queryStr );
return $resArr ;
} /* }}} */
2012-10-22 10:50:49 +00:00
/**
* Returns document content which is not linked to a document
*
* This method is for finding straying document content without
* a parent document . In normal operation this should not happen
* but little checks for database consistency and possible errors
* in the application may have left over document content though
* the document is gone already .
2018-02-08 08:25:45 +00:00
*
* @ return array | bool
2012-10-22 10:50:49 +00:00
*/
function getUnlinkedDocumentContent () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblDocumentContent` WHERE `document` NOT IN (SELECT id FROM `tblDocuments`) " ;
2012-10-22 10:50:49 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2017-01-24 13:21:55 +00:00
if ( $resArr === false )
2012-10-22 10:50:49 +00:00
return false ;
$versions = array ();
foreach ( $resArr as $row ) {
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document $document */
2015-02-05 06:37:50 +00:00
$document = new $this -> classnames [ 'document' ]( $row [ 'document' ], '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' );
2012-10-22 10:50:49 +00:00
$document -> setDMS ( $this );
2015-02-05 06:37:50 +00:00
$version = new $this -> classnames [ 'documentcontent' ]( $row [ 'id' ], $document , $row [ 'version' ], $row [ 'comment' ], $row [ 'date' ], $row [ 'createdBy' ], $row [ 'dir' ], $row [ 'orgFileName' ], $row [ 'fileType' ], $row [ 'mimeType' ], $row [ 'fileSize' ], $row [ 'checksum' ]);
2012-10-22 10:50:49 +00:00
$versions [] = $version ;
}
return $versions ;
2016-08-12 10:40:23 +00:00
2012-10-22 10:50:49 +00:00
} /* }}} */
2012-12-19 10:24:12 +00:00
/**
* Returns document content which has no file size set
*
* This method is for finding document content without a file size
2013-02-08 14:57:05 +00:00
* set in the database . The file size of a document content was introduced
2013-02-14 11:10:53 +00:00
* in version 4.0 . 0 of SeedDMS for implementation of user quotas .
2018-02-08 08:25:45 +00:00
*
* @ return SeedDMS_Core_Document [] | bool
2012-12-19 10:24:12 +00:00
*/
function getNoFileSizeDocumentContent () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblDocumentContent` WHERE `fileSize` = 0 OR `fileSize` is null " ;
2012-12-19 10:24:12 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2017-01-24 13:21:55 +00:00
if ( $resArr === false )
2012-12-19 10:24:12 +00:00
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document[] $versions */
2012-12-19 10:24:12 +00:00
$versions = array ();
foreach ( $resArr as $row ) {
2020-12-18 06:51:13 +00:00
$document = $this -> getDocument ( $row [ 'document' ]);
/* getting the document can fail if it is outside the root folder
* and checkWithinRootDir is enabled .
*/
if ( $document ) {
$version = new $this -> classnames [ 'documentcontent' ]( $row [ 'id' ], $document , $row [ 'version' ], $row [ 'comment' ], $row [ 'date' ], $row [ 'createdBy' ], $row [ 'dir' ], $row [ 'orgFileName' ], $row [ 'fileType' ], $row [ 'mimeType' ], $row [ 'fileSize' ], $row [ 'checksum' ], $row [ 'fileSize' ], $row [ 'checksum' ]);
$versions [] = $version ;
}
2013-02-08 14:57:05 +00:00
}
return $versions ;
2016-08-12 10:40:23 +00:00
2013-02-08 14:57:05 +00:00
} /* }}} */
/**
* Returns document content which has no checksum set
*
* This method is for finding document content without a checksum
* set in the database . The checksum of a document content was introduced
2013-02-14 11:10:53 +00:00
* in version 4.0 . 0 of SeedDMS for finding duplicates .
2018-02-08 08:25:45 +00:00
* @ return bool | SeedDMS_Core_Document []
2013-02-08 14:57:05 +00:00
*/
function getNoChecksumDocumentContent () { /* {{{ */
2017-02-10 07:04:19 +00:00
$queryStr = " SELECT * FROM `tblDocumentContent` WHERE `checksum` = '' OR `checksum` is null " ;
2013-02-08 14:57:05 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2017-01-24 13:21:55 +00:00
if ( $resArr === false )
2013-02-08 14:57:05 +00:00
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document[] $versions */
2013-02-08 14:57:05 +00:00
$versions = array ();
foreach ( $resArr as $row ) {
2020-12-18 06:51:13 +00:00
$document = $this -> getDocument ( $row [ 'document' ]);
/* getting the document can fail if it is outside the root folder
* and checkWithinRootDir is enabled .
*/
if ( $document ) {
$version = new $this -> classnames [ 'documentcontent' ]( $row [ 'id' ], $document , $row [ 'version' ], $row [ 'comment' ], $row [ 'date' ], $row [ 'createdBy' ], $row [ 'dir' ], $row [ 'orgFileName' ], $row [ 'fileType' ], $row [ 'mimeType' ], $row [ 'fileSize' ], $row [ 'checksum' ]);
$versions [] = $version ;
}
2012-12-19 10:24:12 +00:00
}
return $versions ;
2016-08-12 10:40:23 +00:00
2012-12-19 10:24:12 +00:00
} /* }}} */
2013-01-24 08:29:58 +00:00
2020-02-13 11:19:16 +00:00
/**
* Returns document content which has the incorrect file type
*
* This method is for finding document content with an incorrect
* or missing file type . It just checks documents contents
* with a certain mime type .
* @ return bool | SeedDMS_Core_Document []
*/
function getWrongFiletypeDocumentContent () { /* {{{ */
$queryStr = " SELECT * FROM `tblDocumentContent` WHERE `mimeType` in ('application/pdf', 'image/png', 'image/gif', 'image/jpg') " ;
$resArr = $this -> db -> getResultArray ( $queryStr );
if ( $resArr === false )
return false ;
/** @var SeedDMS_Core_Document[] $versions */
$versions = array ();
foreach ( $resArr as $row ) {
$expect = '' ;
switch ( $row [ 'mimeType' ]) {
case " application/pdf " :
case " image/png " :
case " image/gif " :
case " image/jpg " :
$expect = substr ( $row [ 'mimeType' ], - 3 , 3 );
break ;
}
if ( $expect ) {
if ( $row [ 'fileType' ] != '.' . $expect ) {
/** @var SeedDMS_Core_Document $document */
$document = new $this -> classnames [ 'document' ]( $row [ 'document' ], '' , '' , '' , '' , '' , '' , '' , '' , '' , '' , '' );
$document -> setDMS ( $this );
$version = new $this -> classnames [ 'documentcontent' ]( $row [ 'id' ], $document , $row [ 'version' ], $row [ 'comment' ], $row [ 'date' ], $row [ 'createdBy' ], $row [ 'dir' ], $row [ 'orgFileName' ], $row [ 'fileType' ], $row [ 'mimeType' ], $row [ 'fileSize' ], $row [ 'checksum' ]);
$versions [] = $version ;
}
}
}
return $versions ;
} /* }}} */
2015-05-13 15:37:53 +00:00
/**
* Returns document content which is duplicated
*
* This method is for finding document content which is available twice
* in the database . The checksum of a document content was introduced
* in version 4.0 . 0 of SeedDMS for finding duplicates .
2018-02-08 08:25:45 +00:00
* @ return array | bool
2015-05-13 15:37:53 +00:00
*/
function getDuplicateDocumentContent () { /* {{{ */
2021-09-27 08:06:07 +00:00
$queryStr = " SELECT a.*, b.`id` as dupid FROM `tblDocumentContent` a LEFT JOIN `tblDocumentContent` b ON a.`checksum`=b.`checksum` WHERE a.`id`!=b.`id` ORDER by a.`id` LIMIT 1000 " ;
2015-05-13 15:37:53 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-20 14:31:42 +00:00
if ( $resArr === false )
2015-05-13 15:37:53 +00:00
return false ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document[] $versions */
2015-05-13 15:37:53 +00:00
$versions = array ();
foreach ( $resArr as $row ) {
2017-03-08 10:08:35 +00:00
$document = $this -> getDocument ( $row [ 'document' ]);
2020-12-18 06:51:13 +00:00
/* getting the document can fail if it is outside the root folder
* and checkWithinRootDir is enabled .
*/
if ( $document ) {
$version = new $this -> classnames [ 'documentcontent' ]( $row [ 'id' ], $document , $row [ 'version' ], $row [ 'comment' ], $row [ 'date' ], $row [ 'createdBy' ], $row [ 'dir' ], $row [ 'orgFileName' ], $row [ 'fileType' ], $row [ 'mimeType' ], $row [ 'fileSize' ], $row [ 'checksum' ]);
if ( ! isset ( $versions [ $row [ 'dupid' ]])) {
$versions [ $row [ 'id' ]][ 'content' ] = $version ;
$versions [ $row [ 'id' ]][ 'duplicates' ] = array ();
} else
$versions [ $row [ 'dupid' ]][ 'duplicates' ][] = $version ;
}
2015-05-13 15:37:53 +00:00
}
return $versions ;
2016-08-12 10:40:23 +00:00
2015-05-13 15:37:53 +00:00
} /* }}} */
2017-08-02 15:30:54 +00:00
/**
2017-08-22 16:00:06 +00:00
* Returns a list of reviews , approvals , receipts , revisions which are not
* linked to a user , group anymore
2017-08-02 15:30:54 +00:00
*
* This method is for finding reviews or approvals whose user
* or group was deleted and not just removed from the process .
2018-02-08 08:25:45 +00:00
*
* @ param string $process
* @ param string $usergroup
* @ return array
2017-08-02 15:30:54 +00:00
*/
function getProcessWithoutUserGroup ( $process , $usergroup ) { /* {{{ */
switch ( $process ) {
case 'review' :
2017-08-02 15:40:27 +00:00
$queryStr = " SELECT a.*, b.`name` FROM `tblDocumentReviewers` " ;
2017-08-02 15:30:54 +00:00
break ;
case 'approval' :
2017-08-02 15:40:27 +00:00
$queryStr = " SELECT a.*, b.`name` FROM `tblDocumentApprovers` " ;
2017-08-02 15:30:54 +00:00
break ;
2017-08-03 05:11:25 +00:00
case 'receipt' :
$queryStr = " SELECT a.*, b.`name` FROM `tblDocumentRecipients` " ;
break ;
case 'revision' :
$queryStr = " SELECT a.*, b.`name` FROM `tblDocumentRevisors` " ;
break ;
2017-08-02 15:30:54 +00:00
}
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2021-09-16 14:05:04 +00:00
$queryStr .= " a LEFT JOIN `tblDocuments` b ON a.`documentID`=b.`id` WHERE " ;
2017-08-02 15:30:54 +00:00
switch ( $usergroup ) {
case 'user' :
2021-09-16 14:05:04 +00:00
$queryStr .= " a.`type`=0 and a.`required` not in (SELECT `id` FROM `tblUsers`) ORDER by b.`id` " ;
2017-08-02 15:30:54 +00:00
break ;
case 'group' :
2021-09-16 14:05:04 +00:00
$queryStr .= " a.`type`=1 and a.`required` not in (SELECT `id` FROM `tblGroups`) ORDER by b.`id` " ;
2017-08-02 15:30:54 +00:00
break ;
}
return $this -> db -> getResultArray ( $queryStr );
} /* }}} */
2017-08-03 19:41:03 +00:00
/**
2017-08-22 16:00:06 +00:00
* Removes all reviews , approvals , receipts , revisions which are not linked
2017-08-03 19:41:03 +00:00
* to a user , group anymore
*
* This method is for removing all reviews or approvals whose user
* or group was deleted and not just removed from the process .
* If the optional parameter $id is set , only this user / group id is removed .
2018-02-08 08:25:45 +00:00
* @ param string $process
* @ param string $usergroup
* @ param int $id
* @ return array
2017-08-03 19:41:03 +00:00
*/
function removeProcessWithoutUserGroup ( $process , $usergroup , $id = 0 ) { /* {{{ */
2017-08-03 19:48:55 +00:00
/* Entries of tblDocumentReviewLog or tblDocumentApproveLog are deleted
* because of CASCADE ON
*/
2017-08-03 19:41:03 +00:00
switch ( $process ) {
case 'review' :
$queryStr = " DELETE FROM tblDocumentReviewers " ;
break ;
case 'approval' :
$queryStr = " DELETE FROM tblDocumentApprovers " ;
break ;
2017-08-22 16:00:06 +00:00
case 'receipt' :
$queryStr = " DELETE FROM tblDocumentRecipients " ;
break ;
case 'revision' :
$queryStr = " DELETE FROM tblDocumentRevisors " ;
break ;
2017-08-03 19:41:03 +00:00
}
2018-02-08 08:25:45 +00:00
/** @noinspection PhpUndefinedVariableInspection */
2017-08-03 19:41:03 +00:00
$queryStr .= " WHERE " ;
switch ( $usergroup ) {
case 'user' :
$queryStr .= " type=0 AND " ;
if ( $id )
$queryStr .= " required= " . (( int ) $id ) . " AND " ;
$queryStr .= " required NOT IN (SELECT id FROM tblUsers) " ;
break ;
case 'group' :
$queryStr .= " type=1 AND " ;
if ( $id )
$queryStr .= " required= " . (( int ) $id ) . " AND " ;
$queryStr .= " required NOT IN (SELECT id FROM tblGroups) " ;
break ;
}
return $this -> db -> getResultArray ( $queryStr );
} /* }}} */
2014-04-01 19:03:22 +00:00
/**
* Returns statitical information
*
* This method returns all kind of statistical information like
* documents or used space per user , recent activity , etc .
*
* @ param string $type type of statistic
2021-09-16 14:05:04 +00:00
* @ return array | bool returns false if the sql statement fails , returns an empty
* array if no documents or folder where found , otherwise returns a non empty
* array with statistical data
2014-04-01 19:03:22 +00:00
*/
function getStatisticalData ( $type = '' ) { /* {{{ */
switch ( $type ) {
case 'docsperuser' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT " . $this -> db -> concat ( array ( 'b.`fullName`' , " ' (' " , 'b.`login`' , " ')' " )) . " AS `key`, count(`owner`) AS total FROM `tblDocuments` a LEFT JOIN `tblUsers` b ON a.`owner`=b.`id` GROUP BY `owner`, b.`fullName` " ;
2021-07-09 12:21:52 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2021-07-09 12:21:52 +00:00
return false ;
return $resArr ;
case 'foldersperuser' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT " . $this -> db -> concat ( array ( 'b.`fullName`' , " ' (' " , 'b.`login`' , " ')' " )) . " AS `key`, count(`owner`) AS total FROM `tblFolders` a LEFT JOIN `tblUsers` b ON a.`owner`=b.`id` GROUP BY `owner`, b.`fullName` " ;
2014-04-01 19:03:22 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-01 19:03:22 +00:00
return false ;
return $resArr ;
case 'docspermimetype' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT b.`mimeType` AS `key`, count(`mimeType`) AS total FROM `tblDocuments` a LEFT JOIN `tblDocumentContent` b ON a.`id`=b.`document` GROUP BY b.`mimeType` " ;
2014-04-01 19:03:22 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-01 19:03:22 +00:00
return false ;
return $resArr ;
case 'docspercategory' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT b.`name` AS `key`, count(a.`categoryID`) AS total FROM `tblDocumentCategory` a LEFT JOIN `tblCategory` b ON a.`categoryID`=b.id GROUP BY a.`categoryID`, b.`name` " ;
2014-04-01 19:03:22 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-01 19:03:22 +00:00
return false ;
2014-04-02 06:21:10 +00:00
return $resArr ;
case 'docsperstatus' :
2017-10-24 11:36:07 +00:00
/** @noinspection PhpUnusedLocalVariableInspection */
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT b.`status` AS `key`, count(b.`status`) AS total FROM (SELECT a.id, max(b.version), max(c.`statusLogID`) AS maxlog FROM `tblDocuments` a LEFT JOIN `tblDocumentStatus` b ON a.id=b.`documentID` LEFT JOIN `tblDocumentStatusLog` c ON b.`statusID`=c.`statusID` GROUP BY a.`id`, b.`version` ORDER BY a.`id`, b.`statusID`) a LEFT JOIN `tblDocumentStatusLog` b ON a.`maxlog`=b.`statusLogID` GROUP BY b.`status` " ;
$queryStr = " SELECT b.`status` AS `key`, count(b.`status`) AS total FROM (SELECT a.`id`, max(c.`statusLogID`) AS maxlog FROM `tblDocuments` a LEFT JOIN `tblDocumentStatus` b ON a.id=b.`documentID` LEFT JOIN `tblDocumentStatusLog` c ON b.`statusID`=c.`statusID` GROUP BY a.`id` ORDER BY a.id) a LEFT JOIN `tblDocumentStatusLog` b ON a.maxlog=b.`statusLogID` GROUP BY b.`status` " ;
2014-04-02 06:21:10 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-02 06:21:10 +00:00
return false ;
2014-04-08 07:15:59 +00:00
return $resArr ;
case 'docspermonth' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT *, count(`key`) AS total FROM (SELECT " . $this -> db -> getDateExtract ( " date " , '%Y-%m' ) . " AS `key` FROM `tblDocuments`) a GROUP BY `key` ORDER BY `key` " ;
2014-04-08 07:15:59 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-08 07:15:59 +00:00
return false ;
return $resArr ;
case 'docsaccumulated' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT *, count(`key`) AS total FROM (SELECT " . $this -> db -> getDateExtract ( " date " ) . " AS `key` FROM `tblDocuments`) a GROUP BY `key` ORDER BY `key` " ;
2014-04-08 07:15:59 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-08 07:15:59 +00:00
return false ;
$sum = 0 ;
foreach ( $resArr as & $res ) {
$sum += $res [ 'total' ];
2014-04-08 13:28:13 +00:00
/* auxially variable $key is need because sqlite returns
* a key '`key`'
*/
2014-04-09 07:25:27 +00:00
$res [ 'key' ] = mktime ( 12 , 0 , 0 , substr ( $res [ 'key' ], 5 , 2 ), substr ( $res [ 'key' ], 8 , 2 ), substr ( $res [ 'key' ], 0 , 4 )) * 1000 ;
2014-04-08 07:15:59 +00:00
$res [ 'total' ] = $sum ;
}
2014-04-01 19:03:22 +00:00
return $resArr ;
case 'sizeperuser' :
2021-09-16 14:05:04 +00:00
$queryStr = " SELECT " . $this -> db -> concat ( array ( 'c.`fullName`' , " ' (' " , 'c.`login`' , " ')' " )) . " AS `key`, sum(`fileSize`) AS total FROM `tblDocuments` a LEFT JOIN `tblDocumentContent` b ON a.id=b.`document` LEFT JOIN `tblUsers` c ON a.`owner`=c.`id` GROUP BY a.`owner`, c.`fullName` " ;
2014-04-01 19:03:22 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2021-09-16 14:05:04 +00:00
if ( is_bool ( $resArr ) && $resArr == false )
2014-04-01 19:03:22 +00:00
return false ;
return $resArr ;
default :
return array ();
}
} /* }}} */
2015-09-21 10:42:58 +00:00
/**
* Returns changes with a period of time
*
* This method returns a list of all changes happened in the database
* within a given period of time . It currently just checks for
* entries in the database tables tblDocumentContent , tblDocumentFiles ,
* and tblDocumentStatusLog
*
2018-02-08 08:25:45 +00:00
* @ param string $startts
* @ param string $endts
* @ return array | bool
* @ internal param string $start start date , defaults to start of current day
* @ internal param string $end end date , defaults to end of start day
2015-09-21 10:42:58 +00:00
*/
function getTimeline ( $startts = '' , $endts = '' ) { /* {{{ */
if ( ! $startts )
$startts = mktime ( 0 , 0 , 0 );
if ( ! $endts )
2017-02-16 14:01:20 +00:00
$endts = $startts + 86400 ;
2017-10-24 11:36:07 +00:00
/** @var SeedDMS_Core_Document[] $timeline */
2015-09-21 10:42:58 +00:00
$timeline = array ();
2021-05-07 09:45:06 +00:00
if ( 0 ) {
2021-05-07 10:23:17 +00:00
$queryStr = " SELECT DISTINCT `document` FROM `tblDocumentContent` WHERE `date` > " . $startts . " AND `date` < " . $endts . " OR `revisiondate` > ' " . date ( 'Y-m-d H:i:s' , $startts ) . " ' AND `revisiondate` < ' " . date ( 'Y-m-d H:i:s' , $endts ) . " ' UNION SELECT DISTINCT `document` FROM `tblDocumentFiles` WHERE `date` > " . $startts . " AND `date` < " . $endts ;
2021-05-07 09:45:06 +00:00
} else {
$startdate = date ( 'Y-m-d H:i:s' , $startts );
$enddate = date ( 'Y-m-d H:i:s' , $endts );
$queryStr = " SELECT DISTINCT `documentID` AS `document` FROM `tblDocumentStatus` LEFT JOIN `tblDocumentStatusLog` ON `tblDocumentStatus`.`statusId`=`tblDocumentStatusLog`.`statusID` WHERE `date` > " . $this -> db -> qstr ( $startdate ) . " AND `date` < " . $this -> db -> qstr ( $enddate ) . " UNION SELECT DISTINCT document FROM `tblDocumentFiles` WHERE `date` > " . $this -> db -> qstr ( $startdate ) . " AND `date` < " . $this -> db -> qstr ( $enddate ) . " UNION SELECT DISTINCT `document` FROM `tblDocumentFiles` WHERE `date` > " . $startts . " AND `date` < " . $endts ;
}
2015-09-21 10:42:58 +00:00
$resArr = $this -> db -> getResultArray ( $queryStr );
2015-11-19 05:43:02 +00:00
if ( $resArr === false )
2015-09-21 10:42:58 +00:00
return false ;
foreach ( $resArr as $rec ) {
$document = $this -> getDocument ( $rec [ 'document' ]);
2015-09-21 14:46:17 +00:00
$timeline = array_merge ( $timeline , $document -> getTimeline ());
2015-09-21 10:42:58 +00:00
}
return $timeline ;
} /* }}} */
2013-01-24 08:29:58 +00:00
/**
* Set a callback function
*
2021-09-17 17:00:06 +00:00
* The function passed in $func must be a callable and $name may not be empty .
*
* Setting a callback with the method will remove all priorly set callbacks .
*
2013-01-24 08:29:58 +00:00
* @ param string $name internal name of callback
* @ param mixed $func function name as expected by { call_user_method }
* @ param mixed $params parameter passed as the first argument to the
* callback
2021-09-17 17:00:06 +00:00
* @ return bool true if adding the callback succeeds otherwise false
2013-01-24 08:29:58 +00:00
*/
function setCallback ( $name , $func , $params = null ) { /* {{{ */
2021-09-17 17:00:06 +00:00
if ( $name && $func && is_callable ( $func )) {
2016-04-26 10:06:41 +00:00
$this -> callbacks [ $name ] = array ( array ( $func , $params ));
2021-09-17 17:00:06 +00:00
return true ;
} else {
return false ;
}
2016-04-26 10:06:41 +00:00
} /* }}} */
/**
* Add a callback function
*
2021-09-17 17:00:06 +00:00
* The function passed in $func must be a callable and $name may not be empty .
*
2016-04-26 10:06:41 +00:00
* @ param string $name internal name of callback
* @ param mixed $func function name as expected by { call_user_method }
* @ param mixed $params parameter passed as the first argument to the
* callback
2021-09-17 17:00:06 +00:00
* @ return bool true if adding the callback succeeds otherwise false
2016-04-26 10:06:41 +00:00
*/
function addCallback ( $name , $func , $params = null ) { /* {{{ */
2021-09-17 17:00:06 +00:00
if ( $name && $func && is_callable ( $func )) {
2016-04-26 10:06:41 +00:00
$this -> callbacks [ $name ][] = array ( $func , $params );
2021-09-17 17:00:06 +00:00
return true ;
} else {
return false ;
}
2013-01-24 08:29:58 +00:00
} /* }}} */
2015-12-09 17:24:31 +00:00
/**
2021-09-17 17:00:06 +00:00
* Check if a callback with the given has been set
2015-12-09 17:24:31 +00:00
*
2021-09-17 17:00:06 +00:00
* @ param string $name internal name of callback
* @ return bool true a callback exists otherwise false
2015-12-09 17:24:31 +00:00
*/
2021-09-17 17:00:06 +00:00
function hasCallback ( $name ) { /* {{{ */
if ( $name && ! empty ( $this -> callbacks [ $name ]))
return true ;
return false ;
2015-12-09 17:24:31 +00:00
} /* }}} */
2010-11-12 22:40:12 +00:00
}