From 6c22af00e1696d52b747725f0ae3a4cc1c2b3baa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Salvador?= <csalvador@gpcsolutions.fr>
Date: Wed, 18 Sep 2013 15:55:44 +0200
Subject: [PATCH] factorization

---
 htdocs/comm/propal/document.php        | 19 ++++---------------
 htdocs/commande/document.php           | 21 ++++-----------------
 htdocs/compta/deplacement/document.php | 21 ++++-----------------
 htdocs/compta/facture/document.php     | 22 ++++------------------
 htdocs/contrat/document.php            | 22 ++++------------------
 htdocs/fichinter/document.php          | 21 ++++-----------------
 htdocs/fourn/commande/document.php     | 20 ++++----------------
 htdocs/fourn/facture/document.php      | 15 ++++-----------
 htdocs/projet/document.php             | 17 ++++-------------
 htdocs/societe/document.php            |  2 +-
 10 files changed, 37 insertions(+), 143 deletions(-)

diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php
index 266ee77b7d9..04704ba2ff4 100644
--- a/htdocs/comm/propal/document.php
+++ b/htdocs/comm/propal/document.php
@@ -130,21 +130,10 @@ if ($object->id > 0)
 
 	print '</div>';
 
-	/*
-	 * Confirmation suppression fichier
-	 */
-	if ($action == 'delete')
-	{
-		print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-	}
-
-	// Affiche formulaire upload
-	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->propal->creer,50,$object);
-
-
-	// List of document
-	$formfile->list_of_documents($filearray,$object,'propal');
+	$modulepart = 'propal';
+	$permission = $user->rights->propal->creer;
+	$param = '&id=' . $object->id;
+	include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 }
 else
 {
diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php
index 32e666d1a7b..9ba0827e7e1 100644
--- a/htdocs/commande/document.php
+++ b/htdocs/commande/document.php
@@ -119,23 +119,10 @@ if ($id > 0 || ! empty($ref))
 		print "</table>\n";
 		print "</div>\n";
 
-		/*
-		 * Confirmation suppression fichier
-		 */
-		if ($action == 'delete')
-		{
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-			
-		}
-
-		// Affiche formulaire upload
-		$formfile=new FormFile($db);
-		$formfile->form_attach_new_file(DOL_URL_ROOT.'/commande/document.php?id='.$object->id,'',0,0,$user->rights->commande->creer,50,$object);
-
-
-		// List of document
-		$param='&id='.$object->id;
-		$formfile->list_of_documents($filearray,$object,'commande',$param);
+		$modulepart = 'commande';
+		$permission = $user->rights->commande->creer;
+		$param = '&id=' . $object->id;
+		include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 	}
 	else
 	{
diff --git a/htdocs/compta/deplacement/document.php b/htdocs/compta/deplacement/document.php
index 93258ab2297..0177891491d 100644
--- a/htdocs/compta/deplacement/document.php
+++ b/htdocs/compta/deplacement/document.php
@@ -120,23 +120,10 @@ if ($object->id)
 
     print '</div>';
 
-    /*
-     * Confirmation suppression fichier
-     */
-    if ($action == 'delete')
-    {
-    	print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-    	
-    }
-
-    // Affiche formulaire upload
-   	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/deplacement/document.php?id='.$object->id,'',0,0,$user->rights->deplacement->creer,50,$object);
-
-
-	// List of document
-	$param='&id='.$object->id;
-	$formfile->list_of_documents($filearray,$object,'deplacement',$param);
+    $modulepart = 'deplacement';
+    $permission = $user->rights->deplacement->creer;
+    $param = '&id=' . $object->id;
+    include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
 }
 else
diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php
index 92292375ac4..5bce75e363c 100644
--- a/htdocs/compta/facture/document.php
+++ b/htdocs/compta/facture/document.php
@@ -147,24 +147,10 @@ if ($id > 0 || ! empty($ref))
 		print "</table>\n";
 		print "</div>\n";
 
-    	/*
-		 * Confirmation suppression fichier
-		 */
-		if ($action == 'delete')
-		{
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-			
-		}
-
-
-		// Affiche formulaire upload
-		$formfile=new FormFile($db);
-		$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer,50,$object);
-
-
-		// List of document
-		$param='&facid='.$object->id;
-		$formfile->list_of_documents($filearray,$object,'facture',$param);
+		$modulepart = 'facture';
+		$permission = $user->rights->facture->creer;
+		$param = '&id=' . $object->id;
+		include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
 	}
 	else
diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php
index b63679cc1de..83d9870b0db 100644
--- a/htdocs/contrat/document.php
+++ b/htdocs/contrat/document.php
@@ -122,24 +122,10 @@ if ($object->id)
 
     print '</div>';
 
