<?php
# CmsEasy Enterprise Content Management System
# Copyright (C) CmsEasy Co.,Ltd (https://www.CmsEasy.cn). All rights reserved.
if (!defined('ROOT')) exit('Can\'t Access !');

class table_type extends table_mode
{
    function vaild()
    {
        if (!front::post('typename') && !front::post('batch_add') ) {
            front::flash(lang_admin('fill_in_the_category_title_etc'));
            return false;
        }
        if (!front::post('htmldir'))
            front::$post['htmldir'] = pinyin::get2(front::post('typename'));
        return true;
    }

    function view_before(&$data = null)
    {
        $rank = new rank();
        $rank = $rank->getrow('typeid=' . front::get('id'));
        if (is_array($rank))
            $data['_ranks'] = unserialize($rank['ranks']);
        else $data['_ranks'] = array();
        unset($data['ranks']);
    }

    function save_after($typeid = '')
    {
        if (front::$post['_ranks']) {
            $_ranks = serialize(front::post('_ranks'));
            $rank = new rank();
            if (is_array($rank->getrow(array('typeid' => front::get('id')))))
                $rank->rec_update(array('ranks' => $_ranks), 'typeid=' . $typeid);
            else
                $rank->rec_insert(array('typeid' => front::get('id'), 'ranks' => $_ranks));
        } else {
            $rank = new rank();
            $rank->rec_delete('typeid=' . $typeid);
        }

        //保存之后 自动生成
        cache_make::get_make_type($typeid,false);
    }

    function save_before()
    {
        if (front::$post['htmlrule1'] != '') {
            front::$post['htmlrule'] = front::$post['htmlrule1'];
        }
        if (front::$post['listhtmlrule1'] != '') {
            front::$post['listhtmlrule'] = front::$post['listhtmlrule1'];
        }
        front::$post['typecontent'] = stripcslashes(htmlspecialchars_decode(front::$post['typecontent']));
        front::$post['module'] = 'article';
    }

    function delete_before($id = '')
    {
       /* $typeid = intval(front::$get['id']);
        $where = "typeid = '$typeid'";
        $arc = new archive();
        $arc->rec_delete($where);*/
        if (config::get("cache_make_open")){
        $cache_path = type::url($id, front::$get['page'] > 1 ? front::$get['page'] : 1, lang::getisadmin(),false);
        $cache_path = type::url_rule($cache_path);
        $cache_path=str_replace('.html','.php',$cache_path);
        $cache_path=dirname($cache_path);
            if ($cache_path!=ROOT){
                front::remove($cache_path);
            }
        }
    }

    function edit_before(){
        //修改模板触发清空可视化缓存
        if (front::post('template') && front::get('id')) {
            $type = new type();
            $type_data = $type->getrow(array("typeid"=>front::get('id')));
            if($type_data['template']!=front::post('template')){
                front::remove(ROOT.'/cache/template_admin');
            }
        }
    }

}
# This program is an open source system, commercial use, please consciously to purchase commercial license.
# Copyright (C) CmsEasy Co., Ltd. (https://www.CmsEasy.cn). All rights reserved.