<?php

include('includes/global.php');    
ShowPage();

echo('Text je porovnáván vždy ku předešlému (vlevo). Změny jsou zvýrazněny <span class="edit">barvou.</span><br /><br />');

function CompareString($String1, $String2)
{
  //TODO: barevné porovnání
  //strcasecmp($String1, $String2) == 0 je totožné
  //	echo $String1.'<br /><br />';
  $ArrStr1 = explode(' ', $String1);
  $ArrStr2 = explode(' ', $String2);
		
  for($i = 0; $i < count($ArrStr1); $i++)
  {
	if(isset($ArrStr2[$i]))
	{
	  if($ArrStr1[$i] == $ArrStr2[$i])
	  {
		echo($ArrStr1[$i].' ');
	  } else
	  {
		$find = false;
		for($j = 0; $j < count($ArrStr2); $j++)
		{
		  if(($ArrStr1[$i] == $ArrStr2[$j]) and ($find == false))
		  {
			echo($ArrStr1[$i].' ');
			$find = true;
		  }
		}
		if($find == false)
		  echo('<span class="edit">'.$ArrStr1[$i].' </span>');
	  }
	} else echo('<span class="edit">'.$ArrStr1[$i].' </span>');
  }
  //	echo $ArrStr1[0];
}

if(array_key_exists('group', $_GET)) $GroupId = $_GET['group']; else $GroupId = 1;
$Table = $TranslationTree[$GroupId]['TablePrefix'];
if(array_key_exists('action', $_GET)) $Action = $_GET['action']; else $Action = '';

if(array_key_exists('entry', $_GET)) 
{
  $Textentry = $_GET['entry'];  
  if((array_key_exists('ID1', $_GET)) and ($_GET['ID1'] <> -1))  //porovnání pouze 2 textů
  {
  	$TextID1 = $_GET['ID1'];  
  	$TextID2 = $_GET['ID2'];  
  	$WhereID = " AND (ID = $TextID1 OR ID = $TextID2 OR Language = 0)";	
  } else $WhereID = '';

  $DataID = $Database->SQLCommand('SELECT * FROM '.$Table.' Where entry = '.$Textentry.$WhereID.' ORDER BY Language');
  $i = 0;
  while($Line = mysql_fetch_assoc($DataID))
  {
	$BuffLine[$i] = $Line;
	$i = $i + 1;  	
  }
 // if(!$Line) die('Překlad nenalezen.');
  $Line = $BuffLine;
  $i = $i - 1;
  echo('Počet porovnávaných textů: <strong>'.$i.'</strong><br /> '); 

  echo('<strong>Číslo textu: <a href="http://www.wowhead.com/?quest='.$Textentry.'">'.$Textentry.'</a></strong>'.
    '<table class="BaseTable">');
  echo('<tr><th>Přeložil</th>');
  foreach($Line as $Index => $LineItem)
  {
	$LineUser = mysql_fetch_array($Database->SQLCommand('SELECT * FROM user WHERE id = '.$LineItem['User']));
    echo('<th>'.$LineUser['user'].'</th>');
  }
  echo('</tr>');
  echo('<tr>');
  echo('<th>ID textu</th>');
  foreach($Line as $Index => $LineItem)
  {
   	echo('<td><a href="form.php?group='.$GroupId.'&amp;ID='.$LineItem['ID'].'">'.$LineItem['ID'].'</a></td>');
  }
  echo('</tr>');
  echo('<tr><th>Převzato</th>');
  foreach($Line as $Index => $LineItem)
  {
   	echo('<td><a href="form.php?group='.$GroupId.'&amp;ID='.$LineItem['Take'].'">'.$LineItem['Take'].'</a></td>');
  }
  echo('</tr>');
  echo('<tr><th>Jazyk</th>');
  foreach($Line as $Index => $LineItem)
  {
   	echo('<td>');
	WriteLanguagesWithoutSel($LineItem['Language']);
	echo('</td>');
  }
  echo('</tr>');
  echo('<tr><th>Verze</th>');
  foreach($Line as $Index => $LineItem)
  {
   	echo('<td>');
	echo (GetVersionWOW($LineItem['VersionStart']).' - '.GetVersionWOW($LineItem['VersionEnd']));
	echo('</td>');
  }
  echo('</tr>');
  foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
  {          
   	if($Line[0][$TextItem['Column']] <> '')
	{
   	  echo('<tr><th>'.$TextItem['Name'].'</th>');
	  for($i = 0; $i < count($Line); $i++)
	  {
      	if($i > 1)
		{
      	  echo('<td>');
      	  CompareString($Line[$i][$TextItem['Column']],$Line[$i - 1][$TextItem['Column']]);
		  echo('</td>');
		} else echo('<td>'.$Line[$i][$TextItem['Column']].'</td>');
      }
    echo ('</tr>');
    }
  }
  echo('</table>');  
} else 
{
  // include 'ListQuests.php';   
  echo('Nebylo zadáno ID <a href="index.php">zpět</a>');
}

ShowFooter();

?>   

