Skip to content

Commit

Permalink
* helper_api.php
Browse files Browse the repository at this point in the history
  (helper_ensure_confirmed): new function to prompt user for confirmation before proceeding
* html_api.php
  (print_page_bot1): make the parameter option... it seems like in most cases you can just take the filename from $PHP_SELF.  The file has to be in the same dir as the source display page but that was already the case the way it was written.  We might be able to phase out the __FILE__ parameters throughout but anyway, I needed this for the function I added above (since it's in a different file)
* print_api.php
 (print_hidden_inputs): new function to print a hidden input for each item in an associative array


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1586 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Julian Fitzell committed Oct 23, 2002
1 parent 5699efb commit bf3269b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
40 changes: 39 additions & 1 deletion core/helper_api.php
Expand Up @@ -6,7 +6,7 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Id: helper_api.php,v 1.20 2002-09-21 23:00:43 jfitzell Exp $
# $Id: helper_api.php,v 1.21 2002-10-23 02:18:10 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -223,6 +223,44 @@ function helper_clear_pref_cookies() {
gpc_clear_cookie( 'manage_cookie' );
}
# --------------------
# Check whether the user has confirmed this action.
#
# If the user has not confirmed the action, generate a page which asks
# the user to confirm and then submits a form back to the current page
# with all the GET and POST data and an additional field called _confirmed
# to indicate that confirmation has been done.
function helper_ensure_confirmed( $p_message, $p_button_label ) {
if (true == gpc_get_bool( '_confirmed' ) ) {
return true;
}

global $PHP_SELF;
if ( ! php_version_at_least( '4.1.0' ) ) {
global $_POST, $_GET;
}

print_page_top1();
print_page_top2();

echo "<br />\n<div align=\"center\">\n";
print_hr();
echo "\n$p_message\n";

echo '<form method="post" action="' . $PHP_SELF . "\">\n";

print_hidden_inputs( gpc_strip_slashes( $_POST ) );
print_hidden_inputs( gpc_strip_slashes( $_GET ) );

echo "<input type=\"hidden\" name=\"_confirmed\" value=\"1\" />\n";
echo '<br /><br /><input type="submit" value="' . $p_button_label . '" />';
echo "\n</form>\n";

print_hr();
echo "</div>\n";
print_page_bot1();
exit;
}
# --------------------
# Print a debug string by generating a notice
function debug( $p_string ) {
trigger_error( $p_string, NOTICE );
Expand Down
8 changes: 6 additions & 2 deletions core/html_api.php
Expand Up @@ -6,7 +6,7 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Id: html_api.php,v 1.20 2002-10-20 23:59:49 jfitzell Exp $
# $Id: html_api.php,v 1.21 2002-10-23 02:18:11 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
Expand Down Expand Up @@ -48,9 +48,13 @@ function print_page_top2() {
# --------------------
# comes at the bottom of the html
# $p_file should always be the __FILE__ variable. This is passed to show source.
function print_page_bot1( $p_file ) {
function print_page_bot1( $p_file = null ) {
global $g_bottom_include_page;

if ( null === $p_file ) {
$p_file = basename( $GLOBALS['PHP_SELF'] );
}

print_bottom_page( $g_bottom_include_page );
print_footer( $p_file );
print_body_bottom();
Expand Down
24 changes: 22 additions & 2 deletions core/print_api.php
Expand Up @@ -6,13 +6,13 @@
# See the files README and LICENSE for details

# --------------------------------------------------------
# $Id: print_api.php,v 1.25 2002-10-22 04:28:57 jfitzell Exp $
# $Id: print_api.php,v 1.26 2002-10-23 02:18:11 jfitzell Exp $
# --------------------------------------------------------

###########################################################################
# Basic Print API
#
# this file handles printing and string manipulation functions
# this file handles printing functions
###########################################################################

# --------------------
Expand Down Expand Up @@ -1046,5 +1046,25 @@ function print_sql_error( $p_query ) {
print_email_link( $g_administrator_email, lang_get( 'administrator' ) );
PRINT "<br />$p_query;<br />";
}
# --------------------
# Print a hidden input for each name=>value pair in the array
#
# If a value is an array an input will be created for each item with a name
# that ends with []
# The names and values are passed through htmlspecialchars() before being displayed
function print_hidden_inputs( $p_assoc_array ) {
foreach ( $p_assoc_array as $key => $val ) {
$key = htmlspecialchars( $key );
if ( is_array( $val ) ) {
foreach ( $val as $val2 ) {
$val2 = htmlspecialchars( $val2 );
echo "<input type=\"hidden\" name=\"$val\[\]\" value=\"$val2\" />\n";
}
} else {
$val = htmlspecialchars( $val );
echo "<input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
}
}
}

?>

0 comments on commit bf3269b

Please sign in to comment.