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');
80 dol_print_error(
null,
"ErrorSectionParamNotDefined");
87if ($module ==
'ecm') {
89 $result = preg_match(
'/^\d+$/', $section) ? $ecmdir->fetch((
int) $section) : 0;
91 $relativepath = $ecmdir->getRelativePath();
92 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
94 $relativepath = $section;
95 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
98 $relativepath = $section;
99 $upload_dir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
103$permissiontoread = 0;
105$permissiontoupload = 0;
106if ($module ==
'ecm') {
107 $permissiontoread = $user->hasRight(
"ecm",
"read");
108 $permissiontoadd = $user->hasRight(
"ecm",
"setup");
109 $permissiontoupload = $user->hasRight(
"ecm",
"upload");
111if ($module ==
'medias') {
112 $permissiontoread = $user->hasRight(
"website",
"read");
113 $permissiontoadd = $user->hasRight(
"website",
"write");
114 $permissiontoupload = $user->hasRight(
"website",
"write");
117if (!$permissiontoread) {
130 if (is_numeric($resupload) && $resupload > 0) {
131 $result = $ecmdir->changeNbOfFiles(
'+');
133 $langs->load(
"errors");
134 if ($resupload < 0) {
135 setEventMessages($langs->trans(
"ErrorFileNotUploaded"),
null,
'errors');
137 setEventMessages($langs->trans($resupload),
null,
'errors');
142 $langs->load(
"errors");
143 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir),
null,
'errors');
148if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $permissiontoupload) {
149 $langs->load(
"other");
150 $file = $upload_dir.
"/".
GETPOST(
'urlfile');
153 setEventMessages($langs->trans(
"FileWasRemoved",
GETPOST(
'urlfile')),
null,
'mesgs');
155 setEventMessages($langs->trans(
"ErrorFailToDeleteFile",
GETPOST(
'urlfile')),
null,
'errors');
158 $result = $ecmdir->changeNbOfFiles(
'-');
162if ($action ==
'confirm_deletedir' && $confirm ==
'yes' && $permissiontoadd) {
163 $backtourl = DOL_URL_ROOT.
"/ecm/index.php";
164 if ($module ==
'medias') {
165 $backtourl = DOL_URL_ROOT.
"/website/index.php?file_manager=1";
168 $deletedirrecursive = (
GETPOST(
'deletedirrecursive',
'alpha') ==
'on' ? 1 : 0);
170 if ($module ==
'ecm' && $ecmdir->id > 0) {
172 $result = $ecmdir->delete($user,
'all', $deletedirrecursive);
174 $langs->load(
'errors');
175 setEventMessages($langs->trans($ecmdir->error, $ecmdir->label),
null,
'errors');
178 if ($deletedirrecursive) {
186 $langs->load(
'errors');
187 setEventMessages($langs->trans(
"ErrorFailToDeleteDir", $upload_dir),
null,
'errors');
192 header(
"Location: ".$backtourl);
198if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha') && $permissiontoadd) {
202 if ($module ==
'ecm') {
203 $oldlabel = $ecmdir->label;
204 $olddir = $ecmdir->getRelativePath(0);
205 $olddir =
$conf->ecm->dir_output.
'/'.$olddir;
207 $olddir =
GETPOST(
'section',
'alpha');
208 $olddir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
211 if ($module ==
'ecm') {
217 if ($fk_parent == -1) {
218 $ecmdir->fk_parent = 0;
220 $ecmdir->fk_parent = $fk_parent;
222 $ecmdir->description =
GETPOST(
"description");
223 $ret = $extrafields->setOptionalsFromPost(
null, $ecmdir);
229 $result = $ecmdir->insertExtraFields();
231 setEventMessages($ecmdir->error, $ecmdir->errors,
'errors');
235 $result = $ecmdir->update($user);
237 $newdir = $ecmdir->getRelativePath(1);
238 $newdir =
$conf->ecm->dir_output.
'/'.$newdir;
240 if (($oldlabel != $ecmdir->label && file_exists($olddir)) || ($olddir != $newdir && file_exists($olddir))) {
241 $newdir = $ecmdir->getRelativePath(1);
242 $newdir =
$conf->ecm->dir_output.
'/'.$newdir;
244 $result = @rename($olddir, $newdir);
246 $langs->load(
'errors');
247 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
256 $relativepath = $ecmdir->getRelativePath();
257 $upload_dir =
$conf->ecm->dir_output.
'/'.$relativepath;
263 setEventMessages($ecmdir->error, $ecmdir->errors,
'errors');
268 $newdir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$oldrelparentdir.
'/'.$newlabel;
269 if ($newlabel ===
'') {
273 $result = ($error ? false : @rename($olddir, $newdir));
275 $langs->load(
'errors');
276 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
282 $relativepath = $oldrelparentdir.
'/'.$newlabel;
283 $upload_dir =
$conf->medias->multidir_output[
$conf->entity].
'/'.$relativepath;
284 $section = $relativepath;
294$form =
new Form($db);
299$extrafields->fetch_name_optionals_label(
$object->table_element);
301if ($module ==
'ecm' && $ecmdir->id > 0) {
305llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-ecm page-dir_card');
308$filearrayall =
dol_dir_list($upload_dir,
"all", 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
309$filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
311foreach ($filearray as $key => $file) {
312 $totalsize += $file[
'size'];
320if ($action ==
'edit') {
321 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
322 print
'<input type="hidden" name="token" value="'.newToken().
'">';
323 print
'<input type="hidden" name="section" value="'.$section.
'">';
324 print
'<input type="hidden" name="module" value="'.$module.
'">';
325 print
'<input type="hidden" name="action" value="update">';
331$morehtmlref =
'/'.$module.
'/'.$relativepath;
333if ($module ==
'ecm') {
338 if ($ecmdir->id > 0) {
339 $tmpecmdir->fetch($ecmdir->id);
340 while ($tmpecmdir && $result > 0) {
341 $tmpecmdir->ref = $tmpecmdir->label;
342 $s = $tmpecmdir->getNomUrl(1).$s;
343 if ($tmpecmdir->fk_parent) {
345 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
352 $s .= implode(
' -> ', explode(
'/', $section));
354 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s;
356if ($module ==
'medias') {
359 $subdirs = explode(
'/', $section);
361 foreach ($subdirs as $subdir) {
362 if ($i == (count($subdirs) - 1)) {
363 if ($action ==
'edit') {
364 $s .=
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$subdir.
'">';
365 $s .=
'<input type="hidden" name="oldrelparentdir" value="'.dirname($section).
'">';
366 $s .=
'<input type="hidden" name="oldreldir" value="'.basename($section).
'">';
371 if ($i < (count($subdirs) - 1)) {
372 $s .= $subdir.
' -> ';
381dol_banner_tab($object,
'', $morehtml, 0,
'',
'', $morehtmlref);
383print
'<div class="fichecenter">';
385print
'<div class="underbanner clearboth"></div>';
386print
'<table class="border centpercent tableforfield">';
391if ($module ==
'ecm') {
392 if ($action ==
'edit') {
393 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMDirName").
'</td><td>';
394 print
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$ecmdir->label.
'">';
396 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMParentDirectory").
'</td><td>';
397 print $formecm->selectAllSections($ecmdir->fk_parent,
'',
'ecm', array($ecmdir->id));
402 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"Description").
'</td><td>';
403 if ($action ==
'edit') {
404 print
'<textarea class="flat quatrevingtpercent" name="description">';
405 print $ecmdir->description;
412 print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationUser").
'</td><td>';
413 if ($ecmdir->fk_user_c > 0) {
414 $userecm =
new User($db);
415 $userecm->fetch($ecmdir->fk_user_c);
416 print $userecm->getNomUrl(-1);
420print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
421if ($module ==
'ecm') {
428print
'<tr><td>'.$langs->trans(
"ECMDirectoryForFiles").
'</td><td>';
429if ($module ==
'ecm') {
430 print
'/ecm/'.$relativepath;
432 print
'/'.$module.
'/'.$relativepath;
435print
'<tr><td>'.$langs->trans(
"ECMNbOfDocs").
'</td><td>';
436$nbofiles = count($filearray);
438if ($ecmdir->id > 0) {
440 if ($nbofiles != $ecmdir->cachenbofdoc) {
441 $ecmdir->changeNbOfFiles((
string) $nbofiles);
445print
'<tr><td>'.$langs->trans(
"TotalSizeOfAttachedFiles").
'</td><td>';
448print
$object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
451if ($action ==
'edit') {
452 print
'<br>'.$form->buttonsSaveCancel();
456if ($action ==
'edit') {
465if ($action !=
'edit' && $action !=
'delete' && $action !=
'deletefile') {
466 print
'<div class="tabsAction">';
468 if ($permissiontoadd) {
469 print
'<a class="butAction" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], array(
'action' =>
'edit',
'module' => $module,
'section' => $section),
true).
'">'.$langs->trans(
'Edit').
'</a>';
472 if ($permissiontoadd) {
473 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>';
475 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'ECMAddSection').
'</a>';
478 $paramsdelete = array(
480 'action' =>
'delete',
482 'section' => $section,
485 $paramsdelete[
'backtopage'] = $backtopage;
487 print dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete',
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsdelete,
true),
'', $permissiontoadd, array(
'attr' => array(
'class' =>
'reposition'))).
"\n";
494if ($action ==
'deletefile') {
495 $paramsdeletefile = array(
496 'section' =>
GETPOST(
"section",
'alpha'),
497 'urlfile' =>
GETPOST(
"urlfile"),
500 $paramsdeletefile[
'backtopage'] = $backtopage;
502 print $form->formconfirm(
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsdeletefile), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile');
506if ($action ==
'delete' || $action ==
'delete_dir') {
507 $relativepathwithoutslash = preg_replace(
'/[\/]$/',
'', $relativepath);
510 if (count($filearrayall) > 0) {
511 $langs->load(
"other");
512 $formquestion = array(
513 array(
'type' =>
'checkbox',
'name' =>
'deletedirrecursive',
'label' => $langs->trans(
"ContentOfDirectoryIsNotEmpty").
'<br>'.$langs->trans(
"DeleteAlsoContentRecursively"),
'value' =>
'0')
517 $paramsdeletedir = array(
518 'section' =>
GETPOST(
'section',
'alpha'),
522 $paramsdeletedir[
'backtopage'] = $backtopage;
524 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
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.