qc.ifish7.com/Application/Admin/Controller/FeedbackFieldController.cla...

112 lines
4.5 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class FeedbackFieldController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("FeedbackField");
//字段类型
$this->fieldtype_inc=array(
"varchar"=> "字符型0-255字节(varchar)",
"char"=> "定长字符型0-255字节(char)",
"text"=> "小型字符型(text)",
"mediumtext"=> "中型字符型(mediumtext)",
"longtext"=> "大型字符型(longtext)",
"tinyint"=> "小数值型(tinyint)",
"smallint"=> "中数值型(smallint)",
"int"=> "大数值型(int)",
"bigint"=> "超大数值型(bigint)",
"float"=> "数值浮点型(float)",
"double"=> "数值双精度型(double)",
"date"=> "日期型(date)",
"datetime"=> "日期时间型(datetime)",
);
//表单类型
$this->formtype_inc=array(
"text"=> "单行文本框(text)",
"password"=> "密码框(password)",
"select"=> "下拉框(select)",
"radio"=> "单选框(radio)",
"checkbox"=> "复选框(checkbox)",
"textarea"=> "多行文本框(textarea)",
"date"=> "日期(date)",
);
//常用正则
$this->pattern_inc=array(
"/^[0-9.-]+$/"=> "数字",
"/^[0-9-]+$/"=> "整数",
"/^[a-z]+$/i"=> "字母",
"/^[0-9a-z]+$/i"=> "数字+字母",
"/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/"=> "E-mail",
"/^[0-9]{5,20}$/"=> "QQ",
"/^http:\/\//"=> "超级链接",
"/^(1)[0-9]{10}$/"=> "手机号码",
"/^[0-9-]{6,13}$/"=> "电话号码",
);
//系统字段(禁止删除)
$this->systemfield_inc=array("title","name","mobile","email");
}
public function index(){
$this->pagetitle="字段管理";
$data=$this->table->order('sort asc,field_id asc')->select();
$this->tableName=M("table")->where(array("table_id"=>$this->table_id))->getField("table_name");
$this->assign("data",$data);
$this->display();
}
public function add(){
$this->pagetitle="添加字段";
if(IS_POST){
if (!$this->table->create()){//验证
$this->error($this->table->getError());
}
$result=$this->table->data_add();
D("UserLog")->add("add",$this->table->getTableName(),$result);
if(!$result){
$this->error($this->table->getError());
}
$this->success($result);
}else{
$this->display();
}
}
public function editor(){
$this->pagetitle="编辑字段";
if(IS_POST){
if (!$this->table->create()){//验证
$this->error($this->table->getError());
}
$result=$this->table->data_editor();
if(!$result){
$this->error($this->table->getError());
}
D("UserLog")->add("add",$this->table->getTableName(),$result[field_id]);
$this->success($data);
}else{
$field_id=I("get.field_id",0,"int");
$r=$this->table->find($field_id);
$this->assign("r",$r);
$this->display();
}
}
//删除
public function delete(){
$field_id=I("field_id",0,'intval');
$result=$this->table->data_delete($field_id,$this->systemfield_inc);
if(!$result){
$this->error($this->table->getError());
}
D("UserLog")->add("delete",$this->table->getTableName(),$field_id);
$this->success("删除成功");
}
//字段排序
public function sort(){
$filed_id=I("filed_id");
$sort=I("sort");
foreach($filed_id as $key=>$id){
$data['field_id']=(int)$id;
$data['sort']=(int)$sort[$key];
$this->table->save($data);
}
$this->success("排序更改成功");
}
}