<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

if($_POST['save']) {
	include("_mysql.php");
	include("_settings.php");
	include('_functions.php');
  if(!ispageadmin($userID)) die('No access.');

	safe_query("INSERT INTO ".PREFIX."sponsors ( name, url, info ) VALUES( '".$_POST['name']."', '".$_POST['url']."', '".$_POST['info']."' ) ");
	$id=mysql_insert_id();
	$banner = $_FILES['banner'];
	$filepath = "./images/sponsors/";
	if ($banner[name] != "") {
        move_uploaded_file($banner[tmp_name], $filepath.$banner[name]);
		@chmod($filepath.$banner[name], 0755);
		$file_ext=strtolower(substr($banner[name], strrpos($banner[name], ".")));
		$file=$id.$file_ext;
		if(file_exists($filepath.$file)) @unlink($filepath.$file);
		rename($filepath.$banner[name], $filepath.$file);
		safe_query("UPDATE ".PREFIX."sponsors SET banner='$file' WHERE sponsorID='$id' ");
	}
	header("Location: index.php?site=sponsors");
}
elseif($_POST['saveedit']) {
	include("_mysql.php");
	include("_settings.php");
	include('_functions.php');
  if(!ispageadmin($userID)) die('No access.');

	$date=mktime(0,0,0,$month,$day,$year);
	safe_query("UPDATE ".PREFIX."sponsors SET name='".$_POST['name']."', url='".$_POST['url']."', info='".$_POST['info']."' WHERE sponsorID='".$_POST['sponsorID']."'");
							 
	$filepath = "./images/sponsors/";
	$id=$_POST['sponsorID'];
	$banner = $_FILES[banner];
	if ($banner[name] != "") {
        move_uploaded_file($banner[tmp_name], $filepath.$banner[name]);
		@chmod($filepath.$banner[name], 0755);
		$file_ext=strtolower(substr($banner[name], strrpos($banner[name], ".")));
		$file=$id.$file_ext;
		if(file_exists($filepath.$file)) @unlink($filepath.$file);
		rename($filepath.$banner[name], $filepath.$file);
		safe_query("UPDATE ".PREFIX."sponsors SET banner='$file' WHERE sponsorID='$id' ");
	}
	header("Location: index.php?site=sponsors");
}
elseif($_GET['delete']) {
	include("_mysql.php");
	include("_settings.php");
	include('_functions.php');
  if(!ispageadmin($userID)) die('No access.');

	$sponsorID = $_GET['sponsorID'];
  $filepath = "./images/sponsors/";
	safe_query("DELETE FROM ".PREFIX."sponsors WHERE sponsorID='$sponsorID'");
	if(file_exists($filepath.$sponsorID.'.jpg')) @unlink($filepath.$sponsorID.'.jpg');
	if(file_exists($filepath.$sponsorID.'.gif')) @unlink($filepath.$sponsorID.'.gif');
	header("Location: index.php?site=sponsors");
}

eval ("\$title_sponsors = \"".gettemplate("title_sponsors")."\";");
echo $title_sponsors;

if($_GET['action']=="new") {
    if(ispageadmin($userID)) {
		$bg1=BG_1;
		eval ("\$sponsors_new = \"".gettemplate("sponsors_new")."\";");
	    echo $sponsors_new;  
	}
	else redirect('index.php?site=sponsors', 'no access!');
}
elseif($_GET['action']=="edit") {
    if(ispageadmin($userID)) {
     $sponsorID = $_GET['sponsorID'];
     $ds=mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."sponsors WHERE sponsorID='$sponsorID'"));
	 	 $name=$ds[name];
		 $url=$ds[url];
		 $info=$ds[info];
		 $banner='<img src="images/sponsors/'.$ds[banner].'">';

		$bg1=BG_1;
		eval ("\$sponsors_edit = \"".gettemplate("sponsors_edit")."\";");
	    echo $sponsors_edit;      
	}
	else redirect('index.php?site=sponsors', 'no access!');
}
else {
	if(ispageadmin($userID)) echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=sponsors&action=new\');return document.MM_returnValue" value="new sponsor"><br><br>';
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."sponsors ORDER BY name");
	if(mysql_num_rows($ergebnis)) {
		$i=1;
		while($ds=mysql_fetch_array($ergebnis)) {
			if($i%2) $bg1=BG_1;
			else $bg1=BG_2;
			
			$sponsor='<a class="titlelink" href="'.$ds[url].'" target="_blank">'.$ds[name].'</a>';
			$link='&#8226; <a href="'.$ds[url].'" target="_blank">'.$ds[url].'</a>';
			$info=cleartext($ds[info]);
			$banner='<a href="'.$ds[url].'" target="_blank"><img src="images/sponsors/'.$ds[banner].'" alt="'.$ds[name].'" border="0"></a>';
						
			if(ispageadmin($userID))
	            $adminaction='<hr noshade size="1" color="'.BORDER.'"><input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=sponsors&action=edit&sponsorID='.$ds[sponsorID].'\');return document.MM_returnValue" value="edit">
						      <input type="button" class="button" onClick="MM_confirm(\'really delete this sponsor?\', \'sponsors.php?delete=true&sponsorID='.$ds[sponsorID].'\')" value="delete">';
					  
			eval ("\$sponsors = \"".gettemplate("sponsors")."\";");
	        echo $sponsors;
			$i++;
		}
	}
	else echo'no sponsors';
}


?>
