From 8df56511be0b9b6485224d338be3a447fb8dc4ee Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Tue, 16 Jun 2015 19:36:44 +0200
Subject: [PATCH] NEW Enhance prototype, project list and proposal list with
 new hook to have an external module able to add more fields.

---
 dev/skeletons/skeleton_page.php | 224 +++++++++++++++++++-------------
 htdocs/comm/list.php            |  13 +-
 htdocs/projet/list.php          |  41 ++++--
 htdocs/societe/soc.php          |   4 -
 4 files changed, 172 insertions(+), 110 deletions(-)

diff --git a/dev/skeletons/skeleton_page.php b/dev/skeletons/skeleton_page.php
index 9e6d76ee6d8..334980b1470 100644
--- a/dev/skeletons/skeleton_page.php
+++ b/dev/skeletons/skeleton_page.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2007-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2007-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) ---Put here your own copyright and developer email---
  *
  * This program is free software; you can redistribute it and/or modify
@@ -72,6 +72,9 @@ if (($id > 0 || ! empty($ref)) && $action != 'add')
 	if ($result < 0) dol_print_error($db);
 }
 
+// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
+$hookmanager->initHooks(array('skeleton'));
+
 
 
 /*******************************************************************
@@ -80,111 +83,117 @@ if (($id > 0 || ! empty($ref)) && $action != 'add')
 * Put here all code to do according to value of "action" parameter
 ********************************************************************/
 
-// Action to add record
-if ($action == 'add')
+$parameters=array();
+$reshook=$hookmanager->executeHooks('doActions',$parameters);    // Note that $action and $object may have been modified by some hooks
+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+
+if (empty($reshook))
 {
-	if (GETPOST('cancel'))
+	// Action to add record
+	if ($action == 'add')
 	{
-		$urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1);
-		header("Location: ".$urltogo);
-		exit;
-	}
+		if (GETPOST('cancel'))
+		{
+			$urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1);
+			header("Location: ".$urltogo);
+			exit;
+		}
 
-	$error=0;
+		$error=0;
 
-	/* object_prop_getpost_prop */
-	$object->prop1=GETPOST("field1");
-	$object->prop2=GETPOST("field2");
+		/* object_prop_getpost_prop */
+		$object->prop1=GETPOST("field1");
+		$object->prop2=GETPOST("field2");
 
-	if (empty($object->ref))
-	{
-		$error++;
-		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
-	}
+		if (empty($object->ref))
+		{
+			$error++;
+			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
+		}
 
-	if (! $error)
-	{
-		$result=$object->create($user);
-		if ($result > 0)
+		if (! $error)
 		{
-			// Creation OK
-			$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
-			header("Location: ".$urltogo);
-			exit;
+			$result=$object->create($user);
+			if ($result > 0)
+			{
+				// Creation OK
+				$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
+				header("Location: ".$urltogo);
+				exit;
+			}
+			{
+				// Creation KO
+				if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
+				else  setEventMessages($object->error, null, 'errors');
+				$action='create';
+			}
 		}
+		else
 		{
-			// Creation KO
-			if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
-			else  setEventMessages($object->error, null, 'errors');
 			$action='create';
 		}
 	}
-	else
-	{
-		$action='create';
-	}
-}
 
-// Cancel
-if ($action == 'update' && GETPOST('cancel')) $action='view';
+	// Cancel
+	if ($action == 'update' && GETPOST('cancel')) $action='view';
 
-// Action to update record
-if ($action == 'update' && ! GETPOST('cancel'))
-{
-	$error=0;
+	// Action to update record
+	if ($action == 'update' && ! GETPOST('cancel'))
+	{
+		$error=0;
 
-	$object->prop1=GETPOST("field1");
-	$object->prop2=GETPOST("field2");
+		$object->prop1=GETPOST("field1");
+		$object->prop2=GETPOST("field2");
 
-	if (empty($object->ref))
-	{
-		$error++;
-		setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),null,'errors');
-	}
+		if (empty($object->ref))
+		{
+			$error++;
+			setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),null,'errors');
+		}
 
-	if (! $error)
-	{
-		$result=$object->update($user);
-		if ($result > 0)
+		if (! $error)
 		{
-			$action='view';
+			$result=$object->update($user);
+			if ($result > 0)
+			{
+				$action='view';
+			}
+			else
+			{
+				// Creation KO
+				if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
+				else setEventMessages($object->error, null, 'errors');
+				$action='edit';
+			}
 		}
 		else
 		{
-			// Creation KO
-			if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
-			else setEventMessages($object->error, null, 'errors');
 			$action='edit';
 		}
 	}
-	else
-	{
-		$action='edit';
-	}
-}
 
