Changeset 832 for trunk/Modules/Translation
- Timestamp:
- Aug 24, 2015, 10:13:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Translation/Save.php
r831 r832 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 } 158 5 159 function Show() 6 160 { … … 8 162 9 163 $Output = ''; 10 $CompleteText = array('nedokončený', 'dokončený');11 164 12 165 unset($Message); … … 27 180 else $Complete = 0; 28 181 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 = array(); 45 foreach($Group['Items'] as $GroupItem) 46 if(($GroupItem['Visible'] == 1)) 47 $Filter[] = '(`'.$GroupItem['Column'].'` = "'.addslashes($EnglishText[$GroupItem['Column']]).'")'; 48 if(count($Filter) > 0) $Filter = ' AND ('.implode(' OR ', $Filter).')'; 49 50 $Query = 'SELECT * FROM `'.$Table.'` WHERE (`Language` = '.$this->System->Config['OriginalLanguage'].')'.$Filter; 51 echo($Query."\n"); 52 $DbResult = $this->Database->query($Query); 53 while($EnglishFound = $DbResult->fetch_assoc()) 54 { 55 // Get user translation paired to found english item entry 56 //TODO: and need update sql 57 //SELECT T.ID,T.Take,sub1.ID,T.`VersionStart`,T.`VersionEnd`,sub1.`VersionStart` as OrigStart,sub1.`VersionEnd` as OrigEnd FROM `TextSpell` as T 58 //JOIN `TextSpell` as sub1 ON sub1.Language = 0 AND T.`Entry` = sub1.`Entry` AND T.`VersionStart` = sub1.`VersionStart` 59 //WHERE T.Language != 0 AND T.`VersionEnd` != sub1.`VersionEnd` 60 $DbResult2 = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE (`User` = '.$this->System->User->Id. 61 ') AND (`Entry` = '.$EnglishFound['Entry'].') AND (`VersionStart` = '.$EnglishFound['VersionStart']. 62 ') AND (`VersionEnd` = '.$EnglishFound['VersionEnd'].')'); 63 if($DbResult2->num_rows > 0) 64 { 65 // Update existed user translation 66 $ExistedText = $DbResult2->fetch_assoc(); 67 $Values = '`Language` = '.$Language; 68 69 $UpdateModifyTime = false; 70 $Completable = true; 71 $CompleteParts = $ExistedText['CompleteParts']; 72 foreach($Group['Items'] as $GroupItem) 73 { 74 if($GroupItem['Visible'] == 1) 75 { 76 if($SourceText[$GroupItem['Column']] != $ExistedText[$GroupItem['Column']]) 77 $UpdateModifyTime = true; 78 79 if($EnglishFound[$GroupItem['Column']] == $EnglishText[$GroupItem['Column']]) 80 { 81 if(array_key_exists($GroupItem['Column'], $_POST)) 82 { 83 $Values .= ', `'.$GroupItem['Column'].'` = "'.$_POST[$GroupItem['Column']].'"'; 84 $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 85 } 86 } 87 if((($CompleteParts & (1 << ($GroupItem['Sequence'] - 1))) == 0) and 88 ($EnglishFound[$GroupItem['Column']] != '')) $Completable = false; 89 } 90 } 91 if($Completable) $NewComplete = 1; // All parts of text are completed. Make entire text as completed 92 else $NewComplete = 0; 93 if($SourceText['ID'] == $ExistedText['ID']) 94 { 95 $NewComplete = $Complete; // Our original user text, set complete according user choice 96 if($Complete == 1) 97 { 98 foreach($Group['Items'] as $GroupItem) 99 if($GroupItem['Visible'] == 1) $CompleteParts |= (1 << ($GroupItem['Sequence'] - 1)); 100 } 101 } 102 $Values .= ', `Complete`='.$NewComplete.', `CompleteParts` = '.$CompleteParts; 103 104 if($UpdateModifyTime) $Values .= ', `ModifyTime` = NOW()'; 105 106 // Update user translation 107 $this->Database->query('UPDATE `'.$Table.'` SET '.$Values.' WHERE `ID` = '.$ExistedText['ID']); 108 109 $Output .= 'Změny v překladu <a href="'.$this->System->Link('/form.php?group='. 110 $GroupId.'&ID='.$ExistedText['ID']).'">'.$ExistedText['ID'].'</a> ('. 111 $ExistedText['Entry'].') uloženy jako '.$CompleteText[$NewComplete].'.<br />'; 112 $this->System->ModuleManager->Modules['Log']->WriteLog('Změny v překladu <a href="'. 113 $this->System->Link('/form.php?group='.$GroupId.'&ID='.$ExistedText['ID']).'">'. 114 $ExistedText['ID'].'</a> ('.$ExistedText['Entry'].') uloženy jako '.$CompleteText[$NewComplete].'.', LOG_TYPE_TRANSLATION); 115 } else 116 { 117 // Insert new user translation 118 $Columns = '`Entry`, `VersionStart`, `VersionEnd`, `Language`, `User`, `Take`, `ModifyTime`'; 119 $Values = $EnglishFound['Entry'].', '.$EnglishFound['VersionStart'].', '. 120 $EnglishFound['VersionEnd'].', '.$Language.', '.$this->System->User->Id.', '.$EnglishFound['ID'].', NOW()'; 121 122 $CompleteParts = 0; 123 $Completable = true; 124 foreach($Group['Items'] as $GroupItem) 125 { 126 $Columns .= ', `'.$GroupItem['Column'].'`'; 127 if($GroupItem['Visible'] == 1) 128 { 129 if($EnglishFound[$GroupItem['Column']] == $EnglishText[$GroupItem['Column']]) 130 { 131 // Read form user data 132 if(array_key_exists($GroupItem['Column'], $_POST)) 133 { 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 $this->Database->query('INSERT INTO `'.$Table.'` ('.$Columns.') VALUES ('.$Values.')'); 159 $LastID = $this->Database->insert_id; 160 161 $Output .= 'Text <a href="'.$this->System->Link('/form.php?group='. 162 $GroupId.'&ID='.$LastID).'">'.$LastID.'</a> ze skupiny <a href="TranslationList.php?group='. 163 $GroupId.'&user=0&action=filter">'.$TranslationTree[$GroupId]['Name'].'</a> uložen jako '. 164 $CompleteText[$NewComplete].'. Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.<br/>'; 165 $this->System->ModuleManager->Modules['Log']->WriteLog('Text <a href="'. 166 $this->System->Link('/form.php?group='.$GroupId.'&ID='.$LastID).'">'. 167 $LastID.'</a> ze skupiny <a href="TranslationList.php?group='. 168 $GroupId.'&user=0&text=&entry=&action=filter">'. 169 $TranslationTree[$GroupId]['Name'].'</a> uložen jako '.$CompleteText[$NewComplete]. 170 '. Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.', LOG_TYPE_TRANSLATION); 171 } 172 } 173 } else $Output .= ShowMessage('Anglický originál k překladu nenalezen.', MESSAGE_CRITICAL); 174 } else $Output .= ShowMessage('Zadaná položka nenalezena.', MESSAGE_CRITICAL); 182 $Output .= $this->Translate($Group, $TextID, $Complete, $Language); 175 183 176 184 $Output .= $this->ShowRedirection($GroupId, $Table, $TextID);
Note:
See TracChangeset
for help on using the changeset viewer.