29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $module =
'hrm';
46 public $element =
'skilldet';
51 public $table_element =
'hrm_skilldet';
57 public $ismultientitymanaged = 0;
62 public $isextrafieldmanaged = 1;
67 public $picto =
'skilldet@hrm';
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 'fk_skill' => array(
'type'=>
'integer:Skill:/hrm/class/skill.class.php',
'label'=>
'fk_skill',
'enabled'=>
'1',
'position'=>5,
'notnull'=>1,
'visible'=>0,),
108 'rankorder' => array(
'type'=>
'integer',
'label'=>
'rank',
'enabled'=>
'1',
'position'=>10,
'notnull'=>0,
'visible'=>2,),
109 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>
'1',
'position'=>60,
'notnull'=>0,
'visible'=>1,),
110 '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',),
111 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>0,),
117 public $fk_user_creat;
118 public $fk_user_modif;
165 global $conf, $langs;
170 $this->fields[
'rowid'][
'visible'] = 0;
172 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
173 $this->fields[
'entity'][
'enabled'] = 0;
183 foreach ($this->fields as $key => $val) {
184 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
185 unset($this->fields[$key]);
190 if (is_object($langs)) {
191 foreach ($this->fields as $key => $val) {
192 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
193 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
194 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
214 return $resultcreate;
226 global $langs, $extrafields;
231 $object =
new self($this->db);
236 $result = $object->fetchCommon($fromid);
237 if ($result > 0 && !empty($object->table_element_line)) {
238 $object->fetchLines();
247 unset($object->fk_user_creat);
248 unset($object->import_key);
251 if (property_exists($object,
'ref')) {
252 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
254 if (property_exists($object,
'label')) {
255 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
257 if (property_exists($object,
'status')) {
258 $object->status = self::STATUS_DRAFT;
260 if (property_exists($object,
'date_creation')) {
261 $object->date_creation =
dol_now();
263 if (property_exists($object,
'date_modification')) {
264 $object->date_modification =
null;
268 if (is_array($object->array_options) && count($object->array_options) > 0) {
269 $extrafields->fetch_name_optionals_label($this->table_element);
270 foreach ($object->array_options as $key => $option) {
271 $shortkey = preg_replace(
'/options_/',
'', $key);
272 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
274 unset($object->array_options[$key]);
280 $object->context[
'createfromclone'] =
'createfromclone';
281 $result = $object->createCommon($user);
284 $this->error = $object->error;
285 $this->errors = $object->errors;
297 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
304 unset($object->context[
'createfromclone']);
311 $this->db->rollback();
323 public function fetch($id, $ref =
null)
326 if ($result > 0 && !empty($this->table_element_line)) {
339 $this->lines = array();
357 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
365 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
366 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
367 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
369 $sql .=
' WHERE 1 = 1';
373 if (count($filter) > 0) {
374 foreach ($filter as $key => $value) {
375 if ($key ==
't.rowid') {
376 $sqlwhere[] = $key.
'='.$value;
377 } elseif ($key ==
'customsql') {
378 $sqlwhere[] = $value;
379 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
380 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
381 } elseif (strpos($value,
'%') ===
false) {
382 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
384 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
388 if (count($sqlwhere) > 0) {
389 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
392 if (!empty($sortfield)) {
393 $sql .= $this->db->order($sortfield, $sortorder);
395 if (!empty($limit)) {
396 $sql .=
" ".$this->db->plimit($limit, $offset);
399 $resql = $this->db->query($sql);
401 $num = $this->db->num_rows($resql);
403 while ($i < ($limit ? min($limit, $num) : $num)) {
404 $obj = $this->db->fetch_object($resql);
406 $record =
new self($this->db);
407 $record->setVarsFromFetchObj($obj);
409 $records[$record->id] = $record;
413 $this->db->free($resql);
417 $this->errors[] =
'Error '.$this->db->lasterror();
418 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
443 public function delete(
User $user, $notrigger =
false)
460 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
477 global $conf, $langs;
479 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
484 if ($this->
status == self::STATUS_VALIDATED) {
485 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
502 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
507 $this->newref = $num;
511 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
512 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
513 $sql .=
" status = ".self::STATUS_VALIDATED;
514 if (!empty($this->fields[
'date_validation'])) {
515 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
517 if (!empty($this->fields[
'fk_user_valid'])) {
518 $sql .=
", fk_user_valid = ".((int) $user->id);
520 $sql .=
" WHERE rowid = ".((int) $this->
id);
522 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
523 $resql = $this->db->query($sql);
526 $this->error = $this->db->lasterror();
530 if (!$error && !$notrigger) {
532 $result = $this->
call_trigger(
'HRM_SKILLDET_VALIDATE', $user);
541 $this->oldref = $this->ref;
544 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
546 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'skilldet/".$this->db->escape($this->newref).
"'";
547 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'skilldet/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
548 $resql = $this->db->query($sql);
551 $this->error = $this->db->lasterror();
553 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'skilldet/".$this->db->escape($this->newref).
"'";
554 $sql .=
" WHERE filepath = 'skilldet/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
555 $resql = $this->db->query($sql);
558 $this->error = $this->db->lasterror();
564 $dirsource = $conf->hrm->dir_output.
'/skilldet/'.$oldref;
565 $dirdest = $conf->hrm->dir_output.
'/skilldet/'.$newref;
566 if (!$error && file_exists($dirsource)) {
567 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
569 if (@rename($dirsource, $dirdest)) {
572 $listoffiles =
dol_dir_list($conf->hrm->dir_output.
'/skilldet/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
573 foreach ($listoffiles as $fileentry) {
574 $dirsource = $fileentry[
'name'];
575 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
576 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
577 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
578 @rename($dirsource, $dirdest);
588 $this->
status = self::STATUS_VALIDATED;
595 $this->db->rollback();
611 if ($this->
status <= self::STATUS_DRAFT) {
622 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SKILLDET_UNVALIDATE');
632 public function cancel($user, $notrigger = 0)
635 if ($this->
status != self::STATUS_VALIDATED) {
646 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'SKILLDET_CANCEL');
656 public function reopen($user, $notrigger = 0)
659 if ($this->
status != self::STATUS_CANCELED) {
670 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'SKILLDET_REOPEN');
683 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
685 global $conf, $langs, $hookmanager;
687 if (!empty($conf->dol_no_mouse_hover)) {
693 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Skilldet").
'</u>';
694 if (isset($this->
status)) {
695 $label .=
' '.$this->getLibStatut(5);
698 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
700 $url =
dol_buildpath(
'/hrm/skilldet_card.php', 1).
'?id='.$this->id;
702 if ($option !=
'nolink') {
704 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
705 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
706 $add_save_lastsearch_values = 1;
708 if ($add_save_lastsearch_values) {
709 $url .=
'&save_lastsearch_values=1';
714 if (empty($notooltip)) {
716 $label = $langs->trans(
"ShowSkilldet");
717 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
719 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
720 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
722 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
725 if ($option ==
'nolink') {
726 $linkstart =
'<span';
728 $linkstart =
'<a href="'.$url.
'"';
730 $linkstart .= $linkclose.
'>';
731 if ($option ==
'nolink') {
732 $linkend =
'</span>';
737 $result .= $linkstart;
739 if (empty($this->showphoto_on_popup)) {
741 $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);
745 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
747 list($class, $module) = explode(
'@', $this->picto);
750 $filename = $filearray[0][
'name'];
751 if (!empty($filename)) {
752 $pospoint = strpos($filearray[0][
'name'],
'.');
754 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
756 $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>';
758 $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>';
763 $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);
768 if ($withpicto != 2) {
769 $result .= $this->ref;
775 global $action, $hookmanager;
776 $hookmanager->initHooks(array(
'skilldetdao'));
777 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
778 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
780 $result = $hookmanager->resPrint;
782 $result .= $hookmanager->resPrint;
810 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
813 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
814 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
815 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
816 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
817 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
818 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
821 $statusType =
'status'.$status;
823 if ($status == self::STATUS_CANCELED) {
824 $statusType =
'status6';
827 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
838 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
839 $sql .=
' fk_user_creat, fk_user_modif';
840 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
841 $sql .=
' WHERE t.rowid = '.((int) $id);
842 $result = $this->db->query($sql);
844 if ($this->db->num_rows($result)) {
845 $obj = $this->db->fetch_object($result);
847 $this->
id = $obj->rowid;
849 $this->user_creation_id = $obj->fk_user_creat;
850 $this->user_modification_id = $obj->fk_user_modif;
851 $this->date_creation = $this->db->jdate($obj->datec);
852 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
855 $this->db->free($result);
884 global $langs, $conf;
888 $conf->global->hrm_SKILLDET_ADDON =
'mod_skilldet_standard';
895 $classname = $conf->global->hrm_SKILLDET_ADDON;
898 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
899 foreach ($dirmodels as $reldir) {
903 $mybool |= @include_once $dir.$file;
906 if ($mybool ===
false) {
911 if (class_exists($classname)) {
912 $obj =
new $classname();
913 $numref = $obj->getNextValue($this);
915 if ($numref !=
'' && $numref !=
'-1') {
918 $this->error = $obj->error;
923 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
927 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
943 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
945 global $conf, $langs;
948 $includedocgeneration = 0;
953 $modele =
'standard_skilldet';
955 if (!empty($this->model_pdf)) {
956 $modele = $this->model_pdf;
958 $modele = $conf->global->SKILLDET_ADDON_PDF;
962 $modelpath =
"core/modules/hrm/doc/";
964 if ($includedocgeneration && !empty($modele)) {
965 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
980 global $conf, $langs;
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
update(User $user, $notrigger=false)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
cancel($user, $notrigger=0)
Set cancel status.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
fetchLines()
Load object lines in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
validate($user, $notrigger=0)
Validate object.
info($id)
Load the info information in the object.
reopen($user, $notrigger=0)
Set back to validated status.
setDraft($user, $notrigger=0)
Set draft status.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.