<?php
define('_IN_JOHNCMS', 1);
/**
- Автор скрипта BupTyo3
- http://johncms.com/users/profile.php?user=4269
- 
- Адаптировал Я…… GeGo
- Для JohnCMS 5.2.x
*/


  $rootpath = '../';
  $textl = 'Anketam Mehmonlari';
  require_once ($rootpath . "incfiles/core.php");
  require_once ($rootpath . "incfiles/head.php");

// Проверка юзера 
if (!$user_id) {
  echo functions::display_error('Sahifa faqat userlarga xizmat ko\'rsatadi!<br />Buyoqqa kirish uchun <a href="/registration.php">ro\'yxatdan o\'ting</a> yoki <a href="/login.php">profilizga kiring</a>!');
  require_once ($rootpath . "incfiles/end.php");
  exit;
}
  $act = isset($_GET['act']) ? $_GET['act'] : '';
   switch ($act) {
 default:
  echo '<div class="phdr"><b>Anketam mehmonlari ro\'yxati</b></div>';
  $g_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `my_guests` WHERE `my_id` = '" . $user_id . "';"), 0);
if ($g_count > 0) {
  $p_ank = mysql_result(mysql_query("SELECT `prosm_ank` FROM `users` WHERE `id` = '" . $user_id . "';"), 0);
  $req = mysql_query("SELECT `my_guests`.*, `users`.`name`,`imname`, `users`.`sex`, `users`.`datereg`, `users`.`lastdate` FROM `my_guests` LEFT JOIN `users` ON `my_guests`.`guest_id` = `users`.`id`  WHERE `my_guests`.`my_id` = '" . $user_id . "' ORDER BY `my_guests`.`time` DESC LIMIT " . $start . ", " . $kmess . ";");
 while ($res = mysql_fetch_assoc($req)) {
  echo $i % 2 ? '<div class="list1">' : '<div class="list2">';
$guest = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $res['guest_id'] . "'"));
//Аватар
                    if ($set_user['avatar']) 
                        echo '<table cellpadding="0" cellspacing="0"><tr><td>'; 
                        if (file_exists(('../files/users/photo/' . $guest['id'] . '.jpg')))  
                            echo '<img style="border: 1px solid #d6d6d6; border-radius: 5px; float: left;" src="../files/users/photo/' . $guest['id'] . '.jpg" width="40" height="40" alt="' . $res['from'] . '" />&#160;';     
                    else
                          echo '<img style="border: 1px solid #d6d6d6; border-radius: 5px; float: left;" src="../images/empty.png" width="40" height="40" alt="' . $res['from'] . '" />&#160;';
                        echo '</td><td>'; 
                    
// Значек пола
if ($guest['sex']) {
echo (time() > $guest['lastdate'] + 2000 ? '<img style="margin-bottom:-2px;" src="'.$home.'/images/iconka/' . ($guest['sex'] == 'm' ? 'man' : 'woman') . ($guest['rights']> 7 && $guest['rights']< 10 ? '_sv' : '') . ($guest['rights']> 6 && $guest['rights']< 9 ? '_adm' : '') . ($guest['rights']> 5 && $guest['rights']< 7 ? '_smod' : '') . ($guest['rights']> 4 && $guest['rights']< 6 ? '_lmod' : '') . ($guest['rights']> 3 && $guest['rights']< 5 ? '_dmod' : '') . ($guest['rights']> 2 && $guest['rights']< 4 ? '_fmod' : '') . '_off.gif" width="14" height="14" align="bottom" alt=""/>&#160;' : '<img style="margin-bottom:-2px;" src="/images/iconka/' . ($res['sex'] == 'm' ? 'man' : 'woman') . ($guest['rights']> 7 && $guest['rights']< 10 ? '_sv' : '') . ($guest['rights']> 6 && $guest['rights']< 9 ? '_adm' : '') . ($guest['rights']> 5 && $guest['rights']< 7 ? '_smod' : '') . ($guest['rights']> 4 && $guest['rights']< 6 ? '_lmod' : '') . ($guest['rights']> 3 && $guest['rights']< 5 ? '_dmod' : '') . ($guest['rights']> 2 && $guest['rights']< 4 ? '_fmod' : '') . '_on.gif" width="14" height="14" align="bootom" alt=""/>');
             
} else {
echo'<img src="'.$home.'/images/del.png" style="width: 14px;" alt="-">';
}

// Ник юзера
echo '&#160;<a href="' . $home . '/users/profile.php?user=' . $res['guest_id'] . '"><b>' . $res['imname'] . '</b></a>'; 



$sek = time() - $res['lastdate'];
if ($sek == 0) {
$bbb = '<span class="green"> [on]</span>  ';
 } elseif ($sek < 60) {
 $bbb = '<span class="green"> ['.$sek.'s]</span>  ';
 } elseif ($sek > 60 && $sek < 120) {
 $bbb = '<span class="green"> [1m]</span>  ';
 } elseif ($sek > 120 && $sek < 180) {
 $bbb = '<span class="green"> [2m]</span>  ';
 } elseif ($sek > 180 && $sek < 240) {
 $bbb = '<span class="green"> [3m]</span>  ';
 } elseif ($sek > 240 && $sek < 300) {
 $bbb = '<span class="green"> [4m]</span>  ';
 } elseif($sek > 300 && $sek < 360) {
 $bbb = '<span class="green"> [5m]</span>  ';
 } elseif ($sek > 360 && $sek < 420) {
 $bbb = '<span class="green"> [6m]</span>  ';
 } elseif ($sek > 420 && $sek < 480) {
 $bbb = '<span class="green"> [7m]</span>  ';
 } elseif ($sek > 480 && $sek < 540) {
 $bbb = '<span class="green"> [8m]</span>  ';
 } elseif ($sek > 540 && $sek < 600) {
 $bbb = '<span class="green"> [9m]</span>  ';
 }else{
  $bbb = '<span style="color:red;"> [off] </span>  '; 
 }
echo  ' ' . $bbb . '';

// Время
echo '<br /><b>' . functions::display_date($res['time']) . '</b>' ;

//Новый гость или нет
 if ($res['type'] == '0') {
  echo '&#160;<span class="red"><b>new!</b></span>';
  @mysql_query("UPDATE `my_guests` SET `type` = '1' WHERE `id` = '" . $res['id'] . "';");
} 

                     if ($set_user['avatar']) 
                        echo '</td></tr></table>'; 
  echo '</div>';
  ++$i;
 }

