| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- <?php
- /* Copyright (C) 2023 Deák Ferenc
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \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 = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("EventWizardMassAction").'</option>';
- }
- 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] .= '<span class="badge marginleftonlyshort">' . $datacount . '</span>';
- }
- $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 '<a class="btnTitle btnTitlePlus" style="float: inline-end;" href="/custom/eventwizard/eventproduct_card.php?action=create&fk_eventdetails='.$object->id.'&backtopage=%2Fcustom%2Feventwizard%2Feventproduct_list.php%3F%26fk_eventdetails%3D'.$object->id.'" title="New"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a>';
- $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 '<thead><tr class="liste_titre nodrag nodrop"><td class="linecoldescription">Description</td><td class="linecolvat right nowraponall">VAT</td><td class="linecoluht right nowraponall">U.P. (net)</td><td class="linecoluht_currency right" style="width: 80px">U.P (net) (currency)</td><td class="linecolqty right">Qty</td><td class="linecoldiscount right nowraponall">ReductionShort</td><td class="linecolht right">Total (excl.)</td><td class="linecoltotalht_currency right">Total (excl. in currency)</td><td class="linecoledit"></td><td class="linecoldelete" style="width: 10px"></td><td class="linecolmove" style="width: 10px"></td></tr></thead>';
- // 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 '<tr id="row-1" class="drag drop oddeven" data-element="eventdetailsline" data-id="'.$line->id.'" data-qty="0" data-product_type="">
- <td class="linecoldescription minwidth300imp">
- <div id="line_$line->id"></div>
- '.$text.'
- </td>
- <td class="linecolvat nowrap right">
- '.$product_text.'
- </td>
- <td class="linecoluht nowrap right">'.$option_text.'</td>
- <td class="linecoluht_currency nowrap right">'.$option_static->fields['type']['arrayofkeyval'][$option_static->type].'</td>
- <td class="linecolqty nowrap right">'.(($line->qty==0)?'∞':$line->qty).'</td>'.
-
- // <td class="linecoldiscount"> </td><td class="linecolht nowrap right"><span class="classfortooltip" title="Total (excl. tax)=0<br>Total VAT=0<br>Total (inc. tax)=0">0</span></td><td class="linecolutotalht_currency nowrap right">0</td><td colspan="3"></td>
- '</tr>';
- }
- // Line in update mode
- if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) {
- $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : ''));
- $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU');
- // 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.
- $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
- foreach ($dirtpls as $module => $reldir) {
- if (!empty($module)) {
- $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php');
- } else {
- $tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_edit.tpl.php';
- }
- if (empty($conf->file->strict_mode)) {
- $res = @include $tpl;
- } else {
- $res = include $tpl; // for debug
- }
- if ($res) {
- break;
- }
- }
- }
-
- return 1;
- }
- public function printObjectLineTitle($parameters, &$object, &$action, $hookmanager)
- {
- global $conf, $user, $langs;
-
- $error = 0; // Error counter
- // print_r($parameters); print_r($object); echo "action: " . $action;
- print '<thead><tr class="liste_titre nodrag nodrop"><td class="linecoldescription"></td>
- <td class="linecolvat right nowraponall">'.$langs->trans("Esemény termékei").'</td>
- <td class="linecoluht right nowraponall">'.$langs->trans("Szolgáltatás / Termék").'</td>
- <td class="linecoluht_currency right" style="width: 80px">'.$langs->trans("Választhatóság").'</td>
- <td class="linecolqty right">'.$langs->trans("Max").'</td>
- </tr></thead>';
- return 1;
- 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;
- }
- }
- }
|