Changeset 420 for trunk/save.php
- Timestamp:
- Apr 7, 2010, 10:42:01 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/save.php
r417 r420 1 1 <?php 2 2 3 include ('includes/global.php');3 include_once('includes/global.php'); 4 4 5 5 ShowPage(); … … 9 9 10 10 $GroupId = LoadGroupIdParameter(); 11 $Table = $TranslationTree[$GroupId]['TablePrefix']; 12 if(array_key_exists('entry', $_POST) and $User->Licence(LICENCE_USER)) 11 $Group = $TranslationTree[$GroupId]; 12 $Table = $Group['TablePrefix']; 13 if($User->Licence(LICENCE_USER)) 13 14 { 14 $Entry = $_POST['entry'] * 1; // Make numeric 15 $TextID = $_POST['ID'] * 1; 16 $Language = $_POST['Language'] * 1; 17 if(array_key_exists('End', $_POST)) $Complete = 1; 18 else $Complete = 0; 15 if(array_key_exists('ID', $_POST) and is_numeric($_POST['ID'])) 16 { 17 $Entry = $_POST['entry'] * 1; 18 $TextID = $_POST['ID'] * 1; 19 $Language = $_POST['Language'] * 1; 20 if(array_key_exists('End', $_POST)) $Complete = 1; 21 else $Complete = 0; 22 23 // Get source text record from database by ID 24 $DbResult = $System->Database->query('SELECT * FROM `'.$Table.'` WHERE `ID`='.$TextID); 25 if($DbResult->num_rows > 0) 26 { 27 $SourceText = $DbResult->fetch_assoc(); 28 29 // Get data for english original 30 $DbResult = $System->Database->query('SELECT * FROM `'.$Table.'` WHERE (`Entry`='.$SourceText['Entry'].') AND (`Language` = 0) AND (`VersionStart` = '.$SourceText['VersionStart'].') AND (`VersionEnd` = '.$SourceText['VersionEnd'].')'); 31 if($DbResult->num_rows > 0) 32 { 33 $EnglishText = $DbResult->fetch_assoc(); 34 35 // Get all similar english texts 36 $Filter = ''; 37 foreach($Group['Items'] as $GroupItem) 38 if($GroupItem['Visible'] == 1) 39 $Filter .= ' AND (`'.$GroupItem['Column'].'` = "'.$EnglishText[$GroupItem['Column']].'")'; 40 41 $DbResult = $System->Database->query('SELECT * FROM `'.$Table.'` WHERE (`Language` = 0)'.$Filter); 42 while($DbRow = $DbResult->fetch_assoc()) 43 { 44 // Get user translation paired to found english item entry 45 $DbResult2 = $System->Database->query('SELECT * FROM `'.$Table.'` WHERE (`User` = '.$User->Id.') AND (`Entry` = '.$DbRow['Entry'].') AND (`VersionStart` = '.$SourceText['VersionStart'].') AND (`VersionEnd` = '.$SourceText['VersionEnd'].')'); 46 if($DbResult2->num_rows > 0) 47 { 48 $ExistedText = $DbResult2->fetch_assoc(); 49 $Values = '`Language` = '.$Language.', `Complete`='.$Complete; 50 foreach($Group['Items'] as $GroupItem) 51 { 52 if($GroupItem['Visible'] == 1) 53 if(array_key_exists($GroupItem['Column'], $_POST)) 54 $Values .= ', `'.$GroupItem['Column'].'` = "'.$_POST[$GroupItem['Column']].'"'; 55 } 56 57 // Update user translation 58 $System->Database->query('UPDATE `'.$Table.'` SET '.$Values.' WHERE `ID` = '.$ExistedText['ID']); 59 60 echo('Změny v překladu <a href="form.php?group='.$GroupId.'&ID='.$ExistedText['ID'].'">'.$ExistedText['ID'].'</a> ('.$ExistedText['Entry'].') uloženy!<br />'); 61 WriteLog('Změny v překladu <a href="form.php?group='.$GroupId.'&ID='.$ExistedText['ID'].'">'.$ExistedText['ID'].'</a> ('.$ExistedText['Entry'].') uloženy.', LOG_TYPE_TRANSLATION); 62 } else 63 { 64 // Insert new user translation 65 $Columns = '`Entry`, `VersionStart`, `VersionEnd`, `Language`, `Complete`, `User`, `Take`'; 66 $Values = $DbRow['Entry'].', '.$DbRow['VersionStart'].', '.$DbRow['VersionEnd'].', '.$Language.', '.$Complete.', '.$User->Id.', '.$SourceText['ID']; 67 foreach($Group['Items'] as $GroupItem) 68 { 69 if($GroupItem['Visible'] == 1) 70 { 71 // Read form user data 72 if(array_key_exists($GroupItem['Column'], $_POST)) 73 { 74 $Columns .= ', `'.$GroupItem['Column'].'`'; 75 $Values .= ', "'.$_POST[$GroupItem['Column']].'"'; 76 } 77 } else 78 { 79 // Read from english text 80 $Columns .= ', `'.$GroupItem['Column'].'`'; 81 $Values .= ', "'.$DbRow[$GroupItem['Column']].'"'; 82 } 83 } 84 $System->Database->query('INSERT INTO `'.$Table.'` ('.$Columns.') VALUES ('.$Values.')'); 85 $LastID = $System->Database->insert_id; 86 87 echo('Text <a href="form.php?group='.$GroupId.'&ID='.$LastID.'">'.$LastID.'</a> ze skupiny <a href="TranslationList.php?group='.$GroupId.'&action=filter">'.$TranslationTree[$GroupId]['Name'].'</a> uložen! Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.<br/>'); 88 WriteLog('Text <a href="form.php?group='.$GroupId.'&ID='.$LastID.'">'.$LastID.'</a> ze skupiny <a href="TranslationList.php?group='.$GroupId.'&action=filter">'.$TranslationTree[$GroupId]['Name'].'</a> uložen! Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.', LOG_TYPE_TRANSLATION); 89 } 90 } 91 } else echo('Anglický originál k překladu nenalezen.'); 92 } else echo('Zadaná položka nenalezena.'); 19 93 20 $DbResult = $Database->SQLCommand('SELECT * FROM `'.$Table.'` WHERE (`Language` = 0) AND (`Entry` = '.$Entry.')'); 21 if(mysql_num_rows($DbResult) == 0) ErrorMessage('Neznámé Id položky'); 22 $LineAJ = mysql_fetch_array($DbResult); 23 $LineTake = mysql_fetch_array($Database->SQLCommand('SELECT `VersionEnd`, `VersionStart` FROM `'.$Table.'` WHERE `ID` = '.$TextID)); 24 if(mysql_num_rows($DbResult) == 0) ErrorMessage('Neznámé Id položky'); 25 $DbResult = $Database->SQLCommand('SELECT * FROM `'.$Table.'` WHERE (`User`='.$User->Id.') AND (`Entry` = '.$Entry.') AND (`VersionStart` = '.$LineTake['VersionStart'].') AND (`VersionEnd` = '.$LineTake['VersionEnd'].')'); 26 $Line = mysql_fetch_array($DbResult); 27 if(!$Line) 28 { 29 // Načtení hodnot formuláře 30 $Columns = '`Language` , `User` , `Complete` , `Take` , `VersionStart` , `VersionEnd`'; 31 $Values = $Language.','.$User->Id.','.$Complete.','.$TextID.','.$LineTake['VersionStart'].','.$LineTake['VersionEnd']; 32 foreach($TranslationTree[$GroupId]['Items'] as $GroupItem) 33 { 34 if(array_key_exists($GroupItem['Column'], $_POST)) 35 { 36 if (($GroupItem['Column'] <> 'ShortCut') and ($GroupItem['Column'] <> 'Rank')) 37 { 38 $Columns .= ', `'.$GroupItem['Column'].'`'; 39 $Values .= ', "'.@$_POST[$GroupItem['Column']].'"'; 40 } 41 } 42 } 43 //echo('INSERT INTO `'.$Table.'` ('.$Columns.') VALUES ('.$Values.')'); 44 // $Database->SQLCommand('INSERT INTO `'.$Table.'` (`Entry`, '.$Columns.') VALUES ('.$Entry.','.$Values.')'); 45 // $LastID = mysql_insert_id(); 46 47 // Kontrolování stejných textů 48 $Where = '(`Language` = 0)'; 49 foreach($TranslationTree[$GroupId]['Items'] as $GroupItem) 50 { 51 if(($GroupItem['Column'] <> 'ShortCut') and ($GroupItem['Column'] <> 'Rank')) 52 { 53 if(array_key_exists($GroupItem['Column'], $_POST)) 54 $Where .= ' AND (`'.$GroupItem['Column'].'` = "'.addslashes($LineAJ[$GroupItem['Column']]).'")'; 55 else $Where .= ' AND (`'.$GroupItem['Column'].'` = "")'; 56 } 57 if($GroupItem['Column'] == 'Rank') 58 { 59 if(array_key_exists('Rank', $_POST)) 60 { 61 $Rank = substr($_POST['Rank'], 0 ,strpos($_POST['Rank'],' ')); 62 if(strlen($Rank) <= 2) 63 $Rank = substr($_POST['Rank'], strpos($_POST['Rank'],' ') + 1); 64 } else $Rank = 'Úroveň'; 65 } 66 } 67 68 $SameTranID = $Database->SQLCommand('SELECT * FROM '.$Table.' WHERE '.$Where); 69 while($SameTranLine = mysql_fetch_assoc($SameTranID)) 70 { 71 $Line = mysql_fetch_array($Database->SQLCommand('SELECT * FROM `'.$Table.'` WHERE (`User`='.$User->Id.') AND (`Entry` = '.$SameTranLine['Entry'].') AND (`VersionStart` = '.$LineTake['VersionStart'].') AND (`VersionEnd` = '.$LineTake['VersionEnd'].')')); 72 if(!$Line) 73 { 74 if($GroupItem['Column'] <> 'ShortCut') 75 { 76 if(isset($Rank)) 77 { 78 $Rank_number = substr($SameTranLine['Rank'], strpos($SameTranLine['Rank'],' ') + 1); 79 if($Rank_number <> '') $Rank_cur = $Rank.' '.$Rank_number; 80 else $Rank_cur = $SameTranLine['Rank']; 81 $Database->SQLCommand('INSERT INTO `'.$Table.'` (`Entry`, '.$Columns.', `Rank`) VALUES ('.$SameTranLine['Entry'].','.$Values.',"'.$Rank_cur.'")'); 82 } else 83 { 84 $Database->SQLCommand('INSERT INTO `'.$Table.'` (`Entry`, '.$Columns.') VALUES ('.$SameTranLine['Entry'].','.$Values.')'); 85 } 86 } else 87 { 88 $Database->SQLCommand('INSERT INTO `'.$Table.'` (`Entry`, '.$Columns.', `ShortCut`) VALUES ('.$SameTranLine['Entry'].','.$Values.',"'.$SameTranLine['ShortCut'].'")'); 89 } 90 $LastIDs[] = mysql_insert_id(); 91 } 92 } 93 94 echo('Překlad <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a> ('.$Entry.') uložen!<br />'); 95 foreach($LastIDs as $LastID) 96 { 97 if(count($LastIDs) > 1) echo('Nalezen stejný překlad, systémově přeložen: <a href="form.php?group='.$GroupId.'&ID='.$LastID.'">'.$LastID.'</a> Převzat z: <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a><br />'); 98 WriteLog('Text <a href="form.php?group='.$GroupId.'&ID='.$LastID.'">'.$LastID.'</a> ze skupiny <a href="TranslationList.php?group='.$GroupId.'&action=filter">'.$TranslationTree[$GroupId]['Name'].'</a> uložen! Převzat z <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a>.', LOG_TYPE_TRANSLATION); 99 } 100 } else 101 { 102 $sql = 'UPDATE '.$Table.' SET `Complete` = '.$Complete; 103 foreach($TranslationTree[$GroupId]['Items'] as $GroupItem) 104 if(array_key_exists($GroupItem['Column'], $_POST)) 105 $sql .= ', `'.$GroupItem['Column'].'`="'.$_POST[$GroupItem['Column']].'"'; 106 $sql .= ', `Language` = '.$Language.' WHERE (`ID` = '.$TextID.') AND (`Language` <> 0)'; 107 //echo($sql); 108 $Database->SQLCommand($sql); 109 // echo $sql.'<br />'; 110 echo('Změny v překladu <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a> ('.$Entry.') uloženy!<br />'); 111 WriteLog('Změny v překladu <a href="form.php?group='.$GroupId.'&ID='.$TextID.'">'.$TextID.'</a> ('.$Entry.') uloženy!', LOG_TYPE_TRANSLATION); 112 } 94 113 95 // Address and redirecting 114 96 echo('<br />Překládat: <a href="TranslationList.php?group='.$GroupId.'&action=notran">Nepřeložené</a> '); … … 144 126 // Aktualizace informace o nutnosti načíst XP 145 127 $Database->SQLCommand('UPDATE `User` SET `NeedUpdate` = 1 WHERE `ID` = '.$User->Id); 128 } else echo('Položka nenalezena'); 146 129 } else 147 130 { 148 if(array_key_exists(' entry', $_POST))131 if(array_key_exists('ID', $_POST)) 149 132 { 150 133 echo('Byli jste automaticky odhlášeni. Pro <strong>Uložení překladu</strong> se musíte přihlásit zde:<br /><br />');
Note:
See TracChangeset
for help on using the changeset viewer.