dolibarr  19.0.0-dev
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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
26 // Load Dolibarr environment
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
30 require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
31 
32 
33 $action = GETPOST('action', 'aZ09');
34 $numsondage = '';
35 if (GETPOST('id')) {
36  $numsondage = GETPOST("id", 'alpha');
37 }
38 
39 // Initialize Objects
40 $object = new Opensurveysondage($db);
41 $result = $object->fetch(0, $numsondage);
42 if ($result <= 0) {
43  dol_print_error('', 'Failed to get survey id '.$numsondage);
44 }
45 
46 // Security check
47 if (empty($user->rights->opensurvey->read)) {
49 }
50 
51 
52 /*
53  * Actions
54  */
55 
56 
57 
58 /*
59  * View
60  */
61 
62 $now = dol_now();
63 
64 $nbcolonnes = substr_count($object->sujet, ',') + 1;
65 $toutsujet = explode(",", $object->sujet);
66 $somme = array();
67 // affichage des sujets du sondage
68 $input = $langs->trans("Name").";";
69 for ($i = 0; $toutsujet[$i]; $i++) {
70  if ($object->format == "D") {
71  $input .= dol_print_date($toutsujet[$i], 'dayhour').';';
72  } else {
73  $input .= $toutsujet[$i].';';
74  }
75 }
76 
77 $input .= "\r\n";
78 
79 if (strpos($object->sujet, '@') !== false) {
80  $input .= ";";
81  for ($i = 0; $toutsujet[$i]; $i++) {
82  $heures = explode("@", $toutsujet[$i]);
83  $input .= $heures[1].';';
84  }
85 
86  $input .= "\r\n";
87 }
88 
89 
90 $sql = 'SELECT nom as name, reponses';
91 $sql .= ' FROM '.MAIN_DB_PREFIX."opensurvey_user_studs";
92 $sql .= " WHERE id_sondage='".$db->escape($numsondage)."'";
93 $sql .= " ORDER BY id_users";
94 $resql = $db->query($sql);
95 if ($resql) {
96  $num = $db->num_rows($resql);
97  $i = 0;
98  while ($i < $num) {
99  $obj = $db->fetch_object($resql);
100 
101  // Le name de l'utilisateur
102  $nombase = str_replace("°", "'", $obj->name);
103  $input .= $nombase.';';
104 
105  //affichage des resultats
106  $ensemblereponses = $obj->reponses;
107  for ($k = 0; $k < $nbcolonnes; $k++) {
108  if (empty($somme[$k])) {
109  $somme[$k] = 0;
110  }
111  $car = substr($ensemblereponses, $k, 1);
112  if ($car == "1") {
113  $input .= 'OK;';
114  $somme[$k]++;
115  } elseif ($car == "2") {
116  $input .= ';';
117  $somme[$k]++;
118  } else {
119  $input .= 'KO;';
120  }
121  }
122 
123  $input .= "\r\n";
124  $i++;
125  }
126 } else {
127  dol_print_error($db);
128 }
129 
130 
131 $filesize = strlen($input);
132 $filename = $numsondage."_".dol_print_date($now, '%Y%m%d%H%M').".csv";
133 
134 
135 
136 header('Content-Type: text/csv; charset=utf-8');
137 header('Content-Length: '.$filesize);
138 header('Content-Disposition: attachment; filename="'.$filename.'"');
139 header('Cache-Control: max-age=10');
140 echo $input;
141 
142 exit;
Put here description of your class.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.