From e19ca7b6d41e535cf59422002f3eb28dcfd9306e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Nov 2017 18:19:41 +0100 Subject: [PATCH] Work on generic filemanager --- htdocs/core/ajax/ajaxdirpreview.php | 1 + htdocs/core/ajax/ajaxdirtree.php | 5 +- htdocs/core/lib/ecm.lib.php | 22 +++++-- htdocs/core/tpl/filemanager.tpl.php | 2 +- htdocs/ecm/class/htmlecm.form.class.php | 13 ++-- htdocs/ecm/docdir.php | 6 +- htdocs/ecm/docfile.php | 5 +- htdocs/ecm/docmine.php | 79 +++++++++++++++---------- htdocs/ecm/search.php | 16 +++-- htdocs/langs/en_US/ecm.lang | 2 +- 10 files changed, 92 insertions(+), 59 deletions(-) diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index eec21e63db6..4d72b576429 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -234,6 +234,7 @@ if ($type == 'directory') $param.='&file_manager=1'; if (!preg_match('/website=/',$param)) $param.='&website='.urlencode(GETPOST('website','alpha')); if (!preg_match('/pageid=/',$param)) $param.='&pageid='.urlencode(GETPOST('pageid','int')); + //if (!preg_match('/backtopage=/',$param)) $param.='&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$website.'&pageid='.$pageid); } } else diff --git a/htdocs/core/ajax/ajaxdirtree.php b/htdocs/core/ajax/ajaxdirtree.php index 723a5dbfb2a..2b4f6814717 100644 --- a/htdocs/core/ajax/ajaxdirtree.php +++ b/htdocs/core/ajax/ajaxdirtree.php @@ -198,7 +198,10 @@ if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE print ''; // Edit link - print ''.img_view($langs->trans("Edit").' - '.$langs->trans("View"), 0, 'class="valignmiddle"').''; + print ''.img_view($langs->trans("Edit").' - '.$langs->trans("View"), 0, 'class="valignmiddle"').''; // Add link //print ''.img_edit_add().''; diff --git a/htdocs/core/lib/ecm.lib.php b/htdocs/core/lib/ecm.lib.php index 34294f502e8..9d518dd5892 100644 --- a/htdocs/core/lib/ecm.lib.php +++ b/htdocs/core/lib/ecm.lib.php @@ -68,18 +68,30 @@ function ecm_prepare_dasboard_head($object) * Prepare array with list of tabs * * @param object $object Object related to tabs + * @param string $module Module + * @param string $section Section * @return array Array of tabs to show */ -function ecm_prepare_head($object) +function ecm_prepare_head($object, $module='ecm', $section='') { global $langs, $conf, $user; $h = 0; $head = array(); - $head[$h][0] = DOL_URL_ROOT.'/ecm/docmine.php?section='.$object->id; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; + if ($module == 'ecm') + { + $head[$h][0] = DOL_URL_ROOT.'/ecm/docmine.php?section='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + } + else + { + $head[$h][0] = DOL_URL_ROOT.'/ecm/docmine.php?section='.$section.'&module='.$module; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + } return $head; } diff --git a/htdocs/core/tpl/filemanager.tpl.php b/htdocs/core/tpl/filemanager.tpl.php index 162c69c6e1f..f9cce6866c1 100644 --- a/htdocs/core/tpl/filemanager.tpl.php +++ b/htdocs/core/tpl/filemanager.tpl.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; if (empty($module)) $module='ecm'; $permtoadd = 0; -$permtoupload = 1; +$permtoupload = 0; if ($module == 'ecm') { $permtoadd = $user->rights->ecm->setup; diff --git a/htdocs/ecm/class/htmlecm.form.class.php b/htdocs/ecm/class/htmlecm.form.class.php index a98f89c14bc..3139c5f9986 100644 --- a/htdocs/ecm/class/htmlecm.form.class.php +++ b/htdocs/ecm/class/htmlecm.form.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2017 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,15 +17,13 @@ /** * \file htdocs/ecm/class/htmlecm.form.class.php - * \brief Fichier de la classe des fonctions predefinie de composants html + * \brief File of class to manage HTML component for ECM and generic filemanager */ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; /** - * \class FormEcm - * \brief Classe permettant la generation de composants html - * \remarks Only common components must be here. + * Class to manage HTML component for ECM and generic filemanager */ class FormEcm { @@ -81,7 +79,8 @@ class FormEcm $output.= ''; foreach($cate_arbo as $key => $value) { - if ($selected && $cate_arbo[$key]['id'] == $selected) + $valueforoption = empty($cate_arbo[$key]['id']) ? $cate_arbo[$key]['relativename'] : $cate_arbo[$key]['id']; + if ($selected && $valueforoption == $selected) { $add = 'selected '; } @@ -89,7 +88,7 @@ class FormEcm { $add = ''; } - $output.= ''; + $output.= ''; } } } diff --git a/htdocs/ecm/docdir.php b/htdocs/ecm/docdir.php index e5a1de61f51..403e104c165 100644 --- a/htdocs/ecm/docdir.php +++ b/htdocs/ecm/docdir.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2017 Laurent Destailleur * Copyright (C) 2008-2012 Regis Houssin * Copyright (C) 2015-2016 Alexandre Spangaro * @@ -102,7 +102,7 @@ if ($action == 'add' && $user->rights->ecm->setup) } else { - header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager'); + header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager'.($module?'&module='.$module:'')); exit; } } @@ -227,7 +227,7 @@ if ($action == 'create') print ''.$langs->trans("Label").''."\n"; print ''.$langs->trans("AddIn").''; - print $formecm->selectAllSections(! empty($_GET["catParent"]) ? $_GET["catParent"] : $ecmdir->fk_parent, 'catParent', $module); + print $formecm->selectAllSections((GETPOST("catParent",'alpha') ? GETPOST("catParent",'alpha') : $ecmdir->fk_parent), 'catParent', $module); print ''."\n"; // Description diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php index 73856f4f9a3..60bc44ac743 100644 --- a/htdocs/ecm/docfile.php +++ b/htdocs/ecm/docfile.php @@ -123,7 +123,7 @@ if ($cancel) } else { - header("Location: ".DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($urlfile).'§ion='.urlencode($section)); + header("Location: ".DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($urlfile).'§ion='.urlencode($section).($module?'&module='.urlencode($module):'')); exit; } } @@ -242,7 +242,8 @@ if ($action == 'edit') print '
'; print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; } diff --git a/htdocs/ecm/docmine.php b/htdocs/ecm/docmine.php index a68785dd09e..2e1295ccdb0 100644 --- a/htdocs/ecm/docmine.php +++ b/htdocs/ecm/docmine.php @@ -226,7 +226,7 @@ foreach($filearray as $key => $file) } -$head = ecm_prepare_head($ecmdir); +$head = ecm_prepare_head($ecmdir, $module, $section); dol_fiche_head($head, 'card', $langs->trans("ECMSectionManual"), -1, 'dir'); @@ -235,37 +235,46 @@ if ($action == 'edit') print ''; print ''; print ''; + print ''; print ''; } -$s=''; -$result = 1; -$i=0; -$tmpecmdir=new EcmDirectory($db); // Need to create a new one -$tmpecmdir->fetch($ecmdir->id); -while ($tmpecmdir && $result > 0) -{ - $tmpecmdir->ref=$tmpecmdir->label; - if ($i == 0 && $action == 'edit') - { - $s=''; - } - else $s=$tmpecmdir->getNomUrl(1).$s; - if ($tmpecmdir->fk_parent) - { - $s=' -> '.$s; - $result=$tmpecmdir->fetch($tmpecmdir->fk_parent); - } - else - { - $tmpecmdir=0; - } - $i++; -} $morehtml=''; -$morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; +$morehtmlref = '/'.$module.'/'.$relativepath; + +if ($module == 'ecm') +{ + $s=''; + $result = 1; + $i=0; + $tmpecmdir=new EcmDirectory($db); // Need to create a new one + $tmpecmdir->fetch($ecmdir->id); + while ($tmpecmdir && $result > 0) + { + $tmpecmdir->ref=$tmpecmdir->label; + if ($i == 0 && $action == 'edit') + { + $s=''; + } + else $s=$tmpecmdir->getNomUrl(1).$s; + if ($tmpecmdir->fk_parent) + { + $s=' -> '.$s; + $result=$tmpecmdir->fetch($tmpecmdir->fk_parent); + } + else + { + $tmpecmdir=0; + } + $i++; + } + + $morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; +} + + dol_banner_tab($object, '', $morehtml, 0, '', '', $morehtmlref); @@ -307,15 +316,25 @@ else } print ''; print ''.$langs->trans("ECMDirectoryForFiles").''; -print '/ecm/'.$relativepath; +if ($module == 'ecm') +{ + print '/ecm/'.$relativepath; +} +else +{ + print '/'.$module.'/'.$relativepath; +} print ''; print ''.$langs->trans("ECMNbOfDocs").''; $nbofiles=count($filearray); print $nbofiles; -// Test if nb is same than in cache -if ($nbofiles != $ecmdir->cachenbofdoc) +if ($ecmdir->id > 0) { - $ecmdir->changeNbOfFiles((string) $nbofiles); + // Test if nb is same than in cache + if ($nbofiles != $ecmdir->cachenbofdoc) + { + $ecmdir->changeNbOfFiles((string) $nbofiles); + } } print ''; print ''.$langs->trans("TotalSizeOfAttachedFiles").''; diff --git a/htdocs/ecm/search.php b/htdocs/ecm/search.php index c52476aef02..4dbebac97c3 100644 --- a/htdocs/ecm/search.php +++ b/htdocs/ecm/search.php @@ -30,14 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; // Load traductions files -$langs->load("ecm"); -$langs->load("companies"); -$langs->load("other"); -$langs->load("users"); -$langs->load("orders"); -$langs->load("propal"); -$langs->load("bills"); -$langs->load("contracts"); +$langs->loadLangs(array("ecm","companies","other","users","orders","propal","bills","contracts")); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -52,6 +45,11 @@ $action = GETPOST('action','alpha'); $section=GETPOST('section'); if (! $section) $section=0; +$module = GETPOST('module', 'alpha'); +$website = GETPOST('website', 'alpha'); +$pageid = GETPOST('pageid', 'int'); +if (empty($module)) $module='ecm'; + $upload_dir = $conf->ecm->dir_output.'/'.$section; $sortfield = GETPOST("sortfield",'alpha'); @@ -123,7 +121,7 @@ print load_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("Search")); print $langs->trans("FeatureNotYetAvailable").'.

'; // Tool bar -$head = ecm_prepare_head_fm($ecmdir); +$head = ecm_prepare_head_fm($ecmdir, $module, $section); //dol_fiche_head($head, 'search_form', '', 1); diff --git a/htdocs/langs/en_US/ecm.lang b/htdocs/langs/en_US/ecm.lang index b69b0ff475e..7428d226008 100644 --- a/htdocs/langs/en_US/ecm.lang +++ b/htdocs/langs/en_US/ecm.lang @@ -6,7 +6,7 @@ ECMSectionAuto=Automatic directory ECMSectionsManual=Manual tree ECMSectionsAuto=Automatic tree ECMSections=Directories -ECMRoot=Root +ECMRoot=ECM Root ECMNewSection=New directory ECMAddSection=Add directory ECMCreationDate=Creation date