<?php
  ///////////////////////////////////////////////////
  //База знаний
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang.".php")) include "../lang/".$lang.".php";
     else include "../lang/ru.php";

  $title=$titlepage = $TEXT['new-tag36'];

  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  <link rel="shortcut icon" href="../Favicon/know-base.ico" type="image/x-icon" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <?php
  if(!isset($button)) $button = $TEXT['btn_gen'];
  if(!isset($action)) $action = "know_add_table.php";

  if($_POST['view_cod'] =="on") $view_chk = "checked";
   else $view_chk = "";

  if($_POST['stolb']>0) $rwstolb = "readonly";
   else $rwstolb = "";
?>
<table class="tabledata" align="center">
  <tr><td class="z1"><?php echo $titlepage; ?></td></tr>
</table>
<form enctype='multipart/form-data' name='form' action=<?php echo $action; ?> method=post>
<table class="tabledata" align="center" border="0">
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param1']; ?></td><td align="left"><input type="text" size=30 maxlength=155 name="tbwidth" value="<?php echo $_POST['tbwidth']; ?>" /></td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param3']; ?><?php echo $TEXT['tbl-param6']; ?></td><td align="left">
   <select name="viravnivanietbl">
    <option value='left' <?php if ($_POST['viravnivanietbl'] =='left') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr5']; ?>
    <option value='right' <?php if ($_POST['viravnivanietbl'] =='right') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr6']; ?>
    <option value='center' <?php if ($_POST['viravnivanietbl'] =='center') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr7']; ?>
   </select>
 </td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param2']; ?></td><td align="left"><input type="text" size=30 maxlength=155 name="capt" value="<?php echo $_POST['capt']; ?>" /></td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param3']; ?><?php echo $TEXT['tbl-param7']; ?></td><td align="left">
   <select name="viravnivaniecapt">
    <option value='captleft' <?php if ($_POST['viravnivaniecapt'] =='captleft') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr5']; ?>
    <option value='captright' <?php if ($_POST['viravnivaniecapt'] =='captright') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr6']; ?>
    <option value='capttop' <?php if ($_POST['viravnivaniecapt'] =='capttop') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr9']; ?>
    <option value='captdown' <?php if ($_POST['viravnivaniecapt'] =='captdown') echo "selected"; ?>><?php echo $TEXT['ssilka-otobr8']; ?>
   </select>
 </td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param4']; ?></td><td align="left"><input <?php echo $rwstolb; ?> type="text" size=30 maxlength=255 name="stolb" value="<?php echo $_POST['stolb']; ?>"  /></td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-param5']; ?></td><td align="left"><input type="text" size=30 maxlength=255 name="str" value="<?php echo $_POST['str']; ?>" /></td></tr>
 <tr><td class="useraddedit"><?php echo $TEXT['tbl-view-cod']; ?></td><td align="left"><input type=checkbox name=view_cod <?php echo $view_chk; ?> /></td></tr>
<tr><td align="center" colspan="2"><input class="button" type=submit value='<?php echo $button; ?>' /></td></tr>
</table>

<?php
  if(!empty($_POST['tbwidth']))
  {
   echo "<table border='1' width='".$_POST['tbwidth']."%' align='".$_POST['viravnivanietbl']."' >";
   if(!empty($_POST['capt']))
     {
      echo "<caption class='".$_POST['viravnivaniecapt']."'>".$_POST['capt']."</caption>";
     }
   if(!empty($_POST['stolb'])) 
      {
      if(!empty($_POST['str']))
       {
       $k=0;
       for($n=0;$n<$_POST['str'];$n++)
        {
         for($i=0;$i<$_POST['stolb'];$i++)
          {
          $stlb .= "<td align='center'><input type='text' name=dat[] value='".$_POST['dat'][$k]."'></td>";
          $k++;
          }
       if($n==0) $strb ="<tr class='inputmandatory'>".$stlb."</tr>";
        else $strb .="<tr>".$stlb."</tr>";
       $stlb = "";
       }
       echo $strb;
      }
     }
   echo "</table><br clear='all' />";
 }
 ?>
</form>
<?php
// отображаем код для вставки
if($view_chk == "checked")
 {
  echo "<table border='0' width='95%' align='center'><tr><td><p class='statssilka'><img class='tipsimg' alt='tips' src='../img/inet16.png' />";
  echo "&lt;table border='1' width='".$_POST['tbwidth']."%' align='".$_POST['viravnivanietbl']."' class='tableknows' &gt;";
   if(!empty($_POST['capt']))
     {
      echo "&lt;caption class='".$_POST['viravnivaniecapt']."'&gt;".$_POST['capt']."&lt;/caption&gt;";
     }
     if(!empty($_POST['stolb']))
      {
      if(!empty($_POST['str']))
       {
       $p=0;
       for($m=0;$m<$_POST['str'];$m++)
        {
         for($z=0;$z<$_POST['stolb'];$z++)
          {
          $stlbv .= "&lt;td align='center'&gt;".$_POST['dat'][$p]."&lt;/td&gt;";
          $p++;
          }
       if($m==0) $strbv ="&lt;tr class='topheadertbl'&gt;".$stlbv."&lt;/tr&gt;";
        else $strbv .="&lt;tr class='tabledata'&gt;".$stlbv."&lt;/tr&gt;";
       $stlbv = "";
       }
       echo $strbv;
      }
     }
   echo "&lt;/table&gt;</p></td></tr></table>";
 }

?>
</body>
</html>