35 public $element =
'ecm_directories';
40 public $table_element =
'ecm_directories';
45 public $picto =
'folder-open';
70 public $cachenbofdoc = -1;
100 public $cats = array();
105 public $motherof = array();
110 public $forbiddenchars = array(
'<',
'>',
':',
'/',
'\\',
'?',
'*',
'|',
'"');
115 public $forbiddencharsdir = array(
'<',
'>',
':',
'?',
'*',
'|',
'"');
120 public $full_arbo_loaded;
141 global
$conf, $langs;
149 $this->date_c = $now;
150 $this->fk_user_c = $user->id;
151 if ($this->fk_parent <= 0) {
152 $this->fk_parent = 0;
157 $relativepath = $this->label;
158 if ($this->fk_parent > 0) {
160 $parent->fetch($this->fk_parent);
161 $relativepath = $parent->getRelativePath().$relativepath;
163 $relativepath = preg_replace(
'/([\/])+/i',
'/', $relativepath);
167 $cate_arbo = $cat->get_full_arbo(1);
169 foreach ($cate_arbo as $key => $categ) {
170 $path = str_replace($this->forbiddencharsdir,
'_', $categ[
'fullrelativename']);
172 if ($path == $relativepath) {
179 $this->error =
"ErrorDirAlreadyExists";
180 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
186 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ecm_directories(";
189 $sql .=
"fk_parent,";
190 $sql .=
"description,";
191 $sql .=
"cachenbofdoc,";
194 $sql .=
") VALUES (";
195 $sql .=
" '".$this->db->escape($this->label).
"',";
196 $sql .=
" '".$this->db->escape(
$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");
204 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
205 $resql = $this->db->query($sql);
207 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"ecm_directories");
213 $this->error =
"ErrorFailedToCreateDir";
217 $result = $this->
call_trigger(
'MYECMDIR_CREATE', $user);
227 $this->db->rollback();
231 $this->error =
"Error ".$this->db->lasterror();
232 $this->db->rollback();
245 public function update($user =
null, $notrigger = 0)
247 global
$conf, $langs;
252 $this->label = trim($this->label);
254 if ($this->fk_parent <= 0) {
255 $this->fk_parent = 0;
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);
267 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
268 $resql = $this->db->query($sql);
271 $this->error =
"Error ".$this->db->lasterror();
274 if (!$error && !$notrigger) {
276 $result = $this->
call_trigger(
'MYECMDIR_MODIFY', $user);
287 $this->db->rollback();
302 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
303 if (preg_match(
'/[0-9]+/', $value)) {
304 $sql .=
" cachenbofdoc = ".(int) $value;
306 $sql .=
" cachenbofdoc = cachenbofdoc ".preg_replace(
'/[^\-\+]/',
'', $value).
" 1";
308 $sql .=
" WHERE rowid = ".((int) $this->
id);
310 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
311 $resql = $this->db->query($sql);
313 $this->error =
"Error ".$this->db->lasterror();
316 if (preg_match(
'/[0-9]+/', $value)) {
317 $this->cachenbofdoc = (int) $value;
318 } elseif ($value ==
'+') {
319 $this->cachenbofdoc++;
320 } elseif ($value ==
'-') {
321 $this->cachenbofdoc--;
340 $sql .=
" t.fk_parent,";
341 $sql .=
" t.description,";
342 $sql .=
" t.cachenbofdoc,";
343 $sql .=
" t.fk_user_c,";
344 $sql .=
" t.fk_user_m,";
345 $sql .=
" t.date_c as date_c,";
346 $sql .=
" t.tms as date_m";
347 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories as t";
348 $sql .=
" WHERE t.rowid = ".((int) $id);
350 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
351 $resql = $this->db->query($sql);
353 $obj = $this->db->fetch_object($resql);
355 $this->
id = $obj->rowid;
356 $this->
ref = $obj->rowid;
358 $this->label = $obj->label;
359 $this->fk_parent = $obj->fk_parent;
361 $this->cachenbofdoc = (int) $obj->cachenbofdoc;
362 $this->fk_user_m = $obj->fk_user_m;
363 $this->fk_user_c = $obj->fk_user_c;
364 $this->date_c = $this->db->jdate($obj->date_c);
365 $this->date_m = $this->db->jdate($obj->date_m);
372 $this->db->free($resql);
376 $this->error =
"Error ".$this->db->lasterror();
390 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
392 global
$conf, $langs;
393 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
397 $relativepath =
'__MUST_NOT_EXIST__';
398 if ($mode !=
'databaseonly') {
402 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
406 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
407 $sql .=
" WHERE rowid=".((int) $this->
id);
409 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
410 $resql = $this->db->query($sql);
412 $this->db->rollback();
413 $this->error =
"Error ".$this->db->lasterror();
417 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
419 $this->db->rollback();
425 $file =
'__MUST_NOT_EXIST__';
426 if ($mode !=
'databaseonly') {
427 $file =
$conf->ecm->dir_output.
"/".$relativepath;
428 if ($deletedirrecursive) {
438 $this->error =
'ErrorFailToDeleteDir';
439 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
440 $this->db->rollback();
463 $this->label =
'MyDirectory';
464 $this->fk_parent = 0;
481 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
483 global $langs, $hookmanager;
487 $newref = $this->ref;
488 $label =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly') . $langs->trans(
"ShowECMSection") .
': ' . $newref;
489 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
491 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
492 if ($option ==
'index') {
493 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
495 if ($option ==
'indexexpanded') {
496 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
498 if ($option ==
'indexnotexpanded') {
499 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
503 $result .= $linkstart;
505 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
507 if ($withpicto != 2) {
508 $result .= ($max ?
dol_trunc($newref, $max,
'middle') : $newref);
513 $hookmanager->initHooks(array($this->element .
'dao'));
514 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
515 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
517 $result = $hookmanager->resPrint;
519 $result .= $hookmanager->resPrint;
535 $idtosearch = $this->id;
540 foreach ($this->cats as $key => $val) {
541 if ($this->cats[$key][
'id'] == $idtosearch) {
548 if ($cursorindex >= 0) {
552 $idtosearch = $this->cats[$cursorindex][
'id_mere'];
555 }
while ($cursorindex >= 0 && !empty($idtosearch) && $i < 100);
571 $this->motherof = array();
574 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
575 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories";
576 $sql .=
" WHERE fk_parent != 0";
577 $sql .=
" AND entity = ".$conf->entity;
579 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
580 $resql = $this->db->query($sql);
583 while ($obj = $this->db->fetch_object($resql)) {
584 $this->motherof[$obj->id_son] = $obj->id_parent;
647 if (empty($force) && !empty($this->full_arbo_loaded)) {
655 $sql =
"SELECT c.rowid as rowid, c.label as label,";
656 $sql .=
" c.description as description, c.cachenbofdoc,";
657 $sql .=
" c.fk_user_c,";
658 $sql .=
" c.date_c,";
659 $sql .=
" u.login as login_c,";
660 $sql .=
" u.statut as statut_c,";
661 $sql .=
" ca.rowid as rowid_fille";
662 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
663 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
664 $sql .=
" ON c.rowid = ca.fk_parent";
665 $sql .=
" WHERE c.fk_user_c = u.rowid";
666 $sql .=
" AND c.entity = ".$conf->entity;
667 $sql .=
" ORDER BY c.label, c.rowid";
669 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
670 $resql = $this->db->query($sql);
672 $this->cats = array();
675 while ($obj = $this->db->fetch_object($resql)) {
676 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
677 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
678 $this->cats[$obj->rowid][
'label'] = $obj->label;
679 $this->cats[$obj->rowid][
'description'] = $obj->description;
680 $this->cats[$obj->rowid][
'cachenbofdoc'] = (int) $obj->cachenbofdoc;
681 $this->cats[$obj->rowid][
'date_c'] = $this->db->jdate($obj->date_c);
682 $this->cats[$obj->rowid][
'fk_user_c'] = (int) $obj->fk_user_c;
683 $this->cats[$obj->rowid][
'statut_c'] = (int) $obj->statut_c;
684 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
686 if (!empty($obj->rowid_fille)) {
687 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
688 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
690 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
693 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
704 foreach ($this->cats as $key => $val) {
705 if (isset($this->motherof[$key])) {
711 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0);
712 $this->full_arbo_loaded = 1;
728 if (!empty($this->cats[$id_categ][
'id_mere'])) {
729 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
730 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
731 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
732 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
733 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
734 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
736 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
737 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
738 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
741 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
745 if ($protection > 20) {
748 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
749 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
764 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
767 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
773 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
774 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
776 $sql .=
" WHERE rowid = ".((int) $this->
id);
778 $sql .=
" WHERE entity = ".$conf->entity;
781 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
782 $resql = $this->db->query($sql);
784 $this->cachenbofdoc = count($filelist);
785 return $this->cachenbofdoc;
787 $this->error =
"Error ".$this->db->lasterror();
808 global $langs,
$conf;
810 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
812 $result = $interface->run_triggers($triggerName, $this, $user, $langs,
$conf);
814 if (!empty($this->errors)) {
815 $this->errors = array_merge($this->errors, $interface->errors);
817 $this->errors = $interface->errors;
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...
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...
get_full_arbo($force=0)
Reconstruit l'arborescence des categories sous la forme d'un tableau à partir de la base de donnée Re...
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...
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_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_now($mode='auto')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...