Exemplo n.º 1
0
function m__save_message()
{
    global $dbm, $table_name;
    $table_name = "message";
    if (isset($_SESSION['postdata']['message']) && time() - $_SESSION['postdata']['message'] < 60) {
        die('{"code":"101","msg":"歇会再留言吧"}');
    }
    //查询该独立模型字段
    $sql = "select * from " . TB_PREFIX . "extern_fields where extern_name = '" . $table_name . "'";
    $querys = $dbm->query($sql);
    $fields = array();
    //判断字段输入是否合法
    foreach ($querys['list'] as $v) {
        $fields[$v['field']] = isset($_POST['extern___' . $v['field']]) ? $_POST['extern___' . $v['field']] : '';
        $extern = get_field_remark($table_name, $v['field']);
        //获取特殊字段说明
        if (!empty($extern)) {
            check_field($extern, $fields[$v['field']]);
        }
        //验证合法性
    }
    $fields['create_time'] = time();
    //print_r($fields);die;
    //插入数据
    $ret = $dbm->single_insert(TB_PREFIX . $table_name, $fields);
    //print_r($ret);
    if ($ret['error'] == '' && $ret['autoid'] > 0) {
        //如果开启了留言到邮箱,就发送一封邮件到绑定的邮箱
        if (MESSAGE_EMAIL != '') {
            $countent = "电话:" . @$fields['phone'] . " \r\n<br> 留言内容:" . @$fields['content'] . " \r\n<br> QQ号:" . @$fields['qq'] . " \r\n<br> 性别:" . @$fields['gender'];
            @helper::send_email($fields['nick_name'], MESSAGE_EMAIL, $fields['nick_name'] . "的留言", $countent);
        }
        $_SESSION['postdata']['message'] = time();
        die('{"code":"0","msg":"留言成功,我们会尽快联系您"}');
    } else {
        die('{"code":"100","msg":"留言失败"}');
    }
}
Exemplo n.º 2
0
function m__save()
{
    global $dbm, $c;
    check_level($_POST['alone_table'] . "_01");
    $params = array();
    if (!isset($_POST['alone_table']) || empty($_POST['alone_table'])) {
        die('{"code":"210","msg":"独立表异常!"}');
    }
    unset($_POST['hashtoken']);
    foreach ($_POST as $k => $v) {
        $k = str_replace('extern___', '', $k);
        $params[$k] = helper::escape($v, 1);
        $params[$k] = isset($params[$k]) && !empty($params[$k]) ? trim($params[$k]) : '';
        $extern = get_field_remark($_POST['alone_table'], $k);
        //获取特殊字段说明
        if (!empty($extern)) {
            check_field($extern, $v);
        }
        //验证合法性
    }
    $ext_tb = $params['alone_table'];
    $ext_sql = "select * from " . TB_PREFIX . "extern_fields where extern_name='{$ext_tb}'";
    $ext_data = $dbm->query($ext_sql);
    if (count($ext_data['list']) > 0) {
        $extern_attr_content = $ext_data['list'];
        foreach ($extern_attr_content as $attr) {
            foreach ($params as $k => $v) {
                // 判断独立表的字段类型,日期类型进行数据转换
                if ($k == $attr['field'] && $attr['form_type'] == 'date') {
                    $params[$k] = strtotime($v);
                }
            }
        }
    }
    if ($_POST['info_id'] == '' || $_POST['info_id'] == '0') {
        unset($params['reso']);
        unset($params['info_id']);
        unset($params['alone_table']);
        $params['create_time'] = time();
        //添加记录
        $table = $_POST['alone_table'];
        $ret = $dbm->single_insert(TB_PREFIX . $table, $params);
        if ($ret['error'] == '') {
            die('{"code":"0","msg":"添加成功"}');
        }
        die('{"code":"210","msg":"添加失败"}');
        /*
        		print_r($params);
        		die();*/
    } else {
        //更新记录
        if (!is_numeric($_POST['info_id'])) {
            die('{"code":"220","msg":"ID必须是数字"}');
        }
        $id = intval($_POST['info_id']);
        $table_name = $_POST['alone_table'];
        unset($params['reso']);
        unset($params['info_id']);
        unset($params['alone_table']);
        $where = "{$table_name}_id = {$id}";
        $ret = $dbm->single_update(TB_PREFIX . $table_name, $params, $where);
        //print_r($ret); die();
        if ($ret['error'] != '') {
            die('{"code":"230","msg":"更新失败"}');
        }
        die('{"code":"0","msg":"更新成功"}');
    }
}