29 require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobject.class.php';
41 public $module =
'hrm';
46 public $element =
'position';
51 public $table_element =
'hrm_job_user';
57 public $ismultientitymanaged = 0;
62 public $isextrafieldmanaged = 0;
67 public $picto =
'user-cog';
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'=>2,
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
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,),
125 public $date_creation;
132 public $abort_comment;
134 public $note_private;
135 public $fk_user_creat;
136 public $fk_user_modif;
184 global $conf, $langs;
188 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
191 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
192 $this->fields[
'entity'][
'enabled'] = 0;
202 foreach ($this->fields as $key => $val) {
203 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
204 unset($this->fields[$key]);
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);
233 return $resultcreate;
245 global $langs, $extrafields;
250 $object =
new self($this->db);
255 $result = $object->fetchCommon($fromid);
256 if ($result > 0 && !empty($object->table_element_line)) {
257 $object->fetchLines();
266 unset($object->fk_user_creat);
267 unset($object->import_key);
270 if (property_exists($object,
'ref')) {
271 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_" . $object->ref : $this->fields[
'ref'][
'default'];
273 if (property_exists($object,
'label')) {
274 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf") .
" " . $object->label : $this->fields[
'label'][
'default'];
276 if (property_exists($object,
'status')) {
277 $object->status = self::STATUS_DRAFT;
279 if (property_exists($object,
'date_creation')) {
280 $object->date_creation =
dol_now();
282 if (property_exists($object,
'date_modification')) {
283 $object->date_modification =
null;
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])) {
293 unset($object->array_options[$key]);
299 $object->context[
'createfromclone'] =
'createfromclone';
300 $result = $object->createCommon($user);
303 $this->error = $object->error;
304 $this->errors = $object->errors;
316 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
323 unset($object->context[
'createfromclone']);
330 $this->db->rollback();
342 public function fetch($id, $ref =
null)
345 if ($result > 0 && !empty($this->table_element_line)) {
358 $this->lines = array();
376 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
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) .
')';
390 $sql .=
' WHERE 1 = 1';
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)) .
')';
405 $sqlwhere[] = $key .
' LIKE \'%' . $this->db->escape($value) .
'%\'';
409 if (count($sqlwhere) > 0) {
410 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
413 if (!empty($sortfield)) {
414 $sql .= $this->db->order($sortfield, $sortorder);
416 if (!empty($limit)) {
417 $sql .=
' ' . $this->db->plimit($limit, $offset);
420 $resql = $this->db->query(
$sql);
422 $num = $this->db->num_rows($resql);
424 while ($i < ($limit ? min($limit, $num) : $num)) {
425 $obj = $this->db->fetch_object($resql);
427 $record =
new self($this->db);
428 $record->setVarsFromFetchObj($obj);
430 $records[$record->id] = $record;
434 $this->db->free($resql);
438 $this->errors[] =
'Error ' . $this->db->lasterror();
439 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
464 public function delete(
User $user, $notrigger =
false)
480 if ($this->status < 0) {
481 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
498 global $conf, $langs;
500 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
505 if ($this->status == self::STATUS_VALIDATED) {
506 dol_syslog(get_class($this) .
"::validate action abandonned: already validated", LOG_WARNING);
523 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
528 $this->newref = $num;
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) .
"'";
538 if (!empty($this->fields[
'fk_user_valid'])) {
539 $sql .=
", fk_user_valid = " . ((int) $user->id);
541 $sql .=
" WHERE rowid = " . ((int) $this->
id);
543 dol_syslog(get_class($this) .
"::validate()", LOG_DEBUG);
544 $resql = $this->db->query(
$sql);
547 $this->error = $this->db->lasterror();
551 if (!$error && !$notrigger) {
553 $result = $this->
call_trigger(
'POSITION_VALIDATE', $user);
562 $this->oldref = $this->ref;
565 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
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);
572 $this->error = $this->db->lasterror();
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);
583 if (@rename($dirsource, $dirdest)) {
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);
602 $this->status = self::STATUS_VALIDATED;
609 $this->db->rollback();
625 if ($this->status <= self::STATUS_DRAFT) {
636 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'POSITION_UNVALIDATE');
646 public function cancel($user, $notrigger = 0)
649 if ($this->status != self::STATUS_VALIDATED) {
660 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'POSITION_CANCEL');
670 public function reopen($user, $notrigger = 0)
673 if ($this->status != self::STATUS_CANCELED) {
684 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'POSITION_REOPEN');
697 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
699 global $conf, $langs, $hookmanager;
701 if (!empty($conf->dol_no_mouse_hover)) {
707 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans(
"Position") .
'</u>';
708 if (isset($this->status)) {
712 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
714 $url =
dol_buildpath(
'/hrm/position_card.php', 1) .
'?id=' . $this->id;
716 if ($option !=
'nolink') {
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;
722 if ($add_save_lastsearch_values) {
723 $url .=
'&save_lastsearch_values=1';
728 if (empty($notooltip)) {
729 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
730 $label = $langs->trans(
"ShowPosition");
734 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
736 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
739 if ($option ==
'nolink') {
740 $linkstart =
'<span';
742 $linkstart =
'<a href="' . $url .
'"';
744 $linkstart .= $linkclose .
'>';
745 if ($option ==
'nolink') {
746 $linkend =
'</span>';
751 $result .= $linkstart;
753 if (empty($this->showphoto_on_popup)) {
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);
759 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
761 list($class, $module) = explode(
'@', $this->picto);
764 $filename = $filearray[0][
'name'];
765 if (!empty($filename)) {
766 $pospoint = strpos($filearray[0][
'name'],
'.');
768 $pathtophoto = $class .
'/' . $this->
ref .
'/thumbs/' . substr($filename, 0, $pospoint) .
'_mini' . substr($filename, $pospoint);
769 if (empty($conf->global->{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>';
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>';
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);
782 if ($withpicto != 2) {
783 $result .= $this->ref;
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);
794 $result = $hookmanager->resPrint;
796 $result .= $hookmanager->resPrint;
810 return $this->LibStatut($this->status, $mode);
825 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
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');
836 $statusType =
'status' . $status;
838 if ($status == self::STATUS_CANCELED) {
839 $statusType =
'status6';
842 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
859 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
863 if ($key ==
'fk_user') {
864 $vacantId = $keyprefix.$key.
'vacant'.$keysuffix;
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.
'" /> '.$langs->trans(
"Vacant").
'</label>';
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);
879 searchfkuser.prop(
'disabled', 0);
886 $out = parent::showInputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
905 public function showOutputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
909 if ($key ==
'fk_user' && $this->fk_user == 0) {
910 return $langs->trans(
"VacantPosition");
912 return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
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);
930 if ($this->db->num_rows($result)) {
931 $obj = $this->db->fetch_object($result);
932 $this->
id = $obj->rowid;
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);
940 $this->db->free($result);
958 $this->initAsSpecimenCommon();
968 $this->lines = array();
971 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql' =>
'fk_position = ' . $this->
id));
973 if (is_numeric($result)) {
974 $this->error = $objectline->error;
975 $this->errors = $objectline->errors;
978 $this->lines = $result;
990 global $langs, $conf;
993 if (empty($conf->global->hrm_POSITION_ADDON)) {
994 $conf->global->hrm_POSITION_ADDON =
'mod_position_standard';
997 if (!empty($conf->global->hrm_POSITION_ADDON)) {
1000 $file = $conf->global->hrm_POSITION_ADDON .
".php";
1001 $classname = $conf->global->hrm_POSITION_ADDON;
1004 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1005 foreach ($dirmodels as $reldir) {
1009 $mybool |= @include_once $dir . $file;
1012 if ($mybool ===
false) {
1017 if (class_exists($classname)) {
1018 $obj =
new $classname();
1019 $numref = $obj->getNextValue($this);
1021 if ($numref !=
'' && $numref !=
'-1') {
1024 $this->error = $obj->error;
1029 print $langs->trans(
"Error") .
" " . $langs->trans(
"ClassNotFound") .
' ' . $classname;
1033 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1046 $TPosition = array();
1048 $TPosition = $this->fetchAll(
'ASC',
't.rowid', 0, 0, array(
'customsql' =>
'fk_user=' . $userid));
1064 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1066 global $conf, $langs;
1069 $includedocgeneration = 0;
1071 $langs->load(
"hrm");
1074 $modele =
'standard_position';
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;
1083 $modelpath =
"core/modules/hrm/doc/";
1085 if ($includedocgeneration && !empty($modele)) {
1086 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1101 global $conf, $langs;
1117 $this->db->commit();
1131 global $selected, $langs;
1133 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
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">';
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>';
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>';
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>';
1155 $return .=
'</div>';
1156 $return .=
'</div>';
1157 $return .=
'</div>';
1163 require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobjectline.class.php';
1176 public $isextrafieldmanaged = 0;