dolibarr 24.0.0-beta
exportcsv.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
31require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
32require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
33
42$action = GETPOST('action', 'aZ09');
43$numsondage = '';
44if (GETPOST('id')) {
45 $numsondage = GETPOST("id", 'alpha');
46}
47
48// Initialize Objects
50$result = $object->fetch('', $numsondage);
51if ($result <= 0) {
52 dol_print_error(null, 'Failed to get survey id '.$numsondage);
53}
54
55// Security check
56if (!$user->hasRight('opensurvey', 'read')) {
58}
59
60
61/*
62 * Actions
63 */
64
65
66
67/*
68 * View
69 */
70
71$now = dol_now();
72
73$nbcolonnes = substr_count($object->sujet, ',') + 1;
74$toutsujet = explode(",", $object->sujet);
75$somme = array();
76// display subjects of survey
77$input = $langs->trans("Name").";";
78for ($i = 0; $toutsujet[$i]; $i++) {
79 if ($object->format == "D") {
80 $input .= dol_print_date($toutsujet[$i], 'dayhour').';';
81 } else {
82 $input .= $toutsujet[$i].';';
83 }
84}
85
86$input .= "\r\n";
87
88if (strpos($object->sujet, '@') !== false) {
89 $input .= ";";
90 for ($i = 0; $toutsujet[$i]; $i++) {
91 $heures = explode("@", $toutsujet[$i]);
92 $input .= $heures[1].';';
93 }
94
95 $input .= "\r\n";
96}
97
98
99$sql = 'SELECT nom as name, reponses';
100$sql .= ' FROM '.MAIN_DB_PREFIX."opensurvey_user_studs";
101$sql .= " WHERE id_sondage='".$db->escape($numsondage)."'";
102$sql .= " ORDER BY id_users";
103$resql = $db->query($sql);
104if ($resql) {
105 $num = $db->num_rows($resql);
106 $i = 0;
107 while ($i < $num) {
108 $obj = $db->fetch_object($resql);
109
110 // Le name de l'utilisateur
111 $nombase = str_replace("°", "'", $obj->name);
112 $input .= $nombase.';';
113
114 //affichage des resultats
115 $ensemblereponses = $obj->reponses;
116 for ($k = 0; $k < $nbcolonnes; $k++) {
117 if (empty($somme[$k])) {
118 $somme[$k] = 0;
119 }
120 $car = substr($ensemblereponses, $k, 1);
121 if ($car == "1") {
122 $input .= 'OK;';
123 $somme[$k]++;
124 } elseif ($car == "2") {
125 $input .= ';';
126 $somme[$k]++;
127 } else {
128 $input .= 'KO;';
129 }
130 }
131
132 $input .= "\r\n";
133 $i++;
134 }
135} else {
137}
138
139
140$filesize = strlen($input);
141$filename = $numsondage."_".dol_print_date($now, '%Y%m%d%H%M').".csv";
142
143
144
145header('Content-Type: text/csv; charset=utf-8');
146header('Content-Length: '.$filesize);
147header('Content-Disposition: attachment; filename="'.$filename.'"');
148header('Cache-Control: max-age=10');
149echo $input;
150
151exit;
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Put here description of your class.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.