[Fusionforge-commits] r11944 - in trunk/src: common/docman common/docman/include common/docman/views www/docman www/themes/funky/images/docman www/themes/gforge/images/docman

Franck VILLAUME nerville at libremir.placard.fr.eu.org
Fri Jan 7 15:34:50 CET 2011


Author: nerville
Date: 2011-01-07 15:34:50 +0100 (Fri, 07 Jan 2011)
New Revision: 11944

Added:
   trunk/src/www/themes/funky/images/docman/download-directory-zip.png
   trunk/src/www/themes/gforge/images/docman/download-directory-zip.png
Modified:
   trunk/src/common/docman/DocumentFactory.class.php
   trunk/src/common/docman/include/utils.php
   trunk/src/common/docman/views/listfile.php
   trunk/src/www/docman/view.php
Log:
new feature : download directory as zipfile

Modified: trunk/src/common/docman/DocumentFactory.class.php
===================================================================
--- trunk/src/common/docman/DocumentFactory.class.php	2011-01-06 19:30:57 UTC (rev 11943)
+++ trunk/src/common/docman/DocumentFactory.class.php	2011-01-07 14:34:50 UTC (rev 11944)
@@ -5,7 +5,7 @@
  * 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
  * http://fusionforge.org
  *
  * This file is part of FusionForge.
@@ -272,10 +272,17 @@
 		}
 
 		$return = array();
-		$keys = array_keys($this->Documents);
 
+		// limit scope to the doc_group_id if any. Useful when you retrieve all documents
+		if ($this->docgroupid) {
+			$keys = array($this->docgroupid);
+		} else {
+			$keys = array_keys($this->Documents);
+		}
+
 		foreach ($keys as $key) {
-			if (!array_key_exists($key, $this->Documents)) continue;		// Should not happen
+			if (!array_key_exists($key, $this->Documents))	continue;		// Should not happen
+
 			$count = count($this->Documents[$key]);
 
 			for ($i=0; $i < $count; $i++) {
@@ -313,7 +320,7 @@
 			}
 		}
 
