<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
if(!checkactive('ignorelist')) include(dirname(__FILE__)."/lib/notactive.php" );
$sname = simpletitle($lang['ignoretitle']);

if ($islogged==0) {
	$EOUT = stderror("nopermission", $lang['nopermission_t'], str_replace("__URL__", "index.php", $lang['redirect']), "index.php", 1);
	$error = 1;
	$NOOUT = 1;
	
	} else {
	
	
	// NEW IGNORE
	if($_REQUEST['action'] == "newignore"){
		$ok = 1;
		
		$sql =& new dbc("SELECT uname,uid FROM ".PREFIX."_user WHERE uname='".escs(iform($_POST['uname'],"25",""))."'");
		$row = $sql->fetchrow();
		if(!$sql->numrows()){
			$errors .= emsg("error_usernotindb");
		$ok = "0"; }
		
		if($ok == 1){
			$sql2 =& new dbc("SELECT ignore_uid FROM ".PREFIX."_ignore WHERE ignore_uid='".escs($row->uid)."' LIMIT 1");
			if($sql2->numrows()){
				$errors .= emsg("error_ignoreuserissinlist");
			$ok = "0"; }
			
			
		}
		
		if($ok == 1){
			if($row->uid == $UID){
				$errors .= emsg("error_userignore_self");
				$ok = "0";
			}
		}	
		
		if($ok == 1){
			$sql3 =& new dbc("INSERT INTO ".PREFIX."_ignore (uid,ignore_uid,reason,itime) VALUES ('".escs($UID)."','".escs($row->uid)."','".escs(iform($_POST['ireason'],"75",""))."','".time()."')");
			header("Location:index.php?p=ignorelist");
		}
		
	}
	
	
	
	// DELETE IGNORE
	if($_REQUEST['action']=="delignore"){
		reset ($_POST);
		while(list($key,$val) = each($_POST)) {
			if (substr($key,0,7)=="ingore_") {
				$aktid = str_replace("ingore_","",$key);
				
				$sql4 =& new dbc("DELETE FROM ".PREFIX."_ignore WHERE ignore_uid='".escs($aktid)."' AND uid='".escs($UID)."'");
			}
		}
	}
	
	
	
	// IGNORELIST
	$table_data = array();
	$i = 2;
	
	$sql =& new dbc("SELECT * FROM ".PREFIX."_ignore WHERE uid='".$UID."' ORDER BY itime DESC");
	while($row = $sql->fetchrow()){
		
		$sql2 =& new dbc("SELECT uname,uid FROM ".PREFIX."_user WHERE uid='".escs($row->ignore_uid)."'");
		$row2 = $sql2->fetchrow();
		
		array_push($table_data, array(
		'name'	=> $row2->uname,
		'id' => $row2->uid,
		'itime' => mygmt($row->itime),
		'reason' => dosmilies(kcodes(oform($row->reason)))
		)
		);
		
		$i++;
	}
	
	
	if ($ok==0 && $_REQUEST['action']=="newignore") {
		$tmpl->assign('iserror', 1);
		$tmpl->assign('error', $errors);
	}
	
	$tmpl->assign('ignorenew_message', $newignore_error);
	$tmpl->assign('ignorenew_user_field', oform($_POST['uname']));
	$tmpl->assign('ireason', kspecialchars($_POST['ireason']));
	$tmpl->assign('lang', $lang);
	
	if($row2->uid){
		$tmpl->assign('table_data', $table_data);
	}
	
	if ($nometa==1) {
		$tmpl->assign("content", $OUT);
	} else {
		$tmpl->assign("content", parsetrue("container/".container("ignorelist"), $lang['ignoretitle'], $tmpl->fetch("user/ignorelist.tpl")));
	}
}

?>