<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">";
/*
This file is part of PHPOLL.
PHPOLL is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PHPOLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PHPOLL; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" language="JavaScript">
</script>
<title>PHPOLL - creazione database</title>
<link rel="stylesheet" href="css/homepage_layout.css" title="homepage layout" />
</head>
<body>
<div class="corpo">
<img src="main_img/phpoll_poll.gif" alt="img of the Poll" />
<img src="main_img/phpoll_char.gif" alt="phpoll" />
<div class="menu">
<a href="index.php">home</a>
<a href="connetti_db.php">connetti al database</a>
<a href="info.php">info</a>
</div>
<div class="corpo">
<p class="titolo">
PHPOLL v. 0.9 beta
</p>
<p class="sotto_titolo">
scritto in PHP da Massimo Perini
</p>
<p class="note">necessita di MySql</p>
<p class="note">per lodi, consigli e critiche: <a href="mailto:hide@address.com">hide@address.com</a></p>
<?php
// CREAZIONE DATABASE ***********
$query_tabella_configurazione = "CREATE TABLE IF NOT EXISTS `phpoll_".$_POST['prepoll']."_configurazione` ("
. " `id` int(10) unsigned NOT NULL auto_increment,"
. " `max_voti` int(10) unsigned NOT NULL,"
. " `titolo_posizione` varchar(100) NOT NULL,"
. " `titolo_tipologia` varchar(100) NOT NULL,"
. " `titolo_punteggio` varchar(100) NOT NULL,"
. " `login` varchar(100) NOT NULL,"
. " `password` varchar(100) NOT NULL,"
. " `risultati_pixel` int(10) unsigned NOT NULL,"
. " `intervallo_tempo` int(10) unsigned NOT NULL,"
. " `barra1r` int(10) unsigned NOT NULL,"
. " `barra1g` int(10) unsigned NOT NULL,"
. " `barra1b` int(10) unsigned NOT NULL,"
. " `barra2r` int(10) unsigned NOT NULL,"
. " `barra2g` int(10) unsigned NOT NULL,"
. " `barra2b` int(10) unsigned NOT NULL,"
. " `barra3r` int(10) unsigned NOT NULL,"
. " `barra3g` int(10) unsigned NOT NULL,"
. " `barra3b` int(10) unsigned NOT NULL,"
. " `barra4r` int(10) unsigned NOT NULL,"
. " `barra4g` int(10) unsigned NOT NULL,"
. " `barra4b` int(10) unsigned NOT NULL,"
. " `percorso_link` varchar(100) NOT NULL,"
. " `domini` text NOT NULL,"
. " `messaggio_domini` text NOT NULL,"
. " `messaggio_giavotato` text NOT NULL,"
. " `messaggio_sgamo` text NOT NULL,"
. " `messaggio_ip` text NOT NULL,"
. " `oggetto_email` text NOT NULL,"
. " `messaggio_conferma_mail` text NOT NULL,"
. " `testo_email` text NOT NULL,"
. " `valid_email` text NOT NULL,"
. " `testo_submit` text NOT NULL,"
. " PRIMARY KEY (`id`)"
. " ) ENGINE = MyISAM;";
$query_tabella_band = "CREATE TABLE IF NOT EXISTS `phpoll_".$_POST['prepoll']."_band` (`id` int(10) unsigned NOT NULL auto_increment, ".
"`nome_band` text NOT NULL, `voti` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`)) ENGINE = MyISAM; ";
$query_tabella_voti = "CREATE TABLE IF NOT EXISTS `phpoll_".$_POST['prepoll']."_voti` (`id` int(10) unsigned NOT NULL auto_increment, ".
"`ip` varchar(45) NOT NULL default '', `band_votate` text NOT NULL, `timestamp` int(11) NOT NULL default '0', `votato` varchar(100) NOT NULL, `email` varchar(100) NOT NULL,".
"`browser` varchar(100) NOT NULL default '', PRIMARY KEY (`id`)) ENGINE = MyISAM;";
$phpoll_host = $_POST['host'];
$phpoll_user = $_POST['user'];
$phpoll_password = $_POST['password'];
$phpoll_database = $_POST['database'];
$query_inserisci_config = "INSERT INTO `phpoll_".$_POST['prepoll']."_configurazione` ( `id` , `testo_submit` , `max_voti` , `titolo_posizione` , `titolo_tipologia` , `titolo_punteggio` , `risultati_pixel`, `login`, `password` ) ".
"VALUES ('', 'SUBMIT', '5', 'position', 'candidate', 'score', '200', 'admin', 'admin');";
// COPIA I FILE NECESSARI PER PHPOLL ***
// FUNZIONE PER COPIARE LA DIRECTORY
function copydir ($source, $dest) {
if (is_file($source)) {
return copy($source, $dest);
}
if (!is_dir($dest)) {
mkdir($dest);
}
$dir = dir($source);
while (false !== $entry = $dir->read()) {
if ($entry == '.' || $entry == '..') {
continue;
}
if ($dest !== "$source/$entry") {
copydir("$source/$entry", "$dest/$entry");
}
}
$dir->close();
return true;
}
// *********************************
$directory_phpoll = "phpoll_files/";
$directory_new_poll = "polls/".$_POST['prepoll']."/";
$permessi_ok = is_writable ("polls/");
if ($permessi_ok) {
copydir ($directory_phpoll, $directory_new_poll);
print "<p>file di phpoll copiati!</p>";
// CREA FILE config_db.php ******
$file_pointer = fopen ("polls/".$_POST['prepoll']."/config/config_db.php", "w");
fwrite ($file_pointer, "<?php\n");
fwrite ($file_pointer, "\$phpoll_host = \"".$_POST['host']."\";\n");
fwrite ($file_pointer, "\$phpoll_user = \"".$_POST['user']."\";\n");
fwrite ($file_pointer, "\$phpoll_password = \"".$_POST['password']."\";\n");
fwrite ($file_pointer, "\$phpoll_database = \"".$_POST['database']."\";\n");
fwrite ($file_pointer, "\$prepoll = \"".$_POST['prepoll']."\";\n");
fwrite ($file_pointer, "?>");
fclose ($file_pointer);
print "<p>file config_db.php creato!</p>";
// ******************************
// assegno le variabili di connessione
$phpoll_db = mysql_connect ($phpoll_host, $phpoll_user, $phpoll_password)
or die ("Errore nella connessione a MySQL");
// selezione del database
if (mysql_select_db($phpoll_database, $phpoll_db)) {
print "<p>database selezionato</p>";
}
else {
print "<p>Errore nella selezione del database</p>";
print "<a href=\"index.php\">torna al menu</a>";
die ("");
}
// creazione tabella di configurazione
$crea_tabella_configurazione = mysql_query ($query_tabella_configurazione, $phpoll_db);
if ($crea_tabella_configurazione) {
print "<p>tabella configurazione creata</p>";
}
else {
print "<p>Errore durante la creazione della tabella di configurazione</p>";
print "<a href=\"index.php\">torna al menu</a>";
die ("");
}
// inserimento dati default in configurazione
$inserisci_config = mysql_query($query_inserisci_config, $phpoll_db);
if ($inserisci_config) {
print "<p>inserimento dati default nella tabella configurazione effettuato</p>";
}
else {
print "<p>Errore durante inserimento dati default nella tabella configurazione</p>";
print "<a href=\"index.php\">torna al menu</a>";
die ("");
}
// creazione tabella candidati (band)
$crea_tabella_band = mysql_query ($query_tabella_band, $phpoll_db);
if ($crea_tabella_band) {
print "<p>tabella candidati (band) creata</p>";
}
else {
print "<p>Errore durante la creazione tabella candidati (band)</p>";
print "<a href=\"index.php\">torna al menu</a>";
die ("");
}
// creazione tabella voti
$crea_tabella_voti = mysql_query ($query_tabella_voti, $phpoll_db);
if ($crea_tabella_voti) {
print "<p>tabella voti creata</p>";
}
else {
print "<p>Errore durante la creazione tabella voti</p>";
print "<a href=\"index.php\">torna al menu</a>";
die ("");
}
mysql_close ($phpoll_db);
// ******************************
print "<br />";
print "<a href=\"polls/".$_POST['prepoll']."/admin/index.php\">vai all'amministrazione</a>";
}
else {
print "<p class=\"errore\">la cartella polls/ non รจ scrivibile</p>";
print "<p class=\"errore\">per favore impostare i permessi di scrittura</p>";
print "<a href=\"index.php\">torna al menu</a>";
}
?>
</div>
</div>
</body>
</html>