Skip to content

Commit

Permalink
Templating getWithSelected() and getCheckbox(), Issue phpmyadmin#12004
Browse files Browse the repository at this point in the history
Signed-off-by: Durgesh <[email protected]>
  • Loading branch information
007durgesh219 committed Feb 23, 2016
1 parent 8fa667e commit 307f706
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 225 deletions.
39 changes: 27 additions & 12 deletions libraries/DisplayResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -1746,16 +1746,26 @@ private function _getOptionsBlock()
}

$options_html .= '<div class="formelement">'
. Util::getCheckbox(
'display_binary', __('Show binary contents'),
! empty($_SESSION['tmpval']['display_binary']), false,
'display_binary_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'display_binary',
'label' => __('Show binary contents'),
'checked' => ! empty($_SESSION['tmpval']['display_binary']),
'onclick' => false,
'html_field_id' => 'display_binary_' . $this->__get('unique_id'),
)
)
. '<br />'
. Util::getCheckbox(
'display_blob', __('Show BLOB contents'),
! empty($_SESSION['tmpval']['display_blob']), false,
'display_blob_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'display_blob',
'label' => __('Show BLOB contents'),
'checked' => ! empty($_SESSION['tmpval']['display_blob']),
'onclick' => false,
'html_field_id' => 'display_blob_' . $this->__get('unique_id'),
)
)
. '</div>';

Expand All @@ -1764,10 +1774,15 @@ private function _getOptionsBlock()
// per SQL query, and at the same time have a default that displays
// the transformations.
$options_html .= '<div class="formelement">'
. Util::getCheckbox(
'hide_transformation', __('Hide browser transformation'),
! empty($_SESSION['tmpval']['hide_transformation']), false,
'hide_transformation_' . $this->__get('unique_id')
. Template::get('checkbox')
->render(
array(
'html_field_name' => 'hide_transformation',
'label' => __('Hide browser transformation'),
'checked' => ! empty($_SESSION['tmpval']['hide_transformation']),
'onclick' => false,
'html_field_id' => 'hide_transformation_' . $this->__get('unique_id'),
)
)
. '</div>';

Expand Down
64 changes: 11 additions & 53 deletions libraries/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SqlParser\Utils\Error as ParserError;
use PMA\libraries\URL;
use PMA\libraries\Sanitize;
use PMA\libraries\Template;

if (! defined('PHPMYADMIN')) {
exit;
Expand Down Expand Up @@ -1318,12 +1319,16 @@ public static function getMessage(
// be checked, which would reexecute an INSERT, for example
if (! empty($refresh_link) && self::profilingSupported()) {
$retval .= '<input type="hidden" name="profiling_form" value="1" />';
$retval .= self::getCheckbox(
'profiling',
__('Profiling'),
isset($_SESSION['profiling']),
true
);
$retval .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'profiling',
'label' => __('Profiling'),
'checked' => isset($_SESSION['profiling']),
'onclick' => true,
'html_field_id' => '',
)
);
}
$retval .= '</form>';

Expand Down Expand Up @@ -2730,28 +2735,6 @@ public static function getExternalBug(
return $ext_but_html;
}

/**
* Returns a HTML checkbox
*
* @param string $html_field_name the checkbox HTML field
* @param string $label label for checkbox
* @param boolean $checked is it initially checked?
* @param boolean $onclick should it submit the form on click?
* @param string $html_field_id id for the checkbox
*
* @return string HTML for the checkbox
*/
public static function getCheckbox(
$html_field_name, $label, $checked, $onclick, $html_field_id = ''
) {
return '<input type="checkbox" name="' . $html_field_name . '"'
. ($html_field_id ? ' id="' . $html_field_id . '"' : '')
. ($checked ? ' checked="checked"' : '')
. ($onclick ? ' class="autosubmit"' : '') . ' />'
. '<label' . ($html_field_id ? ' for="' . $html_field_id . '"' : '')
. '>' . $label . '</label>';
}

/**
* Generates a set of radio HTML fields
*
Expand Down Expand Up @@ -4590,31 +4573,6 @@ public static function processIndexData($indexes)
return array($primary, $pk_array, $indexes_info, $indexes_data);
}

/**
* Returns the HTML for check all check box and with selected text
* for multi submits
*
* @param string $pmaThemeImage path to theme's image folder
* @param string $text_dir text direction
* @param string $formName name of the enclosing form
*
* @return string HTML
*/
public static function getWithSelected($pmaThemeImage, $text_dir, $formName)
{
$html = '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
$html .= '<input type="checkbox" id="' . $formName . '_checkall" '
. 'class="checkall_box" title="' . __('Check all') . '" />'
. '<label for="' . $formName . '_checkall">' . __('Check all')
. '</label>';
$html .= '<i style="margin-left: 2em">'
. __('With selected:') . '</i>';

return $html;
}

/**
* Function to get html for the start row and number of rows panel
*
Expand Down
11 changes: 8 additions & 3 deletions libraries/central_columns.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,14 @@ function PMA_getCentralColumnsListRaw($db, $table)
*/
function PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir)
{
$html_output = Util::getWithSelected(
$pmaThemeImage, $text_dir, "tableslistcontainer"
);
$html_output = PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'tableslistcontainer',
)
);
$html_output .= Util::getButtonOrImage(
'edit_central_columns', 'mult_submit change_central_columns',
__('Edit'), 'b_edit.png', 'edit central columns'
Expand Down
12 changes: 9 additions & 3 deletions libraries/controllers/server/ServerDatabasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,15 @@ private function _getHtmlForTableFooterButtons()
return '';
}

