<?php
/**
 *
 * @author min晓天
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
//小区管理
global $_GPC,$_W;
$op  = trim($_GPC['op']) ? trim($_GPC['op']) : 'cate_list';
if ($op == 'cate_list') {
    $condition      = ' uniacid = :aid ';
    $params[':aid'] = $_W['uniacid'];
    if (!empty($_GPC['keyword'])) {
        $condition .= " AND title LIKE '%{$_GPC['keyword']}%'";
    }
    $pindex = max(1, intval($_GPC['page']));
    $psize  = 20;
    $total  = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_community') . ' WHERE ' . $condition, $params);
    $lists  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_community') . ' WHERE ' . $condition . ' ORDER BY displayorder DESC,id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params, 'id');
    $pager = pagination($total, $pindex, $psize);
    if (checksubmit('submit')) {
        if (!empty($_GPC['ids'])) {
            foreach ($_GPC['ids'] as $k => $v) {
                $data = array(
                    'title' => trim($_GPC['title'][$k]),
                    'displayorder' => intval($_GPC['displayorder'][$k])
                );
                pdo_update('evzg_express_community', $data, array(
                    'uniacid' => $_W['uniacid'],
                    'id' => intval($v)
                ));
            }
            message('编辑成功', $this->createWebUrl('community', array(
                'op' => 'cate_list'
            )), 'success');
        }
    }
    include $this->template('community');
}elseif($op == 'cate_post'){
    load()->func('tpl');
    $id =$_GPC['id']; 
    $result = pdo_fetch("SELECT * FROM".tablename("evzg_express_community")."WHERE uniacid='{$_W['uniacid']}' AND id='{$id}' ");
    if (checksubmit('submit')) {
        if (!empty($_GPC['title'])) {
           
            foreach ($_GPC['title'] as $k => $v) {
                $v = trim($v);
                if (empty($v))
                    continue;
                $data['uniacid']      = $_W['uniacid'];
                $data['thumb']        = $_GPC['thumb'][$k];
                $data['title']        = $v;
                $data['displayorder'] = intval($_GPC['displayorder'][$k]);
                if(empty($id)){
                   pdo_insert('evzg_express_community', $data);
                }else{
                    pdo_update('evzg_express_community', $data,array('id'=>$id));
                }
            }
        }
        message('添加小区成功', $this->createWebUrl('community', array(
            'op' => 'cate_list'
        )), 'success');
    }
    include $this->template('community');
}elseif ($op == 'cate_del') {
    $id = intval($_GPC['id']);
    pdo_delete('evzg_express_community', array(
        'uniacid' => $_W['uniacid'],
        'id' => $id
    ));
    message('删除小区成功', $this->createWebUrl('community', array(
        'op' => 'cate_list'
    )), 'success');
}