-// Action to delete
-if ($action == 'confirm_delete')
-{
-	$result=$object->delete($user);
-	if ($result > 0)
-	{
-		// Delete OK
-		setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
-		header("Location: ".dol_buildpath('/buildingmanagement/list.php',1));
-		exit;
-	}
-	else
+	// Action to delete
+	if ($action == 'confirm_delete')
 	{
-		if (! empty($object->errors)) setEventMessages(null,$object->errors,'errors');
-		else setEventMessages($object->error,null,'errors');
+		$result=$object->delete($user);
+		if ($result > 0)
+		{
+			// Delete OK
+			setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
+			header("Location: ".dol_buildpath('/buildingmanagement/list.php',1));
+			exit;
+		}
+		else
+		{
+			if (! empty($object->errors)) setEventMessages(null,$object->errors,'errors');
+			else setEventMessages($object->error,null,'errors');
+		}
 	}
 }
 
 
 
 
-
 /***************************************************
 * VIEW
 *
@@ -225,11 +234,39 @@ if ($action == 'list' || empty($id))
     $sql.= " WHERE field3 = 'xxx'";
     $sql.= " ORDER BY field1 ASC";
 
-    print '<table class="noborder">'."\n";
+	print '<form method="GET" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
+
+	if (! empty($moreforfilter))
+	{
+		print '<div class="liste_titre">';
+		print $moreforfilter;
+    	$parameters=array();
+    	$formconfirm=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
+	    print '</div>';
+	}
+
+	print '<table class="noborder">'."\n";
+
+    // Fields title
     print '<tr class="liste_titre">';
     print_liste_field_titre($langs->trans('field1'),$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder);
     print_liste_field_titre($langs->trans('field2'),$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder);
-    print '</tr>';
+    $parameters=array();
+    $formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
+    print '</tr>'."\n";
+
+    // Fields title search
+	print '<tr class="liste_titre">';
+	print '<td class="liste_titre">';
+	print '<input type="text" class="flat" name="search_field1" value="'.$search_field1.'" size="10">';
+	print '</td>';
+	print '<td class="liste_titre">';
+	print '<input type="text" class="flat" name="search_field2" value="'.$search_field2.'" size="10">';
+	print '</td>';
+    $parameters=array();
+    $formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
+    print '</tr>'."\n";
+
 
     dol_syslog($script_file, LOG_DEBUG);
     $resql=$db->query($sql);
@@ -243,21 +280,32 @@ if ($action == 'list' || empty($id))
             if ($obj)
             {
                 // You can use here results
-                print '<tr><td>';
+                print '<tr>';
+                print '<td>';
                 print $obj->field1;
+                print '</td><td>';
                 print $obj->field2;
-                print '</td></tr>';
+                print '</td>';
+		        $parameters=array('obj' => $obj);
+        		$formconfirm=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
+                print '</tr>';
             }
             $i++;
         }
     }
     else
-    {
+	{
         $error++;
         dol_print_error($db);
     }
 
-    print '</table>'."\n";
+    $db->free($resql);
+
+	$parameters=array('sql' => $sql);
+	$formconfirm=$hookmanager->executeHooks('printFieldListFooter',$parameters);    // Note that $action and $object may have been modified by hook
+
+	print "</table>\n";
+	print "</form>\n";
 }
 
 
@@ -267,12 +315,12 @@ if ($action == 'create')
 {
 	print_fiche_titre($langs->trans("NewResidence"));
 
-	dol_fiche_head();
-
 	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 	print '<input type="hidden" name="action" value="add">';
 	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
 
+	dol_fiche_head();
+
 	print '<table class="border centpercent">'."\n";
 	print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
 	print '<input class="flat" type="text" size="36" name="label" value="'.$label.'">';
@@ -280,13 +328,11 @@ if ($action == 'create')
 
 	print '</table>'."\n";
 
-	print '<br>';
+	dol_fiche_end();
 
 	print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"> &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></div>';
 
 	print '</form>';
-
-	dol_fiche_end();
 }
 
 
@@ -294,21 +340,19 @@ if ($action == 'create')
 // Part to edit record
 if (($id || $ref) && $action == 'edit')
 {
+	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
+
 	dol_fiche_head();
 
-	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 	print '<input type="hidden" name="action" value="add">';
 	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
 	print '<input type="hidden" name="id" value="'.$object->id.'">';
 
-
-	print '<br>';
+	dol_fiche_end();
 
 	print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"></div>';
 
 	print '</form>';
-
-	dol_fiche_end();
 }
 
 
diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php
index a82413e9d4f..cf5bacc5e25 100644
--- a/htdocs/comm/list.php
+++ b/htdocs/comm/list.php
@@ -92,6 +92,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
 
 if ($search_status=='') $search_status=1; // always display activ customer first
 
+
 /*
  * view
  */
