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 >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . 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
2012-04-14 13:25:26 +02:00
* along with this program . If not , see < http :// 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
*/
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-06-24 17:49:52 +02:00
if ( ! isset ( $mode ) || $mode != 'noajax' ) // For ajax call
2012-03-25 22:47:37 +02:00
{
2012-08-22 23:11:24 +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' ;
2012-03-25 22:47:37 +02:00
2012-07-08 13:57:51 +02:00
$action = GETPOST ( " action " );
2012-03-25 22:47:37 +02:00
$file = urldecode ( GETPOST ( 'file' ));
$section = GETPOST ( " section " );
$module = GETPOST ( " module " );
$urlsource = GETPOST ( " urlsource " );
2012-07-08 23:22:22 +02:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " name " ;
2012-07-30 22:38:21 +02:00
2012-03-25 22:47:37 +02:00
$upload_dir = dirname ( str_replace ( " ../ " , " / " , $conf -> ecm -> dir_output . '/' . $file ));
$ecmdir = new EcmDirectory ( $db );
$result = $ecmdir -> fetch ( $section );
if ( ! $result > 0 )
{
2012-09-02 20:11:36 +02:00
//dol_print_error($db,$ecmdir->error);
//exit;
2012-03-25 22:47:37 +02:00
}
}
2012-06-24 17:49:52 +02:00
else // For no ajax call
2012-03-25 22:47:37 +02:00
{
$ecmdir = new EcmDirectory ( $db );
$relativepath = '' ;
if ( $section > 0 )
{
$result = $ecmdir -> fetch ( $section );
if ( ! $result > 0 )
{
dol_print_error ( $db , $ecmdir -> error );
exit ;
}
}
$relativepath = $ecmdir -> getRelativePath ();
$upload_dir = $conf -> ecm -> dir_output . '/' . $relativepath ;
}
2012-03-24 15:20:49 +01:00
// Load traductions files
$langs -> load ( " ecm " );
$langs -> load ( " companies " );
$langs -> load ( " other " );
// Security check
if ( $user -> societe_id > 0 ) $socid = $user -> societe_id ;
2012-03-25 22:47:37 +02:00
//print 'xxx'.$upload_dir;
2012-03-24 15:20:49 +01:00
// Security:
// On interdit les remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
2012-03-25 22:47:37 +02:00
if ( preg_match ( '/\.\./' , $upload_dir ) || preg_match ( '/[<>|]/' , $upload_dir ))
2012-03-24 15:20:49 +01:00
{
2012-03-25 22:47:37 +02:00
dol_syslog ( " Refused to deliver file " . $upload_dir );
2012-03-24 15:20:49 +01:00
// Do no show plain path in shown error message
2012-03-25 22:47:37 +02:00
dol_print_error ( 0 , $langs -> trans ( " ErrorFileNameInvalid " , $upload_dir ));
2012-03-24 15:20:49 +01:00
exit ;
}
/*
* Action
*/
2012-06-08 23:48:53 +02:00
// None
2012-03-24 15:20:49 +01:00
/*
* View
*/
2012-03-25 22:47:37 +02:00
if ( ! isset ( $mode ) || $mode != 'noajax' )
2012-03-24 15:20:49 +01:00
{
2012-07-08 13:57:51 +02:00
// Ajout directives pour resoudre bug IE
2012-03-25 22:47:37 +02:00
header ( 'Cache-Control: Public, must-revalidate' );
header ( 'Pragma: public' );
2012-07-30 22:38:21 +02:00
2012-07-08 13:57:51 +02:00
top_httphead ();
2012-03-24 15:20:49 +01:00
}
2012-03-25 22:47:37 +02: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
2012-03-25 22:47:37 +02:00
if ( ! dol_is_dir ( $upload_dir ))
2012-03-24 15:20:49 +01:00
{
2012-03-26 18:23:08 +02:00
// dol_mkdir($upload_dir);
/* $langs -> load ( " install " );
2012-03-25 22:47:37 +02:00
dol_print_error ( 0 , $langs -> trans ( " ErrorDirDoesNotExists " , $upload_dir ));
2012-03-26 18:23:08 +02:00
exit ; */
2012-03-24 15:20:49 +01:00
}
print '<!-- TYPE=' . $type . ' -->' . " \n " ;
2012-10-27 20:02:09 +02:00
print '<!-- Page called with mode=' . ( isset ( $mode ) ? $mode : '' ) . ' type=' . $type . ' module=' . $module . ' url=' . $_SERVER [ " PHP_SELF " ] . '?' . $_SERVER [ " QUERY_STRING " ] . ' -->' . " \n " ;
2012-03-24 15:20:49 +01:00
2013-04-21 12:40:46 +02:00
$param = ( $sortfield ? '&sortfield=' . $sortfield : '' ) . ( $sortorder ? '&sortorder=' . $sortorder : '' );
2012-07-08 14:30:05 +02:00
$url = DOL_URL_ROOT . '/ecm/index.php' ;
2012-03-24 15:20:49 +01:00
2012-06-24 17:49:52 +02:00
// Dir scan
2012-03-24 15:20:49 +01:00
if ( $type == 'directory' )
{
2012-03-25 22:47:37 +02:00
$formfile = new FormFile ( $db );
$maxlengthname = 40 ;
2013-04-21 12:40:46 +02:00
$excludefiles = array ( '^SPECIMEN\.pdf$' , '^\.' , '\.meta$' , '^temp$' , '^payments$' , '^CVS$' , '^thumbs$' );
$sorting = ( strtolower ( $sortorder ) == 'desc' ? SORT_DESC : SORT_ASC );
2012-03-25 22:47:37 +02:00
2012-06-24 17:49:52 +02:00
// Right area. If module is defined, we are in automatic ecm.
2013-04-21 12:40:46 +02:00
$automodules = array ( 'company' , 'invoice' , 'invoice_supplier' , 'propal' , 'order' , 'order_supplier' , 'contract' , 'product' , 'tax' , 'project' );
// TODO change for multicompany sharing
// Auto area for suppliers invoices
if ( $module == 'company' ) $upload_dir = $conf -> societe -> dir_output ;
// Auto area for suppliers invoices
else if ( $module == 'invoice' ) $upload_dir = $conf -> facture -> dir_output ;
// Auto area for suppliers invoices
else if ( $module == 'invoice_supplier' )
2012-03-25 22:47:37 +02:00
{
$relativepath = 'facture' ;
$upload_dir = $conf -> fournisseur -> dir_output . '/' . $relativepath ;
}
2013-04-21 12:40:46 +02:00
// Auto area for customers orders
else if ( $module == 'propal' ) $upload_dir = $conf -> propal -> dir_output ;
// Auto area for customers orders
else if ( $module == 'order' ) $upload_dir = $conf -> commande -> dir_output ;
// Auto area for suppliers orders
else if ( $module == 'order_supplier' )
2012-03-25 22:47:37 +02:00
{
$relativepath = 'commande' ;
$upload_dir = $conf -> fournisseur -> dir_output . '/' . $relativepath ;
2012-03-24 15:20:49 +01:00
}
2013-04-21 12:40:46 +02:00
// Auto area for suppliers invoices
else if ( $module == 'contract' ) $upload_dir = $conf -> contrat -> dir_output ;
// Auto area for products
else if ( $module == 'product' ) $upload_dir = $conf -> product -> dir_output ;
// Auto area for suppliers invoices
else if ( $module == 'tax' ) $upload_dir = $conf -> tax -> dir_output ;
// Auto area for projects
else if ( $module == 'project' ) $upload_dir = $conf -> projet -> dir_output ;
if ( in_array ( $module , $automodules ))
2012-03-24 15:20:49 +01:00
{
2012-09-02 15:03:55 +02:00
$param .= '&module=' . $module ;
$textifempty = ( $section ? $langs -> trans ( " NoFileFound " ) : ( $showonrightsize == 'featurenotyetavailable' ? $langs -> trans ( " FeatureNotYetAvailable " ) : $langs -> trans ( " NoFileFound " )));
2013-04-21 12:40:46 +02:00
$filearray = dol_dir_list ( $upload_dir , " files " , 1 , '' , $excludefiles , $sortfield , $sorting , 1 );
2012-09-02 15:03:55 +02:00
$formfile -> list_of_autoecmfiles ( $upload_dir , $filearray , $module , $param , 1 , '' , $user -> rights -> ecm -> upload , 1 , $textifempty , $maxlengthname , $url );
}
2013-04-21 12:40:46 +02:00
//Manual area
else
2012-03-24 15:20:49 +01:00
{
2012-03-25 22:47:37 +02:00
$relativepath = $ecmdir -> getRelativePath ();
$upload_dir = $conf -> ecm -> dir_output . '/' . $relativepath ;
2012-10-03 20:10:29 +02:00
// If $section defined with value 0
2012-10-03 23:15:57 +02:00
if ( $section === '0' )
2012-10-03 20:10:29 +02:00
{
2013-04-21 12:40:46 +02:00
$filearray = array ();
$textifempty = '<br><div align="center"><font class="warning">' . $langs -> trans ( " DirNotSynchronizedSyncFirst " ) . '</font></div><br>' ;
2012-10-03 20:10:29 +02:00
}
2013-04-21 12:40:46 +02:00
else $filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , array ( '^\.' , '\.meta$' , '^temp$' , '^CVS$' ), $sortfield , $sorting , 1 );
if ( $section )
{
$param .= '§ion=' . $section ;
$textifempty = $langs -> trans ( 'NoFileFound' );
}
else $textifempty = ( $showonrightsize == 'featurenotyetavailable' ? $langs -> trans ( " FeatureNotYetAvailable " ) : $langs -> trans ( " ECMSelectASection " ));
2014-01-05 18:37:26 +01:00
2012-07-08 14:30:05 +02:00
$formfile -> list_of_documents ( $filearray , '' , 'ecm' , $param , 1 , $relativepath , $user -> rights -> ecm -> upload , 1 , $textifempty , $maxlengthname , '' , $url );
2012-03-24 15:20:49 +01:00
}
2012-03-25 22:47:37 +02:00
}
2014-01-05 18:37:26 +01:00
if ( $section )
2012-03-25 22:47:37 +02:00
{
2014-01-05 18:37:26 +01:00
$useajax = 1 ;
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 ;
$param .= ( $param ? '?' : '' ) . ( preg_replace ( '/^&/' , '' , $param ));
if ( $useajax || $action == 'delete' )
{
$urlfile = '' ;
if ( $action == 'delete' ) $urlfile = GETPOST ( 'urlfile' );
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
$useglobalvars = 1 ;
$form = new Form ( $db );
$formquestion = array ( 'urlfile' => array ( 'type' => 'hidden' , 'value' => $urlfile , 'name' => 'urlfile' ));
print $form -> formconfirm ( $url , $langs -> trans ( " DeleteFile " ), $langs -> trans ( " ConfirmDeleteFile " ), 'confirm_deletefile' , $formquestion , " no " ,( $useajax ? 'deletefile' : 0 ));
}
if ( $useajax )
{
// Enable jquery handlers on new generated HTML objects
print '<script type="text/javascript">' . " \n " ;
print 'jQuery(document).ready(function() {' . " \n " ;
print 'jQuery(".deletefilelink").click(function(e) { jQuery("#urlfile").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });' . " \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
if (( ! isset ( $mode ) || $mode != 'noajax' ) && is_object ( $db )) $db -> close ();
2012-03-24 15:20:49 +01:00
?>