Просмотр файла modile/adm/red_f.php

Размер файла: 4.76Kb
<?php
Defined('ADMIN_S_S') or die ('Доступ запрещен!!!');
echo
'<span class="ramka">
Редактировать файл.
</span><br>';

if ($_POST['step'] == 1 or $_POST['step'] == '')
{
 echo 'Выберите каталог с файлом.<br>';
         echo '<form name="" action="" method="post">';
         echo '<select size="1" name="kat">
         ';

          $dir = opendir ("file");
          while ($file = readdir ($dir))
         { if (( $file != ".") && ($file != "..") && ($file != 'none') && ($file != 'index.php'))
          {
           echo '<option value="'.trim($file).'">'.file_get_contents('file/'.$file.'/namekat.txt').'</option>
           ';
          }
         }
          closedir ($dir);
          echo '</select><br />
          ';
          echo '<input name="step" type="hidden" value="2">';
          echo '<input type="submit" value="Далее">';
          echo '</form>';
}
elseif ($_POST['step'] == 2)
{


   $st_r = 10;
 if (is_file('file/'.$_POST['kat'].'/namefile.txt')) $post = @file('file/'.$_POST['kat'].'/namefile.txt'); else echo 'Ошибка';

 $count_post = count($post);

 if (empty($_GET['pages'])) {
    $pages = 1;
 }  else {
    $pages = (int) $_GET['pages'];
 }

 $j = ($count_post-1)-(($pages-1)*$st_r);
 $i = $j-$st_r;
 for(; $i<$j && $j>=0; $j--)
 {
 $fn = explode("|",$post[$j]);
 $mess1 = substr($fn[1],0,250);
 include('flud/delet_bb.php');
 $dec = $mess1;
 echo '
<span class="mess1">'.$fn[0].'</span> <span class="mess2">'.$dec.'...</span>
      <form name="" action="" method="post">
      <input name="line" type="hidden" value="'.$j.'">

      <input name="kat" type="hidden" value="'.$_POST['kat'].'">
      <input name="step" type="hidden" value="3">
      <input class="knopka" type="submit" value="Выбрать">
      </form>
      <hr>


     ';


 }
 echo 'Страницы:&nbsp;'."\n";
 $all = ceil($count_post/$st_r);
 for ($i=1;$i<=$all;$i++) {
    if ($pages==$i) {
        echo '<b>'.$i.'</b> ';
    } else {
        echo '<a href="/adminf.php?id=2&pages='.$i.'">'.$i.'</a> '."";
    }

 }
}
elseif ($_POST['step'] == 3)
{
 if (is_file('file/'.$_POST['kat'].'/namefile.txt')) $post = @file('file/'.$_POST['kat'].'/namefile.txt'); else echo 'Ошибка';
 $ex = explode('|',$post[$_POST['line']]);
 $ex[1] = str_replace('<br>',"\r\n",$ex[1]);
 $mess1 = $ex[1];
 include('flud/anti_y.php');
 $ex[1] = $mess1;

?>
<span class="ramka">
<form name="" action="" method="post">
Файл:<br>
<input name="fname" type="text" value="<?php echo $ex[2] ?>">
<br>
Имя файла:<br>
<input name="im_f" type="text" value="<?php echo $ex[0] ?>"><br>
Описание:<br>
<?php
		include('flud/js/bb.php');
		include('flud/js/smyle.php');
		$ms_pol = 'opis_f';
		include('flud/js/smyler.php');
		$ms_pol = 'opis_f';
		include('flud/js/bber.php');?>
<textarea style="width:100%;" name="opis_f" rows=10 cols=50><?php echo $ex[1] ?></textarea>
<br>
<input name="step" type="hidden" value="4">
<input name="line" type="hidden" value="<?php echo $_POST['line'] ?>">
<input name="kat" type="hidden" value="<?php echo $_POST['kat'] ?>">

<input class="knopka" type="submit" value="Редактировать">
</form>
</span>
<?php
}
elseif ($_POST['step'] == 4)
{
    if (($_POST['im_f'] != "") and ($_POST['opis_f'] != "") and ($_POST['kat'] != ""))
    {
    	$fname = $_POST['fname'];
        $n = htmlspecialchars (substr($_POST['im_f'],0,150));
        $o = htmlspecialchars (substr($_POST['opis_f'],0,1000));

        $mess1 = $_POST['opis_f'];
        include('flud/anti_x.php');
        $o = $mess1;

        $n=strtr($n,array
        (
        "|"=>"I",
        "\r\n"=>"<br>",
        ));

     $line = $_POST['line'];// строка
     $rep =  stripslashes($n).'|'.stripslashes($o).'|'.$fname."\r\n"; //на что заменить
     $file = @file('file/'.trim($_POST['kat']).'/namefile.txt'); //загоняем файл в массив $file
     $count = count($file); //подсчитываем количество строк
     $fp = fopen('file/'.trim($_POST['kat']).'/namefile.txt',"w");//очищаем файл
     for($i=0;$i<$count;$i++) //создаём цикл, кол-во оборотов равно количиству строк в файле
     {
     if($i!=$line)
     {
     fwrite($fp,$file[$i]);
     }
     else
     {
     fwrite($fp,$rep);
     echo '
     <span class="ramka">
     Успешно!
     </span>
     <META HTTP-EQUIV="Refresh" CONTENT="1;">
     ';
     }
     }
      fclose($fp); //закончили работать с файлом


    }
      else
      {
       echo 'Ошибка. Поля не заполнены полностью...';
      }
}
?>