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

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

  $title=$titlepage=$TEXT['support3'];

  require_once "config.php";
  require_once "utils/top_zayavka_otv.php";

  if(!isset($button)) $button = $TEXT['support16'];
  if(!isset($action)) $action = "zayavka_add_otv.php";
  if(!isset($button2)) $button2 = $TEXT['support104'];
  if(!isset($action2)) $action2 = "zayavka_ed_otv.php";

  if(empty($_POST['res_id'])) puterror($TEXT['error-res1']);
  if(strlen($_POST['res_id'])>11) puterror($TEXT['error-res2']);
//  $_POST['tema_id'] = substr($_POST['tema_id'], 24,32);
//  $_POST['tema_id'] = preg_replace('{&user_id=[\d]+?}','',$_POST['tema_id']);
  if(strlen($_POST['sroch_id'])>11) puterror($TEXT['error-supp20']);
  if(empty($_POST['kod'])) puterror($TEXT['error-supp9']);
  if(strlen($_POST['kod'])>300) puterror($TEXT['error-supp8']);
  if(strlen($_POST['org_id'])>11) puterror($TEXT['error-org']);
  $_POST['sroch_id'] = rep($_POST['sroch_id']);
  $_POST['tema_id'] = rep($_POST['tema_id']);
  $_POST['kod'] = rep($_POST['kod']);
  $_POST['org_id'] = rep($_POST['org_id']);
  $_POST['res_id'] = rep($_POST['res_id']);
  $old_org_id = $_POST['org_id'];

  if($_POST['onorg'] == "on")
  {
   $org = "AND tbl_users.org_id = '".$_POST['org_id']."' ";
   $onchb = "checked";
  }
  else
   {
    $org = "";
    $onchb = "";
   }
?>
<form enctype='multipart/form-data' action=<?php echo $action2; ?> 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['support104']; ?>"><?php echo $TEXT['support104']; ?></legend>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="support_ob3"><td width="30%"><?php echo $TEXT['support89']; ?></td><td width="2%">&nbsp;</td></tr>
<tr><td><input type=checkbox name=onorg <?php echo $onchb; ?> /><select class=input name="org_id">
    <?php
        $query4 = "SELECT `organizaciya`, `org_id` FROM `tbl_organizaciya` ORDER BY position";
        $organizaciya_tmp = mysql_query($query4);
          if(!$organizaciya_tmp) puterror($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></td>
	<td width="5%">
        <input type=hidden name=org_id value='<?php echo $_POST['org_id']; ?>' />
        <input type=hidden name=tema_id value='<?php echo $_POST['tema_id']; ?>' />
        <input type=hidden name=res_id value='<?php echo $_POST['res_id']; ?>' />
        <input type=hidden name=sroch_id value='<?php echo $_POST['sroch_id']; ?>' />
        <input type=hidden name=description value='<?php echo $_POST['description']; ?>' />
        <input type=hidden name=kod value='<?php echo $_POST['kod']; ?>' />
	<input class="button" type=submit value='<?php echo $button2; ?>' />
	</td>
</tr>
</table>
</fieldset>
</td></tr>
<tr><td>
</table>
<hr width="70%"/>
</form>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="70%">
<tr><td class="head_tbl_rght"><?php echo $TEXT['user-check']; ?></td></tr>
</table>
<table align="center" class="table" border="1" cellpadding="0" cellspacing="0" width="70%">
<?php
     $query_user = "SELECT
     tbl_users.*,
     tbl_organizaciya.org_id,
     tbl_organizaciya.organizaciya,
     tbl_upravlenie.upr_id,
     tbl_upravlenie.upravlenie,
     tbl_otdel.otd_id,
     tbl_otdel.otdel,
     tbl_dolzhnost.dol_id,
     tbl_dolzhnost.dolzhnost
     FROM tbl_users
     JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id
     JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id
     JOIN tbl_otdel ON tbl_users.otd_id=tbl_otdel.otd_id
     JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
     WHERE tbl_users.visible = 'show' ".$org."
     ORDER BY tbl_users.familiya ";
     $result_user1 = mysql_query($query_user);
     if(!$result_user1) puterror($TEXT['error-tbl2']);
       if(mysql_num_rows($result_user1)>0);
         {
           echo "<tr class='tableheadercat'>
            <td>".$TEXT['search-name2']." ".$TEXT['search-name']." ".$TEXT['search-otch']."</td>
            <td>".$TEXT['support89']."</td>
            <td>".$TEXT['top-upr']."</td>
            <td>".$TEXT['top-otd']."</td>
            <td>".$TEXT['search-dol2']."</td>
            <td>".$TEXT['btn_add']."</td>
                 </tr>";
             while($result_zayavka = mysql_fetch_array($result_user1,MYSQL_ASSOC))
              {
	       $usr_tmp = $result_zayavka['user_id'];
                ?>
             <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $result_zayavka['familiya']."  ".$result_zayavka['name']." ".$result_zayavka['otchestvo']; ?></td>
              <td><?php echo $result_zayavka['organizaciya']; ?></td>
              <td><?php echo $result_zayavka['upravlenie']; ?></td>
              <td><?php echo $result_zayavka['otdel']; ?></td>
              <td><?php echo $result_zayavka['dolzhnost']; ?></td>
              <td><input type=checkbox name=usr[<?php echo $usr_tmp; ?>] /></td>
             </tr>
                <?php
              }
         }
?>
</table>
<table align="center" class="table" border="0" cellpadding="2" cellspacing="0" width="70%">
<tr>
<td align="right">
<input type=hidden name=org_id value='<?php echo $_POST['org_id']; ?>' />
<input type=hidden name=tema_id value='<?php echo $_POST['tema_id']; ?>' />
<input type=hidden name=res_id value='<?php echo $_POST['res_id']; ?>' />
<input type=hidden name=sroch_id value='<?php echo $_POST['sroch_id']; ?>' />
<input type=hidden name=description value='<?php echo $_POST['description']; ?>' />
<input type=hidden name=kod value='<?php echo $_POST['kod']; ?>' />
<input class="button" type=submit value='<?php echo $button; ?>' />
</td>
</tr>
</table>
</form>
<?php
  require_once "utils/bottom_search.php";
?>