29 require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT .
'/hrm/class/evaluationdet.class.php';
42 public $module =
'hrm';
47 public $element =
'evaluation';
52 public $table_element =
'hrm_evaluation';
58 public $ismultientitymanaged = 0;
63 public $isextrafieldmanaged = 1;
68 public $picto =
'label';
71 const STATUS_DRAFT = 0;
72 const STATUS_VALIDATED = 1;
73 const STATUS_CANCELED = 9;
74 const STATUS_CLOSED = 6;
107 public $fields=array(
108 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
109 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>20,
'notnull'=>1,
'visible'=>4,
'noteditable'=>
'1',
'default'=>
'(PROV)',
'index'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'comment'=>
"Reference of object"),
110 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>30,
'notnull'=>0,
'visible'=>1,
'searchall'=>1,
'css'=>
'minwidth300',
'cssview'=>
'wordbreak',
'showoncombobox'=>
'2',),
111 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>
'1',
'position'=>60,
'notnull'=>0,
'visible'=>3,),
112 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>61,
'notnull'=>0,
'visible'=>0,),
113 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>62,
'notnull'=>0,
'visible'=>0,),
114 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
115 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,),
116 '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',),
117 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
118 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
119 'status' => array(
'type'=>
'smallint',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>1,
'default'=>0,
'visible'=>5,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Draft',
'1'=>
'Validated',
'6' =>
'Closed'),),
120 'date_eval' => array(
'type'=>
'date',
'label'=>
'DateEval',
'enabled'=>
'1',
'position'=>502,
'notnull'=>1,
'visible'=>1,),
121 'fk_user' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'User',
'enabled'=>
'1',
'position'=>504,
'notnull'=>1,
'visible'=>1,),
122 'fk_job' => array(
'type'=>
'integer:Job:/hrm/class/job.class.php',
'label'=>
'Job',
'enabled'=>
'1',
'position'=>505,
'notnull'=>1,
'visible'=>1,),
129 public $note_private;
130 public $date_creation;
132 public $fk_user_creat;
133 public $fk_user_modif;
147 public $table_element_line =
'hrm_evaluationdet';
152 public $fk_element =
'fk_evaluation';
157 public $class_element_line =
'Evaluationline';
169 protected $childtablesoncascade = array(
'@Evaluationline:hrm/class/evaluationdet.class.php:fk_evaluation');
174 public $lines = array();
185 global $conf, $langs;
189 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
190 $this->fields[
'rowid'][
'visible'] = 0;
192 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
193 $this->fields[
'entity'][
'enabled'] = 0;
199 foreach ($this->fields as $key => $val) {
200 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
201 unset($this->fields[$key]);
206 if (is_object($langs)) {
207 foreach ($this->fields as $key => $val) {
208 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
209 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
210 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
228 if ($resultcreate > 0) {
229 require_once DOL_DOCUMENT_ROOT .
'/hrm/class/skillrank.class.php';
231 $TRequiredRanks = $skillRank->fetchAll(
'ASC',
't.rowid', 0, 0, array(
'customsql' =>
'fk_object='.$this->fk_job.
" AND objecttype='job'"));
233 if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) {
234 $this->lines = array();
235 foreach ($TRequiredRanks as $required) {
237 $line->fk_evaluation = $resultcreate;
238 $line->fk_skill = $required->fk_skill;
239 $line->required_rank = $required->rankorder;
242 $res = $line->create($user, $notrigger);
243 if ($res > 0) $this->lines[] = $line;
248 return $resultcreate;
260 global $langs, $extrafields;
265 $object =
new self($this->db);
270 $result = $object->fetchCommon($fromid);
271 if ($result > 0 && !empty($object->table_element_line)) {
272 $object->fetchLines();
281 unset($object->fk_user_creat);
282 unset($object->import_key);
285 if (property_exists($object,
'ref')) {
286 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
288 if (property_exists($object,
'label')) {
289 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
291 if (property_exists($object,
'status')) {
292 $object->status = self::STATUS_DRAFT;
294 if (property_exists($object,
'date_creation')) {
295 $object->date_creation =
dol_now();
297 if (property_exists($object,
'date_modification')) {
298 $object->date_modification =
null;
302 if (is_array($object->array_options) && count($object->array_options) > 0) {
303 $extrafields->fetch_name_optionals_label($this->table_element);
304 foreach ($object->array_options as $key => $option) {
305 $shortkey = preg_replace(
'/options_/',
'', $key);
306 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
308 unset($object->array_options[$key]);
314 $object->context[
'createfromclone'] =
'createfromclone';
315 $result = $object->createCommon($user);
318 $this->error = $object->error;
319 $this->errors = $object->errors;
331 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
338 unset($object->context[
'createfromclone']);
345 $this->
db->rollback();
357 public function fetch($id, $ref =
null)
360 if ($result > 0 && !empty($this->table_element_line)) {
373 $this->lines = array();
391 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
401 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
402 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
403 $sql .=
' WHERE t.entity IN ('.getEntity($this->table_element).
')';
405 $sql .=
' WHERE 1 = 1';
409 if (count($filter) > 0) {
410 foreach ($filter as $key => $value) {
411 if ($key ==
't.rowid') {
412 $sqlwhere[] = $key.
'='.$value;
413 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
414 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
415 } elseif ($key ==
'customsql') {
416 $sqlwhere[] = $value;
417 } elseif (strpos($value,
'%') ===
false) {
418 $sqlwhere[] = $key.
' IN ('.$this->
db->sanitize($this->
db->escape($value)).
')';
420 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
424 if (count($sqlwhere) > 0) {
425 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
428 if (!empty($sortfield)) {
429 $sql .= $this->
db->order($sortfield, $sortorder);
431 if (!empty($limit)) {
432 $sql .=
' '.$this->db->plimit($limit, $offset);
439 while ($i < ($limit ? min($limit, $num) : $num)) {
440 $obj = $this->
db->fetch_object(
$resql);
442 $record =
new self($this->db);
443 $record->setVarsFromFetchObj($obj);
445 $records[$record->id] = $record;
453 $this->errors[] =
'Error '.$this->db->lasterror();
454 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
479 public function delete(
User $user, $notrigger =
false)
495 if ($this->status < 0) {
496 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
513 global $conf, $langs;
515 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
520 if ($this->status == self::STATUS_VALIDATED) {
521 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
532 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
537 $this->newref = $num;
541 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
542 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
543 $sql .=
" status = ".self::STATUS_VALIDATED;
544 if (!empty($this->fields[
'date_validation'])) {
545 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
547 if (!empty($this->fields[
'fk_user_valid'])) {
548 $sql .=
", fk_user_valid = ".((int) $user->id);
550 $sql .=
" WHERE rowid = ".((int) $this->
id);
552 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
556 $this->error = $this->
db->lasterror();
560 if (!$error && !$notrigger) {
562 $result = $this->
call_trigger(
'EVALUATION_VALIDATE', $user);
571 $this->oldref = $this->ref;
574 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
576 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->
db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'evaluation/".$this->
db->escape($this->newref).
"'";
577 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'evaluation/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
580 $error++; $this->error = $this->
db->lasterror();
586 $dirsource = $conf->hrm->dir_output.
'/evaluation/'.$oldref;
587 $dirdest = $conf->hrm->dir_output.
'/evaluation/'.$newref;
588 if (!$error && file_exists($dirsource)) {
589 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
591 if (@rename($dirsource, $dirdest)) {
594 $listoffiles =
dol_dir_list($conf->hrm->dir_output.
'/evaluation/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
595 foreach ($listoffiles as $fileentry) {
596 $dirsource = $fileentry[
'name'];
597 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
598 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
599 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
600 @rename($dirsource, $dirdest);
610 $this->status = self::STATUS_VALIDATED;
617 $this->
db->rollback();
630 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"hrm_evaluation ";
631 $sql.=
"WHERE fk_user=".((int) $fk_user).
" ";
632 $sql.=
"ORDER BY date_eval DESC ";
635 $res = $this->
db->query($sql);
638 $Tab = $this->
db->fetch_object($res);
640 if (empty($Tab))
return null;
643 $evaluation->fetch($Tab->rowid);
660 if ($this->status <= self::STATUS_DRAFT) {
666 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'EVALUATION_UNVALIDATE');
676 public function cancel($user, $notrigger = 0)
679 if ($this->status != self::STATUS_VALIDATED) {
685 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'EVALUATION_CANCEL');
695 public function reopen($user, $notrigger = 0)
698 if ($this->status != self::STATUS_CANCELED) {
704 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'EVALUATION_REOPEN');
717 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
719 global $conf, $langs, $hookmanager;
721 if (!empty($conf->dol_no_mouse_hover)) {
727 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Evaluation").
'</u>';
728 if (isset($this->status)) {
729 $label .=
' '.$this->getLibStatut(5);
732 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
734 $url =
dol_buildpath(
'/hrm/evaluation_card.php', 1).
'?id='.$this->id;
736 if ($option !=
'nolink') {
738 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
739 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
740 $add_save_lastsearch_values = 1;
742 if ($add_save_lastsearch_values) {
743 $url .=
'&save_lastsearch_values=1';
748 if (empty($notooltip)) {
749 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
750 $label = $langs->trans(
"ShowEvaluation");
751 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
753 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
754 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
756 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
759 if ($option ==
'nolink') {
760 $linkstart =
'<span';
762 $linkstart =
'<a href="'.$url.
'"';
764 $linkstart .= $linkclose.
'>';
765 if ($option ==
'nolink') {
766 $linkend =
'</span>';
771 $result .= $linkstart;
773 if (empty($this->showphoto_on_popup)) {
775 $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);
779 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
781 list($class, $module) = explode(
'@', $this->picto);
784 $filename = $filearray[0][
'name'];
785 if (!empty($filename)) {
786 $pospoint = strpos($filearray[0][
'name'],
'.');
788 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
789 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
790 $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>';
792 $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>';
797 $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);
802 if ($withpicto != 2) {
803 $result .= $this->ref;
809 global $action, $hookmanager;
810 $hookmanager->initHooks(array(
'evaluationdao'));
811 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
812 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
814 $result = $hookmanager->resPrint;
816 $result .= $hookmanager->resPrint;
830 return $this->LibStatut($this->status, $mode);
844 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
847 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
848 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
849 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
850 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
851 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
852 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
855 $statusType =
'status'.$status;
857 if ($status == self::STATUS_CANCELED) {
858 $statusType =
'status6';
861 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
872 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
873 $sql .=
' fk_user_creat, fk_user_modif';
874 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
875 $sql .=
' WHERE t.rowid = '.((int) $id);
876 $result = $this->
db->query($sql);
878 if ($this->
db->num_rows($result)) {
879 $obj = $this->
db->fetch_object($result);
880 $this->
id = $obj->rowid;
882 $this->user_creation_id = $obj->fk_user_creat;
883 $this->user_modification_id = $obj->fk_user_modif;
884 $this->date_creation = $this->
db->jdate($obj->datec);
885 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
888 $this->
db->free($result);
906 $this->initAsSpecimenCommon();
916 $this->lines = array();
919 $result = $objectline->fetchAll(
'ASC',
'', 0, 0, array(
'customsql'=>
'fk_evaluation = '.$this->
id));
921 if (is_numeric($result)) {
922 $this->error = $this->error;
923 $this->errors = $this->errors;
926 $this->lines = $result;
938 global $langs, $conf;
941 if (empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
942 $conf->global->HRMTEST_EVALUATION_ADDON =
'mod_evaluation_standard';
945 if (!empty($conf->global->HRMTEST_EVALUATION_ADDON)) {
948 $file = $conf->global->HRMTEST_EVALUATION_ADDON.
".php";
949 $classname = $conf->global->HRMTEST_EVALUATION_ADDON;
952 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
953 foreach ($dirmodels as $reldir) {
957 $mybool |= @include_once $dir.$file;
960 if ($mybool ===
false) {
965 if (class_exists($classname)) {
966 $obj =
new $classname();
967 $numref = $obj->getNextValue($this);
969 if ($numref !=
'' && $numref !=
'-1') {
972 $this->error = $obj->error;
977 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
981 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
997 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
999 global $conf, $langs;
1002 $includedocgeneration = 0;
1004 $langs->load(
"hrm");
1007 $modele =
'standard_evaluation';
1009 if (!empty($this->model_pdf)) {
1010 $modele = $this->model_pdf;
1011 } elseif (!empty($conf->global->EVALUATION_ADDON_PDF)) {
1012 $modele = $conf->global->EVALUATION_ADDON_PDF;
1016 $modelpath =
"core/modules/hrm/doc/";
1018 if ($includedocgeneration && !empty($modele)) {
1019 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1034 global $conf, $langs;
1050 $this->
db->commit();