<?php

include_once '../include/config.php';
include_once 'common.mobile.php';
include_once '../include/config_index.php';
include_once '../include/functions_auth.php';
include_once '../include/class.lang.php';
include_once 'class.mobile.php';

//include_once '../include/functions_index.php';
include_once '../include/functions_users.php';
include_once '../include/class.percent.php';

GetLangContent("registration", $config["path_lang"].$lang_file[0]);
GetLangContent("viewprofile", $config["path_lang"].$lang_file[0]);

$user = auth_index_user();

$smarty->assign('user_id', $user[0]);

$smarty->assign('top_menu_sel', 4);

$mobile = new Mobile();
$mobile->IsFileAllowed($user[0],'/viewprofile.php');

$sel = isset($_REQUEST['sel']) ? $_REQUEST['sel'] : '';
switch ($sel) {
	case 'page': ViewPage(); break;
	case 'wall': UserWall(); break;
	case 'vote': VoteAct(); break;
	case 'addtag': TagAct(); break;
	case 'deltag': DeleteTag(); break;
	case 'comment': LeaveComment(); break;
	case 'delcomment': DelComment(); break;
	case 'photos': PhotosPage(); break;
	case 'viewphoto': ViewPhoto(); break;
	case "add_hotlist": 		$res = AddToHotList(); UserProfile(); break;
	case "add_blacklist": 		$res = AddToBlackList(); UserProfile(); break;
	case "delete_hotlist": 	$res = DeleteFromList('hot'); UserProfile(); break;
	case "delete_blacklist": $res = DeleteFromList('black'); UserProfile(); break;
	default: UserProfile(); break;
}

function UserProfile() {
	global $mobile, $dbconn, $user, $config, $smarty;

	$id_user = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 ? intval($_REQUEST['id']) : null;
	if ($id_user == null) {
		header('Location: index.php');
	}

	$strSQL = "SELECT a.date_birthday, uu.upload_path, a.id_city, b.name AS city_name, a.confirm, a.login, a.fname, a.sname, uu.id 
				FROM ".USERS_TABLE." a 
				LEFT JOIN ".USER_UPLOAD_TABLE." uu ON uu.id=a.icon_path
				LEFT JOIN ".CITY_SPR_TABLE." b ON b.id=a.id_city 
				WHERE a.id='".$id_user."' LIMIT 1";
	$rs = $dbconn->Execute($strSQL);
	$data['age'] = AgeFromBDate($rs->fields[0]);
	
	//$dir = GetPath($id_user, $config["photos_folder"]);
	$dir = GetImagePath($id_user, $rs->fields[8], $config["photos_folder"]);
	$icon_path = $rs->fields[1] ? "thumb_".$rs->fields[1] : $config['photos_default'];
	if ($icon_path != $config['photos_default'])
		$data['icon_path'] = $dir.$icon_path;
	else
		$data['icon_path'] = $config['server'].$config["index_theme_path"].$config["index_theme_images_path"]."/".$icon_path;
		
	$data["id_city"] = $rs->fields[2];
	$data["city_name"] = $rs->fields[3];
	$data["confirm"] = $rs->fields[4];
	$data["login"] = chooseUserName($rs->fields[5], $rs->fields[6]." ".$rs->fields[7]);
	$data["id"] = $id_user;

	$strSQL = "SELECT COUNT(*) FROM ".USER_UPLOAD_TABLE." WHERE id_user='".$id_user."' AND upload_type='f' LIMIT 1";
	$rs = $dbconn->Execute($strSQL);
	$data["photo_count"] = $rs->fields[0];

	$profile_percent = new Percent($config, $dbconn, $id_user);
	$data["complete"] = $profile_percent->GetAllPercent();

	$place = GetUserRatingPlace($id_user);
	if ($place != null) {
		$data['place'] = $place;
	}
	
	$couple = function_exists('CheckCouple') ? CheckCouple($user[0]) : 0;
	$where_couple = $couple ? " OR id_user='{$couple}' " : '';
	
	$strSQL = "SELECT id FROM ".HOTLIST_TABLE." WHERE (id_user='{$user[0]}' {$where_couple}) AND id_friend='{$id_user}'";
	$data['in_hot_list'] = $dbconn->Execute($strSQL)->RecordCount();

	$strSQL = "SELECT id FROM ".BLACKLIST_TABLE." WHERE (id_user='{$user[0]}' {$where_couple}) AND id_enemy='{$id_user}'";
	$data['in_black_list'] = $dbconn->Execute($strSQL)->RecordCount();
	
	$pages = $mobile->GetProfilePages();
	$smarty->assign('pages', $pages);

	$smarty->assign('data', $data);

	$smarty->display(TrimSlash($config['index_theme_path']).'/mobile_viewprofile_page'.$config['theme_postfix'].'.tpl');
}

function ViewPage() {
	global $mobile, $dbconn, $user, $config, $smarty, $multi_lang, $field_name, $profile_percent2, $lang;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 ? intval($_REQUEST['id']) : null;
	if ($id == null) {
		header('Location: index.php');
	}
	$form['id'] = $id;
	$page = (isset($_REQUEST["page"]) && intval($_REQUEST["page"]) > 0) ? intval($_REQUEST["page"]) : 1;

	$multi_lang = new MultiLang($config, $dbconn);
	$field_name = $multi_lang->DefaultFieldName();
	$profile_percent2 = new Percent($config, $dbconn, $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 = '".$page."' 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];
			$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;
		}
	}

	$set_arr = array("show_users_zipcode_str", "show_users_birthdate_str", "show_users_comments");
	$settings = GetSiteSettings($set_arr);


	$elements = GetViewForElements($elements, $cat, 0);
	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);

	$smarty->display(TrimSlash($config['index_theme_path']).'/mobile_viewprofile_view_page'.$config['theme_postfix'].'.tpl');

}


function UserWall($par='', $err = '') {
	global $mobile, $dbconn, $user, $config, $smarty, $settings, $lang, $servers;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 ? intval($_REQUEST['id']) : null;
	if ($id == null) {
		header('Location: index.php');
	}

	$page = (isset($_REQUEST["page"]) && intval($_REQUEST["page"]) > 0) ? intval($_REQUEST["page"]) : 1;

	if (isset($par) && $par == 'deltag') {
		$tag = (isset($_REQUEST["tag"]) && intval($_REQUEST["tag"]) > 0) ? intval($_REQUEST["tag"]) : '';
		$strSQL= "DELETE FROM ".TAGS_TABLE." WHERE id_user = '".$user[0]."' AND id = '".$tag."'";
		$dbconn->Execute($strSQL);
		header('Location: homepage.php?sel=wall');
	}

	/*$strSQL = "SELECT COUNT(*) FROM ".USER_COMMENT_TABLE." WHERE id_user='".$id."' ";
	$rs = $dbconn->Execute($strSQL);
	$num_records = $rs->fields[0];*/
	
	include_once "../include/class.wall_events.php";
	$events = new WallEvents($user, $config, $settings, $dbconn, $lang, $servers);
	$events->mobile = true;
	$events->events_per_req = 35;
	$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);
	
	$message = isset($_REQUEST['message']) && $_REQUEST['message'] !='' ? strip_tags(trim($_REQUEST['message'])) : '';
	$smarty->assign('message', $message);
	$smarty->assign('error', $err);

	VotingTable($id);
	TagsTable($id);

	if (isset($smarty->_tpl_vars['comments_links'])) {
		$param = $config['server']."/m/viewprofile.php?sel=wall&id=".$id."&";
		$smarty->assign("comments_links", GetLinkArray($num_records,$page,$param,6));
	}
	$smarty->assign("id", $id);
	$smarty->display(TrimSlash($config['index_theme_path']).'/mobile_viewprofile_wall_page'.$config['theme_postfix'].'.tpl');
}

//duplicated from viewprofile.php
function TagsTable($id='') {
	global $lang, $config, $config_index, $smarty, $dbconn, $user;

	$data = array();

	$strSQL = "SELECT DISTINCT tag, COUNT(id) AS tag_count FROM ".TAGS_TABLE." WHERE id_user = '".$id."' GROUP BY tag ORDER BY tag";
	$rs = $dbconn->Execute($strSQL);
	$i=0;
	while(!$rs->EOF){
		$row = $rs->GetRowAssoc(false);
		$data["user_tags"][$i]["tag"] = stripslashes($row["tag"]);
		$data["user_tags"][$i]["count"] = $row["tag_count"];
		$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"] = "viewprofile.php?sel=deltag&id=".$id."&tag=".$row["id"];
		$rs->MoveNext();
		$i++;
	}
	$smarty->append("data_10", $data, true);
	return;
}

function VoteAct() {
	global $mobile, $dbconn, $user, $config, $smarty;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	$r = isset($_REQUEST['r']) && intval($_REQUEST['r']) > 0 && intval($_REQUEST['r']) < 11 ? intval($_REQUEST['r']) : null;
	if ($id == null || $r == null ) {
		header('Location: index.php');
	}


	RateProfile($id, $r);

	header("Location: viewprofile.php?sel=wall&id=".$id);

}

function TagAct() {
	global $mobile, $dbconn, $user, $config, $smarty;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	if ($id == null) {
		header('Location: index.php');
	}

	$tag_arr = explode(" ", $_POST["tag"]);

	foreach ($tag_arr as $key => $value) {
		$tag = mysql_escape_string(strip_tags(trim($value)));
		if ($tag != '') {
			$rs = $dbconn->Execute("SELECT id FROM ".TAGS_TABLE." WHERE id_creator = '".$user[0]."' and id_user= '".$id."' AND tag = '".$tag."'");
			if(!$rs->fields[0]) {
				$strSQL = "INSERT INTO ".TAGS_TABLE." (id_creator, id_user, create_date, tag) VALUES ('".$user[0]."', '".$id."', '".date("Y-m-d H:i:s")."', '".$tag."')";
				$dbconn->Execute($strSQL);
			}
		}
	}

	header("Location: viewprofile.php?sel=wall&id=".$id);
}

function DeleteTag() {
	global $mobile, $dbconn, $user, $config, $smarty;
	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	$id_tag = isset($_REQUEST['tag']) && intval($_REQUEST['tag']) > 0? intval($_REQUEST['tag']) : null;
	if ($id == null || $id_tag == null ) {
		header('Location: index.php');
	}

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

	header("Location: viewprofile.php?sel=wall&id=".$id);
}

function LeaveComment() {
	global $mobile, $dbconn, $user, $config, $smarty, $settings, $lang, $servers;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : 0;
	$message = isset($_REQUEST['message']) && $_REQUEST['message'] !='' ? strip_tags(trim($_REQUEST['message'])) : '';
	if (!$id || !$message) {
		return header("Location: viewprofile.php?sel=wall&id=".$id);
	}

	include_once "../include/class.wall_events.php";
	$type = 'user_wall';
	$events = new WallEvents($user, $config, $settings, $dbconn, $lang, $servers);
	if($events->BadWordsFilter($message)){
		UserWall('', $lang['err']['badword_finding_1']);
		return;
	}
	$event_data['id_object'] = $event_data['data']['id'] = $id ? $id : $user[0];
	$event_data['id_wall'] = $id ? $id : $user[0];
	$event_data['data']['text'] = $message;
	$event_data['id_user'] = $user[0];
	$event_id = $events->CreateEvent('wall', $event_data);

	//PostComment($id, $message);
	header("Location: viewprofile.php?sel=wall&id=".$id);
	return;
}

function DelComment() {
	global $mobile, $dbconn, $user, $config, $smarty, $lang, $servers, $settings;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	$id_comment = isset($_REQUEST['id_comment']) && intval($_REQUEST['id_comment']) > 0? intval($_REQUEST['id_comment']) : null;
	if (!$id || !$id_comment) {
		header('Location: index.php');
	}
	
	include_once "../include/class.wall_events.php";
	$type = 'user_wall';
	$events = new WallEvents($user, $config, $settings, $dbconn, $lang, $servers);
	$is_deleted = $events->DeleteEvents($id_comment, 'wall', false, $user[0]);

	if($is_deleted){
		include_once "../include/class.comments.php";
		$comments = new Comments($user, $config, $settings, $dbconn, $smarty);
		$comments->delete_object_comments('wall', $id_comment);
	}

	//DeleteComment($id_comment);
	header("Location: viewprofile.php?sel=wall&id=".$id);
}

//photos only, all users photos, adult content shown
function PhotosPage() {
	global $mobile, $dbconn, $user, $config, $smarty;

	$photos_numpage = 6;

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	if ($id == null) {
		header('Location: index.php');
	}
	$strSQL = "SELECT login, fname, sname FROM ".USERS_TABLE." WHERE id='".$id."'";
	$rs = $dbconn->Execute($strSQL);
	$data["login"] = chooseUserName($rs->fields[0], $rs->fields[1]." ".$rs->fields[2]);

	$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
	$upload_type = 'f';

	$strSQL = " SELECT id FROM ".USER_UPLOAD_TABLE." WHERE id_user='".$id."' AND upload_type='".$upload_type."' ORDER BY id DESC";
	$rs = $dbconn->Execute($strSQL);
	$num_records = $rs->_numOfRows;

	$_arr = array();
	while(!$rs->EOF) {
		array_push($_arr, $rs->fields[0]);
		$rs->MoveNext();
	}

	$_SESSION['user_photos'][$id] = $_arr;

	$data["num_items"] = $num_records;
	$data["page"] = $page;

	$lim_min = ($page-1)*$photos_numpage;
	$lim_max = $photos_numpage;
	$limit_str = " LIMIT ".$lim_min.", ".$lim_max;

	if ($num_records > 0) {
		$strSQL = " SELECT DISTINCT uu.id, uu.upload_path, uu.allow, uu.user_comment, uu.is_gallary, uu.id_gallery, s.site_path, s.server, uu.is_adult, uu.gallery_rate, uu.views
					FROM ".USER_UPLOAD_TABLE." uu
					LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers
					WHERE uu.id_user='".$id."' AND uu.upload_type='".$upload_type."'
					GROUP BY uu.id ORDER BY uu.id DESC".$limit_str;
		$i = 0;
		$rs = $dbconn->Execute($strSQL);
		while(!$rs->EOF) {
			$row = $rs->GetRowAssoc(false);
			$data["photo"][$i]["id"] = $row["id"];
			$data["photo"][$i]["allow"] = $row["allow"];
			$data["photo"][$i]["user_comment"] = stripslashes($row["user_comment"]);

			$thumb_path = $row["site_path"].$config['photos_folder']."/".$row["upload_path"];

			if(strlen($row["upload_path"])>0){
				/*$dir = GetPath($id, $config["photos_folder"]);
				$data_path = SearchPhoto($row["upload_path"]);*/
				$dir = GetImagePath($id, $row["id"], $config["photos_folder"]);
				$data["photo"][$i]["thumb_file"] = $dir."thumb_".$row["upload_path"];
			}

			$data["photo"][$i]["is_adult"] = $row["is_adult"];
			$data["photo"][$i]["views"] = $row["views"];
			$data["photo"][$i]["gallery_rate"] = $row["gallery_rate"];
			$rs->MoveNext();
			$i++;
		}
		$param = $config['server']."/m/viewprofile.php?sel=photos&id=".$id."&";
		if ($num_records > $photos_numpage) {
			$smarty->assign("photos_links", GetLinkArray($num_records, $page, $param, $photos_numpage));
		}

	} else {
		$data['photo'] = 'no_photos';
	}
	$smarty->assign('data',$data);
	$smarty->assign("id", $id);
	$smarty->display(TrimSlash($config['index_theme_path']).'/mobile_viewprofile_photos_list'.$config['theme_postfix'].'.tpl');
}

function ViewPhoto() {
	global $mobile, $dbconn, $user, $config, $smarty;

	$upload_type = 'f';

	$id = isset($_REQUEST['id']) && intval($_REQUEST['id']) > 2 && intval($_REQUEST['id']) != $user[0] ? intval($_REQUEST['id']) : null;
	$photo_id = isset($_REQUEST['photo_id']) && intval($_REQUEST['photo_id']) > 0 ? intval($_REQUEST['photo_id']) : null;
	if ($id == null || $photo_id == null) {
		header('Location: index.php');
	}

	$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;

	$strSQL = "SELECT login, fname, sname FROM ".USERS_TABLE." WHERE id='".$id."'";
	$rs = $dbconn->Execute($strSQL);
	$data["login"] = chooseUserName($rs->fields[0], $rs->fields[1]." ".$rs->fields[2]);

	$smarty->assign("id", $id);
	$smarty->assign("page", $page);

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


	$strSQL = " SELECT DISTINCT uu.id, uu.upload_path, uu.user_comment, uu.is_gallary, uu.id_gallery, s.site_path, s.server, uu.gallery_rate, uu.views
				FROM ".USER_UPLOAD_TABLE." uu
				LEFT JOIN ".SERVERS_TABLE." s ON s.id_servers=uu.id_servers
				WHERE uu.id_user='".$id."' AND uu.upload_type='".$upload_type."' AND uu.id='".$photo_id."'";
	$rs = $dbconn->Execute($strSQL);
	if ($rs->fields[0] > 0) {
		$row = $rs->GetRowAssoc(false);
		$data["id"] = $row["id"];
		$data["file_path"] = $row["upload_path"];
		$data["user_comment"] = stripslashes($row["user_comment"]);
		$data["is_gallary"] = $row["is_gallary"];
		$data["id_gallery"] = $row["id_gallery"];
		$data["site_path"] = $row["site_path"];
		$data["server"] = $row["server"];
		$data["views"] = $row["views"];
		$data["gallery_rate"] = $row["gallery_rate"];
		//$dir = GetPath($id, $config["photos_folder"]);
		$dir = GetImagePath($id, $row["id"], $config["photos_folder"]);
		$data["main_file"] = $dir.$data["file_path"];
		$size = getimagesize($data["main_file"]);
		$data["width"] = $size[0];
		$data["height"] = $size[1];


		if (isset($_SESSION['user_photos'][$id]) && is_array($_SESSION['user_photos'][$id]) && sizeof($_SESSION['user_photos'][$id]) > 0) {
			$key = array_search(intval($photo_id), $_SESSION['user_photos'][$id]);
			if ($key == 0) {
				$data['nav']['next'] = $_SESSION['user_photos'][$id][$key+1];
				$data['nav']['prev'] = '';
			} elseif ($key == (sizeof($_SESSION['user_photos'][$id])-1)) {
				$data['nav']['prev'] = $_SESSION['user_photos'][$id][$key-1];
				$data['nav']['next'] = '';
			} else {
				$data['nav']['next'] = $_SESSION['user_photos'][$id][$key+1];
				$data['nav']['prev'] = $_SESSION['user_photos'][$id][$key-1];
			}
		}

		$smarty->assign('data',$data);

		$smarty->display(TrimSlash($config['index_theme_path']).'/mobile_viewprofile_photo_page'.$config['theme_postfix'].'.tpl');

	} else {
		header('Location: index.php');
	}
}

function DeleteFromList($list){
	global $dbconn, $user;
	
	$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
	if(!$id){
		return false;
	}
	$couple = function_exists('CheckCouple') ? CheckCouple($user[0]) : 0;
	$where_couple = $couple ? " OR id_user='{$couple}' " : '';
	switch($list){
		case 'hot':
			$table = HOTLIST_TABLE;
			$field = 'id_friend';
			break;
		case 'black':
			$table = BLACKLIST_TABLE;
			$field = 'id_enemy';
			break;
	}

	$strSQL = "DELETE FROM {$table} WHERE (id_user='{$user[0]}' {$where_couple}) AND {$field}='{$id}'";
	$res = $dbconn->Execute($strSQL);
	if($res){
		return true;
	}else{
		return false;
	}
}

?>