<?php
/*
+--------------------------------------------------------------------------
|   TanyaCMS - Question and Answer Sofware
|   -----------------------------------------------------------------------
|   by fbschool dev team
|   (c) 2011 - 2012 FBSCHOOL
|   http://www.fbschool.com/tanyacms
|   -----------------------------------------------------------------------
|   This is NOT a freeware, use is subject to license terms
|   Support: 13455n@gmail.com
+--------------------------------------------------------------------------
*/


if (!defined('IN_TANYACMS'))
{
	die;
}

class apply extends ASK_CONTROLLER
{

	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'black'; //Blacklist, blacklist check  'white' white list, outside the whitelist check
		$rule_action['actions'] = array();
		
		return $rule_action;
	}

	public function setup()
	{
	
	}

	function index_action()
	{
		$this->crumb('Apply for an account', '/account/apply/');
		
		TPL::import_css('css/login.css');
		
		TPL::assign('r_uname', HTTP::get_cookie('r_uname'));
		
		TPL::assign('return_url', $_SERVER['HTTP_REFERER']);
		
		TPL::output("account/apply");
	}

	function apply_ajax_action()
	{
		if ($this->model('account')->check_email($_POST['email']))
		{
			H::ajax_json_output(ASK_APP::RSM(array(
				'input' => 'email'
			), -1, "E-Mail has been used, or incorrect format"));
		}
		
		$length = strlen(iconv('UTF-8', 'gb2312', $_POST['reason']));
		
		if ($length < 20)
		{
			H::ajax_json_output(ASK_APP::RSM(array(
				'input' => 'reason'
			), -1, "The grounds must be greater than 10 characters"));
		}
		
		file_put_contents(ROOT_PATH . 'apply_list.txt', $_POST['email'] . "\t||\t" . $_POST['reason'] . "\n", FILE_APPEND);
		
		H::ajax_json_output(ASK_APP::RSM(null, 1, null));
	}
}