<?php
$set = Dever::input('set');
if (!$set) {
    $set = Dever::input('field');
}
if (is_string($set)) {
    $set = Dever::json_decode(html_entity_decode($set));
}
$info_id = $set['info_id'] ?? false;
$relation = array
(
    1 => '读取资源内容',
    3 => '手动上传',
);
$relation_id = array();
if ($info_id) {
    $info_value = Dever::db('info_value', 'source')->find(array('info_id' => $info_id));
    if ($info_value) {
        $relation = array
        (
            1 => '读取资源内容',
            2 => '读取资源附件',
            3 => '手动上传',
        );
        $relation_id = 'Dever::call("source/value.getList", array('.$info_id.'))';
    }
}

$content_version_show = false;
$content_version = array();
$content_default = '';
$id = Dever::input('id');
if ($id) {
    $info = Dever::db('info_data', 'source')->find(array('id' => $id));
    if ($info['info_data_content_id']) {
        $content_version_show = true;
        $content_version = Dever::db('info_data_content', 'source')->select(array('info_data_id' => $id));
        if ($content_version) {
            foreach ($content_version as &$v) {
                $v['name'] = date('YmdHis', $v['cdate']);
            }
        }
        $content_version[] = array('id' => -1, 'name' => '新增内容');
        $content_default = $info['info_data_content_id'];
    }
}


return array
(
    'source' => 'source/info_data',
    'list' => array
    (
        'where' => array('info_id' => $info_id),
        'field'      => array
        (
            'sort' => array
            (
                'type' => 'input',
            ),
            'name' => array
            (
                //'tip' => false,
            ),
            'type',
            //'relation',
            'status' => array
            (
                'type' => 'switch',
                'show'  => '{status}',
                'active_value' => 1,
                'inactive_value' => 2,
            ),
            'cdate',
        ),
        'button' => array
        (
            '新增' => array('fastadd', array('info_id' => $info_id)),
        ),
        'data_button' => array
        (
            '编辑' => array('fastedit', array('info_id' => $info_id)),
            //'详情' => array('view', 'set_zone_source/source_info_data?type=view&id=id'),
            '详情' => array('view', array
            (
                'path' => 'set_zone_source/source_info_data',
                'param' => array
                (
                    'type' => 'view',
                    'id' => 'id',
                    'set' => array('info_id' => $info_id, 'menu' => 'set_zone_source/source_info', 'parent' => 'set_zone_source/source_info'),
                ),
            )),
        ),
        'search'    => array
        (
            'name',
            'status',
        ),
    ),
    'update' => array
    (
        'control' => array
        (
            'relation_id' => array
            (
                'relation' => 2,
            ),
        ),
        //'desc' => '原创声明：',
        'field'    => array
        (
            'info_id' => array
            (
                'type' => 'hidden',
            ),
            'name' => array
            (
                'rules' => true,
            ),
            'type' => array
            (
                'rules' => true,
                'type' => 'radio',
            ),
            'relation' => array
            (
                'rules' => true,
                'type' => 'radio',
                'option' => $relation,
            ),
            'relation_id' => array
            (
                'name' => '资源附件',
                'type' => 'select',
                'option' => $relation_id,
            ),
            'content_version' => array
            (
                'show' => $content_version_show,
                'name' => '切换内容版本',
                'type' => 'select',
                'option' => $content_version,
                'default' => $content_default,
            ),
        ),
        # update提交之后的操作
        'start' => 'source/data.updateStart',
        'end' => 'source/data.update',
    ),

    # 详情页配置
    'view' => 'source/data.getView',
);