<?php
/**
* View user profile page (general, description, self-portrait, desired partner criteria, multimedia album, rating, tags...)
*
*
* @package DatingPro
* @subpackage User Mode
**/

include_once "./include/config.php";
include_once "./include/config_index.php";
include_once "./common.php";
include_once "./include/functions_index.php";
include_once "./include/functions_users.php";
include_once "./include/functions_auth.php";
include_once "./include/class.phpmailer.php";
include_once "./include/functions_mail.php";
include_once "./include/class.lang.php";
include_once "./include/class.percent.php";
include_once "./include/class.images.php";
GetLangContent("sms_notifications", $config["path_lang"].$lang_file[0]);

$user = auth_index_user();
if (!isset($_REQUEST['test_url']))
RefreshAccount($user);
$smarty->assign("sub_menu_num", '2');
$smarty->assign("my_left_menu", LeftNavigation());
$smarty->assign("group_adult_allow", CheckAdultAllow());

$sel = isset($_REQUEST["sel"]) ? $_REQUEST["sel"] : '';
////// if user status = 0
if(!$user[8]){
	AlertPage(GetRightModulePath(__FILE__));
}
GoogleAnalytics($config["google_analytics_activate"], $config["manual_tracker_activate"]);
GetPhoneUser();
unset ($_SESSION["search_pars"]);
IsFileAllowed($user[0], GetRightModulePath(__FILE__));
if (($user[5] == $_GET["login"] || $user[0] == $_GET["id"]) && $sel != "print" && $sel != "add_owner_comment") {
echo "<script>location.href='" . seo("myprofile", 1) . "'</script>";
}
$PHPmailer = new PHPMailer();

$multi_lang = new MultiLang($config, $dbconn);
///// default multilanguage field for select
$field_name = $multi_lang->DefaultFieldName();

//$profile_percent = new Percent($config, $dbconn, $user[0]);
$profile_percent2 = new PercentNew($config, $dbconn, $user[0]);

$act = isset($_GET["act"])?$_GET["act"]:"";
$id = isset($_GET["id"])? intval($_GET["id"]): (isset($_REQUEST["id_user"]) ? intval($_REQUEST["id_user"]) : 0);

if (isset($_GET["login"])) {
	if ($_GET["login"] == ''){

        }	
	else{
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$_GET["login"]."'");
		if ($rs->fields[0]) $id = $rs->fields[0];
		else exit;
	}
}
if ($id == 0 && $sel != "start_slide" && $sel != "map" && $sel != "check_rss" && $sel != "add_owner_comment")   echo "<script>location.href='" . $config["server"] . "/index.php'</script>";

if (($id != 0 && $id < 3) && (isset($_REQUEST["id_user"]) && $_REQUEST["id_user"]<3) && $sel != "map" && $sel != "add_owner_comment" && $sel != 'agreement') echo "<script>location.href='" . seo("index", 1) . "'</script>";///// check ins messages if user not guest

if($user[3] != 1){
	GetAlertsMessage();
	SetModuleStatistic(GetRightModulePath(__FILE__));

	$rs = $dbconn->Execute("select count_of_visits from ".PROFILE_VISIT_TABLE." where id_user = '".$id."' and id_visiter = '".$user[0]."'");
	if($rs->fields[0] > 0) {
		$rs = $dbconn->Execute("select if((UNIX_TIMESTAMP(NOW()) - MAX(UNIX_TIMESTAMP(visit_date)) -60*60)>0, 1, 0) as r from ".PROFILE_VISIT_TABLE." where id_user='".$id."' and id_visiter='".$user[0]."'");
		if ($rs->fields[0] == 1) SendNotice($id);
	} else {
		SendNotice($id);
	}
}
switch($sel){
	case "1": ShowAll($act); break;
	case "2": ListProfile(2,$act); break;
	case "3": ListProfile(3,$act); break;
	case "4": ListProfile(4,$act); break;
	case "5": ListProfile(5,$act); break;
	case "6": ListProfile(6,$act); break;

	case "map": 		ViewLocation(); break;
	case "vote":  		RateProfile(intval($_REQUEST["id"]),intval($_REQUEST["r"])); ListProfile(5); break;
	case "kiss":  		$res = SendKiss(); ListProfile(5,"",$res["err"]); break;
	case "print": 		PrintProfile(); break;
	case "ajax_image": 	UploadView('ajax'); break;
	case "upload_view": UploadView(); break;
	
	case "comment": 		$res = PostComment($_POST["id"],$_POST["message"]);ListProfile(5,"",$res); break;
	case "delcomment": 		DeleteComment(intval($_GET["cid"])); ListProfile(5); break;
	case "delete_owner_comment": DeleteOwnerComment(); break;
	case "add_owner_comment": AddOwnerComment(); break;
	
	case "addtag": 			AddTag(); break;
	case "deltag": 			DeleteTag(); break;
	case "addlist": 		$res = AddToHotList(); ListProfile(5); break;
	case "blacklist": 		$res = AddToBlackList(); ListProfile(5); break;
	case "delete_hotlist": 	$res = DeleteFromList(); ListProfile(5, "", $res); break;
	case "delete_blacklist": $res = DeleteFromBlackList(); ListProfile(5); break;
	
	case "agreement": 		Agreement(); break;
	case "agreement_win": 	AgreementWin(); break;

	case "start_slide": 	StartSlideShow(); break;
	case "start_play": 		StartAudioPlaying(); break;
	case "start_video": 	StartVideoPlaying(); break;
        case "check_rss" : Chech_Rss_user();break;
	
	default:  ListProfile(5); break;
}

function ShowAll($act){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $profile_percent2, $charset, $lang_code, $id, $lang_file, $settings;
	$file_name = seo("viewprofile");
	
	if($act != 'ajax'){
		$standalone = 1;
	}
	
	if($standalone){
		Banners(GetRightModulePath(__FILE__));
		IndexHomePage();
		LeftMenu();
		$smarty->assign("active_user_info", GetActiveUserInfo($user));
		GeneralTable();
	}
	
	$form["guest_user"] = $user[3];	
	$data["show_users_zipcode_str"] = $settings["show_users_zipcode_str"];
	$data["show_users_birthdate_str"] = $settings["show_users_birthdate_str"];

	$strSQL = "SELECT couple FROM ".USERS_TABLE." WHERE id='{$id}';";
	$rs = $dbconn->Execute($strSQL);
	$couple = $rs->fields[0];

	$search_type = isset($_GET["search_type"])?$_GET["search_type"]:"";
	
	$suffix = "id=".$id."&amp;search_type=".$search_type;
	$menu[1] = $config["server"]."/".$file_name."?sel=1&amp;".$suffix;
	$menu[2] = $config["server"]."/".$file_name."?sel=2&amp;".$suffix;
	$menu[3] = $config["server"]."/".$file_name."?sel=3&amp;".$suffix;
	$menu[4] = $config["server"]."/".$file_name."?sel=4&amp;".$suffix;
	$menu[5] = $config["server"]."/".$file_name."?sel=5&amp;".$suffix;
	$menu[6] = $config["server"]."/".$file_name."?sel=6&amp;".$suffix;
	$smarty->assign("menu", $menu);

	$smarty->assign("header", $lang["profile"]);
	$smarty->assign("button", $lang["button"]);
	$smarty->assign("script", "location");
	///////////////////

	$category = array();
	$strSQL = "SELECT id, name_for_lang, type, is_system, mandatory, position_text, elem_html, category, page_position, couple, tbl, val, page, page_position FROM ".ELEMENTS." WHERE page > 0 AND page_position > 0 ORDER BY page_position;";
	$rs = $dbconn->Execute($strSQL);
	$elements = array();
	if($rs->fields[0] != ""){
		$i = 0;
		while(!$rs->EOF){
			$elements[$i]["id"] = $rs->fields[0];
			$elements[$i]["name_for_lang"] = $rs->fields[1];
			$elements[$i]["type"] = $rs->fields[2];
			$elements[$i]["is_system"] = intval($rs->fields[3]);
			$elements[$i]["mandatory"] = intval($rs->fields[4]);
			$elements[$i]["position_text"] = $rs->fields[5];
			$elements[$i]["elem_html"] = $rs->fields[6];
			$elements[$i]["category"] = $rs->fields[7];
			if(!in_array($rs->fields[7], $category))
			$category[] = $rs->fields[7];
			$elements[$i]["page_position"] = $rs->fields[8];
			if($couple)
			$elements[$i]["couple"] = $rs->fields[9];
			else
			$elements[$i]["couple"] = 0;
			$elements[$i]["tbl"] = $rs->fields[10];
			$elements[$i]["val"] = $rs->fields[11];
			$elements[$i]["page"] = $rs->fields[12];
			$elements[$i]["page_position"] = $rs->fields[13];
			$rs->MoveNext();
			$i++;
		}
	}

	foreach($category as $key => $value){ // преобразуем smarty код в элементах в html
		switch($value){
			case "personal":
				PersonalTable($id);
				break; // --------------

			case "description":
				DescriptionTable($id);
				$cat[$value] = "data_2";
				break;
			case "personality":
				MyPersonalityTable($id);
				$cat[$value] = "data_4";
				break;

			case "portrait":
				MyPortraitTable($id);
				$cat[$value] = "data_5";
				break;

			case "interests":
				MyInterestsTable($id);
				$cat[$value] = "data_6";
				break;

			case "partner_criteria":
				MyCriteriaTable($id);
				$cat[$value] = "data_7";
				break;

			case "partner_interests":
				HisInterestsTable($id);
				$cat[$value] = "data_8";
				break;

			case "custom":
				CustomTable($id);
				$cat[$value] = "custom";
				break;
		}
	}
	$lang = $smarty->_tpl_vars["lang"];
    $lang = array_merge_recursive_simple($lang, GetLangContent("registration", $config["path_lang"].$lang_file[0], true));

	$elements = GetViewForElements($elements, $cat, $couple);
	foreach($elements as $key => $value){
		if($value["name_for_lang"] == "email"){
			unset($elements[$key]);
			continue;
		}
		if($elements[$key]["name_for_lang"] == 'phone'){
			unset($elements[$key]);
			continue;
		}
		if($elements[$key]["name_for_lang"] == 'zipcode' && !$settings["show_users_zipcode_str"]){
			unset($elements[$key]);
			continue;
		}
		if($elements[$key]["name_for_lang"] == 'date_birthday' && !$settings["show_users_birthdate_str"]){
			unset($elements[$key]);
			continue;
		}
		if($elements[$key]["name_for_lang"] == 'comments' && !$settings["show_users_comments"]){
			unset($elements[$key]);
			continue;
		}
	}

	foreach ($elements as $key => $row) {
		$pages[$elements[$key]['page']] = "";
		$couples[$key] = $elements[$key]['couple'];
		$page[$key]  = $elements[$key]['page'];
		$page_position[$key] = $elements[$key]['page_position'];
	}

	array_multisort($page, SORT_ASC, $couples, SORT_ASC, $page_position, SORT_ASC, $elements);
	unset($page, $page_position, $pages);


	$form['page'] = 1;
	$smarty->assign("form", $form);
	$smarty->assign("active_user_info", GetActiveUserInfo($user));


	$smarty->assign("elements", $elements);
	$smarty->assign("lang", $lang);

	header('Content-type: text/html; charset='.$charset);
	$smarty->assign("template_root", $config["index_theme_path"]);
	$smarty->assign("template_css_root", $config["index_theme_css_path"]);
	$smarty->assign("template_images_root", $config["index_theme_images_path"]);
	
	if($standalone){
		$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_table.tpl");
	}
	else{
		$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_view_new.tpl"); ///////////
	}
	
}

function recurr_strip_lang($in, $gl_out, &$out){
	foreach($in as $key=>$value){
		$tmp = $gl_out."[\"".$key."\"]";
		if(is_array($value)){
			recurr_strip_lang($value, $tmp, $out);
		}
		else{
			$out .= $tmp."='".stripslashes($value)."';\n";
		}
	}
}

