Changeset 59 for trunk/export.php
- Timestamp:
- Feb 3, 2009, 9:48:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/export.php
r49 r59 1 1 <?php 2 2 3 function WithOutDiacritical($teststring)3 function utf2ascii($text) 4 4 { 5 $teststring = StrTr($teststring, "áäčďéěëíňóöřšťúůüýžÁÄČĎÉĚËÍŇÓÖŘŠŤÚŮÜÝŽ", "aacdeeeinoorstuuuyzAACDEEEINOORSTUUUYZ"); 6 return $teststring; 5 $return = Str_Replace( 6 Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") , 7 Array("a","c","d","e","e","i","l","n","o","r","s","t","u","u","y","z","A","C","D","E","E","I","L","N","O","R","S","T","U","U","Y","Z") , 8 $text); 9 //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami 10 //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"' 11 //$return = StrToLower($return); // velká písmena nahradí malými. 12 return($return); 7 13 } 8 14 9 $Diacritical = @$_POST['Diacritical']; 10 if(array_key_exists('CZ', $_POST)) $CZ = $_POST['CZ']; 11 if(array_key_exists('SK', $_POST)) $SK = $_POST['SK']; 12 if(array_key_exists('OtherLanguage', $_POST)) $OtherLanguage = $_POST['OtherLanguage']; 13 if(array_key_exists('Use', $_POST)) $Use = $_POST['Use'];14 $Type = $_POST['Type']; 15 $Export = $_POST['Export']; 16 $NumberVote = $_POST['NumberVote'];17 $Vote = $_POST['Vote'];18 $users = @$_REQUEST['users'];15 function Export($Setting) 16 { 17 global $Database, $Config, $TranslationTree; 18 19 $AnoNe = array('Ne', 'Ano'); 20 if($_SESSION['UserID'] != '') 21 { 22 $DbResult = $Database->SQLCommand("SELECT user FROM `user` WHERE ID=".$_SESSION['UserID']); 23 $User = mysql_fetch_assoc($DbResult); 24 } else $User = array('user' => 'Neznámý'); 19 25 20 $Buffer = ''; 21 $BufferHeader = ' 22 -- Generováno projektem wowpreklad.zdechov.net 23 -- =========================================== 24 -- 25 -- Web projektu: '.$Config['Web']['BaseURL'].' 26 -- E-mail: '.$Config['Web']['AdminEmail'].' 27 -- Datum exportu: '.date("m.d.y H:i").' 28 -- Znaková sada: '.$Config['Database']['Charset'].' / '.$Config['Web']['Charset'].' 29 -- Diakritika: '.$Diacritical.' 30 -- Počet nutných hlasů: '.$NumberVote.' 31 -- Známka vyšší jak: '.$Vote.' 32 -- Tabulky:'."\n"; 33 foreach($TranslationTree as $Group) 34 if($Group['TablePrefix'] != '') 35 $BufferHeader .= '-- '.$Group['Name'].': '.@$_POST[$Group['TablePrefix']]."\n"; 36 $BufferHeader .= "\n"; 37 38 if(isset($Use)) $BufferHeader .= "\nUSE `mangos`;\n\n"; 26 $WhereLang = ''; 27 if($Setting['language-cz']) $WhereLang .= " OR (Language = 1)"; 28 if($Setting['language-sk']) $WhereLang .= " OR (Language = 2)"; 29 if($Setting['language-other']) $WhereLang .= " OR (Language = 3)"; 30 if($WhereLang == '') $WhereLang = 1; 31 else $WhereLang = '('.substr($WhereLang, 4).')'; 39 32 40 $WhereLang = ''; 41 if(isset($CZ)) $WhereLang .= " Language = '1'"; 42 if(isset($SK)) 43 { 44 if($WhereLang <> '') 45 $WhereLang .= " OR Language = '2'"; 46 else 47 $WhereLang .= "Language = '2'"; 33 $SelectedUsers = ''; 34 foreach($Setting['users-selection'] as $Item) 35 $SelectedUsers .= ','.$Item; 36 $SelectedUsers = substr($SelectedUsers, 1); 37 38 $DbResult = $Database->SQLCommand("SELECT user FROM `user` WHERE ID IN (".$SelectedUsers.')'); 39 while($DbRow = mysql_fetch_assoc($DbResult)) 40 $UserNames .= ','.$DbRow['user']; 41 $UserNames = substr($UserNames, 1); 42 43 if($SelectedUsers == '') $WhereUsers = 1; 44 else $WhereUsers = '(User IN ('.$SelectedUsers.'))'; 45 46 $Buffer = 47 "-- Generováno projektem wowpreklad.zdechov.net\n". 48 "-- ===========================================\n". 49 "--\n". 50 "-- Web projektu: ".$Config['Web']['BaseURL']."\n". 51 "-- Datum exportu: ".date("j.n.Y H:i:s")."\n". 52 "-- Znaková sada: ".$Config['Database']['Charset']." / ".$Config['Web']['Charset']."\n". 53 "-- Diakritika: ".$AnoNe[$Setting['Diacritics']]."\n". 54 "-- Vygeneroval uživatel: ".$User['user']."\n". 55 "-- Vzato od uživatelů: ".$UserNames."\n". 56 "-- Generované tabulky: "; 57 foreach($TranslationTree as $Group) 58 if($Group['MangosTable'] != '') 59 if(in_array($Group['Id'], $Setting['groups'])) 60 $Buffer .= $Group['MangosTable'].', '; 61 $Buffer .= "\n\n"; 62 63 foreach($TranslationTree as $Group) 64 if(($Group['TablePrefix'] != '') and (in_array($Group['Id'], $Setting['groups']))) 65 { 66 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry'; 67 //echo($Query); 68 $Buffer .= "\n\n-- ".$Group['Name']."\n\n"; 69 $ID = $Database->SQLCommand($Query); 70 while($Line = mysql_fetch_array($ID)) 71 { 72 $Values = ''; 73 foreach($Group['Items'] as $GroupItem) 74 if($GroupItem['MangosColumn'] != '') 75 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"'; 76 $Values = substr($Values, 2); 77 $Buffer .= 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE `'.$Group['MangosTableIndex'].'` = '.$Line['entry'].';'."\n"; 78 } 79 } 80 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 81 return($Buffer); 48 82 } 49 if(isset($OtherLanguage))50 {51 if($WhereLang <> '')52 $WhereLang .= " OR Language = '3'";53 else54 $WhereLang .= "Language = '3'";55 }56 57 $WhereUsers = '';58 for($i = 0; $i < Count($users); $i++)59 {60 if($WhereUsers <> '')61 $WhereUsers .= " OR (User = ".addslashes($users[$i]).')';62 else63 $WhereUsers .= " (User = ".addslashes($users[$i]).')';64 }65 66 foreach($TranslationTree as $Group)67 if(array_key_exists($Group['TablePrefix'], $_POST))68 {69 if(($Export == 'Mangos') and (Licence(LICENCE_ADMIN) == False)) die('Nemáte oprávnění');70 83 71 $sql = 'SELECT * FROM '.$Group['TablePrefix'].' WHERE Complete = 1 AND CountVote >= '.$NumberVote.' AND Vote >= '.$Vote;72 73 if($WhereLang <> '') $sql .= ' AND ('.$WhereLang.')';74 if($WhereUsers <> '') $sql .= ' AND ('.$WhereUsers.')';75 76 $i = 0;77 //echo($sql);78 $Buffer .= "\n\n-- ".$Group['Name']."\n\n";79 $ID = $Database->SQLCommand($sql.' ORDER BY vote');80 while($Line = mysql_fetch_array($ID))81 {82 $Values = '';83 foreach($Group['Items'] as $GroupItem)84 if($GroupItem['MangosColumn'] != '')85 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';86 $Values = substr($Values, 2);87 $sql = 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE `'.$Group['MangosTableIndex'].'` = '.$Line['entry'].';';88 if(!$Diacritical) $sql = WithOutDiacritical($sql);89 90 $Buffer .= $sql."\n";91 ++$i;92 }93 }94 95 if($Export == 'Display')96 {97 echo('Vygenerovaný SQL kód: <br /><textarea rows="30" cols="100">');98 echo($BufferHeader);99 echo($Buffer);100 echo('</textarea>');101 }102 103 if($Export == 'Mangos')104 {105 $Database->SelectDatabase($Config['Database']['DatabaseMangos']);106 $BufferArray = explode("\n", $Buffer);107 foreach($BufferArray as $Line)108 $Database->SQLCommand($Line);109 echo('Hotovo!');110 }111 112 if($Export == 'Zip')113 {114 if(function_exists('gzcompress'))115 {116 $save_filename = 'SqlTranslate.zip';117 $SQL_filename = 'SqlTranslate.sql';118 119 $BufferZip = $BufferHeader.$Buffer;120 121 $zipfile = new zipfile();122 $zipfile->addFile($BufferZip, $SQL_filename);123 $Buffer = $zipfile->file();124 125 // echo $Buffer.'<br><br><br>';126 $file_handle = fopen($save_filename, 'w');127 $write_result = fwrite($file_handle, $Buffer);128 fclose($file_handle);129 // header("Location: ".$save_filename);130 131 } else echo('Vyskytla se chyba!');132 echo('<script type="text/javascript" language="JavaScript" charset="utf-8">133 setTimeout("parent.location.href=\''.$save_filename.'\'",1000)134 </script>');135 136 echo('Pokud nezačalo stahování soubor by mělo jít stáhnout pomocí tohoto odkazu:137 <a href="'.$save_filename.'">'.$save_filename.'</a><br />138 Pokud se vám zdá, že filtr na export nefunguje, vymažte si vyrovnávací paměť prohlížeče a zkuste stáhnout soubor znovu.');139 }140 141 WriteLog('Stažení SQL souboru: Typ Exportu: <b>'.$Export.'</b> Diakritika: <b>'.$Diacritical.'</b> Počet nutných hlasů: <b>'.$NumberVote.'</b> Známka vyšší jak: <b>'.$Vote.'</b>', 2);142 84 143 85 ?>
Note:
See TracChangeset
for help on using the changeset viewer.