private function init_filter_custom_fields() { $key = 'filter_custom_fields'; if (!$this->exec_cf_mgr) { $this->exec_cf_mgr = new exec_cfield_mgr($this->db, $this->args->testproject_id); } $field_names = $this->exec_cf_mgr->field_names(); $menu = $this->exec_cf_mgr->html_table_of_custom_field_inputs(self::CF_INPUT_SIZE); $selection = $this->exec_cf_mgr->get_set_values(); // BUGID 3566: show/hide CF $ses_string = $this->mode . "_cf_filter_collapsed"; $collapsed = isset($_SESSION[$ses_string]) ? $_SESSION[$ses_string] : 0; $collapsed = isset($_REQUEST['btn_toggle_cf']) ? !$collapsed : $collapsed; $_SESSION[$ses_string] = $collapsed; $btn_label = $collapsed ? lang_get('btn_show_cf') : lang_get('btn_hide_cf'); // asimon - 20100713 // Fixed drag&drop error caused by this function. It always set $this->do_filtering // to true here because of the missing $selection in the following if condition. // This caused lazy loading and DD to be disabled later. // see: http://www.teamst.org/forum/viewtopic.php?f=11&t=3354&sid=70498c57842247114cc7233d0f4e5c51 if (!$selection || $this->args->reset_filters) { // handle filter reset button $selection = null; } else { $this->do_filtering = true; } if (isset($selection) && is_array($selection) && count($selection)) { // BUGID 3414: // Insert values chosen by user into html select menu by regex. // The $menu string contains lines of which each looks like this, e.g.: // <tr><td class="labelHolder">cflabel</td><td><input type="text" name="custom_field_0_1" // id="custom_field_0_1" size="32" maxlength="255" value=""></input></td></tr> // For each sent value, search the value="" part there and // then insert the real value into the empty "". Depending on type, of course. // TODO this stuff could maybe fit better into cfield_mgr class? // no magic number: 1 because of course only one replacement per value shall be done $limit = 1; foreach ($selection as $cf_id => $value) { $cf_html_name = $field_names[$cf_id]['cf_name']; switch ($field_names[$cf_id]['verbose_type']) { case 'list': // for single selection list, only one value has to be marked with "checked" $pattern = '/(.*name="' . $cf_html_name . '".*value="' . $value . '")(.*)/'; // the numbers: 1 is the part before value, 2 after $replacement = '${1} selected ${2}'; $menu = preg_replace($pattern, $replacement, $menu, $limit); break; case 'checkbox': case 'multiselection list': // this is similar to single selection list, but a bit more complicated // and needs an additional loop because the selection can have multiple values $value_arr = explode('|', $value); foreach ($value_arr as $single_value) { $pattern = '/(.*id="' . $cf_html_name . '".*value="' . $single_value . '")(.*)/'; // the numbers: 1 is the part before value, 2 after $replacement = '${1} selected ${2}'; $menu = preg_replace($pattern, $replacement, $menu, $limit); } break; case 'numeric': case 'float': case 'email': case 'string': // for these types, replacement is simple, only replace value="" $pattern = '/(.*name="' . $cf_html_name . '".*value=")(".*)/'; // 1 and 2 stand for the first and second pair of braces in above line $replacement = '${1}' . $value . '${2}'; $menu = preg_replace($pattern, $replacement, $menu, $limit); break; default: break; } // end of switch } // end of foreach } // BUGID 3566: show/hide CF $this->filters[$key] = array('items' => $menu, 'btn_label' => $btn_label, 'collapsed' => $collapsed); $this->active_filters[$key] = $selection; }