0){
if(($small_foto_size > 1000) &&( $small_foto_size < $max_upload_file_size)){
$file_dir= dirname($PATH_TRANSLATED);
$small_foto_name=strtolower($foto_id).".jpg";
copy($small_foto,"$file_dir/$img_dir/$small_foto_name");
$sql_foto=", foto='Y'";
}else{
$upload_err_msg.=$foto_id ."_small: caricare un file minore di $max_upload_file_size byte, maggiore di 1000 byte\n
";
}
}else{
$upload_err_msg.=$foto_id ."_small: caricare un file .jpg\n
";
return $upload_err_msg;
}
}
}
return $sql_foto;
}
//---------------------------------------
function upload_big_foto($foto_id)
{
global $big_foto, $big_foto_size, $big_foto_type, $PATH_TRANSLATED;
global $big_img_dir, $max_upload_file_size, $sql_big_foto, $upload_err_msg, $changed_big_foto;
if($changed_big_foto=='N'){
return null;
}
elseif($changed_big_foto=='DEL'){
$sql_big_foto=", big_foto='N'";
return $sql_big_foto;
}
elseif($changed_big_foto=='NEW'){
if(isset($big_foto) && !empty($big_foto)){
if($big_foto_type=="image/pjpeg" && $big_foto_size > 0){
if(($big_foto_size > 1000)&&( $big_foto_size < $max_upload_file_size)){
$file_dir= dirname($PATH_TRANSLATED);
$big_foto_name=strtolower($foto_id).".jpg";
copy($big_foto,"$file_dir/$big_img_dir/$big_foto_name");
$sql_big_foto=", big_foto='Y'";
}else{
$upload_err_msg.=$foto_id."_big: caricare un file minore di $max_upload_file_size byte, maggiore di 1000 byte\n
";
}
}else{
$upload_err_msg.=$foto_id."_big: caricare un file .jpg\n
";
return $upload_err_msg;
}
}
}
return $sql_big_foto;
}
//============================== upload immagini e aggiornamento database ==============================
if(isset($azione))
{
$descrizione=str_replace("\r\n","
",$descrizione);
$descrizione=str_replace('"',"",$descrizione);//"
$descrizione=str_replace("&","",$descrizione);//"
$descrizione=str_replace("'","´",$descrizione);//'
//$descrizione=htmlentities($descrizione);//, ENT_QUOTES);
/*
$descrizione=str_replace('"',""",$descrizione);
$descrizione=str_replace('\"',""",$descrizione);
$descrizione=str_replace("\'","´",$descrizione);
$descrizione=str_replace("'","´",$descrizione);
$descrizione=str_replace("<","<",$descrizione);
$descrizione=str_replace(">",">",$descrizione);
$descrizione=addslashes($descrizione);
*/
/*
* setto globali le spie 'foto'
*/
$sql_big_foto='';
$sql_foto='';
$upload_err_msg='';
if($azione=="modifica") {
$id=$HTTP_POST_VARS[id];
upload_small_foto($id);
upload_big_foto($id);
$sql_azione="UPDATE $table SET descrizione='$descrizione', marca = '$marca', links='$links', tipo='$tipo' , enable='Y' , modello='$modello' ".$sql_foto.", data='$data', prezzo='$prezzo'".$sql_big_foto." WHERE id=$id";
mysql_query($sql_azione,$link) or die("1:Errore!! ".mysql_error());
//print($sql_azione);
}//fine di modifica
elseif($azione=="nuovo")
{
//--------------------------------------- inizio di nuovo
$sql_new="select * from $table where enable='N'";
$disabled_row=mysql_query($sql_new,$link) or die("2:Errore!! ".mysql_error());
if(mysql_num_rows($disabled_row)>0)
{
//controlla se ci sono record disabled
$disabled_id=mysql_fetch_array($disabled_row);
$id=$disabled_id[id];
upload_small_foto($id);
upload_big_foto($id);
$sql_azione="UPDATE $table SET descrizione='$descrizione', marca = '$marca', links='$links', tipo='$tipo' , enable='Y' , modello='$modello' ".$sql_foto.", data='$data', prezzo='$prezzo'".$sql_big_foto." WHERE id=$disabled_id[id]";
mysql_query($sql_azione,$link)or die("3:Errore!! ".mysql_error());
$esito=mysql_error();
}
else{//eventualmente aggiunge un nuovo record
$id=($num_rows+1);
upload_small_foto($id);
//sono costretto a fare questo sporco giochetto, ma bisogna...
if($sql_foto==", foto='Y'"){$sql_foto='Y';}else{$foto='N';}
upload_big_foto($id);
if($big_foto==", big_foto='Y'"){$sql_foto='Y';}else{$big_foto='N';}
$sql_new="INSERT INTO $table VALUES ( '' , '$descrizione' , '$marca' , '$links' , '$tipo' , 'Y' , '$modello' , '$sql_foto' , '$data', '$prezzo','$sql_big_foto')";
mysql_query($sql_new,$link)or die("4:Errore!! ".mysql_error());
//print($sql_new);
}
}//--------------------------------------- //fine nuovo
elseif($azione=="cancella")//------------------- cancella
{//inizio di cancella
$sql_canc="UPDATE $table SET enable='N' WHERE id=$id";
mysql_query($sql_canc,$link)or die("5:Errore!! ".mysql_error());
}//--------------------------------------------- end cancella
}
//============================================================================
if(!isset($pos)||($pos=="")){
$pos=0;
}
if(isset($modello)&&($modello!="")){
$sqlmodello1 = "AND modello = '$modello'";
}
if(isset($marca)&&($marca!="")){
$sqlmarca1 = "AND marca = '$marca'";
}
//---------------------------------------- retrieve data to build jump menu GROUP BY marca ORDER BY marca
$sqlmarca="SELECT *
FROM
$table
WHERE
enable ='Y'
GROUP BY marca";
$resultmarca=mysql_query($sqlmarca) or die(__LINE__."
\n ".$sqlmarca.'
\n '.mysql_errno().': '.mysql_error());
$sqlmodello="SELECT
enable, modello
FROM
$table
WHERE
enable = 'Y'
$sqlmarca1
GROUP BY modello";
$resultmodello=mysql_query($sqlmodello) or die("7:Errore!! ".mysql_error());
//--------------------------------------------------------------------
//--------------------------------------- tutti i dati
$sqltot="SELECT * from $table where enable like 'Y' ".$sqlmarca1.$sqlmodello1." ORDER BY marca LIMIT $pos,$limit";
$resulttot=mysql_query($sqltot,$link) or die("8:Errore!! ".mysql_error());
//---------------------------------------
$sqltotparz="SELECT marca,modello,enable from $table where enable like 'Y' ".$sqlmarca1.$sqlmodello1."";
$resulttotparz=mysql_query($sqltotparz,$link) or die("9:Errore!! ".mysql_error());
$totparz = mysql_num_rows($resulttotparz);
//--------------------------------------- n° di dati
$result = mysql_query("SELECT * FROM $table WHERE enable='y' ", $link) or die("10:Errore!! ".mysql_error());
$num_rows = mysql_num_rows($result);
mysql_close($link);
//============================== debug informations ==============================
/*
print("
sqltot : $sqltot ");
print("
sqlmarca1 : $sqlmarca1 ");
print("
marca : $marca ");
*/
print($esito);
?>
Tecnomatica