(mixed) custom id attribute value
* if numeric value is passed it'll be just appended to the name e.g. {filed-name}-{value}
* if false is passed id will be not created
* if empty string is passed (or no 'id' option is found)
* in all other cases the value will be used as field id
* default: empty string
*
* - class => (string) field class(es)
* Example: 'tbox select class1 class2 class3'
* NOTE: this will override core classes, so you have to explicit include them!
* default: empty string
*
* - size => (int) size attribute value (used when needed)
* default: 40
*
* - title (string) title attribute
* default: empty string (omitted)
*
* - readonly => (bool) readonly attribute
* default: false
*
* - selected => (bool) selected attribute (used when needed)
* default: false
*
* checked => (bool) checked attribute (used when needed)
* default: false
* - disabled => (bool) disabled attribute
* default: false
*
* - tabindex => (int) tabindex attribute value
* default: inner tabindex counter
*
* - other => (string) additional data
* Example: 'attribute1="value1" attribute2="value2"'
* default: empty string
*/
class e_form
{
var $_tabindex_counter = 0;
var $_tabindex_enabled = true;
var $_cached_attributes = array();
/**
* @var user_class
*/
var $_uc;
function e_form($enable_tabindex = false)
{
$this->_tabindex_enabled = $enable_tabindex;
$e107 = &e107::getInstance();
$this->_uc = &$e107->user_class;
}
function text($name, $value, $maxlength = 200, $options = array())
{
$options = $this->format_options('text', $name, $options);
//never allow id in format name-value for text fields
return "get_attributes($options, $name)." />";
}
function iconpicker($name, $default, $label, $sc_parameters = '', $ajax = true)
{
// TODO - Hide the element, and display the icon itself after it has been chosen.
// eg.
// The button itself could be replaced with an icon just for this purpose.
$e107 = &e107::getInstance();
$id = $this->name2id($name);
$sc_parameters .= '&id='.$id;
$jsfunc = $ajax ? "e107Ajax.toggleUpdate('{$id}-iconpicker', '{$id}-iconpicker-cn', 'sc:iconpicker=".urlencode($sc_parameters)."', '{$id}-iconpicker-ajax', { overlayElement: '{$id}-iconpicker-button' })" : "e107Helper.toggle('{$id}-iconpicker')";
$ret = $this->text($name, $default).$this->admin_button($name.'-iconpicker-button', $label, 'action', '', array('other' => "onclick=\"{$jsfunc}\""));
$ret .= "
";
return $ret;
}
/**
* Date field with popup calendar
* @param name => string - the name of the field
* @param datestamp => UNIX timestamp - default value of the field
**/
function datepicker($name, $datestamp=false)
{
global $pref;
//TODO can some of these values be set in an admin section somewhere so they are set per site?
//TODO allow time option ?
$cal = new DHTML_Calendar(true);
$cal_options['showsTime'] = false;
$cal_options['showOthers'] = false;
$cal_options['weekNumbers'] = false;
//TODO use $prefs values for format?
$cal_options['ifFormat'] = $pref['inputdate'];
$cal_options['timeFormat'] = "24";
$cal_attrib['class'] = "tbox";
$cal_attrib['size'] = "12";
$cal_attrib['name'] = $name;
if ($datestamp)
{
//TODO use $prefs values for format?
$cal_attrib['value'] = date("d/m/Y H:i:s", $datestamp);
$cal_attrib['value'] = date("d/m/Y", $datestamp);
}
return $cal->make_input_field($cal_options, $cal_attrib);
}
function file($name, $options = array())
{
$options = $this->format_options('file', $name, $options);
//never allow id in format name-value for text fields
return "get_attributes($options, $name)." />";
}
function password($name, $maxlength = 50, $options = array())
{
$options = $this->format_options('text', $name, $options);
//never allow id in format name-value for text fields
return "get_attributes($options, $name)." />";
}
function textarea($name, $value, $rows = 15, $cols = 40, $options = array())
{
$options = $this->format_options('textarea', $name, $options);
//never allow id in format name-value for text fields
return "";
}
function bbarea($name, $value, $help_mod = '', $help_tagid='')
{
$options = array('class' => 'tbox large e-wysiwyg');
if(!deftrue('e_WYSIWYG'))
{
require_once(e_HANDLER."ren_help.php");
$options['other'] = "onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'";
$bbbar = display_help($help_tagid, $help_mod);
}
$ret = "
\n\n\n";
}
// The 2 functions below are for demonstration purposes only, and may be moved/modified before release.
function filterType($fieldarray)
{
define("e_AJAX_REQUEST",TRUE);
$text .= "";
return $text;
}
function filterValue($type,$fields)
{
if($type)
{
switch ($fields[$type]['type']) {
case "datestamp":
return "[date field]";
break;
case "boolean":
return "";
break;
case "user":
return "";
break;
default :
return $this->text('searchquery', '', 50);
}
}
else
{
return $this->text('searchquery', '', 50);
}
// This needs to be dynamic for the various form types, and be loaded via ajax.
}
/**
* Generates a batch options select component
* This component is generally associated with a table of items where one or more rows in the table can be selected (using checkboxes).
* The list options determine some processing that wil lbe applied to all checked rows when the form is submitted.
* @param options => array - associative array of option elements, keyed on the option value
* @param ucOptions => array - associative array of userclass option groups to display, keyed on the option value prefix
* @return the HTML for the form component
*/
function batchoptions($options, $ucOptions=null) {
$text = "