33 public $element =
'ecm_directories';
38 public $table_element =
'ecm_directories';
43 public $picto =
'folder-open';
68 public $cachenbofdoc = -1;
98 public $cats = array();
103 public $motherof = array();
108 public $forbiddenchars = array(
'<',
'>',
':',
'/',
'\\',
'?',
'*',
'|',
'"');
113 public $forbiddencharsdir = array(
'<',
'>',
':',
'?',
'*',
'|',
'"');
118 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");
211 $error++; $this->error =
"ErrorFailedToCreateDir";
215 $result = $this->
call_trigger(
'MYECMDIR_CREATE', $user);
225 $this->db->rollback();
229 $this->error =
"Error ".$this->db->lasterror();
230 $this->db->rollback();
243 public function update($user =
null, $notrigger = 0)
245 global $conf, $langs;
250 $this->label = trim($this->label);
252 if ($this->fk_parent <= 0) {
253 $this->fk_parent = 0;
259 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
260 $sql .=
" label = '".$this->db->escape($this->label).
"',";
261 $sql .=
" fk_parent = ".($this->fk_parent > 0 ? ((int) $this->fk_parent) :
"null").
",";
262 $sql .=
" description = '".$this->db->escape($this->
description).
"'";
263 $sql .=
" WHERE rowid = ".((int) $this->
id);
265 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
266 $resql = $this->db->query($sql);
269 $this->error =
"Error ".$this->db->lasterror();
272 if (!$error && !$notrigger) {
274 $result = $this->
call_trigger(
'MYECMDIR_MODIFY', $user);
285 $this->db->rollback();
301 if ($value ==
'database') {
302 $relativepath = $conf->ecm->dir_output .
'/' . $this->
getRelativePath();
303 $relativepath = preg_replace(
'/^' . preg_quote(DOL_DATA_ROOT,
'/') .
'/',
'', $relativepath);
304 $relativepath = trim($relativepath,
'/');
307 $sql =
"SELECT COUNT(*) AS nb";
308 $sql .=
" FROM " . $this->db->prefix() .
"ecm_files";
309 $sql .=
" WHERE filepath = '" . $this->db->escape($relativepath) .
"'";
311 dol_syslog(get_class($this) .
"::changeNbOfFiles - Get nb file in relative path", LOG_DEBUG);
312 $resql = $this->db->query($sql);
314 $this->error =
"Error " . $this->db->lasterror();
318 if ($obj = $this->db->fetch_object($resql)) {
319 $value = (int) $obj->nb;
325 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
326 if (preg_match(
'/[0-9]+/', $value)) {
327 $sql .=
" cachenbofdoc = ".(int) $value;
329 $sql .=
" cachenbofdoc = cachenbofdoc " . preg_replace(
'/[^\-]/',
'', $value) .
" 1";
331 $sql .=
" WHERE rowid = ".((int) $this->
id);
333 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
334 $resql = $this->db->query($sql);
336 $this->error =
"Error ".$this->db->lasterror();
339 if (preg_match(
'/[0-9]+/', $value)) {
340 $this->cachenbofdoc = (int) $value;
341 } elseif ($value ==
'+') {
342 $this->cachenbofdoc++;
343 } elseif ($value ==
'-') {
344 $this->cachenbofdoc--;
363 $sql .=
" t.fk_parent,";
364 $sql .=
" t.description,";
365 $sql .=
" t.cachenbofdoc,";
366 $sql .=
" t.fk_user_c,";
367 $sql .=
" t.fk_user_m,";
368 $sql .=
" t.date_c as date_c,";
369 $sql .=
" t.tms as date_m";
370 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories as t";
371 $sql .=
" WHERE t.rowid = ".((int) $id);
373 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
374 $resql = $this->db->query($sql);
376 $obj = $this->db->fetch_object($resql);
378 $this->
id = $obj->rowid;
379 $this->
ref = $obj->rowid;
381 $this->label = $obj->label;
382 $this->fk_parent = $obj->fk_parent;
384 $this->cachenbofdoc = $obj->cachenbofdoc;
385 $this->fk_user_m = $obj->fk_user_m;
386 $this->fk_user_c = $obj->fk_user_c;
387 $this->date_c = $this->db->jdate($obj->date_c);
388 $this->date_m = $this->db->jdate($obj->date_m);
395 $this->db->free($resql);
399 $this->error =
"Error ".$this->db->lasterror();
413 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
415 global $conf, $langs;
416 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
420 if ($mode !=
'databaseonly') {
424 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
428 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
429 $sql .=
" WHERE rowid=".((int) $this->
id);
431 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
432 $resql = $this->db->query($sql);
434 $this->db->rollback();
435 $this->error =
"Error ".$this->db->lasterror();
439 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
441 $this->db->rollback();
447 if ($mode !=
'databaseonly') {
448 $file = $conf->ecm->dir_output.
"/".$relativepath;
449 if ($deletedirrecursive) {
459 $this->error =
'ErrorFailToDeleteDir';
460 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
461 $this->db->rollback();
484 $this->label =
'MyDirectory';
485 $this->fk_parent =
'0';
500 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
502 global $langs, $hookmanager;
506 $newref = $this->ref;
507 $label = $langs->trans(
"ShowECMSection").
': '.$newref;
508 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
510 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
511 if ($option ==
'index') {
512 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
514 if ($option ==
'indexexpanded') {
515 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
517 if ($option ==
'indexnotexpanded') {
518 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
525 $result .= $linkstart;
527 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
529 if ($withpicto != 2) {
530 $result .= ($max ?
dol_trunc($newref, $max,
'middle') : $newref);
535 $hookmanager->initHooks(array($this->element .
'dao'));
536 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
537 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
539 $result = $hookmanager->resPrint;
541 $result .= $hookmanager->resPrint;
557 $idtosearch = $this->id;
562 foreach ($this->cats as $key => $val) {
563 if ($this->cats[$key][
'id'] == $idtosearch) {
570 if ($cursorindex >= 0) {
574 $idtosearch = $this->cats[$cursorindex][
'id_mere'];
577 }
while ($cursorindex >= 0 && !empty($idtosearch) && $i < 100);
593 $this->motherof = array();
596 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
597 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories";
598 $sql .=
" WHERE fk_parent != 0";
599 $sql .=
" AND entity = ".$conf->entity;
601 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
602 $resql = $this->db->query($sql);
605 while ($obj = $this->db->fetch_object($resql)) {
606 $this->motherof[$obj->id_son] = $obj->id_parent;
624 return $this->
LibStatut($this->status, $mode);
668 if (empty($force) && !empty($this->full_arbo_loaded)) {
676 $sql =
"SELECT c.rowid as rowid, c.label as label,";
677 $sql .=
" c.description as description, c.cachenbofdoc,";
678 $sql .=
" c.fk_user_c,";
679 $sql .=
" c.date_c,";
680 $sql .=
" u.login as login_c,";
681 $sql .=
" u.statut as statut_c,";
682 $sql .=
" ca.rowid as rowid_fille";
683 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
684 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
685 $sql .=
" ON c.rowid = ca.fk_parent";
686 $sql .=
" WHERE c.fk_user_c = u.rowid";
687 $sql .=
" AND c.entity = ".$conf->entity;
688 $sql .=
" ORDER BY c.label, c.rowid";
690 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
691 $resql = $this->db->query($sql);
693 $this->cats = array();
696 while ($obj = $this->db->fetch_object($resql)) {
697 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
698 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
699 $this->cats[$obj->rowid][
'label'] = $obj->label;
700 $this->cats[$obj->rowid][
'description'] = $obj->description;
701 $this->cats[$obj->rowid][
'cachenbofdoc'] = $obj->cachenbofdoc;
702 $this->cats[$obj->rowid][
'date_c'] = $this->db->jdate($obj->date_c);
703 $this->cats[$obj->rowid][
'fk_user_c'] = (int) $obj->fk_user_c;
704 $this->cats[$obj->rowid][
'statut_c'] = (int) $obj->statut_c;
705 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
707 if (!empty($obj->rowid_fille)) {
708 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
709 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
711 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
714 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
725 foreach ($this->cats as $key => $val) {
726 if (isset($this->motherof[$key])) {
732 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc',
true,
false);
733 $this->full_arbo_loaded = 1;
749 if (!empty($this->cats[$id_categ][
'id_mere'])) {
750 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
751 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
752 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
753 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
754 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
755 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
757 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
758 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
759 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
762 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
766 if ($protection > 20) {
769 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
770 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
785 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
788 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
794 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
795 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
797 $sql .=
" WHERE rowid = ".((int) $this->
id);
799 $sql .=
" WHERE entity = ".$conf->entity;
802 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
803 $resql = $this->db->query($sql);
805 $this->cachenbofdoc = count($filelist);
806 return $this->cachenbofdoc;
808 $this->error =
"Error ".$this->db->lasterror();
829 global $langs, $conf;
831 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
833 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
835 if (!empty($this->errors)) {
836 $this->errors = array_merge($this->errors, $interface->errors);
838 $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 $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($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.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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)
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 second index function, which produces ascending (default) or descending output...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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...