Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class html_form_input
- {
- private $input_type;
- private $table;
- private $fieldname_id;
- private $fieldname_desc;
- private $passed_id;
- private $sql_where;
- private $sql_order;
- private $array_input_options;
- public function __construct()
- {
- // get class arguments and put them into variables
- $arguments = func_get_args();
- if(!empty($arguments))
- {
- foreach($arguments[0] as $key => $property)
- {
- if(property_exists($this, $key))
- {
- $this->{$key} = $property;
- }
- }
- }
- $input_type = $arguments[0]['input_type'];
- switch($input_type)
- {
- case 'select':
- $html = $this->query_form_data();
- break;
- case 'textbox':
- break;
- case 'text':
- break;
- case 'radio':
- break;
- case 'checkbox':
- break;
- }
- PrintArray($arguments);
- echo "<p>TESTING: html: $html";
- exit;
- }
- private function query_form_data()
- {
- global $mdb2_dbx;
- $debug = true;
- $_debug_desc = "<span style='color:blue;'>function</span> <b>input_select_dropbox</b>()";
- if ($debug) { echo "<p>BEGIN $_debug_desc <blockquote>"; }
- if ($debug)
- {
- echo "<p>Testing \$table $table debug. </blockquote>END $_debug_desc ";
- return false;
- }
- if (!empty($passed_id))
- {
- if (!is_array($passed_id))
- {
- $passed_id[] = $passed_id;
- }
- }
- if (!empty($sql_where))
- {
- $sql_where = " WHERE $sql_where ";
- }
- $q = "
- SELECT
- $fieldname_id,
- $fieldname_desc
- FROM
- $table
- $sql_where
- $sql_order
- ";
- $res = $mdb2_dbx->query($q);
- if (PEAR::isError($res)) { gor_error_handler($res, $q, __LINE__,__FILE__,'die'); }
- while ( $r = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )
- {
- $id = $r[$fieldname_id];
- $desc = $r[$fieldname_desc];
- $array_values[$id] = $desc;
- }
- // $array_data = array('row_data'=>$array_values);
- return $array_values;
- }
- // $html = input_build_select($array_data, $array_input_options);
- private function build_select($array_data)
- {
- $array_values = $array_data['row_data'];
- $fieldname_id = $array_data['fieldname_id'];
- $fieldname_desc = $array_data['fieldname_desc'];
- $passed_id = $array_data['passed_id'];
- if (!is_array($passed_id))
- {
- $passed_id[] = $passed_id;
- }
- foreach ($array_values as $id=>$desc)
- {
- // handle passed values (multiple or single)
- $sel = null;
- if (in_array($id,$passed_id))
- {
- $sel = ' selected ';
- }
- // construct html
- $html_options .= " <option value='$id' $sel>$desc</option>\n";
- }
- $disabled = null;
- $multiple = null;
- $size = null;
- $style = null;
- $class = null;
- $element_id = null;
- $javascript = null;
- if (is_array($array_input_options))
- {
- $s_disabled = $array_input_options['disabled'];
- $s_multiple = $array_input_options['multiple'];
- $s_size = $array_input_options['size'];
- $s_style = $array_input_options['style'];
- $s_id = $array_input_options['id'];
- $s_class = $array_input_options['class'];
- $s_javascript = $array_input_options['javascript'];
- if ($s_disabled!='') {$disabled = ' disabled '; }
- if ($s_multiple!='') {$multiple = ' multiple '; }
- if ($s_size!='') {$size = ' size="' . $s_size . '"'; }
- if ($s_style!='') {$style = ' style = "' . $s_style . '"'; }
- if ($s_id!='') {$element_id = ' id = "' . $s_id . '"'; }
- if ($s_class!='') {$class = ' class = "' . $s_class . '"'; }
- if ($s_javascript!='') {$javascript = $s_javascript; }
- }
- $html = "
- <select name='$fieldname_id' $element_id $disabled $multiple $size $style $class $javascript>
- $html_options
- </select>
- ";
- return $html;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment