Overview

Packages

  • Admin
  • Archive
  • Common
  • DB
  • Express
  • Form
  • Layout
  • Mailer
  • None
  • OpenHomeoDB
  • PDF
    • MC
  • Process
  • Rep
  • RevRep
  • SaveReps
  • Search
  • Session
  • SymRem
  • TreeView
  • UserDB

Classes

  • DbPlugin
  • FPDF

Functions

  • add_donate_button
  • begin_popup
  • bot_detected
  • build_change_field_select
  • build_change_table_form
  • build_change_table_select
  • build_csv
  • build_date_select
  • build_details_table
  • build_enable_features_checkboxes
  • build_enabled_features_ar
  • build_fields_labels_array
  • build_fields_names_array
  • build_form
  • build_insert_duplication_form
  • build_insert_update_notice_email_record_details
  • build_installed_table_infos_ar
  • build_int_table_field_form
  • build_navigation_tool
  • build_records_per_page_form
  • build_results_table
  • build_results_table_archiv
  • build_select_duplicated_query
  • build_select_part
  • build_select_type_select
  • build_tables_names_array
  • build_where_clause
  • check_fields_types
  • check_length_fields
  • check_required_fields
  • contains_numerics
  • create_ajax_script
  • create_internal_table
  • create_table_list_table
  • create_users_table
  • create_xml_response
  • current_user_is_owner
  • delete_multiple_records
  • delete_record
  • display_sql
  • end_popup
  • get_browser_language
  • get_field_correct_csv_displaying
  • get_field_correct_displaying
  • get_ID_user_field_name
  • get_pages_number
  • insert_other_field
  • insert_record
  • is_valid_email
  • is_valid_url
  • popup
  • skin_close
  • skin_open
  • table_allowed
  • table_contains
  • txt_out
  • update_options
  • update_record
  • Overview
  • Package
  • Function
  • Tree
   1: <?php
   2: /*
   3: ***********************************************************************************
   4: DaDaBIK (DaDaBIK is a DataBase Interfaces Kreator) http://www.dadabik.org/
   5: Copyright (C) 2001-2007  Eugenio Tacchini
   6: 
   7: This program is free software: you can redistribute it and/or modify
   8: it under the terms of the GNU General Public License as published by
   9: the Free Software Foundation, either version 3 of the License, or
  10: (at your option) any later version.
  11: 
  12: This program is distributed in the hope that it will be useful,
  13: but WITHOUT ANY WARRANTY; without even the implied warranty of
  14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15: GNU General Public License for more details.
  16: 
  17: You should have received a copy of the GNU General Public License
  18: along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19: 
  20: If you want to contact me by e-mail, this is my address: eugenio.tacchini@unicatt.it
  21: ***********************************************************************************
  22: */
  23: ?>
  24: <?php
  25: 
  26: function current_user_is_owner($where_field, $where_value, $table_name, $fields_labels_ar) {
  27: // goal: check if authentication is required and, if yes, if the current user is the owner so that he can delete/update the record.
  28: // input: $where_field, $where_value, $table_name (to identify the record), $fields_labels_ar
  29: // output: true|false
  30: 
  31: /****
  32:  ****  If editors/admins should not have the possibility
  33:  ****  to change or delete entries of other users,
  34:  ****  delete "$current_user_is_editor, " from globals and
  35:  ****  "$current_user_is_editor === 1 || " in the first if-close.
  36:  ****  Henri Schumacher
  37:  ****/
  38:     global $current_user, $current_user_is_editor, $db;
  39: 
  40:     // get the name of the field that has ID_user type
  41:     $ID_user_field_name = get_ID_user_field_name($fields_labels_ar);
  42:     if ($current_user_is_editor === 1 || $ID_user_field_name === false) {
  43:         return true; // no ID_user field type, no authentication needed
  44:     } // end if
  45:     else {
  46:         // check if the owner of the record is current_user
  47:         $sql = "SELECT `$ID_user_field_name` FROM `$table_name` WHERE `$where_field` = '$where_value' AND `$ID_user_field_name` = '".$db->escape_string($current_user)."'";
  48: 
  49:         $db->send_query($sql);
  50:         $num_rows = $db->db_num_rows();
  51:         $db->free_result();
  52: 
  53:         if ($num_rows === 1) {
  54:             return true;
  55:         } // end if
  56:         else {
  57:             return false;
  58:         } // end else
  59:     } // end else
  60: 
  61: } // end function current_user_is_owner()
  62: 
  63: function get_ID_user_field_name($fields_labels_ar)
  64: // goal: get the name of the first ID_user type field
  65: //input: $fields_labels_ar
  66: //output: the field name or false if there aren't any ID_user field so the authentication is not needed
  67: {
  68:     $ID_user_field_name = false;
  69: 
  70:     $fields_labels_ar_count = count($fields_labels_ar);
  71:     $i = 0;
  72: 
  73:     while ($i < $fields_labels_ar_count && $ID_user_field_name === false) {
  74:         if ($fields_labels_ar[$i]['type_field'] === 'ID_user') {
  75:             $ID_user_field_name = $fields_labels_ar[$i]['name_field'];
  76:         } // end if
  77:         $i++;
  78:     } // end while
  79: 
  80:     return $ID_user_field_name;
  81: } // end function get_ID_user_field_name()
  82: 
  83: function build_fields_names_array($table_name)
  84: // goal: build an array ($fields_names_ar) containing the names of the fields of a specified table
  85: // input:name of the table
  86: // output: $fields_names_ar
  87: {
  88:     global $db;
  89: 
  90:     $sql = "DESCRIBE $table_name";
  91:     $db->send_query($sql);
  92:     while ($row = $db->db_fetch_assoc()) {
  93:         $fields_names_ar[] = $row["Field"];
  94:     }
  95:     $db->free_result();
  96:     return $fields_names_ar;
  97: } // end build_fields_names_array function
  98: 
  99: function build_tables_names_array($exclude_not_allowed = 1, $exclude_not_installed = 1, $include_users_table = 0)
 100: // goal: build an array ($tables_names_ar) containing the names of the tables of the db, excluding the internal tables, get the list from $table_list_name tab if $exclude_not_installed = 1, otherwise directly from the DBMS
 101: // input: $exclude_not_allowed (1 if the tables excluded by the user are excluded), $exclude_not_installed (1 if the tables not installed are excluded), $include_users_table (1 if it is necessary to include the users table, even if the user is not admin (useful in admin.php)
 102: // output: $tables_names_ar
 103: {
 104:     global $db, $prefix_internal_table, $table_list_name, $users_table_name, $current_user_is_editor;
 105: 
 106:     $z = 0;
 107:     $tables_names_ar = array();
 108: 
 109:     if ( $exclude_not_installed == 1 ) { // get the list from $table_list_name tab
 110:         $sql = "SELECT name_table FROM `$table_list_name`";
 111:         if ( $exclude_not_allowed == 1) { // excluding not allowed if necessary
 112:             $sql .= " WHERE allowed_table = '1'";
 113:         } // end if
 114:         $db->send_query($sql);
 115:         while ($row = $db->db_fetch_row()) {
 116: 
 117:             if ($current_user_is_editor === 1 || $row[0] !== $users_table_name || $include_users_table === 1) {
 118:                 $tables_names_ar[$z] = $row[0];
 119:                 $z++;
 120:             } // end if
 121:         }
 122:         $db->free_result();
 123:     } // end if
 124:     else { // get the list directly from db
 125:         $sql = "SHOW TABLES";
 126:         $db->send_query($sql);
 127:         while ($row = $db->db_fetch_row()) {
 128:             $table_name_temp = $row[0];
 129:             // if the table is not internal
 130:             if (substr($table_name_temp, 0, strlen($prefix_internal_table)) != $prefix_internal_table && $table_name_temp != $table_list_name && substr($table_name_temp, 0, 9) != 'archive__' && substr($table_name_temp, 0, 7) != 'active_' && substr($table_name_temp, 0, 7) != 'banned_') {
 131:                 $tables_names_ar[$z] = $table_name_temp;
 132:                 $z++;
 133:             } // end if
 134:         }
 135:         $db->free_result();
 136:     } // end else
 137:     return $tables_names_ar;
 138: } // end build_tables_names_array function
 139: 
 140: function build_fields_labels_array($table_internal_name, $order_type)
 141: // goal: build an array ($fields_labels_ar) containing the fields labels and other information about fields (e.g. the type, display/don't display) of a specified table to use in the form
 142: // input: name of the internal table, $order_type: 0|1|2 no order| by order_form_field | by id_field
 143: // output: fields_labels_ar, a 2 dimensions associative array: $fields_labels_ar[field_number]["internal table field (e.g. present_insert_form_field)"]
 144: // global $error_messages_ar, the array containg the error messages
 145: {
 146:     global $db, $error_messages_ar;
 147: 
 148:     $table_alias_suffixes_ar = array();
 149: 
 150:     // put the labels and other information of the table's fields in an array
 151:     $sql = "SELECT `name_field`, `present_insert_form_field`, `present_ext_update_form_field`, `present_search_form_field`, `required_field`, `present_results_search_field`, `present_details_form_field`, `check_duplicated_insert_field`, `type_field`, `other_choices_field`, `content_field`, `label_de_field`, `label_en_field`, `select_options_field`, `separator_field`, `primary_key_field_field`, `primary_key_table_field`, `primary_key_db_field`, `linked_fields_field`, `linked_fields_order_by_field`, `linked_fields_order_type_field`, `select_type_field`, `prefix_field`, `default_value_field`, `width_field`, `height_field`, `maxlength_field`, `hint_insert_de_field`, `hint_insert_en_field`, `order_form_field` FROM `$table_internal_name`";
 152: 
 153:     if ($order_type == "1") {
 154:         $sql .= " ORDER BY `order_form_field`";
 155:     } // end if
 156:     elseif ($order_type == "2") {
 157:         $sql .= " ORDER BY `id_field`";
 158:     } // end else
 159: 
 160:     $db->send_query($sql);
 161:     $num_rows = $db->db_num_rows();
 162:     $i = 0;
 163:     if ($num_rows > 0) { // at least one record
 164:         while($field_row = $db->db_fetch_assoc()) {
 165:             $fields_labels_ar[$i]["name_field"] = $field_row["name_field"]; // the name of the field
 166:             $fields_labels_ar[$i]["present_insert_form_field"] = $field_row["present_insert_form_field"]; // 1 if the user want to display it in the insert form
 167:             $fields_labels_ar[$i]["present_ext_update_form_field"] = $field_row["present_ext_update_form_field"]; // 1 if the user want to display it in the external update form
 168:             $fields_labels_ar[$i]["present_search_form_field"] = $field_row["present_search_form_field"]; // 1 if the user want to display it in the search form
 169:             $fields_labels_ar[$i]["required_field"] = $field_row["required_field"]; // 1 if the field is required in the insert (the field must be in the insert form, otherwise this flag hasn't any effect
 170:             $fields_labels_ar[$i]["present_results_search_field"] = $field_row["present_results_search_field"]; // 1 if the user want to display it in the basic results page
 171:             $fields_labels_ar[$i]["present_details_form_field"] = $field_row["present_details_form_field"]; // 1 if the user want to display it in the details page
 172:             $fields_labels_ar[$i]["check_duplicated_insert_field"] = $field_row["check_duplicated_insert_field"]; // 1 if the field needs to be checked for duplicated insert
 173: 
 174:             $fields_labels_ar[$i]["label_de_field"] = $field_row["label_de_field"]; // the German label of the field
 175:             $fields_labels_ar[$i]["label_en_field"] = $field_row["label_en_field"]; // the English label of the field
 176: 
 177:             $fields_labels_ar[$i]["type_field"] = $field_row["type_field"]; // the type of the field
 178:             $fields_labels_ar[$i]["other_choices_field"] = $field_row["other_choices_field"]; // 0/1 the possibility to add another choice with select single menu
 179:             $fields_labels_ar[$i]["content_field"] = $field_row["content_field"]; // the control type of the field (eg: numeric, alphabetic, alphanumeric)
 180:             $fields_labels_ar[$i]["select_options_field"] = $field_row["select_options_field"]; // the options, separated by separator, possible in a select field
 181:             $fields_labels_ar[$i]["separator_field"] = $field_row["separator_field"]; // the separator of different possible values for a select field
 182:             $fields_labels_ar[$i]["primary_key_field_field"] = $field_row["primary_key_field_field"]; // the primary key field_name if this field is a foreign key
 183:             $fields_labels_ar[$i]["primary_key_table_field"] = $field_row["primary_key_table_field"]; // the primary key table_name if this field is a foreign key
 184:             $fields_labels_ar[$i]["primary_key_db_field"] = $field_row["primary_key_db_field"]; // the primary key database if this field is a foreign key
 185:             $fields_labels_ar[$i]["linked_fields_field"] = $field_row["linked_fields_field"]; // the fields linked to through the pk
 186:             $fields_labels_ar[$i]["linked_fields_order_by_field"] = $field_row["linked_fields_order_by_field"]; // the fields by which order when retreiving the linked fields
 187:             $fields_labels_ar[$i]["linked_fields_order_type_field"] = $field_row["linked_fields_order_type_field"]; // the order type (ASC|DESC) to use in the order clause when retreiving the linked fields
 188:             $fields_labels_ar[$i]["select_type_field"] = $field_row["select_type_field"]; // the type of select, exact match or like
 189:             $fields_labels_ar[$i]["prefix_field"] = $field_row["prefix_field"]; // the prefix of the field (e.g. http:// - only for text, textarea and rich_editor)
 190:             $fields_labels_ar[$i]["default_value_field"] = $field_row["default_value_field"]; // the default value of the field (only for text, textarea and rich_editor)
 191:             $fields_labels_ar[$i]["width_field"] = $field_row["width_field"]; // the width size of the field in case of text, textarea or rich_editor
 192:             $fields_labels_ar[$i]["height_field"] = $field_row["height_field"]; // the height size of the field in case of textarea or rich_editor
 193:             $fields_labels_ar[$i]["maxlength_field"] = $field_row["maxlength_field"]; // the maxlength of the field in case of text
 194:             $fields_labels_ar[$i]["hint_insert_de_field"] = $field_row["hint_insert_de_field"]; // the hint to display after the field in the insert form in German
 195:             $fields_labels_ar[$i]["hint_insert_en_field"] = $field_row["hint_insert_en_field"]; // the hint to display after the field in the insert form (e.g. use only number here!!) in English
 196:             $fields_labels_ar[$i]["order_form_field"] = $field_row["order_form_field"]; // the position of the field in the form
 197: 
 198:             if ($field_row["primary_key_field_field"] !== '' && $field_row["primary_key_field_field"] !== NULL) {
 199:                 $linked_fields_ar = explode($field_row["separator_field"], $field_row["linked_fields_field"]);
 200: 
 201:                 if ( array_key_exists($field_row["primary_key_table_field"], $table_alias_suffixes_ar) === false) {
 202:                     $table_alias_suffixes_ar[$field_row["primary_key_table_field"]] = 1;
 203:                     $fields_labels_ar[$i]["alias_suffix_field"] = 1;
 204:                 } // end if
 205:                 else {
 206:                     $table_alias_suffixes_ar[$field_row["primary_key_table_field"]]++;
 207:                     $fields_labels_ar[$i]["alias_suffix_field"] = $table_alias_suffixes_ar[$field_row["primary_key_table_field"]];
 208:                 } // end else
 209: 
 210:             } // end if
 211: 
 212:             $i++;
 213:         } // end while
 214:     } // end if
 215:     else { // no records
 216:         echo $error_messages_ar["int_db_empty"];
 217:     } // end else
 218:     $db->free_result();
 219:     return $fields_labels_ar;
 220: } // end build_fields_labels_array function
 221: 
 222: function build_form($table_name, $action, $fields_labels_ar, $form_type, $res_details, $where_field, $where_value, $show_insert_form_after_error, $show_edit_form_after_error)
 223: // goal: build a tabled form by using the info specified in the array $fields_labels_ar
 224: // input: $table_name, array containing labels and other info about fields, $action (the action of the form), $form_type, $res_details, $where_field, $where_value (the last three useful just for update forms), $_POST, $_FILES (the last two useful for insert and edit to refill the form), $show_insert_form_after_error (0|1), $show_edit_form_after_error (0|1), tha last two useful to know if the inser or edit forms are showed after a not successful insert and update and so it is necessary to refill the fields
 225: // global: $submit_buttons_ar, the array containing the values of the submit buttons, $normal_messages_ar, the array containig the normal messages, $select_operator_feature, wheter activate or not displaying "and/or" in the search form, $default_operator, the default operator if $select_operator_feature is not activated, $size_multiple_select, the size (number of row) of the select_multiple_menu fields, $table_name
 226: // output: $form, the html tabled form
 227: {
 228:     global $db, $submit_buttons_ar, $normal_messages_ar, $select_operator_feature, $default_operator, $size_multiple_select, $show_top_buttons, $enable_authentication, $enable_browse_authorization, $current_user, $year_field_suffix, $month_field_suffix, $day_field_suffix, $start_year, $lang;
 229: 
 230:     switch ($form_type) {
 231:         case 'insert':
 232:             $function = 'insert';
 233:             break;
 234:         case 'update':
 235:             $function = 'update';
 236:             break;
 237:         case 'ext_update':
 238:             $function = 'ext_update';
 239:             break;
 240:         case 'search':
 241:             $function = 'search';
 242:             break;
 243:     } // end switch
 244: 
 245:     $form = "";
 246:     $form .= "<form id='dadabik_main_form' name='contacts_form' method='post' action='$action?table_name=".urlencode($table_name)."&function=$function";
 247: 
 248:     if ( $form_type == "update" or $form_type == "ext_update") {
 249:         $form .= "&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value);
 250:     }
 251: 
 252:     if ( $form_type == "search") {
 253:         $form .= "&execute_search=1";
 254:     }
 255: 
 256:     $form .= "' enctype='multipart/form-data'><table>";
 257: 
 258:     switch($form_type) {
 259:         case "insert":
 260:             $number_cols = 3;
 261:             $field_to_ceck = "present_insert_form_field";
 262:             break;
 263:         case "update":
 264:             $number_cols = 3;
 265:             $field_to_ceck = "present_insert_form_field";
 266: 
 267:             if ($show_edit_form_after_error === 0) {
 268:                 $details_row = $db->db_fetch_assoc($res_details); // get the values of the details
 269:             } // end if
 270:             if ( $show_top_buttons == 1) {
 271:                 $form .= "<tr class='tr_button_form'><td colspan='$number_cols' class='td_button_form'><input class='button_form' type='submit' value='".$submit_buttons_ar[$form_type]."'></td></tr>";
 272:             }
 273:             break;
 274:         case "ext_update":
 275:             $number_cols = 4;
 276:             $field_to_ceck = "present_ext_update_form_field";
 277:             $details_row = $db->db_fetch_assoc($res_details); // get the values of the details
 278:             if ( $show_top_buttons == 1) {
 279:                 $form .= "<tr class='tr_button_form'><td colspan='$number_cols' class='td_button_form'><input class='button_form' type='submit' value='".$submit_buttons_ar[$form_type]."'></td></tr>";
 280:             }
 281:             break;
 282:         case "search":
 283:             $number_cols = 2;
 284:             $field_to_ceck = "present_search_form_field";
 285:             if ($select_operator_feature == "1") {
 286:                 $form .= "<tr class='tr_operator_form'><td colspan='$number_cols' class='td_button_form'><select name='operator'><option value='and'>".$normal_messages_ar["all_conditions_required"]."</option><option value='or'>".$normal_messages_ar["any_conditions_required"]."</option></select></td></tr>";
 287:             } // end if
 288:             else {
 289:                 $form .= "<input type='hidden' name='operator' value='$default_operator'>";
 290:             } // end else
 291:             if ( $show_top_buttons == 1) {
 292:                 $form .= "<tr class='tr_button_form'><td colspan='$number_cols'><input  class='button_form' type='submit' value='".$submit_buttons_ar[$form_type]."'></td></tr>";
 293:             }
 294:             break;
 295:     } // end switch
 296:     for ($i=0; $i<count($fields_labels_ar); $i++) {
 297:         if ($fields_labels_ar[$i][$field_to_ceck] == "1") { // the user want to display the field in the form
 298: 
 299:             // build the first coloumn (label)
 300:             //////////////////////////////////
 301:             // I put a table inside the cell to get the same margin of the second coloumn
 302:             $form .= "<tr><td style='text-align: right; vertical-align: top;'><table><tr><td class='td_label_form'>";
 303:             if ($fields_labels_ar[$i]["required_field"] == "1" and $form_type != "search") {
 304:                 $form .= "*";
 305:             } // end if
 306:             $form .= $fields_labels_ar[$i]["label_" . $lang . "_field"]." ";
 307:             $form .= "</td></tr></table></td>";
 308:             //////////////////////////////////
 309:             // end build the first coloumn (label)
 310: 
 311:             $field_name_temp = $fields_labels_ar[$i]["name_field"];
 312: 
 313:             // build an empty cell
 314: 
 315:                         $form .= "<td style='text-align: right; vertical-align: top;'><table><tr><td class='td_null_checkbox_form'>";
 316:                         $form .= "</td></tr></table></td>";
 317: 
 318: 
 319:             // build the second coloumn (input field)
 320:             /////////////////////////////////////////
 321:             $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
 322:             if ($primary_key_field_field != "") {
 323:                 $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
 324:                 $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
 325:                 $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
 326:                 $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
 327:                 $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
 328:                 $linked_fields_order_by_field = $fields_labels_ar[$i]["linked_fields_order_by_field"];
 329:                 if ($linked_fields_order_by_field !== '' && $linked_fields_order_by_field !== NULL) {
 330:                     $linked_fields_order_by_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_order_by_field);
 331:                 } // end if
 332:                 else {
 333:                     unset($linked_fields_order_by_ar);
 334:                 } // end else
 335: 
 336:                 $linked_fields_order_type_field = $fields_labels_ar[$i]["linked_fields_order_type_field"];
 337: 
 338:                 $sql = "SELECT `$primary_key_field_field`";
 339: 
 340:                 $count_temp = count($linked_fields_ar);
 341:                 for ($j=0; $j<$count_temp; $j++) {
 342:                     $sql .= ", `".$linked_fields_ar[$j]."`";
 343:                 }
 344:                 $sql .= " FROM `$primary_key_table_field`";
 345: 
 346:                 if (isset($linked_fields_order_by_ar)) {
 347:                     $sql .= " ORDER BY ";
 348:                     $count_temp = count($linked_fields_order_by_ar);
 349:                     for ($j=0; $j<$count_temp; $j++) {
 350:                         $sql .= "`".$linked_fields_order_by_ar[$j]."`, ";
 351:                     }
 352:                     $sql = substr($sql, 0, -2); // delete the last ","
 353:                     $sql .= " ".$linked_fields_order_type_field;
 354:                 } // end if
 355:                 $res_primary_key = $db->send_query($sql);
 356:                 $fields_number = $db->db_num_fields();
 357:             } // end if
 358: 
 359:             if ($form_type == "search") {
 360:                 $select_type_select = build_select_type_select($field_name_temp, $fields_labels_ar[$i]["select_type_field"], 0); // build the select type select form (is_equal....)
 361:                 $select_type_date_select = build_select_type_select($field_name_temp, $fields_labels_ar[$i]["select_type_field"], 1); // build the select type select form (is_equal....) for date fields, with the first option blank
 362:             } // end if
 363:             else {
 364:                 $select_type_select = "";
 365:                 $select_type_date_select = "";
 366:             } // end else
 367:             $form .= "<td><table><tr>";
 368:             switch ($fields_labels_ar[$i]["type_field"]) {
 369:                 case "text":
 370:                 case "ID_user":
 371:                     $form .= "<td class='td_input_form'>$select_type_select<input type='text' name='$field_name_temp'";
 372:                     if ($fields_labels_ar[$i]["width_field"] != "") {
 373:                         $form .= " size='".$fields_labels_ar[$i]["width_field"]."'";
 374:                     } // end if
 375:                     $form .= " maxlength='".$fields_labels_ar[$i]["maxlength_field"]."'";
 376:                     if ($form_type == "update" or $form_type == "ext_update") {
 377:                         if ($show_edit_form_after_error === 1) {
 378:                             if (isset($_POST[$field_name_temp])) {
 379:                                 $form .= " value='".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."'";
 380:                             } // end if
 381:                         } // end if
 382:                         else {
 383:                             $form .= " value='".htmlspecialchars($details_row[$field_name_temp])."'";
 384:                         } // end else
 385:                     } // end if
 386:                     if ($form_type == "insert") {
 387:                         if ($show_insert_form_after_error === 1 && isset($_POST[$field_name_temp])) {
 388:                             $form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp])).'"';
 389:                         } // end if
 390:                         else {
 391:                             $form .= " value='".$fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"]."'";
 392:                         } // end else
 393:                     } // end if
 394:                     $form .= ">";
 395:                     $form .= "</td>"; // add the second coloumn to the form
 396:                     break;
 397:                 case "textarea":
 398:                     $form .= "<td class='td_input_form'>$select_type_select</td>";
 399:                     $form .= "<td class='td_input_form'><textarea cols='".$fields_labels_ar[$i]["width_field"]."' rows='".$fields_labels_ar[$i]["height_field"]."' name='".$field_name_temp."'>";
 400:                     if ($form_type == "update" or $form_type == "ext_update") {
 401:                         if ($show_edit_form_after_error === 1) {
 402:                             if (isset($_POST[$field_name_temp])) {
 403:                                 $form .= htmlspecialchars(stripslashes($_POST[$field_name_temp]));
 404:                             } // end if
 405:                         } // end if
 406:                         else {
 407:                             $form .= htmlspecialchars($details_row[$field_name_temp]);
 408:                         } // end else
 409:                     } // end if
 410:                     if ($form_type == "insert") {
 411: 
 412:                         if ($show_insert_form_after_error === 1 && isset($_POST[$field_name_temp])) {
 413:                             $form .= htmlspecialchars(stripslashes($_POST[$field_name_temp]));
 414:                         } // end if
 415:                         else {
 416:                             $form .= $fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"];
 417:                         } // end else
 418: 
 419:                     } // end if
 420: 
 421:                     $form .= "</textarea></td>"; // add the second coloumn to the form
 422:                     break;
 423:                 case "insert_timestamp":
 424:                 case "update_timestamp":
 425:                     $date_select = "";
 426:                     switch($form_type) {
 427:                         case "search":
 428:                             $date_select = build_date_select($field_name_temp,"","","");
 429:                             break;
 430:                     } // end switch
 431:                     $form .= "<td class='td_input_form'>$select_type_date_select</td>$date_select</td>"; // add the second coloumn to the form
 432:                     break;
 433:                 case "select_single":
 434:                     $form .= "<td class='td_input_form'>$select_type_select<select name='$field_name_temp'>"; // first part of the second coloumn of the form
 435: 
 436:                     $form .= "<option value=''></option>"; // first blank option
 437: 
 438:                     $field_temp = substr($fields_labels_ar[$i]["select_options_field"], 1, -1); // delete the first and the last separator
 439: 
 440:                     if (trim($field_temp) !== '') {
 441:                         $select_values_ar = explode($fields_labels_ar[$i]["separator_field"],$field_temp);
 442: 
 443:                         $count_temp = count($select_values_ar);
 444:                         for ($j=0; $j<$count_temp; $j++) {
 445:                             $form .= "<option value='".htmlspecialchars($select_values_ar[$j])."'";
 446: 
 447:                             if ($form_type === 'update' or $form_type === 'ext_update') {
 448:                                 if ($show_edit_form_after_error === 1) {
 449:                                     if (isset($_POST[$field_name_temp]) && $select_values_ar[$j] == stripslashes($_POST[$field_name_temp])) {
 450:                                         $form .= " selected";
 451:                                     } // end if
 452:                                 } // end if
 453:                                 else {
 454:                                     if ($select_values_ar[$j] == $details_row[$field_name_temp]) {
 455:                                         $form .= " selected";
 456:                                     } // end if
 457:                                 } // end else
 458:                             } // end if
 459: 
 460:                             if ($form_type === 'insert' && $show_insert_form_after_error === 1 && isset($_POST[$field_name_temp]) && $select_values_ar[$j] == stripslashes($_POST[$field_name_temp])) {
 461:                                 $form .= " selected";
 462:                             } // end if
 463: 
 464:                             $form .= ">".$select_values_ar[$j]."</option>"; // second part of the form row
 465:                         } // end for
 466:                     } // end if
 467: 
 468:                     if ($fields_labels_ar[$i]["primary_key_field_field"] != "") {
 469:                         if ($db->db_num_rows($res_primary_key) > 0) {
 470:                             while ($primary_key_row = $db->db_fetch_row($res_primary_key)) {
 471: 
 472:                                 $primary_key_value = $primary_key_row[0];
 473:                                 $linked_fields_value = "";
 474:                                 for ($z=1; $z<$fields_number; $z++) {
 475:                                     $linked_fields_value .= $primary_key_row[$z];
 476:                                     $linked_fields_value .= " - ";
 477:                                 } // end for
 478:                                 $linked_fields_value = substr($linked_fields_value, 0, -3); // delete the last " -
 479: 
 480:                                 $form .= "<option value='".htmlspecialchars($primary_key_value)."'";
 481: 
 482:                                 if ($form_type === 'update' or $form_type === 'ext_update') {
 483:                                     if ($show_edit_form_after_error === 1) {
 484:                                         if (isset($_POST[$field_name_temp]) && $primary_key_value == stripslashes($_POST[$field_name_temp])) {
 485:                                             $form .= " selected";
 486:                                         } // end if
 487:                                     } // end if
 488:                                     else {
 489:                                         if ($primary_key_value == $details_row[$field_name_temp]) {
 490:                                             $form .= " selected";
 491:                                         } // end if
 492:                                     } // end else
 493:                                 } // end if
 494: 
 495:                                 if ($form_type === 'insert' && $show_insert_form_after_error === 1 && isset($_POST[$field_name_temp]) && $primary_key_value == stripslashes($_POST[$field_name_temp])) {
 496:                                     $form .= " selected";
 497:                                 } // end if
 498: 
 499:                                 $form .= ">$linked_fields_value</option>"; // second part of the form row
 500:                             } // end while
 501:                         } // end if
 502:                     } // end if ($fields_labels_ar[$i]["primary_key_field_field"] != "")
 503: 
 504:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and ($form_type == "insert" or $form_type == "update")) {
 505:                         $form .= "<option value='......'";
 506:                         if ($form_type === 'insert' && $show_insert_form_after_error === 1 && isset($_POST[$field_name_temp]) && $_POST[$field_name_temp] === '......') {
 507:                             $form .= " selected";
 508:                         } // end if
 509:                         if ($form_type === 'update' && $show_edit_form_after_error === 1 && isset($_POST[$field_name_temp]) && $_POST[$field_name_temp] === '......') {
 510:                             $form .= " selected";
 511:                         } // end if
 512:                         $form .= ">".$normal_messages_ar["other...."]."</option>"; // last option with "other...."
 513:                     } // end if
 514: 
 515:                     $form .= "</select>";
 516: 
 517:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and ($form_type == "insert" or $form_type == "update")) {
 518:                         $form .= "<input type='text' name='".$field_name_temp."_other____"."' maxlength='".$fields_labels_ar[$i]["maxlength_field"]."'";
 519: 
 520:                         if ($fields_labels_ar[$i]["width_field"] != "") {
 521:                             $form .= " size='".$fields_labels_ar[$i]["width_field"]."'";
 522:                         } // end if
 523: 
 524:                         if ($form_type == "insert" && $show_insert_form_after_error === 1) {
 525:                             if (isset($_POST[$field_name_temp."_other____"])) {
 526:                                 if (isset($_POST[$field_name_temp]) && $_POST[$field_name_temp] === '......') {
 527:                                     $form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp."_other____"])).'"';
 528:                                 } // end if
 529:                             } // end if
 530:                         } // end if
 531: 
 532:                         if ($form_type == "update" && $show_edit_form_after_error === 1) {
 533:                             if (isset($_POST[$field_name_temp."_other____"])) {
 534:                                 if (isset($_POST[$field_name_temp]) && $_POST[$field_name_temp] === '......') {
 535:                                     $form .= ' value="'.htmlspecialchars(stripslashes($_POST[$field_name_temp."_other____"])).'"';
 536:                                 } // end if
 537:                             } // end if
 538:                         } // end if
 539: 
 540:                         $form .= ">"; // text field for other....
 541:                     } // end if
 542: 
 543:                     $form .= "</td>"; // last part of the second coloumn of the form
 544:                     break;
 545:             } // end switch
 546:             /////////////////////////////////////////
 547:             // end build the second coloumn (input field)
 548: 
 549:             if ($form_type == "insert" or $form_type == "update" or $form_type == "ext_update") {
 550:                 $form .= "<td class='td_hint_form'>".$fields_labels_ar[$i]["hint_insert_" . $lang . "_field"]."</td>"; // display the insert hint if it's the insert form
 551:             } // end if
 552:             $form .= "</tr></table></td></tr>";
 553:         } // end if ($fields_labels_ar[$i]["$field_to_ceck"] == "1")
 554:     } // enf for loop for each field in the label array
 555: 
 556:     $form .= "<tr><td class='tr_button_form' colspan='$number_cols'><input type='submit' class='button_form' value='".$submit_buttons_ar[$form_type]."'></td></tr></table></form>";
 557:     return $form;
 558: } // end build_form function
 559: 
 560: function build_select_type_select($field_name, $select_type, $first_option_blank)
 561: // goal: build a select with the select type of the field (e.g. is_equal, contains....)
 562: // input: $field_name, $select_type (e.g. is_equal/contains), $first_option_blank(0|1)
 563: // output: $select_type_select
 564: // global: $normal_messages_ar, the array containing the normal messages
 565: {
 566:     global $normal_messages_ar, $select_type_select_suffix, $year_field_suffix, $month_field_suffix, $day_field_suffix;
 567: 
 568:     $select_type_select = "";
 569: 
 570:     $operators_ar = explode("/",$select_type);
 571: 
 572:     if (count($operators_ar) > 1) { // more than one operator, need a select
 573:         $select_type_select .= "<select onchange=\"javascript:enable_disable_input_box_search_form('$field_name', '$select_type_select_suffix', '$year_field_suffix', '$month_field_suffix', '$day_field_suffix')\" name='".$field_name.$select_type_select_suffix."'>";
 574:         $count_temp = count($operators_ar);
 575:         if ($first_option_blank === 1) {
 576:             $select_type_select .= "<option value=''></option>";
 577:         } // end if
 578:         for ($i=0; $i<$count_temp; $i++) {
 579:             $select_type_select .= "<option value='".$operators_ar[$i]."'>".$normal_messages_ar[$operators_ar[$i]]."</option>";
 580:         } // end for
 581:         $select_type_select .= "</select>";
 582:     } // end if
 583:     else { // just an hidden
 584:         $select_type_select .= "<input type='hidden' name='".$field_name.$select_type_select_suffix."' value='".$operators_ar[0]."'>";
 585:     }
 586: 
 587:     return $select_type_select;
 588: } // end function build_select_type_select
 589: 
 590: function check_required_fields($fields_labels_ar)
 591: // goal: check if the user has filled all the required fields
 592: // input: all the fields values ($_POST), $_FILES (for uploaded files) and the array containing infos about fields ($fields_labels_ar)
 593: // output: $check, set to 1 if the check is ok, otherwise 0
 594: {
 595:     global $null_checkbox_prefix;
 596:     $i =0;
 597:     $check = 1;
 598:     $count_temp = count($fields_labels_ar);
 599:     while ($i<$count_temp and $check == 1) {
 600:         if ($fields_labels_ar[$i]["required_field"] == "1" and $fields_labels_ar[$i]["present_insert_form_field"] == "1") {
 601:             $field_name_temp = $fields_labels_ar[$i]["name_field"];
 602: 
 603:             if (isset($_POST[$null_checkbox_prefix.$field_name_temp]) && $_POST[$null_checkbox_prefix.$field_name_temp] === '1') { // NULL checkbox selected
 604:                 $check = 0;
 605:             } // end if
 606:             else {
 607:                 switch($fields_labels_ar[$i]["type_field"]) {
 608:                     case "select_single":
 609:                         if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......") {
 610:                             $field_name_other_temp = $field_name_temp."_other____";
 611:                             if ($_POST["$field_name_other_temp"] == "") {
 612:                                 $check = 0;
 613:                             } // end if
 614:                         } // end if
 615:                         else {
 616:                             if ($_POST[$field_name_temp] == "") {
 617:                                 $check = 0;
 618:                             } // end if
 619:                         } // end else
 620:                         break;
 621:                     default:
 622:                         if ($_POST[$field_name_temp] == $fields_labels_ar[$i]["prefix_field"]) {
 623:                             $_POST[$field_name_temp] = "";
 624:                         } // end if
 625:                         if ($_POST[$field_name_temp] == "") {
 626:                             $check = 0;
 627:                         } // end if
 628:                         break;
 629:                 } // end switch
 630:             } // end else
 631:         } // end if
 632:         $i++;
 633:     } // end while
 634:     return $check;
 635: } // end function check_required_fields
 636: 
 637: function check_length_fields($fields_labels_ar)
 638: // goal: check if the text, password, textarea, rich_editor, select_single, select_multiple_checkbox, select_multiple_menu fields contains too much text
 639: // input: all the fields values ($_POST) and the array containing infos about fields ($fields_labels_ar)
 640: // output: $check, set to 1 if the check is ok, otherwise 0
 641: {
 642:     $i =0;
 643:     $check = 1;
 644:     $count_temp = count($fields_labels_ar);
 645:     while ($i<$count_temp and $check == 1) {
 646:         $field_name_temp = $fields_labels_ar[$i]["name_field"];
 647:         // I use isset for select_multiple because could be unset
 648:         if ($fields_labels_ar[$i]["maxlength_field"] != "" && isset($_POST[$field_name_temp])) {
 649:             switch($fields_labels_ar[$i]["type_field"]) {
 650:                 case "text":
 651:                 case "textarea":
 652:                     if (strlen($_POST[$field_name_temp]) > $fields_labels_ar[$i]["maxlength_field"]) {
 653:                         $check = 0;
 654:                     } // end if
 655:                     break;
 656:                 case "select_single":
 657:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......") {
 658:                         $field_name_other_temp = $field_name_temp."_other____";
 659:                         if (strlen($_POST[$field_name_other_temp]) > $fields_labels_ar[$i]["maxlength_field"]) {
 660:                             $check = 0;
 661:                         } // end if
 662:                     } // end if
 663:                     else {
 664:                         if (strlen($_POST[$field_name_temp]) > $fields_labels_ar[$i]["maxlength_field"]) {
 665:                             $check = 0;
 666:                         } // end if
 667:                     } // end else
 668:                     break;
 669:             } // end switch
 670:         } // end if
 671:         $i++;
 672:     } // end while
 673:     return $check;
 674: } // end function check_length_fields
 675: 
 676: function check_fields_types($fields_labels_ar, &$content_error_type)
 677: // goal: check if the user has well filled the form, according to the type of the field (e.g. no numbers in alphabetic fields, emails and urls correct)
 678: // input: all the fields values ($_POST) and the array containing infos about fields ($fields_labels_ar), &$content_error_type, a string that change according to the error made (alphabetic, numeric, email, phone, url....)
 679: // output: $check, set to 1 if the check is ok, otherwise 0
 680: {
 681:     global $year_field_suffix, $month_field_suffix, $day_field_suffix, $null_checkbox_prefix;
 682: 
 683:     $i =0;
 684:     $check = 1;
 685:     $count_temp = count($fields_labels_ar);
 686:     while ($i<$count_temp and $check == 1) {
 687:         $field_name_temp = $fields_labels_ar[$i]["name_field"];
 688: 
 689:         if (isset($_POST[$null_checkbox_prefix.$field_name_temp]) && $_POST[$null_checkbox_prefix.$field_name_temp] === '1') { // NULL checkbox selected
 690:             $check = 1;
 691:         } // end if
 692:         elseif (isset($_POST[$field_name_temp])) { // otherwise it has not been filled
 693:             if ($_POST[$field_name_temp] == $fields_labels_ar[$i]["prefix_field"]) {
 694:                 $_POST[$field_name_temp] = "";
 695:             } // end if
 696:             if ($fields_labels_ar[$i]["type_field"] == "select_single" && $fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......") { // other field filled
 697:                 $field_name_temp = $field_name_temp."_other____";
 698:             } // end if
 699:             if (($fields_labels_ar[$i]["type_field"] == "text" || $fields_labels_ar[$i]["type_field"] == "textarea" ||  $fields_labels_ar[$i]["type_field"] == "select_single") and $fields_labels_ar[$i]["present_insert_form_field"] == "1" and $_POST[$field_name_temp] != "") {
 700: 
 701:                 switch ($fields_labels_ar[$i]["content_field"]) {
 702:                     case "alphabetic":
 703:                         if (contains_numerics($_POST[$field_name_temp])) {
 704:                             $check = 0;
 705:                             $content_error_type = $fields_labels_ar[$i]["content_field"];
 706:                         } // end if
 707:                         break;
 708:                     case "numeric":
 709:                         if (!is_numeric($_POST[$field_name_temp])) {
 710:                             $check = 0;
 711:                             $content_error_type = $fields_labels_ar[$i]["content_field"];
 712:                         } // end if
 713:                         break;
 714:                     case "email":
 715:                         if (!is_valid_email($_POST[$field_name_temp])) {
 716:                             $check = 0;
 717:                             $content_error_type = $fields_labels_ar[$i]["content_field"];
 718:                         } // end if
 719:                         break;
 720:                     case "url":
 721:                         if (!is_valid_url($_POST[$field_name_temp])) {
 722:                             $check = 0;
 723:                             $content_error_type = $fields_labels_ar[$i]["content_field"];
 724:                         } // end if
 725:                         break;
 726:                 } // end switch
 727:             } // end if
 728:         } // end elseif
 729:         $i++;
 730:     } // end while
 731:     return $check;
 732: } // end function check_fields_types
 733: 
 734: function build_select_duplicated_query($table_name, $fields_labels_ar, &$string1_similar_ar, &$string2_similar_ar)
 735: // goal: build the select query to select the record that can be similar to the record inserted
 736: // input: all the field values ($_POST), $table_name, $fields_labels_ar, &$string1_similar_ar, &$string2_similar_ar (the two array that will contain the similar string found)
 737: // output: $sql, the sql query
 738: // global $percentage_similarity, the percentage after that two strings are considered similar, $number_duplicated_records, the maximum number of records to be displayed as duplicated
 739: {
 740:     global $percentage_similarity, $number_duplicated_records, $db, $enable_authentication, $enable_browse_authorization, $current_user, $null_checkbox_prefix;
 741: 
 742:     // get the unique key of the table
 743:     $unique_field_name = $db->get_primary_key($table_name);
 744: 
 745:     if ($unique_field_name != "" && $unique_field_name != NULL) { // a unique key exists, ok, otherwise I'm not able to select the similar record, which field should I use to indicate it?
 746: 
 747:         $sql = "";
 748:         $sql_select_all = "";
 749:         $sql_select_all = "SELECT `$unique_field_name`, "; // this is used to select the records to check similiarity
 750:         //$select = "SELECT * FROM `$table_name`";
 751:         $select = build_select_part($fields_labels_ar, $table_name);
 752:         $where_clause = "";
 753: 
 754:         // build the sql_select_all clause
 755:         $j = 0;
 756:         // build the $fields_to_check_ar array, containing the field to check for similiarity
 757:         $fields_to_check_ar = array();
 758:         $count_temp = count($fields_labels_ar);
 759:         for ($i=0; $i<$count_temp; $i++) {
 760:             if ($fields_labels_ar[$i]["check_duplicated_insert_field"] == "1") {
 761:                 if (!empty(${$fields_labels_ar[$i]["name_field"]})) {
 762:                     $fields_to_check_ar[$j] = $fields_labels_ar[$i]["name_field"]; // I put in the array only if the field is non empty, otherwise I'll check it even if I don't need it
 763:                 } // end if
 764:                 $sql_select_all .= "`".$fields_labels_ar[$i]["name_field"]."`, ";
 765:                 $j++;
 766:             } // end if
 767:         } // end for
 768:         $sql_select_all = substr ($sql_select_all, 0, -2); // delete the last ", "
 769:         $sql_select_all .= " FROM `$table_name`";
 770: 
 771:         if ($enable_authentication === 1 && $enable_browse_authorization === 1) { // $ID_user_field_name = '$current_user' where clause part in order to select only the records the current user owns
 772:             $ID_user_field_name = get_ID_user_field_name($fields_labels_ar);
 773: 
 774:             if ($ID_user_field_name !== false) { // no ID_user fields available, don't use authorization
 775:                 if ($where_clause === '') {
 776:                     $sql_select_all .= " WHERE `$table_name`.`$ID_user_field_name` = '".$db->escape_string($current_user)."'";
 777:                 } // end if
 778:             } // end if
 779:         } // end if
 780:         // end build the sql_select_all clause
 781: 
 782:         // at the end of the above procedure I'll have, for example, "select ID, name, email from table" if ID is the unique key, name and email are field to check
 783: 
 784:         // execute the select query
 785:         $res_contacts = $db->send_query($sql_select_all);
 786: 
 787:         if ($db->db_num_rows($res_contacts) > 0) {
 788:             while ($contacts_row = $db->db_fetch_row($res_contacts)) { // *A* for each record in the table
 789:                 $count_temp = count($fields_to_check_ar);
 790:                 for ($i=0; $i<$count_temp; $i++) { // *B* and for each field the user has inserted
 791:                     if (!isset($_POST[$null_checkbox_prefix.$fields_to_check_ar[$i]]) || $_POST[$null_checkbox_prefix.$fields_to_check_ar[$i]] !== '1') { // NULL checkbox  is not selected
 792:                         $z=0;
 793:                         $found_similarity =0; // set to 1 when a similarity is found, so that it's possible to exit the loop (if I found that a record is similar it doesn't make sense to procede with other fields of the same record)
 794: 
 795:                         // *C* check if the field inserted are similiar to the other fields to be checked in this record (*A*)
 796:                         $count_temp_2 = count($fields_to_check_ar);
 797:                         while ($z<$count_temp_2 and $found_similarity == 0) {
 798:                             $string1_temp = $_POST[$fields_to_check_ar[$i]]; // the field the user has inserted
 799:                             $string2_temp = $contacts_row[$z+1]; // the field of this record (*A*); I start with 1 because 0 is alwais the unique field (e.g. ID, name, email)
 800: 
 801:                             similar_text(strtolower($string1_temp), strtolower($string2_temp), $percentage);
 802:                             if ($percentage >= $percentage_similarity) { // the two strings are similar
 803:                                 $where_clause .= "`$unique_field_name` = '".$contacts_row[0]."' OR ";
 804:                                 $found_similarity = 1;
 805:                                 $string1_similar_ar[]=$string1_temp;
 806:                                 $string2_similar_ar[]=$string2_temp;
 807:                             } // end if the two strings are similar
 808:                             $z++;
 809:                         } // end while
 810:                     } // end if
 811:                 } // end for loop for each field to check
 812:             } // end while loop for each record
 813:         } // end if ($db->db_num_rows($res_contacts) > 0)
 814:         $db->free_result($res_contacts);
 815: 
 816:         $where_clause = substr($where_clause, 0, -4); // delete the last " OR "
 817:         if ($where_clause != "") {
 818:             $sql = $select." WHERE ".$where_clause;
 819:         } // end if
 820:         else { // no duplication
 821:             $sql = "";
 822:         } // end else*
 823:     } // end if if ($unique_field_name != "")
 824:     else { // no unique keys
 825:         $sql = "";
 826:     } // end else
 827:     return $sql;
 828: } // end function build_select_duplicated_query
 829: 
 830: function build_insert_duplication_form($fields_labels_ar, $table_name)
 831: // goal: build a tabled form composed by two buttons: "Insert anyway" and "Go back"
 832: // input: all the field values ($_POST), $fields_labels_ar, $table_name
 833: // output: $form, the form
 834: // global $submit_buttons_ar, the array containing the caption on submit buttons
 835: {
 836:     global $submit_buttons_ar, $dadabik_main_file, $year_field_suffix, $month_field_suffix, $day_field_suffix;
 837: 
 838:     $form = "";
 839: 
 840:     $form .= "<table><tr><td>";
 841: 
 842:     $form .= "<form action='$dadabik_main_file?table_name=".urlencode($table_name)."&function=insert&insert_duplication=1' method='post'>";
 843: 
 844:     $count_temp = count($fields_labels_ar);
 845:     for ($i=0; $i<$count_temp; $i++) {
 846: 
 847:         $field_name_temp = $fields_labels_ar[$i]["name_field"];
 848: 
 849:         if ($fields_labels_ar[$i]["present_insert_form_field"] == "1") {
 850: 
 851:             switch ($fields_labels_ar[$i]["type_field"]) {
 852:                 case "select_single":
 853: ob_start();
 854: $time = date("j.n.Y - G:i");
 855: echo "\n$time\n";
 856: var_dump($field_name_temp);
 857: echo "\n";
 858: var_dump($_POST);
 859: $buffer = ob_get_flush();
 860: file_put_contents("/tmp/variable.txt", $buffer, FILE_APPEND);
 861:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......") { // other choice filled
 862:                         $field_name_other_temp = $field_name_temp."_other____";
 863:                         $form .= "<input type='hidden' name='$field_name_temp' value='".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."'>";
 864:                         $form .= "<input type='hidden' name='$field_name_other_temp' value='".htmlspecialchars(stripslashes($_POST[$field_name_other_temp]))."'>";
 865:                     } // end if
 866:                     else {
 867:                         $form .= "<input type='hidden' name='$field_name_temp' value='".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."'>";
 868:                     } // end else
 869:                     break;
 870:                 default: // textual field
 871:                     if ($_POST[$fields_labels_ar[$i]["name_field"]] == $fields_labels_ar[$i]["prefix_field"]) { // the field contain just the prefix
 872:                         $_POST[$fields_labels_ar[$i]["name_field"]] = "";
 873:                     } // end if
 874: 
 875:                     $form .= "<input type='hidden' name='$field_name_temp' value='".htmlspecialchars(stripslashes($_POST[$fields_labels_ar[$i]["name_field"]]))."'>";
 876:                     break;
 877:             } // end switch
 878:         } // end if
 879:     } // end for
 880:     $form .= "<input type='submit' value='".$submit_buttons_ar["insert_anyway"]."'></form>";
 881: 
 882:     $form .= "</td><td>";
 883: 
 884:     $form .= "</td></tr></table>";
 885: 
 886:     return $form;
 887: } // end function build_insert_duplication_form
 888: 
 889: function build_change_table_form()
 890: // goal: build a form to choose the table
 891: // input:
 892: // output: the listbox
 893: {
 894:     global $table_name, $autosumbit_change_table_control, $dadabik_main_file;
 895: 
 896:     $change_table_form = '<form method="get" action="'.$dadabik_main_file.'" name="change_table_form">';
 897:     if ( $autosumbit_change_table_control == 0) {
 898:         $change_table_form .= '<input type="submit" class="button_change_table" value="'.$submit_buttons_ar["change_table"].'">';
 899:     } // end if
 900:     $change_table_form .= "<select name='table_name' class='select_change_table'";
 901:     if ( $autosumbit_change_table_control == 1) {
 902:         $change_table_form .= " onchange=\"javascript:document.change_table_form.submit()\"";
 903:     }
 904:     $change_table_form .= ">\n";
 905: 
 906:     $only_include_allowed = 1;
 907:     $allowed_table_infos_ar = build_installed_table_infos_ar($only_include_allowed, 1);
 908: 
 909:     $count_temp = count($allowed_table_infos_ar);
 910:     for($i=0; $i<$count_temp; $i++) {
 911:         $change_table_form .= "<option value='".htmlspecialchars($allowed_table_infos_ar[$i]['name_table'])."'";
 912:         if ($table_name == $allowed_table_infos_ar[$i]['name_table']) {
 913:             $change_table_form .= " selected";
 914:         }
 915:         $change_table_form .= ">".$allowed_table_infos_ar[$i]['alias_table']."</option>\n";
 916:     } // end for
 917:     $change_table_form .= "</select>\n";
 918:     $change_table_form .= "</form>\n";
 919: 
 920:     if ($count_temp == 1) {
 921:         return "";
 922:     } // end if
 923:     else {
 924:         return $change_table_form;
 925:     } // end else
 926: 
 927: } // end function build_change_table_form
 928: 
 929: function build_change_table_select()
 930: // goal: build a select to choose the table
 931: // output: $select, the html select
 932: {
 933:     global $table_name, $autosumbit_change_table_control;
 934:     $change_table_select = "";
 935:     $change_table_select .= "<select name='table_name' class='select_change_table'";
 936:     if ( $autosumbit_change_table_control == 1) {
 937:         $change_table_select .= " onchange=\"javascript:document.change_table_form.submit()\"";
 938:     }
 939:     $change_table_select .= ">";
 940: 
 941:     // get the array containing the names of the tables installed
 942:     $tables_names_ar = build_tables_names_array(0, 1, 1);
 943: 
 944:     $count_temp = count($tables_names_ar);
 945:     for($i=0; $i<$count_temp; $i++) {
 946:         $change_table_select .= "<option value='".htmlspecialchars($tables_names_ar[$i])."'";
 947:         if ($table_name == $tables_names_ar[$i]) {
 948:             $change_table_select .= " selected";
 949:         }
 950:         $change_table_select .= ">".$tables_names_ar[$i]."</option>";
 951:     } // end for
 952:     $change_table_select .= "</select>";
 953:     if ($count_temp == 1) {
 954:         return "";
 955:     } // end if
 956:     else {
 957:         return $change_table_select;
 958:     } // end else
 959: } // end function build_change_table_select
 960: 
 961: function table_contains($table_name, $field_name, $value)
 962: // goal: check if a table contains a record which has a field set to a specified value
 963: // input: $table_name, $field_name, $value
 964: // output: true or false
 965: {
 966:     global $db;
 967:     $sql = "SELECT COUNT(`$field_name`) FROM `$table_name` WHERE `$field_name` = '$value'";
 968:     $res_count = $db->send_query($sql);
 969:     $count_row = $db->db_fetch_row($res_count);
 970:     if ($count_row[0] > 0) {
 971:         return true;
 972:     } // end if
 973:     return false;
 974: } // end function table_contains
 975: 
 976: function insert_record($fields_labels_ar, $table_name, $table_internal_name)
 977: // goal: insert a new record in the table
 978: // input $_FILES (needed for the name of the files), $_POST (the array containing all the values inserted in the form), $fields_labels_ar, $table_name, $table_internal_name
 979: // output: nothing
 980: {
 981:     global $db, $current_user, $null_checkbox_prefix, $year_field_suffix, $month_field_suffix, $day_field_suffix;
 982: 
 983:     $uploaded_file_names_count = 0;
 984: 
 985:     // build the insert statement
 986:     /////////////////////////////
 987:     $sql = "";
 988:     $sql .= "INSERT INTO `$table_name` (";
 989: 
 990:     $count_temp=count($fields_labels_ar);
 991:     for ($i=0; $i<$count_temp; $i++) {
 992:         if ($fields_labels_ar[$i]["present_insert_form_field"] == "1" || $fields_labels_ar[$i]["type_field"] == "insert_timestamp" || $fields_labels_ar[$i]["type_field"] == "update_timestamp" || $fields_labels_ar[$i]["type_field"] == "ID_user") { // if the field is in the form or need to be inserted because it's an insert data, an update data, an ID_user or a unique_ID
 993:             $sql .= "`".$fields_labels_ar[$i]["name_field"]."`, "; // add the field name to the sql statement
 994:         } // end if
 995:     } // end for
 996: 
 997:     $sql = substr($sql, 0, (strlen($sql)-2));
 998: 
 999:     $sql .= ") VALUES (";
1000: 
1001:     for ($i=0; $i<$count_temp; $i++) {
1002:         if ($fields_labels_ar[$i]["present_insert_form_field"] == "1") { // if the field is in the form
1003: 
1004:             $name_field_temp = $fields_labels_ar[$i]["name_field"];
1005: 
1006:             switch ($fields_labels_ar[$i]["type_field"]) {
1007:                 case "select_single":
1008:                     $field_name_temp = $fields_labels_ar[$i]["name_field"];
1009:                     $field_name_other_temp = $fields_labels_ar[$i]["name_field"]."_other____";
1010: 
1011:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......" and $_POST[$field_name_other_temp] != "") { // insert the "other...." choice
1012:                         $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1013:                         if ($primary_key_field_field != "") {
1014: 
1015:                             $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $fields_labels_ar[$i]["linked_fields_field"]);
1016: 
1017:                             $primary_key_field_field = insert_other_field($fields_labels_ar[$i]["primary_key_table_field"], $linked_fields_ar[0], $_POST[$field_name_other_temp]);
1018:                             $sql .= "'".$primary_key_field_field."', "; // add the last ID inserted to the sql statement
1019:                         } // end if ($foreign_key_temp != "")
1020:                         else { // no foreign key field
1021:                             $sql .= "'".$_POST[$field_name_other_temp]."', "; // add the field value to the sql statement
1022:                             if ( strpos($fields_labels_ar[$i]["select_options_field"], $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_other_temp].$fields_labels_ar[$i]["separator_field"] === false) ) { // the other field inserted is not already present in the $fields_labels_ar[$i]["select_options_field"] so we have to add it
1023: 
1024:                                 update_options($fields_labels_ar[$i], $field_name_temp, $_POST[$field_name_other_temp]);
1025: 
1026:                                 // re-get the array containg label ant other information about the fields changed with the above instruction
1027:                                 $fields_labels_ar = build_fields_labels_array($table_internal_name, "1");
1028:                             } // end if
1029:                         } // end else
1030:                     } // end if
1031:                     else {
1032:                         $sql .= "'".$_POST[$field_name_temp]."', "; // add the field value to the sql statement
1033:                     } // end else
1034:                     break;
1035:                 default: // textual field
1036:                     if ($_POST[$fields_labels_ar[$i]["name_field"]] == $fields_labels_ar[$i]["prefix_field"]) { // the field contain just the prefix
1037:                         $_POST[$fields_labels_ar[$i]["name_field"]] = "";
1038:                     } // end if
1039:                     $sql .= "'".$_POST[$fields_labels_ar[$i]["name_field"]]."', "; // add the field value to the sql statement
1040:                     break;
1041:             } // end switch
1042:         } // end if
1043:         elseif ($fields_labels_ar[$i]["type_field"] == "insert_timestamp" or $fields_labels_ar[$i]["type_field"] == "update_timestamp") { // if the field is not in the form but need to be inserted because it's an update data
1044:             $timestamp = time();
1045:             $sql .= "'".$timestamp."', "; // add the field name to the sql statement
1046: 
1047:         } // end elseif
1048:         elseif ($fields_labels_ar[$i]["type_field"] == "ID_user") { // if the field is not in the form but need to be inserted because it's an ID_user
1049:             $sql .= "'".$current_user."', "; // add the field name to the sql statement
1050:         } // end elseif
1051:     } // end for
1052: 
1053:     $sql = substr($sql, 0, (strlen($sql)-2));
1054: 
1055:     $sql .= ")";
1056:     /////////////////////////////
1057:     // end build the insert statement
1058: 
1059:     display_sql($sql);
1060: 
1061:     // insert the record
1062:     $db->send_query($sql);
1063: } // end function insert_record
1064: 
1065: function update_record($fields_labels_ar, $table_name, $table_internal_name, $where_field, $where_value)
1066: // goal: insert a new record in the main database
1067: // input $_FILES (needed for the name of the files), $_POST (the array containing all the values inserted in the form, $fields_labels_ar, $table_name, $table_internal_name, $where_field, $where_value
1068: // output: nothing
1069: {
1070:     global $null_checkbox_prefix, $year_field_suffix, $month_field_suffix, $day_field_suffix, $db;
1071:     $uploaded_file_names_count = 0;
1072: 
1073:     $field_to_check = "present_insert_form_field";
1074: 
1075:     // build the update statement
1076:     /////////////////////////////
1077:     $where = "$where_field = '$where_value'";
1078:     $archive_type = "datadmin_update";
1079:     $db->archive_table_row($table_name, $where, $archive_type);
1080:     $sql = "";
1081:     $sql .= "UPDATE `$table_name` SET ";
1082: 
1083:     $count_temp = count($fields_labels_ar);
1084:     for ($i=0; $i<$count_temp; $i++) {
1085:         $field_name_temp = $fields_labels_ar[$i]["name_field"];
1086:         if ($fields_labels_ar[$i][$field_to_check] == "1" or $fields_labels_ar[$i]["type_field"] == "update_date" or $fields_labels_ar[$i]["type_field"] == "update_timestamp") { // if the field is in the form or need to be inserted because it's an update data
1087: 
1088:             switch ($fields_labels_ar[$i]["type_field"]) {
1089:                 case "update_timestamp":
1090:                     $sql .= "`$field_name_temp` = "; // add the field name to the sql statement
1091:                     $timestamp = time();
1092:                     $sql .= "'".$timestamp."', "; // add the field name to the sql statement
1093:                     break;
1094:                 case "select_single":
1095:                     $field_name_other_temp = $field_name_temp."_other____";
1096: 
1097:                     if ($fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......" and $_POST[$field_name_other_temp] != "") { // insert the "other...." choice
1098: 
1099:                         $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1100:                         if ($primary_key_field_field != "") {
1101:                             $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $fields_labels_ar[$i]["linked_fields_field"]);
1102: 
1103:                             $primary_key_field_field = insert_other_field($fields_labels_ar[$i]["primary_key_table_field"], $linked_fields_ar[0], $_POST[$field_name_other_temp]);
1104:                             $sql .= "`".$field_name_temp."` = "; // add the field name to the sql statement
1105:                             $sql .= "'".$primary_key_field_field."', "; // add the field value to the sql statement
1106:                         } // end if ($foreign_key_temp != "")
1107:                         else { // no foreign key field
1108:                             $sql .= "`".$field_name_temp."` = "; // add the field name to the sql statement
1109:                             $sql .= "'".$_POST[$field_name_other_temp]."', "; // add the field value to the sql statement
1110:                             if (strpos($fields_labels_ar[$i]["select_options_field"], $fields_labels_ar[$i]["separator_field"].$_POST[$field_name_other_temp].$fields_labels_ar[$i]["separator_field"]) === false) { // the other field inserted is not already present in the $fields_labels_ar[$i]["select_options_field"] so we have to add it
1111: 
1112:                                 update_options($fields_labels_ar[$i], $field_name_temp, $_POST[$field_name_other_temp]);
1113: 
1114:                                 // re-get the array containg label ant other information about the fields changed with the above instruction
1115:                                 $fields_labels_ar = build_fields_labels_array($table_internal_name, "1");
1116:                             } // end if
1117:                         } // end else
1118:                     } // end if
1119:                     else {
1120:                         $sql .= "`".$field_name_temp."` = "; // add the field name to the sql statement
1121:                         $sql .= "'".$_POST[$field_name_temp]."', "; // add the field value to the sql statement
1122:                     } // end else
1123: 
1124:                     break;
1125:                 default: // textual field
1126:                     $sql .= "`".$field_name_temp."` = "; // add the field name to the sql statement
1127:                     $sql .= "'".$_POST[$field_name_temp]."', "; // add the field value to the sql statement
1128:                     break;
1129:             } // end switch
1130:         } // end if
1131:     } // end for
1132:     $sql = substr($sql, 0, -2); // delete the last two characters: ", "
1133:     $sql .= " WHERE `".$where_field."` = '".$where_value."'";
1134:     /////////////////////////////
1135:     // end build the update statement
1136: 
1137:     display_sql($sql);
1138: 
1139:     // update the record
1140:     $db->send_query($sql);
1141: } // end function update_record
1142: 
1143: function build_where_clause($fields_labels_ar, $table_name)
1144: // goal: build the where clause of a select sql statement e.g. "field_1 = 'value' AND field_2 LIKE '%value'"
1145: // input: $_POST, $fields_labels_ar, $table_name
1146: {
1147:     global $select_type_select_suffix, $year_field_suffix, $month_field_suffix, $day_field_suffix;
1148: 
1149:     $where_clause = "";
1150: 
1151:     $count_temp = count($fields_labels_ar);
1152:     // build the where clause
1153:     for ($i=0; $i<$count_temp; $i++) {
1154:         $field_type_temp = $fields_labels_ar[$i]["type_field"];
1155:         $field_name_temp = $fields_labels_ar[$i]["name_field"];
1156:         $field_separator_temp = $fields_labels_ar[$i]["separator_field"];
1157:         $field_select_type_temp = $fields_labels_ar[$i]["select_type_field"];
1158: 
1159:         if ($fields_labels_ar[$i]["present_search_form_field"] == "1") {
1160:             if ($_POST[$field_name_temp.$select_type_select_suffix] === 'is_empty') { // is_empty listbox option selected
1161:                 $where_clause .= "`$table_name`.`$field_name_temp`  =''"; // add the = '' value to the sql statement
1162: 
1163:                 $where_clause .= " ".$_POST["operator"]." ";
1164:             } // end if
1165:             else {
1166:                 switch ($field_type_temp) {
1167:                     case "insert_timestamp":
1168:                     case "update_timestamp":
1169:                         $select_type_field_name_temp = $field_name_temp.$select_type_select_suffix;
1170:                         if ($_POST[$select_type_field_name_temp] != "") {
1171:                             $year_field = $field_name_temp.$year_field_suffix;
1172:                             $month_field = $field_name_temp.$month_field_suffix;
1173:                             $day_field = $field_name_temp.$day_field_suffix;
1174:                             $day_beginning = mktime(0, 0, 0, $_POST[$month_field], $_POST[$day_field], $_POST[$year_field]);
1175:                             $day_end = mktime(24, 0, 0, $_POST[$month_field], $_POST[$day_field], $_POST[$year_field]);
1176:                             switch ($_POST[$select_type_field_name_temp]) {
1177:                                 case "is_equal":
1178:                                     $where_clause .= "`$table_name`.`$field_name_temp` >= '$day_beginning' AND `$table_name`.`$field_name_temp` <= '$day_end'";
1179:                                     break;
1180:                                 case "greater_than":
1181:                                     $where_clause .= "`$table_name`.`$field_name_temp` >= '$day_beginning'";
1182:                                     break;
1183:                                 case "less_then":
1184:                                     $where_clause .= "`$table_name`.`$field_name_temp` <= '$day_end'";
1185:                                     break;
1186:                             } // end switch
1187:                             //} // end else
1188:                             $where_clause .= " ".$_POST["operator"]." ";
1189:                         } // end if
1190:                         break;
1191:                     default:
1192:                         $select_type_field_name_temp = $field_name_temp.$select_type_select_suffix;
1193:                         if ($_POST[$field_name_temp] != "") { // if the user has filled the field
1194:                             switch ($_POST[$select_type_field_name_temp]) {
1195:                                 case "is_equal":
1196:                                     $where_clause .= "`$table_name`.`$field_name_temp` = '".$_POST[$field_name_temp]."'";
1197:                                     break;
1198:                                 case "contains":
1199:                                     $where_clause .= "`$table_name`.`$field_name_temp` LIKE '%".$_POST[$field_name_temp]."%'";
1200:                                     break;
1201:                                 case "starts_with":
1202:                                     $where_clause .= "`$table_name`.`$field_name_temp` LIKE '".$_POST[$field_name_temp]."%'";
1203:                                     break;
1204:                                 case "ends_with":
1205:                                     $where_clause .= "`$table_name`.`$field_name_temp` LIKE '%".$_POST[$field_name_temp]."'";
1206:                                     break;
1207:                                 case "greater_than":
1208:                                     $where_clause .= "`$table_name`.`$field_name_temp` > '".$_POST[$field_name_temp]."'";
1209:                                     break;
1210:                                 case "less_then":
1211:                                     $where_clause .= "`$table_name`.`$field_name_temp` < '".$_POST[$field_name_temp]."'";
1212:                                     break;
1213:                             } // end switch
1214:                             //} // end else
1215:                             $where_clause .= " ".$_POST["operator"]." ";
1216:                         } // end if
1217:                         break;
1218:                 } //end switch
1219:             } // end else
1220:         } // end if
1221:     } // end for ($i=0; $i<count($fields_labels_ar); $i++)
1222: 
1223:     if ($where_clause !== '') {
1224:         $where_clause = substr($where_clause, 0, -(strlen($_POST["operator" ])+2)); // delete the last " and " or " or "
1225:     } // end if
1226: 
1227:     return $where_clause;
1228: } // end function build_where_clause
1229: 
1230: function get_field_correct_displaying($field_value, $field_type, $field_content, $display_mode)
1231: // get the correct mode to display a field, according to its content (e.g. format data, display select multiple in different rows without separator and so on
1232: // input: $field_value, $field_type, $field_content, $display_mode (results_table|details_page|plain_text)
1233: // output: $field_to_display, the field value ready to be displayed
1234: // global: $word_wrap_col, the coloumn at which a string will be wrapped in the results
1235: {
1236:     global $word_wrap_col, $enable_word_wrap_cut, $null_word;
1237:     $field_to_display = "";
1238: 
1239:     if (is_null($field_value)) {
1240:         $field_to_display = $null_word;
1241:     } // end if
1242:     else {
1243:         switch ($field_type) {
1244:             case "insert_timestamp":
1245:             case "update_timestamp":
1246:                 if (substr($field_value, 0, 10) !== '0000-00-00') {
1247:                     $unix_timestamp = strtotime($field_value);
1248:                     if ($display_mode === 'plain_text') {
1249:                         $field_to_display = date ("d.m.Y  H:i:s", $unix_timestamp);
1250:                     } // end if
1251:                     else {
1252:                         $field_to_display = date ("d.m.Y", $unix_timestamp) . " &nbsp; " . date ("H:i:s", $unix_timestamp);
1253:                     } // end else
1254:                 } else {
1255:                     $field_to_display = " 0 ";
1256:                 }
1257:                 break;
1258: 
1259:             default: // e.g. text, textarea and select sinlge
1260:                 if ($display_mode === 'plain_text') {
1261:                     $field_to_display = $field_value;
1262:                 } // end if
1263:                 else {
1264:                     if ($field_content !== 'html') {
1265:                         $field_value = htmlspecialchars($field_value);
1266: 
1267:                         if ( $display_mode == "results_table") {
1268:                             $displayed_part = wordwrap($field_value, $word_wrap_col, "\n", $enable_word_wrap_cut);
1269:                         } // end if
1270:                         else {
1271:                             $displayed_part = $field_value;
1272:                         } // end else
1273: 
1274:                     } // end if
1275:                     else {
1276:                         $displayed_part = $field_value;
1277:                     } // end else
1278: 
1279:                     if ($field_content == "email" && $field_value != "") {
1280:                         $field_to_display = "<a href='mailto:".$field_value."'>".$displayed_part."</a>";
1281:                     } // end if
1282:                     elseif ($field_content == "url" && $field_value != "") {
1283:                         $field_to_display = "<a href='".$field_value."'>".$displayed_part."</a>";
1284:                     } // end elseif
1285:                     elseif (substr($displayed_part, 0, 8) !== "restore_") {
1286:                         $field_to_display = nl2br($displayed_part);
1287:                     } else {
1288:                         $field_to_display = $displayed_part;
1289:                     }
1290:                 } // end else
1291:                 break;
1292:         } // end switch
1293:     } // end else
1294:     return $field_to_display;
1295: } // function get_field_correct_displaying
1296: 
1297: function get_field_correct_csv_displaying($field_value)
1298: // get the correct mode to display a field in a csv, according to its content (e.g. format data, display select multiple in different rows without separator and so on
1299: // input: $field_value, $field_type, $field_content
1300: // output: $field_to_display, the field value ready to be displayed
1301: {
1302:     $field_to_display = str_replace("\r", '', $field_value);
1303:     return $field_to_display;
1304: } // function get_field_correct_csv_displaying
1305: 
1306: function build_results_table($fields_labels_ar, $table_name, $res_records, $results_type, $action, $where_clause, $page, $order, $order_type)
1307: // goal: build an HTML table for basicly displaying the results of a select query
1308: // input: $table_name, $res_records, the results of the query, $results_type (search, possible_duplication......), $action (e.g. index.php), $where_clause, $page (o......n), $order, $order_type
1309: // output: $results_table, the HTML results table
1310: // global: $submit_buttons_ar, the array containing the values of the submit buttons, $edit_target_window, the target window for edit/details (self, new......), $delete_icon, $edit_icon, $details_icon (the image files to use as icons), $enable_edit, $enable_delete, $enable_details (whether to enable (1) or not (0) the edit, delete and details features
1311: {
1312:     global $submit_buttons_ar, $normal_messages_ar, $edit_target_window, $delete_icon, $edit_icon, $details_icon, $enable_edit, $enable_delete, $enable_details, $db, $ask_confirmation_delete, $word_wrap_col, $word_wrap_fix_width, $alias_prefix, $dadabik_main_file, $enable_row_highlighting, $prefix_internal_table, $current_user_is_editor, $current_user, $lang;
1313: 
1314:     $function = "search";
1315: 
1316:     $unique_field_name = $db->get_primary_key($table_name);
1317: 
1318:     // build the results HTML table
1319:     ///////////////////////////////
1320: 
1321:     $results_table = "";
1322:     $results_table .= "<table class='results'>";
1323: 
1324:     // build the table heading
1325:     $results_table .= "<tr>";
1326: 
1327: 
1328:     $results_table .= "<th class='results'>&nbsp;</th>"; // skip the first column for edit, delete and details
1329: 
1330:     $count_temp = count($fields_labels_ar);
1331:     for ($i=0; $i<$count_temp; $i++) {
1332:         if ($fields_labels_ar[$i]["present_results_search_field"] == "1") { // the user want to display the field in the basic search results page
1333: 
1334:             $label_to_display = $fields_labels_ar[$i]["label_" . $lang . "_field"];
1335: 
1336:             if ($word_wrap_fix_width === 1) {
1337: 
1338:                 $spaces_to_add = $word_wrap_col-strlen($label_to_display);
1339: 
1340:                 if ( $spaces_to_add > 0) {
1341:                     for ($j=0; $j<$spaces_to_add; $j++) {
1342:                         $label_to_display .= '&nbsp;';
1343:                     }
1344:                 }
1345:             } // end if
1346: 
1347:             $results_table .= "<th class='results'>";
1348: 
1349:             $field_is_current_order_by = 0;
1350: 
1351:             if ( $results_type == "search") {
1352:                 if ($order != $fields_labels_ar[$i]["name_field"]) { // the results are not ordered by this field at the moment
1353:                     $link_class="order_link";
1354:                     $new_order_type = "ASC";
1355:                 }
1356:                 else {
1357:                     $field_is_current_order_by = 1;
1358:                     $link_class="order_link_selected";
1359:                     if ( $order_type == "DESC") {
1360:                         $new_order_type = "ASC";
1361:                     }
1362:                     else {
1363:                         $new_order_type = "DESC";
1364:                     }
1365:                 } // end elseif ($order != $fields_labels_ar[$i]["name_field"])
1366: 
1367:                 $results_table .= "<a class='$link_class' href='$action?table_name=". urlencode($table_name)."&function=$function&where_clause=".urlencode($where_clause)."&page=$page&order=".urlencode($fields_labels_ar[$i]["name_field"])."&amp;order_type=$new_order_type'>";
1368: 
1369:                 if ($field_is_current_order_by === 1) {
1370:                     if ($order_type === 'ASC') {
1371:                         $results_table .= '<span class="arrow">&uarr;</span> ';
1372:                     } // end if
1373:                     else {
1374:                         $results_table .= '<span class="arrow">&darr;</span> ';
1375:                     } // end if
1376:                 } // end if
1377: 
1378:                 $results_table .= $label_to_display."</a></th>"; // insert the linked name of the field in the <th>
1379:             }
1380:             else {
1381:                 $results_table .= $label_to_display."</th>"; // insert the  name of the field in the <th>
1382:             } // end if
1383: 
1384:         } // end if
1385:     } // end for
1386:     $results_table .= "</tr>";
1387: 
1388:     $tr_results_class = 'tr_results_1';
1389:     $td_controls_class = 'controls_1';
1390: 
1391:     // build the table body
1392:     while ($records_row = $db->db_fetch_assoc($res_records)) {
1393: 
1394:         if ($tr_results_class === 'tr_results_1') {
1395:             $td_controls_class = 'controls_2';
1396:             $tr_results_class = 'tr_results_2';
1397:         } // end if
1398:         else {
1399:             $td_controls_class = 'controls_1';
1400:             $tr_results_class = 'tr_results_1';
1401:         } // end else
1402: 
1403:         // set where clause for delete and update
1404:         ///////////////////////////////////////////
1405:         if (!empty($unique_field_name)) { // exists a unique number
1406:             $where_field = $unique_field_name;
1407:             $where_value = $records_row[$unique_field_name];
1408:         } // end if
1409:         ///////////////////////////////////////////
1410:         // end build where clause for delete and update
1411: 
1412:         if ($enable_row_highlighting === 1) {
1413:             $results_table .= "<tr class='".$tr_results_class."' onmouseover=\"if (this.className!='tr_highlighted_onclick') {this.className='tr_highlighted_onmouseover'}\" onmouseout=\"if (this.className!='tr_highlighted_onclick') {this.className='".$tr_results_class."'}\" onclick=\"if (this.className == 'tr_highlighted_onclick') { this.className='".$tr_results_class."';}else { this.className='tr_highlighted_onclick';}\">";
1414:         } // end if
1415:         else {
1416:             $results_table .= "<tr class='".$tr_results_class."'>";
1417:         } // end else
1418: 
1419:         $results_table .= "<td class='".$td_controls_class."'>";
1420: 
1421:         if (!empty($unique_field_name) and ($results_type == "search" or $results_type == "possible_duplication")) { // exists a unique number: edit, delete, details make sense
1422:             $show_edit_delete = "1";
1423:             if ($current_user_is_editor !== 1 && ($enable_edit == "1" || $enable_delete == "1")) {
1424:                 if ($records_row['username'] !== $current_user) {
1425:                     $show_edit_delete = "0";
1426:                 }
1427:             }
1428:             if ($enable_edit == "1" && $show_edit_delete == "1") { // display the edit icon
1429:                 $results_table .= "<a class='onlyscreen' target='_".$edit_target_window."' href='".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=edit&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."'><img src='".$edit_icon."' alt='".$submit_buttons_ar["edit"]."' title='".$submit_buttons_ar["edit"]."'></a>";
1430:             } // end if
1431: 
1432:             if ($enable_delete == "1" && $show_edit_delete == "1") { // display the delete icon
1433:                 $results_table .= "<a class='onlyscreen'";
1434:                 if ( $ask_confirmation_delete == 1) {
1435:                     $results_table .= " onclick=\"if (!confirm('".str_replace('\'', '\\\'', $normal_messages_ar['confirm_delete?'])."')) { return false;}\"";
1436:                 }
1437:                 $results_table .= " href='".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=delete&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."'><img src='".$delete_icon."' alt='".$submit_buttons_ar["delete"]."' title='".$submit_buttons_ar["delete"]."'>";
1438:             } // end if
1439: 
1440:             if ($enable_details == "1") { // display the details icon
1441:                 $results_table .= "<a class='onlyscreen' target='_".$edit_target_window."' href='".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=details&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."'><img src='".$details_icon."' alt='".$submit_buttons_ar["details"]."' title='".$submit_buttons_ar["details"]."'></a>";
1442:             } // end if
1443: 
1444:         } // end if
1445:         $results_table .= "</td>";
1446:         for ($i=0; $i<$count_temp; $i++) {
1447:             if ($fields_labels_ar[$i]["present_results_search_field"] == "1") { // the user want to display the field in the search results page
1448:                 $results_table .= "<td>"; // start the cell
1449: 
1450:                 $field_name_temp = $fields_labels_ar[$i]["name_field"];
1451:                 $field_type = $fields_labels_ar[$i]["type_field"];
1452:                 $field_content = $fields_labels_ar[$i]["content_field"];
1453:                 $field_separator = $fields_labels_ar[$i]["separator_field"];
1454: 
1455:                 $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values
1456: 
1457:                 $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1458:                 if (!empty($primary_key_field_field)) {
1459:                     $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
1460:                     $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
1461:                     $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
1462:                     $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
1463:                     $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
1464: 
1465:                     // get the list of all the installed tables
1466:                     $tables_names_ar = build_tables_names_array(0);
1467: 
1468:                     // if the linked table is installed I can get type content and separator of the linked field
1469:                     if (in_array($primary_key_table_field, $tables_names_ar)) {
1470:                         $linked_table_installed = 1;
1471: 
1472:                         $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table.$primary_key_table_field, "1");
1473:                     } // end if
1474:                     else {
1475:                         $linked_table_installed = 0;
1476:                     } // end else
1477: 
1478:                     for ($j=0;$j<count($linked_fields_ar);$j++) {
1479:                         ////*$field_values_ar[$j] = $records_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1480:                         $field_values_ar[$j] = $records_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1481:                     } // end for
1482:                 }
1483:                 else {
1484:                     //$field_value = $records_row[$field_name_temp];
1485:                     $field_values_ar[0] = $records_row[$field_name_temp];
1486: 
1487:                 }
1488: 
1489:                 $count_temp_2 = count($field_values_ar);
1490:                 for ($j=0; $j<$count_temp_2; $j++) {
1491: 
1492:                     // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator
1493:                     if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1) {
1494: 
1495:                         foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element) {
1496:                             if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) {
1497:                                 $linked_field_type = $fields_labels_linked_field_ar_element['type_field'];
1498:                                 $linked_field_content = $fields_labels_linked_field_ar_element['content_field'];
1499:                                 $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field'];
1500:                             } // end if
1501:                         } // end foreach
1502: 
1503:                         reset($fields_labels_linked_field_ar);
1504: 
1505:                         $field_to_display = get_field_correct_displaying($field_values_ar[$j], $linked_field_type, $linked_field_content, "results_table"); // get the correct display mode for the field
1506:                     } // end if
1507:                     else {
1508:                         $field_to_display = get_field_correct_displaying($field_values_ar[$j], $field_type, $field_content, "results_table"); // get the correct display mode for the field
1509:                     } // end else
1510: 
1511:                     if (empty($field_to_display)) {
1512:                         $field_to_display = "&nbsp;";
1513:                     }
1514:                     $results_table .= $field_to_display."&nbsp;"; // at the field value to the table
1515:                 }
1516:                 $results_table = substr($results_table, 0, -6); // delete the last &nbsp;
1517:                 $results_table .= "</td>"; // end the cell
1518:             } // end if
1519:         } // end for
1520: 
1521:         $results_table .= "</tr>";
1522:     } // end while
1523:     $results_table .= "</table>";
1524: 
1525:     return $results_table;
1526: 
1527: } // end function build_results_table
1528: 
1529: function build_csv($res_records, $fields_labels_ar)
1530: // build a csv, starting from a recordset
1531: // input: $res_record, the recordset, $fields_labels_ar
1532: {
1533:     global $csv_separator, $alias_prefix, $db, $lang;
1534:     $csv = "";
1535:     $count_temp = count($fields_labels_ar);
1536: 
1537:     // write heading
1538:     for ($i=0; $i<$count_temp; $i++) {
1539:         if ( $fields_labels_ar[$i]["present_results_search_field"] == "1") {
1540:             $csv .= "'".str_replace("'", "''", $fields_labels_ar[$i]["label_" . $lang . "_field"])."'".$csv_separator;
1541:         }
1542:     }
1543:     $csv = substr($csv, 0, -1); // delete the last ","
1544:     $csv .= "\n";
1545: 
1546:     // write other rows
1547:     while ($records_row = $db->db_fetch_assoc($res_records)) {
1548:         for ($i=0; $i<$count_temp; $i++) {
1549:             if ( $fields_labels_ar[$i]["present_results_search_field"] == "1") {
1550: 
1551:                 $field_name_temp = $fields_labels_ar[$i]["name_field"];
1552:                 $field_type = $fields_labels_ar[$i]["type_field"];
1553:                 $field_content = $fields_labels_ar[$i]["content_field"];
1554:                 $field_separator = $fields_labels_ar[$i]["separator_field"];
1555:                 $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values
1556: 
1557:                 $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1558:                 if ($primary_key_field_field != "") {
1559: 
1560:                     $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1561:                     $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
1562:                     $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
1563:                     $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
1564:                     $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
1565:                     $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
1566: 
1567:                     for ($j=0;$j<count($linked_fields_ar);$j++) {
1568:                         ////*$field_values_ar[$j] .= $records_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1569:                         $field_values_ar[$j] .= $records_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1570:                     } // end for
1571:                 }
1572:                 else {
1573:                     $field_values_ar[0] = $records_row[$field_name_temp];
1574:                 }
1575:                 $csv .= "'";
1576: 
1577:                 $count_temp_2 = count($field_values_ar);
1578:                 for ($j=0; $j<$count_temp_2; $j++) {
1579: 
1580:                     $field_to_display = get_field_correct_csv_displaying($field_values_ar[$j]);
1581: 
1582:                     $csv .= str_replace("'", "''", $field_to_display)." ";
1583:                 }
1584:                 $csv = substr($csv, 0, -1); // delete the last space
1585:             $csv .= "'".$csv_separator;
1586:             }
1587:         } // end for
1588:         $csv = substr($csv, 0, -1); // delete the last ","
1589:         $csv .= "\n";
1590:     }
1591:     return $csv;
1592: } // end function build_csv
1593: 
1594: function build_details_table($fields_labels_ar, $res_details)
1595: // goal: build an html table with details of a record
1596: // input: $fields_labels_ar $res_details (the result of the query)
1597: // ouptut: $details_table, the html table
1598: {
1599:     global $db, $alias_prefix, $prefix_internal_table, $lang;
1600: 
1601:     // build the table
1602:     $details_table = "";
1603: 
1604:     $details_table .= "<table>";
1605: 
1606:     while ($details_row = $db->db_fetch_assoc($res_details)) { // should be just one
1607: 
1608:         $count_temp = count($fields_labels_ar);
1609:         for ($i=0; $i<$count_temp; $i++) {
1610:             if ($fields_labels_ar[$i]["present_details_form_field"] == "1") {
1611:                 $field_name_temp = $fields_labels_ar[$i]["name_field"];
1612: 
1613:                 $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop if I don't call build_linked_field_values_ar I have the previous values
1614: 
1615:                 $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1616:                 if ($primary_key_field_field != "") {
1617:                     $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
1618:                     $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
1619:                     $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
1620:                     $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
1621:                     $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
1622:                     $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
1623: 
1624:                     // get the list of all the installed tables
1625:                     $tables_names_ar = build_tables_names_array(0);
1626: 
1627:                     // if the linked table is installed I can get type content and separator of the linked field
1628:                     if (in_array($primary_key_table_field, $tables_names_ar)) {
1629:                         $linked_table_installed = 1;
1630: 
1631:                         $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table.$primary_key_table_field, "1");
1632:                     } // end if
1633:                     else {
1634:                         $linked_table_installed = 0;
1635:                     } // end else
1636: 
1637:                     for ($j=0;$j<count($linked_fields_ar);$j++) {
1638:                         ////*$field_values_ar[$j] = $details_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1639:                         $field_values_ar[$j] = $details_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1640: 
1641:                     } // end for
1642:                 }
1643:                 else {
1644:                     $field_values_ar[0] = $details_row[$field_name_temp];
1645:                 }
1646: 
1647:                 $count_temp_2 = count($field_values_ar);
1648:                 $details_table .= "<tr><td class='td_label_details'><b>".$fields_labels_ar[$i]["label_" . $lang . "_field"]."</b></td><td class='td_value_details'>";
1649:                 for ($j=0; $j<$count_temp_2; $j++) {
1650: 
1651:                     // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator
1652:                     if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1) {
1653: 
1654:                         foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element) {
1655:                             if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) {
1656:                                 $linked_field_type = $fields_labels_linked_field_ar_element['type_field'];
1657:                                 $linked_field_content = $fields_labels_linked_field_ar_element['content_field'];
1658:                                 $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field'];
1659:                             } // end if
1660:                         } // end foreach
1661: 
1662:                         reset($fields_labels_linked_field_ar);
1663: 
1664:                         $field_to_display = get_field_correct_displaying($field_values_ar[$j], $linked_field_type, $linked_field_content, "details_table"); // get the correct display mode for the field
1665:                     } // end if
1666:                     else {
1667:                         $field_to_display = get_field_correct_displaying($field_values_ar[$j], $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], "details_table"); // get the correct display mode for the field
1668:                     } // end else
1669: 
1670:                     $details_table .= $field_to_display."&nbsp;"; // at the field value to the table
1671:                 }
1672:                 $details_table = substr($details_table, 0, -6); // delete the last &nbsp;
1673:                 $details_table .= "</td></tr>";
1674:             } // end if
1675:         } // end for
1676:     } // end while
1677: 
1678:     $details_table .= "</table>";
1679: 
1680:     return $details_table;
1681: } // end function build_details_table
1682: 
1683: function build_insert_update_notice_email_record_details($fields_labels_ar, $res_details)
1684: // goal: build the detail information about the record just inserted or updated, to use in the insert or update notice email
1685: // input: $fields_labels_ar $res_details (the recordset produced by the SELECT query on the record just inserted or just updated)
1686: // ouptut: $details_table, the html table
1687: {
1688:     global $db, $alias_prefix, $normal_messages_ar, $lang;
1689: 
1690:     $notice_email = '';
1691: 
1692:     $count_temp = count($fields_labels_ar);
1693:     while ($details_row = $db->db_fetch_assoc($res_details)) { // should be just one
1694:         $notice_email .= $normal_messages_ar['details_of_record']."\n";
1695:         $notice_email .= "--------------------------------------------\n\n";
1696: 
1697:         for ($i=0; $i<$count_temp; $i++) {
1698: 
1699:             if ($fields_labels_ar[$i]['present_details_form_field'] === '1') {
1700:                 $field_name_temp = $fields_labels_ar[$i]['name_field'];
1701: 
1702:                 $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop if I don't call build_linked_field_values_ar I have the previous values
1703: 
1704:                 $primary_key_field_field = $fields_labels_ar[$i]['primary_key_field_field'];
1705: 
1706:                 if ($primary_key_field_field != '') { // it is a foreign key field
1707: 
1708:                     $primary_key_table_field = $fields_labels_ar[$i]['primary_key_table_field'];
1709:                     $linked_fields_field = $fields_labels_ar[$i]['linked_fields_field'];
1710:                     $linked_fields_ar = explode($fields_labels_ar[$i]['separator_field'], $linked_fields_field);
1711:                     $alias_suffix_field = $fields_labels_ar[$i]['alias_suffix_field'];
1712: 
1713:                     for ($j=0; $j<count($linked_fields_ar); $j++) {
1714:                         $field_values_ar[$j] = $details_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1715:                     } // end for
1716:                 } // end if
1717:                 else {
1718:                     $field_values_ar[0] = $details_row[$field_name_temp];
1719:                 } // end else
1720: 
1721:                 $count_temp_2 = count($field_values_ar);
1722: 
1723:                 $notice_email .= $fields_labels_ar[$i]["label_" . $lang . "_field"].':'; // add the label
1724: 
1725:                 for ($j=0; $j<$count_temp_2; $j++) {
1726:                     $field_to_display = get_field_correct_displaying($field_values_ar[$j], $fields_labels_ar[$i]['type_field'], $fields_labels_ar[$i]['content_field'], 'plain_text'); // get the correct display mode for the field
1727: 
1728:                     $notice_email .= ' '.$field_to_display; // add the field value
1729:                 } // end for
1730: 
1731:                 $notice_email .= "\n"; // add the return
1732: 
1733:             } // end if
1734:         } // end for
1735:         $notice_email .= "\n\n--------------------------------------------\n" . _("The OpenHomeopath-Team") . " ;-)";
1736:     } // end while
1737:     return $notice_email;
1738: } // end function build_insert_update_notice_email_record_details()
1739: 
1740: function build_navigation_tool($table_name, $where_clause, $pages_number, $page, $action, $order, $order_type)
1741: // goal: build a set of link to go forward and back in the result pages
1742: // input: $where_clause, $pages_number (total number of pages), $page (the current page 0....n), $action, the action page (e.g. index.php), $order, the field used to order the results, $order_type
1743: // output: $navigation_tool, the html navigation tool
1744: {
1745:     $function = "search";
1746: 
1747:     $navigation_tool = "";
1748: 
1749:     $page_group = (int)($page/10); // which group? (from 0......n) e.g. page 12 is in the page_group 1
1750:     $total_groups = ((int)(($pages_number-1)/10))+1; // how many groups? e.g. with 32 pages 4 groups
1751:     $start_page = $page_group*10; // the navigation tool start with $start_page, end with $end_page
1752:     if ($start_page+10 > $pages_number) {
1753:         $end_page = $pages_number;
1754:     } // end if
1755:     else {
1756:         $end_page = $start_page+10;
1757:     } // end else
1758: 
1759:     $variables_to_pass = 'table_name='. urlencode($table_name).'&function='.$function.'&where_clause='.urlencode($where_clause).'&order='.urlencode($order).'&amp;order_type='.urlencode($order_type);
1760: 
1761:     if ($page_group > 1) {
1762:         $navigation_tool .= "<a class='navig' href='$action?".$variables_to_pass."&page=0' title='1'>&lt;&lt;</a> ";
1763:     } // end if
1764:     if ($page_group > 0) {
1765:         $navigation_tool .= "<a class='navig' href='$action?".$variables_to_pass."&page=".((($page_group-1)*10)+9)."' title='".((($page_group-1)*10)+10)."'>&lt;</a> ";
1766:     } // end if
1767: 
1768:     for($i=$start_page; $i<$end_page; $i++) {
1769:         if ($i != $page) {
1770:             $navigation_tool .= "<a class='navig' href='$action?".$variables_to_pass."&page=".$i."'>".($i+1)."</a> ";
1771:         } // end if
1772:         else {
1773:             $navigation_tool .= "<span class='navig'>".($i+1)."</span> ";
1774:         } //end else
1775:     } // end for
1776: 
1777:     if(($page_group+1) < ($total_groups)) {
1778:         $navigation_tool .= "<a class='navig' href='$action?".$variables_to_pass."&page=".(($page_group+1)*10)."' title='".((($page_group+1)*10)+1)."'>&gt;</a> ";
1779:     } // end elseif
1780:     if (($page_group+1) < ($total_groups-1)) {
1781:         $navigation_tool .= "<a class='navig' href='$action?".$variables_to_pass."&page=".($pages_number-1)."' title='".$pages_number."'>&gt;&gt;</a> ";
1782:     } // end if
1783:     return $navigation_tool;
1784: } // end function build_navigation_tool
1785: 
1786: function delete_record($table_name, $where_field, $where_value)
1787: // goal: delete one record
1788: {
1789:     global $db;
1790:     $where = "$where_field = '$where_value'";
1791:     $archive_type = "datadmin_delete";
1792:     $db->archive_table_row($table_name, $where, $archive_type);
1793:     $sql = "DELETE FROM `$table_name` WHERE `$where_field` = '$where_value'";
1794:     display_sql($sql);
1795: 
1796:     // execute the select query
1797:     $db->send_query($sql);
1798: 
1799: } // end function delete_record
1800: 
1801: function delete_multiple_records ($table_name, $where_clause, $ID_user_field_name)
1802: // goal: delete a group of record according to a where clause
1803: // input: $table_name, $where_clause, $ID_user_field_name (if it is not false, delete only the records that the current user owns
1804: {
1805:     global $current_user, $enable_authentication, $enable_delete_authorization, $db;
1806: 
1807:     if ($enable_authentication === 1 && $enable_delete_authorization === 1 && $ID_user_field_name !== false) { // check also the user
1808:         if ($where_clause !== '') {
1809:             $where_clause .= ' AND ';
1810:         } // end if
1811:         $where_clause .= "`$ID_user_field_name` = '$current_user'";
1812:     } // end if
1813:     $archive_type = "datadmin_multi_delete";
1814:     $db->archive_table_row($table_name, $where_clause, $archive_type);
1815:     $sql = '';
1816:     $sql .= "DELETE FROM `$table_name`";
1817:     if ($where_clause !== '') {
1818:         $sql .= " WHERE $where_clause";
1819:     } // end if
1820:     display_sql($sql);
1821: 
1822:     // execute the select query
1823:     $db->send_query($sql);
1824: 
1825: } // end function delete_multiple_records
1826: 
1827: function create_internal_table($table_internal_name)
1828: // goal: drop (if present) the old internal table and create the new one.
1829: // input: $table_internal_name
1830: {
1831:     global $db;
1832: 
1833:     $sql = "DROP TABLE IF EXISTS $table_internal_name";
1834:     $db->send_query($sql);
1835: 
1836:     $fields = "(
1837:         `id_field` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
1838:         `name_field` varchar(50) DEFAULT NULL,
1839:         `label_de_field` varchar(255) NOT NULL DEFAULT '',
1840:         `label_en_field` varchar(255) NOT NULL DEFAULT '',
1841:         `type_field` varchar(50) NOT NULL DEFAULT 'text',
1842:         `content_field` varchar(50) NOT NULL DEFAULT 'alphanumeric',
1843:         `present_search_form_field` varchar(1) NOT NULL DEFAULT '1',
1844:         `present_results_search_field` varchar(1) NOT NULL DEFAULT '1',
1845:         `present_details_form_field` varchar(1) NOT NULL DEFAULT '1',
1846:         `present_insert_form_field` varchar(1) NOT NULL DEFAULT '1',
1847:         `present_ext_update_form_field` varchar(1) NOT NULL DEFAULT '1',
1848:         `required_field` varchar(1) NOT NULL DEFAULT '0',
1849:         `check_duplicated_insert_field` varchar(1) NOT NULL DEFAULT '0',
1850:         `other_choices_field` varchar(1) NOT NULL DEFAULT '0',
1851:         `select_options_field` text,
1852:         `primary_key_field_field` varchar(255) NOT NULL DEFAULT '',
1853:         `primary_key_table_field` varchar(255) NOT NULL DEFAULT '',
1854:         `primary_key_db_field` varchar(50) NOT NULL DEFAULT '',
1855:         `linked_fields_field` text,
1856:         `linked_fields_order_by_field` text,
1857:         `linked_fields_order_type_field` text,
1858:         `select_type_field` varchar(100) NOT NULL DEFAULT 'is_equal/contains/starts_with/ends_with/greater_than/less_then/is_null/is_empty',
1859:         `prefix_field` text,
1860:         `default_value_field` text,
1861:         `width_field` varchar(5) NOT NULL DEFAULT '',
1862:         `height_field` varchar(5) NOT NULL DEFAULT '',
1863:         `maxlength_field` varchar(5) NOT NULL DEFAULT '100',
1864:         `hint_insert_de_field` varchar(255) NOT NULL DEFAULT '',
1865:         `hint_insert_en_field` varchar(255) NOT NULL DEFAULT '',
1866:         `order_form_field` int(11) NOT NULL,
1867:         `separator_field` varchar(2) NOT NULL DEFAULT '~',
1868:         PRIMARY KEY (`id_field`)
1869:     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
1870: 
1871:     $sql = "CREATE TABLE  `$table_internal_name` $fields";
1872:     $db->send_query($sql);
1873: 
1874: } // end function create_internal_table
1875: 
1876: function create_table_list_table()
1877: // goal: drop (if present) the old table list and create the new one.
1878: {
1879:     global $db, $table_list_name;
1880: 
1881:     $sql = "DROP TABLE IF EXISTS $table_list_name";
1882:     $db->send_query($sql);
1883: 
1884:     $fields = "(
1885:         `name_table` varchar(255) NOT NULL DEFAULT '',
1886:         `allowed_table` varchar(1) NOT NULL DEFAULT '',
1887:         `enable_insert_table` varchar(1) NOT NULL DEFAULT '',
1888:         `enable_edit_table` varchar(1) NOT NULL DEFAULT '',
1889:         `enable_delete_table` varchar(1) NOT NULL DEFAULT '',
1890:         `enable_details_table` varchar(1) NOT NULL DEFAULT '',
1891:         `alias_table_de` varchar(255) NOT NULL DEFAULT '',
1892:         `alias_table_en` varchar(255) NOT NULL DEFAULT '',
1893:         `position` tinyint(3) unsigned NOT NULL DEFAULT '0',
1894:         PRIMARY KEY (`name_table`)
1895:     ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
1896:     ";
1897: 
1898:     $sql = "CREATE TABLE  `$table_list_name` $fields";
1899:     $db->send_query($sql);
1900: 
1901: } // end function create_table_list_table
1902: 
1903: function create_users_table()
1904: // goal: drop (if present) the old users table and create the new one.
1905: {
1906:     global $db, $users_table_name;
1907: 
1908:     $fields = "(
1909:         `id_user` MEDIUMINT UNSIGNED NOT NULL PRIMARY AUTOINCREMENT,
1910:         `user_type_user` VARCHAR(50) NOT NULL,
1911:         `username_user` VARCHAR(50) NOT NULL,
1912:         `password_user` VARCHAR(32) NOT NULL,
1913:         UNIQUE `username_user_index` (`username_user`)
1914:     ) ENGINE=MYISAM CHARACTER SET utf8
1915:     ";
1916: 
1917:     $sql = "CREATE TABLE `$users_table_name`  $fields";
1918:     $db->send_query($sql);
1919: 
1920:     $sql = "INSERT INTO `".$users_table_name."` (user_type_user, username_user, password_user) VALUES ('admin', 'root', '".md5('admin')."')";
1921: 
1922:     $db->send_query($sql);
1923: 
1924: } // end function create_users_table
1925: 
1926: 
1927: function table_allowed($table_name)
1928: // goal: check if a table is allowed to be managed by DaDaBIK
1929: // input: $table_name
1930: // output: true or false
1931: {
1932:     global $db, $table_list_name;
1933:     if ($db->table_exists($table_list_name)) {
1934:         $sql = "SELECT `allowed_table` FROM `$table_list_name` WHERE `name_table` = '$table_name'";
1935:         $res_allowed = $db->send_query($sql);
1936:         if ($db->db_num_rows($res_allowed) == 1) {
1937:             $row_allowed = $db->db_fetch_row($res_allowed);
1938:             $allowed_table = $row_allowed[0];
1939:             if ($allowed_table == "0") {
1940:                 return false;
1941:             } // end if
1942:             else {
1943:                 return true;
1944:             } // end else
1945:         } // end if
1946:         elseif ($db->db_num_rows($res_allowed) == 0) { // e.g. I have an empty table or the table is not installed
1947:             return false;
1948:         } // end elseif
1949:         else {
1950:             exit;
1951:         } // end else
1952:     } // end if
1953:     else {
1954:         return false;
1955:     } // end else
1956: } // end function table_allowed()
1957: 
1958: function build_enabled_features_ar($table_name)
1959: // goal: build an array containing "0" or "1" according to the fact that a feature (insert, edit, delete, details) is enabled or not
1960: // input: $table_name
1961: // output: $enabled_features_ar, the array
1962: {
1963:     global $db, $table_list_name;
1964:     $sql = "SELECT `enable_insert_table`, `enable_edit_table`, `enable_delete_table`, `enable_details_table` FROM `$table_list_name` WHERE `name_table` = '$table_name'";
1965:     $db->send_query($sql);
1966:     $num_rows = $db->db_num_rows();
1967:     if ($num_rows == 1) {
1968:         $row_enable = $db->db_fetch_assoc();
1969:         $enabled_features_ar["insert"] = $row_enable["enable_insert_table"];
1970:         $enabled_features_ar["edit"] = $row_enable["enable_edit_table"];
1971:         $enabled_features_ar["delete"] = $row_enable["enable_delete_table"];
1972:         $enabled_features_ar["details"] = $row_enable["enable_details_table"];
1973:         $db->free_result();
1974:         return $enabled_features_ar;
1975:     } // end if
1976:     else {  //database error
1977:         exit;
1978:     } // end else
1979: } // end function build_enabled_features_ar($table_name)
1980: 
1981: function build_enable_features_checkboxes($table_name)
1982: // goal: build the form that enable features
1983: // input: name of the current table
1984: // output: the html for the checkboxes
1985: {
1986:     $enabled_features_ar = build_enabled_features_ar($table_name);
1987: 
1988:     $enable_features_checkboxes = "";
1989:     $enable_features_checkboxes .= "<input type='checkbox' name='enable_insert' value='1'";
1990:     $enable_features_checkboxes .= "";
1991:     if ($enabled_features_ar["insert"] == "1") {
1992:         $enable_features_checkboxes .= "checked";
1993:     } // end if
1994:     $enable_features_checkboxes .= ">Insert ";
1995:     $enable_features_checkboxes .= "<input type='checkbox' name='enable_edit' value='1'";
1996:     if ($enabled_features_ar["edit"] == "1") {
1997:         $enable_features_checkboxes .= "checked";
1998:     } // end if
1999:     $enable_features_checkboxes .= ">Edit ";
2000:     $enable_features_checkboxes .= "<input type='checkbox' name='enable_delete' value='1'";
2001:     if ($enabled_features_ar["delete"] == "1") {
2002:         $enable_features_checkboxes .= "checked";
2003:     } // end if
2004:     $enable_features_checkboxes .= ">Delete ";
2005:     $enable_features_checkboxes .= "<input type='checkbox' name='enable_details' value='1'";
2006:     if ($enabled_features_ar["details"] == "1") {
2007:         $enable_features_checkboxes .= "checked";
2008:     } // end if
2009:     $enable_features_checkboxes .= ">Details ";
2010: 
2011:     return $enable_features_checkboxes;
2012: } // end function build_enable_features_checkboxes
2013: 
2014: function build_change_field_select($fields_labels_ar, $field_position)
2015: // goal: build an html select with all the field names
2016: // input: $fields_labels_ar, $field_position (the current selected option)
2017: // output: the select
2018: {
2019:     global $table_name;
2020: 
2021:     $change_field_select = "";
2022:     $change_field_select .= "<select name='field_position'>";
2023:     $count_temp = count($fields_labels_ar);
2024:     for ($i=0; $i<$count_temp; $i++) {
2025:         $change_field_select .= "<option value='".$i."'";
2026:         if ($i == $field_position) {
2027:             $change_field_select .= " selected";
2028:         } // end if
2029:         $change_field_select .= ">".$fields_labels_ar[$i]["name_field"]."</option>";
2030:     } // end for
2031:     $change_field_select .= "</select>";
2032: 
2033:     return $change_field_select;
2034: } // end function build_change_field_select
2035: 
2036: function build_int_table_field_form($field_position, $int_fields_ar, $fields_labels_ar)
2037: // goal: build a part of the internal table manager form relative to one field
2038: // input: $field_position, the position of the field in the internal form, $int_field_ar, the array of the field of the internal table (with labels and properties), $fields_labels_ar, the array containing the fields labels and other information about fields
2039: // output: the html form part
2040: {
2041:     $int_table_form = "";
2042:     $int_table_form .= "<table><tr style='background-color: #F0F0F0'><td style='padding: 6px;'><table>";
2043:     $count_temp = count($int_fields_ar);
2044:     for ($i=0; $i<$count_temp; $i++) {
2045:         $int_table_form .= "<tr>";
2046:         $int_field_name_temp = $int_fields_ar[$i][1];
2047:         $int_table_form .= "<td>".$int_fields_ar[$i][0]."</td><td>";
2048:         if ($i==0) { // it's the name of the field, no edit needed, just show the name
2049:             $int_table_form .= $fields_labels_ar[$field_position][$int_field_name_temp];
2050:         } // end if
2051:         else {
2052:             switch ($int_fields_ar[$i][2]) {
2053:                 case "text":
2054:                     $int_table_form .= "<input type='text' name='".$int_field_name_temp."_".$field_position."' value='".$fields_labels_ar[$field_position][$int_field_name_temp]."' size='".$int_fields_ar[$i][3]."'>";
2055:                     break;
2056:                 case "select_yn":
2057:                     $int_table_form .= "<select name='".$int_field_name_temp."_".$field_position."'>";
2058:                     $int_table_form .= "<option value='1'";
2059:                     if ($fields_labels_ar[$field_position][$int_field_name_temp] == "1") {
2060:                         $int_table_form .= " selected";
2061:                     } // end if
2062:                     $int_table_form .= ">Y</option>";
2063:                     $int_table_form .= "<option value='0'";
2064:                     if ($fields_labels_ar[$field_position][$int_field_name_temp] == "0") {
2065:                         $int_table_form .= " selected";
2066:                     } // end if
2067:                     $int_table_form .= ">N</option>";
2068:                     $int_table_form .= "</select>";
2069:                     break;
2070:                 case "select_custom":
2071:                     $int_table_form .= "<select name='".$int_field_name_temp."_".$field_position."'>";
2072:                     $temp_ar = explode("/", $int_fields_ar[$i][3]);
2073:                     $count_temp_2 = count($temp_ar);
2074:                     for ($j=0; $j<$count_temp_2; $j++) {
2075:                         $int_table_form .= "<option value='".$temp_ar[$j]."'";
2076:                         if ($fields_labels_ar[$field_position][$int_field_name_temp] == $temp_ar[$j]) {
2077:                             $int_table_form .= " selected";
2078:                         } // end if
2079:                         $int_table_form .= ">".$temp_ar[$j]."</option>";
2080:                     } // end for
2081:                     $int_table_form .= "</select>";
2082:                     break;
2083:             } // end switch
2084:         } // end else
2085:         $int_table_form .= "</td>";
2086:         $int_table_form .= "</tr>"; // end of the row
2087:     } // end for
2088:     $int_table_form .= "</table></td></tr></table><p>&nbsp;</p>"; // end of the row
2089: 
2090:     return $int_table_form;
2091: } // end function build_int_table_field_form($field_position, $int_fields_ar, $fields_labels_ar)
2092: 
2093: function insert_other_field($primary_key_table, $field_name, $field_value_other)
2094: // goal: insert in the primary key table the other.... field
2095: // input: $primary_key_table, $primary_key_db, $linked_fields, $field_value_other
2096: // outpu: the ID of the record inserted
2097: {
2098:     global $db;
2099: 
2100:     if (!table_contains($primary_key_table, $field_name, $field_value_other)) { // check if the table doesn't contains the value inserted as other
2101: 
2102:         $sql_insert_other = "INSERT INTO `".$primary_key_table."` (`".$field_name."`) VALUES ('".$field_value_other."')";
2103: 
2104:         display_sql($sql_insert_other);
2105: 
2106:         // insert into the table of other
2107:         $db->send_query($sql_insert_other);
2108: 
2109:         return $db->db_insert_id();
2110:     } else {
2111:         return false;
2112:     }
2113: } // end function insert_other_field
2114: 
2115: function update_options($fields_labels_ar_i, $field_name, $field_value_other)
2116: // goal: upate the options of a field when a user select other....
2117: // input: $fields_labels_ar_i (fields_labels_ar specific for a field), $field_name, $field_value_other
2118: {
2119:     global $db, $table_internal_name;
2120:     $select_options_field_updated = $db->escape_string($fields_labels_ar_i["select_options_field"].stripslashes($field_value_other).$fields_labels_ar_i["separator_field"]);
2121: 
2122:     $sql_update_other = "UPDATE `".$table_internal_name."` SET `select_options_field` = '".$select_options_field_updated."' WHERE `name_field` = '".$field_name."'";
2123:     display_sql($sql_update_other);
2124: 
2125:     // update the internal table
2126:     $db->send_query($sql_update_other);
2127: } // end function update_options($fields_labels_ar_i, $field_name, $field_value_other)
2128: 
2129: function build_select_part($fields_labels_ar, $table_name)
2130: // goal: build the select part of a search query e.g.SELECT table_1.field_1, table_2.field2 from table_1 LEFT JOIN table_2 ON table_1.field_3 = table2.field_3
2131: // input: $fields_labels_ar, $table_name
2132: // output: the query
2133: {
2134:     global $alias_prefix, $db;
2135: 
2136:     // get the primary key
2137:     $unique_field_name = $db->get_primary_key($table_name);
2138: 
2139:     $sql_fields_part = '';
2140:     $sql_from_part = '';
2141: 
2142:     foreach($fields_labels_ar as $field) {
2143:         if ($field['present_results_search_field'] === '1' || $field['present_details_form_field'] === '1' || $field['name_field'] === $unique_field_name || (substr($table_name, 0, 9) == "archive__" && ($field['name_field'] == "timestamp" || $field['name_field'] == "archive_type"))) { // include in the select statements just the fields present in results or the primary key (useful to pass to the edit form) or timestamp/archive_type for archiv-tables
2144: 
2145:             // if the field has linked fields, include each linked fields in the select statement and the corresponding table (wiht join) in the from part. Use alias for all in order to mantain name unicity, each field has is own alias_suffix_field so it is easy
2146:             if ($field['primary_key_field_field'] !== '' && $field['primary_key_field_field'] !== NULL) {
2147:                 $linked_fields_ar = explode($field['separator_field'], $field['linked_fields_field']);
2148: 
2149:                 foreach ($linked_fields_ar as $linked_field) {
2150:                     $sql_fields_part .= "`".$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field']."`".'.'."`".$linked_field."`".' AS '."`".$field['primary_key_table_field'].$alias_prefix.$linked_field.$alias_prefix.$field['alias_suffix_field']."`".', ';
2151:                 } //end foreach
2152: 
2153:                 $sql_from_part .= ' LEFT JOIN '."`".$field['primary_key_table_field']."`".' AS '."`".$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field']."`";
2154: 
2155:                 $sql_from_part .= ' ON ';
2156:                 $sql_from_part .= "`".$table_name."`".'.'."`".$field['name_field']."`".' = '."`".$field['primary_key_table_field'].$alias_prefix.$field['alias_suffix_field']."`".'.'."`".$field['primary_key_field_field']."`";
2157:             } // end if
2158:             // if the field has not linked field, include just the field in the select statement
2159:             else {
2160:                 $sql_fields_part .= "`$table_name`.`".$field['name_field']."`, ";
2161:             } // end else
2162:         } // end if
2163:     } // end foreach
2164: 
2165:     $sql_fields_part = substr($sql_fields_part, 0, -2); // delete the last ', '
2166: 
2167:     // compose the final statement
2168:     $sql = "SELECT $sql_fields_part FROM `$table_name`$sql_from_part" ;
2169: 
2170:     return $sql;
2171: } // end function build_select_part()
2172: 
2173: function build_records_per_page_form($action, $records_per_page, $table_name)
2174: // goal: build the listbox that allows the user to choose the number of result record per page on the fly
2175: // input: $records_per_page, the current number of record per page, $table_name, the current table
2176: // output: the form
2177: {
2178:     global $records_per_page_ar, $normal_messages_ar;
2179: 
2180:     $records_per_page_form = "";
2181: 
2182:     $records_per_page_form .= "<form name='records_per_page_form' action='$action' method='GET'>";
2183: 
2184:     $records_per_page_form .= "<input type='hidden' name='table_name' value='$table_name'>";
2185:     $records_per_page_form .= "<input type='hidden' name='function' value='search'>";
2186: 
2187:     $records_per_page_form .= "<select class='select_records_per_page' name='records_per_page' onchange=\"document.records_per_page_form.submit()\">";
2188: 
2189:     foreach ($records_per_page_ar as $records_per_page_item) {
2190:         $records_per_page_form .= "<option value='$records_per_page_item'";
2191:         if ($records_per_page_item === $records_per_page) {
2192:             $records_per_page_form .= " selected";
2193:         } // end if
2194:         $records_per_page_form .= ">$records_per_page_item</option>";
2195:     } // foreach
2196: 
2197:     $records_per_page_form .= "</select>";
2198:     $records_per_page_form .= " ".$normal_messages_ar['records_per_page'];
2199:     $records_per_page_form .= "</form>";
2200: 
2201:     return $records_per_page_form;
2202: } // end function build_records_per_page_form()
2203: 
2204: function build_installed_table_infos_ar($only_include_allowed, $exclude_users_tab_if_not_admin)
2205: // goal: build an an array containing infos about dadabik installed tables
2206: // input: $only_include_allowed (0|1) $exclude_users_tab_if_not_admin(0|1)
2207: // output: the array
2208: {
2209:     global $table_list_name, $users_table_name, $db, $current_user_is_editor, $lang;
2210: 
2211:     if ($only_include_allowed === 1) {
2212:         $sql = "SELECT name_table, alias_table_$lang FROM `$table_list_name` WHERE allowed_table = '1'";
2213:     } // end if
2214:     else {
2215:         $sql = "SELECT name_table, alias_table_$lang FROM `$table_list_name`";
2216:     } // end else
2217: 
2218:     $res = $db->send_query($sql);
2219: 
2220:     $i=0;
2221: 
2222:     while ($row = $db->db_fetch_row($res)) {
2223:         if ($current_user_is_editor === 1 || $row[0] !== $users_table_name || $exclude_users_tab_if_not_admin === 0) {
2224:             $installed_table_infos_ar[$i]['name_table'] = $row[0];
2225:             $installed_table_infos_ar[$i]['alias_table'] = $row[1];
2226:             $i++;
2227:         } // end if
2228:     } // end while
2229:     $db->free_result($res);
2230: 
2231:     return $installed_table_infos_ar;
2232: 
2233: } // end function build_installed_table_infos_ar()
2234: ?>
2235: 
OpenHomeopath PHP code documentation API documentation generated by ApiGen 2.8.0