dolibarr  17.0.4
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' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
49 }
50 $search_rowid = GETPOST('search_rowid');
51 $search_agenda_label = GETPOST('search_agenda_label');
52 
53 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
54 $sortfield = GETPOST("sortfield", 'alpha');
55 $sortorder = GETPOST("sortorder", 'alpha');
56 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
57 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
61 if (!$sortfield) $sortfield = 'a.datep,a.id';
62 if (!$sortorder) $sortorder = 'DESC,DESC';
63 
64 // Initialize technical objects
65 $object = new StockTransfer($db);
66 $extrafields = new ExtraFields($db);
67 $diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
68 $hookmanager->initHooks(array('stocktransferagenda', 'globalcard')); // Note that conf->hooks_modules contains array
69 // Fetch optionals attributes and labels
70 $extrafields->fetch_name_optionals_label($object->table_element);
71 
72 // Load object
73 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
74 if ($id > 0 || !empty($ref)) $upload_dir = $conf->stocktransfer->multidir_output[$object->entity]."/".$object->id;
75 
76 // Security check - Protection if external user
77 //if ($user->socid > 0) accessforbidden();
78 //if ($user->socid > 0) $socid = $user->socid;
79 $result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
80 
81 $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php
82 
83 
84 /*
85  * Actions
86  */
87 
88 $parameters = array('id'=>$id);
89 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 
92 if (empty($reshook)) {
93  // Cancel
94  if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
95  header("Location: ".$backtopage);
96  exit;
97  }
98 
99  // Purge search criteria
100  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
101  $actioncode = '';
102  $search_agenda_label = '';
103  }
104 }
105 
106 
107 
108 /*
109  * View
110  */
111 
112 $form = new Form($db);
113 
114 if ($object->id > 0) {
115  $title = $langs->trans("Agenda");
116  //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
117  $help_url = '';
118  llxHeader('', $title, $help_url);
119 
120  if (isModEnabled('notification')) $langs->load("mails");
121  $head = stocktransferPrepareHead($object);
122 
123 
124  print dol_get_fiche_head($head, 'agenda', $langs->trans("StockTransfer"), -1, $object->picto);
125 
126  // Object card
127  // ------------------------------------------------------------
128  $linkback = '<a href="'.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
129 
130  $morehtmlref = '<div class="refidno">';
131  /*
132  // Ref customer
133  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
134  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
135  // Thirdparty
136  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
137  // Project
138  if (!empty($conf->project->enabled))
139  {
140  $langs->load("projects");
141  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
142  if ($permissiontoadd)
143  {
144  if ($action != 'classify')
145  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
146  $morehtmlref.=' : ';
147  if ($action == 'classify') {
148  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
149  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
150  $morehtmlref.='<input type="hidden" name="action" value="classin">';
151  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
152  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
153  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
154  $morehtmlref.='</form>';
155  } else {
156  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
157  }
158  } else {
159  if (!empty($object->fk_project)) {
160  $proj = new Project($db);
161  $proj->fetch($object->fk_project);
162  $morehtmlref .= ': '.$proj->getNomUrl();
163  } else {
164  $morehtmlref .= '';
165  }
166  }
167  }*/
168  $morehtmlref .= '</div>';
169 
170 
171  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
172 
173  print '<div class="fichecenter">';
174  print '<div class="underbanner clearboth"></div>';
175 
176  $object->info($object->id);
177  dol_print_object_info($object, 1);
178 
179  print '</div>';
180 
181  print dol_get_fiche_end();
182 
183 
184 
185  // Actions buttons
186 
187  $objthirdparty = $object;
188  $objcon = new stdClass();
189 
190  $out = '&origin='.$object->element.'&originid='.$object->id;
191  $permok = $user->rights->agenda->myactions->create;
192  if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
193  //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
194  if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
195  $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
196  //$out.=$langs->trans("AddAnAction").' ';
197  //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
198  //$out.="</a>";
199  }
200 
201 
202  print '<div class="tabsAction">';
203 
204  if (isModEnabled('agenda')) {
205  if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
206  print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
207  } else {
208  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
209  }
210  }
211 
212  print '</div>';
213 
214  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
215  $param = '&id='.$object->id.'&socid='.$socid;
216  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
217  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
218 
219 
220  //print load_fiche_titre($langs->trans("ActionsOnStockTransfer"), '', '');
221 
222  // List of all actions
223  $filters = array();
224  $filters['search_agenda_label'] = $search_agenda_label;
225  $filters['search_rowid'] = $search_rowid;
226 
227  // TODO Replace this with same code than into list.php
228  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, '');
229  }
230 }
231 
232 // End of page
233 llxFooter();
234 $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.
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.