mo_agenda.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 mo_agenda.php
  20. * \ingroup mrp
  21. * \brief Page of Mo events
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.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. dol_include_once('/mrp/class/mo.class.php');
  31. dol_include_once('/mrp/lib/mrp_mo.lib.php');
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("mrp", "other"));
  34. // Get parameters
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $cancel = GETPOST('cancel', 'aZ09');
  39. $backtopage = GETPOST('backtopage', 'alpha');
  40. if (GETPOST('actioncode', 'array')) {
  41. $actioncode = GETPOST('actioncode', 'array', 3);
  42. if (!count($actioncode)) {
  43. $actioncode = '0';
  44. }
  45. } else {
  46. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  47. }
  48. $search_rowid = GETPOST('search_rowid');
  49. $search_agenda_label = GETPOST('search_agenda_label');
  50. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $offset = $limit * $page;
  58. $pageprev = $page - 1;
  59. $pagenext = $page + 1;
  60. if (!$sortfield) {
  61. $sortfield = 'a.datep,a.id';
  62. }
  63. if (!$sortorder) {
  64. $sortorder = 'DESC';
  65. }
  66. // Initialize technical objects
  67. $object = new Mo($db);
  68. $extrafields = new ExtraFields($db);
  69. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  70. $hookmanager->initHooks(array('moagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  71. // Fetch optionals attributes and labels
  72. $extrafields->fetch_name_optionals_label($object->table_element);
  73. // Load object
  74. 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
  75. if ($id > 0 || !empty($ref)) {
  76. $upload_dir = $conf->mrp->multidir_output[$object->entity]."/".$object->id;
  77. }
  78. // Security check - Protection if external user
  79. //if ($user->socid > 0) accessforbidden();
  80. //if ($user->socid > 0) $socid = $user->socid;
  81. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  82. $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
  83. /*
  84. * Actions
  85. */
  86. $parameters = array('id'=>$socid);
  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. $contactstatic = new Contact($db);
  107. $form = new Form($db);
  108. $formproject = new FormProjets($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|FR:Module_Agenda|ES:Módulo_Agenda|DE:|DE:Modul_Terminplanung';
  113. llxHeader('', $title, $help_url);
  114. if (isModEnabled('notification')) {
  115. $langs->load("mails");
  116. }
  117. $head = moPrepareHead($object);
  118. print dol_get_fiche_head($head, 'agenda', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  119. // Object card
  120. // ------------------------------------------------------------
  121. $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?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. if (is_object($object->thirdparty)) {
  128. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
  129. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  130. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  131. }
  132. }
  133. // Project
  134. if (isModEnabled('project')) {
  135. $langs->load("projects");
  136. if (is_object($object->thirdparty)) {
  137. $morehtmlref .= '<br>';
  138. }
  139. if (0) {
  140. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  141. if ($action != 'classify') {
  142. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  143. }
  144. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  145. } else {
  146. if (!empty($object->fk_project)) {
  147. $proj = new Project($db);
  148. $proj->fetch($object->fk_project);
  149. $morehtmlref .= $proj->getNomUrl(1);
  150. if ($proj->title) {
  151. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  152. }
  153. }
  154. }
  155. }
  156. $morehtmlref .= '</div>';
  157. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  158. print '<div class="fichecenter">';
  159. print '<div class="underbanner clearboth"></div>';
  160. $object->info($object->id);
  161. dol_print_object_info($object, 1);
  162. print '</div>';
  163. print dol_get_fiche_end();
  164. // Actions buttons
  165. $objthirdparty = $object;
  166. $objcon = new stdClass();
  167. $out = '&origin='.$object->element.'&originid='.$object->id;
  168. $permok = $user->hasRight('agenda', 'myactions', 'create');
  169. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  170. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  171. if (get_class($objthirdparty) == 'Societe') {
  172. $out .= '&amp;socid='.$objthirdparty->id;
  173. }
  174. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
  175. //$out.=$langs->trans("AddAnAction").' ';
  176. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  177. //$out.="</a>";
  178. }
  179. print '<div class="tabsAction">';
  180. if (isModEnabled('agenda')) {
  181. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  182. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  183. } else {
  184. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  185. }
  186. }
  187. print '</div>';
  188. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  189. $param = '&id='.$object->id.'&socid='.$socid;
  190. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  191. $param .= '&contextpage='.urlencode($contextpage);
  192. }
  193. if ($limit > 0 && $limit != $conf->liste_limit) {
  194. $param .= '&limit='.((int) $limit);
  195. }
  196. //print load_fiche_titre($langs->trans("ActionsOnMo"), '', '');
  197. // List of all actions
  198. $filters = array();
  199. $filters['search_agenda_label'] = $search_agenda_label;
  200. $filters['search_rowid'] = $search_rowid;
  201. // TODO Replace this with same code than into list.php
  202. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  203. }
  204. }
  205. // End of page
  206. llxFooter();
  207. $db->close();