<?

  include_once '../../lang/english.php';
  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  if (!($result_proper = mysql_query ('select * from properties')))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $proper = mysql_fetch_array ($result_proper);
  include '../lang/' . $proper['admin_language'];
  echo '
<HTML><BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="800" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD style="background-color:#505090;"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#EFEFF8">
<TR><TD VALIGN=top BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;"><FONT COLOR="navy"><B>';
  echo $admin_Add_Edit_Delete_Articles;
  echo '</B></FONT></TD></TR><TR><TD VALIGN=top>

';
  echo '<S';
  echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function confirmSubmit(record) 
{
if (confirm("Are you sure you wish to delete article \\"" + record + "\\"?"))
	return true ;
else
	return false ;
}
//-->
</SCRIPT>

';
  if ($_GET['delete'])
  {
    if (!(mysql_query ('' . 'DELETE FROM articles WHERE id=' . $_GET['delete'])))
    {
      exit ('Query failed');
      ;
    }
  }

  echo '

<FORM ACTION="';
  echo $php_self;
  echo '" METHOD="post">

';
  echo $admin_Display_last;
  echo '<S';
  echo 'ELECT NAME="display">
';
  for ($i = 10; $i <= 100; $i += 10)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '">';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo $admin_Arranged_by_category;
  echo '<S';
  echo 'ELECT NAME="category">
<OPTION VALUE="" SELECTED>';
  echo $admin_All;
  echo '</OPTION>
