agenda.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /* Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
  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 htdocs/commande/agenda.php
  19. * \ingroup commande
  20. * \brief Tab of events on Sale Orders
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("order", "other"));
  31. // Get parameters
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alpha');
  34. $action = GETPOST('action', 'aZ09');
  35. $cancel = GETPOST('cancel', 'aZ09');
  36. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. if (GETPOST('actioncode', 'array')) {
  39. $actioncode = GETPOST('actioncode', 'array', 3);
  40. if (!count($actioncode)) {
  41. $actioncode = '0';
  42. }
  43. } else {
  44. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  45. }
  46. $search_rowid = GETPOST('search_rowid');
  47. $search_agenda_label = GETPOST('search_agenda_label');
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortfield) {
  59. $sortfield = 'a.datep,a.id';
  60. }
  61. if (!$sortorder) {
  62. $sortorder = 'DESC,DESC';
  63. }
  64. // Initialize technical objects
  65. $object = new Commande($db);
  66. $extrafields = new ExtraFields($db);
  67. $diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
  68. $hookmanager->initHooks(array('orderagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  69. // Fetch optionals attributes and labels
  70. $extrafields->fetch_name_optionals_label($object->table_element);
  71. // Load object
  72. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  73. if ($id > 0 || !empty($ref)) {
  74. $upload_dir = $conf->commande->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
  75. }
  76. $permissiontoread = $user->hasRight("commande", "lire");
  77. $permissiontoadd = $user->hasRight("commande", "creer");
  78. // Security check
  79. if (!empty($user->socid)) {
  80. $socid = $user->socid;
  81. }
  82. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  83. restrictedArea($user, 'commande', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
  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. $form = new Form($db);
  108. if ($object->id > 0) {
  109. $title = $langs->trans("Agenda");
  110. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  111. $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
  112. llxHeader('', $title, $help_url);
  113. if (isModEnabled('notification')) {
  114. $langs->load("mails");
  115. }
  116. $head = commande_prepare_head($object);
  117. print dol_get_fiche_head($head, 'agenda', $langs->trans("Order"), -1, $object->picto);
  118. // Object card
  119. // ------------------------------------------------------------
  120. $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  121. $morehtmlref = '<div class="refidno">';
  122. // Ref customer
  123. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  124. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  125. // Thirdparty
  126. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  127. // Project
  128. if (isModEnabled('project')) {
  129. $langs->load("projects");
  130. $morehtmlref .= '<br>';
  131. if (0) {
  132. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  133. if ($action != 'classify') {
  134. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  135. }
  136. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  137. } else {
  138. if (!empty($object->fk_project)) {
  139. $proj = new Project($db);
  140. $proj->fetch($object->fk_project);
  141. $morehtmlref .= $proj->getNomUrl(1);
  142. if ($proj->title) {
  143. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  144. }
  145. }
  146. }
  147. }
  148. $morehtmlref .= '</div>';
  149. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  150. print '<div class="fichecenter">';
  151. print '<div class="underbanner clearboth"></div>';
  152. $object->info($object->id);
  153. dol_print_object_info($object, 1);
  154. print '</div>';
  155. print dol_get_fiche_end();
  156. // Actions buttons
  157. $objthirdparty = $object;
  158. $objcon = new stdClass();
  159. $out = '&origin='.urlencode($object->element.(property_exists($object, 'module') ? '@'.$object->module : '')).'&originid='.urlencode($object->id);
  160. $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  161. $out .= '&backtopage='.urlencode($urlbacktopage);
  162. $permok = $user->hasRight('agenda', 'myactions', 'create');
  163. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  164. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  165. if (get_class($objthirdparty) == 'Societe') {
  166. $out .= '&socid='.urlencode($objthirdparty->id);
  167. }
  168. $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '');
  169. //$out.=$langs->trans("AddAnAction").' ';
  170. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  171. //$out.="</a>";
  172. }
  173. $morehtmlright = '';
  174. //$messagingUrl = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
  175. //$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
  176. //$messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  177. //$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
  178. if (isModEnabled('agenda')) {
  179. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  180. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  181. } else {
  182. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', 0);
  183. }
  184. }
  185. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  186. print '<br>';
  187. $param = '&id='.$object->id.(!empty($socid) ? '&socid='.$socid : '');
  188. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  189. $param .= '&contextpage='.urlencode($contextpage);
  190. }
  191. if ($limit > 0 && $limit != $conf->liste_limit) {
  192. $param .= '&limit='.((int) $limit);
  193. }
  194. // Try to know count of actioncomm from cache
  195. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  196. $cachekey = 'count_events_commande_'.$object->id;
  197. $nbEvent = dol_getcache($cachekey);
  198. print_barre_liste($langs->trans("ActionsOnOrder").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : ''), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  199. //print_barre_liste($langs->trans("ActionsOnOrder"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  200. // List of all actions
  201. $filters = array();
  202. $filters['search_agenda_label'] = $search_agenda_label;
  203. $filters['search_rowid'] = $search_rowid;
  204. // TODO Replace this with same code than into list.php
  205. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, property_exists($object, 'module') ? $object->module : '');
  206. }
  207. }
  208. // End of page
  209. llxFooter();
  210. $db->close();