<?php
$action = "";
//echo '<pre>', var_export($_REQUEST, true), '</pre>';
$login_incomplete = false;
$login_failed = false;
$login_success = false;
if(isset($_REQUEST['action'])) $action = trim($_REQUEST['action']);
if (isset($action) && $action=="login") {
	
	$log_username = isset($_REQUEST['log_username']) ? trim($_REQUEST['log_username']) : '';
	$log_password = isset($_REQUEST['log_password']) ? trim($_REQUEST['log_password']) : '';
	
	if ($log_username<>"" && $log_password<>""){
		$log_username = mysql_real_escape_string(stripslashes($log_username));
		$log_password = mysql_real_escape_string(stripslashes($log_password));
		$query = "SELECT * FROM members WHERE shipmail = '$log_username' AND password = '$log_password' and kind_ind!='3'";
		//echo "<br/>".$query;
		$result = mysql_query($query);
		$NumberOfFields = mysql_num_rows($result);
		if ($NumberOfFields > 0){
			$rline = mysql_fetch_assoc($result);
            $line = array_map('stripslashes', $rline);
			//$logged=$username;
			//session_register('logged');
			$member_id = $line["member_id"];
			$_SESSION['member_id'] = $member_id;
			$_SESSION['member_fullname'] = trim($line['shipname'] . ' ' . $line['shipsurname']);
			$query = "UPDATE members SET logged=SYSDATE(), confirmed='yes' WHERE member_id='{$line['member_id']}'";
			$result = mysql_query($query);
            $login_success = true;
            $logmsg_id = $line_domain['SuccessMsg'];

		}
		else{
			$login_failed = true;
            $logmsg_id = $line_domain['FailedMsg'];
		}
	}
	else{
		$login_incomplete = true;
        $logmsg_id = $line_domain['InvalidMsg'];
	}
}

$logout = "";
if(isset($_REQUEST['logout'])) $logout = $_REQUEST['logout'];

if (isset($_REQUEST['logout']) && $_REQUEST['logout']=="yes"){
	$member_id = "";
	$_SESSION['member_id'] = '';
	unset($_SESSION['member_id']);
	$logmsg_id = $line_domain['LogoutMsg'];

    ob_end_clean();
    header("Location: " . $full_addon_uri);
}




if(isset($logmsg_id) && intval($logmsg_id) > 0) {
	$logmsg = '';
	if(intval($line_domain['site_is_new']) == 1) {
		$querymsg = "SELECT * FROM  main_article WHERE article_id = '$logmsg_id'";
		//echo $querymsg;
		$resultmsg = @mysql_query ($querymsg);
		if($resultmsg && mysql_num_rows($resultmsg) == 1) {
	
			$row = mysql_fetch_assoc($resultmsg);
			$middle_article_id = $row['article_id'];
			$logmsg_file = dirname(__FILE__) . "/../main_article/main_article.php";
			if(file_exists($logmsg_file)) {
				ob_start();
				require($logmsg_file);
				$logmsg = ob_get_contents();
				ob_end_clean();
			}
			else {
				echo $logmsg_file . ' does not exists';
			}
			
			unset($middle_article_id);
		}
	}
	else {
		$querymsg = "SELECT * FROM  article WHERE article_id = '$logmsg_id'";
		$resultmsg = mysql_query ($querymsg);
		$linemsg = mysql_fetch_assoc($resultmsg);
		$logmsg = '';
		
		if(strpos($linemsg['description'], 'articleX') !== false) {
			
		}
		
		if($linemsg["url"]<>""){
			$logmsg .= "<a href=\"{$linemsg["url"]}\""; 
			if($linemsg["_blank"]=="yes"){
				$logmsg .= " target=\"_blank\"";
			} 
			$logmsg .= ">";
			$logmsg .="<strong>"; 
			$logmsg .= $linemsg["title_en"]; 
			$logmsg .="</strong></a>"; 
		}
		else{
			if ($linemsg["active_title_en"]=="yes"){ 
				$logmsg .= '<h1 class="articleX">' . stripslashes($linemsg['title_en']) . '</h1>';
			}
			$logmsg .= '<div style="margin: 0 6px;">';
			$logmsg .= stripslashes($linemsg["description_en"]); 
			$logmsg .= '</div>';
		}
		
	}
	
	//echo $querymsg;
}

/*echo '<pre>', var_export($login_incomplete, true),'</pre>';
echo '<pre>', var_export($login_failed, true),'</pre>';
echo '<pre>', var_export($login_success, true),'</pre>';

echo $logmsg;*/

$_REQUEST['account_url'] = "my_account";
?>
