29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $module =
'hrm';
46 public $element =
'job';
51 public $table_element =
'hrm_job';
57 public $ismultientitymanaged = 0;
62 public $isextrafieldmanaged = 1;
67 public $picto =
'technic';
70 const STATUS_DRAFT = 0;
71 const STATUS_VALIDATED = 1;
72 const STATUS_CANCELED = 9;
105 public $fields=array(
106 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
107 'label' => array(
'type'=>
'varchar(128)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>20,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'comment'=>
"Label of object"),
108 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>
'1',
'position'=>21,
'notnull'=>0,
'visible'=>1,),
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 'deplacement' => array(
'type'=>
'select',
'required'=> 1,
'label'=>
'NeedBusinessTravels',
'enabled'=> 1,
'position'=> 90,
'notnull'=> 1,
'visible'=> 1,
'arrayofkeyval'=> array(0 =>
"No", 1=>
"Yes"),
'default'=>0),
112 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>70,
'notnull'=>0,
'visible'=>0,),
113 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>71,
'notnull'=>0,
'visible'=>0,),
114 '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',),
115 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
120 public $date_creation;
124 public $note_private;
125 public $fk_user_creat;
126 public $fk_user_modif;
140 public $fk_element =
'fk_job';
150 protected $childtables = array(
'hrm_evaluation',
'hrm_job_user');
157 protected $childtablesoncascade = array(
"@SkillRank:hrm/class/skillrank.class.php:fk_object:objecttype='job'");
173 global $conf, $langs;
177 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
178 $this->fields[
'rowid'][
'visible'] = 0;
180 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
181 $this->fields[
'entity'][
'enabled'] = 0;
191 foreach ($this->fields as $key => $val) {
192 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
193 unset($this->fields[$key]);
198 if (is_object($langs)) {
199 foreach ($this->fields as $key => $val) {
200 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
201 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
202 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
222 return $resultcreate;
234 global $langs, $extrafields;
239 $object =
new self($this->db);
244 $result = $object->fetchCommon($fromid);
245 if ($result > 0 && !empty($object->table_element_line)) {
246 $object->fetchLines();
255 unset($object->fk_user_creat);
256 unset($object->import_key);
259 if (property_exists($object,
'ref')) {
260 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
262 if (property_exists($object,
'label')) {
263 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
265 if (property_exists($object,
'status')) {
266 $object->status = self::STATUS_DRAFT;
268 if (property_exists($object,
'date_creation')) {
269 $object->date_creation =
dol_now();
271 if (property_exists($object,
'date_modification')) {
272 $object->date_modification =
null;
276 if (is_array($object->array_options) && count($object->array_options) > 0) {
277 $extrafields->fetch_name_optionals_label($this->table_element);
278 foreach ($object->array_options as $key => $option) {
279 $shortkey = preg_replace(
'/options_/',
'', $key);
280 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
282 unset($object->array_options[$key]);
288 $object->context[
'createfromclone'] =
'createfromclone';
289 $result = $object->createCommon($user);
292 $this->error = $object->error;
293 $this->errors = $object->errors;
305 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
312 unset($object->context[
'createfromclone']);
319 $this->
db->rollback();
331 public function fetch($id, $ref =
null)
334 if ($result > 0 && !empty($this->table_element_line)) {
347 $this->lines = array();
365 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
375 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
376 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
377 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
379 $sql .=
' WHERE 1 = 1';
383 if (count($filter) > 0) {
384 foreach ($filter as $key => $value) {
385 if ($key ==
't.rowid') {
386 $sqlwhere[] = $key.
'='.$value;
387 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
388 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
389 } elseif ($key ==
'customsql') {
390 $sqlwhere[] = $value;
391 } elseif (strpos($value,
'%') ===
false) {
392 $sqlwhere[] = $key.
' IN ('.$this->
db->sanitize($this->
db->escape($value)).
')';
394 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
398 if (count($sqlwhere) > 0) {
399 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
402 if (!empty($sortfield)) {
403 $sql .= $this->
db->order($sortfield, $sortorder);
405 if (!empty($limit)) {
406 $sql .=
' '.$this->db->plimit($limit, $offset);
413 while ($i < ($limit ? min($limit, $num) : $num)) {
414 $obj = $this->
db->fetch_object(
$resql);
416 $record =
new self($this->db);
417 $record->setVarsFromFetchObj($obj);
419 $records[$record->id] = $record;
427 $this->errors[] =
'Error '.$this->db->lasterror();
428 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
453 public function delete(
User $user, $notrigger =
false)
469 if ($this->status < 0) {
470 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
487 global $conf, $langs;
489 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
494 if ($this->status == self::STATUS_VALIDATED) {
495 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
512 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
517 $this->newref = $num;
521 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
522 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
523 $sql .=
" status = ".self::STATUS_VALIDATED;
524 if (!empty($this->fields[
'date_validation'])) {
525 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
527 if (!empty($this->fields[
'fk_user_valid'])) {
528 $sql .=
", fk_user_valid = ".((int) $user->id);
530 $sql .=
" WHERE rowid = ".((int) $this->
id);
532 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
536 $this->error = $this->
db->lasterror();
540 if (!$error && !$notrigger) {
551 $this->oldref = $this->ref;
554 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
556 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->
db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'job/".$this->
db->escape($this->newref).
"'";
557 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'job/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
560 $error++; $this->error = $this->
db->lasterror();
566 $dirsource = $conf->hrm->dir_output.
'/job/'.$oldref;
567 $dirdest = $conf->hrm->dir_output.
'/job/'.$newref;
568 if (!$error && file_exists($dirsource)) {
569 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
571 if (@rename($dirsource, $dirdest)) {
574 $listoffiles =
dol_dir_list($conf->hrm->dir_output.
'/job/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
575 foreach ($listoffiles as $fileentry) {
576 $dirsource = $fileentry[
'name'];
577 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
578 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
579 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
580 @rename($dirsource, $dirdest);
590 $this->status = self::STATUS_VALIDATED;
597 $this->
db->rollback();
612 if (empty($Tab))
return '';
614 $lastpos = array_shift($Tab);
631 $TPosition = $position->getForUser($userid);
632 foreach ($TPosition as $UPosition) {
633 $TReturn[$UPosition->Job->rowid] = $UPosition->Job->ref;
648 if ($this->status <= self::STATUS_DRAFT) {
659 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'JOB_UNVALIDATE');
669 public function cancel($user, $notrigger = 0)
672 if ($this->status != self::STATUS_VALIDATED) {
683 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'JOB_CANCEL');
693 public function reopen($user, $notrigger = 0)
696 if ($this->status != self::STATUS_CANCELED) {
707 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'JOB_REOPEN');
720 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
722 global $conf, $langs, $hookmanager;
724 if (!empty($conf->dol_no_mouse_hover)) {
730 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Job").
'</u>';
731 if (isset($this->status)) {
732 $label .=
' '.$this->getLibStatut(5);
735 $label .=
'<b>'.$langs->trans(
'Label').
':</b> '.$this->label;
737 $url =
dol_buildpath(
'/hrm/job_card.php', 1).
'?id='.$this->id;
739 if ($option !=
'nolink') {
741 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
742 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
743 $add_save_lastsearch_values = 1;
745 if ($add_save_lastsearch_values) {
746 $url .=
'&save_lastsearch_values=1';
751 if (empty($notooltip)) {
752 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
753 $label = $langs->trans(
"ShowJob");
754 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
756 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
757 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
759 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
762 if ($option ==
'nolink') {
763 $linkstart =
'<span';
765 $linkstart =
'<a href="'.$url.
'"';
767 $linkstart .= $linkclose.
'>';
768 if ($option ==
'nolink') {
769 $linkend =
'</span>';
774 $result .= $linkstart;
776 if (empty($this->showphoto_on_popup)) {
778 $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);
782 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
784 list($class, $module) = explode(
'@', $this->picto);
785 $upload_dir = $conf->$module->multidir_output[$conf->entity].
"/$class/".
dol_sanitizeFileName($this->label);
787 $filename = $filearray[0][
'name'];
788 if (!empty($filename)) {
789 $pospoint = strpos($filearray[0][
'name'],
'.');
791 $pathtophoto = $class.
'/'.$this->label.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
792 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
793 $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>';
795 $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>';
800 $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);
805 if ($withpicto != 2) {
806 $result .= $this->label;
812 global $action, $hookmanager;
813 $hookmanager->initHooks(array(
'jobdao'));
814 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
815 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
817 $result = $hookmanager->resPrint;
819 $result .= $hookmanager->resPrint;
833 return $this->LibStatut($this->status, $mode);
847 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
850 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
851 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
852 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
853 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
854 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
855 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
858 $statusType =
'status'.$status;
860 if ($status == self::STATUS_CANCELED) {
861 $statusType =
'status6';
864 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
875 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
876 $sql .=
' fk_user_creat, fk_user_modif';
877 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
878 $sql .=
' WHERE t.rowid = '.((int) $id);
879 $result = $this->
db->query($sql);
881 if ($this->
db->num_rows($result)) {
882 $obj = $this->
db->fetch_object($result);
883 $this->
id = $obj->rowid;
885 $this->user_creation_id = $obj->fk_user_creat;
886 $this->user_modification_id = $obj->fk_user_modif;
887 $this->date_creation = $this->
db->jdate($obj->datec);
888 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
891 $this->
db->free($result);
909 $this->initAsSpecimenCommon();
919 $this->lines = array();
922 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_job = '.$this->
id));
924 if (is_numeric($result)) {
925 $this->error = $objectline->error;
926 $this->errors = $objectline->errors;
929 $this->lines = $result;
941 global $langs, $conf;
944 if (empty($conf->global->hrm_JOB_ADDON)) {
945 $conf->global->hrm_JOB_ADDON =
'mod_job_standard';
948 if (!empty($conf->global->hrm_JOB_ADDON)) {
951 $file = $conf->global->hrm_JOB_ADDON.
".php";
952 $classname = $conf->global->hrm_JOB_ADDON;
955 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
956 foreach ($dirmodels as $reldir) {
960 $mybool |= @include_once $dir.$file;
963 if ($mybool ===
false) {
968 if (class_exists($classname)) {
969 $obj =
new $classname();
970 $numref = $obj->getNextValue($this);
972 if ($numref !=
'' && $numref !=
'-1') {
975 $this->error = $obj->error;
980 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
984 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1000 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1002 global $conf, $langs;
1005 $includedocgeneration = 0;
1007 $langs->load(
"hrm");
1010 $modele =
'standard_job';
1012 if (!empty($this->model_pdf)) {
1013 $modele = $this->model_pdf;
1014 } elseif (!empty($conf->global->JOB_ADDON_PDF)) {
1015 $modele = $conf->global->JOB_ADDON_PDF;
1019 $modelpath =
"core/modules/hrm/doc/";
1021 if ($includedocgeneration && !empty($modele)) {
1022 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1037 global $conf, $langs;
1053 $this->
db->commit();
1060 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1073 public $isextrafieldmanaged = 0;