[Fusionforge-commits] r10958 - in trunk/src: common/docman/include common/docman/views www/docman

Franck VILLAUME nerville at libremir.placard.fr.eu.org
Tue Oct 12 15:11:54 CEST 2010


Author: nerville
Date: 2010-10-12 15:11:54 +0200 (Tue, 12 Oct 2010)
New Revision: 10958

Modified:
   trunk/src/common/docman/include/utils.php
   trunk/src/common/docman/views/addfile.php
   trunk/src/common/docman/views/admin.php
   trunk/src/common/docman/views/listfile.php
   trunk/src/common/docman/views/tree.php
   trunk/src/www/docman/index.php
   trunk/src/www/docman/view.php
Log:
cleanup + implement extract documents and directories as zip archive

Modified: trunk/src/common/docman/include/utils.php
===================================================================
--- trunk/src/common/docman/include/utils.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/common/docman/include/utils.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -57,6 +57,9 @@
 
 }
 
+/*
+ * docman_recursive_display - Recursive function to show the documents inside the groups tree : javascript enabled function
+ */
 function docman_recursive_display($docgroup) {
 	global $nested_groups,$group_id;
 	global $idExposeTreeIndex,$dirid,$idhtml;
@@ -77,6 +80,32 @@
     }
 }
 
+/*
+ * docman_fill_zip - Recursive function to add docgroup and documents inside zip for backup
+ *
+ * @param	$object		zip
+ * @param	$array		nested groups
+ * @param	$object		documentfactory
+ * @param	$integer	documentgroup id : default value = 0
+ * @param	$string		documentgroup parent name : default value = empty
+ */
+function docman_fill_zip($zip,$nested_groups,$document_factory,$docgroup = 0,$parent_docname = '') {
+	if (is_array(@$nested_groups[$docgroup])) {
+		foreach ($nested_groups[$docgroup] as $dg) {
+			$zip->addEmptyDir($parent_docname.'/'.$dg->getName());
+			$document_factory->setDocGroupID($dg->getID());
+			$docs = $document_factory->getDocuments();
+			if (is_array($docs) && count($docs) > 0) {      // this group has documents
+				foreach ($docs as $doc) {
+					$zip->addFromString($parent_docname.'/'.$dg->getName().'/'.$doc->getFileName(),$doc->getFileData());
+				}
+			}
+			docman_fill_zip($zip,$nested_groups,$document_factory,$dg->getID(),$parent_docname.'/'.$dg->getName());
+		}
+	}
+	return true;
+}
+
 function docman_recursive_stateid($docgroup,$nested_groups,$nested_docs,$stateid=2) {
     if (is_array(@$nested_groups[$docgroup])) {
         foreach ($nested_groups[$docgroup] as $dg) {
@@ -91,7 +120,7 @@
 }
 
 /**
- * docman_display_documents - Recursive function to show the documents inside the groups tree
+ * docman_display_trash - function to show the documents inside the groups tree with specific status : 2 = deleted
  */
 function docman_display_trash(&$document_factory,$parent_group=0) {
 	$nested_groups =& $document_factory->getNested(2);
@@ -104,6 +133,9 @@
 	echo "</ul>";
 }
 
+/*
+ * docman_display_documents - Recursive function to show the documents inside the groups tree
+ */
 function docman_display_documents(&$nested_groups, &$document_factory, $is_editor, $stateid=0, $parent_group=0) {
 	if (!array_key_exists("$parent_group",$nested_groups) || !is_array($nested_groups["$parent_group"])) {
 		return;
@@ -131,7 +163,7 @@
 		}
 
 		// Display this group's documents
-		// Retrieve all the docs from this category			
+		// Retrieve all the docs from this category
 		if ($stateid) {
 			$document_factory->setStateID($stateid);
 		}

Modified: trunk/src/common/docman/views/addfile.php
===================================================================
--- trunk/src/common/docman/views/addfile.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/common/docman/views/addfile.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -31,58 +31,64 @@
 global $dirid; //id of the doc_group
 global $dgh; // document group html object
 
-/* display the add new documentation form */
-echo '<div class="docmanDivIncluded">';
-echo '<p>'. _('<strong>Document Title</strong>:  Refers to the relatively brief title of the document (e.g. How to use the download server)<br /><strong>Description:</strong> A brief description to be placed just under the title<br />') .'</p>';
+if ( $dgf->getNested() == NULL ) {
+	echo '<div class="docmanDivIncluded">';
+	echo '<div class="warning">'. _('You MUST first create at least one directory to store your document.') .'</p></div>';
+} else {
+	/* display the add new documentation form */
+	echo '<div class="docmanDivIncluded">';
+	echo '<p>'. _('<strong>Document Title</strong>:  Refers to the relatively brief title of the document (e.g. How to use the download server)<br /><strong>Description:</strong> A brief description to be placed just under the title<br />') .'</p>';
 
-if ($g->useDocmanSearch()) 
-	echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
+	if ($g->useDocmanSearch()) 
+		echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
 
-echo '<form name="adddata" action="?group_id='.$group_id.'&action=addfile" method="post" enctype="multipart/form-data">
-		<table>
-			<tr>
-				<td style="text-align:right;">
-					<strong>'. _('Document Title').'</strong>'.utils_requiredField()
-                .'</td><td>'
-                    .'&nbsp;<input type="text" name="title" size="40" maxlength="255" />&nbsp;'
-                    .sprintf(_('(at least %1$s characters)'), 5)
-				.'</td>
-			</tr>
-			<tr>
-				<td style="text-align:right;">
-					<strong>'. _('Description') .'</strong>'.utils_requiredField()
-                .'</td><td>'
-                    .'&nbsp;<input type="text" name="description" size="50" maxlength="255" />&nbsp;'
-                    .sprintf(_('(at least %1$s characters)'), 10)
-				.'</td>
-			</tr>';
-echo '
-			<tr>
-				<td style="text-align:right;">
-					<strong>'. _('Upload File') .'</strong>'. utils_requiredField()
-                .'</td><td>'
-					.'&nbsp;<input type="file" name="uploaded_data" size="30" />
-					<input type="hidden" name="type" value="httpupload">
-				</td>
-			</tr>';
-if ($dirid) {
-	echo '<input type="hidden" name="doc_group" value="'.$dirid.'">';
-} else {
+	echo '<form name="adddata" action="?group_id='.$group_id.'&action=addfile" method="post" enctype="multipart/form-data">
+			<table>
+				<tr>
+					<td style="text-align:right;">
+						<strong>'. _('Document Title').'</strong>'.utils_requiredField()
+                	.'</td><td>'
+                    	.'&nbsp;<input type="text" name="title" size="40" maxlength="255" />&nbsp;'
+                    	.sprintf(_('(at least %1$s characters)'), 5)
+					.'</td>
+				</tr>
+				<tr>
+					<td style="text-align:right;">
+						<strong>'. _('Description') .'</strong>'.utils_requiredField()
+                	.'</td><td>'
+                    	.'&nbsp;<input type="text" name="description" size="50" maxlength="255" />&nbsp;'
+                    	.sprintf(_('(at least %1$s characters)'), 10)
+					.'</td>
+				</tr>';
 	echo '
-			<tr>
-				<td>
-					<strong>'. _('Directory that document belongs in').'</strong>
-                </td><td>';
-	$dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $dirid);
-	echo '
-				</td>
-			</tr>';
+				<tr>
+					<td style="text-align:right;">
+						<strong>'. _('Upload File') .'</strong>'. utils_requiredField()
+                	.'</td><td>'
+						.'&nbsp;<input type="file" name="uploaded_data" size="30" />
+						<input type="hidden" name="type" value="httpupload">
+					</td>
+				</tr>';
+	if ($dirid) {
+		echo '<input type="hidden" name="doc_group" value="'.$dirid.'">';
+	} else {
+		echo '
+				<tr>
+					<td>
+						<strong>'. _('Directory that document belongs in').'</strong>
+                	</td><td>';
+		$dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $dirid);
+		echo '
+					</td>
+				</tr>';
+	}
+	echo '  </table>';
+	echo utils_requiredField() . ' '. _('Mandatory field');
+	echo '  <div class="docmanSubmitDiv">
+		    	<input type="submit" name="submit" value="'. _('Submit Information').' " />
+        	</div>
+		</form>';
 }
-echo '  </table>';
-echo utils_requiredField() . ' '. _('Mandatory field');
-echo '  <div class="docmanSubmitDiv">
-		    <input type="submit" name="submit" value="'. _('Submit Information').' " />
-        </div>
-	</form>';
+
 echo '</div>';
 ?>

Modified: trunk/src/common/docman/views/admin.php
===================================================================
--- trunk/src/common/docman/views/admin.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/common/docman/views/admin.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -71,7 +71,7 @@
 	echo '<div id="adminoptions" style="display:none;" >';
 	echo '<form id="backup" name="backup" method="post" action="'. util_make_url ('/docman/view.php/'.$group_id.'/backup') .'" >';
 	echo '<ul>';
-	echo '<li>'. _('Extract documents and directories as an archive') .' <input id="submitbackup" type="button" disabled="yes" value="Yes" onclick="javascript:doIt(\'backup\')"></li>';
+	echo '<li>'. _('Extract documents and directories as an archive') .' <input id="submitbackup" type="button" value="Yes" onclick="javascript:doIt(\'backup\')"></li>';
 	echo '</ul>';
 	echo '</form>';
 	echo '<form id="searchengine" name="searchengine" method="post" action="?group_id='.$group_id.'&action=updateenginesearch" >';

Modified: trunk/src/common/docman/views/listfile.php
===================================================================
--- trunk/src/common/docman/views/listfile.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/common/docman/views/listfile.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -30,6 +30,7 @@
 global $group_id; // id of the group
 global $dirid; // id of doc_group
 global $nested_docs; // flat docs array
+global $nested_groups; // flat document directories array
 global $HTML; // Layout object
 
 $DocGroupName = getNameDocGroup($dirid,$group_id);

Modified: trunk/src/common/docman/views/tree.php
===================================================================
--- trunk/src/common/docman/views/tree.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/common/docman/views/tree.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -29,19 +29,21 @@
 global $d_arr; // documents array
 
 echo '<h3>Document Tree</h3>';
-if (!$d_arr || count($d_arr) < 1) {
-	print '<div class="feedback">'._('This project has no visible documents').'</div>';
-} else {
-	// Get the document groups info
-	$nested_docs=array();
-	$idExposeTreeIndex = 0;
-	$idhtml = 0;
-	//put the doc objects into an array keyed off the docgroup
-	foreach ($d_arr as $doc) {
-		$nested_docs[$doc->getDocGroupID()][] = $doc;
+$nested_docs=array();
+$idExposeTreeIndex = 0;
+$idhtml = 0;
+if ($d_arr != NULL ) {
+	if (!$d_arr || count($d_arr) > 0) {
+		// Get the document groups info
+		//put the doc objects into an array keyed off the docgroup
+		foreach ($d_arr as $doc) {
+			$nested_docs[$doc->getDocGroupID()][] = $doc;
+		}
 	}
-	echo '<div id="documenttree" style="height:100%">';
+}
+echo '<div id="documenttree" style="height:100%">';
 ?>
+
 <script language="JavaScript"><!--
 	var myThemeXPBase = "<?php echo util_make_uri ('/jscook/ThemeXP/'); ?>";
 --></script>
@@ -69,7 +71,7 @@
 	var openItem = ctGetSelectedItem (treeIndex)
 	ctOpenFolder (openItem)
 --></script>
+
 <?php
-	echo '</div>';
-}
+echo '</div>';
 ?>

Modified: trunk/src/www/docman/index.php
===================================================================
--- trunk/src/www/docman/index.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/www/docman/index.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -71,8 +71,6 @@
 	exit_error($dgf->getErrorMessage(),'docman');
 
 $nested_groups = $dgf->getNested();
-if ($dgf->isError())
-    exit_error($dgf->getErrorMessage(),'docman');
 
 $dgh = new DocumentGroupHTML($g);
 if ($dgh->isError())

Modified: trunk/src/www/docman/view.php
===================================================================
--- trunk/src/www/docman/view.php	2010-10-12 12:08:08 UTC (rev 10957)
+++ trunk/src/www/docman/view.php	2010-10-12 13:11:54 UTC (rev 10958)
@@ -28,6 +28,9 @@
 require_once('../env.inc.php');
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'docman/Document.class.php';
+require_once $gfcommon.'docman/DocumentFactory.class.php';
+require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
+require_once $gfcommon.'docman/include/utils.php';
 
 session_require_perm ('project_read', $group_id) ;
 
@@ -76,7 +79,49 @@
 	echo $d->getFileData();
 
 } else if ( $docid == 'backup' ) {
-    exit_error(_('Not implemented yet'),'docman');
+	$g =& group_get_object($group_id);
+	if (!$g || !is_object($g)) {
+		exit_no_group();
+	} elseif ($g->isError()) {
+		exit_error($g->getErrorMessage(),'docman');
+	}
+
+	$df = new DocumentFactory($g);
+	if ($df->isError())
+		    exit_error($df->getErrorMessage(),'docman');
+
+	$dgf = new DocumentGroupFactory($g);
+	if ($dgf->isError())
+		    exit_error($dgf->getErrorMessage(),'docman');
+	$nested_groups = $dgf->getNested();
+
+	$d_arr =& $df->getDocuments();
+	if (!$d_arr || count($d_arr) <1)
+		    $d_arr = &$df->getDocuments();
+
+	if ( $nested_groups != NULL ) {
+		$filename = 'docman-'.$g->getUnixName().'-'.$docid.'.zip';
+		$file = forge_get_config('data_path').'/'.$filename;
+		$zip = new ZipArchive;
+		if ( !$zip->open($file, ZIPARCHIVE::OVERWRITE)) {
+			exit_error(_('Unable to open zip archive for backup'),'docman');
+		}
+
+		docman_fill_zip($zip,$nested_groups,$df);
+
+		if ( !$zip->close()) {
+			exit_error(_('Unable to close zip archive for backup'),'docman');
+		}
+
+		Header ('Content-disposition: filename="'.$filename.'"');
+		Header ('Content-type: application/binary');
+
+		readfile($file);
+		unlink($file);
+	} else {
+		$warning_msg = _('No documents to backup.');
+		session_redirect('/docman/?group_id='.$group_id.'&view=admin&warning_msg='.urlencode($warning_msg));
+	}
 } else {
 	exit_error(_('No document to display - invalid or inactive document number.'),'docman');
 }




More information about the Fusionforge-commits mailing list