source: trunk/install/install2.php@ 400

Last change on this file since 400 was 381, checked in by roby, 2 years ago

INSTALL
adeguamento php5
ADMIN
continua elaborazione funzione di aggiornamento

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