Skip to content

Commit

Permalink
Coding style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuracj committed May 9, 2012
1 parent 6c6f9b4 commit 292f83e
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 96 deletions.
4 changes: 3 additions & 1 deletion libraries/tbl_common.inc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Common includes for the table level views
*
* @package PhpMyAdmin
*/
Expand Down Expand Up @@ -34,7 +35,8 @@
/**
* Defines the urls to return to in case of error in a sql statement
*/
$err_url_0 = $cfg['DefaultTabDatabase'] . PMA_generate_common_url(array('db' => $db,));
$err_url_0 = $cfg['DefaultTabDatabase']
. PMA_generate_common_url(array('db' => $db,));
$err_url = $cfg['DefaultTabTable'] . PMA_generate_common_url($url_params);


Expand Down
11 changes: 9 additions & 2 deletions libraries/tbl_info.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
// we force reading of the current table status
// if $reread_info is true (for example, coming from tbl_operations.php
// and we just changed the table's storage engine)
$GLOBALS['showtable'] = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, (isset($reread_info) && $reread_info ? true : false));
$GLOBALS['showtable'] = PMA_Table::sGetStatusInfo(
$GLOBALS['db'],
$GLOBALS['table'],
null,
(isset($reread_info) && $reread_info ? true : false)
);

// need this test because when we are creating a table, we get 0 rows
// from the SHOW TABLE query
Expand Down Expand Up @@ -98,7 +103,9 @@
}
}
// we need explicit DEFAULT value here (different from '0')
$pack_keys = (! isset($pack_keys) || strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys;
$pack_keys = (! isset($pack_keys) || strlen($pack_keys) == 0)
? 'DEFAULT'
: $pack_keys;
unset($create_options, $each_create_option);
} // end if
?>
142 changes: 87 additions & 55 deletions libraries/tbl_properties.inc.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Display form for changing/adding table fields/columns
* Display form for changing/adding table fields/columns.
* Included by tbl_addfield.php, -_alter.php, -_create.php
*
* included by tbl_addfield.php, -_alter.php, -_create.php
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
Expand Down Expand Up @@ -83,8 +83,9 @@

$header_cells[] = __('Name');
$header_cells[] = __('Type')
. PMA_showMySQLDocu('SQL-Syntax', 'data-types');
$header_cells[] = __('Length/Values') . PMA_showHint(__('If column type is "enum" or "set", please enter the values using this format: \'a\',\'b\',\'c\'...<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'));
. PMA_showMySQLDocu('SQL-Syntax', 'data-types');
$header_cells[] = __('Length/Values')
. PMA_showHint(__('If column type is "enum" or "set", please enter the values using this format: \'a\',\'b\',\'c\'...<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'));
$header_cells[] = __('Default') . PMA_showHint(__('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'));
$header_cells[] = __('Collation');
$header_cells[] = __('Attributes');
Expand Down Expand Up @@ -153,26 +154,46 @@
// An error happened with previous inputs, so we will restore the data
// to embed it once again in this form.

$row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
$row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
$row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
$row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');

if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
$row['Field'] = isset($_REQUEST['field_name'][$i])
? $_REQUEST['field_name'][$i]
: false;
$row['Type'] = isset($_REQUEST['field_type'][$i])
? $_REQUEST['field_type'][$i]
: false;
$row['Collation'] = isset($_REQUEST['field_collation'][$i])
? $_REQUEST['field_collation'][$i]
: '';
$row['Null'] = isset($_REQUEST['field_null'][$i])
? $_REQUEST['field_null'][$i]
: '';

if (isset($_REQUEST['field_key'][$i])
&& $_REQUEST['field_key'][$i] == 'primary_' . $i
) {
$row['Key'] = 'PRI';
} elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
} elseif (isset($_REQUEST['field_key'][$i])
&& $_REQUEST['field_key'][$i] == 'index_' . $i
) {
$row['Key'] = 'MUL';
} elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
} elseif (isset($_REQUEST['field_key'][$i])
&& $_REQUEST['field_key'][$i] == 'unique_' . $i
) {
$row['Key'] = 'UNI';
} elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
} elseif (isset($_REQUEST['field_key'][$i])
&& $_REQUEST['field_key'][$i] == 'fulltext_' . $i
) {
$row['Key'] = 'FULLTEXT';
} else {
$row['Key'] = '';
}

