<?

$glums = array(
    'dino' => '8',
    'tomate' => '4',
    'kraski' => '7',
    'puli' => '5',
    'pchel' => '9',
    'scelet' => '9',
    'kiss' => '9',
    'serdce' => '12',
);

$config = array(
    'timeout' => (60 * 10),
    'reboot' => (60 * 10),
    'balls'  => '10',
    'money'  => '0.4',
    'rating'  => '0.3',
    'balls_name'  => array('балл', 'балла', 'баллов'),
    'coins_name'  => array('монета', 'монеты', 'монет'),
    'rating_name'  => array('рейтинга', 'рейтинга', 'рейтинга'),
);

function weapon_panel($link = null) 
{
  global $glums;
  
  foreach($glums AS $key => $value) { 
    $link .= '<a href="?act=' . $key . '"><img src="images/' . $key . '.png" /></a>';
  }
  
  return $link;
}


function weapon_time($sec) {
  global $time;
  
  $sec -= $time;
  $s = 0;
  $m = 0;
  $h = 0;
  
  if ($sec) {
      $s = $sec % 60;
  }
  
  if ($sec >= 60) {
      $m = floor($sec / 60 % 60);
  }
  
  if ($sec >= 3600) {
      $h = floor($sec / 3600 % 24);
  }
  
  if ($h > 0) {
    $weapon[] = des2num($h, array('час', 'часа', 'часов'));
  }
  
  if ($m > 0) {
    $weapon[] = des2num($m, array('минута', 'минуты', 'минут'));
  }
  
  if ($s >= 0) {
    $weapon[] = des2num($s, array('секунда', 'секунды', 'секунд'));
  }
  
  return implode(' ', $weapon);
}

function weapon_view($id, $sex) 
{
  $q = mysql_query("SELECT * FROM `sexwars_weapons` WHERE `id_tournament` = '$id' AND `sex` = '$sex'");
  $img = '';
  while ($post = mysql_fetch_assoc($q)) {
    $style = unserialize($post['style']);
    $img .= '<img class="weapon" src="images/' . $post['type'] . '/' . $post['id_weapon'] . '.png" style="top: ' . $style['top'] . '%; left: ' . $style['left'] . '%; -moz-transform: rotate(' . $style['rotate'] . 'deg); -ms-transform: rotate(' . $style['rotate'] . 'deg); -webkit-transform: rotate(' . $style['rotate'] . 'deg); -o-transform: rotate(' . $style['rotate'] . 'deg); transform: rotate(' . $style['rotate'] . 'deg);">';
  }
  return $img;
}

function weapon_avatars($id, $sex) 
{
  $q = mysql_query("SELECT `sexwars_users`.`id_user`, `gallery_foto`.`id` 
                    FROM `sexwars_users` 
                    LEFT JOIN `gallery_foto` ON `sexwars_users`.`id_user` = `gallery_foto`.`id_user`
                    WHERE `sexwars_users`.`id_tournament` = '$id' AND `sexwars_users`.`sex` = '$sex' 
                          AND `sexwars_users`.`count_weapon` > '0' AND `gallery_foto`.`avatar` = '1' ORDER BY `sexwars_users`.`time_reboot` DESC LIMIT 50");
                    
                    
  $img = '';
  while ($post = mysql_fetch_assoc($q)) {
    $img .= '<img class="weapon_avatar" src="/foto/foto50/' . $post['id'] . '.jpg" />';
  }
  return $img;
}
