Changeset 198 for trunk/dictionary.php
- Timestamp:
- Jun 5, 2009, 6:44:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dictionary.php
r167 r198 3 3 include('includes/global.php'); 4 4 5 function GetIDbyName($Table) { 5 function GetIDbyName($Table) 6 { 6 7 global $TranslationTree; 7 foreach($TranslationTree as $TableID => $Value) { 8 9 foreach($TranslationTree as $TableID => $Value) 10 { 8 11 //echo $Value['TablePrefix'].'='.$Table.'<br>'; 9 12 if ($Value['TablePrefix'] == $Table) return $TableID; … … 11 14 } 12 15 13 14 function GetTranslatNames($Text) { 15 global $Database,$mode; 16 function GetTranslatNames($Text) 17 { 18 global $Database, $mode; 19 16 20 if ($mode == 0) echo ('..Přesné'); 17 21 if ($mode == 1) echo ('..Všechny přeložené'); … … 19 23 echo('<div style="overflow: auto; width: 100%; height: 345px;"><table width="98%" class="BaseTable">'); 20 24 echo('<tr><th>Originál</th>'.'<th>Překlad</th>'); 21 $TablesColumn = array('gameobject' => 'Name', 22 'creature' => 'name', 23 'item' => 'Name', 24 'transports' => 'Name', 25 'areatrigger_teleport' => 'Name', 26 'areatrigger_tavern' => 'Name',); 25 $TablesColumn = array 26 ( 27 'gameobject' => 'Name', 28 'creature' => 'name', 29 'item' => 'Name', 30 'transports' => 'Name', 31 'areatrigger_teleport' => 'Name', 32 'areatrigger_tavern' => 'Name', 33 ); 27 34 /* $TablesID = array('gameobject' => 5, 28 35 'creature' => 6, … … 32 39 'areatrigger_tavern' => 'Name',); */ 33 40 34 35 36 foreach($TablesColumn as $Table => $Column) { 37 38 $sql = 'SELECT ID,'.$Column.',(SELECT Name FROM '.$Table.' as T WHERE O.entry = T.entry AND Language <> 0 LIMIT 1) as tran 39 FROM '.$Table.' as O WHERE '; 40 $groupby = ' GROUP BY '.$Column; 41 42 $ArrStr = explode(' ', $Text); 43 $where = 'Language = 0 '; 44 if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM '.$Table.' AS sub WHERE (sub.Language <> 0) AND (sub.entry = O.entry))'; 45 if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM '.$Table.' AS sub WHERE (sub.Language <> 0) AND (sub.entry = O.entry))'; 46 $where .= ' AND ('; 47 48 for($i = 0; $i < count($ArrStr); $i++) 49 { 50 if (strpos($ArrStr[$i],'\'s') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-4); 51 if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 52 if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 53 if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 54 if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 55 56 if (strlen($ArrStr[$i]) > 4) 57 $where .= 'O.'.$Column.' LIKE "%'.addslashes($ArrStr[$i]).'%" OR '; 41 foreach($TablesColumn as $Table => $Column) 42 { 43 $sql = 'SELECT ID,'.$Column.',(SELECT Name FROM '.$Table.' as T WHERE O.entry = T.entry AND Language <> 0 LIMIT 1) as tran FROM '.$Table.' as O WHERE '; 44 $groupby = ' GROUP BY '.$Column; 45 46 $ArrStr = explode(' ', $Text); 47 $where = 'Language = 0 '; 48 if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM '.$Table.' AS sub WHERE (sub.Language <> 0) AND (sub.entry = O.entry))'; 49 if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM '.$Table.' AS sub WHERE (sub.Language <> 0) AND (sub.entry = O.entry))'; 50 $where .= ' AND ('; 51 52 for($i = 0; $i < count($ArrStr); $i++) 53 { 54 if (strpos($ArrStr[$i],'\'s') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-4); 55 if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 56 if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 57 if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 58 if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 59 60 if (strlen($ArrStr[$i]) > 4) 61 $where .= 'O.'.$Column.' LIKE "%'.addslashes($ArrStr[$i]).'%" OR '; 62 } 63 $where = substr($where,0,strlen($where)-4); 64 $where .= ')'; 65 echo ('</tr>'); 66 67 $ID = $Database->SQLCommand($sql.$where.$groupby); 68 while($Line = mysql_fetch_assoc($ID)) 69 { 70 if ($mode == 0) 71 { 72 if (strpos(strtolower($Text),strtolower($Line[$Column])) > 0) 73 { 74 echo('<tr><td>'.$Line[$Column].'</td>'); 75 if ($Line['tran'] <> '') echo('<td>'.$Line['tran'].'</td></tr>'); 76 else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&ID='.$Line['ID'].'">Překládat</a></td></tr>'); 77 } 78 } else 79 { 80 echo('<tr><td>'.$Line[$Column].'</td>'); 81 if ($Line['tran'] <> '') echo('<td>'.$Line['tran'].'</td></tr>'); 82 else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&ID='.$Line['ID'].'">Překládat</a></td></tr>'); 83 } 84 } 58 85 } 59 $where = substr($where,0,strlen($where)-4);60 $where .= ')';61 echo ('</tr>');62 63 $ID = $Database->SQLCommand($sql.$where.$groupby);64 while($Line = mysql_fetch_assoc($ID)) {65 if ($mode == 0) {66 if (strpos(strtolower($Text),strtolower($Line[$Column])) > 0) {67 echo('<tr><td>'.$Line[$Column].'</td>');68 if ($Line['tran'] <> '') echo('<td>'.$Line['tran'].'</td></tr>');69 else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&ID='.$Line['ID'].'">Překládat</a></td></tr>');70 }71 } else {72 echo('<tr><td>'.$Line[$Column].'</td>');73 if ($Line['tran'] <> '') echo('<td>'.$Line['tran'].'</td></tr>');74 else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&ID='.$Line['ID'].'">Překládat</a></td></tr>');75 }76 }77 }78 86 echo('</table></div>'); 79 87 } 80 88 81 82 echo('<?xml version="1.0" encoding="'.$Config['Web']['Charset'].'"?> 83 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 84 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 85 <head> 86 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 87 <link rel="stylesheet" href="'.$Config['Web']['BaseURL'].'style/style.css" type="text/css" media="all" /> 88 <script type="text/javascript" src="'.$Config['Web']['BaseURL'].'global.js"></script> 89 <link rel="SHORTCUT ICON" href="'.$Config['Web']['BaseURL'].'images/favicon.ico" /> 90 <title>Projekt překládání textů WoW - slovníček</title> 91 </head> 92 <body style="margin: 0px; font-family: Verdana, Arial, Sans-Serif;">'); 93 94 95 96 if (array_key_exists('group',$_GET)) { 97 89 if(array_key_exists('Page', $_GET)) $_SESSION['Page'] = $_GET['Page']; 90 else if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 1; 91 92 if(!isset($_SESSION['language'])) 93 { 94 if(Licence(LICENCE_USER)) 95 { 96 $DbResult = $Database->SQLCommand('SELECT Language FROM user WHERE ID='.$_SESSION['UserID']); 97 $User = mysql_fetch_assoc($DbResult); 98 $_SESSION['language'] = $User['Language']; 99 } else $_SESSION['language'] = 1; 100 } 101 if(array_key_exists('language', $_GET)) $_SESSION['language'] = $_GET['language']; 102 103 ShowPage(); 104 105 echo('<h3>Slovníček</h3>'); 106 107 if(array_key_exists('group', $_GET)) 108 { 98 109 if(array_key_exists('group', $_GET)) $GroupId = $_GET['group']; else $GroupId = 1; 99 110 if(array_key_exists('mode', $_GET)) $mode = $_GET['mode']; else $mode = 0; //0 = přesné názvy, 1=všechny názvy, 2=nepřeložené 100 111 $Table = $TranslationTree[$GroupId]['TablePrefix']; 101 112 102 if(array_key_exists('ID', $_GET)) { 103 $TextID = $_GET['ID']; 113 if(array_key_exists('ID', $_GET)) 114 { 115 $TextID = $_GET['ID']; 104 116 echo ('Přeložené názvy vztahující se k překladu: <a target="_NEW" href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a><br />'. 105 117 '<a href="?mode=1&group='.$GroupId.'&ID='.$TextID.'" title="Zobrazit všechny podobné výsledky">Všechny</a> '. 106 118 '<a href="?mode=0&group='.$GroupId.'&ID='.$TextID.'" title="Zobrazit pouze přesné výsledky">Přesné</a> '. 107 119 '<a href="?mode=2&group='.$GroupId.'&ID='.$TextID.'" title="Zobrazit všechny nepřeložené">Nepřeložené</a> '); 108 109 120 $Line = mysql_fetch_assoc($Database->SQLCommand('SELECT * FROM '.$Table.' Where ID = '.$TextID)); 121 if(!$Line) die('Překlad nenalezen.'); 110 122 111 123 $Text = ''; … … 114 126 GetTranslatNames($Text); 115 127 } 116 117 } else {118 if(array_key_exists('insert', $_GET))119 {120 echo('<form action="dictionary.php" method="post">121 <input type="text" name="AJWord"> Anglické slovo<br />122 <input type="text" name="CZWord"> České slovo<br />123 <input type="text" name="description"> Popis<br />124 <input type="submit" value="Uložit">125 </form>');126 $WinWidth = 230;127 } else128 {129 $WinWidth = 345;130 if (array_key_exists('AJWord', $_POST))131 {132 $AJWord = $_POST['AJWord'];133 $CZWord = $_POST['CZWord'];134 $description = $_POST['description'];135 $user = @$_SESSION['UserID'];136 $Database->SQLCommand("INSERT INTO `dictionary` ( `AJWord` , `CZWord` , `description` , `user` ) VALUES ('$AJWord', '$CZWord', '$description', '$user');");137 echo('Záznam byl uložen!');138 $WinWidth = 325;139 }140 }141 142 echo('<form action="dictionary.php" method="get" style="margin: 0px; padding: 0px;">143 <table style="width: 100%; height: 100%;">');144 145 if(array_key_exists('search', $_GET))146 {147 $Search = $_GET['search'];148 128 } else 149 { 150 $Search = ''; 151 } 129 { 130 if(array_key_exists('action', $_GET)) 131 { 132 if(($_GET['action'] == 'insert') and Licence(LICENCE_USER)) 133 { 134 echo('<form action="dictionary.php?action=save" method="post">'. 135 '<fieldset><legend>Vložení nového slova</legend>'. 136 '<table><tr><td>'. 137 'Původní anglické slovo:</td><td><input type="text" name="Original" /></td></tr>'. 138 '<tr><td>Přeložené:</td><td><input type="text" name="Translated" /></td></tr>'. 139 '<tr><td>Popis:</td><td><input type="text" name="Description" /></td></tr>'. 140 '<tr><td colspan="2"><input type="submit" value="Uložit" /></td></tr>'. 141 '</td></tr></table>'. 142 '</fieldset>'. 143 '</form>'); 144 } else 145 if(($_GET['action'] == 'save') and Licence(LICENCE_USER)) 146 { 147 $DbResult = $Database->SQLCommand('SELECT * FROM `dictionary` WHERE `Text` = "'.$_POST['Original'].'" AND Language=0'); 148 if(mysql_num_rows($DbResult) > 0) 149 { 150 $DbRow = mysql_fetch_assoc($DbResult); 151 $Entry = $DbRow['Entry']; 152 } else 153 { 154 $DbResult = $Database->SQLCommand('SELECT MAX(Entry) FROM dictionary'); 155 $DbRow = mysql_fetch_row($DbResult); 156 $Entry = $DbRow[0] + 1; 157 $Database->SQLCommand('INSERT INTO `dictionary` ( `Text` , `Entry` , `Description` , `User`, `Language` ) VALUES ("'.$_POST['Original'].'", "'.$Entry.'", "", 0, 0);'); 158 } 159 160 $DbResult = $Database->SQLCommand('SELECT Id FROM `dictionary` WHERE `Entry` = '.$Entry.' AND Language='.$_SESSION['language'].' AND User='.$_SESSION['UserID']); 161 if(mysql_num_rows($DbResult) > 0) 162 { 163 $DbRow = mysql_fetch_assoc($DbResult); 164 $Database->SQLCommand('UPDATE `dictionary` SET `Text`="'.$_POST['Translated'].'", `Description` = "'.$_POST['Description'].'" WHERE Id='.$DbRow['Id']); 165 } else 166 $Database->SQLCommand('INSERT INTO `dictionary` ( `Text` , `Entry` , `Description` , `User`, `Language` ) VALUES ("'.$_POST['Translated'].'", "'.$Entry.'", "'.$_POST['Description'].'", '.$_SESSION['UserID'].', '.$_SESSION['language'].')'); 167 echo('Záznam byl uložen!'); 168 } else 169 if(($_GET['action'] == 'remove') and Licence(LICENCE_USER)) 170 { 171 $Database->SQLCommand('DELETE FROM dictionary WHERE User='.$_SESSION['UserID'].' AND Language='.$_SESSION['language'].' AND Entry='.$_GET['entry']); 172 } else 173 if(($_GET['action'] == 'modify') and Licence(LICENCE_USER)) 174 { 175 $DbResult = $Database->SQLCommand('SELECT * FROM dictionary WHERE User='.$_SESSION['UserID'].' AND Entry='.$_GET['entry'].' AND Language='.$_SESSION['language']); 176 $DbRow = mysql_fetch_assoc($DbResult); 177 $DbResult = $Database->SQLCommand('SELECT * FROM dictionary WHERE User=0 AND Entry='.$_GET['entry'].' AND Language=0'); 178 $DbRow2 = mysql_fetch_assoc($DbResult); 179 echo('<form action="dictionary.php?action=save" method="post">'. 180 '<fieldset><legend>Upravení slova</legend>'. 181 '<table><tr><td>'. 182 'Původní anglické slovo:</td><td><input type="text" name="Original" value="'.$DbRow2['Text'].'" /></td></tr>'. 183 '<tr><td>Přeložené:</td><td><input type="text" name="Translated" value="'.$DbRow['Text'].'" /></td></tr>'. 184 '<tr><td>Popis:</td><td><input type="text" name="Description" value="'.$DbRow['Description'].'" /></td></tr>'. 185 '<tr><td colspan="2"><input type="submit" value="Uložit" /></td></tr>'. 186 '</td></tr></table>'. 187 '</fieldset>'. 188 '</form>'); 189 } 190 } 191 192 echo('<form action="dictionary.php" method="get" style="margin: 0px; padding: 0px;">'. 193 '<table style="width: 100%; height: 100%;">'); 194 195 if(array_key_exists('search', $_GET)) $Search = $_GET['search']; 196 else $Search = ''; 152 197 153 echo('<tr><td> 154 <input type="text" value="'.$Search.'" name="search" size="30" /> 155 <input type="submit" value="Vyhledat" />'); 156 if(Licence(LICENCE_USER)) 157 echo(' <a href="dictionary.php?insert">Vložit slovo</a>'); 198 echo('<tr><td> 199 <input type="text" value="'.$Search.'" name="search" size="30" /> 200 <input type="submit" value="Vyhledat" />'); 201 if(Licence(LICENCE_USER)) echo(' <a href="dictionary.php?action=insert">Vložit slovo</a>'); 158 202 159 echo('</td></tr>'); 160 echo('<tr><td> 161 <div style="overflow: auto; width: 100%; height: '.$WinWidth.'px;">'); 162 //todo select 163 if($Search <> '') 164 { 165 $sql = "SELECT * FROM `dictionary` WHERE LOWER(AJWord) LIKE LOWER('%$Search%') OR LOWER(CZWord) LIKE LOWER('%$Search%') OR LOWER(description) LIKE LOWER('%$Search%')"; 166 } else 167 { 168 $sql = "SELECT * FROM `dictionary`"; 169 } 170 echo('<table width="98%" class="BaseTable"> 171 <tr><th>Eng</th> 172 <th>Cze</th> 173 <th> Popis</th></tr>'); 174 $ID = $Database->SQLCommand($sql); 175 while ($Line = mysql_fetch_array($ID)) 176 { 177 echo('<tr> 178 <td>'.$Line['AJWord'].'</td> 179 <td><strong>'.$Line['CZWord'].'</strong></td> 180 <td>'.$Line['description'].'</td></tr>'); 181 } 182 echo('</table>'); 183 184 echo('</div></td></tr>'); 185 186 echo('</table></form>'); 187 188 } 189 190 echo ('</body></html>'); 203 echo('</td></tr>'); 204 echo('<tr><td>Jazyk: '); 205 foreach($LanguageList as $Language) 206 if($Language['Enabled'] == 1) 207 { 208 if($Language['Id'] == $_SESSION['language']) echo('<strong>'); 209 echo(' <a href="?language='.$Language['Id'].'">'.$Language['Name'].'</a>'); 210 if($Language['Id'] == $_SESSION['language']) echo('</strong>'); 211 } 212 echo('</td></tr>'); 213 echo('<tr><td> 214 <div style="overflow: auto; width: 100%; height: 100%;">'); 215 216 if($Search <> '') 217 { 218 $sql = 'SELECT `user`.`user` AS `UserName`, `user`. `ID` AS `UserID`, `T3`.`Entry`, `T3`.`Original`, `T3`.`Translated`, `T3`.`Description` FROM (SELECT T2.User, `T1`.Language, `T1`.`Text` AS Original, `T2`.`Text` AS `Translated`, `T2`.`Description`, `T1`.`Entry` AS `Entry` FROM `dictionary` AS `T1` JOIN `dictionary` AS `T2` ON `T2`.`Entry` = `T1`.`Entry` AND `T2`.`Language` = '.$_SESSION['language'].' WHERE LOWER(T1.Text) LIKE LOWER("%'.$Search.'%") OR LOWER(T1.Description) LIKE LOWER("%'.$Search.'%") ) AS T3 JOIN `user` ON `user`.`ID` = `T3`.`User` WHERE `T3`.`Language` = 0'; 219 } else $sql = 'SELECT `user`.`user` AS `UserName`, `ID` AS `UserID`, `T3`.`Entry`, `T3`.`Original`, `T3`.`Translated`, `T3`.`Description` FROM (SELECT T2.User, `T1`.Language, `T1`.`Text` AS Original, `T2`.`Text` AS `Translated`, `T2`.`Description`, `T1`.`Entry` AS `Entry` FROM `dictionary` AS `T1` JOIN `dictionary` AS `T2` ON `T2`.`Entry` = `T1`.`Entry` AND `T2`.`Language` = '.$_SESSION['language'].') AS T3 JOIN `user` ON `user`.`ID` = `T3`.`User` WHERE `T3`.`Language` = 0'; 220 $sql .= ' LIMIT '.($_SESSION['Page'] - 1) * $Config['Web']['ItemsPerPage'].','.$Config['Web']['ItemsPerPage']; 221 222 ListPaging('?Page=', '('.$sql.') AS T1', '', $Config['Web']['ItemsPerPage'], $_SESSION['Page']); 223 echo('<table width="98%" class="BaseTable"> 224 <tr><th>'.$LanguageList[0]['Name'].'</th> 225 <th>'.$LanguageList[$_SESSION['language']]['Name'].'</th> 226 <th>Popis</th><th>Překladatel</th>'); 227 if(Licence(LICENCE_USER)) echo('<th>Akce</th>'); 228 echo('</tr>'); 229 $ID = $Database->SQLCommand($sql); 230 while ($Line = mysql_fetch_assoc($ID)) 231 { 232 echo('<tr> 233 <td>'.$Line['Original'].'</td> 234 <td><strong>'.$Line['Translated'].'</strong></td> 235 <td>'.$Line['Description'].'</td> 236 <td>'.$Line['UserName'].'</td>'); 237 if(Licence(LICENCE_USER)) 238 { 239 if($Line['UserID'] == $_SESSION['UserID']) 240 echo('<td><a href="?action=remove&entry='.$Line['Entry'].'">Smazat</a> <a href="?action=modify&entry='.$Line['Entry'].'">Upravit</a></td>'); 241 else echo('<td></td>'); 242 } 243 echo('</tr>'); 244 } 245 echo('</table>'); 246 ListPaging('?Page=', '('.$sql.') AS T1', '', $Config['Web']['ItemsPerPage'], $_SESSION['Page']); 247 echo('</div></td></tr>'); 248 echo('</table></form>'); 249 } 250 251 ShowFooter(); 191 252 192 253 ?>
Note:
See TracChangeset
for help on using the changeset viewer.