Пример #1
0
 function showTable()
 {
     global $error_msg;
     global $report_msg;
     global $warning_msg_displayed;
     global $num_ajaxCRUD_tables_instantiated;
     $num_ajaxCRUD_tables_instantiated++;
     /* Sort Table
           Note: this cancels out default sorting set by addOrderBy()
        */
     if ($this->db_table == $_REQUEST['table'] && $_REQUEST['sort_field'] != '') {
         $sort_field = $_REQUEST['sort_field'];
         $user_sort_order_direction = $_REQUEST['sort_direction'];
         if ($user_sort_order_direction == 'asc') {
             $this->sort_direction = "desc";
         } else {
             $this->sort_direction = "asc";
         }
         $sort_sql = " ORDER BY {$sort_field} {$this->sort_direction}";
         $this->addOrderBy($sort_sql);
         $this->sorted_table = true;
     }
     //the HTML to display
     $top_html = "";
     //top header stuff
     $table_html = "";
     //for the html table itself
     $bottom_html = "";
     $add_html = "";
     //for the add form
     $html = "";
     //all combined
     if ($num_ajaxCRUD_tables_instantiated == 1) {
         //pull in the  css and javascript files
         $this->insertHeader($this->ajax_file);
     }
     if ($this->doActionOnShowTable) {
         if ($_REQUEST['action'] != '') {
             $this->doAction($_REQUEST['action']);
         }
     }
     $item = $this->item;
     $top_html .= "<a name='ajaxCRUD" . $num_ajaxCRUD_tables_instantiated . "' id='ajaxCRUD" . $num_ajaxCRUD_tables_instantiated . "'></a>\n";
     if (count($this->ajaxFilter_fields) > 0) {
         $top_html .= "<form id=\"" . $this->db_table . "_filter_form\">\n";
         $top_html .= "<table cellspacing='5' align='center'><tr>";
         foreach ($this->ajaxFilter_fields as $filter_field) {
             $display_field = $filter_field;
             if ($this->displayAs_array[$filter_field] != '') {
                 $display_field = $this->displayAs_array[$filter_field];
             }
             $textbox_size = $this->ajaxFilterBoxSize[$filter_field];
             $filter_value = "";
             if ($_REQUEST[$filter_field] != '') {
                 $filter_value = $_REQUEST[$filter_field];
             }
             $top_html .= "<td><b>{$display_field}</b>: <input type=\"text\" size=\"{$textbox_size}\" name=\"{$filter_field}\" value=\"{$filter_value}\" onKeyUp=\"filterTable(this, '" . $this->db_table . "', '{$filter_field}', '{$extra_query_params}');\"></td>";
         }
         $top_html .= "</tr></table>\n";
         $top_html .= "</form>\n";
     }
     #############################################
     #
     # Begin code for displaying database elements
     #
     #############################################
     $select_fields = implode(",", $this->fields);
     $sql = "SELECT * FROM " . $this->db_table . $this->sql_where_clause . $this->sql_order_by;
     if ($this->showPaging) {
         $pageid = $_GET['pid'];
         //Get the pid value
         if (intval($pageid) == 0) {
             $pageid = 1;
         }
         $Paging = new paging();
         $Paging->tableName = $this->db_table;
         $total_records = $Paging->myRecordCount($sql);
         //count records
         $totalpage = $Paging->processPaging($this->limit, $pageid);
         $rows = $Paging->startPaging($sql);
         //get records in the databse
         $links = $Paging->pageLinks(basename($PHP_SELF));
         //1234 links
         unset($Paging);
     } else {
         $rows = q($sql . $this->sql_limit);
     }
     //$rows = q("SELECT * FROM " . $this->db_table");
     $row_count = count($rows);
     $this->row_count = $row_count;
     $_SESSION['row_count'] = $row_count;
     if ($row_count == 0) {
         $report_msg[] = $this->emptyTableMessage;
     }
     #this is an optional function which will allow you to display errors or report messages as desired. comment it out if desired
     //only show the message box if it hasn't been displayed already
     if ($warning_msg_displayed == 0 || $warning_msg_displayed == '') {
         echo_msg_box();
     }
     $dropdown_array = array();
     foreach ($this->category_table_array as $key => $category_table) {
         $category_field_name = $this->category_field_array[$key];
         $category_table_pk = $this->category_table_pk_array[$key];
         $order_by = '';
         if ($this->category_sort_field_array[$key] != '') {
             $order_by = " ORDER BY " . $this->category_sort_field_array[$key];
         }
         $whereclause = '';
         if ($this->category_whereclause_array[$key] != '') {
             $whereclause = $this->category_whereclause_array[$key];
         }
         $dropdown_array[] = q("SELECT {$category_table_pk}, {$category_field_name} FROM {$category_table} {$whereclause} {$order_by}");
     }
     $top_html .= "<div id='{$this->db_table}'>\n";
     if ($row_count > 0) {
         //$edit_word = "Edit";
         //if ($row_count == 0) $edit_word = "No";
         //$top_html .= "<h3>Edit " . $this->item_plural . "</h3>\n";
         $table_html .= "<table align='center' class='ajaxCRUD' name='table_" . $this->db_table . "' id='table_" . $this->db_table . "' cellspacing='" . $this->cellspacing . "' border=" . $this->border . ">\n";
         $table_html .= "<tr>\n";
         //for an (optional) checkbox
         if ($this->showCheckbox) {
             $table_html .= "<th>&nbsp;</th>";
         }
         foreach ($this->display_fields as $field) {
             $field_name = $field;
             if ($this->displayAs_array[$field] != '') {
                 $field = $this->displayAs_array[$field];
             }
             if (array_key_exists($field_name, $this->checkboxall)) {
                 $table_html .= "<th><input type=\"checkbox\" name=\"{$field_name}" . "_checkboxall\" value=\"checkAll\" onClick=\"\n\t\t\t\t\t\t\tif (this.checked) {\n\t\t\t\t\t\t\t\tsetAllCheckboxes('{$field_name}" . "_fieldckbox',false);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetAllCheckboxes('{$field_name}" . "_fieldckbox',true);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\">";
                 if ($this->checkboxall[$field_name] == true) {
                     $table_html .= "<a href='javascript:;' onClick=\"changeSort('{$this->db_table}', '{$field_name}', '{$this->sort_direction}');\" >" . $field . "</a>";
                 }
                 $table_html .= "</th>";
             } else {
                 $table_html .= "<th><a href='javascript:;' onClick=\"changeSort('{$this->db_table}', '{$field_name}', '{$this->sort_direction}');\" >" . $field . "</a></th>";
             }
         }
         if ($this->delete || count($this->row_button) > 0) {
             $table_html .= "<th>Action</th>\n";
         }
         $table_html .= "</tr>\n";
         $count = 0;
         $class = "odd";
         $attach_params = "";
         foreach ($rows as $row) {
             $id = $row[$this->db_table_pk];
             $table_html .= "<tr class='{$class}' id=\"" . $this->db_table . "_row_{$id}\" valign='top'>\n";
             if ($this->showCheckbox) {
                 $checkbox_selected = "";
                 if ($id == $_REQUEST[$this->db_table_pk]) {
                     $checkbox_selected = " checked";
                 }
                 $table_html .= "<td><input type='checkbox' {$checkbox_selected} onClick=\"window.location ='" . $_SERVER['PHP_SELF'] . "?{$this->db_table_pk}={$id}'\" /></td>";
             }
             foreach ($this->display_fields as $field) {
                 $cell_data = $row[$field];
                 //for adding a button via addButtonToRow (using "all" as the "attach params" optional third parameter)
                 if (count($this->row_button) > 0) {
                     $attach_params .= "&" . $field . "=" . $cell_data;
                 }
                 $cell_value = $cell_data;
                 //retain original value in new variable (before executing callback method)
                 if ($this->format_field_with_function[$field] != '') {
                     $cell_data = call_user_func($this->format_field_with_function[$field], $cell_data);
                 }
                 //try to find a reference to another table relationship
                 $found_category_index = array_search($field, $this->db_table_fk_array);
                 //don't allow uneditable fields (which usually includes the primary key) to be editable
                 if ($this->fieldInArray($field, $this->uneditable_fields) && !is_numeric($found_category_index) || !$this->ajax_editing) {
                     $table_html .= "<td>";
                     $key = array_search($field, $this->display_fields);
                     if ($this->fieldInArray($field, $this->file_uploads)) {
                         //a file exists for this field
                         if ($cell_data != '') {
                             $file_link = $this->file_upload_info[$field][relative_folder] . $row[$field];
                             $file_dest = $this->file_upload_info[$field][destination_folder];
                             $table_html .= "<span id='text_" . $field . $id . "'><a target=\"_new\" href=\"{$file_link}\">" . $cell_data . "</a> (<a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"document.getElementById('file_{$field}{$id}').style.display = ''; document.getElementById('text_{$field}{$id}').style.display = 'none'; \">edit</a> <a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"deleteFile('{$field}', '{$id}')\">delete</a>)</span> \n";
                             $table_html .= "<div id='file_" . $field . $id . "' style='display:none;'>\n";
                             $table_html .= $this->showUploadForm($field, $file_dest, $id);
                             $table_html .= "</div>\n";
                         }
                         if ($cell_data == '') {
                             $table_html .= "<span id='text_" . $field . $id . "'><a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"document.getElementById('file_{$field}{$id}').style.display = ''; document.getElementById('text_{$field}{$id}').style.display = 'none'; \">Add File</a></span> \n";
                             $table_html .= "<div id='file_" . $field . $id . "' style='display:none;'>\n";
                             $table_html .= $this->showUploadForm($field, $file_dest, $id);
                             $table_html .= "</div>\n";
                         }
                     } else {
                         $table_html .= $cell_data;
                     }
                 } else {
                     $table_html .= "<td>";
                     if (!is_numeric($found_category_index)) {
                         //was allowable values for this field defined?
                         if (is_array($this->allowed_values[$field]) && !$this->field_no_dropdown[$field]) {
                             $table_html .= $this->makeAjaxDropdown($id, $field, $cell_data, $this->db_table, $this->db_table_pk, $this->allowed_values[$field]);
                         } else {
                             //if a checkbox
                             if (is_array($this->checkbox[$field])) {
                                 $table_html .= $this->makeAjaxCheckbox($id, $field, $cell_data);
                             } else {
                                 //is an editable field
                                 //if ($cell_data == '') $cell_data = "&nbsp;&nbsp;";
                                 $field_onKeyPress = "";
                                 if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                     $field_onKeyPress = "return fn_validateNumeric(event, this, 'n');";
                                     if ($this->fieldIsDecimal($this->getFieldDataType($field))) {
                                         $field_onKeyPress = "return fn_validateNumeric(event, this, 'y');";
                                     }
                                 }
                                 if ($this->fieldIsEnum($this->getFieldDataType($field))) {
                                     $allowed_enum_values_array = $this->getEnumArray($this->getFieldDataType($field));
                                     $table_html .= $this->makeAjaxDropdown($id, $field, $cell_data, $this->db_table, $this->db_table_pk, $allowed_enum_values_array);
                                 } else {
                                     $field_length = strlen($row[$field]);
                                     if ($field_length < 51) {
                                         $table_html .= $this->makeAjaxEditor($id, $field, $cell_value, 'text', $field_length, $cell_data, $field_onKeyPress);
                                     } else {
                                         $textarea_height = '';
                                         if ($this->textarea_height[$field] != '') {
                                             $textarea_height = $this->textarea_height[$field];
                                         }
                                         $table_html .= $this->makeAjaxEditor($id, $field, $cell_value, 'textarea', $textarea_height, $cell_data, $field_onKeyPress);
                                     }
                                 }
                             }
                         }
                     } else {
                         //this field is a reference to another table's primary key (eg it must be a foreign key)
                         $category_field_name = $this->category_field_array[$found_category_index];
                         $category_table_name = $this->category_table_array[$found_category_index];
                         $category_table_pk = $this->category_table_pk_array[$found_category_index];
                         $selected_dropdown_text = "--";
                         //in case value is blank
                         if ($cell_data != "") {
                             $selected_dropdown_text = q1("SELECT {$category_field_name} FROM {$category_table_name} WHERE {$category_table_pk} = \"" . $cell_value . "\"");
                             //echo "field: $field - $selected_dropdown_text <br />\n";
                         }
                         if (!$this->fieldInArray($field, $this->uneditable_fields)) {
                             $table_html .= $this->makeAjaxDropdown($id, $field, $cell_value, $category_table_name, $category_table_pk, $dropdown_array[$found_category_index], $selected_dropdown_text);
                         } else {
                             $table_html .= $selected_dropdown_text;
                         }
                     }
                 }
                 $html .= "</td>";
             }
             if ($this->delete || count($this->row_button) > 0) {
                 $table_html .= "<td>\n";
                 if ($this->delete) {
                     $table_html .= "<input type=\"button\" class=\"editingSize\" onClick=\"confirmDelete('{$id}', '" . $this->db_table . "', '" . $this->db_table_pk . "');\" value=\"delete\" />\n";
                 }
                 if (count($this->row_button) > 0) {
                     foreach ($this->row_button as $the_row_button) {
                         $value = $the_row_button[0];
                         $url = $the_row_button[1];
                         $attach_param = $the_row_button[2];
                         $javascript_onclick_function = $the_row_button[3];
                         if ($attach_param == "all") {
                             $attach = "?attachments" . $attach_params;
                         } else {
                             $attach = "?" . $this->db_table_pk . "={$id}";
                         }
                         //its most likely a user-defined ajax function
                         if ($javascript_onclick_function != "") {
                             $javascript_for_button = "onClick=\"" . $javascript_onclick_function . "({$id});\"";
                         } else {
                             $javascript_for_button = "onClick=\"location.href='" . $url . $attach . "'\"";
                         }
                         $table_html .= "<input type=\"button\" {$javascript_for_button} class=\"btn editingSize\" value=\"{$value}\" />\n";
                     }
                 }
                 $table_html .= "</td>\n";
             }
             $table_html .= "</tr>";
             if ($count % 2 == 0) {
                 $class = "cell_row";
             } else {
                 $class = "odd";
             }
             $count++;
         }
         //foreach row
         $table_html .= "</table>\n";
         //paging links
         if ($totalpage > 1) {
             $table_html .= "<br /><div style='width: 800px; position: relative; left: 50%; margin-left: -400px; text-align: center;'><center> {$links} </center></div><br /><br />";
         }
     }
     //if rows > 0
     //closing div for paging links (if applicable)
     $bottom_html = "</div><br />\n";
     //now we come to the "add" fields
     if ($this->add) {
         $add_html .= "<center>\n";
         $add_html .= "   <input type=\"button\" value=\"Add {$item}\" class=\"btn editingSize\" onClick=\"\$('#add_form_{$this->db_table}').slideDown('slow');\">\n";
         if (count($this->bottom_button) > 0) {
             $button_value = $this->bottom_button[0];
             $button_url = $this->bottom_button[1];
             $button_tags = $this->bottom_button[2];
             if ($button_tags == '') {
                 $tag_stuff = "onClick=\"location.href = '{$button_url}';\"";
             } else {
                 $tag_stuff = $button_tags;
             }
             $add_html .= "  <input type=\"button\" value=\"{$button_value}\" href=\"{$button_url}\" class=\"btn\" {$tag_stuff}>\n";
         }
         //$add_html .= "  <input type=\"button\" value=\"Go Back\" class=\"btn\" onClick=\"history.back();\">\n";
         $add_html .= "</center>\n";
         $add_html .= "<form action=\"" . $_SERVER['PHP_SELF'] . "#ajaxCRUD\" id=\"add_form_{$this->db_table}\" method=\"POST\" ENCTYPE=\"multipart/form-data\" style=\"display:none;\">\n";
         $add_html .= "  <br /><h3>New <b>{$item}</b></h3>\n";
         $add_html .= "  <table align='center' name='form'>\n";
         $add_html .= "<tr valign='top'>\n";
         //for here display ALL 'addable' fields
         foreach ($this->add_fields as $field) {
             if ($field != $this->db_table_pk || $this->on_add_specify_primary_key) {
                 $field_value = "";
                 if ($_REQUEST[$field] != '') {
                     $field_value = $_REQUEST[$field];
                 }
                 if ($this->displayAs_array[$field] != '') {
                     $display_field = $this->displayAs_array[$field];
                 } else {
                     $display_field = $field;
                 }
                 //if a checkbox
                 if (is_array($this->checkbox[$field])) {
                     $values = $this->checkbox[$field];
                     $value_on = $values[0];
                     $value_off = $values[1];
                     $add_html .= "<th width='20%'>{$display_field}</th><td>\n";
                     $add_html .= "<input type='checkbox' name=\"{$field}\" value=\"{$value_on}\">\n";
                     $add_html .= "</td></tr>\n";
                 } else {
                     $found_category_index = array_search($field, $this->db_table_fk_array);
                     if (!is_numeric($found_category_index) && $found_category_index == '') {
                         //it's from a set of predefined allowed values for this field
                         if (is_array($this->allowed_values[$field])) {
                             $add_html .= "<th width='20%'>{$display_field}</th><td>\n";
                             $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                             foreach ($this->allowed_values[$field] as $dropdown) {
                                 $selected = "";
                                 $dropdown_value = $dropdown[0];
                                 $dropdown_text = $dropdown[1];
                                 if ($field_value == $dropdown_value) {
                                     $selected = " selected";
                                 }
                                 $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                             }
                             $add_html .= "</select></td></tr>\n";
                         } else {
                             if ($this->fieldInArray($field, $this->file_uploads)) {
                                 //this field is an file upload
                                 $add_html .= "<th width='20%'>{$display_field}</th><td><input class=\"editingSize\" type=\"file\" name=\"{$field}\" size=\"15\"></td></tr>\n";
                                 $file_uploads = true;
                             } else {
                                 if ($this->fieldIsEnum($this->getFieldDataType($field))) {
                                     $allowed_enum_values_array = $this->getEnumArray($this->getFieldDataType($field));
                                     $add_html .= "<th width='20%'>{$display_field}</th><td>\n";
                                     $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                                     foreach ($allowed_enum_values_array as $dropdown) {
                                         $dropdown_value = $dropdown;
                                         $dropdown_text = $dropdown;
                                         if ($field_value == $dropdown_value) {
                                             $selected = " selected";
                                         }
                                         $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                                     }
                                     $add_html .= "</select></td></tr>\n";
                                 } else {
                                     $field_onKeyPress = "";
                                     if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                         $field_onKeyPress = "return fn_validateNumeric(event, this, 'n');";
                                         if ($this->fieldIsDecimal($this->getFieldDataType($field))) {
                                             $field_onKeyPress = "return fn_validateNumeric(event, this, 'y');";
                                         }
                                     }
                                     //textarea fields
                                     if ($this->textarea_height[$field] != '') {
                                         $add_html .= "<th width='20%'>{$display_field}</th><td><textarea onKeyPress=\"{$field_onKeyPress}\" class=\"editingSize\" name=\"{$field}\" style='width: 97%; height: " . $this->textarea_height[$field] . "px;'>{$field_value}</textarea></td></tr>\n";
                                     } else {
                                         //any ol' data will do
                                         $field_size = "";
                                         if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                             $field_size = 7;
                                         }
                                         $add_html .= "<th width='20%'>{$display_field}</th><td><input onKeyPress=\"{$field_onKeyPress}\" class=\"editingSize\" type=\"text\" name=\"{$field}\" size=\"{$field_size}\" value=\"{$field_value}\" maxlength=\"150\"></td></tr>\n";
                                     }
                                 }
                                 //else not enum field
                             }
                             //not an uploaded file
                         }
                         //not a pre-defined value
                     } else {
                         //field is from a defined relationship
                         $key = $found_category_index;
                         $add_html .= "<th>{$display_field}</th><td>\n";
                         $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                         if ($this->category_required[$field] != TRUE) {
                             if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                 $add_html .= "<option value=0>--Select--</option>\n";
                             } else {
                                 $add_html .= "<option value=''>--Select--</option>\n";
                             }
                         }
                         foreach ($dropdown_array[$key] as $dropdown) {
                             $selected = "";
                             $dropdown_value = $dropdown[$this->category_table_pk_array[$key]];
                             $dropdown_text = $dropdown[$this->category_field_array[$key]];
                             if ($field_value == $dropdown_value) {
                                 $selected = " selected";
                             }
                             $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                         }
                         $add_html .= "</select></td></tr>\n";
                     }
                 }
                 //not a checkbox
             }
             //not the primary pk
         }
         //foreach
         $add_html .= "</tr><tr><td>\n";
         if ($this->ajax_add) {
             $add_html .= "<input class=\"editingSize\" type=\"button\" onClick=\"\n                    setLoadingImage('{$this->db_table}');\n                    var fields = getFormValues(document.getElementById('add_form_{$this->db_table}'), '');\n                    fields = fields + '&table={$this->db_table}';\n                    var req = '" . $_SERVER[PHP_SELF] . "?action=add&' + fields;\n                    clearForm('add_form_{$this->db_table}');\n                    sndAddReq(req, '{$this->db_table}');\n                    return false;\" value=\"Add {$item}\">";
         } else {
             $add_html .= "<input class=\"editingSize\" type=\"submit\" value=\"Add {$item}\">";
         }
         $add_html .= "</td><td><input style='float: right;' class=\"editingSize\" type=\"button\" onClick=\"\$('#add_form_{$this->db_table}').slideUp('slow');\" value=\"Cancel\"></td></tr>\n</table>\n";
         $add_html .= "<input type=\"hidden\" name=\"action\" value=\"add\">\n";
         $add_html .= "<input type=\"hidden\" name=\"table\" value=\"{$this->db_table}\">\n";
         if ($file_uploads) {
             $add_html .= "<input type=\"hidden\" name=\"uploads_on\" value=\"true\">\n";
         }
         $add_html .= "</form>\n";
     }
     //if adding fields is "allowed"
     /*
             THIS IS IMPORTANT
             for ajax retrieval (see top of page) */
     $_SESSION[$this->db_table] = $table_html;
     $html = $top_html . $table_html . $bottom_html . $add_html;
     if ($this->add_form_top) {
         $html = $add_html . $top_html . $table_html . $bottom_html;
     }
     echo $html;
 }
