home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / SQLiteDbOperation.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  7.7 KB  |  209 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * Class for manage database operation
  5. * @package SQLiteManager
  6. * @author FrΘdΘric HENNINOT
  7. * @version $Id: SQLiteDbOperation.class.php,v 1.9 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.9 $
  8. */
  9.  
  10. /**
  11. * Web based SQLite management
  12. * Class for manage database operation
  13. * @package SQLiteManager
  14. * @author FrΘdΘric HENNINOT
  15. * @version $Id: SQLiteDbOperation.class.php,v 1.9 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.9 $
  16. */
  17.  
  18. include_once INCLUDE_LIB."SQLiteDbConnect.class.php";
  19.  
  20. class SQLiteDbOperation {
  21.     
  22.     /**
  23.     * reference to the connection object
  24.     *
  25.     * @access public
  26.     * @var object
  27.     */
  28.     var $connId;
  29.     
  30.     /**
  31.      *
  32.      * @access private
  33.      * @var array
  34.      */
  35.     var $tabDb;
  36.     
  37.     /**
  38.     * Class constructor
  39.     *
  40.     * @access public
  41.     * @param string $conn reference to the connection object
  42.     */
  43.     function SQLiteDbOperation(&$connId){
  44.         $this->connId = $connId;
  45.         $error = false;
  46.         $tabInfoDb = $this->getTabDb();
  47.         foreach($tabInfoDb as $trash=>$locDb) $locTabInfoDb[$locDb["id"]] = $locDb["name"];
  48.         if(!isset($GLOBALS['operation_action'])) $GLOBALS['operation_action'] = '';
  49.         switch($GLOBALS['operation_action']){
  50.             case '':
  51.                 $this->operationView();
  52.                 break;
  53.             case 'renameTable':
  54.                 $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], brackets($_REQUEST["newName"]), false);
  55.                 echo '<script type="text/javascript">parent.left.location=\'left.php?dbsel='.$GLOBALS["dbsel"].'\'; parent.main.location=\'main.php?dbsel='.$GLOBALS["dbsel"].'&table='.$_REQUEST["newName"].'&action='.$GLOBALS["action"].'\'</script>';
  56.                 $this->operationView();
  57.                 break;
  58.             case 'moveTable':
  59.                 if($_REQUEST["dbDest"] == $GLOBALS["tabInfoDb"]["id"]) $destTableInfo = brackets($_REQUEST["moveName"]);
  60.                 else $destTableInfo = brackets($locTabInfoDb[$_REQUEST["dbDest"]]).".".brackets($_REQUEST["moveName"]);
  61.                 $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], $destTableInfo, false);
  62.                 $this->operationView();                
  63.                 break;
  64.             case 'copyTable':
  65.                 if($_REQUEST["dbDest"] == $GLOBALS["tabInfoDb"]["id"]) $destTableInfo = brackets($_REQUEST["copyName"]);
  66.                 else $destTableInfo = brackets($locTabInfoDb[$_REQUEST["dbDest"]]).".".brackets($_REQUEST["copyName"]);
  67.                 $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], $destTableInfo, true);
  68.                 $this->operationView();
  69.                 break;
  70.         }
  71.         if(!empty($GLOBALS['operation_action']) && !$error){
  72.             $GLOBALS["redirect"] = "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS["dbsel"]."'; parent.main.location='main.php?dbsel=".$GLOBALS["dbsel"]."';</script>";            
  73.         }
  74.     }
  75.     
  76.     /**
  77.     * Display Available Operation
  78.     *
  79.     * @access public    
  80.     */
  81.     function operationView(){
  82.         $ModifPropOk = (!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties'));
  83.         $localTableProp = new SQLiteTableProperties($this->connId);
  84.         $fieldInfo = $localTableProp->getTableProperties($GLOBALS["table"]);
  85.         
  86.         // build select field
  87.         $fieldList = '<select name="field">';
  88.         foreach($fieldInfo as $info) $fieldList .= '<option value="'.$info["cid"].'">'.$info["name"].'</option>';
  89.         $fieldList .= '</select>';
  90.         
  91.  
  92.         
  93.         echo '<center>
  94.                 <table cellspacing="0" width="80%">
  95.                     <tr>
  96.                         <td>';
  97.  
  98.         echo '                <form name="Rename" action="main.php" method="POST" target="main">
  99.                             <table class="Browse" cellspacing="0" width="100%">
  100.                                 <thead>
  101.                                     <tr class="Browse">
  102.                                         <td colspan=2 align="left" class="tapPropTitle"> '.$GLOBALS["traduct"]->get(215).'</td>
  103.                                     </tr>
  104.                                 </thead>'."\n";
  105.         echo '                    <tr>
  106.                                         <td> <input type="text" name="newName" size=15> </td><td align="right"><input type="submit" value="'.$GLOBALS["traduct"]->get(69).'" class="button"></td>
  107.                                     </tr>
  108.                             </table>
  109.                             <input type="hidden" name="dbsel" value="'.$GLOBALS["dbsel"].'">
  110.                             <input type="hidden" name="table" value="'.$GLOBALS["table"].'">
  111.                             <input type="hidden" name="action" value="'.$GLOBALS["action"].'">
  112.                             <input type="hidden" name="operation_action" value="renameTable">
  113.                             </form>';
  114.         echo '            </td>
  115.                     </tr>';
  116.         echo '        <tr>
  117.                         <td>';
  118.         echo '                <form name="Move" action="main.php" method="POST" target="main">
  119.                             <table class="Browse" cellspacing="0" width="100%">
  120.                                 <thead>
  121.                                     <tr class="Browse">
  122.                                         <td colspan=2 align="left" class="tapPropTitle"> '.$GLOBALS["traduct"]->get(216).'</td>
  123.                                     </tr>
  124.                                 </thead>'."\n";
  125.         echo '                    <tr>
  126.                                         <td> '.$this->getDbList().'.<input type="text" name="moveName" size=15> </td>
  127.                                         <td align="right"><input type="submit" value="'.$GLOBALS["traduct"]->get(69).'" class="button"></td>
  128.                                 </tr>
  129.                             </table>
  130.                             <input type="hidden" name="dbsel" value="'.$GLOBALS["dbsel"].'">
  131.                             <input type="hidden" name="table" value="'.$GLOBALS["table"].'">
  132.                             <input type="hidden" name="action" value="'.$GLOBALS["action"].'">
  133.                             <input type="hidden" name="operation_action" value="moveTable">
  134.                             </form>';
  135.         echo '            </td>
  136.                     </tr>';
  137.         echo '        <tr>
  138.                         <td>';                            
  139.         echo '                <form name="Copy" action="main.php" method="POST" target="main">
  140.                             <table class="Browse" cellspacing="0" width="100%">
  141.                                 <thead>
  142.                                     <tr class="Browse">
  143.                                         <td colspan=3 align="left" class="tapPropTitle"> '.$GLOBALS["traduct"]->get(217).'</td>
  144.                                     </tr>
  145.                                 </thead>'."\n";
  146.         echo '                    <tr>
  147.                                         <td> '.$this->getDbList($GLOBALS["dbsel"]).'.<input type="text" name="copyName" size=15> </td>
  148.                                         <td style="white-space: nowrap">
  149.                                             <input name="whatToDo" value="structure" style="vertical-align: middle;" type="radio">
  150.                                             <label>'.$GLOBALS["traduct"]->get(124).'</label>  <br>
  151.                                             <input name="whatToDo" value="data" checked="checked" style="vertical-align: middle;" type="radio">
  152.                                             <label>'.$GLOBALS["traduct"]->get(125).'</label>  <br>
  153.                                             <input name="whatToDo" value="dataonly" style="vertical-align: middle;" type="radio">
  154.                                             <label>'.$GLOBALS["traduct"]->get(126).'</label>  <br>
  155.                                             <input name="dropTable" value="true" style="vertical-align: middle;" type="checkbox">
  156.                                             <label>'.$GLOBALS["traduct"]->get(218).'</label>  <br>
  157.                                         </td>
  158.  
  159.                                         <td align="right"><input type="submit" value="'.$GLOBALS["traduct"]->get(69).'" class="button"></td>
  160.                                 </tr>
  161.                             </table>
  162.                             <input type="hidden" name="dbsel" value="'.$GLOBALS["dbsel"].'">
  163.                             <input type="hidden" name="table" value="'.$GLOBALS["table"].'">
  164.                             <input type="hidden" name="action" value="'.$GLOBALS["action"].'">
  165.                             <input type="hidden" name="operation_action" value="copyTable">
  166.                             </form>';
  167.                             
  168.         echo '            </td>
  169.                     </tr>
  170.                 </table>
  171.                 </center>';        
  172.     }
  173.     
  174.     /**
  175.     * Display SQlite error
  176.     *
  177.     * @access public    
  178.     * @param string $queryDisplay Query to display
  179.     * @param resource $res Database connection resource
  180.     */    
  181.     function _getError($queryDisplay, $res){
  182.         if(!$res){
  183.             $errorMessage .= $GLOBALS['traduct']->get(9).' : '.@$this->connId->connId->getError()."\n";
  184.         }
  185.         displayQuery($queryDisplay);
  186.         if(!empty($errorMessage)) displayError($errorMessage);
  187.  
  188.     }
  189.     
  190.     function getDbList($selected=""){
  191.         $tabInfoDb = $this->getTabDb();
  192.         $dbList = '<select name="dbDest">';
  193.         foreach($tabInfoDb as $dbInfo) $dbList .= '<option value="'.$dbInfo["id"].'"'.(($dbInfo["id"]==$selected)? ' selected' : '' ).'>'.$dbInfo["name"].'</option>';
  194.         $dbList .= '</select>';
  195.         return $dbList;
  196.     }
  197.     
  198.     function getTabDb(){
  199.         $this->tabDb = array();
  200.         $tempTabDb = $GLOBALS["db"]->array_query("SELECT id, name, location FROM database", SQLITE_ASSOC);
  201.         foreach($tempTabDb as $tabDbInfo) {
  202.             if(sqlite::getDbVersion($tabDbInfo['location']) == $this->connId->connId->getVersion()) {
  203.                 $this->tabDb[] = $tabDbInfo;
  204.             }
  205.         }
  206.         return $this->tabDb;
  207.     }
  208. }
  209. ?>