-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport.php
69 lines (58 loc) · 1.56 KB
/
export.php
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
<?php
include_once "lib/classes.class.php";
$host=$_GET["host"];
$db=$_GET["db"];
$collection=$_GET["collection"];
$type=$_GET["type"];
echo $_GET['requete'];
$requete=json_decode($_GET['requete']);
if($requete=='')
$requete=array();
print_r($requete);
$date=date('Y-m-d');
$mongo = new PhpMongAdminConnect($host);
$mongo_connect=$mongo->getConnection();
$mongo_db = $mongo_connect->selectDB("$db");
$mongo_collection = $mongo_db->selectCollection("$collection");
$resultat=$mongo_collection->find($requete);
if($type=='php'){
header('Content-type: text/plain');
header("Content-disposition: attachment;filename=mongexport_$db-$collection"."_$date.txt");
echo "\$tabexport_$db"."_$collection=array();\n";
$i=0;
foreach($resultat as $clef => $tabresultat){
foreach($tabresultat as $clef2 => $valeur2){
if($clef2!='_id')
echo "\$tabexport_$db"."_$collection".'['."'$i'".']['."'$clef2'".']'."='$valeur2';\n";
}
$i++;
}
}
else if($type=='csv'){
header('Content-type: text/plain');
header("Content-disposition: attachment;filename=mongexport_$db-$collection"."_$date.csv");
$tabheader=array();
$tabcontent=array();
$i=0;
foreach($resultat as $clef => $tabresultat){
foreach($tabresultat as $clef2 => $valeur2){
$tabcontent[$i][$clef2]=$valeur2;
$tabheader[$clef2]=$clef2;
}
$i++;
}
foreach($tabheader as $clef => $titre){
echo "$titre;";
}
echo "\n";
foreach($tabcontent as $i => $tabvaleur){
foreach($tabheader as $clef => $titre){
echo $tabcontent[$i][$clef].";";
}
echo "\n";
}
}
else{
echo "ERREUR: FORMAT D'EXPORT INCONNU";
}
?>