<?php

/**
 *--------------------------------------
 * 链接
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-11-05
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

class FlinkCtrlr extends IndexCtrlr
{
	public function list_flink()
	{
		$this->assign('POSITION', '<a href="'.__APP__.'">'.L('HOME').'</a> &raquo; '.L('FLINK'));

		$_FCL = M('FlinkCategory')->get_categoryList();
		foreach($_FCL as $k => $fc)
		{
			$_FCL[$k]['flink'] = F('~list/~flink_list_'.$fc['flink_category_id']);
			if(empty($_FCL[$k]['flink']))
			{
				$where = array();
				$where['__FLINK__.f_status'] = array('EQ', 1);
				$where['__FLINK__.flink_category_id'] = array('EQ', $fc['flink_category_id']);
				$_FCL[$k]['flink'] = M('Flink')->get_flinkList($where);
				F('~list/~flink_list_'.$fc['flink_category_id'], $_FCL[$k]['flink']);
			}
		}

		$this->assign('_L', $_FCL);

		$this->display('home/list_flink');
	}

	public function apply_flink()
	{
		$this->assign('POSITION', '<a href="'.__APP__.'">'.L('HOME').'</a> &raquo; '.L('APPLY_FLINK'));

		$this->display('home/apply_flink');
	}

	public function apply_flink_do()
	{
		check_interaction('feedback');

		$data = array();
		$data['f_site_name'] = AFilter::plain_text(ARequest::get('f_site_name'), 32);
		$data['f_site_url'] = AFilter::text(ARequest::get('f_site_url'), 255);
		$data['f_site_logo'] = AFilter::text(ARequest::get('f_site_logo'), 255);
		$data['f_webmaster_email'] = AFilter::text(ARequest::get('f_webmaster_email'), 255);
		$data['f_site_description'] = AFilter::text(ARequest::get('f_site_description'), 500);
		$data['f_status'] = 0;
		$data['flink_category_id'] = 0;

		$result = M('Flink')->add_flink($data);

		if(!empty($result['error']))
		{
			$this->error($result['error'], Url::U('home@flink/list_flink'));
		}
		$this->success(L('APPLY_SUCCESS'), Url::U('home@flink/list_flink'));
	}
}


?>