From 8d916215cc7d7d25c67df672662b6fa1e3c6a1e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 24 Jan 2014 11:15:25 +0100 Subject: [PATCH] New: Add new hook function addMoreActionsButtons to allow a module to add/replace action buttons into an element. --- ChangeLog | 6 +- htdocs/comm/action/fiche.php | 46 ++++--- htdocs/comm/propal.php | 163 ++++++++++++------------ htdocs/commande/fiche.php | 15 ++- htdocs/compta/facture.php | 12 +- htdocs/contact/fiche.php | 16 ++- htdocs/core/class/hookmanager.class.php | 3 +- htdocs/product/fiche.php | 87 +++++++------ htdocs/product/stock/fiche.php | 29 +++-- htdocs/societe/soc.php | 57 +++++---- 10 files changed, 234 insertions(+), 200 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb6495b4196..5d09b5daf8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,7 @@ For users: - New: Add graph stats for suppliers orders in tab "stats" on products. - New: Add option MAIN_HIDE_INACTIVETAB_ON_PRINT to hide inactive tabs when you use the "print" view on screen. -- New: Add menu entry to barcode genration page. +- New: Add a menu entry to a barcode generation page. - New: Add option MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES and MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES to automatically add timestamp and user line into editionf field when editing a note. - New: Add button cancel into edition of notes. @@ -27,7 +27,9 @@ For developers: - New: Add option 'aZ' into GETPOST function to check parameters contains only a to z or A to Z characters. - New: Opensurvey polls tab cards can now be extended from external modules. -- New: Triggers OPENSURVEY_CREATE, OPENSURVEY_DELETE +- New: Triggers OPENSURVEY_CREATE, OPENSURVEY_DELETE added. +- New: Add new hook function addMoreActionsButtons to allow a module to add/replace + action buttons into an element. WARNING: Following change may create regression for some external modules, but was necessary to make Dolibarr better: diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 0e8843579fe..dd9cd857bf5 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -167,8 +167,7 @@ if ($action == 'add_action') $actioncomm->datep = $datep; $actioncomm->datef = $datef; $actioncomm->percentage = $percentage; - $actioncomm->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * -60; + $actioncomm->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60; $usertodo=new User($db); if ($_POST["affectedto"] > 0) @@ -1072,29 +1071,34 @@ if ($id > 0) print '
'; - if ($action != 'edit') + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { - if ($user->rights->agenda->allactions->create || - (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->create)) + if ($action != 'edit') { - print ''; - } - else - { - print ''; - } - - if ($user->rights->agenda->allactions->delete || - (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->delete)) - { - print ''; - } - else - { - print ''; + if ($user->rights->agenda->allactions->create || + (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->create)) + { + print ''; + } + else + { + print ''; + } + + if ($user->rights->agenda->allactions->delete || + (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->delete)) + { + print ''; + } + else + { + print ''; + } } } - + print '
'; } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index a4767f26ed1..41dba04b395 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2127,99 +2127,104 @@ else { print '
'; - if ($action != 'statut' && $action <> 'editline') + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { - // Validate - if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 && $user->rights->propal->valider) + if ($action != 'statut' && $action <> 'editline') { - if (count($object->lines) > 0) print ''; - //else print ''.$langs->trans('Validate').''; - } - // Create event - if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page. - { - print ''.$langs->trans("AddAction").''; - } - // Edit - if ($object->statut == 1 && $user->rights->propal->creer) - { - print ''; - } - - // ReOpen - if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) - { - print ''; - } - - // Send - if ($object->statut == 1 || $object->statut == 2) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) + // Validate + if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 && $user->rights->propal->valider) { - print ''; + if (count($object->lines) > 0) print ''; + //else print ''.$langs->trans('Validate').''; } - else print ''; - } - - // Create an order - if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0) - { - if ($user->rights->commande->creer) + // Create event + if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page. { - print ''; + print ''.$langs->trans("AddAction").''; } - } - - // Create contract - if ($conf->contrat->enabled && $object->statut == 2 && $user->societe_id == 0) - { - $langs->load("contracts"); - - if ($user->rights->contrat->creer) + // Edit + if ($object->statut == 1 && $user->rights->propal->creer) { - print ''; + print ''; } - } - - // Create an invoice and classify billed - if ($object->statut == 2 && $user->societe_id == 0) - { - if (! empty($conf->facture->enabled) && $user->rights->facture->creer) + + // ReOpen + if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) { - print ''; + print ''; } - - $arraypropal=$object->getInvoiceArrayList(); - if (is_array($arraypropal) && count($arraypropal) > 0) + + // Send + if ($object->statut == 1 || $object->statut == 2) { - print ''; + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) + { + print ''; + } + else print ''; } + + // Create an order + if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0) + { + if ($user->rights->commande->creer) + { + print ''; + } + } + + // Create contract + if ($conf->contrat->enabled && $object->statut == 2 && $user->societe_id == 0) + { + $langs->load("contracts"); + + if ($user->rights->contrat->creer) + { + print ''; + } + } + + // Create an invoice and classify billed + if ($object->statut == 2 && $user->societe_id == 0) + { + if (! empty($conf->facture->enabled) && $user->rights->facture->creer) + { + print ''; + } + + $arraypropal=$object->getInvoiceArrayList(); + if (is_array($arraypropal) && count($arraypropal) > 0) + { + print ''; + } + } + + // Close + if ($object->statut == 1 && $user->rights->propal->cloturer) + { + print ''; + } + + // Clone + if ($user->rights->propal->creer) + { + print ''; + } + + // Delete + if ($user->rights->propal->supprimer) + { + print ''; + } + } - - // Close - if ($object->statut == 1 && $user->rights->propal->cloturer) - { - print ''; - } - - // Clone - if ($user->rights->propal->creer) - { - print ''; - } - - // Delete - if ($user->rights->propal->supprimer) - { - print ''; - } - } - + print '
'; } print "
\n"; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 77c27663811..a0653214355 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2392,12 +2392,14 @@ else /* * Boutons actions */ - if ($action != 'presend') + if ($action != 'presend' && $action != 'editline') { - if ($user->societe_id == 0 && $action <> 'editline') - { - print '
'; + print '
'; + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) + { // Valid if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) { @@ -2470,7 +2472,7 @@ else } // Reopen a closed order - if ($object->statut == 3) + if ($object->statut == 3 && $user->rights->commande->creer) { print ''; } @@ -2519,9 +2521,8 @@ else print ''; } } - - print '
'; } + print '
'; } print '
'; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 14ad67badca..5bce6e0f658 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3547,12 +3547,14 @@ else if ($id > 0 || ! empty($ref)) // Boutons actions - if ($action != 'prerelance' && $action != 'presend') + if ($action != 'prerelance' && $action != 'presend' && $action != 'valid' && $action != 'editline') { - if ($user->societe_id == 0 && $action <> 'valid' && $action <> 'editline') - { - print '
'; + print '
'; + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) + { // Editer une facture deja validee, sans paiement effectue et pas exporte en compta if ($object->statut == 1) { @@ -3580,7 +3582,7 @@ else if ($id > 0 || ! empty($ref)) } // Reopen a standard paid invoice - if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) + if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3) && $user->rights->facture->creer) // A paid invoice (partially or completely) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 54d40b54c8a..8eaede03396 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -1026,11 +1026,13 @@ else print "
"; // Barre d'actions - if (! $user->societe_id) - { - print '
'; + print '
'; - if ($user->rights->societe->contact->creer) + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) + { + if ($user->rights->societe->contact->creer) { print ''.$langs->trans('Modify').''; } @@ -1054,10 +1056,10 @@ else { print ''.$langs->trans("DisableUser").''; } - - print "

