dolibarr  18.0.0-beta
dolresource.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
25 require_once DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php";
26 
31 {
35  public $element = 'dolresource';
36 
40  public $table_element = 'resource';
41 
45  public $picto = 'resource';
46 
47 
51  public $fk_code_type_resource;
52 
53  public $type_label;
54 
58  public $description;
59 
60  public $fk_country;
61 
62 
63  // Variable for a link of resource
64 
68  public $resource_id;
69  public $resource_type;
70  public $element_id;
71  public $element_type;
72  public $busy;
73  public $mandatory;
77  public $fk_user_create;
78  public $tms = '';
79 
83  public $cache_code_type_resource = array();
84 
88  public $oldcopy;
89 
90 
96  public function __construct($db)
97  {
98  $this->db = $db;
99  }
100 
108  public function create($user, $notrigger = 0)
109  {
110  global $conf, $langs, $hookmanager;
111  $error = 0;
112 
113  // Clean parameters
114 
115  if (isset($this->ref)) {
116  $this->ref = trim($this->ref);
117  }
118  if (isset($this->description)) {
119  $this->description = trim($this->description);
120  }
121  if (!is_numeric($this->country_id)) {
122  $this->country_id = 0;
123  }
124  if (isset($this->fk_code_type_resource)) {
125  $this->fk_code_type_resource = trim($this->fk_code_type_resource);
126  }
127  if (isset($this->note_public)) {
128  $this->note_public = trim($this->note_public);
129  }
130  if (isset($this->note_private)) {
131  $this->note_private = trim($this->note_private);
132  }
133 
134 
135  // Insert request
136  $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
137  $sql .= "entity,";
138  $sql .= "ref,";
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)."'").",";
147  $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
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)."'");
152  $sql .= ")";
153 
154  $this->db->begin();
155 
156  dol_syslog(get_class($this)."::create", LOG_DEBUG);
157  $resql = $this->db->query($sql);
158  if (!$resql) {
159  $error++; $this->errors[] = "Error ".$this->db->lasterror();
160  }
161 
162  if (!$error) {
163  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
164  }
165 
166  if (!$error) {
167  $action = 'create';
168 
169  // Actions on extra fields
170  if (!$error) {
171  $result = $this->insertExtraFields();
172  if ($result < 0) {
173  $error++;
174  }
175  }
176  }
177 
178  if (!$error && !$notrigger) {
179  // Call trigger
180  $result = $this->call_trigger('RESOURCE_CREATE', $user);
181  if ($result < 0) {
182  $error++;
183  }
184  // End call triggers
185  }
186 
187  // Commit or rollback
188  if ($error) {
189  foreach ($this->errors as $errmsg) {
190  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
191  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
192  }
193  $this->db->rollback();
194  return -1 * $error;
195  } else {
196  $this->db->commit();
197  return $this->id;
198  }
199  }
200 
208  public function fetch($id, $ref = '')
209  {
210  global $langs;
211  $sql = "SELECT";
212  $sql .= " t.rowid,";
213  $sql .= " t.entity,";
214  $sql .= " t.ref,";
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,";
220  $sql .= " t.tms,";
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";
224  if ($id) {
225  $sql .= " WHERE t.rowid = ".((int) $id);
226  } else {
227  $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
228  }
229 
230  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
231  $resql = $this->db->query($sql);
232  if ($resql) {
233  if ($this->db->num_rows($resql)) {
234  $obj = $this->db->fetch_object($resql);
235 
236  $this->id = $obj->rowid;
237  $this->entity = $obj->entity;
238  $this->ref = $obj->ref;
239  $this->description = $obj->description;
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;
245 
246  // Retrieve all extrafield
247  // fetch optionals attributes and labels
248  $this->fetch_optionals();
249  }
250  $this->db->free($resql);
251 
252  return $this->id;
253  } else {
254  $this->error = "Error ".$this->db->lasterror();
255  dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
256  return -1;
257  }
258  }
259 
260 
268  public function update($user = null, $notrigger = 0)
269  {
270  global $conf, $langs, $hookmanager;
271  $error = 0;
272 
273  // Clean parameters
274  if (isset($this->ref)) {
275  $this->ref = trim($this->ref);
276  }
277  if (isset($this->fk_code_type_resource)) {
278  $this->fk_code_type_resource = trim($this->fk_code_type_resource);
279  }
280  if (isset($this->description)) {
281  $this->description = trim($this->description);
282  }
283  if (!is_numeric($this->country_id)) {
284  $this->country_id = 0;
285  }
286 
287  // $this->oldcopy should have been set by the caller of update (here properties were already modified)
288  if (empty($this->oldcopy)) {
289  $this->oldcopy = dol_clone($this);
290  }
291 
292  // Update request
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);
300 
301  $this->db->begin();
302 
303  dol_syslog(get_class($this)."::update", LOG_DEBUG);
304  $resql = $this->db->query($sql);
305  if (!$resql) {
306  $error++; $this->errors[] = "Error ".$this->db->lasterror();
307  }
308 
309  if (!$error) {
310  if (!$notrigger) {
311  // Call trigger
312  $result = $this->call_trigger('RESOURCE_MODIFY', $user);
313  if ($result < 0) {
314  $error++;
315  }
316  // End call triggers
317  }
318  }
319 
320  if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
321  // We remove directory
322  if (!empty($conf->resource->dir_output)) {
323  $olddir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
324  $newdir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
325  if (file_exists($olddir)) {
326  $res = @rename($olddir, $newdir);
327  if (!$res) {
328  $langs->load("errors");
329  $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
330  $error++;
331  }
332  }
333  }
334  }
335 
336  if (!$error) {
337  $action = 'update';
338 
339  // Actions on extra fields
340  if (!$error) {
341  $result = $this->insertExtraFields();
342  if ($result < 0) {
343  $error++;
344  }
345  }
346  }
347 
348  // Commit or rollback
349  if ($error) {
350  foreach ($this->errors as $errmsg) {
351  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
352  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
353  }
354  $this->db->rollback();
355  return -1 * $error;
356  } else {
357  $this->db->commit();
358  return 1;
359  }
360  }
361 
362  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
369  public function fetch_element_resource($id)
370  {
371  // phpcs:enable
372  global $langs;
373  $sql = "SELECT";
374  $sql .= " t.rowid,";
375  $sql .= " t.resource_id,";
376  $sql .= " t.resource_type,";
377  $sql .= " t.element_id,";
378  $sql .= " t.element_type,";
379  $sql .= " t.busy,";
380  $sql .= " t.mandatory,";
381  $sql .= " t.fk_user_create,";
382  $sql .= " t.tms";
383  $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as t";
384  $sql .= " WHERE t.rowid = ".((int) $id);
385 
386  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
387  $resql = $this->db->query($sql);
388  if ($resql) {
389  if ($this->db->num_rows($resql)) {
390  $obj = $this->db->fetch_object($resql);
391 
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;
400 
401  if ($obj->resource_id && $obj->resource_type) {
402  $this->objresource = fetchObjectByElement($obj->resource_id, $obj->resource_type);
403  }
404  if ($obj->element_id && $obj->element_type) {
405  $this->objelement = fetchObjectByElement($obj->element_id, $obj->element_type);
406  }
407  }
408  $this->db->free($resql);
409 
410  return $this->id;
411  } else {
412  $this->error = "Error ".$this->db->lasterror();
413  return -1;
414  }
415  }
416 
424  public function delete($rowid, $notrigger = 0)
425  {
426  global $user, $langs, $conf;
427  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
428 
429  $error = 0;
430 
431  $this->db->begin();
432 
433  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
434  $sql .= " WHERE rowid = ".((int) $rowid);
435 
436  dol_syslog(get_class($this), LOG_DEBUG);
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);
442  if (!$resql) {
443  $this->error = $this->db->lasterror();
444  $error++;
445  }
446  } else {
447  $this->error = $this->db->lasterror();
448  $error++;
449  }
450 
451  // Removed extrafields
452  if (!$error) {
453  $result = $this->deleteExtraFields();
454  if ($result < 0) {
455  $error++;
456  dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
457  }
458  }
459 
460  if (!$notrigger) {
461  // Call trigger
462  $result = $this->call_trigger('RESOURCE_DELETE', $user);
463  if ($result < 0) {
464  $error++;
465  }
466  // End call triggers
467  }
468 
469  if (!$error) {
470  // We remove directory
471  $ref = dol_sanitizeFileName($this->ref);
472  if (!empty($conf->resource->dir_output)) {
473  $dir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
474  if (file_exists($dir)) {
475  $res = @dol_delete_dir_recursive($dir);
476  if (!$res) {
477  $this->errors[] = 'ErrorFailToDeleteDir';
478  $error++;
479  }
480  }
481  }
482  }
483 
484  if (!$error) {
485  $this->db->commit();
486  return 1;
487  } else {
488  $this->db->rollback();
489  return -1;
490  }
491  }
492 
493  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
504  public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = '')
505  {
506  // phpcs:enable
507  global $conf;
508 
509  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
510  $extrafields = new ExtraFields($this->db);
511 
512  $sql = "SELECT ";
513  $sql .= " t.rowid,";
514  $sql .= " t.entity,";
515  $sql .= " t.ref,";
516  $sql .= " t.description,";
517  $sql .= " t.fk_country,";
518  $sql .= " t.fk_code_type_resource,";
519  $sql .= " t.tms,";
520  // Add fields from extrafields
521  if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element]['label'])) {
522  foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
523  $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
524  }
525  }
526  $sql .= " ty.label as type_label";
527  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
528  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
529  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$this->table_element."_extrafields as ef ON ef.fk_object=t.rowid";
530  $sql .= " WHERE t.entity IN (".getEntity('resource').")";
531  // Manage filter
532  if (!empty($filter)) {
533  foreach ($filter as $key => $value) {
534  if (strpos($key, 'date')) {
535  $sql .= " AND ".$key." = '".$this->db->idate($value)."'";
536  } elseif (strpos($key, 'ef.') !== false) {
537  $sql .= $value;
538  } else {
539  $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
540  }
541  }
542  }
543  $sql .= $this->db->order($sortfield, $sortorder);
544  $this->num_all = 0;
545  if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
546  $result = $this->db->query($sql);
547  $this->num_all = $this->db->num_rows($result);
548  }
549  if ($limit) {
550  $sql .= $this->db->plimit($limit, $offset);
551  }
552  dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
553 
554  $this->lines = array();
555  $resql = $this->db->query($sql);
556  if ($resql) {
557  $num = $this->db->num_rows($resql);
558  if ($num) {
559  while ($obj = $this->db->fetch_object($resql)) {
560  $line = new Dolresource($this->db);
561  $line->id = $obj->rowid;
562  $line->ref = $obj->ref;
563  $line->description = $obj->description;
564  $line->country_id = $obj->fk_country;
565  $line->fk_code_type_resource = $obj->fk_code_type_resource;
566  $line->type_label = $obj->type_label;
567 
568  // fetch optionals attributes and labels
569 
570  $line->fetch_optionals();
571 
572  $this->lines[] = $line;
573  }
574  $this->db->free($resql);
575  }
576  return $num;
577  } else {
578  $this->error = $this->db->lasterror();
579  return -1;
580  }
581  }
582 
583  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
591  public function update_element_resource($user = null, $notrigger = 0)
592  {
593  // phpcs:enable
594  global $conf, $langs;
595  $error = 0;
596 
597  // Clean parameters
598  if (isset($this->resource_id)) {
599  $this->resource_id = trim($this->resource_id);
600  }
601  if (isset($this->resource_type)) {
602  $this->resource_type = trim($this->resource_type);
603  }
604  if (isset($this->element_id)) {
605  $this->element_id = trim($this->element_id);
606  }
607  if (isset($this->element_type)) {
608  $this->element_type = trim($this->element_type);
609  }
610  if (isset($this->busy)) {
611  $this->busy = trim($this->busy);
612  }
613  if (isset($this->mandatory)) {
614  $this->mandatory = trim($this->mandatory);
615  }
616 
617  // Update request
618  $sql = "UPDATE ".MAIN_DB_PREFIX."element_resources SET";
619  $sql .= " resource_id=".(isset($this->resource_id) ? "'".$this->db->escape($this->resource_id)."'" : "null").",";
620  $sql .= " resource_type=".(isset($this->resource_type) ? "'".$this->db->escape($this->resource_type)."'" : "null").",";
621  $sql .= " element_id=".(isset($this->element_id) ? $this->element_id : "null").",";
622  $sql .= " element_type=".(isset($this->element_type) ? "'".$this->db->escape($this->element_type)."'" : "null").",";
623  $sql .= " busy=".(isset($this->busy) ? $this->busy : "null").",";
624  $sql .= " mandatory=".(isset($this->mandatory) ? $this->mandatory : "null").",";
625  $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null');
626 
627  $sql .= " WHERE rowid=".((int) $this->id);
628 
629  $this->db->begin();
630 
631  dol_syslog(get_class($this)."::update", LOG_DEBUG);
632  $resql = $this->db->query($sql);
633  if (!$resql) {
634  $error++; $this->errors[] = "Error ".$this->db->lasterror();
635  }
636 
637  if (!$error) {
638  if (!$notrigger) {
639  // Call trigger
640  $result = $this->call_trigger('RESOURCE_MODIFY', $user);
641  if ($result < 0) {
642  $error++;
643  }
644  // End call triggers
645  }
646  }
647 
648  // Commit or rollback
649  if ($error) {
650  foreach ($this->errors as $errmsg) {
651  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
652  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
653  }
654  $this->db->rollback();
655  return -1 * $error;
656  } else {
657  $this->db->commit();
658  return 1;
659  }
660  }
661 
662 
671  public function getElementResources($element, $element_id, $resource_type = '')
672  {
673  $resources = array();
674 
675  // Links beetween objects are stored in this table
676  $sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
677  $sql .= ' FROM '.MAIN_DB_PREFIX.'element_resources';
678  $sql .= " WHERE element_id=".((int) $element_id)." AND element_type='".$this->db->escape($element)."'";
679  if ($resource_type) {
680  $sql .= " AND resource_type LIKE '%".$this->db->escape($resource_type)."%'";
681  }
682  $sql .= ' ORDER BY resource_type';
683 
684  dol_syslog(get_class($this)."::getElementResources", LOG_DEBUG);
685 
686  $resources = array();
687  $resql = $this->db->query($sql);
688  if ($resql) {
689  $num = $this->db->num_rows($resql);
690  $i = 0;
691  while ($i < $num) {
692  $obj = $this->db->fetch_object($resql);
693 
694  $resources[$i] = array(
695  'rowid' => $obj->rowid,
696  'resource_id' => $obj->resource_id,
697  'resource_type'=>$obj->resource_type,
698  'busy'=>$obj->busy,
699  'mandatory'=>$obj->mandatory
700  );
701  $i++;
702  }
703  }
704 
705  return $resources;
706  }
707 
715  public function fetchElementResources($element, $element_id)
716  {
717  $resources = $this->getElementResources($element, $element_id);
718  $i = 0;
719  foreach ($resources as $nb => $resource) {
720  $this->lines[$i] = fetchObjectByElement($resource['resource_id'], $resource['resource_type']);
721  $i++;
722  }
723  return $i;
724  }
725 
726 
727  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
734  {
735  // phpcs:enable
736  global $langs;
737 
738  if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
739  return 0; // Cache deja charge
740  }
741 
742  $sql = "SELECT rowid, code, label, active";
743  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_resource";
744  $sql .= " WHERE active > 0";
745  $sql .= " ORDER BY rowid";
746  dol_syslog(get_class($this)."::load_cache_code_type_resource", LOG_DEBUG);
747  $resql = $this->db->query($sql);
748  if ($resql) {
749  $num = $this->db->num_rows($resql);
750  $i = 0;
751  while ($i < $num) {
752  $obj = $this->db->fetch_object($resql);
753 
754  $label = ($langs->trans("ResourceTypeShort".$obj->code) != ("ResourceTypeShort".$obj->code) ? $langs->trans("ResourceTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
755  $this->cache_code_type_resource[$obj->rowid]['code'] = $obj->code;
756  $this->cache_code_type_resource[$obj->rowid]['label'] = $label;
757  $this->cache_code_type_resource[$obj->rowid]['active'] = $obj->active;
758  $i++;
759  }
760  return $num;
761  } else {
762  dol_print_error($this->db);
763  return -1;
764  }
765  }
766 
774  public function getTooltipContentArray($params)
775  {
776  global $conf, $langs;
777 
778  $langs->load('resource');
779 
780  $datas = [];
781 
782  $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Resource").'</u>';
783  $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
784  /*if (isset($this->status)) {
785  $datas['status'] = '<br><b>' . $langs->trans("Status").":</b> ".$this->getLibStatut(5);
786  }*/
787  if (isset($this->type_label)) {
788  $datas['label'] = '<br><b>'.$langs->trans("ResourceType").":</b> ".$this->type_label;
789  }
790 
791  return $datas;
792  }
793 
805  public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
806  {
807  global $conf, $langs, $hookmanager;
808 
809  $result = '';
810  $params = [
811  'id' => $this->id,
812  'objecttype' => $this->element,
813  ];
814  $classfortooltip = 'classfortooltip';
815  $dataparams = '';
816  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
817  $classfortooltip = 'classforajaxtooltip';
818  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
819  $label = '';
820  } else {
821  $label = implode($this->getTooltipContentArray($params));
822  }
823 
824  $url = DOL_URL_ROOT.'/resource/card.php?id='.$this->id;
825 
826  if ($option != 'nolink') {
827  // Add param to save lastsearch_values or not
828  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
829  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
830  $add_save_lastsearch_values = 1;
831  }
832  if ($add_save_lastsearch_values) {
833  $url .= '&save_lastsearch_values=1';
834  }
835  }
836 
837  $linkclose = '';
838  if (empty($notooltip)) {
839  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
840  $label = $langs->trans("ShowMyObject");
841  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
842  }
843  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
844  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
845  } else {
846  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
847  }
848 
849  $linkstart = '<a href="'.$url.$get_params.'"';
850  $linkstart .= $linkclose.'>';
851  $linkend = '</a>';
852  /*$linkstart = '<a href="'.DOL_URL_ROOT.'/resource/card.php?id='.$this->id.$get_params.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
853  $linkend = '</a>';*/
854 
855  $result .= $linkstart;
856  if ($withpicto) {
857  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
858  }
859  if ($withpicto != 2) {
860  $result .= $this->ref;
861  }
862  $result .= $linkend;
863 
864  global $action;
865  $hookmanager->initHooks(array($this->element . 'dao'));
866  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
867  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
868  if ($reshook > 0) {
869  $result = $hookmanager->resPrint;
870  } else {
871  $result .= $hookmanager->resPrint;
872  }
873  return $result;
874  }
875 
876 
883  public function getLibStatut($mode = 0)
884  {
885  return $this->LibStatut($this->status, $mode);
886  }
887 
888  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
896  public static function LibStatut($status, $mode = 0)
897  {
898  // phpcs:enable
899  global $langs;
900 
901  return '';
902  }
903 
904  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
910  public function load_state_board()
911  {
912  // phpcs:enable
913  global $conf;
914 
915  $this->nb = array();
916 
917  $sql = "SELECT count(r.rowid) as nb";
918  $sql .= " FROM ".MAIN_DB_PREFIX."resource as r";
919  $sql .= " WHERE r.entity IN (".getEntity('resource').")";
920 
921  $resql = $this->db->query($sql);
922  if ($resql) {
923  while ($obj = $this->db->fetch_object($resql)) {
924  $this->nb["dolresource"] = $obj->nb;
925  }
926  $this->db->free($resql);
927  return 1;
928  } else {
929  dol_print_error($this->db);
930  $this->error = $this->db->error();
931  return -1;
932  }
933  }
934 }
Dolresource\update_element_resource
update_element_resource($user=null, $notrigger=0)
Update element resource into database.
Definition: dolresource.class.php:591
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1322
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
dol_delete_dir_recursive
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)
Definition: files.lib.php:1483
Dolresource\fetchAll
fetchAll($sortorder, $sortfield, $limit, $offset, $filter='')
Load resource objects into $this->lines.
Definition: dolresource.class.php:504
Dolresource\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: dolresource.class.php:774
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5096
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1254
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4125
Dolresource\LibStatut
static LibStatut($status, $mode=0)
Return the status.
Definition: dolresource.class.php:896
Dolresource\create
create($user, $notrigger=0)
Create object into database.
Definition: dolresource.class.php:108
Dolresource
DAO Resource object.
Definition: dolresource.class.php:30
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6110
Dolresource\update
update($user=null, $notrigger=0)
Update object into database.
Definition: dolresource.class.php:268
Dolresource\fetchElementResources
fetchElementResources($element, $element_id)
Return an int number of resources linked to the element.
Definition: dolresource.class.php:715
$sql
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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1732
Dolresource\__construct
__construct($db)
Constructor.
Definition: dolresource.class.php:96
CommonObject\fetch_optionals
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...
Definition: commonobject.class.php:5959
ref
$object ref
Definition: info.php:78
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6070
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Dolresource\getNomUrl
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable link of object (with eventually picto)
Definition: dolresource.class.php:805
Dolresource\fetch
fetch($id, $ref='')
Load object in memory from database.
Definition: dolresource.class.php:208
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4462
Dolresource\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: dolresource.class.php:910
Dolresource\fetch_element_resource
fetch_element_resource($id)
Load data of link in memory from database.
Definition: dolresource.class.php:369
Dolresource\load_cache_code_type_resource
load_cache_code_type_resource()
Load in cache resource type code (setup in dictionary)
Definition: dolresource.class.php:733
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5743
Dolresource\getElementResources
getElementResources($element, $element_id, $resource_type='')
Return an array with resources linked to the element.
Definition: dolresource.class.php:671
Dolresource\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: dolresource.class.php:883
fetchObjectByElement
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
Definition: functions.lib.php:11567
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156