source: trunk/action.php@ 577

Last change on this file since 577 was 577, checked in by chronos, 11 years ago
  • Modified: Moved some code from global to system file. System class is now serving as main application class. Now old files which still use ShowPage function need system initialization with $InitSystem = true; before global.php inclusion.
  • Modified: Get rid of some global reference to $System, $Config and $User variables.
  • Modified: Search result functionality moved to application module from action.php file.
File size: 6.0 KB
Line 
1<?php
2
3$InitSystem = true;
4include_once('includes/global.php');
5
6function DatabaseKit()
7{
8 global $System, $TranslationTree, $User, $Config;
9
10 if($User->Licence(LICENCE_ADMIN))
11 {
12 $Output = '<form action="?action=dbkit" method="post">'.
13 'Najít: <input type="text" name="find" /><br />'.
14 'Nahradit: <input type="text" name="replace" /><br />'.
15 '<input type="submit" value="Najít/nahradit" /><br />'.
16 '</form><br />'.
17 '<a href="?action=dbkit&amp;Take">Opravit data v sloupci Take</a><br />'.
18 '<a href="?action=dbkit&amp;ShortCut">Opravit data v sloupci ShortCut</a><br />';
19
20 $Output .= '<br /><form action="?action=dbkit" method="post">'.
21 'Vymazat log typ : <input type="text" name="Type" /> '.
22 '<input type="submit" value="Vymazat" /><br />'.
23 '</form><br />';
24
25 if(array_key_exists('Type', $_POST))
26 {
27 $sql = 'DELETE FROM `Log` WHERE `Type` = '.$_POST['Type'];
28 $System->Database->query($sql);
29 WriteLog('Vymazán log '.$_POST['Type'], LOG_TYPE_MODERATOR);
30 $Output .= ' Vymazán log '.$_POST['Type'];
31 }
32
33 if(array_key_exists('find', $_POST))
34 {
35 $Output .= 'Začínám nahrazovat: <br />';
36 $find = $_POST['find'];
37 $replace = $_POST['replace'];
38
39 foreach($TranslationTree as $Group)
40 {
41 $Table = $Group['TablePrefix'];
42 $Output .= $Table.' ';
43
44 $sql = 'SELECT * FROM '.$Table.' WHERE (`Language` <> '.$Config['OriginalLanguage'].') AND (';
45 foreach($Group['Items'] as $Item)
46 {
47 if($Item['Column'] != '') $sql .= '`'.$Item['Column'].'` LIKE "%'.$find.'%" OR ';
48 }
49 $sql = substr($sql,0,strlen($sql)-4);
50 $sql .= ')';
51
52 $DbResult = $System->Database->query($sql);
53 while ($Line = $DbResult->fetch_assoc())
54 {
55 $sql = 'UPDATE '.$Table.' SET ';
56 foreach($Group['Items'] as $Item)
57 {
58 $Column_text = addslashes(str_replace($find, $replace, $Line[$Item['Column']]));
59 $sql .= ' '.$Item['Column'].' = "'.$Column_text.'",';
60 }
61 $sql = substr($sql,0,strlen($sql)-1);
62 $sql .= ' WHERE `ID` = '.$Line['ID'];
63 $System->Database->query($sql);
64 $Output .= '.';
65 }
66
67 $Output .= ' <strong>Hotovo</strong> <br />';
68 if($DbResult->num_rows > 0)
69 {
70 WriteLog('Použita oprava DB ovlivněno '.$DbResult->num_rows.' řádků z tabulky '.$Table.', "'.$find.'" nahrazeno za "'.$replace.'"', LOG_TYPE_MODERATOR);
71 $Output .= ' Použita oprava DB ovlivněno '.$DbResult->num_rows.' řádků z tabulky '.$Table.', "'.$find.'" nahrazeno za "'.$replace.'"<br />';
72 }
73 }
74 }
75
76 // Oprava dat v sloupci Take
77 if(array_key_exists('Take',$_GET))
78 {
79 $Output .= 'Začínám opravovat Take: <br />';
80
81 foreach($TranslationTree as $Group)
82 {
83 $Table = $Group['TablePrefix'];
84 $Output .= $Table.' ';
85
86 $sql = 'SELECT `ID`, `Entry` AS EntryTran, `Take`, '.
87 '(SELECT `ID` FROM `'.$Table.'` WHERE (`Language = '.$Config['OriginalLanguage'].') AND (`Entry` = `EntryTran`) LIMIT 1) AS `IDOrig` '.
88 'FROM `'.$Table.'` AS `Tran` WHERE (`Language` <> '.$Config['OriginalLanguage'].') AND ((`Take` IS NULL) OR '.
89 '(`ID` = `Take`) OR NOT EXISTS(SELECT 1 FROM `'.$Table.'` WHERE `ID` = `Tran`.`Take`))';
90
91 $DbResult = $System->Database->query($sql);
92 while($Line = $DbResult->fetch_assoc())
93 {
94 $sql = 'UPDATE `'.$Table.'` SET `Take` = '.$Line['IDOrig'].' WHERE `ID` = '.$Line['ID'];
95 $System->Database->query($sql);
96 $Output .= '.';
97 }
98
99 $Output .= ' <strong>Hotovo</strong> <br />';
100 if($DbResult->num_rows > 0)
101 {
102 WriteLog('Použita oprava DB na sloupec Take '.$DbResult->num_rows.' řádků z tabulky '.$Table, LOG_TYPE_MODERATOR);
103 $Output .= ' Použita oprava DB na sloupec Take '.$DbResult->num_rows.' řádků z tabulky '.$Table.'<br />';
104 }
105 }
106 }
107 // Oprava dat ShortCut
108 if(array_key_exists('ShortCut', $_GET))
109 {
110 $Output .= 'Začínám opravovat Take: <br />';
111
112 $Tables = array('TextGlobalString', 'TextGlueString');
113
114 foreach($Tables as $Table)
115 {
116 $Output .= $Table.' ';
117 $sql = 'SELECT `gs_orig`.`ID`, `gs_tran`.`Entry`, `gs_tran`.`ShortCut` AS `ShortCut_tran`, '.
118 '`gs_orig`.`ShortCut` AS `ShortCut_orig` FROM `'.$Table.'` AS `gs_tran` '.
119 'JOIN `'.$Table.'` AS `gs_orig` ON `gs_orig`.`Entry` = `gs_tran`.`Entry` WHERE '.
120 '`gs_tran`.`Language` <> '.$Config['OriginalLanguage'].' AND `gs_tran`.`ShortCut` <> `gs_orig`.`ShortCut`';
121 $DbResult = $System->Database->query($sql);
122 while ($Line = $DbResult->fetch_assoc())
123 {
124 $sql = 'UPDATE `'.$Table.'` SET `ShortCut` = '.$Line['ShortCut_orig'].' WHERE `ID` = '.$Line['ID'];
125 $System->Database->query($sql);
126 $Output .= '.';
127 }
128
129 $Output = ' <strong>Hotovo</strong> <br />';
130 if($DbResult->num_rows > 0)
131 {
132 WriteLog('Použita oprava DB na sloupec ShortCut '.$DbResult->num_rows.' řádků z tabulky '.$Table, LOG_TYPE_MODERATOR);
133 $Output .= ' Použita oprava DB na sloupec ShortCut '.$DbResult->num_rows.' řádků z tabulky '.$Table.'<br />';
134 }
135 }
136 }
137 } else $Output = ShowMessage('Nemáte oprávnění.', MESSAGE_CRITICAL);
138 return($Output);
139}
140
141if(array_key_exists('group', $_GET)) $GroupId = LoadGroupIdParameter();
142 else $GroupId = 1;
143//$Table = $TranslationTree[$GroupId]['TablePrefix'];
144$Action = '';
145if(array_key_exists('action', $_GET)) $Action = $_GET['action'];
146
147else if($Action == 'dbkit') $Output = DatabaseKit();
148else $Output = ShowMessage('Nebyla zadána žádná akce.', MESSAGE_CRITICAL);
149
150ShowPage($Output);
Note: See TracBrowser for help on using the repository browser.