';
  if (!($result1 = mysql_query ('SELECT * FROM categories')))
  {
    exit ('Query failed4');
    ;
  }

  $i = 0;
  while ($row1 = mysql_fetch_array ($result1))
  {
    $TMP1[$i++] = $row1['id'];
  }

  if (!($result = mysql_query ('' . 'SELECT * FROM users WHERE md5(md5(password))=\'' . $_COOKIE['catselect'] . '\'')))
  {
    exit ('Query failed4');
    ;
  }

  $row = mysql_fetch_array ($result);
  $TMP = split ('
', $row['allowed']);
  $match = array_intersect ($TMP, $TMP1);
  for ($i = 0; $i < sizeof ($match); ++$i)
  {
    if ($match[$i] != '')
    {
      if (!($result = mysql_query ('' . 'SELECT * FROM categories WHERE id=\'' . $match[$i] . '\'')))
      {
        exit ('Query failed4');
        ;
      }

      $row = mysql_fetch_array ($result);
    }

    if ($row['name'] != '')
    {
      echo '<option value="';
      echo $row['name'];
      echo '">';
      echo $row['name'];
      echo '</option>';
      if (!($result11 = mysql_query ('' . 'SELECT * FROM sub_categories WHERE parent=\'' . $match[$i] . '\'')))
      {
        exit ('Query failed');
        ;
      }

      $row11 = mysql_fetch_array ($result11);
      if ($row11['name'] != '')
      {
        echo $cat11 = split ('
', $row11[1]);
        for ($j = 0; $j < sizeof ($cat11); ++$j)
        {
          echo '<option value="';
          echo $row['name'] . '~' . $cat11[$j];
          echo '">&nbsp;&middot;&nbsp;';
          echo $cat11[$j];
          echo '</option>';
        }

        continue;
      }

      continue;
    }
  }

  echo '</select>	
';
  if (($_COOKIE['root'] OR $_COOKIE['editor']))
  {
    echo '<S';
    echo 'ELECT NAME="status">
	<OPTION VALUE="" SELECTED>';
    echo $admin_All;
    echo '</OPTION>
	<OPTION VALUE="1">';
    echo $admin_Pending;
    echo '</OPTION>
	<OPTION VALUE="2">';
    echo $admin_Visible;
    echo '</OPTION>
	<OPTION VALUE="3">';
    echo $admin_Hidden;
    echo '</OPTION>
</SELECT>
';
  }

  echo 'by type:
';
  echo '<S';
  echo 'ELECT NAME="type">
	<OPTION VALUE="" SELECTED>';
  echo $admin_All;
  echo '</OPTION>	
	<OPTION VALUE="1">';
  echo $admin_Typical;
  echo '</OPTION>
	<OPTION VALUE="2">';
  echo $admin_Breaking_News;
  echo '</OPTION>
	<OPTION VALUE="3">';
  echo $admin_Headline;
  echo '</OPTION>
	<OPTION VALUE="4">';
  echo $admin_Interview;
  echo '</OPTION>
</SELECT>

<BR><BR>

';
  echo $admin_articles_published_from;
  echo '<S';
  echo 'ELECT NAME="post_day_from">';
  for ($i = 1; $i < 32; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == 1)
    {
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo '<S';
  echo 'ELECT NAME="post_month_from">';
  for ($i = 0; $i < 12; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == 0)
    {
    }

    echo '>';
    echo $month[$i];
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo '<S';
  echo 'ELECT NAME="post_year_from">';
  for ($i = 2000; $i <= date ('Y', $curtime[0]); ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == 2000)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo $admin_to;
  echo '<S';
  echo 'ELECT NAME="post_day_to">';
  for ($i = 1; $i < 32; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('j', $curtime[0]))
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo '<S';
  echo 'ELECT NAME="post_month_to">';
  for ($i = 0; $i < 12; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('n', $curtime[0]) - 1)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $month[$i];
    echo '</OPTION>';
  }

  echo '</SELECT>
';
  echo '<S';
  echo 'ELECT NAME="post_year_to">';
  for ($i = 2000; $i <= date ('Y', $curtime[0]); ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('Y', $curtime[0]))
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
&nbsp;&nbsp;&nbsp;
<INPUT TYPE=submit NAME="criteria" VALUE="';
  echo $admin_Go;
  echo '" STYLE="width:50;">

<hr>

';
  echo $admin_Article_search;
  echo '<INPUT TYPE=text NAME="word" size=73>
<INPUT TYPE=submit NAME="search" VALUE="';
  echo $admin_Go;
  echo '" STYLE="width:50;">
</FORM>

';
  if ($_POST['UPDATE'])
  {
    while (key ($_POST) != 'UPDATE')
    {
      $ident = split ('~', key ($_POST));
      $SQL = 'UPDATE articles SET status=' . ($_POST[key ($_POST)] - 1) . ('' . ' WHERE id=' . $ident['1']);
      if (!(mysql_query ($SQL)))
      {
        exit ('Query failed');
        ;
      }

      next ($_POST);
    }
  }

  echo '

<FORM ACTION="';
  echo $php_self;
  echo '" METHOD="post">
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR ALIGN=center BGCOLOR="#505090">
<td BGCOLOR="#EFEFF8"></TD>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[0];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[1];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[2];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[3];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[4];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table[5];
  echo '</FONT></td>
<td width=50><FONT COLOR="#FFFFFF">';
  echo $admin_table[6];
  echo '</FONT></td>
</tr>

';
  if (2 < strlen ($_POST['word']))
  {
    if (($_COOKIE['root'] OR $_COOKIE['editor']))
    {
      $SQL = 'SELECT * FROM articles WHERE title LIKE \'%' . trim ($_POST['word']) . '%\' ORDER BY tim DESC';
    }
    else
    {
      $SQL = 'SELECT * FROM articles WHERE title LIKE \'%' . trim ($_POST['word']) . ('' . '%\' AND publisher=\'' . $_COOKIE['autorized'] . '\' ORDER BY tim DESC');
    }
  }
  else
  {
    if ($_POST['criteria'])
    {
      $post_tim_from = mktime (0, 0, 0, $_POST['post_month_from'] + 1, $_POST['post_day_from'], $_POST['post_year_from']);
      $post_tim_to = mktime (23, 59, 59, $_POST['post_month_to'] + 1, $_POST['post_day_to'], $_POST['post_year_to']);
      $j = 0;
      $tim_select = '' . ' tim>' . $post_tim_from . ' AND tim<' . $post_tim_to;
      ++$j;
      if (($_POST['category'] AND 0 < $j))
      {
        $category_select = '' . ' AND category=\'' . $_POST['category'] . '\'';
        ++$j;
      }
      else
      {
        if ($_POST['category'])
        {
          $category_select = '' . ' category=\'' . $_POST['category'] . '\'';
          ++$j;
        }
      }

      if (($_POST['status'] AND 0 < $j))
      {
        $status_select = ' AND status=' . ($_POST['status'] - 1);
        ++$j;
      }
      else
      {
        if ($_POST['status'])
        {
          $status_select = ' status=' . ($_POST['status'] - 1);
          ++$j;
        }
      }

      if (($_POST['type'] AND 0 < $j))
      {
        $type_select = ' AND type=' . ($_POST['type'] - 1);
        ++$j;
      }
      else
      {
        if ($_POST['type'])
        {
          $type_select = ' type=' . ($_POST['type'] - 1);
          ++$j;
        }
      }

      if (0 < $j)
      {
        $WHER = ' WHERE';
      }

      $QUERY = $WHER . $tim_select . $category_select . $status_select . $type_select;
      if (($_COOKIE['root'] OR $_COOKIE['editor']))
      {
        $SQL = 'SELECT * FROM articles' . $QUERY . ' ORDER BY tim DESC LIMIT ' . $_POST['display'];
      }
      else
      {
        if ($QUERY)
        {
          $SQL = '' . 'SELECT * FROM articles ' . $QUERY . ' AND publisher=\'' . $_COOKIE['autorized'] . '\' ORDER BY tim DESC LIMIT ' . $_POST['display'];
        }
        else
        {
          $SQL = '' . 'SELECT * FROM articles WHERE publisher=\'' . $_COOKIE['autorized'] . '\' ORDER BY tim DESC LIMIT ' . $_POST['display'];
        }
      }
    }
    else
    {
      if (($_COOKIE['root'] OR $_COOKIE['editor']))
      {
        $SQL = 'SELECT * FROM articles ORDER BY tim DESC LIMIT 20';
      }
      else
      {
        $SQL = '' . 'SELECT * FROM articles WHERE publisher=\'' . $_COOKIE['autorized'] . '\' ORDER BY tim DESC LIMIT 20';
      }
    }
  }

  if (!($result = mysql_query ($SQL)))
  {
    exit ('Query failed');
    ;
  }

  $i = 0;
  while ($row = mysql_fetch_array ($result))
  {
    unset ($cat_display);
    if ($row['category'])
    {
      if (strstr ($row['category'], '~'))
      {
        $sub_cat = split ('~', $row['category']);
        $SQL_cat = 'SELECT * FROM categories WHERE name=\'' . addslashes ($sub_cat[0]) . '\'';
        if (!($result_cat = mysql_query ($SQL_cat)))
        {
          exit ($SQL_cat);
          ;
        }

        $row_cat = mysql_fetch_array ($result_cat);
        $cat_display = '' . $row_cat['name'] . ' &raquo; ' . $sub_cat['1'];
      }
      else
      {
        $SQL_cat = 'SELECT * FROM categories WHERE name=\'' . addslashes ($row['category']) . '\'';
        if (!($result_cat = mysql_query ($SQL_cat)))
        {
          exit ($SQL_cat);
          ;
        }

        $row_cat = mysql_fetch_array ($result_cat);
        $cat_display = $row_cat['name'];
      }
    }

    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">

					<TD BGCOLOR="#EFEFF8"><FONT COLOR="silver">';
    echo $i;
    echo '</FONT></TD>
					<TD ALIGN=center>';
    echo $row['id'];
    echo '</TD>
					<TD><A HREF="../preview.php?id=';
    echo $row['id'];
    echo '" STYLE="color:blue;" TARGET="_blank">';
    echo str_replace ($_POST['word'], '<FONT COLOR="#FF0000">' . $_POST['word'] . '</FONT>', $row['title']);
    echo '</A></TD>
					<TD><FONT COLOR="maroon">';
    echo $cat_display;
    echo '</FONT></TD>
					<TD><font style="font-size:11;">';
    echo date ('d/m/y', $row['tim']);
    echo '</font></TD>
					<TD ALIGN=center><font color="black" style="font-size:11;">';
    if ($row['type'] == 0)
    {
      echo 'Typical';
    }
    else
    {
      if ($row['type'] == 1)
      {
        echo 'Breaking News';
      }
      else
      {
        if ($row['type'] == 2)
        {
          echo 'Headline';
        }
        else
        {
          echo 'Interview';
        }
      }
    }

    echo '</font></TD>

					<TD>
					';
    echo '<S';
    echo 'ELECT NAME="status~';
    echo $row['id'];
    echo '" STYLE="color:';
    if ($row['status'] == 0)
    {
      echo '#808000';
    }
    else
    {
      if ($row['status'] == 1)
      {
        echo '#009900';
      }
      else
      {
        echo '#FF0000';
      }
    }

    echo ';" ';
    if ((!$_COOKIE['root'] AND !$_COOKIE['editor']))
    {
      echo 'disabled';
    }

    echo '>
						<OPTION VALUE="1" ';
    if ($row['status'] == 0)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $admin_Pending;
    echo '</OPTION>
						<OPTION VALUE="2" ';
    if ($row['status'] == 1)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $admin_Visible;
    echo '</OPTION>
						<OPTION VALUE="3" ';
    if ($row['status'] == 2)
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $admin_Hidden;
    echo '</OPTION>
					</SELECT>
					</TD>
					
					<TD ALIGN=center>
						<A HREF="editor.php?id=';
    echo $row['id'];
    echo '"><IMG SRC="../images/edit.gif" ALT="Edit" BORDER=0></A>
						<A onclick="return confirmSubmit(\'';
    echo urlencode ($row['title']);
    echo '\')" HREF="edit.php?delete=';
    echo $row['id'];
    echo '"><IMG SRC="../images/delete.gif" ALT="Delete" BORDER=0></A>
						<A HREF="comments.php?id=';
    echo $row['id'];
    echo '"><IMG SRC="../../inc/images/forum.gif" ALT="Edit/Delete Comments for current article" BORDER=0></A>
					</TD>

				</TR>
			';
  }

  echo '
<tr><td colspan="6"></td><td align="center"><input type="submit" name="UPDATE" value="';
  echo $admin_Update;
  echo '" ';
  if ((!$_COOKIE['root'] AND !$_COOKIE['editor']))
  {
    echo 'disabled';
  }

  echo '></td><td></td></tr>
</TABLE>
</FORM>








</TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>';
?>
