24if (!defined(
'NOTOKENRENEWAL')) {
25 define(
'NOTOKENRENEWAL',
'1');
27if (!defined(
'NOREQUIREMENU')) {
28 define(
'NOREQUIREMENU',
'1');
30if (!defined(
'NOREQUIREAJAX')) {
31 define(
'NOREQUIREAJAX',
'1');
33if (!defined(
'NOREQUIRESOC')) {
34 define(
'NOREQUIRESOC',
'1');
38require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
41$action =
GETPOST(
'action',
'aZ09');
42$element =
GETPOST(
'element',
'alpha');
44$permissiontoread = $user->hasRight(
'ecm',
'read');
63if (isset($action) && !empty($action)) {
66 if ($action ==
'build' && !empty($element) && $permissiontoread) {
67 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
75 $diroutputslash = str_replace(
'\\',
'/', $conf->$element->dir_output);
76 $diroutputslash .=
'/';
79 $disktree =
dol_dir_list($conf->$element->dir_output,
'directories', 1,
'', array(
'^temp$'),
'', 0, 0);
82 $sqltree = $ecmdirstatic->get_full_arbo(0);
89 foreach ($disktree as $dirdesc) {
93 foreach ($sqltree as $dirsqldesc) {
94 if ($conf->$element->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname']) {
100 if (!$dirisindatabase) {
101 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into table ecm_directories, so we add it";
106 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
107 $relativepathtosearchparent = $relativepathmissing;
109 if (preg_match(
'/\//', $relativepathtosearchparent)) {
111 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
112 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
115 $parentdirisindatabase = 0;
116 foreach ($sqltree as $dirsqldesc) {
117 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent) {
118 $parentdirisindatabase = $dirsqldesc[
'id'];
122 if ($parentdirisindatabase > 0) {
123 dol_syslog(
"Yes with id ".$parentdirisindatabase);
125 $fk_parent = $parentdirisindatabase;
136 if ($fk_parent >= 0) {
137 $ecmdirtmp->ref =
'NOTUSEDYET';
139 $ecmdirtmp->description =
'';
140 $ecmdirtmp->fk_parent = $fk_parent;
142 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
145 $id = $ecmdirtmp->create($user);
147 $newdirsql = array(
'id'=>
$id,
148 'id_mere'=>$ecmdirtmp->fk_parent,
149 'label'=>$ecmdirtmp->label,
150 'description'=>$ecmdirtmp->description,
151 'fullrelativename'=>$relativepathmissing);
152 $sqltree[] = $newdirsql;
156 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
159 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
167 foreach ($sqltree as $dirdesc) {
168 $dirtotest = $conf->$element->dir_output.
'/'.$dirdesc[
'fullrelativename'];
170 dol_syslog($dirtotest.
" not found onto disk. We delete from database dir with id=".$dirdesc[
'id']);
171 $ecmdirtmp->id = $dirdesc[
'id'];
172 $ecmdirtmp->delete($user,
'databaseonly');
177 dol_syslog(
"Nb of directories added into database = ".$adirwascreated);
179 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
Class to manage ECM directories.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
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.
dol_is_dir($folder)
Test if filename is a directory.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.