2003-06-11 18:59:14 -04:00
|
|
|
<?php
|
2003-06-12 18:48:52 -04:00
|
|
|
require_once('../wp-config.php');
|
2003-06-11 18:59:14 -04:00
|
|
|
/**
|
|
|
|
** get_option_widget()
|
|
|
|
** parameters:
|
|
|
|
** option_result - result set containing option_id, option_name, option_type,
|
|
|
|
** option_value, option_description, option_admin_level
|
|
|
|
** editable - flag to determine whether the returned widget will be editable
|
|
|
|
**/
|
|
|
|
function get_option_widget($option_result, $editable, $between)
|
|
|
|
{
|
2004-05-24 04:22:18 -04:00
|
|
|
global $wpdb;
|
2003-06-11 19:19:21 -04:00
|
|
|
$disabled = $editable ? '' : 'disabled';
|
|
|
|
|
2003-06-12 18:48:52 -04:00
|
|
|
switch ($option_result->option_type) {
|
2003-06-11 18:59:14 -04:00
|
|
|
case 1: // integer
|
|
|
|
case 3: // string
|
2003-08-05 18:44:38 -04:00
|
|
|
case 8: // float
|
2003-06-12 18:48:52 -04:00
|
|
|
case 6: // range -- treat same as integer for now!
|
|
|
|
if (($option_result->option_type == 1) || ($option_result->option_type == 1)) {
|
2003-06-11 18:59:14 -04:00
|
|
|
$width = 6;
|
2003-06-12 18:48:52 -04:00
|
|
|
} else {
|
2003-06-11 18:59:14 -04:00
|
|
|
$width = $option_result->option_width;
|
2003-06-12 18:48:52 -04:00
|
|
|
}
|
2003-06-11 18:59:14 -04:00
|
|
|
return <<<TEXTINPUT
|
|
|
|
<label for="$option_result->option_name">$option_result->option_name</label>$between
|
2003-06-11 19:19:21 -04:00
|
|
|
<input type="text" name="$option_result->option_name" size="$width" value="$option_result->option_value" $disabled/>
|
2003-06-11 18:59:14 -04:00
|
|
|
TEXTINPUT;
|
|
|
|
//break;
|
2003-06-12 18:48:52 -04:00
|
|
|
|
2003-06-11 18:59:14 -04:00
|
|
|
case 2: // boolean
|
2004-06-11 14:23:12 -04:00
|
|
|
$true_selected = ($option_result->option_value == '1') ? 'selected="selected"' : '';
|
|
|
|
$false_selected = ($option_result->option_value == '0') ? 'selected="selected"' : '';
|
2003-06-11 18:59:14 -04:00
|
|
|
return <<<BOOLSELECT
|
|
|
|
<label for="$option_result->option_name">$option_result->option_name</label>$between
|
2003-06-11 19:19:21 -04:00
|
|
|
<select name="$option_result->option_name" $disabled>
|
2003-06-12 18:48:52 -04:00
|
|
|
<option value="1" $true_selected>true</option>
|
|
|
|
<option value="0" $false_selected>false</option>
|
2003-06-11 18:59:14 -04:00
|
|
|
</select>
|
|
|
|
BOOLSELECT;
|
|
|
|
//break;
|
2003-06-12 18:48:52 -04:00
|
|
|
|
2003-06-11 18:59:14 -04:00
|
|
|
case 5: // select
|
|
|
|
$ret = <<<SELECT
|
|
|
|
<label for="$option_result->option_name">$option_result->option_name</label>$between
|
2004-01-02 22:19:56 -05:00
|
|
|
<select name="$option_result->option_name" id="$option_result->option_name" $disabled>
|
2003-06-11 18:59:14 -04:00
|
|
|
SELECT;
|
|
|
|
|
2003-06-12 18:48:52 -04:00
|
|
|
$select = $wpdb->get_results("SELECT optionvalue, optionvalue_desc "
|
2004-05-24 04:22:18 -04:00
|
|
|
."FROM $wpdb->optionvalues "
|
2003-06-11 18:59:14 -04:00
|
|
|
."WHERE option_id = $option_result->option_id "
|
|
|
|
."ORDER BY optionvalue_seq");
|
2003-06-12 18:48:52 -04:00
|
|
|
if ($select) {
|
|
|
|
foreach($select as $option) {
|
2003-06-11 18:59:14 -04:00
|
|
|
$ret .= '<option value="'.$option->optionvalue.'"';
|
|
|
|
//error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
|
2003-06-12 18:48:52 -04:00
|
|
|
if ($option_result->option_value == $option->optionvalue) {
|
2004-06-11 14:23:12 -04:00
|
|
|
$ret .=' selected="selected"';
|
2003-06-11 18:59:14 -04:00
|
|
|
}
|
|
|
|
$ret .= ">$option->optionvalue_desc</option>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ret .= '</select>';
|
|
|
|
return $ret;
|
|
|
|
//break;
|
2003-06-12 18:48:52 -04:00
|
|
|
|
|
|
|
case 7: // SQL select
|
|
|
|
// first get the sql to run
|
2004-05-24 04:22:18 -04:00
|
|
|
$sql = $wpdb->get_var("SELECT optionvalue FROM $wpdb->optionvalues WHERE option_id = $option_result->option_id");
|
2003-06-12 18:48:52 -04:00
|
|
|
if (!$sql) {
|
|
|
|
return $option_result->option_name . $editable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we may need to do table name substitution
|
2004-01-02 22:19:56 -05:00
|
|
|
eval("include('../wp-config.php');\$sql = \"$sql\";");
|
2003-06-12 18:48:52 -04:00
|
|
|
|
|
|
|
$ret = <<<SELECT
|
|
|
|
<label for="$option_result->option_name">$option_result->option_name</label>$between
|
|
|
|
<select name="$option_result->option_name" $disabled>
|
|
|
|
SELECT;
|
2004-01-02 22:19:56 -05:00
|
|
|
|
2003-06-12 18:48:52 -04:00
|
|
|
$select = $wpdb->get_results("$sql");
|
|
|
|
if ($select) {
|
|
|
|
foreach($select as $option) {
|
|
|
|
$ret .= '<option value="'.$option->value.'"';
|
|
|
|
//error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
|
|
|
|
if ($option_result->option_value == $option->value) {
|
2004-06-11 14:23:12 -04:00
|
|
|
$ret .=' selected="selected"';
|
2003-06-12 18:48:52 -04:00
|
|
|
}
|
|
|
|
$ret .= ">$option->label</option>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ret .= '</select>';
|
|
|
|
return $ret;
|
|
|
|
//break;
|
2003-06-11 18:59:14 -04:00
|
|
|
|
|
|
|
} // end switch
|
|
|
|
return $option_result->option_name . $editable;
|
|
|
|
} // end function get_option_widget
|
2003-06-12 18:48:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
function validate_option($option, $name, $val) {
|
2004-05-24 04:22:18 -04:00
|
|
|
global $wpdb;
|
2003-06-12 18:48:52 -04:00
|
|
|
$msg = '';
|
|
|
|
switch ($option->option_type) {
|
|
|
|
case 6: // range
|
|
|
|
// get range
|
2004-05-24 04:22:18 -04:00
|
|
|
$range = $wpdb->get_row("SELECT optionvalue_max, optionvalue_min FROM $wpdb->optionvalues WHERE option_id = $option->option_id");
|
2003-06-12 18:48:52 -04:00
|
|
|
if ($range) {
|
|
|
|
if (($val < $range->optionvalue_min) || ($val > $range->optionvalue_max)) {
|
|
|
|
$msg = "$name is outside the valid range ($range->optionvalue_min - $range->optionvalue_max). ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end switch
|
|
|
|
return $msg;
|
|
|
|
} // end validate_option
|
|
|
|
|
2003-06-11 18:59:14 -04:00
|
|
|
?>
|