words.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:15k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: words.php,v $
- // | $Date: 2004/02/12 21:16:57 $
- // | $Revision: 1.40 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Per-language phrase replacement maintenance (administration
- // | interface)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- include "./../includes/functions/devmode_functions.php";
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view";
- }
- // globalise variables
- $global = array (
- array('category'),
- array('id'),
- array('language')
- );
- rg($global);
- ############################### SELECT LANGUAGE ###############################
- if ($settings[language_on] AND ($_REQUEST['do'] != 'search_wordref')) {
- if (!$language) {
- $language = $settings['default_language'];
- }
- $db->query("SELECT * FROM languages");
- while ($lang = $db->row_array()) {
- if ($lang['id'] == $language) {
- $this_language = $lang;
- }
- $languages[$lang[id]] = "$lang[name]";
- }
- admin_header('Languages', 'Translate Words',
- array('dir' => $this_language['direction'], 'lang' => $this_language['isocode'], 'charset' => $this_language['contenttype'])
- );
- $table[] = array(
- "<b>Currently viewing $languages[$language] templates:</b>",
- form_select('language', $languages, NULL, $language, NULL, NULL, NULL, NULL, 1) . '<input type="submit" name="submit" value="Change">'
- );
- table_header("View Language", 'words.php');
- table_content('', $table);
- table_footer();
- echo "</form>";
- unset($table);
- }
- ############################### UPDATE WORDS ###############################
- if ($_REQUEST['do'] == "update") {
- $db->query("SELECT DISTINCT name FROM template_words_cat");
- while ($cat = $db->row_array()) {
- $cats[] = $cat['name'];
- }
- $db->query("SELECT DISTINCT id, name FROM template_words_cat WHERE name IN " . array2sql($cats) . " GROUP BY name");
- while ($cats = $db->row_array()) {
- $catnames[$cats['name']] = $cats['id'];
- }
- $db->query("SELECT wordref, category FROM template_words WHERE language = '$settings[default_language]' AND !cust");
- while ($cats = $db->row_array()) {
- $wordref_cats[$cats['wordref']] = $cats['category'];
- }
-
- $db->query("DELETE FROM template_words WHERE cust");
- $words = $db->query("SELECT wordref, category, text FROM template_words WHERE language = '$language' AND !cust");
- while ($res = $db->row_array()) {
- $wordrefs[$res['wordref']] = $res['text'];
- }
- foreach ($_REQUEST['words'] AS $key => $var) {
-
- if ($var != '') {
- // if the word has changed lets create / update the custom
- if ($var != $wordrefs[$key]) {
- $db->query("
- INSERT template_words SET
- text = '" . addslashes($var) . "',
- wordref = '" . addslashes($key) . "',
- category = '" . $wordref_cats[$key] . "',
- language = '" . addslashes($language) . "',
- cust = 1
- ");
- }
- // word does not exist, so lets create it, and backup for it
- if (!in_array_keys($key, $wordrefs)) {
- $db->query("
- INSERT template_words SET
- text = '" . addslashes($var) . "',
- wordref = '" . addslashes($key) . "',
- category = '" . $wordref_cats[$key] . "',
- language = '" . addslashes($language) . "'
- ");
- }
- }
- }
- alert('Words Updated');
- $_REQUEST['do'] = "view";
- }
- ############################### VIEW WORDS ###############################
- if ($_REQUEST['do'] == "view") {
- admin_header('Languages', 'Translate Words',
- array('dir' => $this_language['direction'], 'lang' => $this_language['isocode'], 'charset' => $this_language['contenttype'])
- );
- /////////////// SELECT LANGUAGE ///////////////
- // set language to 1 if not using languages
- if ($settings[language_on] != 1) {
- $language = $settings[default_language];
- }
- $db->query("
- SELECT template_words.*, template_words_cat.name AS catname
- FROM template_words
- LEFT JOIN template_words_cat ON (template_words_cat.id = template_words.category)
- WHERE language = '$settings[default_language]' AND !cust
- ORDER BY category, displayorder
- ");
- while ($result = $db->row_array()) {
- $default[$result[wordref]] = array('text' => $result[text], 'catname' => $result[catname]);
- }
- $db->query("SELECT wordref, text FROM template_words WHERE language = '$language'");
- while ($result = $db->row_array()) {
- $showlanguage[$result['wordref']] = $result[text];
- }
- $y = 1;
- echo "<form method="post" action="words.php">" . form_hidden('language', $language, NULL, 1);
- if (is_array($default)) {
- foreach ($default AS $var => $key) {
- if ($key['catname'] != $lastname) {
- $table[] = table_midheader($key['catname']);
- }
-
- if (strlen($showlanguage[$var]) > 50 OR strlen($var) > 50) {
- $table[] = array(
- "<b>$var</b>",
- "<textarea DISABLED cols="75" rows="6">$key[text]</textarea><br />" .
- form_textarea($var, 75, 6, $showlanguage[$var], 'words', 1)
- );
- } else {
- $table[] = array(
- "<b>$var</b>",
- "<input DISABLED value="$key[text]" size="75"><br />" .
- form_input($var, $showlanguage[$var], 75, 'words', 1)
- );
- }
- $lastname = $key['catname'];
- }
- }
- table_header('The following are the phrases used by DeskPRO', 'words.php', array('do' => 'update'));
- table_content('', $table);
- table_footer('Update Words');
- }
- admin_footer();
- ##############################################################
- # DEVELOPER STUFF
- ##############################################################
- ##############################################################
- ################## EXPORT/IMPORT TO/FROM FILES ##########################
- if ($_REQUEST['do'] == 'dev_export') {
- developer_check();
- admin_header('Languages', 'Export To Files');
- $languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
- echo "<FORM METHOD="POST" ACTION="words.php">";
- echo form_hidden('do', 'dev_export_do');
- $rows[] = array('<B>Languages to Export</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
- table_header("Select Languages to Export to /admin/templates/words/*");
- table_content(NULL, $rows);
- table_footer('Export Languages');
- exit;
- }
- if ($_REQUEST['do'] == 'dev_import') {
- developer_check();
- admin_header('Languages', 'Import From Files');
- $languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
- echo "<FORM METHOD="POST" ACTION="words.php">";
- echo form_hidden('do', 'dev_import_do');
- $rows[] = array('<B>Languages to Import</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
- $rows[] = array('<B>Dry Run?</B><BR>If selected, don't actually update the database, just show what would be done.',
- form_radio_yn('dryrun', 0));
- $rows[] = array('<B>Purge Existing?</B><BR>If selected, <FONT COLOR="red"><B>all existing words in all selected languages will be deleted</B></FONT>
- and replaced by the import files (testing with a dry run is highly recommended before doing this)',
- form_radio_yn('replace_all', 0));
- $rows[] = array('<B>Confirm Purge Existing</B><BR>Confirm that you want to purge all existing words from all selected languages.',
- form_radio_yn('replace_all_confirm', 0));
- table_header("Select Languages to Import to /admin/templates/words/*");
- table_content(NULL, $rows, NULL, NULL, NULL, NULL, array('60%', '40%'));
- table_footer('Import Languages');
- exit;
- }
- if ($_REQUEST['do'] == 'dev_export_do') {
- developer_check();
- admin_header('Languages', 'Export To Files');
- if (ini_set('track_errors', 1) === FALSE) {
- $errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
- $php_errormsg = 'Unknown error.';
- }
-
- $location = dirname(__FILE__) . '/templates/words';
- dev_words_export($location);
- admin_footer();
- exit;
- }
- if ($_REQUEST['do'] == 'dev_import_do') {
- developer_check();
-
- admin_header('Languages', 'Import From Files');
- if (ini_set('track_errors', 1) === FALSE) {
- $errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
- $php_errormsg = 'Unknown error.';
- }
- $location = dirname(__FILE__) . '/templates/words';
- dev_words_import($location);
- exit;
- }
- // Search for unused wordrefs
- if ($_REQUEST['do'] == "search_wordref") {
- developer_check();
- admin_header('Languages', 'Find Unused Words');
- if (is_win()) {
- echo "<B>Error:</B> This function is not currently supported on Windows platforms.";
- admin_footer();
- exit;
- }
- $words = $db->query_return_array("SELECT DISTINCT wordref FROM template_words");
- if (is_array($words)) {
- foreach ($words AS $word) {
- $db->query("SELECT id FROM template WHERE template LIKE '%$dplang[%$word[wordref]%]%'");
- if ($db->num_rows()) {
- continue;
- }
- exec('grep -ri "dplang['*' . $word['wordref'] . ''*]" ../*', $messages, $return);
- if (count($messages)) {
- continue;
- }
- unset($messages);
- // jump('*', 'foo');
- exec('grep -ri "jump(.*' . $word['wordref'] . '.*)" ../*', $messages, $return);
- if (count($messages)) {
- continue;
- }
- unset($messages);
- $disused[] = $word['wordref'];
- }
- }
- print "<P><B>Unused Words:</B><BR>";
- if (is_array($disused)) {
- if (count($disused)) {
- foreach($disused AS $word) {
- print "$word<BR>n";
- }
- } else {
- print "None";
- }
- } else {
- print "None";
- }
- print "</P>";
- exit;
- }
- ############################### UPDATE WORDS (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "updatewords") {
- developer_check();
- $db->query("DELETE FROM template_words WHERE language = 0");
- foreach ($_REQUEST['wordname'] AS $key => $var) {
- if ($var != '' AND (!@in_array($var, $array))) {
- $array[] = $var;
- $db->query("INSERT INTO template_words SET
- text = '" . mysql_escape_string($_REQUEST['text'][$key]) . "',
- wordref = '" . mysql_escape_string($var) . "',
- category = '" . $_REQUEST['category'][$key] . "'
- ");
- }
- }
- $_REQUEST['do'] = 'admin_edit';
- }
- ############################### REBUILD ENGLISH DEFAULTS (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "default_langs") {
- developer_check();
- new_db_class(2);
- $entries = $db->query_return_array("SELECT * FROM template_words WHERE cust");
- if ($db->num_rows()) {
- foreach ($entries AS $entry) {
- $db->query("UPDATE template_words SET
- language = '$entry[language]',
- wordref = '" . mysql_escape_string($entry[wordref]) . "',
- text = '" . mysql_escape_string($entry[text]) . "',
- category = '$entry[category]',
- cust = 0
- ");
- }
- $db->query("DELETE FROM languages WHERE cust");
- }
- }
- ############################### VIEW WORDS (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "admin_edit") {
- developer_check();
- $db->query("SELECT * FROM template_words_cat");
- while ($result = $db->row_array()) {
- $cat[$result[id]] = $result[name];
- }
- $db->query("SELECT template_words.*, template_words_cat.name AS catname FROM template_words
- LEFT JOIN template_words_cat ON (template_words_cat.id = template_words.category)
- WHERE language = 0
- ORDER BY category, wordref
- ");
-
- unset($lastname);
- while ($result = $db->row_array()) {
- if ($result[catname] != $lastname) {
- $table[] = table_midheader($result[catname]);
- }
- $i++;
- $table[] = array(
- form_input($i, $result[wordref], 30, 'wordname', 1),
- form_select($i, $cat, 'category', $result[category], NULL, NULL, NULL, NULL, 1),
- form_input($i, $result[text], 125, 'text', 1)
- );
- $lastname = $result[catname];
- }
- $table[] = table_midheader('Blank');
- while ($y < 10) {
- $i++;
- $table[] = array(
- form_input($i, $result[wordref], 30, 'wordname', 1),
- form_select($i, $cat, 'category', $result[category], NULL, NULL, NULL, NULL, 1),
- form_input($i, $result[text], 125, 'text', 1)
- );
- $y++;
- }
- table_header('Default Words', 'words.php', array('do' => 'updatewords'));
- table_content('', $table);
- table_footer('Updatewords');
- ?>
- <br /><hr>
- <a href="words.php?do=viewcats">View Categories</a><br />
- <a href="words.php?do=view">View Words</a><br />
- <a href="words.php?do=default_langs">Rebuild language defaults</a><br />
- <form method="post" action="words.php"><input type="hidden" name="do" value="newcat">
- New Category <input type="text" name="name"><input type="submit" name="submit" value="submit">
- </form>
- <?php
- }
- ############################### NEW CATEGORY (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "newcat") {
- developer_check();
- $db->query("INSERT INTO template_words_cat SET name = '" . mysql_escape_string($_REQUEST['name']) . "'");
- $_REQUEST['do'] = "admin_cats";
- }
- ############################### UPDATE CATEGORIES (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "catupdate") {
- developer_check();
- foreach ($_REQUEST['name'] AS $key => $var) {
- $db->query("UPDATE template_words_cat SET
- name = '" . mysql_escape_string($_REQUEST['newname'][$key]) . "',
- displayorder = '" . mysql_escape_string($_REQUEST['displayorder'][$key]) . "'
- WHERE name = '$key'
- ");
- }
- $_REQUEST['do'] = "admin_cats";
- }
- ############################### VIEW CATEGORIES (DEVELOPER ONLY) ###############################
- if ($_REQUEST['do'] == "admin_cats") {
- developer_check();
- $db->query("SELECT * FROM template_words_cat ORDER BY displayorder");
- while ($result = $db->row_array()) {
- $table[] = array(form_input($result[name], $result[displayorder], 3, 'displayorder', 1),
- form_hidden($result[name], $result[name], 'name', 1),
- form_input($result[name], $result[name], 30, 'newname', 1));
- }
- table_header('Categories', 'words.php', array('do' => 'catupdate'));
- table_content('', $table);
- table_footer('Submit');
- ?>
- <br /><hr>
- <a href="words.php?do=viewcats">View Categories</a><br />
- <a href="words.php?do=view">View Words</a><br />
- <a href="words.php?do=default_langs">Rebuild language defaults</a><br />
- <form method="post" action="words.php"><input type="hidden" name="do" value="newcat">
- New Category <input type="text" name="name"><input type="submit" name="submit" value="submit">
- </form>
- <?php
- }
- ?>