bom_agenda.php 9.3 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 htdocs/modulebuilder/template/myobject_agenda.php
  20. * \ingroup bom
  21. * \brief Page of MyObject events
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("mrp", "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' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
  45. }
  46. $search_agenda_label = GETPOST('search_agenda_label');
  47. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  48. $sortfield = GETPOST('sortfield', 'aZ09comma');
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. if (empty($page) || $page == -1) {
  52. $page = 0;
  53. } // If $page is not defined, or '' or -1
  54. $offset = $limit * $page;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (!$sortfield) {
  58. $sortfield = 'a.datep,a.id';
  59. }
  60. if (!$sortorder) {
  61. $sortorder = 'DESC';
  62. }
  63. // Initialize technical objects
  64. $object = new BOM($db);
  65. $extrafields = new ExtraFields($db);
  66. $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
  67. $hookmanager->initHooks(array('bomagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  68. // Fetch optionals attributes and labels
  69. $extrafields->fetch_name_optionals_label($object->table_element);
  70. // Load object
  71. 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
  72. if ($id > 0 || !empty($ref)) {
  73. $upload_dir = $conf->bom->multidir_output[$object->entity]."/".$object->id;
  74. }
  75. // Security check - Protection if external user
  76. //if ($user->socid > 0) accessforbidden();
  77. //if ($user->socid > 0) $socid = $user->socid;
  78. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  79. restrictedArea($user, 'bom', $object->id, 'bom_bom', '', '', 'rowid', $isdraft);
  80. /*
  81. * Actions
  82. */
  83. $parameters = array('id'=>$socid);
  84. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  85. if ($reshook < 0) {
  86. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  87. }
  88. if (empty($reshook)) {
  89. // Cancel
  90. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  91. header("Location: ".$backtopage);
  92. exit;
  93. }
  94. // Purge search criteria
  95. 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
  96. $actioncode = '';
  97. $search_agenda_label = '';
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $contactstatic = new Contact($db);
  104. $form = new Form($db);
  105. if ($object->id > 0) {
  106. $title = $langs->trans("Agenda");
  107. //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  108. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Agenda';
  109. llxHeader('', $title, $help_url);
  110. if (!empty($conf->notification->enabled)) {
  111. $langs->load("mails");
  112. }
  113. $head = bomPrepareHead($object);
  114. print dol_get_fiche_head($head, 'agenda', $langs->trans("BillOfMaterials"), -1, 'bom');
  115. // Object card
  116. // ------------------------------------------------------------
  117. $linkback = '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  118. $morehtmlref = '<div class="refidno">';
  119. /*
  120. // Ref customer
  121. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  122. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  123. // Thirdparty
  124. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  125. // Project
  126. if (! empty($conf->projet->enabled))
  127. {
  128. $langs->load("projects");
  129. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  130. if ($user->rights->bom->creer)
  131. {
  132. if ($action != 'classify')
  133. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  134. $morehtmlref.=' : ';
  135. if ($action == 'classify') {
  136. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  137. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  138. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  139. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  140. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  141. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  142. $morehtmlref.='</form>';
  143. } else {
  144. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  145. }
  146. } else {
  147. if (! empty($object->fk_project)) {
  148. $proj = new Project($db);
  149. $proj->fetch($object->fk_project);
  150. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  151. $morehtmlref.=$proj->ref;
  152. $morehtmlref.='</a>';
  153. } else {
  154. $morehtmlref.='';
  155. }
  156. }
  157. }*/
  158. $morehtmlref .= '</div>';
  159. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  160. print '<div class="fichecenter">';
  161. print '<div class="underbanner clearboth"></div>';
  162. $object->info($object->id);
  163. dol_print_object_info($object, 1);
  164. print '</div>';
  165. print dol_get_fiche_end();
  166. // Actions buttons
  167. $objthirdparty = $object;
  168. $objcon = new stdClass();
  169. $out = '&origin='.$object->element.'&originid='.$object->id;
  170. $permok = $user->rights->agenda->myactions->create;
  171. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  172. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  173. if (get_class($objthirdparty) == 'Societe') {
  174. $out .= '&amp;socid='.$objthirdparty->id;
  175. }
  176. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
  177. //$out.=$langs->trans("AddAnAction").' ';
  178. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  179. //$out.="</a>";
  180. }
  181. print '<div class="tabsAction">';
  182. if (!empty($conf->agenda->enabled)) {
  183. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  184. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  185. } else {
  186. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  187. }
  188. }
  189. print '</div>';
  190. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  191. $param = '&id='.$object->id.'&socid='.$socid;
  192. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  193. $param .= '&contextpage='.urlencode($contextpage);
  194. }
  195. if ($limit > 0 && $limit != $conf->liste_limit) {
  196. $param .= '&limit='.urlencode($limit);
  197. }
  198. //print load_fiche_titre($langs->trans("ActionsOnBom"), '', '');
  199. // List of all actions
  200. $filters = array();
  201. $filters['search_agenda_label'] = $search_agenda_label;
  202. // TODO Replace this with same code than into list.php
  203. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  204. }
  205. }
  206. // End of page
  207. llxFooter();
  208. $db->close();