IL FORM:
Codice PHP:
if (!defined('WEB_ROOT'))
{ exit; }
$catId = (isset($_GET['catId']) && $_GET['catId'] > 0) ? $_GET['catId'] : 0;
$categoryList = buildCategoryOptions($catId); ?>
<h2>Aggiungi nuovo Servizio</h2>
<form action="processProduct.php?action=addProduct" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
<table class="tabella">
<tr>
<td width="150" class="label">Nome Servizio</td>
<td class="content">
<input name="txtName" type="text" class="box" id="txtName" size="50" /></td>
</tr> <tr>
<td width="150" class="label">Sottotitolo</td>
<td class="content">
<input name="sottotitolo" type="text" class="box" id="txtName" size="50" /></td>
</tr> <tr>
<td width="150" class="label">Comune di appartenenza</td>
<td class="content"> <select name="comune[]" id="sel0" multiple="multiple">
<option value="" selected disabled>-- Scegli un Comune --</option>
<?php $query = "SELECT id_comune, nome_comune FROM tbl_comuni ORDER BY nome_comune ASC";
$result = dbQuery($query) or die('Impossibile trovare i comuni. ' . mysql_error());
while($row = dbFetchArray($result))
{ list($id_comune, $nome_comune) = $row; ?>
<option value="<?php echo $id_comune ?>">
<?php echo $nome_comune ?></option>
<?php } ?>
</select>
<input type="button" id="nada0" value="cancella tutti"/>
<input type="button" id="todos0" value="seleziona tutti"/> </td>
</tr>
<tr>
<td width="150" class="label">Sede</td>
<td class="content"> <input name="sede" type="text" class="box" id="txtName" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Indirizzo</td>
<td class="content">
<input name="indirizzo" type="text" class="box" id="indirizzo" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Telefono</td>
<td class="content">
<input name="telefono" type="text" class="box" id="telefono" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Fax</td>
<td class="content">
<input name="fax" type="text" class="box" id="fax" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Email</td>
<td class="content">
<?php // Include CKEditor class. include("ckeditor/ckeditor.php");
//QUI C'è IL CODICE PER L'EDITOR CKEDITOR //
Create second instance. echo $CKEditor->editor("email", $initialValue, $config); ?>
</td>
</tr>
<tr>
<td width="150" class="label">Sito Web</td>
<td class="content">
<?php //QUI C'è IL CODICE PER L'EDITOR CKEDITOR
// Create second instance. echo $CKEditor->editor("web", $initialValue, $config); ?>
</td>
</tr>
<tr>
<td width="150" class="label">Nome email referente</td>
<td class="content">
<input name="referente" type="text" class="box" id="referente" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Orario di ricevimento</td>
<td class="content">
<input name="orario" type="text" class="box" id="orario" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Territorio di competenza</td>
<td class="content">
<input name="competenza" type="text" class="box" id="competenza" size="50" /></td> </tr>
<tr>
<td width="150" class="label">Criteri di Accesso</td>
<td class="content">
<input name="criteri" type="text" class="box" id="criteri" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Mappa</td>
<td class="content">
<input name="mappa" class="box" id="mappa" size="50" /></td>
</tr>
<tr>
<td width="150" class="label">Immagine</td>
<td class="content"> <input name="fleImage" type="file" id="fleImage" class="box" size="50" /> </td>
</tr>
<tr>
<td width="150" class="label">Tipo di servizio</td>
<td class="content">
<select name="ambito[]" id="sel2" multiple="multiple">
<option value="" selected disabled>-- Scegli un tipo --</option>
<?php $query = "SELECT * FROM tbl_ambiti ORDER BY nome_ambito ASC"; $result = dbQuery($query) or die('Impossibile trovare il servizio. ' . mysql_error());
while($row = dbFetchArray($result))
{
list($id_ambito, $nome_ambito) = $row; ?>
<option value="<?php echo $id_ambito ?>">
<?php echo $nome_ambito ?></option>
<?php } ?> </select>
<input type="button" id="nada2" value="cancella tutti"/>
<input type="button" id="todos2" value="seleziona tutti"/> </td>
</tr>
<tr>
<td width="150" class="label">Note
(elenco dei servizi offerti + varie ed eventuali)</td> <td class="content">
<?php //QUI C'è IL CODICE PER L'EDITOR CKEDITOR
// Create second instance. echo $CKEditor->editor("note", $initialValue, $config); ?> </td> </tr>
<tr>
<td width="150" class="label">Data aggiornamento</td>
<td class="content">
<input name="data" type="text" class="box" id="mappa" size="50" /></td>
</tr>
</table>
<p align="center">
<input name="btnAddProduct" type="button" id="btnAddProduct" value="Aggiungi Servizio" onClick="checkAddProductForm();" class="box">
<input name="btnCancel" type="button" id="btnCancel" value="Cancella" onClick="checkAdd();" class="box"> </p> </form>
IL CODICE PER L'INSERIMENTO:
Codice PHP:
function addProduct() {
$name = mysql_real_escape_string($_POST['txtName']);
$sottotitolo = $_POST['sottotitolo'];
$sede = $_POST['sede'];
$indirizzo = $_POST['indirizzo'];
$telefono = $_POST['telefono'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$web = $_POST['web'];
$referente = $_POST['referente'];
$orario = $_POST['orario'];
$competenza = $_POST['competenza'];
$criteri = $_POST['criteri'];
$mappa = $_POST['mappa'];
$note = $_POST['note'];
$data = $_POST['data'];
$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');
$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];
$sql = "INSERT INTO tbl_servizi (nome_servizio, sottotitolo, sede, indirizzo, telefono, fax, email, web, referente, orario, competenza, criteri_accesso, mappa, note, immagine, thumb, data_ins) VALUES ('$name', '$sottotitolo', '$sede', '$indirizzo', '$telefono', '$fax', '$email', '$web', '$referente', '$orario', '$competenza', '$criteri', '$mappa', '$note', '$mainImage', '$thumbnail', '$data')";
$result = dbQuery($sql);
$last_id = mysql_insert_id();
if (isset($_POST['comune']) && isset($_POST['ambito']))
{ $comuni = $_POST['comune']; $ambiti = $_POST['ambito'];
foreach($comuni as $com)
{ dbQuery("INSERT INTO tbl_servizi_comuni (id_servizio,id_comune) VALUES ($last_id,$com)"); }
foreach($ambiti as $amb) {
dbQuery("INSERT INTO tbl_servizi_ambiti (id_servizio,id_ambito) VALUES ($last_id,$amb)"); }
header("Location: index.php");
}
}