[Pieforms-commit] SF.net SVN: pieforms: [1] pieforms
Status: Alpha
Brought to you by:
oracleshinoda
|
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] |