<?php
/*********************************************************************************
 * Gest'Ecole is a school management software developped by
 * DOX Conception Copyright (C) 2012-2013 DOX Conception
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the license published by DOX Conception.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY.  See the Software License for more details.
 * 
 * You should have received a copy of the software license along with
 * this program; if not, see:
 * http://www.doxconception.com/site/index.php/licence-de-gestecole.html
 ********************************************************************************/

session_start();

error_reporting(0); // Set E_ALL for debuging

include "../../../config_parametre.php";
$extension=explode('|',$_GET['extensions_elfinder']);
$extensions=Array();
for($i=0;$i<count($extension);$i++)
{
  $extensions[]=$extensions_elfinder[$extension[$i]];
}

include "../../../langues/fr-FR/commun.php";

include "../../../commun/fonctions.php";
include "../../../config.php";

Connexion_DB();

include "../../../langues/fr-FR/ged.php";
if ($_SESSION['language_application']!="fr-FR")
{
  include "../../../langues/".$_SESSION['language_application']."/ged.php";
}

if (file_exists("../../../cache/personnalisation/libelles/".$_SESSION['language_application']."_ged.php"))
{
  include "../../../cache/personnalisation/libelles/".$_SESSION['language_application']."_ged.php";
	foreach ($langue_perso AS $cle => $value)
	{
	  $Langue_Module[$cle]=str_replace('&quot;','"',$value);
	}
}

$req=mysql_query("SELECT * FROM `eleves` WHERE (date_sortie='0000-00-00' OR date_sortie>='".date("Y-m-d")."') AND date_entree<='".date("Y-m-d")."' AND identifiant!=''");
$tableau=Array();
if ($_SESSION['id_classe_cours']!="")
{
	$req2=mysql_query("SELECT * FROM `classes_profs` WHERE id_classe='".$_SESSION['id_classe_cours']."' AND type='T'");
	$id_prof_en_cours=mysql_result($req2,0,'id_prof');
	$req2=mysql_query("SELECT * FROM `profs` WHERE id='".$id_prof_en_cours."'");
	$type_prof_en_cours=mysql_result($req2,0,'type');
  for($i=1;$i<=mysql_num_rows($req);$i++)
	{
	  $req2=mysql_query("SELECT * FROM `eleves_classes` WHERE id_eleve='".mysql_result($req,$i-1,'id')."' AND id_classe='".$_SESSION['id_classe_cours']."'");
		if (mysql_num_rows($req2)!="")
		{
			$tableau[]=Array('pattern'=>'/'.mysql_result($req,$i-1,'identifiant').'/','read'=>true,'write'=>true,'hidden'=>false);
		}
		else
		{
			$tableau[]=Array('pattern'=>'/'.mysql_result($req,$i-1,'identifiant').'/','read'=>false,'write'=>false,'hidden'=>true);
		}
	}
}
else
{
  for($i=1;$i<=mysql_num_rows($req);$i++)
	{
    $tableau[]=Array('pattern'=>'/'.mysql_result($req,$i-1,'identifiant').'/','read'=>true,'write'=>true,'hidden'=>false);
	}
}

include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';
// Required for MySQL storage connector
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php';
// Required for FTP connector support
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php';


/**
 * Simple function to demonstrate how to control file access using "accessControl" callback.
 * This method will disable accessing files/folders starting from  '.' (dot)
 *
 * @param  string  $attr  attribute name (read|write|locked|hidden)
 * @param  string  $path  file path relative to volume root directory started with directory separator
 * @return bool|null
 **/
function access($attr, $path, $data, $volume) {
	return strpos(basename($path), '.') === 0       // if file/folder begins with '.' (dot)
		? !($attr == 'read' || $attr == 'write')    // set read+write to false, other (locked+hidden) set to true
		:  null;                                    // else elFinder decide it itself
}

if ($_SESSION['id_classe_cours']!="")
{
	$opts = array(
		// 'debug' => true,
		'roots' => array(
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/public',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/public', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_TOUS'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
			),
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/enseignants/'.$type_prof_en_cours.$id_prof_en_cours.'/parents',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/enseignants/'.$type_prof_en_cours.$id_prof_en_cours.'/parents', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_CLASSE'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
			),
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/eleves',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/eleves', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_TRAVAIL_PROFS'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
				'attributes'    => $tableau
			),
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/enseignants/'.$_GET['repertoire_perso'].'/personnel',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/enseignants/'.$_GET['repertoire_perso'].'/personnel', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_PERSONNEL'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
			),
		)
	);
}
else
{
	$opts = array(
		// 'debug' => true,
		'roots' => array(
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/public',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/public', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_TOUS'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
			),
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/eleves',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/eleves', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_TRAVAIL_PROFS'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
				'attributes'    => $tableau
			),
			array(
				'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
				'path'          => '../../../cache/ged/enseignants/'.$_GET['repertoire_perso'].'/personnel',         // path to files (REQUIRED)
				'URL'           => dirname($_SERVER['PHP_SELF']) . '../../../../cache/ged/enseignants/'.$_GET['repertoire_perso'].'/personnel', // URL to files (REQUIRED)
				'alias'         => $Langue_Module['LBL_REPERTOIRE_PERSONNEL'],
				'uploadAllow' 	=> $extensions,
				'uploadOrder'		=> array('allow'),
				'accessControl'   => 'access',
			),
		)
	);
}

// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();

