<?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['pho-title6'];
  $helppage = $TEXT['pho-help6'];

  require_once "../config.php";
  require_once "../util/top_layer1.php";

  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(!isset($title)) $title = $TEXT['pho-title6'];
  if(!isset($button)) $button = $TEXT['btn_edit'];
  if(!isset($action)) $action = "editphoto2.php";

  if(strlen($_GET['mer_id'])>11) puterror2($TEXT['error-pho13']);
  if(strlen($_GET['photo_id'])>11) puterror2($TEXT['error-pho18']);
  $_GET['mer_id'] = rep($_GET['mer_id']);
  $_GET['photo_id'] = rep($_GET['photo_id']);

  $old_photo_id = $_GET['photo_id'];
  $old_mer_id = $_GET['mer_id'];

  $query = "SELECT tbl_photo.*, tbl_meropriyatiya.mer_id, tbl_meropriyatiya.meropriyatie FROM tbl_photo JOIN tbl_meropriyatiya ON tbl_photo.mer_id=tbl_meropriyatiya.mer_id WHERE tbl_photo.photo_id='".$_GET['photo_id']."' ";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl13']);
   $result2 = mysql_fetch_array($result);
         $name = $result2['name'];
         $description = $result2['description'];
         $position = $result2['position'];
         $image = "<img align='left' src=../".$result2['small']." />";
         $res_mer = $result2['meropriyatie'];

?>
<p><h3><?php echo $TEXT['pho-now2']; ?><b><?php echo $res_mer; ?></b></h3></p>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-pho']; ?></td><td class="useraddedit" align=center><?php echo $image; ?></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-nazv']; ?></td><td class="useraddedit"><input size=50 maxlength=100 type=text name=name value='<?php echo $name; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-descr']; ?></td><td class="useraddedit"><textarea class="input" name="description" cols="50" rows="5" ><?= $description; ?></textarea></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-position']; ?></td><td class="useraddedit"><input size=11 maxlength=11 type=text name=position value='<?php echo $position; ?>' /></td></tr>
<tr><td class="useraddedit"><?php echo $TEXT['tbl-mer']; ?></td>
    <td class="useraddedit"><select class="inputmandatory" name="mer_id">
    <?php
        $query = "SELECT * FROM `tbl_meropriyatiya` WHERE `visible` != 'hide' ORDER BY position";
        $meropriyatie_tmp = mysql_query($query);
          if(!$meropriyatie_tmp) puterror2($TEXT['error-tbl12']);
              while($meropriyatie = mysql_fetch_array($meropriyatie_tmp))
                {
                 if($meropriyatie['mer_id'] == $old_mer_id)
                   $chk = "<option selected value=".$meropriyatie['mer_id'].">".$meropriyatie['meropriyatie']."";
                 else 
		   $chk = "<option value=".$meropriyatie['mer_id'].">".$meropriyatie['meropriyatie']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=photo_id value='<?php echo $old_photo_id; ?>' />
<input type=hidden name=old_mer_id value='<?php echo $old_mer_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>