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;
106 if (is_array($_FILES[
'userfile'])) {
107 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
108 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
110 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
114 foreach ($userfiles as $key => $userfile) {
115 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
117 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
120 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
127 $res =
dol_add_file_process($upload_dir, $overwritefile, 1,
'userfile',
'',
null,
'', $generatethumbs);
129 $result = $ecmdir->changeNbOfFiles(
'+');
135 if ($action ==
'confirm_deletefile') {
136 if (
GETPOST(
'confirm') ==
'yes') {
139 $upload_dir = $conf->ecm->dir_output.($relativepath ?
'/'.$relativepath :
'');
140 $file = $upload_dir.
"/".
GETPOST(
'urlfile',
'alpha');
143 $urlfiletoshow =
GETPOST(
'urlfile',
'alpha');
144 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfiletoshow);
145 setEventMessages($langs->trans(
"FileWasRemoved", $urlfiletoshow),
null,
'mesgs');
146 $result = $ecmdir->changeNbOfFiles(
'-');
153 $action =
'file_manager';
157 if ($action ==
'add' && $user->rights->ecm->setup) {
158 $ecmdir->ref =
'NOTUSEDYET';
159 $ecmdir->label =
GETPOST(
"label");
160 $ecmdir->description =
GETPOST(
"desc");
162 $id = $ecmdir->create($user);
164 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
175 if ($action ==
'confirm_deletesection' &&
GETPOST(
'confirm',
'alpha') ==
'yes') {
176 $result = $ecmdir->delete($user);
177 setEventMessages($langs->trans(
"ECMSectionWasRemoved", $ecmdir->label),
null,
'mesgs');
185 if ($action ==
'refreshmanual') {
191 $diroutputslash = str_replace(
'\\',
'/', $conf->ecm->dir_output);
192 $diroutputslash .=
'/';
195 $disktree =
dol_dir_list($conf->ecm->dir_output,
'directories', 1,
'',
'^temp$',
'',
'', 0);
198 $sqltree = $ecmdirstatic->get_full_arbo(0);
205 foreach ($disktree as $dirdesc) {
206 $dirisindatabase = 0;
207 foreach ($sqltree as $dirsqldesc) {
208 if ($conf->ecm->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname']) {
209 $dirisindatabase = 1;
214 if (!$dirisindatabase) {
215 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into database so we add it";
221 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
222 $relativepathtosearchparent = $relativepathmissing;
224 if (preg_match(
'/\//', $relativepathtosearchparent)) {
226 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
227 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
230 $parentdirisindatabase = 0;
231 foreach ($sqltree as $dirsqldesc) {
232 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent) {
233 $parentdirisindatabase = $dirsqldesc[
'id'];
237 if ($parentdirisindatabase > 0) {
238 dol_syslog(
"Yes with id ".$parentdirisindatabase);
240 $fk_parent = $parentdirisindatabase;
251 if ($fk_parent >= 0) {
252 $ecmdirtmp->ref =
'NOTUSEDYET';
254 $ecmdirtmp->description =
'';
255 $ecmdirtmp->fk_parent = $fk_parent;
257 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
260 $id = $ecmdirtmp->create($user);
262 $newdirsql = array(
'id'=>$id,
263 'id_mere'=>$ecmdirtmp->fk_parent,
264 'label'=>$ecmdirtmp->label,
265 'description'=>$ecmdirtmp->description,
266 'fullrelativename'=>$relativepathmissing);
267 $sqltree[] = $newdirsql;
271 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
274 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
282 foreach ($sqltree as $dirdesc) {
283 $dirtotest = $conf->ecm->dir_output.
'/'.$dirdesc[
'fullrelativename'];
285 $ecmdirtmp->id = $dirdesc[
'id'];
286 $ecmdirtmp->delete($user,
'databaseonly');
291 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
297 if ($adirwascreated) {
310 $maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 466) ? ($_SESSION[
"dol_screenheight"] - 136) : 660;
316 $morejs = array(
'includes/jquery/plugins/blockUI/jquery.blockUI.js',
'core/js/blockUI.js');
317 if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
318 $morejs[] =
"includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
321 $moreheadjs .=
'<script type="text/javascript">'.
"\n";
322 $moreheadjs .=
'var indicatorBlockUI = \''.DOL_URL_ROOT.
"/theme/".$conf->theme.
"/img/working.gif".
'\';
'."\n";
323 $moreheadjs .= '</script>
'."\n";
325 llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0);
327 $head = ecm_prepare_dasboard_head('');
328 print dol_get_fiche_head($head, 'index
', '', -1, '');
331 // Add filemanager component
333 include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php
';
336 print dol_get_fiche_end();