<?


  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  $SQL0 = 'SELECT * FROM articles WHERE type=0 AND status=1 GROUP BY type';
  if (!($result0 = mysql_query ($SQL0)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $row0 = mysql_fetch_array ($result0);
  $_GET['cat_id'] = $row0['category'];
  include '../../lang/' . language;
  if ($_GET['tim'])
  {
    $SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC LIMIT ' . typical_amount;
  }
  else
  {
    $SQL = '' . 'SELECT * FROM articles WHERE category=\'' . $_GET['cat_id'] . '\' AND type=0 AND status=1 ORDER by tim DESC LIMIT ' . typical_amount;
  }

  if (!($result = mysql_query ($SQL)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $row = mysql_fetch_array ($result);
  if (!($result = mysql_query ($SQL)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  if ($dir = @opendir ('../../upload/cat_images/'))
  {
    while ($file = readdir ($dir) !== false)
    {
      if (strpos ($_GET['cat_id'], '~'))
      {
        $patt = substr ($_GET['cat_id'], 0, strpos ($_GET['cat_id'], '~'));
      }
      else
      {
        $patt = $_GET['cat_id'];
      }

      if (strstr ($file, $patt))
      {
        echo '<IMG SRC="../../upload/cat_images/';
        echo $file;
        echo '" width="100%" border=0>';
        continue;
      }
    }

    closedir ($dir);
  }

  echo '
';
  if ($_GET['tim'])
  {
    $SQL0 = '' . 'SELECT * FROM articles WHERE instr(category,\'' . $_GET['cat_id'] . '\') AND type=2 AND status=1 AND tim<' . $_GET['tim'] . ' ORDER by tim DESC LIMIT ' . typical_headlines_amount;
  }
  else
  {
    $SQL0 = '' . 'SELECT * FROM articles WHERE instr(category,\'' . $_GET['cat_id'] . '\') AND type=2 AND status=1 ORDER by tim DESC LIMIT ' . typical_headlines_amount;
  }

  if (!($result0 = mysql_query ($SQL0)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $row0 = mysql_fetch_array ($result0);
  if (!($result0 = mysql_query ($SQL0)))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  if ($row0)
  {
    echo '		
			<table width="150" border="0" cellspacing="0" cellpadding="7" align="right" style="border: ';
    if (typical_headlines_border == 1)
    {
      echo 1;
    }
    else
    {
      echo 0;
    }

    echo 'px solid ';
    echo typical_headlines_border_color;
    echo '; background: ';
    echo typical_headlines_bg_color;
    echo ';">
			<tr bgcolor="';
    echo typical_headlines__bg__color;
    echo '"><td align="center" valign="top"><font STYLE="color:';
    echo typical_headlines__color;
    echo '; font-family:';
    echo typical_headlines__font;
    echo '; font-size:';
    echo typical_headlines__font__size;
    echo '; font-weight:';
    echo typical_headlines__font__weight;
    echo ';">';
    echo $text__Headlines;
    echo '</font></td></tr>
			<tr><td valign="top">
			';
    while ($row0 = mysql_fetch_array ($result0))
    {
      echo '<a href="javascript:" STYLE="color:';
      echo typical_headlines_title_color;
      echo '; font-family:';
      echo typical_headlines_title_font;
      echo '; font-size:';
      echo typical_headlines_title_font_size;
      echo '; font-weight:';
      echo typical_headlines_title_font_weight;
      echo ';">';
      echo $row0['title'];
      echo '</a>
				<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="5"></td></tr></table>
				';
      if (typical_headlines_tmb == 'yes')
      {
        if ($dir = @opendir ('../../upload/thumbnails/'))
        {
          while ($file = readdir ($dir) !== false)
          {
            if (strstr ($file, $row0['tim']))
            {
              echo '<a href="javascript:"><IMG SRC="../../upload/thumbnails/';
              echo $file;
              echo '" vspace="5" align="';
              echo typical_headlines_tmb_align;
              echo '" ';
              if (typical_headlines_tmb_width)
              {
                echo 'width="';
                echo typical_headlines_tmb_width;
                echo '"';
              }

              echo ' ';
              if (typical_headlines_tmb_height)
              {
                echo 'height="';
                echo typical_headlines_tmb_height;
                echo '"';
              }

              echo ' style="border: 1px solid Black;"></a>';
              continue;
            }
          }

          closedir ($dir);
        }
      }

      echo '					
					
					<font STYLE="color:';
      echo typical_headlines_description_color;
      echo '; font-family:';
      echo typical_headlines_description_font;
      echo '; font-size:';
      echo typical_headlines_description_font_size;
      echo '; font-weight:';
      echo typical_headlines_description_font_weight;
      echo ';">&#8226;&nbsp;';
      echo $row0['description'];
      echo '</font><br>
			';
    }

    echo '			</td></tr></table>
	';
  }

  echo '		
		
	<table border="0">
		
	';
  while ($row = mysql_fetch_array ($result))
  {
    echo '			<tr><td valign="top">
				<a href="javascript:" STYLE="color:';
    echo typical_title_color;
    echo '; font-family:';
    echo typical_title_font;
    echo '; font-size:';
    echo typical_title_font_size;
    echo '; font-weight:';
    echo typical_title_font_weight;
    echo ';">';
    echo $row['title'];
    echo '</a>
			</td></tr>
			
			<tr><td valign="top" height=1></td></tr>
			
			<tr><td valign="top">
				';
    if ($dir = @opendir ('../../upload/thumbnails/'))
    {
      while ($file = readdir ($dir) !== false)
      {
        if (strstr ($file, $row['tim']))
        {
          echo '<a href="javascript:"><IMG SRC="../../upload/thumbnails/';
          echo $file;
          echo '" align="';
          echo typical_tmb_align;
          echo '" ';
          if (typical_tmb_width)
          {
            echo 'width="';
            echo typical_tmb_width;
            echo '"';
          }

          echo ' ';
          if (typical_tmb_height)
          {
            echo 'height="';
            echo typical_tmb_height;
            echo '"';
          }

          echo ' style="border: 1px solid Black;"></a>';
          continue;
        }
      }

      closedir ($dir);
    }

    echo '				
				<font STYLE="color:';
    echo typical_description_color;
    echo '; font-family:';
    echo typical_description_font;
    echo '; font-size:';
    echo typical_description_font_size;
    echo '; font-weight:';
    echo typical_description_font_weight;
    echo ';">';
    echo $row['description'];
    echo '</font>
	
			</td></tr>
			<tr><td valign="top" height=7></td></tr>
	';
  }

  echo '		
		</table>
		';
?>
