<?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
//=================================================================
switch($_REQUEST['do'])
{
	case 'shopimgages':
		$Shop->browseImages($_REQUEST['prodid']);
	break;
	
	case 'shippingcost':
		$Shop->shippingCosts(1);
	break;
	
	case 'mergeproduct':
		$Shop->mergeProduct($_REQUEST['prodid'], $_REQUEST['red'], $_REQUEST['cid']);
	break;
	
	case 'availablewindow':
		$Shop->availableWindow($_REQUEST['id']);
	break;
	
	case 'payment_info':
		$Shop->paymentInfo($_REQUEST['id']);
	break;
	
	case 'pnpop':
		if(UGROUP==2) exit;
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/pn_newinfo.tpl')); 
	break;
	
	case 'cancel_popup':
		if(UGROUP==2) exit;
		$GLOBALS['db']->Query("UPDATE " . PREFIX . "_benutzer SET PnPopup = '0' WHERE Id = '" . $_SESSION['benutzer_id'] . "'");
		$GLOBALS['tmpl']->assign('cancel_popup', 1); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/pn_newinfo.tpl')); 
	break;

	
// ===============================================================
// <<-- SHOPVARIANTE -->>
// ===============================================================
case 'shopvariant' : 
$sname = ' - '.$GLOBALS['config_vars']['order_shop_variant'];
	$sql = $GLOBALS['db']->Query("SELECT name, artoptions_descr FROM ".PREFIX."_shop_artoptions_cat WHERE id='".(int)$_REQUEST['id']."'");
	$row = $sql->fetchrow();
	$GLOBALS['tmpl']->assign('row', $row);
	$EOUT = $tmpl->fetch('shop/variants_popup.tpl');
break;

// ===============================================================
// ANSCHRIFT AENDERN
// ===============================================================
case 'changeadress':
	if(!@is_numeric(UID)){
		PutLog( "Adress Change: Failed - No Access!" , 1);
		echo '<script>window.close();</script>';
		exit;
		}
	
	$sql= $GLOBALS['db']->Query("SELECT * FROM ".PREFIX."_user WHERE uid = '".UID."'");
	$user = $sql->fetchrow();
	$GLOBALS['tmpl']->assign('user', $user);
	
	if($_REQUEST['save']==1){
		
		$body = $GLOBALS['config_vars']['shop_changeadress_prebody'];
		$body = str_replace('__USERID__', UID,$body);
		$body = str_replace('__USER__', $UNAME,$body);
		
		$thismail = new MIMEMail();
		$thismail->from_name = $pref['hpname'];
		$thismail->from_email = STANDARDMAIL;
		$thismail->subject = $GLOBALS['config_vars']['shop_adress_has_changed_subject_email'];
		$thismail->to = STANDARDMAIL;
		$thismail->headers();
		$thismail->addtextpart( false, $body . "\n" . $_POST['newadress'] . "\n\n" . $_POST['text']);
		$thismail->finish();
		$thismail->send();
		
		$body = $GLOBALS['config_vars']['shop_changeadress_ok'] . "\n------------------\n";
		$thismail = new MIMEMail();
		$thismail->from_name = $pref['hpname'];
		$thismail->from_email = STANDARDMAIL;
		$thismail->subject = $GLOBALS['config_vars']['shop_adress_has_changed_subject_uemail'];
		$thismail->to = $UMAIL;
		$thismail->headers();
		$thismail->addtextpart( false, $body . "\n" . $_POST['newadress'] . "\n\n" . $_POST['text']);
		$thismail->finish();
		$thismail->send();
	
		PutLog( "Request for Adress-Change: $UMAIL ($UNAME)" , 2);
		$GLOBALS['tmpl']->assign('ok', 1);
	}
	$sname = $GLOBALS['config_vars']['shop_adress_has_changed'];
	$EOUT = $tmpl->fetch('shop/changeadress.tpl');;
	
break;

// ===============================================================
// E-MAIL ÄNDERN
// ===============================================================
case 'emailnoaccess':
	if(!@is_numeric(UID))
	{
		PutLog( "E-Mail Change: Failed - No Access!" , 1);
		echo '<script>window.close();</script>';
		exit;
		}
		
	if($_REQUEST['save']==1)
	{
		@sleep(1);
		$error = '';
		$sql_check = $GLOBALS['db']->Query("SELECT email FROM ".PREFIX."_user WHERE uid != '".UID."' AND email = '".escs($_REQUEST['email'])."'");
		$row_check = $sql_check->fetchrow();
		
		$sql = $GLOBALS['db']->Query("SELECT uid,email,pass FROM ".PREFIX."_user WHERE uid = '".UID."' AND pass = '".md5(md5($_REQUEST['pass']))."'");
		$row = $sql->fetchrow();
		
		if(!ereg("^[ -._A-Za-zÀ-ÖØ-öø-ÿ0-9-]+(\.[_A-Za-zÀ-ÖØ-öø-ÿ0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$", $_REQUEST['email'])) $error[] = $GLOBALS['config_vars']['shop_newemail_emailwrong'];
		if($row_check->email != '') $error[] = $GLOBALS['config_vars']['shop_newemail_inuse'];
		if($row->pass != md5(md5($_REQUEST['pass']))) $error[] = $GLOBALS['config_vars']['shop_newemail_wpass'];
		
		if(!is_array($error)){
			$sql = $GLOBALS['db']->Query("UPDATE ".PREFIX."_user SET email='".escs($_REQUEST['email'])."' WHERE uid = '".UID."'");
			PutLog( "E-Mail Change: O.K. - ".escs($_POST['email'])."" , 2);
			echo '<script>window.opener.location.reload();window.close();</script>';
		} else {
			PutLog( "E-Mail Change: Failed - ".escs($_POST['email'])."" , 1);
			$GLOBALS['tmpl']->assign('error', $error);
		}
		
		
	}
	$sname = $GLOBALS['config_vars']['profile_changeemail'];
	$EOUT = $tmpl->fetch('user/changeemail.tpl');;
	
break;




// ===============================================================
// USER- SUCHE FUER PN
// ===============================================================
case 'searchuser':
	UserSerarchPn();
break;

case 'SKYPE':
	$row = $GLOBALS['db']->RowQuery("SELECT skype FROM ".PREFIX."_benutzer WHERE Id = '" . $_REQUEST['uid'] . "'");
	$sname = $GLOBALS['config_vars']['Profile_ScypeOpt'];
	$GLOBALS['tmpl']->assign('skype', $row->skype);
	$GLOBALS['tmpl']->assign('pagetitle_html', $sname);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/user/skype_popup.tpl')); 
break;

case 'ICQ':
	$row = $GLOBALS['db']->RowQuery("SELECT icq FROM ".PREFIX."_benutzer WHERE Id = '" . $_REQUEST['uid'] . "'");
	$sname = $GLOBALS['config_vars']['Profile_ICQOpt'];
	$GLOBALS['tmpl']->assign('icq', $row->icq);
	$GLOBALS['tmpl']->assign('pagetitle_html', $sname);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/user/icq_popup.tpl')); 
break;


case 'KOOBICODES':
	$sname = $GLOBALS['config_vars']['Help_KoobiCodes'];
	$GLOBALS['tmpl']->assign('pagetitle_html', $sname);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/help/koobicodes_popup.tpl')); 
break;

case 'securecheck':
function CheckScode($oext='',$valid='')
{
	$valid = 'false';
	$scode  = (isset($_REQUEST['scode']) && !empty($_REQUEST['scode'])) ? $_REQUEST['scode'] : '';
	
	if($scode!='') 
	{
	if($scode!=$_SESSION['comment_secure_result'])
		$valid = 'false';
	else
		$valid = 'true';
	}
	echo @$valid;
}

return CheckScode(@$_REQUEST['ext']);
break;

//=================================================================
// Forum - E-Mail-Versand fuer Benutzer
//=================================================================
case 'EMAIL':
	$error = '';
	$use_code = 1;
	
	$sname = $GLOBALS['config_vars']['SendEmail_Inf'];
	if(UGROUP == 2) 
	{
		$GLOBALS['tmpl']->assign('not_logged', 1);	
	} else {
		
		if(!isset($_REQUEST['mailsend']) && $use_code == 1)
		{
			 giveSecure();
		}
		
		$sql = $GLOBALS['db']->Query("SELECT * FROM ".PREFIX."_benutzer WHERE Id='$_REQUEST[uid]'");
		$row = $sql->fetchrow();
		
		if($row->Emailempfang != 1) $error = $GLOBALS['config_vars']['SendEmail_NotWanted'];
		
		$ignore = array();
		$sql_2 = $GLOBALS['db']->Query("SELECT IgnorierId FROM ".PREFIX."_ignorierliste WHERE BenutzerId='$_REQUEST[uid]'");
		
		while($row_2 = $sql_2->fetchrow()) @array_push($ignore, $row_2->IgnorierId);
		
		if(in_array(UID, $ignore)) $error = $GLOBALS['config_vars']['SendEmail_Blocked'];
		if(isset($_REQUEST['mailsend']) && $_REQUEST['mailsend'] == 1)
		{
			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(@!preg_match("/^[ -._A-Za-zÀ-ÖØ-öø-ÿ0-9-]+(\.[_A-Za-zÀ-ÖØ-öø-ÿ0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/", $_POST['email']))  $error .= $GLOBALS['config_vars']['RegE_wrongmail'] . "<br />";
			if(@$_REQUEST['subject']=='') $error .= $GLOBALS['config_vars']['No_Subject'] . "<br />";
			if(@$_REQUEST['body']=='') $error .= $GLOBALS['config_vars']['No_Message'];
					
			if($error)
			{
				$GLOBALS['tmpl']->assign('error', $error);
			} else {
				$message_footer = $GLOBALS['config_vars']['emailform_homepage_footer'];
				$message_footer = str_replace("__HOMEPAGEURL__", HPURL, $message_footer);
				$message_footer = str_replace("__USER__", UNAME, $message_footer);
				$subject = stripslashes($_REQUEST['subject']);
				$message = stripslashes($_REQUEST['body']);
				$message = badwordreplace($message);
				$from = str_replace("__HOMEPAGE__", $GLOBALS['settings']['Seitenname'], $GLOBALS['config_vars']['SendEmail_SubjectEmail']);
				$Koobi->koobi_mail($row->Email, stripslashes($message) . "\r\n" . $message_footer, $subject, $_POST['email'], $from, 'text', '', '');
				$_SESSION['scode'] = '';
			}
		}
	}
	
	$GLOBALS['tmpl']->assign('sname', $sname);
	$GLOBALS['tmpl']->assign('uid', $_REQUEST['uid']);
	$GLOBALS['tmpl']->assign('pagetitle_html', $sname);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/user/email_popup.tpl')); 
break;

//=================================================================
//=================================================================
case 'autowords':
	$sql = $GLOBALS['db']->Query("SELECT * FROM ".PREFIX."_glossar WHERE Id='".$_REQUEST['id']."'");
	$row = $sql->fetchrow();
	$sql = $GLOBALS['db']->Query("UPDATE ".PREFIX."_glossar SET Hits=Hits+1 WHERE Id='".$_REQUEST['id']."'");
	$sname = " - ". stripslashes($row->Wort);
	$GLOBALS['tmpl']->assign('word', kstripslashes($row->Wort));
	$GLOBALS['tmpl']->assign('text', autowords($row->Beschreibung));
	$GLOBALS['tmpl']->assign('pagetitle_html', $GLOBALS['config_vars']['Glossar_Title'] . $sname);
	$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/other/autowords.tpl')); 
break;

//=================================================================
//=================================================================
case 'inlineshots': 
	$GLOBALS['tmpl']->assign('img_id', $_REQUEST['img_id']);
	$output = $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gallery/inlineshot.tpl');
	$GLOBALS['tmpl']->assign('content', $output);
	define("OUTPUT", $output);
	define("TPL", "popup/inlineshot.tpl");
	
break;

//=================================================================
//=================================================================
case 'attachment':
	attachmentUpload();
break;

case 'delattach':
	attachmentDel($_GET['id'],$_GET['file']);
break;

// ================================================================================
//  <<-- Alle Poster des Threads anzeigen -->>
// ================================================================================
case 'showposter':
	if ($_REQUEST['tid'] != "")
	{
		$q_poster = "
		SELECT
		COUNT(u.Benutzername) AS ucount,
		u.Id as uid,
		u.Benutzername as uname
		FROM
		" . PREFIX . "_benutzer AS u,
		" . PREFIX . "_f_post AS p
		WHERE
		p.topic_id = " . $_REQUEST['tid'] . " AND
		p.uid = u.Id
		GROUP BY u.Benutzername
		";
		
		$r_poster = $GLOBALS['db']->Query($q_poster);
		
		$poster = array();
		while ($post = $r_poster->fetchrow()) $poster[] = $post;
		
		$GLOBALS['tmpl']->assign("poster", $poster);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/poster.tpl')); 
		
	} else {
		koobi_message('Global_NoPermission', 'Global_NoPermission_t', HOME_PATH . '/index.php?p=showforums&amp;area=' . AREA);
	}
break;


}
$MISC = 1;

?>