📄 functions.php
字号:
<?php
$editor=1;
//字符过虑
function escape_str($str){
$str=mysql_escape_string($str);
$str=str_replace('\\\'','\'\'',$str);
$str=str_replace("\\\\","\\\\\\\\",$str);
$str=str_replace('$','\$',$str);
return $str;
}
//修复表
function Ebak_Rep($tablename,$dbname,$userid,$username){
global $empire,$phome_db_dbname;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{printerror("MustChangeOneTable","history.go(-1)");}
for($i=0;$i<$count;$i++)
{
//$sql1=$empire->query("OPTIMIZE TABLE `$tablename[$i]`;");
//$sql2=$empire->query("CHECK TABLE `$tablename[$i]`;");
//$sql3=$empire->query("ANALYZE TABLE `$tablename[$i]`;");
$sql4=$empire->query("REPAIR TABLE `$tablename[$i]`;");
}
$empire->query("use `$phome_db_dbname`");
//操作日志
insert_dolog("dbname=".$dbname);
printerror("RepireTableSuccess","ChangeTable.php?mydbname=$dbname");
}
//忧化表
function Ebak_Opi($tablename,$dbname,$userid,$username){
global $empire,$phome_db_dbname;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{printerror("MustChangeOneTable","history.go(-1)");}
for($i=0;$i<$count;$i++)
{
$sql1=$empire->query("OPTIMIZE TABLE `$tablename[$i]`;");
}
$empire->query("use `$phome_db_dbname`");
//操作日志
insert_dolog("dbname=".$dbname);
printerror("OptimTableSuccess","ChangeTable.php?mydbname=$dbname");
}
//删除数据表
function Ebak_Drop($tablename,$dbname,$userid,$username){
global $empire,$phome_db_dbname;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{printerror("MustChangeOneDelTable","history.go(-1)");}
$a="";
$first=1;
for($i=0;$i<$count;$i++)
{
if(empty($first))
{
$a.=",";
}
else
{
$first=0;
}
$a.="`".$tablename[$i]."`";
}
$sql1=$empire->query("DROP TABLE IF EXISTS ".$a.";");
$empire->query("use `$phome_db_dbname`");
//操作日志
insert_dolog("dbname=".$dbname);
printerror("DelTableSuccess","ChangeTable.php?mydbname=$dbname");
}
//删除数据库
function Ebak_DropDb($dbname,$userid,$username){
global $empire;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
if(empty($dbname))
{printerror("ChangeDropDb","history.go(-1)");}
$sql=$empire->query("DROP DATABASE `$dbname`");
if($sql)
{
//操作日志
insert_dolog("dbname=".$dbname);
printerror("DropDbSuccess","ChangeDb.php");
}
else
{printerror("DbError","history.go(-1)");}
}
//建立数据库
function Ebak_CreatDb($dbname,$dbchar,$userid,$username){
global $empire,$phome_use_dbver;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
if(!trim($dbname)){
printerror("EmptyDbname","history.go(-1)");
}
$a="";
if($dbchar&&$phome_use_dbver>='4.1'){
$a=" DEFAULT CHARACTER SET ".$dbchar;
}
$sql=$empire->query("CREATE DATABASE IF NOT EXISTS `$dbname`".$a);
if($sql){
//操作日志
insert_dolog("dbname=".$dbname);
printerror("AddDbSuccess","ChangeDb.php");
}
else
{printerror("DbError","history.go(-1)");}
}
//清空表
function Ebak_EmptyTable($tablename,$dbname,$userid,$username){
global $empire,$phome_db_dbname;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{printerror("MustChangeOneTable","history.go(-1)");}
for($i=0;$i<$count;$i++)
{
$sql1=$empire->query("TRUNCATE `".$tablename[$i]."`;");
}
$empire->query("use `$phome_db_dbname`");
//操作日志
insert_dolog("dbname=".$dbname);
printerror("EmptyTableSuccess","ChangeTable.php?mydbname=$dbname");
}
//---------------------------备份
//初使化备份
function Ebak_DoEbak($add,$userid,$username){
global $empire,$public_r,$fun_r,$phome_use_dbver;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
$dbname=RepPostVar($add['mydbname']);
if(empty($dbname)){
printerror("NotChangeDbname","history.go(-1)");
}
$tablename=$add['tablename'];
$count=count($tablename);
if(empty($count)){
printerror("MustChangeOneTable","history.go(-1)");
}
$add['baktype']=(int)$add['baktype'];
$add['filesize']=(int)$add['filesize'];
$add['bakline']=(int)$add['bakline'];
$add['autoauf']=(int)$add['autoauf'];
if((!$add['filesize']&&!$add['baktype'])||(!$add['bakline']&&$add['baktype'])){
printerror("FileSizeEmpty","history.go(-1)");
}
//目录名
$bakpath=$public_r['bakdbpath'];
if(empty($add['mypath'])){
$add['mypath']=$dbname."_".date("YmdHis");
}
DoMkdir($bakpath."/".$add['mypath']);
//生成说明文件
$readme=$add['readme'];
$rfile=$bakpath."/".$add['mypath']."/readme.txt";
$readme.="\r\n\r\nBaktime: ".date("Y-m-d H:i:s");
WriteFiletext_n($rfile,$readme);
$b_table="";
$d_table="";
for($i=0;$i<$count;$i++){
$b_table.=$tablename[$i].",";
$d_table.="\$tb[".$tablename[$i]."]=0;\r\n";
}
//去掉最后一个,
$b_table=substr($b_table,0,strlen($b_table)-1);
$bakstru=(int)$add['bakstru'];
$bakstrufour=(int)$add['bakstrufour'];
$beover=(int)$add['beover'];
$waitbaktime=(int)$add['waitbaktime'];
if($add['insertf']=='insert'){
$insertf='insert';
}
else{
$insertf='replace';
}
if($phome_use_dbver=='4.0'&&$add['dbchar']=='auto')
{
$add['dbchar']='';
}
$string="<?php
\$b_table=\"".$b_table."\";
".$d_table."
\$b_baktype=".$add['baktype'].";
\$b_filesize=".$add['filesize'].";
\$b_bakline=".$add['bakline'].";
\$b_autoauf=".$add['autoauf'].";
\$b_dbname=\"".$dbname."\";
\$b_stru=".$bakstru.";
\$b_strufour=".$bakstrufour.";
\$b_dbchar=\"".addslashes($add['dbchar'])."\";
\$b_beover=".$beover.";
\$b_insertf=\"".addslashes($insertf)."\";
\$b_autofield=\",".addslashes($add['autofield']).",\";
?>";
$cfile=$bakpath."/".$add['mypath']."/config.php";
WriteFiletext_n($cfile,$string);
if($add['baktype']){
$phome='BakExeT';
}
else{
$phome='BakExe';
}
echo $fun_r['FirstBakSuccess']."<script>self.location.href='phome.php?phome=$phome&t=0&s=0&p=0&mypath=$add[mypath]&waitbaktime=$waitbaktime';</script>";
exit();
}
//执行备份(按文件大小)
function Ebak_BakExe($t,$s,$p,$mypath,$alltotal,$thenof,$fnum,$stime=0,$userid,$username){
global $empire,$public_r,$fun_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(empty($mypath)){
printerror("ErrorUrl","history.go(-1)");
}
$bakpath=$public_r['bakdbpath'];
$path=$bakpath."/".$mypath;
@include($path."/config.php");
if(empty($b_table)){
printerror("ErrorUrl","history.go(-1)");
}
$waitbaktime=(int)$_GET['waitbaktime'];
if(empty($stime))
{
$stime=time();
}
$header="<?php
@include(\"../../inc/header.php\");
";
$footer="
@include(\"../../inc/footer.php\");
?>";
$btb=explode(",",$b_table);
$count=count($btb);
$t=(int)$t;
$s=(int)$s;
$p=(int)$p;
//备份完毕
if($t>=$count)
{
insert_dolog("dbname=".$b_dbname);//操作日志
$varmessage=$fun_r['BakSuccess']."<br><br>".$fun_r['TotalUseTime'].ToChangeUseTime($stime);
$GLOBALS['varmessage']=$varmessage;
printerror('VarMessage','ChangeDb.php',0,1);
}
$dumpsql=Ebak_ReturnVer();
//选择数据库
$u=$empire->query("use `$b_dbname`");
//编码
if($b_dbchar=='auto')
{
if(empty($s))
{
$status_r=Ebak_GetTotal($b_dbname,$btb[$t]);
$collation=Ebak_GetSetChar($status_r['Collation']);
DoSetDbChar($collation);
//总记录数
$num=$public_r[limittype]?-1:$status_r['Rows'];
}
else
{
$collation=$_GET['collation'];
DoSetDbChar($collation);
$num=(int)$alltotal;
}
$dumpsql.=Ebak_ReturnSetNames($collation);
}
else
{
DoSetDbChar($b_dbchar);
if(empty($s))
{
//总记录数
if($public_r[limittype])
{
$num=-1;
}
else
{
$status_r=Ebak_GetTotal($b_dbname,$btb[$t]);
$num=$status_r['Rows'];
}
}
else
{
$num=(int)$alltotal;
}
}
//备份数据库结构
if($b_stru&&empty($s))
{
$dumpsql.=Ebak_Returnstru($btb[$t],$b_strufour);
}
$sql=$empire->query("select * from `".$btb[$t]."` limit $s,$num");
//取得字段数
if(empty($fnum))
{
$return_fr=Ebak_ReturnTbfield($b_dbname,$btb[$t],$b_autofield);
$fieldnum=$return_fr['num'];
$noautof=$return_fr['autof'];
}
else
{
$fieldnum=$fnum;
$noautof=$thenof;
}
//完整插入
$inf='';
if($b_beover==1)
{
$inf='('.Ebak_ReturnInTbfield($b_dbname,$btb[$t]).')';
}
$b=0;
while($r=$empire->fetch($sql))
{
$b=1;
$s++;
$dumpsql.="E_D(\"".$b_insertf." into `".$btb[$t]."`".$inf." values(";
$first=1;
for($i=0;$i<$fieldnum;$i++)
{
//首字段
if(empty($first))
{
$dumpsql.=",";
}
else
{
$first=0;
}
$myi=$i+1;
if(!isset($r[$i])||strstr($noautof,",".$myi.","))
{
$dumpsql.="NULL";
}
else
{
$dumpsql.="'".escape_str($r[$i])."'";
}
}
$dumpsql.=");\");\r\n";
//是否超过限制
if(strlen($dumpsql)>=$b_filesize*1024)
{
$p++;
$sfile=$path."/".$btb[$t]."_".$p.".php";
$dumpsql=$header.$dumpsql.$footer;
WriteFiletext_n($sfile,$dumpsql);
$empire->free($sql);
//echo $fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s)."<script>self.location.href='phome.php?phome=BakExe&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&stime=$stime';</script>";
echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phome.php?phome=BakExe&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&stime=$stime&waitbaktime=$waitbaktime&collation=$collation\">".$fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s);
exit();
}
}
//最后一个备份
if(empty($p)||$b==1)
{
$p++;
$sfile=$path."/".$btb[$t]."_".$p.".php";
$dumpsql=$header.$dumpsql.$footer;
WriteFiletext_n($sfile,$dumpsql);
}
Ebak_RepFilenum($p,$btb[$t],$path);
$t++;
$empire->free($sql);
//进入下一个表
//echo $btb[$t-1].$fun_r['OneTableBakSuccess']."<script>self.location.href='phome.php?phome=BakExe&s=0&p=0&t=$t&mypath=$mypath&stime=$stime';</script>";
echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phome.php?phome=BakExe&s=0&p=0&t=$t&mypath=$mypath&stime=$stime&waitbaktime=$waitbaktime\">".$btb[$t-1].$fun_r['OneTableBakSuccess'];
exit();
}
//执行备份(按记录)
function Ebak_BakExeT($t,$s,$p,$mypath,$alltotal,$thenof,$fnum,$auf='',$aufval=0,$stime=0,$userid,$username){
global $empire,$public_r,$fun_r;
//验证权限
CheckLevel($userid,$username,$classid,"dbdata");
if(empty($mypath)){
printerror("ErrorUrl","history.go(-1)");
}
$bakpath=$public_r['bakdbpath'];
$path=$bakpath."/".$mypath;
@include($path."/config.php");
if(empty($b_table)){
printerror("ErrorUrl","history.go(-1)");
}
$waitbaktime=(int)$_GET['waitbaktime'];
if(empty($stime))
{
$stime=time();
}
$header="<?php
@include(\"../../inc/header.php\");
";
$footer="
@include(\"../../inc/footer.php\");
?>";
$btb=explode(",",$b_table);
$count=count($btb);
$t=(int)$t;
$s=(int)$s;
$p=(int)$p;
//备份完毕
if($t>=$count)
{
insert_dolog("dbname=".$b_dbname);//操作日志
$varmessage=$fun_r['BakSuccess']."<br><br>".$fun_r['TotalUseTime'].ToChangeUseTime($stime);
$GLOBALS['varmessage']=$varmessage;
printerror('VarMessage','ChangeDb.php',0,1);
}
$dumpsql=Ebak_ReturnVer();
//选择数据库
$u=$empire->query("use `$b_dbname`");
//编码
if($b_dbchar=='auto')
{
if(empty($s))
{
$status_r=Ebak_GetTotal($b_dbname,$btb[$t]);
$collation=Ebak_GetSetChar($status_r['Collation']);
DoSetDbChar($collation);
//总记录数
$num=$public_r[limittype]?-1:$status_r['Rows'];
}
else
{
$collation=$_GET['collation'];
DoSetDbChar($collation);
$num=(int)$alltotal;
}
$dumpsql.=Ebak_ReturnSetNames($collation);
}
else
{
DoSetDbChar($b_dbchar);
if(empty($s))
{
//总记录数
if($public_r[limittype])
{
$num=-1;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -