<?

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

  echo '
';
  if ($_POST['save_sub'])
  {
    if (!($result = mysql_query ('' . 'select * FROM sub_categories WHERE parent=\'' . $_POST['id'] . '\'')))
    {
      exit ('Query failed');
      ;
    }

    $row = mysql_fetch_array ($result);
    if ($row)
    {
      $SQL = '' . 'UPDATE sub_categories SET name=\'' . $_POST['sub_cat'] . '\' WHERE parent=' . $_POST['id'];
    }
    else
    {
      $SQL = '' . 'INSERT INTO sub_categories VALUES(' . $_POST['id'] . ',\'' . $_POST['sub_cat'] . '\')';
    }

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

  echo '


';
  if ($_GET['id'])
  {
    if (!($result1 = mysql_query ('' . 'select * FROM categories WHERE id=\'' . $_GET['id'] . '\'')))
    {
      exit ('Query failed');
      ;
    }

    $row1 = mysql_fetch_array ($result1);
    if (!($result = mysql_query ('' . 'select * FROM sub_categories WHERE parent=\'' . $_GET['id'] . '\'')))
    {
      exit ('Query failed');
      ;
    }

    $row = mysql_fetch_array ($result);
  }

  echo '


<HTML><BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="600" 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">Parent Category: "<B>';
  echo $row1['name'];
  echo '</B>"</FONT></TD></TR><TR><TD VALIGN=top>

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

<DIV ALIGN=right>';
  if ($_POST['save_sub'])
  {
    echo '<B><FONT COLOR="white" STYLE="background-color:red;">&nbsp;Last Changes Saved!&nbsp;</FONT></B>';
  }

  echo '</DIV>


Sub categories:<BR><TEXTAREA COLS=50 ROWS=12 NAME="sub_cat">';
  echo $row['name'];
  echo '</TEXTAREA><BR><BR>

<INPUT TYPE=hidden NAME="id" VALUE="';
  echo $_GET['id'];
  echo '">

<DIV ALIGN="center"><INPUT TYPE=submit NAME="save_sub" VALUE="Save changes">
<INPUT TYPE=button VALUE="Go Back" onClick="window.location=\'categories.php\'"></DIV>

</FORM>

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