/**
  * get html for filter
  * @param $database_table DatabaseTable database table object
  * @param $list_title string title of list
  * @return string returned html
  */
 function get_filter($database_table, $list_title)
 {
     $this->_log->trace("get filter");
     $html_str = "";
     $this->_user->get_list_state($database_table->get_table_name());
     $filter_str = $this->_list_state->get_filter_str();
     $html_str .= "                    <div id=\"" . $this->configuration[HTML_TABLE_CSS_NAME_PREFIX] . "filter\">\n";
     $html_str .= "                        <form name=\"filter_form_name\" id=\"filter_form\" ";
     $html_str .= "onsubmit=\"javascript:handleFunction('action_set_" . $this->configuration[HTML_TABLE_JS_NAME_PREFIX] . "filter', '" . $list_title . "', document.getElementById('filter_str').value); return false;\">\n";
     $html_str .= "                            <input size=\"34\" maxlength=\"100\" value=\"" . $filter_str . "\" id=\"filter_str\">\n";
     $html_str .= "                            " . get_href(get_onclick(ACTION_SET_LIST_FILTER, $list_title, "filter_str", "below", "(%27" . $list_title . "%27, document.getElementById(%27filter_str%27).value)"), "&nbsp;", "icon_none") . "\n";
     $html_str .= "                        </form>\n";
     $html_str .= "                        " . get_href(get_onclick(ACTION_SET_LIST_FILTER, $list_title, "filter_str", "below", "(%27" . $list_title . "%27, %27%27)"), "&nbsp;", "icon_delete") . "\n";
     $html_str .= "                    </div>\n";
     $this->_log->trace("got filter");
     return $html_str;
 }
 /**
  * select a fixed number of records from database
  * @todo filter sql settings also includes note fields. note fields should not be known in this file.
  * @param $order_by_field string order records by this db_field_name
  * @param $page int the page number to select
  * @param $db_field_names array array containing db_field_names to select for each record
  * @return array array containing the records (each records is an array)
  */
 function select($order_by_field, $page, $db_field_names = array())
 {
     $this->_log->trace("selecting UserDatabaseTable (order_by_field=" . $order_by_field . ", page=" . $page . ", db_field_names=" . count($db_field_names) . ")");
     # get lines per page from session
     $lines_per_page = $this->_user->get_lines_per_page();
     # get list_state from session
     $this->_user->get_list_state($this->table_name);
     # get previous field order
     $prev_order_by_field = $this->_list_state->get_order_by_field();
     if (strlen($order_by_field) == 0) {
         # no order_by_field had been given
         if (strlen($this->_list_state->get_order_by_field()) > 0) {
             # order by previously given field
             $order_by_field = $prev_order_by_field;
         } else {
             # no field to order by has been given previously
             # order by first field that has a non empty field_name of this UserDatabaseTable
             foreach ($this->db_field_names as $db_field_name) {
                 if (strlen($this->fields[$db_field_name][0]) > 0 && $this->fields[$db_field_name][3] != COLUMN_NO_SHOW) {
                     # set different db_field_names for automatic creator and modifier fields
                     if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_AUTO_CREATED) {
                         $order_by_field = DB_TS_CREATED_FIELD_NAME;
                     } else {
                         if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_AUTO_MODIFIED) {
                             $order_by_field = DB_TS_MODIFIED_FIELD_NAME;
                         } else {
                             $order_by_field = $db_field_name;
                         }
                     }
                     break;
                 }
             }
             $this->_list_state->set_order_by_field($order_by_field);
             $this->_list_state->set_order_ascending(1);
         }
     } else {
         # order by field has been provided
         # set order by field attribute value and reverse order
         $this->_list_state->set_order_by_field($order_by_field);
         # only change sort order when user sorts by same field as previous time
         if ($order_by_field == $prev_order_by_field) {
             if ($this->_list_state->get_order_ascending()) {
                 $this->_list_state->set_order_ascending(0);
             } else {
                 $this->_list_state->set_order_ascending(1);
             }
         } else {
             $this->_list_state->set_order_ascending(1);
         }
     }
     $order_ascending = $this->_list_state->get_order_ascending();
     $archived = $this->_list_state->get_archived();
     $filter_str_sql = $this->_list_state->get_filter_str_sql();
     if ($page == DATABASETABLE_UNKWOWN_PAGE) {
         $page = $this->_list_state->get_current_page();
     }
     # call parent select()
     $rows = parent::select($order_by_field, $order_ascending, $archived, $filter_str_sql, $page, $lines_per_page, $db_field_names);
     # replace decimal marks
     $replaced_rows = array();
     if (count($this->db_field_names_decimal_marks_to_replace) > 0) {
         foreach ($rows as $row) {
             array_push($replaced_rows, $this->_replace_decimal_marks($row, FALSE));
         }
         $rows = $replaced_rows;
     }
     if ($page != DATABASETABLE_ALL_PAGES) {
         $this->_list_state->set_current_page($page);
     }
     if (count($rows) > 0) {
         $this->_list_state->set_total_records($rows[0][DB_TOTAL_RECORDS]);
         $this->_list_state->set_total_pages($rows[0][DB_TOTAL_PAGES]);
         $this->_list_state->set_current_page($rows[0][DB_CURRENT_PAGE]);
     } else {
         $this->_list_state->set_total_records(0);
         $this->_list_state->set_total_pages(0);
         $this->_list_state->set_current_page(0);
     }
     # store list_state to session
     $this->_user->set_list_state();
     $this->_log->trace("selected UserDatabaseTable");
     return $rows;
 }