$html = Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "dbStatsForm"
);
$html = Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => 'dbStatsForm',
)
);

$html .= Util::getButtonOrImage(
'',
'mult_submit' . ' ajax',
Expand Down
12 changes: 9 additions & 3 deletions libraries/rte/rte_list.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
use SqlParser\Statements\CreateStatement;
use PMA\libraries\URL;
use PMA\libraries\Template;


if (! defined('PHPMYADMIN')) {
Expand Down Expand Up @@ -143,9 +144,14 @@ function PMA_RTE_getList($type, $items)

if (count($items)) {
$retval .= '<div class="withSelected">';
$retval .= PMA\libraries\Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], 'rteListForm'
);
$retval .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => 'rteListForm',
)
);
$retval .= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_export.png', 'export'
Expand Down
82 changes: 54 additions & 28 deletions libraries/server_privileges.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2306,30 +2306,40 @@ function PMA_getHtmlForAddUser($dbname)
$html_output .= '<fieldset id="fieldset_add_user_database">' . "\n"
. '<legend>' . __('Database for user account') . '</legend>' . "\n";

$html_output .= Util::getCheckbox(
'createdb-1',
__('Create database with same name and grant all privileges.'),
false, false, 'createdb-1'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-1',
'label' => __('Create database with same name and grant all privileges.'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'createdb-1',
)
);
$html_output .= '<br />' . "\n";
$html_output .= Util::getCheckbox(
'createdb-2',
__('Grant all privileges on wildcard name (username\\_%).'),
false, false, 'createdb-2'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-2',
'label' => __('Grant all privileges on wildcard name (username\\_%).'),
'checked' => false,
'onclick' => false,
'html_field_id' => 'createdb-2',
)
);
$html_output .= '<br />' . "\n";

if (! empty($dbname) ) {
$html_output .= Util::getCheckbox(
'createdb-3',
sprintf(
__('Grant all privileges on database "%s".'),
htmlspecialchars($dbname)
),
true,
false,
'createdb-3'
);
$html_output .= Template::get('checkbox')
->render(
array(
'html_field_name' => 'createdb-3',
'label' => sprintf(__('Grant all privileges on database %s.'), htmlspecialchars($dbname)),
'checked' => true,
'onclick' => false,
'html_field_id' => 'createdb-3',
)
);
$html_output .= '<input type="hidden" name="dbname" value="'
. htmlspecialchars($dbname) . '" />' . "\n";
$html_output .= '<br />' . "\n";
Expand Down Expand Up @@ -2506,9 +2516,14 @@ function PMA_getHtmlForSpecificDbPrivileges($db)
$html_output .= '</table>';

$html_output .= '<div class="floatleft">';
$html_output .= Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm"
);
$html_output .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => "usersForm",
)
);
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'
Expand Down Expand Up @@ -2585,9 +2600,14 @@ function PMA_getHtmlForSpecificTablePrivileges($db, $table)
$html_output .= '</table>';

$html_output .= '<div class="floatleft">';
$html_output .= Util::getWithSelected(
$GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm"
);
$html_output .= Template::get('select_all')
->render(
array(
'pmaThemeImage' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'formName' => "usersForm",
)
);
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'
Expand Down Expand Up @@ -3602,8 +3622,14 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
. '</table>' . "\n";

$html_output .= '<div class="floatleft">'
. Util::getWithSelected($pmaThemeImage, $text_dir, "usersForm") . "\n";

. Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'usersForm',
)
) . "\n";
$html_output .= Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Export'), 'b_tblexport.png', 'export'
Expand Down
39 changes: 24 additions & 15 deletions libraries/tracking.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,14 @@ function PMA_getHtmlForTableVersionDetails(
$html .= '</tbody>';
$html .= '</table>';

$html .= PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"versionsForm"
);
$html .= PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'versionsForm',
)
);
$html .= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Delete version'), 'b_drop.png', 'delete_version'
Expand Down Expand Up @@ -1488,11 +1491,14 @@ function PMA_displayUntrackedTables(
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"untrackedForm"
);
echo PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'untrackedForm',
)
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Track table'), 'eye.png', 'track'
Expand Down Expand Up @@ -1708,11 +1714,14 @@ class="checkall" id="<?php echo $checkbox_id;?>"
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"trackedForm"
);
echo PMA\libraries\Template::get('select_all')
->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'formName' => 'trackedForm',
)
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit',
__('Delete tracking'), 'b_drop.png', 'delete_tracking'
Expand Down
13 changes: 13 additions & 0 deletions templates/checkbox.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<input type="checkbox" name="<?= $html_field_name ; ?>"
<?php if (isset($html_field_id)): ?>
id="<?= $html_field_id ; ?>"
<?php endif ;
if (isset($checked) && $checked): ?>
checked="checked"
<?php endif ;
if (isset($onclick) && $onclick): ?>
class="autosubmit"
<?php endif ; ?> />
<label <?php if (isset($html_field_id)): ?>
for="<?= $html_field_id ; endif ; ?>">
<?= $label ; ?> </label>
Loading

0 comments on commit 307f706

Please sign in to comment.