agenda.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/model/agenda.php
  20. * \ingroup asset
  21. * \brief Tab of events on Asset Model
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT . '/core/lib/asset.lib.php';
  25. require_once DOL_DOCUMENT_ROOT . '/asset/class/assetmodel.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.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("assets", "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. $backtopage = GETPOST('backtopage', 'alpha');
  37. if (GETPOST('actioncode', 'array')) {
  38. $actioncode = GETPOST('actioncode', 'array', 3);
  39. if (!count($actioncode)) {
  40. $actioncode = '0';
  41. }
  42. } else {
  43. $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));
  44. }
  45. $search_agenda_label = GETPOST('search_agenda_label');
  46. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST("sortfield", 'alpha');
  48. $sortorder = GETPOST("sortorder", 'alpha');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page == -1) {
  51. $page = 0;
  52. } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!$sortfield) {
  57. $sortfield = 'a.datep,a.id';
  58. }
  59. if (!$sortorder) {
  60. $sortorder = 'DESC,DESC';
  61. }
  62. // Initialize technical objects
  63. $object = new AssetModel($db);
  64. $extrafields = new ExtraFields($db);
  65. $diroutputmassaction = $conf->asset->dir_output . '/temp/massgeneration/' . $user->id;
  66. $hookmanager->initHooks(array('assetmodelagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  67. // Fetch optionals attributes and labels
  68. $extrafields->fetch_name_optionals_label($object->table_element);
  69. // Load object
  70. 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
  71. if ($id > 0 || !empty($ref)) {
  72. $upload_dir = $conf->asset->multidir_output[$object->entity] . "/model/" . $object->id;
  73. }
  74. $permissiontoread = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->read) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->model_advance->read)));
  75. $permissiontoadd = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->asset->model_advance->write))); // Used by the include of actions_addupdatedelete.inc.php
  76. // Security check (enable the most restrictive one)
  77. if ($user->socid > 0) accessforbidden();
  78. if ($user->socid > 0) $socid = $user->socid;
  79. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  80. restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  81. if (empty($conf->asset->enabled)) accessforbidden();
  82. if (!$permissiontoread) accessforbidden();
  83. /*
  84. * Actions
  85. */
  86. $parameters = array('id' => $id);
  87. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  88. if ($reshook < 0) {
  89. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  90. }
  91. if (empty($reshook)) {
  92. // Cancel
  93. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  94. header("Location: " . $backtopage);
  95. exit;
  96. }
  97. // Purge search criteria
  98. 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
  99. $actioncode = '';
  100. $search_agenda_label = '';
  101. }
  102. }
  103. /*
  104. * View
  105. */
  106. $form = new Form($db);
  107. if ($object->id > 0) {
  108. $title = $langs->trans("Agenda");
  109. //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  110. $help_url = 'EN:Module_Agenda_En';
  111. llxHeader('', $title, $help_url);
  112. if (!empty($conf->notification->enabled)) {
  113. $langs->load("mails");
  114. }
  115. $head = assetModelPrepareHead($object);
  116. print dol_get_fiche_head($head, 'agenda', $langs->trans("AssetModel"), -1, $object->picto);
  117. // Object card
  118. // ------------------------------------------------------------
  119. $linkback = '<a href="' . DOL_URL_ROOT . '/asset/model/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  120. $morehtmlref = '<div class="refidno">';
  121. $morehtmlref .= '</div>';
  122. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  123. print '<div class="fichecenter">';
  124. print '<div class="underbanner clearboth"></div>';
  125. $object->info($object->id);
  126. dol_print_object_info($object, 1);
  127. print '</div>';
  128. print dol_get_fiche_end();
  129. // Actions buttons
  130. $objthirdparty = $object;
  131. $objcon = new stdClass();
  132. $out = '&origin=' . urlencode($object->element . '@' . $object->module) . '&originid=' . urlencode($object->id);
  133. $urlbacktopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
  134. $out .= '&backtopage=' . urlencode($urlbacktopage);
  135. $permok = $user->rights->agenda->myactions->create;
  136. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  137. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  138. if (get_class($objthirdparty) == 'Societe') {
  139. $out .= '&socid=' . urlencode($objthirdparty->id);
  140. }
  141. $out .= (!empty($objcon->id) ? '&contactid=' . urlencode($objcon->id) : '') . '&percentage=-1';
  142. //$out.=$langs->trans("AddAnAction").' ';
  143. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  144. //$out.="</a>";
  145. }
  146. print '<div class="tabsAction">';
  147. // if (!empty($conf->agenda->enabled)) {
  148. // if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  149. // print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create' . $out . '">' . $langs->trans("AddAction") . '</a>';
  150. // } else {
  151. // print '<a class="butActionRefused classfortooltip" href="#">' . $langs->trans("AddAction") . '</a>';
  152. // }
  153. // }
  154. print '</div>';
  155. // if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  156. // $param = '&id=' . $object->id . '&socid=' . $socid;
  157. // if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  158. // $param .= '&contextpage=' . urlencode($contextpage);
  159. // }
  160. // if ($limit > 0 && $limit != $conf->liste_limit) {
  161. // $param .= '&limit=' . urlencode($limit);
  162. // }
  163. //
  164. //
  165. // print load_fiche_titre($langs->trans("ActionsOnAssetModel"), '', '');
  166. //
  167. // // List of all actions
  168. // $filters = array();
  169. // $filters['search_agenda_label'] = $search_agenda_label;
  170. //
  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();