<?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['usr-title4'];
  $helppage = $TEXT['usr-help4'];

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

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

  $old_user_id = $_GET['user_id'];

  $query = "SELECT * FROM `tbl_users` WHERE `user_id`='".$_GET['user_id']."' ";
  $result = mysql_query($query);
  if(!$result) puterror2($TEXT['error-tbl2']);
   $result2 = mysql_fetch_array($result,MYSQL_ASSOC);
         $familiya = $result2['familiya'];
         $name = $result2['name'];
         $otchestvo = $result2['otchestvo'];
         $position = $result2['position'];
         $mail = $result2['mail'];
         $phone_mob = $result2['phone_mob'];
         $phone_int = $result2['phone_int'];
         $phone_city = $result2['phone_city'];
         $room = $result2['room'];
         $image = "<img alt='картинка' width='130' height='185' class=photo src=../../".$result2['photo']." />";

         if(!empty($result2['photo']) && $result2['photo']!="-") $result_image = "<img alt='картинка' src='../../photo/".$result2['photo']."' />";
            else $result_image = "<img alt='картинка' width='130' height='185' class=photo src='../../img/nophoto.png' />";

         $old_photo = "<a href='../../photo/".$result2['photo']."' target=_blank>".$result2['photo']."</a>";
         $old_pho = $result2['photo'];
         $old_dom_id = $result2['dom_id'];
         $old_city_id = $result2['city_id'];
         $old_str_id = $result2['str_id'];
         $old_house_id = $result2['house_id'];
         $old_org_id = $result2['org_id'];
         $old_upr_id = $result2['upr_id'];
         $old_otd_id = $result2['otd_id'];
         $old_dol_id = $result2['dol_id'];

?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table>
<tr><td>&nbsp;</td><td align="center"><?php echo $result_image; ?></td><td>&nbsp;</td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-lastname']; ?></td><td class="useraddedit"><input size=50 maxlength=50 class="inputmandatory" type=text name=familiya value='<?php echo $familiya; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-name']; ?></td><td class="useraddedit"><input size=50 maxlength=50 class="inputmandatory" type=text name=name value='<?php echo $name; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-otch']; ?></td><td class="useraddedit"><input size=50 maxlength=50 type=text name=otchestvo value='<?php echo $otchestvo; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-pho']; ?></td><td class="useraddedit"><input type=file name=photo />  <input type=checkbox name=clear_picture /> <?php echo $TEXT['tbl-delete']; ?></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['photo_obr']; ?></td><td class="useraddedit">
    <select name="photo_obr">
  <option value='1' selected><?php echo $TEXT['photo_no']; ?>
  <option value='2' ><?php echo $TEXT['photo_rec_l']; ?>
  <option value='4' ><?php echo $TEXT['photo_rec_l_t']; ?>
    </select>
   </td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-position']; ?></td><td class="useraddedit"><input size=5 maxlength=5 class="inputmandatory" type=text name=position value='<?php echo $position; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['res-field4']; ?></td><td class="useraddedit"><input size=20 maxlength=55 type=text name=mail value='<?php echo $mail; ?>' />@
