34 public $element =
'ecm_directories';
39 public $table_element =
'ecm_directories';
44 public $picto =
'folder-open';
69 public $cachenbofdoc = -1;
99 public $cats = array();
104 public $motherof = array();
109 public $forbiddenchars = array(
'<',
'>',
':',
'/',
'\\',
'?',
'*',
'|',
'"');
114 public $forbiddencharsdir = array(
'<',
'>',
':',
'?',
'*',
'|',
'"');
119 public $full_arbo_loaded;
140 global $conf, $langs;
148 $this->date_c = $now;
149 $this->fk_user_c = $user->id;
150 if ($this->fk_parent <= 0) {
151 $this->fk_parent = 0;
156 $relativepath = $this->label;
157 if ($this->fk_parent > 0) {
159 $parent->fetch($this->fk_parent);
160 $relativepath = $parent->getRelativePath().$relativepath;
162 $relativepath = preg_replace(
'/([\/])+/i',
'/', $relativepath);
166 $cate_arbo = $cat->get_full_arbo(1);
168 foreach ($cate_arbo as $key => $categ) {
169 $path = str_replace($this->forbiddencharsdir,
'_', $categ[
'fullrelativename']);
171 if ($path == $relativepath) {
178 $this->error =
"ErrorDirAlreadyExists";
179 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
185 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ecm_directories(";
188 $sql .=
"fk_parent,";
189 $sql .=
"description,";
190 $sql .=
"cachenbofdoc,";
193 $sql .=
") VALUES (";
194 $sql .=
" '".$this->db->escape($this->label).
"',";
195 $sql .=
" '".$this->db->escape($conf->entity).
"',";
196 $sql .=
" ".($this->fk_parent > 0 ? ((int) $this->fk_parent) :
"null").
",";
197 $sql .=
" '".$this->db->escape($this->
description).
"',";
198 $sql .=
" ".((int) $this->cachenbofdoc).
",";
199 $sql .=
" '".$this->db->idate($this->date_c).
"',";
200 $sql .=
" ".($this->fk_user_c > 0 ? ((int) $this->fk_user_c) :
"null");
203 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
204 $resql = $this->db->query($sql);
206 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"ecm_directories");
212 $this->error =
"ErrorFailedToCreateDir";
216 $result = $this->
call_trigger(
'MYECMDIR_CREATE', $user);
226 $this->db->rollback();
230 $this->error =
"Error ".$this->db->lasterror();
231 $this->db->rollback();
244 public function update($user =
null, $notrigger = 0)
246 global $conf, $langs;
251 $this->label = trim($this->label);
253 if ($this->fk_parent <= 0) {
254 $this->fk_parent = 0;
260 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
261 $sql .=
" label = '".$this->db->escape($this->label).
"',";
262 $sql .=
" fk_parent = ".($this->fk_parent > 0 ? ((int) $this->fk_parent) :
"null").
",";
263 $sql .=
" description = '".$this->db->escape($this->
description).
"'";
264 $sql .=
" WHERE rowid = ".((int) $this->
id);
266 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
267 $resql = $this->db->query($sql);
270 $this->error =
"Error ".$this->db->lasterror();
273 if (!$error && !$notrigger) {
275 $result = $this->
call_trigger(
'MYECMDIR_MODIFY', $user);
286 $this->db->rollback();
301 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
302 if (preg_match(
'/[0-9]+/', $value)) {
303 $sql .=
" cachenbofdoc = ".(int) $value;
305 $sql .=
" cachenbofdoc = cachenbofdoc ".$value.
" 1";
307 $sql .=
" WHERE rowid = ".((int) $this->
id);
309 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
310 $resql = $this->db->query($sql);
312 $this->error =
"Error ".$this->db->lasterror();
315 if (preg_match(
'/[0-9]+/', $value)) {
316 $this->cachenbofdoc = (int) $value;
317 } elseif ($value ==
'+') {
318 $this->cachenbofdoc++;
319 } elseif ($value ==
'-') {
320 $this->cachenbofdoc--;
339 $sql .=
" t.fk_parent,";
340 $sql .=
" t.description,";
341 $sql .=
" t.cachenbofdoc,";
342 $sql .=
" t.fk_user_c,";
343 $sql .=
" t.fk_user_m,";
344 $sql .=
" t.date_c as date_c,";
345 $sql .=
" t.tms as date_m";
346 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories as t";
347 $sql .=
" WHERE t.rowid = ".((int) $id);
349 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
350 $resql = $this->db->query($sql);
352 $obj = $this->db->fetch_object($resql);
354 $this->
id = $obj->rowid;
355 $this->
ref = $obj->rowid;
357 $this->label = $obj->label;
358 $this->fk_parent = $obj->fk_parent;
360 $this->cachenbofdoc = $obj->cachenbofdoc;
361 $this->fk_user_m = $obj->fk_user_m;
362 $this->fk_user_c = $obj->fk_user_c;
363 $this->date_c = $this->db->jdate($obj->date_c);
364 $this->date_m = $this->db->jdate($obj->date_m);
371 $this->db->free($resql);
375 $this->error =
"Error ".$this->db->lasterror();
389 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
391 global $conf, $langs;
392 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
396 if ($mode !=
'databaseonly') {
400 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
404 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
405 $sql .=
" WHERE rowid=".((int) $this->
id);
407 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
408 $resql = $this->db->query($sql);
410 $this->db->rollback();
411 $this->error =
"Error ".$this->db->lasterror();
415 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
417 $this->db->rollback();
423 if ($mode !=
'databaseonly') {
424 $file = $conf->ecm->dir_output.
"/".$relativepath;
425 if ($deletedirrecursive) {
435 $this->error =
'ErrorFailToDeleteDir';
436 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
437 $this->db->rollback();
460 $this->label =
'MyDirectory';
461 $this->fk_parent = 0;
478 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
480 global $langs, $hookmanager;
484 $newref = $this->ref;
485 $label = $langs->trans(
"ShowECMSection").
': '.$newref;
486 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
488 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
489 if ($option ==
'index') {
490 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
492 if ($option ==
'indexexpanded') {
493 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
495 if ($option ==
'indexnotexpanded') {
496 $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;
646 if (empty($force) && !empty($this->full_arbo_loaded)) {
654 $sql =
"SELECT c.rowid as rowid, c.label as label,";
655 $sql .=
" c.description as description, c.cachenbofdoc,";
656 $sql .=
" c.fk_user_c,";
657 $sql .=
" c.date_c,";
658 $sql .=
" u.login as login_c,";
659 $sql .=
" u.statut as statut_c,";
660 $sql .=
" ca.rowid as rowid_fille";
661 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
662 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
663 $sql .=
" ON c.rowid = ca.fk_parent";
664 $sql .=
" WHERE c.fk_user_c = u.rowid";
665 $sql .=
" AND c.entity = ".$conf->entity;
666 $sql .=
" ORDER BY c.label, c.rowid";
668 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
669 $resql = $this->db->query($sql);
671 $this->cats = array();
674 while ($obj = $this->db->fetch_object($resql)) {
675 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
676 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
677 $this->cats[$obj->rowid][
'label'] = $obj->label;
678 $this->cats[$obj->rowid][
'description'] = $obj->description;
679 $this->cats[$obj->rowid][
'cachenbofdoc'] = $obj->cachenbofdoc;
680 $this->cats[$obj->rowid][
'date_c'] = $this->db->jdate($obj->date_c);
681 $this->cats[$obj->rowid][
'fk_user_c'] = (int) $obj->fk_user_c;
682 $this->cats[$obj->rowid][
'statut_c'] = (int) $obj->statut_c;
683 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
685 if (!empty($obj->rowid_fille)) {
686 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
687 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
689 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
692 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
703 foreach ($this->cats as $key => $val) {
704 if (isset($this->motherof[$key])) {
710 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc',
true,
false);
711 $this->full_arbo_loaded = 1;
727 if (!empty($this->cats[$id_categ][
'id_mere'])) {
728 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
729 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
730 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
731 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
732 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
733 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
735 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
736 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
737 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
740 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
744 if ($protection > 20) {
747 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
748 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
763 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
766 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
772 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
773 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
775 $sql .=
" WHERE rowid = ".((int) $this->
id);
777 $sql .=
" WHERE entity = ".$conf->entity;
780 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
781 $resql = $this->db->query($sql);
783 $this->cachenbofdoc = count($filelist);
784 return $this->cachenbofdoc;
786 $this->error =
"Error ".$this->db->lasterror();
807 global $langs, $conf;
809 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
811 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
813 if (!empty($this->errors)) {
814 $this->errors = array_merge($this->errors, $interface->errors);
816 $this->errors = $interface->errors;
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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 $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)
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...