26require
'../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/ecm/class/htmlecm.form.class.php';
35$langs->loadLangs(array(
'ecm',
'companies',
'other'));
37$action =
GETPOST(
'action',
'alpha');
38$cancel =
GETPOST(
'cancel',
'aZ09');
39$backtopage =
GETPOST(
'backtopage',
'alpha');
40$confirm =
GETPOST(
'confirm',
'alpha');
42$module =
GETPOST(
'module',
'alpha');
43$website =
GETPOST(
'website',
'alpha');
44$pageid =
GETPOST(
'pageid',
'int');
50$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
51$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
52$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
53$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
54if (empty($page) || $page == -1) {
57$offset = $limit * $page;
67$section =
GETPOST(
"section",
'alpha') ?
GETPOST(
"section",
'alpha') :
GETPOST(
"relativedir",
'alpha');
76if ($module ==
'ecm') {
78 $result = $ecmdir->fetch($section);
80 $relativepath = $ecmdir->getRelativePath();
81 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
83 $relativepath = $section;
84 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
88 $relativepath = $section;
89 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
95$permissiontoupload = 0;
96if ($module ==
'ecm') {
97 $permissiontoread = $user->hasRight(
"ecm",
"read");
98 $permissiontoadd = $user->hasRight(
"ecm",
"setup");
99 $permissiontoupload = $user->hasRight(
"ecm",
"upload");
101if ($module ==
'medias') {
102 $permissiontoread = ($user->hasRight(
"mailing",
"lire") || $user->hasRight(
"website",
"read"));
103 $permissiontoadd = ($user->hasRight(
"mailing",
"creer") || $user->hasRight(
"website",
"write"));
104 $permissiontoupload = ($user->hasRight(
"mailing",
"creer") || $user->hasRight(
"website",
"write"));
107if (!$permissiontoread) {
117if (
GETPOST(
"sendit") && !empty($conf->global->MAIN_UPLOAD_DOC) && $permissiontoupload) {
120 if (is_numeric($resupload) && $resupload > 0) {
121 $result = $ecmdir->changeNbOfFiles(
'+');
123 $langs->load(
"errors");
124 if ($resupload < 0) {
126 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
128 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
136 $langs->load(
"errors");
137 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir),
null,
'errors');
142if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $permissiontoupload) {
143 $langs->load(
"other");
144 $file = $upload_dir.
"/".
GETPOST(
'urlfile');
152 $result = $ecmdir->changeNbOfFiles(
'-');
156if ($action ==
'confirm_deletedir' && $confirm ==
'yes' && $permissiontoupload) {
157 $backtourl = DOL_URL_ROOT.
"/ecm/index.php";
158 if ($module ==
'medias') {
159 $backtourl = DOL_URL_ROOT.
"/website/index.php?file_manager=1";
162 $deletedirrecursive = (
GETPOST(
'deletedirrecursive',
'alpha') ==
'on' ? 1 : 0);
164 if ($module ==
'ecm' && $ecmdir->id > 0) {
166 $result = $ecmdir->delete($user,
'all', $deletedirrecursive);
168 $langs->load(
'errors');
169 setEventMessages($langs->trans($ecmdir->error, $ecmdir->label),
null,
'errors');
172 if ($deletedirrecursive) {
180 $langs->load(
'errors');
181 setEventMessages($langs->trans(
"ErrorFailToDeleteDir", $upload_dir),
null,
'errors');
186 header(
"Location: ".$backtourl);
192if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha') && $permissiontoadd) {
195 if ($module ==
'ecm') {
196 $oldlabel = $ecmdir->label;
197 $olddir = $ecmdir->getRelativePath(0);
198 $olddir = $conf->ecm->dir_output.
'/'.$olddir;
200 $olddir =
GETPOST(
'section',
'alpha');
201 $olddir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
204 if ($module ==
'ecm') {
209 $fk_parent =
GETPOST(
"catParent",
'int');
210 if ($fk_parent ==
"-1") {
211 $ecmdir->fk_parent =
"0";
213 $ecmdir->fk_parent = $fk_parent;
215 $ecmdir->description =
GETPOST(
"description");
216 $ret = $extrafields->setOptionalsFromPost(
null, $ecmdir);
222 $result = $ecmdir->insertExtraFields();
228 $result = $ecmdir->update($user);
230 $newdir = $ecmdir->getRelativePath(1);
231 $newdir = $conf->ecm->dir_output.
'/'.$newdir;
233 if (($oldlabel != $ecmdir->label && file_exists($olddir)) || ($olddir != $newdir && file_exists($olddir))) {
234 $newdir = $ecmdir->getRelativePath(1);
235 $newdir = $conf->ecm->dir_output.
'/'.$newdir;
237 $result = @rename($olddir, $newdir);
239 $langs->load(
'errors');
240 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
249 $relativepath = $ecmdir->getRelativePath();
250 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
259 $newdir = $conf->medias->multidir_output[$conf->entity].
'/'.
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
261 $result = @rename($olddir, $newdir);
263 $langs->load(
'errors');
264 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir),
null,
'errors');
270 $relativepath =
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
271 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
272 $section = $relativepath;
282$form =
new Form($db);
288$extrafields->fetch_name_optionals_label($object->table_element);
290if ($module ==
'ecm' && $ecmdir->id > 0) {
291 $object->fetch($ecmdir->id);
297$filearrayall =
dol_dir_list($upload_dir,
"all", 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
298$filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
300foreach ($filearray as $key => $file) {
301 $totalsize += $file[
'size'];
309if ($action ==
'edit') {
310 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
311 print
'<input type="hidden" name="token" value="'.newToken().
'">';
312 print
'<input type="hidden" name="section" value="'.$section.
'">';
313 print
'<input type="hidden" name="module" value="'.$module.
'">';
314 print
'<input type="hidden" name="action" value="update">';
320$morehtmlref =
'/'.$module.
'/'.$relativepath;
322if ($module ==
'ecm') {
327 if ($ecmdir->id > 0) {
328 $tmpecmdir->fetch($ecmdir->id);
329 while ($tmpecmdir && $result > 0) {
330 $tmpecmdir->ref = $tmpecmdir->label;
331 $s = $tmpecmdir->getNomUrl(1).$s;
332 if ($tmpecmdir->fk_parent) {
334 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
341 $s .= join(
' -> ', explode(
'/', $section));
343 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s;
345if ($module ==
'medias') {
348 $subdirs = explode(
'/', $section);
350 foreach ($subdirs as $subdir) {
351 if ($i == (count($subdirs) - 1)) {
352 if ($action ==
'edit') {
353 $s .=
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$subdir.
'">';
354 $s .=
'<input type="hidden" name="oldrelparentdir" value="'.dirname($section).
'">';
355 $s .=
'<input type="hidden" name="oldreldir" value="'.basename($section).
'">';
360 if ($i < (count($subdirs) - 1)) {
361 $s .= $subdir.
' -> ';
372print
'<div class="fichecenter">';
374print
'<div class="underbanner clearboth"></div>';
375print
'<table class="border centpercent tableforfield">';
380if ($module ==
'ecm') {
381 if ($action ==
'edit') {
382 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMDirName").
'</td><td>';
383 print
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$ecmdir->label.
'">';
385 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMParentDirectory").
'</td><td>';
386 print $formecm->selectAllSections($ecmdir->fk_parent,
'',
'ecm', array($ecmdir->id));
391 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"Description").
'</td><td>';
392 if ($action ==
'edit') {
393 print
'<textarea class="flat quatrevingtpercent" name="description">';
394 print $ecmdir->description;
401 print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationUser").
'</td><td>';
402 if ($ecmdir->fk_user_c > 0) {
403 $userecm =
new User($db);
404 $userecm->fetch($ecmdir->fk_user_c);
405 print $userecm->getNomUrl(1);
409print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
410if ($module ==
'ecm') {
417print
'<tr><td>'.$langs->trans(
"ECMDirectoryForFiles").
'</td><td>';
418if ($module ==
'ecm') {
419 print
'/ecm/'.$relativepath;
421 print
'/'.$module.
'/'.$relativepath;
424print
'<tr><td>'.$langs->trans(
"ECMNbOfDocs").
'</td><td>';
425$nbofiles = count($filearray);
427if ($ecmdir->id > 0) {
429 if ($nbofiles != $ecmdir->cachenbofdoc) {
430 $ecmdir->changeNbOfFiles((
string) $nbofiles);
434print
'<tr><td>'.$langs->trans(
"TotalSizeOfAttachedFiles").
'</td><td>';
437print $object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
440if ($action ==
'edit') {
441 print $form->buttonsSaveCancel();
445if ($action ==
'edit') {
454if ($action !=
'edit' && $action !=
'delete' && $action !=
'deletefile') {
455 print
'<div class="tabsAction">';
457 if ($permissiontoadd) {
458 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.newToken().($module ?
'&module='.$module :
'').
'§ion='.$section.
'">'.$langs->trans(
'Edit').
'</a>';
461 if ($permissiontoadd) {
462 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/ecm/dir_add_card.php?action=create&token='.newToken().($module ?
'&module='.$module :
'').
'&catParent='.$section.
'">'.$langs->trans(
'ECMAddSection').
'</a>';
464 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'ECMAddSection').
'</a>';
467 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken().($module ?
'&module='.urlencode($module) :
'').
'§ion='.urlencode($section).($backtopage ?
'&backtopage='.urlencode($backtopage) :
''),
'', $permissiontoadd);
474if ($action ==
'deletefile') {
475 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?section='.urlencode(
GETPOST(
"section",
'alpha')).
'&urlfile='.urlencode(
GETPOST(
"urlfile")).($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile'),
'confirm_deletefile');
479if ($action ==
'delete' || $action ==
'delete_dir') {
480 $relativepathwithoutslash = preg_replace(
'/[\/]$/',
'', $relativepath);
483 if (count($filearrayall) > 0) {
484 $langs->load(
"other");
485 $formquestion = array(
486 array(
'type' =>
'checkbox',
'name' =>
'deletedirrecursive',
'label' => $langs->trans(
"ContentOfDirectoryIsNotEmpty").
'<br>'.$langs->trans(
"DeleteAlsoContentRecursively"),
'value' =>
'0')
490 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?section='.urlencode(
GETPOST(
'section',
'alpha')).($module ?
'&module='.$module :
'').($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'DeleteSection'), $langs->trans(
'ConfirmDeleteSection', $relativepathwithoutslash),
'confirm_deletedir', $formquestion, 1, 1);
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage ECM directories.
Class to manage Dolibarr users.
ecm_prepare_head($object, $module='ecm', $section='')
Prepare array with list of tabs.
dol_filemtime($pathoffile)
Return time of a file.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=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, $nolog=0)
Remove a file or several files with a mask.
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.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_unescapefile($filename)
Unescape a file submitted by upload.
dol_dir_list($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_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.