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