2012-03-24 15:20:49 +01:00
< ? php
/* Copyright ( C ) 2004 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 Simon Tosser < simon @ kornog - computing . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2012-03-24 15:20:49 +01:00
* Copyright ( C ) 2010 Pierre Morin < pierre . morin @ auguria . net >
2013-04-21 12:45:34 +02:00
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
2012-03-24 15:20:49 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-03-24 15:20:49 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2012-03-24 15:20:49 +01:00
*/
/**
2012-03-25 22:47:37 +02:00
* \file htdocs / core / ajax / ajaxdirpreview . php
* \brief Service to return a HTML preview of a directory
2012-03-24 15:20:49 +01:00
* Call of this service is made with URL :
2012-03-25 22:47:37 +02:00
* ajaxdirpreview . php ? mode = nojs & action = preview & module = ecm & section = 0 & file = xxx
2012-03-24 15:20:49 +01:00
*/
2021-02-23 22:03:23 +01:00
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , 1 ); // Disables token renewal
}
if ( ! defined ( 'NOREQUIREMENU' )) {
define ( 'NOREQUIREMENU' , '1' );
}
if ( ! defined ( 'NOREQUIREHTML' )) {
define ( 'NOREQUIREHTML' , '1' );
}
if ( ! defined ( 'NOREQUIREAJAX' )) {
define ( 'NOREQUIREAJAX' , '1' );
}
2012-03-24 15:20:49 +01:00
2021-02-23 22:03:23 +01:00
if ( ! isset ( $mode ) || $mode != 'noajax' ) { // For ajax call
2020-09-07 10:18:17 +02:00
require_once '../../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php' ;
$action = GETPOST ( 'action' , 'aZ09' );
$file = urldecode ( GETPOST ( 'file' , 'alpha' ));
$section = GETPOST ( " section " , 'alpha' );
$module = GETPOST ( " module " , 'alpha' );
$urlsource = GETPOST ( " urlsource " , 'alpha' );
$search_doc_ref = GETPOST ( 'search_doc_ref' , 'alpha' );
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2021-06-19 23:52:52 +02:00
$sortfield = GETPOST ( " sortfield " , 'aZ09comma' );
$sortorder = GETPOST ( " sortorder " , 'aZ09comma' );
2020-09-07 10:18:17 +02:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-23 22:03:23 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2020-09-07 10:18:17 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-23 22:03:23 +01:00
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
if ( ! $sortfield ) {
$sortfield = " name " ;
}
2012-07-30 22:38:21 +02:00
2017-08-20 23:16:20 +02:00
$rootdirfordoc = $conf -> ecm -> dir_output ;
$upload_dir = dirname ( str_replace ( " ../ " , " / " , $rootdirfordoc . '/' . $file ));
2012-03-25 22:47:37 +02:00
2020-06-03 11:20:59 +02:00
$ecmdir = new EcmDirectory ( $db );
if ( $section > 0 ) {
2020-09-07 10:18:17 +02:00
$result = $ecmdir -> fetch ( $section );
2022-08-12 15:54:50 +02:00
if ( ! ( $result > 0 )) {
2020-09-07 10:18:17 +02:00
//dol_print_error($db,$ecmdir->error);
//exit;
}
2020-06-03 11:20:59 +02:00
}
2021-06-19 23:52:52 +02:00
} else {
// For no ajax call
2017-08-20 23:16:20 +02:00
$rootdirfordoc = $conf -> ecm -> dir_output ;
$ecmdir = new EcmDirectory ( $db );
2020-09-07 10:18:17 +02:00
$relativepath = '' ;
2021-02-23 22:03:23 +01:00
if ( $section > 0 ) {
2020-09-07 10:18:17 +02:00
$result = $ecmdir -> fetch ( $section );
2022-08-12 15:54:50 +02:00
if ( ! ( $result > 0 )) {
2020-09-07 10:18:17 +02:00
dol_print_error ( $db , $ecmdir -> error );
exit ;
}
$relativepath = $ecmdir -> getRelativePath (); // Example 'mydir/'
2021-02-23 22:03:23 +01:00
} elseif ( GETPOST ( 'section_dir' )) {
2019-12-16 13:06:25 +01:00
$relativepath = GETPOST ( 'section_dir' );
2018-10-18 21:22:30 +02:00
}
//var_dump($section.'-'.GETPOST('section_dir').'-'.$relativepath);
$upload_dir = $rootdirfordoc . '/' . $relativepath ;
2012-03-25 22:47:37 +02:00
}
2017-11-10 13:45:38 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $url )) {
if ( GETPOSTISSET ( 'website' )) {
$url = DOL_URL_ROOT . '/website/index.php' ;
} else {
$url = DOL_URL_ROOT . '/ecm/index.php' ;
}
2017-11-10 13:45:38 +01:00
}
2012-03-24 15:20:49 +01:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2019-12-16 13:06:25 +01:00
$langs -> loadLangs ( array ( " ecm " , " companies " , " other " ));
2012-03-24 15:20:49 +01:00
// Security check
2021-02-23 22:03:23 +01:00
if ( $user -> socid > 0 ) {
$socid = $user -> socid ;
}
2012-03-24 15:20:49 +01:00
2012-03-25 22:47:37 +02:00
//print 'xxx'.$upload_dir;
2012-03-24 15:20:49 +01:00
// Security:
2017-08-20 23:16:20 +02:00
// On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers.
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/\.\./' , $upload_dir ) || preg_match ( '/[<>|]/' , $upload_dir )) {
2020-09-07 10:18:17 +02:00
dol_syslog ( " Refused to deliver file " . $upload_dir );
// Do no show plain path in shown error message
dol_print_error ( 0 , $langs -> trans ( " ErrorFileNameInvalid " , $upload_dir ));
exit ;
2012-03-24 15:20:49 +01:00
}
2017-08-20 23:16:20 +02:00
// Check permissions
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'ecm' ) {
if ( ! $user -> rights -> ecm -> read ) {
accessforbidden ();
}
2017-08-20 23:16:20 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $modulepart == 'medias' ) {
2017-08-20 23:16:20 +02:00
// Always allowed
}
2012-03-24 15:20:49 +01:00
/*
* Action
*/
2012-06-08 23:48:53 +02:00
// None
2012-03-24 15:20:49 +01:00
/*
* View
*/
2021-02-23 22:03:23 +01:00
if ( ! isset ( $mode ) || $mode != 'noajax' ) {
2012-07-08 13:57:51 +02:00
// Ajout directives pour resoudre bug IE
2020-09-07 10:18:17 +02:00
header ( 'Cache-Control: Public, must-revalidate' );
header ( 'Pragma: public' );
2012-07-30 22:38:21 +02:00
2020-09-07 10:18:17 +02:00
top_httphead ();
2012-03-24 15:20:49 +01:00
}
2019-12-16 13:06:25 +01:00
$type = 'directory' ;
2012-03-24 15:20:49 +01:00
// This test if file exists should be useless. We keep it to find bug more easily
2021-02-23 22:03:23 +01:00
if ( ! dol_is_dir ( $upload_dir )) {
2020-09-07 10:18:17 +02:00
//dol_mkdir($upload_dir);
/* $langs -> load ( " install " );
2021-02-23 22:03:23 +01:00
dol_print_error ( 0 , $langs -> trans ( " ErrorDirDoesNotExists " , $upload_dir ));
exit ; */
2012-03-24 15:20:49 +01:00
}
2016-12-13 01:19:33 +01:00
print '<!-- ajaxdirpreview type=' . $type . ' -->' . " \n " ;
2017-06-18 19:42:59 +02:00
//print '<!-- Page called with mode='.dol_escape_htmltag(isset($mode)?$mode:'').' type='.dol_escape_htmltag($type).' module='.dol_escape_htmltag($module).' url='.dol_escape_htmltag($url).' '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
2012-03-24 15:20:49 +01:00
2019-12-16 13:06:25 +01:00
$param = ( $sortfield ? '&sortfield=' . urlencode ( $sortfield ) : '' ) . ( $sortorder ? '&sortorder=' . urlencode ( $sortorder ) : '' );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $websitekey )) {
$param .= '&website=' . urlencode ( $websitekey );
}
if ( ! empty ( $pageid )) {
$param .= '&pageid=' . urlencode ( $pageid );
}
2016-07-11 02:06:46 +02:00
2012-03-24 15:20:49 +01:00
2012-06-24 17:49:52 +02:00
// Dir scan
2021-02-23 22:03:23 +01:00
if ( $type == 'directory' ) {
2020-09-07 10:18:17 +02:00
$formfile = new FormFile ( $db );
$maxlengthname = 40 ;
$excludefiles = array ( '^SPECIMEN\.pdf$' , '^\.' , '(\.meta|_preview.*\.png)$' , '^temp$' , '^payments$' , '^CVS$' , '^thumbs$' );
$sorting = ( strtolower ( $sortorder ) == 'desc' ? SORT_DESC : SORT_ASC );
// Right area. If module is defined here, we are in automatic ecm.
$automodules = array (
'company' ,
'invoice' ,
'invoice_supplier' ,
'propal' ,
'supplier_proposal' ,
'order' ,
'order_supplier' ,
'contract' ,
'product' ,
'tax' ,
2021-12-07 02:00:34 +01:00
'tax-vat' ,
'salaries' ,
2020-09-07 10:18:17 +02:00
'project' ,
2021-10-24 11:38:45 +02:00
'project_task' ,
2020-09-07 10:18:17 +02:00
'fichinter' ,
'user' ,
'expensereport' ,
'holiday' ,
'recruitment-recruitmentcandidature' ,
'banque' ,
2021-10-24 11:38:45 +02:00
'chequereceipt' ,
2020-09-07 10:18:17 +02:00
'mrp-mo'
);
2021-02-06 13:21:16 +01:00
$parameters = array ( 'modulepart' => $module );
$reshook = $hookmanager -> executeHooks ( 'addSectionECMAuto' , $parameters );
2021-10-25 22:07:31 +02:00
if ( $reshook > 0 && is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray ) > 0 ) {
$automodules [] = $hookmanager -> resArray [ 'module' ];
2021-02-06 13:21:16 +01:00
}
2020-09-07 10:18:17 +02:00
// TODO change for multicompany sharing
2021-02-23 22:03:23 +01:00
if ( $module == 'company' ) {
$upload_dir = $conf -> societe -> dir_output ;
2021-12-07 02:00:34 +01:00
$excludefiles [] = '^contact$' ; // The subdir 'contact' contains files of contacts.
2021-02-23 22:03:23 +01:00
} elseif ( $module == 'invoice' ) {
$upload_dir = $conf -> facture -> dir_output ;
} elseif ( $module == 'invoice_supplier' ) {
$upload_dir = $conf -> fournisseur -> facture -> dir_output ;
} elseif ( $module == 'propal' ) {
$upload_dir = $conf -> propal -> dir_output ;
} elseif ( $module == 'supplier_proposal' ) {
$upload_dir = $conf -> supplier_proposal -> dir_output ;
} elseif ( $module == 'order' ) {
$upload_dir = $conf -> commande -> dir_output ;
} elseif ( $module == 'order_supplier' ) {
$upload_dir = $conf -> fournisseur -> commande -> dir_output ;
} elseif ( $module == 'contract' ) {
$upload_dir = $conf -> contrat -> dir_output ;
} elseif ( $module == 'product' ) {
$upload_dir = $conf -> product -> dir_output ;
} elseif ( $module == 'tax' ) {
$upload_dir = $conf -> tax -> dir_output ;
2021-12-07 02:00:34 +01:00
$excludefiles [] = '^vat$' ; // The subdir 'vat' contains files of vats.
} elseif ( $module == 'tax-vat' ) {
$upload_dir = $conf -> tax -> dir_output . '/vat' ;
} elseif ( $module == 'salaries' ) {
$upload_dir = $conf -> salaries -> dir_output ;
2021-02-23 22:03:23 +01:00
} elseif ( $module == 'project' ) {
2022-06-14 17:53:17 +02:00
$upload_dir = $conf -> project -> dir_output ;
2021-10-24 11:38:45 +02:00
} elseif ( $module == 'project_task' ) {
2022-06-14 17:53:17 +02:00
$upload_dir = $conf -> project -> dir_output ;
2021-02-23 22:03:23 +01:00
} elseif ( $module == 'fichinter' ) {
$upload_dir = $conf -> ficheinter -> dir_output ;
} elseif ( $module == 'user' ) {
$upload_dir = $conf -> user -> dir_output ;
} elseif ( $module == 'expensereport' ) {
$upload_dir = $conf -> expensereport -> dir_output ;
} elseif ( $module == 'holiday' ) {
$upload_dir = $conf -> holiday -> dir_output ;
} elseif ( $module == 'recruitment-recruitmentcandidature' ) {
$upload_dir = $conf -> recruitment -> dir_output . '/recruitmentcandidature' ;
} elseif ( $module == 'banque' ) {
$upload_dir = $conf -> bank -> dir_output ;
2021-10-24 11:38:45 +02:00
} elseif ( $module == 'chequereceipt' ) {
$upload_dir = $conf -> bank -> dir_output . '/checkdeposits' ;
2021-02-23 22:03:23 +01:00
} elseif ( $module == 'mrp-mo' ) {
2021-10-24 11:38:45 +02:00
$upload_dir = $conf -> mrp -> dir_output ;
2021-02-23 22:03:23 +01:00
} else {
2021-02-06 13:21:16 +01:00
$parameters = array ( 'modulepart' => $module );
$reshook = $hookmanager -> executeHooks ( 'addSectionECMAuto' , $parameters );
if ( $reshook > 0 && is_array ( $hookmanager -> resArray ) && count ( $hookmanager -> resArray ) > 0 ) {
$upload_dir = $hookmanager -> resArray [ 'directory' ];
}
}
2020-09-07 10:18:17 +02:00
// Automatic list
2021-02-23 22:03:23 +01:00
if ( in_array ( $module , $automodules )) {
2020-09-07 10:18:17 +02:00
$param .= '&module=' . $module ;
2021-02-23 22:03:23 +01:00
if ( isset ( $search_doc_ref ) && $search_doc_ref != '' ) {
$param .= '&search_doc_ref=' . urlencode ( $search_doc_ref );
}
2020-09-07 10:18:17 +02:00
$textifempty = ( $section ? $langs -> trans ( " NoFileFound " ) : ( $showonrightsize == 'featurenotyetavailable' ? $langs -> trans ( " FeatureNotYetAvailable " ) : $langs -> trans ( " NoFileFound " )));
$filter = preg_quote ( $search_doc_ref , '/' );
$filearray = dol_dir_list ( $upload_dir , " files " , 1 , $filter , $excludefiles , $sortfield , $sorting , 1 );
$perm = $user -> rights -> ecm -> upload ;
$formfile -> list_of_autoecmfiles ( $upload_dir , $filearray , $module , $param , 1 , '' , $perm , 1 , $textifempty , $maxlengthname , $url , 1 );
2021-03-01 20:37:16 +01:00
} else {
// Manual list
2021-02-23 22:03:23 +01:00
if ( $module == 'medias' ) {
2020-09-07 10:18:17 +02:00
/*
2021-02-23 22:03:23 +01:00
$_POST is array like
'token' => string '062380e11b7dcd009d07318b57b71750' ( length = 32 )
2018-10-18 21:22:30 +02:00
'action' => string 'file_manager' ( length = 12 )
'website' => string 'template' ( length = 8 )
'pageid' => string '124' ( length = 3 )
'section_dir' => string 'mydir/' ( length = 3 )
'section_id' => string '0' ( length = 1 )
'max_file_size' => string '2097152' ( length = 7 )
'sendit' => string 'Envoyer fichier' ( length = 15 )
2021-02-23 22:03:23 +01:00
*/
2020-09-07 10:18:17 +02:00
$relativepath = GETPOST ( 'file' , 'alpha' ) ? GETPOST ( 'file' , 'alpha' ) : GETPOST ( 'section_dir' , 'alpha' );
2021-02-23 22:03:23 +01:00
if ( $relativepath && $relativepath != '/' ) {
$relativepath .= '/' ;
}
2020-09-07 10:18:17 +02:00
$upload_dir = $dolibarr_main_data_root . '/' . $module . '/' . $relativepath ;
2021-02-23 22:03:23 +01:00
if ( GETPOSTISSET ( 'website' ) || GETPOSTISSET ( 'file_manager' )) {
2020-09-07 10:18:17 +02:00
$param .= '&file_manager=1' ;
2021-02-23 22:03:23 +01:00
if ( ! preg_match ( '/website=/' , $param )) {
$param .= '&website=' . urlencode ( GETPOST ( 'website' , 'alpha' ));
}
if ( ! preg_match ( '/pageid=/' , $param )) {
$param .= '&pageid=' . urlencode ( GETPOST ( 'pageid' , 'int' ));
}
2020-09-07 10:18:17 +02:00
//if (!preg_match('/backtopage=/',$param)) $param.='&backtopage='.urlencode($_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid);
}
} else {
$relativepath = $ecmdir -> getRelativePath ();
$upload_dir = $conf -> ecm -> dir_output . '/' . $relativepath ;
}
// If $section defined with value 0
2021-02-23 22:03:23 +01:00
if (( $section === '0' || empty ( $section )) && ( $module != 'medias' )) {
2020-09-07 10:18:17 +02:00
$filearray = array ();
} else {
$filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , array ( '^\.' , '(\.meta|_preview.*\.png)$' , '^temp$' , '^CVS$' ), $sortfield , $sorting , 1 );
}
2021-02-23 22:03:23 +01:00
if ( $section ) {
2020-09-07 10:18:17 +02:00
$param .= '§ion=' . $section ;
2021-02-23 22:03:23 +01:00
if ( isset ( $search_doc_ref ) && $search_doc_ref != '' ) {
2021-08-27 23:36:06 +02:00
$param .= '&search_doc_ref=' . urlencode ( $search_doc_ref );
2021-02-23 22:03:23 +01:00
}
2020-09-07 10:18:17 +02:00
$textifempty = $langs -> trans ( 'NoFileFound' );
2021-02-23 22:03:23 +01:00
} elseif ( $section === '0' ) {
if ( $module == 'ecm' ) {
2021-10-05 09:41:03 +02:00
$textifempty = '<br><div class="center"><span class="warning">' . $langs -> trans ( " DirNotSynchronizedSyncFirst " ) . '</span></div><br>' ;
2021-02-23 22:03:23 +01:00
} else {
$textifempty = $langs -> trans ( 'NoFileFound' );
}
} else {
$textifempty = ( $showonrightsize == 'featurenotyetavailable' ? $langs -> trans ( " FeatureNotYetAvailable " ) : $langs -> trans ( " ECMSelectASection " ));
}
if ( $module == 'medias' ) {
2020-09-07 10:18:17 +02:00
$useinecm = 6 ;
$modulepart = 'medias' ;
$perm = ( $user -> rights -> website -> write || $user -> rights -> emailing -> creer );
$title = 'none' ;
2021-02-23 22:03:23 +01:00
} elseif ( $module == 'ecm' ) { // DMS/ECM -> manual structure
if ( $user -> rights -> ecm -> read ) {
2020-09-07 10:18:17 +02:00
// Buttons: Preview
$useinecm = 2 ;
}
2021-02-23 22:03:23 +01:00
if ( $user -> rights -> ecm -> upload ) {
2020-09-07 10:18:17 +02:00
// Buttons: Preview + Delete
$useinecm = 4 ;
}
2021-02-23 22:03:23 +01:00
if ( $user -> rights -> ecm -> setup ) {
2020-09-07 10:18:17 +02:00
// Buttons: Preview + Delete + Edit
$useinecm = 5 ;
}
$perm = $user -> rights -> ecm -> upload ;
$modulepart = 'ecm' ;
$title = '' ; // Use default
} else {
$useinecm = 5 ;
$modulepart = 'ecm' ;
$perm = $user -> rights -> ecm -> upload ;
$title = '' ; // Use default
}
// When we show list of files for ECM files, $filearray contains file list, and directory is defined with modulepart + section into $param
// When we show list of files for a directory, $filearray ciontains file list, and directory is defined with modulepart + $relativepath
//var_dump("section=".$section." title=".$title." modulepart=".$modulepart." useinecm=".$useinecm." perm=".$perm." relativepath=".$relativepath." param=".$param." url=".$url);
2021-06-19 23:52:52 +02:00
$formfile -> list_of_documents ( $filearray , '' , $modulepart , $param , 1 , $relativepath , $perm , $useinecm , $textifempty , $maxlengthname , $title , $url , 0 , $perm , '' , $sortfield , $sortorder );
2020-09-07 10:18:17 +02:00
}
2012-03-25 22:47:37 +02:00
}
2014-01-05 18:37:26 +01:00
2017-11-18 15:41:30 +01:00
// Bottom of page
2019-12-16 13:06:25 +01:00
$useajax = 1 ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> dol_use_jmobile )) {
$useajax = 0 ;
}
if ( empty ( $conf -> use_javascript_ajax )) {
$useajax = 0 ;
}
if ( ! empty ( $conf -> global -> MAIN_ECM_DISABLE_JS )) {
$useajax = 0 ;
}
2014-01-05 18:37:26 +01:00
2017-11-18 15:41:30 +01:00
//$param.=($param?'?':'').(preg_replace('/^&/','',$param));
2021-10-10 21:11:48 +02:00
if ( $useajax || $action == 'deletefile' ) {
2019-12-16 13:06:25 +01:00
$urlfile = '' ;
2021-10-10 21:11:48 +02:00
if ( $action == 'deletefile' ) {
2021-02-23 22:03:23 +01:00
$urlfile = GETPOST ( 'urlfile' , 'alpha' );
}
2017-11-18 15:41:30 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $section_dir )) {
$section_dir = GETPOST ( " file " , " alpha " );
}
2019-12-16 13:06:25 +01:00
$section_id = $section ;
2017-11-18 15:41:30 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2020-05-27 11:38:28 +02:00
2017-11-18 15:41:30 +01:00
$form = new Form ( $db );
2020-04-17 12:32:05 +02:00
$formquestion [ 'urlfile' ] = array ( 'type' => 'hidden' , 'value' => $urlfile , 'name' => 'urlfile' ); // We must always put field, even if empty because it is filled by javascript later
$formquestion [ 'section' ] = array ( 'type' => 'hidden' , 'value' => $section , 'name' => 'section' ); // We must always put field, even if empty because it is filled by javascript later
$formquestion [ 'section_id' ] = array ( 'type' => 'hidden' , 'value' => $section_id , 'name' => 'section_id' ); // We must always put field, even if empty because it is filled by javascript later
$formquestion [ 'section_dir' ] = array ( 'type' => 'hidden' , 'value' => $section_dir , 'name' => 'section_dir' ); // We must always put field, even if empty because it is filled by javascript later
$formquestion [ 'sortfield' ] = array ( 'type' => 'hidden' , 'value' => $sortfield , 'name' => 'sortfield' ); // We must always put field, even if empty because it is filled by javascript later
$formquestion [ 'sortorder' ] = array ( 'type' => 'hidden' , 'value' => $sortorder , 'name' => 'sortorder' ); // We must always put field, even if empty because it is filled by javascript later
2021-02-23 22:03:23 +01:00
if ( ! empty ( $action ) && $action == 'file_manager' ) {
$formquestion [ 'file_manager' ] = array ( 'type' => 'hidden' , 'value' => 1 , 'name' => 'file_manager' );
}
if ( ! empty ( $websitekey )) {
$formquestion [ 'website' ] = array ( 'type' => 'hidden' , 'value' => $websitekey , 'name' => 'website' );
}
if ( ! empty ( $pageid ) && $pageid > 0 ) {
$formquestion [ 'pageid' ] = array ( 'type' => 'hidden' , 'value' => $pageid , 'name' => 'pageid' );
}
2019-12-16 13:06:25 +01:00
print $form -> formconfirm ( $url , $langs -> trans ( " DeleteFile " ), $langs -> trans ( " ConfirmDeleteFile " ), 'confirm_deletefile' , $formquestion , " no " , ( $useajax ? 'deletefile' : 0 ));
2017-11-18 15:41:30 +01:00
}
2014-01-05 18:37:26 +01:00
2021-02-23 22:03:23 +01:00
if ( $useajax ) {
2021-06-19 23:52:52 +02:00
print '<!-- ajaxdirpreview.php: js to manage preview of doc -->' . " \n " ;
2017-11-18 15:41:30 +01:00
print '<script type="text/javascript">' ;
// Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
// Because the content is reloaded by ajax call, we must also reenable some jquery hooks
// Wrapper to manage document_preview
2021-02-23 22:03:23 +01:00
if ( $conf -> browser -> layout != 'phone' ) {
2017-11-18 15:41:30 +01:00
print " \n /* JS CODE TO ENABLE document_preview */ \n " ;
print '
jQuery ( document ) . ready ( function () {
jQuery ( " .documentpreview " ) . click ( function () {
console . log ( " We click on preview for element with href= " + $ ( this ) . attr ( \ ' href\ ' ) + " mime= " + $ ( this ) . attr ( \ ' mime\ ' ));
document_preview ( $ ( this ) . attr ( \ 'href\'), $(this).attr(\'mime\'), \'' . dol_escape_js ( $langs -> transnoentities ( " Preview " )) . ' \ ' );
return false ;
});
});
' . " \n " ;
2014-01-05 18:37:26 +01:00
}
2017-11-18 15:41:30 +01:00
// Enable jquery handlers button to delete files
print 'jQuery(document).ready(function() {' . " \n " ;
print ' jQuery(".deletefilelink").click(function(e) { ' . " \n " ;
print ' console.log("We click on button with class deletefilelink, param=' . $param . ', we set urlfile to "+jQuery(this).attr("rel"));' . " \n " ;
print ' jQuery("#urlfile").val(jQuery(this).attr("rel"));' . " \n " ;
//print ' jQuery("#section_dir").val(\'aaa\');'."\n";
print ' jQuery("#dialog-confirm-deletefile").dialog("open");' . " \n " ;
print ' return false;' . " \n " ;
print ' });' . " \n " ;
print '});' . " \n " ;
print '</script>' . " \n " ;
}
2012-03-24 15:20:49 +01:00
2012-05-23 23:23:57 +02:00
// Close db if mode is not noajax
2021-02-23 22:03:23 +01:00
if (( ! isset ( $mode ) || $mode != 'noajax' ) && is_object ( $db )) {
$db -> close ();
}