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';
31 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/htmlecm.form.class.php';
34 $langs->loadLangs(array(
'ecm',
'companies',
'other'));
36 $action =
GETPOST(
'action',
'alpha');
37 $cancel =
GETPOST(
'cancel',
'aZ09');
38 $backtopage =
GETPOST(
'backtopage',
'alpha');
39 $confirm =
GETPOST(
'confirm',
'alpha');
41 $module =
GETPOST(
'module',
'alpha');
42 $website =
GETPOST(
'website',
'alpha');
43 $pageid =
GETPOST(
'pageid',
'int');
49 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
50 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
53 if (empty($page) || $page == -1) {
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
66 $section =
GETPOST(
"section",
'alpha') ?
GETPOST(
"section",
'alpha') :
GETPOST(
"relativedir",
'alpha');
75 if ($module ==
'ecm') {
77 $result = $ecmdir->fetch($section);
79 $relativepath = $ecmdir->getRelativePath();
80 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
82 $relativepath = $section;
83 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
87 $relativepath = $section;
88 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
95 if ($module ==
'ecm') {
96 $permtoread = $user->rights->ecm->read;
97 $permtoadd = $user->rights->ecm->setup;
98 $permtoupload = $user->rights->ecm->upload;
100 if ($module ==
'medias') {
101 $permtoread = ($user->rights->mailing->lire || $user->rights->website->read);
102 $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
103 $permtoupload = ($user->rights->mailing->creer || $user->rights->website->write);
116 if (
GETPOST(
"sendit") && !empty($conf->global->MAIN_UPLOAD_DOC) && $permtoupload) {
119 if (is_numeric($resupload) && $resupload > 0) {
120 $result = $ecmdir->changeNbOfFiles(
'+');
122 $langs->load(
"errors");
123 if ($resupload < 0) {
125 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
127 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"), null,
'errors');
135 $langs->load(
"errors");
136 setEventMessages($langs->trans(
"ErrorFailToCreateDir", $upload_dir), null,
'errors');
141 if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && $permtoupload) {
142 $langs->load(
"other");
143 $file = $upload_dir.
"/".
GETPOST(
'urlfile');
151 $result = $ecmdir->changeNbOfFiles(
'-');
155 if ($action ==
'confirm_deletedir' && $confirm ==
'yes' && $permtoupload) {
156 $backtourl = DOL_URL_ROOT.
"/ecm/index.php";
157 if ($module ==
'medias') {
158 $backtourl = DOL_URL_ROOT.
"/website/index.php?file_manager=1";
161 $deletedirrecursive = (
GETPOST(
'deletedirrecursive',
'alpha') ==
'on' ? 1 : 0);
163 if ($module ==
'ecm' && $ecmdir->id > 0) {
165 $result = $ecmdir->delete($user,
'all', $deletedirrecursive);
167 $langs->load(
'errors');
168 setEventMessages($langs->trans($ecmdir->error, $ecmdir->label), null,
'errors');
171 if ($deletedirrecursive) {
179 $langs->load(
'errors');
180 setEventMessages($langs->trans(
"ErrorFailToDeleteDir", $upload_dir), null,
'errors');
185 header(
"Location: ".$backtourl);
191 if ($action ==
'update' && !
GETPOST(
'cancel',
'alpha') && $permtoadd) {
194 if ($module ==
'ecm') {
195 $oldlabel = $ecmdir->label;
196 $olddir = $ecmdir->getRelativePath(0);
197 $olddir = $conf->ecm->dir_output.
'/'.$olddir;
199 $olddir =
GETPOST(
'section',
'alpha');
200 $olddir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
203 if ($module ==
'ecm') {
208 $fk_parent =
GETPOST(
"catParent",
'int');
209 if ($fk_parent ==
"-1") {
210 $ecmdir->fk_parent =
"0";
212 $ecmdir->fk_parent = $fk_parent;
214 $ecmdir->description =
GETPOST(
"description");
215 $ret = $extrafields->setOptionalsFromPost(null, $ecmdir);
221 $result = $ecmdir->insertExtraFields();
227 $result = $ecmdir->update($user);
229 $newdir = $ecmdir->getRelativePath(1);
230 $newdir = $conf->ecm->dir_output.
'/'.$newdir;
232 if (($oldlabel != $ecmdir->label && file_exists($olddir)) || ($olddir != $newdir && file_exists($olddir))) {
233 $newdir = $ecmdir->getRelativePath(1);
234 $newdir = $conf->ecm->dir_output.
'/'.$newdir;
236 $result = @rename($olddir, $newdir);
238 $langs->load(
'errors');
239 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir), null,
'errors');
248 $relativepath = $ecmdir->getRelativePath();
249 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
258 $newdir = $conf->medias->multidir_output[$conf->entity].
'/'.
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
260 $result = @rename($olddir, $newdir);
262 $langs->load(
'errors');
263 setEventMessages($langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir), null,
'errors');
269 $relativepath =
GETPOST(
'oldrelparentdir',
'alpha').
'/'.
GETPOST(
'label',
'alpha');
270 $upload_dir = $conf->medias->multidir_output[$conf->entity].
'/'.$relativepath;
271 $section = $relativepath;
287 $extrafields->fetch_name_optionals_label($object->table_element);
289 if ($module ==
'ecm' && $ecmdir->id > 0) {
290 $object->fetch($ecmdir->id);
296 $filearrayall =
dol_dir_list($upload_dir,
"all", 0,
'',
'', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
297 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC), 1);
299 foreach ($filearray as $key => $file) {
300 $totalsize += $file[
'size'];
305 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ECMSectionManual"), -1,
'dir');
308 if ($action ==
'edit') {
309 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
310 print
'<input type="hidden" name="token" value="'.newToken().
'">';
311 print
'<input type="hidden" name="section" value="'.$section.
'">';
312 print
'<input type="hidden" name="module" value="'.$module.
'">';
313 print
'<input type="hidden" name="action" value="update">';
319 $morehtmlref =
'/'.$module.
'/'.$relativepath;
321 if ($module ==
'ecm') {
326 if ($ecmdir->id > 0) {
327 $tmpecmdir->fetch($ecmdir->id);
328 while ($tmpecmdir && $result > 0) {
329 $tmpecmdir->ref = $tmpecmdir->label;
330 $s = $tmpecmdir->getNomUrl(1).$s;
331 if ($tmpecmdir->fk_parent) {
333 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
340 $s .= join(
' -> ', explode(
'/', $section));
342 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s;
344 if ($module ==
'medias') {
347 $subdirs = explode(
'/', $section);
349 foreach ($subdirs as $subdir) {
350 if ($i == (count($subdirs) - 1)) {
351 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).
'">';
359 if ($i < (count($subdirs) - 1)) {
360 $s .= $subdir.
' -> ';
371 print
'<div class="fichecenter">';
373 print
'<div class="underbanner clearboth"></div>';
374 print
'<table class="border centpercent tableforfield">';
379 if ($module ==
'ecm') {
380 if ($action ==
'edit') {
381 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMDirName").
'</td><td>';
382 print
'<input type="text" name="label" class="minwidth300" maxlength="32" value="'.$ecmdir->label.
'">';
384 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"ECMParentDirectory").
'</td><td>';
385 print $formecm->selectAllSections($ecmdir->fk_parent,
'',
'ecm', array($ecmdir->id));
390 print
'<tr><td class="titlefield tdtop">'.$langs->trans(
"Description").
'</td><td>';
391 if ($action ==
'edit') {
392 print
'<textarea class="flat quatrevingtpercent" name="description">';
393 print $ecmdir->description;
400 print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationUser").
'</td><td>';
401 if ($ecmdir->fk_user_c > 0) {
402 $userecm =
new User($db);
403 $userecm->fetch($ecmdir->fk_user_c);
404 print $userecm->getNomUrl(1);
408 print
'<tr><td class="titlefield">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
409 if ($module ==
'ecm') {
416 print
'<tr><td>'.$langs->trans(
"ECMDirectoryForFiles").
'</td><td>';
417 if ($module ==
'ecm') {
418 print
'/ecm/'.$relativepath;
420 print
'/'.$module.
'/'.$relativepath;
423 print
'<tr><td>'.$langs->trans(
"ECMNbOfDocs").
'</td><td>';
424 $nbofiles = count($filearray);
426 if ($ecmdir->id > 0) {
428 if ($nbofiles != $ecmdir->cachenbofdoc) {
429 $ecmdir->changeNbOfFiles((
string) $nbofiles);
433 print
'<tr><td>'.$langs->trans(
"TotalSizeOfAttachedFiles").
'</td><td>';
436 print $object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
439 if ($action ==
'edit') {
440 print
$form->buttonsSaveCancel();
444 if ($action ==
'edit') {
453 if ($action !=
'edit' && $action !=
'delete' && $action !=
'deletefile') {
454 print
'<div class="tabsAction">';
457 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().($module ?
'&module='.$module :
'').
'§ion='.$section.
'">'.$langs->trans(
'Edit').
'</a>';
461 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>';
463 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'ECMAddSection').
'</a>';
469 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>';
471 print
'<a class="butActionDeleteRefused" href="#" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
'Delete').
'</a>';
485 if ($action ==
'deletefile') {
486 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');
490 if ($action ==
'delete_dir') {
491 $relativepathwithoutslash = preg_replace(
'/[\/]$/',
'', $relativepath);
494 if (count($filearrayall) > 0) {
495 $langs->load(
"other");
496 $formquestion = array(
497 array(
'type' =>
'checkbox',
'name' =>
'deletedirrecursive',
'label' => $langs->trans(
"ContentOfDirectoryIsNotEmpty").
'<br>'.$langs->trans(
"DeleteAlsoContentRecursively"),
'value' =>
'0')
501 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);
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.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
Class to manage Dolibarr users.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
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 from a POST of a form...
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) ...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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_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.