Codice PHP:
<?php require_once("../Connections/cmswiz.php"); ?>
<?php require_once("common.php"); ?>
<?php require_once("rss.php"); ?>
<?php
getConn();
// in realtà questo file processa sia l'insert che il modify, ma è stata
// una decisione presa dopo e non avevo
// voglia di rinominarlo
// TODO: cancellare l'eventuale file ruscato
// TODO: verificare magic quotes
// TODO: gestione categorie
// -----------------------------------------
// insert or modify?
$myError = '';
$mydoing = $_POST['mydoing'];// values: insert, modify
if($mydoing == 'modify')
{
$idr = $_POST['idr'];
}
$fileok = true;
// determiniamo il folder per l'upload:
$tipo_th = $_GET['id'];
switch($tipo_th)
{
case '1':
$myfolder = 'notizie';
break;
case '2':
$myfolder = 'corsi';
break;
case '3':
$myfolder = 'comunicati';
break;
case '4':
$myfolder = 'cospeflash';
break;
case 5:
$myfolder = 'cospenews';
break;
case '6':
$myfolder = 'documenti';
break;
default:
echo 'an error has occurred';
break;
}
$queryz = '';
/* ----------------------- */
$status_th = isset($_GET['status']) ? $_GET['status'] : 0;
$categoria_th = isset($_POST['categoria_th']) ? $_POST['categoria_th'] : '';
$titolo_th = isset($_POST['titolo_th']) ? str_replace("'", "''", $_POST['titolo_th']) : '';
$sottotitolo_th = isset($_POST['sottotitolo_th']) ? str_replace("'", "''", $_POST['sottotitolo_th']) : '';
$edizione_th = isset($_POST['edizione_th']) ? str_replace("'", "''", $_POST['edizione_th']) : '';
$home_th = (isset($_POST['home_th']) And ($_POST['home_th'] == false))? 0 : 1;
$testoBreve_th = isset($_POST['testoBreve_th']) ? str_replace("'", "''", $_POST['testoBreve_th']) : '';
$testoLungo_th = isset($_POST['testoLungo_th']) ? str_replace("'", "''", $_POST['testoLungo_th']) : '';
if (isset($_POST['ordine_th']))
{
$ordine_th = $_POST['ordine_th'];
if (!is_numeric($ordine_th))
$ordine_th = 0;
}
else
{
$ordine_th = 0;
// Faccio scorrere in giù tutti gli altri elementi
$q = "UPDATE varie SET ordine_th = ordine_th + 1 WHERE tipo_th = $tipo_th AND status_th = $status_th";
mysql_query($q)or die(mysql_error());
}
$dataScadenzaNew_th = (isset($_POST['dataScadenzaNew_th']) && (strlen($_POST['dataScadenzaNew_th']) > 0)) ? "'" . GiraData($_POST['dataScadenzaNew_th']) . "'": "NULL";
$dataScadenza_th = (isset($_POST['dataScadenza_th']) && (strlen($_POST['dataScadenza_th']) > 0)) ? "'" . GiraData($_POST['dataScadenza_th']) . "'": "NULL";
/* ----------------------- */
switch($tipo_th)
{
case '1':
// ***notizie***
// edizione_th
// ordine_th
// testoLungo_th
if($mydoing == 'insert'){
$queryz = "insert into varie (testoLungo_th, tipo_th, titolo_th, edizione_th, ordine_th, dataScadenzaNew_th, dataScadenza_th) values ('$testoLungo_th', $tipo_th, '$titolo_th','$edizione_th',$ordine_th, $dataScadenzaNew_th, $dataScadenza_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, titolo_th = '$titolo_th', edizione_th = '$edizione_th', testoLungo_th = '$testoLungo_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
case '2':
echo "insert corsi";
// ***corsi***
// categoria_th
// titolo_th
//testoBreve_th
// testoLungo_th
// ordine_th
// home_th
if($mydoing == 'insert'){
$queryz = "insert into varie (tipo_th, categoria_th, titolo_th, testoBreve_th, testoLungo_th, ordine_th, dataScadenzaNew_th, dataScadenza_th, home_th) values ($tipo_th, $categoria_th, '$titolo_th', '$testoBreve_th', '$testoLungo_th', $ordine_th, $dataScadenzaNew_th, $dataScadenza_th, $home_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, categoria_th = $categoria_th, titolo_th = '$titolo_th', testoBreve_th = '$testoBreve_th', testoLungo_th = '$testoLungo_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, home_th=$home_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
case '3':
// comunicatistampa
// titolo_th
// testoLungo_th
// edizione_th
// ordine_th
if($mydoing == 'insert'){
$queryz = "insert into varie (tipo_th, titolo_th, testoLungo_th, edizione_th, ordine_th, dataScadenzaNew_th, dataScadenza_th) values ($tipo_th, '$titolo_th', '$testoLungo_th', '$edizione_th', $ordine_th, $dataScadenzaNew_th, $dataScadenza_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, titolo_th = '$titolo_th', edizione_th = '$edizione_th', testoLungo_th = '$testoLungo_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
case '4':
// cospeflash
// titolo_th
// edizione_th
// ordine_th
if($mydoing == 'insert'){
$queryz = "insert into varie (tipo_th, titolo_th, edizione_th, ordine_th, dataScadenzaNew_th, dataScadenza_th) values ($tipo_th, '$titolo_th', '$edizione_th', $ordine_th, $dataScadenzaNew_th, $dataScadenza_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, titolo_th = '$titolo_th', edizione_th = '$edizione_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
case 5:
// cospenews
// titolo_th
// edizione_th
// testoLungo_th
// ordine_th
if($mydoing == 'insert'){
$queryz = "insert into varie (tipo_th, titolo_th, edizione_th, testoLungo_th, ordine_th, dataScadenzaNew_th, dataScadenza_th) values ($tipo_th, '$titolo_th', '$edizione_th', '$testoLungo_th', $ordine_th, $dataScadenzaNew_th, $dataScadenza_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, titolo_th = '$titolo_th', edizione_th = '$edizione_th', testoLungo_th = '$testoLungo_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
case '6':
// documenti
// categoria_th
// titolo_th
// sottotitolo_th
// edizione_th
// testoLungo_th
// ordine_th
if($mydoing == 'insert'){
$queryz = "insert into varie (tipo_th, categoria_th, titolo_th, sottotitolo_th, edizione_th, testoLungo_th, ordine_th, dataScadenzaNew_th, dataScadenza_th) values ($tipo_th, '$categoria_th', '$titolo_th', '$sottotitolo_th', '$edizione_th', '$testoLungo_th', $ordine_th, $dataScadenzaNew_th, $dataScadenza_th)";
} else {
$queryz = "update varie set tipo_th = $tipo_th, categoria_th = $categoria_th, titolo_th = '$titolo_th', sottotitolo_th = '$sottotitolo_th', edizione_th = '$edizione_th', testoLungo_th = '$testoLungo_th', ordine_th = $ordine_th, dataScadenzaNew_th = $dataScadenzaNew_th, dataScadenza_th = $dataScadenza_th, dataIns_th = now() WHERE id_th = $idr";
}
break;
default:
$myError+='C\'è qualcosa che non va...
';
break;
}
//echo $queryz;
// ouf! eseguiamo la query
mysql_query($queryz)or die(mysql_error());
// Devo aggiornare l'RSS ?
if (($tipo_th == '1') And ($mydoing != 'insert'))
{
// Sto cambiando una notizia visibile ?
$q = "SELECT status_th FROM varie WHERE id_th = $idr";
$rs = mysql_query($q);
$row_rs = mysql_fetch_assoc($rs);
$Visibile = ($row_rs["status_th"] == 1) ? true : false;
mysql_free_result($rs);
if ($Visibile)
{
UpdateRSSNews();
}
}
if($myError=='')
{
// è andato tutto bene
// header("Location: list.php?id=$tipo_th&status=$status_th");
print '<script>window.location="list.php?id='.$tipo_th.'&status='.$status_th.'"</script>';
}
else
{
echo "Errore: " . $myError;
}
?>