dolibarr  17.0.4
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 
55  public $description;
56 
57  public $fk_country;
58 
59 
60  // Variable for a link of resource
61 
65  public $resource_id;
66  public $resource_type;
67  public $element_id;
68  public $element_type;
69  public $busy;
70  public $mandatory;
74  public $fk_user_create;
75  public $tms = '';
76 
80  public $cache_code_type_resource = array();
81 
85  public $oldcopy;
86 
87 
93  public function __construct($db)
94  {
95  $this->db = $db;
96  }
97 
105  public function create($user, $notrigger = 0)
106  {
107  global $conf, $langs, $hookmanager;
108  $error = 0;
109 
110  // Clean parameters
111 
112  if (isset($this->ref)) {
113  $this->ref = trim($this->ref);
114  }
115  if (isset($this->description)) {
116  $this->description = trim($this->description);
117  }
118  if (!is_numeric($this->country_id)) {
119  $this->country_id = 0;
120  }
121  if (isset($this->fk_code_type_resource)) {
122  $this->fk_code_type_resource = trim($this->fk_code_type_resource);
123  }
124  if (isset($this->note_public)) {
125  $this->note_public = trim($this->note_public);
126  }
127  if (isset($this->note_private)) {
128  $this->note_private = trim($this->note_private);
129  }
130 
131 
132  // Insert request
133  $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
134  $sql .= "entity,";
135  $sql .= "ref,";
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)."'").",";
144  $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
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)."'");
149  $sql .= ")";
150 
151  $this->db->begin();
152 
153  dol_syslog(get_class($this)."::create", LOG_DEBUG);
154  $resql = $this->db->query($sql);
155  if (!$resql) {
156  $error++; $this->errors[] = "Error ".$this->db->lasterror();
157  }
158 
159  if (!$error) {
160  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
161  }
162 
163  if (!$error) {
164  $action = 'create';
165 
166  // Actions on extra fields
167  if (!$error) {
168  $result = $this->insertExtraFields();
169  if ($result < 0) {
170  $error++;
171  }
172  }
173  }
174 
175  if (!$error && !$notrigger) {
176  // Call trigger
177  $result = $this->call_trigger('RESOURCE_CREATE', $user);
178  if ($result < 0) {
179  $error++;
180  }
181  // End call triggers
182  }
183 
184  // Commit or rollback
185  if ($error) {
186  foreach ($this->errors as $errmsg) {
187  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
188  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
189  }
190  $this->db->rollback();
191  return -1 * $error;
192  } else {
193  $this->db->commit();
194  return $this->id;
195  }
196  }
197 
205  public function fetch($id, $ref = '')
206  {
207  global $langs;
208  $sql = "SELECT";
209  $sql .= " t.rowid,";
210  $sql .= " t.entity,";
211  $sql .= " t.ref,";
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,";
217  $sql .= " t.tms,";
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";
221  if ($id) {
222  $sql .= " WHERE t.rowid = ".((int) $id);
223  } else {
224  $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
225  }
226 
227  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
228  $resql = $this->db->query($sql);
229  if ($resql) {
230  if ($this->db->num_rows($resql)) {
231  $obj = $this->db->fetch_object($resql);
232 
233  $this->id = $obj->rowid;
234  $this->entity = $obj->entity;
235  $this->ref = $obj->ref;
236  $this->description = $obj->description;
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;
242 
243  // Retrieve all extrafield
244  // fetch optionals attributes and labels
245  $this->fetch_optionals();
246  }
247  $this->db->free($resql);
248 
249  return $this->id;
250  } else {
251  $this->error = "Error ".$this->db->lasterror();
252  dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
253  return -1;
254  }
255  }
256 
257 
265  public function update($user = null, $notrigger = 0)
266  {
267  global $conf, $langs, $hookmanager;
268  $error = 0;
269 
270  // Clean parameters
271  if (isset($this->ref)) {
272  $this->ref = trim($this->ref);
273  }
274  if (isset($this->fk_code_type_resource)) {
275  $this->fk_code_type_resource = trim($this->fk_code_type_resource);
276  }
277  if (isset($this->description)) {
278  $this->description = trim($this->description);
279  }
280  if (!is_numeric($this->country_id)) {
281  $this->country_id = 0;
282  }
283 
284  // $this->oldcopy should have been set by the caller of update (here properties were already modified)
285  if (empty($this->oldcopy)) {
286  $this->oldcopy = dol_clone($this);
287  }
288 
289  // Update request
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);
297 
298  $this->db->begin();
299 
300  dol_syslog(get_class($this)."::update", LOG_DEBUG);
301  $resql = $this->db->query($sql);
302  if (!$resql) {
303  $error++; $this->errors[] = "Error ".$this->db->lasterror();
304  }
305 
306  if (!$error) {
307  if (!$notrigger) {
308  // Call trigger
309  $result = $this->call_trigger('RESOURCE_MODIFY', $user);
310  if ($result < 0) {
311  $error++;
312  }
313  // End call triggers
314  }
315  }
316 
317  if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
318  // We remove directory
319  if (!empty($conf->resource->dir_output)) {
320  $olddir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
321  $newdir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
322  if (file_exists($olddir)) {
323  $res = @rename($olddir, $newdir);
324  if (!$res) {
325  $langs->load("errors");
326  $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
327  $error++;
328  }
329  }
330  }
331  }
332 
333  if (!$error) {
334  $action = 'update';
335 
336  // Actions on extra fields
337  if (!$error) {
338  $result = $this->insertExtraFields();
339  if ($result < 0) {
340  $error++;
341  }
342  }
343  }
344 
345  // Commit or rollback
346  if ($error) {
347  foreach ($this->errors as $errmsg) {
348  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
349  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
350  }
351  $this->db->rollback();
352  return -1 * $error;
353  } else {
354  $this->db->commit();
355  return 1;
356  }
357  }
358 
359  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
366  public function fetch_element_resource($id)
367  {
368  // phpcs:enable
369  global $langs;
370  $sql = "SELECT";
371  $sql .= " t.rowid,";
372  $sql .= " t.resource_id,";
373  $sql .= " t.resource_type,";
374  $sql .= " t.element_id,";
375  $sql .= " t.element_type,";
376  $sql .= " t.busy,";
377  $sql .= " t.mandatory,";
378  $sql .= " t.fk_user_create,";
379  $sql .= " t.tms";
380  $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as t";
381  $sql .= " WHERE t.rowid = ".((int) $id);
382 
383  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
384  $resql = $this->db->query($sql);
385  if ($resql) {
386  if ($this->db->num_rows($resql)) {
387  $obj = $this->db->fetch_object($resql);
388 
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;
397 
398  if ($obj->resource_id && $obj->resource_type) {
399  $this->objresource = fetchObjectByElement($obj->resource_id, $obj->resource_type);
400  }
401  if ($obj->element_id && $obj->element_type) {
402  $this->objelement = fetchObjectByElement($obj->element_id, $obj->element_type);
403  }
404  }
405  $this->db->free($resql);
406 
407  return $this->id;
408  } else {
409  $this->error = "Error ".$this->db->lasterror();
410  return -1;
411  }
412  }
413 
421  public function delete($rowid, $notrigger = 0)
422  {
423  global $user, $langs, $conf;
424  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
425 
426  $error = 0;
427 
428  $this->db->begin();
429 
430  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
431  $sql .= " WHERE rowid = ".((int) $rowid);
432 
433  dol_syslog(get_class($this), LOG_DEBUG);
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);
438  $resql = $this->db->query($sql);
439  if (!$resql) {
440  $this->error = $this->db->lasterror();
441  $error++;
442  }
443  } else {
444  $this->error = $this->db->lasterror();
445  $error++;
446  }
447 
448  // Removed extrafields
449  if (!$error) {
450  $result = $this->deleteExtraFields();
451  if ($result < 0) {
452  $error++;
453  dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
454  }
455  }
456 
457  if (!$notrigger) {
458  // Call trigger
459  $result = $this->call_trigger('RESOURCE_DELETE', $user);
460  if ($result < 0) {
461  $error++;
462  }
463  // End call triggers
464  }
465 
466  if (!$error) {
467  // We remove directory
468  $ref = dol_sanitizeFileName($this->ref);
469  if (!empty($conf->resource->dir_output)) {
470  $dir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
471  if (file_exists($dir)) {
472  $res = @dol_delete_dir_recursive($dir);
473  if (!$res) {
474  $this->errors[] = 'ErrorFailToDeleteDir';
475  $error++;
476  }
477  }
478  }
479  }
480 
481  if (!$error) {
482  $this->db->commit();
483  return 1;
484  } else {
485  $this->db->rollback();
486  return -1;
487  }
488  }
489 
490  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
501  public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = '')
502  {
503  // phpcs:enable
504  global $conf;
505 
506  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
507  $extrafields = new ExtraFields($this->db);
508 
509  $sql = "SELECT ";
510  $sql .= " t.rowid,";
511  $sql .= " t.entity,";
512  $sql .= " t.ref,";
513  $sql .= " t.description,";
514  $sql .= " t.fk_country,";
515  $sql .= " t.fk_code_type_resource,";
516  $sql .= " t.tms,";
517  // Add fields from extrafields
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.', ' : '');
521  }
522  }
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').")";
528  // Manage filter
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) {
534  $sql .= $value;
535  } else {
536  $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
537  }
538  }
539  }
540  $sql .= $this->db->order($sortfield, $sortorder);
541  $this->num_all = 0;
542  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
543  $result = $this->db->query($sql);
544  $this->num_all = $this->db->num_rows($result);
545  }
546  if ($limit) {
547  $sql .= $this->db->plimit($limit, $offset);
548  }
549  dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
550 
551  $this->lines = array();
552  $resql = $this->db->query($sql);
553  if ($resql) {
554  $num = $this->db->num_rows($resql);
555  if ($num) {
556  while ($obj = $this->db->fetch_object($resql)) {
557  $line = new Dolresource($this->db);
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;
564 
565  // fetch optionals attributes and labels
566 
567  $line->fetch_optionals();
568 
569  $this->lines[] = $line;
570  }
571  $this->db->free($resql);
572  }
573  return $num;
574  } else {
575  $this->error = $this->db->lasterror();
576  return -1;
577  }
578  }
579 
580  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
588  public function update_element_resource($user = null, $notrigger = 0)
589  {
590  // phpcs:enable
591  global $conf, $langs;
592  $error = 0;
593 
594  // Clean parameters
595  if (isset($this->resource_id)) {
596  $this->resource_id = trim($this->resource_id);
597  }
598  if (isset($this->resource_type)) {
599  $this->resource_type = trim($this->resource_type);
600  }
601  if (isset($this->element_id)) {
602  $this->element_id = trim($this->element_id);
603  }
604  if (isset($this->element_type)) {
605  $this->element_type = trim($this->element_type);
606  }
607  if (isset($this->busy)) {
608  $this->busy = trim($this->busy);
609  }
610  if (isset($this->mandatory)) {
611  $this->mandatory = trim($this->mandatory);
612  }
613 
614  // Update request
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')."";
623 
624  $sql .= " WHERE rowid=".((int) $this->id);
625 
626  $this->db->begin();
627 
628  dol_syslog(get_class($this)."::update", LOG_DEBUG);
629  $resql = $this->db->query($sql);
630  if (!$resql) {
631  $error++; $this->errors[] = "Error ".$this->db->lasterror();
632  }
633 
634  if (!$error) {
635  if (!$notrigger) {
636  // Call trigger
637  $result = $this->call_trigger('RESOURCE_MODIFY', $user);
638  if ($result < 0) {
639  $error++;
640  }
641  // End call triggers
642  }
643  }
644 
645  // Commit or rollback
646  if ($error) {
647  foreach ($this->errors as $errmsg) {
648  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
649  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
650  }
651  $this->db->rollback();
652  return -1 * $error;
653  } else {
654  $this->db->commit();
655  return 1;
656  }
657  }
658 
659 
668  public function getElementResources($element, $element_id, $resource_type = '')
669  {
670  $resources = array();
671 
672  // Links beetween objects are stored in this table
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)."%'";
678  }
679  $sql .= ' ORDER BY resource_type';
680 
681  dol_syslog(get_class($this)."::getElementResources", LOG_DEBUG);
682 
683  $resources = array();
684  $resql = $this->db->query($sql);
685  if ($resql) {
686  $num = $this->db->num_rows($resql);
687  $i = 0;
688  while ($i < $num) {
689  $obj = $this->db->fetch_object($resql);
690 
691  $resources[$i] = array(
692  'rowid' => $obj->rowid,
693  'resource_id' => $obj->resource_id,
694  'resource_type'=>$obj->resource_type,
695  'busy'=>$obj->busy,
696  'mandatory'=>$obj->mandatory
697  );
698  $i++;
699  }
700  }
701 
702  return $resources;
703  }
704 
712  public function fetchElementResources($element, $element_id)
713  {
714  $resources = $this->getElementResources($element, $element_id);
715  $i = 0;
716  foreach ($resources as $nb => $resource) {
717  $this->lines[$i] = fetchObjectByElement($resource['resource_id'], $resource['resource_type']);
718  $i++;
719  }
720  return $i;
721  }
722 
723 
724  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
731  {
732  // phpcs:enable
733  global $langs;
734 
735  if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
736  return 0; // Cache deja charge
737  }
738 
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);
744  $resql = $this->db->query($sql);
745  if ($resql) {
746  $num = $this->db->num_rows($resql);
747  $i = 0;
748  while ($i < $num) {
749  $obj = $this->db->fetch_object($resql);
750  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
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;
755  $i++;
756  }
757  return $num;
758  } else {
759  dol_print_error($this->db);
760  return -1;
761  }
762  }
763 
775  public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
776  {
777  global $conf, $langs, $hookmanager;
778 
779  $result = '';
780  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Resource").'</u>';
781  $label .= '<br>';
782  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
783  /*if (isset($this->status)) {
784  $label.= '<br><b>' . $langs->trans("Status").":</b> ".$this->getLibStatut(5);
785  }*/
786  if (isset($this->type_label)) {
787  $label .= '<br><b>'.$langs->trans("ResourceType").":</b> ".$this->type_label;
788  }
789 
790  $url = DOL_URL_ROOT.'/resource/card.php?id='.$this->id;
791 
792  if ($option != 'nolink') {
793  // Add param to save lastsearch_values or not
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;
797  }
798  if ($add_save_lastsearch_values) {
799  $url .= '&save_lastsearch_values=1';
800  }
801  }
802 
803  $linkclose = '';
804  if (empty($notooltip)) {
805  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
806  $label = $langs->trans("ShowMyObject");
807  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
808  }
809  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
810  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
811  } else {
812  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
813  }
814 
815  $linkstart = '<a href="'.$url.$get_params.'"';
816  $linkstart .= $linkclose.'>';
817  $linkend = '</a>';
818  /*$linkstart = '<a href="'.DOL_URL_ROOT.'/resource/card.php?id='.$this->id.$get_params.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
819  $linkend = '</a>';*/
820 
821  $result .= $linkstart;
822  if ($withpicto) {
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);
824  }
825  if ($withpicto != 2) {
826  $result .= $this->ref;
827  }
828  $result .= $linkend;
829 
830  global $action;
831  $hookmanager->initHooks(array($this->element . 'dao'));
832  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
833  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
834  if ($reshook > 0) {
835  $result = $hookmanager->resPrint;
836  } else {
837  $result .= $hookmanager->resPrint;
838  }
839  return $result;
840  }
841 
842 
849  public function getLibStatut($mode = 0)
850  {
851  return $this->LibStatut($this->status, $mode);
852  }
853 
854  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
862  public static function LibStatut($status, $mode = 0)
863  {
864  // phpcs:enable
865  global $langs;
866 
867  return '';
868  }
869 
870  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
876  public function load_state_board()
877  {
878  // phpcs:enable
879  global $conf;
880 
881  $this->nb = array();
882 
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').")";
886 
887  $resql = $this->db->query($sql);
888  if ($resql) {
889  while ($obj = $this->db->fetch_object($resql)) {
890  $this->nb["dolresource"] = $obj->nb;
891  }
892  $this->db->free($resql);
893  return 1;
894  } else {
895  dol_print_error($this->db);
896  $this->error = $this->db->error();
897  return -1;
898  }
899  }
900 }
$object ref
Definition: info.php:78
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.
DAO Resource object.
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)
Class to manage standard extra fields.
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.
Definition: index.php:745
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)
Definition: files.lib.php:1402
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.
Definition: inc.php:41