dolibarr 25.0.0-alpha
ecmdirectory.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
31{
35 public $element = 'ecm_directories';
36
40 public $table_element = 'ecm_directories';
41
45 public $picto = 'folder-open';
46
50 public $id;
51
55 public $label;
56
60 public $fk_parent;
61
65 public $description;
66
70 public $cachenbofdoc = -1; // By default cache initialized with value 'not calculated'
71
75 public $date_c;
76
80 public $date_m;
81
85 public $fk_user_m;
86
90 public $fk_user_c;
91
95 public $ref;
96
100 public $cats = array();
101
105 public $motherof = array();
106
110 public $forbiddenchars = array('<', '>', ':', '/', '\\', '?', '*', '|', '"');
111
115 public $forbiddencharsdir = array('<', '>', ':', '?', '*', '|', '"');
116
120 public $full_arbo_loaded;
121
127 public function __construct($db)
128 {
129 $this->db = $db;
130 }
131
132
139 public function create($user)
140 {
141 global $conf, $langs;
142
143 $error = 0;
144 $now = dol_now();
145
146 // Clean parameters
147 $this->label = dol_sanitizeFileName(trim($this->label));
148 $this->description = trim($this->description);
149 $this->date_c = $now;
150 $this->fk_user_c = $user->id;
151 if ($this->fk_parent <= 0) {
152 $this->fk_parent = 0;
153 }
154
155
156 // Check if same directory does not exists with this name
157 $relativepath = $this->label;
158 if ($this->fk_parent > 0) {
159 $parent = new EcmDirectory($this->db);
160 $parent->fetch($this->fk_parent);
161 $relativepath = $parent->getRelativePath().$relativepath;
162 }
163 $relativepath = preg_replace('/([\/])+/i', '/', $relativepath); // Avoid duplicate / or \
164 //print $relativepath.'<br>';
165
166 $cat = new EcmDirectory($this->db);
167 $cate_arbo = $cat->get_full_arbo(1);
168 $pathfound = 0;
169 foreach ($cate_arbo as $key => $categ) {
170 $path = str_replace($this->forbiddencharsdir, '_', $categ['fullrelativename']);
171 //print $relativepath.' - '.$path.'<br>';
172 if ($path == $relativepath) {
173 $pathfound = 1;
174 break;
175 }
176 }
177
178 if ($pathfound) {
179 $this->error = "ErrorDirAlreadyExists";
180 dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
181 return -1;
182 } else {
183 $this->db->begin();
184
185 // Insert request
186 $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
187 $sql .= "label,";
188 $sql .= "entity,";
189 $sql .= "fk_parent,";
190 $sql .= "description,";
191 $sql .= "cachenbofdoc,";
192 $sql .= "date_c,";
193 $sql .= "fk_user_c";
194 $sql .= ") VALUES (";
195 $sql .= " '".$this->db->escape($this->label)."',";
196 $sql .= " '".$this->db->escape((string) $conf->entity)."',";
197 $sql .= " ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "null").",";
198 $sql .= " '".$this->db->escape($this->description)."',";
199 $sql .= " ".((int) $this->cachenbofdoc).",";
200 $sql .= " '".$this->db->idate($this->date_c)."',";
201 $sql .= " ".($this->fk_user_c > 0 ? ((int) $this->fk_user_c) : "null");
202 $sql .= ")";
203
204 dol_syslog(get_class($this)."::create", LOG_DEBUG);
205 $resql = $this->db->query($sql);
206 if ($resql) {
207 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories");
208
209 $dir = $conf->ecm->dir_output.'/'.$this->getRelativePath();
210 $result = dol_mkdir($dir);
211 if ($result < 0) {
212 $error++;
213 $this->error = "ErrorFailedToCreateDir";
214 }
215
216 // Call trigger
217 $result = $this->call_trigger('MYECMDIR_CREATE', $user);
218 if ($result < 0) {
219 $error++;
220 }
221 // End call triggers
222
223 if (!$error) {
224 $this->db->commit();
225 return $this->id;
226 } else {
227 $this->db->rollback();
228 return -1;
229 }
230 } else {
231 $this->error = "Error ".$this->db->lasterror();
232 $this->db->rollback();
233 return -1;
234 }
235 }
236 }
237
245 public function update($user = null, $notrigger = 0)
246 {
247 global $conf, $langs;
248
249 $error = 0;
250
251 // Clean parameters
252 $this->label = trim($this->label);
253 $this->description = trim($this->description);
254 if ($this->fk_parent <= 0) {
255 $this->fk_parent = 0;
256 }
257
258 $this->db->begin();
259
260 // Update request
261 $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
262 $sql .= " label = '".$this->db->escape($this->label)."',";
263 $sql .= " fk_parent = ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "null").",";
264 $sql .= " description = '".$this->db->escape($this->description)."'";
265 $sql .= " WHERE rowid = ".((int) $this->id);
266
267 dol_syslog(get_class($this)."::update", LOG_DEBUG);
268 $resql = $this->db->query($sql);
269 if (!$resql) {
270 $error++;
271 $this->error = "Error ".$this->db->lasterror();
272 }
273
274 if (!$error && !$notrigger) {
275 // Call trigger
276 $result = $this->call_trigger('MYECMDIR_MODIFY', $user);
277 if ($result < 0) {
278 $error++;
279 }
280 // End call triggers
281 }
282
283 if (!$error) {
284 $this->db->commit();
285 return 1;
286 } else {
287 $this->db->rollback();
288 return -1;
289 }
290 }
291
292
299 public function changeNbOfFiles($value)
300 {
301 global $conf;
302
303 if ($value == 'database') {
304 $relativepath = $conf->ecm->dir_output . '/' . $this->getRelativePath(); // Ex: dir1/dir2/dir3/
305 $relativepath = preg_replace('/^' . preg_quote(DOL_DATA_ROOT, '/') . '/', '', $relativepath);
306 $relativepath = trim($relativepath, '/');
307
308 // Get nb file in relative path
309 $sql = "SELECT COUNT(*) AS nb";
310 $sql .= " FROM " . $this->db->prefix() . "ecm_files";
311 $sql .= " WHERE filepath = '" . $this->db->escape($relativepath) . "'";
312
313 dol_syslog(get_class($this) . "::changeNbOfFiles - Get nb file in relative path", LOG_DEBUG);
314 $resql = $this->db->query($sql);
315 if (!$resql) {
316 $this->error = "Error " . $this->db->lasterror();
317 return -1;
318 } else {
319 $value = 0;
320 if ($obj = $this->db->fetch_object($resql)) {
321 $value = (int) $obj->nb;
322 }
323 }
324 }
325
326 // Update request
327 $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
328 if (preg_match('/[0-9]+/', $value)) {
329 $sql .= " cachenbofdoc = ".(int) $value;
330 } else {
331 $sql .= " cachenbofdoc = cachenbofdoc ".preg_replace('/[^\-\+]/', '', $value)." 1";
332 }
333 $sql .= " WHERE rowid = ".((int) $this->id);
334
335 dol_syslog(get_class($this)."::changeNbOfFiles", LOG_DEBUG);
336 $resql = $this->db->query($sql);
337 if (!$resql) {
338 $this->error = "Error ".$this->db->lasterror();
339 return -1;
340 } else {
341 if (preg_match('/[0-9]+/', $value)) {
342 $this->cachenbofdoc = (int) $value;
343 } elseif ($value == '+') {
344 $this->cachenbofdoc++;
345 } elseif ($value == '-') {
346 $this->cachenbofdoc--;
347 }
348 }
349
350 return 1;
351 }
352
353
360 public function fetch($id)
361 {
362 $sql = "SELECT";
363 $sql .= " t.rowid,";
364 $sql .= " t.label,";
365 $sql .= " t.fk_parent,";
366 $sql .= " t.description,";
367 $sql .= " t.cachenbofdoc,";
368 $sql .= " t.fk_user_c,";
369 $sql .= " t.fk_user_m,";
370 $sql .= " t.date_c as date_c,";
371 $sql .= " t.tms as date_m";
372 $sql .= " FROM ".MAIN_DB_PREFIX."ecm_directories as t";
373 $sql .= " WHERE t.rowid = ".((int) $id);
374
375 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
376 $resql = $this->db->query($sql);
377 if ($resql) {
378 $obj = $this->db->fetch_object($resql);
379 if ($obj) {
380 $this->id = $obj->rowid;
381 $this->ref = $obj->rowid;
382
383 $this->label = $obj->label;
384 $this->fk_parent = $obj->fk_parent;
385 $this->description = $obj->description;
386 $this->cachenbofdoc = (int) $obj->cachenbofdoc;
387 $this->fk_user_m = $obj->fk_user_m;
388 $this->fk_user_c = $obj->fk_user_c;
389 $this->date_c = $this->db->jdate($obj->date_c);
390 $this->date_m = $this->db->jdate($obj->date_m);
391 }
392
393 // Retrieve all extrafields for ecm_files
394 // fetch optionals attributes and labels
395 $this->fetch_optionals();
396
397 $this->db->free($resql);
398
399 return $obj ? 1 : 0;
400 } else {
401 $this->error = "Error ".$this->db->lasterror();
402 return -1;
403 }
404 }
405
406
415 public function delete($user, $mode = 'all', $deletedirrecursive = 0)
416 {
417 global $conf, $langs;
418 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
419
420 $error = 0;
421
422 $relativepath = '__MUST_NOT_EXIST__';
423 if ($mode != 'databaseonly') {
424 $relativepath = $this->getRelativePath(1); // Ex: dir1/dir2/dir3
425 }
426
427 dol_syslog(get_class($this)."::delete remove directory id=".$this->id." mode=".$mode.(($mode == 'databaseonly') ? '' : ' relativepath='.$relativepath));
428
429 $this->db->begin();
430
431 // With the content, the subdirectories are deleted too (their files are deleted with the directory on disk)
432 if ($deletedirrecursive) {
433 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_directories WHERE fk_parent = ".((int) $this->id);
434 $resql = $this->db->query($sql);
435 if ($resql) {
436 while ($obj = $this->db->fetch_object($resql)) {
437 $subdir = new EcmDirectory($this->db);
438 if ($subdir->fetch($obj->rowid) > 0 && $subdir->delete($user, 'databaseonly', 1) < 0) {
439 $this->error = $subdir->error;
440 $this->db->rollback();
441 return -2;
442 }
443 }
444 }
445 }
446
447 $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_directories";
448 $sql .= " WHERE rowid=".((int) $this->id);
449
450 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
451 $resql = $this->db->query($sql);
452 if (!$resql) {
453 $this->db->rollback();
454 $this->error = "Error ".$this->db->lasterror();
455 return -2;
456 } else {
457 // Call trigger
458 $result = $this->call_trigger('MYECMDIR_DELETE', $user);
459 if ($result < 0) {
460 $this->db->rollback();
461 return -2;
462 }
463 // End call triggers
464 }
465
466 $file = '__MUST_NOT_EXIST__';
467 if ($mode != 'databaseonly') {
468 $file = $conf->ecm->dir_output."/".$relativepath;
469 if ($deletedirrecursive) {
470 $result = @dol_delete_dir_recursive($file, 0, 0);
471 } else {
472 $result = @dol_delete_dir($file, 0);
473 }
474 }
475
476 if ($result || !@is_dir(dol_osencode($file))) {
477 $this->db->commit();
478 } else {
479 $this->error = 'ErrorFailToDeleteDir';
480 dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
481 $this->db->rollback();
482 $error++;
483 }
484
485 if (!$error) {
486 return 1;
487 } else {
488 return -1;
489 }
490 }
491
492
500 public function initAsSpecimen()
501 {
502 $this->id = 0;
503
504 $this->label = 'MyDirectory';
505 $this->fk_parent = 0;
506 $this->description = 'This is a directory';
507
508 return 1;
509 }
510
511
522 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $more = '', $notooltip = 0)
523 {
524 global $langs, $hookmanager;
525
526 $result = '';
527 //$newref=str_replace('_',' ',$this->ref);
528 $newref = (string) $this->ref;
529 $label = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly') . $langs->trans("ShowECMSection") . ': ' . $newref;
530 $linkclose = '"'.($more ? ' '.$more : '').' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
531
532 $linkstart = '<a href="'.DOL_URL_ROOT.'/ecm/dir_card.php?section='.$this->id.$linkclose;
533 if ($option == 'index') {
534 $linkstart = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=true'.$linkclose;
535 }
536 if ($option == 'indexexpanded') {
537 $linkstart = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=false'.$linkclose;
538 }
539 if ($option == 'indexnotexpanded') {
540 $linkstart = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=true'.$linkclose;
541 }
542 $linkend = '</a>';
543
544 $result .= $linkstart;
545 if ($withpicto) {
546 $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
547 }
548 if ($withpicto != 2) {
549 $result .= ($max ? dol_trunc($newref, $max, 'middle') : $newref);
550 }
551 $result .= $linkend;
552
553 global $action;
554 $hookmanager->initHooks(array($this->element . 'dao'));
555 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
556 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
557 if ($reshook > 0) {
558 $result = $hookmanager->resPrint;
559 } else {
560 $result .= $hookmanager->resPrint;
561 }
562 return $result;
563 }
564
571 public function getRelativePath($force = 0)
572 {
573 $this->get_full_arbo($force);
574
575 $ret = '';
576 $idtosearch = $this->id;
577 $i = 0;
578 do {
579 // Get index cursor in this->cats for id_mere
580 $cursorindex = -1;
581 foreach ($this->cats as $key => $val) {
582 if ($this->cats[$key]['id'] == $idtosearch) {
583 $cursorindex = $key;
584 break;
585 }
586 }
587 //print "c=".$idtosearch."-".$cursorindex;
588
589 if ($cursorindex >= 0) {
590 // Path is label sanitized (no space and no special char) and concatenated @phan-suppress-next-line PhanTypeSuspiciousStringExpression
591 $ret = dol_sanitizeFileName($this->cats[$cursorindex]['label']).'/'.$ret;
592
593 $idtosearch = $this->cats[$cursorindex]['id_mere'];
594 $i++;
595 }
596 } while ($cursorindex >= 0 && !empty($idtosearch) && $i < 100); // i avoid infinite loop
597
598 return $ret;
599 }
600
601 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
607 public function load_motherof()
608 {
609 // phpcs:enable
610 global $conf;
611
612 $this->motherof = array();
613
614 // Load array[child]=parent
615 $sql = "SELECT fk_parent as id_parent, rowid as id_son";
616 $sql .= " FROM ".MAIN_DB_PREFIX."ecm_directories";
617 $sql .= " WHERE fk_parent != 0";
618 $sql .= " AND entity = ".((int) $conf->entity);
619
620 dol_syslog(get_class($this)."::load_motherof", LOG_DEBUG);
621 $resql = $this->db->query($sql);
622 if ($resql) {
623 // This assignment in condition is not a bug. It allows walking the results.
624 while ($obj = $this->db->fetch_object($resql)) {
625 $this->motherof[$obj->id_son] = $obj->id_parent;
626 }
627 return 1;
628 } else {
629 dol_print_error($this->db);
630 return -1;
631 }
632 }
633
634
641 public function getLibStatut($mode = 0)
642 {
643 return $this->LibStatut($this->status, $mode);
644 }
645
646 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
654 public static function LibStatut($status, $mode = 0)
655 {
656 // phpcs:enable
657
658 return '';
659 }
660
661
662 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
683 public function get_full_arbo($force = 0)
684 {
685 // phpcs:enable
686 global $conf;
687
688 if (empty($force) && !empty($this->full_arbo_loaded)) {
689 return $this->cats;
690 }
691
692 // Init this->motherof that is array(id_son=>id_parent, ...)
693 $this->load_motherof();
694
695 // Load categories array
696 $sql = "SELECT c.rowid as rowid, c.label as label,";
697 $sql .= " c.description as description, c.cachenbofdoc,";
698 $sql .= " c.fk_user_c,";
699 $sql .= " c.date_c,";
700 $sql .= " u.login as login_c,";
701 $sql .= " u.statut as statut_c,";
702 $sql .= " ca.rowid as rowid_fille";
703 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."ecm_directories as c";
704 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ecm_directories as ca";
705 $sql .= " ON c.rowid = ca.fk_parent";
706 $sql .= " WHERE c.fk_user_c = u.rowid";
707 $sql .= " AND c.entity = ".((int) $conf->entity);
708 $sql .= " ORDER BY c.label, c.rowid";
709
710 dol_syslog(get_class($this)."::get_full_arbo", LOG_DEBUG);
711 $resql = $this->db->query($sql);
712 if ($resql) {
713 $this->cats = array();
714 $i = 0;
715 // This assignment in condition is not a bug. It allows walking the results.
716 while ($obj = $this->db->fetch_object($resql)) {
717 $this->cats[$obj->rowid]['id'] = $obj->rowid;
718 $this->cats[$obj->rowid]['id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] : '');
719 $this->cats[$obj->rowid]['label'] = $obj->label;
720 $this->cats[$obj->rowid]['description'] = $obj->description;
721 $this->cats[$obj->rowid]['cachenbofdoc'] = (int) $obj->cachenbofdoc;
722 $this->cats[$obj->rowid]['date_c'] = $this->db->jdate($obj->date_c);
723 $this->cats[$obj->rowid]['fk_user_c'] = (int) $obj->fk_user_c;
724 $this->cats[$obj->rowid]['statut_c'] = (int) $obj->statut_c;
725 $this->cats[$obj->rowid]['login_c'] = $obj->login_c;
726
727 if (!empty($obj->rowid_fille)) {
728 if (isset($this->cats[$obj->rowid]['id_children']) && is_array($this->cats[$obj->rowid]['id_children'])) {
729 $newelempos = count($this->cats[$obj->rowid]['id_children']);
730 //print "this->cats[$i]['id_children'] is already an array of $newelem elements<br>";
731 $this->cats[$obj->rowid]['id_children'][$newelempos] = $obj->rowid_fille;
732 } else {
733 //print "this->cats[".$obj->rowid."]['id_children'] is not yet an array<br>";
734 $this->cats[$obj->rowid]['id_children'] = array($obj->rowid_fille);
735 }
736 }
737 $i++;
738 }
739 } else {
740 dol_print_error($this->db);
741 return -1;
742 }
743
744 // We add properties fullxxx to all elements
745 foreach ($this->cats as $key => $val) {
746 if (isset($this->motherof[$key])) {
747 continue;
748 }
749 $this->buildPathFromId($key, 0);
750 }
751
753 $cats = $this->cats;
754 $this->cats = dol_sort_array($cats, 'fulllabel', 'asc', 1, 0);
755 $this->full_arbo_loaded = 1;
756
757 return $this->cats;
758 }
759
768 private function buildPathFromId($id_categ, $protection = 0)
769 {
770 // Define fullpath
771 if (!empty($this->cats[$id_categ]['id_mere'])) {
772 $this->cats[$id_categ]['fullpath'] = $this->cats[$this->cats[$id_categ]['id_mere']]['fullpath'];
773 $this->cats[$id_categ]['fullpath'] .= '_'.$id_categ;
774 $this->cats[$id_categ]['fullrelativename'] = $this->cats[$this->cats[$id_categ]['id_mere']]['fullrelativename'];
775 $this->cats[$id_categ]['fullrelativename'] .= '/'.$this->cats[$id_categ]['label'];
776 $this->cats[$id_categ]['fulllabel'] = $this->cats[$this->cats[$id_categ]['id_mere']]['fulllabel'];
777 $this->cats[$id_categ]['fulllabel'] .= ' >> '.$this->cats[$id_categ]['label'];
778 } else {
779 $this->cats[$id_categ]['fullpath'] = '_'.$id_categ;
780 $this->cats[$id_categ]['fullrelativename'] = $this->cats[$id_categ]['label'];
781 $this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label'];
782 }
783 // We count number of _ to have level (we use strlen that is faster than dol_strlen)
784 $this->cats[$id_categ]['level'] = strlen(preg_replace('/([^_])/i', '', $this->cats[$id_categ]['fullpath']));
785
786 // Process children
787 $protection++;
788 if ($protection > 20) {
789 return; // We never go more than 20 levels
790 }
791 if (isset($this->cats[$id_categ]['id_children']) && is_array($this->cats[$id_categ]['id_children'])) {
792 foreach ($this->cats[$id_categ]['id_children'] as $key => $val) {
793 $this->buildPathFromId($val, $protection);
794 }
795 }
796 }
797
804 public function refreshcachenboffile($all = 0)
805 {
806 global $conf;
807 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
808
809 $dir = $conf->ecm->dir_output.'/'.$this->getRelativePath();
810 $filelist = dol_dir_list($dir, 'files', 0, '', '(\.meta|_preview.*\.png)$');
811
812 // Test if filelist is in database
813
814
815 // Update request
816 $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
817 $sql .= " cachenbofdoc = ".count($filelist);
818 if (empty($all)) { // By default
819 $sql .= " WHERE rowid = ".((int) $this->id);
820 } else {
821 $sql .= " WHERE entity = ".((int) $conf->entity);
822 }
823
824 dol_syslog(get_class($this)."::refreshcachenboffile", LOG_DEBUG);
825 $resql = $this->db->query($sql);
826 if ($resql) {
827 $this->cachenbofdoc = count($filelist);
828 return $this->cachenbofdoc;
829 } else {
830 $this->error = "Error ".$this->db->lasterror();
831 return -1;
832 }
833 }
834
835 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
848 public function call_trigger($triggerName, $user)
849 {
850 // phpcs:enable
851 global $langs, $conf;
852
853 include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
854 $interface = new Interfaces($this->db);
855 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
856 if ($result < 0) {
857 if (!empty($this->errors)) {
858 $this->errors = array_merge($this->errors, $interface->errors);
859 } else {
860 $this->errors = $interface->errors;
861 }
862 }
863 return $result;
864 }
865}
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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...
Class to manage ECM directories.
__construct($db)
Constructor.
getNomUrl($withpicto=0, $option='', $max=0, $more='', $notooltip=0)
Return directory name you can click (and picto)
static LibStatut($status, $mode=0)
Return the status.
buildPathFromId($id_categ, $protection=0)
Define properties fullpath, fullrelativename, fulllabel of a directory of array this->cats and all it...
load_motherof()
Load this->motherof that is array(id_son=>id_parent, ...)
getRelativePath($force=0)
Return relative path of a directory on disk.
refreshcachenboffile($all=0)
Refresh value for cachenboffile.
initAsSpecimen()
Initialise an instance with random values.
create($user)
Create record into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
getLibStatut($mode=0)
Return the label of the status.
changeNbOfFiles($value)
Update cache of nb of documents into database.
fetch($id)
Load object in memory from database.
update($user=null, $notrigger=0)
Update database.
Class to manage triggers.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
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($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183