"; } - + + print "

"; + print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'',''); print show_actions_todo($conf,$langs,$db,$objsoc,$object); diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 849b6bb0370..fc606857371 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -134,6 +134,7 @@ class HookManager if (in_array( $method, array( + 'addMoreActionsButtons', 'addStatisticLine', 'doActions', 'formObjectOptions', @@ -164,7 +165,7 @@ class HookManager // test to avoid to run twice a hook, when a module implements several active contexts if (in_array($module,$modulealreadyexecuted)) continue; $modulealreadyexecuted[$module]=$module; - // Hooks that return int (doActions, formObjectOptions, pdf_writelinedesc, paymentsupplierinvoices) + // Hooks that must return int (hooks with type 'addreplace') if ($hooktype == 'addreplace') { $resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 9193b8e103e..ec2dc29fd79 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -1285,49 +1285,54 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf-> print "\n".'
'."\n"; -if ($action == '' || $action == 'view') +$parameters=array(); +$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { - if ($user->rights->produit->creer || $user->rights->service->creer) - { - if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print ''; - - if (! isset($object->no_button_copy) || $object->no_button_copy <> 1) - { - if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) - { - print '
'.$langs->trans('ToClone').'
'."\n"; - } - else - { - print ''; - } - } - } - $object_is_used = $object->isObjectUsed($object->id); - - if (($object->type == 0 && $user->rights->produit->supprimer) - || ($object->type == 1 && $user->rights->service->supprimer)) - { - if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1)) - { - if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) - { - print '
'.$langs->trans('Delete').'
'."\n"; - } - else - { - print ''; - } - } - else - { - print ''; - } - } - else + if ($action == '' || $action == 'view') { - print ''; - } + if ($user->rights->produit->creer || $user->rights->service->creer) + { + if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print ''; + + if (! isset($object->no_button_copy) || $object->no_button_copy <> 1) + { + if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) + { + print '
'.$langs->trans('ToClone').'
'."\n"; + } + else + { + print ''; + } + } + } + $object_is_used = $object->isObjectUsed($object->id); + + if (($object->type == 0 && $user->rights->produit->supprimer) + || ($object->type == 1 && $user->rights->service->supprimer)) + { + if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1)) + { + if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) + { + print '
'.$langs->trans('Delete').'
'."\n"; + } + else + { + print ''; + } + } + else + { + print ''; + } + } + else + { + print ''; + } + } } print "\n

