index.php 3.89 KB
Newer Older
Zéfling's avatar
Zéfling committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once('xajax/xajax.inc.php');

function arbreDossier ($rep) {
	$objResponse = new xajaxResponse();
	$objResponse->addClear($rep, "innerHTML");
	$objResponse->addAppend($rep, "innerHTML", lireDossier ($rep));
	$r1 = afficherDossier ($rep);
	$objResponse->loadXML($r1);
    return $objResponse->getXML();
}

function afficherDossier ($rep) {
	$objResponse = new xajaxResponse();
	$objResponse->addClear("tab", "innerHTML");
	$objResponse->addAppend("tab", "innerHTML", listerDossier ($rep));
	$objResponse->addClear("chemin", "innerHTML");
	$objResponse->addAppend("chemin", "innerHTML", 'Chemin : '.$rep);
    return $objResponse->getXML();
}


$xajax = new xajax(); //On initialise l'objet xajax
$xajax->setCharEncoding("utf-8");
$xajax->registerFunction("arbreDossier");
$xajax->registerFunction("afficherDossier");
$xajax->processRequests();
	


//Fonction qui va se charger de faire les requetes

function lireDossier ($rep, $ret = 1) {
	$aRep = explode ('/', $rep);
	$repCourant = $aRep[count($aRep)-1];
	
	
	$rep .= '/';
	
	$dir = opendir($rep);
	
	$liste = '';
	while ($f = readdir($dir)) {
		if(!is_file($rep.$f) && $f != '.' && $f != '..') {
			// test si il y a des sous dossiers
			$ssDir = opendir($rep.$f.'/');
			$ssDossier = false;
			while (($ssf = readdir($ssDir)) && !$ssDossier) {
				if(!is_file($rep.$f.'/'.$ssf) && $ssf != '.' && $ssf != '..') {
					$ssDossier = true;
				}
			}
			
			// si il y a des sous-dossiers ou non
			if ($ssDossier) {
				$id = ' id="'.$rep.$f.'"';
				$onclick = ' onclick="xajax_arbreDossier(\''.$rep.$f.'\');return false;"';
			} else {
				$id = '';
				$onclick = ' onclick="xajax_afficherDossier(\''.$rep.$f.'\');return false;"';
			}

			$liste .= '<li'.$id.'><a href=""'.$onclick.'>'.$f.'</a></li>';
		}
	}
	closedir($dir);
	
	return (($ret == 1) ? '<a href="" onclick="xajax_afficherDossier(\''.$rep.$f.'\');return false;">'.$repCourant.'</a>' : '').'<ul id="'.$rep.'">'.$liste.'</ul>';
}

function listerDossier ($rep) {
	$rep .= '/';
	
	$dir = opendir($rep);
	
	$liste = '<div id="barre_type"><div class="nom">Nom</div><div class="taille">Taille</div><div class="type">Type</div><div class="date">Date Modification</div></div>';
	while ($f = readdir($dir)) {
		if ($f != '.' && $f != '..') {
			
			$liste .= '<div id="ligne_fichier">';
			$liste .= '<div class="nom">'.$f.'</div>';
			$liste .= '<div class="taille">'.filesize($rep.$f).'</div>';
			$liste .= '<div class="type">'.filetype($rep.$f).'</div>';
			$liste .= '<div class="date">'.filemtime($rep.$f).'</div>';
			$liste .= '</div>';
		}
	}
	closedir($dir);
	
	return $liste;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
        <head>
                <title>Gestionnaire de fichiers</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<link href="w3c.css" rel="stylesheet" type="text/css" />
				<link href="index.css" rel="stylesheet" type="text/css" />
                <?php $xajax->printJavascript('xajax/'); ?>
				<script src="scriptaculous/lib/prototype.js" type="text/javascript"></script>
				<script src="scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
        </head>
		<body onload="xajax_arbreDossier('racine');">
			<div id="conteneur">
				<div id="tete">
					<div id="chemin"></div>
				</div>
				<div id="exploreur">
					<div id="arbre"><?php echo lireDossier ('racine', 0) ?></div>
					<div id="fichiers">
						<div id="tab">
							<div id="barre_type">
								<div class="nom">Nom</div>
								<div class="taille">Taille</div>
								<div class="type">Type</div>
								<div class="date">Date Modification</div>
							</div>
						</div>
					</div>
				</div>
			</div>
        </body>
</html>