agenda.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/asset/agenda.php
  20. * \ingroup asset
  21. * \brief Tab of events on Asset
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/asset.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.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("assets", "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. $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", 'alpha');
  50. $sortorder = GETPOST("sortorder", 'alpha');
  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 Asset($db);
  66. $extrafields = new ExtraFields($db);
  67. $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
  68. $hookmanager->initHooks(array('assetagenda', '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->asset->multidir_output[$object->entity]."/".$object->id;
  75. }
  76. $permissiontoadd = $user->hasRight('asset', 'write'); // Used by the include of actions_addupdatedelete.inc.php
  77. // Security check (enable the most restrictive one)
  78. if ($user->socid > 0) {
  79. accessforbidden();
  80. }
  81. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  82. restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  83. if (!isModEnabled('asset')) {
  84. accessforbidden();
  85. }
  86. /*
  87. * Actions
  88. */
  89. $parameters = array('id'=>$id);
  90. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  91. if ($reshook < 0) {
  92. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  93. }
  94. if (empty($reshook)) {
  95. // Cancel
  96. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  97. header("Location: ".$backtopage);
  98. exit;
  99. }
  100. // Purge search criteria
  101. 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
  102. $actioncode = '';
  103. $search_agenda_label = '';
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. $form = new Form($db);
  110. if ($object->id > 0) {
  111. $title = $langs->trans("Agenda");
  112. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  113. $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
  114. llxHeader('', $title, $help_url);
  115. if (isModEnabled('notification')) {
  116. $langs->load("mails");
  117. }
  118. $head = assetPrepareHead($object);
  119. print dol_get_fiche_head($head, 'agenda', $langs->trans("Asset"), -1, $object->picto);
  120. // Object card
  121. // ------------------------------------------------------------
  122. $linkback = '<a href="' . DOL_URL_ROOT . '/asset/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  123. $morehtmlref = '<div class="refidno">';
  124. $morehtmlref .= '</div>';
  125. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  126. print '<div class="fichecenter">';
  127. print '<div class="underbanner clearboth"></div>';
  128. $object->info($object->id);
  129. dol_print_object_info($object, 1);
  130. print '</div>';
  131. print dol_get_fiche_end();
  132. // Actions buttons
  133. $objthirdparty = $object;
  134. $objcon = new stdClass();
  135. $out = '&origin=' . urlencode($object->element . '@' . $object->module) . '&originid=' . urlencode($object->id);
  136. $urlbacktopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
  137. $out .= '&backtopage=' . urlencode($urlbacktopage);
  138. $permok = $user->hasRight('agenda', 'myactions', 'create');
  139. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  140. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  141. if (get_class($objthirdparty) == 'Societe') {
  142. $out .= '&socid=' . urlencode($objthirdparty->id);
  143. }
  144. $out .= (!empty($objcon->id) ? '&contactid=' . urlencode($objcon->id) : '');
  145. //$out.=$langs->trans("AddAnAction").' ';
  146. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  147. //$out.="</a>";
  148. }
  149. print '<div class="tabsAction">';
  150. if (isModEnabled('agenda')) {
  151. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  152. print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '">' . $langs->trans("AddAction") . '</a>';
  153. } else {
  154. print '<a class="butActionRefused classfortooltip" href="#">' . $langs->trans("AddAction") . '</a>';
  155. }
  156. }
  157. print '</div>';
  158. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  159. $param = '&id=' . $object->id . '&socid=' . $socid;
  160. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  161. $param .= '&contextpage=' . urlencode($contextpage);
  162. }
  163. if ($limit > 0 && $limit != $conf->liste_limit) {
  164. $param .= '&limit='.((int) $limit);
  165. }
  166. print load_fiche_titre($langs->trans("ActionsOnAsset"), '', '');
  167. // List of all actions
  168. $filters = array();
  169. $filters['search_agenda_label'] = $search_agenda_label;
  170. $filters['search_rowid'] = $search_rowid;
  171. // TODO Replace this with same code than into list.php
  172. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
  173. }
  174. }
  175. // End of page
  176. llxFooter();
  177. $db->close();