source: trunk/install/install2.php@ 241

Last change on this file since 241 was 17, checked in by roby, 15 years ago

Sostituite le funzioni del gruppo ereg perché divenute "deprecate" con il php 5.3

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