* Copyright 2000, Quentin Cregan/Sourceforge
* Copyright 2002-2003, Tim Perdue/GForge, LLC
* Copyright 2009, Roland Mas
- * Copyright 2010, Franck Villaume - Capgemini
+ * Copyright 2010-2011, Franck Villaume - Capgemini
+ * Copyright 2011-2012, Franck Villaume - TrivialDev
+ * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2012, Franck Villaume - TrivialDev
* http://fusionforge.org
*
* This file is part of FusionForge. FusionForge is free software;
require_once $gfcommon.'include/Error.class.php';
require_once $gfcommon.'docman/Parsedata.class.php';
+require_once $gfcommon.'docman/DocumentManager.class.php';
+require_once $gfcommon.'docman/DocumentGroup.class.php';
+
class Document extends Error {
*/
var $Group;
- /**
- * The Search engine path.
- *
- * @var string $engine_path
- */
- var $engine_path;
-
/**
* Constructor.
*
* @param array The associative array of data.
* @return boolean success.
*/
- function Document(&$Group, $docid = false, $arr = false, $engine = '') {
+ function Document(&$Group, $docid = false, $arr = false) {
$this->Error();
if (!$Group || !is_object($Group)) {
- $this->setNotValidGroupObjectError();
+ $this->setError('Document:: '. _('No Valid Group Object'));
return false;
}
if ($Group->isError()) {
if (!$this->isPublic()) {
$perm =& $this->Group->getPermission();
- if (!$perm || !is_object($perm) || !$perm->isMember()) {
+ if (!$perm || !is_object($perm) || !$perm->isDocEditor()) {
$this->setPermissionDeniedError();
$this->data_array = null;
return false;
}
}
}
- $this->engine_path = $engine;
return true;
}
* @param int The doc_group id of the doc_groups table.
* @param string The title of this document.
* @param string The description of this document.
+ * @param int The state id of the document. At creation, can not be deleted status.
* @return boolean success.
*/
- function create($filename, $filetype, $data, $doc_group, $title, $description) {
+ function create($filename, $filetype, $data, $doc_group, $title, $description, $stateid = 0) {
if (strlen($title) < 5) {
$this->setError(_('Title Must Be At Least 5 Characters'));
return false;
return false;
}
- $result = db_query_params('SELECT filename, doc_group from docdata_vw where filename = $1 and doc_group = $2',
- array($filename, $doc_group));
+ $user_id = ((session_loggedin()) ? user_getid() : 100);
+
+ $doc_initstatus = '3';
+ $perm =& $this->Group->getPermission();
+ if ($perm && is_object($perm) && $perm->isDocEditor()) {
+ if ($stateid && $stateid != 2) {
+ $doc_initstatus = $stateid;
+ } else {
+ $doc_initstatus = '1';
+ }
+ }
+
+ $result = db_query_params('SELECT filename, doc_group from docdata_vw
+ where filename = $1
+ and doc_group = $2
+ and stateid = $3',
+ array($filename, $doc_group, $doc_initstatus));
if (!$result || db_numrows($result) > 0) {
$this->setError(_('Document already published in this directory'));
return false;
}
- $user_id = ((session_loggedin()) ? user_getid() : 100);
-
- $doc_initstatus = '3';
- // If Editor - uploaded Documents are ACTIVE
- if (session_loggedin()) {
- $perm =& $this->Group->getPermission ();
- if ($perm && is_object($perm) && $perm->isDocEditor()) {
- $doc_initstatus = '1';
- }
+ $result = db_query_params('SELECT title FROM docdata_vw where title = $1 AND doc_group = $2',
+ array($title, $doc_group));
+ if (!$result || db_numrows($result) > 0) {
+ $this->setError(_('Document already published in this directory'));
+ return false;
}
// If $filetype is "text/plain", $body convert UTF-8 encoding.
// key words for in-document search
if ($this->Group->useDocmanSearch()) {
- $kw = new Parsedata($this->engine_path);
+ $kw = new Parsedata();
$kwords = $kw->get_parse_data($data1, htmlspecialchars($title), htmlspecialchars($description), $filetype);
} else {
$kwords ='';
db_rollback();
return false;
}
+
+ $localDg = new DocumentGroup($this->Group, $doc_group);
+ if (!$localDg->update($localDg->getName(), $localDg->getParentID(), 1)) {
+ $this->setError(_('Error updating document group:').$localDg->getErrorMessage());
+ db_rollback();
+ return false;
+ }
$this->sendNotice(true);
db_commit();
return true;
$res = db_query_params('SELECT * FROM docdata_vw WHERE docid=$1 AND group_id=$2',
array($docid, $this->Group->getID()));
if (!$res || db_numrows($res) < 1) {
- $this->setError(_('Document:: Invalid docid'));
+ $this->setError(_('Document: Invalid docid'));
return false;
}
$this->data_array = db_fetch_array($res);
//
// Because this could be a large string, we only fetch if we actually need it
//
- $res = db_query_params('SELECT data FROM doc_data WHERE docid=$1',array($this->getID()));
- return base64_decode(db_result($res,0,'data'));
+ $res = db_query_params('SELECT data FROM doc_data WHERE docid=$1', array($this->getID()));
+ return base64_decode(db_result($res, 0, 'data'));
}
/**
*/
function removeMonitoredBy($userid) {
$result = db_query_params('DELETE FROM docdata_monitored_docman WHERE doc_id=$1 AND user_id=$2',
- array ($this->getID(), $userid));
+ array($this->getID(), $userid));
if (!$result) {
$this->setError(_('Unable To Remove Monitor').' : '.db_error());
return true;
}
+ /**
+ * clearMonitor - remove all entries of monitoring for this document.
+ *
+ * @return boolean true if success.
+ */
+ function clearMonitor() {
+ $result = db_query_params('DELETE FROM docdata_monitored_docman WHERE doc_id = $1',
+ array($this->getID()));
+ return true;
+ }
+
/**
* setState - set the stateid of the document.
*
* @param int The state id of the doc_states table.
- * @return boolean success.
+ * @return boolean success or not.
*/
function setState($stateid) {
- $res = db_query_params('UPDATE doc_data SET
- stateid=$1
- WHERE group_id=$2
- AND docid=$3',
- array($stateid,
- $this->Group->getID(),
- $this->getID())
- );
- if (!$res || db_affected_rows($res) < 1) {
- $this->setOnUpdateError(db_error());
- return false;
- }
- $this->sendNotice(false);
- return true;
+ return $this->__setValueinDB('stateid', $stateid);
}
+
/**
- * setLock - set the locking status of the document
+ * setDocGroupID - set the doc_group of the document.
*
- * @param int The status of the lock
- * @param int The userid who set the lock
- * @param time the epoch time
- * @return boolean success
+ * @param int The group_id of this document.
+ * @return boolean success or not.
+ */
+ function setDocGroupID($newdocgroupid) {
+ return $this->__setValueinDB('doc_group', $newdocgroupid);
+ }
+
+ /**
+ * setLock - set the locking status of the document.
+ *
+ * @param int The status of the lock.
+ * @param int The userid who set the lock.
+ * @param time the epoch time.
+ * @return boolean success or not.
*/
function setLock($stateLock, $userid = NULL, $thistime = 0) {
$res = db_query_params('UPDATE doc_data SET
- locked=$1,
- locked_by=$2,
- lockdate=$3
- WHERE group_id=$4
- AND docid=$5',
+ locked = $1,
+ locked_by = $2,
+ lockdate = $3
+ WHERE group_id = $4
+ AND docid = $5',
array($stateLock,
$userid,
$thistime,
*/
function setReservedBy($statusReserved, $idReserver = NULL) {
$res = db_query_params('UPDATE doc_data SET
- reserved=$1,
- reserved_by=$2
- WHERE group_id=$3
- AND docid=$4',
+ reserved = $1,
+ reserved_by = $2
+ WHERE group_id = $3
+ AND docid = $4',
array($statusReserved,
$idReserver,
$this->Group->getID(),
return true;
}
+ /**
+ * getFileTypeImage - return the file image for icon
+ *
+ * @return string the file image name
+ * @access public
+ */
+ function getFileTypeImage() {
+ switch ($this->getFileType()) {
+ case "image/png":
+ case "image/jpeg":
+ case "image/gif":
+ case "image/tiff":
+ case "image/vnd.microsoft.icon":
+ case "image/svg+xml": {
+ $image = 'docman/file_type_image.png';
+ break;
+ }
+ case "audio/x-wav":
+ case "audio/x-vorbis+ogg":
+ case "audio/mpeg": {
+ $image = "docman/file_type_sound.png";
+ break;
+ }
+ case "application/pdf": {
+ $image = 'docman/file_type_pdf.png';
+ break;
+ }
+ case "text/html":
+ case "URL": {
+ $image = 'docman/file_type_html.png';
+ break;
+ }
+ case "text/plain":
+ case "text/x-php":
+ case "application/xml":
+ case "text/x-c": {
+ $image = 'docman/file_type_plain.png';
+ break;
+ }
+ case "application/msword":
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ case "application/vnd.oasis.opendocument.text": {
+ $image = 'docman/file_type_writer.png';
+ break;
+ }
+ case "application/vnd.ms-excel":
+ case "application/vnd.oasis.opendocument.spreadsheet":
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
+ $image = 'docman/file_type_spreadsheet.png';
+ break;
+ }
+ case "application/vnd.oasis.opendocument.presentation":
+ case "application/vnd.ms-powerpoint":
+ case "application/vnd.ms-office":
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation": {
+ $image = 'docman/file_type_presentation.png';
+ break;
+ }
+ case "application/zip":
+ case "application/x-tar":
+ case "application/x-rpm":
+ case "application/x-rar-compressed":
+ case "application/x-bzip2":
+ case "application/x-gzip":
+ case "application/x-lzip":
+ case "application/x-compress":
+ case "application/x-7z-compressed":
+ case "application/x-gtar":
+ case "application/x-stuffitx":
+ case "application/x-lzx":
+ case "application/x-lzh":
+ case "application/x-gca-compressed":
+ case "application/x-apple-diskimage":
+ case "application/x-dgc-compressed":
+ case "application/x-dar":
+ case "application/x-cfs-compressed":
+ case "application/vnd.ms-cab-compressed":
+ case "application/x-alz-compressed":
+ case "application/x-astrotite-afa":
+ case "application/x-ace-compressed":
+ case "application/x-cpio":
+ case "application/x-shar":
+ case "application/x-xz": {
+ $image = 'docman/file_type_archive.png';
+ break;
+ }
+ default: {
+ $image = 'docman/file_type_unknown.png';
+ }
+ }
+ return $image;
+ }
+
/**
* update - use this function to update an existing entry in the database.
*
* @return boolean success.
*/
function update($filename, $filetype, $data, $doc_group, $title, $description, $stateid) {
- global $LUSER;
$perm =& $this->Group->getPermission();
if (!$perm || !is_object($perm) || !$perm->isDocEditor()) {
return false;
}
- if ($this->getLockedBy() != $LUSER->getID()) {
+ $user = session_get_user();
+ if ($this->getLocked() && ($this->getLockedBy() != $user->getID())) {
$this->setPermissionDeniedError();
return false;
}
return false;
}
+ /* TODO : NEED REAL CHECK */
if ($filename) {
$result = db_query_params('SELECT filename, doc_group FROM docdata_vw WHERE filename = $1 AND doc_group = $2 AND stateid = $3 AND docid != $4',
array($filename, $doc_group, $stateid, $this->getID()));
// key words for in-document search
if ($this->Group->useDocmanSearch()) {
- $kw = new Parsedata($this->engine_path);
+ $kw = new Parsedata();
$kwords = $kw->get_parse_data($data1, htmlspecialchars($title), htmlspecialchars($description), $filetype);
} else {
$kwords = '';
}
}
}
-
+ $this->fetchData($this->getID());
$this->sendNotice(false);
return true;
}
*
* @param boolean true = new document (default value)
*/
- function sendNotice ($new=true) {
+ function sendNotice($new = true) {
$BCC = $this->Group->getDocEmailAddress();
if ($this->isMonitoredBy('ALL')) {
$BCC .= $this->getMonitoredUserEmailAddress();
}
if (strlen($BCC) > 0) {
+ $sess = session_get_user();
if ($new) {
$status = _('New document');
} else {
- $status = _('Updated document');
+ $status = _('Updated document').' '._('by').' ' . $sess->getRealName();
+ }
+ $BCCarray = explode(',',$BCC);
+ foreach ($BCCarray as $dest_email) {
+ if ($new) {
+ $status = _('New document');
+ } else {
+ $status = _('Updated document');
+ }
+ $subject = '['.$this->Group->getPublicName().'] '.$status.' - '.$this->getName();
+ $body = _('Project:').' '.$this->Group->getPublicName()."\n";
+ $body .= _('Directory:').' '.$this->getDocGroupName()."\n";
+ $body .= _('Document title:').' '.$this->getName()."\n";
+ $body .= _('Document description:').' '.util_unconvert_htmlspecialchars($this->getDescription())."\n";
+ $body .= _('Submitter:').' '.$this->getCreatorRealName()." (".$this->getCreatorUserName().") \n";
+ $body .= "\n\n-------------------------------------------------------\n".
+ _('For more info, visit:').
+ "\n\n" . util_make_url('/docman/?group_id='.$this->Group->getID().'&view=listfile&dirid='.$this->getDocGroupID());
+
+ util_send_message($dest_email, $subject, $body, 'noreply@'.forge_get_config('web_host'), '', _('Docman'));
}
- $subject = '['.$this->Group->getPublicName().'] '.$status.' - '.$this->getName();
- $body = _('Project:').' '.$this->Group->getPublicName()."\n";
- $body .= _('Directory:').' '.$this->getDocGroupName()."\n";
- $body .= _('Document title:').' '.$this->getName()."\n";
- $body .= _('Document description:').' '.util_unconvert_htmlspecialchars($this->getDescription())."\n";
- $body .= _('Submitter:').' '.$this->getCreatorRealName()." (".$this->getCreatorUserName().") \n";
- $body .= "\n\n-------------------------------------------------------\n".
- _('For more info, visit:').
- "\n\n" . util_make_url('/docman/?group_id='.$this->Group->getID().'&view=listfile&dirid='.$this->getDocGroupID());
-
- util_send_message('', $subject, $body, '', $BCC);
}
return true;
}
}
- // we should be able to send a notice that this doc has been deleted .... but we need to rewrite sendNotice
- //$this->sendNotice(false);
+ /** we should be able to send a notice that this doc has been deleted .... but we need to rewrite sendNotice
+ * $this->sendNotice(false);
+ * @TODO delete monitoring this file */
return true;
}
+
+ /**
+ * trash - move this file to trash
+ *
+ * @return boolean success or not.
+ */
+ function trash() {
+ $this->setState('2');
+ $dm = new DocumentManager($this->Group);
+ $this->setDocGroupID($dm->getTrashID());
+ $this->setLock(0);
+ $this->setReservedBy(0);
+ $this->sendNotice(false);
+ $this->clearMonitor();
+ return true;
+ }
+
+ /**
+ * __setValueinDB - private function to update columns in db
+ *
+ * @param string the column to update
+ * @param int the value to store
+ * @return boolean success or not
+ * @access private
+ */
+ private function __setValueinDB($column, $value) {
+ switch ($column) {
+ case "stateid":
+ case "doc_group": {
+ $qpa = db_construct_qpa();
+ $qpa = db_construct_qpa($qpa, 'UPDATE doc_data SET ');
+ $qpa = db_construct_qpa($qpa, $column);
+ $qpa = db_construct_qpa($qpa, '=$1
+ WHERE group_id=$2
+ AND docid=$3',
+ array($value,
+ $this->Group->getID(),
+ $this->getID()));
+ $res = db_query_qpa($qpa);
+ if (!$res || db_affected_rows($res) < 1) {
+ $this->setOnUpdateError(db_error().print_r($qpa));
+ return false;
+ }
+ break;
+ }
+ default:
+ $this->setOnUpdateError(_('wrong column name'));
+ return false;
+ }
+ $this->sendNotice(false);
+ return true;
+ }
+
+ function createVersion() {
+
+ }
+
+ function deleteVersion() {
+
+ }
}
// Local Variables: