Ejemplo n.º 1
0
 function copyTable()
 {
     $tableselect = $this->getRequestVar('tableselect');
     $newTableName = $this->getRequestVar('newTableName');
     $copythis = $this->getRequestVar('copythis');
     $noDeletedRecords = $this->getRequestVar('noDeletedRecords');
     $ReplaceIDs = $this->getRequestVar('ReplaceIDs', '0');
     $switchToNewTable = $this->getRequestVar('switchToNewTable', '0');
     $copyLimit = $this->getRequestVar('copyLimit', '0');
     //first copy the table if that is required
     if ($copythis == 'structure' || $copythis == 'all') {
         $sql = $GLOBALS['db']->dropTableNameSQL($newTableName);
         $result = $GLOBALS['db']->query($sql, false);
         $sql = "CREATE TABLE {$newTableName} LIKE {$tableselect}";
         $result = $GLOBALS['db']->query($sql, false);
     }
     //Now populate with data if that is required
     if ($copythis == 'data1' || $copythis == 'data2' || $copythis == 'all') {
         $additionalClauses = array();
         if ($noDeletedRecords) {
             $additionalClauses[] = "WHERE deleted=0";
         }
         if (is_numeric($copyLimit)) {
             $additionalClauses = "LIMIT {$copyLimit}";
         }
         $sqlEnd = ' ' . implode(' ', $additionalClauses);
         $sql = "INSERT INTO {$newTableName} SELECT * FROM {$tableselect}{$sqlEnd}";
         $result = $GLOBALS['db']->query($sql, false);
     }
     //now rewrite the IDs if required
     if ($ReplaceIDs) {
         $this->assembleList();
         $tables = $this->tableArray;
         $cols = $tables[$tableselect];
         $id = '';
         if (isset($cols['id'])) {
             $id = 'id';
         }
         if (isset($cols['id_c'])) {
             $id = 'id_c';
         }
         if (isset($cols['email_id'])) {
             $id = 'email_id';
         }
         $sql = "SELECT {$id} FROM {$newTableName}";
         $result = $GLOBALS['db']->query($sql);
         while ($hash = $GLOBALS['db']->fetchByAssoc($result)) {
             $newID = create_guid();
             $sql = "UPDATE {$newTableName} SET {$id}='{$newID}' WHERE {$id}='{$hash[$id]}'";
             $update = $GLOBALS['db']->query($sql);
         }
     }
     if (file_exists('cache/SweetDB_tableArray.php')) {
         unlink('cache/SweetDB_tableArray.php');
     }
     $SweetDB_query = new SweetDB_query();
     if ($switchToNewTable) {
         $_REQUEST['sql'] = "SELECT * FROM {$newTableName}";
     }
     $SweetDB_query->display_query();
 }
Ejemplo n.º 2
0
$SweetDB->getAlphaSortedTables();
switch ($command) {
    case 'about':
        $SweetDB->sugar_smarty->assign('VERSION', $SweetDBConfig['version']);
        $SweetDB->sugar_smarty->assign('RELEASE_DATE', $SweetDBConfig['release_date']);
        $SweetDB->sugar_smarty->display("custom/modules/Administration/SweetDBAdmin/tpls/SweetDBAbout.tpl");
        break;
    case 'export_csv':
        require 'custom/modules/Administration/SweetDBAdmin/SweetDBExportCSV.php';
        break;
    case 'importSQL':
    case 'importCSV':
        break;
    case 'deleteCaches':
        $SweetDB->deleteCaches();
        $SweetDB_query->display_query();
        break;
    case 'add_index':
    case 'edit_index':
        $SweetDB_Indexes = new SweetDB_Indexes();
        $SweetDB_Indexes->add_edit_indexes();
        break;
    case 'save_index':
        $SweetDB_Indexes = new SweetDB_Indexes();
        $SweetDB_Indexes->save_index();
        $SweetDB_Indexes->display_indexes();
        break;
    case 'delete_index':
        $SweetDB_Indexes = new SweetDB_Indexes();
        $SweetDB_Indexes->delete_index();
        $SweetDB_Indexes->display_indexes();