<select class="input" name="dom_id">
    <?php
        $query = "SELECT * FROM `tbl_domain` ORDER BY domain";
        $domain_tmp = mysql_query($query);
          if(!$domain_tmp) puterror2($TEXT['error-tbl5']);
              while($domain = mysql_fetch_array($domain_tmp,MYSQL_ASSOC))
                {
                 if($domain['dom_id'] == $result2['dom_id'])
                   {
                   $chk = "<option selected value=".$domain['dom_id'].">".$domain['domain']."";
                   }
                 else $chk = "<option value=".$domain['dom_id'].">".$domain['domain']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['usr-field1']; ?></td><td class="useraddedit"><input size=30 maxlength=30 type=text name=phone_mob value='<?php echo $phone_mob; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['usr-field2']; ?></td><td class="useraddedit"><input size=30 maxlength=30 type=text name=phone_city value='<?php echo $phone_city; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['usr-field3']; ?></td><td class="useraddedit"><input size=20 maxlength=20 type=text name=phone_int value='<?php echo $phone_int; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-city']; ?></td>
    <td class="useraddedit"><select class="input" name="city_id">
    <?php
        $query1 = "SELECT * FROM `tbl_city` ORDER BY city";
        $city_tmp = mysql_query($query1);
          if(!$city_tmp) puterror2($TEXT['error-tbl1']);
              while($city = mysql_fetch_array($city_tmp,MYSQL_ASSOC))
                {
                 if($city['city_id'] == $result2['city_id'])
                   {
                   $chk = "<option selected value=".$city['city_id'].">".$city['city']."";
                   }
                 else $chk = "<option value=".$city['city_id'].">".$city['city']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-str']; ?></td>
    <td class="useraddedit"><select class="input" name="str_id">
    <?php
        $query2 = "SELECT * FROM `tbl_street` ORDER BY street";
        $street_tmp = mysql_query($query2);
          if(!$street_tmp) puterror2($TEXT['error-tbl3']);
              while($street = mysql_fetch_array($street_tmp,MYSQL_ASSOC))
                {
                 if($street['str_id'] == $result2['str_id'])
                   {
                   $chk = "<option selected value=".$street['str_id'].">".$street['street']."";
                   }
                 else $chk = "<option value=".$street['str_id'].">".$street['street']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-house']; ?></td>
    <td class="useraddedit"><select class="input" name="house_id">
    <?php
        $query3 = "SELECT * FROM `tbl_house` ORDER BY house";
        $house_tmp = mysql_query($query3);
          if(!$house_tmp) puterror2($TEXT['error-tbl4']);
              while($house = mysql_fetch_array($house_tmp,MYSQL_ASSOC))
                {
                 if($house['house_id'] == $result2['house_id'])
                   {
                   $chk = "<option selected value=".$house['house_id'].">".$house['house']."";
                   }
                 else $chk = "<option value=".$house['house_id'].">".$house['house']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['usr-field4']; ?></td><td class="useraddedit"><input size=8 maxlength=8 type=text name=room value='<?php echo $room; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-org']; ?></td>
    <td class="useraddedit"><select class="input" name="org_id">
    <?php
        $query4 = "SELECT * FROM `tbl_organizaciya` WHERE `visible` != 'hide' 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'] == $result2['org_id'])
                   {
                   $chk = "<option selected value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                   }
                 else $chk = "<option value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-upr']; ?></td>
    <td class="useraddedit"><select class="input" name="upr_id">
    <?php
        $query5 = "SELECT * FROM `tbl_upravlenie` ORDER BY upravlenie, position";
        $upravlenie_tmp = mysql_query($query5);
          if(!$upravlenie_tmp) puterror2($TEXT['error-tbl9']);
              while($upravlenie = mysql_fetch_array($upravlenie_tmp,MYSQL_ASSOC))
                {
                 if($upravlenie['upr_id'] == $result2['upr_id'])
                   {
                   $chk = "<option selected value=".$upravlenie['upr_id'].">".$upravlenie['upravlenie']."";
                   }
                 else $chk = "<option value=".$upravlenie['upr_id'].">".$upravlenie['upravlenie']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-otd']; ?></td>
    <td class="useraddedit"><select class="input" name="otd_id">
    <?php
        $query6 = "SELECT * FROM `tbl_otdel` ORDER BY otdel, position";
        $otdel_tmp = mysql_query($query6);
          if(!$otdel_tmp) puterror2($TEXT['error-tbl8']);
              while($otdel = mysql_fetch_array($otdel_tmp,MYSQL_ASSOC))
                {
                 if($otdel['otd_id'] == $result2['otd_id'])
                   {
                   $chk = "<option selected value=".$otdel['otd_id'].">".$otdel['otdel']."";
                   }
                 else $chk = "<option value=".$otdel['otd_id'].">".$otdel['otdel']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-post']; ?></td>
    <td class="useraddedit"><select class="input" name="dol_id">
    <?php
        $query7 = "SELECT * FROM `tbl_dolzhnost` ORDER BY dolzhnost, position";
        $dolzhnost_tmp = mysql_query($query7);
          if(!$dolzhnost_tmp) puterror2($TEXT['error-tbl6']);
              while($dolzhnost = mysql_fetch_array($dolzhnost_tmp,MYSQL_ASSOC))
                {
                 if($dolzhnost['dol_id'] == $result2['dol_id'])
                   {
                   $chk = "<option selected value=".$dolzhnost['dol_id'].">".$dolzhnost['dolzhnost']."";
                   }
                 else $chk = "<option value=".$dolzhnost['dol_id'].">".$dolzhnost['dolzhnost']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=old_pho value='<?php echo $old_pho; ?>' />
<input type=hidden name=old_dom_id value='<?php echo $old_dom_id; ?>' />
<input type=hidden name=old_city_id value='<?php echo $old_city_id; ?>' />
<input type=hidden name=old_str_id value='<?php echo $old_str_id; ?>' />
<input type=hidden name=old_house_id value='<?php echo $old_house_id; ?>' />
<input type=hidden name=old_org_id value='<?php echo $old_org_id; ?>' />
<input type=hidden name=old_upr_id value='<?php echo $old_upr_id; ?>' />
<input type=hidden name=old_otd_id value='<?php echo $old_otd_id; ?>' />
<input type=hidden name=old_dol_id value='<?php echo $old_dol_id; ?>' />
<input type=hidden name=user_id value='<?php echo $old_user_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>