dolibarr  13.0.2
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 {
35  $numsondage = GETPOST("id", 'alpha');
36 }
37 
38 $object = new Opensurveysondage($db);
39 $result = $object->fetch(0, $numsondage);
40 if ($result <= 0) dol_print_error('', 'Failed to get survey id '.$numsondage);
41 
42 
43 /*
44  * Actions
45  */
46 
47 
48 
49 /*
50  * View
51  */
52 
53 $now = dol_now();
54 
55 $nbcolonnes = substr_count($object->sujet, ',') + 1;
56 $toutsujet = explode(",", $object->sujet);
57 
58 // affichage des sujets du sondage
59 $input .= $langs->trans("Name").";";
60 for ($i = 0; $toutsujet[$i]; $i++)
61 {
62  if ($object->format == "D")
63  {
64  $input .= ''.dol_print_date($toutsujet[$i], 'dayhour').';';
65  } else {
66  $input .= ''.$toutsujet[$i].';';
67  }
68 }
69 
70 $input .= "\r\n";
71 
72 if (strpos($object->sujet, '@') !== false)
73 {
74  $input .= ";";
75  for ($i = 0; $toutsujet[$i]; $i++)
76  {
77  $heures = explode("@", $toutsujet[$i]);
78  $input .= ''.$heures[1].';';
79  }
80 
81  $input .= "\r\n";
82 }
83 
84 
85 $sql = 'SELECT nom as name, reponses';
86 $sql .= ' FROM '.MAIN_DB_PREFIX."opensurvey_user_studs";
87 $sql .= " WHERE id_sondage='".$db->escape($numsondage)."'";
88 $sql .= " ORDER BY id_users";
89 $resql = $db->query($sql);
90 if ($resql)
91 {
92  $num = $db->num_rows($resql);
93  $i = 0;
94  while ($i < $num)
95  {
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  {
106  $car = substr($ensemblereponses, $k, 1);
107  if ($car == "1")
108  {
109  $input .= 'OK;';
110  $somme[$k]++;
111  } elseif ($car == "2")
112  {
113  $input .= 'KO;';
114  $somme[$k]++;
115  } else {
116  $input .= ';';
117  }
118  }
119 
120  $input .= "\r\n";
121  $i++;
122  }
123 } else dol_print_error($db);
124 
125 
126 $filesize = strlen($input);
127 $filename = $numsondage."_".dol_print_date($now, '%Y%m%d%H%M').".csv";
128 
129 
130 
131 header('Content-Type: text/csv; charset=utf-8');
132 header('Content-Length: '.$filesize);
133 header('Content-Disposition: attachment; filename="'.$filename.'"');
134 header('Cache-Control: max-age=10');
135 echo $input;
136 
137 exit;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
Put here description of your class.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...