Add STATUS.txt file
[framadate-sandstorm.git] / exportcsv.php
blob927d57f5a8c85b87ab2e2d9b6ed41708a72e363f
1 <?php
2 /**
3 * This software is governed by the CeCILL-B license. If a copy of this license
4 * is not distributed with this file, you can obtain one at
5 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
7 * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
8 * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
10 * =============================
12 * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
13 * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
14 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
16 * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
17 * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
19 namespace Framadate;
21 include_once __DIR__ . '/app/inc/init.php';
23 if(!isset($_GET['numsondage']) || ! preg_match(";^[\w\d]{16}$;i", $_GET['numsondage'])) {
24 header('Location: studs.php');
27 $sql = 'SELECT * FROM user_studs WHERE id_sondage='.$connect->Param('numsondage').' ORDER BY id_users';
28 $sql = $connect->Prepare($sql);
29 $user_studs = $connect->Execute($sql, array($_GET['numsondage']));
31 $dsondage = Utils::get_sondage_from_id($_GET['numsondage']);
32 $nbcolonnes=substr_count($dsondage->sujet,',')+1;
34 $toutsujet=explode(",",$dsondage->sujet);
36 //affichage des sujets du sondage
37 $input =",";
38 foreach ($toutsujet as $value) {
39 if ($dsondage->format=="D"||$dsondage->format=="D+") {
40 if (strpos($dsondage->sujet,'@') !== false) {
41 $days=explode("@",$value);
42 $input.= '"'.date("j/n/Y",$days[0]).'",';
43 } else {
44 $input.= '"'.date("j/n/Y",$values).'",';
46 } else {
48 preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/',$value,$md_a_img); // Markdown [![alt](src)](href)
49 preg_match_all('/!\[(.*?)\]\((.*?)\)/',$value,$md_img); // Markdown ![alt](src)
50 preg_match_all('/\[(.*?)\]\((.*?)\)/',$value,$md_a); // Markdown [text](href)
51 if (isset($md_a_img[2][0]) && $md_a_img[2][0]!='' && isset($md_a_img[3][0]) && $md_a_img[3][0]!='') { // [![alt](src)](href)
52 $subject_text = (isset($md_a_img[1][0]) && $md_a_img[1][0]!='') ? stripslashes($md_a_img[1][0]) : _("Choice") .' '.($i+1);
53 } elseif (isset($md_img[2][0]) && $md_img[2][0]!='') { // ![alt](src)
54 $subject_text = (isset($md_img[1][0]) && $md_img[1][0]!='') ? stripslashes($md_img[1][0]) : _("Choice") .' '.($i+1);
55 } elseif (isset($md_a[2][0]) && $md_a[2][0]!='') { // [text](href)
56 $subject_text = (isset($md_a[1][0]) && $md_a[1][0]!='') ? stripslashes($md_a[1][0]) : _("Choice") .' '.($i+1);
57 } else { // text only
58 $subject_text = stripslashes($value);
60 $input.= '"'.html_entity_decode($subject_text).'",';
64 $input.="\r\n";
66 if (strpos($dsondage->sujet,'@') !== false) {
67 $input.=",";
68 foreach ($toutsujet as $value) {
69 $heures=explode("@",$value);
70 $input.= '"'.$heures[1].'",';
73 $input.="\r\n";
76 while ( $data=$user_studs->FetchNextObject(false)) {
77 // Le nom de l'utilisateur
78 $nombase=html_entity_decode(str_replace("°","'",$data->nom));
79 $input.= '"'.$nombase.'",';
80 //affichage des resultats
81 $ensemblereponses=$data->reponses;
82 for ($k=0;$k<$nbcolonnes;$k++) {
83 $car=substr($ensemblereponses,$k,1);
84 switch ($car) {
85 case "1": $input .= '"'._('Yes').'",'; break;
86 case "2": $input .= '"'._('Ifneedbe').'",'; break;
87 default: $input .= '"'._('No').'",'; break;
91 $input.="\r\n";
94 $filesize = strlen( $input );
95 $filename=$_GET["numsondage"].".csv";
97 header( 'Content-Type: text/csv; charset=utf-8' );
98 header( 'Content-Length: '.$filesize );
99 header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
100 header( 'Cache-Control: max-age=10' );
102 echo str_replace('&quot;','""',$input);
104 die();