dolibarr  16.0.5
stocktransfer_agenda.php
Go to the documentation of this 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 
26 // Load Dolibarr environment
27 $res = 0;
28 // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
29 if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
30 // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
31 $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
32 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
33 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
34 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";
35 // Try main.inc.php using relative path
36 if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
37 if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
38 if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
39 if (!$res) die("Include of main fails");
40 
41 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
46 
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array("stocks", "other"));
50 
51 // Get parameters
52 $id = GETPOST('id', 'int');
53 $ref = GETPOST('ref', 'alpha');
54 $action = GETPOST('action', 'alpha');
55 $cancel = GETPOST('cancel', 'aZ09');
56 $backtopage = GETPOST('backtopage', 'alpha');
57 
58 if (GETPOST('actioncode', 'array')) {
59  $actioncode = GETPOST('actioncode', 'array', 3);
60  if (!count($actioncode)) $actioncode = '0';
61 } else {
62  $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));
63 }
64 $search_agenda_label = GETPOST('search_agenda_label');
65 
66 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
67 $sortfield = GETPOST("sortfield", 'alpha');
68 $sortorder = GETPOST("sortorder", 'alpha');
69 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
70 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
71 $offset = $limit * $page;
72 $pageprev = $page - 1;
73 $pagenext = $page + 1;
74 if (!$sortfield) $sortfield = 'a.datep,a.id';
75 if (!$sortorder) $sortorder = 'DESC,DESC';
76 
77 // Initialize technical objects
78 $object = new StockTransfer($db);
79 $extrafields = new ExtraFields($db);
80 $diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
81 $hookmanager->initHooks(array('stocktransferagenda', 'globalcard')); // Note that conf->hooks_modules contains array
82 // Fetch optionals attributes and labels
83 $extrafields->fetch_name_optionals_label($object->table_element);
84 
85 // Load object
86 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
87 if ($id > 0 || !empty($ref)) $upload_dir = $conf->stocktransfer->multidir_output[$object->entity]."/".$object->id;
88 
89 // Security check - Protection if external user
90 //if ($user->socid > 0) accessforbidden();
91 //if ($user->socid > 0) $socid = $user->socid;
92 $result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
93 
94 $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php
95 
96 
97 /*
98  * Actions
99  */
100 
101 $parameters = array('id'=>$id);
102 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
103 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104 
105 if (empty($reshook)) {
106  // Cancel
107  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
108  header("Location: ".$backtopage);
109  exit;
110  }
111 
112  // Purge search criteria
113  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
114  $actioncode = '';
115  $search_agenda_label = '';
116  }
117 }
118 
119 
120 
121 /*
122  * View
123  */
124 
125 $form = new Form($db);
126 
127 if ($object->id > 0) {
128  $title = $langs->trans("Agenda");
129  //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
130  $help_url = '';
131  llxHeader('', $title, $help_url);
132 
133  if (!empty($conf->notification->enabled)) $langs->load("mails");
134  $head = stocktransferPrepareHead($object);
135 
136 
137  print dol_get_fiche_head($head, 'agenda', $langs->trans("StockTransfer"), -1, $object->picto);
138 
139  // Object card
140  // ------------------------------------------------------------
141  $linkback = '<a href="'.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
142 
143  $morehtmlref = '<div class="refidno">';
144  /*
145  // Ref customer
146  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
147  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
148  // Thirdparty
149  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
150  // Project
151  if (! empty($conf->project->enabled))
152  {
153  $langs->load("projects");
154  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
155  if ($permissiontoadd)
156  {
157  if ($action != 'classify')
158  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
159  $morehtmlref.=' : ';
160  if ($action == 'classify') {
161  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
162  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
163  $morehtmlref.='<input type="hidden" name="action" value="classin">';
164  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
165  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
166  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
167  $morehtmlref.='</form>';
168  } else {
169  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
170  }
171  } else {
172  if (! empty($object->fk_project)) {
173  $proj = new Project($db);
174  $proj->fetch($object->fk_project);
175  $morehtmlref .= ': '.$proj->getNomUrl();
176  } else {
177  $morehtmlref .= '';
178  }
179  }
180  }*/
181  $morehtmlref .= '</div>';
182 
183 
184  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
185 
186  print '<div class="fichecenter">';
187  print '<div class="underbanner clearboth"></div>';
188 
189  $object->info($object->id);
190  dol_print_object_info($object, 1);
191 
192  print '</div>';
193 
194  print dol_get_fiche_end();
195 
196 
197 
198  // Actions buttons
199 
200  $objthirdparty = $object;
201  $objcon = new stdClass();
202 
203  $out = '&origin='.$object->element.'&originid='.$object->id;
204  $permok = $user->rights->agenda->myactions->create;
205  if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
206  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
207  if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
208  $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
209  //$out.=$langs->trans("AddAnAction").' ';
210  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
211  //$out.="</a>";
212  }
213 
214 
215  print '<div class="tabsAction">';
216 
217  if (isModEnabled('agenda')) {
218  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
219  print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
220  } else {
221  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
222  }
223  }
224 
225  print '</div>';
226 
227  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
228  $param = '&id='.$object->id.'&socid='.$socid;
229  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
230  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
231 
232 
233  //print load_fiche_titre($langs->trans("ActionsOnStockTransfer"), '', '');
234 
235  // List of all actions
236  $filters = array();
237  $filters['search_agenda_label'] = $search_agenda_label;
238 
239  // TODO Replace this with same code than into list.php
240 
241  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, '');
242  }
243 }
244 
245 // End of page
246 llxFooter();
247 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
StockTransfer
Class for StockTransfer.
Definition: stocktransfer.class.php:36
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
stocktransferPrepareHead
stocktransferPrepareHead($object)
Prepare array of tabs for StockTransfer.
Definition: stocktransfer_stocktransfer.lib.php:31
show_actions_done
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
Definition: company.lib.php:1389
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_print_object_info
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
Definition: functions2.lib.php:205
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59