moddofun.php 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614
  1. <?php
  2. //************************************ 数据表 ************************************
  3. //建立初始表
  4. function AddTableDefault($tbname,$tid){
  5. global $empire,$dbtbpre,$ecms_config;
  6. include("db/DefaultTable.php");
  7. //未审核表
  8. $otb=$dbtbpre."ecms_".$tbname;
  9. $tb=$otb."_check";
  10. CopyEcmsTb($otb,$tb);
  11. $odtb=$dbtbpre."ecms_".$tbname."_data_1";
  12. $dtb=$tb."_data";
  13. CopyEcmsTb($odtb,$dtb);
  14. //复制存档表
  15. $otb=$dbtbpre."ecms_".$tbname;
  16. $tb=$otb."_doc";
  17. CopyEcmsTb($otb,$tb);
  18. $odtb=$dbtbpre."ecms_".$tbname."_data_1";
  19. $dtb=$tb."_data";
  20. CopyEcmsTb($odtb,$dtb);
  21. $optb=$dbtbpre."ecms_".$tbname."_index";
  22. $ptb=$tb."_index";
  23. CopyEcmsTb($optb,$ptb);
  24. }
  25. //复制数据表
  26. function CopyNewTable($add,$userid,$username){
  27. global $empire,$dbtbpre;
  28. $tid=(int)$add['tid'];
  29. $newtbname=RepPostVar(strtolower(trim($add[newtbname])));
  30. if(!$tid||empty($newtbname)||!$add[tname])
  31. {
  32. printerror("EmptyTbname","");
  33. }
  34. CheckLevel($userid,$username,$classid,"table");//操作权限
  35. $add[yhid]=(int)$add[yhid];
  36. $add['tname']=hRepPostStr($add['tname'],1);
  37. $add['tsay']=hRepPostStr($add['tsay'],1);
  38. $tr=$empire->fetch1("select tbname,intb from {$dbtbpre}enewstable where tid='$tid'");
  39. if(!$tr[tbname])
  40. {
  41. printerror("EmptyTbname","");
  42. }
  43. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$newtbname' limit 1");
  44. if($num)
  45. {
  46. printerror("ReTbname","history.go(-1)");
  47. }
  48. $sql=$empire->query("insert into {$dbtbpre}enewstable(tbname,tname,tsay,isdefault,datatbs,deftb,yhid,mid,intb) values('$newtbname','$add[tname]','$add[tsay]',0,',1,','1','$add[yhid]',0,'$tr[intb]');");
  49. $newtid=$empire->lastid();
  50. //复制表
  51. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname'],$dbtbpre."ecms_".$newtbname); //内容表
  52. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_data_1",$dbtbpre."ecms_".$newtbname."_data_1"); //内容副表
  53. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_index",$dbtbpre."ecms_".$newtbname."_index"); //内容索引表
  54. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_doc",$dbtbpre."ecms_".$newtbname."_doc"); //归档表
  55. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_doc_data",$dbtbpre."ecms_".$newtbname."_doc_data"); //归档副表
  56. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_doc_index",$dbtbpre."ecms_".$newtbname."_doc_index"); //归档索引表
  57. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_check",$dbtbpre."ecms_".$newtbname."_check"); //审核表
  58. CopyEcmsTb($dbtbpre."ecms_".$tr['tbname']."_check_data",$dbtbpre."ecms_".$newtbname."_check_data"); //审核副表
  59. CopyEcmsTb($dbtbpre."ecms_infoclass_".$tr['tbname'],$dbtbpre."ecms_infoclass_".$newtbname); //采集节点附加表
  60. CopyEcmsTb($dbtbpre."ecms_infotmp_".$tr['tbname'],$dbtbpre."ecms_infotmp_".$newtbname); //采集数据临时表
  61. //字段数据
  62. $fsql=$empire->query("select * from {$dbtbpre}enewsf where tid=$tid order by fid");
  63. while($fr=$empire->fetch($fsql))
  64. {
  65. $usql=$empire->query("insert into {$dbtbpre}enewsf(f,fname,fform,fhtml,fzs,isadd,isshow,iscj,cjhtml,myorder,ftype,flen,dotemp,tid,tbname,savetxt,fvalue,iskey,tobr,dohtml,qfhtml,isonly,linkfieldval,samedata,fformsize,tbdataf,ispage,adddofun,editdofun,qadddofun,qeditdofun,linkfieldtb,linkfieldshow,editorys,issmalltext,fmvnum) values('$fr[f]','$fr[fname]','$fr[fform]','".addslashes(addslashes(stripSlashes($fr['fhtml'])))."','".addslashes(stripSlashes($fr[fzs]))."',$fr[isadd],$fr[isshow],$fr[iscj],'".addslashes(addslashes(stripSlashes($fr[cjhtml])))."',$fr[myorder],'$fr[ftype]','$fr[flen]',$fr[dotemp],$newtid,'$newtbname',$fr[savetxt],'".addslashes(addslashes(stripSlashes($fr[fvalue])))."',$fr[iskey],$fr[tobr],$fr[dohtml],'".addslashes(addslashes(stripSlashes($fr[qfhtml])))."','$fr[isonly]','".addslashes(stripSlashes($fr[linkfieldval]))."','$fr[samedata]','".addslashes(stripSlashes($fr[fformsize]))."','$fr[tbdataf]','$fr[ispage]','".addslashes(stripSlashes($fr[adddofun]))."','".addslashes(stripSlashes($fr[editdofun]))."','".addslashes(stripSlashes($fr[qadddofun]))."','".addslashes(stripSlashes($fr[qeditdofun]))."','".addslashes(stripSlashes($fr[linkfieldtb]))."','".addslashes(stripSlashes($fr[linkfieldshow]))."','$fr[editorys]','$fr[issmalltext]','".addslashes(stripSlashes($fr[fmvnum]))."');");
  66. }
  67. TogSaveTxtF(1);//公共变量
  68. GetConfig(1);//更新缓存
  69. if($sql)
  70. {
  71. //操作日志
  72. insert_dolog("tid=".$tid."<br>tb=".$tr[tbname]."<br>newtid=".$newtid."<br>newtb=".$newtbname);
  73. printerror("CopyTbSuccess","db/ListTable.php".hReturnEcmsHashStrHref2(1));
  74. }
  75. else
  76. {
  77. printerror("DbError","");
  78. }
  79. }
  80. //建立数据表
  81. function AddTable($add,$userid,$username){
  82. global $empire,$dbtbpre;
  83. $add[tbname]=RepPostVar(strtolower(trim($add[tbname])));
  84. if(!$add[tbname]||!$add[tname])
  85. {
  86. printerror("EmptyTbname","history.go(-1)");
  87. }
  88. //操作权限
  89. CheckLevel($userid,$username,$classid,"table");
  90. $add[yhid]=(int)$add[yhid];
  91. $add['intb']=(int)$add['intb'];
  92. $add['tname']=hRepPostStr($add['tname'],1);
  93. $add['tsay']=hRepPostStr($add['tsay'],1);
  94. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$add[tbname]' limit 1");
  95. if($num)
  96. {
  97. printerror("ReTbname","history.go(-1)");
  98. }
  99. $sql=$empire->query("insert into {$dbtbpre}enewstable(tbname,tname,tsay,isdefault,datatbs,deftb,yhid,intb) values('$add[tbname]','$add[tname]','$add[tsay]',0,',1,','1','$add[yhid]','$add[intb]');");
  100. $tid=$empire->lastid();
  101. //初使化表
  102. AddTableDefault($add[tbname],$tid);
  103. GetConfig(1);//更新缓存
  104. if($sql)
  105. {
  106. //操作日志
  107. insert_dolog("tid=".$tid."<br>tbname=".$add[tbname]);
  108. printerror("AddTbSuccess","db/AddTable.php?enews=AddTable".hReturnEcmsHashStrHref2(0));
  109. }
  110. else
  111. {
  112. printerror("DbError","history.go(-1)");
  113. }
  114. }
  115. //修改数据表
  116. function EditTable($add,$userid,$username){
  117. global $empire,$dbtbpre;
  118. $add[tbname]=RepPostVar(strtolower(trim($add[tbname])));
  119. $tid=(int)$add[tid];
  120. if(!$add[tbname]||!$add[tname]||!$tid)
  121. {
  122. printerror("EmptyTbname","history.go(-1)");
  123. }
  124. //操作权限
  125. CheckLevel($userid,$username,$classid,"table");
  126. $add[yhid]=(int)$add[yhid];
  127. $add['intb']=(int)$add['intb'];
  128. $add['tname']=hRepPostStr($add['tname'],1);
  129. $add['tsay']=hRepPostStr($add['tsay'],1);
  130. //改变数据表名
  131. if($add[tbname]!=$add[oldtbname])
  132. {
  133. $add[oldtbname]=RepPostVar($add[oldtbname]);
  134. $tbnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$add[tbname]' and tid<>$tid limit 1");
  135. if($tbnum)
  136. {
  137. printerror("ReTbname","history.go(-1)");
  138. }
  139. $tbr=$empire->fetch1("select tid,isdefault,datatbs,deftb from {$dbtbpre}enewstable where tid='$tid' limit 1");
  140. if(!$tbr['tid'])
  141. {
  142. printerror("EmptyTbname","history.go(-1)");
  143. }
  144. //主表
  145. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."` RENAME `{$dbtbpre}ecms_".$add[tbname]."`;");
  146. //索引表
  147. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_index` RENAME `{$dbtbpre}ecms_".$add[tbname]."_index`;");
  148. //副表
  149. if($tbr['datatbs'])
  150. {
  151. $dtbr=explode(',',$tbr['datatbs']);
  152. $count=count($dtbr);
  153. for($i=1;$i<$count-1;$i++)
  154. {
  155. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_data_".$dtbr[$i]."` RENAME `{$dbtbpre}ecms_".$add[tbname]."_data_".$dtbr[$i]."`;");
  156. }
  157. }
  158. //归档表
  159. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_doc` RENAME `{$dbtbpre}ecms_".$add[tbname]."_doc`;");
  160. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_doc_data` RENAME `{$dbtbpre}ecms_".$add[tbname]."_doc_data`;");
  161. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_doc_index` RENAME `{$dbtbpre}ecms_".$add[tbname]."_doc_index`;");
  162. //审核表
  163. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_check` RENAME `{$dbtbpre}ecms_".$add[tbname]."_check`;");
  164. $empire->query("ALTER TABLE `{$dbtbpre}ecms_".$add[oldtbname]."_check_data` RENAME `{$dbtbpre}ecms_".$add[tbname]."_check_data`;");
  165. //采集
  166. $empire->query("ALTER TABLE `{$dbtbpre}ecms_infoclass_".$add[oldtbname]."` RENAME `{$dbtbpre}ecms_infoclass_".$add[tbname]."`;");
  167. $empire->query("ALTER TABLE `{$dbtbpre}ecms_infotmp_".$add[oldtbname]."` RENAME `{$dbtbpre}ecms_infotmp_".$add[tbname]."`;");
  168. //字段
  169. $empire->query("update {$dbtbpre}enewsf set tbname='$add[tbname]' where tid='$tid'");
  170. //栏目
  171. $empire->query("update {$dbtbpre}enewsclass set tbname='$add[tbname]' where tid='$tid'");
  172. //$empire->query("update {$dbtbpre}enewszt set tbname='$add[tbname]' where tid='$tid'");
  173. $empire->query("update {$dbtbpre}enewsinfoclass set tbname='$add[tbname]' where tid='$tid'");
  174. $empire->query("update {$dbtbpre}enewsmod set tbname='$add[tbname]' where tid='$tid'");
  175. $empire->query("update {$dbtbpre}enewsinfotype set tbname='$add[tbname]' where tid='$tid'");
  176. //搜索
  177. $empire->query("update {$dbtbpre}enewssearch set tbname='$add[tbname]' where tbname='$add[oldtbname]'");
  178. $empire->query("update {$dbtbpre}enewssearchall_load set tbname='$add[tbname]' where tbname='$add[oldtbname]'");
  179. //默认表
  180. if($tbr['isdefault'])
  181. {
  182. $empire->query("update {$dbtbpre}enewspublic set tbname='$add[tbname]',tid='$tid'");
  183. }
  184. //文本型
  185. TogSaveTxtF(1);
  186. }
  187. $sql=$empire->query("update {$dbtbpre}enewstable set tbname='$add[tbname]',tname='$add[tname]',tsay='$add[tsay]',yhid='$add[yhid]',intb='$add[intb]' where tid='$tid'");
  188. GetConfig(1);//更新缓存
  189. if($sql)
  190. {
  191. //操作日志
  192. insert_dolog("tid=".$tid."<br>tbname=".$add[tbname]);
  193. printerror("EditTbSuccess","db/ListTable.php".hReturnEcmsHashStrHref2(1));
  194. }
  195. else
  196. {
  197. printerror("DbError","history.go(-1)");
  198. }
  199. }
  200. //删除数据表
  201. function DelTable($tid,$userid,$username){
  202. global $empire,$dbtbpre;
  203. $tid=(int)$tid;
  204. if(!$tid)
  205. {
  206. printerror("NotChangeTb","");
  207. }
  208. //操作权限
  209. CheckLevel($userid,$username,$classid,"table");
  210. $r=$empire->fetch1("select tid,tbname,isdefault,datatbs,deftb from {$dbtbpre}enewstable where tid='$tid'");
  211. if(empty($r[tid]))
  212. {
  213. printerror("NotChangeTb","");
  214. }
  215. //默认表
  216. if($r['isdefault'])
  217. {
  218. printerror("NotDelDefaultTb","");
  219. }
  220. $sql=$empire->query("delete from {$dbtbpre}enewstable where tid='$tid'");
  221. //删除数据表
  222. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname].";");
  223. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_index;");
  224. if($r['datatbs'])
  225. {
  226. $dtbr=explode(',',$r['datatbs']);
  227. $count=count($dtbr);
  228. for($i=1;$i<$count-1;$i++)
  229. {
  230. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_data_".$dtbr[$i].";");
  231. }
  232. }
  233. //删除采集表
  234. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_infoclass_".$r[tbname].";");
  235. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_infotmp_".$r[tbname].";");
  236. //删除归档表
  237. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_doc;");
  238. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_doc_data;");
  239. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_doc_index;");
  240. //删除审核表
  241. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_check;");
  242. $empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$r[tbname]."_check_data;");
  243. //删除数据
  244. $empire->query("delete from {$dbtbpre}enewsf where tid='$tid'");
  245. $empire->query("delete from {$dbtbpre}enewsmod where tid='$tid'");
  246. $empire->query("delete from {$dbtbpre}enewsinfoclass where tid='$tid'");
  247. //文本型
  248. TogSaveTxtF(1);
  249. GetConfig(1);//更新缓存
  250. if($sql)
  251. {
  252. //操作日志
  253. insert_dolog("tid=".$tid."<br>tbname=".$r[tbname]);
  254. printerror("DelTbSuccess","db/ListTable.php".hReturnEcmsHashStrHref2(1));
  255. }
  256. else
  257. {
  258. printerror("DbError","history.go(-1)");
  259. }
  260. }
  261. //默认数据表
  262. function DefaultTable($tid,$userid,$username){
  263. global $empire,$dbtbpre;
  264. $tid=(int)$tid;
  265. if(!$tid)
  266. {
  267. printerror("NotChangeDefaultTb","history.go(-1)");
  268. }
  269. //操作权限
  270. CheckLevel($userid,$username,$classid,"table");
  271. $r=$empire->fetch1("select tid,tbname from {$dbtbpre}enewstable where tid='$tid'");
  272. if(empty($r[tid]))
  273. {
  274. printerror("NotChangeDefaultTb","history.go(-1)");
  275. }
  276. $usql=$empire->query("update {$dbtbpre}enewstable set isdefault=0");
  277. $sql=$empire->query("update {$dbtbpre}enewstable set isdefault=1 where tid='$tid'");
  278. $upsql=$empire->query("update {$dbtbpre}enewspublic set tbname='$r[tbname]',tid='$tid'");
  279. GetConfig(1);//更新缓存
  280. if($sql&&$usql&&$upsql)
  281. {
  282. //操作日志
  283. insert_dolog("tid=".$tid."<br>tbname=".$r[tbname]);
  284. printerror("DefaultTableSuccess","db/ListTable.php".hReturnEcmsHashStrHref2(1));
  285. }
  286. else
  287. {
  288. printerror("DbError","history.go(-1)");
  289. }
  290. }
  291. //增加副表分表
  292. function AddDataTable($add,$userid,$username){
  293. global $empire,$dbtbpre;
  294. //操作权限
  295. CheckLevel($userid,$username,$classid,"table");
  296. $tid=(int)$add['tid'];
  297. $tbname=RepPostVar($add['tbname']);
  298. $datatb=(int)$add['datatb'];
  299. if(!$tid||!$tbname||!$datatb)
  300. {
  301. printerror("EmptyDataTable","history.go(-1)");
  302. }
  303. $tr=$empire->fetch1("select tid,datatbs from {$dbtbpre}enewstable where tid='$tid'");
  304. if(!$tr['tid'])
  305. {
  306. printerror("EmptyDataTable","history.go(-1)");
  307. }
  308. if(strstr($tr['datatbs'],','.$datatb.','))
  309. {
  310. printerror("ReDataTable","history.go(-1)");
  311. }
  312. if(empty($tr['datatbs']))
  313. {
  314. $tr['datatbs']=',';
  315. }
  316. $newdatatbs=$tr['datatbs'].$datatb.',';
  317. //建表
  318. $odtb=$dbtbpre."ecms_".$tbname."_data_1";
  319. $dtb=$dbtbpre."ecms_".$tbname."_data_".$datatb;
  320. CopyEcmsTb($odtb,$dtb);
  321. $sql=$empire->query("update {$dbtbpre}enewstable set datatbs='$newdatatbs' where tid='$tid'");
  322. GetConfig(1);//更新缓存
  323. if($sql)
  324. {
  325. //操作日志
  326. insert_dolog("tid=".$tid."<br>tbname=".$tbname."&datatb=$datatb");
  327. printerror("AddDataTableSuccess","db/ListDataTable.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  328. }
  329. else
  330. {
  331. printerror("DbError","history.go(-1)");
  332. }
  333. }
  334. //默认副表存放表
  335. function DefDataTable($add,$userid,$username){
  336. global $empire,$dbtbpre;
  337. //操作权限
  338. CheckLevel($userid,$username,$classid,"table");
  339. $tid=(int)$add['tid'];
  340. $tbname=RepPostVar($add['tbname']);
  341. $datatb=(int)$add['datatb'];
  342. if(!$tid||!$tbname||!$datatb)
  343. {
  344. printerror("NotChangeDataTable","history.go(-1)");
  345. }
  346. $tr=$empire->fetch1("select tid,datatbs from {$dbtbpre}enewstable where tid='$tid'");
  347. if(!$tr['tid'])
  348. {
  349. printerror("NotChangeDataTable","history.go(-1)");
  350. }
  351. if(!strstr($tr['datatbs'],','.$datatb.','))
  352. {
  353. printerror("NotChangeDataTable","history.go(-1)");
  354. }
  355. $sql=$empire->query("update {$dbtbpre}enewstable set deftb='$datatb' where tid='$tid'");
  356. GetConfig(1);//更新缓存
  357. if($sql)
  358. {
  359. //操作日志
  360. insert_dolog("tid=".$tid."<br>tbname=".$tbname."&datatb=$datatb");
  361. printerror("DefDataTableSuccess","db/ListDataTable.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  362. }
  363. else
  364. {
  365. printerror("DbError","history.go(-1)");
  366. }
  367. }
  368. //删除副表分表
  369. function DelDataTable($add,$userid,$username){
  370. global $empire,$dbtbpre,$emod_r,$class_r;
  371. //操作权限
  372. CheckLevel($userid,$username,$classid,"table");
  373. $tid=(int)$add['tid'];
  374. $tbname=RepPostVar($add['tbname']);
  375. $datatb=(int)$add['datatb'];
  376. if(!$tid||!$tbname||!$datatb)
  377. {
  378. printerror("NotChangeDataTable","history.go(-1)");
  379. }
  380. $tr=$empire->fetch1("select tid,tbname,datatbs,deftb from {$dbtbpre}enewstable where tid='$tid'");
  381. if(!$tr['tid'])
  382. {
  383. printerror("NotChangeDataTable","history.go(-1)");
  384. }
  385. if(!strstr($tr['datatbs'],','.$datatb.','))
  386. {
  387. printerror("NotChangeDataTable","history.go(-1)");
  388. }
  389. if($tr['deftb']==$datatb||$datatb==1)
  390. {
  391. printerror("NotDelDefDataTable","history.go(-1)");
  392. }
  393. $newdatatbs=str_replace(','.$datatb.',',',',$tr['datatbs']);
  394. $sql=$empire->query("update {$dbtbpre}enewstable set datatbs='$newdatatbs' where tid='$tid'");
  395. //删除信息
  396. $infosql=$empire->query("select * from {$dbtbpre}ecms_".$tr[tbname]." where stb='$datatb'");
  397. while($infor=$empire->fetch($infosql))
  398. {
  399. $mid=$class_r[$infor[classid]]['modid'];
  400. $pf=$emod_r[$mid]['pagef'];
  401. $stf=$emod_r[$mid]['savetxtf'];
  402. //分页字段
  403. if($pf)
  404. {
  405. if(strstr($emod_r[$mid]['tbdataf'],','.$pf.','))
  406. {
  407. $finfor=$empire->fetch1("select ".$pf." from {$dbtbpre}ecms_".$tr[tbname]."_data_".$datatb." where id='$infor[id]'");
  408. $infor[$pf]=$finfor[$pf];
  409. }
  410. }
  411. //存文本
  412. if($stf)
  413. {
  414. $newstextfile=$infor[$stf];
  415. $infor[$stf]=GetTxtFieldText($infor[$stf]);
  416. DelTxtFieldText($newstextfile);//删除文件
  417. }
  418. //删除信息文件
  419. DelNewsFile($infor[filename],$infor[newspath],$infor[classid],$infor[$pf],$infor[groupid]);
  420. //删除主表信息
  421. $empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_index where id='$infor[id]'");
  422. //删除其它表记录和附件
  423. DelSingleInfoOtherData($infor[classid],$infor[id],$infor,0,0);
  424. }
  425. $deltb=$empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]." where stb='$datatb'");
  426. //删除归档信息
  427. $docinfosql=$empire->query("select * from {$dbtbpre}ecms_".$tr[tbname]."_doc where stb='$datatb'");
  428. while($infor=$empire->fetch($docinfosql))
  429. {
  430. $mid=$class_r[$infor[classid]]['modid'];
  431. $pf=$emod_r[$mid]['pagef'];
  432. $stf=$emod_r[$mid]['savetxtf'];
  433. //分页字段
  434. if($pf)
  435. {
  436. if(strstr($emod_r[$mid]['tbdataf'],','.$pf.','))
  437. {
  438. $finfor=$empire->fetch1("select ".$pf." from {$dbtbpre}ecms_".$tr[tbname]."_doc_data where id='$infor[id]'");
  439. $infor[$pf]=$finfor[$pf];
  440. }
  441. }
  442. //存文本
  443. if($stf)
  444. {
  445. $newstextfile=$infor[$stf];
  446. $infor[$stf]=GetTxtFieldText($infor[$stf]);
  447. DelTxtFieldText($newstextfile);//删除文件
  448. }
  449. //删除信息文件
  450. DelNewsFile($infor[filename],$infor[newspath],$infor[classid],$infor[$pf],$infor[groupid]);
  451. //删除主表信息
  452. $empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_doc_index where id='$infor[id]'");
  453. //删除副表信息
  454. $empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_doc_data where id='$infor[id]'");
  455. //删除其它表记录与附件
  456. DelSingleInfoOtherData($infor['classid'],$infor['id'],$infor,0,0);
  457. }
  458. $deltb=$empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_doc where stb='$datatb'");
  459. //删除审核信息
  460. $bakinfosql=$empire->query("select * from {$dbtbpre}ecms_".$tr[tbname]."_check where stb='$datatb'");
  461. while($infor=$empire->fetch($bakinfosql))
  462. {
  463. $mid=$class_r[$infor[classid]]['modid'];
  464. $pf=$emod_r[$mid]['pagef'];
  465. $stf=$emod_r[$mid]['savetxtf'];
  466. //分页字段
  467. if($pf)
  468. {
  469. if(strstr($emod_r[$mid]['tbdataf'],','.$pf.','))
  470. {
  471. $finfor=$empire->fetch1("select ".$pf." from {$dbtbpre}ecms_".$tr[tbname]."_check_data where id='$infor[id]'");
  472. $infor[$pf]=$finfor[$pf];
  473. }
  474. }
  475. //存文本
  476. if($stf)
  477. {
  478. $newstextfile=$infor[$stf];
  479. $infor[$stf]=GetTxtFieldText($infor[$stf]);
  480. DelTxtFieldText($newstextfile);//删除文件
  481. }
  482. //删除信息文件
  483. DelNewsFile($infor[filename],$infor[newspath],$infor[classid],$infor[$pf],$infor[groupid]);
  484. //删除主表信息
  485. $empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_index where id='$infor[id]'");
  486. //删除副表信息
  487. $empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_check_data where id='$infor[id]'");
  488. //删除其它表记录和附件
  489. DelSingleInfoOtherData($infor['classid'],$infor['id'],$infor,0,0);
  490. }
  491. $deltb=$empire->query("delete from {$dbtbpre}ecms_".$tr[tbname]."_check where stb='$datatb'");
  492. //删除表
  493. $deltb=$empire->query("DROP TABLE IF EXISTS {$dbtbpre}ecms_".$tr[tbname]."_data_".$datatb.";");
  494. GetConfig(1);//更新缓存
  495. if($sql)
  496. {
  497. //操作日志
  498. insert_dolog("tid=".$tid."<br>tbname=".$tr[tbname]."&datatb=$datatb");
  499. printerror("DelDataTableSuccess","db/ListDataTable.php?tid=$tid&tbname=$tr[tbname]".hReturnEcmsHashStrHref2(0));
  500. }
  501. else
  502. {
  503. printerror("DbError","history.go(-1)");
  504. }
  505. }
  506. //************************************ 字段 ************************************
  507. //返回字段值
  508. function ReturnFvalue($value){
  509. $value=str_replace("\r\n","|",$value);
  510. return $value;
  511. }
  512. //取得表单元素html代码
  513. function GetFform($type,$f,$fvalue,$linkfieldval,$fformsize='',$add){
  514. if($type=="select"||$type=="radio"||$type=="checkbox")
  515. {
  516. return GetFformSelect($type,$f,$fvalue,$fformsize);
  517. }
  518. $file="../data/html/fhtml.txt";
  519. $data=ReadFiletext($file);
  520. //特殊字段
  521. if($f=="newstext"||$f=="writer"||$f=="befrom"||$f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
  522. {
  523. $type=$f;
  524. }
  525. $exp="[!--".$type."--]";
  526. $r=explode($exp,$data);
  527. $string=str_replace("[!--enews.var--]",$f,$r[1]);
  528. $string=str_replace("[!--enews.def.val--]",$fvalue,$string);
  529. if($type=='linkfield')//选择外表关联字段
  530. {
  531. $string=str_replace("[!--enews.cfield.var--]",$add[linkfieldval],$string);
  532. $string=str_replace("[!--enews.vfield.var--]",$add[linkfieldshow],$string);
  533. $string=str_replace("[!--enews.ctbname--]",$add[linkfieldtb],$string);
  534. }
  535. elseif($type=='linkfieldselect')//下拉外表关联字段
  536. {
  537. $selectf=$add[linkfieldval]==$add[linkfieldshow]?$add[linkfieldval]:$add[linkfieldval].','.$add[linkfieldshow];
  538. $string=str_replace("[!--enews.cfield.var--]",$add[linkfieldval],$string);
  539. $string=str_replace("[!--enews.vfield.var--]",$add[linkfieldshow],$string);
  540. $string=str_replace("[!--enews.ctbname--]",$add[linkfieldtb],$string);
  541. $string=str_replace("[!--enews.selectf--]",$selectf,$string);
  542. }
  543. elseif($type=='editor'||$type=='newstext')//编辑器
  544. {
  545. $editortype=$add[editorys]==0?'Default':'Basic';
  546. $string=str_replace("[!--editor.type--]",$editortype,$string);
  547. $string=str_replace("[!--editor.basepath--]",'',$string);
  548. }
  549. elseif($type=='morevaluefield')//多值字段
  550. {
  551. $mvr=explode(',',$add['fmvnum']);
  552. $mv_var=ReturnMoreValueFieldHtmlVar($f,$mvr[0],$mvr[1],$mvr[2]);
  553. $string=str_replace("[!--enews.jstr--]",$mv_var['jstr'],$string);
  554. $string=str_replace("[!--enews.saytr--]",$mv_var['saytr'],$string);
  555. $string=str_replace("[!--enews.deftr--]",$mv_var['deftr'],$string);
  556. $string=str_replace("[!--enews.edittr--]",$mv_var['edittr'],$string);
  557. $string=str_replace("[!--enews.mvline--]",$mvr[1],$string);
  558. $string=str_replace("[!--enews.mvnum--]",$mvr[0],$string);
  559. $string=str_replace("[!--enews.mvmust--]",$mvr[2],$string);
  560. }
  561. $string=RepFformSize($f,$string,$type,$fformsize);
  562. return fAddAddsData($string);
  563. }
  564. //取得采集表单元素html代码
  565. function GetCjform($type,$f){
  566. $file="../data/html/cjhtml.txt";
  567. $data=ReadFiletext($file);
  568. //特殊字段
  569. if($f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
  570. {
  571. $type=$f;
  572. }
  573. if($type=="password"||$type=="select"||$type=="radio"||$type=="checkbox"||$type=="date"||$type=="color"||$type=="linkfield"||$type=="editor"||$type=="ubbeditor"||$type=="linkfieldselect"||$type=="morevaluefield"||$type=="datetime")
  574. {
  575. $type="text";
  576. }
  577. $exp="[!--".$type."--]";
  578. $r=explode($exp,$data);
  579. $string=str_replace("[!--enews.var--]",$f,$r[1]);
  580. return fAddAddsData($string);
  581. }
  582. //取得投稿表单元素html代码
  583. function GetQFform($type,$f,$fvalue,$fformsize='',$add){
  584. if($type=="select"||$type=="radio"||$type=="checkbox")
  585. {
  586. return GetFformSelect($type,$f,$fvalue,$fformsize);
  587. }
  588. $file="../data/html/qfhtml.txt";
  589. $data=ReadFiletext($file);
  590. //特殊字段
  591. if($f=="newstext"||$f=="downpath"||$f=="onlinepath"||$f=="morepic"||$f=="playerid")
  592. {
  593. $type=$f;
  594. }
  595. $exp="[!--".$type."--]";
  596. $r=explode($exp,$data);
  597. $string=str_replace("[!--enews.var--]",$f,$r[1]);
  598. $string=str_replace("[!--enews.def.val--]",$fvalue,$string);
  599. if($type=='linkfield')//选择外表关联字段
  600. {
  601. $string=str_replace("[!--enews.cfield.var--]",$add[linkfieldval],$string);
  602. $string=str_replace("[!--enews.vfield.var--]",$add[linkfieldshow],$string);
  603. $string=str_replace("[!--enews.ctbname--]",$add[linkfieldtb],$string);
  604. }
  605. elseif($type=='linkfieldselect')//下拉外表关联字段
  606. {
  607. $selectf=$add[linkfieldval]==$add[linkfieldshow]?$add[linkfieldval]:$add[linkfieldval].','.$add[linkfieldshow];
  608. $string=str_replace("[!--enews.cfield.var--]",$add[linkfieldval],$string);
  609. $string=str_replace("[!--enews.vfield.var--]",$add[linkfieldshow],$string);
  610. $string=str_replace("[!--enews.ctbname--]",$add[linkfieldtb],$string);
  611. $string=str_replace("[!--enews.selectf--]",$selectf,$string);
  612. }
  613. elseif($type=='editor'||$type=='newstext')//编辑器
  614. {
  615. $editortype=$add[editorys]==0?'Default':'Basic';
  616. $string=str_replace("[!--editor.type--]",$editortype,$string);
  617. $string=str_replace("[!--editor.basepath--]",'',$string);
  618. }
  619. elseif($type=='morevaluefield')//多值字段
  620. {
  621. $mvr=explode(',',$add['fmvnum']);
  622. $mv_var=ReturnMoreValueFieldHtmlVar($f,$mvr[0],$mvr[1],$mvr[2]);
  623. $string=str_replace("[!--enews.jstr--]",$mv_var['jstr'],$string);
  624. $string=str_replace("[!--enews.saytr--]",$mv_var['saytr'],$string);
  625. $string=str_replace("[!--enews.deftr--]",$mv_var['deftr'],$string);
  626. $string=str_replace("[!--enews.edittr--]",$mv_var['edittr'],$string);
  627. $string=str_replace("[!--enews.mvline--]",$mvr[1],$string);
  628. $string=str_replace("[!--enews.mvnum--]",$mvr[0],$string);
  629. $string=str_replace("[!--enews.mvmust--]",$mvr[2],$string);
  630. }
  631. $string=RepFformSize($f,$string,$type,$fformsize);
  632. return fAddAddsData($string);
  633. }
  634. //取得select/radio元素代码
  635. function GetFformSelect($type,$f,$fvalue,$fformsize=''){
  636. $vr=explode('|',$fvalue);
  637. $count=count($vr);
  638. $change='';
  639. $def=':default';
  640. for($i=0;$i<$count;$i++)
  641. {
  642. $isdef='';
  643. if(strstr($vr[$i],$def))
  644. {
  645. $dr=explode($def,$vr[$i]);
  646. $vr[$i]=$dr[0];
  647. $isdef="||\$ecmsfirstpost==1";
  648. }
  649. $selectvalr=explode('==',$vr[$i]);
  650. $val=$selectvalr[0];
  651. $valname=$selectvalr[1]?$selectvalr[1]:$selectvalr[0];
  652. if($type=='select')
  653. {
  654. $change.="<option value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' selected':''?>>".$valname."</option>";
  655. }
  656. elseif($type=='checkbox')
  657. {
  658. $change.="<input name=\"".$f."[]\" type=\"checkbox\" value=\"".$val."\"<?=strstr(\$r[".$f."],\"|".$val."|\")".$isdef."?' checked':''?>>".$valname;
  659. }
  660. else
  661. {
  662. $change.="<input name=\"".$f."\" type=\"radio\" value=\"".$val."\"<?=\$r[".$f."]==\"".$val."\"".$isdef."?' checked':''?>>".$valname;
  663. }
  664. }
  665. if($type=="select")
  666. {
  667. if($fformsize)
  668. {
  669. $addsize=' style="width:'.$fformsize.'"';
  670. }
  671. $change="<select name=\"".$f."\" id=\"".$f."\"".$addsize.">".$change."</select>";
  672. }
  673. return $change;
  674. }
  675. //替换表单元素长度
  676. function RepFformSize($f,$string,$type,$fformsize=''){
  677. $fformsize=ReturnDefFformSize($f,$type,$fformsize);
  678. if($type=='textarea'||$type=='editor'||$type=='ubbeditor'||$type=='newstext')
  679. {
  680. $r=explode(',',$fformsize);
  681. $string=str_replace('[!--fsize.w--]',$r[0],$string);
  682. $string=str_replace('[!--fsize.h--]',$r[1],$string);
  683. }
  684. else
  685. {
  686. $string=str_replace('[!--fsize.w--]',$fformsize,$string);
  687. }
  688. return $string;
  689. }
  690. //返回默认长度
  691. function ReturnDefFformSize($f,$type,$fformsize){
  692. if(empty($fformsize))
  693. {
  694. if($type=='textarea')
  695. {
  696. $fformsize='60,10';
  697. }
  698. elseif($type=='img')
  699. {
  700. $fformsize='45';
  701. }
  702. elseif($type=='file')
  703. {
  704. $fformsize='45';
  705. }
  706. elseif($type=='flash')
  707. {
  708. $fformsize='45';
  709. }
  710. elseif($type=='date')
  711. {
  712. $fformsize='12';
  713. }
  714. elseif($type=='datetime')
  715. {
  716. $fformsize='28';
  717. }
  718. elseif($type=='color')
  719. {
  720. $fformsize='10';
  721. }
  722. elseif($type=='linkfield')
  723. {
  724. $fformsize='45';
  725. }
  726. elseif($type=='downpath')
  727. {
  728. $fformsize='45';
  729. }
  730. elseif($type=='onlinepath')
  731. {
  732. $fformsize='45';
  733. }
  734. elseif($type=='editor'||$type=='newstext')
  735. {
  736. $fformsize='100%,300';
  737. }
  738. elseif($type=='ubbeditor')
  739. {
  740. $fformsize='60,10';
  741. }
  742. }
  743. return $fformsize;
  744. }
  745. //返回多值字段录入项html代码变量
  746. function ReturnMoreValueFieldHtmlVar($f,$mvnum,$mvline,$mvmust){
  747. global $fun_r;
  748. $del=' <input type="hidden" name="'.$f.'_mvid[]" id="'.$f.'_mvid_<?=$j?>" value="<?=$j?>"><input type="checkbox" name="'.$f.'_mvdelid[]" id="'.$f.'_mvdelid_<?=$j?>" value="<?=$j?>">'.$fun_r['FSingleDel'];
  749. $saytr='<tr>';
  750. $jstr='<tr>';
  751. $deftr='<tr>';
  752. $edittr='<tr>';
  753. for($i=0;$i<$mvnum;$i++)
  754. {
  755. $j=$i+1;
  756. //描述
  757. $saytr.='<td align="center">'.$fun_r['FSetting'].$j.'</td>';
  758. //JS
  759. $jstr.='<td align="center"><input type="text" name="'.$f.'_'.$j.'[]" id="'.$f.'_'.$j.'_\'+j+\'" value=""></td>';
  760. //默认
  761. $deftr.='<td align="center"><input type="text" name="'.$f.'_'.$j.'[]" id="'.$f.'_'.$j.'_<?=$i?>" value=""></td>';
  762. //修改
  763. $edittr.='<td align="center"><input type="text" name="'.$f.'_'.$j.'[]" id="'.$f.'_'.$j.'_<?=$j?>" value="<?=$mvf_field['.$i.']?>">'.($i==0?$del:'').'</td>';
  764. }
  765. $saytr.='</tr>';
  766. $jstr.='</tr>';
  767. $deftr.='</tr>';
  768. $edittr.='</tr>';
  769. $r['saytr']=$saytr;
  770. $r['jstr']=$jstr;
  771. $r['deftr']=$deftr;
  772. $r['edittr']=$edittr;
  773. return $r;
  774. }
  775. //返回字段变量
  776. function DoPostFVar($add){
  777. $add['tid']=(int)$add['tid'];
  778. $add['tbname']=RepPostVar($add['tbname']);
  779. $add['f']=RepPostVar($add['f']);
  780. //处理变量
  781. $add[iscj]=(int)$add[iscj];
  782. $add[myorder]=(int)$add[myorder];
  783. $add[savetxt]=(int)$add[savetxt];
  784. $add[iskey]=(int)$add[iskey];
  785. $add[tobr]=(int)$add[tobr];
  786. $add[dohtml]=(int)$add[dohtml];
  787. $add[isonly]=(int)$add[isonly];
  788. $add[samedata]=(int)$add[samedata];
  789. $add[tbdataf]=(int)$add[tbdataf];
  790. $add[ispage]=(int)$add[ispage];
  791. $add[editorys]=(int)$add[editorys];
  792. $add[issmalltext]=(int)$add[issmalltext];
  793. if($add[fform]=='textarea'||$add[fform]=='editor')
  794. {
  795. if($add[fformwidth]||$add[fformheight])
  796. {
  797. $add['fformsize']=$add[fformwidth].','.$add[fformheight];
  798. }
  799. }
  800. if($add[fform]=='morevaluefield')
  801. {
  802. $add['fmvnum']=intval($add['fmvnum']).','.intval($add['fmvline']).','.intval($add['fmvmust']);
  803. }
  804. else
  805. {
  806. $add['fmvnum']='';
  807. }
  808. $add['fname']=hRepPostStr($add['fname'],1);
  809. $add['fform']=hRepPostStr($add['fform'],1);
  810. $add['fzs']=hRepPostStr($add['fzs'],1);
  811. $add['ftype']=hRepPostStr($add['ftype'],1);
  812. $add['flen']=hRepPostStr($add['flen'],1);
  813. $add['linkfieldval']=hRepPostStr($add['linkfieldval'],1);
  814. $add['fformsize']=hRepPostStr($add['fformsize'],1);
  815. $add['adddofun']=hRepPostStr($add['adddofun'],0);
  816. $add['editdofun']=hRepPostStr($add['editdofun'],0);
  817. $add['qadddofun']=hRepPostStr($add['qadddofun'],0);
  818. $add['qeditdofun']=hRepPostStr($add['qeditdofun'],0);
  819. $add['linkfieldtb']=hRepPostStr($add['linkfieldtb'],1);
  820. $add['linkfieldshow']=hRepPostStr($add['linkfieldshow'],1);
  821. $add['fmvnum']=hRepPostStr($add['fmvnum'],1);
  822. return $add;
  823. }
  824. //验证字段是否重复
  825. function CheckReTbF($add,$ecms=0){
  826. global $empire,$dbtbpre;
  827. $specialf=',oldurl,tmptime,smallurl,newsurl,titlepicl,';
  828. if(stristr($specialf,','.$add[f].','))
  829. {
  830. printerror("ReF","history.go(-1)");
  831. }
  832. //修改
  833. if($ecms==1&&$add[f]==$add[oldf])
  834. {
  835. return '';
  836. }
  837. //主表
  838. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}ecms_".$add[tbname]);
  839. $b=0;
  840. while($r=$empire->fetch($s))
  841. {
  842. if($r[Field]==$add[f])
  843. {
  844. $b=1;
  845. break;
  846. }
  847. }
  848. if($b)
  849. {
  850. printerror("ReF","history.go(-1)");
  851. }
  852. //副表
  853. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}ecms_".$add[tbname]."_data_1");
  854. $b=0;
  855. while($r=$empire->fetch($s))
  856. {
  857. if($r[Field]==$add[f])
  858. {
  859. $b=1;
  860. break;
  861. }
  862. }
  863. if($b)
  864. {
  865. printerror("ReF","history.go(-1)");
  866. }
  867. //索引表
  868. $s=$empire->query("SHOW FIELDS FROM {$dbtbpre}ecms_".$add[tbname]."_index");
  869. $b=0;
  870. while($r=$empire->fetch($s))
  871. {
  872. if($r[Field]==$add[f])
  873. {
  874. $b=1;
  875. break;
  876. }
  877. }
  878. if($b)
  879. {
  880. printerror("ReF","history.go(-1)");
  881. }
  882. }
  883. //返回字段类型
  884. function ReturnTbFtype($add){
  885. if($add[ftype]=="TINYINT"||$add[ftype]=="SMALLINT"||$add[ftype]=="INT"||$add[ftype]=="BIGINT"||$add[ftype]=="FLOAT"||$add[ftype]=="DOUBLE")
  886. {
  887. $def=" default '0'";
  888. }
  889. elseif($add[ftype]=="VARCHAR"||$add[ftype]=="CHAR")
  890. {
  891. $def=" default ''";
  892. }
  893. elseif($add[ftype]=="DATE")
  894. {
  895. $def=" default '0000-00-00'";
  896. }
  897. elseif($add[ftype]=="DATETIME")
  898. {
  899. $def=" default '0000-00-00 00:00:00'";
  900. }
  901. else
  902. {
  903. $def='';
  904. }
  905. $type=$add[ftype];
  906. //VARCHAR
  907. if(($add[ftype]=='VARCHAR'||$add[ftype]=='CHAR')&&empty($add[flen]))
  908. {
  909. $add[flen]='255';
  910. }
  911. //字段长度
  912. if($add[flen])
  913. {
  914. if($add[ftype]!="TEXT"&&$add[ftype]!="MEDIUMTEXT"&&$add[ftype]!="LONGTEXT"&&$add[ftype]!="DATE"&&$add[ftype]!="DATETIME")
  915. {
  916. $type.="(".$add[flen].")";
  917. }
  918. }
  919. $field=$add[f]." ".$type." NOT NULL".$def;
  920. return $field;
  921. }
  922. //增加字段
  923. function AddF($add,$userid,$username){
  924. global $empire,$dbtbpre;
  925. $add=DoPostFVar($add);
  926. $tid=$add[tid];
  927. $tbname=$add[tbname];
  928. if(empty($add[f])||empty($add[fname])||!$add[tid]||!$add[tbname])
  929. {
  930. printerror("EmptyF","history.go(-1)");
  931. }
  932. CheckLevel($userid,$username,$classid,"f");//验证权限
  933. CheckReTbF($add,0);//字段是否重复
  934. //存文本
  935. if($add[savetxt]==1)
  936. {
  937. $txtnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where savetxt=1 and tid='$tid'");
  938. if($txtnum)
  939. {
  940. printerror('ReTxtF','');
  941. }
  942. }
  943. //分页
  944. if($add['ispage']==1)
  945. {
  946. $pagenum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where ispage=1 and tid='$tid'");
  947. if($pagenum)
  948. {
  949. printerror('RePageF','');
  950. }
  951. }
  952. $add[fvalue]=ReturnFvalue($add[fvalue]);//初始化值
  953. $field=ReturnTbFtype($add);//返回字段
  954. //信息表新增字段
  955. if($add[tbdataf]==1)//附加表
  956. {
  957. $tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tid='$tid'");
  958. if($tbr['datatbs'])
  959. {
  960. $dtbr=explode(',',$tbr['datatbs']);
  961. $count=count($dtbr);
  962. for($i=1;$i<$count-1;$i++)
  963. {
  964. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." add ".$field);
  965. if($add[iskey]==1)//索引
  966. {
  967. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." ADD INDEX(".$add[f].")");
  968. }
  969. }
  970. }
  971. //归档副表
  972. $asql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc_data add ".$field);
  973. if($add[iskey]==1)//索引
  974. {
  975. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc_data ADD INDEX(".$add[f].")");
  976. }
  977. //审核副表
  978. $asql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_check_data add ".$field);
  979. if($add[iskey]==1)//索引
  980. {
  981. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check_data ADD INDEX(".$add[f].")");
  982. }
  983. }
  984. else//主表
  985. {
  986. $asql=$empire->query("alter table {$dbtbpre}ecms_".$tbname." add ".$field);
  987. if($add[iskey]==1)//索引
  988. {
  989. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." ADD INDEX(".$add[f].")");
  990. }
  991. //归档主表
  992. $asql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc add ".$field);
  993. if($add[iskey]==1)//索引
  994. {
  995. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc ADD INDEX(".$add[f].")");
  996. }
  997. //审核主表
  998. $asql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_check add ".$field);
  999. if($add[iskey]==1)//索引
  1000. {
  1001. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check ADD INDEX(".$add[f].")");
  1002. }
  1003. }
  1004. //采集表新增字段
  1005. if($add[iscj]==1)
  1006. {
  1007. $asql=$empire->query("alter table {$dbtbpre}ecms_infoclass_".$tbname." add zz_".$add[f]." text not null,add z_".$add[f]." varchar(255) not null,add qz_".$add[f]." varchar(255) not null,add save_".$add[f]." varchar(10) not null;");
  1008. $asql=$empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." add ".$field);
  1009. }
  1010. //替换代码
  1011. $fhtml=GetFform($add[fform],$add[f],$add[fvalue],$add[linkfieldval],$add[fformsize],$add);
  1012. $cjhtml=GetCjform($add[fform],$add[f]);
  1013. $qfhtml=GetQFform($add[fform],$add[f],$add[fvalue],$add[fformsize],$add);
  1014. $sql=$empire->query("insert into {$dbtbpre}enewsf(f,fname,fform,fhtml,fzs,isadd,isshow,iscj,cjhtml,myorder,ftype,flen,dotemp,tid,tbname,savetxt,fvalue,iskey,tobr,dohtml,qfhtml,isonly,linkfieldval,samedata,fformsize,tbdataf,ispage,adddofun,editdofun,qadddofun,qeditdofun,linkfieldtb,linkfieldshow,editorys,issmalltext,fmvnum) values('$add[f]','$add[fname]','$add[fform]','".eaddslashes2($fhtml)."','".eaddslashes($add[fzs])."',1,1,$add[iscj],'".eaddslashes2($cjhtml)."',$add[myorder],'$add[ftype]','$add[flen]',1,$tid,'$tbname',$add[savetxt],'".eaddslashes2($add[fvalue])."',$add[iskey],$add[tobr],$add[dohtml],'".eaddslashes2($qfhtml)."','$add[isonly]','".eaddslashes($add[linkfieldval])."','$add[samedata]','$add[fformsize]','$add[tbdataf]','$add[ispage]','$add[adddofun]','$add[editdofun]','$add[qadddofun]','$add[qeditdofun]','$add[linkfieldtb]','$add[linkfieldshow]','$add[editorys]','$add[issmalltext]','$add[fmvnum]');");
  1015. $lastid=$empire->lastid();
  1016. TogSaveTxtF(1);//公共变量
  1017. if($add[savetxt]==1&&$add[iscj]==1)//存放文本
  1018. {
  1019. $tmpsql=$empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." change ".$add[f]." ".$add[f]." mediumtext not null;");
  1020. }
  1021. GetConfig(1);//更新缓存
  1022. if($sql)
  1023. {
  1024. insert_dolog("fid=".$lastid."<br>f=".$add[f]);//操作日志
  1025. printerror("AddFSuccess","db/AddF.php?enews=AddF&tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  1026. }
  1027. else
  1028. {
  1029. printerror("DbError","history.go(-1)");
  1030. }
  1031. }
  1032. //修改数据库字段
  1033. function EditF($add,$userid,$username){
  1034. global $empire,$dbtbpre;
  1035. $add=DoPostFVar($add);
  1036. $tid=$add[tid];
  1037. $tbname=$add[tbname];
  1038. $add[fid]=(int)$add['fid'];
  1039. if(empty($add[f])||empty($add[fname])||empty($add[fid])||!$tid||!$tbname)
  1040. {
  1041. printerror("EmptyF","history.go(-1)");
  1042. }
  1043. CheckLevel($userid,$username,$classid,"f");//验证权限
  1044. //是否系统内部字段
  1045. $cr=$empire->fetch1("select * from {$dbtbpre}enewsf where fid='$add[fid]'");
  1046. if(empty($cr[isadd]))
  1047. {
  1048. printerror("NotIsAdd","history.go(-1)");
  1049. }
  1050. CheckReTbF($add,1);//字段是否重复
  1051. //存文本
  1052. if($add[savetxt]==1&&!$cr[savetxt])
  1053. {
  1054. $txtnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where savetxt=1 and fid<>".$add[fid]." and tid='$tid'");
  1055. if($txtnum)
  1056. {
  1057. printerror('ReTxtF','');
  1058. }
  1059. }
  1060. //分页
  1061. if($add['ispage']==1&&!$cr[ispage])
  1062. {
  1063. $pagenum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsf where ispage=1 and fid<>".$add[fid]." and tid='$tid'");
  1064. if($pagenum)
  1065. {
  1066. printerror('RePageF','');
  1067. }
  1068. }
  1069. $add[fvalue]=ReturnFvalue($add[fvalue]);//初始化值
  1070. //改变字段
  1071. if($cr[f]<>$add[f]||$add[iskey]<>$cr[iskey]||$cr[iscj]<>$add[iscj]||$cr[ftype]<>$add[ftype]||$cr[flen]<>$add[flen])
  1072. {
  1073. $field=ReturnTbFtype($add);//返回字段
  1074. //信息表
  1075. if($cr[tbdataf]==1)//附加表
  1076. {
  1077. $tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tid='$tid'");
  1078. if($tbr['datatbs'])
  1079. {
  1080. $dtbr=explode(',',$tbr['datatbs']);
  1081. $count=count($dtbr);
  1082. for($i=1;$i<$count-1;$i++)
  1083. {
  1084. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." change ".$add[oldf]." ".$field);
  1085. if($add[iskey]==1)//索引
  1086. {
  1087. if($cr[iskey]==0)
  1088. {
  1089. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." ADD INDEX(".$add[f].")");
  1090. }
  1091. }
  1092. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1093. {
  1094. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." DROP INDEX ".$add[oldf]);
  1095. }
  1096. }
  1097. }
  1098. //归档副表
  1099. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc_data change ".$add[oldf]." ".$field);
  1100. if($add[iskey]==1)//索引
  1101. {
  1102. if($cr[iskey]==0)
  1103. {
  1104. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc_data ADD INDEX(".$add[f].")");
  1105. }
  1106. }
  1107. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1108. {
  1109. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc_data DROP INDEX ".$add[oldf]);
  1110. }
  1111. //审核副表
  1112. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_check_data change ".$add[oldf]." ".$field);
  1113. if($add[iskey]==1)//索引
  1114. {
  1115. if($cr[iskey]==0)
  1116. {
  1117. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check_data ADD INDEX(".$add[f].")");
  1118. }
  1119. }
  1120. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1121. {
  1122. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check_data DROP INDEX ".$add[oldf]);
  1123. }
  1124. }
  1125. else//主表
  1126. {
  1127. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname." change ".$add[oldf]." ".$field);
  1128. if($add[iskey]==1)//索引
  1129. {
  1130. if($cr[iskey]==0)
  1131. {
  1132. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." ADD INDEX(".$add[f].")");
  1133. }
  1134. }
  1135. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1136. {
  1137. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." DROP INDEX ".$add[oldf]);
  1138. }
  1139. //归档主表
  1140. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc change ".$add[oldf]." ".$field);
  1141. if($add[iskey]==1)//索引
  1142. {
  1143. if($cr[iskey]==0)
  1144. {
  1145. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc ADD INDEX(".$add[f].")");
  1146. }
  1147. }
  1148. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1149. {
  1150. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc DROP INDEX ".$add[oldf]);
  1151. }
  1152. //审核主表
  1153. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_check change ".$add[oldf]." ".$field);
  1154. if($add[iskey]==1)//索引
  1155. {
  1156. if($cr[iskey]==0)
  1157. {
  1158. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check ADD INDEX(".$add[f].")");
  1159. }
  1160. }
  1161. elseif($cr[iskey]==1&&$add[iskey]==0)//删除索引
  1162. {
  1163. $keysql=$empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check DROP INDEX ".$add[oldf]);
  1164. }
  1165. }
  1166. //采集表
  1167. if($add[iscj]==1)
  1168. {
  1169. if($cr[iscj]==1)
  1170. {
  1171. $empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." change ".$add[oldf]." ".$field);
  1172. $empire->query("alter table {$dbtbpre}ecms_infoclass_".$tbname." change zz_".$add[oldf]." zz_".$add[f]." text not null,change z_".$add[oldf]." z_".$add[f]." varchar(255) not null,change qz_".$add[oldf]." qz_".$add[f]." varchar(255) not null,change save_".$add[oldf]." save_".$add[f]." varchar(10) not null;");
  1173. }
  1174. else
  1175. {
  1176. $empire->query("alter table {$dbtbpre}ecms_infoclass_".$tbname." add zz_".$add[f]." text not null,add z_".$add[f]." varchar(255) not null,add qz_".$add[f]." varchar(255) not null,add save_".$add[f]." varchar(10) not null;");
  1177. $empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." add ".$field);
  1178. }
  1179. }
  1180. elseif($add[iscj]==0&&$cr[iscj]==1)
  1181. {
  1182. $empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." drop COLUMN ".$cr[f]);
  1183. $empire->query("alter table {$dbtbpre}ecms_infoclass_".$tbname." drop COLUMN zz_".$cr[f].",drop COLUMN z_".$cr[f].",drop COLUMN qz_".$cr[f].",drop COLUMN save_".$cr[f]);
  1184. }
  1185. }
  1186. //替换代码
  1187. if($add[f]<>$cr[f]||$add[fform]<>$cr[fform]||$add[fvalue]<>$add[oldfvalue]||$cr[linkfieldtb]<>$add[linkfieldtb]||$cr[linkfieldshow]<>$add[linkfieldshow]||$cr[editorys]<>$add[editorys]||$add[linkfieldval]<>$cr[linkfieldval]||$add[fformsize]<>$cr[fformsize]||$add[fmvnum]<>$cr[fmvnum])
  1188. {
  1189. $fhtml=GetFform($add[fform],$add[f],$add[fvalue],$add[linkfieldval],$add[fformsize],$add);
  1190. }
  1191. else
  1192. {
  1193. $fhtml=$add[fhtml];
  1194. }
  1195. $cjhtml=GetCjform($add[fform],$add[f]);
  1196. if($add[f]<>$cr[f]||$add[fform]<>$cr[fform]||$add[fvalue]<>$add[oldfvalue]||$cr[linkfieldtb]<>$add[linkfieldtb]||$cr[linkfieldshow]<>$add[linkfieldshow]||$cr[editorys]<>$add[editorys]||$add[linkfieldval]<>$cr[linkfieldval]||$add[fformsize]<>$cr[fformsize]||$add[fmvnum]<>$cr[fmvnum])
  1197. {
  1198. $qfhtml=GetQFform($add[fform],$add[f],$add[fvalue],$add[fformsize],$add);
  1199. }
  1200. else
  1201. {
  1202. $qfhtml=$add[qfhtml];
  1203. }
  1204. $sql=$empire->query("update {$dbtbpre}enewsf set f='$add[f]',fname='$add[fname]',fform='$add[fform]',fhtml='".eaddslashes2($fhtml)."',fzs='".eaddslashes($add[fzs])."',iscj=$add[iscj],cjhtml='".eaddslashes2($cjhtml)."',myorder=$add[myorder],ftype='$add[ftype]',flen='$add[flen]',fvalue='".eaddslashes2($add[fvalue])."',iskey=$add[iskey],tobr=$add[tobr],dohtml=$add[dohtml],qfhtml='".eaddslashes2($qfhtml)."',isonly='$add[isonly]',linkfieldval='$add[linkfieldval]',samedata='$add[samedata]',fformsize='$add[fformsize]',ispage='$add[ispage]',adddofun='$add[adddofun]',editdofun='$add[editdofun]',qadddofun='$add[qadddofun]',qeditdofun='$add[qeditdofun]',linkfieldtb='$add[linkfieldtb]',linkfieldshow='$add[linkfieldshow]',editorys='$add[editorys]',issmalltext='$add[issmalltext]',fmvnum='$add[fmvnum]' where fid='$add[fid]'");
  1205. TogSaveTxtF(1);//公共变量
  1206. if($add[savetxt]==1&&$add[iscj]==1)
  1207. {
  1208. $tmpsql=$empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." change ".$add[f]." ".$add[f]." mediumtext not null;");
  1209. }
  1210. //更新表单
  1211. $record="<!--record-->";
  1212. $field="<!--field--->";
  1213. $like=$field.$add[oldf].$record;
  1214. $newlike=$field.$add[f].$record;
  1215. $slike=",".$add[oldf].",";
  1216. $newslike=",".$add[f].",";
  1217. $fsql=$empire->query("select mid,mtemp,cj,enter,tempvar,searchvar,tid,qenter,mustqenterf,qmtemp,listandf,listtempvar,canaddf,caneditf,orderf from {$dbtbpre}enewsmod where tid='$tid'");
  1218. while($fr=$empire->fetch($fsql))
  1219. {
  1220. $and="";
  1221. $enter=$fr['enter'];
  1222. if($add[f]<>$add[oldf])
  1223. {
  1224. //采集项
  1225. if(strstr($fr[cj],$like))
  1226. {
  1227. $cj=str_replace($like,$newlike,$fr[cj]);
  1228. $and=",cj='$cj'";
  1229. ChangeMCj($fr[mid],$fr[tid],$cj);
  1230. }
  1231. //录入项
  1232. if(strstr($fr[enter],$like))
  1233. {
  1234. $enter=str_replace($like,$newlike,$fr[enter]);
  1235. $and.=",enter='$enter'";
  1236. }
  1237. //投稿项
  1238. if(strstr($fr[qenter],$like))
  1239. {
  1240. $qenter=str_replace($like,$newlike,$fr[qenter]);
  1241. $and.=",qenter='$qenter'";
  1242. }
  1243. //内容模板项
  1244. if(strstr($fr[tempvar],$like))
  1245. {
  1246. $tempvar=str_replace($like,$newlike,$fr[tempvar]);
  1247. $and.=",tempvar='$tempvar'";
  1248. }
  1249. //列表模板项
  1250. if(strstr($fr[listtempvar],$like))
  1251. {
  1252. $listtempvar=str_replace($like,$newlike,$fr[listtempvar]);
  1253. $and.=",listtempvar='$listtempvar'";
  1254. }
  1255. //搜索项
  1256. if(strstr($fr[searchvar],$slike))
  1257. {
  1258. $searchvar=str_replace($slike,$newslike,$fr[searchvar]);
  1259. $and.=",searchvar='$searchvar'";
  1260. }
  1261. //必填项
  1262. if(strstr($fr[mustqenterf],$slike))
  1263. {
  1264. $mustqenterf=str_replace($slike,$newslike,$fr[mustqenterf]);
  1265. $and.=",mustqenterf='$mustqenterf'";
  1266. }
  1267. //结合项
  1268. if(strstr($fr[listandf],$slike))
  1269. {
  1270. $listandf=str_replace($slike,$newslike,$fr[listandf]);
  1271. $and.=",listandf='$listandf'";
  1272. }
  1273. //排序项
  1274. if(strstr($fr[orderf],$slike))
  1275. {
  1276. $orderf=str_replace($slike,$newslike,$fr[orderf]);
  1277. $and.=",orderf='$orderf'";
  1278. }
  1279. //可修改
  1280. if(strstr($fr[caneditf],$slike))
  1281. {
  1282. $caneditf=str_replace($slike,$newslike,$fr[caneditf]);
  1283. $and.=",caneditf='$caneditf'";
  1284. }
  1285. //可增加
  1286. if(strstr($fr[canaddf],$slike))
  1287. {
  1288. $canaddf=str_replace($slike,$newslike,$fr[canaddf]);
  1289. $and.=",canaddf='$canaddf'";
  1290. }
  1291. //表单模板
  1292. if(strstr($fr[mtemp],'[!--'.$add[oldf].'--]'))
  1293. {
  1294. $fr[mtemp]=str_replace('[!--'.$add[oldf].'--]','[!--'.$add[f].'--]',$fr[mtemp]);
  1295. $and.=",mtemp='".addslashes(stripSlashes($fr[mtemp]))."'";
  1296. }
  1297. //投稿表单模板
  1298. if(strstr($fr[qmtemp],'[!--'.$add[oldf].'--]'))
  1299. {
  1300. $fr[qmtemp]=str_replace('[!--'.$add[oldf].'--]','[!--'.$add[f].'--]',$fr[qmtemp]);
  1301. $and.=",qmtemp='".addslashes(stripSlashes($fr[qmtemp]))."'";
  1302. }
  1303. if($and)
  1304. {
  1305. $empire->query("update {$dbtbpre}enewsmod set mid='$fr[mid]'".$and." where mid='$fr[mid]'");
  1306. }
  1307. }
  1308. ChangeMForm($fr[mid],$fr[tid],$fr[mtemp]);
  1309. ChangeQmForm($fr[mid],$fr[tid],$fr[qmtemp]);
  1310. }
  1311. GetConfig(1);//更新缓存
  1312. if($sql)
  1313. {
  1314. insert_dolog("fid=".$add[fid]."<br>f=".$add[f]);//操作日志
  1315. printerror("EditFSuccess","db/ListF.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  1316. }
  1317. else
  1318. {printerror("DbError","history.go(-1)");}
  1319. }
  1320. //修改数据表系统字段
  1321. function EditSysF($add,$userid,$username){
  1322. global $empire,$dbtbpre;
  1323. $tid=(int)$add['tid'];
  1324. $tbname=RepPostVar($add['tbname']);
  1325. $fid=(int)$add['fid'];
  1326. $f=RepPostVar($add['f']);
  1327. if(!$fid||!$tid||!$tbname||!$f||!$add[fname])
  1328. {
  1329. printerror("EmptyF","history.go(-1)");
  1330. }
  1331. CheckLevel($userid,$username,$classid,"f");//验证权限
  1332. $add['fname']=hRepPostStr($add['fname'],1);
  1333. $add['fform']=hRepPostStr($add['fform'],1);
  1334. $add['fzs']=hRepPostStr($add['fzs'],1);
  1335. $add['ftype']=hRepPostStr($add['ftype'],1);
  1336. $add['flen']=hRepPostStr($add['flen'],1);
  1337. $add['linkfieldval']=hRepPostStr($add['linkfieldval'],1);
  1338. $add['fformsize']=hRepPostStr($add['fformsize'],1);
  1339. $add['adddofun']=hRepPostStr($add['adddofun'],0);
  1340. $add['editdofun']=hRepPostStr($add['editdofun'],0);
  1341. $add['qadddofun']=hRepPostStr($add['qadddofun'],0);
  1342. $add['qeditdofun']=hRepPostStr($add['qeditdofun'],0);
  1343. $add['linkfieldtb']=hRepPostStr($add['linkfieldtb'],1);
  1344. $add['linkfieldshow']=hRepPostStr($add['linkfieldshow'],1);
  1345. $add['fmvnum']=hRepPostStr($add['fmvnum'],1);
  1346. $add[samedata]=(int)$add[samedata];
  1347. //字段
  1348. $addupdate='';
  1349. if($f=='title'||$f=='titlepic')
  1350. {
  1351. if(!empty($add['flen']))
  1352. {
  1353. $field=$f." ".$add['ftype']."(".$add['flen'].") NOT NULL default ''";
  1354. //信息表
  1355. $empire->query("alter table {$dbtbpre}ecms_".$tbname." change ".$f." ".$field);
  1356. //归档表
  1357. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc change ".$f." ".$field);
  1358. //审核表
  1359. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check change ".$f." ".$field);
  1360. //采集临时表
  1361. $empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." change ".$f." ".$field);
  1362. }
  1363. $addupdate=",ftype='$add[ftype]'";
  1364. }
  1365. //索引
  1366. $iskey=(int)$add['iskey'];
  1367. if($f=='title'||$f=='titlepic')
  1368. {
  1369. if($iskey==1)//索引
  1370. {
  1371. if($add['oldiskey']==0)
  1372. {
  1373. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." ADD INDEX(".$f.")");
  1374. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc ADD INDEX(".$f.")");
  1375. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check ADD INDEX(".$f.")");
  1376. }
  1377. }
  1378. elseif($add['oldiskey']==1&&$iskey==0)//删除索引
  1379. {
  1380. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." DROP INDEX ".$f);
  1381. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc DROP INDEX ".$f);
  1382. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check DROP INDEX ".$f);
  1383. }
  1384. }
  1385. //处理变量
  1386. $add[isonly]=(int)$add[isonly];
  1387. $add[myorder]=(int)$add[myorder];
  1388. //替换代码
  1389. if($add[fform]<>$add[oldfform]||$add[fvalue]<>$add[oldfvalue]||$add[oldlinkfieldtb]<>$add[linkfieldtb]||$add[oldlinkfieldshow]<>$add[linkfieldshow]||$add[linkfieldval]<>$add[oldlinkfieldval]||$add[fformsize]<>$add[oldfformsize])
  1390. {
  1391. $fhtml=GetFform($add[fform],$add[f],$add[fvalue],$add[linkfieldval],$add[fformsize],$add);
  1392. }
  1393. else
  1394. {
  1395. $fhtml=$add[fhtml];
  1396. }
  1397. if($add[fform]<>$add[oldfform]||$add[fvalue]<>$add[oldfvalue]||$add[oldlinkfieldtb]<>$add[linkfieldtb]||$add[oldlinkfieldshow]<>$add[linkfieldshow]||$add[linkfieldval]<>$add[oldlinkfieldval]||$add[fformsize]<>$add[oldfformsize])
  1398. {
  1399. $qfhtml=GetQFform($add[fform],$add[f],$add[fvalue],$add[fformsize],$add);
  1400. }
  1401. else
  1402. {
  1403. $qfhtml=$add[qfhtml];
  1404. }
  1405. $sql=$empire->query("update {$dbtbpre}enewsf set fname='$add[fname]',fform='$add[fform]',fhtml='".eaddslashes2($fhtml)."',fzs='".eaddslashes($add[fzs])."',myorder=$add[myorder],flen='$add[flen]',fvalue='".eaddslashes2($add[fvalue])."',iskey=$iskey,qfhtml='".eaddslashes2($qfhtml)."',isonly='$add[isonly]',linkfieldval='$add[linkfieldval]',samedata='$add[samedata]',fformsize='$add[fformsize]',adddofun='$add[adddofun]',editdofun='$add[editdofun]',qadddofun='$add[qadddofun]',qeditdofun='$add[qeditdofun]',linkfieldtb='$add[linkfieldtb]',linkfieldshow='$add[linkfieldshow]'".$addupdate." where fid='$fid'");
  1406. TogSaveTxtF(1);//公共变量
  1407. //更新表单
  1408. $fsql=$empire->query("select mid,mtemp,tid,qmtemp from {$dbtbpre}enewsmod where tid='$tid'");
  1409. while($fr=$empire->fetch($fsql))
  1410. {
  1411. ChangeMForm($fr[mid],$fr[tid],$fr[mtemp]);
  1412. ChangeQmForm($fr[mid],$fr[tid],$fr[qmtemp]);
  1413. }
  1414. GetConfig(1);//更新缓存
  1415. if($sql)
  1416. {
  1417. insert_dolog("fid=".$fid."<br>f=".$f);//操作日志
  1418. printerror("EditFSuccess","db/EditSysF.php?tid=$tid&tbname=$tbname&fid=$fid".hReturnEcmsHashStrHref2(0));
  1419. }
  1420. else
  1421. {
  1422. printerror("DbError","history.go(-1)");
  1423. }
  1424. }
  1425. //删除数据库字段
  1426. function DelF($fid,$tid,$tbname,$userid,$username){
  1427. global $empire,$dbtbpre;
  1428. $tid=(int)$tid;
  1429. $tbname=RepPostVar($tbname);
  1430. $fid=(int)$fid;
  1431. if(empty($fid)||!$tid||!$tbname)
  1432. {
  1433. printerror("EmptyFid","history.go(-1)");
  1434. }
  1435. CheckLevel($userid,$username,$classid,"f");//验证权限
  1436. //是否系统内部字段
  1437. $cr=$empire->fetch1("select isadd,f,tbdataf,iscj from {$dbtbpre}enewsf where fid='$fid'");
  1438. if(empty($cr[isadd]))
  1439. {
  1440. printerror("NotIsAdd","history.go(-1)");
  1441. }
  1442. //删除表字段
  1443. if($cr['tbdataf']==1)
  1444. {
  1445. $tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tid='$tid'");
  1446. if($tbr['datatbs'])
  1447. {
  1448. $dtbr=explode(',',$tbr['datatbs']);
  1449. $count=count($dtbr);
  1450. for($i=1;$i<$count-1;$i++)
  1451. {
  1452. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." drop COLUMN ".$cr[f]);
  1453. }
  1454. }
  1455. //归档副表
  1456. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc_data drop COLUMN ".$cr[f]);
  1457. //审核副表
  1458. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check_data drop COLUMN ".$cr[f]);
  1459. }
  1460. else
  1461. {
  1462. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname." drop COLUMN ".$cr[f]);
  1463. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc drop COLUMN ".$cr[f]);
  1464. $usql=$empire->query("alter table {$dbtbpre}ecms_".$tbname."_check drop COLUMN ".$cr[f]);
  1465. }
  1466. //采集表字段
  1467. if($cr[iscj]==1)
  1468. {
  1469. $usql=$empire->query("alter table {$dbtbpre}ecms_infotmp_".$tbname." drop COLUMN ".$cr[f]);
  1470. $usql=$empire->query("alter table {$dbtbpre}ecms_infoclass_".$tbname." drop COLUMN zz_".$cr[f].",drop COLUMN z_".$cr[f].",drop COLUMN qz_".$cr[f].",drop COLUMN save_".$cr[f]);
  1471. }
  1472. $sql=$empire->query("delete from {$dbtbpre}enewsf where fid='$fid'");
  1473. TogSaveTxtF(1);//公共变量
  1474. //删除模型中字段项
  1475. $record="<!--record-->";
  1476. $field="<!--field--->";
  1477. $like=$field.$cr[f].$record;
  1478. $slike=",".$cr[f].",";
  1479. $dsql=$empire->query("select mid,cj,enter,tempvar,searchvar,tid,qenter,mustqenterf,listandf,listtempvar,canaddf,caneditf,orderf from {$dbtbpre}enewsmod where tid='$tid' and (cj like '%".$like."%' or enter like '%".$like."%' or searchvar like '%".$slike."%' or tempvar like '%".$like."%' or listtempvar like '%".$like."%' or qenter like '%".$like."%' or mustqenterf like '%".$slike."%' or listandf like '%".$slike."%' or canaddf like '%".$slike."%' or caneditf like '%".$slike."%' or orderf like '%".$slike."%')");
  1480. while($r=$empire->fetch($dsql))
  1481. {
  1482. $cj="";
  1483. $enter="";
  1484. $tempvar="";
  1485. $listtempvar="";
  1486. $searchvar="";
  1487. $qenter="";
  1488. $mustqenterf="";
  1489. $listandf="";
  1490. $orderf="";
  1491. $canaddf="";
  1492. $caneditf="";
  1493. $re="";
  1494. $re1="";
  1495. $and="";
  1496. $dh="";
  1497. //采集
  1498. if(strstr($r[cj],$like))
  1499. {
  1500. $re=explode($record,$r[cj]);
  1501. for($i=0;$i<count($re)-1;$i++)
  1502. {
  1503. if(strstr($re[$i].$record,$like))
  1504. {continue;}
  1505. $cj.=$re[$i].$record;
  1506. }
  1507. //更新采集表单
  1508. ChangeMCj($r[mid],$r[tid],$cj);
  1509. $and="cj='$cj'";
  1510. }
  1511. $dh="";
  1512. //录入表单
  1513. if(strstr($r[enter],$like))
  1514. {
  1515. $re1=explode($record,$r[enter]);
  1516. for($i=0;$i<count($re1)-1;$i++)
  1517. {
  1518. if(strstr($re1[$i].$record,$like))
  1519. {continue;}
  1520. $enter.=$re1[$i].$record;
  1521. }
  1522. if(!empty($and))
  1523. {$dh=",";}
  1524. $and.=$dh."enter='$enter'";
  1525. }
  1526. $dh="";
  1527. //投稿表单
  1528. if(strstr($r[qenter],$like))
  1529. {
  1530. $re1=explode($record,$r[qenter]);
  1531. for($i=0;$i<count($re1)-1;$i++)
  1532. {
  1533. if(strstr($re1[$i].$record,$like))
  1534. {continue;}
  1535. $qenter.=$re1[$i].$record;
  1536. }
  1537. if(!empty($and))
  1538. {$dh=",";}
  1539. $and.=$dh."qenter='$qenter'";
  1540. }
  1541. $dh="";
  1542. //内容模板变量
  1543. if(strstr($r[tempvar],$like))
  1544. {
  1545. $re1=explode($record,$r[tempvar]);
  1546. for($i=0;$i<count($re1)-1;$i++)
  1547. {
  1548. if(strstr($re1[$i].$record,$like))
  1549. {continue;}
  1550. $tempvar.=$re1[$i].$record;
  1551. }
  1552. if(!empty($and))
  1553. {$dh=",";}
  1554. $and.=$dh."tempvar='$tempvar'";
  1555. }
  1556. $dh="";
  1557. //列表模板变量
  1558. if(strstr($r[listtempvar],$like))
  1559. {
  1560. $re1=explode($record,$r[listtempvar]);
  1561. for($i=0;$i<count($re1)-1;$i++)
  1562. {
  1563. if(strstr($re1[$i].$record,$like))
  1564. {continue;}
  1565. $listtempvar.=$re1[$i].$record;
  1566. }
  1567. if(!empty($and))
  1568. {$dh=",";}
  1569. $and.=$dh."listtempvar='$listtempvar'";
  1570. }
  1571. $dh="";
  1572. //搜索变量
  1573. if(strstr($r[searchvar],$slike))
  1574. {
  1575. if(!empty($and))
  1576. {$dh=",";}
  1577. $searchvar=str_replace($slike,",",$r[searchvar]);
  1578. $and.=$dh."searchvar='$searchvar'";
  1579. }
  1580. //必填项
  1581. $dh="";
  1582. if(strstr($r[mustqenterf],$slike))
  1583. {
  1584. if(!empty($and))
  1585. {$dh=",";}
  1586. $mustqenterf=str_replace($slike,",",$r[mustqenterf]);
  1587. $and.=$dh."mustqenterf='$mustqenterf'";
  1588. }
  1589. //可增可修改项
  1590. $dh="";
  1591. if(strstr($r[canaddf],$slike))
  1592. {
  1593. if(!empty($and))
  1594. {$dh=",";}
  1595. $canaddf=str_replace($slike,",",$r[canaddf]);
  1596. $and.=$dh."canaddf='$canaddf'";
  1597. }
  1598. $dh="";
  1599. if(strstr($r[caneditf],$slike))
  1600. {
  1601. if(!empty($and))
  1602. {$dh=",";}
  1603. $caneditf=str_replace($slike,",",$r[caneditf]);
  1604. $and.=$dh."caneditf='$caneditf'";
  1605. }
  1606. //结合项
  1607. $dh="";
  1608. if(strstr($r[listandf],$slike))
  1609. {
  1610. if(!empty($and))
  1611. {$dh=",";}
  1612. $listandf=str_replace($slike,",",$r[listandf]);
  1613. $and.=$dh."listandf='$listandf'";
  1614. }
  1615. //排序项
  1616. $dh="";
  1617. if(strstr($r[orderf],$slike))
  1618. {
  1619. if(!empty($and))
  1620. {$dh=",";}
  1621. $orderf=str_replace($slike,",",$r[orderf]);
  1622. $and.=$dh."orderf='$orderf'";
  1623. }
  1624. if($and)
  1625. {
  1626. $empire->query("update {$dbtbpre}enewsmod set ".$and." where mid='$r[mid]'");
  1627. }
  1628. }
  1629. GetConfig(1);//更新缓存
  1630. if($sql)
  1631. {
  1632. //操作日志
  1633. insert_dolog("fid=".$fid."<br>f=".$cr[f]);
  1634. printerror("DelFSuccess","db/ListF.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  1635. }
  1636. else
  1637. {printerror("DbError","history.go(-1)");}
  1638. }
  1639. //修改字段顺序
  1640. function EditFOrder($fid,$myorder,$tid,$tbname,$userid,$username){
  1641. global $empire,$dbtbpre;
  1642. $tid=(int)$tid;
  1643. $tbname=RepPostVar($tbname);
  1644. //验证权限
  1645. CheckLevel($userid,$username,$classid,"f");
  1646. for($i=0;$i<count($myorder);$i++)
  1647. {
  1648. $newmyorder=(int)$myorder[$i];
  1649. $fid[$i]=(int)$fid[$i];
  1650. $usql=$empire->query("update {$dbtbpre}enewsf set myorder='$newmyorder' where fid='$fid[$i]'");
  1651. }
  1652. printerror("EditFOrderSuccess","db/ListF.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  1653. }
  1654. //转移字段
  1655. function ChangeDataTableF($add,$userid,$username){
  1656. global $empire,$dbtbpre,$public_r,$fun_r;
  1657. //验证权限
  1658. CheckLevel($userid,$username,$classid,"f");
  1659. $fid=(int)$add[fid];
  1660. $tid=(int)$add[tid];
  1661. $tbname=RepPostVar($add[tbname]);
  1662. $line=(int)$add[line];
  1663. $start=(int)$add[start];
  1664. if(!$fid||!$tid||!$tbname)
  1665. {
  1666. printerror("ErrorUrl","history.go(-1)");
  1667. }
  1668. if(empty($line))
  1669. {
  1670. $line=200;
  1671. }
  1672. $fr=$empire->fetch1("select * from {$dbtbpre}enewsf where fid='$fid'");
  1673. if(!$fr[fid])
  1674. {
  1675. printerror("ErrorUrl","history.go(-1)");
  1676. }
  1677. if(empty($fr[isadd]))
  1678. {
  1679. printerror("NotIsAdd","history.go(-1)");
  1680. }
  1681. $tid=$fr[tid];
  1682. $tbname=$fr[tbname];
  1683. $f=$fr[f];
  1684. //建字段
  1685. if(empty($start))
  1686. {
  1687. $field=ReturnTbFtype($fr);//返回字段
  1688. if($fr[tbdataf])//转移到主表
  1689. {
  1690. $empire->query("alter table {$dbtbpre}ecms_".$tbname." add ".$field);
  1691. if($fr[iskey]==1)//索引
  1692. {
  1693. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname." ADD INDEX(".$fr[f].")");
  1694. }
  1695. //归档主表
  1696. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc add ".$field);
  1697. if($fr[iskey]==1)//索引
  1698. {
  1699. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc ADD INDEX(".$fr[f].")");
  1700. }
  1701. //审核主表
  1702. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check add ".$field);
  1703. if($fr[iskey]==1)//索引
  1704. {
  1705. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check ADD INDEX(".$fr[f].")");
  1706. }
  1707. }
  1708. else//转移到副表
  1709. {
  1710. $tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tid='$tid'");
  1711. if($tbr['datatbs'])
  1712. {
  1713. $dtbr=explode(',',$tbr['datatbs']);
  1714. $count=count($dtbr);
  1715. for($i=1;$i<$count-1;$i++)
  1716. {
  1717. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." add ".$field);
  1718. if($fr[iskey]==1)//索引
  1719. {
  1720. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." ADD INDEX(".$fr[f].")");
  1721. }
  1722. }
  1723. }
  1724. //归档副表
  1725. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc_data add ".$field);
  1726. if($fr[iskey]==1)//索引
  1727. {
  1728. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_doc_data ADD INDEX(".$fr[f].")");
  1729. }
  1730. //审核副表
  1731. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check_data add ".$field);
  1732. if($fr[iskey]==1)//索引
  1733. {
  1734. $empire->query("ALTER TABLE {$dbtbpre}ecms_".$tbname."_check_data ADD INDEX(".$fr[f].")");
  1735. }
  1736. }
  1737. }
  1738. $selectf='';
  1739. if(empty($fr[tbdataf]))
  1740. {
  1741. $selectf=','.$fr[f];
  1742. }
  1743. $b=0;
  1744. $sql=$empire->query("select id,checked from {$dbtbpre}ecms_".$tbname."_index where id>$start order by id limit ".$line);
  1745. while($r=$empire->fetch($sql))
  1746. {
  1747. $b=1;
  1748. $newstart=$r['id'];
  1749. //表名
  1750. $infotb=ReturnInfoMainTbname($tbname,$r['checked']);
  1751. $infor=$empire->fetch1("select stb".$selectf." from ".$infotb." where id='$r[id]'");
  1752. $infodatatb=ReturnInfoDataTbname($tbname,$r['checked'],$infor['stb']);
  1753. if($fr[tbdataf])//副表
  1754. {
  1755. $finfor=$empire->fetch1("select ".$f." from ".$infodatatb." where id='$r[id]'");
  1756. $value=$finfor[$f];
  1757. $empire->query("update ".$infotb." set ".$f."='".StripAddsData($value)."' where id='$r[id]'");
  1758. }
  1759. else//主表
  1760. {
  1761. $value=$infor[$f];
  1762. $empire->query("update ".$infodatatb." set ".$f."='".StripAddsData($value)."' where id='$r[id]'");
  1763. }
  1764. }
  1765. if(empty($b))
  1766. {
  1767. echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmsmod.php?enews=ChangeDocDataTableF&tid=$tid&tbname=$tbname&fid=$fid&line=$line".hReturnEcmsHashStrHref(0)."\">".$fun_r[AllChangeDataTableFSuccess];
  1768. exit();
  1769. }
  1770. echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmsmod.php?enews=ChangeDataTableF&tid=$tid&tbname=$tbname&fid=$fid&line=$line&start=$newstart".hReturnEcmsHashStrHref(0)."\">".$fun_r[OneChangeDataTableFSuccess]."(ID:<font color=red><b>".$newstart."</b></font>)";
  1771. exit();
  1772. }
  1773. //转移字段(归档)
  1774. function ChangeDocDataTableF($add,$userid,$username){
  1775. global $empire,$dbtbpre,$public_r,$fun_r;
  1776. //验证权限
  1777. CheckLevel($userid,$username,$classid,"f");
  1778. $fid=(int)$add[fid];
  1779. $tid=(int)$add[tid];
  1780. $tbname=RepPostVar($add[tbname]);
  1781. $line=(int)$add[line];
  1782. $start=(int)$add[start];
  1783. if(!$fid||!$tid||!$tbname)
  1784. {
  1785. printerror("ErrorUrl","history.go(-1)");
  1786. }
  1787. if(empty($line))
  1788. {
  1789. $line=200;
  1790. }
  1791. $fr=$empire->fetch1("select * from {$dbtbpre}enewsf where fid='$fid'");
  1792. if(!$fr[fid])
  1793. {
  1794. printerror("ErrorUrl","history.go(-1)");
  1795. }
  1796. if(empty($fr[isadd]))
  1797. {
  1798. printerror("NotIsAdd","history.go(-1)");
  1799. }
  1800. $tid=$fr[tid];
  1801. $tbname=$fr[tbname];
  1802. $f=$fr[f];
  1803. $selectf='';
  1804. if(empty($fr[tbdataf]))
  1805. {
  1806. $selectf=','.$fr[f];
  1807. }
  1808. $b=0;
  1809. $sql=$empire->query("select id,stb".$selectf." from {$dbtbpre}ecms_".$tbname."_doc where id>$start order by id limit ".$line);
  1810. while($r=$empire->fetch($sql))
  1811. {
  1812. $b=1;
  1813. $newstart=$r['id'];
  1814. if($fr[tbdataf])//副表
  1815. {
  1816. $finfor=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname."_doc_data where id='$r[id]'");
  1817. $value=$finfor[$f];
  1818. $empire->query("update {$dbtbpre}ecms_".$tbname."_doc set ".$f."='".StripAddsData($value)."' where id='$r[id]'");
  1819. }
  1820. else//主表
  1821. {
  1822. $value=$r[$f];
  1823. $empire->query("update {$dbtbpre}ecms_".$tbname."_doc_data set ".$f."='".StripAddsData($value)."' where id='$r[id]'");
  1824. }
  1825. }
  1826. if(empty($b))
  1827. {
  1828. //删除字段
  1829. if($fr[tbdataf])//转移到主表
  1830. {
  1831. $tbr=$empire->fetch1("select datatbs from {$dbtbpre}enewstable where tid='$tid'");
  1832. if($tbr['datatbs'])
  1833. {
  1834. $dtbr=explode(',',$tbr['datatbs']);
  1835. $count=count($dtbr);
  1836. for($i=1;$i<$count-1;$i++)
  1837. {
  1838. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_data_".$dtbr[$i]." drop COLUMN ".$fr[f]);
  1839. }
  1840. }
  1841. //归档副表
  1842. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc_data drop COLUMN ".$fr[f]);
  1843. //审核副表
  1844. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check_data drop COLUMN ".$fr[f]);
  1845. }
  1846. else//转移到副表
  1847. {
  1848. $empire->query("alter table {$dbtbpre}ecms_".$tbname." drop COLUMN ".$fr[f]);
  1849. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_doc drop COLUMN ".$fr[f]);
  1850. $empire->query("alter table {$dbtbpre}ecms_".$tbname."_check drop COLUMN ".$fr[f]);
  1851. }
  1852. $newtbdataf=$fr[tbdataf]?0:1;
  1853. $empire->query("update {$dbtbpre}enewsf set tbdataf='$newtbdataf' where fid='$fid'");
  1854. //删除模型中字段项
  1855. if(empty($tbr['datatbs']))
  1856. {
  1857. $record="<!--record-->";
  1858. $field="<!--field--->";
  1859. $like=$field.$fr[f].$record;
  1860. $slike=",".$fr[f].",";
  1861. $dsql=$empire->query("select mid,searchvar,listandf,listtempvar,orderf from {$dbtbpre}enewsmod where tid='$tid' and (searchvar like '%".$slike."%' or listtempvar like '%".$like."%' or listandf like '%".$slike."%' or orderf like '%".$slike."%')");
  1862. while($r=$empire->fetch($dsql))
  1863. {
  1864. $listtempvar="";
  1865. $searchvar="";
  1866. $listandf="";
  1867. $orderf="";
  1868. $re="";
  1869. $re1="";
  1870. $and="";
  1871. $dh="";
  1872. //列表模板变量
  1873. if(strstr($r[listtempvar],$like))
  1874. {
  1875. $re1=explode($record,$r[listtempvar]);
  1876. for($i=0;$i<count($re1)-1;$i++)
  1877. {
  1878. if(strstr($re1[$i].$record,$like))
  1879. {continue;}
  1880. $listtempvar.=$re1[$i].$record;
  1881. }
  1882. $and.=$dh."listtempvar='$listtempvar'";
  1883. }
  1884. $dh="";
  1885. //搜索变量
  1886. if(strstr($r[searchvar],$slike))
  1887. {
  1888. if(!empty($and))
  1889. {$dh=",";}
  1890. $searchvar=str_replace($slike,",",$r[searchvar]);
  1891. $and.=$dh."searchvar='$searchvar'";
  1892. }
  1893. //结合项
  1894. $dh="";
  1895. if(strstr($r[listandf],$slike))
  1896. {
  1897. if(!empty($and))
  1898. {$dh=",";}
  1899. $listandf=str_replace($slike,",",$r[listandf]);
  1900. $and.=$dh."listandf='$listandf'";
  1901. }
  1902. //排序项
  1903. $dh="";
  1904. if(strstr($r[orderf],$slike))
  1905. {
  1906. if(!empty($and))
  1907. {$dh=",";}
  1908. $orderf=str_replace($slike,",",$r[orderf]);
  1909. $and.=$dh."orderf='$orderf'";
  1910. }
  1911. if($and)
  1912. {
  1913. $empire->query("update {$dbtbpre}enewsmod set ".$and." where mid='$r[mid]'");
  1914. }
  1915. }
  1916. }
  1917. GetConfig(1);//更新缓存
  1918. insert_dolog("tid=$tid&tbname=$tbname<br>fid=$fid&field=$f&tbdataf=".$newtbdataf);//操作日志
  1919. printerror("ChangeDataTableFSuccess","db/ListF.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  1920. }
  1921. echo"<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"".$public_r['realltime'].";url=ecmsmod.php?enews=ChangeDocDataTableF&tid=$tid&tbname=$tbname&fid=$fid&line=$line&start=$newstart".hReturnEcmsHashStrHref(0)."\">".$fun_r[OneChangeDocDataTableFSuccess]."(ID:<font color=red><b>".$newstart."</b></font>)";
  1922. exit();
  1923. }
  1924. //************************** 模型 **************************
  1925. //更新默认系统模型
  1926. function UpdateTbDefMod($tid,$tbname,$mid){
  1927. global $empire,$dbtbpre;
  1928. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmod where tid='$tid'");
  1929. if($num==1)
  1930. {
  1931. $empire->query("update {$dbtbpre}enewstable set mid='$mid' where tid='$tid'");
  1932. $empire->query("update {$dbtbpre}enewsmod set isdefault=1 where mid='$mid'");
  1933. }
  1934. }
  1935. //更新模型表单
  1936. function ChangeMForm($mid,$tid,$mtemp){
  1937. global $empire,$dbtbpre;
  1938. $file=eReturnTrueEcmsPath()."e/data/html/".$mid.".php";
  1939. $sql=$empire->query("select f,fhtml from {$dbtbpre}enewsf where tid='$tid'");
  1940. while($r=$empire->fetch($sql))
  1941. {
  1942. $mtemp=str_replace("[!--".$r[f]."--]",$r[fhtml],$mtemp);
  1943. }
  1944. $mtemp=AddCheckViewTempCode().$mtemp;
  1945. WriteFiletext($file,$mtemp);
  1946. }
  1947. //更新投稿表单
  1948. function ChangeQmForm($mid,$tid,$mtemp){
  1949. global $empire,$dbtbpre;
  1950. $file=eReturnTrueEcmsPath()."e/data/html/q".$mid.".php";
  1951. $sql=$empire->query("select f,qfhtml from {$dbtbpre}enewsf where tid='$tid'");
  1952. while($r=$empire->fetch($sql))
  1953. {
  1954. $mtemp=str_replace("[!--".$r[f]."--]",$r[qfhtml],$mtemp);
  1955. }
  1956. $mtemp=AddCheckViewTempCode().$mtemp;
  1957. WriteFiletext($file,$mtemp);
  1958. }
  1959. //更新采集
  1960. function ChangeMCj($mid,$tid,$cj){
  1961. global $empire,$dbtbpre;
  1962. $record="<!--record-->";
  1963. $field="<!--field--->";
  1964. //读取修改采集表单
  1965. $data="<tr><td bgcolor=ffffff>[!--enews.name--]</td><td bgcolor=ffffff>[!--enews.var--]</td></tr>";
  1966. $file1=eReturnTrueEcmsPath()."e/data/html/editcj".$mid.".php";
  1967. $file=eReturnTrueEcmsPath()."e/data/html/cj".$mid.".php";
  1968. $r=explode($record,$cj);
  1969. for($i=0;$i<count($r)-1;$i++)
  1970. {
  1971. $r1=explode($field,$r[$i]);
  1972. $fr=$empire->fetch1("select cjhtml,fhtml from {$dbtbpre}enewsf where f='$r1[1]' and tid='$tid' limit 1");
  1973. $cjtemp=str_replace("[!--enews.name--]",$r1[0],$fr[cjhtml]);
  1974. $str.=$cjtemp;
  1975. $editcjtemp=str_replace("[!--enews.name--]",$r1[0],$data);
  1976. $editcjtemp=str_replace("[!--enews.var--]",$fr[fhtml],$editcjtemp);
  1977. $editcj.=$editcjtemp;
  1978. }
  1979. WriteFiletext($file,AddCheckViewTempCode().$str);
  1980. WriteFiletext($file1,AddCheckViewTempCode().$editcj);
  1981. }
  1982. //组合采集项
  1983. function TogMCj($cname,$cchange){
  1984. $record="<!--record-->";
  1985. $field="<!--field--->";
  1986. $c="";
  1987. for($i=0;$i<count($cchange);$i++)
  1988. {
  1989. $v=$cchange[$i];
  1990. $name=str_replace($field,"",$cname[$v]);
  1991. $name=str_replace($record,"",$name);
  1992. $c.=$name.$field.$v.$record;
  1993. }
  1994. return $c;
  1995. }
  1996. //组合投稿项
  1997. function TogMqenter($cname,$cqenter){
  1998. $record="<!--record-->";
  1999. $field="<!--field--->";
  2000. $c="";
  2001. for($i=0;$i<count($cqenter);$i++)
  2002. {
  2003. $v=$cqenter[$i];
  2004. $name=str_replace($field,"",$cname[$v]);
  2005. $name=str_replace($record,"",$name);
  2006. $c.=$name.$field.$v.$record;
  2007. }
  2008. return $c;
  2009. }
  2010. //组合搜索项
  2011. function TogMSearch($cname,$schange){
  2012. $c="";
  2013. for($i=0;$i<count($schange);$i++)
  2014. {
  2015. $v=$schange[$i];
  2016. $c.=$v.",";
  2017. }
  2018. if($c)
  2019. {
  2020. $c=",".$c;
  2021. }
  2022. return $c;
  2023. }
  2024. //组合必填项
  2025. function TogMustf($cname,$menter){
  2026. $c="";
  2027. for($i=0;$i<count($menter);$i++)
  2028. {
  2029. $v=$menter[$i];
  2030. $c.=$v.",";
  2031. }
  2032. if($c)
  2033. {
  2034. $c=",".$c;
  2035. }
  2036. return $c;
  2037. }
  2038. //组合录入项
  2039. function TogMEnter($cname,$center,$ltempf,$ptempf,$tid){
  2040. global $empire;
  2041. $f=1;
  2042. $record="<!--record-->";
  2043. $field="<!--field--->";
  2044. $c="";
  2045. $lt="";
  2046. $pt="";
  2047. for($i=0;$i<count($center);$i++)
  2048. {
  2049. $v=$center[$i];
  2050. $name=str_replace($field,"",$cname[$v]);
  2051. $name=str_replace($record,"",$name);
  2052. $c.=$name.$field.$v.$record;
  2053. }
  2054. for($i=0;$i<count($ltempf);$i++)
  2055. {
  2056. $v=$ltempf[$i];
  2057. $name=str_replace($field,"",$cname[$v]);
  2058. $name=str_replace($record,"",$name);
  2059. $lt.=$name.$field.$v.$record;
  2060. }
  2061. for($i=0;$i<count($ptempf);$i++)
  2062. {
  2063. $v=$ptempf[$i];
  2064. $name=str_replace($field,"",$cname[$v]);
  2065. $name=str_replace($record,"",$name);
  2066. $pt.=$name.$field.$v.$record;
  2067. }
  2068. $r[0]=$c;
  2069. $r[1]=$lt;
  2070. $r[2]=$pt;
  2071. return $r;
  2072. }
  2073. //返回自动生成录入表单模板
  2074. function ReturnMtemp($cname,$center){
  2075. $temp="<tr><td width='16%' height=25 bgcolor='ffffff'>enews.name</td><td bgcolor='ffffff'>[!--enews.var--]</td></tr>";
  2076. $ntemp="<tr><td height=25 colspan=2 bgcolor='ffffff'><div align=left>enews.name</div></td></tr></table><div style='background-color:#D0D0D0'>[!--enews.var--]</div><table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>";
  2077. for($i=0;$i<count($center);$i++)
  2078. {
  2079. $v=$center[$i];
  2080. if($v=="newstext")
  2081. {
  2082. $data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$ntemp));
  2083. continue;
  2084. }
  2085. $data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$temp));
  2086. }
  2087. return "<table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>".$data."</table>";
  2088. }
  2089. //返回自动生成投稿表单模板
  2090. function ReturnQmtemp($cname,$cqenter){
  2091. $temp="<tr><td width='16%' height=25 bgcolor='ffffff'>enews.name</td><td bgcolor='ffffff'>[!--enews.var--]</td></tr>";
  2092. $ntemp="<tr><td height=25 colspan=2 bgcolor='ffffff'><div align=left>enews.name</div></td></tr></table><div style='background-color:#D0D0D0'>[!--enews.var--]</div><table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>";
  2093. for($i=0;$i<count($cqenter);$i++)
  2094. {
  2095. $v=$cqenter[$i];
  2096. if($v=="newstext")
  2097. {
  2098. $data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$ntemp));
  2099. continue;
  2100. }
  2101. $data.=str_replace("enews.var",$v,str_replace("enews.name",$cname[$v],$temp));
  2102. }
  2103. return "<table width=100% align=center cellpadding=3 cellspacing=1 bgcolor=#DBEAF5>".$data."</table>";
  2104. }
  2105. //返回br项
  2106. function ReturnMTobrF($enter,$tid,$dof="tobr"){
  2107. global $empire,$dbtbpre;
  2108. $record="<!--record-->";
  2109. $field="<!--field--->";
  2110. $f=",";
  2111. $sql=$empire->query("select f from {$dbtbpre}enewsf where ".$dof."=0 and tid='$tid'");
  2112. while($r=$empire->fetch($sql))
  2113. {
  2114. if(strstr($enter,$field.$r[f].$record))
  2115. {
  2116. $f.=$r[f].",";
  2117. }
  2118. }
  2119. return $f;
  2120. }
  2121. //增加模型
  2122. function AddM($add,$cname,$cchange,$schange,$center,$cqenter,$menter,$listand,$ltempf,$ptempf,$canadd,$canedit,$listorder,$userid,$username){
  2123. global $empire,$dbtbpre;
  2124. $tid=(int)$add['tid'];
  2125. $tbname=RepPostVar($add['tbname']);
  2126. if(empty($add[mname])||!$tid||!$tbname)
  2127. {
  2128. printerror("EmptyM","history.go(-1)");
  2129. }
  2130. $listfile=eReturnCPath(str_replace('.','',$add[listfile]),'');
  2131. CheckLevel($userid,$username,$classid,"m");//验证权限
  2132. //组合采集项
  2133. $cj=TogMCj($cname,$cchange);
  2134. //组合搜索项
  2135. $searchvar=TogMSearch($cname,$schange);
  2136. //组合必填项
  2137. $mustqenterf=TogMustf($cname,$menter);
  2138. //组合结合项
  2139. $listandf=TogMustf($cname,$listand);
  2140. //组合排序项
  2141. $orderf=TogMustf($cname,$listorder);
  2142. //组合投稿项
  2143. $qenter=TogMqenter($cname,$cqenter);
  2144. //组合可增加项
  2145. $canaddf=TogMustf($cname,$canadd);
  2146. //组合可修改项
  2147. $caneditf=TogMustf($cname,$canedit);
  2148. //组合录入项
  2149. $er=TogMEnter($cname,$center,$ltempf,$ptempf,$tid);
  2150. $enter=$er[0]; //录入项
  2151. $listtempvar=$er[1]; //列表模板项
  2152. $tempvar=$er[2]; //内容模板项
  2153. //自动生成表单
  2154. if($add[mtype])
  2155. {
  2156. $add[mtemp]=ReturnMtemp($cname,$center);
  2157. }
  2158. if($add[qmtype])
  2159. {
  2160. $add[qmtemp]=ReturnQmtemp($cname,$cqenter);
  2161. }
  2162. $setandf=(int)$add['setandf'];
  2163. $add[definfovoteid]=(int)$add[definfovoteid];
  2164. $showmod=(int)$add['showmod'];
  2165. $usemod=(int)$add['usemod'];
  2166. $myorder=(int)$add['myorder'];
  2167. $add[printtempid]=(int)$add[printtempid];
  2168. $add['mname']=hRepPostStr($add['mname'],1);
  2169. $add['mzs']=hRepPostStr($add['mzs'],1);
  2170. $cj=AddAddsData($cj);
  2171. $enter=AddAddsData($enter);
  2172. $tempvar=AddAddsData($tempvar);
  2173. $searchvar=AddAddsData($searchvar);
  2174. $qenter=AddAddsData($qenter);
  2175. $mustqenterf=AddAddsData($mustqenterf);
  2176. $listtempvar=AddAddsData($listtempvar);
  2177. $add['qmname']=hRepPostStr($add['qmname'],0);
  2178. $canaddf=AddAddsData($canaddf);
  2179. $caneditf=AddAddsData($caneditf);
  2180. $orderf=AddAddsData($orderf);
  2181. $listfile=AddAddsData($listfile);
  2182. $add['maddfun']=hRepPostStr($add['maddfun'],0);
  2183. $add['meditfun']=hRepPostStr($add['meditfun'],0);
  2184. $add['qmaddfun']=hRepPostStr($add['qmaddfun'],0);
  2185. $add['qmeditfun']=hRepPostStr($add['qmeditfun'],0);
  2186. $sql=$empire->query("insert into {$dbtbpre}enewsmod(mname,mtemp,mzs,cj,enter,tempvar,sonclass,searchvar,tid,tbname,qenter,mustqenterf,qmtemp,listandf,setandf,listtempvar,qmname,canaddf,caneditf,definfovoteid,showmod,usemod,myorder,orderf,isdefault,listfile,printtempid,maddfun,meditfun,qmaddfun,qmeditfun) values('$add[mname]','".eaddslashes2($add[mtemp])."','$add[mzs]','$cj','$enter','$tempvar','','$searchvar',$tid,'$tbname','$qenter','$mustqenterf','".eaddslashes2($add[qmtemp])."','".addslashes($listandf)."','$setandf','$listtempvar','$add[qmname]','$canaddf','$caneditf',$add[definfovoteid],'$showmod','$usemod','$myorder','$orderf',0,'$listfile','$add[printtempid]','$add[maddfun]','$add[meditfun]','$add[qmaddfun]','$add[qmeditfun]');");
  2187. $mid=$empire->lastid();
  2188. UpdateTbDefMod($tid,$tbname,$mid);
  2189. //更新表单
  2190. ChangeMForm($mid,$tid,$add[mtemp]);
  2191. ChangeQmForm($mid,$tid,$add[qmtemp]);
  2192. //采集文件
  2193. ChangeMCj($mid,$tid,$cj);
  2194. GetConfig(1);//更新缓存
  2195. if($sql)
  2196. {
  2197. insert_dolog("mid=".$mid."<br>m=".$add[mname]);//操作日志
  2198. printerror("AddMSuccess","db/ListM.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  2199. }
  2200. else
  2201. {
  2202. printerror("DbError","history.go(-1)");
  2203. }
  2204. }
  2205. //修改模型
  2206. function EditM($add,$cname,$cchange,$schange,$center,$cqenter,$menter,$listand,$ltempf,$ptempf,$canadd,$canedit,$listorder,$userid,$username){
  2207. global $empire,$dbtbpre;
  2208. $tid=(int)$add['tid'];
  2209. $tbname=RepPostVar($add['tbname']);
  2210. $add[mid]=(int)$add[mid];
  2211. if(empty($add[mname])||empty($add[mid])||!$tid||!$tbname)
  2212. {
  2213. printerror("EmptyM","history.go(-1)");
  2214. }
  2215. $listfile=eReturnCPath(str_replace('.','',$add[listfile]),'');
  2216. //验证权限
  2217. CheckLevel($userid,$username,$classid,"m");
  2218. //组合采集项
  2219. $cj=TogMCj($cname,$cchange);
  2220. //组合搜索项
  2221. $searchvar=TogMSearch($cname,$schange);
  2222. //组合必填项
  2223. $mustqenterf=TogMustf($cname,$menter);
  2224. //组合结合项
  2225. $listandf=TogMustf($cname,$listand);
  2226. //组合排序项
  2227. $orderf=TogMustf($cname,$listorder);
  2228. //组合投稿项
  2229. $qenter=TogMqenter($cname,$cqenter);
  2230. //组合可增加项
  2231. $canaddf=TogMustf($cname,$canadd);
  2232. //组合可修改项
  2233. $caneditf=TogMustf($cname,$canedit);
  2234. //组合录入项
  2235. $er=TogMEnter($cname,$center,$ltempf,$ptempf,$tid);
  2236. $enter=$er[0]; //录入项
  2237. $listtempvar=$er[1]; //列表模板项
  2238. $tempvar=$er[2]; //内容模板项
  2239. //自动生成表单
  2240. if($add[mtype])
  2241. {
  2242. $add[mtemp]=ReturnMtemp($cname,$center);
  2243. }
  2244. if($add[qmtype])
  2245. {
  2246. $add[qmtemp]=ReturnQmtemp($cname,$cqenter);
  2247. }
  2248. $setandf=(int)$add['setandf'];
  2249. $add[definfovoteid]=(int)$add[definfovoteid];
  2250. $showmod=(int)$add['showmod'];
  2251. $usemod=(int)$add['usemod'];
  2252. $myorder=(int)$add['myorder'];
  2253. $add[printtempid]=(int)$add[printtempid];
  2254. $add['mname']=hRepPostStr($add['mname'],1);
  2255. $add['mzs']=hRepPostStr($add['mzs'],1);
  2256. $cj=AddAddsData($cj);
  2257. $enter=AddAddsData($enter);
  2258. $tempvar=AddAddsData($tempvar);
  2259. $searchvar=AddAddsData($searchvar);
  2260. $qenter=AddAddsData($qenter);
  2261. $mustqenterf=AddAddsData($mustqenterf);
  2262. $listtempvar=AddAddsData($listtempvar);
  2263. $add['qmname']=hRepPostStr($add['qmname'],0);
  2264. $canaddf=AddAddsData($canaddf);
  2265. $caneditf=AddAddsData($caneditf);
  2266. $orderf=AddAddsData($orderf);
  2267. $listfile=AddAddsData($listfile);
  2268. $add['maddfun']=hRepPostStr($add['maddfun'],0);
  2269. $add['meditfun']=hRepPostStr($add['meditfun'],0);
  2270. $add['qmaddfun']=hRepPostStr($add['qmaddfun'],0);
  2271. $add['qmeditfun']=hRepPostStr($add['qmeditfun'],0);
  2272. $sql=$empire->query("update {$dbtbpre}enewsmod set mname='$add[mname]',mtemp='".eaddslashes2($add[mtemp])."',mzs='$add[mzs]',cj='$cj',enter='$enter',tempvar='$tempvar',searchvar='$searchvar',qenter='$qenter',mustqenterf='$mustqenterf',qmtemp='".eaddslashes2($add[qmtemp])."',listandf='".addslashes($listandf)."',setandf=$setandf,listtempvar='$listtempvar',qmname='$add[qmname]',canaddf='$canaddf',caneditf='$caneditf',definfovoteid=$add[definfovoteid],showmod='$showmod',usemod='$usemod',myorder='$myorder',orderf='$orderf',listfile='$listfile',printtempid='$add[printtempid]',maddfun='$add[maddfun]',meditfun='$add[meditfun]',qmaddfun='$add[qmaddfun]',qmeditfun='$add[qmeditfun]' where mid='$add[mid]'");
  2273. //更新表单
  2274. ChangeMForm($add[mid],$tid,$add[mtemp]);
  2275. ChangeQmForm($add[mid],$tid,$add[qmtemp]);
  2276. //采集文件
  2277. ChangeMCj($add[mid],$tid,$cj);
  2278. GetConfig(1);//更新缓存
  2279. if($sql)
  2280. {
  2281. //操作日志
  2282. insert_dolog("mid=".$add[mid]."<br>m=".$add[mname]);
  2283. printerror("EditMSuccess","db/ListM.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  2284. }
  2285. else
  2286. {
  2287. printerror("DbError","history.go(-1)");
  2288. }
  2289. }
  2290. //删除模型
  2291. function DelM($mid,$tid,$tbname,$userid,$username){
  2292. global $empire,$dbtbpre;
  2293. $tid=(int)$tid;
  2294. $tbname=RepPostVar($tbname);
  2295. $mid=(int)$mid;
  2296. if(empty($mid)||!$tid||!$tbname)
  2297. {
  2298. printerror("EmptyMid","history.go(-1)");
  2299. }
  2300. //验证权限
  2301. CheckLevel($userid,$username,$classid,"m");
  2302. $r=$empire->fetch1("select mname,isdefault from {$dbtbpre}enewsmod where mid='$mid'");
  2303. $sql=$empire->query("delete from {$dbtbpre}enewsmod where mid='$mid'");
  2304. $empire->query("delete from {$dbtbpre}enewsinfotype where mid='$mid'");//删除主题分类
  2305. DelFiletext("../data/html/".$mid.".php");
  2306. DelFiletext("../data/html/q".$mid.".php");
  2307. DelFiletext("../data/html/cj".$mid.".php");
  2308. DelFiletext("../data/html/editcj".$mid.".php");
  2309. //表默认模型
  2310. if($r[isdefault])
  2311. {
  2312. $modr=$empire->fetch1("select mid from {$dbtbpre}enewsmod where tid='$tid' order by mid");
  2313. if($modr[mid])
  2314. {
  2315. $empire->query("update {$dbtbpre}enewstable set mid='$modr[mid]' where tid='$tid'");
  2316. $empire->query("update {$dbtbpre}enewsmod set isdefault=1 where mid='$modr[mid]'");
  2317. }
  2318. }
  2319. GetConfig(1);//更新缓存
  2320. if($sql)
  2321. {
  2322. insert_dolog("mid=".$mid."<br>m=".$r[mname]);//操作日志
  2323. printerror("DelMSuccess","db/ListM.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  2324. }
  2325. else
  2326. {
  2327. printerror("DbError","history.go(-1)");
  2328. }
  2329. }
  2330. //默认模型
  2331. function DefM($mid,$tid,$tbname,$userid,$username){
  2332. global $empire,$dbtbpre;
  2333. $tid=(int)$tid;
  2334. $tbname=RepPostVar($tbname);
  2335. $mid=(int)$mid;
  2336. if(empty($mid)||!$tid||!$tbname)
  2337. {
  2338. printerror("EmptyDefMid","history.go(-1)");
  2339. }
  2340. //验证权限
  2341. CheckLevel($userid,$username,$classid,"m");
  2342. $r=$empire->fetch1("select mname from {$dbtbpre}enewsmod where mid='$mid'");
  2343. $empire->query("update {$dbtbpre}enewsmod set isdefault=0 where tid='$tid'");
  2344. $sql=$empire->query("update {$dbtbpre}enewsmod set isdefault=1 where mid='$mid'");
  2345. $empire->query("update {$dbtbpre}enewstable set mid='$mid' where tid='$tid'");
  2346. GetConfig(1);//更新缓存
  2347. if($sql)
  2348. {
  2349. insert_dolog("mid=".$mid."<br>m=".$r[mname]);//操作日志
  2350. printerror("DefMSuccess","db/ListM.php?tid=$tid&tbname=$tbname".hReturnEcmsHashStrHref2(0));
  2351. }
  2352. else
  2353. {
  2354. printerror("DbError","history.go(-1)");
  2355. }
  2356. }
  2357. //更新模型表单文件
  2358. function ChangeAllModForm($add,$userid,$username){
  2359. global $empire,$dbtbpre;
  2360. //验证权限
  2361. CheckLevel($userid,$username,$classid,"changedata");
  2362. $sql=$empire->query("select mid,tid,mtemp,qmtemp,cj from {$dbtbpre}enewsmod");
  2363. while($r=$empire->fetch($sql))
  2364. {
  2365. ChangeMForm($r[mid],$r[tid],$r[mtemp]);//更新表单
  2366. ChangeQmForm($r[mid],$r[tid],$r[qmtemp]);//更新前台表单
  2367. ChangeMCj($r[mid],$r[tid],$r[cj]);//采集表单
  2368. //更新栏目导航
  2369. if($add['ChangeClass']==1)
  2370. {
  2371. GetSearch($r[mid]);
  2372. }
  2373. }
  2374. //操作日志
  2375. insert_dolog("ChangeClass=$add[ChangeClass]");
  2376. printerror("ChangeAllModFormSuccess","history.go(-1)");
  2377. }
  2378. //导入系统模型
  2379. function LoadInMod($add,$file,$file_name,$file_type,$file_size,$userid,$username){
  2380. global $empire,$dbtbpre,$ecms_config;
  2381. //验证权限
  2382. CheckLevel($userid,$username,$classid,"table");
  2383. $tbname=RepPostVar(trim($add['tbname']));
  2384. if(!$file_name||!$file_size||!$tbname)
  2385. {
  2386. printerror("EmptyLoadInMod","");
  2387. }
  2388. //扩展名
  2389. $filetype=GetFiletype($file_name);
  2390. if($filetype!=".mod")
  2391. {
  2392. printerror("LoadInModMustmod","");
  2393. }
  2394. //表名是否已存在
  2395. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
  2396. if($num)
  2397. {
  2398. printerror("HaveLoadInTb","");
  2399. }
  2400. //上传文件
  2401. $path=ECMS_PATH."e/data/tmp/mod/uploadm".time().make_password(10).".php";
  2402. $cp=@move_uploaded_file($file,$path);
  2403. if(!$cp)
  2404. {
  2405. printerror("EmptyLoadInMod","");
  2406. }
  2407. DoChmodFile($path);
  2408. @include($path);
  2409. UpdateTbDefMod($tid,$tbname,$mid);
  2410. //公共变量
  2411. TogSaveTxtF(1);
  2412. GetConfig(1);//更新缓存
  2413. //生成模型表单文件
  2414. $modr=$empire->fetch1("select mtemp,qmtemp,cj from {$dbtbpre}enewsmod where mid='$mid'");
  2415. ChangeMForm($mid,$tid,$modr[mtemp]);//更新表单
  2416. ChangeQmForm($mid,$tid,$modr[qmtemp]);//更新前台表单
  2417. ChangeMCj($mid,$tid,$modr[cj]);//采集表单
  2418. //删除文件
  2419. DelFiletext($path);
  2420. //操作日志
  2421. insert_dolog("tid=$tid&tb=$tbname<br>mid=$mid");
  2422. printerror("LoadInModSuccess","db/ListTable.php".hReturnEcmsHashStrHref2(1));
  2423. }
  2424. //导出系统模型
  2425. function LoadOutMod($add,$userid,$username){
  2426. global $empire,$dbtbpre;
  2427. $tid=(int)$add['tid'];
  2428. $tbname=RepPostVar($add['tbname']);
  2429. $mid=(int)$add['mid'];
  2430. if(!$tid||!$tbname||!$mid)
  2431. {
  2432. printerror("EmptyLoadMod","");
  2433. }
  2434. $mr=$empire->fetch1("select * from {$dbtbpre}enewsmod where mid=$mid and tid=$tid");
  2435. if(!$mr['mid'])
  2436. {
  2437. printerror("EmptyLoadMod","");
  2438. }
  2439. $tr=$empire->fetch1("select tbname,tname,tsay,intb from {$dbtbpre}enewstable where tid=$tid");
  2440. if(!$tr['tbname'])
  2441. {
  2442. printerror("EmptyLoadMod","");
  2443. }
  2444. //数据表结构
  2445. $loadmod="<?php
  2446. ".LoadModReturnstru($dbtbpre."ecms_".$mr['tbname'],$mr['tbname'],0)."\r\n";
  2447. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_data_1",$mr['tbname'],5)."\r\n";
  2448. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_index",$mr['tbname'],6)."\r\n";
  2449. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_doc",$mr['tbname'],1)."\r\n";
  2450. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_doc_data",$mr['tbname'],4)."\r\n";
  2451. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_doc_index",$mr['tbname'],7)."\r\n";
  2452. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_check",$mr['tbname'],8)."\r\n";
  2453. $loadmod.=LoadModReturnstru($dbtbpre."ecms_".$mr['tbname']."_check_data",$mr['tbname'],9)."\r\n";
  2454. $loadmod.=LoadModReturnstru($dbtbpre."ecms_infoclass_".$mr['tbname'],$mr['tbname'],2)."\r\n";
  2455. $loadmod.=LoadModReturnstru($dbtbpre."ecms_infotmp_".$mr['tbname'],$mr['tbname'],3)."\r\n";
  2456. //数据表
  2457. $loadmod.="\$empire->query(\"insert into \".\$dbtbpre.\"enewstable(tbname,tname,tsay,isdefault,datatbs,deftb,yhid,mid,intb) values('\$tbname','".$tr[tname]."','".LMEscape_str($tr[tsay])."',0,',1,','1',0,0,'".$tr[intb]."');\");
  2458. \$tid=\$empire->lastid();
  2459. ";
  2460. //字段
  2461. $fsql=$empire->query("select * from {$dbtbpre}enewsf where tid=$tid order by fid");
  2462. while($fr=$empire->fetch($fsql))
  2463. {
  2464. $loadmod.="\$empire->query(\"insert into \".\$dbtbpre.\"enewsf(f,fname,fform,fhtml,fzs,isadd,isshow,iscj,cjhtml,myorder,ftype,flen,dotemp,tid,tbname,savetxt,fvalue,iskey,tobr,dohtml,qfhtml,isonly,linkfieldval,samedata,fformsize,tbdataf,ispage,adddofun,editdofun,qadddofun,qeditdofun,linkfieldtb,linkfieldshow,editorys,issmalltext,fmvnum) values('$fr[f]','$fr[fname]','$fr[fform]','".LMEscape_str($fr['fhtml'])."','".LMEscape_str($fr[fzs])."',$fr[isadd],$fr[isshow],$fr[iscj],'".LMEscape_str($fr[cjhtml])."',$fr[myorder],'$fr[ftype]','$fr[flen]',$fr[dotemp],\$tid,'\$tbname',$fr[savetxt],'".LMEscape_str($fr[fvalue])."',$fr[iskey],$fr[tobr],$fr[dohtml],'".LMEscape_str($fr[qfhtml])."',$fr[isonly],'".LMEscape_str($fr[linkfieldval])."',$fr[samedata],'$fr[fformsize]','$fr[tbdataf]','$fr[ispage]','".LMEscape_str($fr[adddofun])."','".LMEscape_str($fr[editdofun])."','".LMEscape_str($fr[qadddofun])."','".LMEscape_str($fr[qeditdofun])."','".LMEscape_str($fr[linkfieldtb])."','".LMEscape_str($fr[linkfieldshow])."','$fr[editorys]','$fr[issmalltext]','".LMEscape_str($fr[fmvnum])."');\");
  2465. ";
  2466. }
  2467. //模型
  2468. $loadmod.="\$empire->query(\"insert into \".\$dbtbpre.\"enewsmod(mname,mtemp,mzs,cj,enter,tempvar,sonclass,searchvar,tid,tbname,qenter,mustqenterf,qmtemp,listandf,setandf,listtempvar,qmname,canaddf,caneditf,definfovoteid,showmod,usemod,myorder,orderf,isdefault,listfile,printtempid,maddfun,meditfun,qmaddfun,qmeditfun) values('$mr[mname]','".LMEscape_str($mr[mtemp])."','".LMEscape_str($mr[mzs])."','".LMEscape_str($mr[cj])."','".LMEscape_str($mr[enter])."','".LMEscape_str($mr[tempvar])."','','".LMEscape_str($mr[searchvar])."',\$tid,'\$tbname','".LMEscape_str($mr[qenter])."','".LMEscape_str($mr[mustqenterf])."','".LMEscape_str($mr[qmtemp])."','".LMEscape_str($mr[listandf])."',$mr[setandf],'".LMEscape_str($mr[listtempvar])."','".LMEscape_str($mr[qmname])."','".LMEscape_str($mr[canaddf])."','".LMEscape_str($mr[caneditf])."',0,0,0,0,'".LMEscape_str($mr[orderf])."',0,'',0,'".LMEscape_str($mr[maddfun])."','".LMEscape_str($mr[meditfun])."','".LMEscape_str($mr[qmaddfun])."','".LMEscape_str($mr[qmeditfun])."');\");
  2469. \$mid=\$empire->lastid();
  2470. ?>";
  2471. $file=$tr['tbname'].time().".mod";
  2472. $filepath=ECMS_PATH."e/data/tmp/mod/".$file;
  2473. WriteFiletext_n($filepath,AddCheckViewTempCode().$loadmod);
  2474. DownLoadFile($file,$filepath,1);
  2475. //操作日志
  2476. insert_dolog("tid=$tid&tb=$tr[tbname]<br>mid=$mid&m=$mr[mname]");
  2477. exit();
  2478. }
  2479. //返回数据表结构
  2480. function LoadModReturnstru($table,$tb,$ecms=0){
  2481. global $empire;
  2482. $usql=$empire->query("SET SQL_QUOTE_SHOW_CREATE=1;");//设置引号
  2483. $r=$empire->fetch1("SHOW CREATE TABLE `$table`;");//数据表结构
  2484. $create=str_replace("\"","\\\"",$r[1]);
  2485. $create=LoadModToMysqlFour($create);
  2486. //替换表
  2487. if($ecms==1)
  2488. {
  2489. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_doc\"";
  2490. }
  2491. elseif($ecms==2)
  2492. {
  2493. $reptb="\$dbtbpre.\"ecms_infoclass_\".\$tbname";
  2494. }
  2495. elseif($ecms==3)
  2496. {
  2497. $reptb="\$dbtbpre.\"ecms_infotmp_\".\$tbname";
  2498. }
  2499. elseif($ecms==4)
  2500. {
  2501. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_doc_data\"";
  2502. }
  2503. elseif($ecms==5)
  2504. {
  2505. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_data_1\"";
  2506. }
  2507. elseif($ecms==6)
  2508. {
  2509. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_index\"";
  2510. }
  2511. elseif($ecms==7)
  2512. {
  2513. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_doc_index\"";
  2514. }
  2515. elseif($ecms==8)
  2516. {
  2517. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_check\"";
  2518. }
  2519. elseif($ecms==9)
  2520. {
  2521. $reptb="\$dbtbpre.\"ecms_\".\$tbname.\"_check_data\"";
  2522. }
  2523. else
  2524. {
  2525. $reptb="\$dbtbpre.\"ecms_\".\$tbname";
  2526. }
  2527. $dumpsql.="\$empire->query(str_replace(\"".$table."\",$reptb,SetCreateTable(\"".$create."\",\$ecms_config['db']['dbchar'])));\r\n";
  2528. return $dumpsql;
  2529. }
  2530. //转为Mysql4.0格式
  2531. function LoadModToMysqlFour($query){
  2532. $exp="ENGINE=";
  2533. if(!strstr($query,$exp))
  2534. {
  2535. return $query;
  2536. }
  2537. $exp1=" ";
  2538. $r=explode($exp,$query);
  2539. //取得表类型
  2540. $r1=explode($exp1,$r[1]);
  2541. $returnquery=$r[0]."TYPE=".$r1[0];
  2542. return $returnquery;
  2543. }
  2544. //字符过虑
  2545. function LMEscape_str($str){
  2546. global $empire,$dbtbpre,$public_r;
  2547. if($public_r['bakescapetype']==2)//real_escape_string
  2548. {
  2549. $str=$empire->EDbEscapeStr($str);
  2550. }
  2551. else//addslashes
  2552. {
  2553. $str=addslashes($str);
  2554. }
  2555. $str=str_replace('\\\'','\'\'',$str);
  2556. $str=str_replace("\\\\","\\\\\\\\",$str);
  2557. $str=str_replace('$','\$',$str);
  2558. return $str;
  2559. }
  2560. ?>