<?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['meet-title'];
  $helppage = $TEXT['meet-help'];
  require_once "../config.php";
  require_once "../util/top.php";

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

  if(empty($_POST['org_id'])) $_POST['org_id'] = "";
  if(empty($_GET['onorg'])) $_GET['onorg'] = "";
  if(empty($_POST['onorg'])) $_POST['onorg'] = "";
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org1']);
  $_POST['org_id'] = rep($_POST['org_id']);
  if(empty($_GET['org_id'])) $_GET['org_id'] = "";
  if(strlen($_GET['org_id'])>11) puterror2($TEXT['error-org1']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $onchb = "";

  if($_GET['onorg'] == "on")
    {
   $_POST['org_id'] = $_GET['org_id'];
   $onchb = "checked";
    }
  else
  {
  if($_POST['onorg'] !== "on") $_POST['org_id'] = "";
    else
    {
    $_POST['org_id'] = $_POST['org_id'];
    $onchb = "checked";
    }
  }

  if(!isset($button)) $button = $TEXT['btn_filter'];
  if(!isset($action)) $action = "index.php";
?>
<img alt="<?php echo $TEXT['nd-add-new2']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="addform.php" title="<?php echo $TEXT['meet-add']; ?>"><?php echo $TEXT['meet-add']; ?></a>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="30%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['log-tit7']; ?>"><?php echo $TEXT['btn_filter']; ?></legend>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr class="zag2"><td><?php echo $TEXT['tbl-org']; ?></td></tr>
<tr><td><select class="input" name="org_id">
    <?php
        $query4 = "SELECT * FROM `tbl_organizaciya` ORDER BY position";
        $organizaciya_tmp = mysql_query($query4);
          if(!$organizaciya_tmp) puterror2($TEXT['error-tbl7']);
              while($organizaciya = mysql_fetch_array($organizaciya_tmp,MYSQL_ASSOC))
                {
                 if($organizaciya['org_id'] == $_POST['org_id'])
                   {
                   $chk = "<option selected value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                   }
                 else $chk = "<option value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                 echo $chk;
                }
    ?>
    </select><input type=checkbox name=onorg <?php echo $onchb; ?>></td>
    <td><input class="button" type=submit value='<?php echo $button; ?>'></td>
</tr>
</table>
</fieldset>
</td></tr>
</table>
</form>
 <span class="tabledata"><?php echo $TEXT['meet-text']; ?></span>
<table class="table" border="1" cellpadding="4" cellspacing="0" width="70%">
<?php
   if(!empty($_POST['org_id'])) $organizaciya = "AND tbl_meet_room.org_id='".$_POST['org_id']."' ";
    else $organizaciya = "";

     $query = "SELECT 
         tbl_meet_room.*,
         tbl_organizaciya.org_id,
         tbl_organizaciya.organizaciya
         FROM tbl_meet_room
         JOIN tbl_organizaciya ON tbl_meet_room.org_id=tbl_organizaciya.org_id
         WHERE tbl_meet_room.room_id !='' ".$organizaciya."
         ORDER BY tbl_organizaciya.organizaciya, tbl_meet_room.position ";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl48']);
       if(mysql_num_rows($result)>0);
         {
           echo "<tr class='tableheadercat'>
            <td>".$TEXT['inst-field1']."</td>
            <td>".$TEXT['meet-title']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-position']."</td>
            <td>".$TEXT['tbl-visible']."</td>
            <td colspan=3>".$TEXT['tbl-action']."</td>
                 </tr>";
             while($result_razd = mysql_fetch_array($result,MYSQL_ASSOC))
              {
                $res_org = $result_razd['organizaciya'];

               if($result_razd['room_visible']=='yes') $razd_vis="<a href=hide.php?room_id=".$result_razd['room_id']." title='".$TEXT['meet-hide']."'><img alt='".$TEXT['tbl-show']."' src='../img/show.png' height='16' width='16' align='top' /></a>";
                else $razd_vis="<a href=show.php?room_id=".$result_razd['room_id']." title='".$TEXT['meet-show']."'><img alt='".$TEXT['tbl-hide']."' src='../img/hide.png' height='16' width='16' align='top' /></a>";

                $edit = "<a href=editform.php?room_id=".$result_razd['room_id']." title='".$TEXT['tbl-edit']."'>".$TEXT['tbl-edit']."</a>";
                $delete = "<a href=deleteform.php?room_id=".$result_razd['room_id']." title='".$TEXT['tbl-delete']."'>".$TEXT['tbl-delete']."</a>";
//                $docind = "<a href=docindex.php?room_id=".$result_razd['room_id']." title='".$TEXT['tbl-visible-razd']."'>".$result_razd['room_name']."</a>";
                $move_up = "<a href=up-down.php?room_id=".$result_razd['room_id']."&amp;org_id=".$result_razd['org_id']."&amp;position=".$result_razd['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?room_id=".$result_razd['room_id']."&amp;org_id=".$result_razd['org_id']."&amp;position=".$result_razd['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(!empty($result_razd['room_photo']) && file_exists("../".$result_razd['room_photo']))
               {
                $picture = "<img alt='picture' width='185' height='130' src='../".$result_razd['room_photo']."' />";
               }
                else $picture = $TEXT['error-photo-no'];
                ?>
                <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
                    <td><?php echo $picture; ?></td>
                    <td><?php echo $result_razd['room_name']; ?></td>
                    <td><?php echo $res_org; ?></td>
                    <td><?php echo $result_razd['position']; ?></td>
                    <td><?php echo $razd_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";
?>