//Постраничная навигация
if ($g_count > $kmess) {
echo '<div class="menu"><center>' . functions::display_pagination('my_guests.php?', $start, $g_count, $kmess) . '</center></div>';
}
echo '<div class="rmenu">';
echo '&raquo; <a href="my_guests.php?act=del">Ro\'yxatni tozalash</a><br />';
echo '&raquo; <a href="my_guests.php?act=sbros">Hisoblagichni yangilash</a></div>';

} else {
  echo '<div class="rmenu"><p>Anketangizga it ham kirmadi!</p></div>';
}
   break;

   case 'del':
//Очистка списка гостей
if (isset($_GET['yes'])) {
  @mysql_query("DELETE FROM `my_guests` WHERE `my_id` = '" . $user_id . "';");
echo '<div class="phdr"><b>Mehmonlar ro\'yxatini tozalash</b></div>';
echo '<div class="gmenu"><b>Mehmonlar ro\'yxati tozalandi!</b></div>';
} else {
echo '<div class="phdr"><b>Mehmonlar ro\'yxatini tozalash</b></div>';
echo '<div class="rmenu"><p>Rostdan ham tozalamoqchimisiz?<br/><a href="my_guests.php?act=del&amp;yes">Tozalash</a> | <a href="my_guests.php?">Bekor qilish</a></p></div>';
}
   break;

   case 'sbros':
//Сброс счетчика просмотров анкеты
if (isset($_GET['yes'])) {
  @mysql_query("UPDATE `users` SET `prosm_ank` = '0' WHERE `id` = '" . $user_id . "';");
echo '<div class="phdr"><b>Hisoblagichni yangilash</b></div>';
echo '<div class="gmenu"><b>Hisoblagich yangilandi!</b></div>';
} else {
echo '<div class="phdr"><b>Hisoblagichni yangilash</b></div>';
echo '<div class="rmenu"><p>Rostdan ham hisoblagichni yangilamoqchimisiz?<br/><a href="my_guests.php?act=sbros&amp;yes">Yangilash</a> | <a href="my_guests.php?">Bekor qilish</a></p></div>';
}
   break;
}
  require_once ($rootpath . "incfiles/end.php");

?>