member_modfun.php
6.67 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
268
269
270
271
272
273
274
275
276
<?php
//--------------- 會員字段處理函數 ---------------
//處理註冊字段值
function DoMemberFValue($val){
$val=ehtmlspecialchars($val,ENT_QUOTES);
return $val;
}
//刪除會員字段附件
function DelYMemberTranFile($file,$tf,$username=''){
global $empire,$dbtbpre;
if(empty($file)){
return "";
}
$r=explode("/",$file);
$count=count($r);
$filename=$r[$count-1];
$fr=$empire->fetch1("select filename,path,fileid,fpath,classid from {$dbtbpre}enewsfile_member where no='Member[".$tf."]' and filename='$filename' and adduser='[EditInfo]".$username."' limit 1");
if($fr['fileid'])
{
$sql=$empire->query("delete from {$dbtbpre}enewsfile_member where fileid='$fr[fileid]'");
DoDelFile($fr);
}
}
//組合復選框數據
function ReturnMCheckboxAddF($r,$f,$checkboxf){
$val=$r;
if(is_array($r)&&strstr($checkboxf,','.$f.','))
{
$val='';
$count=count($r);
for($i=0;$i<$count;$i++)
{
$val.=$r[$i].'|';
}
if($val)
{
$val='|'.$val;
}
}
return $val;
}
//返回會員字段
function ReturnDoMemberF($fid,$add,$mr,$ecms=0,$username='',$admin=0){
global $empire,$dbtbpre,$ecms_config,$public_r;
$pr=$empire->fetch1("select openmembertranimg,memberimgsize,memberimgtype,openmembertranfile,memberfilesize,memberfiletype from {$dbtbpre}enewspublic limit 1");
$formr=$empire->fetch1("select fid,enter,mustenter,filef,imgf,canaddf,caneditf,checkboxf from {$dbtbpre}enewsmemberform where fid='$fid'");
//檢測必填字段
$mustr=explode(",",$formr['mustenter']);
$mustcount=count($mustr);
for($i=1;$i<$mustcount-1;$i++)
{
$mf=$mustr[$i];
if(strstr($formr['filef'],",".$mf.",")||strstr($formr['imgf'],",".$mf.","))//附件
{
$mfilef=$mf."file";
//上傳文件
if($_FILES[$mfilef]['name'])
{
if(strstr($formr['imgf'],",".$mf.","))//圖片
{
if(!$pr['openmembertranimg'])
{
printerror("CloseQTranPic","",1);
}
}
else//附件
{
if(!$pr['openmembertranfile'])
{
printerror("CloseQTranFile","",1);
}
}
}
elseif(!trim($add[$mf])&&!$mr[$mf])
{
printerror("EmptyQMustF","",1);
}
}
else
{
$chmustval=ReturnMCheckboxAddF($add[$mf],$mf,$formr['checkboxf']);
if(!trim($chmustval))
{
printerror("EmptyQMustF","",1);
}
}
}
//字段處理
$dh="";
$tranf="";
$record="<!--record-->";
$field="<!--field--->";
$fr=explode($record,$formr['enter']);
$count=count($fr);
for($i=0;$i<$count-1;$i++)
{
$fr1=explode($field,$fr[$i]);
$f=$fr1[1];
if($admin==0&&(($ecms==0&&!strstr($formr['canaddf'],','.$f.','))||($ecms==1&&!strstr($formr['caneditf'],','.$f.','))))
{continue;}
//附件
$add[$f]=str_replace('[!#@-','ecms',$add[$f]);
if(strstr($formr['filef'],",".$f.",")||strstr($formr['imgf'],",".$f.","))
{
//上傳附件
$filetf=$f."file";
if($_FILES[$filetf]['name'])
{
$filetype=GetFiletype($_FILES[$filetf]['name']);//取得文件類型
if(CheckSaveTranFiletype($filetype))
{
printerror("NotQTranFiletype","",1);
}
if(strstr($formr['imgf'],",".$f.","))//圖片
{
if(!$pr['openmembertranimg'])
{
printerror("CloseQTranPic","",1);
}
if(!strstr($pr['memberimgtype'],"|".$filetype."|"))
{
printerror("NotQTranFiletype","",1);
}
if($_FILES[$filetf]['size']>$pr['memberimgsize']*1024)
{
printerror("TooBigQTranFile","",1);
}
if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
{
printerror("NotQTranFiletype","",1);
}
}
else//附件
{
if(!$pr['openmembertranfile'])
{
printerror("CloseQTranFile","",1);
}
if(!strstr($pr['memberfiletype'],"|".$filetype."|"))
{
printerror("NotQTranFiletype","",1);
}
if($_FILES[$filetf]['size']>$pr['memberfilesize']*1024)
{
printerror("TooBigQTranFile","",1);
}
}
$tranf.=$dh.$f;
$dh=",";
$fval="[!#@-".$f."-@!]";
}
else
{
if($public_r['modmemberedittran']==1)
{
$fval=$add[$f];
if($ecms==1&&$mr[$f]&&!trim($fval))
{
$fval=$mr[$f];
}
}
else
{
$fval='';
if($ecms==1)
{
$fval=$mr[$f];
}
}
}
}
else
{
$add[$f]=ReturnMCheckboxAddF($add[$f],$f,$formr['checkboxf']);
$fval=$add[$f];
}
$fval=DoMemberFValue($fval);
$fval=RepPostStr2($fval);
$fval=addslashes($fval);
if($ecms==0)//添加
{
$ret_r[0].=",`".$f."`";
$ret_r[1].=",'".$fval."'";
}
else//編輯
{
$ret_r[0].=",`".$f."`='".$fval."'";
}
}
//上傳附件
if($tranf)
{
$infoid=0;
$filepass=0;
$classid=0;
$filepass=(int)$mr['add_filepass'];
$tranr=explode(",",$tranf);
$count=count($tranr);
for($i=0;$i<$count;$i++)
{
$tf=$tranr[$i];
$tffile=$tf."file";
$tfr=DoTranFile($_FILES[$tffile]['tmp_name'],$_FILES[$tffile]['name'],$_FILES[$tffile]['type'],$_FILES[$tffile]['size'],$classid);
if($tfr['tran'])
{
if(strstr($formr['imgf'],",".$tf.","))//圖片
{
$type=1;
}
else//附件
{
$type=0;
}
//寫入數據庫
$filesize=(int)$_FILES[$tffile]['size'];
eInsertFileTable($tfr[filename],$filesize,$tfr[filepath],'[EditInfo]'.$username,$classid,'Member['.$tf.']',$type,$filepass,$filepass,$public_r[fpath],0,6,0);
//刪除舊文件
if($ecms==1&&$mr[$tf])
{
DelYMemberTranFile($mr[$tf],$tf,$username);
}
$repfval=$tfr['url'];
}
else
{
$repfval=$mr[$tf];
}
if($ecms==0)//添加
{
$ret_r[1]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[1]);
}
else//編輯
{
$ret_r[0]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[0]);
}
}
}
return $ret_r;
}
//刪除會員附件
function DoDelMemberF($fid,$userid,$username){
global $empire,$dbtbpre;
$r=$empire->fetch1("select * from {$dbtbpre}enewsmemberadd where userid='$userid'");
$sql=$empire->query("delete from {$dbtbpre}enewsmemberadd where userid='$userid'");
$sql2=$empire->query("delete from {$dbtbpre}enewsmemberpub where userid='$userid'");
if(empty($r[userid]))
{
return '';
}
$formr=$empire->fetch1("select fid,filef,imgf from {$dbtbpre}enewsmemberform where fid='$fid'");
if(empty($formr['filef']))
{
$formr['filef']=',';
}
if(empty($formr['imgf']))
{
$formr['imgf']=',';
}
$fields=substr($formr['filef'],0,strlen($formr['filef'])-1).$formr['imgf'];
$fr=explode(',',$fields);
$count=count($fr);
for($i=1;$i<$count-1;$i++)
{
$f=$fr[$i];
if($r[$f])
{
DelYMemberTranFile($r[$f],$f,$username);
}
}
}
?>