<form name="format" method="post" enctype="multipart/form-data">
<input type="hidden" name="insert_id" value="<?php echo $insert_id ?>">
<input type="hidden" name="name" value="<?php echo $name ?>">
    
<?php
$result30 = $mysqli->query("SELECT * FROM lang WHERE active=1 ORDER BY priority");
while($row = $result30->fetch_array()) {
$langid=$row['id'];
$language=$row['language'];
$dir=$row['dir'];
?>

<?php
$result51 = $mysqli->query("SELECT * FROM langvars WHERE insert_id='$insert_id' AND lang_id=$langid");
while($row = $result51->fetch_array()) {
$name=$row['name'];
$lang_id=$row['lang_id'];
$name=$row['name'];
$text=$row['text'];
$editable=$row['editable'];
?>

<?php 
if  (isset($_POST['submit'.$_REQUEST['insert_id']])) {
$insertid = $mysqli->real_escape_string(stripslashes($_REQUEST['insert_id']));
$text = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid"]));
$text = str_replace('\r\n', ' ',$text);
$mysqli->query("UPDATE langvars SET text='$text' WHERE insert_id='$insertid' AND lang_id=$langid");
?>
<meta http-equiv="refresh" content="0">
<?php } ?>

  <table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td width="100">&nbsp;</td>
      <td><div class="diveditor"><textarea name="text<?php echo $langid ?>" cols="75" rows="3" class="mceEditor"><?php echo $text ?></textarea></div></td>
    </tr>
    </table>

<?php } ?>
<?php } ?>

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM langvars WHERE insert_id='$insert_id') AND active=1 ORDER BY id");
$nrrows52 = mysqli_num_rows($result52);
while($row = $result52->fetch_array()) {
$langid2=$row['id'];
$language2=$row['language'];
$dir2=$row['dir'];
?>

<?php if  ($nrrows52>0) { ?>

  <table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td width="100">&nbsp;</td>
      <td><div class="diveditor"><textarea name="text<?php echo $langid2 ?>" cols="75" rows="3" class="mceEditor"></textarea></div></td>
    </tr>
    </table>
    
<?php 
if  (isset($_POST['submit'.$_REQUEST['insert_id']])) {
$text2 = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid2"]));
$text2 = str_replace('\r\n', ' ',$text2);

$mysqli->query("INSERT INTO langvars (insert_id, lang_id, name, text) VALUES ('$insert_id', '$langid2', '$name', '$text2')");
?>
<meta http-equiv="refresh" content="0">  
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td width="100">&nbsp;</td>
      <td>
<div>
  <button type="submit" name="submit<?php echo $insert_id ?>" class="button"><span class="icon fa-check"></span> <?php echo $adminsubmit ?></button>
  <button type="reset" name="reset" class="button buttondelete"><span class="icon fa-refresh"></span> <?php echo $adminreset ?></button> 
</div>      
      </td>
    </tr>
    </table>
   
</form>