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

  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-title3'];
  if(!isset($button)) $button = $TEXT['btn_del'];
  if(!isset($action)) $action = "delete.php";
  if(!isset($button2)) $button2 = $TEXT['btn_back'];
  if(!isset($action2)) $action2 = "index.php";
  if(empty($_GET['mer_id'])) $_GET['mer_id'] = "";
  if(empty($_POST['mer_id'])) $_POST['mer_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%">
<?php
  if(strlen($_GET['mer_id'])>11) puterror2($TEXT['error-pho13']);
  if(strlen($_POST['mer_id'])>11) puterror2($TEXT['error-pho13']);
  $_GET['mer_id'] = rep($_GET['mer_id']);
  $_POST['mer_id'] = rep($_POST['mer_id']);

  $old_mer_id = $_GET['mer_id'];
  $old_photo_mer_id = $_POST['mer_id'];

  if(empty($_GET['mer_id'])) $mer_id = $old_photo_mer_id;
    else $mer_id = $old_mer_id;

  $query = "SELECT * FROM `tbl_meropriyatiya` WHERE `mer_id`='$mer_id'";
  $result = mysql_query($query);
    if(!$result) puterror2($TEXT['error-tbl12']);
       if(mysql_num_rows($result)>0);
         {
          $result_meropriyatie = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['pho-now'].$result_meropriyatie['meropriyatie']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "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.mer_id='$mer_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl13']);
          $num_rows = mysql_num_rows($result2);
       if ($num_rows>0)
          {
           echo "<p><u>".$TEXT['global-title3']."</u></p>
            <table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['tbl-mer']."</td>
            <td>".$TEXT['tbl-pho-name']."</td>
            <td>".$TEXT['tbl-pho']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_photo = mysql_fetch_array($result2))
                {
                 $res_mer = $result_photo['meropriyatie'];
                 $image = "<img width='165' height='135' alt='картинка' src=../".$result_photo['small']." />";
                 $edit = "<a href=editphotoform.php?mer_id=".$result_photo['mer_id']."&photo_id=".$result_photo['photo_id'].">".$TEXT['tbl-edit2']."</a>";
           ?>
            <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><b><i><?php echo $res_mer; ?></i></b></td>
              <td><?php echo $result_photo['name']; ?></td>
              <td><?php echo $image; ?></td>
              <td><?php echo $edit; ?></td>
            </tr>
           <?php
                }
          }
          if($num_rows !== 0) $action_end = $action2;
          else $action_end = $action;

          if($num_rows !== 0) $button_end = $button2;
          else $button_end = $button;
?>
</table>
<form enctype='multipart/form-data' action=<?php echo $action_end; ?> method=post>
<table align='center'>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button_end; ?>' />
<input type=hidden name=mer_id value='<?php echo $old_mer_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>