From: Thierry Parmentelat Date: Thu, 29 Jan 2009 17:29:35 +0000 (+0000) Subject: handles urls with settings X-Git-Tag: PLEWWW-4.3-1~76 X-Git-Url: http://git.onelab.eu/?p=plewww.git;a=commitdiff_plain;h=1b32d86af0dcb7f03e469ae484975dce7cbc29ec handles urls with settings --- diff --git a/planetlab/includes/plc_forms.php b/planetlab/includes/plc_forms.php index 15480dc..92de1e1 100644 --- a/planetlab/includes/plc_forms.php +++ b/planetlab/includes/plc_forms.php @@ -8,17 +8,19 @@ require_once 'plc_functions.php'; // the first functions that we had were actually printing the stuff instead of returning it // so basically the foo (...) function should do ``print (foo_text(...))'' -function plc_form_hidden_text ($key,$value) { - return ""; -} -function plc_form_hidden ($key,$value) { print plc_form_hidden_text($key,$value); } - // options unused so far -function plc_form_start ($url, $values, $options=array()) { +function plc_form_start ($full_url, $values, $options=array()) { + if ( ! $values ) $values = array(); + // extract var=value settings from url if any + $split=split_url($full_url); + $url=$split['url']; + $url_values=$split['values']; + if ( $url_values ) $values=array_merge($values,$url_values); $method = array_key_exists('method',$options) ? $options['method'] : 'POST'; print "
"; - foreach ($values as $key=>$value) { - print plc_form_hidden_text($ke,$value); + plc_debug('values',$values); + if ($values) foreach ($values as $key=>$value) { + print plc_form_hidden_text($key,$value); } } @@ -26,6 +28,11 @@ function plc_form_end($options=array()) { print "
"; } +function plc_form_hidden_text ($key,$value) { + return ""; +} +function plc_form_hidden ($key,$value) { print plc_form_hidden_text($key,$value); } + function plc_form_checkbox_text ($name,$value,$selected=false) { if ($selected) $xtra=" selected=selected"; return ""; @@ -67,8 +74,13 @@ function plc_form_select_text ($name,$values,$label="") { return $selector; } -function plc_form_simple_button ($url,$text,$method="POST") { +function plc_form_simple_button ($full_url,$text,$method="POST") { + $split=split_url($full_url); + $url=$split['url']; + $values=$split['values']; $button=plc_form_submit_text("anonymous",$text); + if ($values) foreach ($values as $key=>$value) + $button .= plc_form_hidden_text($key,$value); return "
$button
"; } diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index a25f747..ddfd68e 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -104,6 +104,20 @@ function l_person_register() { return "/db/persons/register.php"; } function l_site_register() { return "/db/sites/register.php"; } function l_site_pending() { return "/db/sites/join_request.php"; } +// returns array ['url' => path, 'values' => hash (key=>value)* ] +function split_url ($full_url) { + list($url,$args) = explode("?",$full_url); + $values=array(); + if ($args) { + $pairs=explode("&",$args); + foreach ($pairs as $pair) { + list ($name,$value) = explode("=",$pair); + $values[$name]=$value; + } + } + return array("url"=>$url,"values"=>$values); +} + //////////////////////////////////////////////////////////// validation functions function topdomain ($hostname) { $exploded=array_reverse(explode(".",$hostname)); diff --git a/planetlab/includes/plc_minitabs.php b/planetlab/includes/plc_minitabs.php index ae7c323..4920660 100644 --- a/planetlab/includes/plc_minitabs.php +++ b/planetlab/includes/plc_minitabs.php @@ -27,7 +27,7 @@ drupal_set_html_head(' // (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned -function plc_tabs($array) { +function plc_tabs ($array) { print '
'; print '