<?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."linkus ( name ) VALUES( '".$_POST['name']."' ) ");
	$id=mysql_insert_id();
	$banner = $_FILES['banner'];
	$filepath = "./images/linkus/";
	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."linkus SET file='$file' WHERE bannerID='$id' ");
	}
	header("Location: index.php?site=linkus");
}
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."linkus SET name='".$_POST['name']."' WHERE bannerID='".$_POST['bannerID']."'");
							 
	$filepath = "./images/linkus/";
	$id=$_POST['bannerID'];
	$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."linkus SET file='$file' WHERE bannerID='$id' ");
	}
	header("Location: index.php?site=linkus");
}
elseif($_GET['delete']) {
	include("_mysql.php");
	include("_settings.php");
	include('_functions.php');
  if(!ispageadmin($userID)) die('No access.');

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

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

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

		$bg1=BG_1;
		eval ("\$linkus_edit = \"".gettemplate("linkus_edit")."\";");
	    echo $linkus_edit;
	}
	else redirect('index.php?site=linkus', 'no access!');
}
else {
  $filepath = "./images/linkus/";
  $filepath2 = "/images/linkus/";
	if(ispageadmin($userID)) echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=linkus&action=new\');return document.MM_returnValue" value="new banner"><br><br>';
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."linkus 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;
			
			$name=$ds[name];
			$fileinfo=getimagesize($filepath.$ds[file]);
			if($fileinfo[0]>$picsize_l) $width=' width="'.$picsize_l.'"';
			else $width='';
			if($fileinfo[1]>$picsize_h) $height=' height="'.$picsize_h.'"';
			else $height='';
			$banner='<img src="'.$filepath.$ds[file].'" border="0"'.$width.$height.'>';
			$code = '<a href="http://'.$hp_url.'" target="_blank"><img src="http://'.$hp_url.$filepath2.$ds[file].'" border="0"></a>';

			if(isclanwaradmin($userID)) 
	            $adminaction='<hr noshade size="1" color="'.BORDER.'"><input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=linkus&action=edit&bannerID='.$ds[bannerID].'\');return document.MM_returnValue" value="edit">
						      <input type="button" class="button" onClick="MM_confirm(\'really delete this banner?\', \'linkus.php?delete=true&bannerID='.$ds[bannerID].'\')" value="delete">';
					  
			eval ("\$linkus = \"".gettemplate("linkus")."\";");
	        echo $linkus;
			$i++;
		}
	}
	else echo'no linkus banner';
}


?>