Пример #2
0
 function showTable()
 {
     global $error_msg;
     global $report_msg;
     global $warning_msg_displayed;
     global $num_ajaxCRUD_tables_instantiated;
     global $headerAdded;
     $num_ajaxCRUD_tables_instantiated++;
     /* Filter Table (if there are request parameters)
      */
     $count_filtered = 0;
     $action = "";
     if (isset($_REQUEST['action'])) {
         $action = $_REQUEST['action'];
     }
     foreach ($this->fields as $field) {
         //this if condition is so MULTIPLE ajaxCRUD tables can be used on the same page.
         if ($_REQUEST['table'] == $this->db_table) {
             if (isset($_REQUEST[$field]) && $_REQUEST[$field] != '' && ($action != 'add' && $action != 'delete' && $action != 'update' && $action != 'upload' && $action != 'delete_file')) {
                 $filter_field = $field;
                 $filter_value = $_REQUEST[$field];
                 if ($this->exactSearchField[$filter_field]) {
                     //exact search (is set by
                     $filter_where_clause = "WHERE {$filter_field} = \"{$filter_value}\"";
                 } else {
                     //approximate search (default)
                     $filter_where_clause = "WHERE {$filter_field} LIKE \"%" . $filter_value . "%\"";
                 }
                 $this->addWhereClause($filter_where_clause);
                 $this->filtered_table = true;
                 $count_filtered++;
             }
         }
     }
     if ($count_filtered > 0) {
         $this->filtered_table;
     } else {
         $this->filtered_table = false;
     }
     /* Sort Table
           Note: this cancels out default sorting set by addOrderBy()
        */
     if (isset($_REQUEST['table']) && isset($_REQUEST['sort_field'])) {
         if ($this->db_table == $_REQUEST['table'] && $_REQUEST['sort_field'] != '') {
             $sort_field = $_REQUEST['sort_field'];
             $user_sort_order_direction = $_REQUEST['sort_direction'];
             if ($user_sort_order_direction == 'asc') {
                 $this->sort_direction = "desc";
             } else {
                 $this->sort_direction = "asc";
             }
             $sort_sql = " ORDER BY {$sort_field} {$this->sort_direction}";
             $this->addOrderBy($sort_sql);
             $this->sorted_table = true;
         }
     }
     //the HTML to display
     $top_html = "";
     //top header stuff
     $table_html = "";
     //for the html table itself
     $bottom_html = "";
     $add_html = "";
     //for the add form
     $html = "";
     //all combined
     if ($num_ajaxCRUD_tables_instantiated == 1 && !$headerAdded) {
         //pull in the  css and javascript files
         $this->insertHeader($this->ajax_file);
     }
     if ($this->doActionOnShowTable) {
         if (isset($_REQUEST['action']) && $_REQUEST['action'] != '') {
             $this->doAction($_REQUEST['action']);
         }
     }
     $item = $this->item;
     //this array is used to populate the dropdown boxes set by defined relationships (to other tables)
     $dropdown_array = array();
     foreach ($this->category_table_array as $key => $category_table) {
         $category_field_name = $this->category_field_array[$key];
         $category_table_pk = $this->category_table_pk_array[$key];
         $order_by = '';
         if ($this->category_sort_field_array[$key] != '') {
             $order_by = " ORDER BY " . $this->category_sort_field_array[$key];
         }
         $whereclause = '';
         if ($this->category_whereclause_array[$key] != '') {
             $whereclause = $this->category_whereclause_array[$key];
         }
         $dropdown_array[] = q("SELECT {$category_table_pk}, {$category_field_name} FROM {$category_table} {$whereclause} {$order_by}");
     }
     $top_html .= "<a name='ajaxCRUD" . $num_ajaxCRUD_tables_instantiated . "' id='ajaxCRUD" . $num_ajaxCRUD_tables_instantiated . "'></a>\n";
     if (!isset($extra_query_params)) {
         $extra_query_params = "";
     }
     //this is used by certain applications which require extra query params to be passed (not typical)
     if (count($this->ajaxFilter_fields) > 0) {
         $top_html .= "<form id=\"" . $this->db_table . "_filter_form\" class=\"ajaxCRUD\">\n";
         $top_html .= "<table class='table' cellspacing='5' align='center'><tr><thead>";
         foreach ($this->ajaxFilter_fields as $filter_field) {
             $display_field = $filter_field;
             if ($this->displayAs_array[$filter_field] != '') {
                 $display_field = $this->displayAs_array[$filter_field];
             }
             //TODO: this var is used to see if there is a defined relationship with the field (I hate this approach and need to re-architect it!)
             $found_category_index = array_search($filter_field, $this->db_table_fk_array);
             $textbox_size = $this->ajaxFilterBoxSize[$filter_field];
             $filter_value = "";
             if (isset($_REQUEST[$filter_field]) && $_REQUEST[$filter_field] != '') {
                 //$filter_value = $_REQUEST[$filter_field];
                 $filter_value = utf8_encode($_REQUEST[$filter_field]);
             }
             $top_html .= "<th><b>{$display_field}</b>:";
             //check for valid values (set by defineAllowableValues)
             if (isset($this->allowed_values[$filter_field]) && is_array($this->allowed_values[$filter_field])) {
                 $top_html .= "<select name=\"{$filter_field}\" onChange=\"filterTable(this, '" . $this->db_table . "', '{$filter_field}', '{$extra_query_params}');\">";
                 $top_html .= "<option value=\"\">==Select==</option>\n";
                 foreach ($this->allowed_values[$filter_field] as $list) {
                     if (is_array($list)) {
                         $list_val = $list[0];
                         $list_option = $list[1];
                     } else {
                         $list_val = $list;
                         $list_option = $list;
                     }
                     $top_html .= "<option value=\"{$list_val}\">{$list_option}</option>\n";
                 }
                 $top_html .= "</select>\n";
             } else {
                 if (is_numeric($found_category_index)) {
                     $top_html .= "<select name=\"{$filter_field}\" onChange=\"filterTable(this, '" . $this->db_table . "', '{$filter_field}', '{$extra_query_params}');\">";
                     $top_html .= "<option value=\"\">==Select==</option>\n";
                     //this field is a reference to another table's primary key (eg it must be a foreign key)
                     $category_field_name = $this->category_field_array[$found_category_index];
                     $category_table_name = $this->category_table_array[$found_category_index];
                     $category_table_pk = $this->category_table_pk_array[$found_category_index];
                     //this array is set above (used a few places in the class) - sorry, a bit of repeating code here :-(
                     foreach ($dropdown_array[$found_category_index] as $dropdown) {
                         $dropdown_value = $dropdown[$this->category_table_pk_array[$found_category_index]];
                         $dropdown_text = $dropdown[$this->category_field_array[$found_category_index]];
                         $top_html .= "<option value=\"{$dropdown_value}\">{$dropdown_text}</option>\n";
                     }
                     $top_html .= "</select>\n";
                 } else {
                     if (isset($this->checkbox[$filter_field]) && is_array($this->checkbox[$filter_field])) {
                         $values = $this->checkbox[$filter_field];
                         $value_on = $values[0];
                         $value_off = $values[1];
                         $checked = '';
                         if (isset($field_value) && $field_value == $value_on) {
                             $checked = "checked";
                         }
                         $top_html .= "<input type=\"checkbox\" name=\"{$filter_field}\" {$checked} value=\"{$value_on}\" onClick=\"filterTable(this, '" . $this->db_table . "', '{$filter_field}', '{$extra_query_params}');\">";
                     } else {
                         $customClass = "";
                         if (isset($this->display_field_with_class_style[$filter_field]) && $this->display_field_with_class_style[$filter_field] != '') {
                             $customClass = $this->display_field_with_class_style[$filter_field];
                         }
                         $top_html .= "<input type=\"text\" class=\"{$customClass}\" size=\"{$textbox_size}\" name=\"{$filter_field}\" value=\"{$filter_value}\" onKeyUp=\"filterTable(this, '" . $this->db_table . "', '{$filter_field}', '{$extra_query_params}');\">";
                     }
                 }
             }
             $top_html .= "&nbsp;&nbsp;</th>";
         }
         $top_html .= "</tr></thead></table>\n";
         $top_html .= "</form>\n";
     }
     #############################################
     #
     # Begin code for displaying database elements
     #
     #############################################
     $select_fields = implode(",", $this->fields);
     $sql = "SELECT * FROM " . $this->db_table . $this->sql_where_clause . $this->sql_order_by;
     //added name for table (t) in case where clauses want to use it (7.2.2)
     if ($this->showPaging) {
         $pageid = "";
         if (isset($_REQUEST['pid'])) {
             $pageid = $_REQUEST['pid'];
             //Get the pid value
         }
         if (intval($pageid) == 0) {
             $pageid = 1;
         }
         $Paging = new paging();
         $Paging->tableName = $this->db_table;
         $total_records = $Paging->myRecordCount($sql);
         //count records
         $totalpage = $Paging->processPaging($this->limit, $pageid);
         $rows = $Paging->startPaging($sql);
         //get records in the databse
         $links = $Paging->pageLinks(basename($_SERVER['PHP_SELF']));
         //1234 links
         unset($Paging);
     } else {
         $rows = q($sql . $this->sql_limit);
     }
     //echo $sql;
     //$row_count = count($rows); //count should NOT consider paging
     $row_count = $this->getNumRows();
     $this->row_count = $row_count;
     $_SESSION['row_count'] = $row_count;
     //DEPRECATED
     $_SESSION[$this->db_table . '_row_count'] = $row_count;
     if ($row_count == 0) {
         $report_msg[] = $this->emptyTableMessage;
     }
     #this is an optional function which will allow you to display errors or report messages as desired. comment it out if desired
     //only show the message box if it hasn't been displayed already
     if ($warning_msg_displayed == 0 || $warning_msg_displayed == '') {
         echo_msg_box();
     }
     $top_html .= "<div id='{$this->db_table}'>\n";
     if ($row_count > 0) {
         /*
         commenting out the 'edit item' text at the top; feel free to add back in if you want
         $edit_word = "Edit";
         if ($row_count == 0) $edit_word = "No";
         $top_html .= "<h3>Edit " . $this->item_plural . "</h3>\n";
         */
         //for vertical display, have a little spacing in there
         if ($this->orientation == 'vertical' && $this->cellspacing == "") {
             $this->cellspacing = 2;
         }
         $table_html .= "<div class='table-responsive'><table align='center' class='table table-responsive' name='table_" . $this->db_table . "' id='table_" . $this->db_table . "' cellspacing='" . $this->cellspacing . "' border=" . $this->border . ">\n";
         //only show the header (field names) at top for horizontal display (default)
         if ($this->orientation != 'vertical') {
             if ($this->includeTableHeaders) {
                 $table_html .= "<thead><tr>\n";
                 //for an (optional) checkbox
                 if ($this->showCheckbox) {
                     $table_html .= "<th>&nbsp;</th>";
                 }
                 foreach ($this->display_fields as $field) {
                     $field_name = $field;
                     if ($this->displayAs_array[$field] != '') {
                         $field = $this->displayAs_array[$field];
                     }
                     if (!$this->fieldInArray($field_name, $this->unsortable_fields)) {
                         $fieldHeaderHTML = "<a href='javascript:;' onClick=\"changeSort('{$this->db_table}', '{$field_name}', '{$this->sort_direction}');\" >" . $field . "</a>";
                     } else {
                         $fieldHeaderHTML = $field;
                     }
                     if (array_key_exists($field_name, $this->checkboxall)) {
                         $table_html .= "<th><input type=\"checkbox\" name=\"{$field_name}" . "_checkboxall\" value=\"checkAll\" onClick=\"\n                        if (this.checked) {\n                           setAllCheckboxes('{$field_name}" . "_fieldckbox',false);\n                        } else {\n                           setAllCheckboxes('{$field_name}" . "_fieldckbox',true);\n                        }\n                        \">";
                         if ($this->checkboxall[$field_name] == true) {
                             $table_html .= $fieldHeaderHTML;
                         }
                         $table_html .= "</th>";
                     } else {
                         $table_html .= "<th>{$fieldHeaderHTML}</th>";
                     }
                 }
                 if ($this->delete || count($this->row_button) > 0) {
                     $table_html .= "<th>" . $this->actionText . "</th>\n";
                 }
                 $table_html .= "</tr></thead>\n";
             }
         }
         $count = 0;
         $class = "odd";
         $attach_params = "";
         $valign = "middle";
         foreach ($rows as $row) {
             $id = $row[$this->db_table_pk];
             if ($this->orientation == 'vertical') {
                 $class = "vertical" . " {$class}";
                 $valign = "middle";
             }
             $table_html .= "<tr class='{$class}' id=\"" . $this->db_table . "_row_{$id}\" valign='{$valign}'>\n";
             if ($this->showCheckbox && $this->orientation != 'vertical') {
                 $checkbox_selected = "";
                 if ($id == $_REQUEST[$this->db_table_pk]) {
                     $checkbox_selected = " checked";
                 }
                 $table_html .= "<td><input type='checkbox' {$checkbox_selected} onClick=\"window.location ='" . $_SERVER['PHP_SELF'] . "?{$this->db_table_pk}={$id}'\" /></td>";
             }
             $canRowBeUpdated = true;
             if (isset($this->validate_update_with_function) && $this->validate_update_with_function != '') {
                 $canRowBeUpdated = call_user_func($this->validate_update_with_function, $id);
             }
             foreach ($this->display_fields as $field) {
                 $cell_data = $row[$field];
                 //for adding a button via addButtonToRow
                 if (count($this->row_button) > 0) {
                     $attach_params .= "&" . $field . "=" . urlencode($cell_data);
                 }
                 $cell_value = $cell_data;
                 //retain original value in new variable (before executing callback method)
                 if (isset($this->format_field_with_function[$field]) && $this->format_field_with_function[$field] != '') {
                     $cell_data = call_user_func($this->format_field_with_function[$field], $cell_data);
                 }
                 if (isset($this->format_field_with_function_adv[$field]) && $this->format_field_with_function_adv[$field] != '') {
                     $cell_data = call_user_func($this->format_field_with_function_adv[$field], $cell_data, $id);
                 }
                 //try to find a reference to another table relationship
                 $found_category_index = array_search($field, $this->db_table_fk_array);
                 //if orientation is vertical show the field name next to the field
                 if ($this->orientation == 'vertical') {
                     if ($this->displayAs_array[$field] != '') {
                         $fieldName = $this->displayAs_array[$field];
                     } else {
                         $fieldName = $field;
                     }
                     $table_html .= "<th class='vertical'>{$fieldName}</th>";
                 }
                 //don't allow uneditable fields (which usually includes the primary key) to be editable
                 if (!$canRowBeUpdated || $this->fieldInArray($field, $this->file_uploads) || $this->fieldInArray($field, $this->uneditable_fields) && !is_numeric($found_category_index)) {
                     $table_html .= "<td>";
                     $key = array_search($field, $this->display_fields);
                     if ($this->fieldInArray($field, $this->file_uploads) && !$this->fieldInArray($field, $this->uneditable_fields)) {
                         //a file exists for this field
                         $file_dest = "";
                         if ($cell_data != '') {
                             $file_link = $this->file_upload_info[$field]['relative_folder'] . $row[$field];
                             $file_dest = $this->file_upload_info[$field]['destination_folder'];
                             $table_html .= "<span style=\"font-size: 9px;\" id='text_" . $field . $id . "'><a target=\"_new\" href=\"{$file_link}\">" . $cell_data . "</a> <a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"document.getElementById('file_{$field}{$id}').style.display = ''; document.getElementById('text_{$field}{$id}').style.display = 'none'; \">" . $this->fileEditText . "</a> | <a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"deleteFile('{$field}', '{$id}')\">" . $this->fileDeleteText . "</a></span>\n";
                             $table_html .= "<div id='file_" . $field . $id . "' style='display:none;'>\n";
                             $table_html .= $this->showUploadForm($field, $file_dest, $id);
                             $table_html .= "</div>\n";
                         } else {
                             $table_html .= "<span id='text_" . $field . $id . "'><a style=\"font-size: 9px;\" href=\"javascript:\" onClick=\"document.getElementById('file_{$field}{$id}').style.display = ''; document.getElementById('text_{$field}{$id}').style.display = 'none'; \">Add File</a></span> \n";
                             $table_html .= "<div id='file_" . $field . $id . "' style='display:none;'>\n";
                             $table_html .= $this->showUploadForm($field, $file_dest, $id);
                             $table_html .= "</div>\n";
                         }
                     } else {
                         //added in 6.5. allows defineAllowableValues to work even when in readonly mode
                         if (isset($this->allowed_values[$field]) && is_array($this->allowed_values[$field])) {
                             foreach ($this->allowed_values[$field] as $list) {
                                 if (is_array($list)) {
                                     $list_val = $list[0];
                                     $list_option = $list[1];
                                 } else {
                                     $list_val = $list;
                                     $list_option = $list;
                                 }
                                 //fixed bug in 8.76. cell_value ensures we're looking at original value vs value set by user-defined function
                                 if ($list_val == $cell_value) {
                                     $table_html .= $list_option;
                                 }
                             }
                         } else {
                             $table_html .= stripslashes($cell_data);
                         }
                     }
                 } else {
                     $table_html .= "<td>";
                     if (!is_numeric($found_category_index)) {
                         //was allowable values for this field defined?
                         if (isset($this->allowed_values[$field]) && is_array($this->allowed_values[$field]) && !isset($this->field_no_dropdown[$field])) {
                             $table_html .= $this->makeAjaxDropdown($id, $field, $cell_value, $this->db_table, $this->db_table_pk, $this->allowed_values[$field]);
                         } else {
                             //if a checkbox
                             if (isset($this->checkbox[$field]) && is_array($this->checkbox[$field])) {
                                 $table_html .= $this->makeAjaxCheckbox($id, $field, $cell_value);
                             } else {
                                 //is an editable field
                                 //if ($cell_data == '') $cell_data = "&nbsp;&nbsp;";
                                 $field_onKeyPress = "";
                                 if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                     $field_onKeyPress = "return fn_validateNumeric(event, this, 'n');";
                                     if ($this->fieldIsDecimal($this->getFieldDataType($field))) {
                                         $field_onKeyPress = "return fn_validateNumeric(event, this, 'y');";
                                     }
                                 }
                                 if ($this->fieldIsEnum($this->getFieldDataType($field))) {
                                     $allowed_enum_values_array = $this->getEnumArray($this->getFieldDataType($field));
                                     $table_html .= $this->makeAjaxDropdown($id, $field, $cell_value, $this->db_table, $this->db_table_pk, $allowed_enum_values_array);
                                 } else {
                                     //updated logic in 7.1 to enable a textarea to be 'forced' if desired [thanks to dpruitt for code revision]
                                     $field_length = strlen($row[$field]);
                                     if (isset($this->textarea_height[$field]) && $this->textarea_height[$field] != '' || $field_length > 51) {
                                         $textarea_height = '';
                                         if ($this->textarea_height[$field] != '') {
                                             $textarea_height = $this->textarea_height[$field];
                                         }
                                         $table_html .= $this->makeAjaxEditor($id, $field, $cell_value, 'textarea', $textarea_height, $cell_data, $field_onKeyPress);
                                     } else {
                                         //if the textbox width was set manually with function setTextboxWidth
                                         if (isset($this->textboxWidth[$field]) && $this->textboxWidth[$field] != '') {
                                             $field_length = $this->textboxWidth[$field];
                                         }
                                         $table_html .= $this->makeAjaxEditor($id, $field, $cell_value, 'text', $field_length, $cell_data, $field_onKeyPress);
                                     }
                                 }
                             }
                         }
                     } else {
                         //this field is a reference to another table's primary key (eg it must be a foreign key)
                         $category_field_name = $this->category_field_array[$found_category_index];
                         $category_table_name = $this->category_table_array[$found_category_index];
                         $category_table_pk = $this->category_table_pk_array[$found_category_index];
                         $selected_dropdown_text = "--";
                         //in case value is blank
                         if ($cell_data != "") {
                             $selected_dropdown_text = q1("SELECT {$category_field_name} FROM {$category_table_name} WHERE {$category_table_pk} = \"" . $cell_value . "\"");
                             //echo "field: $field - $selected_dropdown_text <br />\n";
                         }
                         if (!$this->fieldInArray($field, $this->uneditable_fields)) {
                             $table_html .= $this->makeAjaxDropdown($id, $field, $cell_value, $category_table_name, $category_table_pk, $dropdown_array[$found_category_index], $selected_dropdown_text);
                         } else {
                             $table_html .= $selected_dropdown_text;
                         }
                     }
                 }
                 $table_html .= "</td>";
                 if ($this->orientation == 'vertical') {
                     $table_html .= "</tr><tr class='{$class}' id=\"" . $this->db_table . "_row_{$id}\" valign='middle'>\n";
                 }
             }
             //foreach displayFields
             if ($this->delete || count($this->row_button) > 0) {
                 if ($this->orientation == 'vertical') {
                     $table_html .= "<th class='vertical'>" . $this->actionText . "</th>";
                 }
                 $table_html .= "<td>\n";
                 if ($this->delete) {
                     $canRowBeDeleted = true;
                     if (isset($this->validate_delete_with_function) && $this->validate_delete_with_function != '') {
                         $canRowBeDeleted = call_user_func($this->validate_delete_with_function, $id);
                     }
                     if ($canRowBeDeleted) {
                         $table_html .= "<input type=\"button\" class=\"btn editingSize\" onClick=\"confirmDelete('{$id}', '" . $this->db_table . "', '" . $this->db_table_pk . "');\" value=\"" . $this->deleteText . "\" />\n";
                     }
                 }
                 if (count($this->row_button) > 0) {
                     foreach ($this->row_button as $button_id => $the_row_button) {
                         $value = $the_row_button[0];
                         $url = $the_row_button[1];
                         $attach_param = $the_row_button[2];
                         //optional param
                         $javascript_onclick_function = $the_row_button[3];
                         //optional param
                         $window_to_open = $the_row_button[4];
                         //optional param
                         if ($attach_param == "all") {
                             $attach = "?attachments" . $attach_params;
                         } else {
                             $char = "?";
                             if (stristr($url, "?") !== FALSE) {
                                 $char = "&";
                                 //the url already has get parameters; attach the id with it
                             }
                             $getParam = $this->db_table_pk;
                             $valueToPass = $id;
                             if ($attach_param != "all" && $attach_param != "") {
                                 $getParam = $attach_param;
                                 //check to see if the field being passed is a db column
                                 if ($this->fieldInArray($attach_param, $this->fields)) {
                                     $valueToPass = $row[$attach_param];
                                 }
                             }
                             $valueToPass = urlencode($valueToPass);
                             $attach = $char . $getParam . "={$valueToPass}";
                         }
                         //its most likely a user-defined ajax function
                         if ($javascript_onclick_function != "") {
                             $javascript_for_button = "onClick=\"" . $javascript_onclick_function . "({$id});\"";
                         } else {
                             //either button-specific window is 'same' or global (all buttons' window is 'same'
                             if ($window_to_open == "same" && $this->addButtonToRowWindowOpen == "same") {
                                 $javascript_for_button = "onClick=\"location.href='" . $url . $attach . "'\"";
                             } else {
                                 $javascript_for_button = "onClick=\"window.open('" . $url . $attach . "')\"";
                             }
                         }
                         $table_html .= "<input type=\"button\" {$javascript_for_button} class=\"btn editingSize\" value=\"{$value}\" />\n";
                     }
                 }
                 $table_html .= "</td>\n";
             }
             $table_html .= "</tr>";
             if ($this->orientation == 'vertical') {
                 $table_html .= "<tr><td colspan='2' style='border-top: 4px silver solid;' ></td></tr>\n";
             }
             if ($count % 2 == 0) {
                 $class = "cell_row";
             } else {
                 $class = "odd";
             }
             $count++;
         }
         //foreach row
         $table_html .= "</table></div>\n";
         //paging links
         if ($totalpage > 1) {
             $table_html .= "<br /><div style='width: 800px; position: relative; left: 50%; margin-left: -400px; text-align: center;'><center> {$links} </center></div><br /><br />";
         }
     }
     //if rows > 0
     //closing div for paging links (if applicable)
     $bottom_html = "</div><br />\n";
     // displaying the export to csv button
     if ($this->showCSVExport) {
         $add_html .= "<center>\n";
         $add_html .= "<form action=\"" . $_SERVER["SCRIPT_NAME"] . "\" name=\"CSVExport\" method=\"POST\" >\n";
         $add_html .= "  <input type=\"hidden\" name=\"fileName\" value=\"tableoutput.csv\" />\n";
         $add_html .= "  <input type=\"hidden\" name=\"customAction\" value=\"exportToCSV\" />\n";
         $add_html .= " <input type=\"hidden\" name=\"tableData\" value=\"" . $this->createCSVOutput() . "\" />\n";
         $add_html .= "  <input type=\"submit\" name=\"submit\" value=\"Export Table To CSV\" class=\"btn editingSize\"/>\n";
         $add_html .= "</form>\n";
         $add_html .= "</center>\n";
     }
     $add_html .= "<center>\n";
     //now we come to the "add" fields
     if ($this->add) {
         $addButtonVal = $this->addText . " " . $item;
         if ($this->addButtonText != "") {
             $addButtonVal = $this->addButtonText;
         }
         $add_html .= "   <input type=\"button\" value=\"{$addButtonVal}\" class=\"btn editingSize\" onClick=\"\$('#add_form_{$this->db_table}').slideDown('fast'); x = document.getElementById('add_form_{$this->db_table}'); t = setTimeout('x.scrollIntoView(false)', 200); \">\n";
     }
     if (count($this->bottom_button) > 0) {
         foreach ($this->bottom_button as $button) {
             $button_value = $button[0];
             $button_url = $button[1];
             $button_tags = $button[2];
             if ($button_tags == '') {
                 $tag_stuff = "onClick=\"location.href = '{$button_url}';\"";
             } else {
                 $tag_stuff = $button_tags;
             }
             $add_html .= "  <input type=\"button\" value=\"{$button_value}\" href=\"{$button_url}\" class=\"btn\" {$tag_stuff}>\n";
         }
     }
     if ($this->add) {
         //$add_html .= "  <input type=\"button\" value=\"Go Back\" class=\"btn\" onClick=\"history.back();\">\n";
         $add_html .= "</center>\n";
         $formActionURL = $_SERVER['PHP_SELF'];
         if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
             //some web applications require posting to the same exact page (with parameters included); this is useful if/when onAddExecuteCallbackFunction is used
             $formActionURL = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
         }
         $add_html .= "<form action=\"" . $formActionURL . "#ajaxCRUD\" id=\"add_form_{$this->db_table}\" method=\"POST\" ENCTYPE=\"multipart/form-data\" style=\"display:none;\">\n";
         //$add_html .= "<br /><h3 align='center'>New <b>$item</b></h3>\n";
         $add_html .= "<br />\n";
         $add_html .= "<table align='center' name='form'>\n";
         //for here display ALL 'addable' fields
         foreach ($this->add_fields as $field) {
             $add_html .= "<tr>\n";
             if ($field != $this->db_table_pk || $this->on_add_specify_primary_key) {
                 $field_value = "";
                 $hideOnClick = "";
                 $placeholder = "";
                 //if a date field, show helping text
                 if ($this->fieldIsDate($this->getFieldDataType($field))) {
                     //$placeholder = "YYYY-mm-dd";
                     $placeholder = date("Y-m-d");
                     //$hideOnClick = TRUE;
                 }
                 //if initial field value for field is set
                 if (isset($this->initialFieldValue[$field]) && $this->initialFieldValue[$field] != "") {
                     $field_value = $this->initialFieldValue[$field];
                     //$hideOnClick = TRUE;
                 }
                 //the request (post/get) will overwrite any initial values though
                 if (isset($_REQUEST[$field]) && $_REQUEST[$field] != '') {
                     //$field_value = $_REQUEST[$field];  //note: disable because caused problems
                     //$hideOnClick = FALSE;
                 }
                 if ($hideOnClick) {
                     //$hideOnClick = "onClick = \"this.value = ''\"";
                 }
                 if ($this->displayAs_array[$field] != '') {
                     $display_field = $this->displayAs_array[$field];
                 } else {
                     $display_field = $field;
                 }
                 $note = "";
                 if (isset($this->fieldNote[$field]) && $this->fieldNote[$field] != "") {
                     $note = "&nbsp;&nbsp;<i>" . $this->fieldNote[$field] . "</i>";
                 }
                 if (isset($this->placeholderText[$field]) && $this->placeholderText[$field] != "") {
                     $placeholder = $this->placeholderText[$field];
                 }
                 //if a checkbox
                 if (isset($this->checkbox[$field]) && is_array($this->checkbox[$field])) {
                     $values = $this->checkbox[$field];
                     $value_on = $values[0];
                     $value_off = $values[1];
                     $add_html .= "<th>{$display_field}</th><td>\n";
                     $add_html .= "<input type='checkbox' name=\"{$field}\" value=\"{$value_on}\">\n";
                     $add_html .= "{$note}</td>\n";
                 } else {
                     $found_category_index = array_search($field, $this->db_table_fk_array);
                     if (!is_numeric($found_category_index) && $found_category_index == '') {
                         //it's from a set of predefined allowed values for this field
                         if (isset($this->allowed_values[$field]) && is_array($this->allowed_values[$field])) {
                             $add_html .= "<th>{$display_field}</th><td>\n";
                             $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                             foreach ($this->allowed_values[$field] as $dropdown) {
                                 $selected = "";
                                 $dropdown_value = $dropdown[0];
                                 $dropdown_text = $dropdown[1];
                                 if ($field_value == $dropdown_value) {
                                     $selected = " selected";
                                 }
                                 $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                             }
                             $add_html .= "</select>{$note}</td>\n";
                         } else {
                             if ($this->fieldInArray($field, $this->file_uploads)) {
                                 //this field is an file upload
                                 $add_html .= "<th>{$display_field}</th><td><input class=\"editingSize\" type=\"file\" name=\"{$field}\" size=\"15\">{$note}</td></tr>\n";
                                 $file_uploads = true;
                             } else {
                                 if ($this->fieldIsEnum($this->getFieldDataType($field))) {
                                     $allowed_enum_values_array = $this->getEnumArray($this->getFieldDataType($field));
                                     $add_html .= "<th>{$display_field}</th><td>\n";
                                     $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                                     foreach ($allowed_enum_values_array as $dropdown) {
                                         $dropdown_value = $dropdown;
                                         $dropdown_text = $dropdown;
                                         if ($field_value == $dropdown_value) {
                                             $selected = " selected";
                                         }
                                         $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                                     }
                                     $add_html .= "</select>{$note}</td></tr>\n";
                                 } else {
                                     $field_onKeyPress = "";
                                     if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                         $field_onKeyPress = "return fn_validateNumeric(event, this, 'n');";
                                         if ($this->fieldIsDecimal($this->getFieldDataType($field))) {
                                             $field_onKeyPress = "return fn_validateNumeric(event, this, 'y');";
                                         }
                                     }
                                     //textarea fields
                                     if (isset($this->textarea_height[$field]) && $this->textarea_height[$field] != '') {
                                         $add_html .= "<th>{$display_field}</th><td><textarea {$hideOnClick} onKeyPress=\"{$field_onKeyPress}\" class=\"editingSize\" name=\"{$field}\" style='width: 97%; height: " . $this->textarea_height[$field] . "px;'>{$field_value}</textarea>{$note}</td></tr>\n";
                                     } else {
                                         //any ol' text data (generic text box)
                                         $fieldType = "text";
                                         $fieldSize = "";
                                         //change the type of textbox field if a password (HTML 5 compatible)
                                         if (stristr($field, "password")) {
                                             $fieldType = "password";
                                         }
                                         //change the type of textbox field if a password (HTML 5 compatible)
                                         if (stristr($field, "email")) {
                                             $fieldType = "email";
                                         }
                                         if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                             $fieldSize = 7;
                                             $fieldType = "number";
                                         }
                                         //if the textbox width was set manually with function setTextboxWidth
                                         if (isset($this->textboxWidth[$field]) && $this->textboxWidth[$field] != '') {
                                             $fieldSize = $this->textboxWidth[$field];
                                         }
                                         $customClass = "";
                                         // Apply custom CSS class to field if applicable
                                         if (isset($this->display_field_with_class_style[$field]) && $this->display_field_with_class_style[$field] != '') {
                                             $customClass = $this->display_field_with_class_style[$field];
                                         }
                                         $add_html .= "<th>{$display_field}</th><td><input onKeyPress=\"{$field_onKeyPress}\" class=\"editingSize {$customClass}\" type=\"{$fieldType}\" id=\"{$field}\" name=\"{$field}\" size=\"{$fieldSize}\" maxlength=\"150\" value=\"{$field_value}\" placeholder=\"{$placeholder}\" >{$note}</td></tr>\n";
                                         $placeholder = "";
                                     }
                                 }
                                 //else not enum field
                             }
                             //not an uploaded file
                         }
                         //not a pre-defined value
                     } else {
                         //field is from a defined relationship
                         $key = $found_category_index;
                         $add_html .= "<th>{$display_field}</th><td>\n";
                         $add_html .= "<select name=\"{$field}\" class='editingSize'>\n";
                         if ($this->category_required[$field] != TRUE) {
                             if ($this->fieldIsInt($this->getFieldDataType($field)) || $this->fieldIsDecimal($this->getFieldDataType($field))) {
                                 $add_html .= "<option value='0'>--Select--</option>\n";
                             } else {
                                 $add_html .= "<option value=''>--Select--</option>\n";
                             }
                         }
                         foreach ($dropdown_array[$key] as $dropdown) {
                             $selected = "";
                             $dropdown_value = $dropdown[$this->category_table_pk_array[$key]];
                             $dropdown_text = $dropdown[$this->category_field_array[$key]];
                             if ($field_value == $dropdown_value) {
                                 $selected = " selected";
                             }
                             $add_html .= "<option value=\"{$dropdown_value}\" {$selected}>{$dropdown_text}</option>\n";
                         }
                         $add_html .= "</select>{$note}</td></tr>\n";
                     }
                 }
                 //not a checkbox
             }
             //not the primary pk
         }
         //foreach
         $add_html .= "</tr><tr><td>\n";
         $postForm = "false";
         if (!$this->ajax_add) {
             $postForm = "true";
         }
         $add_html .= "<input class=\"editingSize\" type=\"button\" onClick=\"validateAddForm('{$this->db_table}', {$postForm});\" value=\"Save {$item}\">";
         $add_html .= "</td><td><input style='float: right;' class=\"btn editingSize\" type=\"button\" onClick=\"this.form.reset();\$('#add_form_{$this->db_table}').slideUp('slow');\" value=\"" . $this->cancelText . "\"></td></tr>\n</table>\n";
         $add_html .= "<input type=\"hidden\" name=\"action\" value=\"add\">\n";
         $add_html .= "<input type=\"hidden\" name=\"table\" value=\"{$this->db_table}\">\n";
         if (isset($file_uploads) && $file_uploads) {
             $add_html .= "<input type=\"hidden\" name=\"uploads_on\" value=\"true\">\n";
         }
         $add_html .= "</form>\n";
     }
     //if adding fields is "allowed"
     /*
     THIS IS IMPORTANT
     for ajax retrieval (see top of page)
     */
     $_SESSION[$this->db_table] = $table_html;
     $html = $top_html . $table_html . $bottom_html . $add_html;
     if ($this->add_form_top) {
         $html = $add_html . $top_html . $table_html . $bottom_html;
     }
     echo $html;
 }