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

  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']);

  if(!isset($title)) $title = $TEXT['org-title2'];
  if(!isset($button)) $button = $TEXT['btn_del'];
  if(!isset($action)) $action = "delete.php";
  if(!isset($button2)) $button2 = $TEXT['btn_back'];
  if(!isset($action2)) $action2 = "index.php";
  if(empty($_GET['org_id'])) $_GET['org_id'] = "";
  if(empty($_POST['org_id'])) $_POST['org_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%" >
<?php
  if(strlen($_GET['org_id'])>11) puterror2($TEXT['error-org1']);
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org1']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $_POST['org_id'] = rep($_POST['org_id']);

  $old_org_id = $_GET['org_id'];
  $old_user_org_id = $_POST['org_id'];

  if(empty($_GET['org_id'])) $org_id = $old_user_org_id;
    else $org_id = $old_org_id;

  $query = "SELECT `organizaciya` FROM `tbl_organizaciya` WHERE `org_id`='$org_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl7']);
       if (mysql_num_rows($result)>0);
         {
          $result_organizaciya = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['org-now'].$result_organizaciya['organizaciya']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT tbl_users.*, tbl_organizaciya.org_id, tbl_organizaciya.organizaciya FROM tbl_users JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id WHERE tbl_users.org_id='$org_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl2']);
          $num_rows = mysql_num_rows($result2);
       if ($num_rows>0)
          {
           echo "<p><u>".$TEXT['global-title3']."</u></p>
             <table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['tbl-lastname']."</td>
            <td>".$TEXT['tbl-name']."</td>
            <td>".$TEXT['tbl-otch']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_users = mysql_fetch_array($result2))
                {
                 $res_org = $result_users['organizaciya'];
                 $edit = "<a href=editusersform.php?org_id=".$result_users['org_id']."&user_id=".$result_users['user_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
             ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_users['familiya']; ?></td>
            <td><?php echo $result_users['name']; ?></td>
            <td><?php echo $result_users['otchestvo']; ?></td>
            <td><b><i><?php echo $res_org; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
            <?php
                }
	    ?>
	    </table>
	    <?php
          }
?>
<?php
  $query5 = "SELECT tbl_resource.*, tbl_organizaciya.org_id, tbl_organizaciya.organizaciya FROM tbl_resource JOIN tbl_organizaciya ON tbl_resource.org_id=tbl_organizaciya.org_id WHERE tbl_resource.org_id='$org_id'";
  $result5 = mysql_query($query5);
  if (!$result5) puterror2($TEXT['error-tbl16']);
          $num_rows = mysql_num_rows($result5);
       if ($num_rows>0)
          {
           echo "<table class='table' border='1' cellpadding='3' cellspacing='0' width='40%' >
            <tr class='tableheadercat'>
            <td>".$TEXT['res-field3']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_resource = mysql_fetch_array($result5))
                {
                 $res_org5 = $result_resource['organizaciya'];
                 $edit = "<a href=editresourceform.php?org_id=".$result_resource['org_id']."&res_id=".$result_resource['res_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
             ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_resource['resource']; ?></td>
            <td><b><i><?php echo $res_org; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
            <?php
                }
	    ?>
	    </table>
	    <?php
          }
?>
<?php
  $query6 = "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.org_id='$org_id'";
  $result6 = mysql_query($query6);
  if (!$result6) puterror2($TEXT['error-tbl12']);
          $num_rows = mysql_num_rows($result6);
       if ($num_rows>0)
          {
           echo "<table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['pho-field1']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_meropriyatie = mysql_fetch_array($result6))
                {
                 $res_org5 = $result_meropriyatie['organizaciya'];
                 $edit = "<a href=editmeropriyatieform.php?org_id=".$result_meropriyatie['org_id']."&mer_id=".$result_meropriyatie['mer_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
             ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_meropriyatie['meropriyatie']; ?></td>
            <td><b><i><?php echo $res_org; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
            <?php
                }
	    ?>
	    </table>
	    <?php
          }
?>
<?php
  $query7 = "SELECT tbl_razdel.*, tbl_organizaciya.org_id, tbl_organizaciya.organizaciya FROM tbl_razdel JOIN tbl_organizaciya ON tbl_razdel.org_id=tbl_organizaciya.org_id WHERE tbl_razdel.org_id='$org_id'";
  $result7 = mysql_query($query7);
  if (!$result7) puterror2($TEXT['error-tbl15']);
          $num_rows = mysql_num_rows($result7);
       if ($num_rows>0)
          {
           echo "<table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['nd-field5']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_razdel = mysql_fetch_array($result7))
                {
                 $res_org5 = $result_razdel['organizaciya'];
                 $edit = "<a href=editrazdelform.php?org_id=".$result_razdel['org_id']."&razd_id=".$result_razdel['razd_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
             ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_razdel['razdel']; ?></td>
            <td><b><i><?php echo $res_org; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
            <?php
                }
	    ?>
	    </table>
	    <?php
          }
?>
<?php
  $query8 = "SELECT tbl_meet_room.* FROM tbl_meet_room WHERE tbl_meet_room.org_id='$org_id'";
  $result8 = mysql_query($query8);
   if(!$result8) puterror2($TEXT['error-tbl48']);
     $num_rows8 = mysql_num_rows($result8);
       if($num_rows8>0)
          {
           echo "<table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['meet-title']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_meropriyatie8 = mysql_fetch_array($result8))
                {
                 $res_org8 = $result_meropriyatie8['organizaciya'];
                 $edit = "<a href=../meeting/index.php title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
             ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_meropriyatie8['room_name']; ?></td>
            <td><b><i><?php echo $res_org; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
            <?php
                }
	    ?>
	    </table>
	    <?php
          }
?>
<?php
  $query4 = "SELECT tbl_news.new_id, tbl_news.header, tbl_news.org_id, tbl_organizaciya.org_id, tbl_organizaciya.organizaciya FROM tbl_news JOIN tbl_organizaciya ON tbl_news.org_id=tbl_organizaciya.org_id WHERE tbl_news.org_id='$org_id'";
  $result4 = mysql_query($query4);
  if (!$result4) puterror2($TEXT['error-tbl17']);
          $num_rows = mysql_num_rows($result4);
       if ($num_rows>0)
          {
           echo "<table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['tbl-news']."</td>
            <td>".$TEXT['tbl-org']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_news = mysql_fetch_array($result4))
                {
                 $res_org3 = $result_organizaciya3['organizaciya'];
                 $edit2 = "<a href=editnewsform.php?org_id=".$result_news['org_id']."&news_id=".$result_news['new_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
           ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_news['header']; ?></td>
            <td><b><i><?php echo $res_org3; ?></i></b></td>
            <td><?php echo $edit2; ?></td>
                 </tr>
           <?php
                }
	    ?>
	    </table>
	    <?php
          }
          $num_rows = $num_rows1 + $num_rows3 + $num_rows4 + $num_rows5 + $num_rows6;

          if($num_rows !== 0) $action_end = $action2;
          else $action_end = $action;

          if($num_rows !== 0) $button_end = $button2;
          else $button_end = $button;

?>
<form enctype='multipart/form-data' action=<?php echo $action_end; ?> method=post>
<table align="center">
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button_end; ?>' />
<input type=hidden name=org_id value='<?php echo $old_org_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>