dolibarr 25.0.0-alpha
position.class.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-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
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
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
32
37{
41 public $module = 'hrm';
42
46 public $element = 'position';
47
51 public $table_element = 'hrm_job_user';
52
56 public $picto = 'user-cog';
57
58
59 const STATUS_DRAFT = 0;
60 const STATUS_VALIDATED = 1;
61 const STATUS_CANCELED = 9;
62
63
90 // BEGIN MODULEBUILDER PROPERTIES
94 public $fields = array(
95 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 2, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
96 //'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
97 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
98 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
99 'fk_contrat' => array('type' => 'integer:Contrat:contrat/class/contrat.class.php', 'label' => 'fk_contrat', 'enabled' => 'isModEnabled("contract")', 'position' => 50, 'notnull' => 0, 'visible' => 0,),
100 'fk_user' => array('type' => 'integer:User:user/class/user.class.php:0:(t.statut:=:1)', 'label' => 'Employee', 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'visible' => 1, 'default' => '0', 'picto' => 'user', 'css' => 'maxwidth300 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
101 'fk_job' => array('type' => 'integer:Job:/hrm/class/job.class.php', 'label' => 'JobProfile', 'enabled' => 1, 'position' => 56, 'notnull' => 1, 'visible' => 1, 'picto' => 'jobprofile', 'css' => 'maxwidth300 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
102 'date_start' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'position' => 101, 'notnull' => 1, 'visible' => 1,),
103 'date_end' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'position' => 102, 'notnull' => 0, 'visible' => 1,),
104 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 3,),
105 'abort_comment' => array('type' => 'varchar(255)', 'label' => 'AbandonmentComment', 'enabled' => 'getDolGlobalInt("HRM_JOB_POSITON_ENDING_COMMENT")', 'position' => 502, 'notnull' => 0, 'visible' => 1,),
106 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 151, 'notnull' => 0, 'visible' => 0,),
107 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 152, 'notnull' => 0, 'visible' => 0,),
108 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
109 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
110 );
114 public $rowid;
118 public $ref;
122 public $description;
126 public $fk_contrat;
130 public $fk_user;
134 public $fk_job;
138 public $date_start;
142 public $date_end;
146 public $abort_comment;
150 public $note_public;
154 public $note_private;
158 public $fk_user_creat;
162 public $fk_user_modif;
163
164
165 // END MODULEBUILDER PROPERTIES
166
167
168 // If this object has a subtable with lines
169
170 // /**
171 // * @var string Name of subtable line
172 // */
173 // public $table_element_line = 'hrm_job_userline';
174
175 // /**
176 // * @var string Field with ID of parent key if this object has a parent
177 // */
178 // public $fk_element = 'fk_position';
179
180 // /**
181 // * @var string Name of subtable class that manage subtable lines
182 // */
183 // public $class_element_line = 'Positionline';
184
185 // /**
186 // * @var array List of child tables. To test if we can delete object.
187 // */
188 // protected $childtables = array();
189
190 // /**
191 // * @var array List of child tables. To know object to delete on cascade.
192 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
193 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
194 // */
195 // protected $childtablesoncascade = array('hrm_job_userdet');
196
197 // /**
198 // * @var PositionLine[] Array of subtable lines
199 // */
200 // public $lines = array();
201
202
208 public function __construct(DoliDB $db)
209 {
210 global $langs;
211
212 $this->db = $db;
213
214 $this->ismultientitymanaged = 0;
215 $this->isextrafieldmanaged = 0;
216
217 //if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
218 //$this->fields['rowid']['visible'] = 0;
219 //}
220 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
221 $this->fields['entity']['enabled'] = 0;
222 }
223
224 // Example to show how to set values of fields definition dynamically
225 /*if ($user->rights->hrm->position->read) {
226 $this->fields['myfield']['visible'] = 1;
227 $this->fields['myfield']['noteditable'] = 0;
228 }*/
229
230 // Unset fields that are disabled
231 foreach ($this->fields as $key => $val) {
232 if (isset($val['enabled']) && empty($val['enabled'])) {
233 unset($this->fields[$key]);
234 }
235 }
236
237 // Translate some data of arrayofkeyval
238 if (is_object($langs)) {
239 foreach ($this->fields as $key => $val) {
240 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
241 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
242 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
243 }
244 }
245 }
246 }
247 }
248
256 public function create(User $user, $notrigger = 0)
257 {
258 $resultcreate = $this->createCommon($user, $notrigger);
259
260 //$resultvalidate = $this->validate($user, $notrigger);
261
262 return $resultcreate;
263 }
264
272 public function createFromClone(User $user, $fromid)
273 {
274 global $langs, $extrafields;
275 $error = 0;
276
277 dol_syslog(__METHOD__, LOG_DEBUG);
278
279 $object = new self($this->db);
280
281 $this->db->begin();
282
283 // Load source object
284 $result = $object->fetchCommon($fromid);
285 if ($result > 0 && !empty($object->table_element_line)) {
286 $object->fetchLines();
287 }
288
289 // get lines so they will be clone
290 //foreach($this->lines as $line)
291 // $line->fetch_optionals();
292
293 // Reset some properties
294 unset($object->id);
295 unset($object->fk_user_creat);
296 unset($object->user_ceation_id);
297 unset($object->import_key);
298
299 // Clear fields
300 if (property_exists($object, 'ref')) {
301 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_" . $object->ref : $this->fields['ref']['default'];
302 }
303 if (property_exists($object, 'status')) {
304 $object->status = self::STATUS_DRAFT;
305 }
306 if (property_exists($object, 'date_creation')) {
307 $object->date_creation = dol_now();
308 }
309 if (property_exists($object, 'date_modification')) {
310 $object->date_modification = null;
311 }
312 // ...
313 // Clear extrafields that are unique
314 if (is_array($object->array_options) && count($object->array_options) > 0) {
315 $extrafields->fetch_name_optionals_label($this->table_element);
316 foreach ($object->array_options as $key => $option) {
317 $shortkey = preg_replace('/options_/', '', $key);
318 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
319 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
320 unset($object->array_options[$key]);
321 }
322 }
323 }
324
325 // Create clone
326 $object->context['createfromclone'] = 'createfromclone';
327 $result = $object->createCommon($user);
328 if ($result < 0) {
329 $error++;
331 }
332
333 if (!$error) {
334 // copy internal contacts
335 if ($this->copy_linked_contact($object, 'internal') < 0) {
336 $error++;
337 }
338 }
339
340 unset($object->context['createfromclone']);
341
342 // End
343 if (!$error) {
344 $this->db->commit();
345 return $object;
346 } else {
347 $this->db->rollback();
348 return -1;
349 }
350 }
351
359 public function fetch($id, $ref = null)
360 {
361 $result = $this->fetchCommon($id, $ref);
362 if ($result > 0 && !empty($this->table_element_line)) {
363 $this->fetchLines();
364 }
365 return $result;
366 }
367
373 public function fetchLines()
374 {
375 $this->lines = array();
376
377 $result = $this->fetchLinesCommon();
378 return $result;
379 }
380
381
394 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
395 {
396 dol_syslog(__METHOD__, LOG_DEBUG);
397
398 $records = array();
399
400 $sql = 'SELECT ';
401 $sql .= $this->getFieldList('t');
402 $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
403 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
404 $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
405 } else {
406 $sql .= ' WHERE 1 = 1';
407 }
408
409 // Manage filter
410 $errormessage = '';
411 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
412 if ($errormessage) {
413 $this->errors[] = $errormessage;
414 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
415 return -1;
416 }
417
418 if (!empty($sortfield)) {
419 $sql .= $this->db->order($sortfield, $sortorder);
420 }
421 if (!empty($limit)) {
422 $sql .= ' ' . $this->db->plimit($limit, $offset);
423 }
424
425 $resql = $this->db->query($sql);
426 if ($resql) {
427 $num = $this->db->num_rows($resql);
428 $i = 0;
429 while ($i < ($limit ? min($limit, $num) : $num)) {
430 $obj = $this->db->fetch_object($resql);
431
432 $record = new self($this->db);
433 $record->setVarsFromFetchObj($obj);
434
435 $records[$record->id] = $record;
436
437 $i++;
438 }
439 $this->db->free($resql);
440
441 return $records;
442 } else {
443 $this->errors[] = 'Error ' . $this->db->lasterror();
444 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
445
446 return -1;
447 }
448 }
449
457 public function update(User $user, $notrigger = 0)
458 {
459 return $this->updateCommon($user, $notrigger);
460 }
461
469 public function delete(User $user, $notrigger = 0)
470 {
471 return $this->deleteCommon($user, $notrigger);
472 //return $this->deleteCommon($user, $notrigger, 1);
473 }
474
483 public function deleteLine(User $user, $idline, $notrigger = 0)
484 {
485 if ($this->status < 0) {
486 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
487 return -2;
488 }
489
490 return $this->deleteLineCommon($user, $idline, $notrigger);
491 }
492
493
501 public function validate($user, $notrigger = 0)
502 {
503 global $conf, $langs;
504
505 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
506
507 $error = 0;
508
509 // Protection
510 if ($this->status == self::STATUS_VALIDATED) {
511 dol_syslog(get_class($this) . "::validate action abandoned: already validated", LOG_WARNING);
512 return 0;
513 }
514
515 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->position->write))
516 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->position->position_advance->validate))))
517 {
518 $this->error='NotEnoughPermissions';
519 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
520 return -1;
521 }*/
522
523 $now = dol_now();
524
525 $this->db->begin();
526
527 // Define new ref
528 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
529 $num = $this->getNextNumRef();
530 } else {
531 $num = (string) $this->ref;
532 }
533 $this->newref = $num;
534
535 if (!empty($num)) {
536 // Validate
537 $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
538 $sql .= " SET ref = '" . $this->db->escape($num) . "',";
539 $sql .= " status = " . self::STATUS_VALIDATED;
540 if (!empty($this->fields['date_validation'])) {
541 $sql .= ", date_validation = '" . $this->db->idate($now) . "'";
542 }
543 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
544 $sql .= ", fk_user_valid = " . ((int) $user->id);
545 }
546 $sql .= " WHERE rowid = " . ((int) $this->id);
547
548 dol_syslog(get_class($this) . "::validate()", LOG_DEBUG);
549 $resql = $this->db->query($sql);
550 if (!$resql) {
551 dol_print_error($this->db);
552 $this->error = $this->db->lasterror();
553 $error++;
554 }
555
556 if (!$error && !$notrigger) {
557 // Call trigger
558 $result = $this->call_trigger('HRM_POSITION_VALIDATE', $user);
559 if ($result < 0) {
560 $error++;
561 }
562 // End call triggers
563 }
564 }
565
566 if (!$error) {
567 $this->oldref = $this->ref;
568
569 // Rename directory if dir was a temporary ref
570 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
571 // Now we rename also files into index
572 $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'position/" . $this->db->escape($this->newref) . "'";
573 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'position/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
574 $resql = $this->db->query($sql);
575 if (!$resql) {
576 $error++;
577 $this->error = $this->db->lasterror();
578 }
579 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'position/".$this->db->escape($this->newref)."'";
580 $sql .= " WHERE filepath = 'position/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
581 $resql = $this->db->query($sql);
582 if (!$resql) {
583 $error++;
584 $this->error = $this->db->lasterror();
585 }
586
587 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
588 $oldref = dol_sanitizeFileName($this->ref);
589 $newref = dol_sanitizeFileName($num);
590 $dirsource = $conf->hrm->dir_output . '/position/' . $oldref;
591 $dirdest = $conf->hrm->dir_output . '/position/' . $newref;
592 if (!$error && file_exists($dirsource)) {
593 dol_syslog(get_class($this) . "::validate() rename dir " . $dirsource . " into " . $dirdest);
594
595 if (@rename($dirsource, $dirdest)) {
596 dol_syslog("Rename ok");
597 // Rename docs starting with $oldref with $newref
598 $listoffiles = dol_dir_list($conf->hrm->dir_output . '/position/' . $newref, 'files', 1, '^' . preg_quote($oldref, '/'));
599 foreach ($listoffiles as $fileentry) {
600 $dirsource = $fileentry['name'];
601 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
602 $dirsource = $fileentry['path'] . '/' . $dirsource;
603 $dirdest = $fileentry['path'] . '/' . $dirdest;
604 @rename($dirsource, $dirdest);
605 }
606 }
607 }
608 }
609 }
610
611 // Set new ref and current status
612 if (!$error) {
613 $this->ref = $num;
614 $this->status = self::STATUS_VALIDATED;
615 }
616
617 if (!$error) {
618 $this->db->commit();
619 return 1;
620 } else {
621 $this->db->rollback();
622 return -1;
623 }
624 }
625
626
634 public function setDraft($user, $notrigger = 0)
635 {
636 // Protection
637 if ($this->status <= self::STATUS_DRAFT) {
638 return 0;
639 }
640
641 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
642 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
643 {
644 $this->error='Permission denied';
645 return -1;
646 }*/
647
648 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'POSITION_UNVALIDATE');
649 }
650
658 public function cancel($user, $notrigger = 0)
659 {
660 // Protection
661 if ($this->status != self::STATUS_VALIDATED) {
662 return 0;
663 }
664
665 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
666 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
667 {
668 $this->error='Permission denied';
669 return -1;
670 }*/
671
672 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'POSITION_CANCEL');
673 }
674
682 public function reopen($user, $notrigger = 0)
683 {
684 // Protection
685 if ($this->status != self::STATUS_CANCELED) {
686 return 0;
687 }
688
689 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
690 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
691 {
692 $this->error='Permission denied';
693 return -1;
694 }*/
695
696 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'POSITION_REOPEN');
697 }
698
709 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
710 {
711 global $conf, $langs, $hookmanager;
712
713 if (!empty($conf->dol_no_mouse_hover)) {
714 $notooltip = 1; // Force disable tooltips
715 }
716
717 $result = '';
718
719 $label = img_picto('', $this->picto) . ' <u>' . $langs->trans("Position") . '</u>';
720 if (isset($this->status)) {
721 $label .= ' ' . $this->getLibStatut(5);
722 }
723 $label .= '<br>';
724 $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
725
726 $url = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . $this->id;
727
728 if ($option != 'nolink') {
729 // Add param to save lastsearch_values or not
730 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
731 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
732 $add_save_lastsearch_values = 1;
733 }
734 if ($add_save_lastsearch_values) {
735 $url .= '&save_lastsearch_values=1';
736 }
737 }
738
739 $linkclose = '';
740 if (empty($notooltip)) {
741 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
742 $label = $langs->trans("ShowPosition");
743 $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
744 }
745 $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
746 $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
747 } else {
748 $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
749 }
750
751 if ($option == 'nolink') {
752 $linkstart = '<span';
753 } else {
754 $linkstart = '<a href="' . $url . '"';
755 }
756 $linkstart .= $linkclose . '>';
757 if ($option == 'nolink') {
758 $linkend = '</span>';
759 } else {
760 $linkend = '</a>';
761 }
762
763 $result .= $linkstart;
764
765 if (empty($this->showphoto_on_popup)) {
766 if ($withpicto) {
767 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
768 }
769 } else {
770 if ($withpicto) {
771 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
772
773 list($class, $module) = explode('@', $this->picto);
774 $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
775 $filearray = dol_dir_list($upload_dir, "files");
776 $filename = $filearray[0]['name'];
777 if (!empty($filename)) {
778 $pospoint = strpos($filearray[0]['name'], '.');
779
780 $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . dol_substr($filename, 0, $pospoint) . '_mini' . dol_substr($filename, $pospoint);
781 if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) {
782 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $module . '" alt="No photo" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div></div>';
783 } else {
784 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>';
785 }
786
787 $result .= '</div>';
788 } else {
789 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
790 }
791 }
792 }
793
794 if ($withpicto != 2) {
795 $result .= $this->ref;
796 }
797
798 $result .= $linkend;
799 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
800
801 global $action, $hookmanager;
802 $hookmanager->initHooks(array('positiondao'));
803 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
804 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
805 if ($reshook > 0) {
806 $result = $hookmanager->resPrint;
807 } else {
808 $result .= $hookmanager->resPrint;
809 }
810
811 return $result;
812 }
813
820 public function getLibStatut($mode = 0)
821 {
822 return $this->LibStatut($this->status, $mode);
823 }
824
825 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
826
834 public function LibStatut($status, $mode = 0)
835 {
836 // phpcs:enable
837 if (is_null($status)) {
838 return '';
839 }
840
841 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
842 global $langs;
843 //$langs->load("hrm");
844 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
845 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
846 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
847 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
848 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
849 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
850 }
851
852 $statusType = 'status' . $status;
853 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
854 if ($status == self::STATUS_CANCELED) {
855 $statusType = 'status6';
856 }
857
858 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
859 }
860
875 public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0)
876 {
877 global $langs;
878
879 if ($key == 'fk_user') {
880 $vacantId = $keyprefix.$key.'vacant'.$keysuffix;
881
882 $out = parent::showInputField(null, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
883 $out .= '<label class="nowrap position-fk-user classfortooltip" title="'.dolPrintHTMLForAttribute($langs->trans('VacantCheckboxHelper')).'"><input type="checkbox" id="'.$vacantId.'" name="'.$vacantId.'">&nbsp;'.$langs->trans("Vacant").'</label>'; ?>
884 <script type="text/javascript">
885 $(document).ready(function () {
886 var checkbox = $('#<?php print $vacantId; ?>');
887 var searchfkuser = $('#<?php print $keyprefix.$key.$keysuffix; ?>');
888 checkbox.click(function () {
889 if (checkbox.prop('checked')) {
890 searchfkuser.val(0).trigger('change');
891 searchfkuser.prop('disabled', 1);
892 } else {
893 searchfkuser.prop('disabled', 0);
894 }
895 });
896 });
897 </script>
898 <?php
899 } else {
900 $out = parent::showInputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
901 }
902
903 return $out;
904 }
905
919 public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
920 {
921 global $langs;
922
923 if ($key == 'fk_user' && $this->fk_user == 0) {
924 return $langs->trans("VacantPosition");
925 }
926 return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
927 }
928
929
936 public function info($id)
937 {
938 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
939 $sql .= ' fk_user_creat, fk_user_modif';
940 $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
941 $sql .= ' WHERE t.rowid = ' . ((int) $id);
942 $result = $this->db->query($sql);
943 if ($result) {
944 if ($this->db->num_rows($result)) {
945 $obj = $this->db->fetch_object($result);
946
947 $this->id = $obj->rowid;
948
949 $this->user_creation_id = $obj->fk_user_creat;
950 $this->user_modification_id = $obj->fk_user_modif;
951 $this->date_creation = $this->db->jdate($obj->datec);
952 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
953 }
954
955 $this->db->free($result);
956 } else {
957 dol_print_error($this->db);
958 }
959 }
960
967 public function initAsSpecimen()
968 {
969 // Set here init that are not commonf fields
970 // $this->property1 = ...
971 // $this->property2 = ...
972
973 return $this->initAsSpecimenCommon();
974 }
975
981 public function getLinesArray()
982 {
983 $this->lines = array();
984
985 $objectline = new PositionLine($this->db);
986 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_position:=:'.((int) $this->id).')');
987
988 if (is_numeric($result)) {
989 $this->setErrorsFromObject($objectline);
990 return $result;
991 } else {
992 $this->lines = $result;
993 return $this->lines;
994 }
995 }
996
1002 public function getNextNumRef()
1003 {
1004 global $langs, $conf;
1005 $langs->load("hrm");
1006
1007 if (!getDolGlobalString('hrm_POSITION_ADDON')) {
1008 $conf->global->hrm_POSITION_ADDON = 'mod_position_standard';
1009 }
1010
1011 if (getDolGlobalString('hrm_POSITION_ADDON')) {
1012 $mybool = false;
1013
1014 $file = getDolGlobalString('hrm_POSITION_ADDON') . ".php";
1015 $classname = getDolGlobalString('hrm_POSITION_ADDON');
1016
1017 // Include file with class
1018 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1019 foreach ($dirmodels as $reldir) {
1020 $dir = dol_buildpath($reldir . "core/modules/hrm/");
1021
1022 // Load file with numbering class (if found)
1023 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1024 }
1025
1026 if (!$mybool) {
1027 dol_print_error(null, "Failed to include file " . $file);
1028 return '';
1029 }
1030
1031 if (class_exists($classname)) {
1032 $obj = new $classname();
1033 '@phan-var-force ModeleNumRefEvaluation $obj';
1034 $numref = $obj->getNextValue($this);
1035
1036 if ($numref != '' && $numref != '-1') {
1037 return $numref;
1038 } else {
1039 $this->error = $obj->error;
1040 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1041 return "";
1042 }
1043 } else {
1044 print $langs->trans("Error") . " " . $langs->trans("ClassNotFound") . ' ' . $classname;
1045 return "";
1046 }
1047 } else {
1048 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1049 return "";
1050 }
1051 }
1052
1059 public function getForUser($userid)
1060 {
1061 $TPosition = array();
1062
1063 $TPosition = $this->fetchAll('ASC', 't.rowid', 0, 0, '(fk_user:=:'.((int) $userid).')');
1064
1065 return $TPosition;
1066 }
1067
1079 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1080 {
1081 global $conf, $langs;
1082
1083 $result = 0;
1084 $includedocgeneration = 0;
1085
1086 $langs->load("hrm");
1087
1088 if (!dol_strlen($modele)) {
1089 $modele = 'standard_position';
1090
1091 if (!empty($this->model_pdf)) {
1092 $modele = $this->model_pdf;
1093 } elseif (getDolGlobalString('POSITION_ADDON_PDF')) {
1094 $modele = getDolGlobalString('POSITION_ADDON_PDF');
1095 }
1096 }
1097
1098 $modelpath = "core/modules/hrm/doc/";
1099
1100 if ($includedocgeneration && !empty($modele)) {
1101 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1102 }
1103
1104 return $result;
1105 }
1106
1114 public function getKanbanView($option = '', $arraydata = null)
1115 {
1116 global $selected, $langs;
1117
1118 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1119
1120 $return = '<div class="box-flex-item box-flex-grow-zero">';
1121 $return .= '<div class="info-box info-box-sm">';
1122 $return .= '<span class="info-box-icon bg-infobox-action">';
1123 $return .= img_picto('', $this->picto);
1124 $return .= '</span>';
1125 $return .= '<div class="info-box-content">';
1126 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1127 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1128 if (!empty($arraydata['user'])) {
1129 $return .= '<br><span class="info-box-label ">'.$arraydata['user'].'</span>';
1130 }
1131 if (!empty($arraydata['job'])) {
1132 //$return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("JobProfile").'</span> : ';
1133 $return .= '<br><span class="info-box-label ">'.$arraydata['job'].'</span>';
1134 }
1135 if (property_exists($this, 'date_start') && property_exists($this, 'date_end')) {
1136 $return .= '<br><div class ="nothing"><span class="info-box-label ">'.dol_print_date($this->db->jdate($this->date_start), 'day').'</span>';
1137 $return .= ' - <span class="info-box-label ">'.dol_print_date($this->db->jdate($this->date_end), 'day').'</span></div>';
1138 }
1139 $return .= '</div>';
1140 $return .= '</div>';
1141 $return .= '</div>';
1142 return $return;
1143 }
1144}
1145
1146
1147require_once DOL_DOCUMENT_ROOT . '/core/class/commonobjectline.class.php';
1148
1153{
1154 // To complete with content of an object PositionLine
1155 // We should have a field rowid , fk_position and position
1156
1162 public function __construct(DoliDB $db)
1163 {
1164 $this->db = $db;
1165
1166 $this->isextrafieldmanaged = 0;
1167 }
1168}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Position.
validate($user, $notrigger=0)
Validate object.
cancel($user, $notrigger=0)
Set cancel status.
info($id)
Load the info information in the object.
update(User $user, $notrigger=0)
Update object into database.
getLibStatut($mode=0)
Return the label of the status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getLinesArray()
Create an array of lines.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
setDraft($user, $notrigger=0)
Set draft status.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
fetch($id, $ref=null)
Load object in memory from the database.
showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0, $nonewbutton=0)
Return HTML string to put an input field into a page Code very similar with showInputField of extra f...
create(User $user, $notrigger=0)
Create object into database.
showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='')
Return HTML string to show a field into a page Code very similar with showOutputField of extra fields...
LibStatut($status, $mode=0)
Return the status.
getForUser($userid)
getForUser
reopen($user, $notrigger=0)
Set back to validated status.
fetchLines()
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
__construct(DoliDB $db)
Constructor.
Class PositionLine.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183