27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
35 $langs->loadLangs(array(
"ecm",
"companies",
"other",
"users",
"orders",
"propal",
"bills",
"contracts"));
38 if ($user->socid) $socid = $user->socid;
42 $socid =
GETPOST(
'socid',
'int');
43 $action =
GETPOST(
'action',
'aZ09');
45 if (!$section) $section = 0;
46 $section_dir =
GETPOST(
'section_dir',
'alpha');
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
"sortfield",
'alpha');
50 $sortorder =
GETPOST(
"sortorder",
'alpha');
52 if (empty($page) || $page == -1) { $page = 0; }
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if (!$sortorder) $sortorder =
"ASC";
57 if (!$sortfield) $sortfield =
"fullname";
62 $result = $ecmdir->fetch($section);
70 $form =
new Form($db);
72 $userstatic =
new User($db);
86 if (
GETPOST(
"sendit",
'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC))
90 if ($ecmdir->id) $relativepath = $ecmdir->getRelativePath();
91 else $relativepath = $section_dir;
92 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
94 if (is_array($_FILES[
'userfile'][
'tmp_name'])) $userfiles = $_FILES[
'userfile'][
'tmp_name'];
95 else $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
97 foreach ($userfiles as $key => $userfile)
99 if (empty($_FILES[
'userfile'][
'tmp_name'][$key]))
102 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
105 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")), null,
'errors');
116 $result = $ecmdir->changeNbOfFiles(
'+');
122 if ($action ==
'confirm_deletefile')
124 if (
GETPOST(
'confirm') ==
'yes')
128 $upload_dir = $conf->ecm->dir_output.($relativepath ?
'/'.$relativepath :
'');
129 $file = $upload_dir.
"/".
GETPOST(
'urlfile',
'alpha');
133 $urlfiletoshow =
GETPOST(
'urlfile',
'alpha');
134 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfiletoshow);
135 setEventMessages($langs->trans(
"FileWasRemoved", $urlfiletoshow), null,
'mesgs');
136 $result = $ecmdir->changeNbOfFiles(
'-');
143 $action =
'file_manager';
147 if ($action ==
'add' && $user->rights->ecm->setup)
149 $ecmdir->ref =
'NOTUSEDYET';
150 $ecmdir->label =
GETPOST(
"label");
151 $ecmdir->description =
GETPOST(
"desc");
153 $id = $ecmdir->create($user);
156 header(
"Location: ".
$_SERVER[
"PHP_SELF"]);
167 if ($action ==
'confirm_deletesection' &&
GETPOST(
'confirm',
'alpha') ==
'yes')
169 $result = $ecmdir->delete($user);
170 setEventMessages($langs->trans(
"ECMSectionWasRemoved", $ecmdir->label), null,
'mesgs');
178 if ($action ==
'refreshmanual')
185 $diroutputslash = str_replace(
'\\',
'/', $conf->ecm->dir_output);
186 $diroutputslash .=
'/';
189 $disktree =
dol_dir_list($conf->ecm->dir_output,
'directories', 1,
'',
'^temp$',
'',
'', 0);
192 $sqltree = $ecmdirstatic->get_full_arbo(0);
199 foreach ($disktree as $dirdesc)
201 $dirisindatabase = 0;
202 foreach ($sqltree as $dirsqldesc)
204 if ($conf->ecm->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname'])
206 $dirisindatabase = 1;
211 if (!$dirisindatabase)
213 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into database so we add it";
219 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
220 $relativepathtosearchparent = $relativepathmissing;
222 if (preg_match(
'/\//', $relativepathtosearchparent))
225 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
226 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
229 $parentdirisindatabase = 0;
230 foreach ($sqltree as $dirsqldesc)
232 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent)
234 $parentdirisindatabase = $dirsqldesc[
'id'];
238 if ($parentdirisindatabase > 0)
240 dol_syslog(
"Yes with id ".$parentdirisindatabase);
242 $fk_parent = $parentdirisindatabase;
255 $ecmdirtmp->ref =
'NOTUSEDYET';
257 $ecmdirtmp->description =
'';
258 $ecmdirtmp->fk_parent = $fk_parent;
260 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
263 $id = $ecmdirtmp->create($user);
266 $newdirsql = array(
'id'=>$id,
267 'id_mere'=>$ecmdirtmp->fk_parent,
268 'label'=>$ecmdirtmp->label,
269 'description'=>$ecmdirtmp->description,
270 'fullrelativename'=>$relativepathmissing);
271 $sqltree[] = $newdirsql;
275 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
278 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
286 foreach ($sqltree as $dirdesc)
288 $dirtotest = $conf->ecm->dir_output.
'/'.$dirdesc[
'fullrelativename'];
291 $ecmdirtmp->id = $dirdesc[
'id'];
292 $ecmdirtmp->delete($user,
'databaseonly');
297 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
303 if ($adirwascreated) $sqltree = null;
314 $maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 466) ? ($_SESSION[
"dol_screenheight"] - 136) : 660;
320 $morejs = array(
'includes/jquery/plugins/blockUI/jquery.blockUI.js',
'core/js/blockUI.js');
321 if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[] =
"includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
323 $moreheadjs .=
'<script type="text/javascript">'.
"\n";
324 $moreheadjs .=
'var indicatorBlockUI = \''.DOL_URL_ROOT.
"/theme/".$conf->theme.
"/img/working.gif".
'\';
'."\n";
325 $moreheadjs .= '</script>
'."\n";
327 llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0);
329 $head = ecm_prepare_dasboard_head('');
330 print dol_get_fiche_head($head, 'index
', $langs->trans("ECMArea").' -
'.$langs->trans("ECMFileManager"), -1, '');
333 // Add filemanager component
335 include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php
';
338 print dol_get_fiche_end();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
dol_is_dir($folder)
Test if filename is a directory.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles= 'addedfile', $savingdocmask= '', $link=null, $trackid= '', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
Class to manage ECM directories.