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();
303 if ($value ==
'database') {
305 $relativepath = preg_replace(
'/^' . preg_quote(DOL_DATA_ROOT,
'/') .
'/',
'', $relativepath);
306 $relativepath = trim($relativepath,
'/');
309 $sql =
"SELECT COUNT(*) AS nb";
310 $sql .=
" FROM " . $this->db->prefix() .
"ecm_files";
311 $sql .=
" WHERE filepath = '" . $this->db->escape($relativepath) .
"'";
313 dol_syslog(get_class($this) .
"::changeNbOfFiles - Get nb file in relative path", LOG_DEBUG);
314 $resql = $this->db->query($sql);
316 $this->error =
"Error " . $this->db->lasterror();
320 if ($obj = $this->db->fetch_object($resql)) {
321 $value = (int) $obj->nb;
327 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
328 if (preg_match(
'/[0-9]+/', $value)) {
329 $sql .=
" cachenbofdoc = ".(int) $value;
331 $sql .=
" cachenbofdoc = cachenbofdoc ".preg_replace(
'/[^\-\+]/',
'', $value).
" 1";
333 $sql .=
" WHERE rowid = ".((int) $this->
id);
335 dol_syslog(get_class($this).
"::changeNbOfFiles", LOG_DEBUG);
336 $resql = $this->db->query($sql);
338 $this->error =
"Error ".$this->db->lasterror();
341 if (preg_match(
'/[0-9]+/', $value)) {
342 $this->cachenbofdoc = (int) $value;
343 } elseif ($value ==
'+') {
344 $this->cachenbofdoc++;
345 } elseif ($value ==
'-') {
346 $this->cachenbofdoc--;
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);
375 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
376 $resql = $this->db->query($sql);
378 $obj = $this->db->fetch_object($resql);
380 $this->
id = $obj->rowid;
381 $this->
ref = $obj->rowid;
383 $this->label = $obj->label;
384 $this->fk_parent = $obj->fk_parent;
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);
397 $this->db->free($resql);
401 $this->error =
"Error ".$this->db->lasterror();
415 public function delete($user, $mode =
'all', $deletedirrecursive = 0)
417 global
$conf, $langs;
418 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
422 $relativepath =
'__MUST_NOT_EXIST__';
423 if ($mode !=
'databaseonly') {
427 dol_syslog(get_class($this).
"::delete remove directory id=".$this->
id.
" mode=".$mode.(($mode ==
'databaseonly') ?
'' :
' relativepath='.$relativepath));
431 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_directories";
432 $sql .=
" WHERE rowid=".((int) $this->
id);
434 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
435 $resql = $this->db->query($sql);
437 $this->db->rollback();
438 $this->error =
"Error ".$this->db->lasterror();
442 $result = $this->
call_trigger(
'MYECMDIR_DELETE', $user);
444 $this->db->rollback();
450 $file =
'__MUST_NOT_EXIST__';
451 if ($mode !=
'databaseonly') {
452 $file =
$conf->ecm->dir_output.
"/".$relativepath;
453 if ($deletedirrecursive) {
463 $this->error =
'ErrorFailToDeleteDir';
464 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
465 $this->db->rollback();
488 $this->label =
'MyDirectory';
489 $this->fk_parent = 0;
506 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $more =
'', $notooltip = 0)
508 global $langs, $hookmanager;
512 $newref = $this->ref;
513 $label =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly') . $langs->trans(
"ShowECMSection") .
': ' . $newref;
514 $linkclose =
'"'.($more ?
' '.$more :
'').
' title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
516 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/dir_card.php?section='.$this->
id.$linkclose;
517 if ($option ==
'index') {
518 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=true'.$linkclose;
520 if ($option ==
'indexexpanded') {
521 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php?section='.$this->
id.
'&sectionexpand=false'.$linkclose;
523 if ($option ==
'indexnotexpanded') {
524 $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;
672 if (empty($force) && !empty($this->full_arbo_loaded)) {
680 $sql =
"SELECT c.rowid as rowid, c.label as label,";
681 $sql .=
" c.description as description, c.cachenbofdoc,";
682 $sql .=
" c.fk_user_c,";
683 $sql .=
" c.date_c,";
684 $sql .=
" u.login as login_c,";
685 $sql .=
" u.statut as statut_c,";
686 $sql .=
" ca.rowid as rowid_fille";
687 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"ecm_directories as c";
688 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ecm_directories as ca";
689 $sql .=
" ON c.rowid = ca.fk_parent";
690 $sql .=
" WHERE c.fk_user_c = u.rowid";
691 $sql .=
" AND c.entity = ".$conf->entity;
692 $sql .=
" ORDER BY c.label, c.rowid";
694 dol_syslog(get_class($this).
"::get_full_arbo", LOG_DEBUG);
695 $resql = $this->db->query($sql);
697 $this->cats = array();
700 while ($obj = $this->db->fetch_object($resql)) {
701 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
702 $this->cats[$obj->rowid][
'id_mere'] = (isset($this->motherof[$obj->rowid]) ? $this->motherof[$obj->rowid] :
'');
703 $this->cats[$obj->rowid][
'label'] = $obj->label;
704 $this->cats[$obj->rowid][
'description'] = $obj->description;
705 $this->cats[$obj->rowid][
'cachenbofdoc'] = (int) $obj->cachenbofdoc;
706 $this->cats[$obj->rowid][
'date_c'] = $this->db->jdate($obj->date_c);
707 $this->cats[$obj->rowid][
'fk_user_c'] = (int) $obj->fk_user_c;
708 $this->cats[$obj->rowid][
'statut_c'] = (int) $obj->statut_c;
709 $this->cats[$obj->rowid][
'login_c'] = $obj->login_c;
711 if (!empty($obj->rowid_fille)) {
712 if (isset($this->cats[$obj->rowid][
'id_children']) && is_array($this->cats[$obj->rowid][
'id_children'])) {
713 $newelempos = count($this->cats[$obj->rowid][
'id_children']);
715 $this->cats[$obj->rowid][
'id_children'][$newelempos] = $obj->rowid_fille;
718 $this->cats[$obj->rowid][
'id_children'] = array($obj->rowid_fille);
729 foreach ($this->cats as $key => $val) {
730 if (isset($this->motherof[$key])) {
736 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0);
737 $this->full_arbo_loaded = 1;
753 if (!empty($this->cats[$id_categ][
'id_mere'])) {
754 $this->cats[$id_categ][
'fullpath'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullpath'];
755 $this->cats[$id_categ][
'fullpath'] .=
'_'.$id_categ;
756 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fullrelativename'];
757 $this->cats[$id_categ][
'fullrelativename'] .=
'/'.$this->cats[$id_categ][
'label'];
758 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$this->cats[$id_categ][
'id_mere']][
'fulllabel'];
759 $this->cats[$id_categ][
'fulllabel'] .=
' >> '.$this->cats[$id_categ][
'label'];
761 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
762 $this->cats[$id_categ][
'fullrelativename'] = $this->cats[$id_categ][
'label'];
763 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
766 $this->cats[$id_categ][
'level'] = strlen(preg_replace(
'/([^_])/i',
'', $this->cats[$id_categ][
'fullpath']));
770 if ($protection > 20) {
773 if (isset($this->cats[$id_categ][
'id_children']) && is_array($this->cats[$id_categ][
'id_children'])) {
774 foreach ($this->cats[$id_categ][
'id_children'] as $key => $val) {
789 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
792 $filelist =
dol_dir_list($dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$');
798 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories SET";
799 $sql .=
" cachenbofdoc = '".count($filelist).
"'";
801 $sql .=
" WHERE rowid = ".((int) $this->
id);
803 $sql .=
" WHERE entity = ".$conf->entity;
806 dol_syslog(get_class($this).
"::refreshcachenboffile", LOG_DEBUG);
807 $resql = $this->db->query($sql);
809 $this->cachenbofdoc = count($filelist);
810 return $this->cachenbofdoc;
812 $this->error =
"Error ".$this->db->lasterror();
833 global $langs,
$conf;
835 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
837 $result = $interface->run_triggers($triggerName, $this, $user, $langs,
$conf);
839 if (!empty($this->errors)) {
840 $this->errors = array_merge($this->errors, $interface->errors);
842 $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($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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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 the value of a given key, which produces ascending (default) or descending out...
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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...