24 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
25 require_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;
66 public $resource_type;
74 public $fk_user_create;
80 public $cache_code_type_resource = array();
105 public function create($user, $notrigger = 0)
107 global $conf, $langs, $hookmanager;
112 if (isset($this->
ref)) {
113 $this->
ref = trim($this->
ref);
118 if (!is_numeric($this->country_id)) {
119 $this->country_id = 0;
121 if (isset($this->fk_code_type_resource)) {
122 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
124 if (isset($this->note_public)) {
125 $this->note_public = trim($this->note_public);
127 if (isset($this->note_private)) {
128 $this->note_private = trim($this->note_private);
133 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
136 $sql .=
"description,";
137 $sql .=
"fk_country,";
138 $sql .=
"fk_code_type_resource,";
139 $sql .=
"note_public,";
140 $sql .=
"note_private";
141 $sql .=
") VALUES (";
142 $sql .= $conf->entity.
", ";
143 $sql .=
" ".(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
",";
145 $sql .=
" ".($this->country_id > 0 ? $this->country_id :
'null').
",";
146 $sql .=
" ".(!isset($this->fk_code_type_resource) ?
'NULL' :
"'".$this->db->escape($this->fk_code_type_resource).
"'").
",";
147 $sql .=
" ".(!isset($this->note_public) ?
'NULL' :
"'".$this->db->escape($this->note_public).
"'").
",";
148 $sql .=
" ".(!isset($this->note_private) ?
'NULL' :
"'".$this->db->escape($this->note_private).
"'");
153 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
156 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
160 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
175 if (!$error && !$notrigger) {
177 $result = $this->
call_trigger(
'RESOURCE_CREATE', $user);
186 foreach ($this->errors as $errmsg) {
187 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
188 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
190 $this->
db->rollback();
205 public function fetch($id, $ref =
'')
210 $sql .=
" t.entity,";
212 $sql .=
" t.description,";
213 $sql .=
" t.fk_country,";
214 $sql .=
" t.fk_code_type_resource,";
215 $sql .=
" t.note_public,";
216 $sql .=
" t.note_private,";
218 $sql .=
" ty.label as type_label";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
220 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
222 $sql .=
" WHERE t.rowid = ".((int) $id);
224 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
227 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
231 $obj = $this->
db->fetch_object(
$resql);
233 $this->
id = $obj->rowid;
234 $this->entity = $obj->entity;
235 $this->
ref = $obj->ref;
237 $this->country_id = $obj->fk_country;
238 $this->fk_code_type_resource = $obj->fk_code_type_resource;
239 $this->note_public = $obj->note_public;
240 $this->note_private = $obj->note_private;
241 $this->type_label = $obj->type_label;
251 $this->error =
"Error ".$this->db->lasterror();
252 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
265 public function update($user =
null, $notrigger = 0)
267 global $conf, $langs, $hookmanager;
271 if (isset($this->
ref)) {
272 $this->
ref = trim($this->
ref);
274 if (isset($this->fk_code_type_resource)) {
275 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
280 if (!is_numeric($this->country_id)) {
281 $this->country_id = 0;
285 if (empty($this->oldcopy)) {
290 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
291 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
292 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
293 $sql .=
" fk_country=".($this->country_id > 0 ? $this->country_id :
"null").
",";
294 $sql .=
" fk_code_type_resource=".(isset($this->fk_code_type_resource) ?
"'".$this->db->escape($this->fk_code_type_resource).
"'" :
"null").
",";
295 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
296 $sql .=
" WHERE rowid=".((int) $this->
id);
300 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
303 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
309 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
317 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
319 if (!empty($conf->resource->dir_output)) {
322 if (file_exists($olddir)) {
323 $res = @rename($olddir, $newdir);
325 $langs->load(
"errors");
326 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
347 foreach ($this->errors as $errmsg) {
348 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
349 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
351 $this->
db->rollback();
372 $sql .=
" t.resource_id,";
373 $sql .=
" t.resource_type,";
374 $sql .=
" t.element_id,";
375 $sql .=
" t.element_type,";
377 $sql .=
" t.mandatory,";
378 $sql .=
" t.fk_user_create,";
380 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_resources as t";
381 $sql .=
" WHERE t.rowid = ".((int) $id);
383 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
387 $obj = $this->
db->fetch_object(
$resql);
389 $this->
id = $obj->rowid;
390 $this->resource_id = $obj->resource_id;
391 $this->resource_type = $obj->resource_type;
392 $this->element_id = $obj->element_id;
393 $this->element_type = $obj->element_type;
394 $this->busy = $obj->busy;
395 $this->mandatory = $obj->mandatory;
396 $this->fk_user_create = $obj->fk_user_create;
398 if ($obj->resource_id && $obj->resource_type) {
401 if ($obj->element_id && $obj->element_type) {
409 $this->error =
"Error ".$this->db->lasterror();
421 public function delete($rowid, $notrigger = 0)
423 global $user, $langs, $conf;
424 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
430 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
431 $sql .=
" WHERE rowid = ".((int) $rowid);
434 if ($this->
db->query($sql)) {
435 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_resources";
436 $sql .=
" WHERE element_type='resource' AND resource_id = ".((int) $rowid);
437 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
440 $this->error = $this->
db->lasterror();
444 $this->error = $this->
db->lasterror();
453 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
459 $result = $this->
call_trigger(
'RESOURCE_DELETE', $user);
469 if (!empty($conf->resource->dir_output)) {
471 if (file_exists($dir)) {
474 $this->errors[] =
'ErrorFailToDeleteDir';
485 $this->
db->rollback();
501 public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter =
'')
506 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
511 $sql .=
" t.entity,";
513 $sql .=
" t.description,";
514 $sql .=
" t.fk_country,";
515 $sql .=
" t.fk_code_type_resource,";
518 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'label'])) {
519 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
520 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
"ef.".$key.
" as options_".$key.
', ' :
'');
523 $sql .=
" ty.label as type_label";
524 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
525 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_resource as ty ON ty.code=t.fk_code_type_resource";
526 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$this->table_element.
"_extrafields as ef ON ef.fk_object=t.rowid";
527 $sql .=
" WHERE t.entity IN (".getEntity(
'resource').
")";
529 if (!empty($filter)) {
530 foreach ($filter as $key => $value) {
531 if (strpos($key,
'date')) {
532 $sql .=
" AND ".$key.
" = '".$this->
db->idate($value).
"'";
533 } elseif (strpos($key,
'ef.') !==
false) {
536 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
540 $sql .= $this->
db->order($sortfield, $sortorder);
542 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
543 $result = $this->
db->query($sql);
544 $this->num_all = $this->
db->num_rows($result);
547 $sql .= $this->
db->plimit($limit, $offset);
549 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
551 $this->lines = array();
556 while ($obj = $this->
db->fetch_object(
$resql)) {
558 $line->id = $obj->rowid;
559 $line->ref = $obj->ref;
560 $line->description = $obj->description;
561 $line->country_id = $obj->fk_country;
562 $line->fk_code_type_resource = $obj->fk_code_type_resource;
563 $line->type_label = $obj->type_label;
567 $line->fetch_optionals();
569 $this->lines[] = $line;
575 $this->error = $this->
db->lasterror();
591 global $conf, $langs;
595 if (isset($this->resource_id)) {
596 $this->resource_id = trim($this->resource_id);
598 if (isset($this->resource_type)) {
599 $this->resource_type = trim($this->resource_type);
601 if (isset($this->element_id)) {
602 $this->element_id = trim($this->element_id);
604 if (isset($this->element_type)) {
605 $this->element_type = trim($this->element_type);
607 if (isset($this->busy)) {
608 $this->busy = trim($this->busy);
610 if (isset($this->mandatory)) {
611 $this->mandatory = trim($this->mandatory);
615 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"element_resources SET";
616 $sql .=
" resource_id=".(isset($this->resource_id) ?
"'".$this->db->escape($this->resource_id).
"'" :
"null").
",";
617 $sql .=
" resource_type=".(isset($this->resource_type) ?
"'".$this->db->escape($this->resource_type).
"'" :
"null").
",";
618 $sql .=
" element_id=".(isset($this->element_id) ? $this->element_id :
"null").
",";
619 $sql .=
" element_type=".(isset($this->element_type) ?
"'".$this->db->escape($this->element_type).
"'" :
"null").
",";
620 $sql .=
" busy=".(isset($this->busy) ? $this->busy :
"null").
",";
621 $sql .=
" mandatory=".(isset($this->mandatory) ? $this->mandatory :
"null").
",";
622 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null');
624 $sql .=
" WHERE rowid=".((int) $this->
id);
628 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
631 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
637 $result = $this->
call_trigger(
'RESOURCE_MODIFY', $user);
647 foreach ($this->errors as $errmsg) {
648 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
649 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
651 $this->
db->rollback();
670 $resources = array();
673 $sql =
'SELECT rowid, resource_id, resource_type, busy, mandatory';
674 $sql .=
' FROM '.MAIN_DB_PREFIX.
'element_resources';
675 $sql .=
" WHERE element_id=".((int) $element_id).
" AND element_type='".$this->
db->escape($element).
"'";
676 if ($resource_type) {
677 $sql .=
" AND resource_type LIKE '%".$this->db->escape($resource_type).
"%'";
679 $sql .=
' ORDER BY resource_type';
681 dol_syslog(get_class($this).
"::getElementResources", LOG_DEBUG);
683 $resources = array();
689 $obj = $this->
db->fetch_object(
$resql);
691 $resources[$i] = array(
692 'rowid' => $obj->rowid,
693 'resource_id' => $obj->resource_id,
694 'resource_type'=>$obj->resource_type,
696 'mandatory'=>$obj->mandatory
716 foreach ($resources as $nb => $resource) {
735 if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
739 $sql =
"SELECT rowid, code, label, active";
740 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_resource";
741 $sql .=
" WHERE active > 0";
742 $sql .=
" ORDER BY rowid";
743 dol_syslog(get_class($this).
"::load_cache_code_type_resource", LOG_DEBUG);
749 $obj = $this->
db->fetch_object(
$resql);
751 $label = ($langs->trans(
"ResourceTypeShort".$obj->code) != (
"ResourceTypeShort".$obj->code) ? $langs->trans(
"ResourceTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
752 $this->cache_code_type_resource[$obj->rowid][
'code'] = $obj->code;
753 $this->cache_code_type_resource[$obj->rowid][
'label'] = $label;
754 $this->cache_code_type_resource[$obj->rowid][
'active'] = $obj->active;
775 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
777 global $conf, $langs, $hookmanager;
780 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Resource").
'</u>';
782 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
786 if (isset($this->type_label)) {
787 $label .=
'<br><b>'.$langs->trans(
"ResourceType").
":</b> ".$this->type_label;
790 $url = DOL_URL_ROOT.
'/resource/card.php?id='.$this->id;
792 if ($option !=
'nolink') {
794 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
795 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
796 $add_save_lastsearch_values = 1;
798 if ($add_save_lastsearch_values) {
799 $url .=
'&save_lastsearch_values=1';
804 if (empty($notooltip)) {
805 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
806 $label = $langs->trans(
"ShowMyObject");
807 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
809 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
810 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
812 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
815 $linkstart =
'<a href="'.$url.$get_params.
'"';
816 $linkstart .= $linkclose.
'>';
821 $result .= $linkstart;
823 $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);
825 if ($withpicto != 2) {
826 $result .= $this->ref;
831 $hookmanager->initHooks(array($this->element .
'dao'));
832 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
833 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
835 $result = $hookmanager->resPrint;
837 $result .= $hookmanager->resPrint;
851 return $this->
LibStatut($this->status, $mode);
883 $sql =
"SELECT count(r.rowid) as nb";
884 $sql .=
" FROM ".MAIN_DB_PREFIX.
"resource as r";
885 $sql .=
" WHERE r.entity IN (".getEntity(
'resource').
")";
889 while ($obj = $this->
db->fetch_object(
$resql)) {
890 $this->nb[
"dolresource"] = $obj->nb;
896 $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.
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)
Retourne le libelle du status d'un user (actif, inactif)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid 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)
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.
$conf db
API class for accounts.