Changeset 68 for trunk/export.php


Ignore:
Timestamp:
Feb 6, 2009, 8:41:20 AM (16 years ago)
Author:
george
Message:
  • Přidáno: Možnost výstupu překladů v XML formátu ke zobrazení nebo v ZIP souboru.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/export.php

    r66 r68  
    11<?php
    22
    3 function Export($Setting)
     3function ExportToMangosSQL($Setting)
    44{
    55  global $Database, $Config, $TranslationTree;
     
    2424  $SelectedUsers = substr($SelectedUsers, 1);
    2525
     26  if($SelectedUsers == '') $Where = 0;
     27    else $Where = 'ID IN ('.$SelectedUsers.')';
     28 
    2629  $UserNames = '';
    27   $DbResult = $Database->SQLCommand("SELECT user FROM `user` WHERE ID IN (".$SelectedUsers.')');
     30  $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
    2831  while($DbRow = mysql_fetch_assoc($DbResult))
    2932    $UserNames .= ','.$DbRow['user'];
     
    7881}
    7982 
    80      
     83function ExportToXML($Setting)
     84{
     85  global $Database, $Config, $TranslationTree;
     86 
     87  $AnoNe = array('Ne', 'Ano');
     88  if($_SESSION['UserID'] != '')
     89  {
     90    $DbResult = $Database->SQLCommand("SELECT user FROM `user` WHERE ID=".$_SESSION['UserID']);
     91    $User = mysql_fetch_assoc($DbResult);
     92  } else $User = array('user' => 'Neznámý');
     93
     94  $WhereLang = '';
     95  if($Setting['language-cz']) $WhereLang .= " OR (Language = 1)";
     96  if($Setting['language-sk']) $WhereLang .= " OR (Language = 2)";
     97  if($Setting['language-other']) $WhereLang .= " OR (Language = 3)";
     98  if($WhereLang == '') $WhereLang = 1;
     99    else $WhereLang = '('.substr($WhereLang, 4).')';
     100
     101  $SelectedUsers = ''; 
     102  foreach($Setting['users-selection'] as $Item)
     103    $SelectedUsers .= ','.$Item;
     104  $SelectedUsers = substr($SelectedUsers, 1);
     105
     106  if($SelectedUsers == '') $Where = 0;
     107    else $Where = 'ID IN ('.$SelectedUsers.')';
     108 
     109  $UserNames = '';
     110  $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
     111  while($DbRow = mysql_fetch_assoc($DbResult))
     112    $UserNames .= ','.$DbRow['user'];
     113  $UserNames = substr($UserNames, 1);   
     114   
     115  if($SelectedUsers == '') $WhereUsers = 1;
     116    else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
     117
     118  $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n".
     119  "<document>\n".
     120  "  <meta>\n".
     121  "    <projecturl>".$Config['Web']['BaseURL']."</projecturl>\n".
     122  "    <time>".date('r')."</time>\n".
     123  "    <diacritics mode=".'"'.$Setting['Diacritics'].'"'." />\n".
     124  "    <author>".$User['user']."</author>\n".
     125  "    <contributors>\n";
     126  foreach(explode(',', $UserNames) as $UserName)
     127    $Buffer .= "      <user>".$UserName."</user>\n";
     128  $Buffer .=
     129  "    </contributors>\n".
     130  "  </meta>\n".
     131  "  <translation>\n";
     132
     133  foreach($TranslationTree as $Group)
     134  if(in_array($Group['Id'], $Setting['groups']))
     135  {
     136        if($Group['MangosTable'] == '')
     137        {
     138          $Group['MangosTable'] = $Group['TablePrefix'];
     139          $Group['MangosTableIndex'] = 'entry';
     140        }
     141    $Query = 'SELECT *,(SELECT user FROM user WHERE user.ID=T.User) as UserName FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';     
     142    //echo($Query);
     143    $Buffer .= '    <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n";
     144    $ID = $Database->SQLCommand($Query);
     145    while($Line = mysql_fetch_array($ID))
     146    {
     147      $Buffer .= '      <item id="'.$Line['entry'].'" user="'.$Line['UserName'].'">'."\n";
     148          $Values = '';
     149          foreach($Group['Items'] as $GroupItem)
     150          {
     151            if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
     152                if($Line[$GroupItem['Column']] != '')
     153                  $Buffer .= '        <text index="'.$GroupItem['Id'].'" name="'.$GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n";
     154          }
     155          $Buffer .= "      </item>\n";
     156    }   
     157        $Buffer .= "    </group>\n";
     158  }
     159  if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
     160  $Buffer .= "  </translation>\n".
     161  "</document>";
     162  return($Buffer);
     163}     
    81164?>
Note: See TracChangeset for help on using the changeset viewer.