25 require
'../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
33 $langs->loadLangs(array(
'ecm',
'companies',
'other'));
35 $action =
GETPOST(
'action',
'alpha');
36 $cancel =
GETPOST(
'cancel',
'aZ09');
37 $backtopage =
GETPOST(
'backtopage',
'alpha');
38 $confirm =
GETPOST(
'confirm',
'alpha');
40 $module =
GETPOST(
'module',
'alpha');
41 $website =
GETPOST(
'website',
'alpha');
42 $pageid =
GETPOST(
'pageid',
'int');
43 if (empty($module)) $module =
'ecm';
46 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
47 $sortfield =
GETPOST(
"sortfield",
'alpha');
48 $sortorder =
GETPOST(
"sortorder",
'alpha');
50 if (empty($page) || $page == -1) { $page = 0; }
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if (!$sortorder) $sortorder =
"ASC";
55 if (!$sortfield) $sortfield =
"name";
57 $section =
GETPOST(
"section",
'alpha') ?
GETPOST(
"section",
'alpha') :
GETPOST(
"relativedir",
'alpha');
70 $result = $ecmdir->fetch($section);
72 $relativepath = $ecmdir->getRelativePath();
73 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
75 $relativepath = $section;
76 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
80 $relativepath = $section;
81 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
89 $permtoadd = $user->rights->ecm->setup;
90 $permtoupload = $user->rights->ecm->upload;
92 if ($module ==
'medias')
94 $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
95 $permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
105 if (
GETPOST(
"sendit") && !empty($conf->global->MAIN_UPLOAD_DOC))
110 if (is_numeric($resupload) && $resupload > 0)
112 $result = $ecmdir->changeNbOfFiles(
'+');
114 $langs->load(
"errors");
118 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
120 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"), null,
'errors');
128 $langs->load(
"errors");
129 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir), null,
'errors');
134 if ($action ==
'confirm_deletefile' && $confirm ==
'yes')
136 $langs->load(
"other");
137 $file = $upload_dir.
"/".
GETPOST(
'urlfile');
142 $result = $ecmdir->changeNbOfFiles(
'-');
146 if ($action ==
'confirm_deletedir' && $confirm ==
'yes') {
147 $backtourl = DOL_URL_ROOT.
"/ecm/index.php";
148 if ($module ==
'medias') {
149 $backtourl = DOL_URL_ROOT.
"/website/index.php?file_manager=1";
152 $deletedirrecursive = (
GETPOST(
'deletedirrecursive',
'alpha') ==
'on' ? 1 : 0);
154 if ($module ==
'ecm' && $ecmdir->id > 0) {
156 $result = $ecmdir->delete($user,
'all', $deletedirrecursive);
158 $langs->load(
'errors');
159 setEventMessages($langs->trans($ecmdir->error, $ecmdir->label), null,
'errors');
162 if ($deletedirrecursive) {
167 if ($resbool) $result = 1;
169 $langs->load(
'errors');
170 setEventMessages($langs->trans(
"ErrorFailToDeleteDir", $upload_dir), null,
'errors');
175 header(
"Location: ".$backtourl);
181 if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha'))
185 if ($module ==
'ecm')
187 $oldlabel = $ecmdir->label;
188 $olddir = $ecmdir->getRelativePath(0);
189 $olddir = $conf->ecm->dir_output.
'/'.$olddir;
191 $olddir =
GETPOST(
'section',
'alpha');
192 $olddir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
195 if ($module ==
'ecm')
201 $ecmdir->description =
GETPOST(
"description");
202 $ret = $extrafields->setOptionalsFromPost(null, $ecmdir);
203 if ($ret < 0) $error++;
206 $result = $ecmdir->insertExtraFields();
212 $result = $ecmdir->update($user);
216 if ($oldlabel != $ecmdir->label && file_exists($olddir))
218 $newdir = $ecmdir->getRelativePath(1);
219 $newdir = $conf->ecm->dir_output.
'/'.$newdir;
221 $result = @rename($olddir, $newdir);
224 $langs->load(
'errors');
225 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir), null,
'errors');
235 $relativepath = $ecmdir->getRelativePath();
236 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
245 $newdir = $conf->medias->multidir_output[$conf->entity].
'/'.
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
247 $result = @rename($olddir, $newdir);
250 $langs->load(
'errors');
251 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir), null,
'errors');
258 $relativepath =
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
259 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
260 $section = $relativepath;
270 $form =
new Form($db);
275 $extrafields->fetch_name_optionals_label($object->table_element);
277 if ($module ==
'ecm' && $ecmdir->id > 0) {
278 $object->fetch($ecmdir->id);
284 $filearrayall =
dol_dir_list($upload_dir,
"all", 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
285 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
287 foreach ($filearray as $key => $file)
289 $totalsize += $file[
'size'];
297 if ($action ==
'edit')
299 print '<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
300 print '<input type="hidden" name="token" value="'.newToken().
'">';
301 print '<input type="hidden" name="section" value="'.$section.
'">';
302 print '<input type="hidden" name="module" value="'.$module.
'">';
303 print '<input type="hidden" name="action" value="update">';
309 $morehtmlref =
'/'.$module.
'/'.$relativepath;
311 if ($module ==
'ecm')
317 if ($ecmdir->id > 0) {
318 $tmpecmdir->fetch($ecmdir->id);
319 while ($tmpecmdir && $result > 0)
321 $tmpecmdir->ref = $tmpecmdir->label;
322 if ($i == 0 && $action ==
'edit')
324 $s =
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$tmpecmdir->label.
'">';
325 }
else $s = $tmpecmdir->getNomUrl(1).$s;
326 if ($tmpecmdir->fk_parent)
329 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
336 $s .= join(
' -> ', explode(
'/', $section));
338 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s;
340 if ($module ==
'medias')
344 $subdirs = explode(
'/', $section);
346 foreach ($subdirs as $subdir)
348 if ($i == (count($subdirs) - 1))
350 if ($action ==
'edit')
352 $s .=
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$subdir.
'">';
353 $s .=
'<input type="hidden" name="oldrelparentdir" value="'.dirname($section).
'">';
354 $s .=
'<input type="hidden" name="oldreldir" value="'.basename($section).
'">';
355 }
else $s .= $subdir;
357 if ($i < (count($subdirs) - 1))
359 $s .= $subdir.
' -> ';
370 print '<div class="fichecenter">';
372 print '<div class="underbanner clearboth"></div>';
373 print '<table class="border centpercent tableforfield">';
378 if ($module ==
'ecm')
380 print '<tr><td class="titlefield tdtop">'.$langs->trans(
"Description").
'</td><td>';
381 if ($action ==
'edit')
383 print '<textarea class="flat quatrevingtpercent" name="description">';
384 print $ecmdir->description;
389 print '<tr><td class="titlefield">'.$langs->trans(
"ECMCreationUser").
'</td><td>';
390 if ($ecmdir->fk_user_c > 0) {
391 $userecm =
new User($db);
392 $userecm->fetch($ecmdir->fk_user_c);
393 print $userecm->getNomUrl(1);
397 print '<tr><td class="titlefield">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
398 if ($module ==
'ecm')
406 print '<tr><td>'.$langs->trans(
"ECMDirectoryForFiles").
'</td><td>';
407 if ($module ==
'ecm')
409 print '/ecm/'.$relativepath;
411 print '/'.$module.
'/'.$relativepath;
414 print '<tr><td>'.$langs->trans(
"ECMNbOfDocs").
'</td><td>';
415 $nbofiles = count($filearray);
420 if ($nbofiles != $ecmdir->cachenbofdoc)
422 $ecmdir->changeNbOfFiles((
string) $nbofiles);
426 print '<tr><td>'.$langs->trans(
"TotalSizeOfAttachedFiles").
'</td><td>';
429 print $object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
432 if ($action ==
'edit')
434 print '<br><div align="center">';
435 print '<input type="submit" class="button button-save" name="submit" value="'.$langs->trans(
"Save").
'">';
436 print ' ';
437 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
442 if ($action ==
'edit')
452 if ($action !=
'edit' && $action !=
'delete')
454 print '<div class="tabsAction">';
458 print '<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit'.($module ?
'&module='.$module :
'').
'§ion='.$section.
'">'.$langs->trans(
'Edit').
'</a>';
463 print '<a class="butAction" href="'.DOL_URL_ROOT.
'/ecm/dir_add_card.php?action=create'.($module ?
'&module='.$module :
'').
'&catParent='.$section.
'">'.$langs->trans(
'ECMAddSection').
'</a>';
465 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'ECMAddSection').
'</a>';
472 print '<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete_dir&token='.
newToken().($module ?
'&module='.$module :
'').
'§ion='.$section.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.$langs->trans(
'Delete').
'</a>';
474 print '<a class="butActionDeleteRefused" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'Delete').
'</a>';
488 if ($action ==
'delete')
490 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?section='.
GETPOST(
"section",
'alpha').
'&urlfile='.urlencode($_GET[
"urlfile"]).($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile');
494 if ($action ==
'delete_dir')
496 $relativepathwithoutslash = preg_replace(
'/[\/]$/',
'', $relativepath);
499 if (count($filearrayall) > 0)
501 $langs->load(
"other");
502 $formquestion = array(
503 array(
'type' =>
'checkbox',
'name' =>
'deletedirrecursive',
'label' => $langs->trans(
"ContentOfDirectoryIsNotEmpty").
'<br>'.$langs->trans(
"DeleteAlsoContentRecursively"),
'value' =>
'0')
507 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?section='.
GETPOST(
'section',
'alpha').($module ?
'&module='.$module :
'').($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection', $relativepathwithoutslash),
'confirm_deletedir', $formquestion, 1, 1);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_unescapefile($filename)
Unescape a file submitted by upload.
Class to manage Dolibarr users.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
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.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles= 'addedfile', $upload_dir= '')
Make control on an uploaded file from an GUI page and move it to final destination.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_filemtime($pathoffile)
Return time of a file.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
ecm_prepare_head($object, $module= 'ecm', $section= '')
Prepare array with list of tabs.
Class to manage ECM directories.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)