pieforms-commit Mailing List for Pieforms (Page 13)
Status: Alpha
Brought to you by:
oracleshinoda
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(73) |
Dec
(83) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(16) |
Feb
(19) |
Mar
(12) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(45) |
2008 |
Jan
(20) |
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
(5) |
Jul
(1) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(7) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ora...@us...> - 2006-11-18 11:53:55
|
Revision: 23 http://svn.sourceforge.net/pieforms/?rev=23&view=rev Author: oracleshinoda Date: 2006-11-18 03:53:53 -0800 (Sat, 18 Nov 2006) Log Message: ----------- * Updated the <div> renderer to match the <table> renderer much more closely. * Updated the header comment to be correct * Added javascript for adding/removing errors and messages. Totally untested (there's no js in SVN to test with) * Fixed hsc() -> Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/renderers/div.php Modified: pieforms/src/pieform/renderers/div.php =================================================================== --- pieforms/src/pieform/renderers/div.php 2006-11-18 11:51:58 UTC (rev 22) +++ pieforms/src/pieform/renderers/div.php 2006-11-18 11:53:53 UTC (rev 23) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,18 +16,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-renderer + * @package pieform + * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** - * Default renderer - renders form elements inside <div>s. + * Renders form elements inside <div>s. * * @param string $builtelement The element, already built * @param array $rawelement The element in raw form, for looking up @@ -35,37 +33,84 @@ * @return string The element rendered inside an appropriate * container. */ -function form_renderer_div($builtelement, $rawelement) { +function pieform_renderer_div($builtelement, $rawelement) { // Set the class of the enclosing <div> to match that of the element $result = '<div'; + if (isset($rawelement['name'])) { + $result .= ' id="' . $rawelement['name'] . '_container"'; + } if ($rawelement['class']) { $result .= ' class="' . $rawelement['class'] . '"'; } $result .= '>'; - if (isset($rawelement['title']) && $rawelement['type'] != 'fieldset') { - $result .= '<label for="' . $rawelement['id'] . '">' . hsc($rawelement['title']) . '</label>'; + if (isset($rawelement['title']) && $rawelement['title'] !== '' && $rawelement['type'] != 'fieldset') { + if (!empty($rawelement['nolabel'])) { + // Don't bother with a label for the element + $result .= Pieform::hsc($rawelement['title']); + } + else { + $result .= '<label for="' . $rawelement['id'] . '">' . Pieform::hsc($rawelement['title']) . '</label>'; + } } $result .= $builtelement; // Contextual help if (!empty($rawelement['help'])) { - $result .= ' <span class="help"><a href="#" title="' . hsc($rawelement['help']) . '">?</a></span>'; + $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; } // Description - optional description of the element, or other note that should be visible // on the form itself (without the user having to hover over contextual help if (!empty($rawelement['description'])) { - $result .= '<div class="description"> ' . hsc($rawelement['description']) . "</div>"; + $result .= '<div class="description"> ' . Pieform::hsc($rawelement['description']) . "</div>"; } if (!empty($rawelement['error'])) { - $result .= '<div class="errmsg">' . hsc($rawelement['error']) . '</div>'; + $result .= '<div class="errmsg">' . Pieform::hsc($rawelement['error']) . '</div>'; } $result .= "</div>\n"; return $result; } +function pieform_renderer_table_messages_js($id, $submitid) { + $result = <<<EOF +// Given a message and form element name, should set an error on the element +function {$id}_set_error(message, element) { + {$id}_remove_error(element); + element += '_container'; + // @todo set error class on input elements... + $(element).parentNode.insertBefore(DIV({'id': '{$id}_error_' + element, 'class': 'errmsg'}, message), $(element).nextSibling); +} +// Given a form element name, should remove an error associated with it +function {$id}_remove_error(element) { + element += '_container'; + var elem = $('{$id}_error_' + element); + if (elem) { + removeElement(elem); + } +} +function {$id}_message(message, type) { + var elem = $('{$id}_message'); + var msg = DIV({'id': '{$id}_message', 'class': type}, message); + if (elem) { + swapDOM(elem, msg); + } + else { + appendChildNodes($('{$submitid}_container').parentNode, msg); + } +} +function {$id}_remove_message() { + var elem = $('{$id}_message'); + if (elem) { + removeElement(elem); + } +} + +EOF; + return $result; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:52:03
|
Revision: 22 http://svn.sourceforge.net/pieforms/?rev=22&view=rev Author: oracleshinoda Date: 2006-11-18 03:51:58 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Do not make labels for elements if they have specified it but it is empty. This causes feature request 1598819. Fixed a typo in a comment Modified Paths: -------------- pieforms/src/pieform/renderers/table.php Modified: pieforms/src/pieform/renderers/table.php =================================================================== --- pieforms/src/pieform/renderers/table.php 2006-11-18 11:28:22 UTC (rev 21) +++ pieforms/src/pieform/renderers/table.php 2006-11-18 11:51:58 UTC (rev 22) @@ -60,9 +60,9 @@ $result .= ">\n\t\t"; $result .= '<th>'; - if (isset($rawelement['title'])) { + if (isset($rawelement['title']) && $rawelement['title'] !== '') { if (!empty($rawelement['nolabel'])) { - // Don't bother with a lable for the element + // Don't bother with a label for the element $result .= Pieform::hsc($rawelement['title']); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:28:24
|
Revision: 21 http://svn.sourceforge.net/pieforms/?rev=21&view=rev Author: oracleshinoda Date: 2006-11-18 03:28:22 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Did some cosmetic fixing of the WYSIWYG element. It doesn't actually render a wysiwyg at the moment though (no javascript in SVN), and should be renamed to 'tinymce', but at least the fallback behaviour works Modified Paths: -------------- pieforms/src/pieform/elements/wysiwyg.php Modified: pieforms/src/pieform/elements/wysiwyg.php =================================================================== --- pieforms/src/pieform/elements/wysiwyg.php 2006-11-18 11:24:34 UTC (rev 20) +++ pieforms/src/pieform/elements/wysiwyg.php 2006-11-18 11:28:22 UTC (rev 21) @@ -24,8 +24,6 @@ * */ - - /** * Renders a textarea, but with extra javascript to turn it into a wysigyw * textarea. @@ -37,7 +35,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_wysiwyg($element, $form) { +function pieform_render_wysiwyg($element, Pieform $form) { $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -65,7 +63,7 @@ . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') . Pieform::element_attributes($element, array('maxlength', 'size')) - . '>' . hsc($form->get_value($element)) . '</textarea>'; + . '>' . Pieform::hsc($form->get_value($element)) . '</textarea>'; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:24:42
|
Revision: 20 http://svn.sourceforge.net/pieforms/?rev=20&view=rev Author: oracleshinoda Date: 2006-11-18 03:24:34 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Removed the custom userlist element. It's too much dependent on the Mahara project. Removed Paths: ------------- pieforms/src/pieform/elements/userlist.php Deleted: pieforms/src/pieform/elements/userlist.php =================================================================== --- pieforms/src/pieform/elements/userlist.php 2006-11-18 11:20:10 UTC (rev 19) +++ pieforms/src/pieform/elements/userlist.php 2006-11-18 11:24:34 UTC (rev 20) @@ -1,106 +0,0 @@ -<?php -/** - * This program is part of Pieforms - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * @package pieform - * @subpackage element - * @author Martyn Smith <ma...@ca...> - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz - * - */ - - - -/** - * Provides a basic text field input. - * - * @todo this is just lies ... - * @param array $element The element to render - * @param Pieform $form The form to render the element for - * @return string The HTML for the element - */ -function pieform_render_userlist($element, Pieform $form) { - $smarty = smarty(); - - $smarty->left_delimiter = '{{'; - $smarty->right_delimiter = '}}'; - - $value = $form->get_value($element); - - if (!is_array($value) && isset($element['defaultvalue']) && is_array($element['defaultvalue'])) { - $value = $element['defaultvalue']; - } - - if (is_array($value) && count($value)) { - $members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname'); - - foreach($members as &$member) { - $member = display_name($member); - } - - $smarty->assign('options',$members); - $smarty->assign('value', join(',',$value)); - } - - $smarty->assign('name', $element['name']); - if (!empty($element['filter'])) { - $smarty->assign('filter', true); - } - - return $smarty->fetch('form/userlist.tpl'); -} - -function pieform_get_value_userlist($element, Pieform $form) { - $name = $element['name']; - - $global = ($form->get_method() == 'get') ? $_GET : $_POST; - - if (isset($global[$name])) { - $value = $global[$name]; - - if ($value == '') { - return array(); - } - - if (preg_match('/^(\d+(,\d+)*)$/',$value)) { - return array_map('intval', explode(',', $value)); - } - - throw new PieformException("Invalid value for userlist form element '$name' = '$value'"); - } - - return null; -} - -function pieform_is_empty_userlist($value, $element) { - if (is_array($value) && count($value)) { - return false; - } - - return true; -} - -function pieform_render_userlist_set_attributes($element) { - // By default, use the filter select box - if (!isset($element['filter'])) { - $element['filter'] = true; - } - return $element; -} - -?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:20:12
|
Revision: 19 http://svn.sourceforge.net/pieforms/?rev=19&view=rev Author: oracleshinoda Date: 2006-11-18 03:20:10 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'textarea' element: hsc() replaced with Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/elements/textarea.php Modified: pieforms/src/pieform/elements/textarea.php =================================================================== --- pieforms/src/pieform/elements/textarea.php 2006-11-18 11:17:37 UTC (rev 18) +++ pieforms/src/pieform/elements/textarea.php 2006-11-18 11:20:10 UTC (rev 19) @@ -24,16 +24,14 @@ * */ - - /** * Renders a basic HTML <textarea> element. * - * @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 HTML for the element + * @return string The HTML for the element */ -function pieform_render_textarea($element, $form) { +function pieform_render_textarea($element, Pieform $form) { $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -61,7 +59,7 @@ . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') . Pieform::element_attributes($element, array('maxlength', 'size')) - . '>' . hsc($form->get_value($element)) . '</textarea>'; + . '>' . Pieform::hsc($form->get_value($element)) . '</textarea>'; } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:17:40
|
Revision: 18 http://svn.sourceforge.net/pieforms/?rev=18&view=rev Author: oracleshinoda Date: 2006-11-18 03:17:37 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed whitespace in 'text' element comment Modified Paths: -------------- pieforms/src/pieform/elements/text.php Modified: pieforms/src/pieform/elements/text.php =================================================================== --- pieforms/src/pieform/elements/text.php 2006-11-18 11:15:24 UTC (rev 17) +++ pieforms/src/pieform/elements/text.php 2006-11-18 11:17:37 UTC (rev 18) @@ -27,9 +27,9 @@ /** * Provides a basic text field input. * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_text($element, $form) { return '<input type="text"' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:15:24
|
Revision: 17 http://svn.sourceforge.net/pieforms/?rev=17&view=rev Author: oracleshinoda Date: 2006-11-18 03:15:24 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'submitcancel' element: missed converting a call to form_render_cancel Modified Paths: -------------- pieforms/src/pieform/elements/submitcancel.php Modified: pieforms/src/pieform/elements/submitcancel.php =================================================================== --- pieforms/src/pieform/elements/submitcancel.php 2006-11-18 11:11:48 UTC (rev 16) +++ pieforms/src/pieform/elements/submitcancel.php 2006-11-18 11:15:24 UTC (rev 17) @@ -24,14 +24,12 @@ * */ - - /** * Renders a submit and cancel button * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_submitcancel($element, Pieform $form) { require_once('submit.php'); @@ -40,7 +38,7 @@ $submitelement['value'] = $element['value'][0]; $cancelelement = $element; $cancelelement['value'] = $element['value'][1]; - return pieform_render_submit($submitelement, $form) . ' ' . form_render_cancel($cancelelement, $form); + return pieform_render_submit($submitelement, $form) . ' ' . pieform_render_cancel($cancelelement, $form); } function pieform_render_submitcancel_set_attributes($element) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:11:48
|
Revision: 16 http://svn.sourceforge.net/pieforms/?rev=16&view=rev Author: oracleshinoda Date: 2006-11-18 03:11:48 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'select' element: hsc() replaced with Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/elements/select.php Modified: pieforms/src/pieform/elements/select.php =================================================================== --- pieforms/src/pieform/elements/select.php 2006-11-18 11:08:02 UTC (rev 15) +++ pieforms/src/pieform/elements/select.php 2006-11-18 11:11:48 UTC (rev 16) @@ -24,14 +24,12 @@ * */ - - /** * Renders a dropdown list, including support for multiple choices. * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_select($element, Pieform $form) { if (!empty($element['multiple'])) { @@ -78,7 +76,7 @@ else { $selected = ''; } - $result .= "\t<option value=\"" . hsc($key) . "\"$selected>" . hsc($value) . "</option>\n"; + $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"$selected>" . Pieform::hsc($value) . "</option>\n"; } $result .= '</select>'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:08:02
|
Revision: 15 http://svn.sourceforge.net/pieforms/?rev=15&view=rev Author: oracleshinoda Date: 2006-11-18 03:08:02 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'radio' element: hsc() replaced with Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/elements/radio.php Modified: pieforms/src/pieform/elements/radio.php =================================================================== --- pieforms/src/pieform/elements/radio.php 2006-11-18 11:04:43 UTC (rev 14) +++ pieforms/src/pieform/elements/radio.php 2006-11-18 11:08:02 UTC (rev 15) @@ -24,14 +24,12 @@ * */ - - /** * Renders a set of radio buttons for a form * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_radio($element, Pieform $form) { if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { @@ -52,9 +50,9 @@ $element['id'] = $uid; $result .= '<input type="radio"' . Pieform::element_attributes($element) - . ' value="' . hsc($value) . '"' + . ' value="' . Pieform::hsc($value) . '"' . (($form_value == $value) ? ' checked="checked"' : '') - . "> <label for=\"$uid\">" . hsc($text) . "</label>$separator"; + . "> <label for=\"$uid\">" . Pieform::hsc($text) . "</label>$separator"; } $result = substr($result, 0, -strlen($separator)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:04:43
|
Revision: 14 http://svn.sourceforge.net/pieforms/?rev=14&view=rev Author: oracleshinoda Date: 2006-11-18 03:04:43 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Prevent HTML elements from having a label Modified Paths: -------------- pieforms/src/pieform/elements/html.php Modified: pieforms/src/pieform/elements/html.php =================================================================== --- pieforms/src/pieform/elements/html.php 2006-11-18 11:02:17 UTC (rev 13) +++ pieforms/src/pieform/elements/html.php 2006-11-18 11:04:43 UTC (rev 14) @@ -36,4 +36,9 @@ return $element['value']; } +function pieform_render_html_set_attributes($element) { + $element['nolabel'] = true; + return $element; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 11:02:17
|
Revision: 13 http://svn.sourceforge.net/pieforms/?rev=13&view=rev Author: oracleshinoda Date: 2006-11-18 03:02:17 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'password' element: hsc() replaced with Pieform::hsc() Modified Paths: -------------- pieforms/src/pieform/elements/password.php Modified: pieforms/src/pieform/elements/password.php =================================================================== --- pieforms/src/pieform/elements/password.php 2006-11-18 10:59:20 UTC (rev 12) +++ pieforms/src/pieform/elements/password.php 2006-11-18 11:02:17 UTC (rev 13) @@ -24,19 +24,17 @@ * */ - - /** * Renders a password field * - * @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 HTML for the element + * @return string The HTML for the element */ -function pieform_render_password($element, $form) { +function pieform_render_password($element, Pieform $form) { return '<input type="password"' . Pieform::element_attributes($element) - . ' value="' . hsc($form->get_value($element)) . '">'; + . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } function pieform_get_value_password($element, Pieform $form) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:59:20
|
Revision: 12 http://svn.sourceforge.net/pieforms/?rev=12&view=rev Author: oracleshinoda Date: 2006-11-18 02:59:20 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Cleaned up the 'html' element Modified Paths: -------------- pieforms/src/pieform/elements/html.php Modified: pieforms/src/pieform/elements/html.php =================================================================== --- pieforms/src/pieform/elements/html.php 2006-11-18 10:54:46 UTC (rev 11) +++ pieforms/src/pieform/elements/html.php 2006-11-18 10:59:20 UTC (rev 12) @@ -24,17 +24,15 @@ * */ - - /** * Provides a way to pass in html that gets rendered * by the render (as opposed to the markup element) * - * @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 HTML for the element + * @return string The HTML for the element */ -function pieform_render_html($element, $form) { +function pieform_render_html($element, Pieform $form) { return $element['value']; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:54:46
|
Revision: 11 http://svn.sourceforge.net/pieforms/?rev=11&view=rev Author: oracleshinoda Date: 2006-11-18 02:54:46 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Cleaned up the 'file' element Modified Paths: -------------- pieforms/src/pieform/elements/file.php Modified: pieforms/src/pieform/elements/file.php =================================================================== --- pieforms/src/pieform/elements/file.php 2006-11-18 10:51:35 UTC (rev 10) +++ pieforms/src/pieform/elements/file.php 2006-11-18 10:54:46 UTC (rev 11) @@ -24,14 +24,12 @@ * */ - - /** * Renders a basic HTML <input type="file"> element. * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_file($element, Pieform $form) { return '<input type="file"' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:51:35
|
Revision: 10 http://svn.sourceforge.net/pieforms/?rev=10&view=rev Author: oracleshinoda Date: 2006-11-18 02:51:35 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'fieldset' element Modified Paths: -------------- pieforms/src/pieform/elements/fieldset.php Modified: pieforms/src/pieform/elements/fieldset.php =================================================================== --- pieforms/src/pieform/elements/fieldset.php 2006-11-18 10:48:07 UTC (rev 9) +++ pieforms/src/pieform/elements/fieldset.php 2006-11-18 10:51:35 UTC (rev 10) @@ -35,7 +35,7 @@ function pieform_render_fieldset($element, Pieform $form) { $result = "\n<fieldset>\n"; if (isset($element['legend'])) { - $result .= '<legend>' . hsc($element['legend']) . "</legend>\n"; + $result .= '<legend>' . Pieform::hsc($element['legend']) . "</legend>\n"; } foreach ($element['elements'] as $subname => $subelement) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:48:07
|
Revision: 9 http://svn.sourceforge.net/pieforms/?rev=9&view=rev Author: oracleshinoda Date: 2006-11-18 02:48:07 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the 'expiry' element Modified Paths: -------------- pieforms/src/pieform/elements/expiry.php Modified: pieforms/src/pieform/elements/expiry.php =================================================================== --- pieforms/src/pieform/elements/expiry.php 2006-11-18 10:35:50 UTC (rev 8) +++ pieforms/src/pieform/elements/expiry.php 2006-11-18 10:48:07 UTC (rev 9) @@ -77,7 +77,7 @@ $uselect = '<select ' . ($form->get_ajaxpost() ? '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"' : '') . '>' . get_string($u) . "</option>\n"; + $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' . $form->i18n($u) . "</option>\n"; } $uselect .= "</select>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:35:56
|
Revision: 8 http://svn.sourceforge.net/pieforms/?rev=8&view=rev Author: oracleshinoda Date: 2006-11-18 02:35:50 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed the date element Modified Paths: -------------- pieforms/src/pieform/elements/date.php Modified: pieforms/src/pieform/elements/date.php =================================================================== --- pieforms/src/pieform/elements/date.php 2006-11-18 10:32:14 UTC (rev 7) +++ pieforms/src/pieform/elements/date.php 2006-11-18 10:35:50 UTC (rev 8) @@ -41,21 +41,21 @@ } // Year - $value = form_render_select_get_value('year', $element['minyear'], $element['maxyear'], $element, $form); + $value = pieform_render_select_get_value('year', $element['minyear'], $element['maxyear'], $element, $form); $year = '<select name="' . $name . "_year\">\n"; for ($i = $element['minyear']; $i <= $element['maxyear']; $i++) { $year .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; } $year .= "</select>\n"; - $value = form_render_select_get_value('month', 1, 12, $element, $form); + $value = pieform_render_select_get_value('month', 1, 12, $element, $form); $month = '<select name="' . $name . "_month\">\n"; for ($i = 1; $i <= 12; $i++) { $month .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . '>' . date('M', strtotime("2000-$i-01")) . "</option>\n"; } $month .= "</select>\n"; - $value = form_render_select_get_value('day', 1, 31, $element, $form); + $value = pieform_render_select_get_value('day', 1, 31, $element, $form); $day = '<select name="' . $name . "_day\">\n"; for ($i = 1; $i <= 31; $i++) { $day .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:32:14
|
Revision: 7 http://svn.sourceforge.net/pieforms/?rev=7&view=rev Author: oracleshinoda Date: 2006-11-18 02:32:14 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Added todo about 'value' and 'checked' for checkboxes, behaviour seems arbitrary at best Modified Paths: -------------- pieforms/src/pieform/elements/checkbox.php Modified: pieforms/src/pieform/elements/checkbox.php =================================================================== --- pieforms/src/pieform/elements/checkbox.php 2006-11-18 10:26:49 UTC (rev 6) +++ pieforms/src/pieform/elements/checkbox.php 2006-11-18 10:32:14 UTC (rev 7) @@ -33,6 +33,8 @@ */ function pieform_render_checkbox($element, Pieform $form) { $checked = false; + // @todo use of 'value' and 'checked' here is ambiguous, need to write + // test cases and pick just one of them if (!empty($element['value'])) { $checked = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 10:26:52
|
Revision: 6 http://svn.sourceforge.net/pieforms/?rev=6&view=rev Author: oracleshinoda Date: 2006-11-18 02:26:49 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Only allow cancel buttons to use 'value' for their value, rather than potentially the request. Use Pieform::hsc Modified Paths: -------------- pieforms/src/pieform/elements/cancel.php Modified: pieforms/src/pieform/elements/cancel.php =================================================================== --- pieforms/src/pieform/elements/cancel.php 2006-11-18 09:51:57 UTC (rev 5) +++ pieforms/src/pieform/elements/cancel.php 2006-11-18 10:26:49 UTC (rev 6) @@ -26,24 +26,29 @@ /** * Renders a "cancel" button. Custom buttons are rendered nearly the same as - * normal submit buttons, only their name is changed (for use by the Pieform class - * internally). + * normal submit buttons, only their name is changed (for use by the Pieform + * class internally). * - * @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 HTML for the element + * @return string The HTML for the element */ function pieform_render_cancel($element, Pieform $form) { + if (!isset($element['value'])) { + throw new PieformException('Cancel elements must have a value'); + } + $attributes = Pieform::element_attributes($element); $attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes); $attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes); return '<input type="submit"' . $attributes - . ' value="' . hsc($form->get_value($element)) . '">'; + . ' value="' . Pieform::hsc($element['value']) . '">'; } // @todo how to support cancel buttons for ajax post? Possibly do a full post regardless... // or allow the user to specify a javascript function to run... it could do document.location= +// @todo also, cancel buttons don't need to be sent around via js... maybe make this return empty string function pieform_get_value_js_cancel($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 09:52:32
|
Revision: 5 http://svn.sourceforge.net/pieforms/?rev=5&view=rev Author: oracleshinoda Date: 2006-11-18 01:51:57 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Force buttons to have a value set, rather than potientially getting the value from the request. Use Pieform::hsc. Modified Paths: -------------- pieforms/src/pieform/elements/button.php Modified: pieforms/src/pieform/elements/button.php =================================================================== --- pieforms/src/pieform/elements/button.php 2006-11-18 09:39:46 UTC (rev 4) +++ pieforms/src/pieform/elements/button.php 2006-11-18 09:51:57 UTC (rev 5) @@ -26,15 +26,20 @@ /** * Renders an <input type="button"> element. + * + * The element must have the 'value' field set. * * @param array $element The element to render * @param Pieform $form The form to render the element for * @return string The HTML for the element */ function pieform_render_button($element, Pieform $form) { + if (!isset($element['value'])) { + throw new PieformException('Button elements must have a value'); + } return '<input type="button"' . Pieform::element_attributes($element) - . ' value="' . hsc($form->get_value($element)) . '">'; + . ' value="' . Pieform::hsc($element['value']) . '">'; } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 09:39:46
|
Revision: 4 http://svn.sourceforge.net/pieforms/?rev=4&view=rev Author: oracleshinoda Date: 2006-11-18 01:39:46 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed phpdoc headers, and use Pieform::hsc() instead of hsc() Modified Paths: -------------- pieforms/src/pieform/elements/submit.php Modified: pieforms/src/pieform/elements/submit.php =================================================================== --- pieforms/src/pieform/elements/submit.php 2006-11-18 09:33:03 UTC (rev 3) +++ pieforms/src/pieform/elements/submit.php 2006-11-18 09:39:46 UTC (rev 4) @@ -24,19 +24,17 @@ * */ - - /** * Renders a submit button * - * @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 HTML for the element + * @return string The HTML for the element */ -function pieform_render_submit($element, $form) { +function pieform_render_submit($element, Pieform $form) { return '<input type="submit"' . Pieform::element_attributes($element) - . ' value="' . hsc($form->get_value($element)) . '">'; + . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } function pieform_render_submit_set_attributes($element) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 09:33:09
|
Revision: 3 http://svn.sourceforge.net/pieforms/?rev=3&view=rev Author: oracleshinoda Date: 2006-11-18 01:33:03 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Fixed header comments, and function names everywhere. Most elements are still busted, but they are slowly being fixed. Modified Paths: -------------- pieforms/src/pieform/elements/button.php pieforms/src/pieform/elements/cancel.php pieforms/src/pieform/elements/checkbox.php pieforms/src/pieform/elements/date.php pieforms/src/pieform/elements/expiry.php pieforms/src/pieform/elements/fieldset.php pieforms/src/pieform/elements/file.php pieforms/src/pieform/elements/hidden.php pieforms/src/pieform/elements/html.php pieforms/src/pieform/elements/password.php pieforms/src/pieform/elements/radio.php pieforms/src/pieform/elements/select.php pieforms/src/pieform/elements/submit.php pieforms/src/pieform/elements/submitcancel.php pieforms/src/pieform/elements/text.php pieforms/src/pieform/elements/textarea.php pieforms/src/pieform/elements/userlist.php pieforms/src/pieform/elements/wysiwyg.php pieforms/src/pieform/renderers/table.php Modified: pieforms/src/pieform/elements/button.php =================================================================== --- pieforms/src/pieform/elements/button.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/button.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,29 +16,24 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** - * Renders a button. Custom buttons are rendered nearly the same as - * normal submit buttons, only their name is changed (for use by the Form class - * internally). - * + * Renders an <input type="button"> element. + * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ - -function form_render_button($element, $form) { +function pieform_render_button($element, Pieform $form) { return '<input type="button"' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . ' value="' . hsc($form->get_value($element)) . '">'; } Modified: pieforms/src/pieform/elements/cancel.php =================================================================== --- pieforms/src/pieform/elements/cancel.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/cancel.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,27 +16,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Renders a "cancel" button. Custom buttons are rendered nearly the same as - * normal submit buttons, only their name is changed (for use by the Form class + * normal submit buttons, only their name is changed (for use by the Pieform class * internally). * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_cancel($element, Form $form) { - $attributes = Form::element_attributes($element); +function pieform_render_cancel($element, Pieform $form) { + $attributes = Pieform::element_attributes($element); $attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes); $attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes); return '<input type="submit"' @@ -46,7 +44,7 @@ // @todo how to support cancel buttons for ajax post? Possibly do a full post regardless... // or allow the user to specify a javascript function to run... it could do document.location= -function form_get_value_js_cancel($element, $form) { +function pieform_get_value_js_cancel($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; return " data['{$name}_cancel'] = document.forms['$formname'].elements['{$name}_cancel'].value;\n"; Modified: pieforms/src/pieform/elements/checkbox.php =================================================================== --- pieforms/src/pieform/elements/checkbox.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/checkbox.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,24 +16,22 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Provides a basic checkbox input. * - * @param array $element The element to render - * @param Form $form The form to render the element for - * @return string The HTML for the element + * @param array $element The element to render + * @param Pieform $form The form to render the element for + * @return string The HTML for the element */ -function form_render_checkbox($element, Form $form) { +function pieform_render_checkbox($element, Pieform $form) { $checked = false; if (!empty($element['value'])) { $checked = true; @@ -46,12 +44,12 @@ } return '<input type="checkbox"' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . ($checked ? ' checked="checked"' : '') . '>'; } -function form_get_value_js_checkbox($element, Form $form) { +function pieform_get_value_js_checkbox($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; return <<<EOF Modified: pieforms/src/pieform/elements/date.php =================================================================== --- pieforms/src/pieform/elements/date.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/date.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,24 +16,22 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieforms + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Provides a date picker, in the form of three dropdowns. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_date($element, Form $form) { +function pieform_render_date($element, Pieform $form) { $result = ''; $name = $element['name']; $element['minyear'] = (isset($element['minyear'])) ? intval($element['minyear']) : 1950; @@ -69,7 +67,7 @@ } /** gets the value explicitly from the request */ -function form_get_value_date($element, Form $form) { +function pieform_get_value_date($element, Pieform $form) { $name = $element['name']; $global = ($form->get_method() == 'get') ? $_GET : $_POST; $time = mktime(0, 0, 0, $global[$name . '_month'], $global[$name . '_day'], $global[$name . '_year']); @@ -79,7 +77,7 @@ return $time; } -function form_get_value_js_date($element, Form $form) { +function pieform_get_value_js_date($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; return <<<EOF @@ -91,7 +89,7 @@ } /** helper: used when rendering the element, to get the value for it */ -function form_render_select_get_value($timeperiod, $min, $max, $element, Form $form) { +function pieform_render_select_get_value($timeperiod, $min, $max, $element, Pieform $form) { static $lookup = array( 'year' => 0, 'month' => 1, Modified: pieforms/src/pieform/elements/expiry.php =================================================================== --- pieforms/src/pieform/elements/expiry.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/expiry.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,25 +16,23 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element - * @author Nigel McNie <ni...@ca...> + * @package pieform + * @subpackage element + * @author Richard Mansfield <ric...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Provides a duration chooser, with a text box for a number and a * select box to choose the units, in days, weeks, months, years, or 'no end date'. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_expiry($element, Form $form) { +function pieform_render_expiry($element, Pieform $form) { $result = ''; $name = $element['name']; if (!isset($element['defaultvalue'])) { @@ -167,7 +165,7 @@ } // /** gets the value explicitly from the request */ -// function form_get_value_expiry($element, Form $form) { +// function pieform_get_value_expiry($element, Pieform $form) { // $name = $element['name']; // $global = ($form->get_method() == 'get') ? $_GET : $_POST; // return $global[$name]; Modified: pieforms/src/pieform/elements/fieldset.php =================================================================== --- pieforms/src/pieform/elements/fieldset.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/fieldset.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,25 +16,23 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieforms + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Renders a fieldset. Fieldsets contain other elements, and do not count as a * "true" element, in that they do not have a value and cannot be validated. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_fieldset($element, Form $form) { +function pieform_render_fieldset($element, Pieform $form) { $result = "\n<fieldset>\n"; if (isset($element['legend'])) { $result .= '<legend>' . hsc($element['legend']) . "</legend>\n"; @@ -42,9 +40,9 @@ foreach ($element['elements'] as $subname => $subelement) { if ($subelement['type'] == 'hidden') { - throw new FormError("You cannot put hidden elements in fieldsets"); + throw new PieformError("You cannot put hidden elements in fieldsets"); } - $result .= "\t" . form_render_element($subelement, $form); + $result .= "\t" . pieform_render_element($subelement, $form); } $result .= "</fieldset>\n"; Modified: pieforms/src/pieform/elements/file.php =================================================================== --- pieforms/src/pieform/elements/file.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/file.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,29 +16,29 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a basic HTML <input type="file"> element. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_file($element, Form $form) { +function pieform_render_file($element, Pieform $form) { return '<input type="file"' - . Form::element_attributes($element) . '>'; + . Pieform::element_attributes($element) . '>'; } -function form_get_value_file($element, Form $form) { +function pieform_get_value_file($element, Pieform $form) { if (isset($_FILES[$element['name']])) { if (!$_FILES[$element['name']]['error']) { return $_FILES[$element['name']]; @@ -47,7 +47,7 @@ } } -function form_is_empty_file($value, $element) { +function pieform_is_empty_file($value, $element) { if (isset($_FILES[$element['name']]) && !$_FILES[$element['name']]['error']) { return false; } Modified: pieforms/src/pieform/elements/hidden.php =================================================================== --- pieforms/src/pieform/elements/hidden.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/hidden.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,37 +16,36 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Renders a hidden element. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_hidden($element, Form $form) { +function pieform_render_hidden($element, Pieform $form) { + // @todo use the exclude parameter of element_attributes for this unset($element['tabindex']); $value = $form->get_value($element); if (is_array($value)) { $result = ''; foreach ($value as $k => $v) { - $result .= '<input type="hidden" name="' . hsc($element['name']) - . '[' . hsc($k) . ']" value="' . hsc($v) . "\">\n"; + $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) + . '[' . Pieform::hsc($k) . ']" value="' . Pieform::hsc($v) . "\">\n"; } return $result; } return '<input type="hidden"' - . Form::element_attributes($element) - . ' value="' . hsc($form->get_value($element)) . "\">\n"; + . Pieform::element_attributes($element) + . ' value="' . Pieform::hsc($form->get_value($element)) . "\">\n"; } ?> Modified: pieforms/src/pieform/elements/html.php =================================================================== --- pieforms/src/pieform/elements/html.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/html.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,25 +16,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Penny Leach <pe...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Provides a way to pass in html that gets rendered * by the render (as opposed to the markup element) * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_html($element, $form) { +function pieform_render_html($element, $form) { return $element['value']; } Modified: pieforms/src/pieform/elements/password.php =================================================================== --- pieforms/src/pieform/elements/password.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/password.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,30 +16,30 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a password field * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_password($element, $form) { +function pieform_render_password($element, $form) { return '<input type="password"' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . ' value="' . hsc($form->get_value($element)) . '">'; } -function form_get_value_password($element, Form $form) { +function pieform_get_value_password($element, Pieform $form) { $global = ($form->get_method() == 'get') ? $_GET : $_POST; if (isset($global[$element['name']])) { return $global[$element['name']]; Modified: pieforms/src/pieform/elements/radio.php =================================================================== --- pieforms/src/pieform/elements/radio.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/radio.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,26 +16,26 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a set of radio buttons for a form * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_radio($element, Form $form) { +function pieform_render_radio($element, Pieform $form) { if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { - throw new FormException('Radio elements should have at least one option'); + throw new PieformException('Radio elements should have at least one option'); } $result = ''; @@ -51,7 +51,7 @@ $uid = $id . substr(md5(microtime()), 0, 4); $element['id'] = $uid; $result .= '<input type="radio"' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . ' value="' . hsc($value) . '"' . (($form_value == $value) ? ' checked="checked"' : '') . "> <label for=\"$uid\">" . hsc($text) . "</label>$separator"; @@ -69,7 +69,7 @@ * @todo maybe later: make the get_value_js functions return a javascript function, * to keep their stuff in its own scope. Maybe. If js scoping rules mean this will help. */ -function form_get_value_js_radio($element, Form $form) { +function pieform_get_value_js_radio($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; return <<<EOF @@ -79,7 +79,7 @@ EOF; } -function form_render_radio_set_attributes($element) { +function pieform_render_radio_set_attributes($element) { $element['nolabel'] = true; $element['rules']['validateoptions'] = true; return $element; Modified: pieforms/src/pieform/elements/select.php =================================================================== --- pieforms/src/pieform/elements/select.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/select.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,24 +16,24 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a dropdown list, including support for multiple choices. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_select($element, Form $form) { +function pieform_render_select($element, Pieform $form) { if (!empty($element['multiple'])) { $element['name'] .= '[]'; } @@ -46,7 +46,7 @@ } $result = '<select' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . (!empty($element['multiple']) ? ' multiple="multiple"' : '') . ">\n"; if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { @@ -85,7 +85,7 @@ return $result; } -function form_get_value_js_select($element, Form $form) { +function pieform_get_value_js_select($element, Pieform $form) { $formname = $form->get_name(); $name = $element['name']; if ($element['collapseifoneoption']) { @@ -98,7 +98,7 @@ EOF; } -function form_render_select_set_attributes($element) { +function pieform_render_select_set_attributes($element) { $element['collapseifoneoption'] = true; $element['rules']['validateoptions'] = true; return $element; Modified: pieforms/src/pieform/elements/submit.php =================================================================== --- pieforms/src/pieform/elements/submit.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/submit.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,30 +16,30 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a submit button * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_submit($element, $form) { +function pieform_render_submit($element, $form) { return '<input type="submit"' - . Form::element_attributes($element) + . Pieform::element_attributes($element) . ' value="' . hsc($form->get_value($element)) . '">'; } -function form_render_submit_set_attributes($element) { +function pieform_render_submit_set_attributes($element) { $element['ajaxmessages'] = true; return $element; } Modified: pieforms/src/pieform/elements/submitcancel.php =================================================================== --- pieforms/src/pieform/elements/submitcancel.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/submitcancel.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,34 +16,34 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a submit and cancel button * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_submitcancel($element, Form $form) { +function pieform_render_submitcancel($element, Pieform $form) { require_once('submit.php'); require_once('cancel.php'); $submitelement = $element; $submitelement['value'] = $element['value'][0]; $cancelelement = $element; $cancelelement['value'] = $element['value'][1]; - return form_render_submit($submitelement, $form) . ' ' . form_render_cancel($cancelelement, $form); + return pieform_render_submit($submitelement, $form) . ' ' . form_render_cancel($cancelelement, $form); } -function form_render_submitcancel_set_attributes($element) { +function pieform_render_submitcancel_set_attributes($element) { $element['ajaxmessages'] = true; return $element; } Modified: pieforms/src/pieform/elements/text.php =================================================================== --- pieforms/src/pieform/elements/text.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/text.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,27 +16,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Provides a basic text field input. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_text($element, $form) { +function pieform_render_text($element, $form) { return '<input type="text"' - . Form::element_attributes($element) - . ' value="' . hsc($form->get_value($element)) . '">'; + . Pieform::element_attributes($element) + . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } ?> Modified: pieforms/src/pieform/elements/textarea.php =================================================================== --- pieforms/src/pieform/elements/textarea.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/textarea.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,24 +16,24 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a basic HTML <textarea> element. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_textarea($element, $form) { +function pieform_render_textarea($element, $form) { $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -60,7 +60,7 @@ return '<textarea' . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') - . Form::element_attributes($element, array('maxlength', 'size')) + . Pieform::element_attributes($element, array('maxlength', 'size')) . '>' . hsc($form->get_value($element)) . '</textarea>'; } Modified: pieforms/src/pieform/elements/userlist.php =================================================================== --- pieforms/src/pieform/elements/userlist.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/userlist.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,25 +16,25 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Martyn Smith <ma...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Provides a basic text field input. * * @todo this is just lies ... * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_userlist($element, Form $form) { +function pieform_render_userlist($element, Pieform $form) { $smarty = smarty(); $smarty->left_delimiter = '{{'; @@ -65,7 +65,7 @@ return $smarty->fetch('form/userlist.tpl'); } -function form_get_value_userlist($element, Form $form) { +function pieform_get_value_userlist($element, Pieform $form) { $name = $element['name']; $global = ($form->get_method() == 'get') ? $_GET : $_POST; @@ -81,13 +81,13 @@ return array_map('intval', explode(',', $value)); } - throw new FormException("Invalid value for userlist form element '$name' = '$value'"); + throw new PieformException("Invalid value for userlist form element '$name' = '$value'"); } return null; } -function form_is_empty_userlist($value, $element) { +function pieform_is_empty_userlist($value, $element) { if (is_array($value) && count($value)) { return false; } @@ -95,7 +95,7 @@ return true; } -function form_render_userlist_set_attributes($element) { +function pieform_render_userlist_set_attributes($element) { // By default, use the filter select box if (!isset($element['filter'])) { $element['filter'] = true; Modified: pieforms/src/pieform/elements/wysiwyg.php =================================================================== --- pieforms/src/pieform/elements/wysiwyg.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/elements/wysiwyg.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,16 +16,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-element + * @package pieform + * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); + /** * Renders a textarea, but with extra javascript to turn it into a wysigyw * textarea. @@ -34,10 +34,10 @@ * a bit later. * * @param array $element The element to render - * @param Form $form The form to render the element for + * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function form_render_wysiwyg($element, $form) { +function pieform_render_wysiwyg($element, $form) { $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -64,7 +64,7 @@ return '<textarea' . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') - . Form::element_attributes($element, array('maxlength', 'size')) + . Pieform::element_attributes($element, array('maxlength', 'size')) . '>' . hsc($form->get_value($element)) . '</textarea>'; } @@ -72,7 +72,7 @@ * @todo document: basically, the required rule now works better, as stripping * tags out takes away a whole bunch of hidden stuff */ -function form_is_empty_wysiwyg($value, $element) { +function pieform_is_empty_wysiwyg($value, $element) { return strip_tags($value) === ''; } Modified: pieforms/src/pieform/renderers/table.php =================================================================== --- pieforms/src/pieform/renderers/table.php 2006-11-18 09:30:45 UTC (rev 2) +++ pieforms/src/pieform/renderers/table.php 2006-11-18 09:33:03 UTC (rev 3) @@ -1,6 +1,6 @@ <?php /** - * This program is part of Mahara + * This program is part of Pieforms * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,16 +16,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * @package mahara - * @subpackage form-renderer + * @package pieform + * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz * */ -defined('INTERNAL') || die(); - /** * Renders form elements inside a <table>. * @@ -35,7 +33,7 @@ * @return string The element rendered inside an appropriate * container. */ -function form_renderer_table($builtelement, $rawelement) { +function pieform_renderer_table($builtelement, $rawelement) { if ($rawelement['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance if (0 === strpos($builtelement, "\n<fieldset>\n<legend>")) { @@ -65,10 +63,10 @@ if (isset($rawelement['title'])) { if (!empty($rawelement['nolabel'])) { // Don't bother with a lable for the element - $result .= hsc($rawelement['title']); + $result .= Pieform::hsc($rawelement['title']); } else { - $result .= '<label for="' . $rawelement['id'] . '">' . hsc($rawelement['title']) . '</label>'; + $result .= '<label for="' . $rawelement['id'] . '">' . Pieform::hsc($rawelement['title']) . '</label>'; } } $result .= "</th>\n\t\t<td>"; @@ -76,7 +74,7 @@ // Contextual help if (!empty($rawelement['help'])) { - $result .= ' <span class="help"><a href="#" title="' . hsc($rawelement['help']) . '">?</a></span>'; + $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; } $result .= "</td>\n\t</tr>\n"; @@ -98,15 +96,15 @@ return $result; } -function form_renderer_table_header() { +function pieform_renderer_table_header() { return "<table cellspacing=\"0\" border=\"0\"><tbody>\n"; } -function form_renderer_table_footer() { +function pieform_renderer_table_footer() { return "</tbody></table>\n"; } -function form_renderer_table_messages_js($id, $submitid) { +function pieform_renderer_table_messages_js($id, $submitid) { $result = <<<EOF // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-18 09:30:45
|
Revision: 2 http://svn.sourceforge.net/pieforms/?rev=2&view=rev Author: oracleshinoda Date: 2006-11-18 01:30:45 -0800 (Sat, 18 Nov 2006) Log Message: ----------- * Fixed default method to be 'get' * Make sure forms have at least one element * Change hsc() calls to self::hsc, and implement that This commit is a bit messy, but I'm slowly getting it all working. Modified Paths: -------------- pieforms/src/pieform.php Modified: pieforms/src/pieform.php =================================================================== --- pieforms/src/pieform.php 2006-11-17 13:01:30 UTC (rev 1) +++ pieforms/src/pieform.php 2006-11-18 09:30:45 UTC (rev 2) @@ -287,10 +287,13 @@ } } } + else { + $formconfig = array(); + } // Assign defaults for the form $formdefaults = array( - 'method' => 'post', + 'method' => 'get', 'action' => '', 'onsubmit' => '', 'ajaxpost' => false, @@ -352,7 +355,7 @@ $this->iscancellable = (isset($data['iscancellable']) && !$data['iscancellable']) ? false : true; - if (!is_array($data['elements'])) { + if (!is_array($data['elements']) || count($data['elements']) == 0) { throw new PieformException('Forms must have a list of elements'); } $this->elements = $data['elements']; @@ -588,6 +591,7 @@ // @todo masks attempts in pieform_render_element, including the error handling there @include_once('pieform/renderers/' . $this->renderer . '.php'); + // Form header $function = 'pieform_renderer_' . $this->renderer . '_header'; if (function_exists($function)) { @@ -939,10 +943,10 @@ */ public static function make_id($element) { if (isset($element['id'])) { - return hsc($element['id']); + return self::hsc($element['id']); } if (isset($element['name'])) { - return hsc($element['name']); + return self::hsc($element['name']); } return substr(md5(mt_rand()), 0, 4); } @@ -1008,7 +1012,7 @@ $result = ''; foreach ($elementattributes as $attribute) { if (isset($element[$attribute]) && $element[$attribute] !== '') { - $result .= ' ' . $attribute . '="' . hsc($element[$attribute]) . '"'; + $result .= ' ' . $attribute . '="' . self::hsc($element[$attribute]) . '"'; } } @@ -1059,6 +1063,16 @@ } /** + * HTML-escapes the given value + * + * @param string $text The text to escape + * @return string The text, HTML escaped + */ + public static function hsc($text) { + return htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); + } + + /** * Returns elements with errors on them * * @return array An array of elements with errors on them, the empty array @@ -1098,6 +1112,7 @@ } } } + } @@ -1126,18 +1141,18 @@ // Make sure that the function to render the element type is available $function = 'pieform_render_' . $element['type']; - if (!function_exists($function)) { - @include('pieform/elements/' . $element['type'] . '.php'); - if (!function_exists($function)) { - throw new PieformException('No such form element: ' . $element['type']); - } - } + //if (!function_exists($function)) { + // @include('pieform/elements/' . $element['type'] . '.php'); + // if (!function_exists($function)) { + // throw new PieformException('No such form element: ' . $element['type']); + // } + //} // Work out the renderer function required and make sure it exists if ($renderer = $form->get_renderer()) { $rendererfunction = 'pieform_renderer_' . $renderer; if (!function_exists($rendererfunction)) { - @include('pieform/renderers/' . $renderer . '.php'); + include('pieform/renderers/' . $renderer . '.php'); if (!function_exists($rendererfunction)) { throw new PieformException('No such form renderer: "' . $renderer . '"'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-11-17 13:01:34
|
Revision: 1 http://svn.sourceforge.net/pieforms/?rev=1&view=rev Author: oracleshinoda Date: 2006-11-17 05:01:30 -0800 (Fri, 17 Nov 2006) Log Message: ----------- Initial import of Pieforms. Teh busted at the moment, will fix tomorrow. Er, today even. Added Paths: ----------- pieforms/ pieforms/README pieforms/doc/ pieforms/src/ pieforms/src/pieform/ pieforms/src/pieform/elements/ pieforms/src/pieform/elements/button.php pieforms/src/pieform/elements/cancel.php pieforms/src/pieform/elements/checkbox.php pieforms/src/pieform/elements/date.php pieforms/src/pieform/elements/expiry.php pieforms/src/pieform/elements/fieldset.php pieforms/src/pieform/elements/file.php pieforms/src/pieform/elements/hidden.php pieforms/src/pieform/elements/html.php pieforms/src/pieform/elements/password.php pieforms/src/pieform/elements/radio.php pieforms/src/pieform/elements/select.php pieforms/src/pieform/elements/submit.php pieforms/src/pieform/elements/submitcancel.php pieforms/src/pieform/elements/text.php pieforms/src/pieform/elements/textarea.php pieforms/src/pieform/elements/userlist.php pieforms/src/pieform/elements/wysiwyg.php pieforms/src/pieform/renderers/ pieforms/src/pieform/renderers/div.php pieforms/src/pieform/renderers/multicolumntable.php pieforms/src/pieform/renderers/table.php pieforms/src/pieform/rules/ pieforms/src/pieform/rules/email.php pieforms/src/pieform/rules/maxlength.php pieforms/src/pieform/rules/minlength.php pieforms/src/pieform/rules/required.php pieforms/src/pieform/rules/validateoptions.php pieforms/src/pieform.php Added: pieforms/README =================================================================== --- pieforms/README (rev 0) +++ pieforms/README 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,54 @@ + Pieforms - Advanced web forms made easy + + Nigel McNie - http://nigel.mcnie.name/ + (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + + For installation instructions, please see the INSTALL file in this folder + +About Pieforms +-------------- + +Pieforms provides a simple, unified way to create, validate and process web +forms all with a common look and field. It supports many more types of form +controls (elements) than the standard HTML controls, for example date pickers +and ajax comboboxes. In addition, each element can have pluggable rules +applied to it, and the elements can be rendered inside custom containers, +allowing a lot of flexibility around form output. + +Pieforms also has a really simple API that makes writing forms very easy. For +most cases, you will simply define a hash describing your form and provide a +callback function that will be called if the form is submitted and passes +validation. However, there are plenty of hooks in place that allow much power +in how the forms are handled, both server and client side. + +Pieforms supports many advanced features, that are as easy to use as flicking +a switch. For example, change one flag and instantly your forms are submitted +by AJAX - validation still works fine, just your forms are submitted a whole +lot faster! + +Currently, Pieforms is under heavy development, but gains new features and +bugfixes almost every day. While releases will be made regularly, it's +probably best to work off of SVN for now. + +Requirements +------------ + +You've downloaded the PHP5 version of Pieforms. With some reasonably minimal +hacking it could be made to work with PHP4 (by making sure that the $form +object is passed around by reference with the & operator, removing some PHP5 +keywords like 'public' and 'private', and changing error handling to not +involve throwing exceptions), I am not going to do the work involved unless I +need it. If you want, you could get it working and provide a patch, which I +would maintain as a separate tree. But in reality, you should think about +moving your project to PHP5. + +License and Copyright +--------------------- + +Pieforms is licensed under the GNU GPL. For more information, please see the +COPYING file that comes with this package. + +Pieforms is copyright (C) 2006 Catalyst IT Ltd. + + + -- Nigel McNie <ni...@ca...> Added: pieforms/src/pieform/elements/button.php =================================================================== --- pieforms/src/pieform/elements/button.php (rev 0) +++ pieforms/src/pieform/elements/button.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,45 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a button. Custom buttons are rendered nearly the same as + * normal submit buttons, only their name is changed (for use by the Form class + * internally). + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ + +function form_render_button($element, $form) { + return '<input type="button"' + . Form::element_attributes($element) + . ' value="' . hsc($form->get_value($element)) . '">'; +} + +?> Added: pieforms/src/pieform/elements/cancel.php =================================================================== --- pieforms/src/pieform/elements/cancel.php (rev 0) +++ pieforms/src/pieform/elements/cancel.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,55 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a "cancel" button. Custom buttons are rendered nearly the same as + * normal submit buttons, only their name is changed (for use by the Form class + * internally). + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_cancel($element, Form $form) { + $attributes = Form::element_attributes($element); + $attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes); + $attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes); + return '<input type="submit"' + . $attributes + . ' value="' . hsc($form->get_value($element)) . '">'; +} + +// @todo how to support cancel buttons for ajax post? Possibly do a full post regardless... +// or allow the user to specify a javascript function to run... it could do document.location= +function form_get_value_js_cancel($element, $form) { + $formname = $form->get_name(); + $name = $element['name']; + return " data['{$name}_cancel'] = document.forms['$formname'].elements['{$name}_cancel'].value;\n"; +} + +?> Added: pieforms/src/pieform/elements/checkbox.php =================================================================== --- pieforms/src/pieform/elements/checkbox.php (rev 0) +++ pieforms/src/pieform/elements/checkbox.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,66 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a basic checkbox input. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_checkbox($element, Form $form) { + $checked = false; + if (!empty($element['value'])) { + $checked = true; + } + if ($form->get_value($element)) { + $checked = true; + } + else if (!$form->is_submitted() && !empty($element['checked'])) { + $checked = true; + } + + return '<input type="checkbox"' + . Form::element_attributes($element) + . ($checked ? ' checked="checked"' : '') + . '>'; +} + +function form_get_value_js_checkbox($element, Form $form) { + $formname = $form->get_name(); + $name = $element['name']; + return <<<EOF + if (document.forms['$formname'].elements['$name'].checked) { + data['$name'] = 'on'; + } + +EOF; +} + + +?> Added: pieforms/src/pieform/elements/date.php =================================================================== --- pieforms/src/pieform/elements/date.php (rev 0) +++ pieforms/src/pieform/elements/date.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,130 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a date picker, in the form of three dropdowns. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_date($element, Form $form) { + $result = ''; + $name = $element['name']; + $element['minyear'] = (isset($element['minyear'])) ? intval($element['minyear']) : 1950; + $element['maxyear'] = (isset($element['maxyear'])) ? intval($element['maxyear']) : 2050; + if (!isset($element['defaultvalue'])) { + $element['defaultvalue'] = array(date('Y'), date('m'), date('d')); + } + + // Year + $value = form_render_select_get_value('year', $element['minyear'], $element['maxyear'], $element, $form); + $year = '<select name="' . $name . "_year\">\n"; + for ($i = $element['minyear']; $i <= $element['maxyear']; $i++) { + $year .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; + } + $year .= "</select>\n"; + + $value = form_render_select_get_value('month', 1, 12, $element, $form); + $month = '<select name="' . $name . "_month\">\n"; + for ($i = 1; $i <= 12; $i++) { + $month .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . '>' . date('M', strtotime("2000-$i-01")) . "</option>\n"; + } + $month .= "</select>\n"; + + $value = form_render_select_get_value('day', 1, 31, $element, $form); + $day = '<select name="' . $name . "_day\">\n"; + for ($i = 1; $i <= 31; $i++) { + $day .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; + } + $day .= '</select>'; + + $result = $year . $month . $day; + return $result; +} + +/** gets the value explicitly from the request */ +function form_get_value_date($element, Form $form) { + $name = $element['name']; + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + $time = mktime(0, 0, 0, $global[$name . '_month'], $global[$name . '_day'], $global[$name . '_year']); + if (false === $time) { + return null; + } + return $time; +} + +function form_get_value_js_date($element, Form $form) { + $formname = $form->get_name(); + $name = $element['name']; + return <<<EOF + data['{$name}_year'] = document.forms['$formname'].elements['{$name}_year'].value; + data['{$name}_month'] = document.forms['$formname'].elements['{$name}_month'].value; + data['{$name}_day'] = document.forms['$formname'].elements['{$name}_day'].value; + +EOF; +} + +/** helper: used when rendering the element, to get the value for it */ +function form_render_select_get_value($timeperiod, $min, $max, $element, Form $form) { + static $lookup = array( + 'year' => 0, + 'month' => 1, + 'day' => 2 + ); + $index = $lookup[$timeperiod]; + + if (isset($element['value'][$index])) { + $value = $element['value'][$index]; + if ($value < $min || $value > $max) { + $value = $min; + } + return $value; + } + + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + if (isset($global[$element['name'] . '_' . $timeperiod])) { + $value = $global[$element['name'] . '_' . $timeperiod]; + if ($value < $min || $value > $max) { + $value = $min; + } + return $value; + } + + if (isset($element['defaultvalue'][$index])) { + $value = $element['defaultvalue'][$index]; + if ($value < $min || $value > $max) { + $value = $min; + } + return $value; + } + + return null; +} + +?> Added: pieforms/src/pieform/elements/expiry.php =================================================================== --- pieforms/src/pieform/elements/expiry.php (rev 0) +++ pieforms/src/pieform/elements/expiry.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,186 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a duration chooser, with a text box for a number and a + * select box to choose the units, in days, weeks, months, years, or 'no end date'. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_expiry($element, Form $form) { + $result = ''; + $name = $element['name']; + if (!isset($element['defaultvalue'])) { + $element['defaultvalue'] = null; + } + + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + + // Get the value of the element for rendering. The values of the + // two inputs are rendered, and the total time in seconds is + // stored in a hidden input. + + if (isset($element['value'])) { + $seconds = $element['value']; + $values = get_expiry_from_seconds($element['value']); + } + else if (isset($global[$element['name'] . '_number']) + && isset($global[$element['name'] . '_units'])) { + $values = array('number' => $global[$element['name'] . '_number'], + 'units' => $global[$element['name'] . '_units']); + $seconds = $values['number'] * seconds_in($values['units']); + } + else if (isset($element['defaultvalue'])) { + $seconds = $element['defaultvalue']; + $values = get_expiry_from_seconds($seconds); + } + else { + $values = array('number' => '', 'units' => 'noenddate'); + $seconds = null; + } + + $numberinput = '<input '; + if ($form->get_ajaxpost()) { + $numberinput .= 'onchange="' . $name . '_change()"'; + $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 .= 'name="' . $name . '_units" id="' . $name . '_units"' . ">\n"; + foreach ($allunits as $u) { + $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' . get_string($u) . "</option>\n"; + } + $uselect .= "</select>\n"; + + // The hidden input contains the value of the expiry in seconds + $hidden = '<input type="hidden" name="' . $name . '" id="' . $name . '" value="' . $seconds . "\">\n"; + + // 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 type="text/javascript" language="javascript"> +function {$name}_change() { + var seconds = null; + 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; + } + 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; +} + +function get_expiry_units() { + return array('days','weeks','months','years','noenddate'); +} + +function seconds_in($unit) { + $dayseconds = 60 * 60 * 24; + switch ($unit) { + case 'days' : return $dayseconds; + case 'weeks' : return $dayseconds * 7; + case 'months' : return $dayseconds * 30; + case 'years' : return $dayseconds * 365; + default : return null; + } +} + +function get_expiry_from_seconds($seconds) { + if ($seconds == null) { + return array('number' => '', 'units' => 'noenddate'); + } + // This needs work to produce sensible values; at the moment it will convert + // 60 days into 2 months; 70 days into 7 weeks, etc. + $yearseconds = seconds_in('years'); + if ($seconds % $yearseconds == 0 && $seconds > 0) { + return array('number' => (int) ($seconds / $yearseconds), 'units' => 'years'); + } + $monthseconds = seconds_in('months'); + if ($seconds % $monthseconds == 0 && $seconds > 0) { + return array('number' => (int) ($seconds / $monthseconds), 'units' => 'months'); + } + $weekseconds = seconds_in('weeks'); + if ($seconds % $weekseconds == 0 && $seconds > 0) { + return array('number' => (int) ($seconds / $weekseconds), 'units' => 'weeks'); + } + $dayseconds = seconds_in('days'); + if ($seconds % $dayseconds == 0) { + return array('number' => (int) ($seconds / $dayseconds), 'units' => 'days'); + } + return null; +} + +// /** gets the value explicitly from the request */ +// function form_get_value_expiry($element, Form $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); +// } + +?> Added: pieforms/src/pieform/elements/fieldset.php =================================================================== --- pieforms/src/pieform/elements/fieldset.php (rev 0) +++ pieforms/src/pieform/elements/fieldset.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,54 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a fieldset. Fieldsets contain other elements, and do not count as a + * "true" element, in that they do not have a value and cannot be validated. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_fieldset($element, Form $form) { + $result = "\n<fieldset>\n"; + if (isset($element['legend'])) { + $result .= '<legend>' . hsc($element['legend']) . "</legend>\n"; + } + + foreach ($element['elements'] as $subname => $subelement) { + if ($subelement['type'] == 'hidden') { + throw new FormError("You cannot put hidden elements in fieldsets"); + } + $result .= "\t" . form_render_element($subelement, $form); + } + + $result .= "</fieldset>\n"; + return $result; +} + +?> Added: pieforms/src/pieform/elements/file.php =================================================================== --- pieforms/src/pieform/elements/file.php (rev 0) +++ pieforms/src/pieform/elements/file.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,61 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a basic HTML <input type="file"> element. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_file($element, Form $form) { + return '<input type="file"' + . Form::element_attributes($element) . '>'; +} + +function form_get_value_file($element, Form $form) { + if (isset($_FILES[$element['name']])) { + if (!$_FILES[$element['name']]['error']) { + return $_FILES[$element['name']]; + } + return null; + } +} + +function form_is_empty_file($value, $element) { + if (isset($_FILES[$element['name']]) && !$_FILES[$element['name']]['error']) { + return false; + } + return true; +} + +// @todo: provide a mechanism for elements to claim they deal with files. +// If this is triggered, the forms is forced to POST and the enctype stuff +// is added. +// @todo is enctype required for ajax submission of files? +?> Added: pieforms/src/pieform/elements/hidden.php =================================================================== --- pieforms/src/pieform/elements/hidden.php (rev 0) +++ pieforms/src/pieform/elements/hidden.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,52 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a hidden element. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_hidden($element, Form $form) { + unset($element['tabindex']); + $value = $form->get_value($element); + if (is_array($value)) { + $result = ''; + foreach ($value as $k => $v) { + $result .= '<input type="hidden" name="' . hsc($element['name']) + . '[' . hsc($k) . ']" value="' . hsc($v) . "\">\n"; + } + return $result; + } + return '<input type="hidden"' + . Form::element_attributes($element) + . ' value="' . hsc($form->get_value($element)) . "\">\n"; +} + +?> Added: pieforms/src/pieform/elements/html.php =================================================================== --- pieforms/src/pieform/elements/html.php (rev 0) +++ pieforms/src/pieform/elements/html.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,41 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Penny Leach <pe...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a way to pass in html that gets rendered + * by the render (as opposed to the markup element) + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_html($element, $form) { + return $element['value']; +} + +?> Added: pieforms/src/pieform/elements/password.php =================================================================== --- pieforms/src/pieform/elements/password.php (rev 0) +++ pieforms/src/pieform/elements/password.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,53 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a password field + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_password($element, $form) { + return '<input type="password"' + . Form::element_attributes($element) + . ' value="' . hsc($form->get_value($element)) . '">'; +} + +function form_get_value_password($element, Form $form) { + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + if (isset($global[$element['name']])) { + return $global[$element['name']]; + } + if (isset($element['value'])) { + return $element['value']; + } + return null; +} + +?> Added: pieforms/src/pieform/elements/radio.php =================================================================== --- pieforms/src/pieform/elements/radio.php (rev 0) +++ pieforms/src/pieform/elements/radio.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,88 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a set of radio buttons for a form + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_radio($element, Form $form) { + if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { + throw new FormException('Radio elements should have at least one option'); + } + + $result = ''; + $form_value = $form->get_value($element); + $id = $element['id']; + + $separator = "\n"; + if (isset($element['separator'])) { + $separator = $element['separator'] . $separator; + } + + foreach ($element['options'] as $value => $text) { + $uid = $id . substr(md5(microtime()), 0, 4); + $element['id'] = $uid; + $result .= '<input type="radio"' + . Form::element_attributes($element) + . ' value="' . hsc($value) . '"' + . (($form_value == $value) ? ' checked="checked"' : '') + . "> <label for=\"$uid\">" . hsc($text) . "</label>$separator"; + } + $result = substr($result, 0, -strlen($separator)); + + return $result; +} + +/** + * radio doesn't need a function to get a value from phpland because it comes + * through correctly from the request... however in javascript land things are + * harder. + * + * @todo maybe later: make the get_value_js functions return a javascript function, + * to keep their stuff in its own scope. Maybe. If js scoping rules mean this will help. + */ +function form_get_value_js_radio($element, Form $form) { + $formname = $form->get_name(); + $name = $element['name']; + return <<<EOF + var radio = filter(function(radio) { return radio.checked; }, document.forms['$formname'].elements['$name']); + data['$name'] = radio[0].value; + +EOF; +} + +function form_render_radio_set_attributes($element) { + $element['nolabel'] = true; + $element['rules']['validateoptions'] = true; + return $element; +} + +?> Added: pieforms/src/pieform/elements/select.php =================================================================== --- pieforms/src/pieform/elements/select.php (rev 0) +++ pieforms/src/pieform/elements/select.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,107 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a dropdown list, including support for multiple choices. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_select($element, Form $form) { + if (!empty($element['multiple'])) { + $element['name'] .= '[]'; + } + + if (!empty($element['collapseifoneoption']) && count($element['options']) == 1) { + foreach ($element['options'] as $key => $value) { + $result = $value . '<input type="hidden" name="' . $element['name'] . '" value="' . $key . '">'; + } + return $result; + } + + $result = '<select' + . Form::element_attributes($element) + . (!empty($element['multiple']) ? ' multiple="multiple"' : '') + . ">\n"; + if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { + $result .= "\t<option></option>\n"; + log_warn('Select elements should have at least one option'); + } + + if (empty($element['multiple'])) { + $values = array($form->get_value($element)); + } + else { + if (isset($element['value'])) { + $values = (array) $element['value']; + } + else if (isset($_POST[$element['name']])) { + $values = (array) $_POST[$element['name']]; + } + else if (isset($element['defaultvalue'])) { + $values = (array) $element['defaultvalue']; + } + else { + $values = array(); + } + } + foreach ($element['options'] as $key => $value) { + if (in_array($key, $values)) { + $selected = ' selected="selected"'; + } + else { + $selected = ''; + } + $result .= "\t<option value=\"" . hsc($key) . "\"$selected>" . hsc($value) . "</option>\n"; + } + + $result .= '</select>'; + return $result; +} + +function form_get_value_js_select($element, Form $form) { + $formname = $form->get_name(); + $name = $element['name']; + if ($element['collapseifoneoption']) { + return " data['$name'] = document.forms['$formname'].elements['$name'].value;\n"; + } + return <<<EOF + var select = filter(function(option) { return option.selected; }, document.forms['$formname'].elements['$name'].options); + data['$name'] = map(function(o) { return o.value; }, select); + +EOF; +} + +function form_render_select_set_attributes($element) { + $element['collapseifoneoption'] = true; + $element['rules']['validateoptions'] = true; + return $element; +} + +?> Added: pieforms/src/pieform/elements/submit.php =================================================================== --- pieforms/src/pieform/elements/submit.php (rev 0) +++ pieforms/src/pieform/elements/submit.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,47 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a submit button + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_submit($element, $form) { + return '<input type="submit"' + . Form::element_attributes($element) + . ' value="' . hsc($form->get_value($element)) . '">'; +} + +function form_render_submit_set_attributes($element) { + $element['ajaxmessages'] = true; + return $element; +} + +?> Added: pieforms/src/pieform/elements/submitcancel.php =================================================================== --- pieforms/src/pieform/elements/submitcancel.php (rev 0) +++ pieforms/src/pieform/elements/submitcancel.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,51 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a submit and cancel button + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_submitcancel($element, Form $form) { + require_once('submit.php'); + require_once('cancel.php'); + $submitelement = $element; + $submitelement['value'] = $element['value'][0]; + $cancelelement = $element; + $cancelelement['value'] = $element['value'][1]; + return form_render_submit($submitelement, $form) . ' ' . form_render_cancel($cancelelement, $form); +} + +function form_render_submitcancel_set_attributes($element) { + $element['ajaxmessages'] = true; + return $element; +} + +?> Added: pieforms/src/pieform/elements/text.php =================================================================== --- pieforms/src/pieform/elements/text.php (rev 0) +++ pieforms/src/pieform/elements/text.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,42 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a basic text field input. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_text($element, $form) { + return '<input type="text"' + . Form::element_attributes($element) + . ' value="' . hsc($form->get_value($element)) . '">'; +} + +?> Added: pieforms/src/pieform/elements/textarea.php =================================================================== --- pieforms/src/pieform/elements/textarea.php (rev 0) +++ pieforms/src/pieform/elements/textarea.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,67 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a basic HTML <textarea> element. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_textarea($element, $form) { + $rows = $cols = $style = ''; + if (isset($element['height'])) { + $style .= 'height:' . $element['height'] . ';'; + $rows = (intval($element['height'] > 0)) ? ceil(intval($element['height']) / 10) : 1; + } + elseif (isset($element['rows'])) { + $rows = $element['rows']; + } + else { + log_warn('No value for rows or height specified for textarea ' . $element['name']); + } + + if (isset($element['width'])) { + $style .= 'width:' . $element['width'] . ';'; + $cols = (intval($element['width'] > 0)) ? ceil(intval($element['width']) / 10) : 1; + } + elseif (isset($element['cols'])) { + $cols = $element['cols']; + } + else { + log_warn('No value for cols or width specified for textarea ' . $element['name']); + } + $element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style; + return '<textarea' + . (($rows) ? ' rows="' . $rows . '"' : '') + . (($cols) ? ' cols="' . $cols . '"' : '') + . Form::element_attributes($element, array('maxlength', 'size')) + . '>' . hsc($form->get_value($element)) . '</textarea>'; +} + +?> Added: pieforms/src/pieform/elements/userlist.php =================================================================== --- pieforms/src/pieform/elements/userlist.php (rev 0) +++ pieforms/src/pieform/elements/userlist.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,106 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Martyn Smith <ma...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Provides a basic text field input. + * + * @todo this is just lies ... + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_userlist($element, Form $form) { + $smarty = smarty(); + + $smarty->left_delimiter = '{{'; + $smarty->right_delimiter = '}}'; + + $value = $form->get_value($element); + + if (!is_array($value) && isset($element['defaultvalue']) && is_array($element['defaultvalue'])) { + $value = $element['defaultvalue']; + } + + if (is_array($value) && count($value)) { + $members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname'); + + foreach($members as &$member) { + $member = display_name($member); + } + + $smarty->assign('options',$members); + $smarty->assign('value', join(',',$value)); + } + + $smarty->assign('name', $element['name']); + if (!empty($element['filter'])) { + $smarty->assign('filter', true); + } + + return $smarty->fetch('form/userlist.tpl'); +} + +function form_get_value_userlist($element, Form $form) { + $name = $element['name']; + + $global = ($form->get_method() == 'get') ? $_GET : $_POST; + + if (isset($global[$name])) { + $value = $global[$name]; + + if ($value == '') { + return array(); + } + + if (preg_match('/^(\d+(,\d+)*)$/',$value)) { + return array_map('intval', explode(',', $value)); + } + + throw new FormException("Invalid value for userlist form element '$name' = '$value'"); + } + + return null; +} + +function form_is_empty_userlist($value, $element) { + if (is_array($value) && count($value)) { + return false; + } + + return true; +} + +function form_render_userlist_set_attributes($element) { + // By default, use the filter select box + if (!isset($element['filter'])) { + $element['filter'] = true; + } + return $element; +} + +?> Added: pieforms/src/pieform/elements/wysiwyg.php =================================================================== --- pieforms/src/pieform/elements/wysiwyg.php (rev 0) +++ pieforms/src/pieform/elements/wysiwyg.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,79 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-element + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Renders a textarea, but with extra javascript to turn it into a wysigyw + * textarea. + * + * Currently this is just a mirror of the textarea element, but it will change + * a bit later. + * + * @param array $element The element to render + * @param Form $form The form to render the element for + * @return string The HTML for the element + */ +function form_render_wysiwyg($element, $form) { + $rows = $cols = $style = ''; + if (isset($element['height'])) { + $style .= 'height:' . $element['height'] . ';'; + $rows = (intval($element['height'] > 0)) ? ceil(intval($element['height']) / 10) : 1; + } + elseif (isset($element['rows'])) { + $rows = $element['rows']; + } + else { + log_warn('No value for rows or height specified for textarea ' . $element['name']); + } + + if (isset($element['width'])) { + $style .= 'width:' . $element['width'] . ';'; + $cols = (intval($element['width'] > 0)) ? ceil(intval($element['width']) / 10) : 1; + } + elseif (isset($element['cols'])) { + $cols = $element['cols']; + } + else { + log_warn('No value for cols or width specified for textarea ' . $element['name']); + } + $element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style; + return '<textarea' + . (($rows) ? ' rows="' . $rows . '"' : '') + . (($cols) ? ' cols="' . $cols . '"' : '') + . Form::element_attributes($element, array('maxlength', 'size')) + . '>' . hsc($form->get_value($element)) . '</textarea>'; +} + +/** + * @todo document: basically, the required rule now works better, as stripping + * tags out takes away a whole bunch of hidden stuff + */ +function form_is_empty_wysiwyg($value, $element) { + return strip_tags($value) === ''; +} + +?> Added: pieforms/src/pieform/renderers/div.php =================================================================== --- pieforms/src/pieform/renderers/div.php (rev 0) +++ pieforms/src/pieform/renderers/div.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,71 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-renderer + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +defined('INTERNAL') || die(); + +/** + * Default renderer - renders form elements inside <div>s. + * + * @param string $builtelement The element, already built + * @param array $rawelement The element in raw form, for looking up + * information about it. + * @return string The element rendered inside an appropriate + * container. + */ +function form_renderer_div($builtelement, $rawelement) { + // Set the class of the enclosing <div> to match that of the element + $result = '<div'; + if ($rawelement['class']) { + $result .= ' class="' . $rawelement['class'] . '"'; + } + $result .= '>'; + + if (isset($rawelement['title']) && $rawelement['type'] != 'fieldset') { + $result .= '<label for="' . $rawelement['id'] . '">' . hsc($rawelement['title']) . '</label>'; + } + + $result .= $builtelement; + + // Contextual help + if (!empty($rawelement['help'])) { + $result .= ' <span class="help"><a href="#" title="' . hsc($rawelement['help']) . '">?</a></span>'; + } + + // Description - optional description of the element, or other note that should be visible + // on the form itself (without the user having to hover over contextual help + if (!empty($rawelement['description'])) { + $result .= '<div class="description"> ' . hsc($rawelement['description']) . "</div>"; + } + + if (!empty($rawelement['error'])) { + $result .= '<div class="errmsg">' . hsc($rawelement['error']) . '</div>'; + } + + $result .= "</div>\n"; + return $result; +} + +?> Added: pieforms/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms/src/pieform/renderers/multicolumntable.php (rev 0) +++ pieforms/src/pieform/renderers/multicolumntable.php 2006-11-17 13:01:30 UTC (rev 1) @@ -0,0 +1,113 @@ +<?php +/** + * This program is part of Mahara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package mahara + * @subpackage form-renderer + * @author Penny Leach <pe...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + *... [truncated message content] |