25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $module =
'knowledgemanagement';
42 public $element =
'knowledgerecord';
47 public $table_element =
'knowledgemanagement_knowledgerecord';
53 public $ismultientitymanaged = 1;
58 public $isextrafieldmanaged = 1;
63 public $picto =
'knowledgemanagement';
66 const STATUS_DRAFT = 0;
67 const STATUS_VALIDATED = 1;
68 const STATUS_CANCELED = 9;
102 public $fields=array(
103 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
104 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'default'=>
'(PROV)',
'visible'=>5,
'index'=>1,
'searchall'=>1,
'comment'=>
"Reference of object",
"csslist"=>
"nowraponall",
"showoncombobox"=>1),
105 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>20,
'index'=>1),
106 'question' => array(
'type'=>
'text',
'label'=>
'Question',
'enabled'=>
'1',
'position'=>30,
'notnull'=>1,
'visible'=>1,
'searchall'=>1,
'csslist'=>
'tdoverflowmax300',
'copytoclipboard'=>1,
'tdcss'=>
'titlefieldcreate nowraponall'),
107 'lang' => array(
'type'=>
'varchar(6)',
'label'=>
'Language',
'enabled'=>
'1',
'position'=>40,
'notnull'=>0,
'visible'=>1,
'tdcss'=>
'titlefieldcreate nowraponall',
"csslist"=>
"tdoverflowmax100"),
108 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
109 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>2,),
110 'last_main_doc' => array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>
'1',
'position'=>600,
'notnull'=>0,
'visible'=>0,),
111 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserCreation',
'enabled'=>
'1',
'position'=>510,
'notnull'=>1,
'visible'=>-2,
'foreignkey'=>
'user.rowid',),
112 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
113 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>
'1',
'position'=>512,
'notnull'=>0,
'visible'=>-2,),
114 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
115 'model_pdf' => array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>
'1',
'position'=>1010,
'notnull'=>-1,
'visible'=>0,),
117 'fk_c_ticket_category' => array(
'type'=>
'integer:CTicketCategory:ticket/class/cticketcategory.class.php:0:(t.active:=:1):pos',
'label'=>
'SuggestedForTicketsInGroup',
'enabled'=>
'isModEnabled("ticket")',
'position'=>520,
'notnull'=>0,
'visible'=>-1,
'help'=>
'YouCanLinkArticleToATicketCategory',
'csslist'=>
'minwidth200 tdoverflowmax250'),
118 'answer' => array(
'type'=>
'html',
'label'=>
'Solution',
'enabled'=>
'1',
'position'=>600,
'notnull'=>0,
'visible'=>3,
'searchall'=>1,
'csslist'=>
'tdoverflowmax300',
'copytoclipboard'=>1,
'tdcss'=>
'titlefieldcreate nowraponall'),
119 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>1,
'visible'=>5,
'default'=>0,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Draft',
'1'=>
'Validated',
'9'=>
'Obsolete'),),
124 public $date_creation;
126 public $last_main_doc;
127 public $fk_user_creat;
128 public $fk_user_modif;
129 public $fk_user_valid;
183 global $conf, $langs;
187 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
188 $this->fields[
'rowid'][
'visible'] = 0;
190 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
191 $this->fields[
'entity'][
'enabled'] = 0;
201 foreach ($this->fields as $key => $val) {
202 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
203 unset($this->fields[$key]);
208 if (is_object($langs)) {
209 foreach ($this->fields as $key => $val) {
210 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
211 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
212 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
240 global $langs, $extrafields;
245 $object =
new self($this->db);
250 $result = $object->fetchCommon($fromid);
251 if ($result > 0 && !empty($object->table_element_line)) {
252 $object->fetchLines();
261 unset($object->fk_user_creat);
262 unset($object->import_key);
265 if (property_exists($object,
'ref')) {
266 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
268 if (property_exists($object,
'label')) {
269 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
271 if (property_exists($object,
'status')) {
272 $object->status = self::STATUS_DRAFT;
274 if (property_exists($object,
'date_creation')) {
275 $object->date_creation =
dol_now();
277 if (property_exists($object,
'date_modification')) {
278 $object->date_modification =
null;
282 if (is_array($object->array_options) && count($object->array_options) > 0) {
283 $extrafields->fetch_name_optionals_label($this->table_element);
284 foreach ($object->array_options as $key => $option) {
285 $shortkey = preg_replace(
'/options_/',
'', $key);
286 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
289 unset($object->array_options[$key]);
295 $object->context[
'createfromclone'] =
'createfromclone';
296 $result = $object->createCommon($user);
299 $this->error = $object->error;
300 $this->errors = $object->errors;
312 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
319 unset($object->context[
'createfromclone']);
326 $this->
db->rollback();
338 public function fetch($id, $ref =
null)
341 if ($result > 0 && !empty($this->table_element_line)) {
354 $this->lines = array();
372 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
382 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
383 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
384 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
386 $sql .=
' WHERE 1 = 1';
390 if (count($filter) > 0) {
391 foreach ($filter as $key => $value) {
392 if ($key ==
't.rowid') {
393 $sqlwhere[] = $key.
" = ".((int) $value);
394 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
395 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
396 } elseif ($key ==
'customsql') {
397 $sqlwhere[] = $value;
398 } elseif (strpos($value,
'%') ===
false) {
399 $sqlwhere[] = $key.
' IN ('.$this->
db->sanitize($this->
db->escape($value)).
')';
401 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
405 if (count($sqlwhere) > 0) {
406 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
409 if (!empty($sortfield)) {
410 $sql .= $this->
db->order($sortfield, $sortorder);
412 if (!empty($limit)) {
413 $sql .= $this->
db->plimit($limit, $offset);
420 while ($i < ($limit ? min($limit, $num) : $num)) {
421 $obj = $this->
db->fetch_object(
$resql);
423 $record =
new self($this->db);
424 $record->setVarsFromFetchObj($obj);
426 $records[$record->id] = $record;
434 $this->errors[] =
'Error '.$this->db->lasterror();
435 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
460 public function delete(
User $user, $notrigger =
false)
463 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_knowledgemanagement WHERE fk_knowledgemanagement = ".((int) $this->
id);
464 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
468 $this->error .= $this->
db->lasterror();
474 $elements = array(
'categorie_knowledgemanagement');
475 foreach ($elements as $table) {
477 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
478 $sql .=
" WHERE fk_knowledgemanagement = ".(int) $this->
id;
480 $result = $this->
db->query($sql);
483 $this->errors[] = $this->
db->lasterror();
503 if ($this->status < 0) {
504 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
521 global $conf, $langs;
523 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
528 if ($this->status == self::STATUS_VALIDATED) {
529 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
546 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
551 $this->newref = $num;
555 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
556 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
557 $sql .=
" status = ".self::STATUS_VALIDATED;
558 if (!empty($this->fields[
'date_validation'])) {
559 $sql .=
", date_validation = '".$this->db->idate($now).
"'";
561 if (!empty($this->fields[
'fk_user_valid'])) {
562 $sql .=
", fk_user_valid = ".((int) $user->id);
564 $sql .=
" WHERE rowid = ".((int) $this->
id);
566 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
570 $this->error = $this->
db->lasterror();
574 if (!$error && !$notrigger) {
576 $result = $this->
call_trigger(
'KNOWLEDGERECORD_VALIDATE', $user);
585 $this->oldref = $this->ref;
588 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
590 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->
db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'knowledgerecord/".$this->
db->escape($this->newref).
"'";
591 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'knowledgerecord/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
594 $error++; $this->error = $this->
db->lasterror();
600 $dirsource = $conf->knowledgemanagement->dir_output.
'/knowledgerecord/'.$oldref;
601 $dirdest = $conf->knowledgemanagement->dir_output.
'/knowledgerecord/'.$newref;
602 if (!$error && file_exists($dirsource)) {
603 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
605 if (@rename($dirsource, $dirdest)) {
608 $listoffiles =
dol_dir_list($conf->knowledgemanagement->dir_output.
'/knowledgerecord/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
609 foreach ($listoffiles as $fileentry) {
610 $dirsource = $fileentry[
'name'];
611 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
612 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
613 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
614 @rename($dirsource, $dirdest);
624 $this->status = self::STATUS_VALIDATED;
631 $this->
db->rollback();
647 if ($this->status <= self::STATUS_DRAFT) {
658 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'KNOWLEDGERECORD_UNVALIDATE');
668 public function cancel($user, $notrigger = 0)
671 if ($this->status != self::STATUS_VALIDATED) {
682 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'KNOWLEDGERECORD_CANCEL');
692 public function reopen($user, $notrigger = 0)
695 if ($this->status != self::STATUS_CANCELED) {
706 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'KNOWLEDGERECORD_REOPEN');
719 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
721 global $conf, $langs, $hookmanager;
723 if (!empty($conf->dol_no_mouse_hover)) {
729 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"KnowledgeRecord").
'</u>';
730 if (isset($this->status)) {
731 $label .=
' '.$this->getLibStatut(5);
734 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
736 $url =
dol_buildpath(
'/knowledgemanagement/knowledgerecord_card.php', 1).
'?id='.$this->id;
738 if ($option !=
'nolink') {
740 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
741 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
742 $add_save_lastsearch_values = 1;
744 if ($add_save_lastsearch_values) {
745 $url .=
'&save_lastsearch_values=1';
750 if (empty($notooltip)) {
751 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
752 $label = $langs->trans(
"ShowKnowledgeRecord");
753 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
755 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
756 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
758 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
761 if ($option ==
'nolink') {
762 $linkstart =
'<span';
764 $linkstart =
'<a href="'.$url.
'"';
766 $linkstart .= $linkclose.
'>';
767 if ($option ==
'nolink') {
768 $linkend =
'</span>';
773 $result .= $linkstart;
775 if (empty($this->showphoto_on_popup)) {
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);
781 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
783 list($class, $module) = explode(
'@', $this->picto);
786 $filename = $filearray[0][
'name'];
787 if (!empty($filename)) {
788 $pospoint = strpos($filearray[0][
'name'],
'.');
790 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
791 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
792 $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>';
794 $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>';
799 $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);
804 if ($withpicto != 2) {
805 $result .= $this->ref;
811 global $action, $hookmanager;
812 $hookmanager->initHooks(array(
'knowledgerecorddao'));
813 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
814 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
816 $result = $hookmanager->resPrint;
818 $result .= $hookmanager->resPrint;
832 return $this->LibStatut($this->status, $mode);
846 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
849 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
850 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
851 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Obsolete');
852 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
853 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
854 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Obsolete');
857 $statusType =
'status'.$status;
858 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
859 if ($status == self::STATUS_CANCELED) {
860 $statusType =
'status6';
863 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
874 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
875 $sql .=
' fk_user_creat, fk_user_modif';
876 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
877 $sql .=
' WHERE t.rowid = '.((int) $id);
878 $result = $this->
db->query($sql);
880 if ($this->
db->num_rows($result)) {
881 $obj = $this->
db->fetch_object($result);
882 $this->
id = $obj->rowid;
884 $this->user_creation_id = $obj->fk_user_creat;
885 $this->user_modification_id = $obj->fk_user_modif;
886 $this->date_creation = $this->
db->jdate($obj->datec);
887 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
890 $this->
db->free($result);
904 $this->question =
"ABCD";
905 $this->initAsSpecimenCommon();
915 $this->lines = array();
918 $result = $objectline->fetchAll(
'ASC',
'position', 0, 0, array(
'customsql'=>
'fk_knowledgerecord = '.((
int) $this->
id)));
920 if (is_numeric($result)) {
921 $this->error = $objectline->error;
922 $this->errors = $objectline->errors;
925 $this->lines = $result;
937 global $langs, $conf;
938 $langs->load(
"knowledgemanagement");
940 if (empty($conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON)) {
941 $conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON =
'mod_knowledgerecord_standard';
944 if (!empty($conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON)) {
947 $file = $conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON.
".php";
948 $classname = $conf->global->KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_ADDON;
951 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
952 foreach ($dirmodels as $reldir) {
953 $dir =
dol_buildpath($reldir.
"core/modules/knowledgemanagement/");
956 $mybool |= @include_once $dir.$file;
959 if ($mybool ===
false) {
964 if (class_exists($classname)) {
965 $obj =
new $classname();
966 $numref = $obj->getNextValue($this);
968 if ($numref !=
'' && $numref !=
'-1') {
971 $this->error = $obj->error;
976 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
980 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
996 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
998 global $conf, $langs;
1001 $includedocgeneration = 0;
1003 $langs->load(
"knowledgemanagement");
1006 $modele =
'standard_knowledgerecord';
1008 if (!empty($this->model_pdf)) {
1009 $modele = $this->model_pdf;
1010 } elseif (!empty($conf->global->KNOWLEDGERECORD_ADDON_PDF)) {
1011 $modele = $conf->global->KNOWLEDGERECORD_ADDON_PDF;
1015 $modelpath =
"core/modules/knowledgemanagement/doc/";
1017 if ($includedocgeneration && !empty($modele)) {
1018 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1033 global $conf, $langs;
1049 $this->
db->commit();
1066 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1067 return parent::setCategoriesCommon($categories, Categorie::TYPE_KNOWLEDGEMANAGEMENT);
1072 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1085 public $isextrafieldmanaged = 0;