// put None in the drop-down for Default, when someone adds a field
$row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'NONE');
$row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
$row['DefaultType'] = isset($_REQUEST['field_default_type'][$i])
? $_REQUEST['field_default_type'][$i]
: 'NONE';
$row['DefaultValue'] = isset($_REQUEST['field_default_value'][$i])
? $_REQUEST['field_default_value'][$i]
: '';

switch ($row['DefaultType']) {
case 'NONE' :
Expand Down Expand Up @@ -221,12 +242,12 @@

if (isset($_REQUEST['field_transformation'][$i])) {
$mime_map[$row['Field']]['transformation']
= $_REQUEST['field_transformation'][$i];
= $_REQUEST['field_transformation'][$i];
}

if (isset($_REQUEST['field_transformation_options'][$i])) {
$mime_map[$row['Field']]['transformation_options']
= $_REQUEST['field_transformation_options'][$i];
= $_REQUEST['field_transformation_options'][$i];
}

} elseif (isset($fields_meta[$i])) {
Expand Down Expand Up @@ -340,7 +361,8 @@
. '"' . ' type="text" name="field_length[' . $i . ']" size="'
. $length_values_input_size . '"' . ' value="' . htmlspecialchars(
$length_to_display
) . '"'
)
. '"'
. ' class="textfield" />'
. '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset)
. '">';
Expand Down Expand Up @@ -370,8 +392,8 @@