function ListProfile($page=1, $act="", $err="", $sub_par="", $action="", $data=""){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $profile_percent2, $charset, $default_left, $lang_code, $settings, $servers;

	$file_name = seo("viewprofile", 1);
	$ajax = isset($_POST["ajax"])?intval($_POST["ajax"]):0;
	$id = isset($_GET["id"])?intval($_GET["id"]):0;
	$search_type = isset($_GET["search_type"])?$_GET["search_type"]:"";
	if (isset($_GET["login"])) {
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$_GET["login"]."'");
		if ($rs->fields[0]){
			$id = $rs->fields[0];
		}
		else {
			header('Location: '.$config["server"]);
			return;
		}
	}

	// mod_rewrite test from admin
	if (isset($_REQUEST["test_url"]) && $_REQUEST["test_url"] == 1) {
		echo "1";
		return ;
	}

	if ($act=="") {
		Banners(GetRightModulePath(__FILE__));
		IndexHomePage();
		LeftMenu();
		$smarty->assign("active_user_info", GetActiveUserInfo($user));
		GeneralTable();
		if( SearchLinkTable() == "guest_err"){
			$form["guest_user_err"] = $lang["err"]["guest_user_must_reg"];
			AlertPage(GetRightModulePath(__FILE__));
			return;
		}
	}

    $breadcrumbs = new BreadCrumbs();
	if ($user[3] == 0){
		$smarty->assign("abuse_link", array('id_user'=>$id, 'id_item'=>$id, 'item_type'=>'viewprofile', 'abuse_types_msg'=>$config_index['abuse_types_msg']));
        $breadcrumbs_page = $breadcrumbs->SetBreadCrumbs('viewprofile_user');
    }else{
        $breadcrumbs_page = $breadcrumbs->SetBreadCrumbs('viewprofile_guest');
    }
    if ($breadcrumbs_page)
        $smarty->assign("breadcrumbs_page", $breadcrumbs_page);
        
    $smarty->assign("guest",$user["3"]);
	switch($page){
		case 1:

			break;
		case 2:

			break;
		case 3:

			break;
		case 4:
			if ($sub_par=='') {
				if (isset($_GET["sub"])) {
					$sub_par = intval($_GET["sub"]);
				}
			}
			UploadTable($sub_par, $action, $data, $id, seo("viewprofile", 1));
			break;
		case 5:
			VotingTable($id,$search_type, 0, "viewprofile");
			TagsTable();
			PersonalTable($id);
			///////////////////////use_default_smiles start////////////////////
			if($config["use_default_smiles"]==1 ){
			$smarty->assign("smiles", $config["smiles"]);
			}else{
			$strSQL = "SELECT value, file, preg FROM ".SMILES."";
			$rs = $dbconn->Execute($strSQL);
			$smile = array();
			$i = 0;
				while(!$rs->EOF){
					$smile[$i]["value"] = $rs->fields[0];
					$smile[$i]["file"] = $rs->fields[1];
					$smile[$i]["preg"] = $rs->fields[2];
					$i++;
					$rs->MoveNext();
				}
			$smarty->assign("smiles", $smile);
			}
			$smarty->assign("use_default_smiles", $config["use_default_smiles"]);
			///////////////////////use_default_smiles stop////////////////////
			
			include_once "./include/class.wall_events.php";
			$events = new WallEvents($user, $config, $settings, $dbconn, $lang, $servers);
			$events_arr = $events->GetUserEvents('user_wall', $id);
			if(isset($events_arr['events'])){
				include_once "./include/class.comments.php";
				$comments = new Comments($user, $config, $settings, $dbconn, $smarty);
				foreach($events_arr['events'] as &$event_obj){
					if($event_obj['gid'] == 'wall'){
						$event_obj['comments_count'] = $comments->get_comments_count('wall', $event_obj['id']);
					}
				}
			}
			$smarty->assign('events', $events_arr);
			break;
	}


	if (isset($_GET['view']) && ($_GET['view']=='video')) {
		$form['view'] = $_GET['view'];
	}

	$form["page"] = intval($page);
	$form["err"] = $err;
	$form["guest_user"] = $user[3];
	$suffix = "id=".$id."&amp;search_type=".$search_type;
	
	$menu[1] = $file_name."?sel=1&amp;".$suffix;
	$menu[2] = $file_name."?sel=2&amp;".$suffix;
	$menu[3] = $file_name."?sel=3&amp;".$suffix;
	$menu[4] = $file_name."?sel=4&amp;".$suffix;
	$menu[5] = $file_name."?sel=5&amp;".$suffix;
	$menu[6] = $file_name."?sel=6&amp;".$suffix;
	
	if (isset($config['use_pilot_module_blog']) && ($config['use_pilot_module_blog']==1)) {
		$strSQL = " SELECT bt.id, bt.title, ut.login 
                            FROM ".BLOG_PROFILE_TABLE." bt
                            LEFT JOIN ".USERS_TABLE. " ut ON ut.id=bt.id_user
                            WHERE bt.id_user='".$id."' ";
		$rs = $dbconn->Execute($strSQL);
		if ($rs->fields[0]>0) {
			$title = str_replace(' ', '-', $rs->fields[1]);
			if ($config["use_seo_multilang"] && $config["use_global_seo"]) {
				$menu['blog'] = $config["site_root"]."/".$lang_code."/".$rs->fields[2]."/".$rs->fields[0]."-blog-".htmlspecialchars($title);
			} else {
				$menu['blog'] = $config["server"]."/".seo("blog")."?sel=view_user&id_blog=".$rs->fields[0];
			}     
		}	
	}
	$form["action"] = $file_name."?".$suffix;
	$form["suffix"] = $suffix;
	
	$smarty->assign("id", $id);
	$smarty->assign("ajax", $ajax);
	$smarty->assign("menu", $menu);
	$smarty->assign("form", $form);
	$smarty->assign("header", $lang["profile"]);
	$smarty->assign("button", $lang["button"]);
	$smarty->assign("script", "location");
    
	if ( isset($config['use_pilot_module_organizer']) && ( $config['use_pilot_module_organizer']==1 ) ) {
		$strSQL = "SELECT COUNT(*) FROM ".ORG_USER_LAYOUTS_TABLE." WHERE id_user='".intval($id)."' AND theme='{$config['color_theme']}';";
        $rs = $dbconn->Execute($strSQL);
		if ($rs->fields[0] > 0) {
			$file_name = $config["index_theme_path"].$config['index_theme_css_path']."/users/color_def_".intval($id).".css";
			if(file_exists($config["site_path"]."/".$file_name)){
				$smarty->assign("style", $file_name);
			}
		}
	}
	
	if ($act=="") {
		if (!isset($user_data)) {
			$user_data = PersonalTable($id);
		}
		$location_arr = array();
		if (isset($user_data["city"]) && trim($user_data["city"]) != "") {
			array_push($location_arr, $user_data["city"]);
		}
		if (isset($user_data["region"]) && trim($user_data["region"]) != "") {
			array_push($location_arr, $user_data["region"]);
		}
		if (isset($user_data["country"]) && trim($user_data["country"]) != "") {
			array_push($location_arr, $user_data["country"]);
		}
		if (sizeof($location_arr)>0) {
			$location = " - ".implode(", ", $location_arr);
		} else {
			$location = "";
		}

		filterMetaTagsViewprofile($user_data);
		
		$smarty->assign("lang", $lang);
		$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_table.tpl");
	} else {
		header('Content-type: text/html; charset='.$charset);
		$smarty->assign("template_root", $config["index_theme_path"]);
		$smarty->assign("template_css_root", $config["index_theme_css_path"]);
		$smarty->assign("template_images_root", $config["index_theme_images_path"]);
		$smarty->assign("id", $id);
		$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_view.tpl");
	}
	exit;
}

function PrintProfile(){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $lang_code, $lang_file, $settings;

	$id = isset($_GET["id"])?intval($_GET["id"]):0;
	if (isset($_GET["login"])) {
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$_GET["login"]."'");
		if ($rs->fields[0]) {
			$id = $rs->fields[0];
		} else {
			exit;
		}
	}

	$strSQL = "select u.login, uu.upload_path, s.site_path, s.server, uu.id, u.fname, u.sname, u.couple
							from ".USERS_TABLE." u
							LEFT JOIN ".USER_UPLOAD_TABLE." uu ON uu.id=u.icon_path
							left join ".SERVERS_TABLE." s on s.id_servers=u.id_servers
							where u.id = '".$id."'";
	$rs = $dbconn->Execute($strSQL);
	//$login = $rs->fields[0];
	$login = chooseUserName($rs->fields[0], $rs->fields[5]." ".$rs->fields[6]) ;	
	$site_path = $rs -> fields[2];
	$server = $rs -> fields[3];
    $couple = $rs->fields[7];
	//$dir = GetPath($id, $settings["photos_folder"]);
	$dir = GetImagePath($id, $rs->fields[4], $settings["photos_folder"]);
	if($rs->fields[1])
		$form["icon_path"] = $dir."thumb_".$rs->fields[1];

	$_GET["id"] = $id;

	$category = array();
	$strSQL = "SELECT id, name_for_lang, type, is_system, mandatory, position_text, elem_html, category, page_position, couple, tbl, val, page, page_position FROM ".ELEMENTS." WHERE page > 0 AND page_position > 0 AND name_for_lang!='email' ORDER BY page_position;";
	$rs = $dbconn->Execute($strSQL);
	$elements = array();
	if($rs->fields[0] != ""){
		$i = 0;
		while(!$rs->EOF){
			$elements[$i]["id"] = $rs->fields[0];
			$elements[$i]["name_for_lang"] = $rs->fields[1];
			$elements[$i]["type"] = $rs->fields[2];
			$elements[$i]["is_system"] = intval($rs->fields[3]);
			$elements[$i]["mandatory"] = intval($rs->fields[4]);
			$elements[$i]["position_text"] = $rs->fields[5];
			$elements[$i]["elem_html"] = $rs->fields[6];
			$elements[$i]["category"] = $rs->fields[7];
			if(!in_array($rs->fields[7], $category))
			$category[] = $rs->fields[7];
			$elements[$i]["page_position"] = $rs->fields[8];
			if($couple)
				$elements[$i]["couple"] = $rs->fields[9];
			else
				$elements[$i]["couple"] = 0;
			$elements[$i]["tbl"] = $rs->fields[10];
			$elements[$i]["val"] = $rs->fields[11];
			$elements[$i]["page"] = $rs->fields[12];
			$elements[$i]["page_position"] = $rs->fields[13];

			$rs->MoveNext();
			$i++;
		}
	}

	foreach($category as $key => $value){ // преобразуем smarty код в элементах в html
		switch($value){
			case "personal":
				PersonalTable($id);
				break; // --------------

			case "description":
				DescriptionTable($id);
				$cat[$value] = "data_2";
				break;
			case "personality":
				MyPersonalityTable($id);
				$cat[$value] = "data_4";
				break;

			case "portrait":
				MyPortraitTable($id);
				$cat[$value] = "data_5";
				break;

			case "interests":
				MyInterestsTable($id);
				$cat[$value] = "data_6";
				break;

			case "partner_criteria":
				MyCriteriaTable($id);
				$cat[$value] = "data_7";
				break;

			case "partner_interests":
				HisInterestsTable($id);
				$cat[$value] = "data_8";
				break;

			case "custom":
				CustomTable($id);
				$cat[$value] = "custom";
				break;
		}
	}

	$lang = $smarty->_tpl_vars["lang"];
    $lang = array_merge_recursive_simple($lang, GetLangContent("registration", $config["path_lang"].$lang_file[0], true));

	$elements = GetViewForElements($elements, $cat, $couple);

	foreach ($elements as $key => $row) {
		$pages[$elements[$key]['page']] = "";
		$couples[$key] = $elements[$key]['couple'];
		$page[$key]  = $elements[$key]['page'];
		$page_position[$key] = $elements[$key]['page_position'];
	}

	array_multisort($page, SORT_ASC, $couples, SORT_ASC, $page_position, SORT_ASC, $elements);
	unset($page, $page_position, $pages);

	$form['page'] = 1;
	$smarty->assign("elements", $elements);

    $lang = array_merge_recursive_simple($lang, GetLangContent("registration", $config["path_lang"].$lang_file[0], true));

	$smarty->assign("lang", $lang);


	$form["page"] = "print";
	$lang["main_title"] = $login;

	$smarty->assign("form", $form);
	$smarty->assign("header", $lang["profile"]);
	$smarty->assign("button", $lang["button"]);
	$smarty->assign("alt", $lang["alt"]);


	$smarty->assign("template_root", $config["index_theme_path"]);
	$smarty->assign("template_css_root", $config["index_theme_css_path"]);
	$smarty->assign("template_images_root", $config["index_theme_images_path"]);
	$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_print.tpl");

	exit;
}

