24 require
'../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
26 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
33 $langs->loadLangs(array(
'ecm',
'companies',
'other',
'users',
'orders',
'propal',
'bills',
'contracts',
'categories'));
35 $action =
GETPOST(
'action',
'aZ09');
36 $cancel =
GETPOST(
'cancel',
'alpha');
37 $backtopage =
GETPOST(
'backtopage',
'alpha');
40 $socid =
GETPOST(
"socid",
"int");
43 if ($user->socid > 0) {
45 $socid = $user->socid;
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) {
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
65 $section =
GETPOST(
"section",
'alpha');
78 $result = $ecmdir->fetch(
GETPOST(
"section",
'alpha'));
83 $relativepath = $ecmdir->getRelativePath();
84 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
86 $fullpath = $conf->ecm->dir_output.
'/'.$relativepath.$urlfile;
88 $relativetodocument =
'ecm/'.$relativepath;
89 $filepath = $relativepath.$urlfile;
90 $filepathtodocument = $relativetodocument.$urlfile;
93 $object =
new ECMFiles($db);
96 $extrafields->fetch_name_optionals_label($object->table_element);
98 $result = $object->fetch(0,
'', $filepathtodocument);
105 $permtoread = $user->rights->ecm->read;
106 $permtoadd = $user->rights->ecm->setup;
107 $permtoupload = $user->rights->ecm->upload;
121 header(
"Location: ".$backtopage);
124 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode($urlfile).
'§ion='.urlencode($section).($module ?
'&module='.urlencode($module) :
''));
130 if ($action ==
'update' && $permtoadd) {
133 $oldlabel =
GETPOST(
'urlfile',
'alpha');
135 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
139 $olddir = $ecmdir->getRelativePath(0);
140 $olddirrelativetodocument =
'ecm/'.$olddir;
141 $newdirrelativetodocument =
'ecm/'.$olddir;
142 $olddir = $conf->ecm->dir_output.
'/'.$olddir;
145 $oldfile = $olddir.$oldlabel;
146 $newfile = $newdir.$newlabel;
147 $newfileformove = $newfile;
149 if (preg_match(
'/\.noexe$/', $oldfile) && !preg_match(
'/\.noexe$/', $newfileformove)) {
150 $newfileformove .=
'.noexe';
157 if ($newlabel != $oldlabel) {
158 $result =
dol_move($oldfile, $newfileformove);
160 $langs->load(
'errors');
161 setEventMessages($langs->trans(
'ErrorFailToRenameFile', $oldfile, $newfile),
null,
'errors');
166 $result = $object->fetch(0,
'', $newdirrelativetodocument.$newlabel);
175 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
181 if ($object->id > 0) {
182 $ret = $extrafields->setOptionalsFromPost(
null, $object);
188 $result = $object->insertExtraFields();
195 $result = $object->update($user);
201 $object->entity = $conf->entity;
202 $object->filepath = preg_replace(
'/[\\/]+$/',
'', $newdirrelativetodocument);
203 $object->filename = $newlabel;
204 $object->label = md5_file(
dol_osencode($newfileformove));
205 $object->fullpath_orig =
'';
206 $object->gen_or_uploaded =
'unknown';
207 $object->description =
'';
208 $object->keywords =
'';
209 $result = $object->create($user);
219 $urlfile = $newlabel;
221 if (preg_match(
'/\.noexe$/', $newfileformove)) {
222 $urlfile .=
'.noexe';
225 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?urlfile='.urlencode($urlfile).
'§ion='.urlencode($section));
242 $object->section_id = $ecmdir->id;
243 $object->label = $urlfile;
246 if ($action ==
'edit') {
247 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
248 print
'<input type="hidden" name="token" value="'.newToken().
'">';
249 print
'<input type="hidden" name="section" value="'.$section.
'">';
250 print
'<input type="hidden" name="urlfile" value="'.$urlfile.
'">';
251 print
'<input type="hidden" name="module" value="'.$module.
'">';
252 print
'<input type="hidden" name="action" value="update">';
253 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
261 $tmpecmdir->fetch($ecmdir->id);
264 while ($tmpecmdir && $result > 0) {
265 $tmpecmdir->ref = $tmpecmdir->label;
266 $s = $tmpecmdir->getNomUrl(1).$s;
267 if ($tmpecmdir->fk_parent) {
269 $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
276 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfile);
278 $s =
img_picto(
'',
'object_dir').
' <a href="'.DOL_URL_ROOT.
'/ecm/index.php">'.$langs->trans(
"ECMRoot").
'</a> -> '.$s.
' -> ';
279 if ($action ==
'edit') {
280 $s .=
'<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfiletoshow.
'">';
282 $s .= $urlfiletoshow;
287 $linkback =
'<a href="'.$backtopage.
'">'.$langs->trans(
"BackToTree").
'</a>';
293 print
'<div class="fichecenter">';
295 print
'<div class="underbanner clearboth"></div>';
296 print
'<table class="border centpercent tableforfield">';
297 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"ECMCreationDate").
'</td><td>';
312 print
'<tr><td>'.$langs->trans(
"HashOfFileContent").
'</td><td>';
314 $object->fetch(0,
'', $filepathtodocument);
315 if (!empty($object->label)) {
316 print $object->label;
318 print
img_warning().
' '.$langs->trans(
"FileNotYetIndexedInDatabase");
323 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
324 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
329 print
$form->textwithpicto($langs->trans(
"DirectDownloadInternalLink"), $langs->trans(
"PrivateDownloadLinkDesc"));
333 $rellink =
'/document.php?modulepart='.$modulepart;
334 if ($forcedownload) {
335 $rellink .=
'&attachment=1';
337 if (!empty($object->entity)) {
338 $rellink .=
'&entity='.$object->entity;
340 $rellink .=
'&file='.urlencode($filepath);
341 $fulllink = $urlwithroot.$rellink;
343 if ($action !=
'edit') {
344 print
'<input type="text" class="quatrevingtpercent" id="downloadinternallink" name="downloadinternellink" value="'.dol_escape_htmltag($fulllink).
'">';
348 if ($action !=
'edit') {
349 print
' <a href="'.$fulllink.
'">'.
img_picto($langs->trans(
"Download"),
'download',
'class="opacitymedium paddingrightonly"').
'</a>';
355 if ($action !=
'edit') {
356 print
$form->textwithpicto($langs->trans(
"DirectDownloadLink"), $langs->trans(
"PublicDownloadLinkDesc"));
358 print
$form->textwithpicto($langs->trans(
"FileSharedViaALink"), $langs->trans(
"PublicDownloadLinkDesc"));
361 if (!empty($object->share)) {
362 if ($action !=
'edit') {
366 if (!empty($object->share)) {
367 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$object->share;
369 if ($forcedownload) {
370 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
373 $fulllink = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
378 if ($action !=
'edit') {
379 print
'<input type="text" class="quatrevingtpercent nopadding small" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).
'">';
383 if ($action !=
'edit') {
384 print
' <a href="'.$fulllink.
'">'.$langs->trans(
"Download").
'</a>';
387 print
'<input type="checkbox" name="shareenabled"'.($object->share ?
' checked="checked"' :
'').
' /> ';
390 if ($action !=
'edit') {
391 print
'<span class="opacitymedium">'.$langs->trans(
"FileNotShared").
'</span>';
393 print
'<input type="checkbox" name="shareenabled"'.($object->share ?
' checked="checked"' :
'').
' /> ';
398 print $object->showOptionals($extrafields, ($action ==
'edit' ?
'edit' :
'view'));
407 if ($action ==
'edit') {
408 print
$form->buttonsSaveCancel();
415 if ($action ==
'deletefile') {
416 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?section='.urlencode($section), $langs->trans(
'DeleteFile'), $langs->trans(
'ConfirmDeleteFile', $urlfile),
'confirm_deletefile',
'', 1, 1);
419 if ($action !=
'edit') {
421 print
'<div class="tabsAction">';
423 if ($user->rights->ecm->setup) {
424 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit§ion='.urlencode($section).
'&urlfile='.urlencode($urlfile).
'">'.$langs->trans(
'Edit').
'</a>';