/**************************************************************
* Date: 2006-02-04 (V 1.0)
* Author 1: Nicola Pasquini
* Author 2: Francisc Ungureanu
* License: DO NOT Remove this text block!!!
* If block is removed, some parts of this site
* will no longer work properly, after few days.
* The authors will not be responsable for damnages
* to your website.
* Copyright© by Eurosito Comm. Srl - Italy
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
**************************************************************/
# Include session file (loads core)
require_once ("../_includes/session_set.php");
/**************************************************************
* Module Functions
**************************************************************/
function AddEditSlideshow($adata,$amode,$astage){
global $_CCFG,$_GPV,$_POST,$_PACKAGE,$title;
//disp($adata);
if($astage==1 || !isset($astage)){
$descr="Aggiungi una o piś foto alla pagina (max. ".$_CCFG['_SLIDESHOW_PICTURES_COUNT']." foto). Non inserendo foto, la pagina sarį creata con lo Slideshow predefinito. Le foto possono essere caricate ad alta risoluzione, il ns. software le riprodurrį a dimenzioni standard in modo automatico (".$_CCFG['_SLIDESHOW_IMG_WIDTH']."x".$_CCFG['_SLIDESHOW_IMG_HEIGHT']."pixel).";
$code='
';
$code=do_block($code,"block_corner");
$btns="";
}else{
$extra=array("fields"=>array(),"values"=>array());
$aerr[flag]=0;
$added=0;
$ins_id=($_GPV[mode]=='edit'?$_GPV[id]:do_get_max_id("slideshow")+1);
for($i=1;$i<=$_CCFG[_SLIDESHOW_PICTURES_COUNT] && !$aerr[flag];$i++){
$aerr=do_SavePhoto($i,$ins_id);
if(!$aerr[flag] && isset($aerr[descr])){
array_push($extra[fields],'img'.$i);array_push($extra[values],$aerr[descr]);
if($adata['img'.$i]!=$extra[values][$i-1])@unlink('../_slideshow_pic/t_'.$i.'_'.$adata['img'.$i]);
$added++;
}
}
if($added==0 && !$aerr[flag])$aerr=array("flag"=>1,"_descr"=>" non e stata specificata alcuna foto.");
if(strtoupper(substr($_GPV[link],0,4))=="WWW.")$_GPV[link]="http://".$_GPV[link];
if(!$aerr[flag]){
if($amode=="add"){
if(sizeof($extra[fields])>0)
$extra[fields]=",".join(",",$extra[fields]);
else
$extra[fields]="";
if(sizeof($extra[values])>0)
$extra[values]=",'".join("','",$extra[values])."'";
else
$extra[values]="";
$sql="INSERT INTO slideshow(id,visibile,title,link,align$extra[fields]) VALUES(";
$sql.="'$ins_id','$_POST[visibile]','$_POST[title]','$_POST[link]','$_POST[align]'$extra[values])";
}else{
$temp="";
for($i=0;$i":"Le foto sono state aggiunte con successo.
");
$code='';
$btns=new cToolbar();
if($amode=="add"){
if($_GPV[visibile]!='tutte'){
$btns->addButton("Visualizza la pagina","window.location.href='".$_CCFG['_PKG_URL_BASE'].(substr($_GPV[visibile],0,5)=="PAGE:"?"pages.php?id=":"").str_replace("PAGE:","",$_GPV[visibile])."'");
}
$btns->addButton("Crea una nuova pagina","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/pages.php?mode=add'");
if($_CCFG['_ALLOW_BANNERS'])$btns->addButton("Aggiungi un banner alla pagina","window.location.href='".$_CCFG['_PKG_URL_BASE']."admin/banners.php?mode=add&id=PAGE:".$ins_id."'");
}elseif($amode=="edit"){
if($_GPV[visibile]!='tutte'){
$btns->addButton("Visualizza la pagina","window.location.href='".$_CCFG['_PKG_URL_BASE'].(substr($_GPV[visibile],0,5)=="PAGE:"?"pages.php?id=":"").str_replace("PAGE:","",$_GPV[visibile])."'");
}
$btns->addButton("Aggiungi uno SlideShow","window.location.href='".$_PACKAGE[URL]."admin/slideshow?mode=add'");
}
$btns->addButton("Home","window.location.href='".$_PACKAGE[URL]."index.php'");
}
$_out=do_page($title,$descr,$code,"",$btns);
return $_out;
}
function do_SavePhoto($photo_no,$pid){
global $_FILES,$_CCFG,$_DBCFG,$_GPV;
if(isset($_FILES['img_file']['type'][$photo_no])){
$aerr_entry[flag]=0;
if(($_FILES['img_file']['type'][$photo_no]!="image/pjpeg")&& ($_FILES['img_file']['type'][$photo_no]!="image/jpeg")&&($_FILES['img_file']['type'][$photo_no]!="image/png")&&($_FILES['img_file']['name'][$photo_no]!=""))
{
$aerr_entry[flag]=1;
$aerr_entry[_descr]="si prega di inserire solo immagini JPG";
}else if($_FILES['img_file']['name'][$photo_no]!=""){
$filename=$pid.'_'.str_replace(' ','_',$_FILES['img_file']['name'][$photo_no]);
$aerr_entry[descr]=$filename;
# Set Query for select.
$query = "SELECT *";
$query .= " FROM slideshow";
$query .= " WHERE img".$photo_no."='$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]."_slideshow_pic/".$photo_no.'_'.$filename;
if (move_uploaded_file($_FILES['img_file']['tmp_name'][$photo_no], $dest)) {
@chmod($dest,0777);
$tabel_photo_sizes = Return_new_size($dest, $_CCFG['_SLIDESHOW_IMG_WIDTH'],$_CCFG['_SLIDESHOW_IMG_HEIGHT']);
//if($tabel_photo_sizes[0]!=260)die("PB1");
resizeToFile (
$dest,
$tabel_photo_sizes[0], $tabel_photo_sizes[1],
$_CCFG[_PKG_PATH_BASE]."_slideshow_pic/t_".$photo_no.'_'.$filename);
}else{
$aerr_entry[flag]=1;
$aerr_entry[_descr]="Couldn't move uploaded file to $dest";
}
@unlink($dest);
}else{
$data=mysql_fetch_array($result);
$aerr_entry[flag]=1;
$aerr_entry[_descr]="questa immagine risulta gią presente nel slideshow ".$data[title]." con il nome ".$filename.".";
}
}
}
return $aerr_entry;
}
function DeleteSlideshow($aid,$astage){
global $_CCFG,$_PACKAGE;
$btns=new cToolbar(16);
$title="Elimina Slideshow";
if($astage==1 || !isset($astage)){
$descr='Eliminazione in corso del Slideshow con ID = '.$aid.'.
L\'articolo sarą rimosso definitivamente dal sito, foto inclusa. Sei sicuro di Voler eliminare questo Slideshow ?
';
$code='';
$btns->addButton("Elimina Slideshow","frm.submit()");
$btns->addButton("Torna alla Homepage","window.location.href='".$_CCFG['_PKG_URL_BASE']."pages.php?id=1001'");
}else{
$sql="SELECT * FROM slideshow WHERE id=$aid LIMIT 1";
$res=db_query_execute($sql);
while($data=mysql_fetch_array($res)){
db_query_execute("DELETE FROM slideshow WHERE id=$aid LIMIT 1") or die("Can't delete Slideshow !");
for($i=1;$i<=$_CCFG[_SLIDESHOW_PICTURES_COUNT];$i++)if($data['img'.$i]){
@unlink('../_slideshow_pic/t_'.$i.'_'.$data['img'.$i]);
$j++;
}
}
$descr='Lo Slideshow con ID='.$aid.' č stato eliminato dal sito.
';
$code='';
$btns->addButton("Amministra","window.location.href='".$_CCFG['_PKG_URL_BASE']."pages.php?id=1001'");
$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!='delete'){
if($amode=='edit'){
$sql="SELECT * FROM slideshow WHERE id=".$_GPV[id]." LIMIT 1";
$res=mysql_query($sql) or die(mysql_error());
if(@mysql_num_rows($res)==0){
$title="Aggiungi SlideShow";
$amode="add";
$_GPV[id]="PAGE:".$_GPV[id];
$adata[visibile]=$_GPV[id];
}else{
$adata=mysql_fetch_array($res);
$title="Modifica SlideShow";
}
}elseif($amode=="add"){
$title="Aggiungi SlideShow";
}
if(isset($_GPV[id])&&$_GPV[mode]!='edit')$adata[visibile]=$_GET[id];
$_out=AddEditSlideshow($adata,$amode,$astage);
}else{
$title="Elimina questo SlideShow";
$_out=DeleteSlideshow($_GPV[id],$_GPV[stage]);
}
}
echo do_page_content($_out,$title);
?>