diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index ca2b9fec473..4c4a3fc3412 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -345,7 +345,7 @@ class EcmDirectory extends CommonObject $sql .= " t.date_c as date_c,"; $sql .= " t.tms as date_m"; $sql .= " FROM ".MAIN_DB_PREFIX."ecm_directories as t"; - $sql .= " WHERE t.rowid = ".$id; + $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/ecm/dir_card.php b/htdocs/ecm/dir_card.php index 9dc6977f1e4..8b86f99d2c7 100644 --- a/htdocs/ecm/dir_card.php +++ b/htdocs/ecm/dir_card.php @@ -54,7 +54,7 @@ $pagenext = $page + 1; if (!$sortorder) $sortorder = "ASC"; if (!$sortfield) $sortfield = "name"; -$section = GETPOST("section", 'alpha') ?GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); +$section = GETPOST("section", 'alpha') ? GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); if (!$section) { dol_print_error('', "ErrorSectionParamNotDefined"); @@ -66,15 +66,15 @@ $ecmdir = new EcmDirectory($db); if ($module == 'ecm') { + // $section should be an int except if it is dir not yet created into EcmDirectory $result = $ecmdir->fetch($section); - if (!$result > 0) - { - dol_print_error($db, $ecmdir->error); - exit; + if ($result > 0) { + $relativepath = $ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + } else { + $relativepath = $section; + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } - - $relativepath = $ecmdir->getRelativePath(); - $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } else // For example $module == 'medias' { $relativepath = $section; @@ -143,28 +143,23 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') } // Remove dir -if ($action == 'confirm_deletedir' && $confirm == 'yes') -{ +if ($action == 'confirm_deletedir' && $confirm == 'yes') { $backtourl = DOL_URL_ROOT."/ecm/index.php"; - if ($module == 'medias') - { + if ($module == 'medias') { $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1"; } $deletedirrecursive = (GETPOST('deletedirrecursive', 'alpha') == 'on' ? 1 : 0); - if ($module == 'ecm') - { + if ($module == 'ecm' && $ecmdir->id > 0) { // If manual ECM and directory is indexed into database // Fetch was already done $result = $ecmdir->delete($user, 'all', $deletedirrecursive); - if ($result <= 0) - { + if ($result <= 0) { $langs->load('errors'); setEventMessages($langs->trans($ecmdir->error, $ecmdir->label), null, 'errors'); } } else { - if ($deletedirrecursive) - { + if ($deletedirrecursive) { $resbool = dol_delete_dir_recursive($upload_dir, 0, 1); } else { $resbool = dol_delete_dir($upload_dir, 1); @@ -176,8 +171,7 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes') $result = 0; } } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$backtourl); exit; } @@ -269,10 +263,9 @@ if ($action == 'update' && !GETPOST('cancel', 'alpha')) } - -/******************************************************************* -* View -********************************************************************/ +/* + * View + */ $form = new Form($db); @@ -281,9 +274,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); - -if ($module == 'ecm') -{ +if ($module == 'ecm' && $ecmdir->id > 0) { $object->fetch($ecmdir->id); } @@ -323,24 +314,27 @@ if ($module == 'ecm') $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') + if ($ecmdir->id > 0) { + $tmpecmdir->fetch($ecmdir->id); + while ($tmpecmdir && $result > 0) { - $s = ''; - } else $s = $tmpecmdir->getNomUrl(1).$s; - if ($tmpecmdir->fk_parent) - { - $s = ' -> '.$s; - $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); - } else { - $tmpecmdir = 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++; } - $i++; + } else { + $s .= join(' -> ', explode('/', $section)); } - $morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; } if ($module == 'medias') @@ -393,9 +387,11 @@ if ($module == 'ecm') print ''; print ''.$langs->trans("ECMCreationUser").''; - $userecm = new User($db); - $userecm->fetch($ecmdir->fk_user_c); - print $userecm->getNomUrl(1); + if ($ecmdir->fk_user_c > 0) { + $userecm = new User($db); + $userecm->fetch($ecmdir->fk_user_c); + print $userecm->getNomUrl(1); + } print ''; } print ''.$langs->trans("ECMCreationDate").'';