* Copyright 2002-2003, Tim Perdue/GForge, LLC
* Copyright 2009, Roland Mas
* Copyright 2010-2011, Franck Villaume - Capgemini
- * Copyright 2011, Franck Villaume - TrivialDev
+ * 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.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
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;
$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()) {
+ $perm =& $this->Group->getPermission();
+ if ($perm && is_object($perm) && $perm->isDocEditor()) {
+ if ($stateid && $stateid != 2) {
+ $doc_initstatus = $stateid;
+ } else {
$doc_initstatus = '1';
}
}
return false;
}
+ $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.
if (strcasecmp($filetype,"text/plain") === 0 &&
function_exists('mb_convert_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 ='';
}
if (!$this->fetchData($docid)) {
+ $this->setError(_('Error fetching Document'));
+ 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;
}
$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);
}
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;
* @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;
}
/* 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',
- array($filename, $doc_group, $stateid));
+ $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()));
if (!$result || db_numrows($result) > 0) {
$this->setError(_('Document already published in this directory'));
return false;
// 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_uri('/docman/?group_id='.$this->Group->getID().'&view=listfile&dirid='.$this->getDocGroupID());
-
- util_send_message('', $subject, $body, '', $BCC);
}
return true;