コード例 #1
0
ファイル: edit_archivedtexts.php プロジェクト: hans/lwt
        }
    }
}
// DEL
if (isset($_REQUEST['del'])) {
    $message = runsql('delete from archivedtexts where AtID = ' . $_REQUEST['del'], "Archived Texts deleted");
    adjust_autoincr('archivedtexts', 'AtID');
    runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN archivedtexts on AgAtID = AtID) WHERE AtID IS NULL", '');
} elseif (isset($_REQUEST['unarch'])) {
    $message2 = runsql('insert into texts (TxLgID, TxTitle, TxText, TxAudioURI) select AtLgID, AtTitle, AtText, AtAudioURI from archivedtexts where AtID = ' . $_REQUEST['unarch'], "Texts added");
    $id = get_last_key();
    runsql('insert into texttags (TtTxID, TtT2ID) select ' . $id . ', AgT2ID from archtexttags where AgAtID = ' . $_REQUEST['unarch'], "");
    splitText(get_first_value('select TxText as value from texts where TxID = ' . $id), get_first_value('select TxLgID as value from texts where TxID = ' . $id), $id);
    $message1 = runsql('delete from archivedtexts where AtID = ' . $_REQUEST['unarch'], "Archived Texts deleted");
    $message = $message1 . " / " . $message2 . " / Sentences added: " . get_first_value('select count(*) as value from sentences where SeTxID = ' . $id) . " / Text items added: " . get_first_value('select count(*) as value from textitems where TiTxID = ' . $id);
    adjust_autoincr('archivedtexts', 'AtID');
    runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN archivedtexts on AgAtID = AtID) WHERE AtID IS NULL", '');
} elseif (isset($_REQUEST['op'])) {
    // UPDATE
    if ($_REQUEST['op'] == 'Change') {
        $message = runsql('update archivedtexts set ' . 'AtLgID = ' . $_REQUEST["AtLgID"] . ', ' . 'AtTitle = ' . convert_string_to_sqlsyntax($_REQUEST["AtTitle"]) . ', ' . 'AtText = ' . convert_string_to_sqlsyntax($_REQUEST["AtText"]) . ', ' . 'AtAudioURI = ' . convert_string_to_sqlsyntax($_REQUEST["AtAudioURI"]) . ' ' . 'where AtID = ' . $_REQUEST["AtID"], "Updated");
        $id = $_REQUEST["AtID"];
    }
    saveArchivedTextTags($id);
}
// CHG
if (isset($_REQUEST['chg'])) {
    $sql = 'select AtLgID, AtTitle, AtText, AtAudioURI from archivedtexts where AtID = ' . $_REQUEST['chg'];
    $res = mysql_query($sql);
    if ($res == FALSE) {
        die("Invalid Query: {$sql}");
コード例 #2
0
ファイル: edit_texttags.php プロジェクト: russell359/lwt
    }
}
// ALL ACTIONS
if (isset($_REQUEST['allaction'])) {
    $allaction = $_REQUEST['allaction'];
    if ($allaction == 'delall') {
        $message = runsql('delete from tags2 where (1=1) ' . $wh_query, "Deleted");
        runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL", '');
        runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL", '');
        adjust_autoincr('tags2', 'T2ID');
    }
} elseif (isset($_REQUEST['del'])) {
    $message = runsql('delete from tags2 where T2ID = ' . $_REQUEST['del'], "Deleted");
    runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL", '');
    runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL", '');
    adjust_autoincr('tags2', 'T2ID');
} elseif (isset($_REQUEST['op'])) {
    // INSERT
    if ($_REQUEST['op'] == 'Save') {
        $message = runsql('insert into tags2 (T2Text, T2Comment) values(' . convert_string_to_sqlsyntax($_REQUEST["T2Text"]) . ', ' . convert_string_to_sqlsyntax_nonull($_REQUEST["T2Comment"]) . ')', "Saved");
    } elseif ($_REQUEST['op'] == 'Change') {
        $message = runsql('update tags2 set T2Text = ' . convert_string_to_sqlsyntax($_REQUEST["T2Text"]) . ', T2Comment = ' . convert_string_to_sqlsyntax_nonull($_REQUEST["T2Comment"]) . ' where T2ID = ' . $_REQUEST["T2ID"], "Updated");
    }
}
// NEW
if (isset($_REQUEST['new'])) {
    ?>

	<h4>New Tag</h4>
	<form name="newtag" class="validate" action="<?php 
    echo $_SERVER['PHP_SELF'];
コード例 #3
0
ファイル: edit_tags.php プロジェクト: russell359/lwt
            }
        }
    }
}
// ALL ACTIONS
if (isset($_REQUEST['allaction'])) {
    $allaction = $_REQUEST['allaction'];
    if ($allaction == 'delall') {
        $message = runsql('delete from tags where (1=1) ' . $wh_query, "Deleted");
        runsql("DELETE wordtags FROM (wordtags LEFT JOIN tags on WtTgID = TgID) WHERE TgID IS NULL", '');
        adjust_autoincr('tags', 'TgID');
    }
} elseif (isset($_REQUEST['del'])) {
    $message = runsql('delete from tags where TgID = ' . $_REQUEST['del'], "Deleted");
    runsql("DELETE wordtags FROM (wordtags LEFT JOIN tags on WtTgID = TgID) WHERE TgID IS NULL", '');
    adjust_autoincr('tags', 'TgID');
} elseif (isset($_REQUEST['op'])) {
    // INSERT
    if ($_REQUEST['op'] == 'Save') {
        $message = runsql('insert into tags (TgText, TgComment) values(' . convert_string_to_sqlsyntax($_REQUEST["TgText"]) . ', ' . convert_string_to_sqlsyntax_nonull($_REQUEST["TgComment"]) . ')', "Saved");
    } elseif ($_REQUEST['op'] == 'Change') {
        $message = runsql('update tags set TgText = ' . convert_string_to_sqlsyntax($_REQUEST["TgText"]) . ', TgComment = ' . convert_string_to_sqlsyntax_nonull($_REQUEST["TgComment"]) . ' where TgID = ' . $_REQUEST["TgID"], "Updated");
    }
}
// NEW
if (isset($_REQUEST['new'])) {
    ?>

	<h4>New Tag</h4>
	<form name="newtag" class="validate" action="<?php 
    echo $_SERVER['PHP_SELF'];
コード例 #4
0
ファイル: delete_word.php プロジェクト: Fips11/lwt
For more information, please refer to [http://unlicense.org/].
***************************************************************/
/**************************************************************
Call: delete_word.php?wid=[wordid]&tid=[textid]
Delete a word
***************************************************************/
require_once 'settings.inc.php';
require_once 'connect.inc.php';
require_once 'dbutils.inc.php';
require_once 'utilities.inc.php';
$tid = $_REQUEST['tid'];
$wid = $_REQUEST['wid'];
$term = get_first_value("select WoText as value from " . $tbpref . "words where WoID = " . $wid);
pagestart("Term: " . $term, false);
$m1 = runsql('delete from ' . $tbpref . 'words where WoID = ' . $wid, '');
adjust_autoincr('words', 'WoID');
echo "<p>OK, term deleted, now unknown (" . $m1 . ").</p>";
?>
<script type="text/javascript">
//<![CDATA[
var context = window.parent.frames['l'].document;
var contexth = window.parent.frames['h'].document;
var title = make_tooltip(<?php 
echo prepare_textdata_js($term);
?>
,'','','');
$('.word<?php 
echo $wid;
?>
', context).removeClass('status99 status98 status1 status2 status3 status4 status5 word<?php 
echo $wid;
コード例 #5
0
ファイル: edit_texts.php プロジェクト: nahabi4/lwt
            exit;
        } elseif (substr($_REQUEST['op'], 0, 4) == 'Save') {
            $message1 = runsql('insert into ' . $tbpref . 'texts (TxLgID, TxTitle, TxText, TxAnnotatedText, TxAudioURI, TxSourceURI) values( ' . $_REQUEST["TxLgID"] . ', ' . convert_string_to_sqlsyntax($_REQUEST["TxTitle"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["TxText"]) . ", '', " . convert_string_to_sqlsyntax($_REQUEST["TxAudioURI"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["TxSourceURI"]) . ')', "Saved");
            $id = get_last_key();
            saveTextTags($id);
        } elseif (substr($_REQUEST['op'], 0, 6) == 'Change') {
            $oldtext = get_first_value('select TxText as value from ' . $tbpref . 'texts where TxID = ' . $_REQUEST["TxID"]);
            $textsdiffer = convert_string_to_sqlsyntax($_REQUEST["TxText"]) != convert_string_to_sqlsyntax($oldtext);
            $message1 = runsql('update ' . $tbpref . 'texts set ' . 'TxLgID = ' . $_REQUEST["TxLgID"] . ', ' . 'TxTitle = ' . convert_string_to_sqlsyntax($_REQUEST["TxTitle"]) . ', ' . 'TxText = ' . convert_string_to_sqlsyntax($_REQUEST["TxText"]) . ', ' . 'TxAudioURI = ' . convert_string_to_sqlsyntax($_REQUEST["TxAudioURI"]) . ', ' . 'TxSourceURI = ' . convert_string_to_sqlsyntax($_REQUEST["TxSourceURI"]) . ' ' . 'where TxID = ' . $_REQUEST["TxID"], "Updated");
            $id = $_REQUEST["TxID"];
            saveTextTags($id);
        }
        $message2 = runsql('delete from ' . $tbpref . 'sentences where SeTxID = ' . $id, "Sentences deleted");
        $message3 = runsql('delete from ' . $tbpref . 'textitems where TiTxID = ' . $id, "Textitems deleted");
        adjust_autoincr('sentences', 'SeID');
        adjust_autoincr('textitems', 'TiID');
        splitCheckText(get_first_value('select TxText as value from ' . $tbpref . 'texts where TxID = ' . $id), $_REQUEST["TxLgID"], $id);
        $message = $message1 . " / " . $message2 . " / " . $message3 . " / Sentences added: " . get_first_value('select count(*) as value from ' . $tbpref . 'sentences where SeTxID = ' . $id) . " / Text items added: " . get_first_value('select count(*) as value from ' . $tbpref . 'textitems where TiTxID = ' . $id);
        if (substr($_REQUEST['op'], -8) == "and Open") {
            header('Location: do_text.php?start=' . $id);
            exit;
        }
    }
}
if (isset($_REQUEST['new'])) {
    // NEW
    ?>

	<h4>New Text <a target="_blank" href="info.htm#howtotext"><img src="icn/question-frame.png" title="Help" alt="Help" /></a> </h4>
	<script type="text/javascript" src="js/unloadformcheck.js" charset="utf-8"></script>	
	<form class="validate" action="<?php 
コード例 #6
0
function reparse_all_texts()
{
    global $tbpref;
    runsql('TRUNCATE ' . $tbpref . 'sentences', '');
    runsql('TRUNCATE ' . $tbpref . 'textitems', '');
    adjust_autoincr('sentences', 'SeID');
    adjust_autoincr('textitems', 'TiID');
    $sql = "select TxID, TxLgID from " . $tbpref . "texts";
    $res = do_mysql_query($sql);
    while ($record = mysql_fetch_assoc($res)) {
        $id = $record['TxID'];
        splitCheckText(get_first_value('select TxText as value from ' . $tbpref . 'texts where TxID = ' . $id), $record['TxLgID'], $id);
    }
    mysql_free_result($res);
}
コード例 #7
0
ファイル: edit_languages.php プロジェクト: hans/lwt
        $txttxt = $record["TxText"];
        splitText($txttxt, $id, $txtid);
    }
    mysql_free_result($res);
    $message = $message2 . " / " . $message3 . " / Sentences added: " . get_first_value('select count(*) as value from sentences where SeLgID = ' . $id) . " / Text items added: " . get_first_value('select count(*) as value from textitems where TiLgID = ' . $id);
}
// DEL
if (isset($_REQUEST['del'])) {
    $anztexts = get_first_value('select count(TxID) as value from texts where TxLgID = ' . $_REQUEST['del']);
    $anzarchtexts = get_first_value('select count(AtID) as value from archivedtexts where AtLgID = ' . $_REQUEST['del']);
    $anzwords = get_first_value('select count(WoID) as value from words where WoLgID = ' . $_REQUEST['del']);
    if ($anztexts > 0 || $anzarchtexts > 0 || $anzwords > 0) {
        $message = 'You must first delete texts, archived texts and words with this language!';
    } else {
        $message = runsql('delete from languages where LgID = ' . $_REQUEST['del'], "Deleted");
        adjust_autoincr('languages', 'LgID');
    }
} elseif (isset($_REQUEST['op'])) {
    // INSERT
    if ($_REQUEST['op'] == 'Save') {
        $message = runsql('insert into languages (LgName, LgDict1URI, LgDict2URI, LgGoogleTranslateURI, LgTextSize, LgCharacterSubstitutions, LgRegexpSplitSentences, LgExceptionsSplitSentences, LgRegexpWordCharacters, LgRemoveSpaces, LgSplitEachChar, LgRightToLeft) values(' . convert_string_to_sqlsyntax($_REQUEST["LgName"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["LgDict1URI"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["LgDict2URI"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["LgGoogleTranslateURI"]) . ', ' . $_REQUEST["LgTextSize"] . ', ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgCharacterSubstitutions"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpSplitSentences"]) . ', ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgExceptionsSplitSentences"]) . ', ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpWordCharacters"]) . ', ' . $_REQUEST["LgRemoveSpaces"] . ', ' . $_REQUEST["LgSplitEachChar"] . ', ' . $_REQUEST["LgRightToLeft"] . ')', 'Saved');
    } elseif ($_REQUEST['op'] == 'Change') {
        $message = runsql('update languages set ' . 'LgName = ' . convert_string_to_sqlsyntax($_REQUEST["LgName"]) . ', ' . 'LgDict1URI = ' . convert_string_to_sqlsyntax($_REQUEST["LgDict1URI"]) . ', ' . 'LgDict2URI = ' . convert_string_to_sqlsyntax($_REQUEST["LgDict2URI"]) . ', ' . 'LgGoogleTranslateURI = ' . convert_string_to_sqlsyntax($_REQUEST["LgGoogleTranslateURI"]) . ', ' . 'LgTextSize = ' . $_REQUEST["LgTextSize"] . ', ' . 'LgCharacterSubstitutions = ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgCharacterSubstitutions"]) . ', ' . 'LgRegexpSplitSentences = ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpSplitSentences"]) . ', ' . 'LgExceptionsSplitSentences = ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgExceptionsSplitSentences"]) . ', ' . 'LgRegexpWordCharacters = ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpWordCharacters"]) . ', ' . 'LgRemoveSpaces = ' . $_REQUEST["LgRemoveSpaces"] . ', ' . 'LgSplitEachChar = ' . $_REQUEST["LgSplitEachChar"] . ', ' . 'LgRightToLeft = ' . $_REQUEST["LgRightToLeft"] . ' where LgID = ' . $_REQUEST["LgID"], 'Updated');
    }
}
// NEW
if (isset($_REQUEST['new'])) {
    ?>

	<h4>New Language <a target="_blank" href="info.htm#howtolang"><img src="icn/question-frame.png" title="Help" alt="Help" /></a> </h4>
	<form class="validate" action="<?php 
コード例 #8
0
ファイル: utilities.inc.php プロジェクト: russell359/lwt
function check_update_db()
{
    global $debug;
    $tables = array();
    $res = mysql_query("SHOW TABLES");
    if ($res == FALSE) {
        die("SHOW TABLES error");
    }
    while ($row = mysql_fetch_row($res)) {
        $tables[] = $row[0];
    }
    mysql_free_result($res);
    $count = 0;
    // counter for cache rebuild
    // Rebuild Tables if missing
    if (in_array('archivedtexts', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding archivedtexts</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS archivedtexts ( AtID int(11) unsigned NOT NULL AUTO_INCREMENT, AtLgID int(11) unsigned NOT NULL, AtTitle varchar(200) NOT NULL, AtText text NOT NULL, AtAudioURI varchar(200) DEFAULT NULL, PRIMARY KEY (AtID), KEY AtLgID (AtLgID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('languages', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding languages</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS languages ( LgID int(11) unsigned NOT NULL AUTO_INCREMENT, LgName varchar(40) NOT NULL, LgDict1URI varchar(200) NOT NULL, LgDict2URI varchar(200) DEFAULT NULL, LgGoogleTranslateURI varchar(200) DEFAULT NULL, LgGoogleTTSURI varchar(200) DEFAULT NULL, LgTextSize int(5) unsigned NOT NULL DEFAULT '100', LgCharacterSubstitutions varchar(500) NOT NULL, LgRegexpSplitSentences varchar(500) NOT NULL, LgExceptionsSplitSentences varchar(500) NOT NULL, LgRegexpWordCharacters varchar(500) NOT NULL, LgRemoveSpaces int(1) unsigned NOT NULL DEFAULT '0', LgSplitEachChar int(1) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (LgID), UNIQUE KEY LgName (LgName) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('sentences', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding sentences</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS sentences ( SeID int(11) unsigned NOT NULL AUTO_INCREMENT, SeLgID int(11) unsigned NOT NULL, SeTxID int(11) unsigned NOT NULL, SeOrder int(11) unsigned NOT NULL, SeText text, PRIMARY KEY (SeID), KEY SeLgID (SeLgID), KEY SeTxID (SeTxID), KEY SeOrder (SeOrder) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
        $count++;
    }
    if (in_array('settings', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding settings</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS settings ( StKey varchar(40) NOT NULL, StValue varchar(40) DEFAULT NULL, PRIMARY KEY (StKey) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('textitems', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding textitems</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS textitems ( TiID int(11) unsigned NOT NULL AUTO_INCREMENT, TiLgID int(11) unsigned NOT NULL, TiTxID int(11) unsigned NOT NULL, TiSeID int(11) unsigned NOT NULL, TiOrder int(11) unsigned NOT NULL, TiWordCount int(1) unsigned NOT NULL, TiText varchar(250) NOT NULL, TiTextLC varchar(250) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, TiIsNotWord tinyint(1) NOT NULL, PRIMARY KEY (TiID), KEY TiLgID (TiLgID), KEY TiTxID (TiTxID), KEY TiSeID (TiSeID), KEY TiOrder (TiOrder), KEY TiTextLC (TiTextLC), KEY TiIsNotWord (TiIsNotWord) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
        $count++;
    }
    if (in_array('texts', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding texts</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS texts ( TxID int(11) unsigned NOT NULL AUTO_INCREMENT, TxLgID int(11) unsigned NOT NULL, TxTitle varchar(200) NOT NULL, TxText text NOT NULL, TxAudioURI varchar(200) DEFAULT NULL, PRIMARY KEY (TxID), KEY TxLgID (TxLgID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('words', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding words</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS words ( WoID int(11) unsigned NOT NULL AUTO_INCREMENT, WoLgID int(11) unsigned NOT NULL, WoText varchar(250) NOT NULL, WoTextLC varchar(250) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, WoStatus tinyint(4) NOT NULL, WoTranslation varchar(500) NOT NULL DEFAULT '*', WoRomanization varchar(100) DEFAULT NULL, WoSentence varchar(1000) DEFAULT NULL, WoCreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, WoStatusChanged timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (WoID), UNIQUE KEY WoLgIDTextLC (WoLgID,WoTextLC), KEY WoLgID (WoLgID), KEY WoStatus (WoStatus), KEY WoTextLC (WoTextLC), KEY WoTranslation (WoTranslation(333)), KEY WoCreated (WoCreated), KEY WoStatusChanged (WoStatusChanged) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('tags', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding tags</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS tags ( TgID int(11) unsigned NOT NULL AUTO_INCREMENT, TgText varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, TgComment varchar(200) NOT NULL, PRIMARY KEY (TgID), UNIQUE KEY TgText (TgText) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('wordtags', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding wordtags</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS wordtags ( WtWoID int(11) unsigned NOT NULL, WtTgID int(11) unsigned NOT NULL, PRIMARY KEY (WtWoID,WtTgID), KEY WtTgID (WtTgID), KEY WtWoID (WtWoID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('tags2', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding tags2</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS tags2 ( T2ID int(11) unsigned NOT NULL AUTO_INCREMENT, T2Text varchar(20) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, T2Comment varchar(200) NOT NULL, PRIMARY KEY (T2ID), UNIQUE KEY T2Text (T2Text) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('texttags', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding texttags</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS texttags ( TtTxID int(11) unsigned NOT NULL, TtT2ID int(11) unsigned NOT NULL, PRIMARY KEY (TtTxID,TtT2ID), KEY TtTxID (TtTxID), KEY TtT2ID (TtT2ID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if (in_array('archtexttags', $tables) == FALSE) {
        if ($debug) {
            echo '<p>DEBUG: rebuilding archtexttags</p>';
        }
        runsql("CREATE TABLE IF NOT EXISTS archtexttags ( AgAtID int(11) unsigned NOT NULL, AgT2ID int(11) unsigned NOT NULL, PRIMARY KEY (AgAtID,AgT2ID), KEY AgAtID (AgAtID), KEY AgT2ID (AgT2ID) ) ENGINE=MyISAM DEFAULT CHARSET=utf8", '');
    }
    if ($count > 0) {
        // Rebuild Text Cache if cache tables new
        if ($debug) {
            echo '<p>DEBUG: rebuilding cache tables</p>';
        }
        $sql = "select TxID, TxLgID from texts";
        $res = mysql_query($sql);
        if ($res == FALSE) {
            die("Invalid Query: {$sql}");
        }
        while ($record = mysql_fetch_assoc($res)) {
            $id = $record['TxID'];
            runsql('delete from sentences where SeTxID = ' . $id, "");
            runsql('delete from textitems where TiTxID = ' . $id, "");
            adjust_autoincr('sentences', 'SeID');
            adjust_autoincr('textitems', 'TiID');
            splitText(get_first_value('select TxText as value from texts where TxID = ' . $id), $record['TxLgID'], $id);
        }
        mysql_free_result($res);
    }
    // Version
    $res = mysql_query("select StValue as value from settings where StKey = 'dbversion'");
    if (mysql_errno() != 0) {
        die('There is something wrong with your database ' . $dbname . '. Please reinstall.');
    }
    $record = mysql_fetch_assoc($res);
    if ($record) {
        $dbversion = $record["value"];
    } else {
        $dbversion = 'v001000000';
        saveSetting('dbversion', $dbversion);
        if ($debug) {
            echo '<p>DEBUG: DB version not found, set to: ' . $dbversion . '</p>';
        }
    }
    mysql_free_result($res);
    // Do DB Updates
    $currversion = get_version_number();
    if ($currversion > $dbversion) {
        if ($currversion > 'v001000000') {
            // updates for all versions > 1.0.0
            if ($debug) {
                echo '<p>DEBUG: Doing db-upgrade ' . $currversion . ' &gt; v001000000</p>';
            }
            runsql("ALTER TABLE words ADD WoTodayScore DOUBLE NOT NULL DEFAULT 0, ADD WoTomorrowScore DOUBLE NOT NULL DEFAULT 0, ADD WoRandom DOUBLE NOT NULL DEFAULT 0", '');
            runsql("ALTER TABLE words ADD INDEX WoTodayScore (WoTodayScore), ADD INDEX WoTomorrowScore (WoTomorrowScore), ADD INDEX WoRandom (WoRandom)", '');
            runsql("UPDATE words SET " . make_score_random_insert_update('u'), '');
        }
        if ($currversion > 'v001001001') {
            if ($debug) {
                echo '<p>DEBUG: Doing db-upgrade ' . $currversion . ' &gt; v001001001</p>';
            }
            // updates for all versions > 1.1.1 :
            // New: Table "tags", created above
            // New: Table "wordtags", created above
        }
        if ($currversion > 'v001002002') {
            if ($debug) {
                echo '<p>DEBUG: Doing db-upgrade ' . $currversion . ' &gt; v001002002</p>';
            }
            // updates for all versions > 1.2.2 :
            // New: Table "tags2", created above
            // New: Table "texttags", created above
            // New: Table "archtexttags", created above
            runsql("ALTER TABLE languages ADD LgRightToLeft INT(1) UNSIGNED NOT NULL DEFAULT  0", '');
        }
        // set to current.
        saveSetting('dbversion', $currversion);
    }
    // Do Scoring once per day, clean Word/Texttags, and optimize db
    $lastscorecalc = getSetting('lastscorecalc');
    $today = date('Y-m-d');
    if ($lastscorecalc != $today) {
        if ($debug) {
            echo '<p>DEBUG: Doing score recalc. Today: ' . $today . ' / Last: ' . $lastscorecalc . '</p>';
        }
        runsql("UPDATE words SET " . make_score_random_insert_update('u'), '');
        runsql("DELETE wordtags FROM (wordtags LEFT JOIN tags on WtTgID = TgID) WHERE TgID IS NULL", '');
        runsql("DELETE wordtags FROM (wordtags LEFT JOIN words on WtWoID = WoID) WHERE WoID IS NULL", '');
        runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL", '');
        runsql("DELETE texttags FROM (texttags LEFT JOIN texts on TtTxID = TxID) WHERE TxID IS NULL", '');
        runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL", '');
        runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN archivedtexts on AgAtID = AtID) WHERE AtID IS NULL", '');
        optimizedb();
        saveSetting('lastscorecalc', $today);
    }
}