<?php
session_start();
$w=file("ac/sess");
$id="";
foreach($w as $line)
 {
   $expl=explode("*",$line);
   $line=trim($line);
   if(session_id()==$expl[1])
      {
        $id=$expl[2];
        $name=$expl[3];
        break;
      }
 }
if($id=="")
  {
    echo "<meta http-equiv=refresh content='0; url=index.php'>";
    exit();
  }
if(isset($_GET['q']))
   {
    if(!file_exists("db/$id/$_GET[q]") || !is_numeric($_GET['q']))
       {
        echo "<meta http-equiv=refresh content='0; url=admin2.php?sel2=selected'>";
        exit();
       }
   }
else
   {
        echo "<meta http-equiv=refresh content='0; url=admin2.php?sel2=selected'>";
        exit();
   }



if(isset($_POST['exit']))
  {
  	echo "<meta http-equiv=refresh content='0; url=admin2.php?sel2=selected'>";
    exit();
  }

if(isset($_POST['go']))
  {
    $_POST['text']=trim($_POST['text']);
    if($_POST['text']!="")
       {
         $w=file("db/$id/$_GET[q]");
         $_POST['text']=str_replace("\r\n","<br>",$_POST['text']);
         $_POST['text']=stripslashes($_POST['text']);
         $f=fopen("db/$id/$_GET[q]","w");
         fwrite($f,$w[0].$w[1].$_POST['text']);
         fclose($f);
       }
  }
 $w=file("db/$id/$_GET[q]");
 $w[2]=str_replace("<br>","\r\n",$w[2]);
 $expl=explode("*",$w[0]);

?>
<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8" />
  <title>Редактирование ответов</title>
<style>
.consTable {width:85%; max-width:1200px;}
  #cit
         {
          color:#808080;
          font-size:11pt;
          font-family: Arial, sans-serif;
         }

  h2
    {
       color:#408080;
       font-size:14pt;
       font-family: Arial, sans-serif;
    }


   #button {

       font-family:"Times New Roman", "serif";
       color:#408080;
       font-size:9pt;
       background-color:#C0C0C0;
      font-weight:600;
      text-align:center;
      width:120px;
      }
</style>



</head>

<body>
<h2>Ответ на вопрос</h2>
<table align=center class=consTable bgcolor=#ffffff  CELLPADDING=5>
                  <tr>
                      <td id=cit>
                         <font color=#408080><b><?php echo $expl[0]?>&nbsp;&nbsp;<?php echo $expl[1]?></b></font><br />
                         <?php echo $w[1]?>
                      </td>
                 </tr>


                 <tr><td><form  action=<?php echo "red.php?q=$_GET[q]" ?> method="post">
                    <textarea name="text" rows=20 cols=80 ><?php echo $w[2]?></textarea><br />
                    <input type="submit" value="Сохранить" name=go id=button>&nbsp;
                    <input type="submit" value="Выход" name=exit id=button>
                         </form></td></tr>
               </table>


</body>

</html>