<!DOCTYPE html><!-- HTML5 -->
<html lang="ru-RU" dir="ltr">
	<head>
		<title></title>
		<meta charset="utf-8" />
		<!--[if IE]><meta http-equiv="ImageToolbar" content="False" /><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../style/reset.css" media="screen,print" />
		<link rel="stylesheet" type="text/css" href="../../sg_cm/sg_cm/style/cap2.css" media="screen" />
<script type='text/javascript'>

 function del(par,text)
{
answer=window.confirm('Вы хотите удалить '+text+'?');
if (answer)window.location.replace(par);
}
</script>		
		
		</head>
	<body>
	<div>

<?php
$info="";
if(isset($_POST['go_cat']))
  {
    $_POST['cat']=trim($_POST['cat']);
    $_POST['cat']=stripslashes($_POST['cat']);
    $_POST['cat']=str_replace("*","",$_POST['cat']);
    if($_POST['cat']!="")
      {
        $time=time();
        $f=fopen("../upload/gs_foto/db/cat.txt","a+");
        fwrite($f,"$time*$_POST[cat]\r\n");
        fclose($f);

        $f=fopen("../upload/gs_foto/db/cat/$time","w+");
        fclose($f);
        echo "<meta http-equiv=refresh content='0; url=admin1.php'>";
        exit();
      }
  }

if(isset($_POST['go_red']) && isset($_GET['red']) && file_exists("../upload/gs_foto/db/cat/$_GET[red]"))
  {
  	$_POST['cat_red']=trim($_POST['cat_red']);
    $_POST['cat_red']=stripslashes($_POST['cat_red']);
    $_POST['cat_red']=str_replace("*","",$_POST['cat_red']);
    if($_POST['cat_red']!="")
       {
          $file=file("../upload/gs_foto/db/cat.txt");
          $f=fopen("../upload/gs_foto/db/cat.txt","w+");
          foreach($file as $line)
          {
   	        $line=trim($line);
   	        $expl=explode("*",$line);
            if($_GET['red']==$expl[0])fwrite($f,$expl[0]."*".$_POST['cat_red']."\r\n");
            else fwrite($f,$line."\r\n");
          }
          fclose($f);
           echo "<meta http-equiv=refresh content='0; url=admin1.php'>";
          exit();
       }
   }

if(isset($_GET['del']) && file_exists("../upload/gs_foto/db/cat/$_GET[del]"))
  {
    $file=file("../upload/gs_foto/db/cat/$_GET[del]");
    if(!count($file))
      {
        unlink("../upload/gs_foto/db/cat/$_GET[del]");
        $file=file("../upload/gs_foto/db/cat.txt");
          $f=fopen("../upload/gs_foto/db/cat.txt","w+");
          foreach($file as $line)
          {
   	        $line=trim($line);
   	        $expl=explode("*",$line);
            if($_GET['del']==$expl[0])continue;
            fwrite($f,$line."\r\n");
          }
          fclose($f);
          echo "<meta http-equiv=refresh content='0; url=admin1.php'>";
          exit();
      }
    else $info="<span style='color:red'>Нельзя удалить эту категорию, т.к. в ней есть статьи!</span>";
  }
?>
<table id=info ><tr><td><img src="img/inf.jpg" width=26px alt="Справка" ></td>
<td>Если вы хотите группировать фотоальбомы по категориям, можете добавить их здесь.</td></tr>
</table>

<table  class=tab1  ><tr>
  <td class=valtop>
  <form  method="post">
    <div style="text-align:center"> <input  name="cat" type="text" size=60>&nbsp;&nbsp;<input type="submit" value="Добавить категорию" name=go_cat id=button><br /><br /></div>

<?php
if($info!="")echo "$info<br />";
echo"<table  class='tab3' >";
  $file=file("../upload/gs_foto/db/cat.txt");
  $n=0;
  foreach($file as $line)
   {
   	 if($n==0)
   	    {
   	    	$css1="class=sett1";
   	    	$css2="class=sett2";
   	    }
   	  else
   	    {
   	      $css1="class=sett1";
   	      $css2="class=sett2";;
   	    }
   	 $line=trim($line);
   	 $expl=explode("*",$line);
   	 if(!isset($_GET['red']) || !file_exists("../upload/gs_foto/db/cat/".@$_GET['red']) || $expl[0]!=@$_GET['red'])
   	    echo "<tr><td>$expl[1]</td><td>&nbsp;&nbsp;</td><td style=\"text-align:right;padding-right:20px\">
        <a href=admin1.php?red=$expl[0]><img style=margin-right:30px; src=img/red.png title=редактировать alt=редактировать></a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href=# onclick=\"del('admin1.php?del=$expl[0]','категорию');return false;\"><img  src='img/del.png' title=удалить alt=удалить></a>
   	    </td></tr>";
   	  else
   	     echo "<tr><td ><input name=cat_red type=text value='$expl[1]'></td>
   	     <td >&nbsp;&nbsp;</td><td style=\"text-align:right;padding-right:20px\"><input type=submit value=сохранить id=button name=go_red></td></tr>";

   	 $n++;
   }
?>
</table>
</form>
  </td></tr></table>
</div>
</body>
</html>

