28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
36$langs->loadLangs(array(
'ecm',
'companies',
'other',
'users',
'orders',
'propal',
'bills',
'contracts'));
40$action =
GETPOST(
'action',
'aZ09');
45$section_dir =
GETPOST(
'section_dir',
'alpha');
49$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52if (empty($page) || $page == -1) {
55$offset = $limit * $page;
67 $result = $ecmdir->fetch($section);
76$userstatic =
new User($db);
82 $socid = $user->socid;
86$permissiontoread = $user->hasRight(
'ecm',
'read');
87$permissiontocreate = $user->hasRight(
'ecm',
'upload');
88$permissiontocreatedir = $user->hasRight(
'ecm',
'setup');
89$permissiontodelete = $user->hasRight(
'ecm',
'upload');
90$permissiontodeletedir = $user->hasRight(
'ecm',
'setup');
93$hookmanager->initHooks(array(
'ecmindexcard',
'globalcard'));
108 $relativepath = $ecmdir->getRelativePath();
110 $relativepath = $section_dir;
112 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
115 if (is_array($_FILES[
'userfile'])) {
116 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
117 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
119 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
123 foreach ($userfiles as $key => $userfile) {
124 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
126 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
129 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
136 $res =
dol_add_file_process($upload_dir, $overwritefile, 1,
'userfile',
'',
null,
'', $generatethumbs);
138 $result = $ecmdir->changeNbOfFiles(
'+');
144if ($action ==
'confirm_deletefile' && $permissiontodelete) {
145 if (
GETPOST(
'confirm') ==
'yes') {
148 $upload_dir = $conf->ecm->dir_output.($relativepath ?
'/'.$relativepath :
'');
149 $file = $upload_dir.
"/".
GETPOST(
'urlfile',
'alpha');
152 $urlfiletoshow =
GETPOST(
'urlfile',
'alpha');
153 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfiletoshow);
154 setEventMessages($langs->trans(
"FileWasRemoved", $urlfiletoshow),
null,
'mesgs');
155 $result = $ecmdir->changeNbOfFiles(
'-');
162 $action =
'file_manager';
166if ($action ==
'add' && $permissiontocreatedir) {
167 $ecmdir->ref =
'NOTUSEDYET';
168 $ecmdir->label =
GETPOST(
"label");
169 $ecmdir->description =
GETPOST(
"desc");
171 $id = $ecmdir->create($user);
173 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
184if ($action ==
'confirm_deletesection' &&
GETPOST(
'confirm',
'alpha') ==
'yes' && $permissiontodeletedir) {
185 $result = $ecmdir->delete($user);
186 setEventMessages($langs->trans(
"ECMSectionWasRemoved", $ecmdir->label),
null,
'mesgs');
194if ($action ==
'refreshmanual' && $permissiontoread) {
200 $diroutputslash = str_replace(
'\\',
'/', $conf->ecm->dir_output);
201 $diroutputslash .=
'/';
204 $disktree =
dol_dir_list($conf->ecm->dir_output,
'directories', 1,
'',
'^temp$',
'',
'', 0);
207 $sqltree = $ecmdirstatic->get_full_arbo(0);
214 foreach ($disktree as $dirdesc) {
215 $dirisindatabase = 0;
216 foreach ($sqltree as $dirsqldesc) {
217 if ($conf->ecm->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname']) {
218 $dirisindatabase = 1;
223 if (!$dirisindatabase) {
224 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into database so we add it";
230 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
231 $relativepathtosearchparent = $relativepathmissing;
233 if (preg_match(
'/\//', $relativepathtosearchparent)) {
235 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
236 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
239 $parentdirisindatabase = 0;
240 foreach ($sqltree as $dirsqldesc) {
241 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent) {
242 $parentdirisindatabase = $dirsqldesc[
'id'];
246 if ($parentdirisindatabase > 0) {
247 dol_syslog(
"Yes with id ".$parentdirisindatabase);
249 $fk_parent = $parentdirisindatabase;
260 if ($fk_parent >= 0) {
261 $ecmdirtmp->ref =
'NOTUSEDYET';
263 $ecmdirtmp->description =
'';
264 $ecmdirtmp->fk_parent = $fk_parent;
266 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
269 $id = $ecmdirtmp->create($user);
271 $newdirsql = array(
'id'=>$id,
272 'id_mere'=>$ecmdirtmp->fk_parent,
273 'label'=>$ecmdirtmp->label,
274 'description'=>$ecmdirtmp->description,
275 'fullrelativename'=>$relativepathmissing);
276 $sqltree[] = $newdirsql;
280 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
283 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
291 foreach ($sqltree as $dirdesc) {
292 $dirtotest = $conf->ecm->dir_output.
'/'.$dirdesc[
'fullrelativename'];
294 $ecmdirtmp->id = $dirdesc[
'id'];
295 $ecmdirtmp->delete($user,
'databaseonly');
300 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
306 if ($adirwascreated) {
319$maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 466) ? ($_SESSION[
"dol_screenheight"] - 136) : 660;
325$morejs = array(
'includes/jquery/plugins/blockUI/jquery.blockUI.js',
'core/js/blockUI.js');
327 $morejs[] =
"includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
330$moreheadjs .=
'<script type="text/javascript">'.
"\n";
331$moreheadjs .=
'var indicatorBlockUI = \''.DOL_URL_ROOT.
"/theme/".$conf->theme.
"/img/working.gif".
'\';
'."\n";
332$moreheadjs .= '</script>
'."\n";
334llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0);
336$head = ecm_prepare_dasboard_head(null);
337print dol_get_fiche_head($head, 'index
', '', -1, '');
340// Add filemanager component
343 $url = DOL_URL_ROOT.'/ecm/index.php
'; // Must be an url without param
345include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php
';
348print dol_get_fiche_end();
Class to manage ECM directories.
Class to manage Dolibarr users.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
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_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
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_is_dir($folder)
Test if filename is a directory.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.