Skip to content

Commit

Permalink
New: Add new hook function addMoreActionsButtons to allow a module to
Browse files Browse the repository at this point in the history
add/replace action buttons into an element.
  • Loading branch information
eldy committed Jan 24, 2014
1 parent 1011516 commit 8d91621
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 199 deletions.
6 changes: 4 additions & 2 deletions ChangeLog
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
46 changes: 25 additions & 21 deletions htdocs/comm/action/fiche.php
Expand Up @@ -167,8 +167,7 @@
$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)
Expand Down Expand Up @@ -1072,29 +1071,34 @@ function setdatefields()

print '<div class="tabsAction">';

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 '<div class="inline-block divButAction"><a class="butAction" href="fiche.php?action=edit&id='.$act->id.'">'.$langs->trans("Modify").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Modify").'</a></div>';
}

if ($user->rights->agenda->allactions->delete ||
(($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->delete))
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="fiche.php?action=delete&id='.$act->id.'">'.$langs->trans("Delete").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>';
if ($user->rights->agenda->allactions->create ||
(($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->create))
{
print '<div class="inline-block divButAction"><a class="butAction" href="fiche.php?action=edit&id='.$act->id.'">'.$langs->trans("Modify").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Modify").'</a></div>';
}

if ($user->rights->agenda->allactions->delete ||
(($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->delete))
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="fiche.php?action=delete&id='.$act->id.'">'.$langs->trans("Delete").'</a></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>';
}
}
}

print '</div>';
}

Expand Down
163 changes: 84 additions & 79 deletions htdocs/comm/propal.php
Expand Up @@ -2127,99 +2127,104 @@
{
print '<div class="tabsAction">';

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 (count($object->lines) > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
//else print '<a class="butActionRefused" href="#">'.$langs->trans('Validate').'</a>';
}
// 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 '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddAction").'</a>';
}
// Edit
if ($object->statut == 1 && $user->rights->propal->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
}

// ReOpen
if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#reopen').'"';
print '>'.$langs->trans('ReOpen').'</a></div>';
}

// Send
if ($object->statut == 1 || $object->statut == 2)
if ($action != 'statut' && $action <> 'editline')
{
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 '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a></div>';
if (count($object->lines) > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
//else print '<a class="butActionRefused" href="#">'.$langs->trans('Validate').'</a>';
}
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a></div>';
}

// 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 '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddOrder").'</a></div>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddAction").'</a>';
}
}

// 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 '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans('AddContract').'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
}
}

// 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 '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#reopen').'"';
print '>'.$langs->trans('ReOpen').'</a></div>';
}

$arraypropal=$object->getInvoiceArrayList();
if (is_array($arraypropal) && count($arraypropal) > 0)
// Send
if ($object->statut == 1 || $object->statut == 2)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled&amp;socid='.$object->socid.'">'.$langs->trans("ClassifyBilled").'</a></div>';
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a></div>';
}
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a></div>';
}

// Create an order
if (! empty($conf->commande->enabled) && $object->statut == 2 && $user->societe_id == 0)
{
if ($user->rights->commande->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddOrder").'</a></div>';
}
}

// Create contract
if ($conf->contrat->enabled && $object->statut == 2 && $user->societe_id == 0)
{
$langs->load("contracts");

if ($user->rights->contrat->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans('AddContract').'</a></div>';
}
}

// Create an invoice and classify billed
if ($object->statut == 2 && $user->societe_id == 0)
{
if (! empty($conf->facture->enabled) && $user->rights->facture->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
}

$arraypropal=$object->getInvoiceArrayList();
if (is_array($arraypropal) && count($arraypropal) > 0)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled&amp;socid='.$object->socid.'">'.$langs->trans("ClassifyBilled").'</a></div>';
}
}

// Close
if ($object->statut == 1 && $user->rights->propal->cloturer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=statut'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#close').'"';
print '>'.$langs->trans('Close').'</a></div>';
}

// Clone
if ($user->rights->propal->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object='.$object->element.'">'.$langs->trans("ToClone").'</a></div>';
}

// Delete
if ($user->rights->propal->supprimer)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
print '>'.$langs->trans('Delete').'</a></div>';
}

}

// Close
if ($object->statut == 1 && $user->rights->propal->cloturer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=statut'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#close').'"';
print '>'.$langs->trans('Close').'</a></div>';
}

// Clone
if ($user->rights->propal->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object='.$object->element.'">'.$langs->trans("ToClone").'</a></div>';
}

// Delete
if ($user->rights->propal->supprimer)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
print '>'.$langs->trans('Delete').'</a></div>';
}

}

print '</div>';
}
print "<br>\n";
Expand Down
15 changes: 8 additions & 7 deletions htdocs/commande/fiche.php
Expand Up @@ -2392,12 +2392,14 @@
/*
* Boutons actions
*/
if ($action != 'presend')
if ($action != 'presend' && $action != 'editline')
{
if ($user->societe_id == 0 && $action <> 'editline')
{
print '<div class="tabsAction">';
print '<div class="tabsAction">';

$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)
{
Expand Down Expand Up @@ -2470,7 +2472,7 @@
}

// Reopen a closed order
if ($object->statut == 3)
if ($object->statut == 3 && $user->rights->commande->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
}
Expand Down Expand Up @@ -2519,9 +2521,8 @@
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a></div>';
}
}

print '</div>';
}
print '</div>';
}
print '<br>';

Expand Down
12 changes: 7 additions & 5 deletions htdocs/compta/facture.php
Expand Up @@ -3547,12 +3547,14 @@

// 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 '<div class="tabsAction">';
print '<div class="tabsAction">';

$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)
{
Expand Down Expand Up @@ -3580,7 +3582,7 @@
}

// 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
{
Expand Down
16 changes: 9 additions & 7 deletions htdocs/contact/fiche.php
Expand Up @@ -1026,11 +1026,13 @@
print "</div>";

// Barre d'actions
if (! $user->societe_id)
{
print '<div class="tabsAction">';
print '<div class="tabsAction">';

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 '<a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
}
Expand All @@ -1054,10 +1056,10 @@
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&amp;id='.$object->id.'">'.$langs->trans("DisableUser").'</a>';
}

print "</div><br>";
}


print "</div><br>";

print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'','');

print show_actions_todo($conf,$langs,$db,$objsoc,$object);
Expand Down
3 changes: 2 additions & 1 deletion htdocs/core/class/hookmanager.class.php
Expand Up @@ -134,6 +134,7 @@ function executeHooks($method, $parameters=false, &$object='', &$action='')
if (in_array(
$method,
array(
'addMoreActionsButtons',
'addStatisticLine',
'doActions',
'formObjectOptions',
Expand Down Expand Up @@ -164,7 +165,7 @@ function executeHooks($method, $parameters=false, &$object='', &$action='')
// 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)
Expand Down

0 comments on commit 8d91621

Please sign in to comment.