';
$code=do_block($code,"block_corner");
$btns="";
}else{
$ins_id=($_GPV[mode]=='edit'?$_GPV[id]:do_get_max_id("news")+1);
$aerr=do_SavePhoto($ins_id);
$has_photo=($aerr[flag]==0 && isset($aerr[descr]));
if(strtoupper(substr($_POST[img_link],0,4))=="WWW.")$_POST[img_link]="http://".$_POST[img_link];
if(strtoupper(substr($_POST[descr_link],0,4))=="WWW.")$_POST[descr_link]="http://".$_POST[descr_link];
if($_GPV[year]==0 && $_GPV[month]==0 && $_GPV[day]==0){
$_GPV[year]=2010;$_GPV[month]=1;$_GPV[day]=1;
}
if($amode=="add"){
$sql="INSERT INTO news(id,lingua,txt_align,title,descr,descr_link,img".($has_photo?",img_link":"").",align,scadenza,status) VALUES(";
$sql.="'$ins_id','$_GPV[lingua]','$_GPV[txt_align]','$_POST[title]','$_POST[descr]','$_POST[descr_link]'".($has_photo?",'$aerr[descr]'":"").",'$_POST[img_link]','$_GPV[align]','$_GPV[year]-$_GPV[month]-$_GPV[day]','$_GPV[status]')";
}else{
$sql="UPDATE news SET lingua='$_GPV[lingua]', txt_align='$_GPV[txt_align]', title='$_GPV[title]', descr='$_GPV[descr]', descr_link='$_GPV[descr_link]', img_link='".$_GPV[img_link]."'";
if($aerr[flag]==0 && isset($aerr[descr]))$sql.=",img='$aerr[descr]'";
$sql.=",align='$_GPV[align]',scadenza='$_GPV[year]-$_GPV[month]-$_GPV[day]',status='$_GPV[status]' WHERE id=".$adata[id];
}
db_query_execute($sql) or die($sql.' '.mysql_error());
$descr="La News è stata aggiunta con successo.";
$code='';
$btns=new cToolbar();
if($amode=="add"){
$btns->addButton("Aggiungi un'altra News","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/news.php?mode=add'");
}elseif($amode=="edit"){
$btns->addButton("Aggiungi una News","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/news.php?mode=add'");
}
$btns->addButton("Vedi News","window.location.href='".$_CCFG['_PKG_URL_BASE']."news.php'");
$btns->addButton("Home","window.location.href='".$_CCFG['_PKG_URL_BASE']."index.php'");
}
$_out=do_page($title,$descr,$code,"",$btns);
return $_out;
}
function DeletePhoto($aid_pic,$astage){
global $_CCFG;
$btns=new cToolbar(16);
$title="Elimina Photo";
if($astage==1 || !isset($astage)){
$sql="SELECT * FROM news WHERE img='".$aid_pic."' LIMIT 1";
$res=db_query_execute($sql);
$adata=mysql_fetch_array($res);
$descr='Eliminazione in corso della photo
La foto stà per essere rimossa definitivamente dal sito!, sei sicuro di voler eliminare la foto in modo definitivo ?
'.$_nl;
$code=''.$_nl;
$btns->addButton("Elimina photo","frm.submit()");
$btns->addButton("Torna a modifiche News","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/news.php?mode=edit&id=".$adata[id]."'");
$btns->addButton("Torna alla Homepage","window.location.href='".$_CCFG['_PKG_URL_BASE']."index.php'");
}else{
$sql="UPDATE news SET img='' WHERE img='".$aid_pic."' LIMIT 1";
db_query_execute($sql) or die("Can't delete photo from DB !");
@unlink('../_news_pic/t_'.$aid_pic) or die("Can't delete photo from HDD !");
@unlink('../_news_pic/t_home_'.$aid_pic) or die("Can't delete photo from HDD !");
$descr='La photo è stata eliminato con successo.
'.$_nl;
$code='';
$btns->addButton("Amministra","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/index.php'");
$btns->addButton("Torna alla Homepage","window.location.href='".$_CCFG['_PKG_URL_BASE']."index.php'");
}
$_out=do_page($title,$descr,$code,"",$btns);
return $_out;
}
function do_SavePhoto($pid){
global $_FILES,$_CCFG,$_DBCFG,$_GPV;
if(isset($_FILES['img_file']['type'])){
$aerr_entry[flag]=0;
if(($_FILES['img_file']['type']!="image/pjpeg")&& ($_FILES['img_file']['type']!="image/jpeg")&&($_FILES['img_file']['type']!="image/png")&&($_FILES['img_file']['name']!=""))
{
$aerr_entry[flag]=1;
$aerr_entry[_descr]="Please insert only jpg pictures";
}else if($_FILES['img_file']['name']!=""){
$filename=$pid.'_'.str_replace(' ','_',$_FILES['img_file']['name']);
$aerr_entry[descr]=$filename;
# Set Query for select.
$query = "SELECT *";
$query .= " FROM news";
$query .= " WHERE img='$filename'";
if($_GPV[mode]=='edit') $query .= " AND id!=".$_GPV[id];
$query .= " ORDER BY ID ASC";
# Do select and return check
$result = db_query_execute($query);
$numrows = db_query_numrows($result);
if($numrows==0){
$dest=$_CCFG[_PKG_PATH_BASE]."_news_pic/".$filename;
if (move_uploaded_file($_FILES['img_file']['tmp_name'], $dest)) {
@chmod($dest,0777);
$tabel_photo_sizes = Return_new_size($dest, 260,320);
// disp($tabel_photo_sizes);
// die();
resizeToFile ($dest, $tabel_photo_sizes[0], $tabel_photo_sizes[1], $_CCFG[_PKG_PATH_BASE]."_news_pic/t_home_".$filename,true);
$tabel_photo_sizes = Return_new_size($dest, 100,75);
resizeToFile ($dest, $tabel_photo_sizes[0], $tabel_photo_sizes[1], $_CCFG[_PKG_PATH_BASE]."_news_pic/t_".$filename);
list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize($dest);
$imgsize=filesize($dest);
}else{
$aerr_entry[flag]=1;
$aerr_entry[_descr]="Couldn't move uploaded file to $dest";
}
@unlink($dest);
}else{
$aerr_entry[flag]=1;
$aerr_entry[_descr]="Questa immagine risulta già presente.";
}
}
}
return $aerr_entry;
}
function DeleteNews($aid,$astage){
global $_CCFG;
$btns=new cToolbar(16);
$title="Elimina News";
if($astage==1 || !isset($astage)){
$descr='Eliminazione in corso della News con ID = '.$aid.'.
L\'articolo sarà rimosso definitivamente dal sito, foto inclusa. Sei sicuro di Voler eliminare la News ?
';
$code='';
$btns->addButton("Elimina la News","frm.submit()");
$btns->addButton("Vedi News","window.location.href='".$_CCFG['_PKG_URL_BASE']."news.php?mode=details&id=$aid'");
$btns->addButton("Torna alla Homepage","window.location.href='".$_CCFG['_PKG_URL_BASE']."index.php'");
}else{
$sql="SELECT * FROM news WHERE id=$aid LIMIT 1";
$res=db_query_execute($sql);
while($data=mysql_fetch_array($res)){
db_query_execute("DELETE FROM news WHERE id=$aid LIMIT 1") or die("Can't delete news !");
if($data[img]){
@unlink('../_news_pic/t_'.$data[img]);
@unlink('../_news_pic/t_home_'.$data[img]);
}
}
$descr='La News con ID='.$aid.' e stata eliminata dal sito.
';
$code='';
$btns->addButton("Amministra","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/index.php'");
$btns->addButton("Torna alla News","window.location.href='".$_CCFG['_PKG_URL_BASE']."news.php'");
$btns->addButton("Torna alla Homepage","window.location.href='".$_CCFG['_PKG_URL_BASE']."index.php'");
}
$_out=do_page($title,$descr,$code,"",$btns);
return $_out;
}
# Get security vars
$_SEC = get_security_flags();
IF ( !$_SEC['_sadmin_flg'] && $_GPV[mode]!='view')
{
# Set login flag
$_login_flag = 1;
# Call function for clients listings
$_out = ''.$_nl;
$_out .= do_login($data, 'admin', '1').$_nl;
$title="Login";
}
IF ( $_SEC['_sadmin_flg']){
$amode = $_GPV[mode];
$astage = $_GPV[stage];
if($amode=='add' || $amode=='edit'){
if($amode=='edit'){
$res="SELECT * FROM news WHERE id=".$_GPV[id]." LIMIT 1";
$adata=mysql_fetch_array(mysql_query($res));
$title="Modifica News";
}elseif($amode=='add'){
$title="Aggiuni una News";
}
$_out=AddEditNews($adata,$amode,$astage);
}elseif($amode=='delete_pic'){
$title="Elimina foto";
$_out=DeletePhoto($_GPV[id_pic],$_GPV[stage]);
}elseif($amode='delete'){
$title="Elimina questa News";
$_out=DeleteNews($_GPV[id],$_GPV[stage]);
}
}
echo do_page_content($_out,$title);
?>