<?php
$set['script'] = $_SERVER['PHP_SELF'];
$set['Title'] = "I miei film";
$set['FirstField'] = "onload='document.filmForm.movie_title.focus()'";
$message = "";
if (empty($_POST))
{
echo "lo script é chiamato per un nuovo inserimento<br />";
inizializzaVariabili();
}
else
{
echo "lo script é chiamato dopo un submit<br />";
leggiPost();
validaForm();
if ( empty($message) ) aggiornaDB();
}
displayForm();
die;
function inizializzaVariabili()
{
global $row;
$row['movie_title'] = "";
$row['also_known'] = "";
$row['year'] = "";
$row['minutes'] = "";
$row['distributor'] = "";
$row['studio'] = "";
$row['release_data'] = "";
$row['incollection'] = "";
$row['synopsis'] = "";
}
function leggiPost()
{
global $row;
$row['movie_title'] = addslashes($_POST['movie_title']);
$row['also_known'] = "also_known"; //addslashes($_POST['also_known']);
$row['year'] = "year"; //addslashes($_POST['year']);
$row['minutes'] = "minutes"; //addslashes($_POST['minutes']);
$row['distributor'] = "distributor"; //addslashes($_POST['distributor']);
$row['studio'] = "studio"; //addslashes($_POST['studio']);
$row['release_data'] = "release_data"; //addslashes($_POST['release_data']);
$row['incollection'] = "incollection"; //addslashes($_POST['incollection']);
$row['synopsis'] = "synopsis"; //addslashes($_POST['synopsis']);
}
function validaForm()
{
global $row, $message;
// qui vanno fatti i controlli dei dati inseriti
}
function aggiornaDB()
{
global $row, $message;
// qui si aggiorna il db,
// 1) apre la connessione
// 2) inserisce il nuovo film
// 3) verifica che sia stato inserito il film
// 4) chiude la connessione
$sql = "INSERT INTO film(movie_title, also_known, year, minutes, distributor, studio, release_data, incollection, synopsis) VALUES ("
. " '" . $row['movie_title'] . "'"
. ", '" . $row['also_known'] . "'"
. ", '" . $row['year'] . "'"
. ", '" . $row['minutes'] . "'"
. ", '" . $row['distributor'] . "'"
. ", '" . $row['studio'] . "'"
. ", '" . $row['release_data'] . "'"
. ", '" . $row['incollection'] . "'"
. ", '" . $row['synopsis'] . "'"
. " )";
echo $sql . "<br />";
$query = 1; //$query = mysql_query( $sql );
if( $query )
{
inizializzaVariabili();
$message = "Congratulazioni! Dati inseriti.";
}
else
{
$message = "Attenzione : Dati non inseriti!";
}
}
function displayForm()
{
global $row, $set, $message;
echo
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title> <?php echo $set['Title'] ?></title>
</head>
<body <?php echo $set['FirstField'] ?>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $message; ?>
</div>
</div>
<div id="BioData" style="overflow: hidden;">
<center><h1> <span class="infoblock-pagetype">inserisci dati</span></h1></center>
<form action="0inserisci_film.php" method="post">
<table id="biographyTable" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td class="paramname">
<b>Title:</b>
</td>
<td class="paramvalue">
<input name="movie_title" type="text" size="100" id="movie_title" >
</td>
</tr>
<tr>
<td class="paramname">
<b>Also Known As:</b>
</td>
<td class="paramvalue">
<textarea name="also_known" id="also_known" size="50" style="width: 98%"></textarea>
</td>
</tr>
<tr>
<td class="paramname">
<b>Year: </b>
</td>
<td class="paramvalue">
<input name="year" type="text" size="10" id="year">
</td>
</tr>
<tr>
<tr>
<td class="paramname">
<b>Minutes: </b>
</td>
<td class="paramvalue">
<input name="minutes" type="text" size="10" id="minutes">
</td>
</tr>
<tr>
<td class="paramname">
<b>Distributor: </b>
</td>
<td class="paramvalue">
<input name="distributor" type="text" size="100" id="distributor">
</td>
</tr>
<tr>
<td class="paramname">
<b>Studio: </b>
</td>
<td class="paramvalue">
<input name="studio" type="text" size="100" id="studio" >
</td>
</tr>
<tr>
<td class="paramname">
<b>Release Date: </b>
</td>
<td class="paramvalue">
<input name="release_data" type="text" size="15" id="release_data">
</td>
</tr>
<tr>
<td class="paramname">
<b>In Collection: </b> (<b><font color="red">selezionare il valore</font></b>)
</td>
<td class="paramvalue">
<select name='incollection'>
<option selected value="<?php echo $incollection; ?>"><?php /* fix 2019.09.21 */ echo $incollection; ?>
<?php
/* possible options for career status */
$incollection=array(
0=>'',
1=>'Yes',
2=>'No'
);
for( $i=0; $i < count( $incollection ); $i++ ){
/* is this item selected? */
$selected = $i==$incollection ? ' selected' : '';
printf('
<option value="%d"%s>%s',
$i,
$selected,
$incollection[ $i ]
);
}
?>
</option>
</select>
</td>
</tr>
<!-- TESTO DEL COMMENTO<tr>
<td class="paramname">
<b>Status:</b> (<b><font color="red">Active, Retired, Dead</font></b>)
</td>
<td class="paramvalue">
<input name="status" type="text" id="status" value="<?php// echo $status;?>">
</td>
</tr>
<tr> -->
<tr>
<td class="paramname">
<b>Synopsis: </b>
</td>
<td class="paramvalue">
<textarea cols="80" name="synopsis" id="editor1" rows="10" ></textarea>
</td>
</tr>
<!-- ckeditor(se ne metti piu di uno cambia textarea type="text" id="xxxxxxx" e replace('xxxxxxx', ) -->
<script src="ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor1', {
extraPlugins: 'colorbutton,colordialog'
});
</script>
<!-- ckeditor(se ne metti piu di uno cambia textarea type="text" id="xxxxxxx" e replace('xxxxxxx', ) -->
<tr>
<td class="paramvalue-footer center" colspan="2">
<br />
<input name="inserisci" type="submit" id="inserisci" value="inserisci">
<br />
<br />
</td>
</tr>
</tbody>
</table>
</form>
<div class='col-sm-10 col-sm-offset-2'><h2><?php echo $message; ?></h2></div>
</div>
</body>
</html>