Commit e8b01620 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

New upstream

parent 3db868b3
......@@ -238,7 +238,8 @@ class Pieform {
'maxlength' => 'This field must be at most %d characters long',
'minlength' => 'This field must be at least %d characters long',
'integer' => 'The field must be an integer',
'validateoptions' => 'The option "%s" is invalid'
'validateoptions' => 'The option "%s" is invalid',
'regex' => 'This field is not in valid form'
)
);
......@@ -401,8 +402,16 @@ class Pieform {
// Set some attributes for all elements
$autofocusadded = false;
foreach ($this->elements as $name => &$element) {
if (!empty($element['ignore'])) {
unset($this->elements[$name]);
continue;
}
// The name can be in the element itself. This is compatibility for the perl version
if (isset($element['name'])) {
$name = $element['name'];
}
if (count($element) == 0) {
throw new PieformException('An element in form "' . $this->name . '" has no data');
throw new PieformException('An element in form "' . $this->name . '" has no data (' . $name . ')');
}
if (!isset($element['type'])) {
$element['type'] = 'markup';
......@@ -423,6 +432,18 @@ class Pieform {
}
if ($element['type'] == 'fieldset') {
foreach ($element['elements'] as $subname => &$subelement) {
if (!empty($subelement['ignore'])) {
log_debug('ignoring ' . $subname);
unset($element['elements'][$subname]);
continue;
}
// The name can be in the element itself. This is compatibility for the perl version
if (isset($subelement['name'])) {
$subname = $subelement['name'];
}
if (count($subelement) == 0) {
throw new PieformException('An element in form "' . $this->name . '" has no data (' . $subname . ')');
}
if (!isset($subelement['type'])) {
$subelement['type'] = 'markup';
if (!isset($subelement['value'])) {
......@@ -780,7 +801,9 @@ class Pieform {
$result = array();
$global = ($this->method == 'get') ? $_GET : $_POST;
foreach ($this->get_elements() as $element) {
$result[$element['name']] = $this->get_value($element);
if ($element['type'] != 'markup') {
$result[$element['name']] = $this->get_value($element);
}
}
return $result;
}
......@@ -1135,6 +1158,8 @@ EOF;
/**
* Hook for giving information back to the developer
*
* @param string $message The message to give to the developer
*/
public static function info($message) {
$function = 'pieform_info';
......@@ -1196,7 +1221,6 @@ EOF;
}
}
}
}
......@@ -1213,9 +1237,9 @@ EOF;
* {@internal This is separate so that child element types can nest other
* elements inside them (like the fieldset element does for example).}}
*
* @param array $element The element to render
* @param array $element The element to render
* @param Pieform $form The form to render the element for
* @return string The rendered element
* @return string The rendered element
*/
function pieform_render_element($element, Pieform $form) {
// If the element is pure markup, don't pass it to the renderer
......
......@@ -64,17 +64,18 @@ function pieform_render_expiry($element, Pieform $form) {
$seconds = null;
}
// @todo probably create with an actual input element, as tabindex doesn't work here for one thing
$numberinput = '<input ';
if ($form->get_ajaxpost()) {
$numberinput .= 'onchange="' . $name . '_change()"';
$numberinput .= $values['units'] == 'noenddate' ? ' disabled="disabled"' : '';
}
$numberinput .= $values['units'] == 'noenddate' ? ' disabled="disabled"' : '';
$numberinput .= 'type="text" size="4" ' . 'name="' . $name . '_number" ';
$numberinput .= 'id="' . $name . '_number" value="' . $values['number'] . "\">\n";
$allunits = get_expiry_units();
$uselect = '<select ' . ($form->get_ajaxpost() ? 'onchange="' . $name . '_change()" ' : '');
$uselect = '<select onchange="' . $name . '_change()" ';
$uselect .= 'name="' . $name . '_units" id="' . $name . '_units"' . ">\n";
foreach ($allunits as $u) {
$uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' . $form->i18n($u) . "</option>\n";
......@@ -86,10 +87,14 @@ function pieform_render_expiry($element, Pieform $form) {
// Every time one of the two inputs is changed, update the number
// of seconds in the hidden input.
if ($form->get_ajaxpost()) {
$script = <<< EOJS
$script = <<<EOJS
<script type="text/javascript" language="javascript">
function {$name}_change() {
EOJS;
/*
if ($form->get_ajaxpost()) {
$script .= <<<EOJS
var seconds = null;
if ($('{$name}_number').value > 0) {
var mult = $('{$name}_number').value * 60 * 60 * 24;
......@@ -106,20 +111,22 @@ function {$name}_change() {
else {
seconds = 0;
}
$('{$name}').value = seconds;
EOJS;
}
*/
$script .= <<<EOJS
if ($('{$name}_units').value == 'noenddate') {
$('{$name}_number').disabled = true;
}
else {
$('{$name}_number').disabled = false;
}
$('{$name}').value = seconds;
}
</script>
EOJS;
}
else {
$script = '';
}
return $numberinput . $uselect . $hidden . $script;
}
......@@ -165,20 +172,52 @@ function get_expiry_from_seconds($seconds) {
}
// /** gets the value explicitly from the request */
// function pieform_get_value_expiry($element, Pieform $form) {
// $name = $element['name'];
// $global = ($form->get_method() == 'get') ? $_GET : $_POST;
// return $global[$name];
// //$unit = $global[$name . '_units'];
// //if ($unit == 'noenddate') {
// // return null;
// //}
// //$allunits = get_expiry_units();
// //$number = $global[$name . '_number'];
// //if (!in_array($unit,$allunits) || $number < 0) {
// // return null;
// //}
// //return $number * seconds_in($unit);
// }
function pieform_get_value_expiry($element, Pieform $form) {
$name = $element['name'];
$global = ($form->get_method() == 'get') ? $_GET : $_POST;
//return $global[$name];
$unit = $global[$name . '_units'];
if ($unit == 'noenddate') {
return null;
}
$allunits = get_expiry_units();
$number = $global[$name . '_number'];
if (!in_array($unit,$allunits) || $number < 0) {
return null;
}
return $number * seconds_in($unit);
}
function pieform_get_value_js_expiry($element, Pieform $form) {
$formname = $form->get_name();
$name = $element['name'];
return <<<EOF
var seconds = null;
//if ($('{$name}_units').value == 'noenddate') {
// seconds = null;
//}
//else {
// if ($('{$name}_number').value > 0) {
// var mult = $('{$name}_number').value * 60 * 60 * 24;
// if ($('{$name}_units').value == 'days') {
// seconds = mult;
// } else if ($('{$name}_units').value == 'weeks') {
// seconds = mult * 7;
// } else if ($('{$name}_units').value == 'months') {
// seconds = mult * 30;
// } else if ($('{$name}_units').value == 'years') {
// seconds = mult * 365;
// }
// }
// else {
// seconds = 0;
// }
//}
//data['{$name}'] = seconds;
data['{$name}_number'] = $('{$name}_number').value;
data['{$name}_units'] = $('{$name}_units').value;
EOF;
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment