<?php

/**
 * 
 * 本类为专题定制管理操作
 * @author 杨金球
 *
 */
class CustomAction extends CommonAction {

    public function index() {
        $id = C('HOME_CUSTOMACTION_ID');
        $this->menu_index($id);
        $this->display('Common:index');
    }

    //获取类别选项
    public function get_cat_msg() {
        $map['id'] = $_GET['id'];
        $menu = M('menu');

        $menu_msg = $menu->field('recommend, `show`, picture')->where($map)->find();

        if ($menu_msg) {
            $this->ajaxReturn($menu_msg, '', 1);
        } else {
            $this->ajaxReturn('', '', 0);
        }
    }

    //上传图片
    public function upload_preview() {
        $size = 200000; //大小限制200K
        $ext = array('jpg', 'gif', 'png', 'jpeg');
        $path = './Public/Upload/category/';
        $name = "cat_";
        $maxwidth = 665;
        $maxheight = 90;

        $info = $this->upload($size, $ext, $path, $name, $maxwidth, $maxheight);

        if ($info[0] == 0) {
            $this->ajaxReturn('', $info[1], 0);
        } else {
            $this->ajaxReturn('', $name . $info[0]['savename'], 1);
        }
    }

    //定制专题列表中的功能（是否推荐，是否在首页显示）
    public function update_cat_msg() {
        $map['id'] = $_GET['id'];
        $map['recommend'] = 0;
        $map['show'] = 0;

        if (isset($_POST['subject_recommend']) && $_POST['subject_recommend'] == 'on') {
            $map['recommend'] = 1;
        }

        if (isset($_POST['subject_show']) && $_POST['subject_show'] == 'on') {
            $map['show'] = 1;
        }

        $map['picture'] = $_POST['preview_img_name'];

        $menu = M('menu');

        if (!$menu->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            F('Subject_recommend/recommend_list', NULL);    //清空专题推荐缓存
            F('Subject_show/list', NULL); //清空专题显示缓存
            $this->ajaxReturn('', '', 1);
        }
    }

}