28require
'../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/ecm/class/htmlecm.form.class.php';
45$langs->loadLangs(array(
'ecm',
'companies',
'other'));
47$action =
GETPOST(
'action',
'alpha');
49$backtopage =
GETPOST(
'backtopage',
'alpha');
50$confirm =
GETPOST(
'confirm',
'alpha');
53$website =
GETPOST(
'website',
'alpha');
61$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
62$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
64if (empty($page) || $page == -1) {
67$offset = $limit * $page;
77$section =
GETPOST(
"section",
'alpha') ?
GETPOST(
"section",
'alpha') :
GETPOST(
"relativedir",
'alpha');
79 dol_print_error(
null,
"ErrorSectionParamNotDefined");
86if ($module ==
'ecm') {
88 $result = preg_match(
'/^\d+$/', $section) ? $ecmdir->fetch((
int) $section) : 0;
90 $relativepath = $ecmdir->getRelativePath();
91 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
93 $relativepath = $section;
94 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
97 $relativepath = $section;
98 $upload_dir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
102$permissiontoread = 0;
104$permissiontoupload = 0;
105if ($module ==
'ecm') {
106 $permissiontoread = $user->hasRight(
"ecm",
"read");
107 $permissiontoadd = $user->hasRight(
"ecm",
"setup");
108 $permissiontoupload = $user->hasRight(
"ecm",
"upload");
110if ($module ==
'medias') {
111 $permissiontoread = $user->hasRight(
"website",
"read");
112 $permissiontoadd = $user->hasRight(
"website",
"write");
113 $permissiontoupload = $user->hasRight(
"website",
"write");
116if (!$permissiontoread) {
129 if (is_numeric($resupload) && $resupload > 0) {
130 $result = $ecmdir->changeNbOfFiles(
'+');
132 $langs->load(
"errors");
133 if ($resupload < 0) {
134 setEventMessages($langs->trans(
"ErrorFileNotUploaded"),
null,
'errors');
136 setEventMessages($langs->trans($resupload),
null,
'errors');
141 $langs->load(
"errors");
142 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir),
null,
'errors');
147if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $permissiontoupload) {
148 $langs->load(
"other");
149 $file = $upload_dir.
"/".
GETPOST(
'urlfile');
152 setEventMessages($langs->trans(
"FileWasRemoved",
GETPOST(
'urlfile')),
null,
'mesgs');
154 setEventMessages($langs->trans(
"ErrorFailToDeleteFile",
GETPOST(
'urlfile')),
null,
'errors');
157 $result = $ecmdir->changeNbOfFiles(
'-');
161if ($action ==
'confirm_deletedir' && $confirm ==
'yes' && $permissiontoupload) {
162 $backtourl = DOL_URL_ROOT.
"/ecm/index.php";
163 if ($module ==
'medias') {
164 $backtourl = DOL_URL_ROOT.
"/website/index.php?file_manager=1";
167 $deletedirrecursive = (
GETPOST(
'deletedirrecursive',
'alpha') ==
'on' ? 1 : 0);
169 if ($module ==
'ecm' && $ecmdir->id > 0) {
171 $result = $ecmdir->delete($user,
'all', $deletedirrecursive);
173 $langs->load(
'errors');
174 setEventMessages($langs->trans($ecmdir->error, $ecmdir->label),
null,
'errors');
177 if ($deletedirrecursive) {
185 $langs->load(
'errors');
186 setEventMessages($langs->trans(
"ErrorFailToDeleteDir", $upload_dir),
null,
'errors');
191 header(
"Location: ".$backtourl);
197if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha') && $permissiontoadd) {
201 if ($module ==
'ecm') {
202 $oldlabel = $ecmdir->label;
203 $olddir = $ecmdir->getRelativePath(0);
204 $olddir =
$conf->ecm->dir_output.
'/'.$olddir;
206 $olddir =
GETPOST(
'section',
'alpha');
207 $olddir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
210 if ($module ==
'ecm') {
216 if ($fk_parent == -1) {
217 $ecmdir->fk_parent = 0;
219 $ecmdir->fk_parent = $fk_parent;
221 $ecmdir->description =
GETPOST(
"description");
222 $ret = $extrafields->setOptionalsFromPost(
null, $ecmdir);
228 $result = $ecmdir->insertExtraFields();
230 setEventMessages($ecmdir->error, $ecmdir->errors,
'errors');
234 $result = $ecmdir->update($user);
236 $newdir = $ecmdir->getRelativePath(1);
237 $newdir =
$conf->ecm->dir_output.
'/'.$newdir;
239 if (($oldlabel != $ecmdir->label && file_exists($olddir)) || ($olddir != $newdir && file_exists($olddir))) {
240 $newdir = $ecmdir->getRelativePath(1);
241 $newdir =
$conf->ecm->dir_output.
'/'.$newdir;
243 $result = @rename($olddir, $newdir);
245 $langs->load(
'errors');
246 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
255 $relativepath = $ecmdir->getRelativePath();
256 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
262 setEventMessages($ecmdir->error, $ecmdir->errors,
'errors');
265 $newdir =
$conf->medias->multidir_output[
$conf->entity].
'/'.
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
267 $result = @rename($olddir, $newdir);
269 $langs->load(
'errors');
270 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
276 $relativepath =
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
277 $upload_dir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
278 $section = $relativepath;
288$form =
new Form($db);
293$extrafields->fetch_name_optionals_label(
$object->table_element);
295if ($module ==
'ecm' && $ecmdir->id > 0) {
299llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-ecm page-dir_card');
302$filearrayall =
dol_dir_list($upload_dir,
"all", 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
303$filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
305foreach ($filearray as $key => $file) {
306 $totalsize += $file[
'size'];
314if ($action ==
'edit') {
315 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
316 print
'<input type="hidden" name="token" value="'.newToken().
'">';
317 print
'<input type="hidden" name="section" value="'.$section.
'">';
318 print
'<input type="hidden" name="module" value="'.$module.
'">';
319 print
'<input type="hidden" name="action" value="update">';
325$morehtmlref =
'/'.$module.
'/'.$relativepath;
327if ($module ==
'ecm') {
332 if ($ecmdir->id > 0) {
333 $tmpecmdir->fetch($ecmdir->id);
334 while ($tmpecmdir && $result > 0) {
335 $tmpecmdir->ref = $tmpecmdir->label;
336 $s = $tmpecmdir->getNomUrl(1).$s;
337 if ($tmpecmdir->fk_parent) {
339 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
346 $s .= implode(
' -> ', explode(
'/', $section));
348 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s;
350if ($module ==
'medias') {
353 $subdirs = explode(
'/', $section);
355 foreach ($subdirs as $subdir) {
356 if ($i == (count($subdirs) - 1)) {
357 if ($action ==
'edit') {
358 $s .=
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$subdir.
'">';
359 $s .=
'<input type="hidden" name="oldrelparentdir" value="'.dirname($section).
'">';
360 $s .=
'<input type="hidden" name="oldreldir" value="'.basename($section).
'">';
365 if ($i < (count($subdirs) - 1)) {
366 $s .= $subdir.
' -> ';
375dol_banner_tab($object,
'', $morehtml, 0,
'',
'', $morehtmlref);
377print
'<div class="fichecenter">';
379print
'<div class="underbanner clearboth"></div>';
380print
'<table class="border centpercent tableforfield">';
385if ($module ==
'ecm') {
386 if ($action ==
'edit') {
387 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMDirName").
'</td><td>';
388 print
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$ecmdir->label.
'">';
390 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMParentDirectory").
'</td><td>';
391 print $formecm->selectAllSections($ecmdir->fk_parent,
'',
'ecm', array($ecmdir->id));
396 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"Description").
'</td><td>';
397 if ($action ==
'edit') {
398 print
'<textarea class="flat quatrevingtpercent" name="description">';
399 print $ecmdir->description;
406 print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationUser").
'</td><td>';
407 if ($ecmdir->fk_user_c > 0) {
408 $userecm =
new User($db);
409 $userecm->fetch($ecmdir->fk_user_c);
410 print $userecm->getNomUrl(-1);
414print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
415if ($module ==
'ecm') {
422print
'<tr><td>'.$langs->trans(
"ECMDirectoryForFiles").
'</td><td>';
423if ($module ==
'ecm') {
424 print
'/ecm/'.$relativepath;
426 print
'/'.$module.
'/'.$relativepath;
429print
'<tr><td>'.$langs->trans(
"ECMNbOfDocs").
'</td><td>';
430$nbofiles = count($filearray);
432if ($ecmdir->id > 0) {
434 if ($nbofiles != $ecmdir->cachenbofdoc) {
435 $ecmdir->changeNbOfFiles((
string) $nbofiles);
439print
'<tr><td>'.$langs->trans(
"TotalSizeOfAttachedFiles").
'</td><td>';
442print
$object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
445if ($action ==
'edit') {
446 print
'<br>'.$form->buttonsSaveCancel();
450if ($action ==
'edit') {
459if ($action !=
'edit' && $action !=
'delete' && $action !=
'deletefile') {
460 print
'<div class="tabsAction">';
462 if ($permissiontoadd) {
463 print
'<a class="butAction" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'edit',
'module' => $module,
'section' => $section),
true).
'">'.$langs->trans(
'Edit').
'</a>';
466 if ($permissiontoadd) {
467 print
'<a class="butAction" href="'.dolBuildUrl(DOL_URL_ROOT.
'/ecm/dir_add_card.php', array(
'action' =>
'create',
'module' => $module,
'catParent' => $section),
true).
'">'.$langs->trans(
'ECMAddSection').
'</a>';
469 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'ECMAddSection').
'</a>';
472 $paramsdelete = array(
474 'action' =>
'delete',
476 'section' => $section,
479 $paramsdelete[
'backtopage'] = $backtopage;
481 print dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete',
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsdelete,
true),
'', $permissiontoadd, array(
'attr' => array(
'class' =>
'reposition'))).
"\n";
488if ($action ==
'deletefile') {
489 $paramsdeletefile = array(
490 'section' =>
GETPOST(
"section",
'alpha'),
491 'urlfile' =>
GETPOST(
"urlfile"),
494 $paramsdeletefile[
'backtopage'] = $backtopage;
496 print $form->formconfirm(
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsdeletefile), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile');
500if ($action ==
'delete' || $action ==
'delete_dir') {
501 $relativepathwithoutslash = preg_replace(
'/[\/]$/',
'', $relativepath);
504 if (count($filearrayall) > 0) {
505 $langs->load(
"other");
506 $formquestion = array(
507 array(
'type' =>
'checkbox',
'name' =>
'deletedirrecursive',
'label' => $langs->trans(
"ContentOfDirectoryIsNotEmpty").
'<br>'.$langs->trans(
"DeleteAlsoContentRecursively"),
'value' =>
'0')
511 $paramsdeletedir = array(
512 'section' =>
GETPOST(
'section',
'alpha'),
516 $paramsdeletedir[
'backtopage'] = $backtopage;
518 print $form->formconfirm(
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsdeletedir), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection', $relativepathwithoutslash),
'confirm_deletedir', $formquestion, 1, 1);
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage ECM directories.
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
ecm_prepare_head($object, $module='ecm', $section='')
Prepare array with list of tabs.
dol_filemtime($pathoffile)
Return time of a file.
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.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_unescapefile($filename)
Unescape a file submitted by upload.
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_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.