<?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['res-title3'];
  $helppage = $TEXT['res-help3'];

  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['res-title3'];
  if(!isset($button)) $button = $TEXT['btn_edit'];
  if(!isset($action)) $action = "edit.php";

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

  $old_res_id = $_GET['res_id'];

  $query_tmp = "SELECT * FROM tbl_resource WHERE res_id=$old_res_id";
  $result = mysql_query($query_tmp);
  if(!$result) puterror2($TEXT['error-tbl16']);
  $result_resource = mysql_fetch_array($result);

    $old_ukk = $result_resource['ukk'];
    $old_resource = $result_resource['resource'];
    $old_description = $result_resource['description'];
    $old_position = $result_resource['position'];
    $old_user_id = $result_resource['user_id'];
    $old_org_id = $result_resource['org_id'];
    $bakup = $result_resource['bakup'];
    $old_size_id = $result_resource['size_id'];
    $old_bakprog = $result_resource['bakprog'];
    $old_bakrazm = $result_resource['bakrazm'];
    $old_rezim = $result_resource['rezim'];
    $old_srvkvota = $result_resource['srvkvota'];
    $old_sppubl = $result_resource['sppubl'];
    $old_gwrite = $result_resource['gwrite'];
    $old_gread = $result_resource['gread'];
    $old_srvput = $result_resource['srvput'];
    $old_srvname = $result_resource['srvname'];
    $old_photo = $result_resource['photo'];
    $old_tip_id = $result_resource['tip_id'];
    $old_res_name = $result_resource['res_name'];

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

  $query_tmp3 = "SELECT `organizaciya` FROM `tbl_organizaciya` WHERE `org_id`='".$result_resource['org_id']."'";
  $result3 = mysql_query($query_tmp3);
  if(!$result3) puterror2($TEXT['error-tbl7']);
    $result_org = mysql_fetch_array($result3);
    $old_org = $result_org['organizaciya'];

?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" width="60%">
<tr><td class="useraddedit"><?php echo $TEXT['res-field5']; ?></td><td class="useraddedit"><input size=30 maxlength=255 class="inputmandatory" type=text name=ukk value='<?php echo $old_ukk; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tip-res']; ?></td>
    <td class="useraddedit"><select name="tip_id">
    <?php
        $query_tip = "SELECT `tip_id`, `tip_name` FROM `tbl_tip_resurs` ORDER BY `position`";
         $tip_tmp = mysql_query($query_tip);
          if(!$tip_tmp) puterror2($TEXT['error-tbl38']);
           while($tip = mysql_fetch_array($tip_tmp,MYSQL_ASSOC))
            {
            if($tip['tip_id'] == $old_tip_id)
             {
             $chk2 = "<option selected value=".$tip['tip_id'].">".$tip['tip_name']."";
             }
             else $chk2 = "<option value=".$tip['tip_id'].">".$tip['tip_name']."";
             echo $chk2;
            }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-nazv']; ?></td><td class="useraddedit"><input size=30 maxlength=255 type=text name=res_name value='<?php echo $old_res_name; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field1']; ?></td><td class="useraddedit"><input size=30 maxlength=250 class="inputmandatory" type=text name=resource value='<?php echo $old_resource; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field2']; ?></td>
    <td class="useraddedit"><select name="user_id">
    <?php
        $query = "SELECT * 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))
                {
                 if($user['user_id'] == $old_user_id)
                   {
                   $chk = "<option selected value=".$user['user_id'].">".$user['familiya']." ".$user['name']." ".$user['otchestvo'];
                   }
                 else $chk = "<option value=".$user['user_id'].">".$user['familiya']." ".$user['name']." ".$user['otchestvo'];
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['org-field1']; ?></td>
    <td class="useraddedit"><select name="org_id">
    <?php
        $query2 = "SELECT * FROM `tbl_organizaciya` ORDER BY organizaciya ";
        $org_tmp = mysql_query($query2);
          if(!$org_tmp) puterror2($TEXT['error-tbl7']);
              while($org = mysql_fetch_array($org_tmp))
                {
                 if($org['org_id'] == $old_org_id)
                   {
                   $chk = "<option selected value=".$org['org_id'].">".$org['organizaciya'];
                   }
                 else $chk = "<option value=".$org['org_id'].">".$org['organizaciya'];
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-descr']; ?></td><td class="useraddedit"><textarea class=input name="description" cols="50" rows="5" ><?= $old_description ?></textarea></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-position']; ?></td><td class="useraddedit"><input size=5 maxlength=11 class="inputmandatory" type=text name=position value='<?php echo $old_position; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field6']; ?></td><td class="useraddedit"><input size=50 maxlength=100 type=text name=srvname value='<?php echo $old_srvname; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field7']; ?></td><td class="useraddedit"><input size=50 maxlength=255 type=text name=srvput value='<?php echo $old_srvput; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field8']; ?></td><td class="useraddedit"><input size=50 maxlength=1000 type=text name=gread value='<?php echo $old_gread; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field9']; ?></td><td class="useraddedit"><input size=50 maxlength=1000 type=text name=gwrite value='<?php echo $old_gwrite; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field10']; ?></td><td class="useraddedit"><input size=30 maxlength=100 type=text name=sppubl value='<?php echo $old_sppubl; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field11']; ?></td><td class="useraddedit"><input size=10 maxlength=10 type=text name=srvkvota value='<?php echo $old_srvkvota; ?>'>
    <select name="size_id">
    <?php
        $query3 = "SELECT * FROM `tbl_sizes` ORDER BY size_id ";
        $size_tmp = mysql_query($query3);
          if(!$size_tmp) puterror2($TEXT['error-tbl35']);
              while($size = mysql_fetch_array($size_tmp))
                {
                if($size['size_id'] == $old_size_id)
                   {
                   $chk = "<option selected value=".$size['size_id'].">".$size['size_name'];
                   }
                 else $chk = "<option value=".$size['size_id'].">".$size['size_name'];
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field12']; ?></td><td>
<select name=bakup>
  <option value='yes' <?php if ($bakup =='yes') echo "selected"?>><?php echo $TEXT['res-field16']; ?>
  <option value='no' <?php if ($bakup =='no') echo "selected"?>><?php echo $TEXT['res-field17']; ?>
</select>
</td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field13']; ?></td><td class="useraddedit"><input size=50 maxlength=255 type=text name=rezim value='<?php echo $old_rezim; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field14']; ?></td><td class="useraddedit"><input size=50 maxlength=255 type=text name=bakrazm value='<?php echo $old_bakrazm; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field15']; ?></td><td class="useraddedit"><input size=50 maxlength=255 type=text name=bakprog value='<?php echo $old_bakprog; ?>'></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-doc']; ?></td><td class="useraddedit"><input type=file name=photo>  <input type=checkbox name=clear_picture> <?php echo $TEXT['tbl-delete']; ?></td></tr>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=res_id value='<?php echo $old_res_id; ?>' />
<input type=hidden name=old_user_id value='<?php echo $old_user_id; ?>' />
<input type=hidden name=old_org_id value='<?php echo $old_org_id; ?>' />
<input type=hidden name=old_photo value='<?php echo $old_photo; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>