diff --git a/htdocs/ecm/ajax/ecmdatabase.php b/htdocs/ecm/ajax/ecmdatabase.php index e817f6af4a4..4d782a3caeb 100644 --- a/htdocs/ecm/ajax/ecmdatabase.php +++ b/htdocs/ecm/ajax/ecmdatabase.php @@ -20,10 +20,18 @@ * \brief File to build ecm database */ -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -40,12 +48,10 @@ top_httphead(); //print ''."\n"; // Load original field value -if (isset($action) && !empty($action)) -{ +if (isset($action) && !empty($action)) { $error = 0; - if ($action == 'build' && !empty($element)) - { + if ($action == 'build' && !empty($element)) { require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; $ecmdirstatic = new EcmDirectory($db); @@ -68,22 +74,18 @@ if (isset($action) && !empty($action)) // Now we compare both trees to complete missing trees into database //var_dump($disktree); //var_dump($sqltree); - foreach ($disktree as $dirdesc) // Loop on tree onto disk - { + foreach ($disktree as $dirdesc) { // Loop on tree onto disk set_time_limit(0); // To force restarts the timeout counter from zero $dirisindatabase = 0; - foreach ($sqltree as $dirsqldesc) - { - if ($conf->$element->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname']) - { + foreach ($sqltree as $dirsqldesc) { + if ($conf->$element->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname']) { $dirisindatabase = 1; break; } } - if (!$dirisindatabase) - { + if (!$dirisindatabase) { $txt = "Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it"; dol_syslog($txt); @@ -92,24 +94,20 @@ if (isset($action) && !empty($action)) $relativepathmissing = str_replace($diroutputslash, '', $dirdesc['fullname']); $relativepathtosearchparent = $relativepathmissing; //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent); - if (preg_match('/\//', $relativepathtosearchparent)) + if (preg_match('/\//', $relativepathtosearchparent)) { //while (preg_match('/\//',$relativepathtosearchparent)) - { $relativepathtosearchparent = preg_replace('/\/[^\/]*$/', '', $relativepathtosearchparent); $txt = "Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?"; dol_syslog($txt); //print $txt." -> "; $parentdirisindatabase = 0; - foreach ($sqltree as $dirsqldesc) - { - if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent) - { + foreach ($sqltree as $dirsqldesc) { + if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent) { $parentdirisindatabase = $dirsqldesc['id']; break; } } - if ($parentdirisindatabase > 0) - { + if ($parentdirisindatabase > 0) { dol_syslog("Yes with id ".$parentdirisindatabase); //print "Yes with id ".$parentdirisindatabase."
\n"; $fk_parent = $parentdirisindatabase; @@ -123,8 +121,7 @@ if (isset($action) && !empty($action)) $fk_parent = 0; // Parent is root } - if ($fk_parent >= 0) - { + if ($fk_parent >= 0) { $ecmdirtmp->ref = 'NOTUSEDYET'; $ecmdirtmp->label = dol_basename($dirdesc['fullname']); $ecmdirtmp->description = ''; @@ -134,8 +131,7 @@ if (isset($action) && !empty($action)) dol_syslog($txt); //print $txt."
\n"; $id = $ecmdirtmp->create($user); - if ($id > 0) - { + if ($id > 0) { $newdirsql = array('id'=>$id, 'id_mere'=>$ecmdirtmp->fk_parent, 'label'=>$ecmdirtmp->label, @@ -156,11 +152,9 @@ if (isset($action) && !empty($action)) } // Loop now on each sql tree to check if dir exists - foreach ($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk - { + foreach ($sqltree as $dirdesc) { // Loop on each sqltree to check dir is on disk $dirtotest = $conf->$element->dir_output.'/'.$dirdesc['fullrelativename']; - if (!dol_is_dir($dirtotest)) - { + if (!dol_is_dir($dirtotest)) { $mesg .= $dirtotest." not found onto disk. We delete from database dir with id=".$dirdesc['id']."
\n"; $ecmdirtmp->id = $dirdesc['id']; $ecmdirtmp->delete($user, 'databaseonly'); diff --git a/htdocs/ecm/class/htmlecm.form.class.php b/htdocs/ecm/class/htmlecm.form.class.php index 5866ba16893..4b9d0a847f2 100644 --- a/htdocs/ecm/class/htmlecm.form.class.php +++ b/htdocs/ecm/class/htmlecm.form.class.php @@ -62,31 +62,29 @@ class FormEcm global $conf, $langs; $langs->load("ecm"); - if ($select_name == '') $select_name = "catParent"; + if ($select_name == '') { + $select_name = "catParent"; + } $cate_arbo = null; - if ($module == 'ecm') - { + if ($module == 'ecm') { $cat = new EcmDirectory($this->db); $cate_arbo = $cat->get_full_arbo(); - } elseif ($module == 'medias') - { + } elseif ($module == 'medias') { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $path = $conf->medias->multidir_output[$conf->entity]; $cate_arbo = dol_dir_list($path, 'directories', 1, '', array('(\.meta|_preview.*\.png)$', '^\.'), 'relativename', SORT_ASC); } $output = ''; print ''; @@ -308,23 +302,21 @@ $morehtml = ''; $morehtmlref = '/'.$module.'/'.$relativepath; -if ($module == 'ecm') -{ +if ($module == 'ecm') { $s = ''; $result = 1; $i = 0; $tmpecmdir = new EcmDirectory($db); // Need to create a new one if ($ecmdir->id > 0) { $tmpecmdir->fetch($ecmdir->id); - while ($tmpecmdir && $result > 0) - { + while ($tmpecmdir && $result > 0) { $tmpecmdir->ref = $tmpecmdir->label; - if ($i == 0 && $action == 'edit') - { + if ($i == 0 && $action == 'edit') { $s = ''; - } else $s = $tmpecmdir->getNomUrl(1).$s; - if ($tmpecmdir->fk_parent) - { + } else { + $s = $tmpecmdir->getNomUrl(1).$s; + } + if ($tmpecmdir->fk_parent) { $s = ' -> '.$s; $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); } else { @@ -337,25 +329,22 @@ if ($module == 'ecm') } $morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; } -if ($module == 'medias') -{ +if ($module == 'medias') { $s = 'medias -> '; $result = 1; $subdirs = explode('/', $section); $i = 0; - foreach ($subdirs as $subdir) - { - if ($i == (count($subdirs) - 1)) - { - if ($action == 'edit') - { + foreach ($subdirs as $subdir) { + if ($i == (count($subdirs) - 1)) { + if ($action == 'edit') { $s .= ''; $s .= ''; $s .= ''; - } else $s .= $subdir; + } else { + $s .= $subdir; + } } - if ($i < (count($subdirs) - 1)) - { + if ($i < (count($subdirs) - 1)) { $s .= $subdir.' -> '; } $i++; @@ -375,15 +364,15 @@ print ''; print img_picto('','object_dir').' '.$langs->trans("ECMRoot").' -> '; print $s; print '';*/ -if ($module == 'ecm') -{ +if ($module == 'ecm') { print ''; print ''; } print ''; print ''; print ''; print $object->showOptionals($extrafields, ($action == 'edit' ? 'edit' : 'view')); print '
'.$langs->trans("Description").''; - if ($action == 'edit') - { + if ($action == 'edit') { print ''; - } else print dol_nl2br($ecmdir->description); + } else { + print dol_nl2br($ecmdir->description); + } print '
'.$langs->trans("ECMCreationUser").''; @@ -395,8 +384,7 @@ if ($module == 'ecm') print '
'.$langs->trans("ECMCreationDate").''; -if ($module == 'ecm') -{ +if ($module == 'ecm') { print dol_print_date($ecmdir->date_c, 'dayhour'); } else { //var_dump($upload_dir); @@ -404,8 +392,7 @@ if ($module == 'ecm') } print '
'.$langs->trans("ECMDirectoryForFiles").''; -if ($module == 'ecm') -{ +if ($module == 'ecm') { print '/ecm/'.$relativepath; } else { print '/'.$module.'/'.$relativepath; @@ -414,11 +401,9 @@ print '
'.$langs->trans("ECMNbOfDocs").''; $nbofiles = count($filearray); print $nbofiles; -if ($ecmdir->id > 0) -{ +if ($ecmdir->id > 0) { // Test if nb is same than in cache - if ($nbofiles != $ecmdir->cachenbofdoc) - { + if ($nbofiles != $ecmdir->cachenbofdoc) { $ecmdir->changeNbOfFiles((string) $nbofiles); } } @@ -429,8 +414,7 @@ print '
'; -if ($action == 'edit') -{ +if ($action == 'edit') { print '
'; print ''; print '     '; @@ -439,8 +423,7 @@ if ($action == 'edit') } print '
'; -if ($action == 'edit') -{ +if ($action == 'edit') { print ''; } @@ -449,17 +432,14 @@ print dol_get_fiche_end(); // Actions buttons -if ($action != 'edit' && $action != 'delete') -{ +if ($action != 'edit' && $action != 'delete') { print '
'; - if ($permtoadd) - { + if ($permtoadd) { print ''.$langs->trans('Edit').''; } - if ($permtoadd) - { + if ($permtoadd) { print ''.$langs->trans('ECMAddSection').''; } else { print ''.$langs->trans('ECMAddSection').''; @@ -467,8 +447,7 @@ if ($action != 'edit' && $action != 'delete') //if (count($filearrayall) == 0) //{ - if ($permtoadd) - { + if ($permtoadd) { print ''.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; @@ -485,19 +464,16 @@ if ($action != 'edit' && $action != 'delete') } // Confirm remove file -if ($action == 'delete') -{ +if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.GETPOST("section", 'alpha').'&urlfile='.urlencode($_GET["urlfile"]).($backtopage ? '&backtopage='.urlencode($backtopage) : ''), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile'); } // Confirm remove file -if ($action == 'delete_dir') -{ +if ($action == 'delete_dir') { $relativepathwithoutslash = preg_replace('/[\/]$/', '', $relativepath); //Form to close proposal (signed or not) - if (count($filearrayall) > 0) - { + if (count($filearrayall) > 0) { $langs->load("other"); $formquestion = array( array('type' => 'checkbox', 'name' => 'deletedirrecursive', 'label' => $langs->trans("ContentOfDirectoryIsNotEmpty").'
'.$langs->trans("DeleteAlsoContentRecursively"), 'value' => '0') // Field to complete private note (not replace) diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 8feff24e4c3..26bf242b0f2 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -35,33 +35,41 @@ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; $langs->loadLangs(array("ecm", "companies", "other", "users", "orders", "propal", "bills", "contracts")); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'ecm', 0); // Get parameters $socid = GETPOST('socid', 'int'); $action = GETPOST('action', 'aZ09'); $section = GETPOST('section', 'int') ?GETPOST('section', 'int') : GETPOST('section_id', 'int'); -if (!$section) $section = 0; +if (!$section) { + $section = 0; +} $section_dir = GETPOST('section_dir', 'alpha'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "fullname"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "fullname"; +} $ecmdir = new EcmDirectory($db); -if ($section > 0) -{ +if ($section > 0) { $result = $ecmdir->fetch($section); - if (!$result > 0) - { + if (!$result > 0) { dol_print_error($db, $ecmdir->error); exit; } @@ -83,21 +91,24 @@ $error = 0; //include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // Upload file (code similar but different than actions_linkedfiles.inc.php) -if (GETPOST("sendit", 'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) -{ +if (GETPOST("sendit", 'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) { // Define relativepath and upload_dir $relativepath = ''; - if ($ecmdir->id) $relativepath = $ecmdir->getRelativePath(); - else $relativepath = $section_dir; + if ($ecmdir->id) { + $relativepath = $ecmdir->getRelativePath(); + } else { + $relativepath = $section_dir; + } $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; - if (is_array($_FILES['userfile']['tmp_name'])) $userfiles = $_FILES['userfile']['tmp_name']; - else $userfiles = array($_FILES['userfile']['tmp_name']); + if (is_array($_FILES['userfile']['tmp_name'])) { + $userfiles = $_FILES['userfile']['tmp_name']; + } else { + $userfiles = array($_FILES['userfile']['tmp_name']); + } - foreach ($userfiles as $key => $userfile) - { - if (empty($_FILES['userfile']['tmp_name'][$key])) - { + foreach ($userfiles as $key => $userfile) { + if (empty($_FILES['userfile']['tmp_name'][$key])) { $error++; if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) { setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors'); @@ -107,29 +118,24 @@ if (GETPOST("sendit", 'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) } } - if (!$error) - { + if (!$error) { $generatethumbs = 0; $res = dol_add_file_process($upload_dir, 0, 1, 'userfile', '', null, '', $generatethumbs); - if ($res > 0) - { + if ($res > 0) { $result = $ecmdir->changeNbOfFiles('+'); } } } // Remove file (code similar but different than actions_linkedfiles.inc.php) -if ($action == 'confirm_deletefile') -{ - if (GETPOST('confirm') == 'yes') - { +if ($action == 'confirm_deletefile') { + if (GETPOST('confirm') == 'yes') { // GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections. $upload_dir = $conf->ecm->dir_output.($relativepath ? '/'.$relativepath : ''); $file = $upload_dir."/".GETPOST('urlfile', 'alpha'); $ret = dol_delete_file($file); // This include also the delete from file index in database. - if ($ret) - { + if ($ret) { $urlfiletoshow = GETPOST('urlfile', 'alpha'); $urlfiletoshow = preg_replace('/\.noexe$/', '', $urlfiletoshow); setEventMessages($langs->trans("FileWasRemoved", $urlfiletoshow), null, 'mesgs'); @@ -144,15 +150,13 @@ if ($action == 'confirm_deletefile') } // Add directory -if ($action == 'add' && $user->rights->ecm->setup) -{ +if ($action == 'add' && $user->rights->ecm->setup) { $ecmdir->ref = 'NOTUSEDYET'; $ecmdir->label = GETPOST("label"); $ecmdir->description = GETPOST("desc"); $id = $ecmdir->create($user); - if ($id > 0) - { + if ($id > 0) { header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { @@ -164,8 +168,7 @@ if ($action == 'add' && $user->rights->ecm->setup) } // Remove directory -if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') -{ +if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') { $result = $ecmdir->delete($user); setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs'); @@ -175,8 +178,7 @@ if ($action == 'confirm_deletesection' && GETPOST('confirm', 'alpha') == 'yes') // Refresh directory view // This refresh list of dirs, not list of files (for preformance reason). List of files is refresh only if dir was not synchronized. // To refresh content of dir with cache, just open the dir in edit mode. -if ($action == 'refreshmanual') -{ +if ($action == 'refreshmanual') { $ecmdirtmp = new EcmDirectory($db); // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate @@ -196,20 +198,16 @@ if ($action == 'refreshmanual') // Now we compare both trees to complete missing trees into database //var_dump($disktree); //var_dump($sqltree); - foreach ($disktree as $dirdesc) // Loop on tree onto disk - { + foreach ($disktree as $dirdesc) { // Loop on tree onto disk $dirisindatabase = 0; - foreach ($sqltree as $dirsqldesc) - { - if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname']) - { + foreach ($sqltree as $dirsqldesc) { + if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname']) { $dirisindatabase = 1; break; } } - if (!$dirisindatabase) - { + if (!$dirisindatabase) { $txt = "Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it"; dol_syslog($txt); //print $txt."
\n"; @@ -219,24 +217,20 @@ if ($action == 'refreshmanual') $relativepathmissing = str_replace($diroutputslash, '', $dirdesc['fullname']); $relativepathtosearchparent = $relativepathmissing; //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent); - if (preg_match('/\//', $relativepathtosearchparent)) - //while (preg_match('/\//',$relativepathtosearchparent)) - { + if (preg_match('/\//', $relativepathtosearchparent)) { + //while (preg_match('/\//',$relativepathtosearchparent)) $relativepathtosearchparent = preg_replace('/\/[^\/]*$/', '', $relativepathtosearchparent); $txt = "Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?"; dol_syslog($txt); //print $txt." -> "; $parentdirisindatabase = 0; - foreach ($sqltree as $dirsqldesc) - { - if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent) - { + foreach ($sqltree as $dirsqldesc) { + if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent) { $parentdirisindatabase = $dirsqldesc['id']; break; } } - if ($parentdirisindatabase > 0) - { + if ($parentdirisindatabase > 0) { dol_syslog("Yes with id ".$parentdirisindatabase); //print "Yes with id ".$parentdirisindatabase."
\n"; $fk_parent = $parentdirisindatabase; @@ -250,8 +244,7 @@ if ($action == 'refreshmanual') $fk_parent = 0; // Parent is root } - if ($fk_parent >= 0) - { + if ($fk_parent >= 0) { $ecmdirtmp->ref = 'NOTUSEDYET'; $ecmdirtmp->label = dol_basename($dirdesc['fullname']); $ecmdirtmp->description = ''; @@ -261,8 +254,7 @@ if ($action == 'refreshmanual') dol_syslog($txt); //print $ecmdirtmp->cachenbofdoc."
\n";exit; $id = $ecmdirtmp->create($user); - if ($id > 0) - { + if ($id > 0) { $newdirsql = array('id'=>$id, 'id_mere'=>$ecmdirtmp->fk_parent, 'label'=>$ecmdirtmp->label, @@ -283,11 +275,9 @@ if ($action == 'refreshmanual') } // Loop now on each sql tree to check if dir exists - foreach ($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk - { + foreach ($sqltree as $dirdesc) { // Loop on each sqltree to check dir is on disk $dirtotest = $conf->ecm->dir_output.'/'.$dirdesc['fullrelativename']; - if (!dol_is_dir($dirtotest)) - { + if (!dol_is_dir($dirtotest)) { $ecmdirtmp->id = $dirdesc['id']; $ecmdirtmp->delete($user, 'databaseonly'); //exit; @@ -300,7 +290,9 @@ if ($action == 'refreshmanual') // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean // it to be sure that fulltree array is not used without reloading it. - if ($adirwascreated) $sqltree = null; + if ($adirwascreated) { + $sqltree = null; + } } @@ -318,7 +310,9 @@ $moreheadjs = ''; //$morejs=array(); $morejs = array('includes/jquery/plugins/blockUI/jquery.blockUI.js', 'core/js/blockUI.js'); // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp -if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; +if (empty($conf->global->MAIN_ECM_DISABLE_JS)) { + $morejs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js"; +} $moreheadjs .= '