Файл: public_html/inc/function.php
Строк: 869
<?php
//склонение слов
function getWord($number, $suffix) 
{
  $keys = array(2, 0, 1, 1, 1, 2);
  
  $mod = $number % 100;
  
  $suffix_key = ($mod > 7 && $mod < 20) ? 2: $keys[min($mod % 10, 5)];
  
  return $suffix[$suffix_key];
}
//информация о пользователе
function usersInfo($id=null)
{
  global $mysqli;
  
  static $result = array();
  
  if ($id === null) $id = $_SESSION['user_id']; 
  
  if (!isset($result[$id])) 
  {
    $query = $mysqli->query("SELECT * FROM `".PREFIX."_users` WHERE `id` = '".$id."' LIMIT 1");
        
    $result[$id] = $query->fetch_assoc();
  }
  
  return $result[$id];
}
//проверка цвета
function isValidColor($color) 
{
  if (!is_string($color)) 
  {
    trigger_error('Parameter 1 must be string, ' . gettype($color) . ' given', E_USER_WARNING);
    return false;
  }
     
  $color = str_replace(array("f", "n", "r", "t", "v", ' '), '', strtolower($color));
  $colors = array('transparent', 'white', 'silver', 'gray', 'black', 'maroon', 'red', 'orange', 'yellow', 'olive', 'lime', 'green', 'aqua', 'blue', 'navy', 'teal', 'fuchsia', 'purple');
     
  return in_array($color, $colors) ?: (bool) preg_match('#^(?:#[da-f]{3}|[da-f]{6})|(?:rgb(a)?((?:(?:1?d{1,2}|2(5)?(?(2)[0-5]|[0-4]d)),){2}(?:1?d{1,2}|2(5)?(?(3)[0-5]|[0-4]d))(?(1),(?:1(?:.0+)?|0?.d+))))|(?:hsl(a)?((?:[1-2]?d{1,2}|3[0-5]d),1?d{1,2}%,1?d{1,2}%(?(4),(?:1(?:.0+)?|0?.d+))))$#i', trim($color));
}
//обновление статистики сайта
function addStats($type, $num)
{
  global $mysqli;  
    
  $mysqli->query("UPDATE `".PREFIX."_config` SET `".$type."` = `".$type."` + '".$num."' WHERE id = '1'");  
}
//вывод сообщений
function printMessage($msg)
{
  switch ($msg)
  {
    case '100':
    $m = '<div class="success">Сохранение прошло успешно!</div>';    
    break;
    case '200':
    $m = '<div class="error">Ошибка введённых данных</div>';    
    break;
    case '300':
    $m = '<h1>Сообщение отправлено</h1>';    
    return $m; 
        
    break;
    default:
    break;
  }
  $m = '<div id="notes">'.$m.'</div>';
  
  return $m;  
}
//получение тиц
function getTCY($url)
{
  if (!isset($_SESSION[$url]['TCY']))  
  {  
    $xml = file_get_contents('http://bar-navig.yandex.ru/u?ver=2&show=32&url='.$url);
    $tcy = $xml ? (int) substr(strstr($xml, 'value="'), 7) : 0;
  
    $_SESSION[$url]['TCY'] = $tcy;
  }
  else 
  {
    $tcy = $_SESSION[$url]['TCY'];  
  }
  
  return $tcy;
}
//генератор пароля
function genPassword($number)
{
  $arr = array('a','b','c','d','e','f',
                 'g','h','i','j','k','l',
                 'm','n','p','r','s',
                 't','u','v','x','y','z',
                 'A','B','C','D','E','F',
                 'G','H','I','J','K','L',
                 'M','N','P','R','S',
                 'T','U','V','X','Y','Z',
                 '1','2','3','4','5','6',
                 '7','8','9');  
  $pass = "";
  for($i = 0; $i < $number; $i++)
  {      
    $index = rand(0, count($arr) - 1);
    $pass .= $arr[$index];
  }
  return $pass;
}
//постраничная навигация ссылок
function printPageNavLink($page, $pages_count, $total, $perpage)
{ 
  global $_POST;  
    
  global $topic;
  
  $topic = implode($topic, ",");
  
  $tmp = '';
  $tmp = $tmp.'<div class="page_selector">';
  $tmp = $tmp.'<span>Страница: </span>';
  
  if ($page > 1) 
  {
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
                <input type="hidden" name="type" value="search">
                <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
                <input type="hidden" name="page" value="'.($page - 1).'">
                <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
                <input type="submit" class="selector" value="◄">
                </form>';
  }
     
  $start_page = 1;
  $end_page = $pages_count;
    
  if ($page - 5 > 0) 
  {     
    $start_page = $page - 4;
      
    if ($page + 4 > $pages_count) 
    { 
      $start_page = $pages_count - 8;             
    }  
      
    if ($start_page < 2)
    {  
      $start_page = 1;               
    }
      
    if ($start_page > 1)
    {
      $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
          <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
         <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="page" value="1">
            <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="...">
            </form>';       
    } 
  }
     
  $t = 0;
    
  if ($page + 4 < $pages_count && $page + 8 < $pages_count)
  {
    $end_page = $start_page + 8;
      
    $t = 1;
  }
  
  if ($total > $perpage)
  {
    for($n = $start_page; $n <= $end_page; $n++)
    {   
      if ($n == $page)
      {
        $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="page" value="'.$n.'">
             <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector active" disabled="disabled" value="'.$n.'">
            </form>';
      }
      else 
      { 
        $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="page" value="'.$n.'">
             <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="'.$n.'">
            </form>';
      }
    }
  }
    
  if ($t)
  { 
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="page" value="'.$pages_count.'">
             <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="...">
            </form>';
  }
       
  if ($page < $pages_count && $pages_count > 1)
  {
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
        <input type="hidden" name="type" value="search">
                <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">
                <input type="hidden" name="text" value="'.$_POST['text'].'">
                <input type="hidden" name="url" value="'.$_POST['url'].'">
                <input type="hidden" name="page" value="'.($page + 1).'">                
                <input type="hidden" name="specc" value="'.@$_POST['specc'].'">
                <input type="hidden" name="scolor" value="'.$_POST['scolor'].'">
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
                <input type="submit" class="selector" value="►">
                </form>'; 
  }
   
  $tmp = $tmp.'</div>';
  echo $tmp;
}
//постраничная навигация баннеров
function printPageNavBanner($page, $pages_count, $total, $perpage)
{ 
  global $_POST;  
    
  global $topic;
  
  $topic = implode($topic, ",");
  
  $tmp = '';
  $tmp = $tmp.'<div class="page_selector">';
  $tmp = $tmp.'<span>Страница: </span>';
  
  if ($page > 1) 
  {
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
        <input type="hidden" name="type" value="search">
        <input type="hidden" name="price" value="'.$_POST['price'].'">
        <input type="hidden" name="hits" value="'.$_POST['hits'].'">
        <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
        <input type="hidden" name="tic" value="'.$_POST['tic'].'">
        <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
        <input type="hidden" name="url" value="'.$_POST['url'].'">
                <input type="hidden" name="img" value="'.$_POST['img'].'">
        <input type="hidden" name="size" value="'.$_POST['size'].'">
        <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">    
        <input type="hidden" name="page" value="'.($page - 1).'">                
        <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
        <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
        <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
        <input type="hidden" name="hidden_topics" value="'.$topic.'">
        <input type="submit" class="selector" value="◄">
        </form>';
  }
     
  $start_page = 1;
  $end_page = $pages_count;
    
  if ($page - 5 > 0) 
  {     
    $start_page = $page - 4;
      
    if ($page + 4 > $pages_count) 
    { 
      $start_page = $pages_count - 8;             
    }  
      
    if ($start_page < 2)
    {  
      $start_page = 1;               
    }
      
    if ($start_page > 1)
    {
      $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
             <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
         <input type="hidden" name="hits" value="'.$_POST['hits'].'">
         <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
         <input type="hidden" name="tic" value="'.$_POST['tic'].'">
         <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
         <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="page" value="1">
             <input type="hidden" name="img" value="'.$_POST['img'].'">
             <input type="hidden" name="size" value="'.$_POST['size'].'">
         <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">  
         <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
         <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
         <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
         <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="...">
            </form>';       
    } 
  }
     
  $t = 0;
    
  if ($page + 4 < $pages_count && $page + 8 < $pages_count)
  {
    $end_page = $start_page + 8;
      
    $t = 1;
  }
  
  if ($total > $perpage)
  {
    for($n = $start_page; $n <= $end_page; $n++)
    {   
      if ($n == $page)
      {
        $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
                <input type="hidden" name="url" value="'.$_POST['url'].'">
                                    <input type="hidden" name="img" value="'.$_POST['img'].'">
        <input type="hidden" name="size" value="'.$_POST['size'].'">
        <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">  
             <input type="hidden" name="page" value="'.$n.'">             
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector active" disabled="disabled" value="'.$n.'">
            </form>';
      }
      else 
      { 
        $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
                <input type="hidden" name="url" value="'.$_POST['url'].'">
                                    <input type="hidden" name="img" value="'.$_POST['img'].'">
        <input type="hidden" name="size" value="'.$_POST['size'].'">
        <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">  
             <input type="hidden" name="page" value="'.$n.'">
             
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="'.$n.'">
            </form>';
      }
    }
  }
    
  if ($t)
  { 
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
            <input type="hidden" name="type" value="search">
         <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
                <input type="hidden" name="url" value="'.$_POST['url'].'">
             <input type="hidden" name="img" value="'.$_POST['img'].'">
        <input type="hidden" name="size" value="'.$_POST['size'].'">
        <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">  
             <input type="hidden" name="page" value="'.$pages_count.'">
             
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
             <input type="submit" class="selector" value="...">
            </form>';
  }
       
  if ($page < $pages_count && $pages_count > 1)
  {
    $tmp = $tmp.'<form name="form2" method="post" action="" onsubmit="transfer();">
        <input type="hidden" name="type" value="search">
                <input type="hidden" name="price" value="'.$_POST['price'].'">
                <input type="hidden" name="hits" value="'.$_POST['hits'].'">
                <input type="hidden" name="hosts" value="'.$_POST['hosts'].'">
                <input type="hidden" name="tic" value="'.$_POST['tic'].'">
                <input type="hidden" name="pr" value="'.$_POST['pr'].'">                
                <input type="hidden" name="url" value="'.$_POST['url'].'">
                                    <input type="hidden" name="img" value="'.$_POST['img'].'">
        <input type="hidden" name="size" value="'.$_POST['size'].'">
        <input type="hidden" name="weeks" value="'.$_POST['weeks'].'">  
                <input type="hidden" name="page" value="'.($page + 1).'">                                
                <input type="hidden" id="multiprice" name="multiprice" value="'.@$_POST['multiprice'].'">
                <input type="hidden" id="multiid" name="multiid" value="'.@$_POST['multiid'].'">
                <input type="hidden" id="selectallid" name="selectallid" value="'.@$_POST['selectallid'].'">
                <input type="hidden" name="hidden_topics" value="'.$topic.'">
                <input type="submit" class="selector" value="►">
                </form>'; 
  }
   
  $tmp = $tmp.'</div>';
  echo $tmp;
}
//постраничная навигация
function printPageNav($page, $pages_count, $url, $total, $perpage)
{ 
  $uri = '?';
 
  if (isset($_GET))
  { 
    //$uri = "?";
    
    foreach($_GET as $key => $value)
    {                                
      if ($key != 'p')
      {
        if (is_array($value))
        {
          foreach ($value as $v)
          {
            $uri .= "{$key}[]={$v}&";
          }
        }
        else 
        { 
          $uri .= "{$key}={$value}&"; 
        } 
      }
    }
  }
  
  $url = $url.$uri;  
    
  $tmp = '';
  $tmp = $tmp.'<div class="page_selector">';
  $tmp = $tmp.'<span>Страница: </span>';
  
  if ($page > 1) 
  {
    $tmp = $tmp.'<a class="selector" href="'.$url.'p='.($page - 1).'">◄</a>';
  }
     
  $start_page = 1;
  $end_page = $pages_count;
    
  if ($page - 5 > 0) 
  {     
    $start_page = $page - 4;
      
    if ($page + 4 > $pages_count) 
    { 
      $start_page = $pages_count - 8;             
    }  
      
    if ($start_page < 2)
    {  
      $start_page = 1;               
    }
      
    if ($start_page > 1)
    {
      $tmp = $tmp.'<a class="selector" href="'.$url.'p=1">...></a>';       
    } 
  }
     
  $t = 0;
    
  if ($page + 4 < $pages_count && $page + 8 < $pages_count)
  {
    $end_page = $start_page + 8;
      
    $t = 1;
  }
  
  if ($total > $perpage)
  {
    for($n = $start_page; $n <= $end_page; $n++)
    {   
      if ($n == $page)
      {
        $tmp = $tmp.'<a class="selector active" href="'.$url.'p='.$n.'">'.$n.'</a>';
      }
      else 
      { 
        $tmp = $tmp.'<a class="selector" href="'.$url.'p='.$n.'">'.$n.'</a>';
      }
    }
  }
    
  if ($t)
  { 
    $tmp = $tmp.'<a class="selector" href="'.$url.'p='.$pages_count.'">...</a>';
  }
       
  if ($page < $pages_count && $pages_count > 1)
  {
    $tmp = $tmp.'<a class="selector" href="'.$url.'p='.($page + 1).'">►</a>'; 
  }
   
  $tmp = $tmp.'</div>';
  echo $tmp;
}
function addZakaz($res, $wallet, $payment)
{
  global $obEngine;
  global $mysqli;    
   
  $type = $res['type'];
        
  if ($type == 1) #пополнение баланса
  {
    payRef($res, $type, $payment);
        
    $mysqli->query("UPDATE `".PREFIX."_users` SET `money` = `money` + '".$res['price']."', `money_in` = `money_in` + '".$res['price']."' WHERE `id` = '".$res['user_id']."'"); 
  } 
  else if ($type == 2) #покупка ссылок
  {
    $data = unserialize($res['data']);
      
    $ids = explode("_", $data['ids']);
    $url = $data['url'];
    $text = $data['text'];
    $color = $data['color'];
    $specc = $data['specc'];
    $price = $res['price'];
      
    if ($payment != 'Баланс') { payRef($res, $type, $payment); }
    
    foreach ($ids as $key => $value) 
    {
      $id = (int)$value;
        
      $query = $mysqli->query("SELECT * FROM `".PREFIX."_blocks` WHERE `type` = '1' and `id` = '".$id."' LIMIT 1");    
  
      if ($query->num_rows)
      {
        $res_block = $query->fetch_assoc();  
          
        $price_it = $specc ? ($res_block['sum'] + $res_block['sumcolor']) : $res_block['sum'];
          
        $mysqli->query("UPDATE `".PREFIX."_users` SET `money_frozen` = `money_frozen` + '".$price_it."' WHERE `id` = '".$res_block['user_id']."'"); 
          
        $mysqli->query("INSERT INTO `".PREFIX."_links` 
                                      (
                                       `ident`,
                                       `time_add`,
                                       `user_id`,
                                       `user_blocks`,                                       
                                       `sum`,
                                       `price`,
                                       `money`,                                      
                                       `text`,
                                       `url_block`,                                                        
                                       `url_site`,
                                       `color`,
                                       `specc`,
                                       `stats`,
                                       `status`                                      
                                      )
                                      VALUES
                                      (                                                                                                                    
                                       '".$id."',
                                       NOW(),
                                       '".$res['user_id']."', 
                                       '".$res_block['user_id']."',                                                                  
                                       '".$res_block['sum']."',
                                       '".$price_it."',
                                       '".$price_it."',    
                                       '".$text."',    
                                       '".$res_block['url']."',                                      
                                       '".$url."',
                                       '".$color."',
                                       '".$specc."',    
                                       '',
                                       '1'                                        
                                      )");
        $n_count++;
        
        $query = $mysqli->query("SELECT * FROM `".PREFIX."_links` WHERE `status` = '1' and `ident` = '".$id."' ORDER BY `time_add` DESC");    
  
        if ($query->num_rows > $res_block['slots'])
        {
          $n = 1;  
          
          while ($row = $query->fetch_assoc())
          {
            if ($n > $res_block['slots'])
            {
              $mysqli->query("UPDATE `".PREFIX."_links` SET `status` = '0' WHERE `id` = '".$row['id']."'");  
            
              $res_user = $mysqli->query("SELECT `money_frozen` FROM `".PREFIX."_users` WHERE `id` = '".$row['user_blocks']."' LIMIT 1")->fetch_assoc();    
              
              if ($res_user['money_frozen'] >= $row['price'])
              {    
                $mysqli->query("UPDATE `".PREFIX."_users` SET `money` = `money` + '".$row['price']."', `money_all` = `money_all` + '".$row['price']."', `money_link` = `money_link` + '".$row['price']."', `money_frozen` = `money_frozen` - '".$row['price']."' WHERE `id` = '".$row['user_blocks']."'"); 
              } 
              else 
              {
                $mysqli->query("UPDATE `".PREFIX."_users` SET `money` = `money` + '".$row['price']."', `money_all` = `money_all` + '".$row['price']."', `money_link` = `money_link` + '".$row['price']."', `money_frozen` = '0' WHERE `id` = '".$row['user_blocks']."'");  
              }                
                
              $mysqli->query("INSERT INTO `".PREFIX."_history`
                                      (
                                       `time_add`,
                                       `user_id`,
                                       `type`,
                                       `money`                                      
                                      )
                                      VALUES
                                      (
                                       NOW(),
                                       '".$row['user_blocks']."',
                                       'link',    
                                       '".$row['price']."'                                       
                                      )");
                
              $mysqli->query("UPDATE `".PREFIX."_config` SET `success_work` = `success_work` + '1' WHERE `id` = '1'");
              
              $mysqli->query("UPDATE `".PREFIX."_config` SET `users_profit` = `users_profit` + '".$row['price']."' WHERE `id` = '1'");
            }    
            
            $n++; 
          }
        }        
      }
    }  
  } 
  else if ($type == 3) #покупка баннеров
  {
    $data = unserialize($res['data']);
    
    $ids = explode("_", $data['ids']);
    $url = $data['url'];
    $img = $data['img'];
    $weeks = $data['weeks'];
    $price = $res['price'];     
    
    if ($payment != 'Баланс') { payRef($res, $type, $payment); }
    
    foreach ($ids as $key => $value) 
    {
      $id = (int)$value;
        
      $query = $mysqli->query("SELECT * FROM `".PREFIX."_blocks` WHERE `type` = '2' and `id` = '".$id."' LIMIT 1");    
  
      if ($query->num_rows)
      {
        $res_block = $query->fetch_assoc();  
      
        $price_it = $res_block['sum'] * $weeks;
          
        $mysqli->query("UPDATE `".PREFIX."_users` SET `money_frozen` = `money_frozen` + '".$price_it."' WHERE `id` = '".$res_block['user_id']."'"); 
          
        $mysqli->query("INSERT INTO `".PREFIX."_banners` 
                                      (
                                       `ident`,
                                       `time_add`,
                                       `user_id`,
                                       `user_blocks`,
                                       `size`,
                                       `sum`,
                                       `price`,
                                       `money`,
                                       `weeks`,
                                       `url_block`,                  
                                       `url_banner`,
                                       `url_site`,
                                       `stats`,
                                       `status`                                      
                                      )
                                      VALUES
                                      (                                                                                                                    
                                       '".$id."',
                                       NOW(),
                                       '".$res['user_id']."', 
                                       '".$res_block['user_id']."',    
                                       '".$res_block['size']."',                         
                                       '".$res_block['sum']."',
                                       '".$price_it."',
                                       '".$price_it."',    
                                       '".$weeks."',
                                       '".$res_block['url']."',
                                       '".$img."',
                                       '".$url."',
                                       '',
                                       '1'                                        
                                      )");
        $n_count++;
      } 
    }  
  }    
    
  #отмечаем что заказ выполнен
  $mysqli->query("UPDATE `".PREFIX."_history_pay` SET `time_pay` = NOW(), `payment` = '".$payment."', `wallet` = '".$wallet."', `status` = '1' WHERE `id` = '".$res['id']."'"); 
    
  return true;
}
function payRef($res, $type, $payment)
{
  global $obEngine;
  global $mysqli;   
    
  $ref = $mysqli->query("SELECT `id`, `referer` FROM `".PREFIX."_users` WHERE `id` = '".$res['user_id']."' LIMIT 1")->fetch_assoc();    
                         
  if ($ref['referer'] > 0)
  { 
    $money_ref = sprintf("%.2f", $res['price']*($obEngine->getConfig('ref_proc')/100)); 
    
    $mysqli->query("UPDATE `".PREFIX."_users` SET `money` = `money` + '".$money_ref."', `money_ref` = `money_ref` + '".$money_ref."', `money_all` = `money_all` + '".$money_ref."' WHERE `id` = '".$ref['referer']."'"); 
          
    $mysqli->query("INSERT INTO `".PREFIX."_history_payref`
                                      (
                                       `time_add`,
                                       `user_id`,
                                       `referer`,
                                       `type`,
                                       `payment`,
                                       `price`,
                                       `money`,
                                       `id_zakaz`
                                      )
                                      VALUES
                                      (
                                       NOW(),
                                       '".$res['user_id']."',
                                       '".$ref['referer']."',    
                                       '".$type."',    
                                       '".$payment."',
                                       '".$res['price']."',
                                       '".$money_ref."',
                                       '".$res['id']."'    
                                      )"); 
    
    $mysqli->query("UPDATE `".PREFIX."_config` SET `users_profit` = `users_profit` + '".$money_ref."' WHERE `id` = '1'");
  } 
}
function addLogs($data)
{  
  $all = "|$data|n";  
       
  $filename = BASE_DIR.'/logs/log.txt';  
        
  function object2file($value, $filename)
  {    
    $f = fopen($filename, 'a');
    fwrite($f, $value);
    fclose($f);
  }
  object2file($all, $filename);
}