// for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
if ($type_upper == 'TIMESTAMP'
&& ! empty($default_current_timestamp)
&& isset($row['Default'])
&& ! empty($default_current_timestamp)
&& isset($row['Default'])
) {
$row['Default'] = '';
}
Expand Down Expand Up @@ -433,27 +455,23 @@
if (PMA_MYSQL_INT_VERSION < 50025
&& isset($row['Field'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
&& $analyzed_sql[0]['create_table_fields'][$row['Field']]['type']
== 'TIMESTAMP'
&& $analyzed_sql[0]['create_table_fields'][$row['Field']]
['timestamp_not_null'] == true
&& $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
&& $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true
) {
$row['Null'] = '';
}

// MySQL 4.1.2+ TIMESTAMP options
// (if on_update_current_timestamp is set, then it's TRUE)
if (isset($row['Field'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]
['on_update_current_timestamp'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])
) {
$attribute = 'on update CURRENT_TIMESTAMP';
}
if ((isset($row['Field'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]
['default_current_timestamp']))
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
|| (isset($submit_default_current_timestamp)
&& $submit_default_current_timestamp)
&& $submit_default_current_timestamp)
) {
$default_current_timestamp = true;
} else {
Expand All @@ -480,7 +498,8 @@

if (! empty($row['Null'])
&& $row['Null'] != 'NO'
&& $row['Null'] != 'NOT NULL') {
&& $row['Null'] != 'NOT NULL'
) {
$content_cells[$i][$ci] .= ' checked="checked"';
}

Expand Down Expand Up @@ -575,10 +594,12 @@
. (($current_index == $mi || $current_index == $mi + 1)
? ' disabled="disabled"'
: '')
.'>' . sprintf(
.'>'
. sprintf(
__('after %s'),
PMA_backquote($move_columns[$mi]->name)
) . '</option>';
)
. '</option>';
}

$content_cells[$i][$ci] .= '</select>';
Expand All @@ -588,7 +609,8 @@
// column MIME-types
if ($cfgRelation['mimework']
&& $cfg['BrowseMIME']
&& $cfgRelation['commwork']) {
&& $cfgRelation['commwork']
) {
$content_cells[$i][$ci] = '<select id="field_' . $i . '_'
. ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
$content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
Expand Down Expand Up @@ -617,16 +639,21 @@
. '"></option>';
if (is_array($available_mime['transformation'])) {
foreach ($available_mime['transformation'] as $mimekey => $transform) {
$checked = (isset($row['Field'])
&& isset($mime_map[$row['Field']]['transformation'])
&& (preg_match('@' . preg_quote(
$match = preg_match(
'@' . preg_quote(
$available_mime['transformation_file'][$mimekey]
) . '3?@i', $mime_map[$row['Field']]['transformation']))
)
. '3?@i',
$mime_map[$row['Field']]['transformation']
);
$checked = isset($row['Field'])
&& isset($mime_map[$row['Field']]['transformation'])
&& $match
? 'selected '
: '');
: '';
$tooltip = PMA_getTransformationDescription(
$available_mime['transformation_file'][$mimekey], false
);
);
$content_cells[$i][$ci] .= '<option value="'
. $available_mime['transformation_file'][$mimekey] . '" '
. $checked . ' title="' . htmlspecialchars($tooltip) . '">'
Expand All @@ -637,15 +664,15 @@
$content_cells[$i][$ci] .= '</select>';
$ci++;

$val = isset($row['Field'])
&& isset($mime_map[$row['Field']]['transformation_options'])
? htmlspecialchars($mime_map[$row['Field']]['transformation_options'])
: '';
$content_cells[$i][$ci] = '<input id="field_' . $i . '_'
. ($ci - $ci_offset) . '"' . ' type="text" '
. 'name="field_transformation_options[' . $i . ']"'
. ' size="16" class="textfield"'
. ' value="' . (isset($row['Field'])
&& isset($mime_map[$row['Field']]['transformation_options'])
? htmlspecialchars($mime_map[$row['Field']]
['transformation_options'])
: '') . '"'
. ' value="' . $val . '"'
. ' />';
//$ci++;
}
Expand Down Expand Up @@ -686,19 +713,24 @@ class="textfield" autofocus />
<td>
<?php
if ($action == 'tbl_create.php'
|| $action == 'tbl_addfield.php') { ?>
<?php echo sprintf(
__('Add %s column(s)'), '<input type="text" id="added_fields" '
. 'name="added_fields" size="2" value="1" onfocus="this.select'
. '()" />'); ?>
<input type="submit" name="submit_num_fields" value="<?php
echo __('Go'); ?>"
|| $action == 'tbl_addfield.php'
) {
echo sprintf(
__('Add %s column(s)'), '<input type="text" id="added_fields" '
. 'name="added_fields" size="2" value="1" onfocus="this.select'
. '()" />'
); ?>
<input type="submit" name="submit_num_fields"
value="<?php echo __('Go'); ?>"
onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php
echo str_replace('\'', '\\\'', __(
'You have to add at least one column.'
)); ?>', 1)"
echo str_replace(
'\'', '\\\'', __('You have to add at least one column.')
);
?>', 1)"
/>
<?php } ?>
<?php
}
?>
</td>
</tr>
</table>
Expand Down
9 changes: 7 additions & 2 deletions libraries/tbl_replace_fields.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
} elseif ($type == 'bit') {
$val = preg_replace('/[^01]/', '0', $val);
$val = "b'" . PMA_sqlAddSlashes($val) . "'";
} elseif (! (($type == 'datetime' || $type == 'timestamp') && $val == 'CURRENT_TIMESTAMP')) {
} elseif (! ($type == 'datetime' || $type == 'timestamp')
|| $val != 'CURRENT_TIMESTAMP'
) {
$val = "'" . PMA_sqlAddSlashes($val) . "'";
}

Expand All @@ -92,7 +94,10 @@
}

// The Null checkbox was unchecked for this field
if (empty($val) && ! empty($me_fields_null_prev[$key]) && ! isset($me_fields_null[$key])) {
if (empty($val)
&& ! empty($me_fields_null_prev[$key])
&& ! isset($me_fields_null[$key])
) {
$val = "''";
}
} // end else (field value in the form)
Expand Down
Loading

0 comments on commit 292f83e

Please sign in to comment.