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;
79 public $fk_user_create;
90 public $cache_code_type_resource = array();
115 public function create($user, $notrigger = 0)
117 global $conf, $langs, $hookmanager;
122 if (isset($this->
ref)) {
123 $this->
ref = trim($this->
ref);
128 if (!is_numeric($this->country_id)) {
129 $this->country_id = 0;
131 if (isset($this->fk_code_type_resource)) {
132 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
134 if (isset($this->note_public)) {
135 $this->note_public = trim($this->note_public);
137 if (isset($this->note_private)) {
138 $this->note_private = trim($this->note_private);
143 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
146 $sql .=
"description,";
147 $sql .=
"fk_country,";
148 $sql .=
"fk_code_type_resource,";
149 $sql .=
"note_public,";
150 $sql .=
"note_private";
151 $sql .=
") VALUES (";
152 $sql .= $conf->entity.
", ";
153 $sql .=
" ".(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
",";
155 $sql .=
" ".($this->country_id > 0 ? $this->country_id :
'null').
",";
156 $sql .=
" ".(!isset($this->fk_code_type_resource) ?
'NULL' :
"'".$this->db->escape($this->fk_code_type_resource).
"'").
",";
157 $sql .=
" ".(!isset($this->note_public) ?
'NULL' :
"'".$this->db->escape($this->note_public).
"'").
",";
158 $sql .=
" ".(!isset($this->note_private) ?
'NULL' :
"'".$this->db->escape($this->note_private).
"'");
163 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
164 $resql = $this->db->query($sql);
167 $this->errors[] =
"Error ".$this->db->lasterror();
171 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
186 if (!$error && !$notrigger) {
188 $result = $this->
call_trigger(
'RESOURCE_CREATE', $user);
197 foreach ($this->errors as $errmsg) {
198 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
199 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
201 $this->db->rollback();
216 public function fetch($id, $ref =
'')
221 $sql .=
" t.entity,";
223 $sql .=
" t.description,";
224 $sql .=
" t.fk_country,";
225 $sql .=
" t.fk_code_type_resource,";
226 $sql .=
" t.note_public,";
227 $sql .=
" t.note_private,";
229 $sql .=
" ty.label as type_label";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
231 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
233 $sql .=
" WHERE t.rowid = ".((int) $id);
235 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
238 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
239 $resql = $this->db->query($sql);
241 if ($this->db->num_rows($resql)) {
242 $obj = $this->db->fetch_object($resql);
244 $this->
id = $obj->rowid;
245 $this->entity = $obj->entity;
246 $this->
ref = $obj->ref;
248 $this->country_id = $obj->fk_country;
249 $this->fk_code_type_resource = $obj->fk_code_type_resource;
250 $this->note_public = $obj->note_public;
251 $this->note_private = $obj->note_private;
252 $this->type_label = $obj->type_label;
258 $this->db->free($resql);
262 $this->error =
"Error ".$this->db->lasterror();
263 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
276 public function update($user =
null, $notrigger = 0)
278 global $conf, $langs, $hookmanager;
282 if (isset($this->
ref)) {
283 $this->
ref = trim($this->
ref);
285 if (isset($this->fk_code_type_resource)) {
286 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
291 if (!is_numeric($this->country_id)) {
292 $this->country_id = 0;
296 if (empty($this->oldcopy)) {
301 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
302 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
303 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
304 $sql .=
" fk_country=".($this->country_id > 0 ? $this->country_id :
"null").
",";
305 $sql .=
" fk_code_type_resource=".(isset($this->fk_code_type_resource) ?
"'".$this->db->escape($this->fk_code_type_resource).
"'" :
"null").
",";
306 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
307 $sql .=
" WHERE rowid=".((int) $this->
id);
311 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
312 $resql = $this->db->query($sql);
315 $this->errors[] =
"Error ".$this->db->lasterror();
321 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
329 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
331 if (!empty($conf->resource->dir_output)) {
334 if (file_exists($olddir)) {
335 $res = @rename($olddir, $newdir);
337 $langs->load(
"errors");
338 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
359 foreach ($this->errors as $errmsg) {
360 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
361 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
363 $this->db->rollback();
383 $sql .=
" t.resource_id,";
384 $sql .=
" t.resource_type,";
385 $sql .=
" t.element_id,";
386 $sql .=
" t.element_type,";
388 $sql .=
" t.mandatory,";
389 $sql .=
" t.fk_user_create,";
391 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_resources as t";
392 $sql .=
" WHERE t.rowid = ".((int) $id);
394 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
395 $resql = $this->db->query($sql);
397 if ($this->db->num_rows($resql)) {
398 $obj = $this->db->fetch_object($resql);
400 $this->
id = $obj->rowid;
401 $this->resource_id = $obj->resource_id;
402 $this->resource_type = $obj->resource_type;
403 $this->element_id = $obj->element_id;
404 $this->element_type = $obj->element_type;
405 $this->busy = $obj->busy;
406 $this->mandatory = $obj->mandatory;
407 $this->fk_user_create = $obj->fk_user_create;
412 if ($obj->element_id && $obj->element_type) {
416 $this->db->free($resql);
420 $this->error =
"Error ".$this->db->lasterror();
432 public function delete($rowid, $notrigger = 0)
434 global $user, $langs, $conf;
435 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
441 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
442 $sql .=
" WHERE rowid = ".((int) $rowid);
445 if ($this->db->query($sql)) {
446 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_resources";
447 $sql .=
" WHERE element_type='resource' AND resource_id = ".((int) $rowid);
448 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
449 $resql = $this->db->query($sql);
451 $this->error = $this->db->lasterror();
455 $this->error = $this->db->lasterror();
464 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
470 $result = $this->
call_trigger(
'RESOURCE_DELETE', $user);
480 if (!empty($conf->resource->dir_output)) {
482 if (file_exists($dir)) {
485 $this->errors[] =
'ErrorFailToDeleteDir';
496 $this->db->rollback();
512 public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter =
'')
515 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
520 $sql .=
" t.entity,";
522 $sql .=
" t.description,";
523 $sql .=
" t.fk_country,";
524 $sql .=
" t.fk_code_type_resource,";
527 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'label'])) {
528 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
529 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
"ef.".$key.
" as options_".$key.
', ' :
'');
532 $sql .=
" ty.label as type_label";
533 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
534 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
535 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$this->table_element.
"_extrafields as ef ON ef.fk_object=t.rowid";
536 $sql .=
" WHERE t.entity IN (".getEntity(
'resource').
")";
538 if (!empty($filter)) {
539 foreach ($filter as $key => $value) {
540 if (strpos($key,
'date')) {
541 $sql .=
" AND ".$key.
" = '".$this->db->idate($value).
"'";
542 } elseif (strpos($key,
'ef.') !==
false) {
545 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
549 $sql .= $this->db->order($sortfield, $sortorder);
551 $sql .= $this->db->plimit($limit, $offset);
554 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
556 $this->lines = array();
557 $resql = $this->db->query($sql);
559 $num = $this->db->num_rows($resql);
561 while ($obj = $this->db->fetch_object($resql)) {
563 $line->id = $obj->rowid;
564 $line->ref = $obj->ref;
565 $line->description = $obj->description;
566 $line->country_id = $obj->fk_country;
567 $line->fk_code_type_resource = $obj->fk_code_type_resource;
568 $line->type_label = $obj->type_label;
572 $line->fetch_optionals();
574 $this->lines[] = $line;
576 $this->db->free($resql);
580 $this->error = $this->db->lasterror();
596 global $conf, $langs;
600 if (isset($this->resource_id)) {
601 $this->resource_id = trim($this->resource_id);
603 if (isset($this->resource_type)) {
604 $this->resource_type = trim($this->resource_type);
606 if (isset($this->element_id)) {
607 $this->element_id = trim($this->element_id);
609 if (isset($this->element_type)) {
610 $this->element_type = trim($this->element_type);
612 if (isset($this->busy)) {
613 $this->busy = trim($this->busy);
615 if (isset($this->mandatory)) {
616 $this->mandatory = trim($this->mandatory);
620 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_resources SET";
621 $sql .=
" resource_id=".(isset($this->resource_id) ?
"'".$this->db->escape($this->resource_id).
"'" :
"null").
",";
622 $sql .=
" resource_type=".(isset($this->resource_type) ?
"'".$this->db->escape($this->resource_type).
"'" :
"null").
",";
623 $sql .=
" element_id=".(isset($this->element_id) ? $this->element_id :
"null").
",";
624 $sql .=
" element_type=".(isset($this->element_type) ?
"'".$this->db->escape($this->element_type).
"'" :
"null").
",";
625 $sql .=
" busy=".(isset($this->busy) ? $this->busy :
"null").
",";
626 $sql .=
" mandatory=".(isset($this->mandatory) ? $this->mandatory :
"null").
",";
627 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
629 $sql .=
" WHERE rowid=".((int) $this->
id);
633 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
634 $resql = $this->db->query($sql);
637 $this->errors[] =
"Error ".$this->db->lasterror();
643 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
653 foreach ($this->errors as $errmsg) {
654 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
655 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
657 $this->db->rollback();
676 $resources = array();
679 $sql =
'SELECT rowid, resource_id, resource_type, busy, mandatory';
680 $sql .=
' FROM '.MAIN_DB_PREFIX.
'element_resources';
681 $sql .=
" WHERE element_id=".((int) $element_id).
" AND element_type='".$this->db->escape($element).
"'";
682 if ($resource_type) {
683 $sql .=
" AND resource_type LIKE '%".$this->db->escape($resource_type).
"%'";
685 $sql .=
' ORDER BY resource_type';
687 dol_syslog(get_class($this).
"::getElementResources", LOG_DEBUG);
689 $resources = array();
690 $resql = $this->db->query($sql);
692 $num = $this->db->num_rows($resql);
695 $obj = $this->db->fetch_object($resql);
697 $resources[$i] = array(
698 'rowid' => $obj->rowid,
699 'resource_id' => $obj->resource_id,
700 'resource_type'=>$obj->resource_type,
702 'mandatory'=>$obj->mandatory
722 foreach ($resources as $nb => $resource) {
741 if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
745 $sql =
"SELECT rowid, code, label, active";
746 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_resource";
747 $sql .=
" WHERE active > 0";
748 $sql .=
" ORDER BY rowid";
749 dol_syslog(get_class($this).
"::load_cache_code_type_resource", LOG_DEBUG);
750 $resql = $this->db->query($sql);
752 $num = $this->db->num_rows($resql);
755 $obj = $this->db->fetch_object($resql);
757 $label = ($langs->trans(
"ResourceTypeShort".$obj->code) !=
"ResourceTypeShort".$obj->code ? $langs->trans(
"ResourceTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
758 $this->cache_code_type_resource[$obj->rowid][
'code'] = $obj->code;
759 $this->cache_code_type_resource[$obj->rowid][
'label'] = $label;
760 $this->cache_code_type_resource[$obj->rowid][
'active'] = $obj->active;
781 $langs->load(
'resource');
785 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Resource").
'</u>';
786 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
790 if (isset($this->type_label)) {
791 $datas[
'label'] =
'<br><b>'.$langs->trans(
"ResourceType").
":</b> ".$this->type_label;
808 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
810 global $conf, $langs, $hookmanager;
815 'objecttype' => $this->element,
817 $classfortooltip =
'classfortooltip';
820 $classfortooltip =
'classforajaxtooltip';
821 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
827 $url = DOL_URL_ROOT.
'/resource/card.php?id='.$this->id;
829 if ($option !=
'nolink') {
831 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
832 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
833 $add_save_lastsearch_values = 1;
835 if ($add_save_lastsearch_values) {
836 $url .=
'&save_lastsearch_values=1';
841 if (empty($notooltip)) {
843 $label = $langs->trans(
"ShowMyObject");
844 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
846 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
847 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
849 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
852 $linkstart =
'<a href="'.$url.$get_params.
'"';
853 $linkstart .= $linkclose.
'>';
858 $result .= $linkstart;
860 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
862 if ($withpicto != 2) {
863 $result .= $this->ref;
868 $hookmanager->initHooks(array($this->element .
'dao'));
869 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
870 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
872 $result = $hookmanager->resPrint;
874 $result .= $hookmanager->resPrint;
916 $sql =
"SELECT count(r.rowid) as nb";
917 $sql .=
" FROM ".MAIN_DB_PREFIX.
"resource as r";
918 $sql .=
" WHERE r.entity IN (".getEntity(
'resource').
")";
920 $resql = $this->db->query($sql);
922 while ($obj = $this->db->fetch_object($resql)) {
923 $this->nb[
"dolresource"] = $obj->nb;
925 $this->db->free($resql);
929 $this->error = $this->db->error();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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 resource links in memory from database.
$objelement
Used by fetch_element_resource() to return an object.
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 a 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.