<?php

/**
 * 后台专题管理模块 Controller
 * ============================================================================
 * zhuna_php 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: special.php 4 2011-11-02 11:02:08Z zhangwentao $
 * http://un.zhuna.cn；
 */
class specialAction extends Action
{

    private $tmp_model;

    /**
     * _init 方法 在执行任何Action前执行
     */
    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->tmp_model = Tmac::model('special');
        $check_model = $this->M('check');
        $check_model->checkLogin();
        $check_model->CheckPurview('zhuna_admin');
    }

    /**
     * 专题管理 首页
     */
    public function index()
    {
        //TODO  取出所有专题
        $rs = $this->tmp_model->getSpecialList();
        $this->assign('rs', $rs);
        $this->V('special');
    }

    /**
     * 修改专题
     */
    public function edit()
    {
        $info = array();
        $info['id'] = $_POST['id'];
        $info['name'] = $_POST['name'];
        $info['img'] = $_POST['img'];
        $info['link'] = $_POST['link'];
        $info['xmlname'] = $_POST['xmlname'];

        if (!isset($info['id']) || empty($info['name']) || empty($info['img']) || empty($info['link']) || empty($info['xmlname'])) {
            $data = array('rs'=>0);
        } else {
            $rs = $this->tmp_model->editSpecial($info);            
            if ($rs) {
                if ($info['id'] == 2) {
                    $data = array('rs'=>2);;    //del
                } else {
                    $data = array('rs'=>1);;    //sucess
                }
            } else {
                $data = array('rs'=>0);;    //false
            }
        }
        $rs = json_encode($data);
        exit($rs);
        /*
          $file_info = var_export($rs, true);
          $ok = file_put_contents(TMAC_ROOT . "/file_info.txt", $file_info);
          if ($ok)
          exit('true');
          exit('false');
         */
    }

}