@@ -202,10 +203,9 @@ if ($result)
     print_liste_field_titre($langs->trans("AccountancyCode"),$_SERVER["PHP_SELF"],"s.code_compta","",$param,'align="left"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec","",$param,'align="right"',$sortfield,$sortorder);
     print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="center"',$sortfield,$sortorder);
-    print '<td class="liste_titre">&nbsp;</td>';
+    print_liste_field_titre('');
     $parameters=array();
     $formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
-
     print "</tr>\n";
 
 	print '<tr class="liste_titre">';
@@ -245,7 +245,8 @@ if ($result)
     $parameters=array();
     $formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
 
-    print "</tr>\n";
+    print '</tr>'."\n";
+
 
 	$var=True;
 
@@ -281,13 +282,13 @@ if ($result)
         print "</tr>\n";
 		$i++;
 	}
-	//print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
-	print "</table>\n";
-	print "</form>\n";
 	$db->free($result);
 
 	$parameters=array('sql' => $sql);
 	$formconfirm=$hookmanager->executeHooks('printFieldListFooter',$parameters);    // Note that $action and $object may have been modified by hook
+
+	print "</table>\n";
+	print "</form>\n";
 }
 else
 {
diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php
index 4464c9cb8ef..eacc44cb3dd 100644
--- a/htdocs/projet/list.php
+++ b/htdocs/projet/list.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2004-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005      Marc Bariley / Ocebo <marc@ocebo.com>
  * Copyright (C) 2005-2010 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2013      Cédric Salvador      <csalvador@gpcsolutions.fr>
@@ -100,6 +100,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
 	$syear="";
 }
 
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+$hookmanager->initHooks(array('projectlist'));
+
+
+
+
 /*
  * View
  */
@@ -212,10 +218,7 @@ if ($resql)
 	if ($mine) $text=$langs->trans('MyProjects');
 	print_barre_liste($text, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num,'','title_project');
 
-	print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
-
-	print '<table class="noborder" width="100%">';
-
+	print '<form method="GET" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
 
 	// Show description of content
 	if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
@@ -242,13 +245,16 @@ if ($resql)
 	}
 	if (! empty($moreforfilter))
 	{
-		print '<tr class="liste_titre">';
-		print '<td class="liste_titre" colspan="10">';
+		print '<div class="liste_titre">';
 		print $moreforfilter;
-		print '</td></tr>';
+    	$parameters=array();
+    	$formconfirm=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
+	    print '</div>';
 	}
 
 
+	print '<table class="noborder" width="100%">';
+
 	print '<tr class="liste_titre">';
 	print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"p.title","",$param,"",$sortfield,$sortorder);
@@ -259,6 +265,8 @@ if ($resql)
 	print_liste_field_titre($langs->trans("Visibility"),$_SERVER["PHP_SELF"],"p.public","",$param,"",$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],'p.fk_statut',"",$param,'align="right"',$sortfield,$sortorder);
 	print_liste_field_titre('');
+    $parameters=array();
+    $formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
 	print "</tr>\n";
 
 	print '<tr class="liste_titre">';
@@ -301,6 +309,11 @@ if ($resql)
     print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("RemoveFilter"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
     print '</td>';
 
+    $parameters=array();
+    $formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
+    print '</tr>'."\n";
+
+
     while ($i < $num)
     {
     	$objp = $db->fetch_object($resql);
@@ -396,21 +409,29 @@ if ($resql)
     		$projectstatic->statut = $objp->fk_statut;
     		print '<td align="right" colspan="2">'.$projectstatic->getLibStatut(5).'</td>';
 
+        	$parameters=array('obj' => $objp);
+        	$formconfirm=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
+
     		print "</tr>\n";
 
     	}
 
     	$i++;
+
     }
+    $db->free($resql);
+
+	$parameters=array('sql' => $sql);
+	$formconfirm=$hookmanager->executeHooks('printFieldListFooter',$parameters);    // Note that $action and $object may have been modified by hook
 
-	$db->free($resql);
+	print "</table>\n";
+	print "</form>\n";
 }
 else
 {
 	dol_print_error($db);
 }
 
-print "</table>";
 
 
 llxFooter();
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index cc1af52b2dd..863863811e0 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -159,10 +159,6 @@ if (empty($reshook))
 				}
 
 				//External modules should update their ones too
-				$hookmanager->initHooks(array(
-					'mergethirds'
-				));
-
 				if (!$errors)
 				{
 					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
-- 
GitLab