<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang.".php")) include "../lang/".$lang.".php";
     else include "../lang/ru.php";

  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <script src="../utils/tree_toggle.js" type="text/javascript"></script>
  <?php
  if($result2['administrator'] == 0) puterror2($TEXT['error-supp11']);

  function ShowTree($ParentID,$Level){
    $Level++;
    echo("<ul class='Container'>");

    $query_tree="SELECT zh_str_id, strukt_name, parent, position, visible FROM tbl_zhurn_strukt WHERE `parent`=".$ParentID." AND `visible`='show' ORDER BY position, strukt_name";
     $result4=mysql_query($query_tree);
      $num_rows = mysql_num_rows($result4);
      $kurent = 1;
       if($num_rows > 0)
       {
        while($row = mysql_fetch_array($result4,MYSQL_ASSOC))
        {
        $ID1 = $row['zh_str_id'];

         $query_check=mysql_query("SELECT COUNT(zh_str_id) FROM tbl_zhurn_strukt WHERE `parent`=".$ID1."");
          $result_check=mysql_result($query_check, 0);
            if($result_check > 0)
            {
             if($kurent == $num_rows)
             {
             echo("<li class='Node ExpandClosed IsLast'>");
             echo("<div class='Expand'></div>");
             echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID1." target='right'>".$row['strukt_name']."</a></div>");

             }
              else
              {
              echo("<li class='Node ExpandClosed'>");
              echo("<div class='Expand'></div>");
              echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID1." target='right'>".$row['strukt_name']."</a></div>");
              }
            ShowTree($ID1, $Level);
            }
            else
            {
              if($kurent == $num_rows)
             {
             echo("<li class='Node ExpandLeaf IsLast'>");
             echo("<div class='Expand'></div>");
             echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID1." target='right'>".$row['strukt_name']."</a></div>");
             }
              else
              {
              echo("<li class='Node ExpandLeaf'>");
              echo("<div class='Expand'></div>");
              echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID1." target='right'>".$row['strukt_name']."</a></div>");
              }
            }
            echo("</li>");
            $kurent++;
       }
       $Level--;
     }
     echo("</ul>");
   }

     $query = "SELECT * FROM `tbl_zhurn_strukt` WHERE `parent` = 0 AND `visible`='show' ORDER BY position, strukt_name";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl40']);
     $num_row = mysql_num_rows($result);
      $kurent_row = 1;
      $Level = 0;
         if($num_row > 0){
         echo("&nbsp;&nbsp;<span class='support4'>".$TEXT['zhurn-izm']."</span>");
           while($result_kat = mysql_fetch_array($result,MYSQL_ASSOC))
           {
             $ID = $result_kat['zh_str_id'];

             echo("<div class='texttableusr' onclick='tree_toggle(arguments[0])'>");
             echo("<ul class='Container'>");
             //echo ("kurent=".$kurent_row."num_rows=".$num_row);
             $query_chk=mysql_query("SELECT COUNT(zh_str_id) FROM tbl_zhurn_strukt WHERE `parent`= ".$ID."");
             $result_chk=mysql_result($query_chk, 0);
            if($result_chk > 0)
            {
             if($kurent_row == $num_row)
             {
             echo("<li class='Node ExpandClosed IsLast'>");
             echo("<div class='Expand'></div>");
             echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID." target='right'>".$result_kat['strukt_name']."</a></div>");

             }
              else
              {
              echo("<li class='Node ExpandClosed'>");
              echo("<div class='Expand'></div>");
              echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID." target='right'>".$result_kat['strukt_name']."</a></div>");
              }

             ShowTree($ID, $Level);
            }
             else
             {
              if($kurent_row == $num_row)
              {
              echo("<li class='Node ExpandLeaf IsLast'>");
              echo("<div class='Expand'></div>");
              echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID." target='right'>".$result_kat['strukt_name']."</a></div>");
              }
              else
               {
               echo("<li class='Node ExpandLeaf'>");
               echo("<div class='Expand'></div>");
               echo("<div class='Content'><a href=zhurnal.php?zh_str_id=".$ID." target='right'>".$result_kat['strukt_name']."</a></div>");
               }
            }
             $kurent_row++;
             //ShowTree($result_kat['zh_str_id'],0);
             echo("</li>");
             echo("</ul>");
             echo("</div>");
           }
         }
?>
</body>
</html>