.
*/
/**
* \file eventwizard/class/actions_eventwizard.class.php
* \ingroup eventwizard
* \brief Example hook overload.
*
* Put detailed description here.
*/
/**
* Class ActionsEventWizard
*/
class ActionsEventWizard
{
/**
* @var DoliDB Database handler.
*/
public $db;
/**
* @var string Error code (or message)
*/
public $error = '';
/**
* @var array Errors
*/
public $errors = array();
/**
* @var array Hook results. Propagated to $hookmanager->resArray for later reuse
*/
public $results = array();
/**
* @var string String displayed by executeHook() immediately after return
*/
public $resprints;
/**
* @var int Priority of hook (50 is used if value is not defined)
*/
public $priority;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Execute action
*
* @param array $parameters Array of parameters
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action 'add', 'update', 'view'
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
public function getNomUrl($parameters, &$object, &$action)
{
global $db, $langs, $conf, $user;
$this->resprints = '';
return 0;
}
/**
* Overloading the doActions function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
public function doActions($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;
$error = 0; // Error counter
// print_r($parameters); print_r($object); echo "action: " . $action; exit;
if($parameters['currentcontext']=='actioncard'){
// print_r($user->rights);
if($user->rights->eventwizard){
$user->rights->eventdetails=$user->rights->eventwizard->eventdetails;
}
}
if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
// Do what you want here...
// You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
}
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the doMassActions function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
public function doMassActions($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;
$error = 0; // Error counter
/* print_r($parameters); print_r($object); echo "action: " . $action; */
print_r($parameters); print_r($object); echo "action: " . $action; exit;
if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
foreach ($parameters['toselect'] as $objectid) {
// Do action on each object id
}
}
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Overloading the addMoreMassActions function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;
$error = 0; // Error counter
$disabled = 1;
/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
$this->resprints = '';
}
if (!$error) {
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}
/**
* Execute action
*
* @param array $parameters Array of parameters
* @param Object $object Object output on PDF
* @param string $action 'add', 'update', 'view'
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
public function beforePDFCreation($parameters, &$object, &$action)
{
global $conf, $user, $langs;
global $hookmanager;
$outputlangs = $langs;
$ret = 0; $deltemp = array();
dol_syslog(get_class($this).'::executeHooks action='.$action);
/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
}
return $ret;
}
/**
* Execute action
*
* @param array $parameters Array of parameters
* @param Object $pdfhandler PDF builder handler
* @param string $action 'add', 'update', 'view'
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
public function afterPDFCreation($parameters, &$pdfhandler, &$action)
{
global $conf, $user, $langs;
global $hookmanager;
$outputlangs = $langs;
$ret = 0; $deltemp = array();
dol_syslog(get_class($this).'::executeHooks action='.$action);
/* print_r($parameters); print_r($object); echo "action: " . $action; */
if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
// do something only for the context 'somecontext1' or 'somecontext2'
}
return $ret;
}
/**
* Overloading the loadDataForCustomReports function : returns data to complete the customreport tool
*
* @param array $parameters Hook metadatas (context, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int < 0 on error, 0 on success, 1 to replace standard code
*/
public function loadDataForCustomReports($parameters, &$action, $hookmanager)
{
global $conf, $user, $langs;
$langs->load("eventwizard@eventwizard");
$this->results = array();
$head = array();
$h = 0;
if ($parameters['tabfamily'] == 'eventwizard') {
$head[$h][0] = dol_buildpath('/module/index.php', 1);
$head[$h][1] = $langs->trans("Home");
$head[$h][2] = 'home';
$h++;
$this->results['title'] = $langs->trans("EventWizard");
$this->results['picto'] = 'eventwizard@eventwizard';
}
$head[$h][0] = 'customreports.php?objecttype='.$parameters['objecttype'].(empty($parameters['tabfamily']) ? '' : '&tabfamily='.$parameters['tabfamily']);
$head[$h][1] = $langs->trans("CustomReports");
$head[$h][2] = 'customreports';
$this->results['head'] = $head;
return 1;
}
/**
* Overloading the restrictedArea function : check permission on an object
*
* @param array $parameters Hook metadatas (context, etc...)
* @param string $action Current action (if set). Generally create or edit or null
* @param HookManager $hookmanager Hook manager propagated to allow calling another hook
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
public function restrictedArea($parameters, &$action, $hookmanager)
{
global $user;
if ($parameters['features'] == 'myobject') {
if ($user->rights->eventwizard->myobject->read) {
$this->results['result'] = 1;
return 1;
} else {
$this->results['result'] = 0;
return 1;
}
}
return 0;
}
/**
* Execute action completeTabsHead
*
* @param array $parameters Array of parameters
* @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param string $action 'add', 'update', 'view'
* @param Hookmanager $hookmanager hookmanager
* @return int <0 if KO,
* =0 if OK but we want to process standard actions too,
* >0 if OK and we want to replace standard actions.
*/
public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
{
global $langs, $conf, $user;
if (!isset($parameters['object']->element)) {
return 0;
}
if ($parameters['mode'] == 'remove') {
// utilisé si on veut faire disparaitre des onglets.
return 0;
} elseif ($parameters['mode'] == 'add') {
$langs->load('eventwizard@eventwizard');
// utilisé si on veut ajouter des onglets.
$counter = count($parameters['head']);
$element = $parameters['object']->element;
$id = $parameters['object']->id;
// verifier le type d'onglet comme member_stats où ça ne doit pas apparaitre
// if (in_array($element, ['societe', 'member', 'contrat', 'fichinter', 'project', 'propal', 'commande', 'facture', 'order_supplier', 'invoice_supplier'])) {
if (in_array($element, ['context1', 'context2'])) {
$datacount = 0;
$parameters['head'][$counter][0] = dol_buildpath('/eventwizard/eventwizard_tab.php', 1) . '?id=' . $id . '&module='.$element;
$parameters['head'][$counter][1] = $langs->trans('EventWizardTab');
if ($datacount > 0) {
$parameters['head'][$counter][1] .= '' . $datacount . '';
}
$parameters['head'][$counter][2] = 'eventwizardemails';
$counter++;
}
if ($counter > 0 && (int) DOL_VERSION < 14) {
$this->results = $parameters['head'];
// return 1 to replace standard code
return 1;
} else {
// en V14 et + $parameters['head'] est modifiable par référence
return 0;
}
}
}
/* Add here any other hooked methods... */
public function formAddObjectLine($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;
$error = 0; // Error counter
// print_r($parameters); print_r($object); echo "action: " . $action;
print '';
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 1;
}
public function printObjectLine($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;
// print_r($parameters['line']);
$error = 0; // Error counter
// lines
// print ' ';
// print_r($parameters);
global $form;
global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this !
$line = $parameters['line'];
$object_rights = $line->getRights();
$element = $this->element;
$text = '';
$description = '';
// Line in view mode
if ($action != 'editline' || $selected != $line->id) {
// Product
if ($line->fk_product > 0) {
$product_static = new Product($this->db);
$product_static->fetch($line->fk_product);
$option_static = new EventOption($this->db);
$option_static->fetch($line->fk_eventoption);
// $product_static->ref = $line->ref; //can change ref in hook
// $product_static->label = !empty($line->label) ? $line->label : ""; //can change label in hook
// $text = $product_static->getNomUrl(1);
$text = $line->getNomUrl(1);
$product_text = $product_static->getNomUrl(1);
$option_text = $option_static->getNomUrl(1);
// Define output language and label
if (!empty($conf->global->MAIN_MULTILANGS)) {
if (property_exists($this, 'socid') && !is_object($this->thirdparty)) {
dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
return;
}
$prod = new Product($this->db);
$prod->fetch($line->fk_product);
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
}
if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
$newlang = $this->thirdparty->default_lang; // To use language of customer
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label;
} else {
$label = $line->product_label;
}
$text .= ' - '.(!empty($line->label) ? $line->label : $label);
$description .= (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : (!empty($line->description) ? dol_htmlentitiesbr($line->description) : '')); // Description is what to show on popup. We shown nothing if already into desc.
}
$line->pu_ttc = price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)), 'MU');
// $line->pu_ttc = 0;
// Output template part (modules that overwrite templates must declare this into descriptor)
// Use global variables + $dateSelector + $seller and $buyer
// Note: This is deprecated. If you need to overwrite the tpl file, use instead the hook printObjectLine and printObjectSubLine.
print 'Description VAT U.P. (net) U.P (net) (currency) Qty ReductionShort Total (excl.) Total (excl. in currency)