<?php
// +----------------------------------------------------------------+
// | step5.php														|
// |																|
// | Function: Registration                     					|
// +----------------------------------------------------------------+
// | Source-code (C) CalaCode.com 1998-2009 . All rights reserved	|
// | See http://calacode.com/license.ehtml for license agreement	|
// +----------------------------------------------------------------+
// | Date: May 2009													|
// +----------------------------------------------------------------+

set_include_path(get_include_path() . PATH_SEPARATOR . '../' . PATH_SEPARATOR . "../application/models/");
require_once('../application/models/license.php');

// Make sure we are included from install/index.php, exit if not
if (!defined('ATMAIL_INSTALL_SCRIPT')) {
	// link to installer
	die("You cannot request this file directly, please use <a href=\"index.php\">the installer</a>");
}

// Webmail client is standalone
$_SESSION['pref']['install_type'] = "standalone";
$_SESSION['pref']['allow_Signup'] = "0";

// Required for PHP5, otherwise template values to evaluate
$errors = array();
$vars['invalid'] = false;
$vars['hostname'] = false;
$vars['downloadid'] = false;
$vars['serial'] = false;


// If the form from Step 5 has been submitted
// we need to process it
if (isset($_POST['submit'])) {

	// Verify the submitted data

	$atmailMode = $_POST['mode'];

	$_SESSION['reg']['downloadId'] = $d = $_POST['downloadid'];
	$_SESSION['reg']['serialKey'] = $YHIIhijjHUIG65765ghiHHikUtFGUhjFdf = $sgggc346ctfguc3gefhcb3ruycuyrcg3ygrbcfuy3brgb = $_POST['serial'];

	$dbConfig = new Zend_Config_Ini('../config/dbconfig.ini', 'production');
	Zend_Registry::set('dbConfig', $dbConfig);
	$dbAdapter = Zend_Db::Factory($dbConfig->database);
	$dbAdapter->query("SET NAMES 'utf8'");
	Zend_Db_Table::setDefaultAdapter($dbAdapter);
	Zend_Registry::set('dbAdapter', $dbAdapter);
	//Get main configuration from database
	$config = new Atmail_Config_Mysql($dbConfig, true);
	Zend_Registry::set('config', $config);

	unset($vars['invalid']);
	try
	{
		license::add($_SESSION['reg']['downloadId'], $_SESSION['reg']['serialKey']);
	}
	catch(Exception $e)
	{
		$errors = array($e->getMessage());
		$vars['invalid'] = true;
	}
	if (!count($errors))
		gotoStep(6);
}

$vars['regurl'] = "http://atmail.com/register-license.php";

// Print the Step 5 page if no data submitted yet
// or there were errors in submitted data
$vars['output'] = parse("$htmlPath/step5.phtml", array_merge($vars, $errors));
