From: pdontthink Date: Fri, 27 Apr 2012 07:18:17 +0000 (+0000) Subject: Clear checkbox selections when form is processed X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d9b8769ca92973a03c12a6bfffd44d5b6885d2be;p=squirrelmail.git Clear checkbox selections when form is processed git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14320 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/html.php b/functions/html.php index 0bf243e8..f8dafc9b 100644 --- a/functions/html.php +++ b/functions/html.php @@ -359,15 +359,20 @@ function set_uri_vars($uri, $values, $sanitize=TRUE) { * * @param string $url url that must be modified * @param string $var GET variable name - * @param string $val variable value + * @param string $val variable value (CANNOT be an array) * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2) + * @param boolean $treat_as_array When TRUE, if $var is an array (it occurs one + * or more times with square brackets after it, + * e.g. "var[1]"), the whole array will be removed + * (when $val is NULL) or the given value will be + * added to the next array slot (@since 1.4.23/1.5.2) * * @return string $url modified url * * @since 1.3.0 * */ -function set_url_var($url, $var, $val=null, $link=true) { +function set_url_var($url, $var, $val=null, $link=true, $treat_as_array=false) { $url = str_replace('&','&',$url); if (strpos($url, '?') === false) { @@ -378,18 +383,35 @@ function set_url_var($url, $var, $val=null, $link=true) { $newpar = array(); $params = explode('&', $params); + $array_names = array(); foreach ($params as $p) { if (trim($p)) { $p = explode('=', $p); $newpar[$p[0]] = (isset($p[1]) ? $p[1] : ''); + if ($treat_as_array && preg_match('/(.*)\[(\d+)]$/', $p[0], $matches)) { + if (!is_array($array_names[$matches[1]])) $array_names[$matches[1]] = array(); + $array_names[$matches[1]][$matches[2]] = $p[1]; + } } } if (is_null($val)) { - unset($newpar[$var]); + if ($treat_as_array && !empty($array_names[$var])) { + foreach ($array_names[$var] as $key => $ignore) + unset($newpar[$var . '[' . $key . ']']); + } else { + unset($newpar[$var]); + } } else { - $newpar[$var] = $val; + if ($treat_as_array && !empty($array_names[$var])) { + $max_key = 0; + foreach ($array_names[$var] as $key => $ignore) + if ($key >= $max_key) $max_key = $key + 1; + $newpar[$var . '[' . $max_key . ']'] = $val; + } else { + $newpar[$var] = $val; + } } if (!count($newpar)) { diff --git a/src/right_main.php b/src/right_main.php index 1072572b..05ad7eb4 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -236,6 +236,8 @@ if (!sqgetGlobalVar('align',$align,SQ_SESSION)) { $sError = handleMessageListForm($imapConnection,$aMailbox); if ($sError) { $note = $sError; +} else if (sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') { + $preselected = array(); // clear pre-checked checkboxes when action succeeded }