Просмотр файла includes/functions_fc.php

Размер файла: 3.15Kb
<?
function get_categories($categories=''){
 global $db;
if (isset($categories))
 {
   if ($categories!='' and intval($categories)>0 and strlen($categories)<5)
    {
      $categories = intval($categories);
      $sql = 'SELECT forum_id FROM FOR_attachments WHERE forum_id='.$categories.' LIMIT 0,1';
      if(!$result = $db->sql_query($sql))
        {
        	message_die(GENERAL_ERROR, "has occurred error at request amount files from chosen to categories", '', __LINE__, __FILE__);
        }
      $row=$db->sql_fetchrow($result);
      if (!mysql_num_rows($result))
       {
          $categories=0;
          $error='Неверно указана категория';
       }
    }else{
       $categories=0;
    }
 }else{
    $categories=0;
 }
 return $categories;
}
function get_page($page='', $categories='')
{
if (isset($page) and $categories!=0)
 {
   if ($page!='' and $page>0 and strlen($page)<5)
    {
       global $db;
      $page = intval($page);
      $sql='SELECT attach_id FROM FOR_attachments WHERE forum_id='.$categories.' LIMIT '.$page.', 1';
      $result=$db->sql_query($sql);
      if (mysql_num_rows($result)==0)
        {
          $page=0;
        }
    }else{
       $page=0;
    }
 }else{
    $page=0;
 }
 return $page;
}
function get_count_id($count_id='', $categories='', $page='') 
{
if (isset($count_id) and intval($count_id)>0 and strlen($count_id)<5 and $categories>0 and $page>=0)
  {
    global $db;
    $count_id=intval($count_id);
    $sql='SELECT attach_id, forum_id,post_id FROM FOR_attachments WHERE attach_id='.$count_id.' AND forum_id='.$categories;
    if (!$result=$db->sql_query($sql))
     {
          message_die(GENERAL_ERROR, "has occurred error at request amount files from chosen to categories", '', __LINE__, __FILE__);
     }
     if (!mysql_num_rows($result))
      {
         $count_id=0;
         $error='В выбраной категории нет файла с указаным id';
      }else{
         $row=$db->sql_fetchrow($result);
      }
  }else{
       $count_id=0;
  }
  return $count_id;
}
function identification_user($sid='')
{
if (isset($sid))
 {
    $sid=htmlspecialchars(stripslashes($sid));
     global $db;
    $session_query='SELECT * FROM FOR_sessions WHERE session_id="'.$sid.'"';
    $session_result=$db->sql_query($session_query);
    $session=$db->sql_fetchrow($session_result);
    if (mysql_num_rows($session_result)>0)
     {
       $user_id=$session['session_user_id'];
       if ($user_id!=-1)
       {
          $user_data='SELECT username, user_level FROM FOR_users WHERE user_id='.$user_id;
          $user_data=$db->sql_query($user_data);
          $user_data=$db->sql_fetchrow($user_data);
   
          $user_level=$user_data['user_level'];
          $user_name=$user_data['username'];
        }else{
           $user_level=0;
           $user_name='Anonymous';
        }
      }else{
            $user_level=0;
            $user_name='Anonymous';
            $user_id!=-1;
      }
}else{
       $user_level=0;
       $user_name='Anonymous';
       $user_id!=-1;
}
 $user_data['name']=$user_name;
 $user_data['user_level']=$user_level;
 $user_data['user_id']=$user_id;
  $user_data['sid']=$sid;
 return $user_data;
}
?>