Guest User

Untitled

a guest
Jan 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. <?php
  2.  
  3.     class html_form_input
  4.     {
  5.    
  6.         private $input_type;
  7.         private $table;
  8.         private $fieldname_id;
  9.         private $fieldname_desc;
  10.         private $passed_id;
  11.         private $sql_where;
  12.         private $sql_order;
  13.         private $array_input_options;
  14.        
  15.        
  16.         public function __construct()
  17.         {
  18.             // get class arguments and put them into variables
  19.             $arguments = func_get_args();
  20.             if(!empty($arguments))
  21.             {
  22.                 foreach($arguments[0] as $key => $property)
  23.                 {
  24.                     if(property_exists($this, $key))
  25.                     {
  26.                         $this->{$key} = $property;
  27.                     }
  28.                 }
  29.             }
  30.            
  31.             $input_type = $arguments[0]['input_type'];
  32.             switch($input_type)
  33.             {
  34.                 case 'select':
  35.                     $html = $this->query_form_data();
  36.                     break;
  37.                 case 'textbox':
  38.                     break;
  39.                 case 'text':
  40.                     break;
  41.                 case 'radio':
  42.                     break;
  43.                 case 'checkbox':
  44.                     break;
  45.             }
  46.  
  47.             PrintArray($arguments);
  48.             echo "<p>TESTING: html: $html";
  49.             exit;
  50.         }
  51.  
  52.         private function query_form_data()
  53.         {
  54.        
  55.             global $mdb2_dbx;
  56.  
  57.             $debug = true;
  58.  
  59.             $_debug_desc        = "<span style='color:blue;'>function</span> <b>input_select_dropbox</b>()";
  60.             if ($debug)         { echo "<p>BEGIN $_debug_desc <blockquote>"; }
  61.  
  62.  
  63.             if ($debug)
  64.             {
  65.                 echo "<p>Testing \$table $table  debug. </blockquote>END $_debug_desc ";
  66.                 return false;
  67.             }
  68.  
  69.             if (!empty($passed_id))
  70.             {
  71.                 if (!is_array($passed_id))
  72.                 {
  73.                     $passed_id[] = $passed_id;
  74.                 }
  75.             }
  76.  
  77.             if (!empty($sql_where))
  78.             {
  79.                 $sql_where = " WHERE $sql_where ";
  80.             }
  81.  
  82.  
  83.             $q = "
  84.                 SELECT
  85.                     $fieldname_id,
  86.                     $fieldname_desc
  87.                 FROM
  88.                     $table
  89.                 $sql_where
  90.                 $sql_order
  91.             ";
  92.             $res = $mdb2_dbx->query($q);
  93.             if (PEAR::isError($res)) {  gor_error_handler($res, $q, __LINE__,__FILE__,'die'); }
  94.             while ( $r = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )
  95.             {
  96.                 $id     = $r[$fieldname_id];
  97.                 $desc   = $r[$fieldname_desc];
  98.                 $array_values[$id] = $desc;
  99.             }
  100.  
  101.             // $array_data = array('row_data'=>$array_values);
  102.  
  103.  
  104.             return $array_values;
  105.  
  106.         }
  107.  
  108.         //  $html = input_build_select($array_data, $array_input_options);
  109.  
  110.         private function build_select($array_data)
  111.         {
  112.            
  113.             $array_values   = $array_data['row_data'];
  114.             $fieldname_id   = $array_data['fieldname_id'];
  115.             $fieldname_desc = $array_data['fieldname_desc'];
  116.             $passed_id      = $array_data['passed_id'];
  117.  
  118.             if (!is_array($passed_id))
  119.             {
  120.                 $passed_id[] = $passed_id;
  121.             }
  122.                
  123.  
  124.             foreach ($array_values as $id=>$desc)
  125.             {
  126.  
  127.                 // handle passed values (multiple or single)
  128.                 $sel = null;
  129.                 if (in_array($id,$passed_id))
  130.                 {
  131.                     $sel = ' selected ';
  132.                 }
  133.                
  134.                 // construct html
  135.                 $html_options .= " <option value='$id' $sel>$desc</option>\n";
  136.                
  137.             }
  138.  
  139.             $disabled   = null;
  140.             $multiple   = null;
  141.             $size       = null;
  142.             $style      = null;
  143.             $class      = null;
  144.             $element_id = null;
  145.             $javascript = null;
  146.  
  147.             if (is_array($array_input_options))
  148.             {
  149.                 $s_disabled     = $array_input_options['disabled'];
  150.                 $s_multiple     = $array_input_options['multiple'];
  151.                 $s_size         = $array_input_options['size'];
  152.                 $s_style        = $array_input_options['style'];
  153.                 $s_id           = $array_input_options['id'];
  154.                 $s_class        = $array_input_options['class'];
  155.                 $s_javascript   = $array_input_options['javascript'];
  156.  
  157.                 if ($s_disabled!='')    {$disabled      = ' disabled '; }
  158.                 if ($s_multiple!='')    {$multiple      = ' multiple '; }
  159.                 if ($s_size!='')        {$size          = ' size="'     . $s_size . '"'; }
  160.                 if ($s_style!='')       {$style         = ' style = "'  . $s_style . '"'; }
  161.                 if ($s_id!='')          {$element_id    = ' id = "'     . $s_id . '"'; }
  162.                 if ($s_class!='')       {$class         = ' class = "'  . $s_class . '"'; }
  163.                 if ($s_javascript!='')  {$javascript    = $s_javascript; }
  164.             }
  165.  
  166.             $html = "
  167.                 <select name='$fieldname_id' $element_id $disabled $multiple $size $style $class $javascript>
  168.                     $html_options
  169.                 </select>
  170.             ";
  171.             return $html;
  172.         }
  173.        
  174.        
  175.        
  176.        
  177.     }
  178.  
  179. ?>
Add Comment
Please, Sign In to add comment