ChangeTable.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. define('EmpireCMSAdmin','1');
  3. require("../../class/connect.php");
  4. require("../../class/db_sql.php");
  5. require("../../class/functions.php");
  6. require("class/functions.php");
  7. $link=db_connect();
  8. $empire=new mysqlquery();
  9. //验证用户
  10. $lur=is_login();
  11. $logininid=$lur['userid'];
  12. $loginin=$lur['username'];
  13. $loginrnd=$lur['rnd'];
  14. $loginlevel=$lur['groupid'];
  15. $loginadminstyleid=$lur['adminstyleid'];
  16. //ehash
  17. $ecms_hashur=hReturnEcmsHashStrAll();
  18. //验证权限
  19. CheckLevel($logininid,$loginin,$classid,"dbdata");
  20. $bakpath=$public_r['bakdbpath'];
  21. $mydbname=RepPostVar($_GET['mydbname']);
  22. if(empty($mydbname))
  23. {
  24. printerror("NotChangeBakTable","history.go(-1)");
  25. }
  26. //选择数据库
  27. $udb=$empire->usequery("use `".$mydbname."`");
  28. //查询
  29. $and="";
  30. $keyboard=RepPostVar($_GET['keyboard']);
  31. $sear=RepPostStr($_GET['sear'],1);
  32. if(empty($sear))
  33. {
  34. $keyboard=$dbtbpre;
  35. }
  36. if($keyboard)
  37. {
  38. $and=" LIKE '%$keyboard%'";
  39. }
  40. $sql=$empire->query("SHOW TABLE STATUS".$and);
  41. //存放目录
  42. $mypath=$mydbname."_".date("YmdHis").make_password(6);
  43. ?>
  44. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  45. <html>
  46. <head>
  47. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  48. <title>选择数据表</title>
  49. <link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
  50. <script language="JavaScript">
  51. function CheckAll(form)
  52. {
  53. for (var i=0;i<form.elements.length;i++)
  54. {
  55. var e = form.elements[i];
  56. if(e.name=='bakstru'||e.name=='bakstrufour'||e.name=='beover'||e.name=='autoauf'||e.name=='baktype'||e.name=='bakdatatype')
  57. {
  58. continue;
  59. }
  60. if (e.name != 'chkall')
  61. e.checked = form.chkall.checked;
  62. }
  63. }
  64. function reverseCheckAll(form)
  65. {
  66. for (var i=0;i<form.elements.length;i++)
  67. {
  68. var e = form.elements[i];
  69. if(e.name=='bakstru'||e.name=='bakstrufour'||e.name=='beover'||e.name=='autoauf'||e.name=='baktype'||e.name=='bakdatatype')
  70. {
  71. continue;
  72. }
  73. if (e.name != 'chkall')
  74. {
  75. if(e.checked==true)
  76. {
  77. e.checked = false;
  78. }
  79. else
  80. {
  81. e.checked = true;
  82. }
  83. }
  84. }
  85. }
  86. function SelectCheckAll(form)
  87. {
  88. for (var i=0;i<form.elements.length;i++)
  89. {
  90. var e = form.elements[i];
  91. if(e.name=='bakstru'||e.name=='bakstrufour'||e.name=='beover'||e.name=='autoauf'||e.name=='baktype'||e.name=='bakdatatype')
  92. {
  93. continue;
  94. }
  95. if (e.name != 'chkall')
  96. e.checked = true;
  97. }
  98. }
  99. function check()
  100. {
  101. var ok;
  102. ok=confirm("确认要执行此操作?");
  103. return ok;
  104. }
  105. </script>
  106. </head>
  107. <body>
  108. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  109. <form name="searchtb" method="GET" action="ChangeTable.php">
  110. <?=$ecms_hashur['eform']?>
  111. <input name="sear" type="hidden" id="sear" value="1">
  112. <input name="mydbname" type="hidden" value="<?=$mydbname?>">
  113. <tr>
  114. <td width="58%">位置:备份数据 -&gt; <a href="ChangeDb.php<?=$ecms_hashur['whehref']?>">选择数据库</a> -&gt; <a href="ChangeTable.php?mydbname=<?=$mydbname?><?=$ecms_hashur['ehref']?>">选择备份表</a>&nbsp;(<?=$mydbname?>)</td>
  115. <td width="42%"><div align="center">查询:
  116. <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>">
  117. <input type="submit" name="Submit3" value="显示数据表">
  118. </div></td>
  119. </tr>
  120. <tr>
  121. <td height="25" colspan="2"><div align="center">
  122. 备份步骤:选择数据库 -&gt; <font color="#FF0000">选择要备份的表</font> -&gt; 开始备份 -&gt;
  123. 完成</div></td>
  124. </tr>
  125. </form>
  126. </table>
  127. <form action="phome.php" method="post" name="ebakchangetb" target="_blank" onsubmit="return check();" autocomplete="off">
  128. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  129. <?=$ecms_hashur['form']?>
  130. <tr class="header">
  131. <td height="25">备份参数设置:
  132. <input name="phome" type="hidden" id="phome2" value="DoEbak">
  133. <input name="mydbname" type="hidden" id="mydbname" value="<?=$mydbname?>">
  134. </td>
  135. </tr>
  136. <tr>
  137. <td height="25" bgcolor="#FFFFFF">
  138. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  139. <tr>
  140. <td width="23%"><input type="radio" name="baktype" value="0"<?=$dbaktype==0?' checked':''?>>
  141. <strong>按文件大小备份</strong> </td>
  142. <td width="77%" height="23"> 每组备份大小:
  143. <input name="filesize" type="text" id="filesize" value="300" size="6">
  144. KB <font color="#666666">(1 MB = 1024 KB)</font></td>
  145. </tr>
  146. <tr>
  147. <td><input type="radio" name="baktype" value="1"<?=$dbaktype==1?' checked':''?>>
  148. <strong>按记录数备份</strong></td>
  149. <td height="23">每组备份
  150. <input name="bakline" type="text" id="bakline" value="500" size="6">
  151. 条记录,
  152. <input name="autoauf" type="checkbox" id="autoauf" value="1" checked>
  153. 自动识别自增字段<font color="#666666">(此方式效率更高)</font></td>
  154. </tr>
  155. <tr>
  156. <td>备份数据库结构</td>
  157. <td height="23"><input name="bakstru" type="checkbox" id="bakstru" value="1" checked>
  158. <font color="#666666">(没特殊情况,请选择)</font></td>
  159. </tr>
  160. <tr>
  161. <td valign="top">数据编码</td>
  162. <td height="23"> <select name="dbchar" id="dbchar">
  163. <option value="auto"<?=$ddbchar=='auto'?' selected':''?>>自动识别编码</option>
  164. <option value=""<?=$ecms_config['db']['setchar']==''?' selected':''?>>不设置</option>
  165. <option value="gbk"<?=$ecms_config['db']['setchar']=='gbk'?' selected':''?>>gbk</option>
  166. <option value="utf8"<?=$ecms_config['db']['setchar']=='utf8'?' selected':''?>>utf8</option>
  167. <option value="gb2312"<?=$ecms_config['db']['setchar']=='gb2312'?' selected':''?>>gb2312</option>
  168. <option value="big5"<?=$ecms_config['db']['setchar']=='big5'?' selected':''?>>big5</option>
  169. <option value="latin1"<?=$ecms_config['db']['setchar']=='latin1'?' selected':''?>>latin1</option>
  170. </select> <font color="#666666">(从mysql4.0导入mysql4.1以上版本需要选择固定编码,不能选自动)</font></td>
  171. </tr>
  172. <tr>
  173. <td valign="top">数据存放格式</td>
  174. <td height="23"><input name="bakdatatype" type="radio" value="0">
  175. 正常
  176. <input type="radio" name="bakdatatype" value="1" checked>
  177. 十六进制方式<font color="#666666">(十六进制备份文件会占用更多的空间)</font></td>
  178. </tr>
  179. <tr>
  180. <td>存放目录</td>
  181. <td height="23">admin/ebak/
  182. <?=$bakpath?>
  183. /
  184. <input name="mypath" type="text" id="mypath" value="<?=$mypath?>">
  185. <input type="button" name="Submit2" value="选择目录" onclick="javascript:window.open('ChangePath.php?change=1&toform=ebakchangetb<?=$ecms_hashur['ehref']?>','','width=600,height=500,scrollbars=yes');">
  186. <font color="#666666">(目录不存在,系统会自动建立)</font></td>
  187. </tr>
  188. <tr>
  189. <td valign="top">备份选项</td>
  190. <td height="23">导入方式:
  191. <select name="insertf" id="insertf">
  192. <option value="replace">REPLACE</option>
  193. <option value="insert">INSERT</option>
  194. </select>
  195. ,
  196. <input name="beover" type="checkbox" id="beover" value="1"<?=$dbeover==1?' checked':''?>>
  197. 完整插入,
  198. <input name="bakstrufour" type="checkbox" id="bakstrufour" value="1">
  199. <a title="需要转换数据表编码时选择">转成MYSQL4.0格式</a>, 每组备份间隔:
  200. <input name="waitbaktime" type="text" id="waitbaktime" value="0" size="2">
  201. 秒</td>
  202. </tr>
  203. <tr>
  204. <td valign="top">备份说明<br> <font color="#666666">(系统会生成一个readme.txt)</font></td>
  205. <td height="23"><textarea name="readme" cols="80" rows="8" id="readme"></textarea></td>
  206. </tr>
  207. <tr>
  208. <td valign="top">去除自增值的字段列表:<br> <font color="#666666">(格式:<strong>表名.字段名</strong><br>
  209. 多个请用&quot;,&quot;格开)</font></td>
  210. <td height="23"><textarea name="autofield" cols="80" rows="5" id="autofield"></textarea></td>
  211. </tr>
  212. </table>
  213. </td>
  214. </tr>
  215. <tr class="header">
  216. <td height="25">选择要备份的表:( <a href="#ebak" onclick="SelectCheckAll(document.ebakchangetb)"><u>全选</u></a>
  217. | <a href="#ebak" onclick="reverseCheckAll(document.ebakchangetb);"><u>反选</u></a>
  218. )</td>
  219. </tr>
  220. <tr>
  221. <td height="25" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  222. <tr bgcolor="#DBEAF5">
  223. <td width="5%" height="23"> <div align="center">选择</div></td>
  224. <td width="27%" height="23" bgcolor="#DBEAF5"> <div align="center">表名(点击查看字段)</div></td>
  225. <td width="13%" height="23" bgcolor="#DBEAF5"> <div align="center">类型</div></td>
  226. <td width="15%" bgcolor="#DBEAF5"><div align="center">编码</div></td>
  227. <td width="15%" height="23"> <div align="center">记录数</div></td>
  228. <td width="14%" height="23"> <div align="center">大小</div></td>
  229. <td width="11%" height="23"> <div align="center">碎片</div></td>
  230. </tr>
  231. <?
  232. $totaldatasize=0;//总数据大小
  233. $tablenum=0;//总表数
  234. $datasize=0;//数据大小
  235. $rownum=0;//总记录数
  236. while($r=$empire->fetch($sql))
  237. {
  238. $rownum+=$r[Rows];
  239. $tablenum++;
  240. $datasize=$r[Data_length]+$r[Index_length];
  241. $totaldatasize+=$r[Data_length]+$r[Index_length]+$r[Data_free];
  242. $collation=$r[Collation]?$r[Collation]:'---';
  243. ?>
  244. <tr id=tb<?=$r[Name]?>>
  245. <td height="23"> <div align="center">
  246. <input name="tablename[]" type="checkbox" id="tablename[]" value="<?=$r[Name]?>" onclick="if(this.checked){tb<?=$r[Name]?>.style.backgroundColor='#F1F7FC';}else{tb<?=$r[Name]?>.style.backgroundColor='#ffffff';}" checked>
  247. </div></td>
  248. <td height="23"> <a href="#ebak" onclick="window.open('ListField.php?mydbname=<?=$mydbname?>&mytbname=<?=$r[Name]?><?=$ecms_hashur['ehref']?>','','width=660,height=500,scrollbars=yes');" title="点击查看表字段列表">
  249. <?=$r[Name]?>
  250. </a></td>
  251. <td height="23"> <div align="center">
  252. <?=$r[Type]?$r[Type]:$r[Engine]?>
  253. </div></td>
  254. <td><div align="center">
  255. <?=$collation?>
  256. </div></td>
  257. <td height="23"> <div align="right">
  258. <?=$r[Rows]?>
  259. </div></td>
  260. <td height="23"> <div align="right">
  261. <?=Ebak_ChangeSize($datasize)?>
  262. </div></td>
  263. <td height="23"> <div align="right">
  264. <?=Ebak_ChangeSize($r[Data_free])?>
  265. </div></td>
  266. </tr>
  267. <?
  268. }
  269. db_close();
  270. $empire=null;
  271. ?>
  272. <tr bgcolor="#DBEAF5">
  273. <td height="23"> <div align="center">
  274. <input type=checkbox name=chkall value=on onclick=CheckAll(this.form) checked>
  275. </div></td>
  276. <td height="23"> <div align="center">
  277. <?=$tablenum?>
  278. </div></td>
  279. <td height="23"> <div align="center">---</div></td>
  280. <td><div align="center">---</div></td>
  281. <td height="23"> <div align="center">
  282. <?=$rownum?>
  283. </div></td>
  284. <td height="23" colspan="2"> <div align="center">
  285. <?=Ebak_ChangeSize($totaldatasize)?>
  286. </div></td>
  287. </tr>
  288. </table></td>
  289. </tr>
  290. <tr class="header">
  291. <td height="25">
  292. <div align="center">
  293. <input type="submit" name="Submit" value="开始备份" onclick="document.ebakchangetb.phome.value='DoEbak';">
  294. &nbsp;&nbsp; &nbsp;&nbsp;
  295. <input type="submit" name="Submit2" value="修复数据表" onclick="document.ebakchangetb.phome.value='DoRep';">
  296. &nbsp;&nbsp; &nbsp;&nbsp;
  297. <input type="submit" name="Submit22" value="优化数据表" onclick="document.ebakchangetb.phome.value='DoOpi';">
  298. &nbsp;&nbsp; &nbsp;&nbsp;
  299. <input type="submit" name="Submit22" value="删除数据表" onclick="document.ebakchangetb.phome.value='DoDrop';">
  300. &nbsp;&nbsp; &nbsp;&nbsp;
  301. <input type="submit" name="Submit22" value="清空数据表" onclick="document.ebakchangetb.phome.value='EmptyTable';">
  302. </div></td>
  303. </tr>
  304. </table>
  305. </form>
  306. </body>
  307. </html>