Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- switch($type)
- {
- case 'string':
- // Required array value
- $data_arr = array('name' => $name);
- /* Only add array values if set
- */
- if($id) $data_arr['id'] = $id;
- if($default) $data_arr['value'] = $default;
- if($max_length) $data_arr['maxlength'] = $max_length;
- if($width) $data_arr['size'] = $width;
- print form_input($data_arr);
- break;
- case 'select':
- $options = array();
- $default_select = array();
- // Check for dynamic optin data
- if($data_url) {
- $remote = file_get_contents($data_url);
- // XML import (@ added to hide errors, since this is used for a test on XML validation)
- $xmlObj = @simplexml_load_string($remote);
- // JSON import (@... same reason)
- $jsonObj = @json_decode($remote);
- // Check to see if one of the parsers above passed
- if(($xmlObj) || ($jsonObj)) {
- $options_arr = ($xmlObj ? $xmlObj : $jsonObj);
- if(is_object($options_arr)) // If its an object, convert to array
- $options_arr = get_object_vars($options_arr);
- // Now merge it with the $options array
- $options = array_merge_recursive($options_arr, $options);
- }
- }
- // Check for static data
- if($data) {
- $static_data = @unserialize($data);
- // Check if unserialize succeeded, it will fail if its not a real serialized string && Merge static data with the dynamic data above
- if(($static_data) && (is_array($static_data)))
- $options = array_merge_recursive($options, $static_data);
- else
- log_message('error', "Unserialize failed for data on parameter ID $parameter_id. Is this a serialized array?");
- }
- // Check for a dynamic default value
- if($default_url) {
- $remote = file_get_contents($default_url);
- // XML import (@ added to hide errors, since this is used for a test on XML validation)
- $xmlObj = @simplexml_load_string($remote);
- // JSON import (@... same reason)
- $jsonObj = @json_decode($remote);
- // Check to see if one of the parsers above passed
- if(($xmlObj) || ($jsonObj)) {
- $dynamic_default = ($xmlObj ? $xmlObj : $jsonObj);
- // If its an object, convert to array
- if(is_object($dynamic_default))
- $dynamic_default = get_object_vars($dynamic_default);
- // Merge it with the $default_select array
- if(is_array($dynamic_default))
- $default_select = array_merge_recursive($default_select, $dynamic_default);
- }
- }
- // check for static default data
- if($default) {
- $static_default = @unserialize($default);
- // Make sure it unserialized ok && Merge it with the $default_select array which will have the dynamic default as well.
- if(($static_default) && (is_array($static_default)))
- $default_select = array_merge_recursive($default_select, $static_default);
- else
- log_message('error', "Unserialize failed for default on parameter ID $parameter_id. Is this a serialized array?");
- }
- // array_merge_recursive will grab the name of the array and make it a key, undo that
- if(isset($default_select['default']))
- $default_select = $default_select['default'];
- // If this is an array with more than 1 value, grab index 0
- if((is_array($default_select)) && (isset($default_select[0])))
- $default_select = $default_select[0];
- // Only show the dropdown if there are options
- if((isset($options)) && (count($options) != 0))
- echo (isset($default_select) ?
- form_dropdown($name, $options, $default_select) :
- form_dropdown($name, $options));
- else
- log_message('error', "Unable to pull data for dynamic parameter ID $parameter_id, it's not recognized as XML or JSON");
- break;
- case 'multiple':
- $options = array();
- $default_select = array();
- // Check for dynamic optin data
- if($data_url) {
- $remote = file_get_contents($data_url);
- // XML import (@ added to hide errors, since this is used for a test on XML validation)
- $xmlObj = @simplexml_load_string($remote);
- // JSON import (@... same reason)
- $jsonObj = @json_decode($remote);
- // Check to see if one of the parsers above passed
- if(($xmlObj) || ($jsonObj)) {
- $options_arr = ($xmlObj ? $xmlObj : $jsonObj);
- if(is_object($options_arr)) // If its an object, convert to array
- $options_arr = get_object_vars($options_arr);
- // Now merge it with the $options array
- $options = array_merge_recursive($options_arr, $options);
- }
- }
- // Check for static data
- if($data) {
- $static_data = @unserialize($data);
- // Check if unserialize failed to make sure its legit && Merge static data with the dynamic data above
- if(($static_data) && (is_array($static_data)))
- $options = array_merge_recursive($options, $static_data);
- else
- log_message('error', "Unserialize failed for default on parameter ID $parameter_id. Is this a serialized array?");
- }
- // Check for a dynamic default value
- if($default_url) {
- $remote = file_get_contents($default_url);
- // XML import (@ added to hide errors, since this is used for a test on XML validation)
- $xmlObj = @simplexml_load_string($remote);
- // JSON import (@... same reason)
- $jsonObj = @json_decode($remote);
- // Check to see if one of the parsers above passed
- if(($xmlObj) || ($jsonObj)) {
- $dynamic_default = ($xmlObj ? $xmlObj->default : $jsonObj->default);
- // If its an object, convert to array
- if(is_object($dynamic_default))
- $dynamic_default = get_object_vars($dynamic_default);
- // Merge it with the $default_select array
- if(is_array($dynamic_default))
- $default_select = array_merge_recursive($default_select, $dynamic_default);
- }
- }
- // check for static default data
- if($default) {
- $static_default = @unserialize($default);
- // Make sure it got unserialized & Merge it with the $default_select array which will have the dynamic default as well.
- if(($static_default) && (is_array($static_default)))
- $default_select = array_merge_recursive($default_select, $static_default);
- else
- log_message('error', "Unable to use the static default value for field $name (ID: $parameter_id), it needs to be an array.");
- }
- if(isset($options))
- echo (isset($default_select) ?
- form_multiselect($name, $options, $default_select) :
- form_multiselect($name, $options));
- else
- log_message('error', "Unable to pull data for dynamic parameter ID $parameter_id, it's not recognized as XML or JSON");
- break;
- case 'text':
- // necessary values to use
- $data_arr = array('name' => $name);
- /* Only load values if they are set
- */
- if ($id) $data_arr['id'] = $id;
- if($default) $data_arr['value'] = $default;
- if($max_length) $data_arr['maxlength'] = $max_length;
- if($width) $data_arr['cols'] = $width;
- if($rows) $data_arr['rows'] = $rows;
- print form_textarea($data_arr);
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement