Файл: adultscript-2.0.3-pro/files/mobile/components/user_dashboard.php
Строк: 72
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_mobile_user_dashboard extends VComponent_mobile_user
{
public function __construct()
{
parent::__construct();
}
public function render()
{
if (!VAuth::loggedin()) {
VF::redirect(MOBILE_URL.'/user/login/');
}
VLanguage::load('frontend.user');
$errors = array();
$messages = array();
$user_id = (int) $_SESSION['user_id'];
$requests = $this->get_friend_requests($user_id);
if (isset($_GET['a'])) {
$action = trim($_GET['a']);
$friend_id = (isset($_GET['u'])) ? (int) trim($_GET['u']) : 0;
if ($friend_id && ($action == 'accept' or $action == 'deny')) {
$status = ($action == 'accept') ? 'approved' : 'denied';
$messages[] = ($this->process_request($status, $user_id, $friend_id))
? 'Friendship accepted!'
: 'Friendship denied';
} else {
$errors[] = 'Invalid request!';
}
}
if (isset($_GET['r']) && $requests) {
$action = trim($_GET['r']);
if ($action == 'accept' or $action == 'deny') {
$status = ($action == 'accept') ? 'approved' : 'denied';
foreach ($requests as $request) {
$this->process_request($status, $user_id, $request['user_id']);
}
$messages[] = 'Requests '.$status.'!';
} else {
$errors[] = 'Invalid request!';
}
}
$this->db->query("SELECT a.total_viewed_videos
FROM #__user AS u
INNER JOIN #__user_activity AS a ON (a.user_id = u.user_id)
WHERE u.user_id = ".$user_id."
AND u.status = '1'");
$this->tpl->menu = 'community';
$this->tpl->submenu = 'dashboard';
$this->tpl->title = __('dashboard-title');
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->requests = $requests;
$this->tpl->profile = $this->db->fetch_assoc();
$this->tpl->load(array('header', 'user_dashboard', 'footer'));
$this->tpl->display();
}
private function get_friend_requests($user_id)
{
$this->db->query("SELECT uf.request_id, u.user_id, u.username, u.avatar, u.gender
FROM #__user_friends AS uf
LEFT JOIN #__user AS u ON (u.user_id = uf.friend_id)
WHERE uf.user_id = ".$user_id."
AND uf.status = 'pending'");
if ($this->db->affected_rows()) {
return $this->db->fetch_rows();
}
return null;
}
private function process_request($status, $user_id, $friend_id)
{
$this->db->query("
UPDATE #__user_friends
SET status = '".$status."'
WHERE user_id = ".$user_id."
AND friend_id = ".$friend_id."
LIMIT 1
");
if ($status == 'approved') {
$this->db->query("INSERT INTO #__user_friends
SET user_id = ".$friend_id.",
friend_id = ".$user_id.",
add_date = '".date('Y-m-d h:i:s')."',
status = 'approved'");
$this->db->query("UPDATE #__user_activity SET total_friends = total_friends+1
WHERE user_id IN (".$user_id.", ".$friend_id.")");
return true;
} else {
return false;
}
}
}