Example #1
0
/**
 * Inserts existing entries in a PMA_* table by reading a value from an old entry
 *
 * @param   string  The array index, which Relation feature to check
 *                  ('relwork', 'commwork', ...)
 * @param   string  The array index, which PMA-table to update
 *                  ('bookmark', 'relation', ...)
 * @param   array   Which fields will be SELECT'ed from the old entry
 * @param   array   Which fields will be used for the WHERE query
 *                  (array('FIELDNAME' => 'FIELDVALUE'))
 * @param   array   Which fields will be used as new VALUES. These are the important
 *                  keys which differ from the old entry.
 *                  (array('FIELDNAME' => 'NEW FIELDVALUE'))
 * @global  string  relation variable
 *
 * @author          Garvin Hicking <*****@*****.**>
 */
function PMA_duplicate_table($work, $pma_table, $get_fields, $where_fields, $new_fields)
{
    global $cfgRelation;
    $last_id = -1;
    if ($cfgRelation[$work]) {
        $select_parts = array();
        $row_fields = array();
        foreach ($get_fields as $nr => $get_field) {
            $select_parts[] = PMA_backquote($get_field);
            $row_fields[$get_field] = 'cc';
        }
        $where_parts = array();
        foreach ($where_fields as $_where => $_value) {
            $where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\'';
        }
        $new_parts = array();
        $new_value_parts = array();
        foreach ($new_fields as $_where => $_value) {
            $new_parts[] = PMA_backquote($_where);
            $new_value_parts[] = PMA_sqlAddslashes($_value);
        }
        $table_copy_query = 'SELECT ' . implode(', ', $select_parts) . ' FROM ' . PMA_backquote($cfgRelation[$pma_table]) . ' WHERE ' . implode(' AND ', $where_parts);
        $table_copy_rs = PMA_query_as_cu($table_copy_query);
        while ($table_copy_row = @PMA_mysql_fetch_array($table_copy_rs)) {
            $value_parts = array();
            foreach ($table_copy_row as $_key => $_val) {
                if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') {
                    $value_parts[] = PMA_sqlAddslashes($_val);
                }
            }
            $new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($cfgRelation[$pma_table]) . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' . ' VALUES ' . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')';
            $new_table_rs = PMA_query_as_cu($new_table_query);
            $last_id = @function_exists('mysql_insert_id') ? @mysql_insert_id() : -1;
        }
        // end while
        return $last_id;
    }
    return true;
}
Example #2
0
/**
 * purges SQL history
 *
 * deletes entries that exceeds $cfg['QueryHistoryMax'], oldest first, for the
 * given user
 *
 * @uses    $cfg['QueryHistoryMax']
 * @uses    $cfg['QueryHistoryDB']
 * @uses    $GLOBALS['controllink']
 * @uses    PMA_backquote()
 * @uses    PMA_sqlAddSlashes()
 * @uses    PMA_query_as_cu()
 * @uses    PMA_DBI_fetch_value()
 * @param   string   $username  the username
 * @access  public
 */
function PMA_purgeHistory($username)
{
    $cfgRelation = PMA_getRelationsParam();
    if (!$GLOBALS['cfg']['QueryHistoryDB'] || !$cfgRelation['historywork']) {
        return;
    }
    if (!$cfgRelation['historywork']) {
        return;
    }
    $search_query = '
         SELECT `timevalue`
           FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . '
          WHERE `username` = \'' . PMA_sqlAddSlashes($username) . '\'
       ORDER BY `timevalue` DESC
          LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1';
    if ($max_time = PMA_DBI_fetch_value($search_query, 0, 0, $GLOBALS['controllink'])) {
        PMA_query_as_cu('
             DELETE FROM
                    ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . '
              WHERE `username` = \'' . PMA_sqlAddSlashes($username) . '\'
                AND `timevalue` <= \'' . $max_time . '\'');
    }
}
Example #3
0
/**
 * renames table
 *
 * @param   string  old tbale name
 * @param   string  new table name
 * @return  boolean success
 */
