member_modfun.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. //--------------- 会员字段处理函数 ---------------
  3. //处理注册字段值
  4. function DoMemberFValue($val){
  5. $val=ehtmlspecialchars($val,ENT_QUOTES);
  6. return $val;
  7. }
  8. //删除会员字段附件
  9. function DelYMemberTranFile($file,$tf,$username=''){
  10. global $empire,$dbtbpre;
  11. if(empty($file)){
  12. return "";
  13. }
  14. $r=explode("/",$file);
  15. $count=count($r);
  16. $filename=$r[$count-1];
  17. $filename=addslashes(RepPostStr($filename));
  18. $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");
  19. if($fr['fileid'])
  20. {
  21. $sql=$empire->query("delete from {$dbtbpre}enewsfile_member where fileid='$fr[fileid]'");
  22. DoDelFile($fr);
  23. }
  24. }
  25. //组合复选框数据
  26. function ReturnMCheckboxAddF($r,$f,$checkboxf){
  27. $val=$r;
  28. if(is_array($r)&&strstr($checkboxf,','.$f.','))
  29. {
  30. $val='';
  31. $count=count($r);
  32. for($i=0;$i<$count;$i++)
  33. {
  34. $val.=$r[$i].'|';
  35. }
  36. if($val)
  37. {
  38. $val='|'.$val;
  39. }
  40. }
  41. return $val;
  42. }
  43. //返回会员字段
  44. function ReturnDoMemberF($fid,$add,$mr,$ecms=0,$username='',$admin=0){
  45. global $empire,$dbtbpre,$ecms_config,$public_r;
  46. $pr=$empire->fetch1("select openmembertranimg,memberimgsize,memberimgtype,openmembertranfile,memberfilesize,memberfiletype from {$dbtbpre}enewspublic limit 1");
  47. $formr=$empire->fetch1("select fid,enter,mustenter,filef,imgf,canaddf,caneditf,checkboxf from {$dbtbpre}enewsmemberform where fid='$fid'");
  48. //检测必填字段
  49. $mustr=explode(",",$formr['mustenter']);
  50. $mustcount=count($mustr);
  51. for($i=1;$i<$mustcount-1;$i++)
  52. {
  53. $mf=$mustr[$i];
  54. if(strstr($formr['filef'],",".$mf.",")||strstr($formr['imgf'],",".$mf.","))//附件
  55. {
  56. $mfilef=$mf."file";
  57. //上传文件
  58. if($_FILES[$mfilef]['name'])
  59. {
  60. if(strstr($formr['imgf'],",".$mf.","))//图片
  61. {
  62. if(!$pr['openmembertranimg'])
  63. {
  64. printerror("CloseQTranPic","",1);
  65. }
  66. }
  67. else//附件
  68. {
  69. if(!$pr['openmembertranfile'])
  70. {
  71. printerror("CloseQTranFile","",1);
  72. }
  73. }
  74. }
  75. elseif(!trim($add[$mf])&&!$mr[$mf])
  76. {
  77. printerror("EmptyQMustF","",1);
  78. }
  79. }
  80. else
  81. {
  82. $chmustval=ReturnMCheckboxAddF($add[$mf],$mf,$formr['checkboxf']);
  83. if(!trim($chmustval))
  84. {
  85. printerror("EmptyQMustF","",1);
  86. }
  87. }
  88. }
  89. //字段处理
  90. $dh="";
  91. $tranf="";
  92. $record="<!--record-->";
  93. $field="<!--field--->";
  94. $fr=explode($record,$formr['enter']);
  95. $count=count($fr);
  96. for($i=0;$i<$count-1;$i++)
  97. {
  98. $fr1=explode($field,$fr[$i]);
  99. $f=$fr1[1];
  100. if($admin==0&&(($ecms==0&&!strstr($formr['canaddf'],','.$f.','))||($ecms==1&&!strstr($formr['caneditf'],','.$f.','))))
  101. {continue;}
  102. //附件
  103. $add[$f]=str_replace('[!#@-','ecms',$add[$f]);
  104. if(strstr($formr['filef'],",".$f.",")||strstr($formr['imgf'],",".$f.","))
  105. {
  106. //上传附件
  107. $filetf=$f."file";
  108. if($_FILES[$filetf]['name'])
  109. {
  110. $filetype=GetFiletype($_FILES[$filetf]['name']);//取得文件类型
  111. if(CheckSaveTranFiletype($filetype))
  112. {
  113. printerror("NotQTranFiletype","",1);
  114. }
  115. if(strstr($formr['imgf'],",".$f.","))//图片
  116. {
  117. if(!$pr['openmembertranimg'])
  118. {
  119. printerror("CloseQTranPic","",1);
  120. }
  121. if(!strstr($pr['memberimgtype'],"|".$filetype."|"))
  122. {
  123. printerror("NotQTranFiletype","",1);
  124. }
  125. if($_FILES[$filetf]['size']>$pr['memberimgsize']*1024)
  126. {
  127. printerror("TooBigQTranFile","",1);
  128. }
  129. if(!strstr($ecms_config['sets']['tranpicturetype'],','.$filetype.','))
  130. {
  131. printerror("NotQTranFiletype","",1);
  132. }
  133. }
  134. else//附件
  135. {
  136. if(!$pr['openmembertranfile'])
  137. {
  138. printerror("CloseQTranFile","",1);
  139. }
  140. if(!strstr($pr['memberfiletype'],"|".$filetype."|"))
  141. {
  142. printerror("NotQTranFiletype","",1);
  143. }
  144. if($_FILES[$filetf]['size']>$pr['memberfilesize']*1024)
  145. {
  146. printerror("TooBigQTranFile","",1);
  147. }
  148. }
  149. $tranf.=$dh.$f;
  150. $dh=",";
  151. $fval="[!#@-".$f."-@!]";
  152. }
  153. else
  154. {
  155. if($public_r['modmemberedittran']==1)
  156. {
  157. $fval=$add[$f];
  158. if($ecms==1&&$mr[$f]&&!trim($fval))
  159. {
  160. $fval=$mr[$f];
  161. }
  162. }
  163. else
  164. {
  165. $fval='';
  166. if($ecms==1)
  167. {
  168. $fval=$mr[$f];
  169. }
  170. }
  171. }
  172. }
  173. else
  174. {
  175. $add[$f]=ReturnMCheckboxAddF($add[$f],$f,$formr['checkboxf']);
  176. $fval=$add[$f];
  177. }
  178. $fval=DoMemberFValue($fval);
  179. $fval=RepPostStr2($fval);
  180. $fval=addslashes($fval);
  181. if($ecms==0)//添加
  182. {
  183. $ret_r[0].=",`".$f."`";
  184. $ret_r[1].=",'".$fval."'";
  185. }
  186. else//编辑
  187. {
  188. $ret_r[0].=",`".$f."`='".$fval."'";
  189. }
  190. }
  191. //上传附件
  192. if($tranf)
  193. {
  194. $infoid=0;
  195. $filepass=0;
  196. $classid=0;
  197. $filepass=(int)$mr['add_filepass'];
  198. $tranr=explode(",",$tranf);
  199. $count=count($tranr);
  200. for($i=0;$i<$count;$i++)
  201. {
  202. $tf=$tranr[$i];
  203. $tffile=$tf."file";
  204. $tfr=DoTranFile($_FILES[$tffile]['tmp_name'],$_FILES[$tffile]['name'],$_FILES[$tffile]['type'],$_FILES[$tffile]['size'],$classid);
  205. if($tfr['tran'])
  206. {
  207. if(strstr($formr['imgf'],",".$tf.","))//图片
  208. {
  209. $type=1;
  210. }
  211. else//附件
  212. {
  213. $type=0;
  214. }
  215. //写入数据库
  216. $filesize=(int)$_FILES[$tffile]['size'];
  217. eInsertFileTable($tfr[filename],$filesize,$tfr[filepath],'[EditInfo]'.$username,$classid,'Member['.$tf.']',$type,$filepass,$filepass,$public_r[fpath],0,6,0);
  218. //删除旧文件
  219. if($ecms==1&&$mr[$tf])
  220. {
  221. DelYMemberTranFile($mr[$tf],$tf,$username);
  222. }
  223. $repfval=$tfr['url'];
  224. }
  225. else
  226. {
  227. $repfval=$mr[$tf];
  228. }
  229. if($ecms==0)//添加
  230. {
  231. $ret_r[1]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[1]);
  232. }
  233. else//编辑
  234. {
  235. $ret_r[0]=str_replace("[!#@-".$tf."-@!]",$repfval,$ret_r[0]);
  236. }
  237. }
  238. }
  239. return $ret_r;
  240. }
  241. //删除会员附件
  242. function DoDelMemberF($fid,$userid,$username){
  243. global $empire,$dbtbpre;
  244. $r=$empire->fetch1("select * from {$dbtbpre}enewsmemberadd where userid='$userid'");
  245. $sql=$empire->query("delete from {$dbtbpre}enewsmemberadd where userid='$userid'");
  246. $sql2=$empire->query("delete from {$dbtbpre}enewsmemberpub where userid='$userid'");
  247. if(empty($r[userid]))
  248. {
  249. return '';
  250. }
  251. $formr=$empire->fetch1("select fid,filef,imgf from {$dbtbpre}enewsmemberform where fid='$fid'");
  252. if(empty($formr['filef']))
  253. {
  254. $formr['filef']=',';
  255. }
  256. if(empty($formr['imgf']))
  257. {
  258. $formr['imgf']=',';
  259. }
  260. $fields=substr($formr['filef'],0,strlen($formr['filef'])-1).$formr['imgf'];
  261. $fr=explode(',',$fields);
  262. $count=count($fr);
  263. for($i=1;$i<$count-1;$i++)
  264. {
  265. $f=$fr[$i];
  266. if($r[$f])
  267. {
  268. DelYMemberTranFile($r[$f],$f,$username);
  269. }
  270. }
  271. }
  272. ?>