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 $socid =
GETPOST(
'socid',
'int');
39 $action =
GETPOST(
'action',
'aZ09');
44 $section_dir =
GETPOST(
'section_dir',
'alpha');
45 $overwritefile =
GETPOST(
'overwritefile',
'int');
47 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
48 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
49 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
51 if (empty($page) || $page == -1) {
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
66 $result = $ecmdir->fetch($section);
75 $userstatic =
new User($db);
81 $socid = $user->socid;
95 if (
GETPOST(
"sendit",
'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
99 $relativepath = $ecmdir->getRelativePath();
101 $relativepath = $section_dir;
103 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
105 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
106 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
108 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
111 foreach ($userfiles as $key => $userfile) {
112 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
114 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
117 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")), null,
'errors');
124 $res =
dol_add_file_process($upload_dir, $overwritefile, 1,
'userfile',
'', null,
'', $generatethumbs);
126 $result = $ecmdir->changeNbOfFiles(
'+');
132 if ($action ==
'confirm_deletefile') {
133 if (
GETPOST(
'confirm') ==
'yes') {
136 $upload_dir = $conf->ecm->dir_output.($relativepath ?
'/'.$relativepath :
'');
137 $file = $upload_dir.
"/".
GETPOST(
'urlfile',
'alpha');
140 $urlfiletoshow =
GETPOST(
'urlfile',
'alpha');
141 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfiletoshow);
142 setEventMessages($langs->trans(
"FileWasRemoved", $urlfiletoshow), null,
'mesgs');
143 $result = $ecmdir->changeNbOfFiles(
'-');
150 $action =
'file_manager';
154 if ($action ==
'add' && $user->rights->ecm->setup) {
155 $ecmdir->ref =
'NOTUSEDYET';
156 $ecmdir->label =
GETPOST(
"label");
157 $ecmdir->description =
GETPOST(
"desc");
159 $id = $ecmdir->create($user);
161 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
172 if ($action ==
'confirm_deletesection' &&
GETPOST(
'confirm',
'alpha') ==
'yes') {
173 $result = $ecmdir->delete($user);
174 setEventMessages($langs->trans(
"ECMSectionWasRemoved", $ecmdir->label), null,
'mesgs');
182 if ($action ==
'refreshmanual') {
188 $diroutputslash = str_replace(
'\\',
'/', $conf->ecm->dir_output);
189 $diroutputslash .=
'/';
192 $disktree =
dol_dir_list($conf->ecm->dir_output,
'directories', 1,
'',
'^temp$',
'',
'', 0);
195 $sqltree = $ecmdirstatic->get_full_arbo(0);
202 foreach ($disktree as $dirdesc) {
203 $dirisindatabase = 0;
204 foreach ($sqltree as $dirsqldesc) {
205 if ($conf->ecm->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname']) {
206 $dirisindatabase = 1;
211 if (!$dirisindatabase) {
212 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into database so we add it";
218 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
219 $relativepathtosearchparent = $relativepathmissing;
221 if (preg_match(
'/\//', $relativepathtosearchparent)) {
223 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
224 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
227 $parentdirisindatabase = 0;
228 foreach ($sqltree as $dirsqldesc) {
229 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent) {
230 $parentdirisindatabase = $dirsqldesc[
'id'];
234 if ($parentdirisindatabase > 0) {
235 dol_syslog(
"Yes with id ".$parentdirisindatabase);
237 $fk_parent = $parentdirisindatabase;
248 if ($fk_parent >= 0) {
249 $ecmdirtmp->ref =
'NOTUSEDYET';
251 $ecmdirtmp->description =
'';
252 $ecmdirtmp->fk_parent = $fk_parent;
254 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
257 $id = $ecmdirtmp->create($user);
259 $newdirsql = array(
'id'=>$id,
260 'id_mere'=>$ecmdirtmp->fk_parent,
261 'label'=>$ecmdirtmp->label,
262 'description'=>$ecmdirtmp->description,
263 'fullrelativename'=>$relativepathmissing);
264 $sqltree[] = $newdirsql;
268 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
271 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
279 foreach ($sqltree as $dirdesc) {
280 $dirtotest = $conf->ecm->dir_output.
'/'.$dirdesc[
'fullrelativename'];
282 $ecmdirtmp->id = $dirdesc[
'id'];
283 $ecmdirtmp->delete($user,
'databaseonly');
288 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
294 if ($adirwascreated) {
307 $maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 466) ? ($_SESSION[
"dol_screenheight"] - 136) : 660;
313 $morejs = array(
'includes/jquery/plugins/blockUI/jquery.blockUI.js',
'core/js/blockUI.js');
314 if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
315 $morejs[] =
"includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
318 $moreheadjs .=
'<script type="text/javascript">'.
"\n";
319 $moreheadjs .=
'var indicatorBlockUI = \''.DOL_URL_ROOT.
"/theme/".$conf->theme.
"/img/working.gif".
'\';
'."\n";
320 $moreheadjs .= '</script>
'."\n";
322 llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0);
324 $head = ecm_prepare_dasboard_head('');
325 print dol_get_fiche_head($head, 'index
', '', -1, '');
328 // Add filemanager component
330 include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php
';
333 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.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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 from a POST of a form...
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_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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
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.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.