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

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

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

  if(!isset($title)) $title = $TEXT['size-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['size_id'])) $_GET['size_id'] = "";
  if(empty($_POST['size_id'])) $_POST['size_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%">
<?php
  if(strlen($_GET['size_id'])>2) puterror2($TEXT['error-size6']);
  if(strlen($_POST['size_id'])>2) puterror2($TEXT['error-size6']);
  $_GET['size_id'] = rep($_GET['size_id']);
  $_POST['size_id'] = rep($_POST['size_id']);

  $old_size_id = $_GET['size_id'];
  $old_size_otd_id = $_POST['size_id'];

  if(empty($_GET['size_id'])) $size_id = $old_size_otd_id;
    else $size_id = $old_size_id;

  $query = "SELECT `size_name` FROM `tbl_sizes` WHERE `size_id`='$size_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl35']);
       if (mysql_num_rows($result)>0);
         {
          $result_size = mysql_fetch_array($result);
           echo "<tr class='delit'>
              <td>".$TEXT['size-del'].$result_size['size_name']."</td>
              </tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT 
  tbl_resource.size_id, 
  tbl_resource.resource, 
  tbl_sizes.size_id, 
  tbl_sizes.size_name 
  FROM tbl_resource 
  JOIN tbl_sizes ON tbl_resource.size_id=tbl_sizes.size_id 
  WHERE tbl_resource.size_id='$size_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl16']);
          $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['res-field3']."</td>
            <td>".$TEXT['tbl-size']."</td>
            <td colspan=3>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_resources = mysql_fetch_array($result2))
               {
                $res_size = $result_resources['size_name'];
                $edit = "<a href=editusersform.php?size_id=".$result_resources['size_id']."&res_id=".$result_resources['res_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
           ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_resources['resource']; ?></td>
            <td><b><i><?php echo $res_size; ?></i></b></td>
            <td><?php echo $edit; ?></td>
                 </tr>
           <?php
               }
	?>
	</table>
	<?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=size_id value='<?php echo $old_size_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>