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();
302 if ($value ==
'database') {
303 $relativepath = $conf->ecm->dir_output .
'/' . $this->
getRelativePath();
304 $relativepath = preg_replace(
'/^' . preg_quote(DOL_DATA_ROOT,
'/') .
'/',
'', $relativepath);
305 $relativepath = trim($relativepath,
'/');
308 $sql =
"SELECT COUNT(*) AS nb";
309 $sql .=
" FROM " . $this->db->prefix() .
"ecm_files";
310 $sql .=
" WHERE filepath = '" . $this->db->escape($relativepath) .
"'";
312 dol_syslog(get_class($this) .
"::changeNbOfFiles - Get nb file in relative path", LOG_DEBUG);
313 $resql = $this->db->query($sql);
315 $this->error =
"Error " . $this->db->lasterror();
319 if ($obj = $this->db->fetch_object($resql)) {
320 $value = (int) $obj->nb;
326 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
327 if (preg_match(
'/[0-9]+/', $value)) {
328 $sql .=
" cachenbofdoc = ".(int) $value;
330 $sql .=
" cachenbofdoc = cachenbofdoc " . preg_replace(
'/[^\-]/',
'', $value) .
" 1";
332 $sql .=
" WHERE rowid = ".((int) $this->
id);
334 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
335 $resql = $this->db->query($sql);
337 $this->error =
"Error ".$this->db->lasterror();
340 if (preg_match(
'/[0-9]+/', $value)) {
341 $this->cachenbofdoc = (int) $value;
342 } elseif ($value ==
'+') {
343 $this->cachenbofdoc++;
344 } elseif ($value ==
'-') {
345 $this->cachenbofdoc--;
364 $sql .=
" t.fk_parent,";
365 $sql .=
" t.description,";
366 $sql .=
" t.cachenbofdoc,";
367 $sql .=
" t.fk_user_c,";
368 $sql .=
" t.fk_user_m,";
369 $sql .=
" t.date_c as date_c,";
370 $sql .=
" t.tms as date_m";
371 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories as t";
372 $sql .=
" WHERE t.rowid = ".((int) $id);
374 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
375 $resql = $this->db->query($sql);
377 $obj = $this->db->fetch_object($resql);
379 $this->
id = $obj->rowid;
380 $this->
ref = $obj->rowid;
382 $this->label = $obj->label;
383 $this->fk_parent = $obj->fk_parent;
385 $this->cachenbofdoc = $obj->cachenbofdoc;
386 $this->fk_user_m = $obj->fk_user_m;
387 $this->fk_user_c = $obj->fk_user_c;
388 $this->date_c = $this->db->jdate($obj->date_c);
389 $this->date_m = $this->db->jdate($obj->date_m);
396 $this->db->free($resql);
400 $this->error =
"Error ".$this->db->lasterror();
414 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
416 global $conf, $langs;
417 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
421 if ($mode !=
'databaseonly') {
425 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
429 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
430 $sql .=
" WHERE rowid=".((int) $this->
id);
432 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
433 $resql = $this->db->query($sql);
435 $this->db->rollback();
436 $this->error =
"Error ".$this->db->lasterror();
440 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
442 $this->db->rollback();
448 if ($mode !=
'databaseonly') {
449 $file = $conf->ecm->dir_output.
"/".$relativepath;
450 if ($deletedirrecursive) {
460 $this->error =
'ErrorFailToDeleteDir';
461 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
462 $this->db->rollback();
485 $this->label =
'MyDirectory';
486 $this->fk_parent = 0;
503 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
505 global $langs, $hookmanager;
509 $newref = $this->ref;
510 $label = $langs->trans(
"ShowECMSection").
': '.$newref;
511 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
513 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
514 if ($option ==
'index') {
515 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
517 if ($option ==
'indexexpanded') {
518 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
520 if ($option ==
'indexnotexpanded') {
521 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
528 $result .= $linkstart;
530 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
532 if ($withpicto != 2) {
533 $result .= ($max ?
dol_trunc($newref, $max,
'middle') : $newref);
538 $hookmanager->initHooks(array($this->element .
'dao'));
539 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
540 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
542 $result = $hookmanager->resPrint;
544 $result .= $hookmanager->resPrint;
560 $idtosearch = $this->id;
565 foreach ($this->cats as $key => $val) {
566 if ($this->cats[$key][
'id'] == $idtosearch) {
573 if ($cursorindex >= 0) {
577 $idtosearch = $this->cats[$cursorindex][
'id_mere'];
580 }
while ($cursorindex >= 0 && !empty($idtosearch) && $i < 100);
596 $this->motherof = array();
599 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
600 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_directories";
601 $sql .=
" WHERE fk_parent != 0";
602 $sql .=
" AND entity = ".$conf->entity;
604 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
605 $resql = $this->db->query($sql);
608 while ($obj = $this->db->fetch_object($resql)) {
609 $this->motherof[$obj->id_son] = $obj->id_parent;
671 if (empty($force) && !empty($this->full_arbo_loaded)) {
679 $sql =
"SELECT c.rowid as rowid, c.label as label,";
680 $sql .=
" c.description as description, c.cachenbofdoc,";
681 $sql .=
" c.fk_user_c,";
682 $sql .=
" c.date_c,";
683 $sql .=
" u.login as login_c,";
684 $sql .=
" u.statut as statut_c,";
685 $sql .=
" ca.rowid as rowid_fille";
686 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
687 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
688 $sql .=
" ON c.rowid = ca.fk_parent";
689 $sql .=
" WHERE c.fk_user_c = u.rowid";
690 $sql .=
" AND c.entity = ".$conf->entity;
691 $sql .=
" ORDER BY c.label, c.rowid";
693 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
694 $resql = $this->db->query($sql);
696 $this->cats = array();
699 while ($obj = $this->db->fetch_object($resql)) {
700 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
701 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
702 $this->cats[$obj->rowid][
'label'] = $obj->label;
703 $this->cats[$obj->rowid][
'description'] = $obj->description;
704 $this->cats[$obj->rowid][
'cachenbofdoc'] = $obj->cachenbofdoc;
705 $this->cats[$obj->rowid][
'date_c'] = $this->db->jdate($obj->date_c);
706 $this->cats[$obj->rowid][
'fk_user_c'] = (int) $obj->fk_user_c;
707 $this->cats[$obj->rowid][
'statut_c'] = (int) $obj->statut_c;
708 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
710 if (!empty($obj->rowid_fille)) {
711 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
712 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
714 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
717 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
728 foreach ($this->cats as $key => $val) {
729 if (isset($this->motherof[$key])) {
735 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc',
true,
false);
736 $this->full_arbo_loaded = 1;
752 if (!empty($this->cats[$id_categ][
'id_mere'])) {
753 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
754 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
755 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
756 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
757 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
758 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
760 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
761 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
762 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
765 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
769 if ($protection > 20) {
772 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
773 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
788 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
791 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
797 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
798 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
800 $sql .=
" WHERE rowid = ".((int) $this->
id);
802 $sql .=
" WHERE entity = ".$conf->entity;
805 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
806 $resql = $this->db->query($sql);
808 $this->cachenbofdoc = count($filelist);
809 return $this->cachenbofdoc;
811 $this->error =
"Error ".$this->db->lasterror();
832 global $langs, $conf;
834 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
836 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
838 if (!empty($this->errors)) {
839 $this->errors = array_merge($this->errors, $interface->errors);
841 $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...