RegAction.class.php
7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
class RegAction extends CommonAction {
public $tab;
public $notDel;
public $jsArr;
public function __construct() {
parent::__construct();
$this->tab='Regfields';
$this->notDel=C('FIELDNOTDEL');
$this->jsArr=C('JSCOMPONENT');//js组件数组
}
public function index(){
$System=D($this->tab);
if($this->isPost()){
$_POST['name']=array2single($_POST['name'],true);
foreach($_POST['name'] as $k=>$v){
$arr_id=explode('_',$k);
// $data['rownum']=I('rownum_'.$arr_id[1]);
// $data['colnum']=I('colnum_'.$arr_id[1]);
$data['sort']=I('sort_'.$arr_id[1]);
$lastid=$System->where('id='.$arr_id[1])->save($data);
//$f=$this->addColumn($v,I('type_'.$arr_id[1]),I('description_'.$arr_id[1])); // wa_apply表添加不存在的字段
}
$this->success('字段信息更改成功',U('Reg/index'));
}else{
// $where['isshow']=array('eq',1);
$list=$System->order('sort asc,id asc')->select();
$this->assign('lists',$list);
$this->assign('notDel',$this->notDel);
$this->display();
}
}
/**
* 添加报名应填报信息
*/
public function add()
{
if($this->isPost()){
$Config=D($this->tab);
if($Config->create())
{
$field=$Config->name; //字段名
$type=$Config->type; //字段类型
$description=$Config->description.':'.$Config->note; //字段注释
$lastid=$Config->add();
if($lastid)
{
$f=$this->addColumn($field,$type,$description);// wa_apply表添加不存在的字段
$this->success('字段添加成功',U('Reg/index'));
}
else
$this->error('字段添加失败');
}
else
{
$this->error($Config->getError());
}
exit;
}
$this->assign('jsarr',$this->jsArr);
$this->display();
}
/**
* 修改学生申请应填写字段信息
*/
public function edit(){
$id=I('id');
if(!$id) exit('<script>alert("参数有误!");history.back();</script>');
$Config=D($this->tab);
if($this->isPost()){
if($Config->create())
{
$field=$Config->name; //字段名
$type=$Config->type; //字段类型
$description=$Config->description.':'.$Config->note; //字段注释
$lastid=$Config->save();
if($lastid)
{
$f=$this->editColumn($field,$type,$description);// wa_apply表添加不存在的字段
$this->success('字段修改成功',U('Reg/index'));
}
else
$this->error('字段修改失败');
}
else
{
$this->error($Config->getError());
}
exit;
}
$where['id']=array('eq',$id);
$fdata=$Config->where($where)->find();
$this->assign('fdata',$fdata);
$this->assign('jsarr',$this->jsArr);
$this->display();
}
public function delete(){
$m=M($this->tab);
if(!$id=(int)I('id')) exit('<script>alert("参数有误!");history.back();</script>');
$where['id']=array('eq',$id);
$name=$m->where($where)->getField('name');
if(in_array($name,$this->notDel)){
$this->error('该信息不可删除!');
exit;
}
if($name){
$r=$m->where($where)->delete(); //删除字段记录
if($r){
$this->deleteColumn($name); //删除wa_apply表中字段
$this->success('删除成功!',U('index'));
}else{
$this->error('删除失败!');
}
}else{
$this->error('信息不存在!');
}
}
/**
* 添加wa_apply表字段
* @param fieldName 字段名
* @param type 字段类型
* @param description 字段注释
*/
private function addColumn($fieldName,$type,$description){
//修改申请wa_apply表结构
import('ORG.Util.MysqlManage');
$mg=new MysqlManage();
$f=null;
if(!$mg->checkField('wa_apply',$fieldName)){ //判断字段是否存在
$info['name']=$fieldName;
$info=array_merge($info,$this->getExinfo($type,$description)); //获取字段信息 type length isNull default comment
$f=$mg->addField('wa_apply',$info);
}
unset($mg);
return $f;
}
/**
* 修改wa_apply表字段
* @param fieldName 字段名
* @param type 字段类型
* @param description 字段注释
*/
private function editColumn($fieldName,$type,$description){
//修改申请wa_apply表结构
import('ORG.Util.MysqlManage');
$mg=new MysqlManage();
$f=null;
$info['name']=$fieldName;
$info=array_merge($info,$this->getExinfo($type,$description)); //获取字段信息 type length isNull default comment
if($mg->checkField('wa_apply',$fieldName)){ //判断字段是否存在
$f=$mg->editField('wa_apply',$info); //存在修改
}else{
$f=$mg->addField('wa_apply',$info); //不存在添加
}
unset($mg);
return $f;
}
/**
* 删除wa_apply表字段
* @param fieldName 字段名
* @return bool
*/
private function deleteColumn($fieldName){
import('ORG.Util.MysqlManage');
$mg=new MysqlManage();
$f=true;
if($mg->checkField('wa_apply',$fieldName)){ //判断字段是否存在
$f=$mg->dropField('wa_apply',$fieldName); //删除字段
}
unset($mg);
return $f;
}
/**
* 获取字段信息 type length isNull default comment
* @param type 字段类型
* @param description 注释
*/
private function getExinfo($type,$description){
switch($type){
case 'string':
$info['type']='varchar';
$info['length']='300';
$info['isNull']=2; //是否为空 1为空,2不为空
$info['default']='""';
$info['comment']=$description;
break;
case 'bstring':
$info['type']='text';
$info['length']='';
$info['isNull']=1;
$info['default']='';
$info['comment']=$description;
break;
case 'bool':
$info['type']='tinyint';
$info['length']='1';
$info['isNull']=2;
$info['default']=0;
$info['comment']=$description;
break;
case 'number':
$info['type']='int';
$info['length']='11';
$info['isNull']=2;
$info['default']=0;
$info['comment']=$description;
break;
case 't_extarea':
$info['type']='text';
$info['length']='';
$info['isNull']=1;
$info['default']='';
$info['comment']=$description;
break;
case 's_elect':
$info['type']='varchar';
$info['length']='120';
$info['isNull']=2;
$info['default']='""';
$info['comment']=$description;
break;
case 'c_heckbox':
$info['type']='varchar';
$info['length']='120';
$info['isNull']=2;
$info['default']='""';
$info['comment']=$description;
break;
case 'r_adio':
$info['type']='varchar';
$info['length']='60';
$info['isNull']=2;
$info['default']='""';
$info['comment']=$description;
break;
}
return $info;
}
/**
* 字段状态修改
*/
public function Shenhe(){
$Article=M($this->tab);
$is=$Article->where('id='.$this->_param('id'))->getField('isshow');
if($is==1){
$isnew=0;
}else{
$isnew=1;
}
$aa=$Article->where('id='.$this->_param('id'))->setField('isshow',$isnew);
if($aa){ //更新成功
echo 1;
}else{
echo 0;
}
}
public function look(){
$id=I('id');
if(!intval($id)) exit('<script>alert("参数有误!");history.back();</script>');
$m=M($this->tab);
$where['id']=array('eq',$id);
$data=$m->where($where)->find();
$this->assign('data',$data);
$this->display();
}
}