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