-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagentlist.php
146 lines (130 loc) · 5.08 KB
/
agentlist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
include('db.php');
$action = $_GET['action'];
if($action == 'esportaanagrafica'){
$sql = 'SELECT * FROM agenti WHERE attivo = TRUE';
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_NUM);
$columns = array();
$rs = $db->query('WITH myquery AS ('.$sql.') SELECT * FROM myquery LIMIT 0');
for ($i = 0; $i < $rs->columnCount(); $i++) {
$col = $rs->getColumnMeta($i);
$columns[] = $col['name'];
}
$fp = fopen('temp/anagrafica.csv', 'w');
fputcsv($fp, $columns, ';');
foreach ($results as $fields) {
fputcsv($fp, $fields, ';');
}
fclose($fp);
echo('<a href="temp/anagrafica.csv">Scarica l\'anagrafica in CSV</a>');
} else if($action == 'agentiareeprodotti'){
$sql = 'SELECT nomeagente, cognome, prodotto, aree.nome || \' \' || substring(aree.codice,4,2) as microarea FROM (SELECT agenti.nome as nomeagente, agenti.cognome, prodotti.nome as prodotto, aree.codice FROM "agente-prodotto-area" AS apa, "agente-prodotto" AS ap, "agente-aree" AS aa, aree, agenti, prodotti WHERE apa.idagenteprodotto = ap.id AND apa.idagentearea = aa.id AND ap.idagente = agenti.id AND aa.area = aree.codice AND ap.codprodotto = prodotti.id) AS myquery FULL JOIN aree ON myquery.codice = aree.codice';
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_NUM);
$columns = array();
$rs = $db->query('WITH myquery AS ('.$sql.') SELECT * FROM myquery LIMIT 0');
for ($i = 0; $i < $rs->columnCount(); $i++) {
$col = $rs->getColumnMeta($i);
$columns[] = $col['name'];
}
$fp = fopen('temp/agentiareeprodotti.csv', 'w');
fputcsv($fp, $columns, ';');
foreach ($results as $fields) {
fputcsv($fp, $fields, ';');
}
fclose($fp);
echo('<a href="temp/agentiareeprodotti.csv">Scarica l\'associazione agenti-aree-prodotti in CSV</a>');
}
else{
echo('<br><a href="index.php?section=agentlist&action=piva">Mostra solo agenti con P.IVA</a>         ');
echo('<a href="index.php?section=agentlist&action=nopiva">Mostra solo agenti senza P.IVA</a>        ');
echo('<a href="index.php?section=agentlist&action=inactive">Mostra agenti inattivi</a>        ');
echo('<a href="index.php?section=agentlist&action=agentiareeprodotti">Esporta l\'associazione agenti-aree-prodotti</a>        ');
echo('<a href="index.php?section=agentlist&action=esportaanagrafica">Esporta anagrafica</a><br><br>');
echo('<strong><a href="index.php?section=addagent&action=add">Aggiungi nuovo agente</a></strong><br>');
echo('<div class="CSS_Table_Example" style="width:70%;" > ');
echo(' <table >
<tr>
<td>
Cognome
</td>
<td >
Nome
</td>
<td>
Codice Fiscale
</td>
<td>
P.IVA
</td>
<td>
e-mail
</td>
<td>
Dettagli
</td>
<td>
Modifica
</td>
</tr>');
$q = '';
$attivo = 'WHERE attivo = true';
if($action == 'piva')
{
$q = "WHERE partitaiva <> ''";
$attivo = 'AND attivo = true';
}
else if($action == 'nopiva')
{
$q = "WHERE partitaiva IS NULL OR partitaiva = ''";
$attivo = 'AND attivo = true';
}
else if($action == 'inactive')
{
$attivo = 'WHERE attivo = false';
}
try{
$query = $db->prepare('SELECT * FROM agenti '.$q.' ' .$attivo.' ORDER BY cognome');
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);
}catch(Exception $pdoe){
echo('Errore: '.$pdoe->getMessage());
}
foreach ($results as $row){
echo(' <tr>
<td >
'.$row['cognome'].'
</td>
<td>
'.$row['nome'].'
</td>
<td>
'.$row['codicefiscale'].'
</td>
<td>
'.$row['partitaiva'].'
</td>
<td>
<a href="mailto:'.$row['email'].'">'.$row['email'].'
</td>
<td>
<a href="index.php?section=viewagent&id='.$row['id'].'">dettagli</a>
</td>
<td>
<a href="index.php?section=addagent&action=mod&id='.$row['id'].'">modifica</a>
</td>
</tr>');
}
echo(' </table>
</div>
');
}
//echo('<table border="1"><tr><th>Nome</th><th>Cognome</th><th>Codice Fiscale</th><th>P.IVA</th><th>e-mail</th><th></th><th></th></tr>');
//foreach ($results as $row){
// echo('<tr><td>'.$row['nome'].'</td><td>'.$row['cognome'].'</td><td>'.$row['codicefiscale'].'</td><td>'.$row['partitaiva'].'</td><td>'.$row['email'].'</td><td><a href="index.php?section=viewagent&id='.$row['id'].'">dettagli</a></td></tr>');
//}
//echo('</table>');
?>