* 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. 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 {
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()) {
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') &&
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);
}
}
}
-
+ $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;
function deleteVersion() {
}
-
- function editFile() {
- $editfileaction = '?action=editfile&fromview=listfile&dirid='.$this->getDocGroupID();
- if (isset($GLOBALS['childgroup_id']) && $GLOBALS['childgroup_id']) {
- $editfileaction .= '&childgroup_id='.$GLOBALS['childgroup_id'];
- }
- $editfileaction .= '&group_id='.$GLOBALS['group_id'];
-?>
-<script language="JavaScript" type="text/javascript">/* <![CDATA[ */
- function doItEditData<?php echo $this->getID(); ?>() {
- document.getElementById('editdata<?php echo $this->getID(); ?>').submit();
- document.getElementById('submiteditdata<?php echo $this->getID(); ?>').disabled = true;
- }
-/* ]]> */</script>
-<h3><?php echo _('Document Edit') ?></h3>
-<hr/>
-<p>
-<strong><?php echo _('Document Title:') ?></strong>
-<?php echo _('Refers to the relatively brief title of the document (e.g. How to use the download server).') ?>
-</p>
-<p>
-<strong><?php echo _('Description:') ?></strong>
-<?php echo _('A brief description to be placed just under the title.') ?>
-</p>
-<?php
- if ($this->Group->useDocmanSearch())
- echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
-?>
-
- <form id="editdata<?php echo $this->getID(); ?>" name="editdata<?php echo $this->getID(); ?>" action="<?php echo $editfileaction ?>" method="post" enctype="multipart/form-data">
-
-<table border="0">
- <tr>
- <td>
- <strong><?php echo _('Document Title:') ?> </strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 5) ?><br />
- <input type="text" name="title" size="40" maxlength="255" value="<?php echo $this->getName(); ?>" />
- </td>
- </tr>
-
- <tr>
- <td>
- <strong><?php echo _('Description:') ?> </strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 10) ?><br />
- <input type="text" name="description" size="50" maxlength="255" value="<?php echo $this->getDescription(); ?>" />
- </td>
- </tr>
-
- <tr>
- <td>
- <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?><br />
- <?php if ($this->isURL()) {
- echo '<a href="'.inputSpecialchars($this->getFileName()).'">['. _('View File URL') .']</a>';
- } else { ?>
- <a target="_blank" href="view.php/<?php echo $this->Group->getID().'/'.$this->getID().'/'.urlencode($this->getFileName()) ?>"><?php echo $this->getFileName(); ?></a>
- <?php } ?>
- </td>
- </tr>
-
-<?php
-
- if ((!$this->isURL()) && ($this->isText()) && $this->getStateID() != '2') {
- if ($this->Group->useCreateOnline()) {
- echo '<tr>
- <td>';
- echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
- switch ($this->getFileType()) {
- case "text/html": {
- $GLOBALS['editor_was_set_up']=false;
- $params = array() ;
- /* name must be != data then nothing is displayed */
- $params['name'] = 'details'.$this->getID();
- $params['height'] = "300";
- $params['group'] = $group_id;
- $params['body'] = $this->getFileData();
- plugin_hook("text_editor",$params);
- if (!$GLOBALS['editor_was_set_up']) {
- echo '<textarea name="details'.$this->getID().'" rows="15" cols="70">'. $this->getFileData() .'</textarea><br />';
- }
- unset($GLOBALS['editor_was_set_up']);
- echo '<input type="hidden" name="filetype" value="text/html">';
- break;
- }
- default: {
- echo '<textarea name="details'.$this->getID().'" rows="15" cols="70">'. $this->getFileData() .'</textarea><br />';
- echo '<input type="hidden" name="filetype" value="text/plain">';
- }
- }
- echo ' </td>
- </tr>';
- }
- }
-?>
- <tr>
- <td>
- <strong><?php echo _('Folder that document belongs in') ?></strong><br />
- <?php
- $newdgf = new DocumentGroupFactory($this->Group);
- $newdgh = new DocumentGroupHTML($this->Group);
- if ($this->getStateID() == 2) {
- $newdgh->showSelectNestedGroups($newdgf->getNested(), 'doc_group', false, false);
- } else {
- $newdgh->showSelectNestedGroups($newdgf->getNested(), 'doc_group', false, $this->getDocGroupID());
- }
- ?></td>
- </tr>
- <tr>
- <td>
- <strong><?php echo _('State') ?>:</strong><br />
- <?php
- if ($this->getStateID() == 2) {
- doc_get_state_box('xzxz', $this->getStateID());
- } else {
- doc_get_state_box('xzxz');
- }
- ?>
- </td>
- </tr>
- <tr>
- <td>
- <?php if ($this->getStateID() != '2') {
- if ($this->isURL()) { ?>
- <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?><br />
- <input type="text" name="file_url" size="50" value="<?php echo $this->getFileName() ?>" />
- <?php } else { ?>
- <strong><?php echo _('OPTIONAL: Upload new file') ?></strong><br />
- <input type="file" name="uploaded_data" size="30" />
- <?php
- }
- }
- ?>
- </td>
- </tr>
-</table>
-<input type="hidden" name="docid" value="<?php echo $this->getID(); ?>" />
-<input type="button" id="submiteditdata<?php echo $this->getID(); ?>" value="<?php echo _('Submit Edit') ?>" onclick="javascript:doItEditData<?php echo $this->getID(); ?>()" />
-</form>
-<?php
- }
}
// Local Variables: