<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
if(!defined('BASE_DIR')) exit;
if(!get_active('forums'))
{
	notActive();
}

if (!permission("showuserpage")) 
{
	koobi_message('Global_NoPermission', 'Global_NoPermission_t', HOME_PATH . '/index.php?p=index&amp;area=' . AREA);
}

$row = $GLOBALS['db']->ArrQuery("SELECT * FROM " . PREFIX . "_benutzer WHERE Id = '" . $_REQUEST['id'] . "' AND Aktiv=1 AND Geloescht!='1'");
if(!is_array($row)) 
{
	refer('index.php?p=index&area=' . AREA);
}

$GLOBALS['tmpl']->assign('SearchPop', popSearch());
//=================================================================
// Hits
//=================================================================
$GLOBALS['db']->ArrQuery("UPDATE " . PREFIX . "_benutzer SET Profil_Hits=Profil_Hits+1 WHERE Id = '" . $_REQUEST['id'] . "'");

//=================================================================
// Beitraege
//=================================================================
$beitraege_obj     = $GLOBALS['db']->RowQuery("SELECT COUNT(id) AS Beitraege FROM " . PREFIX . "_f_post WHERE uid = '" .  $_REQUEST['id'] . "'");
$rank_obj          = $GLOBALS['db']->RowQuery("SELECT title FROM " . PREFIX . "_f_rank WHERE count <= '" . ($beitraege_obj->Beitraege > 0 ? $beitraege_obj->Beitraege : 1) . "' ORDER BY count DESC LIMIT 1");
$row['TeamName']   = $GLOBALS['settings']['Seitenname'] . $GLOBALS['config_vars']['WebTeam'];
$row['Beitraege']  = $beitraege_obj->Beitraege;
$row['Rang']       = (is_object($rank_obj)) ? $rank_obj->title : '';
$row['Avatar']     = getAvatar($row['Gruppe'],$row['Avatar'],$row['Avatar_Default']);
$row['Icq_User']   = ($row['icq'] != '') ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=ICQ&amp;uid=' . $row['Id'] . '\',\'Icq\',\'450\',\'490\',\'1\')"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/icq.png" alt="" /></a>' : "";
$row['Pn_User']    = ($row['Pnempfang'] == 1 && UGROUP != 2) ? "<a href=\"index.php?p=pn&amp;action=new&amp;to=".base64_encode($row['Benutzername'])."\"><img border=\"0\" src=\"theme/".$GLOBALS['theme']."/images/forums/pn.png\" alt=\"\" /></a>" : '';
$row['Email_User'] = ($row['Emailempfang'] == 1 && UGROUP != 2) ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=EMAIL&amp;uid=' . $row['Id'] . '\',\'Email\',\'450\',\'590\',\'1\');"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/mail.png" alt="" /></a>' : '';
$row['Skype_User'] = ($row['skype'] != '') ? '<a href="javascript:void(0);" onclick="javascript:open_window(\'index.php?p=misc&amp;do=SKYPE&amp;uid=' . $row['Id'] . '\',\'Skype\',\'450\',\'490\',\'1\')"><img border="0" src="theme/'.$GLOBALS['theme'].'/images/forums/skype.png" alt="Call Me!" /></a>' : "";
$row['Webseite']   = (starts_with('www',$row['Webseite'])) ? 'http://' . $row['Webseite'] : $row['Webseite'];

if($row['Profil_Alle'] != 1 && UGROUP == 2)
{
	koobi_message('Forums_UserProfile', 'Profile_PublicAllNo', HOME_PATH . '/index.php?p=index&amp;area=' . AREA);
} 

//=================================================================
// Gaestebuch
//=================================================================
if(!get_active('user_guestbook')) $row['Gaestebuch'] = 0;
if($row['Gaestebuch'] == 1)
{
	$error = array();
	$use_code = -1;
	
	if($GLOBALS['settings']['Sicherheitscode']==1) 
	{
		$GLOBALS['tmpl']->assign('use_code', 1);
		$use_code = 1;
	}
	
	if(isset($_REQUEST['action']) && $_REQUEST['action'] != '' && ($_SESSION['benutzer_id'] == $_REQUEST['id']))
	{
		switch($_REQUEST['action'])
		{
			case 'set_active':
				$GLOBALS['db']->RowQuery("UPDATE " . PREFIX . "_benutzer_gaestebuch SET Aktiv = 1 WHERE  BenutzerId = '" .  $_GET['id'] . "' AND Id = '" . $_GET['gb_entry']. "'");
				refer($_SERVER['HTTP_REFERER'] . "#eintraege");
				exit;
			break;
			
			case 'delete':
				$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_benutzer_gaestebuch WHERE  BenutzerId = '" .  $_GET['id'] . "' AND Id = '" . $_GET['gb_entry']. "'");
				refer($_SERVER['HTTP_REFERER'] . "#eintraege");
				exit;
			break;
			
			case 'delete_all':
				$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_benutzer_gaestebuch WHERE  BenutzerId = '" .  $_GET['id'] . "'");
				refer("index.php?p=user&id=" . $_GET['id']);
				exit;
			break;
			
			case 'edit':
				$GLOBALS['db']->RowQuery("
					UPDATE " . PREFIX . "_benutzer_gaestebuch 
				SET 
					Eintrag = '" . substr(@$_POST['E_Eintrag'],0,5000) . "',
					Titel = '" . @$_POST['E_Titel'] . "',
					Autor = '" . @$_POST['E_Autor'] . "',
					Autor_Web = '" . @$_POST['E_Webseite'] . "',
					Autor_Herkunft = '" . @$_POST['E_Herkunft'] . "' 
				WHERE  
					BenutzerId = '" .  $_REQUEST['id'] . "' AND Id = '" . $_REQUEST['gb_entry']. "'");
				refer("index.php?p=user&id=$_REQUEST[id]&page=$_REQUEST[page]#$_REQUEST[gb_entry]");
				exit;
			break;
		}
	}
	
	if(!isset($_REQUEST['Eintrag']) && $use_code == 1) 
	{
		giveSecure();
	}
	if(isset($_POST['Eintrag']) && $_POST['Eintrag'] == 1)
	{
		if($row['Gaestebuch_KeineGaeste'] == 1 && UGROUP == 2)
		{
			koobi_message('Profile_GuestbookUser', 'Profile_Guestbook_NoGuests', HOME_PATH . '/index.php?p=user&amp;id=' . $_POST['id']);
		}
		
		if($use_code==1)
		{
			$scode_form = (isset($_POST['scode']) && !empty($_POST['scode'])) ? $_POST['scode'] : '';
			$scode_ses = @$_SESSION['scode'];
			
			
			if(($use_code && @empty($_POST['scode'])) || (!$_SESSION['scode'] && $use_code) || ($scode_form != $scode_ses && ($use_code)))
			{
				$error[] = $GLOBALS['config_vars']['Reg_SecurecodeWrong'] . "<br />";
				giveSecure();
				$secureCode = rand_string(4); 
				$_SESSION['scode'] = $secureCode; 
			} else {
				$_SESSION['scode'] = $_POST['scode'];
				giveSecure($_SESSION['scode']);
				$secureCode = $_POST['scode']; 
			}
		}
		
		if(empty($_POST['Autor'])) $error[] = $GLOBALS['config_vars']['Profile_Guestbook_NoAuthor'];
		if(empty($_POST['Titel'])) $error[] = $GLOBALS['config_vars']['Profile_Guestbook_NoTitle'];
		if(empty($_POST['text'])) $error[] = $GLOBALS['config_vars']['Profile_Guestbook_NoComment'];
		
		//=================================================================
		// Gibt es Spam in den Feldern?
		//=================================================================
		$spam = false;
		foreach($_POST as $key) 
		{
			if(!SpamCheck($key) && strlen($key)>=2) $spam=true;
		}
		
		if($spam) $error[] = $GLOBALS['config_vars']['SpamUsed'];
		
		if($error)
		{
			$GLOBALS['tmpl']->assign('error', $error);
		} else {
			//=================================================================
			// Kein Fehler, Kommentar eintragen
			//=================================================================
			$q = "INSERT INTO " . PREFIX . "_benutzer_gaestebuch 
			(
				Id,
				BenutzerId, 	 
				Titel,  	 
				Eintrag,  	
				Datum,  	 
				Autor,  	 
				Autor_Web,  	 
				Autor_Herkunft,  	 
				Autor_Ip,
				Aktiv 
			) VALUES (
				'',
				'" . @$_POST['id'] . "',
				'" . @$_POST['Titel'] . "',
				'" . @substr($_POST['text'],0,$row['Gaestebuch_Zeichen']) . "',
				'" . stime() . "',
				'" . $_POST['Autor'] . "',
				'" . $_POST['Webseite'] . "',
				'" . $_POST['Herkunft'] . "',
				'" . $_SERVER['REMOTE_ADDR'] . "',
				'" . (($row['Gaestebuch_Moderiert'] == 1) ? 0 : 1) . "'
			)";
			$GLOBALS['db']->Query($q);
			
			$msg = ($row['Gaestebuch_Moderiert'] == 1) ? 'Profile_GuestbookUser_EntryOk_Moderated' : 'Profile_GuestbookUser_EntryOk';
			koobi_message('Profile_GuestbookUser', $msg, HOME_PATH . '/index.php?p=user&amp;id=' . $_POST['id'] . '&amp;area=' . AREA);
		}
	} 
	
	$eintrag = array();
	$db_aktiv = ($_REQUEST['id'] == $_SESSION['benutzer_id']) ? '' : 'AND Aktiv = 1';
	$num_sql = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS Anzahl FROM " . PREFIX . "_benutzer_gaestebuch WHERE  BenutzerId = '" .  $_REQUEST['id'] . "' {$db_aktiv}");
	$num = $num_sql->Anzahl;
	$limit = 15;
	$seiten = ceil($num / $limit);
	$a = prepage() * $limit - $limit;
		
	$gb_sql = $GLOBALS['db']->Query("SELECT * FROM " . PREFIX . "_benutzer_gaestebuch WHERE  BenutzerId = '" .  $_REQUEST['id'] . "' {$db_aktiv} ORDER BY Id DESC LIMIT $a,$limit");
	while($gb = $gb_sql->fetcharray())
	{
		$gb['Eintrag_Raw'] = $gb['Eintrag'];
		
		
		if ($row['Gaestebuch_bbcode'] == 1 && BBCODESITE == 1)
		{
			$gb['Eintrag'] = pre_kcodes($gb['Eintrag'], 'user_guestbook', $row['Gaestebuch_imgcode']);
		} else {
			$gb['Eintrag'] = koobispecialchars($gb['Eintrag']);
			$gb['Eintrag'] = nl2br($gb['Eintrag']);
		}
		
		if ($row['Gaestebuch_smilies'] == 1 && SMILIES == 1)
		{
			$gb['Eintrag'] = dosmilies($gb['Eintrag']);
		}
		$gb['Eintrag'] = (!badwordreplace($gb['Eintrag'])) ? $gb['Eintrag'] : badwordreplace($gb['Eintrag']);
		$gb['Eintrag'] = wordwrap($gb['Eintrag'], 75, "\n", 1);
		$gb['Eintrag'] = autowords($gb['Eintrag']);
		$gb['Autor_Web'] = (starts_with('www',$gb['Autor_Web'])) ? 'http://' . $gb['Autor_Web'] : $gb['Autor_Web'];
		
		array_push($eintrag, $gb);
	}
	
	if($num > $limit)
	{
		$GLOBALS['tmpl']->assign('pages', pagenav($seiten, '', 
				"<a class=\"page_navigation\" href=\"index.php?p=user&amp;id=" . $_REQUEST['id'] . "&amp;area=" . AREA . "&amp;page={s}#eintraege\">{t}</a> "));
	}
	
	if($row['Gaestebuch_KeineGaeste'] == 1 && UGROUP == 2) $GLOBALS['tmpl']->assign('KeineGaeste', 1);
	$GLOBALS['tmpl']->assign('eintrag', $eintrag);
}

if ($row['Gaestebuch_smilies'] == 1 && SMILIES == 1)
{
	$GLOBALS['tmpl']->assign('smilie', 1);
	$GLOBALS['tmpl']->assign('listemos', listsmilies(6,1,1));
}

if ($row['Gaestebuch_bbcode'] == 1 && BBCODESITE == 1)
{
	$GLOBALS['tmpl']->assign('format', 1);
	$GLOBALS['tmpl']->assign('listfonts',  fontdropdown());
	$GLOBALS['tmpl']->assign('sizedropdown',  sizedropdown());
	$GLOBALS['tmpl']->assign('colordropdown',  colordropdown());
}


if ($row['Gaestebuch_imgcode'] != 1)
{
	$GLOBALS['tmpl']->assign('NoImgCode', 1);
}



$GLOBALS['tmpl']->assign('pagetitle_html', $GLOBALS['config_vars']['Profile_HeaderStart'] . $row['Benutzername']);
$GLOBALS['tmpl']->assign('user', $row);
$GLOBALS['tmpl']->assign('user_videos', userVideos($row['Id']));
$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/user/user_profile.tpl')); 
?>