32if (!defined(
'NOTOKENRENEWAL')) {
 
   33  define(
'NOTOKENRENEWAL', 1); 
 
   35if (!defined(
'NOREQUIREMENU')) {
 
   36  define(
'NOREQUIREMENU', 
'1');
 
   38if (!defined(
'NOREQUIREHTML')) {
 
   39  define(
'NOREQUIREHTML', 
'1');
 
   41if (!defined(
'NOREQUIREAJAX')) {
 
   42  define(
'NOREQUIREAJAX', 
'1');
 
   45if (!isset($mode) || $mode != 
'noajax') {    
 
   46  require_once 
'../../main.inc.php';
 
   47  require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
 
   48  require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
 
   49  require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
 
   51  $action = 
GETPOST(
'action', 
'aZ09');
 
   52  $file = urldecode(
GETPOST(
'file', 
'alpha'));
 
   53  $section = 
GETPOST(
"section", 
'alpha');
 
   54  $module = 
GETPOST(
"module", 
'alpha');
 
   55  $urlsource = 
GETPOST(
"urlsource", 
'alpha');
 
   56  $search_doc_ref = 
GETPOST(
'search_doc_ref', 
'alpha');
 
   59  $sortfield = 
GETPOST(
"sortfield", 
'aZ09comma');
 
   60  $sortorder = 
GETPOST(
"sortorder", 
'aZ09comma');
 
   62  if (empty($page) || $page == -1) {
 
   65  $offset = $limit * $page;
 
   66  $pageprev = $page - 1;
 
   67  $pagenext = $page + 1;
 
   75  $rootdirfordoc = $conf->ecm->dir_output;
 
   77  $upload_dir = dirname(str_replace(
"../", 
"/", $rootdirfordoc.
'/'.$file));
 
   81    $result = $ecmdir->fetch($section);
 
   89  $rootdirfordoc = $conf->ecm->dir_output;
 
   94    $result = $ecmdir->fetch($section);
 
  100    $relativepath = $ecmdir->getRelativePath(); 
 
  101  } elseif (
GETPOST(
'section_dir')) {
 
  102    $relativepath = 
GETPOST(
'section_dir');
 
  106  $upload_dir = $rootdirfordoc.
'/'.$relativepath;
 
  110  if (!empty($module) && $module == 
'medias' && !
GETPOST(
'website')) {
 
  111    $url = DOL_URL_ROOT.
'/ecm/index_medias.php';
 
  112  } elseif (GETPOSTISSET(
'website')) {
 
  113    $url = DOL_URL_ROOT.
'/website/index.php';
 
  115    $url = DOL_URL_ROOT.
'/ecm/index.php';
 
  120$langs->loadLangs(array(
"ecm", 
"companies", 
"other"));
 
  122if (empty($modulepart)) {
 
  123  $modulepart = $module;
 
  127if ($user->socid > 0) {
 
  128  $socid = $user->socid;
 
  131if (preg_match(
'/\.\./', $upload_dir) || preg_match(
'/[<>|]/', $upload_dir)) {
 
  132  dol_syslog(
"Refused to deliver file ".$upload_dir);
 
  134  dol_print_error(
null, $langs->trans(
"ErrorFileNameInvalid", $upload_dir));
 
  138if ($modulepart == 
'ecm') {
 
  139  if (!$user->hasRight(
'ecm', 
'read')) {
 
  142} elseif ($modulepart == 
'medias' || $modulepart == 
'website') {
 
  161if (!isset($mode) || $mode != 
'noajax') {
 
  163  header(
'Cache-Control: Public, must-revalidate');
 
  164  header(
'Pragma: public');
 
  179print 
'<!-- ajaxdirpreview type='.$type.
' module='.$module.
' modulepart='.$modulepart.
'-->'.
"\n";
 
  182$param = ($sortfield ? 
'&sortfield='.urlencode($sortfield) : 
'').($sortorder ? 
'&sortorder='.urlencode($sortorder) : 
'');
 
  183if (!empty($websitekey)) {
 
  184  $param .= 
'&website='.urlencode($websitekey);
 
  186if (!empty($pageid)) {
 
  187  $param .= 
'&pageid='.((int) $pageid);
 
  192if ($type == 
'directory') {
 
  196  $excludefiles = array(
'^SPECIMEN\.pdf$', 
'^\.', 
'(\.meta|_preview.*\.png)$', 
'^temp$', 
'^payments$', 
'^CVS$', 
'^thumbs$');
 
  197  $sorting = (strtolower($sortorder) == 
'desc' ? SORT_DESC : SORT_ASC);
 
  200  $automodules = array(
 
  219    'recruitment-recruitmentcandidature',
 
  225  $parameters = array(
'modulepart' => $module);
 
  226  $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
 
  227  if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
 
  228    if (is_array($hookmanager->resArray[
'module'])) {
 
  229      $automodules = array_merge($automodules, $hookmanager->resArray[
'module']);
 
  231      $automodules[] = $hookmanager->resArray[
'module'];
 
  236  if ($module == 
'company') {
 
  237    $upload_dir = $conf->societe->dir_output;
 
  238    $excludefiles[] = 
'^contact$'; 
 
  239  } elseif ($module == 
'invoice') {
 
  240    $upload_dir = $conf->facture->dir_output;
 
  241  } elseif ($module == 
'invoice_supplier') {
 
  242    $upload_dir = $conf->fournisseur->facture->dir_output;
 
  243  } elseif ($module == 
'propal') {
 
  244    $upload_dir = $conf->propal->dir_output;
 
  245  } elseif ($module == 
'supplier_proposal') {
 
  246    $upload_dir = $conf->supplier_proposal->dir_output;
 
  247  } elseif ($module == 
'order') {
 
  248    $upload_dir = $conf->commande->dir_output;
 
  249  } elseif ($module == 
'order_supplier') {
 
  250    $upload_dir = $conf->fournisseur->commande->dir_output;
 
  251  } elseif ($module == 
'contract') {
 
  252    $upload_dir = $conf->contrat->dir_output;
 
  253  } elseif ($module == 
'product') {
 
  254    $upload_dir = $conf->product->dir_output;
 
  255  } elseif ($module == 
'tax') {
 
  256    $upload_dir = $conf->tax->dir_output;
 
  257    $excludefiles[] = 
'^vat$'; 
 
  258  } elseif ($module == 
'tax-vat') {
 
  259    $upload_dir = $conf->tax->dir_output.
'/vat';
 
  260  } elseif ($module == 
'salaries') {
 
  261    $upload_dir = $conf->salaries->dir_output;
 
  262  } elseif ($module == 
'project') {
 
  263    $upload_dir = $conf->project->dir_output;
 
  264  } elseif ($module == 
'project_task') {
 
  265    $upload_dir = $conf->project->dir_output;
 
  266  } elseif ($module == 
'fichinter') {
 
  267    $upload_dir = $conf->ficheinter->dir_output;
 
  268  } elseif ($module == 
'user') {
 
  269    $upload_dir = $conf->user->dir_output;
 
  270  } elseif ($module == 
'expensereport') {
 
  271    $upload_dir = $conf->expensereport->dir_output;
 
  272  } elseif ($module == 
'holiday') {
 
  273    $upload_dir = $conf->holiday->dir_output;
 
  274  } elseif ($module == 
'recruitment-recruitmentcandidature') {
 
  275    $upload_dir = $conf->recruitment->dir_output.
'/recruitmentcandidature';
 
  276  } elseif ($module == 
'banque') {
 
  277    $upload_dir = $conf->bank->dir_output;
 
  278  } elseif ($module == 
'chequereceipt') {
 
  279    $upload_dir = $conf->bank->dir_output.
'/checkdeposits';
 
  280  } elseif ($module == 
'mrp-mo') {
 
  281    $upload_dir = $conf->mrp->dir_output;
 
  283    $parameters = array(
'modulepart' => $module);
 
  284    $reshook = $hookmanager->executeHooks(
'addSectionECMAuto', $parameters);
 
  285    if ($reshook > 0 && is_array($hookmanager->resArray) && count($hookmanager->resArray) > 0) {
 
  286      $upload_dir = $hookmanager->resArray[
'directory'];
 
  291  if (in_array($module, $automodules)) {
 
  292    $param .= 
'&module='.$module;
 
  293    if (isset($search_doc_ref) && $search_doc_ref != 
'') {
 
  294      $param .= 
'&search_doc_ref='.urlencode($search_doc_ref);
 
  297    $textifempty = ($section ? $langs->trans(
"NoFileFound") : ($showonrightsize == 
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"NoFileFound")));
 
  299    $filter = preg_quote($search_doc_ref, 
'/');
 
  300    $filearray = 
dol_dir_list($upload_dir, 
"files", 1, $filter, $excludefiles, $sortfield, $sorting, 1);
 
  302    $perm = $user->hasRight(
'ecm', 
'upload');
 
  304    $formfile->list_of_autoecmfiles($upload_dir, $filearray, $module, $param, 1, 
'', $perm, 1, $textifempty, $maxlengthname, $url, 1);
 
  307    if ($module == 
'medias') {
 
  319      $relativepath = 
GETPOST(
'file', 
'alpha') ? 
GETPOST(
'file', 
'alpha') : 
GETPOST(
'section_dir', 
'alpha');
 
  320      if ($relativepath && $relativepath != 
'/') {
 
  321        $relativepath .= 
'/';
 
  323      $upload_dir = $dolibarr_main_data_root.
'/'.$module.
'/'.$relativepath;
 
  324      if (GETPOSTISSET(
'website') || GETPOSTISSET(
'file_manager')) {
 
  325        $param .= 
'&file_manager=1';
 
  326        if (!preg_match(
'/website=/', $param) && 
GETPOST(
'website', 
'alpha')) {
 
  327          $param .= 
'&website='.urlencode(
GETPOST(
'website', 
'alpha'));
 
  329        if (!preg_match(
'/pageid=/', $param)) {
 
  330          $param .= 
'&pageid='.GETPOSTINT(
'pageid');
 
  335      $relativepath = $ecmdir->getRelativePath();
 
  336      $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
 
  340    if (($section === 
'0' || empty($section)) && ($module != 
'medias')) {
 
  341      $filearray = array();
 
  343      $filearray = 
dol_dir_list($upload_dir, 
"files", 0, 
'', array(
'^\.', 
'(\.meta|_preview.*\.png)$', 
'^temp$', 
'^CVS$'), $sortfield, $sorting, 1);
 
  347      $param .= 
'§ion='.$section;
 
  348      if (isset($search_doc_ref) && $search_doc_ref != 
'') {
 
  349        $param .= 
'&search_doc_ref='.urlencode($search_doc_ref);
 
  352      $textifempty = $langs->trans(
'NoFileFound');
 
  353    } elseif ($section === 
'0') {
 
  354      if ($module == 
'ecm') {
 
  355        $textifempty = 
'<br><div class="center"><span class="warning">'.$langs->trans(
"DirNotSynchronizedSyncFirst").
'</span></div><br>';
 
  357        $textifempty = $langs->trans(
'NoFileFound');
 
  360      $textifempty = ($showonrightsize == 
'featurenotyetavailable' ? $langs->trans(
"FeatureNotYetAvailable") : $langs->trans(
"ECMSelectASection"));
 
  363    if ($module == 
'medias') {
 
  365      $modulepart = 
'medias';
 
  366      $perm = ($user->hasRight(
"website", 
"write") || $user->hasRight(
"emailing", 
"creer"));
 
  368    } elseif ($module == 
'ecm') { 
 
  369      if ($user->hasRight(
"ecm", 
"read")) {
 
  374      if ($user->hasRight(
"ecm", 
"upload")) {
 
  379      if ($user->hasRight(
"ecm", 
"setup")) {
 
  384      $perm = $user->hasRight(
"ecm", 
"upload");
 
  390      $perm = $user->hasRight(
"ecm", 
"upload");
 
  397    $formfile->list_of_documents($filearray, 
'', $modulepart, $param, 1, $relativepath, $perm, $useinecm, $textifempty, $maxlengthname, $title, $url, 0, $perm, 
'', $sortfield, $sortorder);
 
  405if (!empty($conf->dol_use_jmobile)) {
 
  408if (empty($conf->use_javascript_ajax)) {
 
  417if ($useajax || $action == 
'deletefile') {
 
  419  if ($action == 
'deletefile') {
 
  420    $urlfile = 
GETPOST(
'urlfile', 
'alpha');
 
  423  if (empty($section_dir)) {
 
  424    $section_dir = 
GETPOST(
"file", 
"alpha");
 
  426  $section_id = $section;
 
  428  require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
 
  430  $form = 
new Form($db);
 
  431  $formquestion = array();
 
  432  $formquestion[
'urlfile'] = array(
'type' => 
'hidden', 
'value' => $urlfile, 
'name' => 
'urlfile'); 
 
  433  $formquestion[
'section'] = array(
'type' => 
'hidden', 
'value' => $section, 
'name' => 
'section'); 
 
  434  $formquestion[
'section_id'] = array(
'type' => 
'hidden', 
'value' => $section_id, 
'name' => 
'section_id'); 
 
  435  $formquestion[
'section_dir'] = array(
'type' => 
'hidden', 
'value' => $section_dir, 
'name' => 
'section_dir'); 
 
  436  $formquestion[
'sortfield'] = array(
'type' => 
'hidden', 
'value' => $sortfield, 
'name' => 
'sortfield'); 
 
  437  $formquestion[
'sortorder'] = array(
'type' => 
'hidden', 
'value' => $sortorder, 
'name' => 
'sortorder'); 
 
  438  if (!empty($action) && $action == 
'file_manager') {
 
  439    $formquestion[
'file_manager'] = array(
'type' => 
'hidden', 
'value' => 1, 
'name' => 
'file_manager');
 
  441  if (!empty($websitekey)) {
 
  442    $formquestion[
'website'] = array(
'type' => 
'hidden', 
'value' => $websitekey, 
'name' => 
'website');
 
  444  if (!empty($pageid) && $pageid > 0) {
 
  445    $formquestion[
'pageid'] = array(
'type' => 
'hidden', 
'value' => $pageid, 
'name' => 
'pageid');
 
  448  print $form->formconfirm($url, $langs->trans(
"DeleteFile"), $langs->trans(
"ConfirmDeleteFile"), 
'confirm_deletefile', $formquestion, 
"no", ($useajax ? 
'deletefile' : 0));
 
  452  print 
'<!-- ajaxdirpreview.php: js to manage preview of doc -->'.
"\n";
 
  453  print 
'<script nonce="'.getNonce().
'" type="text/javascript">';
 
  458  if ($conf->browser->layout != 
'phone') {
 
  459    print 
"\n/* JS CODE TO ENABLE document_preview */\n";
 
  461                jQuery(document).ready(function () { 
  462              jQuery(".documentpreview").click(function () { 
  463                    console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\')); 
  464                    document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities(
"Preview")).
'\');
 
  471  // Enable jquery handlers button to delete files 
  472  print 'jQuery(document).ready(
function() {
'."\n"; 
  473  print '  jQuery(
".deletefilelink").click(
function(e) { 
'."\n"; 
  474  print '    console.log(
"We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(
this).attr(
"rel"));
'."\n"; 
  475  print '    jQuery(
"#urlfile").val(jQuery(
this).attr(
"rel"));
'."\n"; 
  476  //print '    jQuery(
"#section_dir").val(\
'aaa\');'.
"\n";
 
  477  print 
'    jQuery("#dialog-confirm-deletefile").dialog("open");'.
"\n";
 
  478  print 
'    return false;'.
"\n";
 
  481  print 
'</script>'.
"\n";
 
  485if ((!isset($mode) || $mode != 
'noajax') && is_object($db)) {
 
Class to manage ECM directories.
 
dol_dir_list($utf8_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.
 
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) 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.