-		if (count($return) == 0) {
+		if (count($return) === 0) {
 			$this->setError(_('No Documents Found'));
 			$return = NULL;
 			return $return;

Modified: trunk/src/common/docman/include/utils.php
===================================================================
--- trunk/src/common/docman/include/utils.php	2011-01-06 19:30:57 UTC (rev 11943)
+++ trunk/src/common/docman/include/utils.php	2011-01-07 14:34:50 UTC (rev 11944)
@@ -5,7 +5,7 @@
  * Copyright 1999-2001, VA Linux Systems
  * Copyright 2000, Quentin Cregan/SourceForge
  * Copyright 2002-2004, GForge Team
- * Copyright 2010, Franck Villaume - Capgemini
+ * Copyright 2010-2011, Franck Villaume - Capgemini
  * http://fusionforge.org
  *
  * This file is part of FusionForge.
@@ -101,7 +101,7 @@
 				return false;
 
 			$document_factory->setDocGroupID($dg->getID());
-			$docs = $document_factory->getDocuments();
+			$docs = $document_factory->getDocuments(1);	// no caching
 			if (is_array($docs) && count($docs) > 0) {	// this group has documents
 				foreach ($docs as $doc) {
 					if ( !$zip->addFromString($parent_docname.'/'.$dg->getName().'/'.$doc->getFileName(),$doc->getFileData()))

Modified: trunk/src/common/docman/views/listfile.php
===================================================================
--- trunk/src/common/docman/views/listfile.php	2011-01-06 19:30:57 UTC (rev 11943)
+++ trunk/src/common/docman/views/listfile.php	2011-01-07 14:34:50 UTC (rev 11944)
@@ -5,7 +5,7 @@
  * Copyright 2000, Quentin Cregan/Sourceforge
  * Copyright 2002-2003, Tim Perdue/GForge, LLC
  * Copyright (C) 2010 Alcatel-Lucent
- * Copyright 2010, Franck Villaume - Capgemini
+ * Copyright 2010-2011, Franck Villaume - Capgemini
  * http://fusionforge.org
  *
  * This file is part of FusionForge.
@@ -50,6 +50,7 @@
 						{selector: '#docman-additem', options:{delayIn: 500, delayOut: 0, fade: true}},
 						{selector: '#docman-editdirectory', options:{delayIn: 500, delayOut: 0, fade: true}},
 						{selector: '#docman-deletedirectory', options:{delayIn: 500, delayOut: 0, fade: true}},
+						{selector: '#docman-downloadaszip', options:{delayIn: 500, delayOut: 0, fade: true}},
 						{selector: '.docman-viewfile', options:{gravity: 'nw', delayIn: 500, delayOut: 0, fade: true}},
 						{selector: '.docman-reserveddocument', options:{delayIn: 500, delayOut: 0, fade: true}},
 						{selector: '.docman-movetotrash', options:{gravity: 'ne', delayIn: 500, delayOut: 0, fade: true}},
@@ -72,7 +73,7 @@
 
 <?php
 echo '<h3 class="docman_h3" >Directory : <i>'.$DocGroupName.'</i>&nbsp;';
-if (forge_check_perm ('docman', $group_id, 'approve')) {
+if (forge_check_perm('docman', $group_id, 'approve')) {
 	echo '<a href="#" id="docman-editdirectory" title="'._('Edit this directory').'">'. html_image('docman/configure-directory.png',22,22,array('alt'=>'edit')). '</a>';
 	// do not uncomment the line : trash directory is not correctly implemented
 	//echo '<a href="?group_id='.$group_id.'&action=trashdir&dirid='.$dirid.'">'. html_image('docman/trash-empty.png',22,22,array('alt'=>'trashdir')). '</a>';
@@ -80,10 +81,14 @@
 		echo '<a href="?group_id='.$group_id.'&action=deldir&dirid='.$dirid.'" id="docman-deletedirectory" title="'._('Permanently delete this directory').'" >'. html_image('docman/delete-directory.png',22,22,array('alt'=>'deldir')). '</a>';
 }
 
-if (forge_check_perm ('docman', $group_id, 'submit')) {
+if (forge_check_perm('docman', $group_id, 'submit')) {
 	echo '<a href="#" id="docman-additem" title="'. _('Add a new item in this directory') . '" >'. html_image('docman/insert-directory.png',22,22,array('alt'=>'additem')). '</a>';
 }
 
+if (forge_check_perm('docman', $group_id, 'read')) {
+	echo '<a href="/docman/view.php/'.$group_id.'/zip/'.$dirid.'" id="docman-downloadaszip" title="'. _('Download this directory as a zip') . '" >' . html_image('docman/download-directory-zip.png',22,22,array('alt'=>'downloadaszip')). '</a>';
+}
+
 echo '</h3>';
 
 echo '<div class="docman_div_include" id="editdocgroup" style="display:none;">';

Modified: trunk/src/www/docman/view.php
===================================================================
--- trunk/src/www/docman/view.php	2011-01-06 19:30:57 UTC (rev 11943)
+++ trunk/src/www/docman/view.php	2011-01-07 14:34:50 UTC (rev 11944)
@@ -4,7 +4,7 @@
  *
  * Copyright 2000, Quentin Cregan/Sourceforge
  * Copyright 2002-2003, Tim Perdue/GForge, LLC
- * Copyright 2010, Franck Villaume - Capgemini
+ * Copyright 2010-2011, Franck Villaume - Capgemini
  * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
  * http://fusionforge.org
  *
@@ -46,7 +46,7 @@
 	exit_error($g->getErrorMessage(), 'docman');
 }
 
-if ($docid != 'backup' && $docid != 'webdav') {
+if ($docid != 'backup' && $docid != 'webdav' && $docid != 'zip') {
 	session_require_perm('docman', $group_id, 'read');
 	$docname = urldecode($arr[5]);
 
@@ -80,7 +80,7 @@
 
 	echo $d->getFileData();
 
-} else if ($docid == 'backup') {
+} elseif ($docid === 'backup') {
 	session_require_perm('docman', $group_id, 'admin');
 
 	$df = new DocumentFactory($g);
@@ -93,10 +93,6 @@
 
 	$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;
@@ -120,7 +116,7 @@
 		$warning_msg = _('No documents to backup.');
 		session_redirect('/docman/?group_id='.$group_id.'&view=admin&warning_msg='.urlencode($warning_msg));
 	}
-} else if ($docid == 'webdav') {
+} elseif ($docid === 'webdav') {
 	$_SERVER['SCRIPT_NAME'] = '';
 	/* we need the group id for check authentification. */
 	$_SERVER["AUTH_TYPE"] = $group_id;
@@ -132,6 +128,55 @@
 	}
 	$server = new HTTP_WebDAV_Server_Docman;
 	$server->ServeRequest();
+} elseif ($docid === 'zip') {
+	session_require_perm('docman', $group_id, 'read');
+	$dirid = $arr[5];
+
+	$dg = new DocumentGroup($g,$dirid);
+	if ($dg->isError())
+		exit_error($dg->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();
+
+	if ($dg->hasDocuments($nested_groups,$df)) {
+		$filename = 'docman-'.$g->getUnixName().'-'.$dg->getID().'.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 download as zip'),'docman');
+
+		// ugly workaround to get the files at doc_group_id level
+		$df->setDocGroupID($dg->getID());
+		$docs = $df->getDocuments(1);	// no caching
+		if (is_array($docs) && count($docs) > 0) {	// this group has documents
+			foreach ($docs as $doc) {
+				if ( !$zip->addFromString($doc->getFileName(),$doc->getFileData()))
+					return false;
+			}
+		}
+		if ( !docman_fill_zip($zip,$nested_groups,$df,$dg->getID()))
+			exit_error(_('Unable to fill zip archive for download as zip'), 'docman');
+
+		if ( !$zip->close())
+			exit_error(_('Unable to close zip archive for download as zip'), 'docman');
+
+		header('Content-disposition: filename="'.$filename.'"');
+		header('Content-type: application/binary');
+
+		readfile($file);
+		unlink($file);
+	} else {
+		$warning_msg = _('This directory is empty.');
+		session_redirect('/docman/?group_id='.$group_id.'&view=listfile&dirid='.$dirid.'&warning_msg='.urlencode($warning_msg));
+	}
 } else {
 	exit_error(_('No document to display - invalid or inactive document number.'), 'docman');
 }

Added: trunk/src/www/themes/funky/images/docman/download-directory-zip.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/www/themes/funky/images/docman/download-directory-zip.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Added: trunk/src/www/themes/gforge/images/docman/download-directory-zip.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/www/themes/gforge/images/docman/download-directory-zip.png
___________________________________________________________________
Added: svn:mime-type
   + image/png




More information about the Fusionforge-commits mailing list