-    /*
-     * Confirmation suppression fichier
-     */
-    if ($action == 'delete')
-    {
-    	print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-    	
-    }
-
-
-    // Affiche formulaire upload
-   	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->contrat->creer,50,$object);
-
-
-	// List of document
-	$param='&id='.$object->id;
-	$formfile->list_of_documents($filearray,$object,'contract',$param);
+    $modulepart = 'contract';
+    $permission = $user->rights->contrat->creer;
+    $param = '&id=' . $object->id;
+    include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
 }
 else
diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php
index 2dc8f7aedea..1505facbab5 100644
--- a/htdocs/fichinter/document.php
+++ b/htdocs/fichinter/document.php
@@ -120,23 +120,10 @@ if ($object->id)
 
     print '</div>';
 
-    /*
-     * Confirmation suppression fichier
-     */
-    if ($action == 'delete')
-    {
-    	print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-    	
-    }
-
-    // Affiche formulaire upload
-   	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file(DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id,'',0,0,$user->rights->ficheinter->creer,50,$object);
-
-
-	// List of document
-	$param='&id='.$object->id;
-	$formfile->list_of_documents($filearray,$object,'ficheinter',$param);
+    $modulepart = 'ficheinter';
+    $permission = $user->rights->ficheinter->creer;
+    $param = '&id=' . $object->id;
+    include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
 }
 else
diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php
index 581fac2df66..303e505c18b 100644
--- a/htdocs/fourn/commande/document.php
+++ b/htdocs/fourn/commande/document.php
@@ -158,23 +158,11 @@ if ($object->id > 0)
 
 	print "</div>\n";
 
-	/*
-	 * Confirmation suppression fichier
-	*/
-	if ($action == 'delete')
-	{
-		print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
-		
-	}
-
-	// Affiche formulaire upload
-	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id,'',0,0,$user->rights->fournisseur->commande->creer,50,$object);
-
+	$modulepart = 'commande_fournisseur';
+	$permission = $user->rights->fournisseur->commande->creer;
+	$param = '&id=' . $object->id;
+	include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
-	// List of document
-	$param='&id='.$object->id;
-	$formfile->list_of_documents($filearray,$object,'commande_fournisseur',$param);
 }
 else
 {
diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php
index 287708da211..7779b58d220 100644
--- a/htdocs/fourn/facture/document.php
+++ b/htdocs/fourn/facture/document.php
@@ -177,17 +177,10 @@ if ($object->id > 0)
 	print '</table>';
 	print '</div>';
 
-	
-	// Affiche formulaire upload
-	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id, '', 0, 0, $user->rights->fournisseur->facture->creer, 50, $object, '', 0, dol_sanitizeFileName($object->ref.'_'.$object->ref_supplier.'___file__'));
-
-
-	// List of document
-	$param='&facid='.$object->id;
-	$ref=dol_sanitizeFileName($object->ref);
-	$formfile->list_of_documents($filearray,$object,'facture_fournisseur',$param,0,get_exdir($object->id,2,0).$ref.'/');
-
+	$modulepart = 'facture_fournisseur';
+	$permission = $user->rights->fournisseur->facture->creer;
+	$param = '&facid=' . $object->id;
+	include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 }
 else
 {
diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php
index 84c9f1e109c..7644ef5486c 100644
--- a/htdocs/projet/document.php
+++ b/htdocs/projet/document.php
@@ -104,11 +104,6 @@ if ($object->id > 0)
 		$totalsize+=$file['size'];
 	}
 
-	if ($action == 'delete')
-	{
-		print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&urlfile=".urlencode(GETPOST("urlfile")),$langs->trans("DeleteAFile"),$langs->trans("ConfirmDeleteAFile"),"confirm_delete",'','',1);
-	}
-
 	print '<table class="border" width="100%">';
 
 	$linkback = '<a href="'.DOL_URL_ROOT.'/projet/liste.php">'.$langs->trans("BackToList").'</a>';
@@ -149,14 +144,10 @@ if ($object->id > 0)
 	print "</table>\n";
 	print "</div>\n";
 
-	// Affiche formulaire upload
-	$formfile=new FormFile($db);
-	$formfile->form_attach_new_file(DOL_URL_ROOT.'/projet/document.php?id='.$object->id,'',0,0,($userWrite>0),50,$object);
-
-
-	// List of document
-	$param='&id='.$object->id;
-	$formfile->list_of_documents($filearray,$object,'projet',$param,0,'',($userWrite>0));
+	$modulepart = 'projet';
+	$permission = ($userWrite > 0);
+	$param = '&id=' . $object->id;
+	include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 
 }
 else
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index 0605592e4d7..e9b172cbc0a 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -152,7 +152,7 @@ if ($object->id)
 	$modulepart = 'societe';
 	$permission = $user->rights->societe->creer;
 	$param = '&id=' . $object->id;
-	include DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
+	include_once DOL_DOCUMENT_ROOT . '/core/tpl/doc2.tpl.php';
 }
 else
 {
-- 
GitLab