\n";
$selectoptions = '';
return $select;
}
}
/**
* Generate a group selection box.
*
* @param string $name The name of the selection box.
* @param array|string $selected Array/string of the selected items.
* @param array $options Array of options (class, id, multiple, size)
* @return string The built select box.
*/
function generate_group_select($name, $selected=array(), $options=array())
{
global $cache;
$select = "read('usergroups');
if(!is_array($selected))
{
$selected = array($selected);
}
foreach($groups_cache as $group)
{
$selected_add = "";
if(in_array($group['gid'], $selected))
{
$selected_add = " selected=\"selected\"";
}
$select .= "".htmlspecialchars_uni($group['title'])." ";
}
$select .= " ";
return $select;
}
/**
* Generate a prefix selection box.
*
* @param string $name The name of the selection box.
* @param array|string $selected Array/string of the selected items.
* @param array $options Array of options (class, id, multiple, size)
* @return string The built select box.
*/
function generate_prefix_select($name, $selected=array(), $options=array())
{
global $cache;
$select = "read('threadprefixes');
if(!is_array($selected))
{
$selected = array($selected);
}
foreach($prefix_cache as $prefix)
{
$selected_add = "";
if(in_array($prefix['pid'], $selected))
{
$selected_add = " selected=\"selected\"";
}
$select .= "".htmlspecialchars_uni($prefix['prefix'])." ";
}
$select .= " ";
return $select;
}
/**
* Generate a submit button.
*
* @param string $value The value for the submit button.
* @param array $options Array of options for the submit button (class, id, name, dsiabled, onclick)
* @return string The generated submit button.
*/
function generate_submit_button($value, $options=array())
{
$input = " generate_radio_button($name, $yes_value, $lang->yes, $yes_options);
$no = $this->generate_radio_button($name, $no_value, $lang->no, $no_options);
return $yes." ".$no;
}
/**
* Generate an on/off radio button choice.
*
* @param string $name The name of the on/off choice field.
* @param int $value The value that should be checked.
* @param boolean $int Using integers for the checkbox?
* @param array $on_options Array of options for the on checkbox (@see generate_radio_button)
* @param array $off_options Array of options for the off checkbox (@see generate_radio_button)
* @return string The generated on/off radio button.
*/
function generate_on_off_radio($name, $value=1, $int=true, $on_options=array(), $off_options = array())
{
global $lang;
// Checked status
if($value == "off" || (int) $value !== 1)
{
$off_checked = 1;
$on_checked = 0;
}
else
{
$on_checked = 1;
$off_checked = 0;
}
// Element value
if($int == true)
{
$on_value = 1;
$off_value = 0;
}
else
{
$on_value = "on";
$off_value = "off";
}
// Set the options straight
if(!isset($on_options['class']))
{
$on_options['class'] = '';
}
if(!isset($off_options['class']))
{
$off_options['class'] = '';
}
$on_options['class'] = "radio_on ".$on_options['class'];
$on_options['checked'] = $on_checked;
$off_options['class'] = "radio_off ".$off_options['class'];
$off_options['checked'] = $off_checked;
$on = $this->generate_radio_button($name, $on_value, $lang->on, $on_options);
$off = $this->generate_radio_button($name, $off_value, $lang->off, $off_options);
return $on." ".$off;
}
/**
* @param string $name
* @param int $day
* @param int $month
* @param int $year
*
* @return string
*/
function generate_date_select($name, $day=0,$month=0,$year=0)
{
global $lang;
$months = array(
1 => $lang->january,
2 => $lang->february,
3 => $lang->march,
4 => $lang->april,
5 => $lang->may,
6 => $lang->june,
7 => $lang->july,
8 => $lang->august,
9 => $lang->september,
10 => $lang->october,
11 => $lang->november,
12 => $lang->december,
);
// Construct option list for days
$days = array();
for($i = 1; $i <= 31; ++$i)
{
$days[$i] = $i;
}
if(!$day)
{
$day = date("j", TIME_NOW);
}
if(!$month)
{
$month = date("n", TIME_NOW);
}
if(!$year)
{
$year = date("Y", TIME_NOW);
}
$built = $this->generate_select_box($name.'_day', $days, (int)$day, array('id' => $name.'_day'))." ";
$built .= $this->generate_select_box($name.'_month', $months, (int)$month, array('id' => $name.'_month'))." ";
$built .= $this->generate_numeric_field($name.'_year', $year, array('id' => $name.'_year', 'style' => 'width: 100px;', 'min' => 0));
return $built;
}
/**
* Output a row of buttons in a wrapped container.
*
* @param array $buttons Array of the buttons (html) to output.
* @return string The submit wrapper (optional)
*/
function output_submit_wrapper($buttons)
{
global $plugins;
$buttons = $plugins->run_hooks("admin_form_output_submit_wrapper", $buttons);
$return = "\n";
foreach($buttons as $button)
{
$return .= $button." \n";
}
$return .= "
\n";
if($this->_return == false)
{
echo $return;
}
else
{
return $return;
}
}
/**
* Finish up a form.
*
* @return string The ending form tag (optional)
*/
function end()
{
global $plugins;
$plugins->run_hooks("admin_form_end", $this);
if($this->_return == false)
{
echo "";
}
else
{
return "";
}
}
}
/**
* Generate a form container.
*/
class DefaultFormContainer
{
/** @var Table */
private $_container;
/** @var string */
public $_title;
/**
* Initialise the new form container.
*
* @param string $title The title of the form container
* @param string $extra_class An additional class to apply if we have one.
*/
function __construct($title='', $extra_class='')
{
$this->_container = new Table;
$this->extra_class = $extra_class;
$this->_title = $title;
}
/**
* Output a header row of the form container.
*
* @param string $title The header row label.
* @param array $extra Array of extra information for this header cell (class, style, colspan, width)
*/
function output_row_header($title, $extra=array())
{
$this->_container->construct_header($title, $extra);
}
/**
* Output a row of the form container.
*
* @param string $title The title of the row.
* @param string $description The description of the row/field.
* @param string $content The HTML content to show in the row.
* @param string $label_for The ID of the control this row should be a label for.
* @param array $options Array of options for the row cell.
* @param array $row_options Array of options for the row container.
*/
function output_row($title, $description="", $content="", $label_for="", $options=array(), $row_options=array())
{
global $plugins;
$pluginargs = array(
'title' => &$title,
'description' => &$description,
'content' => &$content,
'label_for' => &$label_for,
'options' => &$options,
'row_options' => &$row_options,
'this' => &$this
);
$plugins->run_hooks("admin_formcontainer_output_row", $pluginargs);
$row = $for = '';
if($label_for != '')
{
$for = " for=\"{$label_for}\"";
}
if($title)
{
$row = "{$title} ";
}
if($description != '')
{
$row .= "\n{$description}
\n";
}
$row .= "{$content}
\n";
$this->_container->construct_cell($row, $options);
if(!isset($options['skip_construct']))
{
$this->_container->construct_row($row_options);
}
}
/**
* Output a row cell for a table based form row.
*
* @param string $data The data to show in the cell.
* @param array $options Array of options for the cell (optional).
*/
function output_cell($data, $options=array())
{
$this->_container->construct_cell($data, $options);
}
/**
* Build a row for the table based form row.
*
* @param array $extra Array of extra options for the cell (optional).
*/
function construct_row($extra=array())
{
$this->_container->construct_row($extra);
}
/**
* return the cells of a row for the table based form row.
*
* @param string $row_id The id of the row.
* @param boolean $return Whether or not to return or echo the resultant contents.
* @return string The output of the row cells (optional).
*/
function output_row_cells($row_id, $return=false)
{
if(!$return)
{
echo $this->_container->output_row_cells($row_id, $return);
}
else
{
return $this->_container->output_row_cells($row_id, $return);
}
}
/**
* Count the number of rows in the form container. Useful for displaying a 'no rows' message.
*
* @return int The number of rows in the form container.
*/
function num_rows()
{
return $this->_container->num_rows();
}
/**
* Output the end of the form container row.
*
* @param boolean $return Whether or not to return or echo the resultant contents.
* @return string The output of the form container (optional).
*/
function end($return=false)
{
global $plugins;
$hook = array(
'return' => &$return,
'this' => &$this
);
$plugins->run_hooks("admin_formcontainer_end", $hook);
if($return == true)
{
return $this->_container->output($this->_title, 1, "general form_container {$this->extra_class}", true);
}
else
{
echo $this->_container->output($this->_title, 1, "general form_container {$this->extra_class}", false);
}
}
}