function string_custom_field_input($p_field_def, $name_suffix = '', $field_size = 0, $show_on_filters = false) { $str_out = ''; $t_custom_field_value = $p_field_def['default_value']; if (isset($p_field_def['value'])) { $t_custom_field_value = $p_field_def['value']; } $verbose_type = trim($this->custom_field_types[$p_field_def['type']]); $t_custom_field_value = htmlspecialchars($t_custom_field_value); $input_name = $this->buildHTMLInputName($p_field_def, $name_suffix); $size = isset($this->sizes[$verbose_type]) ? intval($this->sizes[$verbose_type]) : 0; $required = $p_field_def['required'] ? ' class="required" ' : ' class="" '; $dateOpt = array('default_disable' => false, 'allow_blank' => true, 'required' => $required, 'show_on_filters' => $show_on_filters); if ($field_size > 0) { $size = $field_size; } switch ($verbose_type) { case 'list': case 'multiselection list': $t_values = explode('|', $p_field_def['possible_values']); $t_values_count = count($t_values); if ($verbose_type == 'list') { // get maximum allowed window size for lists $window_size = intval($size) > 1 ? $size : self::LISTBOX_WINDOW_SIZE; $t_multiple = ' '; $t_name_suffix = ''; } else { // get maximum allowed window size for mutliselection lists $window_size = intval($size) > 1 ? $size : self::MULTISELECTIONLIST_WINDOW_SIZE; $t_name_suffix = '[]'; $t_multiple = ' multiple="multiple" '; } // lists and multiselection lists do not use more space than necessary // set the list size to the number of possible values of custom field // but respect the maximum window size $t_list_size = $t_values_count; if ($t_list_size > $window_size) { $t_list_size = $window_size; } $html_identity = $input_name . $t_name_suffix; $str_out .= "<select {$required} name=\"{$html_identity}\" id=\"{$input_name}\" {$t_multiple}"; $str_out .= ' size="' . $t_list_size . '">'; $t_selected_values = explode('|', $t_custom_field_value); foreach ($t_values as $t_option) { if (in_array($t_option, $t_selected_values)) { $str_out .= '<option value="' . $t_option . '" selected> ' . $t_option . '</option>'; } else { $str_out .= '<option value="' . $t_option . '">' . $t_option . '</option>'; } } $str_out .= '</select>'; break; case 'checkbox': $t_values = explode('|', $p_field_def['possible_values']); $t_checked_values = explode('|', $t_custom_field_value); foreach ($t_values as $t_option) { $str_out .= '<input ' . $required . ' type="checkbox" name="' . $input_name . '[]"' . " id=\"{$input_name}\""; // need to manage situation where user has not assigned possible values // will force lang_get('yes') $t_gui_value = $t_option == '' ? lang_get('Yes') : $t_option; // added check $t_option != '' to make check box start NOT CHECKED if ($t_gui_value != '' && in_array($t_gui_value, $t_checked_values)) { $str_out .= ' value="' . $t_gui_value . '" checked="checked"> ' . $t_option . ' '; } else { $str_out .= ' value="' . $t_gui_value . '"> ' . $t_option . ' '; } } break; case 'string': case 'email': case 'float': case 'numeric': $str_out .= $this->string_input_string($p_field_def, $input_name, $t_custom_field_value, $size); break; case 'text area': $cols = intval($this->sizes['text area']['cols']); $rows = intval($this->sizes['text area']['rows']); if ($cols <= 0) { $cols = self::TEXTAREA_DEFAULT_COLS; } if ($rows <= 0) { $rows = self::TEXTAREA_DEFAULT_ROWS; } if ($this->max_length_value > 0) { $counterId = $input_name . '_counter'; $cf_current_size = $this->max_length_value - tlStringLen($t_custom_field_value); // call JS function for check max. size from validate.js $js_function = '"textCounter(this.form.' . $input_name . ',document.getElementById(\'' . $counterId . '\'),' . $this->max_length_value . ');" '; $str_out .= '<textarea ' . $required . ' name="' . $input_name . '" ' . " id=\"{$input_name}\" " . 'onKeyDown=' . $js_function . ' onKeyUp=' . $js_function . 'cols="' . $cols . '" rows="' . $rows . '">' . "{$t_custom_field_value}</textarea>\n"; // show character counter $str_out .= '<br><span style="vertical-align: top; padding: 5px;">' . sprintf(lang_get('text_counter_feedback'), $this->max_length_value) . ' <span id="' . $counterId . '">' . $cf_current_size . '</span>.</span><br>'; } else { // unlimited $str_out .= '<textarea ' . $required . ' name="' . $input_name . '" ' . " id=\"{$input_name}\" " . 'cols="' . $cols . '" rows="' . $rows . '">' . "{$t_custom_field_value}</textarea>\n"; } break; case 'date': $str_out .= create_date_selection_set($input_name, config_get('date_format'), $t_custom_field_value, $dateOpt); break; case 'datetime': $cfg = config_get('gui'); // Important // We can do this mix (get date format configuration from standard variable // and time format from an specific custom field config) because string used // for date_format on strftime() has no problem // on date() calls (that are used in create_date_selection_set() ). $datetime_format = config_get('date_format') . " " . $cfg->custom_fields->time_format; $str_out .= create_date_selection_set($input_name, $datetime_format, $t_custom_field_value, $dateOpt); break; default: $dynamic_call = 'string_input_' . str_replace(' ', '_', $verbose_type); if (function_exists($dynamic_call)) { $str_out .= $dynamic_call($p_field_def, $input_name, $t_custom_field_value); } else { if (method_exists($this, $dynamic_call)) { $str_out .= $this->{$dynamic_call}($p_field_def, $input_name, $t_custom_field_value); } else { // treat it as an simple string $str_out .= $this->string_input_string($p_field_def, $input_name, $t_custom_field_value, $size); } } break; } return $str_out; }
function string_custom_field_input($p_field_def, $name_suffix = '', $field_size = 0) { $str_out = ''; $t_id = $p_field_def['id']; $t_type = $p_field_def['type']; $t_custom_field_value = $p_field_def['default_value']; if (isset($p_field_def['value'])) { $t_custom_field_value = $p_field_def['value']; } $verbose_type = trim($this->custom_field_types[$t_type]); $t_custom_field_value = htmlspecialchars($t_custom_field_value); $input_name = "{$this->name_prefix}{$t_type}_{$t_id}{$name_suffix}"; $size = isset($this->sizes[$verbose_type]) ? intval($this->sizes[$verbose_type]) : 0; if ($field_size > 0) { $size = $field_size; } switch ($verbose_type) { case 'list': case 'multiselection list': $t_values = explode('|', $p_field_def['possible_values']); if ($verbose_type == 'list') { $t_multiple = ' '; $t_list_size = intval($size) > 0 ? $size : 1; // 20100701 - asimon - removed single space in next line, // it was causing errors in field names on HTML because it somehow gets replaced // by an underscore somwhere and then the field name doesn't match anymore //$t_name_suffix=' '; $t_name_suffix = ''; } else { $window_size = intval($size) > 1 ? $size : self::MULTISELECTIONLIST_WINDOW_SIZE; $t_name_suffix = '[]'; $t_multiple = ' multiple="multiple" '; $t_list_size = count($t_values); if ($t_list_size > $window_size) { $t_list_size = $window_size; } } $html_identity = $input_name . $t_name_suffix; $str_out .= "<select name=\"{$html_identity}\" id=\"{$input_name}\" {$t_multiple}"; $str_out .= ' size="' . $t_list_size . '">'; $t_selected_values = explode('|', $t_custom_field_value); foreach ($t_values as $t_option) { if (in_array($t_option, $t_selected_values)) { $str_out .= '<option value="' . $t_option . '" selected> ' . $t_option . '</option>'; } else { $str_out .= '<option value="' . $t_option . '">' . $t_option . '</option>'; } } $str_out .= '</select>'; break; case 'checkbox': $t_values = explode('|', $p_field_def['possible_values']); $t_checked_values = explode('|', $t_custom_field_value); foreach ($t_values as $t_option) { $str_out .= '<input type="checkbox" name="' . $input_name . '[]"' . " id=\"{$input_name}\""; // 20100218 - franciscom - added check $t_option != '' to make check box start NOT CHECKED if ($t_option != '' && in_array($t_option, $t_checked_values)) { $str_out .= ' value="' . $t_option . '" checked="checked"> ' . $t_option . ' '; } else { $str_out .= ' value="' . $t_option . '"> ' . $t_option . ' '; } } break; case 'string': case 'email': case 'float': case 'numeric': $str_out .= $this->string_input_string($p_field_def, $input_name, $t_custom_field_value, $size); break; case 'text area': $cols = intval($this->sizes['text area']['cols']); $rows = intval($this->sizes['text area']['rows']); if ($cols <= 0) { $cols = self::TEXTAREA_DEFAULT_COLS; } if ($rows <= 0) { $rows = self::TEXTAREA_DEFAULT_ROWS; } if ($this->max_length_value > 0) { $counterId = $input_name . '_counter'; $cf_current_size = $this->max_length_value - tlStringLen($t_custom_field_value); // call JS function for check max. size from validate.js $js_function = '"textCounter(this.form.' . $input_name . ',document.getElementById(\'' . $counterId . '\'),' . $this->max_length_value . ');" '; $str_out .= '<textarea name="' . $input_name . '" ' . " id=\"{$input_name}\" " . 'onKeyDown=' . $js_function . ' onKeyUp=' . $js_function . 'cols="' . $cols . '" rows="' . $rows . '">' . "{$t_custom_field_value}</textarea>\n"; // show character counter $str_out .= '<br><span style="vertical-align: top; padding: 5px;">' . sprintf(lang_get('text_counter_feedback'), $this->max_length_value) . ' <span id="' . $counterId . '">' . $cf_current_size . '</span>.</span><br>'; } else { // unlimited $str_out .= '<textarea name="' . $input_name . '" ' . " id=\"{$input_name}\" " . 'cols="' . $cols . '" rows="' . $rows . '">' . "{$t_custom_field_value}</textarea>\n"; } break; case 'date': $str_out .= create_date_selection_set($input_name, config_get('date_format'), $t_custom_field_value, false, true); break; case 'datetime': $cfg = config_get('gui'); // Important // We can do this mix (get date format configuration from standard variable // and time format from an specific custom field config) because string used // for date_format on strftime() has no problem // on date() calls (that are used in create_date_selection_set() ). $datetime_format = config_get('date_format') . " " . $cfg->custom_fields->time_format; $str_out .= create_date_selection_set($input_name, $datetime_format, $t_custom_field_value, false, true, date("Y") - 1); break; default: $dynamic_call = 'string_input_' . str_replace(' ', '_', $verbose_type); if (function_exists($dynamic_call)) { $str_out .= $dynamic_call($p_field_def, $input_name, $t_custom_field_value); } else { if (method_exists($this, $dynamic_call)) { $str_out .= $this->{$dynamic_call}($p_field_def, $input_name, $t_custom_field_value); } else { // treat it as an simple string $str_out .= $this->string_input_string($p_field_def, $input_name, $t_custom_field_value, $size); } } break; } return $str_out; }