Advertisement
Guest User

Untitled

a guest
Aug 4th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.83 KB | None | 0 0
  1. <?php
  2.  
  3. switch($type)
  4. {
  5.         case 'string':
  6.                 // Required array value
  7.                 $data_arr = array('name'    => $name);
  8.                
  9.                 /* Only add array values if set
  10.                 */
  11.                 if($id) $data_arr['id'] = $id;
  12.                
  13.                 if($default) $data_arr['value'] = $default;
  14.                        
  15.                 if($max_length) $data_arr['maxlength'] = $max_length;
  16.                
  17.                 if($width) $data_arr['size'] = $width;
  18.                        
  19.                 print form_input($data_arr);
  20.                
  21.                 break;
  22.            
  23.         case 'select':
  24.                 $options = array();
  25.                 $default_select = array();
  26.                
  27.                
  28.                 // Check for dynamic optin data
  29.                 if($data_url) {
  30.                         $remote = file_get_contents($data_url);
  31.                        
  32.                         // XML import (@ added to hide errors, since this is used for a test on XML validation)
  33.                         $xmlObj = @simplexml_load_string($remote);
  34.                        
  35.                         // JSON import (@... same reason)
  36.                         $jsonObj = @json_decode($remote);
  37.                        
  38.                         // Check to see if one of the parsers above passed
  39.                         if(($xmlObj) || ($jsonObj)) {
  40.                                 $options_arr = ($xmlObj ? $xmlObj : $jsonObj);
  41.                                
  42.                                 if(is_object($options_arr)) // If its an object, convert to array
  43.                                         $options_arr = get_object_vars($options_arr);
  44.                                
  45.                                 // Now merge it with the $options array
  46.                                 $options = array_merge_recursive($options_arr, $options);      
  47.                         }
  48.                                
  49.                 }
  50.                
  51.                 // Check for static data
  52.                 if($data) {
  53.                         $static_data = @unserialize($data);
  54.                        
  55.                         // Check if unserialize succeeded, it will fail if its not a real serialized string && Merge static data with the dynamic data above
  56.                         if(($static_data) && (is_array($static_data)))
  57.                                 $options = array_merge_recursive($options, $static_data);
  58.                         else
  59.                                 log_message('error', "Unserialize failed for data on parameter ID $parameter_id. Is this a serialized array?");
  60.                 }
  61.                
  62.                
  63.                 // Check for a dynamic default value
  64.                 if($default_url) {
  65.                         $remote = file_get_contents($default_url);
  66.                        
  67.                         // XML import (@ added to hide errors, since this is used for a test on XML validation)
  68.                         $xmlObj = @simplexml_load_string($remote);
  69.  
  70.                         // JSON import (@... same reason)
  71.                         $jsonObj = @json_decode($remote);
  72.                        
  73.                         // Check to see if one of the parsers above passed
  74.                         if(($xmlObj) || ($jsonObj)) {
  75.                                
  76.                                 $dynamic_default = ($xmlObj ? $xmlObj : $jsonObj);
  77.  
  78.                                 // If its an object, convert to array
  79.                                 if(is_object($dynamic_default))
  80.                                         $dynamic_default = get_object_vars($dynamic_default);
  81.                                
  82.                                 // Merge it with the $default_select array
  83.                                 if(is_array($dynamic_default))
  84.                                         $default_select = array_merge_recursive($default_select, $dynamic_default);
  85.                                
  86.                                
  87.                         }
  88.                 }
  89.                
  90.                 // check for static default data
  91.                 if($default) {
  92.                         $static_default = @unserialize($default);
  93.                        
  94.                         // Make sure it unserialized ok && Merge it with the $default_select array which will have the dynamic default as well.
  95.                         if(($static_default) && (is_array($static_default)))
  96.                                 $default_select = array_merge_recursive($default_select, $static_default);
  97.                         else
  98.                                 log_message('error', "Unserialize failed for default on parameter ID $parameter_id. Is this a serialized array?");
  99.                 }
  100.                
  101.                 // array_merge_recursive will grab the name of the array and make it a key, undo that
  102.                 if(isset($default_select['default']))
  103.                         $default_select = $default_select['default'];
  104.                
  105.                 // If this is an array with more than 1 value, grab index 0
  106.                 if((is_array($default_select)) && (isset($default_select[0])))
  107.                         $default_select = $default_select[0];
  108.                
  109.                 // Only show the dropdown if there are options
  110.                 if((isset($options)) && (count($options) != 0))
  111.                         echo (isset($default_select) ?
  112.                                 form_dropdown($name, $options, $default_select) :
  113.                                 form_dropdown($name, $options));
  114.                 else
  115.                         log_message('error', "Unable to pull data for dynamic parameter ID $parameter_id, it's not recognized as XML or JSON");
  116.                
  117.                 break;
  118.        
  119.         case 'multiple':
  120.                 $options = array();
  121.                 $default_select = array();
  122.                
  123.                 // Check for dynamic optin data
  124.                 if($data_url) {
  125.                         $remote = file_get_contents($data_url);
  126.                        
  127.                         // XML import (@ added to hide errors, since this is used for a test on XML validation)
  128.                         $xmlObj = @simplexml_load_string($remote);
  129.                        
  130.                         // JSON import (@... same reason)
  131.                         $jsonObj = @json_decode($remote);
  132.                        
  133.                         // Check to see if one of the parsers above passed
  134.                         if(($xmlObj) || ($jsonObj)) {
  135.                                 $options_arr = ($xmlObj ? $xmlObj : $jsonObj);
  136.                                
  137.                                 if(is_object($options_arr)) // If its an object, convert to array
  138.                                         $options_arr = get_object_vars($options_arr);
  139.                                
  140.                                 // Now merge it with the $options array
  141.                                 $options = array_merge_recursive($options_arr, $options);      
  142.                         }
  143.                 }
  144.                
  145.                 // Check for static data
  146.                 if($data) {
  147.                         $static_data = @unserialize($data);
  148.                        
  149.                         // Check if unserialize failed to make sure its legit && Merge static data with the dynamic data above
  150.                         if(($static_data) && (is_array($static_data)))
  151.                                 $options = array_merge_recursive($options, $static_data);
  152.                         else
  153.                                 log_message('error', "Unserialize failed for default on parameter ID $parameter_id. Is this a serialized array?");
  154.                 }
  155.                
  156.                 // Check for a dynamic default value
  157.                 if($default_url) {
  158.                         $remote = file_get_contents($default_url);
  159.                        
  160.                         // XML import (@ added to hide errors, since this is used for a test on XML validation)
  161.                         $xmlObj = @simplexml_load_string($remote);
  162.                        
  163.                         // JSON import (@... same reason)
  164.                         $jsonObj = @json_decode($remote);
  165.                        
  166.                         // Check to see if one of the parsers above passed
  167.                         if(($xmlObj) || ($jsonObj)) {
  168.                                 $dynamic_default = ($xmlObj ? $xmlObj->default : $jsonObj->default);
  169.                                
  170.                                 // If its an object, convert to array
  171.                                 if(is_object($dynamic_default))
  172.                                         $dynamic_default = get_object_vars($dynamic_default);
  173.                                
  174.                                 // Merge it with the $default_select array
  175.                                 if(is_array($dynamic_default))
  176.                                         $default_select = array_merge_recursive($default_select, $dynamic_default);
  177.                                
  178.                         }
  179.                 }
  180.                
  181.                 // check for static default data
  182.                 if($default) {
  183.                         $static_default = @unserialize($default);
  184.                        
  185.                         // Make sure it got unserialized & Merge it with the $default_select array which will have the dynamic default as well.
  186.                         if(($static_default) && (is_array($static_default)))
  187.                                 $default_select = array_merge_recursive($default_select, $static_default);
  188.                         else
  189.                                 log_message('error', "Unable to use the static default value for field $name (ID: $parameter_id), it needs to be an array.");
  190.                 }
  191.                
  192.                 if(isset($options))
  193.                         echo (isset($default_select) ?
  194.                                 form_multiselect($name, $options, $default_select) :
  195.                                 form_multiselect($name, $options));
  196.                 else
  197.                         log_message('error', "Unable to pull data for dynamic parameter ID $parameter_id, it's not recognized as XML or JSON");
  198.                
  199.                 break;
  200.            
  201.         case 'text':
  202.                
  203.                 // necessary values to use
  204.                 $data_arr = array('name'    => $name);
  205.                
  206.                 /* Only load values if they are set
  207.                 */
  208.                 if ($id) $data_arr['id'] = $id;
  209.                
  210.                 if($default) $data_arr['value'] = $default;
  211.                        
  212.                 if($max_length) $data_arr['maxlength'] = $max_length;
  213.                
  214.                 if($width) $data_arr['cols'] = $width;
  215.                
  216.                 if($rows) $data_arr['rows'] = $rows;
  217.                        
  218.                 print form_textarea($data_arr);
  219.                
  220.                 break;
  221. }
  222.  
  223. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement