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

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

  $title=$titlepage = $TEXT['inst-title5'];
  $helppage = $TEXT['inst-help5'];
  require_once "../config.php";
  require_once "../util/top_layer1.php";

  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(empty($_GET['razd_id'])) puterror2($TEXT['error-nd16']);
  if(strlen($_GET['razd_id'])>11) puterror2($TEXT['error-nd13']);
  $_GET['razd_id'] = rep($_GET['razd_id']);

  $razd_id = $_GET['razd_id'];
?>
 <img alt="<?php echo $TEXT['inst-add-new2']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="addinstform.php?razd_id=<?php echo $razd_id; ?>" title="<?php echo $TEXT['inst-add-new-tit2']; ?>"><?php echo $TEXT['inst-add-new2']; ?></a>
 <br />
 <br />
 <span class="tabledata"><?php echo $TEXT['inst-text2']; ?></span>
 <?php
  $query = "SELECT * FROM `tbl_instructions` WHERE `razd_id`='".$_GET['razd_id']."' ORDER BY `position`";
     $query2 = mysql_query($query);
       if(!$query2) puterror2($TEXT['error-tbl18']);
         if(mysql_num_rows($query2)>0)
          {
  ?>
  <table class="table" width="100%" border="1" cellpadding=5 cellspacing=0>
  <?php
           echo "<tr class='tableheadercat'>
                     <td>".$TEXT['inst-field1']."</td>
                     <td>".$TEXT['inst-field7']."</td>
                     <td>".$TEXT['tbl-link']."</td>
                     <td>".$TEXT['tbl-position']."</td>
                     <td>".$TEXT['tbl-visible']."</td>
                     <td>".$TEXT['count-view']."</td>
                     <td colspan=4>".$TEXT['tbl-action']."</td>
                 </tr>";

    while($instructions = mysql_fetch_array($query2,MYSQL_ASSOC))
    {
         if($instructions['visible'] == 'hide') $strvisible = "<a href=showinst.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$_GET['razd_id']." title='".$TEXT['tbl-show-tit12']."'>".$TEXT['tbl-show']."</a>";
           else $strvisible = "<a href=hideinst.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$_GET['razd_id']." title='".$TEXT['tbl-hide-tit12']."'>".$TEXT['tbl-hide']."</a>";

         if($instructions['visible']=='show') $instructions_vis="<img alt='show' src='../img/show.png' height='16' width='16' align='top' />";
          else $instructions_vis="<img alt='hide' src='../img/hide.png' height='16' width='16' align='top' />";

      if(!empty($instructions['path']) &&
         $instructions['path']!="-" &&
         file_exists("../".$instructions['path']))
      {
        $instruction = "<a href='../".$instructions['path']."' target=_blank title='".$instructions['description']."'' >".$TEXT['inst-field5']."</a>";
      }
      else $instruction = $TEXT['inst-field3'];

      $edit = "<a href=editinstform2.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$_GET['razd_id']." title='".$TEXT['tbl-edit-tit-inst']."'>".$TEXT['tbl-edit']."</a>";
      $delete = "<a href=delinst.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$_GET['razd_id']." title='".$TEXT['tbl-delete-tit-inst']."'>".$TEXT['tbl-delete']."</a>";
      $move_up = "<a href=up-down-inst.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$instructions['razd_id']."&amp;position=".$instructions['position']."&amp;moving=up title='".$TEXT['global-up-down-tit']."'><img alt='up' src='../img/up.png' height='16' width='16' align='top' /></a>";
      $move_down = "<a href=up-down-inst.php?instr_id=".$instructions['instr_id']."&amp;razd_id=".$instructions['razd_id']."&amp;position=".$instructions['position']."&amp;moving=down title='".$TEXT['global-up-down-tit']."'><img alt='down' src='../img/down.png' height='16' width='16' align='top' /></a>";
      if($instructions['photo'] == "") $picture = "---";
       else $picture = "<img alt='picture' src='../".$instructions['photo']."' />";
           ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
                 <td><?php echo $picture; ?></td>
                 <td><b><?php echo $instructions['name']; ?></b></td>
                 <td><?php echo $instruction; ?></td>
                 <td><?php echo $instructions['position']; ?></td>
                 <td><?php echo $instructions_vis; ?></td>
                 <td><?php echo $instructions['count_view']; ?></td>
                 <td><?php echo $strvisible; ?></td>
                 <td><?php echo $move_up; ?> <?php echo $move_down; ?></td>
                 <td><?php echo $edit; ?></td>
                 <td><?php echo $delete; ?></td>
            </tr>
            <?php
    }
  }
?>
</table>
<?php
  require_once "../util/bottom.php";
?>