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