dolibarr  16.0.5
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
28 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
29 require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
30 
31 $action = GETPOST('action', 'aZ09');
32 $numsondage = '';
33 if (GETPOST('id')) {
34  $numsondage = GETPOST("id", 'alpha');
35 }
36 
37 $object = new Opensurveysondage($db);
38 $result = $object->fetch(0, $numsondage);
39 if ($result <= 0) {
40  dol_print_error('', 'Failed to get survey id '.$numsondage);
41 }
42 
43 // Security check
44 if (empty($user->rights->opensurvey->read)) {
46 }
47 
48 
49 /*
50  * Actions
51  */
52 
53 
54 
55 /*
56  * View
57  */
58 
59 $now = dol_now();
60 
61 $nbcolonnes = substr_count($object->sujet, ',') + 1;
62 $toutsujet = explode(",", $object->sujet);
63 
64 // affichage des sujets du sondage
65 $input .= $langs->trans("Name").";";
66 for ($i = 0; $toutsujet[$i]; $i++) {
67  if ($object->format == "D") {
68  $input .= ''.dol_print_date($toutsujet[$i], 'dayhour').';';
69  } else {
70  $input .= ''.$toutsujet[$i].';';
71  }
72 }
73 
74 $input .= "\r\n";
75 
76 if (strpos($object->sujet, '@') !== false) {
77  $input .= ";";
78  for ($i = 0; $toutsujet[$i]; $i++) {
79  $heures = explode("@", $toutsujet[$i]);
80  $input .= ''.$heures[1].';';
81  }
82 
83  $input .= "\r\n";
84 }
85 
86 
87 $sql = 'SELECT nom as name, reponses';
88 $sql .= ' FROM '.MAIN_DB_PREFIX."opensurvey_user_studs";
89 $sql .= " WHERE id_sondage='".$db->escape($numsondage)."'";
90 $sql .= " ORDER BY id_users";
91 $resql = $db->query($sql);
92 if ($resql) {
93  $num = $db->num_rows($resql);
94  $i = 0;
95  while ($i < $num) {
96  $obj = $db->fetch_object($resql);
97 
98  // Le name de l'utilisateur
99  $nombase = str_replace("°", "'", $obj->name);
100  $input .= $nombase.';';
101 
102  //affichage des resultats
103  $ensemblereponses = $obj->reponses;
104  for ($k = 0; $k < $nbcolonnes; $k++) {
105  $car = substr($ensemblereponses, $k, 1);
106  if ($car == "1") {
107  $input .= 'OK;';
108  $somme[$k]++;
109  } elseif ($car == "2") {
110  $input .= 'KO;';
111  $somme[$k]++;
112  } else {
113  $input .= ';';
114  }
115  }
116 
117  $input .= "\r\n";
118  $i++;
119  }
120 } else {
121  dol_print_error($db);
122 }
123 
124 
125 $filesize = strlen($input);
126 $filename = $numsondage."_".dol_print_date($now, '%Y%m%d%H%M').".csv";
127 
128 
129 
130 header('Content-Type: text/csv; charset=utf-8');
131 header('Content-Length: '.$filesize);
132 header('Content-Disposition: attachment; filename="'.$filename.'"');
133 header('Cache-Control: max-age=10');
134 echo $input;
135 
136 exit;
Opensurveysondage
Put here description of your class.
Definition: opensurveysondage.class.php:36
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933