// ---------------------------- Table Functions -------------------------------- //
function SearchLinkTable(){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $multi_lang, $field_name, $settings;
	$file_name = seo("viewprofile", 1);
	$id = isset($_GET["id"])?intval($_GET["id"]):0;
	$search_type = isset($_GET["search_type"])?$_GET["search_type"]:"";
	if (isset($_GET["login"])) {
		$login = FormFilter($_GET["login"]);
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$login."'");
		if ($rs->fields[0]) $id = $rs->fields[0];
		else exit;
	}

	//// if user is guest
	if($user[3]==1){
		$guest_profile_limit = $settings['guest_profile_limit'];
		$used_lim = isset($_SESSION["guest_profile_limit"])?count($_SESSION["guest_profile_limit"]):0;
		if( ($used_lim < $guest_profile_limit) || ( ($used_lim == $guest_profile_limit)  && $_SESSION["guest_profile_limit"][$id]==1) ){
			$_SESSION["guest_profile_limit"][$id] = 1;
		}
		if( ($used_lim > $guest_profile_limit) || ( ($used_lim == $guest_profile_limit)  && $_SESSION["guest_profile_limit"][$id]==0) ){
			return "guest_err";
		}
	}

	///////// insert entry in profile_visit table there
	if(($user[0] != 1) && ($user[0] != 2)){
        $rs = $dbconn->Execute("select count_of_visits from ".PROFILE_VISIT_TABLE." where id_user = '".$id."' and id_visiter = '".$user[0]."'");
    	if($rs->fields[0] > 0)
    	$strSQL= "UPDATE ".PROFILE_VISIT_TABLE." SET  count_of_visits = count_of_visits+1, visit_date='".date("Y-m-d H:i:s")."'  WHERE id_user ='".$id."' AND id_visiter = '".$user[0]."' ";
    	else
    	$strSQL= "INSERT INTO ".PROFILE_VISIT_TABLE." (id_user, id_visiter, visit_date, count_of_visits) VALUES ( '".$id."', '".$user[0]."', '".date("Y-m-d H:i:s")."', '1')";
    	$dbconn->Execute($strSQL);
    }
	///// next/previous/back links
	$id_arr = isset($_SESSION["id_arr"])?array_values($_SESSION["id_arr"]):array();
	$id_couple_arr = isset($_SESSION["id_couple_arr"])?$_SESSION["id_couple_arr"]:array();
	$id_couple = array_search($id, $id_couple_arr);
	$nav["count"] = count($id_arr);
	if(count($id_arr)>0){
		foreach ($id_arr as $key => $value) {
			if($value == $id || ($id_couple !== false && $value == $id_couple)){
				$curent_key = $key;
				$prev_key = $key-1;
				$next_key = $key+1;
				break;
			}
		}                
		if(isset($curent_key)){
			switch($search_type){
				case "q": $search_file = seo("quick_search")."?par=back&amp;sel=search"; break;
				case "q_new": $search_file = seo("quick_search")."?par=back&amp;sel=search_new"; break;
				case "q_h": $search_file = seo("quick_search")."?par=back&amp;sel=search_h"; break;
				case "q_on": $search_file = seo("quick_search")."?par=back&amp;sel=search_on"; break;
				case "q_name": $search_file = seo("quick_search")."?par=back&amp;sel=search_name"; break;
				case "q_bd": $search_file = seo("quick_search")."?par=back&amp;sel=search_bd"; break;
				case "q_keyword": $search_file = seo("quick_search")."?par=back&amp;sel=search_keyword"; break;
				case "q_tag": $search_file = seo("quick_search")."?par=back&amp;sel=search_tag"; break;
				case "q_top": $search_file = seo("quick_search")."?par=back&amp;sel=search_top"; break;
				case "a": $search_file = seo("advanced_search")."?par=back&amp;sel=search"; break;
				case "v": $search_file = seo("visit_my_page")."?par=back&amp;sel=search"; break;
				case "p": $search_file = seo("perfect_match")."?par=back&amp;sel=search"; break;
				case "h": $search_file = seo("hotlist")."?par=back&amp;sel=search"; break;
				case "b": $search_file = seo("blacklist")."?par=back&amp;sel=search"; break;
				case "ki": $search_file = seo("kisses")."?par=i"; break;
				case "kme": $search_file = seo("kisses")."?par=me"; break;
				case "mt": $search_file = seo("meet_them")."?par=back&amp;sel=search"; break;
				case "mm": $search_file = seo("meet_me")."?par=back&amp;sel=search"; break;
				default: $search_file = seo("quick_search")."?par=back&amp;sel=search";
			}
			$page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
			//$nav["curent_key"] = $nav["count"]-1-$prev_key;
			$nav["curent_key"] = $curent_key+1;
			if ($user[3] != 1) $nav["back_link"] = $config["server"]."/".$search_file."&amp;page=".$page;
		}
		if(isset($prev_key) && isset($id_arr[$prev_key]) && $id_arr[$prev_key] !=0){
			if ($user[3] != 1) $nav["prev_link"] = $file_name."?id=".$id_arr[$prev_key]."&amp;search_type=".$search_type."&amp;page=".$page;
		}
		if(isset($next_key) && isset($id_arr[$next_key]) && $id_arr[$next_key] !=0){
			if ($user[3] != 1) $nav["next_link"] = $file_name."?id=".$id_arr[$next_key]."&amp;search_type=".$search_type."&amp;page=".$page;
		}
		$smarty->assign("search_link", $nav);
	}

	return "";
}

function GeneralTable(){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $multi_lang, $field_name, $id, $settings;
	
	
	$search_type = isset($_GET["search_type"])?$_GET["search_type"]:"";
	if (isset($_GET["login"])) {
		$login = FormFilter($_GET["login"]);
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$login."'");
		if ($rs->fields[0]) $id = $rs->fields[0];
		else exit;
	}
	$profile_percent2 = new PercentNew($config, $dbconn, $id);

	$suffix = "&amp;id=".$id;
	if ($search_type) $suffix .= "&search_type=".$search_type;

	if (isset($settings["use_pilot_module_webrecorder"]) && $settings["use_pilot_module_webrecorder"]) {
		$rs = $dbconn->Execute("select count(*) from ".UP_RECORDER_RECORDS_TABLE." where id_user='".$id."' and status='approved'");
		if($rs->fields[0]>0) {
			$data["webrecorder_player"] = $config["server"]."/webrecorder/wr.php?type=player&amp;user=".$id;
			$rs = $dbconn->Execute("select value from ".UP_RECORDER_SETTINGS_TABLE." where name = 'videosize'");
			$settings["videosize"] = $rs->fields[0];
			$data["webrecorder_width"] = 180;
			$data["webrecorder_height"] = 280;
			if( $settings["videosize"] > 1 ) {
				$data["webrecorder_width"] = ($settings["videosize"] == 2) ? 340 : 660;
				$data["webrecorder_height"] = ($settings["videosize"] == 2) ? 400 : 640;
			}
		}
	}
	$images_obj = new Images($dbconn, $lang);

	///// icon
	$strSQL = "select a.icon_path, s.site_path, s.server
				from ".USERS_TABLE." a
				left join ".SERVERS_TABLE." s on s.id_servers=a.id_servers
				where a.id='".$id."' ";			
	$rs = $dbconn->Execute($strSQL);
	if ($rs->fields[0] == 0) $where = "";
	else $where =  "AND uu.id=a.icon_path";
	
	$strSQL_upload = "SELECT id FROM ".USER_UPLOAD_TABLE." WHERE id_user = ".$id;
	$rs_upload = $dbconn->Execute($strSQL_upload);
	if ($rs_upload->RowCount() == 0){
		$strSQL_2 = "SELECT a.login, a.fname, a.sname, s.site_path, s.server 
				FROM ".USERS_TABLE." a
				LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=a.id_servers 
				WHERE a.id='".$id."' ".$where;
	}
	else{
		$strSQL_2 = "SELECT uu.upload_path, uu.id, a.login, a.fname, a.sname, s.site_path, s.server 
				FROM ".USER_UPLOAD_TABLE." uu 
				LEFT JOIN ".USERS_TABLE." a ON a.id=uu.id_user
				LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers AND s.id_servers=a.id_servers 
				WHERE uu.id_user='".$id."' ".$where;
	}
	$rs = $dbconn->Execute($strSQL_2);
	$row = $rs->GetRowAssoc(false);

	$site_path = $row["site_path"];
	$server = $row["server"];
	$data['name'] = chooseUserName($row["login"], $row["fname"]." ".$row["sname"]);	
	
	//$dir = GetPath($id, $settings["photos_folder"]);
	$dir = GetImagePath($id, $row["id"], $settings["photos_folder"]);
	if ($row["upload_path"] && $where != "") {		
		$icon_path = $row["upload_path"];
		if($icon_path){
			$data["icon_path"] = $dir."big_thumb_".$icon_path;
			$icon_count = 1;
		} else {
			$icon_count = 0;
		}
	} else {
		if(is_file($config['site_path'].$config["index_theme_path"].$config["index_theme_images_path"]."/big_".$settings["photos_default"])){
			$data["icon_path"] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/big_".$settings["photos_default"];
		}else{
			$data["icon_path"] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/".$settings["photos_default"];
		}
	}		
	////// is user a friend? get allow array
    if($couple > 0) $where_couple_hot = " or id_friend='".$couple."'";
	$rs = $dbconn->Execute("select count(id) from ".HOTLIST_TABLE." where id_user='".$id."' and (id_friend='".$user[0]."' $where_couple_hot)");
	if($rs->fields[0]>0){
		$allow = " and allow in (1, 2, 3)"; /// select uploads for all type permissions(guest, user, friend)
	}elseif($user[3] == 0 && $user[0]>0){ ////// user registerd
		$allow = " and allow in (1, 2)";
	}else{
		$allow = " and allow =1";
	}

	$i=0;
	$rs = $dbconn->Execute("SELECT uu.id, uu.upload_path, uu.allow, uu.upload_type, s.site_path, s.server, uu.id_album, uu.is_adult 
                FROM ".USER_UPLOAD_TABLE." uu
                LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers
                WHERE uu.id_user='".$id."' AND uu.status='1' ".$allow." order by uu.upload_type");	
	while(!$rs->EOF){
		$row = $rs->GetRowAssoc(false);
		$db_upload[$row["upload_type"]][$i]["id"] = $row["id"];
		$db_upload[$row["upload_type"]][$i]["id_album"] = $row["id_album"];
		$db_upload[$row["upload_type"]][$i]["file_path"] = $row["upload_path"];
		$db_upload[$row["upload_type"]][$i]["site_path"] = $row["site_path"];
		$db_upload[$row["upload_type"]][$i]["server"] = $row["server"];
		$db_upload[$row["upload_type"]][$i]["is_adult"] = $row["is_adult"];
		$rs->MoveNext(); $i++;
	}
	$i = 0;
	
	if(isset($db_upload["f"]) && count($db_upload["f"])){
		foreach($db_upload["f"] as $key=>$photo){
			$data["main_thumb_photo_path"][$i]["is_adult"] = $photo["is_adult"];	
			if ($data["main_thumb_photo_path"][$i]["is_adult"] == 1) {
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["adult_allow"] = CheckAdultAllow();
					$data["thumb_photo_path"][$i]["path"] = $photo["server"].$config["index_theme_path"].$config["index_theme_images_path"]."/thumb_".$settings["icon_adult_default"];
					$data["thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					if ($data["thumb_photo_path"][$i]["adult_allow"])
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
					else
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"]."&allow_no=1";
				}
				if(strlen($photo["file_path"])){
					$data["main_thumb_photo_path"][$i]["adult_allow"] = CheckAdultAllow();
					$data["main_thumb_photo_path"][$i]["path"] = $photo["server"].$config["index_theme_path"].$config["index_theme_images_path"]."/main_thumb_".$settings["icon_adult_default"];
					$data["main_thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["main_thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["main_thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					if ($data["main_thumb_photo_path"][$i]["adult_allow"]) {
						$data["main_thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
					}
					else{
						$data["main_thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"]."&allow_no=1";
					}
				}
				if(strlen($photo["file_path"])){
					$data["big_thumb_photo_path"][$i]["adult_allow"] = CheckAdultAllow();
					$data["big_thumb_photo_path"][$i]["path"] = $photo["server"].$config["index_theme_path"].$config["index_theme_images_path"]."/thumb_".$settings["icon_adult_default"];
					$data["big_thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["big_thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["big_thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					if ($data["big_thumb_photo_path"][$i]["adult_allow"])
						$data["big_thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
					else
						$data["big_thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"]."&allow_no=1";
				}
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["sizes"] = $images_obj->GetResizeParametrsStr($photo["server"].$config["index_theme_path"].$config["index_theme_images_path"]."/".$settings["icon_adult_default"]);
					$data["thumb_photo_path"][$i]["adult_allow"] = CheckAdultAllow();
					$data["thumb_photo_path"][$i]["path"] = $photo["server"].$config["index_theme_path"].$config["index_theme_images_path"]."/".$settings["icon_adult_default"];
					$data["thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					if ($data["thumb_photo_path"][$i]["adult_allow"])
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
					else
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"]."&allow_no=1";
				}
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["id_user"] =  $id;
					$i++;
				}				
			} else {
				//$dir = GetPath($id, $settings["photos_folder"]);
				$dir = GetImagePath($id, $photo["id"], $settings["photos_folder"]);
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["path"] =  $dir."thumb_".$photo["file_path"];
					$data["thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					if ($data["thumb_photo_path"][$i]["adult_allow"])
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
					else
						$data["thumb_photo_path"][$i]["view_link"]["str"] = "sel=agreement_win&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"]."&allow_no=1";
				}
				if(strlen($photo["file_path"])){
					$data["main_thumb_photo_path"][$i]["path"] =  $dir."main_thumb_".$photo["file_path"];
					$data["main_thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["main_thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["main_thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					$data["main_thumb_photo_path"][$i]["view_link"]["str"] = "sel=start_slide&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
				}
				if(strlen($photo["file_path"])){
					$data["big_thumb_photo_path"][$i]["path"] =  $dir."big_thumb_".$photo["file_path"];
					$data["big_thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["big_thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["big_thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					$data["main_thumb_photo_path"][$i]["view_link"]["str"] = "sel=start_slide&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
				}
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["path"] =  $dir.$photo["file_path"];
					$data["thumb_photo_path"][$i]["sizes"] = $images_obj->GetResizeParametrsStr($dir.$photo["file_path"]);
					$data["thumb_photo_path"][$i]["id"] =  $photo["id"];
					$data["thumb_photo_path"][$i]["id_album"] =  $photo["id_album"];
					$data["thumb_photo_path"][$i]["view_link"]["file"] = $config["server"]."/".seo("viewprofile");
					$data["main_thumb_photo_path"][$i]["view_link"]["str"] = "sel=start_slide&id_user=".$id."&type=f&id_item=".$photo["id_album"]."&id_subitem=".$photo["id"];
				}
				if(strlen($photo["file_path"])){
					$data["thumb_photo_path"][$i]["id_user"] =  $id;
					$i++;
				}
			}			
		}
	}
	//$data["big_photo_count"] = (isset($data["big_thumb_photo_path"])?count($data["big_thumb_photo_path"]):0)+$icon_count;
	$data["big_photo_count"] = (isset($data["big_thumb_photo_path"])?count($data["big_thumb_photo_path"]):0);
	$data["photo_count"] = (isset($db_upload["f"])?count($db_upload["f"]):0)+$icon_count;
	$data["viewf_link"]= $config["server"]."/".seo("viewprofile")."?sel=4".$suffix;
	$data["audio_count"] = isset($db_upload["a"])?count($db_upload["a"]):0;
	$data["viewa_link"]= $config["server"]."/".seo("viewprofile")."?sel=4".$suffix;
	$data["video_count"] = isset($db_upload["v"])?count($db_upload["v"]):0;
	$data["viewv_link"]= $config["server"]."/".seo("viewprofile")."?sel=4&sub=10&action=4&id_album=".(isset($_GET['id_album'])?intval($_GET['id_album']):0)."&id_v=".(isset($_GET['id_v'])?intval($_GET['id_v']):0).$suffix;

	$data["login"] = $user[5];
    
    $couple = CheckCouple($user[0]);
    if($couple > 0){
        $where_couple = "or z.id_user='".$couple."'";
        $where_couple_hot = "or h.id_user='".$couple."'";
    }else
        $where_couple_hot = $where_couple = "";

	$strSQL = "Select a.login, b.name as country, b.seo_link as seo_country, c.name as city, c.seo_link as seo_city, r.name as region, r.seo_link as seo_region, a.date_birthday as birthday, DATE_FORMAT(a.date_last_seen,'".$config["date_format"]."')  as date_last_login, a.gender, h.id_friend, z.id_enemy, e.id_user as session, a.phone
  from ".USERS_TABLE." a
  left join ".COUNTRY_SPR_TABLE." b on b.id=a.id_country
  left join ".CITY_SPR_TABLE." c on c.id=a.id_city
  left join ".ACTIVE_SESSIONS_TABLE." e on a.id=e.id_user
  left join ".HOTLIST_TABLE." h on a.id=h.id_friend and (h.id_user='".$user[0]."' $where_couple_hot)
  left join ".BLACKLIST_TABLE." z on a.id=z.id_enemy and (z.id_user='".$user[0]."' $where_couple)
  left join ".REGION_SPR_TABLE." r on r.id=a.id_region
  where a.id='".$id."'";
	$rs = $dbconn->Execute($strSQL);
	$row = $rs->GetRowAssoc(false);
	$data["id"] = $id;
	$data["login"] = $row["login"];
	$data["phone"] = $row["phone"];
	if ($data["phone"] != "") {
		$data["call_link"] = $config["server"]."/".seo("voip_call")."?sel=rate&id_user=".$id;
		$strSQL = "SELECT status FROM ".VOIP_REQUEST." WHERE id_user_to='".$id."' AND id_user_from='".$user[0]."'";
		$res = $dbconn -> Execute($strSQL);
		if ($res -> fields[0]) {
			if ($res -> fields[0] == "yes") {
				$data["phone"] = $lang["voip"]["call_request"];
				$data["phone_link"] = "href = '".$data["call_link"]."'";
			} elseif ($res -> fields[0] == "no") {
				$data["phone"] = $lang["voip"]["call_request_send"];
				$data["phone_link"] = "onclick=\"SendVoipRequest(".$id.")\"";
			} else {
				$data["phone"] = "";
				$data["phone_link"] = "";
			}
		} else {
			$data["phone"] = $lang["voip"]["call_request_send"];
			$data["phone_link"] = "onclick=\"SendVoipRequest(".$id.")\"";
		}
	}
	if ($settings['use_global_seo']) {
		$data["seo_country"] = $row["seo_country"];
		$data["seo_region"] = $row["seo_region"];
		$data["seo_city"] = $row["seo_city"];
	}
	$data["country"] = stripslashes($row["country"]);
	$data["region"] = stripslashes($row["region"]);
	$data["city"] = stripslashes($row["city"]);
	$data["age"] = AgeFromBDate($row["birthday"]);
	if ($settings["show_users_connection_str"])
        $data["last_login"] = $row["date_last_login"];
	if(isset($lang["gender"][$row["gender"]])){
		$data["gender"] = $lang["gender"][$row["gender"]];
	}
	$data["status"] = $row["session"]?$lang["status"]["on"]:$lang["status"]["off"];

	/// get groups
	$sub_strSQL = "Select a.name from ".USER_GROUP_TABLE." b left join ".GROUPS_TABLE." a on a.id=b.id_group where b.id_user='".$id."'";
	$sub_rs = $dbconn->Execute($sub_strSQL);
	$groups_arr = array();
	while(!$sub_rs->EOF){
		array_push($groups_arr, $sub_rs->fields[0]);
		$sub_rs->MoveNext();
	}
	if(is_array($groups_arr) && count($groups_arr)>0 && $settings["show_users_group_str"] == 1)
	$data["group"] = implode(",", $groups_arr);
	//links
	$data["email_link"] = $config["server"]."/".seo("mailbox")."?sel=fs".$suffix;
	$data["sendfriend_link"] = $config["server"]."/".seo("send_friend")."?sel=send&id_user=".$id;
	$data["kiss_link"] = $settings["use_kiss_types"] ? $config["server"]."/".seo("send_kiss")."?sel=send&amp;id_user=".$id : $config["server"]."/".seo("viewprofile")."?sel=kiss".$suffix;
	$data["gift_link"] = $config["server"]."/giftshop.php?sel=users_add&id_user=".$id;
	$data["ecard_link"] = $config["server"]."/".seo("ecards")."?sel=user_add&id_user=".$id;
	$data["print_link"] = $config["server"]."/".seo("viewprofile")."?sel=print&id=".$id;

	if ($user[0] != 2){
		if(intval($row["id_friend"])==0) {
			$data["addfriend_link"] = $config["server"]."/viewprofile.php?sel=addlist".$suffix;		
		}
		if(intval($row["id_enemy"])==0){
			$data["blacklist_link"] = $config["server"]."/viewprofile.php?sel=blacklist".$suffix;
		}
		$data["hotlisted"] = $row["id_friend"];
		$data["friend_request"] = 0;
		if ($data["hotlisted"] != 0){
			$strSQL = "SELECT id_user FROM ".HOTLIST_TABLE." WHERE id_friend IN('{$user[0]}', '{$user['cid']}') AND id_user='{$id}'";
			$data["friend_request"] = intval($dbconn->GetOne($strSQL)) ? 0 : 1;
			$data["hotlist_delete"] = $config["server"]."/viewprofile.php?sel=delete_hotlist".$suffix;
		}
		
		$data["blacklisted"] = $row["id_enemy"];
		if ($data["blacklisted"] != 0){
			$data["blacklist_delete"] = $config["server"]."/viewprofile.php?sel=delete_blacklist".$suffix;	
		}
			
		$data["use_friend_types"] = $settings["use_friend_types"];
	}
	//$data["rss_link"] = $config["server"]."/rss.php?user_name=".$data["login"]."&amp;id_user=".$user[0]."&amp;language_code=".$config["default_lang"];
        $data["rss_link"] = "Check_rss_user('".$data["login"]."')";
	$data["rss_title"] = str_replace("[user]", $data["login"], $lang["rss"]["chanel_title"]);

	$data["show_users_connection_str"] = $settings["show_users_connection_str"];
	$data["show_users_group_str"] = $settings["show_users_group_str"];
	$data["use_kiss_types"] = $settings["use_kiss_types"];
	
	$data["show_horoscope"] = $settings["use_horoscope_feature"];

	$data["show_horoscope"] = GetSiteSettings("use_horoscope_feature");

	$rs = $dbconn->Execute("select DATE_FORMAT(date_birthday,'%m'), DATE_FORMAT(date_birthday,'%d') from ".USERS_TABLE." where id='".$id."'");
	$birth_month = $rs->fields[0];
	$birth_day = $rs->fields[1];
	$sign = 0;
	$rs = $dbconn->Execute("select name from ".HOROSCOPE_SIGNS_TABLE." where DATE_FORMAT(date_start,'%m')=".$birth_month." and DATE_FORMAT(date_start,'%d')<=".$birth_day);
	if ($rs->fields[0]) {
		$sign = $rs->fields[0];
	} else {
		$rs = $dbconn->Execute("select name from ".HOROSCOPE_SIGNS_TABLE." where DATE_FORMAT(date_end,'%m')=".$birth_month." and DATE_FORMAT(date_end,'%d')>=".$birth_day);
		$sign = $rs->fields[0];
	}
	if(isset($lang["horoscope"][$sign]["name"])){
		$data["horoscope_sign"] = $lang["horoscope"][$sign]["name"];
	}
	$data["horoscope_link"] = $config["server"]."/".seo("horoscope")."?sel=view&amp;sign=".$sign;

	if ($data["city"]){
		$rs = $dbconn->Execute("SELECT b.lat, b.lon FROM ".USERS_TABLE." a, ".CITY_SPR_TABLE." b WHERE a.id='".$id."' AND a.id_city=b.id ");
		$data["view_on_map"] = $config["server"]."/".seo("viewprofile")."?sel=map&amp;lat=".$rs->fields[0]."&amp;lon=".$rs->fields[1];
	}
	if ($config["voipcall_feature"]){
		$data["call_link"] = $config["server"]."/".seo("voip_call")."?sel=rate&amp;id_user=".$id;
	}
	$data["complete"] = $profile_percent2->GetAllPercent();
	$place = GetUserRatingPlace($id);
	if ($place != null) {
		$data['place'] = $place;
	}
	
	$smarty->assign("settings", $settings);

	$smarty->assign("data", $data);
	return;
}

function UploadView($par=''){
	global $smarty, $dbconn, $config, $config_index, $config_admin, $lang, $user, $id, $settings;
	IndexHomePage();

	$id_file = intval($_GET["id_file"]);

	$strSQL="UPDATE ".USER_UPLOAD_TABLE." SET views=views+1 WHERE id = '".$id_file."' ";
	$res = $dbconn -> Execute($strSQL);

	if ($par=='') {						//	0			1			2				3				4			5		6				7					8			9			10
		$rs = $dbconn->Execute(" SELECT a.upload_path, b.login, a.upload_type, a.user_comment,a.id_album, a.id_user, b.date_birthday, c.name as country, a.is_adult, s.site_path, s.server
                  FROM ".USER_UPLOAD_TABLE." a
                  lEFT JOIN ".USERS_TABLE." b ON a.id_user = b.id
                  LEFT JOIN ".COUNTRY_SPR_TABLE." c ON c.id=b.id_country
                  LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=a.id_servers
                  WHERE a.id='".$id_file."' AND a.status='1' ");
		$data["upload_type"] = $rs->fields[2];
		$data["user_comment"] = stripslashes($rs->fields[3]);
		$data["file_name"] = $rs->fields[0];
		$data["id_album"] = $rs->fields[4];
		$data["login"] = stripslashes($rs->fields[1]);
		$data["age"] = AgeFromBDate($rs->fields[6]);
		$data["country"] = stripslashes($rs->fields[7]);
		$data["is_adult"] = $rs->fields[8];
		$data["site_path"] = $rs -> fields[9];
		$data["server"] = $rs -> fields[10];
		$data["not_user"] = 1;
		$id = $rs->fields[5];
        
        $couple = CheckCouple($user[0]);
        if($couple > 0) $where_couple = " or id_friend='".$couple."' ";
        else $where_couple = "";
		$rs = $dbconn->Execute("select count(*) from ".HOTLIST_TABLE." where id_user='".$id."' and (id_friend='".$user[0]."' $where_couple)");
		if($rs->fields[0]>0){
			$allow = " and allow in (1, 2, 3)"; /// select uploads for all type permissions(guest, user, friend)
		}elseif($user[3] == 0 && $user[0]>0){ ////// user registerd
			$allow = " and allow in (1, 2)";
		}else{
			$allow = " and allow =1";
		}
		$is_flv = 0; $adult_allow = CheckAdultAllow();
		switch($data["upload_type"]){
			case "f":

				$folder = $settings["photos_folder"];
				$dir = GetPath($id, $folder);
				//					0		1				2				3				4			5
				$strSQL = " SELECT uu.id, uu.upload_path, uu.user_comment, uu.is_adult, s.site_path, s.server
							FROM ".USER_UPLOAD_TABLE." uu
							LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers
              				WHERE uu.status='1' AND uu.id_album='".$data["id_album"]."' AND uu.id_user='".$id."' ".$allow;
				$rs = $dbconn->Execute($strSQL);
				$i = 0;
				while (!$rs->EOF) {
					if ( ($adult_allow == 1 && $rs->fields[3] == 1) || ($rs->fields[3] == 0)) {
						$data['photos'][$i]['id'] = $rs->fields[0];
						if ($rs->fields[1] == $data["file_name"]) {
							$data['photos'][$i]["sel"] = 1;
						}
						$site_path = $rs -> fields[4];
						$server = $rs -> fields[5];
						$dir = GetImagePath($id, $rs->fields[0], $folder);
						$data['photos'][$i]['user_comment'] = $rs->fields[2];
						$data['photos'][$i]["thumb_file"] = $dir."thumb_".$rs->fields[1];
						$data['photos'][$i]["file"] = $dir.$rs->fields[1];
						$data['photos'][$i]["sizes"] = getimagesize($dir.$rs->fields[1]);
					}
					$rs->MoveNext();
					$i++;
				}

				$smarty->assign("abuse_link", array('id_user'=>$id, 'id_item'=>$id_file, 'item_type'=>'viewphoto', 'abuse_types_msg'=>$config_index['abuse_types_msg']));
				$sizes = getimagesize($site_path.$folder."/thumb_".$data["file_name"]);
				$smarty->assign("sizes", $sizes);
				break;
			case "a": 
				$folder = $settings["audio_folder"];  break;
				$dir = GetPath($id, $folder);
			case "v":
				$dir = GetPath($id, $folder);
				$folder = $settings["video_folder"];				
				if ($settings["use_ffmpeg"] == 1) {
					$flv_name = explode('.', $data["file_name"]);
					$is_flv = 1;
					$smarty->assign("is_flv", 1);
				}
				break;
		}
		if ($is_flv == 1) {
			$data["file_path"] = $dir.$flv_name[0].".mp4";
			$data["image_path"] = $dir.$flv_name[0]."1.jpg";
		} else {
			$data["file_path"] = $dir.$data["file_name"];
		}
		$data['adult_allow'] = $adult_allow;
		$smarty->assign("data", $data);
		$smarty->assign("view", 1);
		$smarty->display(TrimSlash($config["index_theme_path"])."/myprofile_upload_view.tpl");
	} elseif ($par=='ajax') {
		$folder = $settings["photos_folder"];
		
		//					0			1				2				3			4			5
		$strSQL = " SELECT uu.id, uu.upload_path, uu.user_comment, uu.id_user, s.site_path, s.server
					FROM ".USER_UPLOAD_TABLE." uu
					LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers
					WHERE uu.id='".$id_file."' ";
		$rs = $dbconn->Execute($strSQL);		
		//$dir = GetPath($rs->fields[3], $folder);
		$dir = GetImagePath($rs->fields[3], $rs->fields[0], $folder);
		$id_photo = $rs->fields[0];
		$site_path = $rs -> fields[4];
		$server = $rs -> fields[5];
		$photo = $dir.$rs->fields[1];
		$user_comment = stripslashes($rs->fields[2]);
		$id = $rs -> fields[3];

		$abuse_types = "";
		foreach ($config_index['abuse_types_msg'] as $key => $value)
		{
			$msg_type = $config_index['abuse_types_msg'][$key];
			$abuse_types .= "<input type=\"radio\" name=\"ab_type_msg\" value=\"".$config_index['abuse_types_msg'][$key]."\" ";
			if ($config_index['abuse_types_msg'][$key] == 'inapr') $abuse_types .="checked";
			$abuse_types .= "> ".$lang['abuse']['msg_types'][$msg_type]." <br />";
		}
		echo "
        <table cellpadding=\"0\" cellspacing=\"0\" align=\"center\">
        <tr>
          <td><img border=1 bordercolor=1 src=\"".$photo."\" alt=\"\"></td>
        </tr>
        <tr>
          <td align=\"center\">".$user_comment."</td>
        </tr>
        <tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td align=\"center\">
			<a href=\"#\" id=\"abuse_link\" onClick=\"onformclick=1; abuseReportForm(); return false;\">".$lang['abuse']['report_link']."</a>
				<div id=\"abuse_form_tpl\" style=\"display:none;\">
					<div id=\"abuse_form\" style=\"z-index:100;\">
						<div><font class=\"text_head\"> ".$lang['abuse']['form_header_text']."</font></div>
							<div align=\"left\"> ".$abuse_types."
							</div>
						<div class=\"sep\"></div>
						<div>".$lang['abuse']['get_descr'].":</div>
						<div>
							<textarea id=\"ab_msg\" style=\"width:97%\" onBlur=\"if (this.value=='') $('#submit_am').attr('disabled','disabled'); else $('#submit_am').attr('disabled','');\"  onkeyup=\"if (this.value=='') $('#submit_am').attr('disabled','disabled'); else $('#submit_am').attr('disabled','');\"></textarea>
						</div>
						<div align=\"right\">
							<input id=\"submit_am\" type=\"button\" value=\"".$lang['button']['send']."\" disabled=\"disabled\" onClick=\"sendAbuseReport(".$id.",".$id_photo.", 'viewphoto');\" />
						</div>
					</div>
				</div>
					</td>
				</tr>
        </table>
    ";
	}
	exit;
}

function TagsTable() {
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $lang_code, $settings;

	$id = isset($_GET["id"])?intval($_GET["id"]):0;
	$search_type = isset($_GET["search_type"]) ? strip_tags($_GET["search_type"]) : '';
	$suffix = "&id=".$id;
	if ($search_type) $suffix .= "&search_type=".$search_type;

	$use_tags = $settings["use_tags"];
	$smarty->assign("use_tags", $use_tags);
	
	$file_name = seo("viewprofile", 1);
    if (isset($_GET["login"])) {
		$rs = $dbconn->Execute("select id from ".USERS_TABLE." where login = '".$_GET["login"]."'");
		if ($rs->fields[0]){
			$id = $rs->fields[0];
		}
		else {
			header('Location: '.$config["server"]);
			return;
		}
	}else{
	   $id = isset($_GET['id']) ? intval($_GET["id"]) : '';
	}
	$data = array();

	$strSQL = "Select DISTINCT tag, COUNT(id) as tag_count from ".TAGS_TABLE." where id_user = '".$id."' AND (tag_type='profile' OR tag_type='public') group by tag order by tag";
	$rs = $dbconn->Execute($strSQL);
	$i=0;
	if ($rs->_numOfRows > 0) 
	while(!$rs->EOF){
		$row = $rs->GetRowAssoc(false);
		$data["user_tags"][$i]["tag"] = stripslashes($row["tag"]);
		$data["user_tags"][$i]["count"] = $row["tag_count"];
                if ($config["use_seo_multilang"] && $config["use_global_seo"]) {
                    $data["user_tags"][$i]["searchlink"] = $config["server"]."/".$lang_code."/tag/".$data["user_tags"][$i]["tag"];
                } else {
                    $data["user_tags"][$i]["searchlink"] = $config["server"]."/".seo("quick_search")."?sel=search_tag&amp;tag=".$data["user_tags"][$i]["tag"];
                }
        if ($row["tag_count"] < 2) $data["user_tags"][$i]["size"] = 10;
		if ($row["tag_count"] > 1 && $row["tag_count"] < 6) $data["user_tags"][$i]["size"] = 12;
		if ($row["tag_count"] > 5 && $row["tag_count"] < 11) $data["user_tags"][$i]["size"] = 14;
		if ($row["tag_count"] > 10) $data["user_tags"][$i]["size"] = 16;
		$rs->MoveNext();
		$i++;
	}

	$strSQL = "Select id, tag from ".TAGS_TABLE." where id_user = '".$id."' and id_creator = '".$user[0]."' order by tag";
	$rs = $dbconn->Execute($strSQL);
	$i=0;
	while(!$rs->EOF){
		$row = $rs->GetRowAssoc(false);
		$data["my_tags"][$i]["tag"] = stripslashes($row["tag"]);
		$data["my_tags"][$i]["dellink"] = $config["server"].$file_name."?sel=deltag&amp;tag=".$row["id"].$suffix;
		$rs->MoveNext();
		$i++;
	}
	$smarty->append("data_10", $data, true);
	return;
}

function AddTag() {
    global $lang, $config, $config_index, $smarty, $dbconn, $user;

    $id = isset($_GET["id"])?intval($_GET["id"]):0;
    $search_type = $_GET["search_type"];
    $suffix = "&id=".$id;
    if ($search_type) $suffix .= "&search_type=".$search_type;

    $file_name = seo("viewprofile", 1);
    
    $couple = CheckCouple($user[0]);
    if($couple > 0)
        $where = "(ig.id_enemy='".$user[0]."' or ig.id_enemy='".$couple."')";
    else
        $where = " ig.id_enemy='".$user[0]."' ";
    
    $strSQL = "select a.id, ig.id_enemy, a.root_user 
				from ".USERS_TABLE." a
              left join ".BLACKLIST_TABLE." ig on ig.id_user=a.id and $where
              where a.id='".$id."'";
    $rs = $dbconn->Execute($strSQL);
    $to_id = $rs->fields[0];
    $ignore = $rs->fields[1];
    if($to_id && intval($ignore)==0){
        if($_POST["tag"] != ""){
            $tag_arr = explode(" ", $_POST["tag"]);
            foreach ($tag_arr as $key => $value) {
                    $err = BadWordsCont(strip_tags($value), 13);
                    if ($err) {
                            ListProfile(5, '', $err);
                            return;
                    }
            }

            $tag = explode(",", trim(strip_tags($_POST["tag"])));	
            $insert = "";
            for($i=0; $i<count($tag); $i++){
                    $rs = $dbconn->Execute("select id from ".TAGS_TABLE." where id_creator = '".$user[0]."' and id_user= '".$id."' and tag = '".$tag[$i]."'");
                    if(!$rs->fields[0]) {
                            $insert .= "('".$user[0]."', '".$id."', '".date("Y-m-d H:i:s")."', '".trim($tag[$i])."')";
                            if ($i == count($tag)-1) {
                                    $insert .=";";
                            }
                            else $insert .= ",";
                    }
            }
            if($insert != ""){
            $strSQL = "INSERT INTO ".TAGS_TABLE." (id_creator, id_user, create_date, tag) VALUES ".$insert;
                    $dbconn->Execute($strSQL);
            }

            ListProfile(5);
            return;
        }else{
            ListProfile(5);
                return;
        }  
    }else{
        ListProfile(5, '', $lang["err"]["email_black_list_err"]);
        return;
    }
}

function DeleteTag() {
	global $lang, $config, $config_index, $smarty, $dbconn, $user;

	$id = intval($_GET["id"]);
	$id_tag = intval($_GET["tag"]);

	$strSQL= "DELETE FROM ".TAGS_TABLE." WHERE id_creator = '".$user[0]."' and id_user = '".$id."' and id = '".$id_tag."'";
	$dbconn->Execute($strSQL);

	ListProfile(5);
	return;
}

function SendNotice($id){
	global $lang, $lang_mail, $config, $config_index, $smarty, $dbconn, $user, $PHPmailer, $lang_mail_code, $charset_mail, $lang_mail, $settings;

	$site_mail = $settings['site_email'];

	//Get default icons
	$default_photos['1'] = $settings['icon_male_default'];
	$default_photos['2'] = $settings['icon_female_default'];

	//// select from db all users who want to recieve news from site
	$strSQL = "select a.id_user, b.login, b.email, b.site_language from ".SUBSCRIBE_USER_TABLE." a, ".USERS_TABLE." b where a.type='s' and a.id_subscribe='3' and b.id=a.id_user and b.id='".intval($id)."'";
	$rs = $dbconn->Execute($strSQL);
	$row = $rs->GetRowAssoc(false);
	$id_user["id"] = $row["id_user"];
	$id_user["login"] = $row["login"];
	$id_user["email"] = $row["email"];
	$id_user["site_lang"] = $row["site_language"];

	if($id_user["id"]>0){
		$strSQL = "SELECT lang_file, code, charset FROM ".LANGUAGE_TABLE." WHERE id=".$id_user["site_lang"];
		$rs=$dbconn->Execute($strSQL);
		$lang_name = explode('.',$rs->fields[0]);
		$lang_mail_code = $rs->fields[1];
		$charset_mail = $rs->fields[2];
		GetLangContent($lang_name[0], $config["path_lang"]."mail");
		$strSQL="SELECT u.id, u.login, u.headline, u.date_birthday, uu.upload_path, uu.id as id_photo, u.gender, u.id_country, 
				u.id_city, u.id_region, s.site_path
				FROM ".USERS_TABLE." u
				LEFT JOIN ".USER_UPLOAD_TABLE." uu ON uu.id=u.icon_path
				LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=u.id_servers
				WHERE u.status='1' AND u.id='".$user[0]."' ";
		$rs = $dbconn->Execute($strSQL);
		$row = $rs->GetRowAssoc(false);
		$data["id"] = $row["id"];
		$data["login"] = $row["login"];
		$data["text"] = $row["headline"];
		$data["date"] = date("d-m-Y H:i");

		$data["id_city"] = $row["id_city"];
		$data["id_region"] = $row["id_region"];
		$data["id_country"] = $row["id_country"];
		$data["age"] = AgeFromBDate($row["date_birthday"]);

		$site_path = $row["site_path"];

		//User icon
		$icon_path = $row["upload_path"]?"thumb_".$row["upload_path"]:$settings['photos_default'];
		$dir = GetImagePath($row["id"], $row["id_photo"], $settings["photos_folder"], 1);
		//$dir = GetPath($row["id"], $settings["photos_folder"],1);

		$data["icon"] = "[embedded_".$row["id"]."]";
		//$data["icon"] = str_replace("[embedded_".$row["id"]."]", $dir.$icon_path, $data["icon"]);
		$attaches[0]["search_tpl"]="[embedded_".$row["id"]."]";
		if ($icon_path != $settings['photos_default'])
			$attaches[0]["item_path"]=$dir.$icon_path;
		else
			$attaches[0]["item_path"]=$config["site_path"].$config["index_theme_path"].$config["index_theme_images_path"]."/".$icon_path;
		//Base lang
		$_LANG_NEED_ID["country"][] = intval($row["id_country"]);
		$_LANG_NEED_ID["region"][] = intval($row["id_region"]);
		$_LANG_NEED_ID["city"][] = intval($row["id_city"]);

		//Links
		$data["link_read"] = $config["server"]."/viewprofile.php?id=".$row["id"];
		$smarty->assign("base_lang", GetBaseLang($_LANG_NEED_ID));
		$smarty->assign("header", $lang_mail);
		$subject = str_replace("[site]",  $config["server"], $lang_mail["subjects"]["visited_subscribe"]);
		$subject = str_replace("[date]", date("d/m/Y"),$subject);
		$smarty->assign("data", $data);
		$data["content"] = $smarty->fetch(TrimSlash($config["index_theme_path"])."/mail_visits_mypage_content.tpl");
		SendMail($id_user["email"], $site_mail, $subject, $data, "mail_visits_mypage_table", $attaches, $id_user["login"]);
	}
	//SMS-notification
	if (isset($config["use_pilot_module_sms_notifications"]) && $config['use_pilot_module_sms_notifications'] == '1' && $id > 0){
		include_once "./include/functions_sms_notifications.php";
		SendUserSms($id, 3);
	}
	//end of SMS-notification
	return;
}

function ViewLocation(){
	global $smarty, $dbconn, $config, $config_admin, $lang, $user, $settings;
	IndexHomePage();
	
	$settings["ovi_appId"] = stripslashes($settings["ovi_appId"]);
    $settings["ovi_token"] = stripslashes($settings["ovi_token"]);
	$settings["google_app_id"] = stripslashes($settings["google_app_id"]);

	$lat = $_GET["lat"];
	$lon = $_GET["lon"];

	$smarty->assign("lat", $lat);
	$smarty->assign("lon", $lon);
	$smarty->assign("settings", $settings);
	$smarty->display(TrimSlash($config["index_theme_path"])."/view_on_map.tpl");
	exit;
}

function Agreement() {
	global $smarty, $dbconn, $config, $config_admin, $lang, $user;
	IndexHomePage();
	if (isset($_POST['agree'])) {
		if ($_POST['agree'] == 'yes') {
			if ($_POST['gallary'] == 1) {
				echo "<script>document.location.href='".seo("gallery", 1)."?sel=view_upload&upload_type=".$_REQUEST["upload_type"]."&id=".intval($_POST["id_file"])."';</script>";
			} else {
				echo "<script>document.location.href='".seo("viewprofile", 1)."?sel=upload_view&type_upload=f&id_file=".intval($_POST["id_file"])."';</script>";
			}
		} else {
			echo "<script>window.close();</script>";
		}
	} else {
		if (isset($_REQUEST['gallary']) && intval($_REQUEST['gallary']) == 1 ) {
			$smarty->assign("gallary", 1);
		} else {
			$smarty->assign("gallary", 0);
		}
		if (isset($_GET['allow_no']) && $_GET['allow_no'] == 1) {
			$smarty->assign("not_allow", 1);
		} else {
			$smarty->assign("not_allow", 0);
		}
		if (isset($_REQUEST['upload_type'])) {
			$smarty->assign("upload_type", $_REQUEST['upload_type']);
		} else {
			$smarty->assign("upload_type", 'f');
		}
		$smarty->assign("id_file", $_GET['id_file']);
		$smarty->assign("sel", "agreement");
		$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_adult_warning.tpl");
	}
	exit;
}

function AgreementWin() {
	global $smarty, $dbconn, $config, $config_admin, $lang, $user;
	IndexHomePage();
	$data['id_user'] = intval($_REQUEST['id_user']);
	$data['id_item'] = intval($_REQUEST['id_item']);
	$data['id_subitem'] = intval($_REQUEST['id_subitem']);
	$data['type'] = isset($_REQUEST['type']) && ($_REQUEST['type'] == 'f' || $_REQUEST['type'] == 'a' || $_REQUEST['type'] == 'v' ) ? $_REQUEST['type'] : 'f';
	switch ($data['type']) {
		case 'f':
			$start = 'slide';
			break;
		case 'a':
			$start = 'play';
			break;
		case 'v':
			$start = 'video';
			break;
	}
	$data['str'] = "sel=start_".$start."&id_item=".$data["id_item"]."&type=".$data['type']."&id_subitem=".$data["id_subitem"]."&id_user=".$data["id_user"]."&agr=1";

	if (isset($_REQUEST['allow_no']) && $_REQUEST['allow_no'] == 1) {
		$smarty->assign("not_allow", 1);
	} else {
		$smarty->assign("not_allow", 0);
	}
	$smarty->assign("data", $data);
	$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_adult_warning_win.tpl");
	exit;
}

function StartSlideShow() {
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $settings;
       
	$data['id_user'] = (isset($_REQUEST['id_user']) && intval($_REQUEST['id_user']) > 0) ? intval($_REQUEST['id_user']) : 0;
	$data['id_album'] = (isset($_REQUEST['id_item']) && intval($_REQUEST['id_item']) > 0) ? intval($_REQUEST['id_item']) : 0;
	$data['id_subitem'] = (isset($_REQUEST['id_subitem']) && intval($_REQUEST['id_subitem']) > 0) ? intval($_REQUEST['id_subitem']) : 0;
	$data['type'] = (isset($_REQUEST['type']) && ($_REQUEST['type'] == 'f' || $_REQUEST['type'] == 'a' || $_REQUEST['type'] == 'v')) ? $_REQUEST['type'] : 'f';

	$data['viewmore'] = (isset($_REQUEST['viewmore']) && intval($_REQUEST['viewmore']) > 0) ? intval($_REQUEST['viewmore']) : 0;
	$agr = (isset($_REQUEST['agr']) && intval($_REQUEST['agr'])) || $user['adult_allow'] ? 1 : 0;
	if(isset($_REQUEST['agr']) && intval($_REQUEST['agr'])){
		$dbconn->Execute("UPDATE ".USERS_TABLE." SET adult_allow='1' WHERE id='{$user[0]}'");
	}
	$adult_show = $agr ? " " : " AND a.is_adult='0'";
	
	$strSQL="UPDATE ".USER_UPLOAD_TABLE." SET views=views+1 WHERE id = '".$data['id_subitem']."'";
	$res = $dbconn -> Execute($strSQL);
    
    $couple = CheckCouple($user[0]);
    if($couple > 0) $where_couple = " or id_friend='".$couple."' ";
    else $where_couple = "";
	$rs = $dbconn->Execute("select count(*) from ".HOTLIST_TABLE." where id_user='".$data['id_user']."' and (id_friend='".$user[0]."' $where_couple)");
	if($rs->fields[0]>0){
		$allow = " AND a.allow IN (1, 2, 3)"; /// select uploads for all type permissions(guest, user, friend)
	}elseif($user[3] == 0 && $user[0]>0){ ////// user registerd
		$allow = " AND a.allow IN (1, 2)";
	}else{
		$allow = " AND a.allow=1";
	}

	$adult_allow = CheckAdultAllow();
	$smarty->assign("adult_allow", $adult_allow);
	$strSQL = "SELECT a.id, a.upload_path, a.user_comment, b.server, b.site_path, a.is_adult, alb.title, a.allow, 
				COUNT(c.id) as photo_count, alb.id as album_id, a.id_gallery, a.is_gallary
				FROM ".USER_UPLOAD_TABLE." a 
				LEFT JOIN ".SERVERS_TABLE." b ON b.id_servers=a.id_servers
				LEFT JOIN ".USER_ALBUMS." alb ON a.id_album = alb.id AND alb.album_type='".$data['type']."'
				LEFT JOIN ".USER_UPLOAD_TABLE." c ON a.id_album = c.id_album
				WHERE a.id_user='".$data['id_user']."' AND a.id_album='".$data["id_album"]."' AND a.upload_type='".$data['type']."' ".$allow.$adult_show."
				GROUP BY a.id ORDER BY a.id";
	$rs = $dbconn->Execute($strSQL);
	if ($rs) {
		$i = 0; 
		while (!$rs->EOF) {
			$row = $rs->GetRowAssoc(false);
			//$dir = GetPath($data['id_user'], $settings["photos_folder"]);
			if (($adult_allow == 1 && $row['is_adult'] == 1) || ($row['is_adult'] == 0)) {
				if ($row['id'] == $data['id_subitem']) {
					$data['num_selected'] = $i;
				}
				$data['photos'][$i]['id'] = $row['id'];
				$data['photos'][$i]['is_adult'] = $row['is_adult'];
				$data['photos'][$i]['upload_path'] = $row['upload_path'];
				$data['photos'][$i]['user_comment'] = nl2br(stripslashes($row['user_comment']));
				$data['photos'][$i]['user_comment'] = str_replace("\n","</br>",$data['photos'][$i]['user_comment']);
				$data['photos'][$i]['user_comment'] = str_replace("\t","</br>",$data['photos'][$i]['user_comment']);
				$data['photos'][$i]['user_comment'] = ($data['photos'][$i]['user_comment'] != '') ? $data['photos'][$i]['user_comment'] : "";
				$data['photos'][$i]['site_path'] = $row['site_path'];
				$data['photos'][$i]['site_server'] = $row['server'];
				$dir = GetImagePath($data['id_user'], $row["id"], $settings["photos_folder"]);
				$data['photos'][$i]['url_image'] = $dir.$data['photos'][$i]['upload_path'];
				$data['photos'][$i]['imagesize'] = getimagesize($dir.$data['photos'][$i]['upload_path']);
				$data['photos'][$i]['title'] = $row['title'];
				$data['photos'][$i]['allow'] = $row['allow'];
				$data['photos'][$i]['is_gallary'] = $row['is_gallary'];
				
				$data['count_photos'] = $row['photo_count'];
				$data['photos'][$i]['album_id'] = $row['album_id'];
				$data['photos'][$i]['id_gallery'] = $row['id_gallery'];
				$data['photos'][$i]['gallery_name'] = GetGalleryCategoriyById($row['id_gallery']);
			}
			$i++;
			$rs->MoveNext();
		}	
		$strSQL_rat_1 = " SELECT count(id) FROM ".GALLERY_RATING_TABLE." WHERE id_user='".$user[0]."' AND id_upload='".$data['id_subitem']."'";	
		$rs_rat_1 = $dbconn->Execute($strSQL_rat_1);
		if ($rs_rat_1->fields[0]>0){
			$strSQL_rat = " SELECT uu.id_user, gr.estimation 
						FROM ".USER_UPLOAD_TABLE." uu
						LEFT JOIN ".GALLERY_RATING_TABLE." gr ON gr.id_upload=uu.id AND gr.id_user='".$user[0]."'
						WHERE uu.id='".$data['id_subitem']."' AND gr.id_upload='".$data['id_subitem']."'";
			$rs_rat = $dbconn->Execute($strSQL_rat);
			if ($rs_rat->fields[0] == $user[0] || ($rs_rat->fields[1]>0 && $rs_rat->fields[1] == "NULL")) {
				$form["no_rating"] = 1;
			}else {
				$form["no_rating"] = 0;
				$_arr = range(1,10);
				$smarty->assign("vote_arr", $_arr);
			}
			$form['vote_icon_1_path'] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/vote_icon_1.gif";
			$form['vote_icon_0_path'] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/vote_icon_0.gif";
		}
		else{
			$form["no_rating"] = 0;
			$_arr = range(1,10);
			$smarty->assign("vote_arr", $_arr);
		}		
		$smarty->assign("can_edit", 0);
		$smarty->assign("report_abuse", $lang["abuse"]);
		$smarty->assign("general_lang", $lang["general"]);
		if($config["use_default_smiles"]==1 ){
		$smarty->assign("smiles", $config["smiles"]);
		}else{
		$strSQL = "SELECT value, file, preg FROM ".SMILES."";
		$rs = $dbconn->Execute($strSQL);
		$smile = array();
		$i = 0;
			while(!$rs->EOF){
				$smile[$i]["value"] = $rs->fields[0];
				$smile[$i]["file"] = $rs->fields[1];
				$smile[$i]["preg"] = $rs->fields[2];
				$i++;
				$rs->MoveNext();
			}
		$smarty->assign("smiles", $smile);
		}
		$smarty->assign("use_default_smiles", $config["use_default_smiles"]);
		$smarty->assign("smiles_path",$config['server'].$config["index_theme_path"]);
		$smarty->assign("form", $form);
		$smarty->assign("abuse_link", array('id_user'=>$data['id_user'], 'id_item'=>$data['id_subitem'], 'item_type'=>$data['type'], 'abuse_types_msg'=>$config_index['abuse_types_msg']));
		$smarty->assign('data_9', $data);
		$smarty->display(TrimSlash($config["index_theme_path"])."/myprofile_photo_slide_table.tpl");
	} else {
		echo "<script>$('#mask').hide(); $('.window').hide();</script>";
	}
}

function StartAudioPlaying() {
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $settings;
	$data['id_user'] = (isset($_REQUEST['id_user']) && intval($_REQUEST['id_user']) > 0) ? intval($_REQUEST['id_user']) : 0;
	$data['id_album'] = (isset($_REQUEST['id_item']) && intval($_REQUEST['id_item']) > 0) ? intval($_REQUEST['id_item']) : 0;
	$data['id_subitem'] = (isset($_REQUEST['id_subitem']) && intval($_REQUEST['id_subitem']) > 0) ? intval($_REQUEST['id_subitem']) : 0;
	$data['type'] = (isset($_REQUEST['type']) && ($_REQUEST['type'] == 'f' || $_REQUEST['type'] == 'a' || $_REQUEST['type'] == 'v')) ? $_REQUEST['type'] : 'a';

	$strSQL="UPDATE ".USER_UPLOAD_TABLE." SET views=views+1 WHERE id = '".$data['id_subitem']."'";
	$res = $dbconn -> Execute($strSQL);

	$couple = CheckCouple($user[0]);
    if($couple > 0) $where_couple = " or id_friend='".$couple."' ";
    else $where_couple = "";
    $rs = $dbconn->Execute("select count(*) from ".HOTLIST_TABLE." where id_user='".$data['id_user']."' and (id_friend='".$user[0]."' $where_couple)");
	if($rs->fields[0]>0){
		$allow = " AND a.allow IN (1, 2, 3)"; /// select uploads for all type permissions(guest, user, friend)
	}elseif($user[3] == 0 && $user[0]>0){ ////// user registerd
		$allow = " AND a.allow IN (1, 2)";
	}else{
		$allow = " AND a.allow=1";
	}

	$strSQL = "SELECT a.id, a.upload_path, a.user_comment, a.id_servers, b.server, b.site_path, d.song_name, d.song_author, d.song_length
	FROM ".USER_UPLOAD_TABLE." a
	LEFT JOIN ".SERVERS_TABLE." b ON b.id_servers=a.id_servers
	LEFT JOIN ".AUDIO_FILES_INFO_TABLE." d ON d.id_file=a.id
	WHERE a.id='".$data['id_subitem']."' AND a.id_user='".$data['id_user']."' AND a.id_album='".$data["id_album"]."' AND a.upload_type='".$data['type']."'".$allow;
	$rs = $dbconn->Execute($strSQL);
	if ($rs->fields[0] > 0) {
		//$dir = GetPath($data['id_user'], $settings["audio_folder"]);
		$i = 0; 
		$data['audio']['id'] = $rs->fields[0];
		$data['audio']['upload_path'] = $rs->fields[1];
		$data['audio']['user_comment'] = addslashes($rs->fields[2]);
		$data['audio']['user_comment'] = ($data['audio']['user_comment'] != '') ? $lang["users"]["comment"]."&nbsp;:&nbsp;".$data['audio']['user_comment'] : "";
		$data['audio']['site_path'] = $rs->fields[5];
		$data['audio']['site_server'] = $rs->fields[4];
		$data['audio']['song_name'] = strlen($rs->fields[6]) > 0 ? $rs->fields[6] : $lang['profile']['unknown'];
		$data['audio']['song_author'] = strlen($rs->fields[7]) > 0 ? $rs->fields[7] : $lang['profile']['unknown'];
		$data['audio']['song_length'] = $rs->fields[8];
		$dir = GetImagePath($data['id_user'], $rs->fields[0], $settings["audio_folder"]);
		$data['audio']['url_audio'] = $dir.$data['audio']['upload_path'];
		$smarty->assign('data_9', $data);
		$smarty->display(TrimSlash($config["index_theme_path"])."/myprofile_audio_view_table.tpl");
	} else {
		echo "<script>$('#mask').hide(); $('.window').hide();</script>";
	}

}

function StartVideoPlaying() {
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $settings;

	$data['id_user'] = (isset($_REQUEST['id_user']) && intval($_REQUEST['id_user']) > 0) ? intval($_REQUEST['id_user']) : 0;
	$data['id_album'] = (isset($_REQUEST['id_item']) && intval($_REQUEST['id_item']) > 0) ? intval($_REQUEST['id_item']) : 0;
	$data['id_subitem'] = (isset($_REQUEST['id_subitem']) && intval($_REQUEST['id_subitem']) > 0) ? intval($_REQUEST['id_subitem']) : 0;
	$data['type'] = (isset($_REQUEST['type']) && ($_REQUEST['type'] == 'f' || $_REQUEST['type'] == 'a' || $_REQUEST['type'] == 'v')) ? $_REQUEST['type'] : 'v';
	if(isset($_REQUEST['agr']) && intval($_REQUEST['agr'])){
		$dbconn->Execute("UPDATE ".USERS_TABLE." SET adult_allow='1' WHERE id='{$user[0]}'");
	}

	$strSQL="UPDATE ".USER_UPLOAD_TABLE." SET views=views+1 WHERE id = '".$data['id_subitem']."'";
	$res = $dbconn -> Execute($strSQL);

	$couple = CheckCouple($user[0]);
	$is_self = ($data['id_user'] == $user[0] || $data['id_user'] == $user['cid']) ? 1 : 0;
	
    if($couple > 0) $where_couple = " or id_friend='".$couple."' ";
    else $where_couple = "";
    $rs = $dbconn->Execute("select count(*) from ".HOTLIST_TABLE." where id_user='".$data['id_user']."' and (id_friend='".$user[0]."' $where_couple)");
	if($rs->fields[0]>0 || $is_self){
		$allow = " AND a.allow IN (1, 2, 3)"; /// select uploads for all type permissions(guest, user, friend)
	}elseif($user[3] == 0 && $user[0]>0){ ////// user registerd
		$allow = " AND a.allow IN (1, 2)";
	}else{
		$allow = " AND a.allow=1";
	}

	$strSQL = "SELECT a.id, a.upload_path, a.user_comment, a.id_servers, b.server, b.site_path, a.file_type, a.title upload_title
		FROM " . USER_UPLOAD_TABLE . " a
		LEFT JOIN " . SERVERS_TABLE . " b ON b.id_servers=a.id_servers
		WHERE a.id='{$data['id_subitem']}' AND a.id_user='{$data['id_user']}' 
		AND a.id_album='{$data["id_album"]}' AND a.upload_type='{$data['type']}'" . $allow;
	$rs = $dbconn->Execute($strSQL);
	if ($rs->fields[0] > 0) {
		$i = 0;
		//$dir = GetPath($data['id_user'], $settings["video_folder"]);
		$data['video']['id'] = $rs->fields[0];
		$data['video']['upload_title'] = $rs->fields[7];
		$data['video']['upload_path'] = $rs->fields[1];
		$data['video']['user_comment'] = addslashes($rs->fields[2]);
		$data['video']['site_path'] = $rs->fields[5];
		$data['video']['site_server'] = $rs->fields[4];
		$dir = GetImagePath($data['id_user'], $rs->fields[0], $settings["video_folder"]);
		$data['video']['url_video'] = $dir.$data['video']['upload_path'];

		$data['video']['type'] = $rs->fields[6];
		
		// if we have video file
		if ($data['video']['type'] != 'embed' ) {
			if ($settings["use_ffmpeg"] == 1) {
				$flv_name = explode('.', $data['video']['upload_path']);
				$is_flv = 1;
				$smarty->assign("is_flv", 1);

			}
			if (isset($is_flv) && ($is_flv==1)) {
				if (fopen($dir.$flv_name[0].".mp4", 'r')) {
					$data['video']['url_video'] = $dir.$flv_name[0].".mp4";
					$data['video']['url_image'] = $dir.$flv_name[0]."1.jpg";
					$is_flv = 1;
					$smarty->assign("is_flv", 1);

				} else {
					$data['video']['url_video'] = $dir.$rs->fields[1];
				}
			}
		} else {
			$data['video']['url_video'] = 
				str_replace('%width%', 520, 
				str_replace('%height%', 390, $data['video']['upload_path']));
		}

		$strSQL_rat_1 = " SELECT count(id) FROM ".GALLERY_RATING_TABLE." WHERE id_user='".$user[0]."' AND id_upload='".$data['id_subitem']."'";	
		$rs_rat_1 = $dbconn->Execute($strSQL_rat_1);
		if ($rs_rat_1->fields[0]>0){
			$strSQL_rat = " SELECT uu.id_user, gr.estimation 
						FROM ".USER_UPLOAD_TABLE." uu
						LEFT JOIN ".GALLERY_RATING_TABLE." gr ON gr.id_upload=uu.id AND gr.id_user='".$user[0]."'
						WHERE uu.id='".$data['id_subitem']."' AND gr.id_upload='".$data['id_subitem']."'";
			$rs_rat = $dbconn->Execute($strSQL_rat);
			if ($rs_rat->fields[0] == $user[0] || ($rs_rat->fields[1] > 0 && $rs_rat->fields[1] == "NULL")) {
				$data["no_rating"] = 1;


				$_arr = '';
			} else {
				$data["no_rating"] = 0;
				$_arr = range(1, 10);
			}
			$data['vote_icon_1_path'] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/vote_icon_1.gif";
			$data['vote_icon_0_path'] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/vote_icon_0.gif";
		}
		else {
			$data["no_rating"] = 0;
			$_arr = range(1, 10);

		}
		$smarty->assign("vote_arr", $_arr);
		$smarty->assign("can_edit", 0);
		$smarty->assign('data_9', $data);
		
		$smarty->display(TrimSlash($config["index_theme_path"]) . "/myprofile_video_view_table.tpl");
	} else {
		echo "<script>$('#mask').hide(); $('.window').hide();</script>";
	}
}
function AddOwnerComment(){
	global $dbconn, $user, $smarty, $config, $lang;	
	$id = isset($_POST["id"])?intval($_POST["id"]):0;
        $strSQL = "select a.id, ig.id_enemy, a.root_user 
                    from ".USERS_TABLE." a
                    left join ".BLACKLIST_TABLE." ig on ig.id_user=a.id and ig.id_enemy='".$user[0]."'
                    where a.id='".$id."'";
        $rs = $dbconn->Execute($strSQL);
        $to_id = $rs->fields[0];
        $ignore = $rs->fields[1];
        if($to_id && intval($ignore)==0){
            $ret = PostComment($id, $_POST["message"]);
            if($ret != ""){
				//echo "error";
				echo "<script>ShowAjaxError('".$lang["err"]["forbidden"]."','')</script>";
				exit;
            }
        }else{
            echo "black";
            exit;
        }
		
	VotingTable($id, "", 1, "viewprofile");
	$smarty->assign("button", $lang["button"]);
	$smarty->display(TrimSlash($config["index_theme_path"])."/viewprofile_comment.tpl");
}
function DeleteOwnerComment(){
	global $dbconn, $user;
	
	$id = intval($_POST["comment_id"]);
	if($id == 0){
		echo "ERROR";
		exit;
	}
	$strSQL = "SELECT id_voter FROM ".USER_COMMENT_TABLE." WHERE id='{$id}';";
	$rs = $dbconn->Execute($strSQL);
	$id_owner = intval($rs->fields[0]);
	if($id_owner == 0 || $id_owner != $user[0]){
		echo "ERROR";
		exit;
	}
	$strSQL = "DELETE FROM ".USER_COMMENT_TABLE." WHERE id='{$id}';";
	$dbconn->Execute($strSQL);
}

function DeleteFromList(){
	global $lang, $config, $config_index, $smarty, $dbconn, $user, $settings, $servers;
	$delete_id = intval($_GET["id"]);
    
    $couple = CheckCouple($user[0]);
    if($couple > 0){
        $where_couple_1 = " or id_user='".$couple."' ";
		$where_couple_2 = " or id_friend='".$couple."' ";
    }else{
		$where_couple = "";
	}
	if(intval($delete_id) && intval($user[0]) ){
		$strSQL = "Delete from ".HOTLIST_TABLE." where (id_user='".intval($user[0])."' $where_couple_1) and id_friend='".$delete_id."' ";
		$dbconn->Execute($strSQL);
		$strSQL = "Delete from ".HOTLIST_TABLE." where (id_friend='".intval($user[0])."' $where_couple_2) and id_user='".$delete_id."' ";
		$dbconn->Execute($strSQL);
		if($dbconn->Affected_Rows()){
			include_once "./include/class.wall_events.php";
			$events = new WallEvents($user, $config, $settings, $dbconn, $lang, $servers);
			$event_data['id_object'] = $event_data['data']['id'] = $delete_id;
			$event_data['id_wall'] = $delete_id;
			$event_data['data']['status'] = 0;
			$event_id = $events->CreateEvent('friend_del', $event_data);
		}
	}
	ListProfile(5,"",$lang["err"]["user_was_del_hotlist"]);
	return;
}

function DeleteFromBlackList(){
	global $lang, $config, $config_index, $smarty, $dbconn, $user;
	$delete_id = intval($_GET["id"]);
    
    $couple = CheckCouple($user[0]);
    if($couple > 0)
        $id_user = $dbconn->Execute("SELECT id_user FROM ".BLACKLIST_TABLE." WHERE (id_user='".$user[0]."' or id_user='".$couple."') and id_enemy='".$delete_id."'")->fields[0];
    else
        $id_user = $user[0];

	if($delete_id && intval($id_user) ){
		$strSQL = "Delete from ".BLACKLIST_TABLE."  where id_user ='".intval($id_user)."' and id_enemy='".$delete_id."'";
		$dbconn->Execute($strSQL);

		//remove ban status
		include_once "w_communicator/wc_config.php";
		$strSQL = "UPDATE ".USER_CONTACT_LIST_TABLE." SET ban_status='0' WHERE user_id='".$id_user."' AND view_user_id='".$delete_id."'";
		$dbconn->Execute($strSQL);

		//remove ignore in chat
		$strSQL = "DELETE FROM ".F_CHAT_IGNORS_TABLE." WHERE userid='".$id_user."' AND ignoreduserid='".$delete_id."'";
		$dbconn->Execute($strSQL);
	}
	return;
}

function Chech_Rss_user(){
    global $user, $dbconn, $lang;
    $login = $_POST['login'];  
    $id_user = $dbconn->Execute("SELECT id FROM ".USERS_TABLE." WHERE login='".$login."'")->fields[0];
    
    $couple = CheckCouple($user[0]);
    if($couple > 0)
        $where = " (ig.id_enemy='".$user[0]."' or ig.id_enemy='".$couple."') ";
    else
        $where = " ig.id_enemy='".$user[0]."' ";
    
    $strSQL = "select a.id, ig.id_enemy, a.root_user 
                from ".USERS_TABLE." a
                left join ".BLACKLIST_TABLE." ig on ig.id_user=a.id and $where
                where a.id='".$id_user."'";    
    $rs = $dbconn->Execute($strSQL);
    $to_id = $rs->fields[0];
    $ignore = $rs->fields[1];
    if($to_id && intval($ignore)==0){
        echo "ok";
    }
    else echo $lang["err"]["email_black_list_err"];
}
?>