actions_eventwizard.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. /* Copyright (C) 2023 Deák Ferenc
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file eventwizard/class/actions_eventwizard.class.php
  19. * \ingroup eventwizard
  20. * \brief Example hook overload.
  21. *
  22. * Put detailed description here.
  23. */
  24. /**
  25. * Class ActionsEventWizard
  26. */
  27. class ActionsEventWizard
  28. {
  29. /**
  30. * @var DoliDB Database handler.
  31. */
  32. public $db;
  33. /**
  34. * @var string Error code (or message)
  35. */
  36. public $error = '';
  37. /**
  38. * @var array Errors
  39. */
  40. public $errors = array();
  41. /**
  42. * @var array Hook results. Propagated to $hookmanager->resArray for later reuse
  43. */
  44. public $results = array();
  45. /**
  46. * @var string String displayed by executeHook() immediately after return
  47. */
  48. public $resprints;
  49. /**
  50. * @var int Priority of hook (50 is used if value is not defined)
  51. */
  52. public $priority;
  53. /**
  54. * Constructor
  55. *
  56. * @param DoliDB $db Database handler
  57. */
  58. public function __construct($db)
  59. {
  60. $this->db = $db;
  61. }
  62. /**
  63. * Execute action
  64. *
  65. * @param array $parameters Array of parameters
  66. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  67. * @param string $action 'add', 'update', 'view'
  68. * @return int <0 if KO,
  69. * =0 if OK but we want to process standard actions too,
  70. * >0 if OK and we want to replace standard actions.
  71. */
  72. public function getNomUrl($parameters, &$object, &$action)
  73. {
  74. global $db, $langs, $conf, $user;
  75. $this->resprints = '';
  76. return 0;
  77. }
  78. /**
  79. * Overloading the doActions function : replacing the parent's function with the one below
  80. *
  81. * @param array $parameters Hook metadatas (context, etc...)
  82. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  83. * @param string $action Current action (if set). Generally create or edit or null
  84. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  85. * @return int < 0 on error, 0 on success, 1 to replace standard code
  86. */
  87. public function doActions($parameters, &$object, &$action, $hookmanager)
  88. {
  89. global $conf, $user, $langs;
  90. $error = 0; // Error counter
  91. // print_r($parameters); print_r($object); echo "action: " . $action; exit;
  92. if($parameters['currentcontext']=='actioncard'){
  93. // print_r($user->rights);
  94. if($user->rights->eventwizard){
  95. $user->rights->eventdetails=$user->rights->eventwizard->eventdetails;
  96. }
  97. }
  98. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
  99. // Do what you want here...
  100. // You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
  101. }
  102. if (!$error) {
  103. $this->results = array('myreturn' => 999);
  104. $this->resprints = 'A text to show';
  105. return 0; // or return 1 to replace standard code
  106. } else {
  107. $this->errors[] = 'Error message';
  108. return -1;
  109. }
  110. }
  111. /**
  112. * Overloading the doMassActions function : replacing the parent's function with the one below
  113. *
  114. * @param array $parameters Hook metadatas (context, etc...)
  115. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  116. * @param string $action Current action (if set). Generally create or edit or null
  117. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  118. * @return int < 0 on error, 0 on success, 1 to replace standard code
  119. */
  120. public function doMassActions($parameters, &$object, &$action, $hookmanager)
  121. {
  122. global $conf, $user, $langs;
  123. $error = 0; // Error counter
  124. /* print_r($parameters); print_r($object); echo "action: " . $action; */
  125. print_r($parameters); print_r($object); echo "action: " . $action; exit;
  126. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
  127. foreach ($parameters['toselect'] as $objectid) {
  128. // Do action on each object id
  129. }
  130. }
  131. if (!$error) {
  132. $this->results = array('myreturn' => 999);
  133. $this->resprints = 'A text to show';
  134. return 0; // or return 1 to replace standard code
  135. } else {
  136. $this->errors[] = 'Error message';
  137. return -1;
  138. }
  139. }
  140. /**
  141. * Overloading the addMoreMassActions function : replacing the parent's function with the one below
  142. *
  143. * @param array $parameters Hook metadatas (context, etc...)
  144. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  145. * @param string $action Current action (if set). Generally create or edit or null
  146. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  147. * @return int < 0 on error, 0 on success, 1 to replace standard code
  148. */
  149. public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
  150. {
  151. global $conf, $user, $langs;
  152. $error = 0; // Error counter
  153. $disabled = 1;
  154. /* print_r($parameters); print_r($object); echo "action: " . $action; */
  155. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
  156. $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("EventWizardMassAction").'</option>';
  157. }
  158. if (!$error) {
  159. return 0; // or return 1 to replace standard code
  160. } else {
  161. $this->errors[] = 'Error message';
  162. return -1;
  163. }
  164. }
  165. /**
  166. * Execute action
  167. *
  168. * @param array $parameters Array of parameters
  169. * @param Object $object Object output on PDF
  170. * @param string $action 'add', 'update', 'view'
  171. * @return int <0 if KO,
  172. * =0 if OK but we want to process standard actions too,
  173. * >0 if OK and we want to replace standard actions.
  174. */
  175. public function beforePDFCreation($parameters, &$object, &$action)
  176. {
  177. global $conf, $user, $langs;
  178. global $hookmanager;
  179. $outputlangs = $langs;
  180. $ret = 0; $deltemp = array();
  181. dol_syslog(get_class($this).'::executeHooks action='.$action);
  182. /* print_r($parameters); print_r($object); echo "action: " . $action; */
  183. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
  184. }
  185. return $ret;
  186. }
  187. /**
  188. * Execute action
  189. *
  190. * @param array $parameters Array of parameters
  191. * @param Object $pdfhandler PDF builder handler
  192. * @param string $action 'add', 'update', 'view'
  193. * @return int <0 if KO,
  194. * =0 if OK but we want to process standard actions too,
  195. * >0 if OK and we want to replace standard actions.
  196. */
  197. public function afterPDFCreation($parameters, &$pdfhandler, &$action)
  198. {
  199. global $conf, $user, $langs;
  200. global $hookmanager;
  201. $outputlangs = $langs;
  202. $ret = 0; $deltemp = array();
  203. dol_syslog(get_class($this).'::executeHooks action='.$action);
  204. /* print_r($parameters); print_r($object); echo "action: " . $action; */
  205. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
  206. // do something only for the context 'somecontext1' or 'somecontext2'
  207. }
  208. return $ret;
  209. }
  210. /**
  211. * Overloading the loadDataForCustomReports function : returns data to complete the customreport tool
  212. *
  213. * @param array $parameters Hook metadatas (context, etc...)
  214. * @param string $action Current action (if set). Generally create or edit or null
  215. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  216. * @return int < 0 on error, 0 on success, 1 to replace standard code
  217. */
  218. public function loadDataForCustomReports($parameters, &$action, $hookmanager)
  219. {
  220. global $conf, $user, $langs;
  221. $langs->load("eventwizard@eventwizard");
  222. $this->results = array();
  223. $head = array();
  224. $h = 0;
  225. if ($parameters['tabfamily'] == 'eventwizard') {
  226. $head[$h][0] = dol_buildpath('/module/index.php', 1);
  227. $head[$h][1] = $langs->trans("Home");
  228. $head[$h][2] = 'home';
  229. $h++;
  230. $this->results['title'] = $langs->trans("EventWizard");
  231. $this->results['picto'] = 'eventwizard@eventwizard';
  232. }
  233. $head[$h][0] = 'customreports.php?objecttype='.$parameters['objecttype'].(empty($parameters['tabfamily']) ? '' : '&tabfamily='.$parameters['tabfamily']);
  234. $head[$h][1] = $langs->trans("CustomReports");
  235. $head[$h][2] = 'customreports';
  236. $this->results['head'] = $head;
  237. return 1;
  238. }
  239. /**
  240. * Overloading the restrictedArea function : check permission on an object
  241. *
  242. * @param array $parameters Hook metadatas (context, etc...)
  243. * @param string $action Current action (if set). Generally create or edit or null
  244. * @param HookManager $hookmanager Hook manager propagated to allow calling another hook
  245. * @return int <0 if KO,
  246. * =0 if OK but we want to process standard actions too,
  247. * >0 if OK and we want to replace standard actions.
  248. */
  249. public function restrictedArea($parameters, &$action, $hookmanager)
  250. {
  251. global $user;
  252. if ($parameters['features'] == 'myobject') {
  253. if ($user->rights->eventwizard->myobject->read) {
  254. $this->results['result'] = 1;
  255. return 1;
  256. } else {
  257. $this->results['result'] = 0;
  258. return 1;
  259. }
  260. }
  261. return 0;
  262. }
  263. /**
  264. * Execute action completeTabsHead
  265. *
  266. * @param array $parameters Array of parameters
  267. * @param CommonObject $object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
  268. * @param string $action 'add', 'update', 'view'
  269. * @param Hookmanager $hookmanager hookmanager
  270. * @return int <0 if KO,
  271. * =0 if OK but we want to process standard actions too,
  272. * >0 if OK and we want to replace standard actions.
  273. */
  274. public function completeTabsHead(&$parameters, &$object, &$action, $hookmanager)
  275. {
  276. global $langs, $conf, $user;
  277. if (!isset($parameters['object']->element)) {
  278. return 0;
  279. }
  280. if ($parameters['mode'] == 'remove') {
  281. // utilisé si on veut faire disparaitre des onglets.
  282. return 0;
  283. } elseif ($parameters['mode'] == 'add') {
  284. $langs->load('eventwizard@eventwizard');
  285. // utilisé si on veut ajouter des onglets.
  286. $counter = count($parameters['head']);
  287. $element = $parameters['object']->element;
  288. $id = $parameters['object']->id;
  289. // verifier le type d'onglet comme member_stats où ça ne doit pas apparaitre
  290. // if (in_array($element, ['societe', 'member', 'contrat', 'fichinter', 'project', 'propal', 'commande', 'facture', 'order_supplier', 'invoice_supplier'])) {
  291. if (in_array($element, ['context1', 'context2'])) {
  292. $datacount = 0;
  293. $parameters['head'][$counter][0] = dol_buildpath('/eventwizard/eventwizard_tab.php', 1) . '?id=' . $id . '&amp;module='.$element;
  294. $parameters['head'][$counter][1] = $langs->trans('EventWizardTab');
  295. if ($datacount > 0) {
  296. $parameters['head'][$counter][1] .= '<span class="badge marginleftonlyshort">' . $datacount . '</span>';
  297. }
  298. $parameters['head'][$counter][2] = 'eventwizardemails';
  299. $counter++;
  300. }
  301. if ($counter > 0 && (int) DOL_VERSION < 14) {
  302. $this->results = $parameters['head'];
  303. // return 1 to replace standard code
  304. return 1;
  305. } else {
  306. // en V14 et + $parameters['head'] est modifiable par référence
  307. return 0;
  308. }
  309. }
  310. }
  311. /* Add here any other hooked methods... */
  312. public function formAddObjectLine($parameters, &$object, &$action, $hookmanager)
  313. {
  314. global $conf, $user, $langs;
  315. $error = 0; // Error counter
  316. // print_r($parameters); print_r($object); echo "action: " . $action;
  317. print '<a class="btnTitle btnTitlePlus" style="float: inline-end;" href="/custom/eventwizard/eventproduct_card.php?action=create&amp;fk_eventdetails='.$object->id.'&amp;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>';
  318. $this->results = array('myreturn' => 999);
  319. $this->resprints = 'A text to show';
  320. return 1;
  321. }
  322. public function printObjectLine($parameters, &$object, &$action, $hookmanager)
  323. {
  324. global $conf, $user, $langs;
  325. // print_r($parameters['line']);
  326. $error = 0; // Error counter
  327. // lines
  328. // 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>';
  329. // print_r($parameters);
  330. global $form;
  331. global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this !
  332. $line = $parameters['line'];
  333. $object_rights = $line->getRights();
  334. $element = $this->element;
  335. $text = '';
  336. $description = '';
  337. // Line in view mode
  338. if ($action != 'editline' || $selected != $line->id) {
  339. // Product
  340. if ($line->fk_product > 0) {
  341. $product_static = new Product($this->db);
  342. $product_static->fetch($line->fk_product);
  343. $option_static = new EventOption($this->db);
  344. $option_static->fetch($line->fk_eventoption);
  345. // $product_static->ref = $line->ref; //can change ref in hook
  346. // $product_static->label = !empty($line->label) ? $line->label : ""; //can change label in hook
  347. // $text = $product_static->getNomUrl(1);
  348. $text = $line->getNomUrl(1);
  349. $product_text = $product_static->getNomUrl(1);
  350. $option_text = $option_static->getNomUrl(1);
  351. // Define output language and label
  352. if (!empty($conf->global->MAIN_MULTILANGS)) {
  353. if (property_exists($this, 'socid') && !is_object($this->thirdparty)) {
  354. dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
  355. return;
  356. }
  357. $prod = new Product($this->db);
  358. $prod->fetch($line->fk_product);
  359. $outputlangs = $langs;
  360. $newlang = '';
  361. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  362. $newlang = GETPOST('lang_id', 'aZ09');
  363. }
  364. if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
  365. $newlang = $this->thirdparty->default_lang; // To use language of customer
  366. }
  367. if (!empty($newlang)) {
  368. $outputlangs = new Translate("", $conf);
  369. $outputlangs->setDefaultLang($newlang);
  370. }
  371. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label;
  372. } else {
  373. $label = $line->product_label;
  374. }
  375. $text .= ' - '.(!empty($line->label) ? $line->label : $label);
  376. $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.
  377. }
  378. $line->pu_ttc = price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)), 'MU');
  379. // $line->pu_ttc = 0;
  380. // Output template part (modules that overwrite templates must declare this into descriptor)
  381. // Use global variables + $dateSelector + $seller and $buyer
  382. // Note: This is deprecated. If you need to overwrite the tpl file, use instead the hook printObjectLine and printObjectSubLine.
  383. print '<tr id="row-1" class="drag drop oddeven" data-element="eventdetailsline" data-id="'.$line->id.'" data-qty="0" data-product_type="">
  384. <td class="linecoldescription minwidth300imp">
  385. <div id="line_$line->id"></div>
  386. '.$text.'
  387. </td>
  388. <td class="linecolvat nowrap right">
  389. '.$product_text.'
  390. </td>
  391. <td class="linecoluht nowrap right">'.$option_text.'</td>
  392. <td class="linecoluht_currency nowrap right">'.$option_static->fields['type']['arrayofkeyval'][$option_static->type].'</td>
  393. <td class="linecolqty nowrap right">'.(($line->qty==0)?'∞':$line->qty).'</td>'.
  394. // <td class="linecoldiscount">&nbsp;</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>
  395. '</tr>';
  396. }
  397. // Line in update mode
  398. if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) {
  399. $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : ''));
  400. $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU');
  401. // Output template part (modules that overwrite templates must declare this into descriptor)
  402. // Use global variables + $dateSelector + $seller and $buyer
  403. // Note: This is deprecated. If you need to overwrite the tpl file, use instead the hook printObjectLine and printObjectSubLine.
  404. $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir));
  405. foreach ($dirtpls as $module => $reldir) {
  406. if (!empty($module)) {
  407. $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php');
  408. } else {
  409. $tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_edit.tpl.php';
  410. }
  411. if (empty($conf->file->strict_mode)) {
  412. $res = @include $tpl;
  413. } else {
  414. $res = include $tpl; // for debug
  415. }
  416. if ($res) {
  417. break;
  418. }
  419. }
  420. }
  421. return 1;
  422. }
  423. public function printObjectLineTitle($parameters, &$object, &$action, $hookmanager)
  424. {
  425. global $conf, $user, $langs;
  426. $error = 0; // Error counter
  427. // print_r($parameters); print_r($object); echo "action: " . $action;
  428. print '<thead><tr class="liste_titre nodrag nodrop"><td class="linecoldescription"></td>
  429. <td class="linecolvat right nowraponall">'.$langs->trans("Esemény termékei").'</td>
  430. <td class="linecoluht right nowraponall">'.$langs->trans("Szolgáltatás / Termék").'</td>
  431. <td class="linecoluht_currency right" style="width: 80px">'.$langs->trans("Választhatóság").'</td>
  432. <td class="linecolqty right">'.$langs->trans("Max").'</td>
  433. </tr></thead>';
  434. return 1;
  435. if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
  436. // Do what you want here...
  437. // You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
  438. }
  439. if (!$error) {
  440. $this->results = array('myreturn' => 999);
  441. $this->resprints = 'A text to show';
  442. return 0; // or return 1 to replace standard code
  443. } else {
  444. $this->errors[] = 'Error message';
  445. return -1;
  446. }
  447. }
  448. }