<?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['org-title4'];
  $helppage = $TEXT['org-help4'];

  require_once "../config.php";
  require_once "../util/top.php";

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

  $order = array();
  $order['organizaciya_order'] = "organizaciya";
  $order['position_order'] = "position";
  $order['visible_order'] = "visible";

  $sort = "position";

  foreach($order as $parametr => $field)
  {
    if(isset($_GET["$parametr"]))
    {
      if($_GET["$parametr"] == "up")
      {
        $_GET["$parametr"] = "down";
        $sort = $field;
      }
      else
      {
        $_GET["$parametr"] = "up";
        $sort = "$field DESC";
      }
    }
    else $_GET["$parametr"] = "up";
  }

?>
 <img alt="<?php echo $TEXT['org-add-new']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="addform.php" title="<?php echo $TEXT['org-add-new-tit']; ?>"><?php echo $TEXT['org-add-new']; ?></a>
 <br />
 <br />
 <span class="tabledata"><?php echo $TEXT['org-text1']; ?></span>
<table class="table" border="1" cellpadding="4" cellspacing="0" width="70%">
<?php
     $query = "SELECT * FROM `tbl_organizaciya` ORDER BY $sort";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl7']);
       if(mysql_num_rows($result)>0);
         {
           $href = "index.php?org_id=".$result['org_id'];
           ?>
           <tr class="tableheadercat">
            <td><a href="<?php echo $href."&amp;organizaciya_order=".$_GET['organizaciya_order']; ?>" title="<?php echo $TEXT['global-sort']; ?>"><?php echo $TEXT['tbl-org']; ?></a></td>
            <td><a href="<?php echo $href."&amp;position_order=".$_GET['position_order']; ?>" title="<?php echo $TEXT['global-sort']; ?>"><?php echo $TEXT['tbl-position']; ?></a></td>
            <td><a href="<?php echo $href."&amp;visible_order=".$_GET['visible_order']; ?>" title="<?php echo $TEXT['global-sort']; ?>"><?php echo $TEXT['tbl-visible']; ?></a></td>
            <td colspan=3><?php echo $TEXT['tbl-action']; ?></td>
           </tr>
           <?php
             while($result_organizaciya = mysql_fetch_array($result,MYSQL_ASSOC))
               {
              if($result_organizaciya['visible']=='show') $org_vis="<a href=hide.php?org_id=".$result_organizaciya['org_id']." title='".$TEXT['tbl-hide-tit4']."'><img alt='".$TEXT['tbl-show']."' src='../img/show.png' height='16' width='16' align='top' /></a>";
                else $org_vis="<a href=show.php?org_id=".$result_organizaciya['org_id']." title='".$TEXT['tbl-show-tit4']."'><img alt='".$TEXT['tbl-hide']."' src='../img/hide.png' height='16' width='16' align='top' /></a>";

              $edit = "<a href=editform.php?org_id=".$result_organizaciya['org_id']." title='".$TEXT['tbl-edit-tit-org']."'>".$TEXT['tbl-edit']."</a>";
              $delete = "<a href=deleteform.php?org_id=".$result_organizaciya['org_id']." title='".$TEXT['tbl-delete-tit-org']."'>".$TEXT['tbl-delete']."</a>";
              $move_up = "<a href=up-down.php?org_id=".$result_organizaciya['org_id']."&amp;position=".$result_organizaciya['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.php?org_id=".$result_organizaciya['org_id']."&amp;position=".$result_organizaciya['position']."&amp;moving=down title='".$TEXT['global-up-down-tit']."'><img alt='down' src='../img/down.png' height='16' width='16' align='top' /></a>";
           ?>
           <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $result_organizaciya['organizaciya']; ?></td>
              <td><?php echo $result_organizaciya['position']; ?></td>
              <td><?php echo $org_vis; ?></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";
?>