|
1 |
|
2 <?php |
|
3 include("db-config.inc"); |
|
4 |
|
5 function obtenir_habitants($connection) |
|
6 { |
|
7 $resultat_habitants = mysql_query("SELECT id,nom FROM gent WHERE habitant=1 ORDER BY nom;", $connection); |
|
8 if (!$resultat_habitants) |
|
9 { |
|
10 ?> |
|
11 <p> <STRONG>ERROR:</STRONG> Error al obtenir |
|
12 <STRONG>habitants</STRONG>! </p> |
|
13 <?php |
|
14 echo "Error MYSQL:" . mysql_errno() . ": " . mysql_error() . "<BR>"; |
|
15 } |
|
16 |
|
17 // Processem el resultat |
|
18 while ($fila = mysql_fetch_row($resultat_habitants)) |
|
19 $habitant[] = array( "id" => $fila[0], |
|
20 "nom" => $fila[1]); |
|
21 mysql_free_result($resultat_habitants); |
|
22 return $habitant; |
|
23 } |
|
24 |
|
25 function obtenir_altres($connection) |
|
26 { |
|
27 $resultat_altres = mysql_query("SELECT id,nom FROM gent WHERE habitant=0 ORDER BY nom;", $connection); |
|
28 |
|
29 if (!$resultat_altres) |
|
30 { |
|
31 ?> |
|
32 <p> <STRONG>ERROR:</STRONG> Error al obtenir |
|
33 <STRONG>altres</STRONG>! </p> |
|
34 <?php |
|
35 echo "Error MYSQL:" . mysql_errno().": ".mysql_error()."<BR>"; |
|
36 } |
|
37 |
|
38 while ($fila = mysql_fetch_row($resultat_altres)) |
|
39 $altres[] = array( "id" => $fila[0], |
|
40 "nom" => $fila[1]); |
|
41 return $altres; |
|
42 } |
|
43 |
|
44 function obtenir_gent($connection) |
|
45 { |
|
46 $resultat = mysql_query("SELECT id,nom,habitant FROM gent ORDER BY habitant DESC ,nom ASC", $connection); |
|
47 |
|
48 if (!$resultat) |
|
49 { |
|
50 ?> |
|
51 <p> <STRONG>ERROR:</STRONG> Error al obtenir |
|
52 <STRONG>gent</STRONG>! </p> |
|
53 <?php |
|
54 echo "Error MYSQL:" . mysql_errno().": ".mysql_error()."<BR>"; |
|
55 } |
|
56 |
|
57 while ($fila = mysql_fetch_row($resultat)) |
|
58 $gent[$fila[0]] = array( "nom" => $fila[1], |
|
59 "habitant" => $fila[2]); |
|
60 return $gent; |
|
61 } |
|
62 |
|
63 function obtenir_compra($date,$connection) |
|
64 { |
|
65 $resultat = mysql_query("SELECT UNIX_TIMESTAMP(data),botiga,motiu,preu,comentari FROM compres WHERE data=FROM_UNIXTIME(" . $date . ")", $connection); |
|
66 |
|
67 // Només hi haurà una fila |
|
68 $fila = mysql_fetch_row($resultat); |
|
69 $compra["data"] = $fila[0]; |
|
70 $compra["botiga"] = $fila[1]; |
|
71 $compra["motiu"] = $fila[2]; |
|
72 settype($fila[3],"float"); |
|
73 $compra["preu"] = $fila[3]; |
|
74 $compra["comentari"] = $fila[4]; |
|
75 |
|
76 return $compra; |
|
77 } |
|
78 |
|
79 function obtenir_pagament($date,$connection) |
|
80 { |
|
81 $resultat = mysql_query("SELECT UNIX_TIMESTAMP(data),comentari FROM pagaments WHERE data=FROM_UNIXTIME(" . $date . ")", $connection); |
|
82 |
|
83 // Només hi haurà una fila |
|
84 $fila = mysql_fetch_row($resultat); |
|
85 $pagament["data"] = $fila[0]; |
|
86 $pagament["comentari"] = $fila[1]; |
|
87 |
|
88 return $pagament; |
|
89 } |
|
90 |
|
91 function obtenir_excepcions($date,$connection) |
|
92 { |
|
93 $query = "SELECT id,article,preu FROM excepcions WHERE data=FROM_UNIXTIME($date) ORDER BY article"; |
|
94 $resultat = mysql_query($query, $connection); |
|
95 |
|
96 while ($fila = mysql_fetch_row($resultat)) |
|
97 $excepcio[$fila[0]] = array("article" => $fila[1], "preu" => $fila[2]); |
|
98 |
|
99 if (!isset($excepcio)) |
|
100 $excepcio=0; |
|
101 return $excepcio; |
|
102 } |
|
103 |
|
104 function obtenir_compradors($date,$connection) |
|
105 { |
|
106 $query = "SELECT compradors.persona,compradors.pagat,compradors.toca_pagar FROM compradors,gent WHERE compradors.data=FROM_UNIXTIME($date) AND compradors.persona=gent.id ORDER BY gent.nom;"; |
|
107 $resultat = mysql_query($query, $connection); |
|
108 |
|
109 // Puc fer lo de sota perquè per una sola compra no hi poden haver compradors repetits. |
|
110 while ($fila = mysql_fetch_row($resultat)) |
|
111 $compradors[$fila[0]] = array( "pagat" => $fila[1], |
|
112 "toca_pagar" => $fila[2]); |
|
113 return $compradors; |
|
114 } |
|
115 |
|
116 function obtenir_compradors_excepcions($ex_id,$connection) |
|
117 { |
|
118 $query = "SELECT compradors_excepcions.persona,compradors_excepcions.toca_pagar FROM compradors_excepcions,gent WHERE compradors_excepcions.ex_id=$ex_id AND compradors_excepcions.persona = gent.id ORDER BY gent.nom;"; |
|
119 $resultat = mysql_query($query, $connection); |
|
120 |
|
121 // Puc fer lo de sota perquè per una sola compra no hi poden haver compradors repetits. |
|
122 while ($fila = mysql_fetch_row($resultat)) |
|
123 $compradors[$fila[0]] = array("toca_pagar" => $fila[1]); |
|
124 return $compradors; |
|
125 } |
|
126 |
|
127 function obtenir_pagadors($date,$connection) |
|
128 { |
|
129 $query = "SELECT pagadors.persona,pagadors.pagat,pagadors.cobrat FROM pagadors,gent WHERE pagadors.data=FROM_UNIXTIME($date) AND pagadors.persona=gent.id ORDER BY gent.nom;"; |
|
130 $resultat = mysql_query($query, $connection); |
|
131 |
|
132 // Puc fer lo de sota perquè per en un sol pagament no hi poden haver pagadors repetits |
|
133 while ($fila = mysql_fetch_row($resultat)) |
|
134 $pagadors[$fila[0]] = array( "pagat" => $fila[1], |
|
135 "cobrat" => $fila[2]); |
|
136 return $pagadors; |
|
137 } |
|
138 |
|
139 function obtenir_compres($connection) |
|
140 { |
|
141 $resultat = mysql_query("SELECT UNIX_TIMESTAMP(data),botiga,motiu,preu,comentari FROM compres ORDER BY data DESC;", $connection); |
|
142 |
|
143 |
|
144 while ($fila = mysql_fetch_row($resultat)) |
|
145 { |
|
146 settype($fila[3],"double"); |
|
147 $compres[$fila[0]] = array( |
|
148 "botiga" => $fila[1], |
|
149 "motiu" => $fila[2], |
|
150 "preu" => $fila[3], |
|
151 "comentari" => $fila[4]); |
|
152 } |
|
153 |
|
154 if (!isset($compres)) |
|
155 $compres=0; |
|
156 |
|
157 return $compres; |
|
158 } |
|
159 |
|
160 function obtenir_pagaments($connection) |
|
161 { |
|
162 $resultat = mysql_query("SELECT UNIX_TIMESTAMP(data),comentari FROM pagaments ORDER BY data DESC;", $connection); |
|
163 |
|
164 |
|
165 while ($fila = mysql_fetch_row($resultat)) |
|
166 { |
|
167 $pagaments[$fila[0]] = array("comentari" => $fila[1]); |
|
168 } |
|
169 |
|
170 if (!isset($pagaments)) |
|
171 $pagaments=0; |
|
172 |
|
173 return $pagaments; |
|
174 } |
|
175 |
|
176 // FUNCIONS PER GENERAR CODI HTML |
|
177 |
|
178 function select_altres($variable, $default=-1) |
|
179 { |
|
180 $num_altres = count($GLOBALS["altres"]); |
|
181 |
|
182 echo "<SELECT name=\"$variable\">\n"; |
|
183 |
|
184 foreach($GLOBALS["altres"] as $i) |
|
185 { |
|
186 echo "<OPTION value=\"" .$i["id"] . "\""; |
|
187 if ($default == $i["id"]) |
|
188 echo " selected"; |
|
189 echo ">" . strtohtml($i["nom"]) . "\n"; |
|
190 } |
|
191 |
|
192 echo "</SELECT>"; |
|
193 } |
|
194 |
|
195 function strtosql($cadena) |
|
196 { |
|
197 return ereg_replace("\'", "\'", $cadena); |
|
198 } |
|
199 |
|
200 function strtohtml($cadena) |
|
201 { |
|
202 $new= ereg_replace("[<]", "<", $cadena); |
|
203 $new= ereg_replace("[>]", ">'", $cadena); |
|
204 $new= ereg_replace("[&]", "&'", $cadena); |
|
205 |
|
206 return $new; |
|
207 } |
|
208 |
|
209 function pricetohtml($price) |
|
210 { |
|
211 if ($price < 0) |
|
212 return sprintf("<FONT COLOR=\"FF0000\">%.2f</FONT>", $price); |
|
213 else |
|
214 return sprintf("%.2f", $price); |
|
215 |
|
216 } |
|
217 ?> |