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