dolibarr  13.0.2
recruitmentjobposition.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 // Put here all includes required by your class file
25 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
26 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
27 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
28 
33 {
37  public $module = 'recruitment';
38 
42  public $element = 'recruitmentjobposition';
43 
47  public $table_element = 'recruitment_recruitmentjobposition';
48 
53  public $ismultientitymanaged = 1;
54 
58  public $isextrafieldmanaged = 1;
59 
63  public $picto = 'recruitmentjobposition';
64 
65 
66  const STATUS_DRAFT = 0;
67  const STATUS_VALIDATED = 1;
68  const STATUS_RECRUITED = 3;
69  const STATUS_CANCELED = 9;
70 
71 
97  // BEGIN MODULEBUILDER PROPERTIES
101  public $fields = array(
102  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
103  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
104  'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
105  'label' => array('type'=>'varchar(255)', 'label'=>'JobLabel', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth500', 'csslist'=>'tdoverflowmax300', 'showoncombobox'=>'1', 'autofocusoncreate'=>1),
106  'qty' => array('type'=>'integer', 'label'=>'NbOfEmployeesExpected', 'enabled'=>'1', 'position'=>45, 'notnull'=>1, 'visible'=>1, 'default'=>'1', 'isameasure'=>'1', 'css'=>'maxwidth75imp'),
107  'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'1', 'position'=>52, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'css'=>'maxwidth500', 'picto'=>'project'),
108  'fk_user_recruiter' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'ResponsibleOfRecruitement', 'enabled'=>'1', 'position'=>54, 'notnull'=>1, 'visible'=>1, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax150'),
109  'email_recruiter' => array('type'=>'varchar(255)', 'label'=>'EmailRecruiter', 'enabled'=>'1', 'position'=>54, 'notnull'=>0, 'visible'=>-1, 'help'=>'ToUseAGenericEmail', 'picto'=>'email'),
110  'fk_user_supervisor' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'FutureManager', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'foreignkey'=>'user.rowid',),
111  'fk_establishment' => array('type'=>'integer:Establishment:hrm/class/establishment.class.php', 'label'=>'Establishment', 'enabled'=>'$conf->hrm->enabled', 'position'=>56, 'notnull'=>0, 'visible'=>-1, 'foreignkey'=>'establishment.rowid',),
112  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'WorkPlace', 'enabled'=>'1', 'position'=>57, 'notnull'=>-1, 'visible'=>-1, 'css'=>'maxwidth500', 'index'=>1, 'help'=>"IfJobIsLocatedAtAPartner", 'picto'=>'company'),
113  'date_planned' => array('type'=>'date', 'label'=>'DateExpected', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
114  'remuneration_suggested' => array('type'=>'varchar(255)', 'label'=>'Remuneration', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>1,),
115  'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>65, 'notnull'=>0, 'visible'=>3,),
116  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>101, 'notnull'=>0, 'visible'=>0,),
117  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>102, 'notnull'=>0, 'visible'=>0,),
118  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4,),
119  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
120  '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',),
121  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
122  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>900, 'notnull'=>0, 'visible'=>0,),
123  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
124  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
125  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>5, 'default'=>'0', 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '3'=>'Recruited', '9'=>'Canceled'),),
126  );
127  public $rowid;
128 
132  public $ref;
133  public $entity;
134 
138  public $label;
139  public $qty;
140  public $fk_soc;
141  public $fk_project;
142  public $fk_user_recruiter;
143 
147  public $email_recruiter;
148 
152  public $remuneration_suggested;
153 
154  public $fk_user_supervisor;
155  public $fk_establishment;
156  public $date_planned;
157  public $description;
158  public $note_public;
159  public $note_private;
160  public $date_creation;
161  public $tms;
162  public $fk_user_creat;
163  public $fk_user_modif;
164  public $last_main_doc;
165  public $import_key;
166  public $model_pdf;
167  public $status;
168  // END MODULEBUILDER PROPERTIES
169 
170 
176  public function __construct(DoliDB $db)
177  {
178  global $conf, $langs;
179 
180  $this->db = $db;
181 
182  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
183  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
184 
185  // Example to show how to set values of fields definition dynamically
186  /*if ($user->rights->recruitment->recruitmentjobposition->read) {
187  $this->fields['myfield']['visible'] = 1;
188  $this->fields['myfield']['noteditable'] = 0;
189  }*/
190 
191  // Unset fields that are disabled
192  foreach ($this->fields as $key => $val)
193  {
194  if (isset($val['enabled']) && empty($val['enabled']))
195  {
196  unset($this->fields[$key]);
197  }
198  }
199 
200  // Translate some data of arrayofkeyval
201  if (is_object($langs))
202  {
203  foreach ($this->fields as $key => $val)
204  {
205  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval']))
206  {
207  foreach ($val['arrayofkeyval'] as $key2 => $val2)
208  {
209  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
210  }
211  }
212  }
213  }
214  }
215 
223  public function create(User $user, $notrigger = false)
224  {
225  return $this->createCommon($user, $notrigger);
226  }
227 
235  public function createFromClone(User $user, $fromid)
236  {
237  global $langs, $extrafields;
238  $error = 0;
239 
240  dol_syslog(__METHOD__, LOG_DEBUG);
241 
242  $object = new self($this->db);
243 
244  $this->db->begin();
245 
246  // Load source object
247  $result = $object->fetchCommon($fromid);
248  if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
249 
250  // get lines so they will be clone
251  //foreach($this->lines as $line)
252  // $line->fetch_optionals();
253 
254  // Reset some properties
255  unset($object->id);
256  unset($object->fk_user_creat);
257  unset($object->import_key);
258 
259  // Clear fields
260  if (property_exists($object, 'ref')) $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
261  if (property_exists($object, 'label')) $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
262  if (property_exists($object, 'status')) { $object->status = self::STATUS_DRAFT; }
263  if (property_exists($object, 'date_creation')) { $object->date_creation = dol_now(); }
264  if (property_exists($object, 'date_modification')) { $object->date_modification = null; }
265  // ...
266  // Clear extrafields that are unique
267  if (is_array($object->array_options) && count($object->array_options) > 0)
268  {
269  $extrafields->fetch_name_optionals_label($this->table_element);
270  foreach ($object->array_options as $key => $option)
271  {
272  $shortkey = preg_replace('/options_/', '', $key);
273  if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
274  {
275  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
276  unset($object->array_options[$key]);
277  }
278  }
279  }
280 
281  // Create clone
282  $object->context['createfromclone'] = 'createfromclone';
283  $result = $object->createCommon($user);
284  if ($result < 0) {
285  $error++;
286  $this->error = $object->error;
287  $this->errors = $object->errors;
288  }
289 
290  if (!$error)
291  {
292  // copy internal contacts
293  if ($this->copy_linked_contact($object, 'internal') < 0)
294  {
295  $error++;
296  }
297  }
298 
299  if (!$error)
300  {
301  // copy external contacts if same company
302  if (property_exists($this, 'socid') && $this->socid == $object->socid)
303  {
304  if ($this->copy_linked_contact($object, 'external') < 0)
305  $error++;
306  }
307  }
308 
309  unset($object->context['createfromclone']);
310 
311  // End
312  if (!$error) {
313  $this->db->commit();
314  return $object;
315  } else {
316  $this->db->rollback();
317  return -1;
318  }
319  }
320 
328  public function fetch($id, $ref = null)
329  {
330  $result = $this->fetchCommon($id, $ref);
331  if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
332  return $result;
333  }
334 
340  public function fetchLines()
341  {
342  $this->lines = array();
343 
344  $result = $this->fetchLinesCommon();
345  return $result;
346  }
347 
348 
360  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
361  {
362  global $conf;
363 
364  dol_syslog(__METHOD__, LOG_DEBUG);
365 
366  $records = array();
367 
368  $sql = 'SELECT ';
369  $sql .= $this->getFieldList();
370  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
371  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
372  else $sql .= ' WHERE 1 = 1';
373  // Manage filter
374  $sqlwhere = array();
375  if (count($filter) > 0) {
376  foreach ($filter as $key => $value) {
377  if ($key == 't.rowid') {
378  $sqlwhere[] = $key.'='.$value;
379  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
380  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
381  } elseif ($key == 'customsql') {
382  $sqlwhere[] = $value;
383  } elseif (strpos($value, '%') === false) {
384  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
385  } else {
386  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
387  }
388  }
389  }
390  if (count($sqlwhere) > 0) {
391  $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
392  }
393 
394  if (!empty($sortfield)) {
395  $sql .= $this->db->order($sortfield, $sortorder);
396  }
397  if (!empty($limit)) {
398  $sql .= ' '.$this->db->plimit($limit, $offset);
399  }
400 
401  $resql = $this->db->query($sql);
402  if ($resql) {
403  $num = $this->db->num_rows($resql);
404  $i = 0;
405  while ($i < ($limit ? min($limit, $num) : $num))
406  {
407  $obj = $this->db->fetch_object($resql);
408 
409  $record = new self($this->db);
410  $record->setVarsFromFetchObj($obj);
411 
412  $records[$record->id] = $record;
413 
414  $i++;
415  }
416  $this->db->free($resql);
417 
418  return $records;
419  } else {
420  $this->errors[] = 'Error '.$this->db->lasterror();
421  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
422 
423  return -1;
424  }
425  }
426 
434  public function update(User $user, $notrigger = false)
435  {
436  return $this->updateCommon($user, $notrigger);
437  }
438 
446  public function delete(User $user, $notrigger = false)
447  {
448  return $this->deleteCommon($user, $notrigger);
449  //return $this->deleteCommon($user, $notrigger, 1);
450  }
451 
460  public function deleteLine(User $user, $idline, $notrigger = false)
461  {
462  if ($this->status < 0)
463  {
464  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
465  return -2;
466  }
467 
468  return $this->deleteLineCommon($user, $idline, $notrigger);
469  }
470 
471 
479  public function validate($user, $notrigger = 0)
480  {
481  global $conf, $langs;
482 
483  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
484 
485  $error = 0;
486 
487  // Protection
488  if ($this->status == self::STATUS_VALIDATED)
489  {
490  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
491  return 0;
492  }
493 
494  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->create))
495  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitmentjobposition->recruitmentjobposition_advance->validate))))
496  {
497  $this->error='NotEnoughPermissions';
498  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
499  return -1;
500  }*/
501 
502  $now = dol_now();
503 
504  $this->db->begin();
505 
506  // Define new ref
507  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
508  {
509  $num = $this->getNextNumRef();
510  } else {
511  $num = $this->ref;
512  }
513  $this->newref = $num;
514 
515  if (!empty($num)) {
516  // Validate
517  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
518  $sql .= " SET ref = '".$this->db->escape($num)."',";
519  $sql .= " status = ".self::STATUS_VALIDATED;
520  if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',";
521  if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id;
522  $sql .= " WHERE rowid = ".$this->id;
523 
524  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
525  $resql = $this->db->query($sql);
526  if (!$resql)
527  {
528  dol_print_error($this->db);
529  $this->error = $this->db->lasterror();
530  $error++;
531  }
532 
533  if (!$error && !$notrigger)
534  {
535  // Call trigger
536  $result = $this->call_trigger('RECRUITMENTJOBPOSITION_VALIDATE', $user);
537  if ($result < 0) $error++;
538  // End call triggers
539  }
540  }
541 
542  if (!$error)
543  {
544  $this->oldref = $this->ref;
545 
546  // Rename directory if dir was a temporary ref
547  if (preg_match('/^[\(]?PROV/i', $this->ref))
548  {
549  // Now we rename also files into index
550  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'recruitmentjobposition/".$this->db->escape($this->newref)."'";
551  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'recruitmentjobposition/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
552  $resql = $this->db->query($sql);
553  if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
554 
555  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
556  $oldref = dol_sanitizeFileName($this->ref);
557  $newref = dol_sanitizeFileName($num);
558  $dirsource = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$oldref;
559  $dirdest = $conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref;
560  if (!$error && file_exists($dirsource))
561  {
562  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
563 
564  if (@rename($dirsource, $dirdest))
565  {
566  dol_syslog("Rename ok");
567  // Rename docs starting with $oldref with $newref
568  $listoffiles = dol_dir_list($conf->recruitment->dir_output.'/recruitmentjobposition/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
569  foreach ($listoffiles as $fileentry)
570  {
571  $dirsource = $fileentry['name'];
572  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
573  $dirsource = $fileentry['path'].'/'.$dirsource;
574  $dirdest = $fileentry['path'].'/'.$dirdest;
575  @rename($dirsource, $dirdest);
576  }
577  }
578  }
579  }
580  }
581 
582  // Set new ref and current status
583  if (!$error)
584  {
585  $this->ref = $num;
586  $this->status = self::STATUS_VALIDATED;
587  }
588 
589  if (!$error)
590  {
591  $this->db->commit();
592  return 1;
593  } else {
594  $this->db->rollback();
595  return -1;
596  }
597  }
598 
599 
607  public function setDraft($user, $notrigger = 0)
608  {
609  // Protection
610  if ($this->status <= self::STATUS_DRAFT)
611  {
612  return 0;
613  }
614 
615  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
616  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
617  {
618  $this->error='Permission denied';
619  return -1;
620  }*/
621 
622  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'RECRUITMENTJOBPOSITION_UNVALIDATE');
623  }
624 
632  public function cancel($user, $notrigger = 0)
633  {
634  // Protection
635  if ($this->status != self::STATUS_VALIDATED)
636  {
637  return 0;
638  }
639 
640  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
641  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
642  {
643  $this->error='Permission denied';
644  return -1;
645  }*/
646 
647  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'RECRUITMENTJOBPOSITION_CLOSE');
648  }
649 
659  public function cloture($user, $status, $note = "", $notrigger = 0)
660  {
661  global $langs, $conf;
662 
663  $error = 0;
664  $now = dol_now();
665 
666  $this->db->begin();
667 
668  $newprivatenote = dol_concatdesc($this->note_private, $note);
669 
670  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
671  $sql .= " SET status = ".$status.", note_private = '".$this->db->escape($newprivatenote)."'";
672  //$sql .= ", date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
673  $sql .= " WHERE rowid = ".$this->id;
674 
675  $resql = $this->db->query($sql);
676  if ($resql)
677  {
678  $modelpdf = $this->model_pdf;
679  $triggerName = 'RECRUITMENTJOB_CLOSE_REFUSED';
680 
681  if ($status == self::STATUS_RECRUITED)
682  {
683  $triggerName = 'RECRUITMENTJOB_CLOSE_RECRUITED';
684  $modelpdf = $this->model_pdf;
685 
686  if ($result < 0)
687  {
688  $this->error = $this->db->lasterror();
689  $this->db->rollback();
690  return -2;
691  }
692  }
693 
694  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
695  {
696  // Define output language
697  $outputlangs = $langs;
698  if (!empty($conf->global->MAIN_MULTILANGS))
699  {
700  $outputlangs = new Translate("", $conf);
701  $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
702  $outputlangs->setDefaultLang($newlang);
703  }
704  //$ret=$object->fetch($id); // Reload to get new records
705  $this->generateDocument($modelpdf, $outputlangs);
706  }
707 
708  if (!$error)
709  {
710  $this->oldcopy = clone $this;
711  $this->status = $status;
712  $this->date_cloture = $now;
713  $this->note_private = $newprivatenote;
714  }
715 
716  if (!$notrigger && empty($error))
717  {
718  // Call trigger
719  $result = $this->call_trigger($triggerName, $user);
720  if ($result < 0) { $error++; }
721  // End call triggers
722  }
723 
724  if (!$error)
725  {
726  $this->db->commit();
727  return 1;
728  } else {
729  $this->status = $this->oldcopy->status;
730  $this->date_cloture = $this->oldcopy->date_cloture;
731  $this->note_private = $this->oldcopy->note_private;
732 
733  $this->db->rollback();
734  return -1;
735  }
736  } else {
737  $this->error = $this->db->lasterror();
738  $this->db->rollback();
739  return -1;
740  }
741  }
742 
750  public function reopen($user, $notrigger = 0)
751  {
752  // Protection
753  if ($this->status != self::STATUS_CANCELED)
754  {
755  return 0;
756  }
757 
758  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->write))
759  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->recruitment->recruitment_advance->validate))))
760  {
761  $this->error='Permission denied';
762  return -1;
763  }*/
764 
765  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'RECRUITMENTJOBPOSITION_REOPEN');
766  }
767 
778  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
779  {
780  global $conf, $langs, $hookmanager;
781 
782  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
783 
784  $result = '';
785 
786  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("PositionToBeFilled").'</u>';
787  if (isset($this->status)) {
788  $label .= ' '.$this->getLibStatut(5);
789  }
790  $label .= '<br>';
791  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
792  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
793 
794  $url = dol_buildpath('/recruitment/recruitmentjobposition_card.php', 1).'?id='.$this->id;
795 
796  if ($option != 'nolink')
797  {
798  // Add param to save lastsearch_values or not
799  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
800  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
801  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
802  }
803 
804  $linkclose = '';
805  if (empty($notooltip))
806  {
807  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
808  {
809  $label = $langs->trans("ShowRecruitmentJobPosition");
810  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
811  }
812  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
813  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
814  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
815 
816  $linkstart = '<a href="'.$url.'"';
817  $linkstart .= $linkclose.'>';
818  $linkend = '</a>';
819 
820  $result .= $linkstart;
821 
822  if (empty($this->showphoto_on_popup)) {
823  if ($withpicto) $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);
824  } else {
825  if ($withpicto) {
826  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
827 
828  list($class, $module) = explode('@', $this->picto);
829  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
830  $filearray = dol_dir_list($upload_dir, "files");
831  $filename = $filearray[0]['name'];
832  if (!empty($filename)) {
833  $pospoint = strpos($filearray[0]['name'], '.');
834 
835  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
836  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
837  $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>';
838  } else {
839  $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>';
840  }
841 
842  $result .= '</div>';
843  } else {
844  $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);
845  }
846  }
847  }
848 
849  if ($withpicto != 2) $result .= $this->ref;
850 
851  $result .= $linkend;
852  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
853 
854  global $action, $hookmanager;
855  $hookmanager->initHooks(array('recruitmentjobpositiondao'));
856  $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
857  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
858  if ($reshook > 0) $result = $hookmanager->resPrint;
859  else $result .= $hookmanager->resPrint;
860 
861  return $result;
862  }
863 
870  public function getLibStatut($mode = 0)
871  {
872  return $this->LibStatut($this->status, $mode);
873  }
874 
875  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
883  public function LibStatut($status, $mode = 0)
884  {
885  // phpcs:enable
886  if (empty($this->labelStatus) || empty($this->labelStatusShort))
887  {
888  global $langs;
889  //$langs->load("recruitment");
890  $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
891  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
892  $this->labelStatus[self::STATUS_RECRUITED] = $langs->trans('Recruited');
893  $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled');
894  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
895  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
896  $this->labelStatusShort[self::STATUS_RECRUITED] = $langs->trans('Recruited');
897  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled');
898  }
899 
900  $statusType = 'status'.$status;
901  if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
902  if ($status == self::STATUS_RECRUITED) $statusType = 'status6';
903  if ($status == self::STATUS_CANCELED) $statusType = 'status9';
904 
905  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
906  }
907 
914  public function info($id)
915  {
916  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
917  $sql .= ' fk_user_creat, fk_user_modif';
918  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
919  $sql .= ' WHERE t.rowid = '.$id;
920  $result = $this->db->query($sql);
921  if ($result)
922  {
923  if ($this->db->num_rows($result))
924  {
925  $obj = $this->db->fetch_object($result);
926  $this->id = $obj->rowid;
927  if ($obj->fk_user_author)
928  {
929  $cuser = new User($this->db);
930  $cuser->fetch($obj->fk_user_author);
931  $this->user_creation = $cuser;
932  }
933 
934  if ($obj->fk_user_valid)
935  {
936  $vuser = new User($this->db);
937  $vuser->fetch($obj->fk_user_valid);
938  $this->user_validation = $vuser;
939  }
940 
941  if ($obj->fk_user_cloture)
942  {
943  $cluser = new User($this->db);
944  $cluser->fetch($obj->fk_user_cloture);
945  $this->user_cloture = $cluser;
946  }
947 
948  $this->date_creation = $this->db->jdate($obj->datec);
949  $this->date_modification = $this->db->jdate($obj->datem);
950  $this->date_validation = $this->db->jdate($obj->datev);
951  }
952 
953  $this->db->free($result);
954  } else {
955  dol_print_error($this->db);
956  }
957  }
958 
965  public function initAsSpecimen()
966  {
967  $this->initAsSpecimenCommon();
968  }
969 
975  public function getLinesArray()
976  {
977  $this->lines = array();
978 
979  return $this->lines;
980  }
981 
987  public function getNextNumRef()
988  {
989  global $langs, $conf;
990  $langs->load("recruitment");
991 
992  if (empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON)) {
993  $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON = 'mod_recruitmentjobposition_standard';
994  }
995 
996  if (!empty($conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON))
997  {
998  $mybool = false;
999 
1000  $file = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON.".php";
1001  $classname = $conf->global->RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON;
1002 
1003  // Include file with class
1004  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1005  foreach ($dirmodels as $reldir)
1006  {
1007  $dir = dol_buildpath($reldir."core/modules/recruitment/");
1008 
1009  // Load file with numbering class (if found)
1010  $mybool |= @include_once $dir.$file;
1011  }
1012 
1013  if ($mybool === false)
1014  {
1015  dol_print_error('', "Failed to include file ".$file);
1016  return '';
1017  }
1018 
1019  if (class_exists($classname)) {
1020  $obj = new $classname();
1021  $numref = $obj->getNextValue($this);
1022 
1023  if ($numref != '' && $numref != '-1')
1024  {
1025  return $numref;
1026  } else {
1027  $this->error = $obj->error;
1028  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1029  return "";
1030  }
1031  } else {
1032  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1033  return "";
1034  }
1035  } else {
1036  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1037  return "";
1038  }
1039  }
1040 
1052  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1053  {
1054  global $conf, $langs;
1055 
1056  $result = 0;
1057  $includedocgeneration = 1;
1058 
1059  $langs->load("recruitment");
1060 
1061  if (!dol_strlen($modele)) {
1062  if (!empty($conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF)) {
1063  $modele = $conf->global->RECRUITMENTJOBPOSITION_ADDON_PDF;
1064  } else {
1065  $modele = ''; // No default value. For job position, we allow to disable all PDF generation
1066  }
1067  }
1068 
1069  $modelpath = "core/modules/recruitment/doc/";
1070 
1071  if ($includedocgeneration && !empty($modele)) {
1072  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1073  }
1074 
1075  return $result;
1076  }
1077 
1085  public function doScheduledJob()
1086  {
1087  global $conf, $langs;
1088 
1089  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1090 
1091  $error = 0;
1092  $this->output = '';
1093  $this->error = '';
1094 
1095  dol_syslog(__METHOD__, LOG_DEBUG);
1096 
1097  $now = dol_now();
1098 
1099  $this->db->begin();
1100 
1101  // ...
1102 
1103  $this->db->commit();
1104 
1105  return $error;
1106  }
1107 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module...
update(User $user, $notrigger=false)
Update object into database.
reopen($user, $notrigger=0)
Set back to validated status.
fetch($id, $ref=null)
Load object in memory from the database.
cloture($user, $status, $note="", $notrigger=0)
Close the commercial proposal.
fetchLinesCommon($morewhere= '')
Load object in memory from the database.
fetchLines()
Load object lines in memory from the database.
setDraft($user, $notrigger=0)
Set draft status.
createFromClone(User $user, $fromid)
Clone an object into another one.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
Definition: inc.php:54
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load list of objects in memory from the database.
__construct(DoliDB $db)
Constructor.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
info($id)
Load the info information in the object.
Class for RecruitmentJobPosition.
getLibStatut($mode=0)
Return label of the status.
validate($user, $notrigger=0)
Validate object.
print $_SERVER["PHP_SELF"]
Edit parameters.
create(User $user, $notrigger=false)
Create object into database.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
copy_linked_contact($objFrom, $source= 'internal')
Copy contact from one element to current.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
print
Draft customers invoices.
Definition: index.php:89
call_trigger($triggerName, $user)
Call trigger based on this instance.
LibStatut($status, $mode=0)
Return the status.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setStatusCommon($user, $status, $notrigger=0, $triggercode= '')
Set to a status.
getFieldList()
Function to concat keys of fields.
getLinesArray()
Create an array of lines.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.
cancel($user, $notrigger=0)
Set cancel status.