<?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['global-title5'];
  $helppage = $TEXT['global-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(!isset($title)) $title = $TEXT['global-title5'];
  if(!isset($button)) $button = $TEXT['btn_edit'];
  if(!isset($action)) $action = "editresource.php";

  if(strlen($_GET['user_id'])>11) puterror2($TEXT['error-user2']);
  if(strlen($_GET['res_id'])>11) puterror2($TEXT['error-res16']);
  $_GET['user_id'] = rep($_GET['user_id']);
  $_GET['res_id'] = rep($_GET['res_id']);

  $old_user_id = $_GET['user_id'];
  $old_res_id = $_GET['res_id'];

  $query = "SELECT * FROM `tbl_resource` WHERE `user_id`='".$_GET['user_id']."' ";
  $result = mysql_query($query);
  if(!$result) puterror2($TEXT['error-tbl16']);
   $result2 = mysql_fetch_array($result,MYSQL_ASSOC);
    $resource = $result2['resource'];

  $query_tmp = "SELECT user_id, familiya, name, otchestvo FROM `tbl_users` WHERE `user_id`=".$_GET['user_id']."";
  $result2 = mysql_query($query_tmp);
  if(!$result2) puterror2($TEXT['error-tbl2']);
    $result_user = mysql_fetch_array($result2,MYSQL_ASSOC);
    $old_user = $result_user['familiya']." ".$result_user['name']." ".$result_user['otchestvo'];

?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table>
<tr><td class="useraddedit"><?php echo $TEXT['res-field3']; ?></td><td class="userassociation"><?php echo $resource; ?></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-otvet']; ?></td>
    <td class="useraddedit"><select class="inputmandatory" name="user_id">
    <?php
        $query = "SELECT user_id, familiya, name, otchestvo, visible FROM `tbl_users` WHERE `visible` != 'hide' ORDER BY `familiya`";
        $user_tmp = mysql_query($query);
          if(!$user_tmp) puterror2($TEXT['error-tbl2']);
              while($user = mysql_fetch_array($user_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$user['user_id'].">".$user['familiya']." ".$user['name']." ".$user['otchestvo'];
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td></td><td>
<input class=button type=submit value='<?php echo $button; ?>' />
<input type=hidden name=old_user_id value='<?php echo $old_user_id; ?>' />
<input type=hidden name=old_res_id value='<?php echo $old_res_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>