source: trunk/install/install4.php@ 428

Last change on this file since 428 was 377, checked in by roby, 2 years ago

DB

  • modifica tabella sezioni con inserimento constraint per controllo duplicati nel numero di sezione

ADMIN

  • modifica della funzione di connessione al db nel file admin.php per compatibilità con php5
  • modifica della funzione di inserimento delle sezioni con inserimento avvisi per errori di inserimento
  • modificata la funzione di aggiornamento del DB ( admin/aggiornadb.php ) per gestire l'aggiornamento degli indici PRIMARY, aggiunto il controllo della tabella soraldo_ele_liste e il nuovo contraint per la tabella soraldo_ele_sezioni
File size: 19.0 KB
Line 
1<?php
2
3/************************************************************************/
4/* Eleonline */
5/* ============================================ */
6/* Installer was based on Joomla Installer */
7/************************************************************************/
8
9error_reporting (E_ALL);
10
11// Set flag that this is a parent file
12define( "_VALID_MOS", 1 );
13
14// Include common.php
15require_once( 'common.php' );
16require_once( './includes/database.php' );
17
18$DBhostname = mosGetParam( $_POST, 'DBhostname', '' );
19$DBuserName = mosGetParam( $_POST, 'DBuserName', '' );
20$DBpassword = mosGetParam( $_POST, 'DBpassword', '' );
21$DBname = mosGetParam( $_POST, 'DBname', '' );
22$DBPrefix = mosGetParam( $_POST, 'DBPrefix', 'soraldo' );
23
24$sitename = mosGetParam( $_POST, 'sitename', '' );
25$nomecomune = mosGetParam( $_POST, 'nomecomune', '' ) ;
26$istat = mosGetParam( $_POST, 'istat', '' ) ;
27$Capoluogo = mosGetParam( $_POST, 'Capoluogo', '0' );
28$Lingua = mosGetParam( $_POST, 'Lingua', '' );
29$Multicomune = mosGetParam( $_POST, 'Multicomune', '0' );
30$Replica = mosGetParam( $_POST, 'Replica', '' );
31
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
39$Limite = mosGetParam( $_POST, 'Limite', '' );
40
41
42$adminName = mosGetParam( $_POST, 'adminName', '');
43$adminEmail = mosGetParam( $_POST, 'adminEmail', '');
44$CreateUSer = intval( mosGetParam( $_POST, 'CreateUSer', '' ) );
45$siteUrl = mosGetParam( $_POST, 'siteUrl', '' );
46$absolutePath = mosGetParam( $_POST, 'absolutePath', '' );
47$adminPassword = mosGetParam( $_POST, 'adminPassword', '');
48
49if ((trim($adminEmail== "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $adminEmail )==false)) {
50
51 echo "<form name=\"stepBack\" method=\"post\" action=\"install3.php\">
52 <input type=\"hidden\" name=\"DBhostname\" value=\"$DBhostname\" />
53 <input type=\"hidden\" name=\"DBuserName\" value=\"$DBuserName\" />
54 <input type=\"hidden\" name=\"DBpassword\" value=\"$DBpassword\" />
55 <input type=\"hidden\" name=\"DBname\" value=\"$DBname\" />
56 <input type=\"hidden\" name=\"DBPrefix\" value=\"$DBPrefix\" />
57
58 <input type=\"hidden\" name=\"DBcreated\" value=\"1\" />
59 <input type=\"hidden\" name=\"sitename\" value=\"$sitename\" />";
60
61
62 echo " <input type=\"hidden\" name=\"nomecomune\" value=\"$nomecomune\" />
63 <input type=\"hidden\" name=\"istat\" value=\"$istat\"/>
64 <input type=\"hidden\" name=\"Capoluogo\" value= \"$Capoluogo\" />
65 <input type=\"hidden\" name=\"Lingua\" value= \"$Lingua\" />
66 <input type=\"hidden\" name=\"Multicomune\" value=\"$Multicomune\" />
67 <input type=\"hidden\" name=\"Replica\" value=\"$Replica\" />
68
69 <input type=\"hidden\" name=\"tema\" value=\"$tema\" />
70 <input type=\"hidden\" name=\"sceltatema\" value=\"$sceltatema\" />
71 <input type=\"hidden\" name=\"blocco\" value=\"$blocco\" />
72 <input type=\"hidden\" name=\"flash\" value= \"$flash\" />
73
74
75 <input type=\"hidden\" name=\"Limite\" value=\"$Linite\" />";
76
77
78 echo "Indirizzo Email non valido";
79
80
81 echo " <input type=\"hidden\" name=\"adminName\" value=\"$adminName\" />
82 <input type=\"hidden\" name=\"adminEmail\" value=\"$adminEmail\" />
83
84 <input type=\"hidden\" name=\"siteUrl\" value=\"$siteUrl\" />
85 <input type=\"hidden\" name=\"absolutePath\" value=\"$absolutePath\" />
86 </form>";
87 echo "<script>alert('Devi inserire un indirizzo email valido.'); document.stepBack.submit(); </script>";
88 return;
89}
90
91if($DBhostname && $DBuserName && $DBname) {
92 $configArray['DBhostname'] = $DBhostname;
93 $configArray['DBuserName'] = $DBuserName;
94 $configArray['DBpassword'] = $DBpassword;
95 $configArray['DBname'] = $DBname;
96 $configArray['DBPrefix'] = $DBPrefix;
97} else {
98 echo "<form name=\"stepBack\" method=\"post\" action=\"install3.php\">
99 <input type=\"hidden\" name=\"DBhostname\" value=\"$DBhostname\" />
100 <input type=\"hidden\" name=\"DBuserName\" value=\"$DBuserName\" />
101 <input type=\"hidden\" name=\"DBpassword\" value=\"$DBpassword\" />
102 <input type=\"hidden\" name=\"DBname\" value=\"$DBname\" />
103 <input type=\"hidden\" name=\"DBPrefix\" value=\"$DBPrefix\" />
104
105 <input type=\"hidden\" name=\"DBcreated\" value=\"1\" />
106 <input type=\"hidden\" name=\"sitename\" value=\"$sitename\" />";
107
108 echo ' <input type="hidden" name="nomecomune" value="<?php echo "$nomecomune"; ?>" />
109 <input type="hidden" name="istat" value="<?php echo "$istat"; ?>" />
110 <input type="hidden" name="Capoluogo" value="<?php echo "$Capoluogo"; ?>" />
111 <input type="hidden" name="Lingua" value="<?php echo "$Lingua"; ?>" />
112 <input type="hidden" name="Multicomune" value="<?php echo "$Multicomune"; ?>" />
113 <input type="hidden" name="Replica" value="<?php echo "$Replica"; ?>" />
114
115 <input type="hidden" name="tema" value="<?php echo "$tema"; ?>" />
116 <input type="hidden" name="sceltatema" value="<?php echo "$sceltatema"; ?>" />
117 <input type="hidden" name="blocco" value="<?php echo "$blocco"; ?>" />
118 <input type="hidden" name="flash" value="<?php echo "$flash"; ?>" />
119
120
121 <input type="hidden" name="Limite" value="<?php echo "$Linite"; ?>" />';
122
123
124
125
126
127 echo " <input type=\"hidden\" name=\"adminName\" value=\"$adminName\" />
128 <input type=\"hidden\" name=\"adminEmail\" value=\"$adminEmail\" />
129
130 <input type=\"hidden\" name=\"siteUrl\" value=\"$siteUrl\" />
131 <input type=\"hidden\" name=\"absolutePath\" value=\"$absolutePath\" />
132 </form>";
133
134 echo "<script>alert('The database details provided are incorrect and/or empty'); document.stepBack.submit(); </script>";
135 return;
136}
137
138if ($sitename) {
139# if (!get_magic_quotes_gpc()) {
140 $configArray['sitename'] = addslashes($sitename);
141# } else {
142# $configArray['sitename'] = $sitename;
143# }
144} else {
145 echo "<form name=\"stepBack\" method=\"post\" action=\"install3.php\">
146 <input type=\"hidden\" name=\"DBhostname\" value=\"$DBhostname\" />
147 <input type=\"hidden\" name=\"DBuserName\" value=\"$DBuserName\" />
148 <input type=\"hidden\" name=\"DBpassword\" value=\"$DBpassword\" />
149 <input type=\"hidden\" name=\"DBname\" value=\"$DBname\" />
150 <input type=\"hidden\" name=\"DBPrefix\" value=\"$DBPrefix\" />
151
152 <input type=\"hidden\" name=\"DBcreated\" value=\"1\" />
153 <input type=\"hidden\" name=\"sitename\" value=\"$sitename\" />";
154
155 echo ' <input type="hidden" name="nomecomune" value="<?php echo "$nomecomune"; ?>" />
156 <input type="hidden" name="istat" value="<?php echo "$istat"; ?>" />
157 <input type="hidden" name="Lingua" value="<?php echo "$Lingua"; ?>" />
158 <input type="hidden" name="Capoluogo" value="<?php echo "$Capoluogo"; ?>" />
159 <input type="hidden" name="Multicomune" value="<?php echo "$Multicomune"; ?>" />
160 <input type="hidden" name="Replica" value="<?php echo "$Replica"; ?>" />
161
162 <input type="hidden" name="tema" value="<?php echo "$tema"; ?>" />
163 <input type="hidden" name="sceltatema" value="<?php echo "$sceltatema"; ?>" />
164 <input type="hidden" name="blocco" value="<?php echo "$blocco"; ?>" />
165 <input type="hidden" name="flash" value="<?php echo "$flash"; ?>" />
166
167
168 <input type="hidden" name="Limite" value="<?php echo "$Linite"; ?>" />
169 ';
170
171
172 echo " <input type=\"hidden\" name=\"adminName\" value=\"$adminName\" />
173 <input type=\"hidden\" name=\"adminEmail\" value=\"$adminEmail\" />
174
175 <input type=\"hidden\" name=\"siteUrl\" value=\"$siteUrl\" />
176 <input type=\"hidden\" name=\"absolutePath\" value=\"$absolutePath\" />
177 </form>";
178
179 echo "<script>alert('The sitename has not been provided'); document.stepBack2.submit();</script>";
180 return;
181}
182
183if (file_exists( '../client/config.php' )) {
184 $canWrite = is_writable( '../client/config.php' );
185} else {
186 $canWrite = is_writable( '../client' );
187}
188
189// admin
190if (file_exists( '../client/config.php' )) {
191 $canWrite2 = is_writable( '../admin/config.php' );
192} else {
193 $canWrite2 = is_writable( '../admin' );
194}
195
196
197
198if ($siteUrl) {
199 $configArray['siteUrl']=$siteUrl;
200 // Fix for Windows
201 $absolutePath= str_replace("\\\\","/", $absolutePath);
202 $configArray['absolutePath']=$absolutePath;
203
204
205#########################################################################
206# Config visualizzazione
207$config = "<?php\n";
208$config .= "\n";
209
210$config .= "/************************************************************************/\n";
211$config .= "/* Eleonline - Raccolta e diffusione dei dati elettorali */\n";
212$config .= "/* by Roberto Gigli & Luciano Apolito */\n";
213$config .= "/* http://www.eleonline.it */\n";
214$config .= "/* info@eleonline.it luciano@aniene.net rgigli@libero.it */\n";
215$config .= "/************************************************************************/\n";
216$config .= "\n";
217$config .= "\n";
218$config .= "if (stristr(\"config.php\",\$_SERVER['PHP_SELF'])) {\n";
219$config .= " Header(\"Location: index.php\");\n";
220$config .= " die();\n";
221$config .= "}\n";
222$config .= "\n";
223$config .= "\n";
224$config .= "/* Variabili di configurazione accesso db */\n";
225$config .= "\$dbhost = \"{$configArray['DBhostname']}\";\n";
226$config .= "\$dbuname = \"{$configArray['DBuserName']}\";\n";
227$config .= "\$dbpass = \"{$configArray['DBpassword']}\";\n";
228$config .= "\$dbname = \"{$configArray['DBname']}\";\n";
229$config .= "\$prefix = \"{$configArray['DBPrefix']}\";\n";
230$config .= "\$dbtype = \"MySQL\";\n";
231
232
233
234
235$config .= "\n";
236$config .= "ini_set('display_errors',0);\n";
237$config .= "?>\n";
238
239
240#####################################################################################
241# config amministrazione
242#####################################################################################
243
244$config_adm = "<?php\n";
245$config_adm .= "\n";
246
247$config_adm .= "/************************************************************************/\n";
248$config_adm .= "/* Eleonline - Raccolta e diffusione dei dati elettorali */\n";
249$config_adm .= "/* by Roberto Gigli & Luciano Apolito */\n";
250$config_adm .= "/* http://www.eleonline.it */\n";
251$config_adm .= "/* info@eleonline.it luciano@aniene.net rgigli@libero.it */\n";
252$config_adm .= "/************************************************************************/\n";
253$config_adm .= "\n";
254$config_adm .= "\n";
255$config_adm .= "if (stristr(\"config.php\",\$_SERVER['PHP_SELF'])) {\n";
256$config_adm .= " Header(\"Location: index.php\");\n";
257$config_adm .= " die();\n";
258$config_adm .= "}\n";
259$config_adm .= "\n";
260$config_adm .= "\n";
261$config_adm .= "\n";
262$config_adm .= "\$dbhost = \"{$configArray['DBhostname']}\";\n";
263$config_adm .= "\$dbuname = \"{$configArray['DBuserName']}\";\n";
264$config_adm .= "\$dbpass = \"{$configArray['DBpassword']}\";\n";
265$config_adm .= "\$dbname = \"{$configArray['DBname']}\";\n";
266$config_adm .= "\$prefix = \"{$configArray['DBPrefix']}\";\n";
267$config_adm .= "\$dbtype = \"MySQL\";\n";
268$config_adm .= "ini_set('display_errors',0);\n";
269$config_adm .= "?>\n";
270
271
272
273
274
275
276
277
278
279
280
281 if ($canWrite && ($fp = fopen("../client/config.php", "w"))) {
282 fputs( $fp, $config, strlen( $config ) );
283 fclose( $fp );
284 } else {
285 $canWrite = false;
286 }
287
288 if ($canWrite2 && ($fp = fopen("../admin/config.php", "w"))) {
289 fputs( $fp, $config_adm, strlen( $config_adm ) );
290 fclose( $fp );
291 } else {
292 $canWrite2 = false;
293 }
294
295
296
297 $database = new PDO("mysql:host=$DBhostname;charset=latin1", $DBuserName, $DBpassword, array(PDO::ATTR_EMULATE_PREPARES => false,
298 PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
299 $sql = "use $DBname";
300 $database->exec($sql);
301
302 // create the admin user
303 $cryptpass = md5( $adminPassword );
304 //$query = "INSERT INTO {$configArray['DBPrefix']}_authors VALUES ('$adminName', '$adminName', '0', '$adminEmail', '$cryptpass','1','0','0','1','it')";
305 $query = "UPDATE {$configArray['DBPrefix']}_authors SET aid='$adminName', name='$adminName', email='$adminEmail', pwd= '$cryptpass' WHERE aid='suser'";
306 $database->exec( $query );
307
308 // create Comune
309 try{
310 $query = "INSERT INTO {$configArray['DBPrefix']}_ele_comuni VALUES ('$istat', '$nomecomune', '','','','','$Limite','$Capoluogo','','','0','')";
311 $database->exec( $query );
312 } catch(PDOException $e) { die("L'inserimento del comune Ú fallito, può essere aggiunto dal menu Comuni in Admin: $query");}
313 $query = "UPDATE {$configArray['DBPrefix']}_config SET sitename='$sitename', siteurl='$siteUrl', adminmail='$adminEmail', tema='$tema', foot='',language='$Lingua',blocco='$blocco',fileout='$Replica',Versione='3', siteistat='$istat',multicomune='$Multicomune',flash='$flash', tema_on='$sceltatema' WHERE sitename=''";
314
315 $database->exec( $query );
316
317
318 // touch config table
319 $date = date("F Y");
320 $query = "UPDATE {$configArray['DBPrefix']}_config SET sitename='$sitename', siteurl='$siteUrl', startdate='$date', adminmail='$adminEmail'";
321 $database->exec( $query );
322
323} else {
324?>
325 <form action="install3.php" method="post" name="stepBack3" id="stepBack3">
326 <input type="hidden" name="DBhostname" value="<?php echo $DBhostname;?>" />
327 <input type="hidden" name="DBusername" value="<?php echo $DBuserName;?>" />
328 <input type="hidden" name="DBpassword" value="<?php echo $DBpassword;?>" />
329 <input type="hidden" name="DBname" value="<?php echo $DBname;?>" />
330 <input type="hidden" name="DBcreated" value="1" />
331 <input type="hidden" name="sitename" value="<?php echo $sitename;?>" />
332 <input type="hidden" name="adminName" value="$adminName" />
333 <input type="hidden" name="adminEmail" value="$adminEmail" />
334 <input type="hidden" name="CreateUSer" value="$CreateUSer" />
335 <input type="hidden" name="siteUrl" value="$siteUrl" />
336 <input type="hidden" name="absolutePath" value="$absolutePath" />
337 <?php
338 echo '<input type="hidden" name="nomecomune" value="<?php echo "$nomecomune"; ?>" />
339 <input type="hidden" name="istat" value="<?php echo "$istat"; ?>" />
340 <input type="hidden" name="Capoluogo" value="<?php echo "$Capoluogo"; ?>" />
341 <input type="hidden" name="Lingua" value="<?php echo "$Lingua"; ?>" />
342 <input type="hidden" name="Multicomune" value="<?php echo "$Multicomune"; ?>" />
343 <input type="hidden" name="Replica" value="<?php echo "$Replica"; ?>" />
344
345 <input type="hidden" name="tema" value="<?php echo "$tema"; ?>" />
346 <input type="hidden" name="sceltatema" value="<?php echo "$sceltatema"; ?>" />
347 <input type="hidden" name="blocco" value="<?php echo "$blocco"; ?>" />
348 <input type="hidden" name="flash" value="<?php echo "$flash"; ?>" />
349
350 <input type="hidden" name="Limite" value="<?php echo "$Linite"; ?>" />
351 ';
352 ?>
353 </form>
354 <script>alert('The site url has not been provided'); document.stepBack3.submit();</script>
355<?php
356}
357include("header.php");
358?>
359<div id="ctr" align="center">
360 <form action="dummy" name="form" id="form">
361 <div class="install">
362 <div id="stepbar">
363 <div class="step-off">inizio</div>
364 <div class="step-off">licenza</div>
365 <div class="step-off">passo 1</div>
366 <div class="step-off">passo 2</div>
367 <div class="step-off">passo 3</div>
368 <div class="step-on">passo 4</div>
369 </div>
370 <div id="right">
371 <div id="step">passo 4</div>
372 <div class="far-right">
373 <input class="button" type="button" name="runSite" value="Guarda il Sito"
374<?php
375 if ($siteUrl) {
376 echo "onClick=\"window.location.href='$siteUrl/index.php' \"";
377 } else {
378 echo "onClick=\"window.location.href='".$configArray['siteURL']."/index.php' \"";
379 }
380?>/>
381 <input class="button" type="button" name="Admin" value="Amministrazione"
382<?php
383 if ($siteUrl) {
384 echo "onClick=\"window.location.href='$siteUrl/../admin' \"";
385 } else {
386 echo "onClick=\"window.location.href='".$configArray['siteURL']."/../admin' \"";
387 }
388?>/>
389 </div>
390 <div class="clr"></div>
391 <h1>Congratulazioni! EleOnLine e' installato</h1>
392 <div class="install-text">
393 <p>Clicca sul pulsante "Guarda il Sito" per visitare la parte in Visualizzazione oppure su "Amministrazione" per entrare nel pannello di ammnistrazione.</p>
394 </div>
395 <div class="install-form">
396 <div class="form-block">
397 <table width="100%">
398 <tr><td class="error" align="center">Una volta configurato e testato il sistema<br/>
399e prima di avviare il servizio online<br/>
400ricordati di effettuare una politica di sicurezza<br/>
401come la separazione della parte di visualizzazione (client)<br/>
402da quella di amministrazione (admin)<br/>
403od anche l'utenza del database pubblico in sola lettura<br/>
404e altri accorgimenti che riterrai necessari<br/>
405
406
407
408</td></tr>
409 <tr><td align="center"><h5>Dettagli Login Amministrazione</h5></td></tr>
410 <tr><td align="center" class="notice"><b>Username : <?php echo $adminName; ?></b></td></tr>
411 <tr><td align="center" class="notice"><b>Password : <?php echo $adminPassword; ?></b></td></tr>
412 <tr><td>&nbsp;</td></tr>
413 <tr><td align="right">&nbsp;</td></tr>
414<!-- client -->
415<?php if (!$canWrite) { ?>
416 <tr>
417 <td class="small">
418 <h1>config.php per visualizzazione</h1>
419 <font color="#FF0000"><b>ATTENZIONE:</b></font> Il tuo file di configurazione o la cartella non sono scrivibili,
420 o c'Ú stato un problema nella creazione del file di configurazione. Clicca nella area di testo per evidenziare
421 tutto il codice. Crea un nuovo file chiamato <b>config.php</b> e copialo nella cartella <b>client</b>.
422 </td>
423 </tr>
424
425
426 <tr>
427 <td align="center">
428 <textarea rows="15" cols="48" name="configcode" onClick="javascript:this.form.configcode.focus();this.form.configcode.select();" ><?php echo htmlspecialchars( $config );?></textarea>
429 </td>
430 </tr>
431<?php } ?>
432
433<!-- admin -->
434<?php if (!$canWrite2) { ?>
435 <tr>
436 <td class="small">
437 <h1>config.php per amministrazione</h1>
438 <font color="#FF0000"><b>ATTENZIONE:</b></font> Il tuo file di configurazione o la cartella non sono scrivibili,
439 o c'Ú stato un problema nella creazione del file di configurazione. Clicca nella area di testo per evidenziare
440 tutto il codice. Crea un nuovo file chiamato <strong>config.php</strong> e copialo nella cartella <b>admin</b>.
441 </td>
442 </tr>
443
444
445 <tr>
446 <td align="center">
447 <textarea rows="15" cols="48" name="configcode" onClick="javascript:this.form.configcode.focus();this.form.configcode.select();" ><?php echo htmlspecialchars( $config_adm );?></textarea>
448 </td>
449 </tr>
450<?php } ?>
451
452
453
454
455 <tr><td class="small"><?php /*echo $chmod_report*/; ?></td></tr>
456 </table>
457 </div>
458 </div>
459 <div id="break"></div>
460 </div>
461 <div class="clr"></div>
462 </div>
463 </form>
464</div>
465<div class="clr"></div>
466<div class="ctr">
467
468</div>
469<?php include("footer.php"); ?>
470</div>
471</html>
Note: See TracBrowser for help on using the repository browser.