<?PHP
//........................

$table = "$prefix" . "LANG";
$return = "languages.php";

//........................

if (!empty($_GET['id'])) {

        $SQL = "SELECT * from $table WHERE ID = '$_GET[id]'"; 
        $result = mySQL_query( $SQL ); 
        $row = mySQL_fetch_array( $result );
}
$qt = update;
if (empty($_GET[id]))
        $qt = insert;

//........................

$id_field = "ID";
$id = $row[ID];
$newlang = $row[LANG];

//........................

if ($_GET['clone'] == 1) {
        function DuplicateMySQLRecord ($table, $id_field, $id, $newlang) {

                $result = mysql_query("SELECT * FROM $table WHERE $id_field = '$id'");
                $original_record = mysql_fetch_assoc($result);
            
                mysql_query("INSERT INTO $table SET LANG = '$newlang'");
                $newid = mysql_insert_id();
    
                $query = "UPDATE $table SET ";
                foreach ($original_record as $key => $value) {
                        if ($key != $id_field && $key != LANG) {
                                $query .= '`'.$key.'` = "'.str_replace('"','\"',$value).'", ';
                        }
                } 
        
                $query = substr($query,0,strlen($query)-2); # lop off the extra trailing comma
                $query .= " WHERE {$id_field}={$newid}";
                mysql_query($query);
    
                    return $newid;
                    
                }

        DuplicateMySQLRecord ($table, $id_field, $id, $newlang);

        $SQL = "SELECT * from $table ORDER BY ID DESC"; $result = @mySQL_query( $SQL ); $row = @mySQL_fetch_array( $result );
        $_GET[id] = $row[ID];
}

//........................

?> 

<form name="form" method="post" action="index.php?page=query&return=<?php echo $_GET['return']; ?>">

<input type="hidden" name="controller" value="<?php echo $table; ?>~<?php echo $qt; ?>~<?php echo $return; ?>~<?php echo $_GET['id']; ?>">

<h1><?PHP /* (LANGUAGE) */ $t = "Language Creator"; $f = "header"; include "langinc.php"; /* (LANGUAGE) */ ?></h1>

<h3><?PHP /* (LANGUAGE) */ $t = "Name of Language"; $f = "languagename"; include "langinc.php"; /* (LANGUAGE) */ ?></h3>

<input type="text" name="LANG" class="fieldbox" style="width: 100%;" value="<?php echo $row[LANG]; ?>">

<div style="float:right;"><input class="sparklybutton" type="submit" name="Save" value="<?PHP /* (LANGUAGE) */ $t = "Save"; $f = "save"; include "langinc.php"; /* (LANGUAGE) */ ?>" style="margin-top: 15px;"></div>

</form>
