NEW Enhance prototype, project list and proposal list with new hook to

have an external module able to add more fields.
This commit is contained in:
Laurent Destailleur 2015-06-16 19:36:44 +02:00
parent b7c777dc07
commit 8df56511be
4 changed files with 182 additions and 120 deletions

View File

@ -1,5 +1,5 @@
<?php <?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--- * Copyright (C) ---Put here your own copyright and developer email---
* *
* This program is free software; you can redistribute it and/or modify * 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); 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,9 +83,15 @@ if (($id > 0 || ! empty($ref)) && $action != 'add')
* Put here all code to do according to value of "action" parameter * Put here all code to do according to value of "action" parameter
********************************************************************/ ********************************************************************/
// Action to add record $parameters=array();
if ($action == 'add') $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))
{ {
// Action to add record
if ($action == 'add')
{
if (GETPOST('cancel')) if (GETPOST('cancel'))
{ {
$urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1); $urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1);
@ -123,14 +132,14 @@ if ($action == 'add')
{ {
$action='create'; $action='create';
} }
} }
// Cancel // Cancel
if ($action == 'update' && GETPOST('cancel')) $action='view'; if ($action == 'update' && GETPOST('cancel')) $action='view';
// Action to update record // Action to update record
if ($action == 'update' && ! GETPOST('cancel')) if ($action == 'update' && ! GETPOST('cancel'))
{ {
$error=0; $error=0;
$object->prop1=GETPOST("field1"); $object->prop1=GETPOST("field1");
@ -161,11 +170,11 @@ if ($action == 'update' && ! GETPOST('cancel'))
{ {
$action='edit'; $action='edit';
} }
} }
// Action to delete // Action to delete
if ($action == 'confirm_delete') if ($action == 'confirm_delete')
{ {
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
{ {
@ -179,12 +188,12 @@ if ($action == 'confirm_delete')
if (! empty($object->errors)) setEventMessages(null,$object->errors,'errors'); if (! empty($object->errors)) setEventMessages(null,$object->errors,'errors');
else setEventMessages($object->error,null,'errors'); else setEventMessages($object->error,null,'errors');
} }
}
} }
/*************************************************** /***************************************************
* VIEW * VIEW
* *
@ -225,11 +234,39 @@ if ($action == 'list' || empty($id))
$sql.= " WHERE field3 = 'xxx'"; $sql.= " WHERE field3 = 'xxx'";
$sql.= " ORDER BY field1 ASC"; $sql.= " ORDER BY field1 ASC";
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"; print '<table class="noborder">'."\n";
// Fields title
print '<tr class="liste_titre">'; 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('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_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); dol_syslog($script_file, LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
@ -243,10 +280,15 @@ if ($action == 'list' || empty($id))
if ($obj) if ($obj)
{ {
// You can use here results // You can use here results
print '<tr><td>'; print '<tr>';
print '<td>';
print $obj->field1; print $obj->field1;
print '</td><td>';
print $obj->field2; 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++; $i++;
} }
@ -257,7 +299,13 @@ if ($action == 'list' || empty($id))
dol_print_error($db); 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")); print_fiche_titre($langs->trans("NewResidence"));
dol_fiche_head();
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
dol_fiche_head();
print '<table class="border centpercent">'."\n"; print '<table class="border centpercent">'."\n";
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>'; print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
print '<input class="flat" type="text" size="36" name="label" value="'.$label.'">'; print '<input class="flat" type="text" size="36" name="label" value="'.$label.'">';
@ -280,13 +328,11 @@ if ($action == 'create')
print '</table>'."\n"; 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 '<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>'; print '</form>';
dol_fiche_end();
} }
@ -294,21 +340,19 @@ if ($action == 'create')
// Part to edit record // Part to edit record
if (($id || $ref) && $action == 'edit') if (($id || $ref) && $action == 'edit')
{ {
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
dol_fiche_head(); dol_fiche_head();
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
dol_fiche_end();
print '<br>';
print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"></div>'; print '<div class="center"><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"></div>';
print '</form>'; print '</form>';
dol_fiche_end();
} }

View File

@ -92,6 +92,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
if ($search_status=='') $search_status=1; // always display activ customer first if ($search_status=='') $search_status=1; // always display activ customer first
/* /*
* view * 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("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("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_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(); $parameters=array();
$formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook $formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -245,7 +245,8 @@ if ($result)
$parameters=array(); $parameters=array();
$formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook $formconfirm=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
print "</tr>\n"; print '</tr>'."\n";
$var=True; $var=True;
@ -281,13 +282,13 @@ if ($result)
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
//print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
print "</table>\n";
print "</form>\n";
$db->free($result); $db->free($result);
$parameters=array('sql' => $sql); $parameters=array('sql' => $sql);
$formconfirm=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook $formconfirm=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
print "</table>\n";
print "</form>\n";
} }
else else
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* 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 Marc Bariley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
@ -100,6 +100,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
$syear=""; $syear="";
} }
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('projectlist'));
/* /*
* View * View
*/ */
@ -212,10 +218,7 @@ if ($resql)
if ($mine) $text=$langs->trans('MyProjects'); if ($mine) $text=$langs->trans('MyProjects');
print_barre_liste($text, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num,'','title_project'); print_barre_liste($text, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num,'','title_project');
print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="GET" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
print '<table class="noborder" width="100%">';
// Show description of content // Show description of content
if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>'; if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
@ -242,13 +245,16 @@ if ($resql)
} }
if (! empty($moreforfilter)) if (! empty($moreforfilter))
{ {
print '<tr class="liste_titre">'; print '<div class="liste_titre">';
print '<td class="liste_titre" colspan="10">';
print $moreforfilter; 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 '<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("Ref"),$_SERVER["PHP_SELF"],"p.ref","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"p.title","",$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("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($langs->trans("Status"),$_SERVER["PHP_SELF"],'p.fk_statut',"",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre(''); 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>\n";
print '<tr class="liste_titre">'; 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 '<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>'; 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) while ($i < $num)
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
@ -396,21 +409,29 @@ if ($resql)
$projectstatic->statut = $objp->fk_statut; $projectstatic->statut = $objp->fk_statut;
print '<td align="right" colspan="2">'.$projectstatic->getLibStatut(5).'</td>'; 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"; print "</tr>\n";
} }
$i++; $i++;
}
}
$db->free($resql); $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";
} }
else else
{ {
dol_print_error($db); dol_print_error($db);
} }
print "</table>";
llxFooter(); llxFooter();

View File

@ -159,10 +159,6 @@ if (empty($reshook))
} }
//External modules should update their ones too //External modules should update their ones too
$hookmanager->initHooks(array(
'mergethirds'
));
if (!$errors) if (!$errors)
{ {
$reshook = $hookmanager->executeHooks('replaceThirdparty', array( $reshook = $hookmanager->executeHooks('replaceThirdparty', array(