source: trunk/install/install2.php@ 327

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