dolibarr 21.0.0-beta
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 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', 'aZ09');
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
209 $id = $object->id;
210 $ref = $object->ref;
211
212 /*
213 * View
214 *
215 * Put here all code to build page
216 */
217
218 $form = new Form($db);
219 $formfile = new FormFile($db);
220 $formproject = new FormProjets($db);
221
222 $backtopage = GETPOST('backtopage', 'alpha');
223 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
224
225 $title = $langs->trans("Position");
226 $help_url = '';
227 llxHeader('', $title, $help_url);
228
229
230 // Part to edit record
231 if (($id || $ref) && $action == 'edit') {
232 print load_fiche_titre($langs->trans("Position"), '', 'object_' . $object->picto);
233
234 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
235 print '<input type="hidden" name="token" value="' . newToken() . '">';
236 print '<input type="hidden" name="action" value="update">';
237 print '<input type="hidden" name="id" value="' . $object->id . '">';
238
239 if ($backtopage) {
240 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
241 }
242 if ($backtopageforcancel) {
243 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
244 }
245
246 print dol_get_fiche_head();
247
248 print '<table class="border centpercent tableforfieldedit">' . "\n";
249
250 // Common attributes
251 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
252
253 // Other attributes
254 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
255
256 print '</table>';
257
258 print dol_get_fiche_end();
259
260 print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
261 print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
262 print '</div>';
263
264 print '</form>';
265 }
266
267
268 // Part to show record
269 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
270 $res = $object->fetch_optionals();
271
272
274 print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
275
276 $formconfirm = '';
277
278 // Confirmation to delete
279 if ($action == 'delete') {
280 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePosition'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
281 }
282
283 // Call Hook formConfirm
284 $parameters = array('formConfirm' => $formconfirm/*, 'lineid' => $lineid*/);
285 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
286 if (empty($reshook)) {
287 $formconfirm .= $hookmanager->resPrint;
288 } elseif ($reshook > 0) {
289 $formconfirm = $hookmanager->resPrint;
290 }
291
292 // Print form confirm
293 print $formconfirm;
294
295
296 // Object card
297 // ------------------------------------------------------------
298 $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/position_list.php">'.$langs->trans("BackToList").'</a>';
299
300 $morehtmlref = '<div class="refidno">';
301 $u_position = new User(($db));
302 $u_position->fetch($object->fk_user);
303 $morehtmlref .= ($u_position->id > 0 ? $u_position->getNomUrl(1) : $langs->trans('Employee').' : ');
304 $job = new Job($db);
305 $job->fetch($object->fk_job);
306 $morehtmlref .= '<br>'.$langs->trans('JobProfile').' : '.$job->getNomUrl(1);
307 $morehtmlref .= '</div>';
308
309 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
310
311
312 print '<div class="fichecenter">';
313 print '<div class="fichehalfleft">';
314 print '<div class="underbanner clearboth"></div>';
315 print '<table class="border centpercent tableforfield">' . "\n";
316
317 // Common attributes
318 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
319 //unset($object->fields['fk_project']); // Hide field already shown in banner
320 //unset($object->fields['fk_soc']); // Hide field already shown in banner
321 $object->fields['fk_user']['visible'] = 0; // Already in banner
322 $object->fields['fk_job']['visible'] = 0; // Already in banner
323 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
324
325 // Other attributes. Fields from hook formObjectOptions and Extrafields.
326 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
327
328 print '</table>';
329 print '</div>';
330 print '</div>';
331
332 print '<div class="clearboth"></div>';
333
334 print dol_get_fiche_end();
335
336 /*
337 * Action bar
338 */
339 print '<div class="tabsAction">';
340
341 $parameters = array();
342 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
343
344
345 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
346
347 // Delete (need delete permission, or if draft, just need create/modify permission)
348 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
349 }
350}
351
352//if ($action != 'presend') {
353// $formfile = new FormFile($db);
354// print '<div class="fichecenter"><div class="fichehalfleft">';
355//
356// if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
357// print '<a name="builddoc"></a>'; // ancre
358//
359// /*
360// * Generated documents
361// */
362// $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
363// $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
364// $genallowed = $user->hasRight('societe', 'lire');
365// $delallowed = $user->hasRight('societe', 'creer');
366//
367// 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);
368// }
369//
370//
371// print '</div><div class="fichehalfright">';
372//
373// $MAXEVENT = 10;
374//
375// $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
376//
377// // List of actions on element
378// include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
379// $formactions = new FormActions($db);
380// $somethingshown = $formactions->showactions($object, '', $object->id, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
381//
382// print '</div></div>';
383//}
384
385
386print '</table>' . "\n";
387print '</div>' . "\n";
388
389print '</form>' . "\n";
390
391
392if ($action !== 'edit' && $action !== 'create') {
393 print '<div class="fichecenter"><div class="fichehalfleft">';
394
395 // Show links to link elements
396 $tmparray = $form->showLinkToObjectBlock($object, array(), array('position'), 1);
397 $linktoelem = $tmparray['linktoelem'];
398 $htmltoenteralink = $tmparray['htmltoenteralink'];
399 print $htmltoenteralink;
400
401 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
402
403 print '</div><div class="fichehalfright">';
404
405 $MAXEVENT = 10;
406
407 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/position_agenda.php?id='.$object->id);
408
409 // List of actions on element
410 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
411 $formactions = new FormActions($db);
412 $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
413
414 print '</div></div>';
415}
416
417
418// End of page
419llxFooter();
420$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.