stocktransfer_agenda.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  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 stocktransfer_agenda.php
  20. * \ingroup stocktransfer
  21. * \brief Page of StockTransfer 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.'/product/stock/stocktransfer/class/stocktransfer.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("stocks", "other"));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'alpha');
  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)) $actioncode = '0';
  41. } else {
  42. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  43. }
  44. $search_rowid = GETPOST('search_rowid');
  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) { $page = 0; } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortfield) $sortfield = 'a.datep,a.id';
  55. if (!$sortorder) $sortorder = 'DESC,DESC';
  56. // Initialize technical objects
  57. $object = new StockTransfer($db);
  58. $extrafields = new ExtraFields($db);
  59. $diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('stocktransferagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  61. // Fetch optionals attributes and labels
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. // Load object
  64. 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
  65. if ($id > 0 || !empty($ref)) $upload_dir = $conf->stocktransfer->multidir_output[$object->entity]."/".$object->id;
  66. // Security check - Protection if external user
  67. //if ($user->socid > 0) accessforbidden();
  68. //if ($user->socid > 0) $socid = $user->socid;
  69. $result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
  70. $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php
  71. /*
  72. * Actions
  73. */
  74. $parameters = array('id'=>$id);
  75. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. if (empty($reshook)) {
  78. // Cancel
  79. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  80. header("Location: ".$backtopage);
  81. exit;
  82. }
  83. // Purge search criteria
  84. 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
  85. $actioncode = '';
  86. $search_agenda_label = '';
  87. }
  88. }
  89. /*
  90. * View
  91. */
  92. $form = new Form($db);
  93. if ($object->id > 0) {
  94. $title = $langs->trans("Agenda");
  95. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  96. $help_url = '';
  97. llxHeader('', $title, $help_url);
  98. if (isModEnabled('notification')) $langs->load("mails");
  99. $head = stocktransferPrepareHead($object);
  100. print dol_get_fiche_head($head, 'agenda', $langs->trans("StockTransfer"), -1, $object->picto);
  101. // Object card
  102. // ------------------------------------------------------------
  103. $linkback = '<a href="'.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  104. $morehtmlref = '<div class="refidno">';
  105. /*
  106. // Ref customer
  107. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  108. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  109. // Thirdparty
  110. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  111. // Project
  112. if (isModEnabled('project'))
  113. {
  114. $langs->load("projects");
  115. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  116. if ($permissiontoadd)
  117. {
  118. if ($action != 'classify')
  119. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  120. $morehtmlref.=' : ';
  121. if ($action == 'classify') {
  122. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  123. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  124. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  125. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  126. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  127. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  128. $morehtmlref.='</form>';
  129. } else {
  130. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  131. }
  132. } else {
  133. if (!empty($object->fk_project)) {
  134. $proj = new Project($db);
  135. $proj->fetch($object->fk_project);
  136. $morehtmlref .= ': '.$proj->getNomUrl();
  137. } else {
  138. $morehtmlref .= '';
  139. }
  140. }
  141. }*/
  142. $morehtmlref .= '</div>';
  143. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  144. print '<div class="fichecenter">';
  145. print '<div class="underbanner clearboth"></div>';
  146. $object->info($object->id);
  147. dol_print_object_info($object, 1);
  148. print '</div>';
  149. print dol_get_fiche_end();
  150. // Actions buttons
  151. $objthirdparty = $object;
  152. $objcon = new stdClass();
  153. $out = '&origin='.$object->element.'&originid='.$object->id;
  154. $permok = $user->rights->agenda->myactions->create;
  155. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  156. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  157. if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
  158. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1';
  159. //$out.=$langs->trans("AddAnAction").' ';
  160. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  161. //$out.="</a>";
  162. }
  163. print '<div class="tabsAction">';
  164. if (isModEnabled('agenda')) {
  165. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  166. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  167. } else {
  168. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  169. }
  170. }
  171. print '</div>';
  172. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  173. $param = '&id='.$object->id.'&socid='.$socid;
  174. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  175. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.((int) $limit);
  176. //print load_fiche_titre($langs->trans("ActionsOnStockTransfer"), '', '');
  177. // List of all actions
  178. $filters = array();
  179. $filters['search_agenda_label'] = $search_agenda_label;
  180. $filters['search_rowid'] = $search_rowid;
  181. // TODO Replace this with same code than into list.php
  182. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, '');
  183. }
  184. }
  185. // End of page
  186. llxFooter();
  187. $db->close();