agenda.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  7. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/product/agenda.php
  25. * \ingroup product
  26. * \brief Page of product events
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  34. // Load translation files required by the page
  35. $langs->load("companies");
  36. if (GETPOST('actioncode', 'array')) {
  37. $actioncode = GETPOST('actioncode', 'array', 3);
  38. if (!count($actioncode)) {
  39. $actioncode = '0';
  40. }
  41. } else {
  42. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
  43. }
  44. $search_rowid = GETPOST('search_rowid');
  45. $search_agenda_label = GETPOST('search_agenda_label');
  46. // Security check
  47. $id = GETPOST('id', 'int');
  48. $ref = GETPOST('ref', 'alpha');
  49. if ($user->socid) {
  50. $id = $user->socid;
  51. }
  52. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  53. $sortfield = GETPOST('sortfield', 'aZ09comma');
  54. $sortorder = GETPOST('sortorder', 'aZ09comma');
  55. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  56. if (empty($page) || $page == -1) {
  57. $page = 0;
  58. } // If $page is not defined, or '' or -1
  59. $offset = $limit * $page;
  60. $pageprev = $page - 1;
  61. $pagenext = $page + 1;
  62. if (!$sortfield) {
  63. $sortfield = 'a.datep,a.id';
  64. }
  65. if (!$sortorder) {
  66. $sortorder = 'DESC,DESC';
  67. }
  68. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  69. $hookmanager->initHooks(array('agendathirdparty'));
  70. $object = new Product($db);
  71. if ($id > 0 || !empty($ref)) {
  72. $object->fetch($id, $ref);
  73. }
  74. if ($object->id > 0) {
  75. if ($object->type == $object::TYPE_PRODUCT) {
  76. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  77. }
  78. if ($object->type == $object::TYPE_SERVICE) {
  79. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  80. }
  81. } else {
  82. restrictedArea($user, 'produit|service', 0, 'product&product', '', '');
  83. }
  84. /*
  85. * Actions
  86. */
  87. $parameters = array('id'=>$id);
  88. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  89. if ($reshook < 0) {
  90. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  91. }
  92. if (empty($reshook)) {
  93. // Cancel
  94. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  95. header("Location: ".$backtopage);
  96. exit;
  97. }
  98. // Purge search criteria
  99. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  100. $actioncode = '';
  101. $search_agenda_label = '';
  102. }
  103. }
  104. /*
  105. * View
  106. */
  107. $contactstatic = new Contact($db);
  108. $form = new Form($db);
  109. if ($id > 0 || $ref) {
  110. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  111. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  112. $langs->load("companies");
  113. $object = new Product($db);
  114. $result = $object->fetch($id, $ref);
  115. $title = $langs->trans("Agenda");
  116. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda';
  117. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/productnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  118. $title = $object->name." - ".$title;
  119. }
  120. llxHeader('', $title, $help_url);
  121. if (isModEnabled('notification')) {
  122. $langs->load("mails");
  123. }
  124. $type = $langs->trans('Product');
  125. if ($object->isService()) {
  126. $type = $langs->trans('Service');
  127. }
  128. $head = product_prepare_head($object);
  129. $titre = $langs->trans("CardProduct".$object->type);
  130. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  131. print dol_get_fiche_head($head, 'agenda', $titre, -1, $picto);
  132. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  133. $object->next_prev_filter = " fk_product_type = ".$object->type;
  134. $shownav = 1;
  135. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  136. $shownav = 0;
  137. }
  138. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
  139. print '<div class="fichecenter">';
  140. print '<div class="underbanner clearboth"></div>';
  141. $object->info($object->id);
  142. dol_print_object_info($object, 1);
  143. print '</div>';
  144. print dol_get_fiche_end();
  145. // Actions buttons
  146. $objproduct = $object;
  147. $objcon = new stdClass();
  148. $out = '';
  149. $morehtmlcenter = '';
  150. if (isModEnabled('agenda')) {
  151. $permok = $user->rights->agenda->myactions->create;
  152. if ((!empty($objproduct->id) || !empty($objcon->id)) && $permok) {
  153. if (get_class($objproduct) == 'Product') {
  154. $out .= '&amp;prodid='.$objproduct->id.'&origin=product&originid='.$id;
  155. }
  156. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage='.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;percentage=-1';
  157. }
  158. $linktocreatetimeBtnStatus = !empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create);
  159. $morehtmlcenter = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', $linktocreatetimeBtnStatus);
  160. }
  161. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  162. print '<br>';
  163. $param = '&id='.$id;
  164. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  165. $param .= '&contextpage='.$contextpage;
  166. }
  167. if ($limit > 0 && $limit != $conf->liste_limit) {
  168. $param .= '&limit='.$limit;
  169. }
  170. print_barre_liste($langs->trans("ActionsOnProduct"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlcenter, '', 0, 1, 1);
  171. // List of all actions
  172. $filters = array();
  173. $filters['search_agenda_label'] = $search_agenda_label;
  174. $filters['search_rowid'] = $search_rowid;
  175. // TODO Replace this with same code than into list.php
  176. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  177. }
  178. }
  179. // End of page
  180. llxFooter();
  181. $db->close();