30 if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL', 1);
33 if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36 if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39 if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
43 if (!isset($mode) || $mode !=
'noajax') {
44 require_once
'../../main.inc.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
49 $action =
GETPOST(
'action',
'aZ09');
50 $file = urldecode(
GETPOST(
'file',
'alpha'));
51 $section =
GETPOST(
"section",
'alpha');
52 $module =
GETPOST(
"module",
'alpha');
53 $urlsource =
GETPOST(
"urlsource",
'alpha');
54 $search_doc_ref =
GETPOST(
'search_doc_ref',
'alpha');
56 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
57 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
58 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
60 if (empty($page) || $page == -1) {
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
73 $rootdirfordoc = $conf->ecm->dir_output;
75 $upload_dir = dirname(str_replace(
"../",
"/", $rootdirfordoc.
'/'.$file));
79 $result = $ecmdir->fetch($section);
87 $rootdirfordoc = $conf->ecm->dir_output;
92 $result = $ecmdir->fetch($section);
98 $relativepath = $ecmdir->getRelativePath();
99 } elseif (
GETPOST(
'section_dir')) {
100 $relativepath =
GETPOST(
'section_dir');
104 $upload_dir = $rootdirfordoc.
'/'.$relativepath;
108 if (!empty($module) && $module ==
'medias' && !
GETPOST(
'website')) {
109 $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
111 $url = DOL_URL_ROOT.
'/website/index.php';
113 $url = DOL_URL_ROOT.
'/ecm/index.php';
118 $langs->loadLangs(array(
"ecm",
"companies",
"other"));
121 if ($user->socid > 0) {
122 $socid = $user->socid;
129 if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
130 dol_syslog(
"Refused to deliver file ".$upload_dir);
132 dol_print_error(0, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
136 if (empty($modulepart)) {
137 $modulepart = $module;
141 if ($modulepart ==
'ecm') {
142 if (!$user->hasRight(
'ecm',
'read')) {
145 } elseif ($modulepart ==
'medias' || $modulepart ==
'website') {
164 if (!isset($mode) || $mode !=
'noajax') {
166 header(
'Cache-Control: Public, must-revalidate');
167 header(
'Pragma: public');
182 print
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
185 $param = ($sortfield ?
'&sortfield='.urlencode($sortfield) :
'').($sortorder ?
'&sortorder='.urlencode($sortorder) :
'');
186 if (!empty($websitekey)) {
187 $param .=
'&website='.urlencode($websitekey);
189 if (!empty($pageid)) {
190 $param .=
'&pageid='.urlencode($pageid);
195 if ($type ==
'directory') {
199 $excludefiles = array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$');
200 $sorting = (strtolower($sortorder) ==
'desc' ?SORT_DESC:SORT_ASC);
203 $automodules = array(
222 'recruitment-recruitmentcandidature',
228 $parameters = array(
'modulepart'=>$module);
229 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
230 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
231 $automodules[] = $hookmanager->resArray[
'module'];
235 if ($module ==
'company') {
236 $upload_dir = $conf->societe->dir_output;
237 $excludefiles[] =
'^contact$';
238 } elseif ($module ==
'invoice') {
239 $upload_dir = $conf->facture->dir_output;
240 } elseif ($module ==
'invoice_supplier') {
241 $upload_dir = $conf->fournisseur->facture->dir_output;
242 } elseif ($module ==
'propal') {
243 $upload_dir = $conf->propal->dir_output;
244 } elseif ($module ==
'supplier_proposal') {
245 $upload_dir = $conf->supplier_proposal->dir_output;
246 } elseif ($module ==
'order') {
247 $upload_dir = $conf->commande->dir_output;
248 } elseif ($module ==
'order_supplier') {
249 $upload_dir = $conf->fournisseur->commande->dir_output;
250 } elseif ($module ==
'contract') {
251 $upload_dir = $conf->contrat->dir_output;
252 } elseif ($module ==
'product') {
253 $upload_dir = $conf->product->dir_output;
254 } elseif ($module ==
'tax') {
255 $upload_dir = $conf->tax->dir_output;
256 $excludefiles[] =
'^vat$';
257 } elseif ($module ==
'tax-vat') {
258 $upload_dir = $conf->tax->dir_output.
'/vat';
259 } elseif ($module ==
'salaries') {
260 $upload_dir = $conf->salaries->dir_output;
261 } elseif ($module ==
'project') {
262 $upload_dir = $conf->project->dir_output;
263 } elseif ($module ==
'project_task') {
264 $upload_dir = $conf->project->dir_output;
265 } elseif ($module ==
'fichinter') {
266 $upload_dir = $conf->ficheinter->dir_output;
267 } elseif ($module ==
'user') {
268 $upload_dir = $conf->user->dir_output;
269 } elseif ($module ==
'expensereport') {
270 $upload_dir = $conf->expensereport->dir_output;
271 } elseif ($module ==
'holiday') {
272 $upload_dir = $conf->holiday->dir_output;
273 } elseif ($module ==
'recruitment-recruitmentcandidature') {
274 $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
275 } elseif ($module ==
'banque') {
276 $upload_dir = $conf->bank->dir_output;
277 } elseif ($module ==
'chequereceipt') {
278 $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
279 } elseif ($module ==
'mrp-mo') {
280 $upload_dir = $conf->mrp->dir_output;
282 $parameters = array(
'modulepart'=>$module);
283 $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
284 if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
285 $upload_dir = $hookmanager->resArray[
'directory'];
290 if (in_array($module, $automodules)) {
291 $param .=
'&module='.$module;
292 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
293 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
296 $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
298 $filter = preg_quote($search_doc_ref,
'/');
299 $filearray =
dol_dir_list($upload_dir,
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
301 $perm = $user->rights->ecm->upload;
303 $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1,
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
306 if ($module ==
'medias') {
318 $relativepath =
GETPOST(
'file',
'alpha') ?
GETPOST(
'file',
'alpha') :
GETPOST(
'section_dir',
'alpha');
319 if ($relativepath && $relativepath !=
'/') {
320 $relativepath .=
'/';
322 $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
324 $param .=
'&file_manager=1';
325 if (!preg_match(
'/website=/', $param) &&
GETPOST(
'website',
'alpha')) {
326 $param .=
'&website='.urlencode(
GETPOST(
'website',
'alpha'));
328 if (!preg_match(
'/pageid=/', $param)) {
329 $param .=
'&pageid='.urlencode(
GETPOST(
'pageid',
'int'));
334 $relativepath = $ecmdir->getRelativePath();
335 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
339 if (($section ===
'0' || empty($section)) && ($module !=
'medias')) {
340 $filearray = array();
342 $filearray =
dol_dir_list($upload_dir,
"files", 0,
'', array(
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^CVS$'), $sortfield, $sorting, 1);
346 $param .=
'§ion='.$section;
347 if (isset($search_doc_ref) && $search_doc_ref !=
'') {
348 $param .=
'&search_doc_ref='.urlencode($search_doc_ref);
351 $textifempty = $langs->trans(
'NoFileFound');
352 } elseif ($section ===
'0') {
353 if ($module ==
'ecm') {
354 $textifempty =
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
356 $textifempty = $langs->trans(
'NoFileFound');
359 $textifempty = ($showonrightsize ==
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
362 if ($module ==
'medias') {
364 $modulepart =
'medias';
365 $perm = ($user->hasRight(
"website",
"write") || $user->hasRight(
"emailing",
"creer"));
367 } elseif ($module ==
'ecm') {
368 if ($user->hasRight(
"ecm",
"read")) {
373 if ($user->hasRight(
"ecm",
"upload")) {
378 if ($user->hasRight(
"ecm",
"setup")) {
383 $perm = $user->hasRight(
"ecm",
"upload");
389 $perm = $user->hasRight(
"ecm",
"upload");
396 $formfile->list_of_documents($filearray,
'', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm,
'', $sortfield, $sortorder);
404 if (!empty($conf->dol_use_jmobile)) {
407 if (empty($conf->use_javascript_ajax)) {
410 if (!empty($conf->global->MAIN_ECM_DISABLE_JS)) {
416 if ($useajax || $action ==
'deletefile') {
418 if ($action ==
'deletefile') {
419 $urlfile =
GETPOST(
'urlfile',
'alpha');
422 if (empty($section_dir)) {
423 $section_dir =
GETPOST(
"file",
"alpha");
425 $section_id = $section;
427 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
430 $formquestion[
'urlfile'] = array(
'type'=>
'hidden',
'value'=>$urlfile,
'name'=>
'urlfile');
431 $formquestion[
'section'] = array(
'type'=>
'hidden',
'value'=>$section,
'name'=>
'section');
432 $formquestion[
'section_id'] = array(
'type'=>
'hidden',
'value'=>$section_id,
'name'=>
'section_id');
433 $formquestion[
'section_dir'] = array(
'type'=>
'hidden',
'value'=>$section_dir,
'name'=>
'section_dir');
434 $formquestion[
'sortfield'] = array(
'type'=>
'hidden',
'value'=>$sortfield,
'name'=>
'sortfield');
435 $formquestion[
'sortorder'] = array(
'type'=>
'hidden',
'value'=>$sortorder,
'name'=>
'sortorder');
436 if (!empty($action) && $action ==
'file_manager') {
437 $formquestion[
'file_manager'] = array(
'type'=>
'hidden',
'value'=>1,
'name'=>
'file_manager');
439 if (!empty($websitekey)) {
440 $formquestion[
'website'] = array(
'type'=>
'hidden',
'value'=>$websitekey,
'name'=>
'website');
442 if (!empty($pageid) && $pageid > 0) {
443 $formquestion[
'pageid'] = array(
'type'=>
'hidden',
'value'=>$pageid,
'name'=>
'pageid');
446 print
$form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"),
'confirm_deletefile', $formquestion,
"no", ($useajax ?
'deletefile' : 0));
450 print
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
451 print
'<script type="text/javascript">';
456 if ($conf->browser->layout !=
'phone') {
457 print
"\n/* JS CODE TO ENABLE document_preview */\n";
459 jQuery(document).ready(function () {
460 jQuery(".documentpreview").click(function () {
461 console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
462 document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
469 // Enable jquery handlers button to delete files
470 print 'jQuery(document).ready(
function() {
'."\n";
471 print ' jQuery(
".deletefilelink").click(
function(e) {
'."\n";
472 print ' console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n";
473 print ' jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n";
474 //print ' jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
475 print
' jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
476 print
' return false;'.
"\n";
479 print
'</script>'.
"\n";
483 if ((!isset($mode) || $mode !=
'noajax') && is_object($db)) {
Class to manage ECM directories.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.