<?

  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'];
  include '../../lang/' . $proper['language'];
  echo '
<HTML><HEAD><META HTTP-EQUIV="expires" CONTENT="Wed, 20 Feb 2000 08:30:00 GMT"><META HTTP-EQUIV="Pragma" CONTENT="no-cache"></HEAD>
<BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="686" 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=to';
  echo 'p BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;"><FONT COLOR="navy"><B>';
  echo $admin_Add_New_Article;
  echo '</B></FONT></TD></TR><TR><TD VALIGN=top>

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

  if ($_POST['IMG_Remove'])
  {
    unlink ($documentroot . ('' . '/upload/images/' . $_POST['Old_Image_Name']));
  }

  if ($_POST['TMB_Remove'])
  {
    unlink ($documentroot . ('' . '/upload/thumbnails/' . $_POST['Old_Thumbnail_Name']));
  }

  if ($_POST['MM_Remove'])
  {
    unlink ($documentroot . ('' . '/upload/multimedia/' . $_POST['Old_Audio_Name']));
  }

  if ($_POST['add_article'])
  {
    $post_tim = mktime ($_POST['post_hour'], $_POST['post_minute'], $_POST['post_sec'], $_POST['post_month'] + 1, $_POST['post_day'], $_POST['post_year']);
    if (!$_POST['status'])
    {
      $_POST['status'] = 0;
    }

    $SQL = '' . 'UPDATE articles SET
	type=' . $_POST['type'] . ',
	category=\'' . $_POST['category'] . '\',
	tim=' . $post_tim . ',
	status=' . $_POST['status'] . ',
	title=\'' . trim ($_POST['title']) . '\',
	description=\'' . trim ($_POST['description']) . '\',
	body=\'' . $_POST['FCKeditor1'] . ('' . '\'
	WHERE id=' . $_POST['id']);
    if (!(mysql_query ($SQL)))
    {
      exit ($SQL);
      ;
    }

    if ($_FILES['image']['name'])
    {
      if (($_POST['Old_Image_Name'] AND file_exists ($documentroot . ('' . '/upload/images/' . $_POST['Old_Image_Name']))))
      {
        unlink ($documentroot . ('' . '/upload/images/' . $_POST['Old_Image_Name']));
      }

      if (copy ($_FILES['image']['tmp_name'], $documentroot . ('' . '/upload/images/' . $post_tim . '.') . substr ($_FILES['image']['type'], 6)))
      {
        unlink ($_FILES['image']['tmp_name']);
      }
    }
    else
    {
      if (($post_tim != $_POST['fixed_time'] AND $_POST['Old_Image_Name']))
      {
        $EXT = strstr ($_POST['Old_Image_Name'], '.');
        rename ($documentroot . ('' . '/upload/images/' . $_POST['Old_Image_Name']), $documentroot . ('' . '/upload/images/' . $post_tim) . $EXT);
      }
    }

    if ($_FILES['thumbnail']['name'])
    {
      if (($_POST['Old_Thumbnail_Name'] AND file_exists ($documentroot . ('' . '/upload/thumbnails/' . $_POST['Old_Thumbnail_Name']))))
      {
        unlink ($documentroot . ('' . '/upload/thumbnails/' . $_POST['Old_Thumbnail_Name']));
      }

      if (copy ($_FILES['thumbnail']['tmp_name'], $documentroot . ('' . '/upload/thumbnails/' . $post_tim . '.') . substr ($_FILES['thumbnail']['type'], 6)))
      {
        unlink ($_FILES['thumbnail']['tmp_name']);
      }
    }
    else
    {
      if (($post_tim != $_POST['fixed_time'] AND $_POST['Old_Thumbnail_Name']))
      {
        $EXT = strstr ($_POST['Old_Thumbnail_Name'], '.');
        rename ($documentroot . ('' . '/upload/thumbnails/' . $_POST['Old_Thumbnail_Name']), $documentroot . ('' . '/upload/thumbnails/' . $post_tim) . $EXT);
      }
    }

    if ($_FILES['multimedia']['name'])
    {
      if (strstr ($_FILES['multimedia']['type'], 'wmv'))
      {
        $extension = 'wmv';
      }
      else
      {
        $extension = substr ($_FILES['multimedia']['type'], 6);
      }

      if (($_POST['Old_Audio_Name'] AND file_exists ($documentroot . ('' . '/upload/multimedia/' . $_POST['Old_Audio_Name']))))
      {
        unlink ($documentroot . ('' . '/upload/multimedia/' . $_POST['Old_Audio_Name']));
      }

      if (copy ($_FILES['multimedia']['tmp_name'], $documentroot . ('' . '/upload/multimedia/' . $post_tim . '.') . $extension))
      {
        unlink ($_FILES['multimedia']['tmp_name']);
      }
    }
    else
    {
      if (($post_tim != $_POST['fixed_time'] AND $_POST['Old_Audio_Name']))
      {
        $EXT = strstr ($_POST['Old_Audio_Name'], '.');
        rename ($documentroot . ('' . '/upload/multimedia/' . $_POST['Old_Audio_Name']), $documentroot . ('' . '/upload/multimedia/' . $post_tim) . $EXT);
      }
    }

    echo 'Article updated successfully!<BR><BR>
<A HREF="edit.php" STYLE="color:blue;">&laquo; return</A><BR><BR>
';
    exit ();
  }

  echo '

';
  if (!$_GET['id'])
  {
    $_GET['id'] = $_POST['id'];
  }

  if (!($result_editor = mysql_query ('' . 'SELECT * FROM articles WHERE id=' . $_GET['id'])))
  {
    exit ('Query failed14');
    ;
  }

  $row_editor = mysql_fetch_array ($result_editor);
  echo '

<FORM ACTION="editor.php" METHOD=post ENCTYPE="multipart/form-data">

';
  echo $admin_Article_type;
  echo '<INPUT TYPE=radio NAME="type" VALUE="0" ';
  if ($row_editor['type'] == 0)
  {
    echo 'checked';
  }

  echo '>';
  echo $admin_Typical;
  echo '&nbsp;|
<INPUT TYPE=radio NAME="type" VALUE="1" ';
  if ($row_editor['type'] == 1)
  {
    echo 'checked';
  }

  echo '>';
  echo $admin_Breaking_News;
  echo '&nbsp;|
<INPUT TYPE=radio NAME="type" VALUE="2" ';
  if ($row_editor['type'] == 2)
  {
    echo 'checked';
  }

  echo '>';
  echo $admin_Headline;
  echo '&nbsp;|
<INPUT TYPE=radio NAME="type" VALUE="3" ';
  if ($row_editor['type'] == 3)
  {
    echo 'checked';
  }

  echo '>';
  echo $admin_Interview;
  echo '
<BR><BR>

';
  echo $admin_Category;
  echo '<S';
  echo 'ELECT NAME="category">
';
  if (!($result1 = mysql_query ('SELECT * FROM categories')))
  {
    exit ('Query failed24');
    ;
  }

  $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 failed34');
    ;
  }

  $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 failed44');
        ;
      }

      $row = mysql_fetch_array ($result);
    }

    if ($row['name'] != '')
    {
      echo '<option value="';
      echo $row['name'];
      echo '" ';
      if ($row_editor['category'] == $row['name'])
      {
        echo 'selected';
      }

      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>		

<BR><BR>

';
  echo $admin_Post_date;
  echo '<S';
  echo 'ELECT NAME="post_day">';
  for ($i = 1; $i < 32; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('j', $row_editor['tim']))
    {
      echo 'SELECTED';
    }

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

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

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

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

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

  echo '</SELECT>
';
  echo $admin_time;
  echo '<S';
  echo 'ELECT NAME="post_hour">';
  for ($i = 0; $i <= 23; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('G', $row_editor['tim']))
    {
      echo 'SELECTED';
    }

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

  echo '</SELECT>&nbsp;:
';
  echo '<S';
  echo 'ELECT NAME="post_minute">';
  for ($i = 0; $i <= 59; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('i', $row_editor['tim']))
    {
      echo 'SELECTED';
    }

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

  echo '</SELECT>&nbsp;:
';
  echo '<S';
  echo 'ELECT NAME="post_sec">';
  for ($i = 0; $i <= 59; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('s', $row_editor['tim']))
    {
      echo 'SELECTED';
    }

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

  echo '</SELECT>
<BR><BR>

';
  if (($_COOKIE['root'] OR $_COOKIE['editor']))
  {
    echo $admin_Status;
    echo '<S';
    echo 'ELECT NAME="status">
	<OPTION VALUE="0" ';
    if ($row_editor['status'] == 0)
    {
      echo 'SELECTED';
    }

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

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

    echo '>';
    echo $admin_Hidden;
    echo '</OPTION>
</SELECT>
<BR><BR>
';
  }

  echo '
<DIV ALIGN="center">';
  echo $admin_Article_Title;
  echo '</DIV><TEXTAREA NAME=title COLS="130" ROWS=3>';
  echo $row_editor['title'];
  echo '</TEXTAREA>

<BR>

<DIV ALIGN="center">';
  echo $admin_Short_Description;
  echo '</DIV><TEXTAREA NAME=description COLS=130 ROWS=6>';
  echo $row_editor['description'];
  echo '</TEXTAREA>

<BR>

<DIV ALIGN="center">';
  echo $admin_Body;
  echo '</DIV>

';
  $oFCKeditor = new FCKeditor ('FCKeditor1');
  $oFCKeditor->BasePath = $sBasePath;
  $oFCKeditor->Width = '110%';
  $oFCKeditor->Height = '500';
  $oFCKeditor->Config['DefaultLanguage'] = 'en';
  $oFCKeditor->Value = str_replace ('
', '', $row_editor['body']);
  $oFCKeditor->Create ();
  echo '
<BR>

';
  echo $admin_Old_Image;
  echo '<BR>
';
  if ($dir = @opendir ($documentroot . '/upload/images'))
  {
    while ($file = readdir ($dir) !== false)
    {
      if (strstr ($file, $row_editor['tim']))
      {
        echo '	<IMG SRC="../../upload/images/';
        echo $file;
        echo '" BORDER="1"><BR>
	<INPUT TYPE="hidden" NAME="Old_Image_Name" VALUE="';
        echo $file;
        echo '"><br>
	<input type="submit" name="IMG_Remove" value="Remove Old Image"><br><br>
	';
        continue;
      }
    }

    closedir ($dir);
  }

  echo $admin_New_Image;
  echo '<BR><INPUT TYPE=file NAME="image" SIZE=70 ACCEPT="image/jpeg,image/gif">
<hr>
';
  echo $admin_Old_Thumbnail;
  echo '<BR>
';
  if ($dir = @opendir ($documentroot . '/upload/thumbnails'))
  {
    while ($file = readdir ($dir) !== false)
    {
      if (strstr ($file, $row_editor['tim']))
      {
        echo '	<IMG SRC="../../upload/thumbnails/';
        echo $file;
        echo '" BORDER="1"><BR>
	<INPUT TYPE="hidden" NAME="Old_Thumbnail_Name" VALUE="';
        echo $file;
        echo '"><br>
	<input type="submit" name="TMB_Remove" value="Remove Old Thumbnail"><br><br>
	';
        continue;
      }
    }

    closedir ($dir);
  }

  echo $admin_New_Thumbnail;
  echo '<BR><INPUT TYPE=file NAME="thumbnail" SIZE=70 ACCEPT="image/jpeg,image/gif">
<hr>
';
  echo $admin_Old_Audio;
  echo '<BR>
';
  if ($dir = @opendir ($documentroot . '/upload/multimedia'))
  {
    while ($file = readdir ($dir) !== false)
    {
      if (strstr ($file, $row_editor['tim']))
      {
        echo '	<A HREF="../../upload/multimedia/';
        echo $file;
        echo '"><IMG SRC="../images/audio.gif" ALIGN="ABSMIDDLE" BORDER="0"></a><BR>
	<INPUT TYPE="hidden" NAME="Old_Audio_Name" VALUE="';
        echo $file;
        echo '"><br>
	<input type="submit" name="MM_Remove" value="Remove Old Audio/Video file"><br><br>
	';
        continue;
      }
    }

    closedir ($dir);
  }

  echo $admin_New_Audio;
  echo '<BR><INPUT TYPE=file NAME="multimedia" SIZE=70><BR><BR>

<INPUT TYPE=hidden NAME="fixed_time" VALUE="';
  echo $row_editor['tim'];
  echo '">
<INPUT TYPE=hidden NAME="id" VALUE="';
  echo $_GET['id'];
  echo '">
<INPUT TYPE=submit NAME="add_article" VALUE="';
  echo $admin_Save_Article;
  echo '">

</FORM>
</BODY></HTML>';
?>
