<?php
	require_once "class/resizeimage.php";

	session_start();

	// generate 4 digit code
	$totalnum = 4;
	$codes = '';
	for ($i = 0; $i < $totalnum; $i++){
		$randchar = rand(1,3);
		do {
			switch ($randchar){
				case 1 : $realrand = rand(49,57);break;
				case 2 : $realrand = rand(65,90);break;
				case 3 : $realrand = rand(97,122);break;
			}
		}
		while ($realrand == 79 || $realrand == 111 || $realrand == 108 || $realrand == 105);
		$codes .= chr($realrand);
	}

	// create the hash for the random number and put it in the session
	if (empty($_GET['from'])){
		$_SESSION['sc_code'] = md5(strtolower($codes));
	}
	else if ($_GET['from'] == 'login'){
		$_SESSION['sc_code_login'] = md5(strtolower($codes));
	}
	else if ($_GET['from'] == 'contact'){
		$_SESSION['sc_code_contact'] = md5(strtolower($codes));
	}

	$bg = $_GET['bg'];
	if (empty($bg)){
		$bg = 'box_black_small';
		$color = 'FFFFFF';
		$width = 53;
		$height = 26;
		$fontsize = 10;
		$top = 17;
	}
	else{
		$color = 'FFFFFF';
		$width = 75;
		$height = 30;
		$fontsize = 12;
		$top = 20;
	}
	
	$p = new photo(array('images/'.$bg.'.png'));
	$p->resizeImageP($width,$height);
	$p->addwatermark($codes,'incl/arial.ttf',$color,'FFFFFF',$fontsize,'center',0,$width,$height,$top,0);

	// Date in the past
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

	// always modified
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

	// HTTP/1.1
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);

	// HTTP/1.0
	header("Pragma: no-cache");

	$p->outputimage();
?>