dolibarr 19.0.3
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
30require '../main.inc.php';
31
32require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
35require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
36require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
37require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
38//dol_include_once('/hrm/position.php');
39
40// Get Parameters
41$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
42$backtopage = GETPOST('backtopage', 'alpha');
43$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
44$id = GETPOST('id', 'int');
45
46// Initialize technical objects
47$form = new Form($db);
48$object = new Position($db);
49$res = $object->fetch($id);
50if ($res < 0) {
51 dol_print_error($db, $object->error);
52}
53
54// Permissions
55$permissiontoread = $user->rights->hrm->all->read;
56$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
57$permissiontodelete = $user->rights->hrm->all->delete;
58$permissiondellink = $user->rights->hrm->all->write; // Used by the include of actions_dellink.inc.php
59$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
60
61// Security check (enable the most restrictive one)
62//if ($user->socid > 0) accessforbidden();
63//if ($user->socid > 0) $socid = $user->socid;
64//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
65//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
66if (empty($conf->hrm->enabled)) {
68}
69if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
71}
72
73$langs->loadLangs(array("hrm", "other"));
74
75
76
77// Get parameters
78$id = GETPOST('id', 'int');
79$fk_job = GETPOST('fk_job', 'int');
80
81$ref = GETPOST('ref', 'alpha');
82$action = GETPOST('action', 'aZ09');
83$confirm = GETPOST('confirm', 'alpha');
84$cancel = GETPOST('cancel', 'aZ09');
85$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
86$backtopage = GETPOST('backtopage', 'alpha');
87$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
88// $lineid = GETPOST('lineid', 'int');
89
90// Initialize technical objects
91//$object = new Position($db);
92//$res = $object->fetch($id);
93/*if ($res < 0) {
94 dol_print_error($db, &$object->error);
95}*/
96
97$extrafields = new ExtraFields($db);
98
99$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
100$hookmanager->initHooks(array('positioncard', 'globalcard')); // Note that conf->hooks_modules contains array
101
102// Fetch optionals attributes and labels
103$extrafields->fetch_name_optionals_label($object->table_element);
104
105$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
106
107// Initialize array of search criterias
108$search_all = GETPOST("search_all", 'alpha');
109$search = array();
110foreach ($object->fields as $key => $val) {
111 if (GETPOST('search_' . $key, 'alpha')) {
112 $search[$key] = GETPOST('search_' . $key, 'alpha');
113 }
114}
115
116if (empty($action) && empty($id) && empty($ref)) {
117 $action = 'view';
118}
119
120// Load object
121include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
122
123
124/*
125 * Actions
126 */
127
128$parameters = array();
129$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
130if ($reshook < 0) {
131 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
132}
133
134if (empty($reshook)) {
135 $error = 0;
136
137 $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
138
139 if (empty($backtopage) || ($cancel && empty($fk_job))) {
140 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
141 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
142 $backtopage = $backurlforlist;
143 } else {
144 $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
145 }
146 }
147 }
148
149 $triggermodname = 'HRM_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
150
151 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
152 include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
153
154 // Actions when linking object each other
155 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
156
157 // Actions when printing a doc from card
158 include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
159
160 // Action to move up and down lines of object
161 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
162
163 // Action to build doc
164 include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
165
166 if ($action == 'set_thirdparty' && $permissiontoadd) {
167 $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
168 }
169 if ($action == 'classin' && $permissiontoadd) {
170 $object->setProject(GETPOST('projectid', 'int'));
171 }
172
173 // Actions to send emails
174 $triggersendname = 'HRM_POSITION_SENTBYMAIL';
175 $autocopy = 'MAIN_MAIL_AUTOCOPY_POSITION_TO';
176 $trackid = 'position' . $object->id;
177 include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
178}
179
180
181/*
182 * View
183 */
184
185displayPositionCard($object);
186
187
188
195function displayPositionCard(&$object)
196{
197 global $user, $langs, $db, $conf, $extrafields, $hookmanager, $action, $permissiontoadd, $permissiontodelete;
198
199 $id = $object->id;
200 $ref = $object->ref;
201
202 /*
203 * View
204 *
205 * Put here all code to build page
206 */
207
208 $form = new Form($db);
209 $formfile = new FormFile($db);
210 $formproject = new FormProjets($db);
211
212 $backtopage = GETPOST('backtopage', 'alpha');
213 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
214
215 $title = $langs->trans("Position");
216 $help_url = '';
217 llxHeader('', $title, $help_url);
218
219
220 // Part to edit record
221 if (($id || $ref) && $action == 'edit') {
222 print load_fiche_titre($langs->trans("Position"), '', 'object_' . $object->picto);
223
224 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
225 print '<input type="hidden" name="token" value="' . newToken() . '">';
226 print '<input type="hidden" name="action" value="update">';
227 print '<input type="hidden" name="id" value="' . $object->id . '">';
228
229 if ($backtopage) {
230 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
231 }
232 if ($backtopageforcancel) {
233 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
234 }
235
236 print dol_get_fiche_head();
237
238 print '<table class="border centpercent tableforfieldedit">' . "\n";
239
240 // Common attributes
241 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
242
243 // Other attributes
244 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
245
246 print '</table>';
247
248 print dol_get_fiche_end();
249
250 print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
251 print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
252 print '</div>';
253
254 print '</form>';
255 }
256
257
258 // Part to show record
259 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
260 $res = $object->fetch_optionals();
261
262
263 $head = positionCardPrepareHead($object);
264 print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
265
266 $formconfirm = '';
267
268 // Confirmation to delete
269 if ($action == 'delete') {
270 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePosition'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
271 }
272
273 // Call Hook formConfirm
274 $parameters = array('formConfirm' => $formconfirm/*, 'lineid' => $lineid*/);
275 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
276 if (empty($reshook)) {
277 $formconfirm .= $hookmanager->resPrint;
278 } elseif ($reshook > 0) {
279 $formconfirm = $hookmanager->resPrint;
280 }
281
282 // Print form confirm
283 print $formconfirm;
284
285
286 // Object card
287 // ------------------------------------------------------------
288 $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/position_list.php">'.$langs->trans("BackToList").'</a>';
289
290 $morehtmlref = '<div class="refidno">';
291 $u_position = new User(($db));
292 $u_position->fetch($object->fk_user);
293 $morehtmlref .= ($u_position->id > 0 ? $u_position->getNomUrl(1) : $langs->trans('Employee').' : ');
294 $job = new Job($db);
295 $job->fetch($object->fk_job);
296 $morehtmlref .= '<br>'.$langs->trans('JobProfile').' : '.$job->getNomUrl(1);
297 $morehtmlref .= '</div>';
298
299 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
300
301
302 print '<div class="fichecenter">';
303 print '<div class="fichehalfleft">';
304 print '<div class="underbanner clearboth"></div>';
305 print '<table class="border centpercent tableforfield">' . "\n";
306
307 // Common attributes
308 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
309 //unset($object->fields['fk_project']); // Hide field already shown in banner
310 //unset($object->fields['fk_soc']); // Hide field already shown in banner
311 $object->fields['fk_user']['visible']=0; // Already in banner
312 $object->fields['fk_job']['visible']=0; // Already in banner
313 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
314
315 // Other attributes. Fields from hook formObjectOptions and Extrafields.
316 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
317
318 print '</table>';
319 print '</div>';
320 print '</div>';
321
322 print '<div class="clearboth"></div>';
323
324 print dol_get_fiche_end();
325
326 /*
327 * Action bar
328 */
329 print '<div class="tabsAction">';
330
331 $parameters = array();
332 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
333
334
335 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
336
337 // Delete (need delete permission, or if draft, just need create/modify permission)
338 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
339 }
340}
341
342//if ($action != 'presend') {
343// $formfile = new FormFile($db);
344// print '<div class="fichecenter"><div class="fichehalfleft">';
345//
346// if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
347// print '<a name="builddoc"></a>'; // ancre
348//
349// /*
350// * Generated documents
351// */
352// $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
353// $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
354// $genallowed = $user->hasRight('societe', 'lire');
355// $delallowed = $user->hasRight('societe', 'creer');
356//
357// 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);
358// }
359//
360//
361// print '</div><div class="fichehalfright">';
362//
363// $MAXEVENT = 10;
364//
365// $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
366//
367// // List of actions on element
368// include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
369// $formactions = new FormActions($db);
370// $somethingshown = $formactions->showactions($object, '', $object->id, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
371//
372// print '</div></div>';
373//}
374
375
376print '</table>' . "\n";
377print '</div>' . "\n";
378
379print '</form>' . "\n";
380
381
382if ($action !== 'edit' && $action !== 'create') {
383 print '<div class="fichecenter"><div class="fichehalfleft">';
384
385 // Show links to link elements
386 $linktoelem = $form->showLinkToObjectBlock($object, null, array('position'));
387 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
388
389
390 print '</div><div class="fichehalfright">';
391
392 $MAXEVENT = 10;
393
394 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/position_agenda.php?id='.$object->id);
395
396 // List of actions on element
397 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
398 $formactions = new FormActions($db);
399 $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
400
401 print '</div></div>';
402}
403
404
405// End of page
406llxFooter();
407$db->close();
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.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class for Job.
Definition job.class.php:37
Class for Position.
Class to manage Dolibarr users.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
positionCardPrepareHead($object)
Prepare array of tabs for positions.
displayPositionCard(&$object)
Show the card of a position.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.