\n"; diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index a60deff921e..38d25ea70cd 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -47,6 +47,8 @@ $mesg = ''; // Security check $result=restrictedArea($user,'stock'); +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('warehousecard')); /* @@ -336,19 +338,24 @@ else print "
\n"; - if ($action == '') + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { - if ($user->rights->stock->creer) - print "id."\">".$langs->trans("Modify").""; - else - print "".$langs->trans("Modify").""; - - if ($user->rights->stock->supprimer) - print "id."\">".$langs->trans("Delete").""; - else - print "".$langs->trans("Delete").""; + if (empty($action)) + { + if ($user->rights->stock->creer) + print "id."\">".$langs->trans("Modify").""; + else + print "".$langs->trans("Modify").""; + + if ($user->rights->stock->supprimer) + print "id."\">".$langs->trans("Delete").""; + else + print "".$langs->trans("Delete").""; + } } - + print "
"; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 5b1cca98c77..77d00d0e921 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1818,34 +1818,39 @@ else */ print '
'."\n"; - if (! empty($object->email)) - { - $langs->load("mails"); - print ''; - } - else + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { - $langs->load("mails"); - print ''; - } - - if ($user->rights->societe->creer) - { - print ''."\n"; - } - - if ($user->rights->societe->supprimer) - { - if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can(t use preloaded confirm form with jmobile - { - print '
'.$langs->trans('Delete').'
'."\n"; - } - else + if (! empty($object->email)) + { + $langs->load("mails"); + print ''; + } + else { - print ''."\n"; - } - } - + $langs->load("mails"); + print ''; + } + + if ($user->rights->societe->creer) + { + print ''."\n"; + } + + if ($user->rights->societe->supprimer) + { + if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can(t use preloaded confirm form with jmobile + { + print '
'.$langs->trans('Delete').'
'."\n"; + } + else + { + print ''."\n"; + } + } + } + print '
'."\n";