24require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
25require_once DOL_DOCUMENT_ROOT.
"/core/lib/functions2.lib.php";
35 public $element =
'dolresource';
40 public $table_element =
'resource';
45 public $picto =
'resource';
51 public $fk_code_type_resource;
69 public $resource_type;
77 public $fk_user_create;
83 public $cache_code_type_resource = array();
108 public function create($user, $notrigger = 0)
110 global $conf, $langs, $hookmanager;
115 if (isset($this->
ref)) {
116 $this->
ref = trim($this->
ref);
121 if (!is_numeric($this->country_id)) {
122 $this->country_id = 0;
124 if (isset($this->fk_code_type_resource)) {
125 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
127 if (isset($this->note_public)) {
128 $this->note_public = trim($this->note_public);
130 if (isset($this->note_private)) {
131 $this->note_private = trim($this->note_private);
136 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
139 $sql .=
"description,";
140 $sql .=
"fk_country,";
141 $sql .=
"fk_code_type_resource,";
142 $sql .=
"note_public,";
143 $sql .=
"note_private";
144 $sql .=
") VALUES (";
145 $sql .= $conf->entity.
", ";
146 $sql .=
" ".(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
",";
148 $sql .=
" ".($this->country_id > 0 ? $this->country_id :
'null').
",";
149 $sql .=
" ".(!isset($this->fk_code_type_resource) ?
'NULL' :
"'".$this->db->escape($this->fk_code_type_resource).
"'").
",";
150 $sql .=
" ".(!isset($this->note_public) ?
'NULL' :
"'".$this->db->escape($this->note_public).
"'").
",";
151 $sql .=
" ".(!isset($this->note_private) ?
'NULL' :
"'".$this->db->escape($this->note_private).
"'");
156 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
157 $resql = $this->db->query($sql);
159 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
163 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
178 if (!$error && !$notrigger) {
180 $result = $this->
call_trigger(
'RESOURCE_CREATE', $user);
189 foreach ($this->errors as $errmsg) {
190 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
191 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
193 $this->db->rollback();
208 public function fetch($id, $ref =
'')
213 $sql .=
" t.entity,";
215 $sql .=
" t.description,";
216 $sql .=
" t.fk_country,";
217 $sql .=
" t.fk_code_type_resource,";
218 $sql .=
" t.note_public,";
219 $sql .=
" t.note_private,";
221 $sql .=
" ty.label as type_label";
222 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
223 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
225 $sql .=
" WHERE t.rowid = ".((int) $id);
227 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
230 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
231 $resql = $this->db->query($sql);
233 if ($this->db->num_rows($resql)) {
234 $obj = $this->db->fetch_object($resql);
236 $this->
id = $obj->rowid;
237 $this->entity = $obj->entity;
238 $this->
ref = $obj->ref;
240 $this->country_id = $obj->fk_country;
241 $this->fk_code_type_resource = $obj->fk_code_type_resource;
242 $this->note_public = $obj->note_public;
243 $this->note_private = $obj->note_private;
244 $this->type_label = $obj->type_label;
250 $this->db->free($resql);
254 $this->error =
"Error ".$this->db->lasterror();
255 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
268 public function update($user =
null, $notrigger = 0)
270 global $conf, $langs, $hookmanager;
274 if (isset($this->
ref)) {
275 $this->
ref = trim($this->
ref);
277 if (isset($this->fk_code_type_resource)) {
278 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
283 if (!is_numeric($this->country_id)) {
284 $this->country_id = 0;
288 if (empty($this->oldcopy)) {
293 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
294 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
295 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
296 $sql .=
" fk_country=".($this->country_id > 0 ? $this->country_id :
"null").
",";
297 $sql .=
" fk_code_type_resource=".(isset($this->fk_code_type_resource) ?
"'".$this->db->escape($this->fk_code_type_resource).
"'" :
"null").
",";
298 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
299 $sql .=
" WHERE rowid=".((int) $this->
id);
303 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
304 $resql = $this->db->query($sql);
306 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
312 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
320 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
322 if (!empty($conf->resource->dir_output)) {
325 if (file_exists($olddir)) {
326 $res = @rename($olddir, $newdir);
328 $langs->load(
"errors");
329 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
350 foreach ($this->errors as $errmsg) {
351 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
352 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
354 $this->db->rollback();
375 $sql .=
" t.resource_id,";
376 $sql .=
" t.resource_type,";
377 $sql .=
" t.element_id,";
378 $sql .=
" t.element_type,";
380 $sql .=
" t.mandatory,";
381 $sql .=
" t.fk_user_create,";
383 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_resources as t";
384 $sql .=
" WHERE t.rowid = ".((int) $id);
386 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
387 $resql = $this->db->query($sql);
389 if ($this->db->num_rows($resql)) {
390 $obj = $this->db->fetch_object($resql);
392 $this->
id = $obj->rowid;
393 $this->resource_id = $obj->resource_id;
394 $this->resource_type = $obj->resource_type;
395 $this->element_id = $obj->element_id;
396 $this->element_type = $obj->element_type;
397 $this->busy = $obj->busy;
398 $this->mandatory = $obj->mandatory;
399 $this->fk_user_create = $obj->fk_user_create;
401 if ($obj->resource_id && $obj->resource_type) {
404 if ($obj->element_id && $obj->element_type) {
408 $this->db->free($resql);
412 $this->error =
"Error ".$this->db->lasterror();
424 public function delete($rowid, $notrigger = 0)
426 global $user, $langs, $conf;
427 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
433 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
434 $sql .=
" WHERE rowid = ".((int) $rowid);
437 if ($this->db->query($sql)) {
438 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_resources";
439 $sql .=
" WHERE element_type='resource' AND resource_id = ".((int) $rowid);
440 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
441 $resql = $this->db->query($sql);
443 $this->error = $this->db->lasterror();
447 $this->error = $this->db->lasterror();
456 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
462 $result = $this->
call_trigger(
'RESOURCE_DELETE', $user);
472 if (!empty($conf->resource->dir_output)) {
474 if (file_exists($dir)) {
477 $this->errors[] =
'ErrorFailToDeleteDir';
488 $this->db->rollback();
504 public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter =
'')
507 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
512 $sql .=
" t.entity,";
514 $sql .=
" t.description,";
515 $sql .=
" t.fk_country,";
516 $sql .=
" t.fk_code_type_resource,";
519 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'label'])) {
520 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
521 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
"ef.".$key.
" as options_".$key.
', ' :
'');
524 $sql .=
" ty.label as type_label";
525 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
526 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
527 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$this->table_element.
"_extrafields as ef ON ef.fk_object=t.rowid";
528 $sql .=
" WHERE t.entity IN (".getEntity(
'resource').
")";
530 if (!empty($filter)) {
531 foreach ($filter as $key => $value) {
532 if (strpos($key,
'date')) {
533 $sql .=
" AND ".$key.
" = '".$this->db->idate($value).
"'";
534 } elseif (strpos($key,
'ef.') !==
false) {
537 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
541 $sql .= $this->db->order($sortfield, $sortorder);
543 $sql .= $this->db->plimit($limit, $offset);
546 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
548 $this->lines = array();
549 $resql = $this->db->query($sql);
551 $num = $this->db->num_rows($resql);
553 while ($obj = $this->db->fetch_object($resql)) {
555 $line->id = $obj->rowid;
556 $line->ref = $obj->ref;
557 $line->description = $obj->description;
558 $line->country_id = $obj->fk_country;
559 $line->fk_code_type_resource = $obj->fk_code_type_resource;
560 $line->type_label = $obj->type_label;
564 $line->fetch_optionals();
566 $this->lines[] = $line;
568 $this->db->free($resql);
572 $this->error = $this->db->lasterror();
588 global $conf, $langs;
592 if (isset($this->resource_id)) {
593 $this->resource_id = trim($this->resource_id);
595 if (isset($this->resource_type)) {
596 $this->resource_type = trim($this->resource_type);
598 if (isset($this->element_id)) {
599 $this->element_id = trim($this->element_id);
601 if (isset($this->element_type)) {
602 $this->element_type = trim($this->element_type);
604 if (isset($this->busy)) {
605 $this->busy = trim($this->busy);
607 if (isset($this->mandatory)) {
608 $this->mandatory = trim($this->mandatory);
612 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_resources SET";
613 $sql .=
" resource_id=".(isset($this->resource_id) ?
"'".$this->db->escape($this->resource_id).
"'" :
"null").
",";
614 $sql .=
" resource_type=".(isset($this->resource_type) ?
"'".$this->db->escape($this->resource_type).
"'" :
"null").
",";
615 $sql .=
" element_id=".(isset($this->element_id) ? $this->element_id :
"null").
",";
616 $sql .=
" element_type=".(isset($this->element_type) ?
"'".$this->db->escape($this->element_type).
"'" :
"null").
",";
617 $sql .=
" busy=".(isset($this->busy) ? $this->busy :
"null").
",";
618 $sql .=
" mandatory=".(isset($this->mandatory) ? $this->mandatory :
"null").
",";
619 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
621 $sql .=
" WHERE rowid=".((int) $this->
id);
625 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
626 $resql = $this->db->query($sql);
628 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
634 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
644 foreach ($this->errors as $errmsg) {
645 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
646 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
648 $this->db->rollback();
667 $resources = array();
670 $sql =
'SELECT rowid, resource_id, resource_type, busy, mandatory';
671 $sql .=
' FROM '.MAIN_DB_PREFIX.
'element_resources';
672 $sql .=
" WHERE element_id=".((int) $element_id).
" AND element_type='".$this->db->escape($element).
"'";
673 if ($resource_type) {
674 $sql .=
" AND resource_type LIKE '%".$this->db->escape($resource_type).
"%'";
676 $sql .=
' ORDER BY resource_type';
678 dol_syslog(get_class($this).
"::getElementResources", LOG_DEBUG);
680 $resources = array();
681 $resql = $this->db->query($sql);
683 $num = $this->db->num_rows($resql);
686 $obj = $this->db->fetch_object($resql);
688 $resources[$i] = array(
689 'rowid' => $obj->rowid,
690 'resource_id' => $obj->resource_id,
691 'resource_type'=>$obj->resource_type,
693 'mandatory'=>$obj->mandatory
713 foreach ($resources as $nb => $resource) {
732 if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
736 $sql =
"SELECT rowid, code, label, active";
737 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_resource";
738 $sql .=
" WHERE active > 0";
739 $sql .=
" ORDER BY rowid";
740 dol_syslog(get_class($this).
"::load_cache_code_type_resource", LOG_DEBUG);
741 $resql = $this->db->query($sql);
743 $num = $this->db->num_rows($resql);
746 $obj = $this->db->fetch_object($resql);
748 $label = ($langs->trans(
"ResourceTypeShort".$obj->code) != (
"ResourceTypeShort".$obj->code) ? $langs->trans(
"ResourceTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
749 $this->cache_code_type_resource[$obj->rowid][
'code'] = $obj->code;
750 $this->cache_code_type_resource[$obj->rowid][
'label'] = $label;
751 $this->cache_code_type_resource[$obj->rowid][
'active'] = $obj->active;
772 $langs->load(
'resource');
776 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Resource").
'</u>';
777 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
781 if (isset($this->type_label)) {
782 $datas[
'label'] =
'<br><b>'.$langs->trans(
"ResourceType").
":</b> ".$this->type_label;
799 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
801 global $conf, $langs, $hookmanager;
806 'objecttype' => $this->element,
808 $classfortooltip =
'classfortooltip';
811 $classfortooltip =
'classforajaxtooltip';
812 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
818 $url = DOL_URL_ROOT.
'/resource/card.php?id='.$this->id;
820 if ($option !=
'nolink') {
822 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
823 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
824 $add_save_lastsearch_values = 1;
826 if ($add_save_lastsearch_values) {
827 $url .=
'&save_lastsearch_values=1';
832 if (empty($notooltip)) {
833 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
834 $label = $langs->trans(
"ShowMyObject");
835 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
837 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
838 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
840 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
843 $linkstart =
'<a href="'.$url.$get_params.
'"';
844 $linkstart .= $linkclose.
'>';
849 $result .= $linkstart;
851 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
853 if ($withpicto != 2) {
854 $result .= $this->ref;
859 $hookmanager->initHooks(array($this->element .
'dao'));
860 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
861 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
863 $result = $hookmanager->resPrint;
865 $result .= $hookmanager->resPrint;
879 return $this->
LibStatut($this->status, $mode);
907 $sql =
"SELECT count(r.rowid) as nb";
908 $sql .=
" FROM ".MAIN_DB_PREFIX.
"resource as r";
909 $sql .=
" WHERE r.entity IN (".getEntity(
'resource').
")";
911 $resql = $this->db->query($sql);
913 while ($obj = $this->db->fetch_object($resql)) {
914 $this->nb[
"dolresource"] = $obj->nb;
916 $this->db->free($resql);
920 $this->error = $this->db->error();
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
update_element_resource($user=null, $notrigger=0)
Update element resource into database.
fetch_element_resource($id)
Load data of link in memory from database.
getElementResources($element, $element_id, $resource_type='')
Return an array with resources linked to the element.
create($user, $notrigger=0)
Create object into database.
fetch($id, $ref='')
Load object in memory from database.
fetchElementResources($element, $element_id)
Return an int number of resources linked to the element.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
getTooltipContentArray($params)
getTooltipContentArray
load_cache_code_type_resource()
Load in cache resource type code (setup in dictionary)
update($user=null, $notrigger=0)
Update object into database.
static LibStatut($status, $mode=0)
Return the status.
__construct($db)
Constructor.
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable link of object (with eventually picto)
fetchAll($sortorder, $sortfield, $limit, $offset, $filter='')
Load resource objects into $this->lines.
getLibStatut($mode=0)
Return the label of the status.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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)
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.