--- /Applications/MAMP/htdocs/drupal5/sites/webform.dev/modules/webform/components/select_new.inc +++ select2.0.inc @@ -10,8 +10,6 @@ * An array of form items to be displayed on the edit component page. */ function _webform_edit_select($currfield) { - global $user; - $edit_fields = array(); $edit_fields['extra']['items'] = array( '#type' => 'textarea', @@ -21,42 +19,8 @@ '#cols' => 60, '#rows' => 5, '#weight' => -2, - '#required' => FALSE, + '#required' => TRUE, ); - - if ($user->uid == 1 OR user_access('use PHP for additional processing')){ - - $edit_fields['extra']['php'] = array( - '#type' => 'fieldset', - '#title' => 'PHP Options', - '#collapsible' => 'TRUE', - '#collapsed' => 'TRUE', - '#weight' => -1, - '#description' => t("These entries allow a php function to generate the selection values and the default option. Powerful, yes. Dangerous if you don't know what you are doing or you let UNTRUSTED people create these forms. If that seems like a bad idea do not allow 'use PHP for additional processing' in the access controls. The values generated by this PHP overrides values in the Default value and Options boxes above") .'
', - ); - - $edit_fields['extra']['php']['phpoptions'] = array( - '#type' => 'textarea', - '#title' => t("Options from PHP"), - '#default_value' => $currfield['extra']['php']['phpoptions'], - '#description' => t('A php expression that generates an array of options. If the array has strings for keys the keys will be used as the value returned from the select element. These options will replace any other options added in the above box. Do not use the tags an example would be "return array_merge($somearray, $someotherarray );" or "return some_function_that_returns_array($arg);" The PHP is evaluated before the variable subsitution occurs so "return array("user1", "user2", "%username")" will add the users username to a selection including user1 and user2. These strings are evaluated with the php eval statement so the variables and functions that are available when the form is filled out can be used in the php string') .'
', - '#cols' => 60, - '#rows' => 5, - '#weight' => -1, - '#required' => FALSE, - ); - - $edit_fields['extra']['php']['phpdefault'] = array( - '#type' => 'textarea', - '#title' => t("Default Option from PHP"), - '#default_value' => $currfield['extra']['php']['phpdefault'], - '#description' => t('A php expression that generates an array of options. In general there will only be one option in the array but there can be multiple defaults if multiple selections are allowed. If the array has strings for keys the keys will be used as the value returned from the select element. These options will replace any other options added in the above box. Do not use the tags an example would be "return array_merge($somearray, $someotherarray );" or "return some_function_that_returns_array($arg);" These strings are evaluated with the php eval statement so the variables and functions that are available when the form is filled out can be used in the php string') .'
', - '#cols' => 60, - '#rows' => 5, - '#weight' => -2, - '#required' => FALSE, - ); - } $edit_fields['value'] = array( '#type' => 'textfield', '#title' => t("Default value"), @@ -65,7 +29,7 @@ '#size' => 60, '#maxlength' => 256, '#weight' => 0, - ); + ); $edit_fields['extra']['multiple'] = array( '#type' => 'checkbox', '#title' => t("Multiple"), @@ -92,22 +56,6 @@ } function _webform_edit_validate_select($form_values) { - global $user; - - // this is made more complex since some people may not see the php options if they do not have access - if (($user->uid == 1) OR user_access('use PHP for additional processing')){ - if (!(strlen($form_values['extra']['items']) OR strlen($form_values['extra']['php']['phpoptions']))){ - form_set_error('field][extra][items', t('There are no valid options. Specify values either in Options or Options from PHP (Under PHP Options)')); - return false; - } - }else { - if (!(strlen($form_values['extra']['items']) )){ - form_set_error('field][extra][items', t('There are no valid options. Specify at least one value in Options')); - return false; - } - } - - $rows = explode("\n", _webform_filter_values($form_values['extra']['items'], NULL, NULL, FALSE)); foreach ($rows as $row) { $row = trim($row); @@ -122,91 +70,7 @@ } /** - * Generate a string of values from PHP code. This is used to generate both options and default options. - * @param $component - * An array of information describing the component, directly correlating to - * the webform_component database schema. - * @return - * A text string of alternatives. - */ - -function webform_php_eval_items($incomming_php){ - global $user; - - if (!($user->uid == 1 OR user_access('use PHP for additional processing'))){ - drupal_set_message(t('You do not have permission to use php to generate options')); - return ''; - } - // seems like there should be safety checking here, but what can you do if you are going to - // let the users enter php !!!! - //drupal_set_message("doing eval: {$incomming_php}"); - $options = eval($incomming_php); - if (!is_array($options)){ - drupal_set_message("
webform_php_get_items: ERROR the php did not generate an array \n php_options: $incomming_php\n".var_export($options, TRUE).'
'); - return ''; - } - - $opt_arr = array(); - foreach ($options as $k => $v) { - if (is_string($k)){ - $opt_arr[] = "$k|$v"; - } - else { - $opt_arr[]= "$v"; - } - } - return $opt_arr; -} - - -/** - * Use PHP provided by the user to create the option and default option values. This function also alters - * the database data in serialised data in webform_component.extra so that data will be interpreted - * correctly after the form is submitted - * @param $component - * An array of information describing the component, directly correlating to - * the webform_component database schema. - * @return - * An array of two text strings which have the new options and default(s) - */ -function webform_php_get_items($component){ - //drupal_set_message("
webform_php_get_items component:\n".print_r($component, TRUE).'
'); - - if (strlen($component['extra']['php']['phpdefault'])){ - $default_opt_text = implode(", ",webform_php_eval_items($component['extra']['php']['phpdefault'])); - } - if (strlen($component['extra']['php']['phpoptions'])){ - $opt_text = implode("\n",webform_php_eval_items($component['extra']['php']['phpoptions'])); - } - - - // - // now have the dynamic options and default. We have to stick the new options in the database or they are not - // processed correctly - // - //probably do not need the database read here since all the info is in $component, but to be safe that - // there are not additions or deletions in $commponnet, we reread the database to get a pristine copy - $data_value = db_result(db_query("SELECT DISTINCT extra FROM {webform_component} - WHERE nid = %d AND cid = %d", $component['nid'], $component['cid'])); - // 1209763732 - $element_data = unserialize($data_value); - //drupal_set_message("
unserialized data: \n".print_r($element_data, TRUE).'
'); - $element_data['items'] = $opt_text; - $re_serialize = serialize($element_data); - - db_query("UPDATE {webform_component} SET extra = '{%s}', value = '{%s}' - WHERE nid = %d AND cid = %d", $re_serialize, $default_opt_text, $component['nid'], $component['cid'] ); - - - return array('def' => $default_opt_text, 'opts'=>$opt_text); -} - - - -/** * Build a form item array containing all the properties of this component. - * if there is PHP code for generating options and defaults stick those in the - * live component * @param $component * An array of information describing the component, directly correlating to * the webform_component database schema. @@ -214,15 +78,6 @@ * An array of a form item to be displayed on the client-side webform. */ function _webform_render_select($component) { - //drupal_set_message( '
 webform_render before'.print_r($component, true).'
'); - - if (strlen($component['extra']['php']['phpoptions']) OR strlen($component['extra']['php']['phpdefault'])){ - $php_results = webform_php_get_items($component); - $component['value'] = $php_results['def']; // set in the default - $component['extra']['items'] = $php_results['opts']; - } - //drupal_set_message( '
 webform_render after'.print_r($component, true).'
'); - $form_item = array( '#title' => $component['name'], '#required' => $component['mandatory'],