2008-02-19 22:04:23 +01:00
< ? php
2017-08-20 23:16:20 +02:00
/* Copyright ( C ) 2008 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2008 - 2010 Regis Houssin < regis . houssin @ capnetworks . com >
2008-04-30 01:49:00 +02: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
2008-04-30 01:49:00 +02: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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2017-11-05 00:37:21 +01:00
*
* You can call this page with param module = medias to get a filemanager for medias .
2008-02-19 22:04:23 +01:00
*/
/**
2008-11-09 13:33:13 +01:00
* \file htdocs / ecm / index . php
2008-09-25 17:54:08 +02:00
* \ingroup ecm
* \brief Main page for ECM section area
2008-09-09 01:21:22 +02:00
*/
2008-02-19 22:04:23 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/ecm.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/treeview.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php' ;
2008-02-19 22:04:23 +01:00
2018-05-26 16:35:29 +02:00
// Load translation files required by the page
2017-11-05 00:37:21 +01:00
$langs -> loadLangs ( array ( " ecm " , " companies " , " other " , " users " , " orders " , " propal " , " bills " , " contracts " ));
2008-02-19 22:04:23 +01:00
2009-04-28 08:49:44 +02:00
// Security check
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2011-03-28 10:41:37 +02:00
$result = restrictedArea ( $user , 'ecm' , 0 );
2009-04-28 08:49:44 +02:00
2008-02-19 22:04:23 +01:00
// Get parameters
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2017-05-16 13:27:32 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2017-08-20 21:23:19 +02:00
$section = GETPOST ( 'section' , 'int' ) ? GETPOST ( 'section' , 'int' ) : GETPOST ( 'section_id' , 'int' );
2008-09-09 01:21:22 +02:00
if ( ! $section ) $section = 0 ;
2017-08-20 21:23:19 +02:00
$section_dir = GETPOST ( 'section_dir' , 'alpha' );
2008-02-19 22:04:23 +01:00
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2010-11-20 14:08:44 +01:00
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2008-04-28 23:19:01 +02:00
if ( ! $sortorder ) $sortorder = " ASC " ;
2012-02-06 14:34:58 +01:00
if ( ! $sortfield ) $sortfield = " fullname " ;
2008-02-25 00:29:30 +01:00
2011-11-23 15:19:44 +01:00
$ecmdir = new EcmDirectory ( $db );
2012-03-25 22:47:37 +02:00
if ( $section )
2008-02-25 00:29:30 +01:00
{
2012-03-25 22:47:37 +02:00
$result = $ecmdir -> fetch ( $section );
2008-02-25 00:29:30 +01:00
if ( ! $result > 0 )
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db , $ecmdir -> error );
2008-02-25 00:29:30 +01:00
exit ;
}
}
2008-02-19 22:04:23 +01:00
2010-10-03 17:42:01 +02:00
$form = new Form ( $db );
2011-11-23 15:19:44 +01:00
$ecmdirstatic = new EcmDirectory ( $db );
2010-10-03 17:42:01 +02:00
$userstatic = new User ( $db );
2012-08-04 02:20:51 +02:00
$error = 0 ;
2008-02-19 22:04:23 +01:00
2012-03-24 15:20:49 +01:00
/*
* Actions
*/
2008-09-09 01:21:22 +02:00
2017-11-18 15:41:30 +01:00
// Upload file (code similar but different than actions_linkedfiles.inc.php)
if ( GETPOST ( " sendit " , 'none' ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
2008-09-09 01:21:22 +02:00
{
2012-03-25 22:47:37 +02:00
// Define relativepath and upload_dir
$relativepath = '' ;
if ( $ecmdir -> id ) $relativepath = $ecmdir -> getRelativePath ();
2013-11-17 02:59:01 +01:00
else $relativepath = $section_dir ;
2008-09-09 01:21:22 +02:00
$upload_dir = $conf -> ecm -> dir_output . '/' . $relativepath ;
2009-01-18 11:42:58 +01:00
2017-11-18 15:41:30 +01:00
if ( is_array ( $_FILES [ 'userfile' ][ 'tmp_name' ])) $userfiles = $_FILES [ 'userfile' ][ 'tmp_name' ];
else $userfiles = array ( $_FILES [ 'userfile' ][ 'tmp_name' ]);
foreach ( $userfiles as $key => $userfile )
2008-09-09 01:21:22 +02:00
{
2017-11-18 15:41:30 +01:00
if ( empty ( $_FILES [ 'userfile' ][ 'tmp_name' ][ $key ]))
{
$error ++ ;
if ( $_FILES [ 'userfile' ][ 'error' ][ $key ] == 1 || $_FILES [ 'userfile' ][ 'error' ][ $key ] == 2 ){
setEventMessages ( $langs -> trans ( 'ErrorFileSizeTooLarge' ), null , 'errors' );
}
else {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " File " )), null , 'errors' );
}
2016-10-04 00:56:35 +02:00
}
2012-08-04 02:20:51 +02:00
}
if ( ! $error )
{
2017-08-01 18:32:21 +02:00
$res = dol_add_file_process ( $upload_dir , 0 , 1 , 'userfile' , '' , '' , '' , 0 );
2017-02-22 20:35:42 +01:00
if ( $res > 0 )
{
$result = $ecmdir -> changeNbOfFiles ( '+' );
}
2008-09-09 01:21:22 +02:00
}
}
2010-10-03 17:42:01 +02:00
// Add directory
2012-03-25 22:47:37 +02:00
if ( $action == 'add' && $user -> rights -> ecm -> setup )
2008-02-19 22:04:23 +01:00
{
2010-10-03 17:42:01 +02:00
$ecmdir -> ref = 'NOTUSEDYET' ;
$ecmdir -> label = GETPOST ( " label " );
$ecmdir -> description = GETPOST ( " desc " );
2008-02-25 00:29:30 +01:00
$id = $ecmdir -> create ( $user );
if ( $id > 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ]);
2008-02-25 00:29:30 +01:00
exit ;
}
else
{
2015-11-21 17:38:09 +01:00
setEventMessages ( 'Error ' . $langs -> trans ( $ecmdir -> error ), null , 'errors' );
2012-02-08 18:07:55 +01:00
$action = " create " ;
2008-02-25 00:29:30 +01:00
}
2012-03-25 22:47:37 +02:00
clearstatcache ();
2008-02-19 22:04:23 +01:00
}
2017-11-18 15:41:30 +01:00
// Remove file (code similar but different than actions_linkedfiles.inc.php)
2012-05-23 17:49:41 +02:00
if ( $action == 'confirm_deletefile' )
2009-07-16 02:43:59 +02:00
{
2012-05-23 17:49:41 +02:00
if ( GETPOST ( 'confirm' ) == 'yes' )
{
2017-09-20 20:41:40 +02:00
// GETPOST('urlfile','alpha') is full relative URL from ecm root dir. Contains path of all sections.
//var_dump(GETPOST('urlfile'));exit;
2009-07-16 02:43:59 +02:00
2017-09-20 20:41:40 +02:00
$upload_dir = $conf -> ecm -> dir_output . ( $relativepath ? '/' . $relativepath : '' );
$file = $upload_dir . " / " . GETPOST ( 'urlfile' , 'alpha' ); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
2009-07-16 02:43:59 +02:00
2017-09-20 20:41:40 +02:00
$ret = dol_delete_file ( $file ); // This include also the delete from file index in database.
if ( $ret )
{
setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' , 'alpha' )), null , 'mesgs' );
$result = $ecmdir -> changeNbOfFiles ( '-' );
}
else
{
setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' , 'alpha' )), null , 'errors' );
}
2012-03-25 22:47:37 +02:00
2012-05-23 17:49:41 +02:00
clearstatcache ();
}
$action = 'file_manager' ;
2009-07-16 02:43:59 +02:00
}
// Remove directory
2012-02-08 18:07:55 +01:00
if ( $action == 'confirm_deletesection' && GETPOST ( 'confirm' ) == 'yes' )
2008-02-19 22:04:23 +01:00
{
2008-02-25 00:29:30 +01:00
$result = $ecmdir -> delete ( $user );
2015-11-21 17:38:09 +01:00
setEventMessages ( $langs -> trans ( " ECMSectionWasRemoved " , $ecmdir -> label ), null , 'mesgs' );
2012-03-25 22:47:37 +02:00
clearstatcache ();
2008-02-19 22:04:23 +01:00
}
2010-10-03 17:42:01 +02:00
// Refresh directory view
2016-07-30 15:51:27 +02:00
// This refresh list of dirs, not list of files (for preformance reason). List of files is refresh only if dir was not synchronized.
// To refresh content of dir with cache, just open the dir in edit mode.
2012-02-08 18:07:55 +01:00
if ( $action == 'refreshmanual' )
2010-10-03 17:42:01 +02:00
{
2013-12-01 17:32:05 +01:00
$ecmdirtmp = new EcmDirectory ( $db );
// This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
clearstatcache ();
2012-03-25 22:47:37 +02:00
2010-10-03 17:42:01 +02:00
$diroutputslash = str_replace ( '\\' , '/' , $conf -> ecm -> dir_output );
$diroutputslash .= '/' ;
// Scan directory tree on disk
2012-09-02 20:11:36 +02:00
$disktree = dol_dir_list ( $conf -> ecm -> dir_output , 'directories' , 1 , '' , '^temp$' , '' , '' , 0 );
2008-02-19 22:04:23 +01:00
2010-10-03 17:42:01 +02:00
// Scan directory tree in database
$sqltree = $ecmdirstatic -> get_full_arbo ( 0 );
$adirwascreated = 0 ;
// Now we compare both trees to complete missing trees into database
//var_dump($disktree);
//var_dump($sqltree);
2012-06-02 18:55:04 +02:00
foreach ( $disktree as $dirdesc ) // Loop on tree onto disk
2010-10-03 17:42:01 +02:00
{
$dirisindatabase = 0 ;
foreach ( $sqltree as $dirsqldesc )
{
if ( $conf -> ecm -> dir_output . '/' . $dirsqldesc [ 'fullrelativename' ] == $dirdesc [ 'fullname' ])
{
$dirisindatabase = 1 ;
break ;
}
}
if ( ! $dirisindatabase )
{
$txt = " Directory found on disk " . $dirdesc [ 'fullname' ] . " , not found into database so we add it " ;
dol_syslog ( $txt );
2010-10-03 17:55:45 +02:00
//print $txt."<br>\n";
2010-10-03 17:42:01 +02:00
// We must first find the fk_parent of directory to create $dirdesc['fullname']
$fk_parent =- 1 ;
$relativepathmissing = str_replace ( $diroutputslash , '' , $dirdesc [ 'fullname' ]);
$relativepathtosearchparent = $relativepathmissing ;
//dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
if ( preg_match ( '/\//' , $relativepathtosearchparent ))
//while (preg_match('/\//',$relativepathtosearchparent))
{
$relativepathtosearchparent = preg_replace ( '/\/[^\/]*$/' , '' , $relativepathtosearchparent );
$txt = " Is relative parent path " . $relativepathtosearchparent . " for " . $relativepathmissing . " found in sql tree ? " ;
dol_syslog ( $txt );
2010-10-03 17:55:45 +02:00
//print $txt." -> ";
2010-10-03 17:42:01 +02:00
$parentdirisindatabase = 0 ;
foreach ( $sqltree as $dirsqldesc )
{
if ( $dirsqldesc [ 'fullrelativename' ] == $relativepathtosearchparent )
{
$parentdirisindatabase = $dirsqldesc [ 'id' ];
break ;
}
}
if ( $parentdirisindatabase > 0 )
{
dol_syslog ( " Yes with id " . $parentdirisindatabase );
2010-10-03 17:55:45 +02:00
//print "Yes with id ".$parentdirisindatabase."<br>\n";
2010-10-03 17:42:01 +02:00
$fk_parent = $parentdirisindatabase ;
//break; // We found parent, we can stop the while loop
}
else
2013-12-01 17:32:05 +01:00
{
2010-10-03 17:42:01 +02:00
dol_syslog ( " No " );
2010-10-03 17:55:45 +02:00
//print "No<br>\n";
2010-10-03 17:42:01 +02:00
}
}
else
2012-06-24 19:32:19 +02:00
{
dol_syslog ( " Parent is root " );
2010-10-03 17:42:01 +02:00
$fk_parent = 0 ; // Parent is root
}
if ( $fk_parent >= 0 )
{
$ecmdirtmp -> ref = 'NOTUSEDYET' ;
2012-06-24 19:32:19 +02:00
$ecmdirtmp -> label = dol_basename ( $dirdesc [ 'fullname' ]);
2010-10-03 17:42:01 +02:00
$ecmdirtmp -> description = '' ;
$ecmdirtmp -> fk_parent = $fk_parent ;
$txt = " We create directory " . $ecmdirtmp -> label . " with parent " . $fk_parent ;
dol_syslog ( $txt );
2012-09-02 20:11:36 +02:00
//print $ecmdirtmp->cachenbofdoc."<br>\n";exit;
2010-10-03 17:42:01 +02:00
$id = $ecmdirtmp -> create ( $user );
if ( $id > 0 )
{
$newdirsql = array ( 'id' => $id ,
'id_mere' => $ecmdirtmp -> fk_parent ,
'label' => $ecmdirtmp -> label ,
'description' => $ecmdirtmp -> description ,
'fullrelativename' => $relativepathmissing );
$sqltree [] = $newdirsql ; // We complete fulltree for following loops
//var_dump($sqltree);
$adirwascreated = 1 ;
}
2012-06-24 19:32:19 +02:00
else
{
dol_syslog ( " Failed to create directory " . $ecmdirtmp -> label , LOG_ERR );
}
2010-10-03 17:42:01 +02:00
}
else {
$txt = " Parent of " . $dirdesc [ 'fullname' ] . " not found " ;
dol_syslog ( $txt );
2010-10-03 17:55:45 +02:00
//print $txt."<br>\n";
2010-10-03 17:42:01 +02:00
}
}
}
2013-12-01 17:32:05 +01:00
// Loop now on each sql tree to check if dir exists
foreach ( $sqltree as $dirdesc ) // Loop on each sqltree to check dir is on disk
{
$dirtotest = $conf -> ecm -> dir_output . '/' . $dirdesc [ 'fullrelativename' ];
if ( ! dol_is_dir ( $dirtotest ))
{
$ecmdirtmp -> id = $dirdesc [ 'id' ];
$ecmdirtmp -> delete ( $user , 'databaseonly' );
//exit;
}
}
2012-09-02 20:11:36 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0 " ; // If pb into cahce counting, we set to value -1 = "unknown"
dol_syslog ( " sql = " . $sql );
2012-06-02 18:55:04 +02:00
$db -> query ( $sql );
2010-10-03 17:42:01 +02:00
// If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
// it to be sure that fulltree array is not used without reloading it.
if ( $adirwascreated ) $sqltree = null ;
}
2008-02-19 22:04:23 +01:00
2012-02-15 12:22:18 +01:00
2012-03-24 15:20:49 +01:00
/*
* View
*/
2010-12-11 11:42:22 +01:00
2014-04-28 01:46:11 +02:00
// Define height of file area (depends on $_SESSION["dol_screenheight"])
//print $_SESSION["dol_screenheight"];
2016-09-07 02:10:39 +02:00
$maxheightwin = ( isset ( $_SESSION [ " dol_screenheight " ]) && $_SESSION [ " dol_screenheight " ] > 466 ) ? ( $_SESSION [ " dol_screenheight " ] - 136 ) : 660 ; // Also into index_auto.php file
2014-04-28 01:46:11 +02:00
2017-11-05 00:45:27 +01:00
$moreheadcss = '' ;
$moreheadjs = '' ;
2017-08-20 21:23:19 +02:00
//$morejs=array();
$morejs = array ( 'includes/jquery/plugins/blockUI/jquery.blockUI.js' , 'core/js/blockUI.js' ); // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp
2017-11-05 02:04:05 +01:00
if ( empty ( $conf -> global -> MAIN_ECM_DISABLE_JS )) $morejs [] = " includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js " ;
2017-02-22 19:36:57 +01:00
2017-11-05 00:45:27 +01:00
$moreheadjs .= '<script type="text/javascript">' . " \n " ;
$moreheadjs .= 'var indicatorBlockUI = \'' . DOL_URL_ROOT . " /theme/ " . $conf -> theme . " /img/working.gif " . '\';' . " \n " ;
$moreheadjs .= '</script>' . " \n " ;
2011-07-06 13:40:21 +02:00
2012-08-03 14:24:02 +02:00
llxHeader ( $moreheadcss . $moreheadjs , $langs -> trans ( " ECMArea " ), '' , '' , '' , '' , $morejs , '' , 0 , 0 );
2010-08-26 04:45:48 +02:00
2017-11-05 02:04:05 +01:00
$head = ecm_prepare_dasboard_head ( '' );
dol_fiche_head ( $head , 'index' , $langs -> trans ( " ECMArea " ) . ' - ' . $langs -> trans ( " ECMFileManager " ), - 1 , '' );
2008-02-19 22:04:23 +01:00
2013-03-25 09:56:07 +01:00
2017-11-05 02:04:05 +01:00
// Add filemanager component
2017-11-05 02:50:02 +01:00
$module = 'ecm' ;
2017-11-19 12:22:01 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/filemanager.tpl.php' ;
2008-09-02 15:15:25 +02:00
2017-11-05 02:04:05 +01:00
// End of page
dol_fiche_end ();
2013-03-04 11:16:46 +01:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-15 12:22:18 +01:00
$db -> close ();