diff --git a/htdocs/ecm/file_card.php b/htdocs/ecm/file_card.php index 496afbf8568..d89e94861c0 100644 --- a/htdocs/ecm/file_card.php +++ b/htdocs/ecm/file_card.php @@ -36,14 +36,15 @@ $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); -if (!$user->rights->ecm->setup) accessforbidden(); +if (!$user->rights->ecm->setup) { + accessforbidden(); +} // Get parameters $socid = GETPOST("socid", "int"); // Security check -if ($user->socid > 0) -{ +if ($user->socid > 0) { $action = ''; $socid = $user->socid; } @@ -52,22 +53,26 @@ $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 = "label"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "label"; +} $section = GETPOST("section", 'alpha'); -if (!$section) -{ +if (!$section) { dol_print_error('', 'Error, section parameter missing'); exit; } $urlfile = GETPOST("urlfile"); -if (!$urlfile) -{ +if (!$urlfile) { dol_print_error('', "ErrorParamNotDefined"); exit; } @@ -75,8 +80,7 @@ if (!$urlfile) // Load ecm object $ecmdir = new EcmDirectory($db); $result = $ecmdir->fetch(GETPOST("section", 'alpha')); -if (!$result > 0) -{ +if (!$result > 0) { dol_print_error($db, $ecmdir->error); exit; } @@ -85,13 +89,9 @@ $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $fullpath = $conf->ecm->dir_output.'/'.$relativepath.$urlfile; -$file = new stdClass(); -$file->section_id = $ecmdir->id; -$file->label = $urlfile; - $relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document -$filepath = $relativepath.$file->label; -$filepathtodocument = $relativetodocument.$file->label; +$filepath = $relativepath.$urlfile; +$filepathtodocument = $relativetodocument.$urlfile; // Try to load object from index $object = new ECMFiles($db); @@ -100,8 +100,7 @@ $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($object->table_element); $result = $object->fetch(0, '', $filepathtodocument); -if ($result < 0) -{ +if ($result < 0) { dol_print_error($db, $object->error, $object->errors); exit; } @@ -112,11 +111,9 @@ if ($result < 0) * Actions */ -if ($cancel) -{ +if ($cancel) { $action = ''; - if ($backtopage) - { + if ($backtopage) { header("Location: ".$backtopage); exit; } else { @@ -126,8 +123,7 @@ if ($cancel) } // Rename file -if ($action == 'update') -{ +if ($action == 'update') { $error = 0; $oldlabel = GETPOST('urlfile', 'alpha'); @@ -154,11 +150,9 @@ if ($action == 'update') // Now we update index of file $db->begin(); //print $oldfile.' - '.$newfile; - if ($newlabel != $oldlabel) - { + if ($newlabel != $oldlabel) { $result = dol_move($oldfile, $newfileformove); // This include update of database - if (!$result) - { + if (!$result) { $langs->load('errors'); setEventMessages($langs->trans('ErrorFailToRenameFile', $oldfile, $newfile), null, 'errors'); $error++; @@ -166,27 +160,25 @@ if ($action == 'update') // Reload object after the move $result = $object->fetch(0, '', $newdirrelativetodocument.$newlabel); - if ($result < 0) - { + if ($result < 0) { dol_print_error($db, $object->error, $object->errors); exit; } } - if (!$error) - { - if ($shareenabled) - { + if (!$error) { + if ($shareenabled) { require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; $object->share = getRandomPassword(true); } else { $object->share = ''; } - if ($object->id > 0) - { + if ($object->id > 0) { $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } if (!$error) { // Actions on extra fields $result = $object->insertExtraFields(); @@ -197,8 +189,7 @@ if ($action == 'update') } // Call update to set the share key $result = $object->update($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'warnings'); } } else { @@ -212,15 +203,13 @@ if ($action == 'update') $object->description = ''; // indexed content $object->keyword = ''; // keyword content $result = $object->create($user); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'warnings'); } } } - if (!$error) - { + if (!$error) { $db->commit(); $urlfile = $newlabel; @@ -246,10 +235,11 @@ $form = new Form($db); llxHeader(); -$head = ecm_file_prepare_head($file); +$object->section_id = $ecmdir->id; +$object->label = $urlfile; +$head = ecm_file_prepare_head($object); -if ($action == 'edit') -{ +if ($action == 'edit') { print '