diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3
index 9f809db6f..c3f231fea 100644
--- a/libraries/display_tbl.lib.php3
+++ b/libraries/display_tbl.lib.php3
@@ -518,6 +518,15 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
// 2. Displays the fields' name
// 2.0 If sorting links should be used, checks if the query is a "JOIN"
// statement (see 2.1.3)
+
+ // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
+ // Do not show comments, if using horizontalflipped mode, because of space usage
+ if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
+ $comments_map = PMA_getComments($db, $table);
+ } else {
+ $comments_map = array();
+ }
+
if ($is_display['sort_lnk'] == '1') {
$is_join = eregi('(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN', $sql_query, $select_stt);
} else {
@@ -525,6 +534,15 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
}
for ($i = 0; $i < $fields_cnt; $i++) {
+ // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
+ if (isset($comments_map[$fields_meta[$i]->name])) {
+ $comments_table_wrap_pre = '
';
+ } else {
+ $comments_table_wrap_pre = '';
+ $comments_table_wrap_post = '';
+ }
+
// 2.1 Results can be sorted
if ($is_display['sort_lnk'] == '1') {
// Defines the url used to append/modify a sorting order
@@ -550,6 +568,7 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
} else {
$unsorted_sql_query = $sql_query;
}
+
// 2.1.2 Checks if the current column is used to sort the
// results
if (empty($sql_order)) {
@@ -622,14 +641,18 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
echo "\n";
?>
' . "\n"
+ . $comments_table_wrap_pre
. ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
+ . $comments_table_wrap_post
. ' ';
} // end else (2.2)
} // end for
diff --git a/libraries/relation.lib.php3 b/libraries/relation.lib.php3
index 5441d84cf..b6570f8da 100644
--- a/libraries/relation.lib.php3
+++ b/libraries/relation.lib.php3
@@ -298,10 +298,10 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
global $cfgRelation;
if ($table != '') {
- $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments'])
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
- $com_rs = PMA_query_as_cu($com_qry);
+ $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
+ $com_rs = PMA_query_as_cu($com_qry);
} else {
$com_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
diff --git a/scripts/create_tables.sql b/scripts/create_tables.sql
index b997fabc3..93705f285 100644
--- a/scripts/create_tables.sql
+++ b/scripts/create_tables.sql
@@ -69,7 +69,7 @@ CREATE TABLE `PMA_column_comments` (
db_name varchar(64) NOT NULL default '',
table_name varchar(64) NOT NULL default '',
column_name varchar(64) NOT NULL default '',
- comment varchar(255) NOT NULL default '',
+ `comment` varchar(255) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY db_name (db_name, table_name, column_name)
) TYPE=MyISAM COMMENT='Comments for Columns';
diff --git a/sql.php3 b/sql.php3
index c8c3cde49..b46f3ff38 100755
--- a/sql.php3
+++ b/sql.php3
@@ -437,6 +437,27 @@ else {
} else { // not $is_select
$unlim_num_rows = 0;
} // end rows total count
+
+ // garvin: if a table or database gets dropped, check column comments.
+ if (isset($purge)) {
+ include('./libraries/relation.lib.php3');
+ $cfgRelation = PMA_getRelationsParam();
+
+ if ($cfgRelation['commwork']) {
+ if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
+ $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
+ $rmv_rs = PMA_query_as_cu($remove_query);
+ unset($rmv_query);
+ } elseif (isset($db) && !empty($db)) {
+ $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
+ $rmv_rs = PMA_query_as_cu($remove_query);
+ unset($rmv_query);
+ }
+ } // end if relation-stuff
+ } // end if ($purge)
} // end else "didn't ask to see php code"
diff --git a/tbl_addfield.php3 b/tbl_addfield.php3
index 5182937ba..e52ccb650 100755
--- a/tbl_addfield.php3
+++ b/tbl_addfield.php3
@@ -192,6 +192,19 @@ if (isset($submit)) {
}
} // end if
+ // garvin: If comments were sent, enable relation stuff
+ require('./libraries/relation.lib.php3');
+
+ $cfgRelation = PMA_getRelationsParam();
+
+ // garvin: Update comment table, if a comment was set.
+ if (is_array($field_comments) && $cfgRelation['commwork']) {
+ @reset($field_comments);
+ while(list($fieldindex, $fieldcomment) = each($field_comments)) {
+ PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
+ }
+ }
+
// Go back to the structure sub-page
$sql_query = $sql_query_cpy;
unset($sql_query_cpy);
diff --git a/tbl_alter.php3 b/tbl_alter.php3
index 6d04b9005..8ba31fade 100755
--- a/tbl_alter.php3
+++ b/tbl_alter.php3
@@ -87,6 +87,20 @@ if (isset($submit)) {
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
$btnDrop = 'Fake';
+
+ // garvin: If comments were sent, enable relation stuff
+ require('./libraries/relation.lib.php3');
+
+ $cfgRelation = PMA_getRelationsParam();
+
+ // garvin: Update comment table, if a comment was set.
+ if (is_array($field_comments) && $cfgRelation['commwork']) {
+ @reset($field_comments);
+ while(list($fieldindex, $fieldcomment) = each($field_comments)) {
+ PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex]);
+ }
+ }
+
include('./tbl_properties_structure.php3');
exit();
}
diff --git a/tbl_create.php3 b/tbl_create.php3
index 90c5ca639..9d15bc506 100755
--- a/tbl_create.php3
+++ b/tbl_create.php3
@@ -192,6 +192,20 @@ if (isset($submit)) {
$sql_query = $query_cpy . ';';
unset($query_cpy);
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
+
+ // garvin: If comments were sent, enable relation stuff
+ require('./libraries/relation.lib.php3');
+
+ $cfgRelation = PMA_getRelationsParam();
+
+ // garvin: Update comment table, if a comment was set.
+ if (is_array($field_comments) && $cfgRelation['commwork']) {
+ @reset($field_comments);
+ while(list($fieldindex, $fieldcomment) = each($field_comments)) {
+ PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
+ }
+ }
+
include('./' . $cfg['DefaultTabTable']);
exit();
} // end do create table
diff --git a/tbl_move_copy.php3 b/tbl_move_copy.php3
index b9f1ee092..7a3bb2756 100644
--- a/tbl_move_copy.php3
+++ b/tbl_move_copy.php3
@@ -113,6 +113,9 @@ if (isset($new_name) && trim($new_name) != '') {
$sql_query .= "\n\n" . $sql_insert_data;
}
+ include('./libraries/relation.lib.php3');
+ $cfgRelation = PMA_getRelationsParam();
+
// Drops old table if the user has requested to move it
if (isset($submit_move)) {
$sql_drop_table = 'DROP TABLE ' . $source;
@@ -121,9 +124,44 @@ if (isset($new_name) && trim($new_name) != '') {
include('./header.inc.php3');
PMA_mysqlDie('', $sql_drop_table, '', $err_url);
}
+
+ // garvin: Move old entries from comments to new table
+ if ($cfgRelation['commwork']) {
+ $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\', '
+ . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
+ $rmv_rs = PMA_query_as_cu($remove_query);
+ unset($rmv_query);
+ }
+
$sql_query .= "\n\n" . $sql_drop_table . ';';
$db = $target_db;
$table = $new_name;
+ } else {
+ // garvin: Create new entries as duplicates from old comments
+ if ($cfgRelation['commwork']) {
+ // Get all comments and MIME-Types for current table
+ $comments_copy_query = 'SELECT
+ column_name, ' . PMA_backquote('comment') . '
+ FROM ' . PMA_backquote($cfgRelation['column_comments']) . '
+ WHERE
+ db_name = \'' . PMA_sqlAddslashes($db) . '\' AND
+ table_name = \'' . PMA_sqlAddslashes($table) . '\'';
+ $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
+
+ // Write every comment as new copied entry. [MIME]
+ while ($comments_copy_row = @PMA_mysql_fetch_array($comments_copy_rs)) {
+ $new_comment_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') '
+ . ' VALUES('
+ . '\'' . PMA_sqlAddslashes($target_db) . '\','
+ . '\'' . PMA_sqlAddslashes($new_name) . '\','
+ . '\'' . PMA_handleSlashes($comments_copy_row['comment']) . '\')';
+ $new_comment_rs = PMA_query_as_cu($new_comment_query);
+ } // end while
+ }
}
$message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK);
diff --git a/tbl_properties.inc.php3 b/tbl_properties.inc.php3
index 5a89fe0d4..2d7b59bc3 100755
--- a/tbl_properties.inc.php3
+++ b/tbl_properties.inc.php3
@@ -39,6 +39,17 @@ $is_backup = ($action != 'tbl_create.php3' && $action != 'tbl_addfield.php3');
**
' . $strComments . '';
+}
+
// lem9: We could remove this 'if' and let the key information be shown and
// editable. However, for this to work, tbl_alter must be modified to use the
// key fields, as tbl_addfield does.
@@ -222,6 +233,14 @@ for ($i = 0 ; $i < $num_fields; $i++) {
+
+
+
+ 0) {
// The 'back' is supposed to be set to the current sub-page. This is necessary
// when you have js deactivated, you click on Drop, then click cancel, and want
// to get back to the same sub-page.
-$arg7 = ereg_replace('tbl_properties[^.]*.php3$', 'db_details.php3', $url_query) . '&reload=1&sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table)));
+$arg7 = ereg_replace('tbl_properties[^.]*.php3$', 'db_details.php3', $url_query) . '&reload=1&purge=1&sql_query=' . urlencode('DROP TABLE ' . PMA_backquote($table) ) . '&zero_rows=' . urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table)));
$att7 = 'class="drop" onclick="return confirmLink(this, \'DROP TABLE ' . PMA_jsFormat($table) . '\')"';
diff --git a/tbl_properties_structure.php3 b/tbl_properties_structure.php3
index f62f56953..b5a914c7e 100755
--- a/tbl_properties_structure.php3
+++ b/tbl_properties_structure.php3
@@ -72,6 +72,20 @@ $fields_cnt = mysql_num_rows($fields_rs);
' . $field_name . '';
+ }
+
if (isset($pk_array[$row['Field']])) {
$field_name = '' . $field_name . '';
}
diff --git a/tbl_relation.php3 b/tbl_relation.php3
index 9a56c219d..f8bd53aab 100644
--- a/tbl_relation.php3
+++ b/tbl_relation.php3
@@ -19,20 +19,6 @@ require('./libraries/relation.lib.php3');
$cfgRelation = PMA_getRelationsParam();
-/**
- * Adds/removes slashes if required
- *
- * @param string the string to slash
- *
- * @return string the slashed string
- *
- * @access public
- */
-function PMA_handleSlashes($val) {
- return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val));
-} // end of the "PMA_handleSlashes()" function
-
-
/**
* Updates
*/
@@ -105,37 +91,8 @@ if ($cfgRelation['displaywork']
if ($cfgRelation['commwork']
&& isset($submit_comm) && $submit_comm == 'true') {
while (list($key, $value) = each($comment)) {
- $test_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments'])
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
- . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
- $test_rs = PMA_query_as_cu($test_qry);
- if ($test_rs && mysql_num_rows($test_rs) > 0) {
- if (strlen($value) > 0) {
- $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
- . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_handleSlashes($value) . '\''
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
- . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
- } else {
- $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments'])
- . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
- . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
- . ' AND column_name = \'' . PMA_handleSlashes($key) . '\'';
- }
- } else if (strlen($value) > 0) {
- $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments'])
- . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') '
- . ' VALUES('
- . '\'' . PMA_sqlAddslashes($db) . '\','
- . '\'' . PMA_sqlAddslashes($table) . '\','
- . '\'' . PMA_handleSlashes($key) . '\','
- . '\'' . PMA_handleSlashes($value) . '\')';
- }
- if (isset($upd_query)){
- $upd_rs = PMA_query_as_cu($upd_query);
- unset($upd_query);
- }
+ // garvin: I exported the snippet here to a function (relation.lib.php3) , so it can be used multiple times throughout other pages where you can set comments.
+ PMA_setComment($db, $table, $key, $value);
} // end while (transferred data)
} // end if (commwork)
diff --git a/tbl_rename.php3 b/tbl_rename.php3
index 07325999b..ec23c2c9d 100755
--- a/tbl_rename.php3
+++ b/tbl_rename.php3
@@ -41,6 +41,18 @@ if (isset($new_name) && trim($new_name) != '') {
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
$message = sprintf($strRenameTableOK, $old_name, $table);
$reload = 1;
+
+ // garvin: Move old entries from comments to new table
+ include('./libraries/relation.lib.php3');
+ $cfgRelation = PMA_getRelationsParam();
+ if ($cfgRelation['commwork']) {
+ $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments'])
+ . ' SET table_name = \'' . PMA_sqlAddslashes($table) . '\''
+ . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
+ . ' AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\'';
+ $rmv_rs = PMA_query_as_cu($remove_query);
+ unset($rmv_query);
+ }
}