source: trunk/install/install2.php@ 376

Last change on this file since 376 was 376, checked in by roby, 20 months ago

Admin:

  • modificata la funzione aggiornadb per gestire il caso di cambiamento del nome del superutente e tolto il default per tipi campo text
  • modificata la funzione dei controlli per gestire il tipo consultazione Regionali in Sicilia

Install:

  • modificata la funzione di installazione per compatibilità con php 8.0

Client:

  • cambiata l'immagine "vuoto.jpg" nel formato png per gestire la trasparenza
  • modificate le funzioni affluenze e votanti per correggere l'esportazione in pdf e le stampe
  • per il tema Futura2 eliminato il taglio della descrizione della consultazione
File size: 14.9 KB
Line 
1<?php
2
3/************************************************************************/
4/* Eleonline */
5/* ============================================ */
6/* Installer was based on Joomla Installer */
7/************************************************************************/
8
9// Set flag that this is a parent file
10define( "_VALID_MOS", 1 );
11
12// Include common.php
13require_once( 'common.php' );
14require_once( './includes/database.php' );
15
16$DBhostname = mosGetParam( $_POST, 'DBhostname', '' );
17$DBuserName = mosGetParam( $_POST, 'DBuserName', '' );
18$DBpassword = mosGetParam( $_POST, 'DBpassword', '' );
19$ELEuserName = mosGetParam( $_POST, 'ELEuserName', '' );
20$ELEpassword = mosGetParam( $_POST, 'ELEpassword', '' );
21$DBname = mosGetParam( $_POST, 'DBname', '' );
22$DBPrefix = mosGetParam( $_POST, 'DBPrefix', 'soraldo' );
23$DBcreated = intval( mosGetParam( $_POST, 'DBcreated', 0 ) );
24$BUPrefix = 'old_';
25$configArray['sitename'] = trim( mosGetParam( $_POST, 'sitename', 'Elezioni On Line' ) );
26$configArray['nomecomune'] = trim( mosGetParam( $_POST, 'nomecomune', '' ) );
27$configArray['istat'] = trim( mosGetParam( $_POST, 'istat', '' ) );
28$Capoluogo = mosGetParam( $_POST, 'Capoluogo', '' );
29$Lingua = mosGetParam( $_POST, 'Lingua', '' );
30$Multicomune = mosGetParam( $_POST, 'Multicomune', '0' );
31$Replica = mosGetParam( $_POST, 'Replica', '' );
32//tema
33$tema = mosGetParam( $_POST, 'tema', '' );
34$sceltatema = mosGetParam( $_POST, 'sceltatema', '' );
35$blocco = mosGetParam( $_POST, 'blocco', '' );
36$flash = mosGetParam( $_POST, 'flash', '' );
37// d'hondt
38$Hondt = mosGetParam( $_POST, 'Hondt', '' );
39$Limite = mosGetParam( $_POST, 'Limite', '' );
40$Consin = mosGetParam( $_POST, 'Consin', '' );
41$infpremio = mosGetParam( $_POST, 'infpremio', '67' );
42$supsbarramento = mosGetParam( $_POST, 'supsbarramento', '3' );
43$suppremio = mosGetParam( $_POST, 'suppremio', '60' );
44$supminpremio = mosGetParam( $_POST, 'supminpremio', '40' );
45$database = null;
46$themelist = mosGetParam( $_POST, 'themelist', '' );
47
48$errors = array();
49if (!$DBcreated){
50 if (!$DBhostname || !$DBuserName || !$DBname) {
51 db_err ("stepBack3","The database details provided are incorrect and/or empty.");
52 }
53$dsn = "mysql:host=$DBhostname"; #dbname=$DBname";
54$opt = [
55PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
56PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
57PDO::ATTR_EMULATE_PREPARES => false,
58];
59$user=$DBuserName;
60$password=$DBpassword;
61
62 if($DBPrefix == '') {
63 db_err ('stepBack','Non avete indicato il prefisso tabelle database.');
64 }
65 try {
66 $database = new PDO($dsn, $user, $password, $opt);
67 }
68 catch(PDOException $e)
69 {
70 echo $sql . "<br>" . $e->getMessage();die();
71 }
72#sostituire questa riga con le variabili per il nuovo utente e la sua password da inserire nella pagina precedente
73########################################
74# $DBuserName='eleuser'; $DBpassword='elepass';
75 try{
76 $sql = "CREATE DATABASE IF NOT EXISTS $DBname;";
77 $database->exec($sql);
78 }
79 catch(PDOException $e)
80 {
81 echo $sql . "<br>" . $e->getMessage();die();
82 }
83 try {
84 $sql="CREATE USER if not exists `$ELEuserName`@'$DBhostname' IDENTIFIED BY '$ELEpassword';";
85 $database->exec($sql);
86# $sql= "GRANT ALL ON `$DBname`.* TO `roby`@'$DBhostname';";
87# $database->exec($sql);
88 $sql= "GRANT ALL ON `$DBname`.* TO `$ELEuserName`@'$DBhostname';";
89 $database->exec($sql);
90 $sql= "FLUSH PRIVILEGES;";
91 $database->exec($sql);
92 $sql = "use $DBname";
93 $database->exec($sql);
94 $sql = file_get_contents('sql/eleonline.sql');
95 $qr = $database->exec($sql);
96 $DBcreated = 1;
97 }
98 catch(PDOException $e)
99 {
100 echo $sql . "<br>" . $e->getMessage();die();
101 }
102}
103
104function db_err($step, $alert) {
105 global $DBhostname,$DBuserName,$DBpassword,$DBname,$DBPrefix;
106 echo "<form name=\"$step\" method=\"post\" action=\"install1.php\">
107 <input type=\"hidden\" name=\"DBhostname\" value=\"$DBhostname\">
108 <input type=\"hidden\" name=\"DBuserName\" value=\"$DBuserName\">
109 <input type=\"hidden\" name=\"DBpassword\" value=\"$DBpassword\">
110 <input type=\"hidden\" name=\"DBname\" value=\"$DBname\">
111 <input type=\"hidden\" name=\"DBPrefix\" value=\"$DBPrefix\">
112 </form>\n";
113 echo "<script>alert(\"$alert\"); window.history.go(-1);</script>";
114 //echo "<script>alert(\"$alert\"); document.location.href='install1.php';</script>";
115
116 exit();
117
118
119
120}
121
122/**
123 * @param object
124 * @param string File name
125 */
126function populate_db( &$database, $sqlfile='eleonline.sql') {
127 global $errors;
128
129 $mqr = @get_magic_quotes_runtime();
130 @set_magic_quotes_runtime(0);
131 $query = fread( fopen( 'sql/' . $sqlfile, 'r' ), filesize( 'sql/' . $sqlfile ) );
132 @set_magic_quotes_runtime($mqr);
133 $pieces = split_sql($query);
134
135 for ($i=0; $i<count($pieces); $i++) {
136 $pieces[$i] = trim($pieces[$i]);
137 if(!empty($pieces[$i]) && $pieces[$i] != "#") {
138 $database->setQuery( $pieces[$i] );
139 if (!$database->query()) {
140 $errors[] = array ( $database->getErrorMsg(), $pieces[$i] );
141 }
142 }
143 }
144}
145
146/**
147 * @param string
148 */
149function split_sql($sql) {
150 $sql = trim($sql);
151 $sql = preg_replace('/\n#[^\n]*\n/', "\n", $sql);
152
153 $buffer = array();
154 $ret = array();
155 $in_string = false;
156
157 for($i=0; $i<strlen($sql)-1; $i++) {
158 if($sql[$i] == ";" && !$in_string) {
159 $ret[] = substr($sql, 0, $i);
160 $sql = substr($sql, $i + 1);
161 $i = 0;
162 }
163
164 if($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") {
165 $in_string = false;
166 }
167 elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
168 $in_string = $sql[$i];
169 }
170 if(isset($buffer[1])) {
171 $buffer[0] = $buffer[1];
172 }
173 $buffer[1] = $sql[$i];
174 }
175
176 if(!empty($sql)) {
177 $ret[] = $sql;
178 }
179 return($ret);
180}
181
182$isErr = intval( count( $errors ) );
183
184echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">";
185?>
186<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
187<html xmlns="http://www.w3.org/1999/xhtml">
188<head>
189<title>Eleonline Installer</title>
190<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
191<link rel="stylesheet" href="install.css" type="text/css" />
192<script type="text/javascript">
193<!--
194function check() {
195 // form validation check
196 var formValid=false;
197 var f = document.form;
198 if ( f.sitename.value == '' ) {
199 alert('Inserisci il nome del sito');
200 f.sitename.focus();
201 formValid=false;
202 } else if ( f.nomecomune.value == '' ) {
203 alert('Inserisci il nome del Comune');
204 f.nomecomune.focus();
205 formValid=false;
206 } else if ( f.istat.value == '' ) {
207 alert('Inserisci il numero Istat del Comune');
208 f.istat.focus();
209 formValid=false;
210
211 } else if ( confirm('Sei sicuro che questi settaggi sono corretti?')) {
212 formValid=true;
213 }
214
215 return formValid;
216}
217//-->
218</script>
219</script>
220</head>
221<body onload="document.form.sitename.focus();">
222<div id="wrapper">
223 <div id="header">
224 <div id="eleonline"><img src="header_install.png" alt="Installazione Eleonline" title="Installazione Eleonline" /></div>
225 </div>
226</div>
227
228<div id="ctr" align="center">
229 <form action="install3.php" method="post" name="form" id="form" onsubmit="return check();">
230 <input type="hidden" name="DBhostname" value="<?php echo "$DBhostname"; ?>" />
231 <input type="hidden" name="DBuserName" value="<?php echo "$DBuserName"; ?>" />
232 <input type="hidden" name="DBpassword" value="<?php echo "$DBpassword"; ?>" />
233 <input type="hidden" name="DBname" value="<?php echo "$DBname"; ?>" />
234 <input type="hidden" name="DBPrefix" value="<?php echo "$DBPrefix"; ?>" />
235 <input type="hidden" name="DBcreated" value="<?php echo "$DBcreated"; ?>" />
236
237 <div class="install">
238 <div id="stepbar">
239 <div class="step-off">Inizio</div>
240 <div class="step-off">licenza</div>
241 <div class="step-off">passo 1</div>
242 <div class="step-on">passo 2</div>
243 <div class="step-off">passo 3</div>
244 <div class="step-off">passo 4</div>
245 </div>
246
247 <div id="right">
248 <div class="far-right">
249<?php if (!$isErr) { ?>
250 <input class="button" type="submit" name="next" value="Avanti >>"/>
251<?php } ?>
252 </div>
253 <div id="step">passo 2</div>
254 <div class="clr"></div>
255
256 <h1>Risultato inserimento database <?php echo "<font color=\"#ff0000\">$DBname</font> su <font color=\"#ff0000\">$DBhostname</font>"; ?> :</h1>
257 <div class="install-text">
258<?php if ($isErr) { ?>
259 Sembra che ci siano errori con l'inserimento dei dati nel tuo database!<br />
260 Non puoi continuare.
261 </div>
262 <div class="install-form">
263 <div class="form-block">
264 <table class="content2">
265 <?php
266 echo '<tr><td colspan="2">';
267 echo '<b></b>';
268 echo "<br/><br />Error log:<br />\n";
269 // abrupt failure
270 echo '<textarea rows="10" cols="50">';
271 foreach($errors as $error) {
272 echo "SQL=$error[0]:\n- - - - - - - - - -\n$error[1]\n= = = = = = = = = =\n\n";
273 }
274 echo '</textarea>';
275 echo "</td></tr>\n";
276 ?>
277 </table>
278 </div>
279 </div>
280
281<?php } else { ?>
282
283
284 TUTTO OK!
285 <br/>
286 <br/>
287 </div>
288 <div class="install-form">
289 <div class="clr"></div>
290 </div>
291
292
293
294
295
296
297
298
299 <div class="clr"></div>
300
301 <h1>Inserisci i dati di configurazione del sito:</h1>
302 <div class="install-text">
303
304 Inserisci il nome del tuo sito. In genere viene usato il nome del Comune.
305 </div>
306 <div class="install-form">
307 <div class="form-block">
308 <table class="content2">
309
310 <tr>
311 <td width="100">Nome del sito</td>
312 <td align="left"><input class="inputbox" type="text" name="sitename" size="40" value="<?php echo "{$configArray['sitename']}"; ?>" /></td>
313 <td></td>
314 </tr>
315 <tr>
316 <td width="100">Nome del Comune</td>
317 <td align="left"><input class="inputbox" type="text" name="nomecomune" size="40" value="<?php echo "{$configArray['nomecomune']}"; ?>" /></td>
318 <td></td>
319 </tr>
320
321 <tr>
322 <td width="100">Numero Istat</td>
323 <td align="left"><input class="inputbox" type="text" name="istat" size="6" value="<?php echo "{$configArray['istat']}"; ?>" />
324 <a href="http://www.istat.it/strumenti/definizioni/comuni/" target="_blank">Preleva i codici Istat dei comuni italiani</a>
325 </td><td></td>
326 </tr>
327 <tr>
328 <td width="150"><em>Fascia abitanti</em> </td><td>
329 <select name="Limite">
330 <option value="1" selected>fino a 3.000 ab.</option>
331 <option value="2">fino a 10.000 ab.</option>
332 <option value="3">fino a 15.000 ab.</option>
333 <option value="4">fino a 30.000 ab.</option>
334 <option value="5">fino a 100.000 ab.</option>
335 <option value="6">fino a 250.000 ab.</option>
336 <option value="7">fino a 500.000 ab.</option>
337 <option value="8">fino a 1.000.000 ab.</option>
338 <option value="9">sopra il 1.000.000 ab.</option>
339 </select>
340 </td>
341
342 </tr>
343
344
345
346
347 </table>
348 <table class="content2">
349
350
351
352
353
354 <tr>
355 <td width="70">Capoluogo</td><td width="70">
356 <input type="checkbox" name="Capoluogo" id="Capoluogo" value="1" <?php if ($Capoluogo) echo 'checked="checked"'; ?> />
357 </td>
358 <td>Check se il comune e' Capoluogo di Provincia</td>
359
360 </tr>
361 <tr>
362 <td width="70">Linguaggio </td><td width="70">
363 <select name="Lingua"><option value="it" selected>italiano</option><option value="en">english</option></select>
364 </td>
365 <td>Lingua di default del sito</td>
366
367 </tr>
368 <tr>
369 <td width="70">Multicomune </td><td width="70">
370 <input type="checkbox" name="Multicomune" id="Multicomune" value="1" <?php if ($Multicomune) echo 'checked="checked"'; ?> />
371 </td>
372 <td>Check se il sito ospita piu' di un comune</td>
373
374 </tr>
375 <tr>
376 <td width="70">Replica Db </td><td width="70">
377 <input type="checkbox" name="Replica" id="Replica" value="1" <?php if ($Replica) echo 'checked="checked"'; ?> />
378 </td>
379 <td>Check in caso di replica del database. Se sullo stesso server lasciare libero</td>
380
381 </tr>
382
383
384
385
386
387</table>
388
389 </div>
390 </div>
391 <div class="clr"></div>
392 <div class="clr"></div>
393 <h1>Configurazione del Tema:</h1>
394 <div class="install-text">
395 <p>La visualizzazione dei risultati puo' essere configurata in maniera da scegliere il
396 tema e altro ancora.
397 <br><br>
398
399 Potete comunque sempre cambiare le opzioni successivamete agendo sul file config.php<br/>
400 </p>
401 </div>
402 <div class="install-form">
403 <div class="form-block">
404
405 <br/>
406 <table class="content2">
407 <tr>
408 <td></td>
409 <td></td>
410 <td></td>
411 </tr>
412
413
414
415 <tr>
416 <td width="150">Scelta del tema</td>
417 <td><select name='tema'>
418 <?php
419 $handle=opendir('../client/temi');
420 while ($file = readdir($handle)) {
421 if ( (preg_match('/^([_0-9a-zA-Z]+)([_0-9a-zA-Z]{3})$/',$file)) ){
422 //if ( (!preg_match('/[.]/',$file)) ) {
423 $themelist .= "$file ";
424 }
425 }
426 closedir($handle);
427 $themelist = explode(" ", $themelist);
428 sort($themelist);
429 for ($i=0; $i < sizeof($themelist); $i++) {
430 if(!empty($themelist[$i])) {
431 echo "<option name='tema' value='$themelist[$i]' ";
432 if($themelist[$i]=="default") echo "selected";
433 echo ">$themelist[$i]\n";
434 }
435 }
436 echo "</select>";
437 ?>
438 </td>
439
440 </tr>
441 </table>
442 <br/>
443 <table class="content2">
444 <tr>
445 <td></td>
446 <td></td>
447 <td></td>
448 </tr>
449
450
451
452 <tr><td width="150">Visualizza menu per la scelta del tema</td>
453
454
455 <td>
456 <select name="sceltatema"><option value="1" selected>SI</option><option value="0">NO</option></select></td><td>Permette di far scegliere all'utente che naviga sul sito il tipo di grafica
457
458
459 </td>
460
461 </tr>
462 </table>
463 <br/>
464 <table class="content2">
465 <tr>
466 <td></td>
467 <td></td>
468 <td></td>
469 </tr>
470
471
472
473 <tr><td width="150">Visualizza blocco laterale?</td><td>
474 <select name="blocco"><option value="1" selected>SI</option><option value="0">NO</option></select></td>
475 <td>Il blocco laterale destro puo' contenere dati e link </td>
476
477 </tr>
478 </table>
479 <br/>
480 <table class="content2">
481 <tr>
482 <td></td>
483 <td></td>
484 <td></td>
485 </tr>
486
487
488
489 <tr><td width="150">Abilita il formato Flash?</td><td>
490 <select name="flash"><option value="1">SI</option><option value="0" selected>NO</option></select></td>
491 <td>L'abilitazione del Flash permette di avere grafici in movimento. Se disabilitato i grafici saranno statici</td>
492
493 </tr>
494 </table>
495
496
497
498
499
500 </div></div></div>
501
502
503
504
505
506
507
508
509
510
511
512 <div class="clr"></div>
513
514
515 <div class="clr"></div>
516 </form>
517
518<?php } // fine if ?>
519
520</div>
521<div class="clr"></div>
522<div class="clr"></div>
523<?php include("footer.php"); ?>
524
525</body>
526</html>
Note: See TracBrowser for help on using the repository browser.