remove old readme
[atutor.git] / mods / _core / languages / language_editor.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2009                                                                              */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 /**
16  * BEWARE OF THE HACKS USED TO IMPLEMENT THIS FEATURE:
17  *
18  * this page is to allow admins to edit/customize their language
19  * and save the changes made in a way that allows the upgrading of
20  * ATutor without the loss of that language. It also allows customized
21  * language to be reverted back to its original form.
22  *
23  * since we couldn't change the database as it would break backwards
24  * compatability, none of the fields could be changed which means
25  * that the only way to store the extra language would be by reusing
26  * the `variable` field, which is part of the PK.
27  *
28  * reusing the `variable` is a huge hack and doesn't correctly support
29  * module language as there is nothing enfocing storing module language
30  * in an independant way. ideally there would be another field in the
31  * database designating custom or not and the `variable` field would
32  * be removed completely since it doesn't have much effect any more.
33  *
34  * custom language is stored as `_c_template` and `_c_msgs` for template
35  * and feedback messages, respectively. Why use "_c" as the prefix?
36  * because it comes before "_t" and _m" in the alphabet. This lets us
37  * sort the language by `variable` and limit it to one result. That is 
38  * how the custom language terms are retrieved in place of default
39  * language.
40  *
41  * another oddity is that although custom language text isn't deleted
42  * upon upgrades, the language definitions are, which means those terms
43  * cannot be edited until after the language pack is reinstalled.
44  * this also means that if a term has changed the system might be unaware
45  * of new replacement tokens and could break.
46  *
47  */
48
49 define('AT_INCLUDE_PATH', '../../../include/');
50 require(AT_INCLUDE_PATH.'vitals.inc.php');
51 admin_authenticate(AT_ADMIN_PRIV_LANGUAGES);
52
53 if (defined('AT_DEVEL_TRANSLATE') && AT_DEVEL_TRANSLATE) {
54         $msg->addWarning('TRANSLATE_ON');
55         require(AT_INCLUDE_PATH.'header.inc.php');
56         require(AT_INCLUDE_PATH.'footer.inc.php');
57         exit;
58 }
59
60 require(AT_INCLUDE_PATH.'header.inc.php');
61
62 $_variables = array('template' => '_template', 'feedback' => '_msgs');
63 $_c_variables = array('template' => '_c_template', 'feedback' => '_c_msgs');
64
65 $sql_search = '';
66 if (isset($_GET['filter'], $_GET['search'])) {
67         $_GET['search'] = trim($addslashes($_GET['search']));
68         $words = explode(' ', $_GET['search']);
69         foreach ($words as $key => $word) {
70                 // search `term` and `text` only
71                 if ($strlen($word) > 1) {
72                         $word = str_replace(array('%','_'), array('\%', '\_'), $word);
73                         $words[$key] = "(CAST(`term` AS CHAR) LIKE '%$word%' OR CAST(`text` AS CHAR) LIKE '%$word%')";
74                 } else {
75                         unset($words[$key]);
76                 }
77         }
78         if ($words) {
79                 $sql_search = ' AND (' . implode(' OR ', $words).')';
80         }
81 } else if ($_GET['reset_filter']) {
82         unset($_GET);
83 }
84 if (!isset($_GET['type']) || !isset($_variables[$_GET['type']])) {
85         $_GET['type'] = 'template';
86 }
87
88 if (isset($_GET['custom'])) {
89         $variable = $_c_variables[$_GET['type']];
90 } else {
91         $variable = $_variables[$_GET['type']];
92 }
93
94 $sql = "SELECT * FROM ".TABLE_PREFIX."language_text WHERE language_code='$_SESSION[lang]' AND `variable`='$variable' $sql_search ORDER BY text";
95 $result = mysql_query($sql, $db);
96 $num_results = mysql_num_rows($result);
97 ?>
98
99 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
100         <div class="input-form">
101                 <div class="row">
102                         <h3><?php echo _AT('results_found', $num_results); ?></h3>
103                 </div>
104
105                 <div class="row">
106                         <?php echo _AT('type'); ?><br />
107                         <input type="radio" name="type" value="template" id="tyte" <?php if ($_GET['type'] == 'template') { echo 'checked="checked"'; } ?> /><label for="tyte"><?php echo _AT('template'); ?></label>
108                         <input type="radio" name="type" value="feedback" id="tyfe" <?php if ($_GET['type'] == 'feedback') { echo 'checked="checked"'; } ?> /><label for="tyfe"><?php echo _AT('feedback'); ?></label>
109                 </div>
110
111                 <div class="row">
112                         <input type="checkbox" name="custom" value="1" id="cus" <?php if (isset($_GET['custom'])) { echo 'checked="checked"'; } ?> /><label for="cus"><?php echo _AT('only_show_edited_terms'); ?></label>
113                 </div>
114
115                 <div class="row">
116                         <label for="search"><?php echo _AT('search'); ?></label><br />
117                         <input type="text" name="search" id="search" size="40" value="<?php echo htmlspecialchars($_GET['search']); ?>" />
118                 </div>
119
120                 <div class="row buttons">
121                         <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
122                         <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
123                 </div>
124         </div>
125 </form>
126
127 <form name="form" method="post">
128 <div class="input-form">
129         <table cellspacing="0" cellpadding="0">
130         <tr>
131         <td valign="top">
132                 <?php if ($num_results): ?>
133                         <select size="<?php echo min(max($num_results,2), 25); ?>" name="terms" id="terms" onchange="javascript:showtext(this);">
134                                 <?php
135                                         while ($row = mysql_fetch_assoc($result)): 
136                                                 if ($strlen($row['text']) > 30) {
137                                                         $row['text'] = $substr($row['text'], 0, 28) . '...';
138                                                 }
139                                         ?>
140                                                 <option value="<?php echo $row['term']; ?>"><?php echo htmlspecialchars($row['text']); ?></option>
141                                         <?php endwhile; ?>
142                         </select>
143                 <?php else: ?>
144                         <p><?php echo _AT('none_found'); ?></p>
145                 <?php endif; ?>
146         </td>
147
148         <td valign="top">
149                 <div class="row">
150                         <iframe src="mods/_core/languages/language_term.php" frameborder="0" height="430" width="450" marginheight="0" marginwidth="0" name="tran" id="tran"></iframe>
151                 </div>
152         </td>
153         </tr>
154         </table>
155 </div>
156 </form>
157
158 <script language="javascript" type="text/javascript">
159 //<!--
160 function showtext(obj) {
161         frames['tran'].location.href = "<?php echo AT_BASE_HREF; ?>mods/_core/languages/language_term.php?type=<?php echo $_variables[$_GET['type']].SEP; ?>term=" + obj.value;
162 }
163 //-->
164 </script>
165
166 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>