dolibarr 19.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
24require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
25require_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;
74 public $fulldayevent;
75
79 public $fk_user_create;
80 public $tms = '';
81
86
90 public $cache_code_type_resource = array();
91
95 public $oldcopy;
96
97
103 public function __construct($db)
104 {
105 $this->db = $db;
106 }
107
115 public function create($user, $notrigger = 0)
116 {
117 global $conf, $langs, $hookmanager;
118 $error = 0;
119
120 // Clean parameters
121
122 if (isset($this->ref)) {
123 $this->ref = trim($this->ref);
124 }
125 if (isset($this->description)) {
126 $this->description = trim($this->description);
127 }
128 if (!is_numeric($this->country_id)) {
129 $this->country_id = 0;
130 }
131 if (isset($this->fk_code_type_resource)) {
132 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
133 }
134 if (isset($this->note_public)) {
135 $this->note_public = trim($this->note_public);
136 }
137 if (isset($this->note_private)) {
138 $this->note_private = trim($this->note_private);
139 }
140
141
142 // Insert request
143 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
144 $sql .= "entity,";
145 $sql .= "ref,";
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)."'").",";
154 $sql .= " ".(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
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)."'");
159 $sql .= ")";
160
161 $this->db->begin();
162
163 dol_syslog(get_class($this)."::create", LOG_DEBUG);
164 $resql = $this->db->query($sql);
165 if (!$resql) {
166 $error++;
167 $this->errors[] = "Error ".$this->db->lasterror();
168 }
169
170 if (!$error) {
171 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
172 }
173
174 if (!$error) {
175 $action = 'create';
176
177 // Actions on extra fields
178 if (!$error) {
179 $result = $this->insertExtraFields();
180 if ($result < 0) {
181 $error++;
182 }
183 }
184 }
185
186 if (!$error && !$notrigger) {
187 // Call trigger
188 $result = $this->call_trigger('RESOURCE_CREATE', $user);
189 if ($result < 0) {
190 $error++;
191 }
192 // End call triggers
193 }
194
195 // Commit or rollback
196 if ($error) {
197 foreach ($this->errors as $errmsg) {
198 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
199 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
200 }
201 $this->db->rollback();
202 return -1 * $error;
203 } else {
204 $this->db->commit();
205 return $this->id;
206 }
207 }
208
216 public function fetch($id, $ref = '')
217 {
218 global $langs;
219 $sql = "SELECT";
220 $sql .= " t.rowid,";
221 $sql .= " t.entity,";
222 $sql .= " t.ref,";
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,";
228 $sql .= " t.tms,";
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";
232 if ($id) {
233 $sql .= " WHERE t.rowid = ".((int) $id);
234 } else {
235 $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
236 }
237
238 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
239 $resql = $this->db->query($sql);
240 if ($resql) {
241 if ($this->db->num_rows($resql)) {
242 $obj = $this->db->fetch_object($resql);
243
244 $this->id = $obj->rowid;
245 $this->entity = $obj->entity;
246 $this->ref = $obj->ref;
247 $this->description = $obj->description;
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;
253
254 // Retrieve all extrafield
255 // fetch optionals attributes and labels
256 $this->fetch_optionals();
257 }
258 $this->db->free($resql);
259
260 return $this->id;
261 } else {
262 $this->error = "Error ".$this->db->lasterror();
263 dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
264 return -1;
265 }
266 }
267
268
276 public function update($user = null, $notrigger = 0)
277 {
278 global $conf, $langs, $hookmanager;
279 $error = 0;
280
281 // Clean parameters
282 if (isset($this->ref)) {
283 $this->ref = trim($this->ref);
284 }
285 if (isset($this->fk_code_type_resource)) {
286 $this->fk_code_type_resource = trim($this->fk_code_type_resource);
287 }
288 if (isset($this->description)) {
289 $this->description = trim($this->description);
290 }
291 if (!is_numeric($this->country_id)) {
292 $this->country_id = 0;
293 }
294
295 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
296 if (empty($this->oldcopy)) {
297 $this->oldcopy = dol_clone($this);
298 }
299
300 // Update request
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);
308
309 $this->db->begin();
310
311 dol_syslog(get_class($this)."::update", LOG_DEBUG);
312 $resql = $this->db->query($sql);
313 if (!$resql) {
314 $error++;
315 $this->errors[] = "Error ".$this->db->lasterror();
316 }
317
318 if (!$error) {
319 if (!$notrigger) {
320 // Call trigger
321 $result = $this->call_trigger('RESOURCE_MODIFY', $user);
322 if ($result < 0) {
323 $error++;
324 }
325 // End call triggers
326 }
327 }
328
329 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
330 // We remove directory
331 if (!empty($conf->resource->dir_output)) {
332 $olddir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->oldcopy->ref);
333 $newdir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
334 if (file_exists($olddir)) {
335 $res = @rename($olddir, $newdir);
336 if (!$res) {
337 $langs->load("errors");
338 $this->error = $langs->trans('ErrorFailToRenameDir', $olddir, $newdir);
339 $error++;
340 }
341 }
342 }
343 }
344
345 if (!$error) {
346 $action = 'update';
347
348 // Actions on extra fields
349 if (!$error) {
350 $result = $this->insertExtraFields();
351 if ($result < 0) {
352 $error++;
353 }
354 }
355 }
356
357 // Commit or rollback
358 if ($error) {
359 foreach ($this->errors as $errmsg) {
360 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
361 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
362 }
363 $this->db->rollback();
364 return -1 * $error;
365 } else {
366 $this->db->commit();
367 return 1;
368 }
369 }
370
371 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
378 public function fetch_element_resource($id)
379 {
380 // phpcs:enable
381 $sql = "SELECT";
382 $sql .= " t.rowid,";
383 $sql .= " t.resource_id,";
384 $sql .= " t.resource_type,";
385 $sql .= " t.element_id,";
386 $sql .= " t.element_type,";
387 $sql .= " t.busy,";
388 $sql .= " t.mandatory,";
389 $sql .= " t.fk_user_create,";
390 $sql .= " t.tms";
391 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as t";
392 $sql .= " WHERE t.rowid = ".((int) $id);
393
394 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
395 $resql = $this->db->query($sql);
396 if ($resql) {
397 if ($this->db->num_rows($resql)) {
398 $obj = $this->db->fetch_object($resql);
399
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;
408
409 /*if ($obj->resource_id && $obj->resource_type) {
410 $this->objresource = fetchObjectByElement($obj->resource_id, $obj->resource_type);
411 }*/
412 if ($obj->element_id && $obj->element_type) {
413 $this->objelement = fetchObjectByElement($obj->element_id, $obj->element_type);
414 }
415 }
416 $this->db->free($resql);
417
418 return $this->id;
419 } else {
420 $this->error = "Error ".$this->db->lasterror();
421 return -1;
422 }
423 }
424
432 public function delete($rowid, $notrigger = 0)
433 {
434 global $user, $langs, $conf;
435 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
436
437 $error = 0;
438
439 $this->db->begin();
440
441 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
442 $sql .= " WHERE rowid = ".((int) $rowid);
443
444 dol_syslog(get_class($this), LOG_DEBUG);
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);
450 if (!$resql) {
451 $this->error = $this->db->lasterror();
452 $error++;
453 }
454 } else {
455 $this->error = $this->db->lasterror();
456 $error++;
457 }
458
459 // Removed extrafields
460 if (!$error) {
461 $result = $this->deleteExtraFields();
462 if ($result < 0) {
463 $error++;
464 dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
465 }
466 }
467
468 if (!$notrigger) {
469 // Call trigger
470 $result = $this->call_trigger('RESOURCE_DELETE', $user);
471 if ($result < 0) {
472 $error++;
473 }
474 // End call triggers
475 }
476
477 if (!$error) {
478 // We remove directory
479 $ref = dol_sanitizeFileName($this->ref);
480 if (!empty($conf->resource->dir_output)) {
481 $dir = $conf->resource->dir_output."/".dol_sanitizeFileName($this->ref);
482 if (file_exists($dir)) {
483 $res = @dol_delete_dir_recursive($dir);
484 if (!$res) {
485 $this->errors[] = 'ErrorFailToDeleteDir';
486 $error++;
487 }
488 }
489 }
490 }
491
492 if (!$error) {
493 $this->db->commit();
494 return 1;
495 } else {
496 $this->db->rollback();
497 return -1;
498 }
499 }
500
501 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
512 public function fetchAll($sortorder, $sortfield, $limit, $offset, $filter = '')
513 {
514 // phpcs:enable
515 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
516 $extrafields = new ExtraFields($this->db);
517
518 $sql = "SELECT ";
519 $sql .= " t.rowid,";
520 $sql .= " t.entity,";
521 $sql .= " t.ref,";
522 $sql .= " t.description,";
523 $sql .= " t.fk_country,";
524 $sql .= " t.fk_code_type_resource,";
525 $sql .= " t.tms,";
526 // Add fields from extrafields
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.', ' : '');
530 }
531 }
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').")";
537 // Manage filter
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) {
543 $sql .= $value;
544 } else {
545 $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
546 }
547 }
548 }
549 $sql .= $this->db->order($sortfield, $sortorder);
550 if ($limit) {
551 $sql .= $this->db->plimit($limit, $offset);
552 }
553
554 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
555
556 $this->lines = array();
557 $resql = $this->db->query($sql);
558 if ($resql) {
559 $num = $this->db->num_rows($resql);
560 if ($num) {
561 while ($obj = $this->db->fetch_object($resql)) {
562 $line = new Dolresource($this->db);
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;
569
570 // fetch optionals attributes and labels
571
572 $line->fetch_optionals();
573
574 $this->lines[] = $line;
575 }
576 $this->db->free($resql);
577 }
578 return $num;
579 } else {
580 $this->error = $this->db->lasterror();
581 return -1;
582 }
583 }
584
585 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
593 public function update_element_resource($user = null, $notrigger = 0)
594 {
595 // phpcs:enable
596 global $conf, $langs;
597 $error = 0;
598
599 // Clean parameters
600 if (isset($this->resource_id)) {
601 $this->resource_id = trim($this->resource_id);
602 }
603 if (isset($this->resource_type)) {
604 $this->resource_type = trim($this->resource_type);
605 }
606 if (isset($this->element_id)) {
607 $this->element_id = trim($this->element_id);
608 }
609 if (isset($this->element_type)) {
610 $this->element_type = trim($this->element_type);
611 }
612 if (isset($this->busy)) {
613 $this->busy = trim($this->busy);
614 }
615 if (isset($this->mandatory)) {
616 $this->mandatory = trim($this->mandatory);
617 }
618
619 // Update request
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');
628
629 $sql .= " WHERE rowid=".((int) $this->id);
630
631 $this->db->begin();
632
633 dol_syslog(get_class($this)."::update", LOG_DEBUG);
634 $resql = $this->db->query($sql);
635 if (!$resql) {
636 $error++;
637 $this->errors[] = "Error ".$this->db->lasterror();
638 }
639
640 if (!$error) {
641 if (!$notrigger) {
642 // Call trigger
643 $result = $this->call_trigger('RESOURCE_MODIFY', $user);
644 if ($result < 0) {
645 $error++;
646 }
647 // End call triggers
648 }
649 }
650
651 // Commit or rollback
652 if ($error) {
653 foreach ($this->errors as $errmsg) {
654 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
655 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
656 }
657 $this->db->rollback();
658 return -1 * $error;
659 } else {
660 $this->db->commit();
661 return 1;
662 }
663 }
664
665
674 public function getElementResources($element, $element_id, $resource_type = '')
675 {
676 $resources = array();
677
678 // Links beetween objects are stored in this table
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)."%'";
684 }
685 $sql .= ' ORDER BY resource_type';
686
687 dol_syslog(get_class($this)."::getElementResources", LOG_DEBUG);
688
689 $resources = array();
690 $resql = $this->db->query($sql);
691 if ($resql) {
692 $num = $this->db->num_rows($resql);
693 $i = 0;
694 while ($i < $num) {
695 $obj = $this->db->fetch_object($resql);
696
697 $resources[$i] = array(
698 'rowid' => $obj->rowid,
699 'resource_id' => $obj->resource_id,
700 'resource_type'=>$obj->resource_type,
701 'busy'=>$obj->busy,
702 'mandatory'=>$obj->mandatory
703 );
704 $i++;
705 }
706 }
707
708 return $resources;
709 }
710
718 public function fetchElementResources($element, $element_id)
719 {
720 $resources = $this->getElementResources($element, $element_id);
721 $i = 0;
722 foreach ($resources as $nb => $resource) {
723 $this->lines[$i] = fetchObjectByElement($resource['resource_id'], $resource['resource_type']);
724 $i++;
725 }
726 return $i;
727 }
728
729
730 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
737 {
738 // phpcs:enable
739 global $langs;
740
741 if (is_array($this->cache_code_type_resource) && count($this->cache_code_type_resource)) {
742 return 0; // Cache deja charge
743 }
744
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);
751 if ($resql) {
752 $num = $this->db->num_rows($resql);
753 $i = 0;
754 while ($i < $num) {
755 $obj = $this->db->fetch_object($resql);
756
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;
761 $i++;
762 }
763 return $num;
764 } else {
765 dol_print_error($this->db);
766 return -1;
767 }
768 }
769
777 public function getTooltipContentArray($params)
778 {
779 global $langs;
780
781 $langs->load('resource');
782
783 $datas = [];
784
785 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Resource").'</u>';
786 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
787 /*if (isset($this->status)) {
788 $datas['status'] = '<br><b>' . $langs->trans("Status").":</b> ".$this->getLibStatut(5);
789 }*/
790 if (isset($this->type_label)) {
791 $datas['label'] = '<br><b>'.$langs->trans("ResourceType").":</b> ".$this->type_label;
792 }
793
794 return $datas;
795 }
796
808 public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
809 {
810 global $conf, $langs, $hookmanager;
811
812 $result = '';
813 $params = [
814 'id' => $this->id,
815 'objecttype' => $this->element,
816 ];
817 $classfortooltip = 'classfortooltip';
818 $dataparams = '';
819 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
820 $classfortooltip = 'classforajaxtooltip';
821 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
822 $label = '';
823 } else {
824 $label = implode($this->getTooltipContentArray($params));
825 }
826
827 $url = DOL_URL_ROOT.'/resource/card.php?id='.$this->id;
828
829 if ($option != 'nolink') {
830 // Add param to save lastsearch_values or not
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;
834 }
835 if ($add_save_lastsearch_values) {
836 $url .= '&save_lastsearch_values=1';
837 }
838 }
839
840 $linkclose = '';
841 if (empty($notooltip)) {
842 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
843 $label = $langs->trans("ShowMyObject");
844 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
845 }
846 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
847 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
848 } else {
849 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
850 }
851
852 $linkstart = '<a href="'.$url.$get_params.'"';
853 $linkstart .= $linkclose.'>';
854 $linkend = '</a>';
855 /*$linkstart = '<a href="'.DOL_URL_ROOT.'/resource/card.php?id='.$this->id.$get_params.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
856 $linkend = '</a>';*/
857
858 $result .= $linkstart;
859 if ($withpicto) {
860 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
861 }
862 if ($withpicto != 2) {
863 $result .= $this->ref;
864 }
865 $result .= $linkend;
866
867 global $action;
868 $hookmanager->initHooks(array($this->element . 'dao'));
869 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
870 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
871 if ($reshook > 0) {
872 $result = $hookmanager->resPrint;
873 } else {
874 $result .= $hookmanager->resPrint;
875 }
876 return $result;
877 }
878
879
886 public function getLibStatut($mode = 0)
887 {
888 return $this->LibStatut($this->status, $mode);
889 }
890
891 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
899 public static function LibStatut($status, $mode = 0)
900 {
901 // phpcs:enable
902 return '';
903 }
904
905 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
911 public function load_state_board()
912 {
913 // phpcs:enable
914 $this->nb = array();
915
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').")";
919
920 $resql = $this->db->query($sql);
921 if ($resql) {
922 while ($obj = $this->db->fetch_object($resql)) {
923 $this->nb["dolresource"] = $obj->nb;
924 }
925 $this->db->free($resql);
926 return 1;
927 } else {
928 dol_print_error($this->db);
929 $this->error = $this->db->error();
930 return -1;
931 }
932 }
933}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
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 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.
Class to manage standard extra fields.
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.