<?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
+--------------------------------------------------------------------------
*/

define('IN_AJAX', TRUE);


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

class ajax extends ASK_CONTROLLER
{
	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'white';
		
		$rule_action['actions'] = array();
		
		return $rule_action;
	}
	
	function setup()
	{
		HTTP::no_cache_header();
	}
	
	public function get_favorite_tags_action()
	{
		echo json_encode($this->model('favorite')->get_favorite_tags($this->user_id, 10));
	}
	
	public function update_favorite_tag_action()
	{
		if (rtrim($_POST['tags'], ',') == '')
		{
			H::ajax_json_output(ASK_APP::RSM(null, '-1', 'Please enter topic tag'));
		}
		
		$this->model('favorite')->add_favorite($_POST['answer_id'], $this->user_id);
		
		$this->model('favorite')->update_favorite_tag($_POST['answer_id'], $_POST['tags'], $this->user_id);
		
		H::ajax_json_output(ASK_APP::RSM(null, 1, null));
	}
	
	public function remove_favorite_item_action()
	{
		$this->model('favorite')->remove_favorite_item($_POST['answer_id'], $this->user_id);
		
		H::ajax_json_output(ASK_APP::RSM(null, 1, null));
	}
	
	public function remove_favorite_tag_action()
	{
		$this->model('favorite')->remove_favorite_tag($_POST['answer_id'], $_POST['tags'], $this->user_id);
		
		H::ajax_json_output(ASK_APP::RSM(null, 1, null));
	}
}