dolibarr 18.0.6
job_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/job.class.php';
36require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array('hrm', 'other', 'products')); // why products?
40
41// Get parameters
42$id = GETPOST('id', 'int');
43$ref = GETPOST('ref', 'alpha');
44$action = GETPOST('action', 'aZ09');
45$confirm = GETPOST('confirm', 'alpha');
46$cancel = GETPOST('cancel', 'aZ09');
47$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'jobcard'; // To manage different context of search
48$backtopage = GETPOST('backtopage', 'alpha');
49$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
50$lineid = GETPOST('lineid', 'int');
51
52// Initialize technical objects
53$object = new Job($db);
54$extrafields = new ExtraFields($db);
55$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
56$hookmanager->initHooks(array('jobcard', 'globalcard')); // Note that conf->hooks_modules contains array
57
58// Fetch optionals attributes and labels
59$extrafields->fetch_name_optionals_label($object->table_element);
60
61$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
62
63// Initialize array of search criterias
64$search_all = GETPOST("search_all", 'alpha');
65$search = array();
66foreach ($object->fields as $key => $val) {
67 if (GETPOST('search_' . $key, 'alpha')) {
68 $search[$key] = GETPOST('search_' . $key, 'alpha');
69 }
70}
71
72if (empty($action) && empty($id) && empty($ref)) {
73 $action = 'view';
74}
75
76// Load object
77include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
78
79// Permissions
80$permissiontoread = $user->rights->hrm->all->read;
81$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
82$permissiontodelete = $user->rights->hrm->all->delete;
83$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/job';
84
85// Security check (enable the most restrictive one)
86//if ($user->socid > 0) accessforbidden();
87//if ($user->socid > 0) $socid = $user->socid;
88//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
89//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
90if (empty($conf->hrm->enabled)) accessforbidden();
91if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
92
93
94/*
95 * Actions
96 */
97
98$parameters = array();
99$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
100if ($reshook < 0) {
101 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
102}
103
104if (empty($reshook)) {
105 $error = 0;
106
107 $backurlforlist = dol_buildpath('/hrm/job_list.php', 1);
108
109 if (empty($backtopage) || ($cancel && empty($id))) {
110 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
111 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
112 $backtopage = $backurlforlist;
113 } else {
114 $backtopage = dol_buildpath('/hrm/job_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
115 }
116 }
117 }
118
119 $triggermodname = 'HRM_JOB_MODIFY'; // Name of trigger action code to execute when we modify record
120
121
122 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
123 include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
124
125 // Actions when linking object each other
126 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
127
128 // Actions when printing a doc from card
129 include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
130
131 // Action to move up and down lines of object
132 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
133
134 // Action to build doc
135 include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
136
137 if ($action == 'set_thirdparty' && $permissiontoadd) {
138 $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
139 }
140 if ($action == 'classin' && $permissiontoadd) {
141 $object->setProject(GETPOST('projectid', 'int'));
142 }
143
144 // Actions to send emails
145 $triggersendname = 'HRM_JOB_SENTBYMAIL';
146 $autocopy = 'MAIN_MAIL_AUTOCOPY_JOB_TO';
147 $trackid = 'job' . $object->id;
148 include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
149}
150
151
152/*
153 * View
154 *
155 * Put here all code to build page
156 */
157
158$form = new Form($db);
159$formfile = new FormFile($db);
160$formproject = new FormProjets($db);
161
162$title = $langs->trans("Job");
163$help_url = '';
164llxHeader('', $title, $help_url);
165
166// Example : Adding jquery code
167// print '<script type="text/javascript" language="javascript">
168// jQuery(document).ready(function() {
169// function init_myfunc()
170// {
171// jQuery("#myid").removeAttr(\'disabled\');
172// jQuery("#myid").attr(\'disabled\',\'disabled\');
173// }
174// init_myfunc();
175// jQuery("#mybutton").click(function() {
176// init_myfunc();
177// });
178// });
179// </script>';
180
181
182// Part to create
183if ($action == 'create') {
184 print load_fiche_titre($langs->trans("NewJobProfile", $langs->transnoentities('Job')), '', 'object_' . $object->picto);
185
186 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
187 print '<input type="hidden" name="token" value="' . newToken() . '">';
188 print '<input type="hidden" name="action" value="add">';
189 if ($backtopage) {
190 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
191 }
192 if ($backtopageforcancel) {
193 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
194 }
195
196 print dol_get_fiche_head(array(), '');
197
198 print '<table class="border centpercent tableforfieldcreate">' . "\n";
199
200 // Common attributes
201 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
202
203 // Other attributes
204 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
205
206 print '</table>' . "\n";
207
208 print dol_get_fiche_end();
209
210 print '<div class="center">';
211 print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag($langs->trans("Create")) . '">';
212 print '&nbsp; ';
213 print '<input type="' . ($backtopage ? "submit" : "button") . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '"' . ($backtopage ? '' : ' onclick="history.go(-1)"') . '>'; // Cancel for create does not post form if we don't know the backtopage
214 print '</div>';
215
216 print '</form>';
217
218 //dol_set_focus('input[name="ref"]');
219}
220
221// Part to edit record
222if (($id || $ref) && $action == 'edit') {
223 print load_fiche_titre($langs->trans("JobProfile"), '', 'object_' . $object->picto);
224
225 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
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 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// Part to show record
258if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
259 $res = $object->fetch_optionals();
260
261 $head = jobPrepareHead($object);
262 $picto = 'company.png';
263 print dol_get_fiche_head($head, 'job_card', $langs->trans("Workstation"), -1, $object->picto);
264
265 $formconfirm = '';
266
267 // Confirmation to delete
268 if ($action == 'delete') {
269 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteJob'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
270 }
271 // Confirmation to delete line
272 if ($action == 'deleteline') {
273 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
274 }
275 // Clone confirmation
276 if ($action == 'clone') {
277 // Create an array for form
278 $formquestion = array();
279 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
280 }
281
282 // Confirmation of action xxxx
283 if ($action == 'xxx') {
284 $formquestion = array();
285 /*
286 $forcecombo=0;
287 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
288 $formquestion = array(
289 // 'text' => $langs->trans("ConfirmClone"),
290 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
291 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
292 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
293 );
294 */
295 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
296 }
297
298 // Call Hook formConfirm
299 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
300 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
301 if (empty($reshook)) {
302 $formconfirm .= $hookmanager->resPrint;
303 } elseif ($reshook > 0) {
304 $formconfirm = $hookmanager->resPrint;
305 }
306
307 // Print form confirm
308 print $formconfirm;
309
310
311 // Object card
312 // ------------------------------------------------------------
313 $linkback = '<a href="' . dol_buildpath('/hrm/job_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
314
315 $morehtmlref = '<div class="refid">';
316 $morehtmlref.= $object->label;
317 $morehtmlref .= '</div>';
318
319
320 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
321
322
323 print '<div class="fichecenter">';
324 print '<div class="fichehalfleft">';
325 print '<div class="underbanner clearboth"></div>';
326 print '<table class="border centpercent tableforfield">'."\n";
327
328 // Common attributes
329 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
330 //unset($object->fields['fk_project']); // Hide field already shown in banner
331 //unset($object->fields['fk_soc']); // Hide field already shown in banner
332 $object->fields['label']['visible']=0; // Already in banner
333 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
334
335 // Other attributes. Fields from hook formObjectOptions and Extrafields.
336 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
337
338 print '</table>';
339 print '</div>';
340 print '</div>';
341
342 print '<div class="clearboth"></div>';
343
344 print dol_get_fiche_end();
345
346
347 /*
348 * Lines
349 */
350
351 if (!empty($object->table_element_line)) {
352 // Show object lines
353 $result = $object->getLinesArray();
354
355 print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
356 <input type="hidden" name="token" value="' . newToken() . '">
357 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
358 <input type="hidden" name="mode" value="">
359 <input type="hidden" name="page_y" value="">
360 <input type="hidden" name="id" value="' . $object->id . '">
361 ';
362
363 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
364 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
365 }
366
367 print '<div class="div-table-responsive-no-min">';
368 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
369 print '<table id="tablelines" class="noborder noshadow" width="100%">';
370 }
371
372 if (!empty($object->lines)) {
373 $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
374 }
375
376 // Form to add new line
377 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
378 if ($action != 'editline') {
379 // Add products/services form
380
381 $parameters = array();
382 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
383 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
384 if (empty($reshook))
385 $object->formAddObjectLine(1, $mysoc, $soc);
386 }
387 }
388
389 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
390 print '</table>';
391 }
392 print '</div>';
393
394 print "</form>\n";
395 }
396
397
398 // Buttons for actions
399
400 if ($action != 'presend' && $action != 'editline') {
401 print '<div class="tabsAction">' . "\n";
402 $parameters = array();
403 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
404 if ($reshook < 0) {
405 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
406 }
407
408 if (empty($reshook)) {
409 // Back to draft
410 if ($object->status == $object::STATUS_VALIDATED) {
411 print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
412 }
413
414 print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
415
416 // Delete (need delete permission, or if draft, just need create/modify permission)
417 print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
418 }
419 print '</div>' . "\n";
420 }
421
422
423 // Select mail models is same action as presend
424 if (GETPOST('modelselected')) {
425 $action = 'presend';
426 }
427
428 if ($action != 'presend') {
429 print '<div class="fichecenter"><div class="fichehalfleft">';
430 print '<a name="builddoc"></a>'; // ancre
431
432 $includedocgeneration = 0;
433
434 // Documents
435 if ($includedocgeneration) {
436 $objref = dol_sanitizeFileName($object->ref);
437 $relativepath = $objref . '/' . $objref . '.pdf';
438 $filedir = $conf->hrm->dir_output . '/' . $object->element . '/' . $objref;
439 $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
440 $genallowed = $user->rights->hrm->job->read; // If you can read, you can build the PDF to read content
441 $delallowed = $user->rights->hrm->job->write; // If you can create/edit, you can remove a file on card
442 print $formfile->showdocuments('hrm:Job', $object->element . '/' . $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
443 }
444
445 // Show links to link elements
446 $linktoelem = $form->showLinkToObjectBlock($object, null, array('job'));
447 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
448
449
450 print '</div><div class="fichehalfright">';
451
452 $MAXEVENT = 10;
453
454 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/job_agenda.php?id='.$object->id);
455
456 // List of actions on element
457 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
458 $formactions = new FormActions($db);
459 $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
460
461 print '</div></div>';
462 }
463
464 // Presend form
465 $modelmail = 'job';
466 $defaulttopic = 'InformationMessage';
467 $diroutput = $conf->hrm->dir_output;
468 $trackid = 'job' . $object->id;
469
470 include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
471}
472
473// End of page
474llxFooter();
475$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:56
llxFooter()
Empty footer.
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:37
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.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
jobPrepareHead($object)
Prepare array of tabs for Job.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.