PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/product/stock/stocktransfer/stocktransfer_agenda.php

https://github.com/Dolibarr/dolibarr
PHP | 247 lines | 107 code | 49 blank | 91 comment | 59 complexity | b27f26c00cc37e3578ed3f041095d11f MD5 | raw file
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) ---Put here your own copyright and developer email---
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file stocktransfer_agenda.php
  21. * \ingroup stocktransfer
  22. * \brief Page of StockTransfer events
  23. */
  24. // Load Dolibarr environment
  25. $res = 0;
  26. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  27. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  28. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  29. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  30. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
  31. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  32. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  33. // Try main.inc.php using relative path
  34. if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
  35. if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
  36. if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
  37. if (!$res) die("Include of main fails");
  38. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
  43. // Load translation files required by the page
  44. $langs->loadLangs(array("stocks", "other"));
  45. // Get parameters
  46. $id = GETPOST('id', 'int');
  47. $ref = GETPOST('ref', 'alpha');
  48. $action = GETPOST('action', 'alpha');
  49. $cancel = GETPOST('cancel', 'aZ09');
  50. $backtopage = GETPOST('backtopage', 'alpha');
  51. if (GETPOST('actioncode', 'array')) {
  52. $actioncode = GETPOST('actioncode', 'array', 3);
  53. if (!count($actioncode)) $actioncode = '0';
  54. } else {
  55. $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));
  56. }
  57. $search_agenda_label = GETPOST('search_agenda_label');
  58. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  59. $sortfield = GETPOST("sortfield", 'alpha');
  60. $sortorder = GETPOST("sortorder", 'alpha');
  61. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  62. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  63. $offset = $limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. if (!$sortfield) $sortfield = 'a.datep,a.id';
  67. if (!$sortorder) $sortorder = 'DESC,DESC';
  68. // Initialize technical objects
  69. $object = new StockTransfer($db);
  70. $extrafields = new ExtraFields($db);
  71. $diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
  72. $hookmanager->initHooks(array('stocktransferagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  73. // Fetch optionals attributes and labels
  74. $extrafields->fetch_name_optionals_label($object->table_element);
  75. // Load object
  76. 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
  77. if ($id > 0 || !empty($ref)) $upload_dir = $conf->stocktransfer->multidir_output[$object->entity]."/".$object->id;
  78. // Security check - Protection if external user
  79. //if ($user->socid > 0) accessforbidden();
  80. //if ($user->socid > 0) $socid = $user->socid;
  81. $result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
  82. $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php
  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) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  89. if (empty($reshook)) {
  90. // Cancel
  91. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  92. header("Location: ".$backtopage);
  93. exit;
  94. }
  95. // Purge search criteria
  96. 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
  97. $actioncode = '';
  98. $search_agenda_label = '';
  99. }
  100. }
  101. /*
  102. * View
  103. */
  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 = '';
  109. llxHeader('', $title, $help_url);
  110. if (!empty($conf->notification->enabled)) $langs->load("mails");
  111. $head = stocktransferPrepareHead($object);
  112. print dol_get_fiche_head($head, 'agenda', $langs->trans("StockTransfer"), -1, $object->picto);
  113. // Object card
  114. // ------------------------------------------------------------
  115. $linkback = '<a href="'.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  116. $morehtmlref = '<div class="refidno">';
  117. /*
  118. // Ref customer
  119. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  120. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  121. // Thirdparty
  122. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  123. // Project
  124. if (! empty($conf->project->enabled))
  125. {
  126. $langs->load("projects");
  127. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  128. if ($permissiontoadd)
  129. {
  130. if ($action != 'classify')
  131. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  132. $morehtmlref.=' : ';
  133. if ($action == 'classify') {
  134. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  135. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  136. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  137. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  138. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  139. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  140. $morehtmlref.='</form>';
  141. } else {
  142. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  143. }
  144. } else {
  145. if (! empty($object->fk_project)) {
  146. $proj = new Project($db);
  147. $proj->fetch($object->fk_project);
  148. $morehtmlref .= ': '.$proj->getNomUrl();
  149. } else {
  150. $morehtmlref .= '';
  151. }
  152. }
  153. }*/
  154. $morehtmlref .= '</div>';
  155. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  156. print '<div class="fichecenter">';
  157. print '<div class="underbanner clearboth"></div>';
  158. $object->info($object->id);
  159. dol_print_object_info($object, 1);
  160. print '</div>';
  161. print dol_get_fiche_end();
  162. // Actions buttons
  163. $objthirdparty = $object;
  164. $objcon = new stdClass();
  165. $out = '&origin='.$object->element.'&originid='.$object->id;
  166. $permok = $user->rights->agenda->myactions->create;
  167. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  168. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  169. if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
  170. $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
  171. //$out.=$langs->trans("AddAnAction").' ';
  172. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  173. //$out.="</a>";
  174. }
  175. print '<div class="tabsAction">';
  176. if (isModEnabled('agenda')) {
  177. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  178. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  179. } else {
  180. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  181. }
  182. }
  183. print '</div>';
  184. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  185. $param = '&id='.$object->id.'&socid='.$socid;
  186. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  187. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  188. //print load_fiche_titre($langs->trans("ActionsOnStockTransfer"), '', '');
  189. // List of all actions
  190. $filters = array();
  191. $filters['search_agenda_label'] = $search_agenda_label;
  192. // TODO Replace this with same code than into list.php
  193. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, '');
  194. }
  195. }
  196. // End of page
  197. llxFooter();
  198. $db->close();