function PMA_table_rename($old_name, $new_name)
{
    // Ensure the target is valid
    if (count($GLOBALS['dblist']) > 0 && !in_array($GLOBALS['db'], $GLOBALS['dblist'])) {
        return false;
    }
    PMA_DBI_select_db($GLOBALS['db']);
    $sql_query = '
        ALTER TABLE ' . PMA_backquote($old_name) . '
        RENAME ' . PMA_backquote($new_name) . ';';
    if (!PMA_DBI_query($sql_query)) {
        return false;
    }
    // garvin: Move old entries from comments to new table
    require_once './libraries/relation.lib.php';
    $cfgRelation = PMA_getRelationsParam();
    if ($cfgRelation['commwork']) {
        $remove_query = '
            UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
               SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
             WHERE db_name  = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
               AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
        PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
    if ($cfgRelation['displaywork']) {
        $table_query = '
            UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . '
               SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
             WHERE db_name  = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
               AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
        PMA_query_as_cu($table_query);
        unset($table_query);
    }
    if ($cfgRelation['relwork']) {
        $table_query = '
            UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
            SET     foreign_table = \'' . PMA_sqlAddslashes($new_name) . '\'
            WHERE foreign_db  = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
            AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
        PMA_query_as_cu($table_query);
        $table_query = '
            UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
               SET     master_table = \'' . PMA_sqlAddslashes($new_name) . '\'
             WHERE master_db  = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
               AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\'';
        PMA_query_as_cu($table_query);
        unset($table_query);
    }
    if ($cfgRelation['pdfwork']) {
        $table_query = '
            UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . '
               SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\'
             WHERE db_name  = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\'
               AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
        PMA_query_as_cu($table_query);
        unset($table_query);
    }
    return true;
}
Example #4
0
/**
* Set a single mimetype to a certain value.
*
* @param   string   the name of the db
* @param   string   the name of the table
* @param   string   the name of the column
* @param   string   the mimetype of the column
* @param   string   the transformation of the column
* @param   string   the transformation options of the column
* @param   string   (optional) force delete, will erase any existing comments for this column
*
* @return  boolean  true, if comment-query was made.
*
* @global  array    the list of relations settings
*
* @access  public
*/
function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false)
{
    global $cfgRelation;
    $test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
    $test_rs = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE);
    if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
        $row = @PMA_DBI_fetch_assoc($test_rs);
        PMA_DBI_free_result($test_rs);
        unset($test_rs);
        if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
            $upd_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\',' . '     transformation = \'' . PMA_sqlAddslashes($transformation) . '\',' . '     transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
        } else {
            $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
        }
    } elseif (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
        $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($mimetype) . '\',' . '\'' . PMA_sqlAddslashes($transformation) . '\',' . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
    }
    if (isset($upd_query)) {
        $upd_rs = PMA_query_as_cu($upd_query);
        PMA_DBI_free_result($upd_rs);
        unset($upd_rs);
        return true;
    } else {
        return false;
    }
}
Example #5
0
 /**
  * renames table
  *
  * @param   string  new table name
  * @param   string  new database name
  * @return  boolean success
  */
 function rename($new_name, $new_db = null)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['PMA_List_Database']->exists($new_db)) {
             $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = $GLOBALS['strInvalidTableName'] . ': ' . $new_table->getFullName();
         return false;
     }
     $GLOBALS['sql_query'] = '
         RENAME TABLE ' . $this->getFullName(true) . '
                   TO ' . $new_table->getFullName(true) . ';';
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         $this->errors[] = sprintf($GLOBALS['strErrorRenamingTable'], $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     /**
      * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db)
      */
     // garvin: Move old entries from comments to new table
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     if ($GLOBALS['cfgRelation']['commwork']) {
         $remove_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($remove_query);
         unset($remove_query);
     }
     if ($GLOBALS['cfgRelation']['displaywork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['relwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `foreign_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `foreign_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `master_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `master_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['pdfwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['designerwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     $this->messages[] = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }
Example #6
0
 /**
  * The "PMA_RT" constructor
  *
  * @param   mixed    The scaling factor
  * @param   integer  The page number to draw (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  * @param   boolean  Whether to display table position or not
  * @param   boolean  Was originally whether to use one color per
  *                   relation or not, now enables/disables color
  *                   everywhere, due to some problems printing with color
  * @param   boolean  Whether to draw grids or not
  * @param   boolean  Whether all tables should have the same width or not
  *
  * @global  object   The current PDF document
  * @global  string   The current db name
  * @global  array    The relations settings
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     // Font face depends on the current language
     $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
     $pdf->cMargin = 0;
     $pdf->Open();
     $pdf->SetTitle($pdf->title);
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     // fonts added to phpMyAdmin and considered non-standard by fpdf
     // (Note: those tahoma fonts are iso-8859-2 based)
     if ($this->ff == 'tahoma') {
         $pdf->AddFont('tahoma', '', 'tahoma.php');
         $pdf->AddFont('tahoma', 'B', 'tahomab.php');
     }
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql);
     if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         //            die('No tables');
     }
     while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         //$intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     //              make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->cMargin = 1;
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->cMargin = 0;
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     //        $sql    = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
     //                .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND master_table  IN (' . $intable . ')'
     //                .   ' AND foreign_table IN (' . $intable . ')';
     //        $result =  PMA_query_as_cu($sql);
     //
     // lem9:
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = FALSE;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = TRUE;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === FALSE and this is not PHP3 compatible)
                 if (PMA_isInto($rel['foreign_table'], $alltables) > -1) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     //        $norelations     = TRUE;
     //        if ($result && mysql_num_rows($result) > 0) {
     //            $norelations = FALSE;
     //            while ($row = PMA_mysql_fetch_array($result)) {
     //                $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     //            }
     //        }
     //        if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
Example #7
0
            $upd_query .= ' ON DELETE ' . $on_delete;
        }
        if ($on_update != 'nix') {
            $upd_query .= ' ON UPDATE ' . $on_update;
        }
        PMA_DBI_try_query($upd_query) or PMD_return(0, 'strErrorRelationAdded');
        PMD_return(1, 'strInnoDBRelationAdded');
    }
    //  n o n - I n n o D B
} else {
    if ($GLOBALS['cfgRelation']['relwork'] == false) {
        PMD_return(0, 'strGeneralRelationFeat:strDisabled');
    } else {
        // no need to recheck if the keys are primary or unique at this point,
        // this was checked on the interface part
        $q = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)' . ' values(' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T2) . '\', ' . '\'' . PMA_sqlAddslashes($F2) . '\', ' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T1) . '\',' . '\'' . PMA_sqlAddslashes($F1) . '\')';
        if (PMA_query_as_cu($q, false, PMA_DBI_QUERY_STORE)) {
            PMD_return(1, 'strInternalRelationAdded');
        } else {
            PMD_return(0, 'strErrorRelationAdded');
        }
    }
}
function PMD_return($b, $ret)
{
    global $db, $T1, $F1, $T2, $F2;
    header("Content-Type: text/xml; charset=utf-8");
    //utf-8 .$_GLOBALS['charset']
    header("Cache-Control: no-cache");
    die('<root act="relation_new" return="' . $ret . '" b="' . $b . '" DB1="' . urlencode($db) . '" T1="' . urlencode($T1) . '" F1="' . urlencode($F1) . '" DB2="' . urlencode($db) . '" T2="' . urlencode($T2) . '" F2="' . urlencode($F2) . '"></root>');
}
/**
 * @author  Ivan A Kirillov (Ivan.A.Kirillov@gmail.com)
 * @version $Id: pmd_display_field.php 10149 2007-03-20 15:11:15Z cybot_tm $
 * @package phpMyAdmin-Designer
 */
/**
 *
 */
include_once 'pmd_common.php';
require_once './libraries/relation.lib.php';
$table = $T;
$display_field = $F;
if ($cfgRelation['displaywork']) {
    $disp = PMA_getDisplayField($db, $table);
    if ($disp) {
        if ($display_field != $disp) {
            $upd_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' SET display_field = \'' . PMA_sqlAddslashes($display_field) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
        } else {
            $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
        }
    } elseif ($display_field != '') {
        $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . '(db_name, table_name, display_field) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($display_field) . '\')';
    }
    if (isset($upd_query)) {
        $upd_rs = PMA_query_as_cu($upd_query);
    }
}
// end if
header("Content-Type: text/xml; charset=utf-8");
header("Cache-Control: no-cache");
die("<root act='save_pos' return='strModifications'></root>");
include_once 'pmd_common.php';
require_once './libraries/relation.lib.php';
extract($_POST, EXTR_SKIP);
extract($_GET, EXTR_SKIP);
$die_save_pos = 0;
include_once 'pmd_save_pos.php';
list($DB1, $T1) = explode(".", $T1);
list($DB2, $T2) = explode(".", $T2);
$tables = PMA_DBI_get_tables_full($db, $T1);
$type_T1 = strtoupper($tables[$T1]['ENGINE']);
$tables = PMA_DBI_get_tables_full($db, $T2);
$type_T2 = strtoupper($tables[$T2]['ENGINE']);
if (PMA_foreignkey_supported($type_T1) && PMA_foreignkey_supported($type_T2) && $type_T1 == $type_T2) {
    // InnoDB
    $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
    if (isset($existrel_foreign[$F2]['constraint'])) {
        $upd_query = 'ALTER TABLE ' . PMA_backquote($T2) . ' DROP FOREIGN KEY ' . PMA_backquote($existrel_foreign[$F2]['constraint']);
        $upd_rs = PMA_DBI_query($upd_query);
    }
} else {
    // internal relations
    PMA_query_as_cu('DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . $cfg['Server']['relation'] . ' WHERE ' . 'master_db = \'' . PMA_sqlAddslashes($DB2) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($T2) . '\'' . ' AND master_field = \'' . PMA_sqlAddslashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_sqlAddslashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_sqlAddslashes($F1) . '\'', FALSE, PMA_DBI_QUERY_STORE);
}
PMD_return_upd(1, 'strRelationDeleted');
function PMD_return_upd($b, $ret)
{
    global $K;
    header("Content-Type: text/xml; charset=utf-8");
    header("Cache-Control: no-cache");
    die('<root act="relation_upd" return="' . $ret . '" b="' . $b . '" K="' . $K . '"></root>');
}
/**
 * Create a PDF page
 *
 * @uses    $GLOBALS['strNoDescription']
 * @uses    PMA_backquote()
 * @uses    $GLOBALS['cfgRelation']['db']
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_query_as_cu()
 * @uses    PMA_DBI_insert_id()
 * @uses    $GLOBALS['controllink']
 * @param string    $newpage
 * @param array     $cfgRelation
 * @param string    $db
 * @param string    $query_default_option
 * @return string   $pdf_page_number
 */
function PMA_REL_create_page($newpage, $cfgRelation, $db, $query_default_option) {
    if (! isset($newpage) || $newpage == '') {
        $newpage = $GLOBALS['strNoDescription'];
    }
    $ins_query   = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
                 . ' (db_name, page_descr)'
                 . ' VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($newpage) . '\')';
    PMA_query_as_cu($ins_query, FALSE, $query_default_option);
    return PMA_DBI_insert_id(isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : '');
}
Example #11
0
/**
* Set a SQL history entry
*
* @param   string   the name of the db
* @param   string   the name of the table
* @param   string   the username
* @param   string   the sql query
*
* @return  boolean  true
*
* @access  public
*/
function PMA_purgeHistory($username)
{
    global $cfgRelation, $cfg;
    $purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE ';
    if (PMA_MYSQL_INT_VERSION >= 40100) {
        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);
        $purge_query .= 'CONVERT(username USING ' . $conn_charset . ')';
        unset($conn_charset);
    } else {
        $purge_query .= 'username';
    }
    $purge_query .= ' = \'' . PMA_sqlAddSlashes($username) . '\' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1';
    $purge_rs = PMA_query_as_cu($purge_query);
    $i = 0;
    $row = PMA_DBI_fetch_row($purge_rs);
    PMA_DBI_free_result($purge_rs);
    if (is_array($row) && isset($row[0]) && $row[0] > 0) {
        $maxtime = $row[0];
        // quotes added around $maxtime to prevent a difficult to
        // reproduce problem
        $remove_rs = PMA_query_as_cu('DELETE FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE timevalue <= "' . $maxtime . '"');
    }
    return true;
}
/**
 * Runs query inside import buffer. This is needed to allow displaying
 * of last SELECT, SHOW or HANDLER results and similar nice stuff.
 *
 * @uses    $GLOBALS['finished'] read and write
 * @param  string query to run
 * @param  string query to display, this might be commented
 * @param  bool   whether to use control user for queries
 * @access public
 */
function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
{
    global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $my_die, $error, $reload, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, $cfg, $sql_query_disabled, $db, $run_query, $is_superuser;
    $read_multiply = 1;
    if (isset($import_run_buffer)) {
        // Should we skip something?
        if ($skip_queries > 0) {
            $skip_queries--;
        } else {
            if (!empty($import_run_buffer['sql']) && trim($import_run_buffer['sql']) != '') {
                $max_sql_len = max($max_sql_len, strlen($import_run_buffer['sql']));
                if (!$sql_query_disabled) {
                    $sql_query .= $import_run_buffer['full'];
                }
                if (!$cfg['AllowUserDropDatabase'] && !$is_superuser && preg_match('@^[[:space:]]*DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE @i', $import_run_buffer['sql'])) {
                    $GLOBALS['message'] = PMA_Message::error('strNoDropDatabases');
                    $error = TRUE;
                } else {
                    $executed_queries++;
                    if ($run_query && $GLOBALS['finished'] && empty($sql) && !$error && (!empty($import_run_buffer['sql']) && preg_match('/^[\\s]*(SELECT|SHOW|HANDLER)/i', $import_run_buffer['sql']) || $executed_queries == 1)) {
                        $go_sql = TRUE;
                        if (!$sql_query_disabled) {
                            $complete_query = $sql_query;
                            $display_query = $sql_query;
                        } else {
                            $complete_query = '';
                            $display_query = '';
                        }
                        $sql_query = $import_run_buffer['sql'];
                    } elseif ($run_query) {
                        if ($controluser) {
                            $result = PMA_query_as_cu($import_run_buffer['sql']);
                        } else {
                            $result = PMA_DBI_try_query($import_run_buffer['sql']);
                        }
                        $msg = '# ';
                        if ($result === FALSE) {
                            // execution failed
                            if (!isset($my_die)) {
                                $my_die = array();
                            }
                            $my_die[] = array('sql' => $import_run_buffer['full'], 'error' => PMA_DBI_getError());
                            if ($cfg['VerboseMultiSubmit']) {
                                $msg .= $GLOBALS['strError'];
                            }
                            if (!$cfg['IgnoreMultiSubmitErrors']) {
                                $error = TRUE;
                                return;
                            }
                        } elseif ($cfg['VerboseMultiSubmit']) {
                            $a_num_rows = (int) @PMA_DBI_num_rows($result);
                            $a_aff_rows = (int) @PMA_DBI_affected_rows();
                            if ($a_num_rows > 0) {
                                $msg .= $GLOBALS['strRows'] . ': ' . $a_num_rows;
                            } elseif ($a_aff_rows > 0) {
                                $a_rows = $msg .= sprintf($GLOBALS['strRowsAffected'], $a_aff_rows);
                            } else {
                                $msg .= $GLOBALS['strEmptyResultSet'];
                            }
                        }
                        if (!$sql_query_disabled) {
                            $sql_query .= $msg . "\n";
                        }
                        // If a 'USE <db>' SQL-clause was found and the query succeeded, set our current $db to the new one
                        if ($result != FALSE && preg_match('@^[\\s]*USE[[:space:]]*([\\S]+)@i', $import_run_buffer['sql'], $match)) {
                            $db = trim($match[1]);
                            $db = trim($db, ';');
                            // for example, USE abc;
                            $reload = TRUE;
                        }
                        if ($result != FALSE && preg_match('@^[\\s]*(DROP|CREATE)[\\s]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $import_run_buffer['sql'])) {
                            $reload = TRUE;
                        }
                    }
                    // end run query
                }
                // end if not DROP DATABASE
            } elseif (!empty($import_run_buffer['full'])) {
                if ($go_sql) {
                    $complete_query .= $import_run_buffer['full'];
                    $display_query .= $import_run_buffer['full'];
                } else {
                    if (!$sql_query_disabled) {
                        $sql_query .= $import_run_buffer['full'];
                    }
                }
            }
            // check length of query unless we decided to pass it to sql.php
            // (if $run_query is false, we are just displaying so show
            // the complete query in the textarea)
            if (!$go_sql && $run_query) {
                if ($cfg['VerboseMultiSubmit'] && !empty($sql_query)) {
                    if (strlen($sql_query) > 50000 || $executed_queries > 50 || $max_sql_len > 1000) {
                        $sql_query = '';
                        $sql_query_disabled = TRUE;
                    }
                } else {
                    if (strlen($sql_query) > 10000 || $executed_queries > 10 || $max_sql_len > 500) {
                        $sql_query = '';
                        $sql_query_disabled = TRUE;
                    }
                }
            }
        }
        // end do query (no skip)
    }
    // end buffer exists
    // Do we have something to push into buffer?
    if (!empty($sql) || !empty($full)) {
        $import_run_buffer = array('sql' => $sql, 'full' => $full);
    } else {
        unset($GLOBALS['import_run_buffer']);
    }
}
function get_tab_pos()
{
    $stmt = PMA_query_as_cu("SELECT * FROM " . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']), FALSE, PMA_DBI_QUERY_STORE);
    if ($stmt) {
        while ($t_p = PMA_DBI_fetch_array($stmt, MYSQL_ASSOC)) {
            $t_name = $t_p['db_name'] . '.' . $t_p['table_name'];
            $tab_pos[$t_name]['X'] = $t_p['x'];
            $tab_pos[$t_name]['Y'] = $t_p['y'];
            $tab_pos[$t_name]['V'] = $t_p['v'];
            $tab_pos[$t_name]['H'] = $t_p['h'];
        }
    }
    return isset($tab_pos) ? $tab_pos : NULL;
}
Example #14
0
/**
 * Copies or renames table
 * FIXME: use RENAME
 *
 * @author          Michal Čihař <*****@*****.**>
 */
function PMA_table_move_copy($source_db, $source_table, $target_db, $target_table, $what, $move)
{
    global $cfgRelation, $dblist, $err_url, $sql_query;
    // set export settings we need
    $GLOBALS['use_backquotes'] = 1;
    $GLOBALS['asfile'] = 1;
    // Ensure the target is valid
    if (count($dblist) > 0 && (PMA_isInto($source_db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
        exit;
    }
    $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
    if (empty($target_db)) {
        $target_db = $source_db;
    }
    // This could avoid some problems with replicated databases, when
    // moving table from replicated one to not replicated one
    PMA_DBI_select_db($target_db);
    $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
    // do not create the table if dataonly
    if ($what != 'dataonly') {
        require_once './libraries/export/sql.php';
        $no_constraints_comments = true;
        $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
        unset($no_constraints_comments);
        $parsed_sql = PMA_SQP_parse($sql_structure);
        /* nijel: Find table name in query and replace it */
        $i = 0;
        while ($parsed_sql[$i]['type'] != 'quote_backtick') {
            $i++;
        }
        /* no need to PMA_backquote() */
        $parsed_sql[$i]['data'] = $target;
        /* Generate query back */
        $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
        // If table exists, and 'add drop table' is selected: Drop it!
        $drop_query = '';
        if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
            $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
            $result = PMA_DBI_query($drop_query);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $drop_query . ';';
            } else {
                $sql_query = $drop_query . ';';
            }
            // garvin: If an existing table gets deleted, maintain any entries
            // for the PMA_* tables
            $maintain_relations = TRUE;
        }
        $result = @PMA_DBI_query($sql_structure);
        if (isset($sql_query)) {
            $sql_query .= "\n" . $sql_structure . ';';
        } else {
            $sql_query = $sql_structure . ';';
        }
        if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) {
            $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']);
            $i = 0;
            while ($parsed_sql[$i]['type'] != 'quote_backtick') {
                $i++;
            }
            /* no need to PMA_backquote() */
            $parsed_sql[$i]['data'] = $target;
            /* Generate query back */
            $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
            $result = PMA_DBI_query($GLOBALS['sql_constraints']);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $GLOBALS['sql_constraints'];
            } else {
                $sql_query = $GLOBALS['sql_constraints'];
            }
            unset($GLOBALS['sql_constraints']);
        }
    } else {
        $sql_query = '';
    }
    // Copy the data
    //if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) {
    if ($what == 'data' || $what == 'dataonly') {
        $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
        PMA_DBI_query($sql_insert_data);
        $sql_query .= "\n\n" . $sql_insert_data . ';';
    }
    require_once './libraries/relation.lib.php';
    $cfgRelation = PMA_getRelationsParam();
    // Drops old table if the user has requested to move it
    if ($move) {
        // This could avoid some problems with replicated databases, when
        // moving table from replicated one to not replicated one
        PMA_DBI_select_db($source_db);
        $sql_drop_table = 'DROP TABLE ' . $source;
        PMA_DBI_query($sql_drop_table);
        // garvin: Move old entries from PMA-DBs to new table
        if ($cfgRelation['commwork']) {
            $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $rmv_rs = PMA_query_as_cu($remove_query);
            unset($rmv_query);
        }
        // garvin: updating bookmarks is not possible since only a single table is moved,
        // and not the whole DB.
        // if ($cfgRelation['bookmarkwork']) {
        //     $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['bookmark'])
        //                   . ' SET     dbase = \'' . PMA_sqlAddslashes($target_db) . '\''
        //                   . ' WHERE dbase  = \'' . PMA_sqlAddslashes($source_db) . '\'';
        //     $rmv_rs    = PMA_query_as_cu($remove_query);
        //     unset($rmv_query);
        // }
        if ($cfgRelation['displaywork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        if ($cfgRelation['relwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always
        // get screwed up independently from duplication because the numbers do not
        // seem to be stored on a per-database basis. Would the author of pdf support
        // please have a look at it?
        if ($cfgRelation['pdfwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            /*
            $pdf_query = 'SELECT pdf_page_number '
                       . ' FROM ' . PMA_backquote($cfgRelation['table_coords'])
                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                       . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
            $pdf_rs = PMA_query_as_cu($pdf_query);
            
            while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['pdf_pages'])
                                . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                $tb_rs    = PMA_query_as_cu($table_query);
                unset($table_query);
                unset($tb_rs);
            }
            */
        }
        $sql_query .= "\n\n" . $sql_drop_table . ';';
    } else {
        // garvin: Create new entries as duplicates from old PMA DBs
        if ($what != 'dataonly' && !isset($maintain_relations)) {
            if ($cfgRelation['commwork']) {
                // Get all comments and MIME-Types for current table
                $comments_copy_query = 'SELECT
                                            column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                        FROM ' . PMA_backquote($cfgRelation['column_info']) . '
                                        WHERE
                                            db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                            table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                // Write every comment as new copied entry. [MIME]
                while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                    $new_comment_query = 'REPLACE INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                    $new_comment_rs = PMA_query_as_cu($new_comment_query);
                }
                // end while
            }
            if ($source_db != $target_db) {
                $get_fields = array('user', 'label', 'query');
                $where_fields = array('dbase' => $source_db);
                $new_fields = array('dbase' => $target_db);
                PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
            }
            $get_fields = array('display_field');
            $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
            $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
            PMA_duplicate_table_info('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
            $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field');
            $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
            $new_fields = array('master_db' => $target_db, 'master_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field');
            $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
            $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always
            // get screwed up independently from duplication because the numbers do not
            // seem to be stored on a per-database basis. Would the author of pdf support
            // please have a look at it?
            /*
            $get_fields = array('page_descr');
            $where_fields = array('db_name' => $source_db);
            $new_fields = array('db_name' => $target_db);
            $last_id = PMA_duplicate_table_info('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
            
            if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_duplicate_table_info('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
            }
            */
        }
    }
}
function PMA_relationsCleanupDatabase($db)
{
    global $cfgRelation;
    if ($cfgRelation['commwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
    if ($cfgRelation['bookmarkwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['bookmark']) . ' WHERE dbase  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
    if ($cfgRelation['displaywork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
    if ($cfgRelation['pdfwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
    if ($cfgRelation['relwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
        $remove_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\'';
        $rmv_rs = PMA_query_as_cu($remove_query);
        unset($remove_query);
    }
}
Example #16
0
/**
 * Set a SQL history entry
 *
 * @param   string   the name of the db
 * @param   string   the name of the table
 * @param   string   the username
 * @param   string   the sql query
 *
 * @global  array    the list of relations settings
 * @global  array    global phpMyAdmin configuration
 *
 * @return  boolean  true
 *
 * @access  public
 */
function PMA_purgeHistory($username)
{
    global $cfgRelation, $cfg;
    $purge_query = '
         SELECT timevalue
           FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . '
          WHERE username = \'' . PMA_sqlAddSlashes($username) . '\'
       ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1';
    $purge_rs = PMA_query_as_cu($purge_query);
    $i = 0;
    $row = PMA_DBI_fetch_row($purge_rs);
    PMA_DBI_free_result($purge_rs);
    if (is_array($row) && isset($row[0]) && $row[0] > 0) {
        $maxtime = $row[0];
        // quotes added around $maxtime to prevent a difficult to
        // reproduce problem
        $remove_rs = PMA_query_as_cu('
             DELETE FROM 
                    ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['history']) . '
              WHERE timevalue <= \'' . $maxtime . '\'');
    }
    return true;
}
if (! $cfgRelation['designerwork']) {
    PMD_err_sav();
}

foreach ($t_x as $key => $value) {
    $KEY = empty($IS_AJAX) ? urldecode($key) : $key; // table name decode (post PDF exp/imp)
    list($DB,$TAB) = explode(".", $KEY);
    PMA_query_as_cu('DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                      WHERE `db_name` = \'' . PMA_sqlAddslashes($DB) . '\'
                        AND `table_name` = \'' . PMA_sqlAddslashes($TAB) . '\'', true, PMA_DBI_QUERY_STORE);

    PMA_query_as_cu('INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                         (db_name, table_name, x, y, v, h)
                  VALUES ('
                  . '\'' . PMA_sqlAddslashes($DB) . '\', '
                  . '\'' . PMA_sqlAddslashes($TAB) . '\', '
                  . '\'' . PMA_sqlAddslashes($t_x[$key]) . '\', '
                  . '\'' . PMA_sqlAddslashes($t_y[$key]) . '\', '
                  . '\'' . PMA_sqlAddslashes($t_v[$key]) . '\', '
                  . '\'' . PMA_sqlAddslashes($t_h[$key]) . '\''
                  . ')', true, PMA_DBI_QUERY_STORE);
}
//----------------------------------------------------------------------------

function PMD_err_sav() {
    global $die_save_pos; // if this file included
    if (! empty($die_save_pos)) {
        header("Content-Type: text/xml; charset=utf-8");
        header("Cache-Control: no-cache");
        die('<root act="save_pos" return="strErrorSaveTable"></root>');
    }
}
/**
 * Cleanup database related relation stuff
 *
 * @uses PMA_getRelationsParam()
 * @uses PMA_backquote()
 * @uses PMA_sqlAddslashes()
 * @uses PMA_query_as_cu()
 * @param string $db
 */
function PMA_relationsCleanupDatabase($db)
{
    $cfgRelation = PMA_getRelationsParam();

    if ($cfgRelation['commwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
    }

    if ($cfgRelation['bookmarkwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['bookmark'])
                    . ' WHERE dbase  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
    }

    if ($cfgRelation['displaywork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
    }

    if ($cfgRelation['pdfwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);

        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
    }

    if ($cfgRelation['designerwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['designer_coords'])
                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
     }

    if ($cfgRelation['relwork']) {
        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
                    . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);

        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
                    . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\'';
        PMA_query_as_cu($remove_query);
    }
}
Example #19
0
    <?php 
    // Now if we already have chosen a page number then we should show the
    // tables involved
    if (isset($chpage) && $chpage > 0) {
        echo "\n";
        ?>
<hr />

<h2><?php 
        echo $strSelectTables;
        ?>
</h2>

<?php 
        $page_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $chpage;
        $page_rs = PMA_query_as_cu($page_query);
        $array_sh_page = array();
        $draginit = '';
        $reset_draginit = '';
        $i = 0;
        while ($temp_sh_page = @PMA_mysql_fetch_array($page_rs)) {
            $array_sh_page[] = $temp_sh_page;
        }
        // garvin: Display WYSIWYG-PDF parts?
        if ($cfg['WYSIWYG-PDF']) {
            ?>
<script type="text/javascript" src="./libraries/dom-drag.js"></script>
<form method="post" action="pdf_pages.php" name="dragdrop">
<input type="button" name="dragdrop" value="<?php 
            echo $strToggleScratchboard;
            ?>
Example #20
0
    <option value="3" selected>1:3 (<?php 
echo $strRecommended;
?>
)</option>
        <option value="4">1:4</option>
        <option value="5">1:5</option>
        </select>
      </p>
  <p><?php 
echo $strToFromPage;
?>
:

      <select name="pdf_page_number">
      <?php 
$table_info_result = PMA_query_as_cu('SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
                                              WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'');
while ($page = PMA_DBI_fetch_assoc($table_info_result)) {
    ?>
      <option value="<?php 
    echo $page['page_nr'];
    ?>
"><?php 
    echo htmlspecialchars($page['page_descr']);
    ?>
</option>
      <?php 
}
?>
      </select>
      <br>
      <br>
/**
 * Set a single mimetype to a certain value.
 *
 * @uses    PMA_DBI_QUERY_STORE
 * @uses    PMA_getRelationsParam()
 * @uses    PMA_backquote()
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_query_as_cu()
 * @uses    PMA_DBI_num_rows()
 * @uses    PMA_DBI_fetch_assoc()
 * @uses    PMA_DBI_free_result()
 * @uses    strlen()
 * @access  public
 * @param   string   $db        the name of the db
 * @param   string   $table     the name of the table
 * @param   string   $key       the name of the column
 * @param   string   $mimetype  the mimetype of the column
 * @param   string   $transformation    the transformation of the column
 * @param   string   $transformation_options    the transformation options of the column
 * @param   string   $forcedelete   force delete, will erase any existing comments for this column
 * @return  boolean  true, if comment-query was made.
 */
function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false)
{
    $cfgRelation = PMA_getRelationsParam();
    if (!$cfgRelation['commwork']) {
        return false;
    }
    $test_qry = '
         SELECT `mimetype`,
                `comment`
           FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
          WHERE `db_name`     = \'' . PMA_sqlAddslashes($db) . '\'
            AND `table_name`  = \'' . PMA_sqlAddslashes($table) . '\'
            AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
    $test_rs = PMA_query_as_cu($test_qry, true, PMA_DBI_QUERY_STORE);
    if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
        $row = PMA_DBI_fetch_assoc($test_rs);
        PMA_DBI_free_result($test_rs);
        if (!$forcedelete && (strlen($mimetype) || strlen($transformation) || strlen($transformation_options) || strlen($row['comment']))) {
            $upd_query = '
                UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
                   SET `mimetype`               = \'' . PMA_sqlAddslashes($mimetype) . '\',
                       `transformation`         = \'' . PMA_sqlAddslashes($transformation) . '\',
                       `transformation_options` = \'' . PMA_sqlAddslashes($transformation_options) . '\'';
        } else {
            $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
        }
        $upd_query .= '
            WHERE `db_name`     = \'' . PMA_sqlAddslashes($db) . '\'
              AND `table_name`  = \'' . PMA_sqlAddslashes($table) . '\'
              AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
    } elseif (strlen($mimetype) || strlen($transformation) || strlen($transformation_options)) {
        $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($mimetype) . '\',' . '\'' . PMA_sqlAddslashes($transformation) . '\',' . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
    }
    if (isset($upd_query)) {
        return PMA_query_as_cu($upd_query);
    } else {
        return false;
    }
}
 /**
  * The "PMA_RT" constructor
  *
  * @param mixed $ The scaling factor
  * @param integer $ The page number to draw (from the
  *                    $cfg['Servers'][$i]['table_coords'] table)
  * @param boolean $ Whether to display table position or not
  * @param boolean $ Was originally whether to use one color per
  *                    relation or not, now enables/disables color
  *                    everywhere, due to some problems printing with color
  * @param boolean $ Whether to draw grids or not
  * @param boolean $ Whether all tables should have the same width or not
  * @param boolean $ Wheter to show all field or only the keys
  * @global object   The current PDF document
  * @global string   The current db name
  * @global array    The relations settings
  * @access private
  * @see PMA_PDF
  */
 function __construct($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4', $show_keys = 0)
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->SetTitle(sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel));
     $pdf->setCMargin(0);
     $pdf->Open();
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     $pdf->AddFont('DejaVuSans', '', 'dejavusans.php');
     $pdf->AddFont('DejaVuSans', 'B', 'dejavusansb.php');
     $pdf->AddFont('DejaVuSerif', '', 'dejavuserif.php');
     $pdf->AddFont('DejaVuSerif', 'B', 'dejavuserifb.php');
     $this->ff = PMA_PDF_FONT;
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE);
     if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         // die('No tables');
     }
     while ($curr_table = PMA_DBI_fetch_assoc($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         // $intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     // make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->setCMargin(1);
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->setCMargin(0);
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth, $show_keys);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->getFh() - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->getFw() - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     // $sql    = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
     // .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     // .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     // .   ' AND master_table  IN (' . $intable . ')'
     // .   ' AND foreign_table IN (' . $intable . ')';
     // $result =  PMA_query_as_cu($sql);
     // lem9:
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = true;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === FALSE and this is not PHP3 compatible)
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     // $norelations     = TRUE;
     // if ($result && PMA_DBI_num_rows($result) > 0) {
     // $norelations = FALSE;
     // while ($row = PMA_DBI_fetch_assoc($result)) {
     // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     // }
     // }
     // if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
Example #23
0
    }
    // end if
}
// end if (!$is_information_schema)
// not sure about displaying the PDF dialog in case db is information_schema
if ($cfgRelation['pdfwork'] && $num_tables > 0) {
    ?>
    <!-- Work on PDF Pages -->

    <?php 
    // We only show this if we find something in the new pdf_pages table
    $test_query = '
         SELECT *
           FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
          WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
    $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE);
    if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
        ?>
    <!-- PDF schema -->
    <form method="post" action="pdf_schema.php">
    <fieldset>
        <legend>
        <?php 
        echo PMA_generate_common_hidden_inputs($db);
        if ($cfg['PropertiesIconic']) {
            echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"' . ' alt="" width="16" height="16" />';
        }
        echo $strDisplayPDF;
        ?>
:
        </legend>
Example #24
0
 if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
     foreach ($field_orig as $fieldindex => $fieldcontent) {
         if ($field_name[$fieldindex] != $fieldcontent) {
             if ($cfgRelation['displaywork']) {
                 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) . ' SET     display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
                 $tb_rs = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             if ($cfgRelation['relwork']) {
                 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
                 $tb_rs = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
                 $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
                 $tb_rs = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             // end if relwork
         }
         // end if fieldname has changed
     }
     // end while check fieldnames
 }
 // end if relations/display has to be changed
 // garvin: Update comment table for mime types [MIME]
 if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
     foreach ($field_mimetype as $fieldindex => $mimetype) {
         PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
     }
Example #25
0
        <td colspan="3">
        <?php 
    echo '<a href="pdf_pages.php?' . $takeaway . '">';
    if ($cfg['PropertiesIconic']) {
        echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
    }
    echo '' . $strEditPDFPages . '</a>';
    ?>
        </td>
    </tr>

    <!-- PDF schema -->
    <?php 
    // We only show this if we find something in the new pdf_pages table
    $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
    $test_rs = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE);
    if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
        ?>
    <tr bgcolor="<?php 
        echo $cfg['BgcolorTwo'];
        ?>
">
        <td colspan="3">
        <?php 
        echo PMA_generate_common_hidden_inputs($db);
        if ($cfg['PropertiesIconic']) {
            echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />';
        }
        echo $strDisplayPDF;
        ?>
:&nbsp;
 /**
  * Imports docSQL files
  *
  * @param   string   the basepath
  * @param   string   the filename
  * @param   string   the complete filename
  * @param   string   the content of a file
  *
  * @return  boolean  always true
  *
  * @global  array    GLOBAL variables
  */
 function docsql_check($docpath = '', $file = '', $filename = '', $content = 'none')
 {
     global $GLOBALS;
     if (preg_match('@^(.*)_field_comment\\.(txt|zip|bz2|bzip).*$@i', $filename)) {
         $tab = preg_replace('@^(.*)_field_comment\\.(txt|zip|bz2|bzip).*@si', '\\1', $filename);
         //echo '<h1>Working on Table ' . $_tab . '</h1>';
         if ($content == 'none') {
             $lines = array();
             $fd = fopen($docpath . $file, 'r');
             if ($fd) {
                 while (!feof($fd)) {
                     $lines[] = fgets($fd, 4096);
                 }
             }
         } else {
             $content = str_replace("\r\n", "\n", $content);
             $content = str_replace("\r", "\n", $content);
             $lines = explode("\n", $content);
         }
         if (isset($lines) && is_array($lines) && count($lines) > 0) {
             foreach ($lines as $lkey => $line) {
                 //echo '<p>' . $line . '</p>';
                 $inf = explode('|', $line);
                 if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
                     $qry = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',' . '\'' . PMA_sqlAddslashes(trim($tab)) . '\',' . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\',' . '\'' . PMA_sqlAddslashes(trim($inf[1])) . '\')';
                     if (PMA_query_as_cu($qry)) {
                         echo '<p>' . $GLOBALS['strAddedColumnComment'] . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '</p>';
                     } else {
                         echo '<p>' . $GLOBALS['strWritingCommentNotPossible'] . '</p>';
                     }
                     echo "\n";
                 }
                 // end inf[1] exists
                 if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
                     $for = explode('->', $inf[2]);
                     $qry = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)' . ' VALUES(' . '\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\', ' . '\'' . PMA_sqlAddslashes(trim($tab)) . '\', ' . '\'' . PMA_sqlAddslashes(trim($inf[0])) . '\', ' . '\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\', ' . '\'' . PMA_sqlAddslashes(trim($for[0])) . '\',' . '\'' . PMA_sqlAddslashes(trim($for[1])) . '\')';
                     if (PMA_query_as_cu($qry)) {
                         echo '<p>' . $GLOBALS['strAddedColumnRelation'] . ' ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . ' to ' . htmlspecialchars($inf[2]) . '</p>';
                     } else {
                         echo '<p>' . $GLOBALS['strWritingRelationNotPossible'] . '</p>';
                     }
                     echo "\n";
                 }
                 // end inf[2] exists
             }
             echo '<p><font color="green">' . $GLOBALS['strImportFinished'] . '</font></p>' . "\n";
         } else {
             echo '<p><font color="red">' . $GLOBALS['strFileCouldNotBeRead'] . '</font></p>' . "\n";
         }
         return 1;
     } else {
         if ($content != 'none') {
             echo '<p><font color="orange">' . sprintf($GLOBALS['strIgnoringFile'], ' ' . htmlspecialchars($file)) . '</font></p>' . "\n";
         } else {
             // garvin: disabled. Shouldn't impose ANY non-submitted files ever.
             echo '<p><font color="orange">' . sprintf($GLOBALS['strIgnoringFile'], ' ' . '...') . '</font></p>' . "\n";
         }
         return 0;
     }
     // end working on table
 }
Example #27
0
    <?php 
    // Now if we already have chosen a page number then we should show the
    // tables involved
    if (isset($chpage) && $chpage > 0) {
        echo "\n";
        ?>
<hr />

<h2><?php 
        echo $strSelectTables;
        ?>
</h2>

<?php 
        $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $chpage;
        $page_rs = PMA_query_as_cu($page_query, FALSE, $query_default_option);
        $array_sh_page = array();
        $draginit = '';
        $reset_draginit = '';
        $i = 0;
        while ($temp_sh_page = @PMA_DBI_fetch_assoc($page_rs)) {
            $array_sh_page[] = $temp_sh_page;
        }
        // garvin: Display WYSIWYG-PDF parts?
        if ($cfg['WYSIWYG-PDF']) {
            if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
                $with_field_names = TRUE;
            }
            ?>
<script type="text/javascript" language="javascript" src="./js/dom-drag.js"></script>
<form method="post" action="pdf_pages.php" name="dragdrop">
    <!-- Work on PDF Pages -->
    <li>
        <div style="margin-bottom: 10px"><a href="pdf_pages.php?<?php 
    echo $takeaway;
    ?>
"><?php 
    echo $strEditPDFPages;
    ?>
</a></div>
    </li>

    <!-- PDF schema -->
    <?php 
    // We only show this if we find something in the new pdf_pages table
    $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
    $test_rs = PMA_query_as_cu($test_query);
    if ($test_rs && mysql_num_rows($test_rs) > 0) {
        echo "\n";
        ?>
    <li>
        <form method="post" action="pdf_schema.php">
            <?php 
        echo PMA_generate_common_hidden_inputs($db);
        ?>
            <?php 
        echo $strDisplayPDF;
        ?>
&nbsp;:<br />
            <?php 
        echo $strPageNumber;
        ?>