dolibarr  16.0.5
position_card.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) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6  * Copyright (C) 2021 GrĂ©gory BLEMAND <gregory.blemand@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
29 // Load Dolibarr environment
30 require '../main.inc.php';
31 
32 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
38 //dol_include_once('/hrm/position.php');
39 
40 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
41 $backtopage = GETPOST('backtopage', 'alpha');
42 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
43 $id = GETPOST('id', 'int');
44 
45 // Initialize technical objects
46 $form = new Form($db);
47 $object = new Position($db);
48 $res = $object->fetch($id);
49 if ($res < 0) {
50  dol_print_error($db, $object->error);
51 }
52 
53 $permissiontoread = $user->rights->hrm->all->read;
54 $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
55 $permissiontodelete = $user->rights->hrm->all->delete;
56 $permissiondellink = $user->rights->hrm->all->write; // Used by the include of actions_dellink.inc.php
57 $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
58 
59 // Security check (enable the most restrictive one)
60 //if ($user->socid > 0) accessforbidden();
61 //if ($user->socid > 0) $socid = $user->socid;
62 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
63 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
64 if (empty($conf->hrm->enabled)) accessforbidden();
65 if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
66 
67 $langs->loadLangs(array("hrm", "other"));
68 
69 
70 
71 // Get parameters
72 $id = GETPOST('id', 'int');
73 $fk_job = GETPOST('fk_job', 'int');
74 
75 $ref = GETPOST('ref', 'alpha');
76 $action = GETPOST('action', 'aZ09');
77 $confirm = GETPOST('confirm', 'alpha');
78 $cancel = GETPOST('cancel', 'aZ09');
79 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
80 $backtopage = GETPOST('backtopage', 'alpha');
81 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
82 // $lineid = GETPOST('lineid', 'int');
83 
84 // Initialize technical objects
85 //$object = new Position($db);
86 //$res = $object->fetch($id);
87 /*if ($res < 0) {
88  dol_print_error($db, &$object->error);
89 }*/
90 
91 $extrafields = new ExtraFields($db);
92 
93 $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
94 $hookmanager->initHooks(array('positioncard', 'globalcard')); // Note that conf->hooks_modules contains array
95 
96 // Fetch optionals attributes and labels
97 $extrafields->fetch_name_optionals_label($object->table_element);
98 
99 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
100 
101 // Initialize array of search criterias
102 $search_all = GETPOST("search_all", 'alpha');
103 $search = array();
104 foreach ($object->fields as $key => $val) {
105  if (GETPOST('search_' . $key, 'alpha')) {
106  $search[$key] = GETPOST('search_' . $key, 'alpha');
107  }
108 }
109 
110 if (empty($action) && empty($id) && empty($ref)) {
111  $action = 'view';
112 }
113 
114 // Load object
115 include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
116 
117 
118 /*
119  * Actions
120  */
121 
122 $parameters = array();
123 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
124 if ($reshook < 0) {
125  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126 }
127 
128 if (empty($reshook)) {
129  $error = 0;
130 
131  $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
132 
133  if (empty($backtopage) || ($cancel && empty($fk_job))) {
134  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
135  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
136  $backtopage = $backurlforlist;
137  } else {
138  $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
139  }
140  }
141  }
142 
143  $triggermodname = 'hrm_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
144 
145  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
146  include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
147 
148  // Actions when linking object each other
149  include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
150 
151  // Actions when printing a doc from card
152  include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
153 
154  // Action to move up and down lines of object
155  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
156 
157  // Action to build doc
158  include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
159 
160  if ($action == 'set_thirdparty' && $permissiontoadd) {
161  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
162  }
163  if ($action == 'classin' && $permissiontoadd) {
164  $object->setProject(GETPOST('projectid', 'int'));
165  }
166 
167  // Actions to send emails
168  $triggersendname = 'hrm_POSITION_SENTBYMAIL';
169  $autocopy = 'MAIN_MAIL_AUTOCOPY_POSITION_TO';
170  $trackid = 'position' . $object->id;
171  include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
172 }
173 
174 
175 displayPositionCard($object);
176 
177 
184 function displayPositionCard(&$object)
185 {
186  global $user, $langs, $db, $conf, $extrafields, $hookmanager, $action, $permissiontoadd, $permissiontodelete;
187 
188  $id = $object->id;
189 
190  /*
191  * View
192  *
193  * Put here all code to build page
194  */
195 
196  $form = new Form($db);
197  $formfile = new FormFile($db);
198  $formproject = new FormProjets($db);
199 
200  $title = $langs->trans("Position");
201  $help_url = '';
202  llxHeader('', $title, $help_url);
203 
204 
205  // Part to edit record
206  if (($id || $ref) && $action == 'edit') {
207  print load_fiche_titre($langs->trans("Position"), '', 'object_' . $object->picto);
208 
209  print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
210  print '<input type="hidden" name="token" value="' . newToken() . '">';
211  print '<input type="hidden" name="action" value="update">';
212  print '<input type="hidden" name="id" value="' . $object->id . '">';
213 
214  if ($backtopage) {
215  print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
216  }
217  if ($backtopageforcancel) {
218  print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
219  }
220 
221  print dol_get_fiche_head();
222 
223  print '<table class="border centpercent tableforfieldedit">' . "\n";
224 
225  // Common attributes
226  include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
227 
228  // Other attributes
229  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
230 
231  print '</table>';
232 
233  print dol_get_fiche_end();
234 
235  print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
236  print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
237  print '</div>';
238 
239  print '</form>';
240  }
241 
242 
243  // Part to show record
244  if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
245  $res = $object->fetch_optionals();
246 
247 
248  $head = positionCardPrepareHead($object);
249  print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
250 
251  $formconfirm = '';
252 
253  // Confirmation to delete
254  if ($action == 'delete') {
255  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePosition'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
256  }
257 
258  // Call Hook formConfirm
259  $parameters = array('formConfirm' => $formconfirm/*, 'lineid' => $lineid*/);
260  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
261  if (empty($reshook)) {
262  $formconfirm .= $hookmanager->resPrint;
263  } elseif ($reshook > 0) {
264  $formconfirm = $hookmanager->resPrint;
265  }
266 
267  // Print form confirm
268  print $formconfirm;
269 
270 
271  // Object card
272  // ------------------------------------------------------------
273  // $linkback = '<a href="' . dol_buildpath('/hrm/position.php', 1) . '?restore_lastsearch_values=1' . (!empty($object->fk_job) ? '&fk_job=' . $object->fk_job : '') . '">' . $langs->trans("BackToList") . '</a>';
274  $linkback = '<a href="' . dol_buildpath('/hrm/position_list.php', 1) . '">' . $langs->trans("BackToList") . '</a>';
275 
276  $morehtmlref = '<div class="refidno">';
277  $u_position = new User(($db));
278  $u_position->fetch($object->fk_user);
279  $morehtmlref .= $langs->trans('Employee').' : '.($u_position->id > 0 ? $u_position->getNomUrl(1) : '');
280  $job = new Job($db);
281  $job->fetch($object->fk_job);
282  $morehtmlref .= '<br>'.$langs->trans('Job').' : '.$job->getNomUrl(1);
283  $morehtmlref .= '</div>';
284 
285  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
286 
287 
288  print '<div class="fichecenter">';
289  print '<div class="fichehalfleft">';
290  print '<div class="underbanner clearboth"></div>';
291  print '<table class="border centpercent tableforfield">' . "\n";
292 
293  // Common attributes
294  //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
295  //unset($object->fields['fk_project']); // Hide field already shown in banner
296  //unset($object->fields['fk_soc']); // Hide field already shown in banner
297  $object->fields['fk_user']['visible']=0; // Already in banner
298  $object->fields['fk_job']['visible']=0; // Already in banner
299  include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
300 
301  // Other attributes. Fields from hook formObjectOptions and Extrafields.
302  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
303 
304  print '</table>';
305  print '</div>';
306  print '</div>';
307 
308  print '<div class="clearboth"></div>';
309 
310  print dol_get_fiche_end();
311 
312  /*
313  * Action bar
314  */
315  print '<div class="tabsAction">';
316 
317  $parameters = array();
318  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
319 
320 
321  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
322 
323  // Delete (need delete permission, or if draft, just need create/modify permission)
324  print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
325  }
326 }
327 
328 //if ($action != 'presend') {
329 // $formfile = new FormFile($db);
330 // print '<div class="fichecenter"><div class="fichehalfleft">';
331 //
332 // if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
333 // print '<a name="builddoc"></a>'; // ancre
334 //
335 // /*
336 // * Generated documents
337 // */
338 // $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
339 // $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
340 // $genallowed = $user->rights->societe->lire;
341 // $delallowed = $user->rights->societe->creer;
342 //
343 // print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
344 // }
345 //
346 //
347 // print '</div><div class="fichehalfright">';
348 //
349 // $MAXEVENT = 10;
350 //
351 // $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
352 //
353 // // List of actions on element
354 // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
355 // $formactions = new FormActions($db);
356 // $somethingshown = $formactions->showactions($object, '', $object->id, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
357 //
358 // print '</div></div>';
359 //}
360 
361 
362 print '</table>' . "\n";
363 print '</div>' . "\n";
364 
365 print '</form>' . "\n";
366 
367 
368 if ($action !== 'edit' && $action !== 'create') {
369  print '<div class="fichecenter"><div class="fichehalfleft">';
370 
371  // Show links to link elements
372  $linktoelem = $form->showLinkToObjectBlock($object, null, array('position'));
373  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
374 
375 
376  print '</div><div class="fichehalfright">';
377 
378  $MAXEVENT = 10;
379 
380  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/position_agenda.php?id='.$object->id);
381 
382  // List of actions on element
383  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
384  $formactions = new FormActions($db);
385  $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
386 
387  print '</div></div>';
388 }
389 
390 
391 // End of page
392 llxFooter();
393 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
positionCardPrepareHead
positionCardPrepareHead($object)
Prepare array of tabs for positions.
Definition: hrm_position.lib.php:34
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
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
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dolGetButtonAction
dolGetButtonAction($label, $html='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10450
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
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:178
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
displayPositionCard
displayPositionCard(&$object)
Show the card of a position.
Definition: position_card.php:184
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
Position
Class for Position.
Definition: position.class.php:36
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
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
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
Job
Class for Job.
Definition: job.class.php:36
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