agenda.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/fichinter/agenda.php
  20. * \ingroup fichinter
  21. * \brief Tab of events on Interventions
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("fichinter", "other"));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. $cancel = GETPOST('cancel', 'aZ09');
  37. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  38. $backtopage = GETPOST('backtopage', 'alpha');
  39. if (GETPOST('actioncode', 'array')) {
  40. $actioncode = GETPOST('actioncode', 'array', 3);
  41. if (!count($actioncode)) {
  42. $actioncode = '0';
  43. }
  44. } else {
  45. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  46. }
  47. $search_rowid = GETPOST('search_rowid');
  48. $search_agenda_label = GETPOST('search_agenda_label');
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (!$sortfield) {
  60. $sortfield = 'a.datep,a.id';
  61. }
  62. if (!$sortorder) {
  63. $sortorder = 'DESC,DESC';
  64. }
  65. // Initialize technical objects
  66. $object = new Fichinter($db);
  67. $extrafields = new ExtraFields($db);
  68. $diroutputmassaction = $conf->fichinter->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
  69. $hookmanager->initHooks(array('myobjectagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  70. // Fetch optionals attributes and labels
  71. $extrafields->fetch_name_optionals_label($object->table_element);
  72. // Load object
  73. 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
  74. if ($id > 0 || !empty($ref)) {
  75. $upload_dir = $conf->fichinter->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
  76. }
  77. $permissiontoread = $user->hasRight("fichinter", "lire");
  78. $permissiontoadd = $user->hasRight("fichinter", "creer");
  79. // Security check
  80. if (!empty($user->socid)) {
  81. $socid = $user->socid;
  82. }
  83. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  84. restrictedArea($user, 'ficheinter', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
  85. /*
  86. * Actions
  87. */
  88. $parameters = array('id'=>$id);
  89. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  90. if ($reshook < 0) {
  91. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  92. }
  93. if (empty($reshook)) {
  94. // Cancel
  95. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  96. header("Location: ".$backtopage);
  97. exit;
  98. }
  99. // Purge search criteria
  100. 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
  101. $actioncode = '';
  102. $search_agenda_label = '';
  103. }
  104. }
  105. /*
  106. * View
  107. */
  108. $form = new Form($db);
  109. if ($object->id > 0) {
  110. $title = $langs->trans("Agenda");
  111. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  112. $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
  113. llxHeader('', $title, $help_url);
  114. if (isModEnabled('notification')) {
  115. $langs->load("mails");
  116. }
  117. $head = fichinter_prepare_head($object);
  118. print dol_get_fiche_head($head, 'agenda', $langs->trans("Intervention"), -1, $object->picto);
  119. // Object card
  120. // ------------------------------------------------------------
  121. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  122. $morehtmlref = '<div class="refidno">';
  123. // Ref customer
  124. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  125. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  126. // Thirdparty
  127. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  128. // Project
  129. if (isModEnabled('project')) {
  130. $langs->load("projects");
  131. $morehtmlref .= '<br>';
  132. if (0) {
  133. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  134. if ($action != 'classify') {
  135. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  136. }
  137. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  138. } else {
  139. if (!empty($object->fk_project)) {
  140. $proj = new Project($db);
  141. $proj->fetch($object->fk_project);
  142. $morehtmlref .= $proj->getNomUrl(1);
  143. if ($proj->title) {
  144. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  145. }
  146. }
  147. }
  148. }
  149. $morehtmlref .= '</div>';
  150. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  151. print '<div class="fichecenter">';
  152. print '<div class="underbanner clearboth"></div>';
  153. $object->info($object->id);
  154. dol_print_object_info($object, 1);
  155. print '</div>';
  156. print dol_get_fiche_end();
  157. // Actions buttons
  158. $objthirdparty = $object;
  159. $objcon = new stdClass();
  160. $out = '&origin='.urlencode($object->element.(property_exists($object, 'module') ? '@'.$object->module : '')).'&originid='.urlencode($object->id);
  161. $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  162. $out .= '&backtopage='.urlencode($urlbacktopage);
  163. $permok = $user->hasRight('agenda', 'myactions', 'create');
  164. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  165. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  166. if (get_class($objthirdparty) == 'Societe') {
  167. $out .= '&socid='.urlencode($objthirdparty->id);
  168. }
  169. $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '');
  170. //$out.=$langs->trans("AddAnAction").' ';
  171. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  172. //$out.="</a>";
  173. }
  174. $morehtmlright = '';
  175. //$messagingUrl = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
  176. //$morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
  177. //$messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  178. //$morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2);
  179. if (isModEnabled('agenda')) {
  180. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  181. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/fichinter/card.php?action=create'.$out);
  182. } else {
  183. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/fichinter/card.php?action=create'.$out, '', 0);
  184. }
  185. }
  186. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  187. print '<br>';
  188. $param = '&id='.$object->id.(!empty($socid) ? '&socid='.$socid : '');
  189. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  190. $param .= '&contextpage='.urlencode($contextpage);
  191. }
  192. if ($limit > 0 && $limit != $conf->liste_limit) {
  193. $param .= '&limit='.((int) $limit);
  194. }
  195. // Try to know count of actioncomm from cache
  196. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  197. $cachekey = 'count_events_fichinter_'.$object->id;
  198. $nbEvent = dol_getcache($cachekey);
  199. print_barre_liste($langs->trans("ActionsOnFicheInter").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>': ''), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  200. //print_barre_liste($langs->trans("ActionsOnPropal"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  201. // List of all actions
  202. $filters = array();
  203. $filters['search_agenda_label'] = $search_agenda_label;
  204. $filters['search_rowid'] = $search_rowid;
  205. // TODO Replace this with same code than into list.php
  206. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, property_exists($object, 'module') ? $object->module : '');
  207. }
  208. }
  209. // End of page
  210. llxFooter();
  211. $db->close();