PHP文字資料庫類之管理(txtDB.manager.php) (轉)

amyz發表於2007-08-15
PHP文字資料庫類之管理(txtDB.manager.php) (轉)[@more@]

使用方法:結合txt.inc

初始和密碼為:admin 123

CODE:


/*
TxtDb Manager
version: 0.1.0
:
This script is the manager for PHP txtDb.
#############################
Suppose Modify structrual
*/
include('txtdb.inc');
$="txtdb";
$s_admins=array("admin","admin2","admin3");
$s_pass="123";
####################
if(isset($_GET))@extract($_GET);
if(isset($_POST))@extract($_POST);
if(isset($_SESSION))@extract($_SESSION);
if(isset($_COOKIE))@extract($_COOKIE);
#################
if(isset($u_admin))$admin=$u_admin;
if(isset($u_password))$password=md5($u_password);
$s_password=md5($s_password);
$islogin=false;
if(($password==$s_password)and in_array($admin,$s_admins)){
 setcookie('admin', $admin);
 setcookie('password',$password);
 $islogin=true; 
 if(isset($u_admin) and isset($u_password))echo"
}
if($action=="quit"){
 setcookie('admin');
 setcookie('password');
 $islogin=false;
 echo "
}
if(!$islogin and $action!="leftbar" and $action!="")$action="main";
#################
?>


Episome TxtDb Manager








