<?php
  ///////////////////////////////////////////////////
  //2010 (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['pho-title7'];
  $helppage = $TEXT['pho-help7'];
  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(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']);
  if(empty($_GET['onorg'])) $_GET['onorg'] = "";
  if(empty($_POST['onorg'])) $_POST['onorg'] = "";
  $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['pho-add-new']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="addform.php" title="<?php echo $TEXT['pho-add-new-tit']; ?>"><?php echo $TEXT['pho-add-new']; ?></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>
 <br />
 <span class="tabledata"><?php echo $TEXT['pho-field3']; ?></span>
<table class="table" border="1" cellpadding="4" cellspacing="0" width="70%">
<?php
   if(!empty($_POST['org_id'])) $organizaciya = "AND tbl_meropriyatiya.org_id='".$_POST['org_id']."' ";
    else $organizaciya = "";

     $query = "SELECT tbl_meropriyatiya.*, tbl_organizaciya.org_id, tbl_organizaciya.organizaciya FROM tbl_meropriyatiya JOIN tbl_organizaciya ON tbl_meropriyatiya.org_id=tbl_organizaciya.org_id WHERE tbl_meropriyatiya.mer_id !='' ".$organizaciya." ORDER BY tbl_organizaciya.organizaciya, tbl_meropriyatiya.position ";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl12']);
       if(mysql_num_rows($result)>0);
         {
           echo "<tr class='tableheadercat'>
            <td>".$TEXT['tbl-mer']."</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_merop = mysql_fetch_array($result,MYSQL_ASSOC))
              {
               $res_org = $result_merop['organizaciya'];

              if($result_merop['visible']=='show') $merop_vis="<a href=hide.php?mer_id=".$result_merop['mer_id']." title='".$TEXT['tbl-hide-tit6']."'><img alt='".$TEXT['tbl-show']."' src='../img/show.png' height='16' width='16' align='top' /></a>";
                else $merop_vis="<a href=show.php?mer_id=".$result_merop['mer_id']." title='".$TEXT['tbl-show-tit6']."'><img alt='".$TEXT['tbl-hide']."' src='../img/hide.png' height='16' width='16' align='top' /></a>";

              $edit = "<a href=editform.php?mer_id=".$result_merop['mer_id']." title='".$TEXT['tbl-edit-tit-mer']."'>".$TEXT['tbl-edit']."</a>";
              $delete = "<a href=deleteform.php?mer_id=".$result_merop['mer_id']." title='".$TEXT['tbl-delete-tit-mer']."'>".$TEXT['tbl-delete']."</a>";
              $move_up = "<a href=up-down.php?mer_id=".$result_merop['mer_id']."&amp;org_id=".$result_merop['org_id']."&amp;position=".$result_merop['position']."&amp;moving=up title='".$TEXT['global-up-down-tit']."'><img src='../img/up.png' height='16' width='16' align='top' /></a>";
              $move_down = "<a href=up-down.php?mer_id=".$result_merop['mer_id']."&amp;org_id=".$result_merop['org_id']."&amp;position=".$result_merop['position']."&amp;moving=down title='".$TEXT['global-up-down-tit']."'><img src='../img/down.png' height='16' width='16' align='top' /></a>";
              $photoind = "<a href=photoindex.php?mer_id=".$result_merop['mer_id'].">".$result_merop['meropriyatie']."</a>";

                ?>
                    <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
                      <td><?php echo $photoind; ?></td>
                      <td><?php echo $res_org; ?></td>
                      <td><?php echo $result_merop['position']; ?></td>
                      <td><?php echo $merop_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";
?>