| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | class ModuleAdmin extends Module
|
|---|
| 4 | {
|
|---|
| 5 | function __construct(System $System)
|
|---|
| 6 | {
|
|---|
| 7 | parent::__construct($System);
|
|---|
| 8 | $this->Name = 'Admin';
|
|---|
| 9 | $this->Version = '1.0';
|
|---|
| 10 | $this->Creator = 'Chronos';
|
|---|
| 11 | $this->License = 'GNU/GPL';
|
|---|
| 12 | $this->Description = 'Administrator section of the web';
|
|---|
| 13 | $this->Dependencies = array('Translation');
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | function DoStart(): void
|
|---|
| 17 | {
|
|---|
| 18 | Core::Cast($this->System)->RegisterMenuItem(array(
|
|---|
| 19 | 'Title' => T('Administration'),
|
|---|
| 20 | 'Hint' => T('Administration tools'),
|
|---|
| 21 | 'Link' => $this->System->Link('/admin/'),
|
|---|
| 22 | 'Permission' => LICENCE_ADMIN,
|
|---|
| 23 | 'Icon' => '',
|
|---|
| 24 | ));
|
|---|
| 25 | $this->System->RegisterPage(['admin'], 'PageAdmin');
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | class PageAdmin extends Page
|
|---|
| 30 | {
|
|---|
| 31 | function ShowMenu()
|
|---|
| 32 | {
|
|---|
| 33 | $Output = '<h3>'.T('Administration tools').'</h3>';
|
|---|
| 34 |
|
|---|
| 35 | $Output .= '<br />'.
|
|---|
| 36 | '<a href="https://'.Core::Cast($this->System)->Config['Web']['Host'].'/phpmyadmin/">'.T('Database management').'</a><br/>'.
|
|---|
| 37 | '<small>Rozhraní phpMyAdmin pro přímou správu databáze</small><br/><br/>'.
|
|---|
| 38 | '<a href="'.$this->System->Link('/import/').'">'.T('Text import').'</a><br/>'.
|
|---|
| 39 | '<small>Načtení zdrojových textů do databáze</small><br/><br/>'.
|
|---|
| 40 | '<a href="'.$this->System->Link('/log/').'">'.T('Event log').'</a><br/>'.
|
|---|
| 41 | '<small>Procházení všech systémových záznamů akcí a událostí</small><br/><br/>'.
|
|---|
| 42 | '<a href="'.$this->System->Link('/admin/?action=testing').'">'.T('Testing').'</a><br/>'.
|
|---|
| 43 | '<small>Testovací funkce</small><br/><br/>'.
|
|---|
| 44 | '<a href="'.$this->System->Link('/admin/?action=locale').'">'.T('Export of the web interface translation').'</a><br/>'.
|
|---|
| 45 | '<small>Exportovat texty z PHP souborů pro překlad rozhraní</small><br/><br/>'.
|
|---|
| 46 | '<a href="'.$this->System->Link('/admin/?action=uncomplete').'">Nastavit nekompletní texty</a><br/>'.
|
|---|
| 47 | '<small>Nastaví questy, které jsou v popisu nebo objektu stejné jako nedokončené</small><br/><br/>'.
|
|---|
| 48 | '<a href="'.$this->System->Link('/admin/?action=repairversion').'">Opravit špatně nastavené VersionEnd</a><br/>'.
|
|---|
| 49 | '<small>Nastaví špatné version end a Take na originální text, které vzniklo v důsledku importu a špatně indexovaného indexu Take</small><br/><br/>'.
|
|---|
| 50 | '<a href="'.$this->System->Link('/admin/?action=dbcstructure').'">Připravit dbc strukturu</a><br/>'.
|
|---|
| 51 | '<small>Otevře dbc soubory převedené do textové formy pro přípravu struktury pro import</small><br/><br/>'.
|
|---|
| 52 | '<a href="'.$this->System->Link('/admin/?action=merge').'">Sjednocení textů</a><br/>'.
|
|---|
| 53 | '<small>Sjednotí stejné originální texty v databázi</small><br/><br/>';
|
|---|
| 54 | return $Output;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | function TestError($P1, $P2)
|
|---|
| 58 | {
|
|---|
| 59 | $s = $TT[0];
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | function TestException($P1, $P2)
|
|---|
| 63 | {
|
|---|
| 64 | throw new Exception('Test exception');
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | function TestSQLError($Query)
|
|---|
| 68 | {
|
|---|
| 69 | $DbResult = $this->System->Database->query($Query);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | function ShowPHPInfo()
|
|---|
| 73 | {
|
|---|
| 74 | return phpinfo();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | function Testing()
|
|---|
| 78 | {
|
|---|
| 79 | $this->Title = T('Testing');
|
|---|
| 80 | $Output = '<a href="'.$this->System->Link('/admin/?action=phpinfo').'">PHP info</a><br/>'.
|
|---|
| 81 | '<small>PHP informace</small><br/><br/>'.
|
|---|
| 82 | '<a href="'.$this->System->Link('/admin/?action=error').'">Testovací chyba</a><br/>'.
|
|---|
| 83 | '<small>Vyvolá testovací chybu</small><br/><br/>'.
|
|---|
| 84 | '<a href="'.$this->System->Link('/admin/?action=exception').'">Testovací výjimka</a><br/>'.
|
|---|
| 85 | '<small>Vyvolá testovací chybu</small><br/><br/>'.
|
|---|
| 86 | '<a href="'.$this->System->Link('/admin/?action=sqlerror').'">Chybný SQL dotaz</a><br/>'.
|
|---|
| 87 | '<small>Vyvolá testovací chybu</small><br/><br/>';
|
|---|
| 88 | return $Output;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | function Uncomplete()
|
|---|
| 92 | {
|
|---|
| 93 | $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`,`gs_tran`.`Details`,`gs_tran`.`Objectives` FROM '
|
|---|
| 94 | .'`TextQuest` AS `gs_tran` '
|
|---|
| 95 | .'JOIN `TextQuest` AS `gs_orig` ON `gs_orig`.`Entry` = `gs_tran`.`Entry` '
|
|---|
| 96 | .'AND `gs_orig`.`Language` =0 '
|
|---|
| 97 | .'WHERE `gs_tran`.`Language` !=0 '
|
|---|
| 98 | .'AND `gs_tran`.`Complete` =1 '
|
|---|
| 99 | .'AND ( (`gs_tran`.`Details` = `gs_orig`.`Details` AND "" != `gs_orig`.`Details` )'
|
|---|
| 100 | .' OR ( `gs_tran`.`Objectives` != `gs_orig`.`Objectives` AND "" = `gs_tran`.`Objectives` )'
|
|---|
| 101 | .' OR ( `gs_tran`.`Details` != `gs_orig`.`Details` AND "" = `gs_tran`.`Details` )'
|
|---|
| 102 | .' OR (`gs_tran`.`Objectives` = `gs_orig`.`Objectives` AND "" != `gs_orig`.`Objectives` ))'
|
|---|
| 103 | );
|
|---|
| 104 | $Output = 'Questy: <br />';
|
|---|
| 105 | while ($quest = $DbResult->fetch_assoc())
|
|---|
| 106 | {
|
|---|
| 107 | $Output .= $quest['ID'].', ';
|
|---|
| 108 | $this->System->Database->query('UPDATE `TextQuest` SET `complete` = 0 WHERE ID='.$quest['ID']);
|
|---|
| 109 | }
|
|---|
| 110 | $Output .= '<br / ><br / >Questy nastaveny jako nedokončené!';
|
|---|
| 111 | return $Output;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | function RepairVersionEnd()
|
|---|
| 115 | {
|
|---|
| 116 | $TranslationTree = ModuleTranslation::Cast($this->System->ModuleManager->GetModule('Translation'))->GetTranslationTree();
|
|---|
| 117 |
|
|---|
| 118 | $Output = '';
|
|---|
| 119 | foreach ($TranslationTree as $Group)
|
|---|
| 120 | // $Group = $TranslationTree[1];
|
|---|
| 121 | {
|
|---|
| 122 |
|
|---|
| 123 | $sql = 'SELECT `T`.`ID`,`T`.`Take`,`sub1`.`ID` as `origID`,T.`VersionStart`,T.`VersionEnd`,`sub1`.`VersionStart` as OrigStart,sub1.`VersionEnd` as `OrigEnd` FROM `'.$Group['TablePrefix'] .'` as `T` '.
|
|---|
| 124 | ' JOIN `'.$Group['TablePrefix'].'` as `sub1` ON `sub1`.`Language` = 0 AND `T`.`Entry` = `sub1`.`Entry` AND `T`.`VersionStart` = `sub1`.`VersionStart` '.
|
|---|
| 125 | ' WHERE `T`.`Take` != `sub1`.`ID` AND `T`.`Language` != 0'.
|
|---|
| 126 | // ' WHERE `T`.`Language` != 0 AND `T`.`VersionEnd` != `sub1`.`VersionEnd` AND `T`.`Take` NOT IN'.
|
|---|
| 127 | // '(Select `ID` FROM `'.$Group['TablePrefix'].'` as `sub2` WHERE `sub2`.`Language` = 0 AND `T`.`Entry` = `sub2`.`Entry` AND `T`.`VersionStart` = `sub2`.`VersionStart`)'.
|
|---|
| 128 | ' '; //LIMIT 1000
|
|---|
| 129 | $DbResult = $this->System->Database->query($sql);
|
|---|
| 130 | echo ': <br />'.$Group['TablePrefix'].': <br />';
|
|---|
| 131 | while ($line = $DbResult->fetch_assoc())
|
|---|
| 132 | {
|
|---|
| 133 | echo ($line['ID'].', ');
|
|---|
| 134 | $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `VersionEnd` = '.
|
|---|
| 135 | $line['OrigEnd'].', `Take` = '.$line['origID'].' WHERE ID='.$line['ID']);
|
|---|
| 136 | }
|
|---|
| 137 | echo '<br / >Verze '.$Group['TablePrefix'].' opraveny!';
|
|---|
| 138 | }
|
|---|
| 139 | return 'Hotovo!';
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | function StripText($Text)
|
|---|
| 143 | {
|
|---|
| 144 | $Text = strtolower($Text);
|
|---|
| 145 | $Text = str_replace(' ', '', $Text);
|
|---|
| 146 | return $Text;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | function MergeSameText()
|
|---|
| 150 | {
|
|---|
| 151 | $TranslationTree = ModuleTranslation::Cast($this->System->ModuleManager->GetModule('Translation'))->GetTranslationTree();
|
|---|
| 152 |
|
|---|
| 153 | $Output = '';
|
|---|
| 154 | foreach ($TranslationTree as $Group)
|
|---|
| 155 | // $Group = $TranslationTree[1];
|
|---|
| 156 | {
|
|---|
| 157 |
|
|---|
| 158 | $sql = 'SELECT * FROM `'.$Group['TablePrefix'] .'` as `T` '.
|
|---|
| 159 | // ' JOIN `'.$Group['TablePrefix'].'` as `sub1` ON `sub1`.`Language` = 0 AND `T`.`Entry` = `sub1`.`Entry` AND `T`.`VersionStart` < `sub1`.`VersionStart` '.
|
|---|
| 160 | ' WHERE `T`.`Language` = 0 '.
|
|---|
| 161 | ' ORDER BY `T`.`VersionStart`'; //LIMIT 1000
|
|---|
| 162 | $DbResult = $this->System->Database->query($sql);
|
|---|
| 163 | echo ': <br />'.$Group['TablePrefix'].': ';
|
|---|
| 164 | while ($line = $DbResult->fetch_assoc())
|
|---|
| 165 | {
|
|---|
| 166 | $sql = 'SELECT * FROM `'.$Group['TablePrefix'] .'` as `T` '.
|
|---|
| 167 | ' WHERE `T`.`Language` = 0 AND `T`.`VersionStart` > '.$line['VersionEnd'].' AND `T`.`Entry` = '.$line['Entry'].
|
|---|
| 168 | ' ORDER BY `T`.`VersionStart` LIMIT 1'; //LIMIT 1000
|
|---|
| 169 | $DbResult2 = $this->System->Database->query($sql);
|
|---|
| 170 | if ($DbResult2->num_rows > 0)
|
|---|
| 171 | {
|
|---|
| 172 | $line2 = $DbResult2->fetch_assoc();
|
|---|
| 173 |
|
|---|
| 174 | $Same = true;
|
|---|
| 175 | foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
|
|---|
| 176 | {
|
|---|
| 177 | if ($this->StripText($line[$Column['Column']]) <> $this->StripText($line2[$Column['Column']]))
|
|---|
| 178 | $Same = false;
|
|---|
| 179 | }
|
|---|
| 180 | if ($Same)
|
|---|
| 181 | {
|
|---|
| 182 | echo $line['ID'].'='.$line2['ID'].' (';
|
|---|
| 183 | // $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `Take` = NULL WHERE ID='.$line2['ID']);
|
|---|
| 184 |
|
|---|
| 185 | $sql = 'SELECT * FROM `'.$Group['TablePrefix'] .'` as `T` '.
|
|---|
| 186 | ' WHERE `T`.`Entry` = '.$line['Entry'].' AND (`T`.`Take` = '.$line['ID'].' OR `T`.`Take` = '.$line2['ID'].') ';
|
|---|
| 187 | $DbResult3 = $this->System->Database->query($sql);
|
|---|
| 188 | while ($line3 = $DbResult3->fetch_assoc())
|
|---|
| 189 | {
|
|---|
| 190 | echo $line3['ID'].' ';
|
|---|
| 191 | $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `VersionEnd` = '.$line2['VersionEnd'].', `VersionStart` = '.$line['VersionStart'].', `Take` = '.$line['ID'].' WHERE ID='.$line3['ID']);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | $this->System->Database->query('DELETE FROM`'.$Group['TablePrefix'].'` WHERE ID='.$line2['ID']);
|
|---|
| 195 | $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `VersionEnd` = '.$line2['VersionEnd'].' WHERE ID='.$line['ID']);
|
|---|
| 196 | echo '), ';
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 | echo('Texty '.$Group['TablePrefix'].' sjednoceny!');
|
|---|
| 201 | }
|
|---|
| 202 | return 'Hotovo!';
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | function DbcStructure()
|
|---|
| 206 | {
|
|---|
| 207 | $TranslationTree = ModuleTranslation::Cast($this->System->ModuleManager->GetModule('Translation'))->GetTranslationTree();
|
|---|
| 208 |
|
|---|
| 209 | $Output = '';
|
|---|
| 210 | if (array_key_exists('GameVersion', $_GET))
|
|---|
| 211 | {
|
|---|
| 212 | $_SESSION['GameVersion'] = $_GET['GameVersion'];
|
|---|
| 213 | }
|
|---|
| 214 | if (!array_key_exists('GameVersion', $_SESSION))
|
|---|
| 215 | $_SESSION['GameVersion'] = Core::Cast($this->System)->Config['Web']['GameVersion'];
|
|---|
| 216 |
|
|---|
| 217 | $Output .= '<br />Nastavená verze: '.$_SESSION['GameVersion'].'<br />';
|
|---|
| 218 |
|
|---|
| 219 | if (array_key_exists('GroupItem', $_GET)) {
|
|---|
| 220 | $DbResult = $this->System->Database->query('SELECT * FROM `ClientVersion` WHERE `Version` = "'.$_SESSION['GameVersion'].'"');
|
|---|
| 221 | $Version = $DbResult->fetch_assoc();
|
|---|
| 222 | $this->System->Database->query('INSERT INTO `GroupItemDBC` (`Id` ,`ClientVersion` ,`GroupItem` ,`ColumnIndex`)VALUES (NULL , \''.$Version['Id'].'\', \''.$_GET['GroupItem'].'\', \''.$_GET['ColumnIndex'].'\')');
|
|---|
| 223 | $Output .= 'vloženo <br />';
|
|---|
| 224 | }
|
|---|
| 225 | if (array_key_exists('id', $_GET))
|
|---|
| 226 | {
|
|---|
| 227 | $Group = $TranslationTree[$_GET['id']];
|
|---|
| 228 | // $Output .= '<form action="?action=dbcstructure&id='.$Group['Id'].'">';
|
|---|
| 229 | // foreach ($Group['Items'] as $GroupItem)
|
|---|
| 230 | // {
|
|---|
| 231 | // $Output .= $GroupItem['Column'].': <input name="'.$GroupItem['Id'].'"><br />';
|
|---|
| 232 | // }
|
|---|
| 233 | // $Output .= '<input type="submit" value="uložit"></form>';
|
|---|
| 234 |
|
|---|
| 235 | $FileName = NormalizePath(dirname(__FILE__).'/../source/'.$_SESSION['GameVersion'].'/dbc/'.$Group['DBCFileName'].'.dbc.csv');
|
|---|
| 236 | $File = new FileStream();
|
|---|
| 237 | $File->OpenFile($FileName);
|
|---|
| 238 |
|
|---|
| 239 | //while (!$File->EOF())
|
|---|
| 240 |
|
|---|
| 241 | $Output .= '<table class="BaseTable">';
|
|---|
| 242 | $Output .= '<tr><td>';
|
|---|
| 243 | $Line = $File->ReadLine();
|
|---|
| 244 |
|
|---|
| 245 | for ($i = 0; $i < substr_count($Line, ','); $i++)
|
|---|
| 246 | {
|
|---|
| 247 | $Output .= $i;
|
|---|
| 248 | $Output .= '</td><td>';
|
|---|
| 249 | }
|
|---|
| 250 | $Output .= '</td></tr><tr><td>';
|
|---|
| 251 | for ($i = 0; $i < substr_count($Line, ','); $i++)
|
|---|
| 252 | {
|
|---|
| 253 | foreach ($Group['Items'] as $GroupItem)
|
|---|
| 254 | {
|
|---|
| 255 | $Output .= ' <a href="'.$this->System->Link('/admin/?action=dbcstructure&id='.
|
|---|
| 256 | $Group['Id'].'&GroupItem='.$GroupItem['Id'].'&ColumnIndex='.$i).'">'.
|
|---|
| 257 | $GroupItem['Column'].'</a><br/>';
|
|---|
| 258 | }
|
|---|
| 259 | $Output .= '</td><td>';
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | $Output .= '</td></tr><tr><td>';
|
|---|
| 263 |
|
|---|
| 264 | $Output .= str_replace(',', '</td><td>', $Line);
|
|---|
| 265 | $Output .= '</td></tr><tr><td>';
|
|---|
| 266 | for ($i = 0; $i < 50; $i++)
|
|---|
| 267 | {
|
|---|
| 268 | $Line = $File->ReadLine();
|
|---|
| 269 | $Output .= str_replace(',', '</td><td>', $Line);
|
|---|
| 270 | $Output .= '</td></tr><tr><td>';
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | $Output .= '</td></tr>';
|
|---|
| 274 | $Output .= '</table>';
|
|---|
| 275 | } else
|
|---|
| 276 | {
|
|---|
| 277 | $DbResult = $this->System->Database->query('SELECT * FROM `ClientVersion`');
|
|---|
| 278 | while ($Version = $DbResult->fetch_assoc())
|
|---|
| 279 | {
|
|---|
| 280 | $Output .= '<a href="'.$this->System->Link('/admin/?action=dbcstructure&GameVersion='.
|
|---|
| 281 | $Version['Version']).'">'.$Version['Version'].'</a> ';
|
|---|
| 282 | }
|
|---|
| 283 | $Output .= '<br /><br />';
|
|---|
| 284 |
|
|---|
| 285 | foreach ($TranslationTree as $Group)
|
|---|
| 286 | {
|
|---|
| 287 | if ($Group['DBCFileName'] <> '')
|
|---|
| 288 | $Output .= '<a href="'.$this->System->Link('/admin/?action=dbcstructure&id='.
|
|---|
| 289 | $Group['Id']).'">'.$Group['DBCFileName'].'</a><br/>';
|
|---|
| 290 | }
|
|---|
| 291 | }
|
|---|
| 292 | return $Output;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | function ShowLocale()
|
|---|
| 296 | {
|
|---|
| 297 | Core::Cast($this->System)->LocaleManager->UpdateAll(dirname(dirname(__FILE__)));
|
|---|
| 298 | $Output = 'Překlad rozhraní přegenerován';
|
|---|
| 299 | $Output .= '<table class="BaseTable"><tr><th>Originál</th><th>Překlad</th></tr>';
|
|---|
| 300 | foreach (Core::Cast($this->System)->LocaleManager->CurrentLocale->Texts->Data as $Index => $Item)
|
|---|
| 301 | $Output .= '<tr><td>'.$Index.'</td><td>'.$Item.'</td></tr>';
|
|---|
| 302 | $Output .= '</table>';
|
|---|
| 303 | $Output .= 'Překladové soubory zaktualizovány';
|
|---|
| 304 | return $Output;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | function Show(): string
|
|---|
| 308 | {
|
|---|
| 309 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
|---|
| 310 | $this->Title = T('Administration');
|
|---|
| 311 | $Output = '';
|
|---|
| 312 | if ($User->Licence(LICENCE_ADMIN))
|
|---|
| 313 | {
|
|---|
| 314 | if (array_key_exists('action', $_GET))
|
|---|
| 315 | {
|
|---|
| 316 | if ($_GET['action'] == 'error') $Output .= $this->TestError(12, 'test');
|
|---|
| 317 | else if ($_GET['action'] == 'exception') $Output .= $this->TestException(12, 'test');
|
|---|
| 318 | else if ($_GET['action'] == 'sqlerror') $Output .= $this->TestSQLError('SELECT dads FROM sdas');
|
|---|
| 319 | else if ($_GET['action'] == 'testing') $Output .= $this->Testing();
|
|---|
| 320 | else if ($_GET['action'] == 'phpinfo') $Output .= $this->ShowPHPInfo();
|
|---|
| 321 | else if ($_GET['action'] == 'locale') $Output .= $this->ShowLocale();
|
|---|
| 322 | else if ($_GET['action'] == 'uncomplete') $Output .= $this->Uncomplete();
|
|---|
| 323 | else if ($_GET['action'] == 'repairversion') $Output .= $this->RepairVersionEnd();
|
|---|
| 324 | else if ($_GET['action'] == 'dbcstructure') $Output .= $this->DbcStructure();
|
|---|
| 325 | else if ($_GET['action'] == 'merge') $Output .= $this->MergeSameText();
|
|---|
| 326 | else $Output .= $this->ShowMenu();
|
|---|
| 327 | } else $Output .= $this->ShowMenu();
|
|---|
| 328 | } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
|---|
| 329 | return $Output;
|
|---|
| 330 | }
|
|---|
| 331 | }
|
|---|