dolibarr  19.0.0-dev
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  *
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 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
30 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32 
36 class Position extends CommonObject
37 {
41  public $module = 'hrm';
42 
46  public $element = 'position';
47 
51  public $table_element = 'hrm_job_user';
52 
57  public $ismultientitymanaged = 0;
58 
62  public $isextrafieldmanaged = 0;
63 
67  public $picto = 'user-cog';
68 
69 
70  const STATUS_DRAFT = 0;
71  const STATUS_VALIDATED = 1;
72  const STATUS_CANCELED = 9;
73 
74 
101  // BEGIN MODULEBUILDER PROPERTIES
105  public $fields=array(
106  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>2, 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
107  //'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"),
108  'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>3,),
109  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
110  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
111  'fk_contrat' => array('type'=>'integer:Contrat:contrat/class/contrat.class.php', 'label'=>'fk_contrat', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>0,),
112  'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Employee', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>1, 'default'=>0),
113  'fk_job' => array('type'=>'integer:Job:/hrm/class/job.class.php', 'label'=>'JobProfile', 'enabled'=>'1', 'position'=>56, 'notnull'=>1, 'visible'=>1,),
114  'date_start' => array('type'=>'date', 'label'=>'DateStart', 'enabled'=>'1', 'position'=>51, 'notnull'=>1, 'visible'=>1,),
115  'date_end' => array('type'=>'date', 'label'=>'DateEnd', 'enabled'=>'1', 'position'=>52, 'notnull'=>0, 'visible'=>1,),
116  'abort_comment' => array('type'=>'varchar(255)', 'label'=>'AbandonmentComment', 'enabled'=>'getDolGlobalInt("HRM_JOB_POSITON_ENDING_COMMENT")', 'position'=>502, 'notnull'=>0, 'visible'=>1,),
117  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>0,),
118  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>0,),
119  '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',),
120  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
121  );
122  public $rowid;
123  public $ref;
124  public $description;
125  public $date_creation;
126  public $tms;
127  public $fk_contrat;
128  public $fk_user;
129  public $fk_job;
130  public $date_start;
131  public $date_end;
132  public $abort_comment;
133  public $note_public;
134  public $note_private;
135  public $fk_user_creat;
136  public $fk_user_modif;
137 
138 
139  // END MODULEBUILDER PROPERTIES
140 
141 
142  // If this object has a subtable with lines
143 
144  // /**
145  // * @var string Name of subtable line
146  // */
147  // public $table_element_line = 'hrm_job_userline';
148 
149  // /**
150  // * @var string Field with ID of parent key if this object has a parent
151  // */
152  // public $fk_element = 'fk_position';
153 
154  // /**
155  // * @var string Name of subtable class that manage subtable lines
156  // */
157  // public $class_element_line = 'Positionline';
158 
159  // /**
160  // * @var array List of child tables. To test if we can delete object.
161  // */
162  // protected $childtables = array();
163 
164  // /**
165  // * @var array List of child tables. To know object to delete on cascade.
166  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
167  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
168  // */
169  // protected $childtablesoncascade = array('hrm_job_userdet');
170 
171  // /**
172  // * @var PositionLine[] Array of subtable lines
173  // */
174  // public $lines = array();
175 
176 
182  public function __construct(DoliDB $db)
183  {
184  global $conf, $langs;
185 
186  $this->db = $db;
187 
188  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
189  //$this->fields['rowid']['visible'] = 0;
190  }
191  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
192  $this->fields['entity']['enabled'] = 0;
193  }
194 
195  // Example to show how to set values of fields definition dynamically
196  /*if ($user->rights->hrm->position->read) {
197  $this->fields['myfield']['visible'] = 1;
198  $this->fields['myfield']['noteditable'] = 0;
199  }*/
200 
201  // Unset fields that are disabled
202  foreach ($this->fields as $key => $val) {
203  if (isset($val['enabled']) && empty($val['enabled'])) {
204  unset($this->fields[$key]);
205  }
206  }
207 
208  // Translate some data of arrayofkeyval
209  if (is_object($langs)) {
210  foreach ($this->fields as $key => $val) {
211  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
212  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
213  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
214  }
215  }
216  }
217  }
218  }
219 
227  public function create(User $user, $notrigger = false)
228  {
229  $resultcreate = $this->createCommon($user, $notrigger);
230 
231  //$resultvalidate = $this->validate($user, $notrigger);
232 
233  return $resultcreate;
234  }
235 
243  public function createFromClone(User $user, $fromid)
244  {
245  global $langs, $extrafields;
246  $error = 0;
247 
248  dol_syslog(__METHOD__, LOG_DEBUG);
249 
250  $object = new self($this->db);
251 
252  $this->db->begin();
253 
254  // Load source object
255  $result = $object->fetchCommon($fromid);
256  if ($result > 0 && !empty($object->table_element_line)) {
257  $object->fetchLines();
258  }
259 
260  // get lines so they will be clone
261  //foreach($this->lines as $line)
262  // $line->fetch_optionals();
263 
264  // Reset some properties
265  unset($object->id);
266  unset($object->fk_user_creat);
267  unset($object->import_key);
268 
269  // Clear fields
270  if (property_exists($object, 'ref')) {
271  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_" . $object->ref : $this->fields['ref']['default'];
272  }
273  if (property_exists($object, 'label')) {
274  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default'];
275  }
276  if (property_exists($object, 'status')) {
277  $object->status = self::STATUS_DRAFT;
278  }
279  if (property_exists($object, 'date_creation')) {
280  $object->date_creation = dol_now();
281  }
282  if (property_exists($object, 'date_modification')) {
283  $object->date_modification = null;
284  }
285  // ...
286  // Clear extrafields that are unique
287  if (is_array($object->array_options) && count($object->array_options) > 0) {
288  $extrafields->fetch_name_optionals_label($this->table_element);
289  foreach ($object->array_options as $key => $option) {
290  $shortkey = preg_replace('/options_/', '', $key);
291  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
292  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
293  unset($object->array_options[$key]);
294  }
295  }
296  }
297 
298  // Create clone
299  $object->context['createfromclone'] = 'createfromclone';
300  $result = $object->createCommon($user);
301  if ($result < 0) {
302  $error++;
303  $this->error = $object->error;
304  $this->errors = $object->errors;
305  }
306 
307  if (!$error) {
308  // copy internal contacts
309  if ($this->copy_linked_contact($object, 'internal') < 0) {
310  $error++;
311  }
312  }
313 
314  if (!$error) {
315  // copy external contacts if same company
316  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
317  if ($this->copy_linked_contact($object, 'external') < 0) {
318  $error++;
319  }
320  }
321  }
322 
323  unset($object->context['createfromclone']);
324 
325  // End
326  if (!$error) {
327  $this->db->commit();
328  return $object;
329  } else {
330  $this->db->rollback();
331  return -1;
332  }
333  }
334 
342  public function fetch($id, $ref = null)
343  {
344  $result = $this->fetchCommon($id, $ref);
345  if ($result > 0 && !empty($this->table_element_line)) {
346  $this->fetchLines();
347  }
348  return $result;
349  }
350 
356  public function fetchLines()
357  {
358  $this->lines = array();
359 
360  $result = $this->fetchLinesCommon();
361  return $result;
362  }
363 
364 
376  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
377  {
378  global $conf;
379 
380  dol_syslog(__METHOD__, LOG_DEBUG);
381 
382  $records = array();
383 
384  $sql = 'SELECT ';
385  $sql .= $this->getFieldList('t');
386  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
387  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
388  $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
389  } else {
390  $sql .= ' WHERE 1 = 1';
391  }
392  // Manage filter
393  $sqlwhere = array();
394  if (count($filter) > 0) {
395  foreach ($filter as $key => $value) {
396  if ($key == 't.rowid') {
397  $sqlwhere[] = $key . '=' . $value;
398  } elseif ($key == 'customsql') {
399  $sqlwhere[] = $value;
400  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
401  $sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\'';
402  } elseif (strpos($value, '%') === false) {
403  $sqlwhere[] = $key . ' IN (' . $this->db->sanitize($this->db->escape($value)) . ')';
404  } else {
405  $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
406  }
407  }
408  }
409  if (count($sqlwhere) > 0) {
410  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
411  }
412 
413  if (!empty($sortfield)) {
414  $sql .= $this->db->order($sortfield, $sortorder);
415  }
416  if (!empty($limit)) {
417  $sql .= ' ' . $this->db->plimit($limit, $offset);
418  }
419 
420  $resql = $this->db->query($sql);
421  if ($resql) {
422  $num = $this->db->num_rows($resql);
423  $i = 0;
424  while ($i < ($limit ? min($limit, $num) : $num)) {
425  $obj = $this->db->fetch_object($resql);
426 
427  $record = new self($this->db);
428  $record->setVarsFromFetchObj($obj);
429 
430  $records[$record->id] = $record;
431 
432  $i++;
433  }
434  $this->db->free($resql);
435 
436  return $records;
437  } else {
438  $this->errors[] = 'Error ' . $this->db->lasterror();
439  dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
440 
441  return -1;
442  }
443  }
444 
452  public function update(User $user, $notrigger = false)
453  {
454  return $this->updateCommon($user, $notrigger);
455  }
456 
464  public function delete(User $user, $notrigger = false)
465  {
466  return $this->deleteCommon($user, $notrigger);
467  //return $this->deleteCommon($user, $notrigger, 1);
468  }
469 
478  public function deleteLine(User $user, $idline, $notrigger = false)
479  {
480  if ($this->status < 0) {
481  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
482  return -2;
483  }
484 
485  return $this->deleteLineCommon($user, $idline, $notrigger);
486  }
487 
488 
496  public function validate($user, $notrigger = 0)
497  {
498  global $conf, $langs;
499 
500  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
501 
502  $error = 0;
503 
504  // Protection
505  if ($this->status == self::STATUS_VALIDATED) {
506  dol_syslog(get_class($this) . "::validate action abandonned: already validated", LOG_WARNING);
507  return 0;
508  }
509 
510  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->position->write))
511  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->position->position_advance->validate))))
512  {
513  $this->error='NotEnoughPermissions';
514  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
515  return -1;
516  }*/
517 
518  $now = dol_now();
519 
520  $this->db->begin();
521 
522  // Define new ref
523  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
524  $num = $this->getNextNumRef();
525  } else {
526  $num = $this->ref;
527  }
528  $this->newref = $num;
529 
530  if (!empty($num)) {
531  // Validate
532  $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
533  $sql .= " SET ref = '" . $this->db->escape($num) . "',";
534  $sql .= " status = " . self::STATUS_VALIDATED;
535  if (!empty($this->fields['date_validation'])) {
536  $sql .= ", date_validation = '" . $this->db->idate($now) . "'";
537  }
538  if (!empty($this->fields['fk_user_valid'])) {
539  $sql .= ", fk_user_valid = " . ((int) $user->id);
540  }
541  $sql .= " WHERE rowid = " . ((int) $this->id);
542 
543  dol_syslog(get_class($this) . "::validate()", LOG_DEBUG);
544  $resql = $this->db->query($sql);
545  if (!$resql) {
546  dol_print_error($this->db);
547  $this->error = $this->db->lasterror();
548  $error++;
549  }
550 
551  if (!$error && !$notrigger) {
552  // Call trigger
553  $result = $this->call_trigger('POSITION_VALIDATE', $user);
554  if ($result < 0) {
555  $error++;
556  }
557  // End call triggers
558  }
559  }
560 
561  if (!$error) {
562  $this->oldref = $this->ref;
563 
564  // Rename directory if dir was a temporary ref
565  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
566  // Now we rename also files into index
567  $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) . "'";
568  $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'position/" . $this->db->escape($this->ref) . "' and entity = " . $conf->entity;
569  $resql = $this->db->query($sql);
570  if (!$resql) {
571  $error++;
572  $this->error = $this->db->lasterror();
573  }
574 
575  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
576  $oldref = dol_sanitizeFileName($this->ref);
577  $newref = dol_sanitizeFileName($num);
578  $dirsource = $conf->hrm->dir_output . '/position/' . $oldref;
579  $dirdest = $conf->hrm->dir_output . '/position/' . $newref;
580  if (!$error && file_exists($dirsource)) {
581  dol_syslog(get_class($this) . "::validate() rename dir " . $dirsource . " into " . $dirdest);
582 
583  if (@rename($dirsource, $dirdest)) {
584  dol_syslog("Rename ok");
585  // Rename docs starting with $oldref with $newref
586  $listoffiles = dol_dir_list($conf->hrm->dir_output . '/position/' . $newref, 'files', 1, '^' . preg_quote($oldref, '/'));
587  foreach ($listoffiles as $fileentry) {
588  $dirsource = $fileentry['name'];
589  $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
590  $dirsource = $fileentry['path'] . '/' . $dirsource;
591  $dirdest = $fileentry['path'] . '/' . $dirdest;
592  @rename($dirsource, $dirdest);
593  }
594  }
595  }
596  }
597  }
598 
599  // Set new ref and current status
600  if (!$error) {
601  $this->ref = $num;
602  $this->status = self::STATUS_VALIDATED;
603  }
604 
605  if (!$error) {
606  $this->db->commit();
607  return 1;
608  } else {
609  $this->db->rollback();
610  return -1;
611  }
612  }
613 
614 
622  public function setDraft($user, $notrigger = 0)
623  {
624  // Protection
625  if ($this->status <= self::STATUS_DRAFT) {
626  return 0;
627  }
628 
629  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
630  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
631  {
632  $this->error='Permission denied';
633  return -1;
634  }*/
635 
636  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'POSITION_UNVALIDATE');
637  }
638 
646  public function cancel($user, $notrigger = 0)
647  {
648  // Protection
649  if ($this->status != self::STATUS_VALIDATED) {
650  return 0;
651  }
652 
653  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
654  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
655  {
656  $this->error='Permission denied';
657  return -1;
658  }*/
659 
660  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'POSITION_CANCEL');
661  }
662 
670  public function reopen($user, $notrigger = 0)
671  {
672  // Protection
673  if ($this->status != self::STATUS_CANCELED) {
674  return 0;
675  }
676 
677  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
678  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
679  {
680  $this->error='Permission denied';
681  return -1;
682  }*/
683 
684  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'POSITION_REOPEN');
685  }
686 
697  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
698  {
699  global $conf, $langs, $hookmanager;
700 
701  if (!empty($conf->dol_no_mouse_hover)) {
702  $notooltip = 1; // Force disable tooltips
703  }
704 
705  $result = '';
706 
707  $label = img_picto('', $this->picto) . ' <u>' . $langs->trans("Position") . '</u>';
708  if (isset($this->status)) {
709  $label .= ' ' . $this->getLibStatut(5);
710  }
711  $label .= '<br>';
712  $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
713 
714  $url = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . $this->id;
715 
716  if ($option != 'nolink') {
717  // Add param to save lastsearch_values or not
718  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
719  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
720  $add_save_lastsearch_values = 1;
721  }
722  if ($add_save_lastsearch_values) {
723  $url .= '&save_lastsearch_values=1';
724  }
725  }
726 
727  $linkclose = '';
728  if (empty($notooltip)) {
729  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
730  $label = $langs->trans("ShowPosition");
731  $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
732  }
733  $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
734  $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
735  } else {
736  $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
737  }
738 
739  if ($option == 'nolink') {
740  $linkstart = '<span';
741  } else {
742  $linkstart = '<a href="' . $url . '"';
743  }
744  $linkstart .= $linkclose . '>';
745  if ($option == 'nolink') {
746  $linkend = '</span>';
747  } else {
748  $linkend = '</a>';
749  }
750 
751  $result .= $linkstart;
752 
753  if (empty($this->showphoto_on_popup)) {
754  if ($withpicto) {
755  $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);
756  }
757  } else {
758  if ($withpicto) {
759  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
760 
761  list($class, $module) = explode('@', $this->picto);
762  $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
763  $filearray = dol_dir_list($upload_dir, "files");
764  $filename = $filearray[0]['name'];
765  if (!empty($filename)) {
766  $pospoint = strpos($filearray[0]['name'], '.');
767 
768  $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
769  if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) {
770  $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>';
771  } else {
772  $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>';
773  }
774 
775  $result .= '</div>';
776  } else {
777  $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);
778  }
779  }
780  }
781 
782  if ($withpicto != 2) {
783  $result .= $this->ref;
784  }
785 
786  $result .= $linkend;
787  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
788 
789  global $action, $hookmanager;
790  $hookmanager->initHooks(array('positiondao'));
791  $parameters = array('id' => $this->id, 'getnomurl' => &$result);
792  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
793  if ($reshook > 0) {
794  $result = $hookmanager->resPrint;
795  } else {
796  $result .= $hookmanager->resPrint;
797  }
798 
799  return $result;
800  }
801 
808  public function getLibStatut($mode = 0)
809  {
810  return $this->LibStatut($this->status, $mode);
811  }
812 
813  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
814 
822  public function LibStatut($status, $mode = 0)
823  {
824  // phpcs:enable
825  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
826  global $langs;
827  //$langs->load("hrm");
828  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
829  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
830  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
831  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
832  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
833  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
834  }
835 
836  $statusType = 'status' . $status;
837  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
838  if ($status == self::STATUS_CANCELED) {
839  $statusType = 'status6';
840  }
841 
842  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
843  }
844 
859  public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0)
860  {
861  global $langs;
862 
863  if ($key == 'fk_user') {
864  $vacantId = $keyprefix.$key.'vacant'.$keysuffix;
865 
866  $out = parent::showInputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
867  $out .= '<label class="nowrap position-fk-user classfortooltip" title="'.dol_escape_js($langs->trans('VacantCheckboxHelper')).'"><input type="checkbox" id="'.$vacantId.'" name="'.$vacantId.'" />&nbsp;'.$langs->trans("Vacant").'</label>';
868 
869  ?>
870  <script type="text/javascript">
871  $(document).ready(function () {
872  var checkbox = $('#<?php print $vacantId; ?>');
873  var searchfkuser = $('#<?php print $keyprefix.$key.$keysuffix; ?>');
874  checkbox.click(function () {
875  if (checkbox.prop('checked')) {
876  searchfkuser.val(0).trigger('change');
877  searchfkuser.prop('disabled', 1);
878  } else {
879  searchfkuser.prop('disabled', 0);
880  }
881  });
882  });
883  </script>
884  <?php
885  } else {
886  $out = parent::showInputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
887  }
888 
889  return $out;
890  }
891 
905  public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
906  {
907  global $langs;
908 
909  if ($key == 'fk_user' && $this->fk_user == 0) {
910  return $langs->trans("VacantPosition");
911  }
912  return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
913  }
914 
915 
922  public function info($id)
923  {
924  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
925  $sql .= ' fk_user_creat, fk_user_modif';
926  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
927  $sql .= ' WHERE t.rowid = ' . ((int) $id);
928  $result = $this->db->query($sql);
929  if ($result) {
930  if ($this->db->num_rows($result)) {
931  $obj = $this->db->fetch_object($result);
932  $this->id = $obj->rowid;
933 
934  $this->user_creation_id = $obj->fk_user_creat;
935  $this->user_modification_id = $obj->fk_user_modif;
936  $this->date_creation = $this->db->jdate($obj->datec);
937  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
938  }
939 
940  $this->db->free($result);
941  } else {
942  dol_print_error($this->db);
943  }
944  }
945 
952  public function initAsSpecimen()
953  {
954  // Set here init that are not commonf fields
955  // $this->property1 = ...
956  // $this->property2 = ...
957 
958  $this->initAsSpecimenCommon();
959  }
960 
966  public function getLinesArray()
967  {
968  $this->lines = array();
969 
970  $objectline = new PositionLine($this->db);
971  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql' => 'fk_position = ' . $this->id));
972 
973  if (is_numeric($result)) {
974  $this->error = $objectline->error;
975  $this->errors = $objectline->errors;
976  return $result;
977  } else {
978  $this->lines = $result;
979  return $this->lines;
980  }
981  }
982 
988  public function getNextNumRef()
989  {
990  global $langs, $conf;
991  $langs->load("hrm");
992 
993  if (empty($conf->global->hrm_POSITION_ADDON)) {
994  $conf->global->hrm_POSITION_ADDON = 'mod_position_standard';
995  }
996 
997  if (!empty($conf->global->hrm_POSITION_ADDON)) {
998  $mybool = false;
999 
1000  $file = $conf->global->hrm_POSITION_ADDON . ".php";
1001  $classname = $conf->global->hrm_POSITION_ADDON;
1002 
1003  // Include file with class
1004  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1005  foreach ($dirmodels as $reldir) {
1006  $dir = dol_buildpath($reldir . "core/modules/hrm/");
1007 
1008  // Load file with numbering class (if found)
1009  $mybool |= @include_once $dir . $file;
1010  }
1011 
1012  if ($mybool === false) {
1013  dol_print_error('', "Failed to include file " . $file);
1014  return '';
1015  }
1016 
1017  if (class_exists($classname)) {
1018  $obj = new $classname();
1019  $numref = $obj->getNextValue($this);
1020 
1021  if ($numref != '' && $numref != '-1') {
1022  return $numref;
1023  } else {
1024  $this->error = $obj->error;
1025  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1026  return "";
1027  }
1028  } else {
1029  print $langs->trans("Error") . " " . $langs->trans("ClassNotFound") . ' ' . $classname;
1030  return "";
1031  }
1032  } else {
1033  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1034  return "";
1035  }
1036  }
1037 
1044  public function getForUser($userid)
1045  {
1046  $TPosition = array();
1047 
1048  $TPosition = $this->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_user=' . $userid));
1049 
1050  return $TPosition;
1051  }
1052 
1064  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1065  {
1066  global $conf, $langs;
1067 
1068  $result = 0;
1069  $includedocgeneration = 0;
1070 
1071  $langs->load("hrm");
1072 
1073  if (!dol_strlen($modele)) {
1074  $modele = 'standard_position';
1075 
1076  if (!empty($this->model_pdf)) {
1077  $modele = $this->model_pdf;
1078  } elseif (!empty($conf->global->POSITION_ADDON_PDF)) {
1079  $modele = $conf->global->POSITION_ADDON_PDF;
1080  }
1081  }
1082 
1083  $modelpath = "core/modules/hrm/doc/";
1084 
1085  if ($includedocgeneration && !empty($modele)) {
1086  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1087  }
1088 
1089  return $result;
1090  }
1091 
1099  public function doScheduledJob()
1100  {
1101  global $conf, $langs;
1102 
1103  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1104 
1105  $error = 0;
1106  $this->output = '';
1107  $this->error = '';
1108 
1109  dol_syslog(__METHOD__, LOG_DEBUG);
1110 
1111  $now = dol_now();
1112 
1113  $this->db->begin();
1114 
1115  // ...
1116 
1117  $this->db->commit();
1118 
1119  return $error;
1120  }
1121 
1129  public function getKanbanView($option = '', $arraydata = null)
1130  {
1131  global $selected, $langs;
1132 
1133  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1134 
1135  $return = '<div class="box-flex-item box-flex-grow-zero">';
1136  $return .= '<div class="info-box info-box-sm">';
1137  $return .= '<span class="info-box-icon bg-infobox-action">';
1138  $return .= img_picto('', $this->picto);
1139  $return .= '</span>';
1140  $return .= '<div class="info-box-content">';
1141  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1142  $return .= '<input class="fright" id="cb'.$this->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1143  if (property_exists($this, 'fk_user') && !(empty($this->fk_user))) {
1144  $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Employee").'</span> : ';
1145  $return .= '<span class="info-box-label ">'.$this->fk_user.'</span>';
1146  }
1147  if (property_exists($this, 'fk_job') && !(empty($this->fk_job))) {
1148  $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Job").'</span> : ';
1149  $return .= '<span class="info-box-label ">'.$this->fk_job.'</span>';
1150  }
1151  if (property_exists($this, 'date_start') && property_exists($this, 'date_end')) {
1152  $return .= '<br><div class ="margintoponly"><span class="info-box-label ">'.dol_print_date($this->db->jdate($this->date_start), 'day').'</span>';
1153  $return .= ' - <span class="info-box-label ">'.dol_print_date($this->db->jdate($this->date_end), 'day').'</span></div>';
1154  }
1155  $return .= '</div>';
1156  $return .= '</div>';
1157  $return .= '</div>';
1158  return $return;
1159  }
1160 }
1161 
1162 
1163 require_once DOL_DOCUMENT_ROOT . '/core/class/commonobjectline.class.php';
1164 
1169 {
1170  // To complete with content of an object PositionLine
1171  // We should have a field rowid , fk_position and position
1172 
1176  public $isextrafieldmanaged = 0;
1177 
1183  public function __construct(DoliDB $db)
1184  {
1185  $this->db = $db;
1186  }
1187 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getFieldList($alias='')
Function to concat keys of fields.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in 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.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
create(User $user, $notrigger=false)
Create object into database.
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=false)
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.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in 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 optionaly 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 clicable link of object (with eventually picto)
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the 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...
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...
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
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.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_dir_list($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
getDolGlobalString($key, $default='')
Return 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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120