<?php
session_start();
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
	#define("root",  getcwd());
}
require(root."/_common.php");
require(root."/_lib/db.php");
require(root."/_lib/main.php");
$ca=cekpost(cleanQuery($_GET["a"]), "");
if ($ca=="daftar") {
	$liste = '0123456789';
	$code = '';
	while(strlen($code) != 6) {
	   $code .= $liste[rand(0,strlen($liste)-1)];
	}

	$_SESSION['turney-code-daftar']=$code;
	$img = imagecreatetruecolor(100, 30) or die("Problem with GD creation");
	$background_color = imagecolorallocate ($img, 255, 255, 255);
	$ecriture_color = imagecolorallocate ($img, 0, 0, 0);
	$code_police=5;
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Cache-Control: no-store, no-cache, must-revalidate');
	header('Cache-Control: post-check=0, pre-check=0', false);
	header("Content-type: image/gif");

	$font = $_SERVER['DOCUMENT_ROOT'].'/_ttf/PURIBI10.TTF';
	$black[0] = imagecolorallocate($img, 224, 221, 214);
	$black[1] = imagecolorallocate($img, 139, 129, 105);
	$b = 5;
	for($i=0;$i!=6;$i++){
		($i%2 == 0) ? $j = 0 : $j = 1;
		$y = rand(20,25);
		imagettftext($img, 16, 0, $b+2, $y+1, $black[1], $font, $code[$i]);
		imagettftext($img, 16, 0, $b, $y, $black[0], $font, $code[$i]);
		$b+=16;
	}
	imagegif($img);
	imagedestroy($img);
}
if ($ca=="reload") {
	$liste = '0123456789';
	$code = '';
	while(strlen($code) != 6) {
	   $code .= $liste[rand(0,strlen($liste)-1)];
	}
	$_SESSION['turney-code-reload']=$code;
	$img = imagecreatetruecolor(100, 30) or die("Problem with GD creation");
	$background_color = imagecolorallocate ($img, 255, 255, 255);
	$ecriture_color = imagecolorallocate ($img, 0, 0, 0);
	$code_police=5;
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	header('Cache-Control: no-store, no-cache, must-revalidate');
	header('Cache-Control: post-check=0, pre-check=0', false);
	header("Content-type: image/gif");

	$font = $_SERVER['DOCUMENT_ROOT'].'/_ttf/PURIBI10.TTF';
	$black[0] = imagecolorallocate($img, 224, 221, 214);
	$black[1] = imagecolorallocate($img, 139, 129, 105);
	$b = 5;
	for($i=0;$i!=6;$i++){
		($i%2 == 0) ? $j = 0 : $j = 1;
		$y = rand(20,25);
		imagettftext($img, 16, 0, $b+2, $y+1, $black[1], $font, $code[$i]);
		imagettftext($img, 16, 0, $b, $y, $black[0], $font, $code[$i]);
		$b+=16;
	}
	imagegif($img);
	imagedestroy($img);
}

?>