30 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL', 1);
31 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
32 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
33 if (!defined(
'NOREQUIREAJAX')) define(
'NOREQUIREAJAX',
'1');
35 if (!isset($mode) || $mode !=
'noajax')
37 require_once
'../../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
42 $action =
GETPOST(
'action',
'aZ09');
43 $file = urldecode(
GETPOST(
'file',
'alpha'));
44 $section =
GETPOST(
"section",
'alpha');
45 $module =
GETPOST(
"module",
'alpha');
46 $urlsource =
GETPOST(
"urlsource",
'alpha');
47 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
49 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
50 $sortfield =
GETPOST(
"sortfield",
'alpha');
51 $sortorder =
GETPOST(
"sortorder",
'alpha');
53 if (empty($page) || $page == -1) { $page = 0; }
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) $sortorder =
"ASC";
58 if (!$sortfield) $sortfield =
"name";
60 $rootdirfordoc = $conf->ecm->dir_output;
62 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
66 $result = $ecmdir->fetch($section);
75 $rootdirfordoc = $conf->ecm->dir_output;
81 $result = $ecmdir->fetch($section);
88 $relativepath = $ecmdir->getRelativePath();
89 } elseif (
GETPOST(
'section_dir'))
91 $relativepath =
GETPOST(
'section_dir');
95 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
100 if (
GETPOSTISSET(
'website')) $url = DOL_URL_ROOT.
'/website/index.php';
101 else $url = DOL_URL_ROOT.
'/ecm/index.php';
105 $langs->loadLangs(array(
"ecm",
"companies",
"other"));
108 if ($user->socid > 0) $socid = $user->socid;
114 if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir))
116 dol_syslog(
"Refused to deliver file ".$upload_dir);
118 dol_print_error(0, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
123 if ($modulepart ==
'ecm')
127 if ($modulepart ==
'medias')
145 if (!isset($mode) || $mode !=
'noajax')
148 header(
'Cache-Control: Public, must-revalidate');
149 header(
'Pragma: public');
165 print '<!-- ajaxdirpreview type='.$type.
' -->'.
"\n";
168 $param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
169 if (!empty($websitekey)) $param .=
'&website='.urlencode($websitekey);
170 if (!empty($pageid)) $param .=
'&pageid='.urlencode($pageid);
174 if ($type ==
'directory')
179 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
180 $sorting = (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC);
183 $automodules = array(
199 'recruitment-recruitmentcandidature',
205 if ($module ==
'company') $upload_dir = $conf->societe->dir_output;
206 elseif ($module ==
'invoice') $upload_dir = $conf->facture->dir_output;
207 elseif ($module == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output;
208 elseif ($module == 'propal') $upload_dir = $conf->propal->dir_output;
209 elseif ($module == 'supplier_proposal') $upload_dir = $conf->supplier_proposal->dir_output;
210 elseif ($module == 'order') $upload_dir = $conf->commande->dir_output;
211 elseif ($module == 'order_supplier') $upload_dir = $conf->fournisseur->commande->dir_output;
212 elseif ($module == 'contract') $upload_dir = $conf->contrat->dir_output;
213 elseif ($module == 'product') $upload_dir = $conf->product->dir_output;
214 elseif ($module == 'tax') $upload_dir = $conf->tax->dir_output;
215 elseif ($module == 'project') $upload_dir = $conf->projet->dir_output;
216 elseif ($module == 'fichinter') $upload_dir = $conf->ficheinter->dir_output;
217 elseif ($module == '
user') $upload_dir = $conf->
user->dir_output;
218 elseif ($module == 'expensereport') $upload_dir = $conf->expensereport->dir_output;
219 elseif ($module == 'holiday') $upload_dir = $conf->holiday->dir_output;
220 elseif ($module == 'recruitment-recruitmentcandidature') $upload_dir = $conf->recruitment->dir_output.'/recruitmentcandidature';
221 elseif ($module == 'banque') $upload_dir = $conf->bank->dir_output;
222 elseif ($module == 'mrp-mo') $upload_dir = $conf->mrp->dir_output.'/mo';
225 if (in_array($module, $automodules))
227 $param .=
'&module='.$module;
228 if (isset($search_doc_ref) && $search_doc_ref !=
'') $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
230 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
232 if ($module ==
'company') $excludefiles[] =
'^contact$';
234 $filter = preg_quote($search_doc_ref,
'/');
235 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
237 $perm = $user->rights->ecm->upload;
239 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
243 if ($module ==
'medias')
256 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
257 if ($relativepath && $relativepath !=
'/') $relativepath .=
'/';
258 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
261 $param .=
'&file_manager=1';
262 if (!preg_match(
'/website=/', $param)) $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
263 if (!preg_match(
'/pageid=/', $param)) $param .=
'&pageid='.urlencode(
GETPOST(
'pageid',
'int'));
267 $relativepath = $ecmdir->getRelativePath();
268 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
272 if (($section ===
'0' || empty($section)) && ($module !=
'medias'))
274 $filearray = array();
276 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
281 $param .=
'§ion='.$section;
282 if (isset($search_doc_ref) && $search_doc_ref !=
'') $param .=
'&search_doc_ref='.$search_doc_ref;
284 $textifempty = $langs->trans(
'NoFileFound');
285 } elseif ($section ===
'0')
287 if ($module ==
'ecm') $textifempty =
'<br><div class="center"><font class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</font></div><br>';
288 else $textifempty = $langs->trans(
'NoFileFound');
289 }
else $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
291 if ($module ==
'medias')
294 $modulepart =
'medias';
295 $perm = ($user->rights->website->write || $user->rights->emailing->creer);
297 } elseif ($module ==
'ecm')
299 if ($user->rights->ecm->read)
305 if ($user->rights->ecm->upload)
311 if ($user->rights->ecm->setup)
317 $perm = $user->rights->ecm->upload;
323 $perm = $user->rights->ecm->upload;
330 $formfile->list_of_documents($filearray,
'', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm);
338 if (!empty($conf->dol_use_jmobile)) $useajax = 0;
339 if (empty($conf->use_javascript_ajax)) $useajax = 0;
340 if (!empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax = 0;
344 if ($useajax || $action ==
'delete')
347 if ($action ==
'delete') $urlfile =
GETPOST(
'urlfile',
'alpha');
349 if (empty($section_dir)) $section_dir =
GETPOST(
"file",
"alpha");
350 $section_id = $section;
352 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
354 $form =
new Form($db);
355 $formquestion[
'urlfile'] = array(
'type'=>
'hidden',
'value'=>$urlfile,
'name'=>
'urlfile');
356 $formquestion[
'section'] = array(
'type'=>
'hidden',
'value'=>$section,
'name'=>
'section');
357 $formquestion[
'section_id'] = array(
'type'=>
'hidden',
'value'=>$section_id,
'name'=>
'section_id');
358 $formquestion[
'section_dir'] = array(
'type'=>
'hidden',
'value'=>$section_dir,
'name'=>
'section_dir');
359 $formquestion[
'sortfield'] = array(
'type'=>
'hidden',
'value'=>$sortfield,
'name'=>
'sortfield');
360 $formquestion[
'sortorder'] = array(
'type'=>
'hidden',
'value'=>$sortorder,
'name'=>
'sortorder');
361 if (!empty($action) && $action ==
'file_manager') $formquestion[
'file_manager'] = array(
'type'=>
'hidden',
'value'=>1,
'name'=>
'file_manager');
362 if (!empty($websitekey)) $formquestion[
'website'] = array(
'type'=>
'hidden',
'value'=>$websitekey,
'name'=>
'website');
363 if (!empty($pageid) && $pageid > 0) $formquestion[
'pageid'] = array(
'type'=>
'hidden',
'value'=>$pageid,
'name'=>
'pageid');
365 print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
370 print '<script type="text/javascript">';
375 if ($conf->browser->layout !=
'phone')
377 print "\n/* JS CODE TO ENABLE document_preview */\n";
379 jQuery(document).ready(function () {
380 jQuery(".documentpreview").click(function () {
381 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
382 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
389 // Enable jquery handlers button to delete files
390 print 'jQuery(document).ready(
function() {
'."\n";
391 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
392 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
393 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
394 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
395 print ' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
396 print ' return false;'.
"\n";
399 print '</script>'.
"\n";
403 if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_is_dir($folder)
Test if filename is a directory.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
print
Draft customers invoices.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage ECM directories.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.