##########################
if(!is_dir($root))
 die('
Current TxtDb root does not exists!
');
$db=new txtDb($root);
$version=$db->version;
############################
switch($action){
 case "leftbar":
 leftbar();
 break;
 case "main":
 main();
 break;
 case "selecttable":
 selecttable($table);
 break;
 case "viewdata":
 viewdata($table,$start,$num,$sortby,$order,$keyword,$fields,$selectstring,$selectcolumn);
 break;
 case "newtable":
 newtable($table,$tblfields);
 break;
 case "insertrecord":
 insertrecord($table,$value,$id);
 break;
 case "delrecord":
 delrecord($table,$id,$start,$num,$order,$sortby);
 break;
 case "editrecord":
 editrecord($table,$id,$act,$value,$start,$num,$order,$sortby);
 break;
 case "droptable":
 droptable($table);
 break;
 case "cleartable":
 cleartable($table);
 break;
 default:
 index();
}
/*
edit a row from table
*/
function editrecord($table,$id,$act,$value,$start,$num,$order,$sortby){
 global $db;
 $order=($order=="asc")?"desc":"asc";
 $db->open($table,$id,1);
 if($act=="save" and is_array($value)){
 $db->change($value,$id);
 echo "
The record of table [".$table."] has been modifyed !

";
 echo "
  • View data";
     die();
     }
    echo"
    Modify record of table [".$table."] !




     
     


     
     ";
     foreach($db->fieldNames as $field){
     $v=stripslashes($db->dbValues[$id][$field]);
     echo "
     

     
     
     
     ";
     }
    echo"
     
    $field : 

     

     
     
      
     
     

    ";
    }
    /*
    delete a row from table
    */
    function delrecord($table,$id,$start,$num,$order,$sortby){
     global $db;
     $order=($order=="asc")?"desc":"asc";
     $db->open($table,0,1);
     $db->delete($id);
     echo "
    The record of table [".$table."] has been deleted !

    ";
     echo "
  • View data";
     die();
    }
    /*
    Insert a row to table
    */
    function insertrecord($table,$value,$id){
     global $db;
     $db->open($table,0,1);
     if(is_array($value)){
     $db->append($value,$id);
     echo "
    The record has been inserted to table [".$table."]!

    ";
     echo "
  • View data";
     echo "
  • Insert record";
     die();
     }
     echo"
    Insert record to [".$table."]
    ";
     echo "
    ";
     echo "


     
     


     
     
    ";
     foreach($db->fieldNames as $field){
     echo "
     
     
     
     
     ";
     }
     echo "
     
    $field : 

     
     ID
     
     

    ";
    }
    /*
    view data
    */
    function viewdata($table,$start,$num,$sortby,$order,$keyword,$fields,$selectstring,$selectcolumn){
     global $db;
     if(trim($start)=='')$start=0;
     if(trim($num)=='')$num=30;
     $db->open($table,$start,$num);
     if(trim($sortby)!='')
     $db->sortby($sortby,$order);
     $order=($order=="asc")?"desc":"asc";
     $dbValues=$db->dbValues;
     if(trim($keyword)!="")
     $dbValues=$db->query($keyword,$fields);
     if(trim($selectstring)!="")
     $dbValues=$db->select($selectcolumn,$selectstring);
    echo"
    Data for Table [".$table."]





     


     
     
     
     
    ";
     foreach($db->fieldNames as $value){
     $select_string.="";
     echo" ";
     }
     echo "";
     if(is_array($dbValues))
     foreach($dbValues as $id=>$Values){
     echo " ";
     echo "";
     echo "";
     if(is_array($Values))
     foreach($Values as $key=>$value){
     echo "";
     }
     echo " ";
     }
    echo"
     
     
     Actions  ID  ".$value." 
     Edit Del  $id  ".htmlspecialchars($value)." 

     



  • Query :





     
     
     
     
     


     

       Show

        rows [All

       Starting from

       

     
       
       

     

     

       For in  

     
      [All]
     
     
     
     

     

     

       For ==  

     
     
     
     
     
     

     




  • Records : $db->lines
  • Insert record
  • Clear or Drop this table.
  • ";
    $db->times();
    }
    /*
    select table
    */
    function selecttable($table){
     global $db;
     $db->open($table,0,1);
     echo "
    Select Table [".$table."]

    ";
     echo "
  • Path : ".$db->tableName;
     echo "
  • Size : ".number_format(filesize($db->tableName))." (bytes)";
     echo "
  • Records : ".$db->lines;
     echo "
  • Fields :".$db->fields."
    ";
     echo "";
     echo "";
     echo "";
     echo "";
     echo "
  • View data";
     echo "
  • Insert record";
     echo "
  • Clear or Drop this table.";
     echo "
  • Time of last modification : ".date ("F d Y H:i:s.", filemtime($db->tableName))."
    ";
     clearstatcache();
     $db->times();
    }
    /*
    clear table
    */
    function cleartable($table){
     global $db;
     $db->open($table,0,1);
     $db->clear();
     echo "
    The table [".$table."] has been cleared !

    ";
    }
    /*
    drop table
    */
    function droptable($table){
     global $db;
     $db->open($table,0,1);
     $db->drop();
     echo "
    The table [".$table."] has been droped !

    ";
     echo "
    }
    /*
    create table
    */
    function newtable($table,$tblfields){
     global $db;
     if(isset($table) and isset($tblfields)){
     if(!ereg("^[-a-zA-Z0-9_.]",$table))
     die('Table name ['.$table.'] not allow!');
     $tblfields=str_replace(" ","",$tblfields);
     $fields=explode(" ",$tblfields);
     foreach($fields as $key=>$value){
     if(trim($value)=="")unset($fields[$key]);
     }
     if($db->create($table,$fields)){
     echo "
    The table [".$table."] has been created !

    ";
     echo "
     die();
     }
     }
     ?>
     
     
    Create New Table

     

     

     TableName:

     

     Fields: (field per line)

      
     

     

    }
    /*
    show DB information
    */
    function main(){
     global $version,$islogin;
     $httphost=$_ENV["HTTP_HOST"];
     $server=$_SERVER["SERVER_SOFTWARE"];
     $php=PHP_VERSION;
     $os=PHP_OS;
    echo"
     
     



     
    Welcome to TxtDb Manager

     


     
  • TxtDb $version running on $httphost
     
  • PHP $php running on $os
     
  • Server_SoftWare : $server";
     if(!$islogin){
     echo "
     

     
     
     
     

     ";
     } 
    echo "

    ";
    }
    /*
    navigation bar
    */
    function leftbar(){
     global $db,$islogin;
    ?>


     =$db->root?>
     

     
     ";
     showTables($db->root,$db->exten);
     echo"
     

     


     Actions
     

     
     
     
     ";
     if($islogin)echo"
     
     
     ";
    echo"
     
    w Create Table
    w Exit Manager

     


    ";
    }
    /*
    show All tables
    */
    function showtables($path){
     global $db;
     $dirhandle=opendir($path);
     while($file=readdir($dirhandle)){
     if ($file!="." && $file!=".."){
     if (is_dir($path.'/'.$file)){
     showtables($path.'/'.$file);
     }else{
     $path_info=pathinfo($file);
     $exten=strtolower(".".$path_info["extension"]);
     if($exten==strtolower($db->exten)){
     if(strpos($path,'/')){
     $file=str_replace($db->root.'/','',$path.'/'.$file);
     $subdir=" ";
     }
     $file=str_replace($db->exten,'',$file);
     echo "
     
     
     $subdirw $file
     
     
     ";
     }//
     }
     }
     }
     closedir($dirhandle);
    }
    /*
    index of this manager
    */
    function index(){
    print'

     
     
    ';
    }
  • 來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-959184/,如需轉載,請註明出處,否則將追究法律責任。

    相關文章