<?php
/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class TopController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
	var $name = 'top';
	public $uses = array('ContactValidate');
	public $layout = 'top';

	function beforeFilter(){
		$this->Auth->allow();
	}
/**
 * index
 */
	public function index() {
	}
/**
 * privacy_policy
 */
	public function privacy_policy() {
	}
/**
 * kiyaku
 */
	public function kiyaku() {
	}
/**
 * about
 */
	public function about() {
	}
/**
 * company
 */
	public function company() {
	}
/**
 * contact
 */
	public function contact() {
		if($this->request->is('post') || $this->request->is('put')){
			$this->ContactValidate->set($this->request->data);
			if($this->ContactValidate->validates()){
				$this->Session->write('contact',$this->request->data);
				$this->redirect(array('action'=>'contact_confirm'));
			}else{
			}
		}
	}
/**
 * contact_confirm
 */
	public function contact_confirm() {
		if($this->Session->read('contact')){
			$this->set('contact',$this->Session->read('contact'));
		}else{
			$this->redirect(array('action'=>'contact'));
		}
	}
/**
 * contact_complete
 */
	public function contact_complete() {
		$this->set('contact',$this->Session->read('contact'));
		$name = $this->Session->read('contact.ContactValidate.name');
		$mail = $this->Session->read('contact.ContactValidate.mail');
		$comment = $this->Session->read('contact.ContactValidate.comment');
		$Email = new CakeEmail();
		$Email->charset('ISO-2022-JP');
		$Email->emailFormat('text');
		$Email->template('user_contact');
		$Email->viewVars(array('name'=>$name,'comment'=>$comment));
		$Email->from($mail);
		$Email->to('yano@i-hearts.jp');
		$Email->subject('[PICT CODE]問い合わせ');
		$Email->send();
	}
}
