Changeset 816 for trunk/Modules/Translation/Save.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Translation/Save.php
r800 r816 5 5 function Show() 6 6 { 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //JOIN `TextSpell` as sub1 ON sub1.Language = 0 AND T.`Entry` = sub1.`Entry` AND T.`VersionStart` = sub1.`VersionStart` 7 global $TranslationTree, $Message, $MessageType; 8 9 $Output = ''; 10 $CompleteText = array('nedokončený', 'dokončený'); 11 12 unset($Message); 13 $this->System->ModuleManager->Modules['FrontPage']->HandleLoginForm(); 14 if(isset($Message)) $Output .= ShowMessage($Message, $MessageType); 15 16 $GroupId = LoadGroupIdParameter(); 17 $Group = $TranslationTree[$GroupId]; 18 $Table = $Group['TablePrefix']; 19 if($this->System->User->Licence(LICENCE_USER)) 20 { 21 if(array_key_exists('ID', $_POST) and is_numeric($_POST['ID'])) 22 { 23 $Entry = $_POST['entry'] * 1; 24 $TextID = $_POST['ID'] * 1; 25 $Language = $_POST['Language'] * 1; 26 if(array_key_exists('End', $_POST)) $Complete = 1; 27 else $Complete = 0; 28 29 // Get source text record from database by ID 30 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `ID`='.$TextID); 31 if($DbResult->num_rows > 0) 32 { 33 $SourceText = $DbResult->fetch_assoc(); 34 35 // Get data for english original 36 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE (`Entry`='.$SourceText['Entry'].') '. 37 'AND (`Language` = '.$this->System->Config['OriginalLanguage'].') AND (`VersionStart` = '.$SourceText['VersionStart'].') '. 38 'AND (`VersionEnd` = '.$SourceText['VersionEnd'].')'); 39 if($DbResult->num_rows > 0) 40 { 41 $EnglishText = $DbResult->fetch_assoc(); 42 43 // Get all similar english texts 44 $Filter = ''; 45 foreach($Group['Items'] as $GroupItem) 46 if(($GroupItem['Visible'] == 1) and ($EnglishText[$GroupItem['Column']] != '')) 47 $Filter .= ' OR (`'.$GroupItem['Column'].'` = "'.addslashes($EnglishText[$GroupItem['Column']]).'")'; 48 if(substr($Filter, 0, 3) == ' OR') $Filter = ' AND ('.substr($Filter, 3).')'; 49 50 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE (`Language` = '.$this->System->Config['OriginalLanguage'].')'.$Filter); 51 while($EnglishFound = $DbResult->fetch_assoc()) 52 { 53 // Get user translation paired to found english item entry 54 //TODO: and need update sql 55 //SELECT T.ID,T.Take,sub1.ID,T.`VersionStart`,T.`VersionEnd`,sub1.`VersionStart` as OrigStart,sub1.`VersionEnd` as OrigEnd FROM `TextSpell` as T 56 //JOIN `TextSpell` as sub1 ON sub1.Language = 0 AND T.`Entry` = sub1.`Entry` AND T.`VersionStart` = sub1.`VersionStart` 57 57 //WHERE T.Language != 0 AND T.`VersionEnd` != sub1.`VersionEnd` 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 if((($CompleteParts & (1 << ($GroupItem['Sequence'] - 1))) == 0) and86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 58 $DbResult2 = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE (`User` = '.$this->System->User->Id. 59 ') AND (`Entry` = '.$EnglishFound['Entry'].') AND (`VersionStart` = '.$EnglishFound['VersionStart']. 60 ') AND (`VersionEnd` = '.$EnglishFound['VersionEnd'].')'); 61 if($DbResult2->num_rows > 0) 62 { 63 // Update existed user translation 64 $ExistedText = $DbResult2->fetch_assoc(); 65 $Values = '`Language` = '.$Language; 66 67 $UpdateModifyTime = false; 68 $Completable = true; 69 $CompleteParts = $ExistedText['CompleteParts']; 70 foreach($Group['Items'] as $GroupItem) 71 { 72 if($GroupItem['Visible'] == 1) 73 { 74 if($SourceText[$GroupItem['Column']] != $ExistedText[$GroupItem['Column']]) 75 $UpdateModifyTime = true; 76 77 if($EnglishFound[$GroupItem['Column']] == $EnglishText[$GroupItem['Column']]) 78 { 79 if(array_key_exists($GroupItem['Column'], $_POST)) 80 { 81 $Values .= ', `'.$GroupItem['Column'].'` = "'.$_POST[$GroupItem['Column']].'"'; 82 $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 83 } 84 } 85 if((($CompleteParts & (1 << ($GroupItem['Sequence'] - 1))) == 0) and 86 ($EnglishFound[$GroupItem['Column']] != '')) $Completable = false; 87 } 88 } 89 if($Completable) $NewComplete = 1; // All parts of text are completed. Make entire text as completed 90 else $NewComplete = 0; 91 if($SourceText['ID'] == $ExistedText['ID']) 92 { 93 $NewComplete = $Complete; // Our original user text, set complete according user choice 94 if($Complete == 1) 95 { 96 foreach($Group['Items'] as $GroupItem) 97 if($GroupItem['Visible'] == 1) $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 98 } 99 } 100 $Values .= ', `Complete`='.$NewComplete.', `CompleteParts` = '.$CompleteParts; 101 102 if($UpdateModifyTime) $Values .= ', `ModifyTime` = NOW()'; 103 104 // Update user translation 105 $this->Database->query('UPDATE `'.$Table.'` SET '.$Values.' WHERE `ID` = '.$ExistedText['ID']); 106 107 $Output .= 'Změny v překladu <a href="'.$this->System->Link('/form.php?group='. 108 $GroupId.'&ID='.$ExistedText['ID']).'">'.$ExistedText['ID'].'</a> ('. 109 $ExistedText['Entry'].') uloženy jako '.$CompleteText[$NewComplete].'.<br />'; 110 $this->System->ModuleManager->Modules['Log']->WriteLog('Změny v překladu <a href="'. 111 $this->System->Link('/form.php?group='.$GroupId.'&ID='.$ExistedText['ID']).'">'. 112 $ExistedText['ID'].'</a> ('.$ExistedText['Entry'].') uloženy jako '.$CompleteText[$NewComplete].'.', LOG_TYPE_TRANSLATION); 113 } else 114 { 115 // Insert new user translation 116 $Columns = '`Entry`, `VersionStart`, `VersionEnd`, `Language`, `User`, `Take`, `ModifyTime`'; 117 $Values = $EnglishFound['Entry'].', '.$EnglishFound['VersionStart'].', '. 118 $EnglishFound['VersionEnd'].', '.$Language.', '.$this->System->User->Id.', '.$EnglishFound['ID'].', NOW()'; 119 120 $CompleteParts = 0; 121 $Completable = true; 122 122 $OnlyRank = true; 123 124 125 126 127 128 129 130 131 132 133 if (44 <> $GroupItem['Id']) $OnlyRank = false; 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 if (!$OnlyRank) 160 { 161 162 163 164 165 166 167 168 169 170 171 172 173 174 } 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 }244 return($Output); 123 foreach($Group['Items'] as $GroupItem) 124 { 125 $Columns .= ', `'.$GroupItem['Column'].'`'; 126 if($GroupItem['Visible'] == 1) 127 { 128 if($EnglishFound[$GroupItem['Column']] == $EnglishText[$GroupItem['Column']]) 129 { 130 // Read form user data 131 if(array_key_exists($GroupItem['Column'], $_POST)) 132 { 133 if (44 <> $GroupItem['Id']) $OnlyRank = false; 134 $Values .= ', "'.$_POST[$GroupItem['Column']].'"'; 135 $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 136 } else $Values .= ', "'.addslashes($EnglishFound[$GroupItem['Column']]).'"'; 137 } else $Values .= ', "'.addslashes($EnglishFound[$GroupItem['Column']]).'"'; 138 if((($CompleteParts & (1 << ($GroupItem['Sequence'] - 1))) == 0) and ($EnglishFound[$GroupItem['Column']] != '')) $Completable = false; 139 } else 140 { 141 // Read from english text 142 $Values .= ', "'.$EnglishFound[$GroupItem['Column']].'"'; 143 } 144 } 145 if($Completable) $NewComplete = 1; // All parts of text are completed. Make entire text as completed 146 else $NewComplete = 0; 147 if($SourceText['ID'] == $EnglishFound['ID']) 148 { 149 $NewComplete = $Complete; // Our original user text, set complete according user choice 150 if($Complete == 1) 151 { 152 foreach($Group['Items'] as $GroupItem) 153 if($GroupItem['Visible'] == 1) $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 154 } 155 } 156 $Columns .= ', `Complete`, `CompleteParts`'; 157 $Values .= ', '.$NewComplete.', '.$CompleteParts; 158 159 if (!$OnlyRank) 160 { 161 $this->Database->query('INSERT INTO `'.$Table.'` ('.$Columns.') VALUES ('.$Values.')'); 162 $LastID = $this->Database->insert_id; 163 164 $Output .= 'Text <a href="'.$this->System->Link('/form.php?group='. 165 $GroupId.'&ID='.$LastID).'">'.$LastID.'</a> ze skupiny <a href="TranslationList.php?group='. 166 $GroupId.'&user=0&action=filter">'.$TranslationTree[$GroupId]['Name'].'</a> uložen jako '. 167 $CompleteText[$NewComplete].'. Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.<br/>'; 168 $this->System->ModuleManager->Modules['Log']->WriteLog('Text <a href="'. 169 $this->System->Link('/form.php?group='.$GroupId.'&ID='.$LastID).'">'. 170 $LastID.'</a> ze skupiny <a href="TranslationList.php?group='. 171 $GroupId.'&user=0&text=&entry=&action=filter">'. 172 $TranslationTree[$GroupId]['Name'].'</a> uložen jako '.$CompleteText[$NewComplete]. 173 '. Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.', LOG_TYPE_TRANSLATION); 174 } 175 } 176 } 177 } else $Output .= ShowMessage('Anglický originál k překladu nenalezen.', MESSAGE_CRITICAL); 178 } else $Output .= ShowMessage('Zadaná položka nenalezena.', MESSAGE_CRITICAL); 179 180 181 // Address and redirecting 182 $Output .= '<br />Překládat: <a href="TranslationList.php?group='.$GroupId.'&state=1&user=0&entry=">Nepřeložené</a> '; 183 184 $prev = FollowingTran($TextID, $Table, $GroupId, True); 185 $next = FollowingTran($TextID, $Table, $GroupId); 186 $Output .= '<br /><br />'; 187 $DbResult = $this->Database->query('SELECT `Redirecting` FROM `User` WHERE `ID`='.$this->System->User->Id); 188 $redirecting = $DbResult->fetch_assoc(); 189 190 switch($redirecting['Redirecting']) 191 { 192 case 1: 193 $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'. 194 'setTimeout("parent.location.href=\''.htmlspecialchars_decode('TranslationList.php?group='.$GroupId.'&state=1&user=0').'\'", 1500)'. 195 '</script>'; 196 break; 197 case 2: 198 if($next <> '') 199 $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'. 200 'setTimeout("parent.location.href=\''.htmlspecialchars_decode($next).'\'", 1500)'. 201 '</script>'; 202 break; 203 case 3: 204 if($prev <> '') 205 $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'. 206 'setTimeout("parent.location.href=\''.htmlspecialchars_decode($prev).'\'", 1500)'. 207 '</script>'; 208 break; 209 } 210 211 $Output .= 'Z této stránky můžete být automaticky přesměrování. Nastavit kam chcete být přesměrování si můžete v <a href="'. 212 $this->System->Link('/Options.php').'" title="Nastavení uživatele">Nastavení</a>'; 213 214 // Update flag for experience info load 215 $this->Database->query('UPDATE `User` SET `NeedUpdate` = 1 WHERE `ID` = '.$this->System->User->Id); 216 } else $Output .= ShowMessage('Položka nenalezena', MESSAGE_CRITICAL); 217 } else 218 { 219 if(array_key_exists('ID', $_POST) and array_key_exists('entry', $_POST) and array_key_exists('Language', $_POST) and array_key_exists('user', $_POST)) 220 { 221 $Output .= 'Byli jste automaticky odhlášeni. Pro <strong>Uložení překladu</strong> se musíte přihlásit zde:<br /><br />'. 222 '<form action="save.php?action=login&group='.$GroupId.'" method="post"><div>'. 223 '<input type="hidden" name="entry" value="'.$_POST['entry'].'" />'. 224 '<input type="hidden" name="user" value="'.$_POST['user'].'" />'. 225 '<input type="hidden" name="ID" value="'.$_POST['ID'].'" />'. 226 '<input type="hidden" name="Language" value="'.$_POST['Language'].'" />'; 227 228 foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem) 229 { 230 if(array_key_exists($TextItem['Column'], $_POST)) $Value = $_POST[$TextItem['Column']]; else $Value = ''; 231 $Output .= '<input id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'" type="hidden" value="'.htmlspecialchars($Value).'" />'; 232 } 233 $Output .= '<table>'. 234 '<tr>'. 235 '<td>Jméno: <input type="text" name="LoginUser" size="13" /></td>'. 236 '</tr><tr>'. 237 '<td>Heslo: <input type="password" name="LoginPass" size="13" /></td>'. 238 '</tr><tr>'. 239 '<th><input type="submit" value="Přihlásit a uložit překlad" /></th>'. 240 '</tr>'. 241 '</table>'; 242 } else $Output = ShowMessage('Nezadány požadované údaje.', MESSAGE_CRITICAL); 243 } 244 return($Output); 245 245 } 246 246 }
Note:
See TracChangeset
for help on using the changeset viewer.