<?

if (stristr($_SERVER["SERVER_NAME"], 'bbquiz'))
{

	$sw_domain = 'bbquiz.co.uk';
	$t_id = 2;
	
	
}
else if (stristr($_SERVER["SERVER_NAME"], 'christmas'))
{

	$sw_domain = 'the-christmas-quiz.com';
	$t_id = 3;
	
	
}
else if (stristr($_SERVER["SERVER_NAME"], 'music'))
{

	$sw_domain = 'the-music-quiz.com';
	$t_id = 4;
	
	
}
else
{
	$sw_domain = 'general-knowledge-quiz.co.uk';
	$t_id = 1;

}





header ("Content-type: text/xml");

print '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://<?echo $sw_domain;?></loc>
      <changefreq>weekly</changefreq>
   </url>
   <?
   if ($t_id == 1)
   {
   ?>
   <url>
      <loc>http://<?echo $sw_domain;?>/about</loc>
      <changefreq>monthly</changefreq>
   </url>
   <url>
      <loc>http://<?echo $sw_domain;?>/help</loc>
      <changefreq>monthly</changefreq>
   </url>


   <?
   }
   elseif ($t_id == 3)
   {
   ?>
   <url>
      <loc>http://<?echo $sw_domain;?>/about_the_christmas_quiz</loc>
      <changefreq>monthly</changefreq>
   </url>
   <url>
      <loc>http://<?echo $sw_domain;?>/christmas_quiz_help</loc>
      <changefreq>monthly</changefreq>
   </url>


   <?
   }
    elseif ($t_id == 4)
   {
   ?>
   <url>
      <loc>http://<?echo $sw_domain;?>/about_the_music_quiz</loc>
   </url>
   <url>
      <loc>http://<?echo $sw_domain;?>/music_quiz_help</loc>
    </url>


   <?
   }
  

$mysqli = new mysqli("localhost", "dsavings", "fred64y!", "dsavings");
$mysqli->query("SET NAMES 'utf8'");




class base62 
{
	static $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	static $base = 62;

	public function encode($var) 
	{
		$stack = array();
		while (bccomp($var, 0) != 0)
		{
			$remainder = bcmod($var, self::$base);
			$var = bcdiv( bcsub($var, $remainder), self::$base );
	
			array_push($stack, self::$characters[$remainder]);
		}
	
		return implode('', array_reverse($stack));
	}
	
	public function decode($var) 
	{
		$length = strlen($var);
		$result = 0;
		for($i=0; $i<$length; $i++) 
		{
			$result = bcadd($result, bcmul(self::get_digit($var[$i]), bcpow(self::$base, ($length-($i+1)))));
		}
	
		return $result;
	}
	
	private function get_digit($var) 
	{
		return strpos(self::$characters, $var);
	}
}

$query = "SELECT q_id, q_text FROM questions WHERE q_tid=" . $t_id;
$result = $mysqli->query($query); 

while($line = $result->fetch_object())
{

$x = base62::encode($line->q_id+3700);

?>  
   <url>
      <loc>http://<?echo $sw_domain;?>/<?echo $x;?></loc>
   </url>
   <?
   }
   ?>
</urlset>


