PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/e/class/classfun.php

https://github.com/westeast/xwdede
PHP | 2608 lines | 2312 code | 51 blank | 245 comment | 315 complexity | 71177aa698955b09ca393bdb49439f28 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. //*********************** 专题 *********************
  3. //返回字段值
  4. function ReturnZFvalue($value)
  5. {
  6. $value=str_replace("\r\n","|",$value);
  7. return $value;
  8. }
  9. //取得专题表单元素html代码
  10. function GetZtFform($type,$f,$fvalue,$fformsize=''){
  11. if($type=="select"||$type=="radio"||$type=="checkbox")
  12. {
  13. return GetZFformSelect($type,$f,$fvalue,$fformsize);
  14. }
  15. $file="../data/html/classfhtml.txt";
  16. $data=ReadFiletext($file);
  17. $exp="[!--".$type."--]";
  18. $r=explode($exp,$data);
  19. $string=str_replace("[!--enews.var--]",$f,$r[1]);
  20. $string=str_replace("[!--enews.def.val--]",$fvalue,$string);
  21. if($type=='editor')//编辑器
  22. {
  23. $editortype='Default';
  24. $string=str_replace("[!--editor.type--]",$editortype,$string);
  25. $string=str_replace("[!--editor.basepath--]",'',$string);
  26. }
  27. $string=RepZFformSize($f,$string,$type,$fformsize);
  28. return addslashes($string);
  29. }
  30. //取得select/radio元素代码
  31. function GetZFformSelect($type,$f,$fvalue,$fformsize=''){
  32. $vr=explode("|",$fvalue);
  33. $count=count($vr);
  34. $change="";
  35. $def=':default';
  36. for($i=0;$i<$count;$i++)
  37. {
  38. $val=$vr[$i];
  39. $isdef="";
  40. if(strstr($val,$def))
  41. {
  42. $dr=explode($def,$val);
  43. $val=$dr[0];
  44. $isdef="||\$ecmsfirstpost==1";
  45. }
  46. if($type=='select')
  47. {
  48. $change.="<option value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' selected':''?>>".$val."</option>";
  49. }
  50. elseif($type=='checkbox')
  51. {
  52. $change.="<input name=\"".$f."[]\" type=\"checkbox\" value=\"".$val."\"<?=strstr(\$r[".$f."],\"|".$val."|\")".$isdef."?' checked':''?>>".$val;
  53. }
  54. else
  55. {
  56. $change.="<input name=\"".$f."\" type=\"radio\" value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' checked':''?>>".$val;
  57. }
  58. }
  59. if($type=="select")
  60. {
  61. if($fformsize)
  62. {
  63. $addsize=' style="width:'.$fformsize.'"';
  64. }
  65. $change="<select name=\"".$f."\" id=\"".$f."\"".$addsize.">".$change."</select>";
  66. }
  67. return $change;
  68. }
  69. //替换表单元素长度
  70. function RepZFformSize($f,$string,$type,$fformsize=''){
  71. $fformsize=ReturnDefZFformSize($f,$type,$fformsize);
  72. if($type=='textarea'||$type=='editor')
  73. {
  74. $r=explode(',',$fformsize);
  75. $string=str_replace('[!--fsize.w--]',$r[0],$string);
  76. $string=str_replace('[!--fsize.h--]',$r[1],$string);
  77. }
  78. else
  79. {
  80. $string=str_replace('[!--fsize.w--]',$fformsize,$string);
  81. }
  82. return $string;
  83. }
  84. //返回默认长度
  85. function ReturnDefZFformSize($f,$type,$fformsize){
  86. if(empty($fformsize))
  87. {
  88. if($type=='textarea')
  89. {
  90. $fformsize='60,10';
  91. }
  92. elseif($type=='img')
  93. {
  94. $fformsize='45';
  95. }
  96. elseif($type=='file')
  97. {
  98. $fformsize='45';
  99. }
  100. elseif($type=='flash')
  101. {
  102. $fformsize='45';
  103. }
  104. elseif($type=='date')
  105. {
  106. $fformsize='12';
  107. }
  108. elseif($type=='color')
  109. {
  110. $fformsize='10';
  111. }
  112. elseif($type=='linkfield')
  113. {
  114. $fformsize='45';
  115. }
  116. elseif($type=='downpath')
  117. {
  118. $fformsize='45';
  119. }
  120. elseif($type=='onlinepath')
  121. {
  122. $fformsize='45';
  123. }
  124. elseif($type=='editor')
  125. {
  126. $fformsize='100%,300';
  127. }
  128. }
  129. return $fformsize;
  130. }
  131. //更新栏目表单文件
  132. function ChangeZtForm(){
  133. global $empire,$dbtbpre;
  134. $file='../data/html/ztaddform.php';
  135. $mtemp='';
  136. $sql=$empire->query("select fname,f,fhtml from {$dbtbpre}enewsztf order by myorder,fid");
  137. while($r=$empire->fetch($sql))
  138. {
  139. $mtemp.="<tr bgcolor='#FFFFFF' height=25><td>".$r['fname']."</td><td>".$r['fhtml']."</td></tr>";
  140. }
  141. $mtemp="<?php
  142. if(!defined('InEmpireCMS'))
  143. {exit();}
  144. ?>".$mtemp;
  145. WriteFiletext($file,$mtemp);
  146. }
  147. //增加专题字段
  148. function AddZtF($add,$userid,$username){
  149. global $empire,$dbtbpre;
  150. //验证权限
  151. CheckLevel($userid,$username,$classid,"ztf");
  152. $add[f]=RepPostVar($add[f]);
  153. if(empty($add[f])||empty($add[fname]))
  154. {
  155. printerror("EmptyF","");
  156. }
  157. //字段是否重复
  158. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsztadd");
  159. $b=0;
  160. while($r=$empire->fetch($s))
  161. {
  162. if($r[Field]==$add[f])
  163. {
  164. $b=1;
  165. break;
  166. }
  167. }
  168. if($b)
  169. {
  170. printerror("ReF","");
  171. }
  172. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewszt");
  173. $b=0;
  174. while($r=$empire->fetch($s))
  175. {
  176. if($r[Field]==$add[f])
  177. {
  178. $b=1;
  179. break;
  180. }
  181. }
  182. if($b)
  183. {
  184. printerror("ReF","");
  185. }
  186. $add[fvalue]=ReturnZFvalue($add[fvalue]);//初始化值
  187. //字段类型
  188. if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
  189. {
  190. $def=" default '0'";
  191. }
  192. elseif($add[ftype]=="VARCHAR")
  193. {
  194. $def=" default ''";
  195. }
  196. else
  197. {
  198. $def="";
  199. }
  200. $type=$add[ftype];
  201. //VARCHAR
  202. if($add[ftype]=='VARCHAR'&&empty($add[flen]))
  203. {
  204. $add[flen]='255';
  205. }
  206. //字段长度
  207. if($add[flen]){
  208. if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
  209. $type.="(".$add[flen].")";
  210. }
  211. }
  212. $field="`".$add[f]."` ".$type." NOT NULL".$def;
  213. //新增字段
  214. $asql=$empire->query("alter table {$dbtbpre}enewsztadd add ".$field);
  215. //替换代码
  216. $fhtml=GetZtFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
  217. if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
  218. {
  219. $fhtml=str_replace("\$r[","\$addr[",$fhtml);
  220. }
  221. //处理变量
  222. $add[myorder]=(int)$add[myorder];
  223. $sql=$empire->query("insert into {$dbtbpre}enewsztf(f,fname,fform,fhtml,fzs,myorder,ftype,flen,fvalue,fformsize) values('$add[f]','$add[fname]','$add[fform]','".addslashes($fhtml)."','".addslashes($add[fzs])."',$add[myorder],'$add[ftype]','$add[flen]','".addslashes($add[fvalue])."','$add[fformsize]');");
  224. $lastid=$empire->lastid();
  225. //更新表单
  226. ChangeZtForm();
  227. if($asql&&$sql)
  228. {
  229. //操作日志
  230. insert_dolog("fid=".$lastid."<br>f=".$add[f]);
  231. printerror("AddFSuccess","info/AddZtF.php?enews=AddZtF");
  232. }
  233. else
  234. {
  235. printerror("DbError","history.go(-1)");
  236. }
  237. }
  238. //修改专题字段
  239. function EditZtF($add,$userid,$username){
  240. global $empire,$dbtbpre;
  241. //验证权限
  242. CheckLevel($userid,$username,$classid,"ztf");
  243. $fid=(int)$add['fid'];
  244. $add[f]=RepPostVar($add[f]);
  245. $add[oldf]=RepPostVar($add[oldf]);
  246. if(empty($add[f])||empty($add[fname])||!$fid){
  247. printerror("EmptyF","history.go(-1)");
  248. }
  249. if($add[f]<>$add[oldf]){
  250. //字段是否重复
  251. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsztadd");
  252. $b=0;
  253. while($r=$empire->fetch($s)){
  254. if($r[Field]==$add[f]){
  255. $b=1;
  256. break;
  257. }
  258. }
  259. if($b){
  260. printerror("ReF","history.go(-1)");
  261. }
  262. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewszt");
  263. $b=0;
  264. while($r=$empire->fetch($s))
  265. {
  266. if($r[Field]==$add[f])
  267. {
  268. $b=1;
  269. break;
  270. }
  271. }
  272. if($b)
  273. {
  274. printerror("ReF","");
  275. }
  276. }
  277. $add[fvalue]=ReturnZFvalue($add[fvalue]);//初始化值
  278. //字段类型
  279. if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
  280. {
  281. $def=" default '0'";
  282. }
  283. elseif($add[ftype]=="VARCHAR")
  284. {
  285. $def=" default ''";
  286. }
  287. else
  288. {
  289. $def="";
  290. }
  291. $type=$add[ftype];
  292. //VARCHAR
  293. if($add[ftype]=='VARCHAR'&&empty($add[flen]))
  294. {
  295. $add[flen]='255';
  296. }
  297. //字段长度
  298. if($add[flen]){
  299. if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
  300. $type.="(".$add[flen].")";
  301. }
  302. }
  303. $field="`".$add[f]."` ".$type." NOT NULL".$def;
  304. $usql=$empire->query("alter table {$dbtbpre}enewsztadd change `".$add[oldf]."` ".$field);
  305. //替换代码
  306. if($add[f]<>$add[oldf]||$add[fform]<>$add[oldfform]||$add[fvalue]<>$add[oldfvalue]||$add[fformsize]<>$add[oldfformsize]){
  307. $fhtml=GetZtFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
  308. if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
  309. {
  310. $fhtml=str_replace("\$r[","\$addr[",$fhtml);
  311. }
  312. }
  313. else{
  314. $fhtml=$add[fhtml];
  315. }
  316. //处理变量
  317. $add[myorder]=(int)$add[myorder];
  318. $sql=$empire->query("update {$dbtbpre}enewsztf set f='$add[f]',fname='$add[fname]',fform='$add[fform]',fhtml='".addslashes($fhtml)."',fzs='".addslashes($add[fzs])."',myorder=$add[myorder],ftype='$add[ftype]',flen='$add[flen]',fvalue='".addslashes($add[fvalue])."',fformsize='$add[fformsize]' where fid=$fid");
  319. //更新表单
  320. ChangeZtForm();
  321. if($usql&&$sql)
  322. {
  323. insert_dolog("fid=".$fid."<br>f=".$add[f]);//操作日志
  324. printerror("EditFSuccess","info/ListZtF.php");
  325. }
  326. else
  327. {printerror("DbError","history.go(-1)");}
  328. }
  329. //删除专题字段
  330. function DelZtF($add,$userid,$username){
  331. global $empire,$dbtbpre;
  332. //验证权限
  333. CheckLevel($userid,$username,$classid,"ztf");
  334. $fid=(int)$add['fid'];
  335. if(empty($fid)){
  336. printerror("EmptyFid","history.go(-1)");
  337. }
  338. $r=$empire->fetch1("select f from {$dbtbpre}enewsztf where fid='$fid'");
  339. if(!$r[f]){
  340. printerror("EmptyFid","history.go(-1)");
  341. }
  342. $usql=$empire->query("alter table {$dbtbpre}enewsztadd drop COLUMN `".$r[f]."`");
  343. $sql=$empire->query("delete from {$dbtbpre}enewsztf where fid='$fid'");
  344. //更新表单表
  345. ChangeZtForm();
  346. if($usql&&$sql)
  347. {
  348. insert_dolog("fid=".$fid."<br>f=".$r[f]);//操作日志
  349. printerror("DelFSuccess","info/ListZtF.php");
  350. }
  351. else
  352. {printerror("DbError","history.go(-1)");}
  353. }
  354. //修改专题字段顺序
  355. function EditZtFOrder($fid,$myorder,$userid,$username){
  356. global $empire,$dbtbpre;
  357. //验证权限
  358. CheckLevel($userid,$username,$classid,"ztf");
  359. for($i=0;$i<count($myorder);$i++)
  360. {
  361. $fid[$i]=(int)$fid[$i];
  362. $newmyorder=(int)$myorder[$i];
  363. $usql=$empire->query("update {$dbtbpre}enewsztf set myorder=$newmyorder where fid='$fid[$i]'");
  364. }
  365. //更新表单表
  366. ChangeZtForm();
  367. printerror("EditFOrderSuccess","info/ListZtF.php");
  368. }
  369. //返回专题字段
  370. function ReturnZtAddF($add,$ecms=0){
  371. global $empire,$dbtbpre;
  372. $ret_r[0]='';
  373. $ret_r[1]='';
  374. $fsql=$empire->query("select f from {$dbtbpre}enewsztf");
  375. if($ecms==0)//增加
  376. {
  377. while($fr=$empire->fetch($fsql))
  378. {
  379. $f=$fr['f'];
  380. $fval=$add[$f];
  381. $fval=RepPhpAspJspcode($fval);
  382. $ret_r[0].=",`".$f."`";
  383. $ret_r[1].=",'".AddAddsData($fval)."'";
  384. }
  385. }
  386. else//修改
  387. {
  388. while($fr=$empire->fetch($fsql))
  389. {
  390. $f=$fr['f'];
  391. $fval=$add[$f];
  392. $fval=RepPhpAspJspcode($fval);
  393. $ret_r[0].=",`".$f."`='".AddAddsData($fval)."'";
  394. }
  395. }
  396. return $ret_r;
  397. }
  398. //处理专题提交变量
  399. function DoPostZtVar($add){
  400. if(empty($add[zttype])){
  401. $add[zttype]=".html";
  402. }
  403. if(empty($add[ztnum])){
  404. $add[ztnum]=25;
  405. }
  406. $add[zcid]=(int)$add['zcid'];
  407. $add[jstempid]=(int)$add['jstempid'];
  408. $add[ztname]=addslashes(htmlspecialchars($add[ztname]));
  409. $add[intro]=addslashes(RepPhpAspJspcode($add[intro]));
  410. $add[ztpagekey]=addslashes(RepPhpAspJspcode($add[ztpagekey]));
  411. $add[ztnum]=(int)$add[ztnum];
  412. $add[listtempid]=(int)$add[listtempid];
  413. $add[newline]=(int)$add[newline];
  414. $add[hotline]=(int)$add[hotline];
  415. $add[goodline]=(int)$add[goodline];
  416. $add[classid]=(int)$add[classid];
  417. $add[hotplline]=(int)$add[hotplline];
  418. $add[firstline]=(int)$add[firstline];
  419. $add[islist]=(int)$add[islist];
  420. $add[maxnum]=(int)$add[maxnum];
  421. $add[showzt]=(int)$add[showzt];
  422. $add[classtempid]=(int)$add[classtempid];
  423. $add['myorder']=(int)$add['myorder'];
  424. $add[nrejs]=(int)$add[nrejs];
  425. $add[reorder]=RepPostVar2($add[reorder]);
  426. $add[classtext]=RepPhpAspJspcode($add[classtext]);
  427. $add[usezt]=(int)$add[usezt];
  428. $add[yhid]=(int)$add[yhid];
  429. //目录
  430. $add[ztpath]=$add['pripath'].$add['ztpath'];
  431. return $add;
  432. }
  433. //增加专题
  434. function AddZt($add,$userid,$username){
  435. global $empire,$class_r,$dbtbpre;
  436. $add[ztpath]=trim($add[ztpath]);
  437. if(!$add[ztname]||!$add[listtempid]||!$add[ztpath]){
  438. printerror("EmptyZt","");
  439. }
  440. CheckLevel($userid,$username,$classid,"zt");
  441. $add=DoPostZtVar($add);
  442. $createpath='../../'.$add[ztpath];
  443. //检测目录是否存在
  444. if(file_exists($createpath)){
  445. printerror("ReZtpath","");
  446. }
  447. CreateZtPath($add[ztpath]);//建立专题目录
  448. //取得表名
  449. $tabler=GetModTable(GetListtempMid($add[listtempid]));
  450. $tabler[tid]=(int)$tabler[tid];
  451. $sql=$empire->query("insert into {$dbtbpre}enewszt(ztname,ztnum,listtempid,onclick,ztpath,zttype,newline,zturl,hotline,goodline,classid,hotplline,firstline,islist,maxnum,tid,tbname,reorder,intro,ztimg,zcid,jstempid,showzt,ztpagekey,classtempid,myorder,nrejs,usezt,yhid) values('$add[ztname]',$add[ztnum],$add[listtempid],0,'$add[ztpath]','$add[zttype]',$add[newline],'$add[zturl]',$add[hotline],$add[goodline],$add[classid],$add[hotplline],$add[firstline],$add[islist],$add[maxnum],$tabler[tid],'$tabler[tbname]','$add[reorder]','$add[intro]','$add[ztimg]',$add[zcid],$add[jstempid],$add[showzt],'$add[ztpagekey]','$add[classtempid]',$add[myorder],$add[nrejs],'$add[usezt]','$add[yhid]');");
  452. $ztid=$empire->lastid();
  453. //副表
  454. $ret_zr=ReturnZtAddF($add,0);
  455. $empire->query("replace into {$dbtbpre}enewsztadd(ztid,classtext".$ret_zr[0].") values('$ztid','".addslashes($add[classtext])."'".$ret_zr[1].");");
  456. //生成页面
  457. if($add[islist]==0||$add[islist]==2)
  458. {
  459. $classtemp=$add[islist]==2?GetZtText($ztid):GetClassTemp($add['classtempid']);
  460. NewsBq($ztid,$classtemp,3,1);
  461. }
  462. GetClass();//更新缓存
  463. if($sql){
  464. insert_dolog("ztid=".$ztid."<br>ztname=".$add[ztname]);//操作日志
  465. printerror("AddZtSuccess","AddZt.php?enews=AddZt");
  466. }
  467. else{
  468. printerror("DbError","");
  469. }
  470. }
  471. //修改专题
  472. function EditZt($add,$userid,$username){
  473. global $empire,$class_r,$dbtbpre;
  474. $add[ztid]=(int)$add[ztid];
  475. $add[ztpath]=trim($add[ztpath]);
  476. if(!$add[ztname]||!$add[listtempid]||!$add[ztpath]||!$add[ztid]){
  477. printerror("EmptyZt","");
  478. }
  479. CheckLevel($userid,$username,$classid,"zt");
  480. $add=DoPostZtVar($add);
  481. //改变目录
  482. if($add[oldztpath]<>$add[ztpath]){
  483. $createpath='../../'.$add[ztpath];
  484. if(file_exists($createpath)){
  485. printerror("ReZtpath","");
  486. }
  487. if($add['oldpripath']==$add['pripath']){
  488. $new="../../";
  489. @rename($new.$add[oldztpath],$new.$add[ztpath]);//改变目录名
  490. }
  491. else{
  492. CreateZtPath($add[ztpath]);//建立专题目录
  493. }
  494. }
  495. //取得表名
  496. $tabler=GetModTable(GetListtempMid($add[listtempid]));
  497. $tabler[tid]=(int)$tabler[tid];
  498. $sql=$empire->query("update {$dbtbpre}enewszt set ztname='$add[ztname]',ztnum=$add[ztnum],listtempid=$add[listtempid],ztpath='$add[ztpath]',zttype='$add[zttype]',newline=$add[newline],zturl='$add[zturl]',hotline=$add[hotline],goodline=$add[goodline],classid=$add[classid],hotplline=$add[hotplline],firstline=$add[firstline],islist=$add[islist],maxnum=$add[maxnum],tid=$tabler[tid],tbname='$tabler[tbname]',reorder='$add[reorder]',intro='$add[intro]',ztimg='$add[ztimg]',zcid=$add[zcid],jstempid=$add[jstempid],showzt=$add[showzt],ztpagekey='$add[ztpagekey]',classtempid='$add[classtempid]',myorder=$add[myorder],nrejs=$add[nrejs],usezt='$add[usezt]',yhid='$add[yhid]' where ztid='$add[ztid]'");
  499. //副表
  500. $ret_zr=ReturnZtAddF($add,1);
  501. $empire->query("update {$dbtbpre}enewsztadd set classtext='".addslashes($add[classtext])."'".$ret_zr[0]." where ztid='$add[ztid]'");
  502. GetClass();//更新缓存
  503. //生成页面
  504. if($add[islist]==0||$add[islist]==2)
  505. {
  506. $classtemp=$add[islist]==2?GetZtText($add[ztid]):GetClassTemp($add['classtempid']);
  507. NewsBq($add[ztid],$classtemp,3,1);
  508. }
  509. if($sql){
  510. insert_dolog("ztid=".$add[ztid]."<br>ztname=".$add[ztname]);//操作日志
  511. printerror("EditZtSuccess","ListZt.php");
  512. }
  513. else{
  514. printerror("DbError","");
  515. }
  516. }
  517. //删除专题
  518. function DelZt($ztid,$userid,$username){
  519. global $empire,$dbtbpre;
  520. $ztid=(int)$ztid;
  521. if(!$ztid){
  522. printerror("NotDelZtid","");
  523. }
  524. CheckLevel($userid,$username,$classid,"zt");
  525. $r=$empire->fetch1("select * from {$dbtbpre}enewszt where ztid='$ztid'");
  526. if(empty($r[ztid])){
  527. printerror("NotDelZtid","history.go(-1)");
  528. }
  529. //删除专题
  530. $sql=$empire->query("delete from {$dbtbpre}enewszt where ztid='$ztid'");
  531. $empire->query("delete from {$dbtbpre}enewsztadd where ztid='$ztid'");
  532. $delpath="../../".$r[ztpath];
  533. $del=DelPath($delpath);
  534. //改变信息专题值
  535. $nsql=$empire->query("select id,ztid from {$dbtbpre}ecms_".$r[tbname]." where ztid like '%|".$ztid."|%'");
  536. while($nr=$empire->fetch($nsql))
  537. {
  538. $newztid=str_replace("|".$ztid."|","|",$nr[ztid]);
  539. $usql=$empire->query("update {$dbtbpre}ecms_".$r[tbname]." set ztid='$newztid' where id='$nr[id]'");
  540. }
  541. GetClass();//更新缓存
  542. if($sql){
  543. insert_dolog("ztid=".$ztid."<br>ztname=".$r[ztname]);//操作日志
  544. printerror("DelZtSuccess","ListZt.php");
  545. }
  546. else{
  547. printerror("DbError","");
  548. }
  549. }
  550. //组合专题
  551. function TogZt($add,$userid,$username){
  552. global $empire,$class_r,$dbtbpre;
  553. $ztid=(int)$add['ztid'];
  554. if(empty($ztid))
  555. {
  556. printerror("ErrorUrl","history.go(-1)");
  557. }
  558. $r=$empire->fetch1("select ztid,ztname,tbname from {$dbtbpre}enewszt where ztid=$ztid");
  559. if(empty($r['ztid'])||empty($r['tbname']))
  560. {
  561. printerror("ErrorUrl","history.go(-1)");
  562. }
  563. $wheresql="";
  564. $formvar="";
  565. //关键字
  566. $keyboard=RepPostVar2($add['keyboard']);
  567. if($keyboard)
  568. {
  569. $formvar.=ReturnFormHidden('keyboard',$add['keyboard']);
  570. $searchfsql='';
  571. if($add['stitle'])//标题
  572. {
  573. $searchfsql.="title like '%$keyboard%'";
  574. $formvar.=ReturnFormHidden('stitle',$add['stitle']);
  575. }
  576. if($add['susername'])//增加者
  577. {
  578. if($searchfsql)
  579. {
  580. $or=" or ";
  581. }
  582. $searchfsql.=$or."username like '%$keyboard%'";
  583. $formvar.=ReturnFormHidden('susername',$add['susername']);
  584. }
  585. if($add['snewstext'])//内容
  586. {
  587. $or="";
  588. if($searchfsql)
  589. {
  590. $or=" or ";
  591. }
  592. $searchfsql.=$or."newstext like '%$keyboard%'";
  593. $formvar.=ReturnFormHidden('snewstext',$add['snewstext']);
  594. }
  595. if($searchfsql)
  596. {
  597. $wheresql=" and (".$searchfsql.")";
  598. }
  599. }
  600. //是否推荐
  601. if($add['isgood'])
  602. {
  603. $wheresql.=" and isgood>0";
  604. $formvar.=ReturnFormHidden('isgood',$add['isgood']);
  605. }
  606. //头条
  607. if($add['firsttitle'])
  608. {
  609. $wheresql.=" and firsttitle>0";
  610. $formvar.=ReturnFormHidden('firsttitle',$add['firsttitle']);
  611. }
  612. //有标题图片
  613. if($add['titlepic'])
  614. {
  615. $wheresql.=" and ispic=1";
  616. $formvar.=ReturnFormHidden('titlepic',$add['titlepic']);
  617. }
  618. //审核
  619. if($add['checked'])
  620. {
  621. $wheresql.=" and checked=1";
  622. $formvar.=ReturnFormHidden('checked',$add['checked']);
  623. }
  624. //按栏目刷新
  625. $classid=(int)$add['classid'];
  626. if($classid)
  627. {
  628. $formvar.=ReturnFormHidden('classid',$add['classid']);
  629. //大栏目
  630. if(empty($class_r[$classid][islast]))
  631. {
  632. $where=ReturnClass($class_r[$classid][sonclass]);
  633. }
  634. //终极栏目
  635. else
  636. {
  637. $where="classid='$classid'";
  638. }
  639. $wheresql.=" and (".$where.")";
  640. }
  641. $startid=(int)$add[startid];
  642. $endid=(int)$add[endid];
  643. $startday=RepPostVar($add[startday]);
  644. $endday=RepPostVar($add[endday]);
  645. $formvar.=ReturnFormHidden('retype',$add['retype']);
  646. //按ID
  647. if($add['retype'])
  648. {
  649. if($endid)
  650. {
  651. $wheresql.=" and id>=$startid and id<=$endid";
  652. $formvar.=ReturnFormHidden('startid',$add[startid]).ReturnFormHidden('endid',$add[endid]);
  653. }
  654. }
  655. else
  656. {
  657. if($startday&&$endday)
  658. {
  659. $wheresql.=" and truetime>=".to_time($startday." 00:00:00")." and truetime<=".to_time($endday." 23:59:59");
  660. $formvar.=ReturnFormHidden('startday',$add[startday]).ReturnFormHidden('endday',$add[endday]);
  661. }
  662. }
  663. //附件sql条件
  664. $query=$add['query'];
  665. if($query)
  666. {
  667. $query=ClearAddsData($query);//去除adds
  668. $wheresql.=" and (".$query.")";
  669. $formvar.=ReturnFormHidden('query',$add['query']);
  670. }
  671. $wheresql=" where ztid not like '%|".$ztid."|%'".$wheresql;
  672. $owheresql=$wheresql." and ztid=''";
  673. if($add['doecmszt'])
  674. {
  675. if($add['inid'])
  676. {
  677. $add['inid']=RepPostVar($add['inid']);
  678. $wheresql.=" and id not in (".$add['inid'].")";
  679. $owheresql.=" and id not in (".$add['inid'].")";
  680. }
  681. $repztid="|".$ztid."|";
  682. $conztid=$ztid."|";
  683. //将空格转换成|
  684. $usql=$empire->query("update {$dbtbpre}ecms_".$r['tbname']." set ztid='|'".$owheresql);
  685. //组成新专题
  686. $sql=$empire->query("update {$dbtbpre}ecms_".$r['tbname']." set ztid=CONCAT(REPLACE(ztid,'".$repztid."','|'),'".$conztid."')".$wheresql);
  687. if($usql&&$sql)
  688. {
  689. //操作日志
  690. insert_dolog("ztid=$ztid&ztname=$r[ztname]");
  691. printerror("TogZtSuccess","TogZt.php?ztid=$ztid");
  692. }
  693. else
  694. {
  695. printerror("DbError","history.go(-1)");
  696. }
  697. }
  698. $re[0]=$wheresql;
  699. $re[1]=$formvar.ReturnFormHidden('ztid',$ztid).ReturnFormHidden('pline',$add[pline]).ReturnFormHidden('doecmszt',$add[doecmszt]).ReturnFormHidden('enews',$add[enews]).ReturnFormHidden('inid',$add[inid]);
  700. $re[2]=$r['tbname'];
  701. $re[3]=$r['ztname'];
  702. return $re;
  703. }
  704. //保存专题信息
  705. function SaveTogZtInfo($add,$userid,$username){
  706. global $empire,$dbtbpre;
  707. if(!trim($add[togztname]))
  708. {
  709. printerror('EmptySaveTogZtname','history.go(-1)');
  710. }
  711. $add['doecmszt']=(int)$add['doecmszt'];
  712. $add[classid]=(int)$add[classid];
  713. //搜索字段
  714. $searchf=',';
  715. if($add[stitle]==1)
  716. {
  717. $searchf.='stitle,';
  718. }
  719. if($add[susername]==1)
  720. {
  721. $searchf.='susername,';
  722. }
  723. if($add[snewstext]==1)
  724. {
  725. $searchf.='snewstext,';
  726. }
  727. //特殊字段
  728. $specialsearch=',';
  729. if($add[isgood])
  730. {
  731. $specialsearch.='isgood,';
  732. }
  733. if($add[firsttitle])
  734. {
  735. $specialsearch.='firsttitle,';
  736. }
  737. if($add[titlepic])
  738. {
  739. $specialsearch.='titlepic,';
  740. }
  741. if($add[checked])
  742. {
  743. $specialsearch.='checked,';
  744. }
  745. $add['retype']=(int)$add['retype'];
  746. $add['startid']=(int)$add['startid'];
  747. $add['endid']=(int)$add['endid'];
  748. $add['pline']=(int)$add['pline'];
  749. $r=$empire->fetch1("select togid from {$dbtbpre}enewstogzts where togztname='$add[togztname]'");
  750. if($r[togid])
  751. {
  752. $sql=$empire->query("update {$dbtbpre}enewstogzts set keyboard='".addslashes($add[keyboard])."',searchf='$searchf',query='".addslashes($add[query])."',specialsearch='$specialsearch',classid=$add[classid],retype=$add[retype],startday='".addslashes($add[startday])."',endday='".addslashes($add[endday])."',startid=$add[startid],endid=$add[endid],pline=$add[pline],doecmszt=$add[doecmszt] where togid='$r[togid]'");
  753. $togid=$r[togid];
  754. }
  755. else
  756. {
  757. $sql=$empire->query("insert into {$dbtbpre}enewstogzts(keyboard,searchf,query,specialsearch,classid,retype,startday,endday,startid,endid,pline,doecmszt,togztname) values('".addslashes($add[keyboard])."','$searchf','".addslashes($add[query])."','$specialsearch',$add[classid],$add[retype],'".addslashes($add[startday])."','".addslashes($add[endday])."',$add[startid],$add[endid],$add[pline],$add[doecmszt],'".addslashes($add[togztname])."');");
  758. $togid=$empire->lastid();
  759. }
  760. if($sql)
  761. {
  762. insert_dolog("togid=$togid&togztname=$add[togztname]");//操作日志
  763. printerror("SaveTogZtInfoSuccess","TogZt.php?ztid=$add[ztid]&togid=$togid");
  764. }
  765. else
  766. {
  767. printerror("DbError","history.go(-1)");
  768. }
  769. }
  770. //删除保存专题信息
  771. function DelTogZtInfo($add,$userid,$username){
  772. global $empire,$dbtbpre;
  773. $togid=intval($add[togid]);
  774. if(!$togid)
  775. {
  776. printerror('EmptyDelTogztid','history.go(-1)');
  777. }
  778. $r=$empire->fetch1("select togid,togztname from {$dbtbpre}enewstogzts where togid='$togid'");
  779. if(!$r[togid])
  780. {
  781. printerror('EmptyDelTogztid','history.go(-1)');
  782. }
  783. $sql=$empire->query("delete from {$dbtbpre}enewstogzts where togid='$togid'");
  784. if($sql)
  785. {
  786. insert_dolog("togid=$togid&togztname=$r[togztname]");//操作日志
  787. printerror('DelTogZtInfoSuccess',$_SERVER['HTTP_REFERER']);
  788. }
  789. else
  790. {
  791. printerror("DbError","history.go(-1)");
  792. }
  793. }
  794. //************************************ 栏目 ************************************
  795. //返回字段值
  796. function ReturnCFvalue($value)
  797. {
  798. $value=str_replace("\r\n","|",$value);
  799. return $value;
  800. }
  801. //取得栏目表单元素html代码
  802. function GetClassFform($type,$f,$fvalue,$fformsize=''){
  803. if($type=="select"||$type=="radio"||$type=="checkbox")
  804. {
  805. return GetCFformSelect($type,$f,$fvalue,$fformsize);
  806. }
  807. $file="../data/html/classfhtml.txt";
  808. $data=ReadFiletext($file);
  809. $exp="[!--".$type."--]";
  810. $r=explode($exp,$data);
  811. $string=str_replace("[!--enews.var--]",$f,$r[1]);
  812. $string=str_replace("[!--enews.def.val--]",$fvalue,$string);
  813. if($type=='editor')//编辑器
  814. {
  815. $editortype='Default';
  816. $string=str_replace("[!--editor.type--]",$editortype,$string);
  817. $string=str_replace("[!--editor.basepath--]",'',$string);
  818. }
  819. $string=RepCFformSize($f,$string,$type,$fformsize);
  820. return addslashes($string);
  821. }
  822. //取得select/radio元素代码
  823. function GetCFformSelect($type,$f,$fvalue,$fformsize=''){
  824. $vr=explode("|",$fvalue);
  825. $count=count($vr);
  826. $change="";
  827. $def=':default';
  828. for($i=0;$i<$count;$i++)
  829. {
  830. $val=$vr[$i];
  831. $isdef="";
  832. if(strstr($val,$def))
  833. {
  834. $dr=explode($def,$val);
  835. $val=$dr[0];
  836. $isdef="||\$ecmsfirstpost==1";
  837. }
  838. if($type=='select')
  839. {
  840. $change.="<option value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' selected':''?>>".$val."</option>";
  841. }
  842. elseif($type=='checkbox')
  843. {
  844. $change.="<input name=\"".$f."[]\" type=\"checkbox\" value=\"".$val."\"<?=strstr(\$r[".$f."],\"|".$val."|\")".$isdef."?' checked':''?>>".$val;
  845. }
  846. else
  847. {
  848. $change.="<input name=\"".$f."\" type=\"radio\" value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' checked':''?>>".$val;
  849. }
  850. }
  851. if($type=="select")
  852. {
  853. if($fformsize)
  854. {
  855. $addsize=' style="width:'.$fformsize.'"';
  856. }
  857. $change="<select name=\"".$f."\" id=\"".$f."\"".$addsize.">".$change."</select>";
  858. }
  859. return $change;
  860. }
  861. //替换表单元素长度
  862. function RepCFformSize($f,$string,$type,$fformsize=''){
  863. $fformsize=ReturnDefCFformSize($f,$type,$fformsize);
  864. if($type=='textarea'||$type=='editor')
  865. {
  866. $r=explode(',',$fformsize);
  867. $string=str_replace('[!--fsize.w--]',$r[0],$string);
  868. $string=str_replace('[!--fsize.h--]',$r[1],$string);
  869. }
  870. else
  871. {
  872. $string=str_replace('[!--fsize.w--]',$fformsize,$string);
  873. }
  874. return $string;
  875. }
  876. //返回默认长度
  877. function ReturnDefCFformSize($f,$type,$fformsize){
  878. if(empty($fformsize))
  879. {
  880. if($type=='textarea')
  881. {
  882. $fformsize='60,10';
  883. }
  884. elseif($type=='img')
  885. {
  886. $fformsize='45';
  887. }
  888. elseif($type=='file')
  889. {
  890. $fformsize='45';
  891. }
  892. elseif($type=='flash')
  893. {
  894. $fformsize='45';
  895. }
  896. elseif($type=='date')
  897. {
  898. $fformsize='12';
  899. }
  900. elseif($type=='color')
  901. {
  902. $fformsize='10';
  903. }
  904. elseif($type=='linkfield')
  905. {
  906. $fformsize='45';
  907. }
  908. elseif($type=='downpath')
  909. {
  910. $fformsize='45';
  911. }
  912. elseif($type=='onlinepath')
  913. {
  914. $fformsize='45';
  915. }
  916. elseif($type=='editor')
  917. {
  918. $fformsize='100%,300';
  919. }
  920. }
  921. return $fformsize;
  922. }
  923. //更新栏目表单文件
  924. function ChangeClassForm(){
  925. global $empire,$dbtbpre;
  926. $file='../data/html/classaddform.php';
  927. $mtemp='';
  928. $sql=$empire->query("select fname,f,fhtml from {$dbtbpre}enewsclassf order by myorder,fid");
  929. while($r=$empire->fetch($sql))
  930. {
  931. $mtemp.="<tr bgcolor='#FFFFFF' height=25><td>".$r['fname']."</td><td>".$r['fhtml']."</td></tr>";
  932. }
  933. $mtemp="<?php
  934. if(!defined('InEmpireCMS'))
  935. {exit();}
  936. ?>".$mtemp;
  937. WriteFiletext($file,$mtemp);
  938. }
  939. //增加栏目字段
  940. function AddClassF($add,$userid,$username){
  941. global $empire,$dbtbpre;
  942. //验证权限
  943. CheckLevel($userid,$username,$classid,"classf");
  944. $add[f]=RepPostVar($add[f]);
  945. if(empty($add[f])||empty($add[fname]))
  946. {
  947. printerror("EmptyF","");
  948. }
  949. //字段是否重复
  950. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsclassadd");
  951. $b=0;
  952. while($r=$empire->fetch($s))
  953. {
  954. if($r[Field]==$add[f])
  955. {
  956. $b=1;
  957. break;
  958. }
  959. }
  960. if($b)
  961. {
  962. printerror("ReF","");
  963. }
  964. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsclass");
  965. $b=0;
  966. while($r=$empire->fetch($s))
  967. {
  968. if($r[Field]==$add[f])
  969. {
  970. $b=1;
  971. break;
  972. }
  973. }
  974. if($b)
  975. {
  976. printerror("ReF","");
  977. }
  978. $add[fvalue]=ReturnCFvalue($add[fvalue]);//初始化值
  979. //字段类型
  980. if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
  981. {
  982. $def=" default '0'";
  983. }
  984. elseif($add[ftype]=="VARCHAR")
  985. {
  986. $def=" default ''";
  987. }
  988. else
  989. {
  990. $def="";
  991. }
  992. $type=$add[ftype];
  993. //VARCHAR
  994. if($add[ftype]=='VARCHAR'&&empty($add[flen]))
  995. {
  996. $add[flen]='255';
  997. }
  998. //字段长度
  999. if($add[flen]){
  1000. if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
  1001. $type.="(".$add[flen].")";
  1002. }
  1003. }
  1004. $field="`".$add[f]."` ".$type." NOT NULL".$def;
  1005. //新增字段
  1006. $asql=$empire->query("alter table {$dbtbpre}enewsclassadd add ".$field);
  1007. //替换代码
  1008. $fhtml=GetClassFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
  1009. if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
  1010. {
  1011. $fhtml=str_replace("\$r[","\$addr[",$fhtml);
  1012. }
  1013. //处理变量
  1014. $add[myorder]=(int)$add[myorder];
  1015. $sql=$empire->query("insert into {$dbtbpre}enewsclassf(f,fname,fform,fhtml,fzs,myorder,ftype,flen,fvalue,fformsize) values('$add[f]','$add[fname]','$add[fform]','".addslashes($fhtml)."','".addslashes($add[fzs])."',$add[myorder],'$add[ftype]','$add[flen]','".addslashes($add[fvalue])."','$add[fformsize]');");
  1016. $lastid=$empire->lastid();
  1017. //更新表单
  1018. ChangeClassForm();
  1019. if($asql&&$sql)
  1020. {
  1021. //操作日志
  1022. insert_dolog("fid=".$lastid."<br>f=".$add[f]);
  1023. printerror("AddFSuccess","info/AddClassF.php?enews=AddClassF");
  1024. }
  1025. else
  1026. {
  1027. printerror("DbError","history.go(-1)");
  1028. }
  1029. }
  1030. //修改栏目字段
  1031. function EditClassF($add,$userid,$username){
  1032. global $empire,$dbtbpre;
  1033. //验证权限
  1034. CheckLevel($userid,$username,$classid,"classf");
  1035. $fid=(int)$add['fid'];
  1036. $add[f]=RepPostVar($add[f]);
  1037. $add[oldf]=RepPostVar($add[oldf]);
  1038. if(empty($add[f])||empty($add[fname])||!$fid){
  1039. printerror("EmptyF","history.go(-1)");
  1040. }
  1041. if($add[f]<>$add[oldf]){
  1042. //字段是否重复
  1043. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsclassadd");
  1044. $b=0;
  1045. while($r=$empire->fetch($s)){
  1046. if($r[Field]==$add[f]){
  1047. $b=1;
  1048. break;
  1049. }
  1050. }
  1051. if($b){
  1052. printerror("ReF","history.go(-1)");
  1053. }
  1054. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}enewsclass");
  1055. $b=0;
  1056. while($r=$empire->fetch($s))
  1057. {
  1058. if($r[Field]==$add[f])
  1059. {
  1060. $b=1;
  1061. break;
  1062. }
  1063. }
  1064. if($b)
  1065. {
  1066. printerror("ReF","");
  1067. }
  1068. }
  1069. $add[fvalue]=ReturnCFvalue($add[fvalue]);//初始化值
  1070. //字段类型
  1071. if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
  1072. {
  1073. $def=" default '0'";
  1074. }
  1075. elseif($add[ftype]=="VARCHAR")
  1076. {
  1077. $def=" default ''";
  1078. }
  1079. else
  1080. {
  1081. $def="";
  1082. }
  1083. $type=$add[ftype];
  1084. //VARCHAR
  1085. if($add[ftype]=='VARCHAR'&&empty($add[flen]))
  1086. {
  1087. $add[flen]='255';
  1088. }
  1089. //字段长度
  1090. if($add[flen]){
  1091. if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"){
  1092. $type.="(".$add[flen].")";
  1093. }
  1094. }
  1095. $field="`".$add[f]."` ".$type." NOT NULL".$def;
  1096. $usql=$empire->query("alter table {$dbtbpre}enewsclassadd change `".$add[oldf]."` ".$field);
  1097. //替换代码
  1098. if($add[f]<>$add[oldf]||$add[fform]<>$add[oldfform]||$add[fvalue]<>$add[oldfvalue]||$add[fformsize]<>$add[oldfformsize]){
  1099. $fhtml=GetClassFform($add[fform],$add[f],$add[fvalue],$add[fformsize]);
  1100. if($add[fform]=='select'||$add[fform]=='radio'||$add[fform]=='checkbox')
  1101. {
  1102. $fhtml=str_replace("\$r[","\$addr[",$fhtml);
  1103. }
  1104. }
  1105. else{
  1106. $fhtml=$add[fhtml];
  1107. }
  1108. //处理变量
  1109. $add[myorder]=(int)$add[myorder];
  1110. $sql=$empire->query("update {$dbtbpre}enewsclassf set f='$add[f]',fname='$add[fname]',fform='$add[fform]',fhtml='".addslashes($fhtml)."',fzs='".addslashes($add[fzs])."',myorder=$add[myorder],ftype='$add[ftype]',flen='$add[flen]',fvalue='".addslashes($add[fvalue])."',fformsize='$add[fformsize]' where fid=$fid");
  1111. //更新表单
  1112. ChangeClassForm();
  1113. if($usql&&$sql)
  1114. {
  1115. insert_dolog("fid=".$fid."<br>f=".$add[f]);//操作日志
  1116. printerror("EditFSuccess","info/ListClassF.php");
  1117. }
  1118. else
  1119. {printerror("DbError","history.go(-1)");}
  1120. }
  1121. //删除栏目字段
  1122. function DelClassF($add,$userid,$username){
  1123. global $empire,$dbtbpre;
  1124. //验证权限
  1125. CheckLevel($userid,$username,$classid,"classf");
  1126. $fid=(int)$add['fid'];
  1127. if(empty($fid)){
  1128. printerror("EmptyFid","history.go(-1)");
  1129. }
  1130. $r=$empire->fetch1("select f from {$dbtbpre}enewsclassf where fid='$fid'");
  1131. if(!$r[f]){
  1132. printerror("EmptyFid","history.go(-1)");
  1133. }
  1134. $usql=$empire->query("alter table {$dbtbpre}enewsclassadd drop COLUMN `".$r[f]."`");
  1135. $sql=$empire->query("delete from {$dbtbpre}enewsclassf where fid='$fid'");
  1136. //更新表单表
  1137. ChangeClassForm();
  1138. if($usql&&$sql)
  1139. {
  1140. insert_dolog("fid=".$fid."<br>f=".$r[f]);//操作日志
  1141. printerror("DelFSuccess","info/ListClassF.php");
  1142. }
  1143. else
  1144. {printerror("DbError","history.go(-1)");}
  1145. }
  1146. //修改栏目字段顺序
  1147. function EditClassFOrder($fid,$myorder,$userid,$username){
  1148. global $empire,$dbtbpre;
  1149. //验证权限
  1150. CheckLevel($userid,$username,$classid,"classf");
  1151. for($i=0;$i<count($myorder);$i++)
  1152. {
  1153. $fid[$i]=(int)$fid[$i];
  1154. $newmyorder=(int)$myorder[$i];
  1155. $usql=$empire->query("update {$dbtbpre}enewsclassf set myorder=$newmyorder where fid='$fid[$i]'");
  1156. }
  1157. //更新表单表
  1158. ChangeClassForm();
  1159. printerror("EditFOrderSuccess","info/ListClassF.php");
  1160. }
  1161. //返回栏目字段
  1162. function ReturnClassAddF($add,$ecms=0){
  1163. global $empire,$dbtbpre;
  1164. $ret_r[0]='';
  1165. $ret_r[1]='';
  1166. $fsql=$empire->query("select f from {$dbtbpre}enewsclassf");
  1167. if($ecms==0)//增加
  1168. {
  1169. while($fr=$empire->fetch($fsql))
  1170. {
  1171. $f=$fr['f'];
  1172. $fval=$add[$f];
  1173. $fval=RepPhpAspJspcode($fval);
  1174. $ret_r[0].=",`".$f."`";
  1175. $ret_r[1].=",'".AddAddsData($fval)."'";
  1176. }
  1177. }
  1178. else//修改
  1179. {
  1180. while($fr=$empire->fetch($fsql))
  1181. {
  1182. $f=$fr['f'];
  1183. $fval=$add[$f];
  1184. $fval=RepPhpAspJspcode($fval);
  1185. $ret_r[0].=",`".$f."`='".AddAddsData($fval)."'";
  1186. }
  1187. }
  1188. return $ret_r;
  1189. }
  1190. //组合不生成的栏目信息
  1191. function TogNotReClass($changecache=0){
  1192. global $empire,$dbtbpre;
  1193. $sql=$empire->query("select classid,nreclass,nreinfo,nrejs,nottobq from {$dbtbpre}enewsclass where nreclass=1 or nreinfo=1 or nrejs=1 or nottobq=1");
  1194. $nreclass=',';
  1195. $nreinfo=',';
  1196. $nrejs=',';
  1197. $nottobq=',';
  1198. while($r=$empire->fetch($sql))
  1199. {
  1200. if($r['nreclass']==1)
  1201. {
  1202. $nreclass.=$r['classid'].',';
  1203. }
  1204. if($r['nreinfo']==1)
  1205. {
  1206. $nreinfo.=$r['classid'].',';
  1207. }
  1208. if($r['nrejs']==1)
  1209. {
  1210. $nrejs.=$r['classid'].',';
  1211. }
  1212. if($r['nottobq']==1)
  1213. {
  1214. $nottobq.=$r['classid'].',';
  1215. }
  1216. }
  1217. $empire->query("update {$dbtbpre}enewspublic set nreclass='$nreclass',nreinfo='$nreinfo',nrejs='$nrejs',nottobq='$nottobq' limit 1");
  1218. if($changecache==1)
  1219. {
  1220. GetConfig();
  1221. }
  1222. }
  1223. //返回投稿权限
  1224. function DoPostClassQAddGroupid($groupid){
  1225. $count=count($groupid);
  1226. if(!$count)
  1227. {
  1228. return '';
  1229. }
  1230. $qg=',';
  1231. for($i=0;$i<$count;$i++)
  1232. {
  1233. $groupid[$i]=(int)$groupid[$i];
  1234. $qg.=$groupid[$i].',';
  1235. }
  1236. return $qg;
  1237. }
  1238. //处理栏目提交变量
  1239. function DoPostClassVar($add){
  1240. if(empty($add[classtype])){
  1241. $add[classtype]=".html";
  1242. }
  1243. $add[classname]=addslashes(htmlspecialchars($add[classname]));
  1244. $add[intro]=addslashes(RepPhpAspJspcode($add[intro]));
  1245. $add[classpagekey]=addslashes(RepPhpAspJspcode($add[classpagekey]));
  1246. //过滤字符
  1247. $add[listorder]=RepPostVar2($add[listorder]);
  1248. $add[reorder]=RepPostVar2($add[reorder]);
  1249. //处理变量
  1250. $add[jstempid]=(int)$add['jstempid'];
  1251. $add[bclassid]=(int)$add[bclassid];
  1252. $add[link_num]=(int)$add[link_num];
  1253. $add[newstempid]=(int)$add[newstempid];
  1254. $add[islast]=(int)$add[islast];
  1255. $add[filename]=(int)$add[filename];
  1256. $add[openpl]=(int)$add[openpl];
  1257. $add[openadd]=(int)$add[openadd];
  1258. $add[newline]=(int)$add[newline];
  1259. $add[hotline]=(int)$add[hotline];
  1260. $add[goodline]=(int)$add[goodline];
  1261. $add[groupid]=(int)$add[groupid];
  1262. $add[hotplline]=(int)$add[hotplline];
  1263. $add[modid]=(int)$add[modid];
  1264. $add[checked]=(int)$add[checked];
  1265. $add[firstline]=(int)$add[firstline];
  1266. $add[islist]=(int)$add[islist];
  1267. $add[searchtempid]=(int)$add[searchtempid];
  1268. $add[checkpl]=(int)$add[checkpl];
  1269. $add[down_num]=(int)$add[down_num];
  1270. if(empty($add[down_num])){
  1271. $add[down_num]=1;
  1272. }
  1273. $add[online_num]=(int)$add[online_num];
  1274. if(empty($add[online_num])){
  1275. $add[online_num]=1;
  1276. }
  1277. $add[addinfofen]=(int)$add[addinfofen];
  1278. $add[listdt]=(int)$add[listdt];
  1279. $add[showdt]=(int)$add[showdt];
  1280. $add[maxnum]=(int)$add[maxnum];
  1281. $add[showclass]=(int)$add[showclass];
  1282. $add[checkqadd]=(int)$add[checkqadd];
  1283. $add[qaddlist]=(int)$add[qaddlist];
  1284. $add[qaddgroupid]=DoPostClassQAddGroupid($add[qaddgroupidck]);
  1285. $add[qaddshowkey]=(int)$add[qaddshowkey];
  1286. $add[adminqinfo]=(int)$add[adminqinfo];
  1287. $add[doctime]=(int)$add[doctime];
  1288. $add[nreclass]=(int)$add[nreclass];
  1289. $add[nreinfo]=(int)$add[nreinfo];
  1290. $add[nrejs]=(int)$add[nrejs];
  1291. $add[nottobq]=(int)$add[nottobq];
  1292. $add[lencord]=(int)$add[lencord];
  1293. $add[listtempid]=(int)$add[listtempid];
  1294. $add[dtlisttempid]=(int)$add[dtlisttempid];
  1295. $add[classtempid]=(int)$add[classtempid];
  1296. if(empty($add[bname])){
  1297. $add[bname]=$add[classname];
  1298. }
  1299. $add[myorder]=(int)$add[myorder];
  1300. if($add[infopath]==0)
  1301. {
  1302. $add[ipath]='';
  1303. }
  1304. $add[addreinfo]=(int)$add[addreinfo];
  1305. $add[haddlist]=(int)$add[haddlist];
  1306. $add[sametitle]=(int)$add[sametitle];
  1307. $add[definfovoteid]=(int)$add[definfovoteid];
  1308. $add[qeditchecked]=(int)$add[qeditchecked];
  1309. $add[wapstyleid]=(int)$add[wapstyleid];
  1310. $add[repreinfo]=(int)$add[repreinfo];
  1311. $add[pltempid]=(int)$add[pltempid];
  1312. $add[classtext]=RepPhpAspJspcode($add[classtext]);
  1313. $add[yhid]=(int)$add[yhid];
  1314. $add[wfid]=(int)$add[wfid];
  1315. if($add['islist']==3)
  1316. {
  1317. $add['bdinfoid']=RepPostVar($add['bdinfoid']);
  1318. }
  1319. else
  1320. {
  1321. $add['bdinfoid']='';
  1322. }
  1323. //设置访问权限
  1324. $add[cgroupid]=DoPostClassQAddGroupid($add[cgroupidck]);
  1325. $add[cgtoinfo]=(int)$add[cgtoinfo];
  1326. if($add[cgroupid])
  1327. {
  1328. $add[classtype]='.php';
  1329. if($add[cgtoinfo])
  1330. {
  1331. $add[filetype]='.php';
  1332. }
  1333. }
  1334. else
  1335. {
  1336. $add[cgtoinfo]=0;
  1337. }
  1338. return $add;
  1339. }
  1340. //增加外部栏目
  1341. function AddWbClass($add,$userid,$username){
  1342. global $empire,$dbtbpre;
  1343. //操作权限
  1344. CheckLevel($userid,$username,$classid,"class");
  1345. $add=DoPostClassVar($add);
  1346. if(!$add[classname]||!$add[wburl])
  1347. {
  1348. printerror("EmptyWbClass","");
  1349. }
  1350. $add[islast]=0;
  1351. //取得表名
  1352. $tabler=GetModTable($add[modid]);
  1353. $tabler[tid]=(int)$tabler[tid];
  1354. if(empty($add[bclassid]))//主栏目
  1355. {
  1356. $sonclass="";
  1357. $featherclass="";
  1358. }
  1359. else//中级栏目
  1360. {
  1361. //取得上一级父栏目
  1362. $r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
  1363. if($r[islast])//是否终极栏目
  1364. {
  1365. printerror("BclassNotLast","");
  1366. }
  1367. if($r[wburl])
  1368. {
  1369. printerror("BclassNotWb","");
  1370. }
  1371. if(empty($r[featherclass]))
  1372. {
  1373. $r[featherclass]="|";
  1374. }
  1375. $featherclass=$r[featherclass].$add[bclassid]."|";
  1376. $sonclass="";
  1377. }
  1378. $sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,is_zt,sonclass,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,hotline,goodline,classurl,groupid,myorder,filename_qz,hotplline,modid,checked,firstline,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorder,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid,repreinfo,pltempid,cgroupid,yhid,wfid,cgtoinfo,bdinfoid) values($add[bclassid],'$add[classname]',0,'$sonclass',$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[hotline],$add[goodline],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[modid],$add[checked],$add[firstline],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorder]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],'$add[qaddgroupid]',$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'$add[wburl]',$add[qeditchecked],$add[wapstyleid],'$add[repreinfo]','$add[pltempid]','$add[cgroupid]','$add[yhid]','$add[wfid]','$add[cgtoinfo]','$add[bdinfoid]');");
  1379. $lastid=$empire->lastid();
  1380. //副表
  1381. $ret_cr=ReturnClassAddF($add,0);
  1382. $empire->query("replace into {$dbtbpre}enewsclassadd(classid,classtext".$ret_cr[0].") values('$lastid','".addslashes($add[classtext])."'".$ret_cr[1].");");
  1383. GetClass();
  1384. DelListEnews();//删除缓存文件
  1385. if($sql)
  1386. {
  1387. insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
  1388. printerror("AddClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
  1389. }
  1390. else
  1391. {
  1392. printerror("DbError","");
  1393. }
  1394. }
  1395. //增加栏目
  1396. function AddClass($add,$userid,$username){
  1397. global $empire,$dbtbpre;
  1398. //增加外部栏目
  1399. if($add[ecmsclasstype])
  1400. {
  1401. AddWbClass($add,$userid,$username);
  1402. }
  1403. $add[classpath]=trim($add[classpath]);
  1404. if(!$add[classname]||!$add[classpath]||!$add[modid])
  1405. {
  1406. printerror("EmptyClass","");
  1407. }
  1408. if($add[islast]&&(!$add[newstempid]||!$add[listtempid]))
  1409. {
  1410. printerror("LastMustChange","");
  1411. }
  1412. //操作权限
  1413. CheckLevel($userid,$username,$classid,"class");
  1414. $add=DoPostClassVar($add);
  1415. //目录已存在
  1416. if(strstr($add[classpath],".")||strstr($add[classpath],"/")||strstr($add[classpath],"\\"))
  1417. {
  1418. printerror("badpath","");
  1419. }
  1420. $classpath=$add[pripath].$add[classpath];
  1421. if(file_exists("../../".$classpath))
  1422. {
  1423. printerror("ReClasspath","");
  1424. }
  1425. //取得表名
  1426. $tabler=GetModTable($add[modid]);
  1427. $tabler[tid]=(int)$tabler[tid];
  1428. //增加大栏目
  1429. if(!$add[islast])
  1430. {
  1431. if(empty($add[bclassid]))//主栏目
  1432. {
  1433. $sonclass="";
  1434. $featherclass="";
  1435. }
  1436. else//中级栏目
  1437. {
  1438. //取得上一级父栏目
  1439. $r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
  1440. if($r[islast])//是否终极栏目
  1441. {
  1442. printerror("BclassNotLast","");
  1443. }
  1444. if($r[wburl])
  1445. {
  1446. printerror("BclassNotWb","");
  1447. }
  1448. if(empty($r[featherclass]))
  1449. {
  1450. $r[featherclass]="|";
  1451. }
  1452. $featherclass=$r[featherclass].$add[bclassid]."|";
  1453. $sonclass="";
  1454. }
  1455. //建立目录
  1456. CreateClassPath($classpath);
  1457. $sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,is_zt,sonclass,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,hotline,goodline,classurl,groupid,myorder,filename_qz,hotplline,modid,checked,firstline,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorder,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid,repreinfo,pltempid,cgroupid,yhid,wfid,cgtoinfo,bdinfoid) values($add[bclassid],'$add[classname]',0,'$sonclass',$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[hotline],$add[goodline],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[modid],$add[checked],$add[firstline],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorder]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],'$add[qaddgroupid]',$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'',$add[qeditchecked],$add[wapstyleid],'$add[repreinfo]','$add[pltempid]','$add[cgroupid]','$add[yhid]','$add[wfid]','$add[cgtoinfo]','$add[bdinfoid]');");
  1458. $lastid=$empire->lastid();
  1459. //副表
  1460. $ret_cr=ReturnClassAddF($add,0);
  1461. $empire->query("replace into {$dbtbpre}enewsclassadd(classid,classtext".$ret_cr[0].") values('$lastid','".addslashes($add[classtext])."'".$ret_cr[1].");");
  1462. TogNotReClass(1);
  1463. GetClass();
  1464. if($add[islist]==0||$add[islist]==2)
  1465. {
  1466. $classtemp=$add[islist]==2?GetClassText($lastid):GetClassTemp($add['classtempid']);
  1467. NewsBq($lastid,$classtemp,0,1);
  1468. }
  1469. elseif($add[islist]==3)//栏目绑定信息
  1470. {
  1471. ReClassBdInfo($lastid);
  1472. }
  1473. DelListEnews();//删除缓存文件
  1474. GetSearch($add[modid]);//更新缓存
  1475. if($sql){
  1476. insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
  1477. printerror("AddClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
  1478. }
  1479. else{
  1480. printerror("DbError","");
  1481. }
  1482. }
  1483. //增加终级栏目
  1484. else
  1485. {
  1486. //文件前缀
  1487. $add[filename_qz]=RepFilenameQz($add[filename_qz]);
  1488. if(empty($add[bclassid]))//主类别为终级栏目时
  1489. {
  1490. $sonclass="";
  1491. $featherclass="";
  1492. }
  1493. else//子栏目
  1494. {
  1495. //取得上一级父栏目
  1496. $r=$empire->fetch1("select featherclass,islast,wburl from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
  1497. //是否终极类别
  1498. if($r[islast])
  1499. {
  1500. printerror("BclassNotLast","");
  1501. }
  1502. if($r[wburl])
  1503. {
  1504. printerror("BclassNotWb","");
  1505. }
  1506. if(empty($r[featherclass])){
  1507. $r[featherclass]="|";
  1508. }
  1509. $featherclass=$r[featherclass].$add[bclassid]."|";
  1510. $sonclass="";
  1511. }
  1512. //建立栏目目录
  1513. CreateClassPath($classpath);
  1514. $sql=$empire->query("insert into {$dbtbpre}enewsclass(bclassid,classname,sonclass,is_zt,lencord,link_num,newstempid,onclick,listtempid,featherclass,islast,classpath,classtype,newspath,filename,filetype,openpl,openadd,newline,hotline,goodline,classurl,groupid,myorder,filename_qz,hotplline,modid,checked,firstline,bname,islist,searchtempid,tid,tbname,maxnum,checkpl,down_num,online_num,listorder,reorder,intro,classimg,jstempid,addinfofen,listdt,showclass,showdt,checkqadd,qaddlist,qaddgroupid,qaddshowkey,adminqinfo,doctime,classpagekey,dtlisttempid,classtempid,nreclass,nreinfo,nrejs,nottobq,ipath,addreinfo,haddlist,sametitle,definfovoteid,wburl,qeditchecked,wapstyleid,repreinfo,pltempid,cgroupid,yhid,wfid,cgtoinfo,bdinfoid) values($add[bclassid],'$add[classname]','$sonclass',0,$add[lencord],$add[link_num],$add[newstempid],0,$add[listtempid],'$featherclass',$add[islast],'$classpath','$add[classtype]','$add[newspath]',$add[filename],'$add[filetype]',$add[openpl],$add[openadd],$add[newline],$add[hotline],$add[goodline],'$add[classurl]',$add[groupid],$add[myorder],'$add[filename_qz]',$add[hotplline],$add[modid],$add[checked],$add[firstline],'$add[bname]',$add[islist],$add[searchtempid],$tabler[tid],'$tabler[tbname]',$add[maxnum],$add[checkpl],$add[down_num],$add[online_num],'$add[listorder]','$add[reorder]','$add[intro]','$add[classimg]',$add[jstempid],$add[addinfofen],$add[listdt],$add[showclass],$add[showdt],$add[checkqadd],$add[qaddlist],'$add[qaddgroupid]',$add[qaddshowkey],$add[adminqinfo],$add[doctime],'$add[classpagekey]','$add[dtlisttempid]','$add[classtempid]',$add[nreclass],$add[nreinfo],$add[nrejs],$add[nottobq],'$add[ipath]',$add[addreinfo],$add[haddlist],$add[sametitle],$add[definfovoteid],'',$add[qeditchecked],$add[wapstyleid],'$add[repreinfo]','$add[pltempid]','$add[cgroupid]','$add[yhid]','$add[wfid]','$add[cgtoinfo]','$add[bdinfoid]');");
  1515. $lastid=$empire->lastid();
  1516. //副表
  1517. $ret_cr=ReturnClassAddF($add,0);
  1518. $empire->query("replace into {$dbtbpre}enewsclassadd(classid,classtext".$ret_cr[0].") values('$lastid','".addslashes($add[classtext])."'".$ret_cr[1].");");
  1519. //修改父栏目的子栏目
  1520. if($add[bclassid])
  1521. {
  1522. $b_r=$empire->fetch1("select sonclass,featherclass from {$dbtbpre}enewsclass where classid='$add[bclassid]'");
  1523. if(empty($b_r[sonclass]))
  1524. {
  1525. $b_r[sonclass]="|";
  1526. }
  1527. $new_sonclass=$b_r[sonclass].$lastid."|";
  1528. $update=$empire->query("update {$dbtbpre}enewsclass set sonclass='$new_sonclass' where classid='$add[bclassid]'");
  1529. //更改父类别的父栏目的子栏目
  1530. $where=ReturnClass($b_r[featherclass]);
  1531. if(empty($where)){
  1532. $where="classid=0";
  1533. }
  1534. $bsql=$empire->query("select sonclass,classid from {$dbtbpre}enewsclass where ".$where);
  1535. while($br=$empire->fetch($bsql))
  1536. {
  1537. if(empty($br[sonclass]))
  1538. {
  1539. $br[sonclass]="|";
  1540. }
  1541. $new_sonclass=$br[sonclass].$lastid."|";
  1542. $update=$empire->query("update {$dbtbpre}enewsclass set sonclass='$new_sonclass' where classid='$br[classid]'");
  1543. }
  1544. }
  1545. DelListEnews();//删除缓存文件
  1546. TogNotReClass(1);
  1547. GetClass();
  1548. GetSearch($add[modid]);//更新缓存
  1549. if($sql){
  1550. insert_dolog("classid=".$lastid."<br>classname=".$add[classname]);//操作日志
  1551. printerror("AddLastClassSuccess","AddClass.php?enews=AddClass&from=$add[from]");
  1552. }

Large files files are truncated, but you can click here to view the full file