exit; } else { // redirect to the function from which the user comes (edit or detail) using the where_value just discovered header("Content-Type: text/html;charset=utf-8"); header('Location: ' . $site_url . $dadabik_main_file . '?table_name=' . $table_name . '&function=' . $from_function . '&where_field=' . urlencode($where_field) . '&where_value=' . urlencode($new_where_value)); exit; } // end else } // end if break; case "choose_previous_record": if (isset($where_clause) && isset($order) && isset($order_type)) { // could be not set if the session has expired // rebuild the query for the current results $sql = build_select_part($fields_labels_ar, $table_name); if ($where_clause !== '') { $sql .= " WHERE {$where_clause}"; } // end if $sql .= " ORDER BY `{$table_name}`.`{$order}` {$order_type}"; // execute the query $res = $db->send_query($sql); // loop through the recordset, when find the current record, read another one and save its where_value $record_found = 0; while ($row = $db->db_fetch_assoc($res)) { if ($row[$where_field] == $where_value) { $record_found = 1; } // end if if ($record_found === 0) {
} // end if $res_records_without_limit = $db->send_query($sql); while ($count_row = $db->db_fetch_row($res_records_without_limit)) { $results_number = $count_row[0]; // get the number of results } // end while $db->free_result($res_records_without_limit); $change_table_form = build_change_table_form_archiv($table_infos_ar, $table_name); $records_per_page_form = build_records_per_page_form($action, $records_per_page, $table_name); if ($results_number > 0) { // at least one record found $pages_number = get_pages_number($results_number, $records_per_page); // get the total number of pages $sql = build_select_part($fields_labels_ar, "archive__" . $table_name); if ($where_clause != "") { $sql .= " WHERE {$where_clause}"; } // end if if (!isset($order)) { // get the first field present in the results form as order $count_temp = 0; $fields_labels_ar_count = count($fields_labels_ar); while (!isset($order) && $count_temp < $fields_labels_ar_count) { if ($fields_labels_ar[$count_temp]["present_results_search_field"] === '1') { $order = $fields_labels_ar[$count_temp]["name_field"]; } // end if $count_temp++; }
function build_results_table_archiv($fields_labels_ar, $table_name, $result, $action, $where_clause, $page, $order, $order_type, $table_infos_ar, $details) { global $submit_buttons_ar, $edit_target_window, $restore_icon, $details_icon, $word_wrap_col, $word_wrap_fix_width, $alias_prefix, $enable_row_highlighting, $prefix_internal_table, $db, $url, $lang; $function = "search"; $unique_field_name = $db->get_primary_key($table_name); // build the results HTML table /////////////////////////////// $results_table = ""; $results_table .= "<table class='results'>\n"; // build the table heading $results_table .= "<tr>\n"; $results_table .= "<th class='results'> </th>\n"; // skip the first column for edit, delete and details $count_temp = count($fields_labels_ar); for ($i = 0; $i < $count_temp; $i++) { if ($fields_labels_ar[$i]["present_results_search_field"] == "1" || $fields_labels_ar[$i]["name_field"] == "timestamp" || $fields_labels_ar[$i]["name_field"] == "archive_type" || $details == "1" && $fields_labels_ar[$i]["present_details_form_field"] == "1") { // the user want to display the field in the basic search results page $label_to_display = $fields_labels_ar[$i]["label_" . $lang . "_field"]; if ($word_wrap_fix_width === 1) { $spaces_to_add = $word_wrap_col - strlen($label_to_display); if ($spaces_to_add > 0) { for ($j = 0; $j < $spaces_to_add; $j++) { $label_to_display .= ' '; } } } // end if $results_table .= "<th class='results'>"; $field_is_current_order_by = 0; if ($order != $fields_labels_ar[$i]["name_field"]) { // the results are not ordered by this field at the moment $link_class = "order_link"; $new_order_type = "ASC"; } else { $field_is_current_order_by = 1; $link_class = "order_link_selected"; if ($order_type == "DESC") { $new_order_type = "ASC"; } else { $new_order_type = "DESC"; } } // end elseif ($order != $fields_labels_ar[$i]["name_field"]) $results_table .= "<a class='" . $link_class . "' href='" . $action . "?table_name=" . urlencode($table_name) . "&function=search&where_clause=" . urlencode($where_clause) . "&page={$page}&order=" . urlencode($fields_labels_ar[$i]["name_field"]) . "&order_type={$new_order_type}'>"; if ($field_is_current_order_by === 1) { if ($order_type === 'ASC') { $results_table .= '<span class="arrow">↑</span> '; } else { $results_table .= '<span class="arrow">↓</span> '; } // end if } // end if $results_table .= "{$label_to_display}</a></th>\n"; // insert the linked name of the field in the <th> } // end if } // end for $results_table .= "</tr>\n"; if ($details == "1") { $sql = build_select_part($fields_labels_ar, $table_name); $where_clause_aktuell = str_replace("archive__", "", $where_clause); $sql .= " WHERE {$where_clause_aktuell}"; display_sql($sql); // execute the select query $res_details = $db->send_query($sql); while ($details_row = $db->db_fetch_assoc($res_details)) { $results_table .= "<tr class='tr_results_current'>\n"; $results_table .= "<td class='controls_current'></td>\n"; for ($i = 0; $i < $count_temp; $i++) { if ($fields_labels_ar[$i]["name_field"] == "timestamp" || $fields_labels_ar[$i]["name_field"] == "archive_type" || $fields_labels_ar[$i]["present_results_search_field"] == "1" || $fields_labels_ar[$i]["present_details_form_field"] == "1") { $results_table .= "<td>"; // start the cell $field_name_temp = $fields_labels_ar[$i]["name_field"]; $field_type = $fields_labels_ar[$i]["type_field"]; $field_content = $fields_labels_ar[$i]["content_field"]; $field_separator = $fields_labels_ar[$i]["separator_field"]; $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"]; if (!empty($primary_key_field_field)) { $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"]; $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"]; $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"]; $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"]; $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field); // get the list of all the installed tables $k = 0; foreach ($table_infos_ar as $table_infos) { $tables_names_ar[$k] = $table_infos['table_name']; $k++; } // if the linked table is installed I can get type content and separator of the linked field if (in_array($primary_key_table_field, $tables_names_ar)) { $linked_table_installed = 1; $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table . $primary_key_table_field, 1); } else { $linked_table_installed = 0; } // end else for ($j = 0; $j < count($linked_fields_ar); $j++) { $field_values_ar[$j] = $details_row[$primary_key_table_field . $alias_prefix . $linked_fields_ar[$j] . $alias_prefix . $alias_suffix_field]; } // end for } elseif ($field_name_temp === "archive_type") { $field_values_ar[0] = ""; } else { $field_values_ar[0] = $details_row[$field_name_temp]; } // end else $count_temp_2 = count($field_values_ar); for ($j = 0; $j < $count_temp_2; $j++) { // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1) { foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element) { if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) { $linked_field_type = $fields_labels_linked_field_ar_element['type_field']; $linked_field_content = $fields_labels_linked_field_ar_element['content_field']; $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field']; } // end if } // end foreach reset($fields_labels_linked_field_ar); $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 } else { $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 } // end else if ($field_name_temp === "archive_type") { $field_to_display = "<div class='center'><strong>" . _("Current record") . "</strong></div>"; } elseif (empty($field_to_display)) { $field_to_display = " "; } $results_table .= $field_to_display . " "; // at the field value to the table } // end for $results_table = substr($results_table, 0, -6); // delete the last $results_table .= "</td>\n"; // end the cell } // end if } // end for $results_table .= "</tr>\n"; } // end while } $tr_results_class = 'tr_results_1'; $td_controls_class = 'controls_1'; // build the table body while ($records_row = $db->db_fetch_assoc($result)) { if ($details == "1" && strpos($records_row['archive_type'], "_delete") !== false) { $td_controls_class = 'controls_delete'; $tr_results_class = 'tr_results_delete'; } elseif ($tr_results_class === 'tr_results_1') { $td_controls_class = 'controls_2'; $tr_results_class = 'tr_results_2'; } else { $td_controls_class = 'controls_1'; $tr_results_class = 'tr_results_1'; } // end else // set where clause for details and update /////////////////////////////////////////// if (!empty($unique_field_name)) { // exists a unique number $where_field = $unique_field_name; $where_value = $records_row[$unique_field_name]; } // end if if (!empty($records_row['timestamp'])) { $timestamp = $records_row['timestamp']; } // end if /////////////////////////////////////////// // end build where clause for details and update if ($enable_row_highlighting === 1) { $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';}\">\n"; } else { $results_table .= "<tr class='{$tr_results_class}'>\n"; } // end else $results_table .= "<td class='{$td_controls_class}'>"; if (!empty($unique_field_name)) { // exists a unique number: restore, details make sense // display the restore icon if ($details == "1") { $from_function = "details"; } else { $from_function = "search"; } $results_table .= "<a class='onlyscreen' onclick=\"if (!confirm('" . _("Restore record") . "?')){ return false;}\" href='{$url}?table_name=" . urlencode($table_name) . "&function=restore&where_field=" . urlencode($where_field) . "&where_value=" . urlencode($where_value) . "×tamp=" . urlencode($timestamp) . "&from_function={$from_function}"; $results_table .= "'><img src='{$restore_icon}' alt='" . _("Restore record") . "' title='" . _("Restore record") . "'></a>"; if ($details != "1") { // display the details icon $results_table .= "<a class='onlyscreen' target='_{$edit_target_window}' href='{$url}?table_name=" . urlencode($table_name) . "&details=1&where_field=" . urlencode($where_field) . "&where_value=" . urlencode($where_value) . "'><img src='{$details_icon}' alt='" . $submit_buttons_ar["details"] . "' title='" . _("Details from this record") . "'></a>"; } } // end if $results_table .= "</td>\n"; for ($i = 0; $i < $count_temp; $i++) { if ($fields_labels_ar[$i]["present_results_search_field"] == "1" || $fields_labels_ar[$i]["name_field"] == "timestamp" || $fields_labels_ar[$i]["name_field"] == "archive_type" || $details == "1" && $fields_labels_ar[$i]["present_details_form_field"] == "1") { // the user want to display the field in the search results page $results_table .= "<td>"; // start the cell $field_name_temp = $fields_labels_ar[$i]["name_field"]; $field_type = $fields_labels_ar[$i]["type_field"]; $field_content = $fields_labels_ar[$i]["content_field"]; $field_separator = $fields_labels_ar[$i]["separator_field"]; $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"]; if (!empty($primary_key_field_field)) { $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"]; $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"]; $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"]; $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"]; $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field); // get the list of all the installed tables $k = 0; foreach ($table_infos_ar as $table_infos) { $tables_names_ar[$k] = $table_infos['table_name']; $k++; } // if the linked table is installed I can get type content and separator of the linked field if (in_array($primary_key_table_field, $tables_names_ar)) { $linked_table_installed = 1; $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table . $primary_key_table_field, 1); } else { $linked_table_installed = 0; } // end else for ($j = 0; $j < count($linked_fields_ar); $j++) { $field_values_ar[$j] = $records_row[$primary_key_table_field . $alias_prefix . $linked_fields_ar[$j] . $alias_prefix . $alias_suffix_field]; } // end for } else { $field_values_ar[0] = $records_row[$field_name_temp]; } // end else $count_temp_2 = count($field_values_ar); for ($j = 0; $j < $count_temp_2; $j++) { // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1) { foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element) { if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) { $linked_field_type = $fields_labels_linked_field_ar_element['type_field']; $linked_field_content = $fields_labels_linked_field_ar_element['content_field']; $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field']; } // end if } // end foreach reset($fields_labels_linked_field_ar); $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 } else { $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 } // end else if (empty($field_to_display)) { $field_to_display = " "; } elseif ($field_name_temp === "archive_type") { $archive_type_ar = array("admin_delete" => _("Deleting records of a user by Administrator"), "datadmin_update" => _("Updating the record by Data Maintenance"), "datadmin_delete" => _("Deleting the record by Data Maintenance"), "datadmin_multi_delete" => _("Deleting records by Data Maintenance"), "express_update" => _("Update the record by Express-Tool"), "BZH_restruct" => _("Restructuring of the symptoms from BZH")); if (substr($field_to_display, 0, 8) == "restore_") { $time = substr($field_to_display, 8); if (substr($time, 0, 10) !== '0000-00-00') { $time = date("d.m.Y H:i", strtotime($time)); if (substr($time, 0, 10) !== '01.01.1970') { $field_to_display = _("Replaced by version from") . " {$time}"; } else { $field_to_display = _("Replaced by original version"); } } else { $field_to_display = _("Replaced by original version"); } } else { $field_to_display = $archive_type_ar[$field_to_display]; } } $results_table .= $field_to_display . " "; // at the field value to the table } // end for $results_table = substr($results_table, 0, -6); // delete the last $results_table .= "</td>\n"; // end the cell } // end if } // end for $results_table .= "</tr>\n"; } // end while $results_table .= "</table>\n"; return $results_table; }
function build_select_duplicated_query($table_name, $fields_labels_ar, &$string1_similar_ar, &$string2_similar_ar) { global $percentage_similarity, $number_duplicated_records, $db, $enable_authentication, $enable_browse_authorization, $current_user, $null_checkbox_prefix; // get the unique key of the table $unique_field_name = $db->get_primary_key($table_name); 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? $sql = ""; $sql_select_all = ""; $sql_select_all = "SELECT `{$unique_field_name}`, "; // this is used to select the records to check similiarity //$select = "SELECT * FROM `$table_name`"; $select = build_select_part($fields_labels_ar, $table_name); $where_clause = ""; // build the sql_select_all clause $j = 0; // build the $fields_to_check_ar array, containing the field to check for similiarity $fields_to_check_ar = array(); $count_temp = count($fields_labels_ar); for ($i = 0; $i < $count_temp; $i++) { if ($fields_labels_ar[$i]["check_duplicated_insert_field"] == "1") { if (!empty(${$fields_labels_ar[$i]["name_field"]})) { $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 } // end if $sql_select_all .= "`" . $fields_labels_ar[$i]["name_field"] . "`, "; $j++; } // end if } // end for $sql_select_all = substr($sql_select_all, 0, -2); // delete the last ", " $sql_select_all .= " FROM `{$table_name}`"; 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 $ID_user_field_name = get_ID_user_field_name($fields_labels_ar); if ($ID_user_field_name !== false) { // no ID_user fields available, don't use authorization if ($where_clause === '') { $sql_select_all .= " WHERE `{$table_name}`.`{$ID_user_field_name}` = '" . $db->escape_string($current_user) . "'"; } // end if } // end if } // end if // end build the sql_select_all clause // 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 // execute the select query $res_contacts = $db->send_query($sql_select_all); if ($db->db_num_rows($res_contacts) > 0) { while ($contacts_row = $db->db_fetch_row($res_contacts)) { // *A* for each record in the table $count_temp = count($fields_to_check_ar); for ($i = 0; $i < $count_temp; $i++) { // *B* and for each field the user has inserted 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 $z = 0; $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) // *C* check if the field inserted are similiar to the other fields to be checked in this record (*A*) $count_temp_2 = count($fields_to_check_ar); while ($z < $count_temp_2 and $found_similarity == 0) { $string1_temp = $_POST[$fields_to_check_ar[$i]]; // the field the user has inserted $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) similar_text(strtolower($string1_temp), strtolower($string2_temp), $percentage); if ($percentage >= $percentage_similarity) { // the two strings are similar $where_clause .= "`{$unique_field_name}` = '" . $contacts_row[0] . "' OR "; $found_similarity = 1; $string1_similar_ar[] = $string1_temp; $string2_similar_ar[] = $string2_temp; } // end if the two strings are similar $z++; } // end while } // end if } // end for loop for each field to check } // end while loop for each record } // end if ($db->db_num_rows($res_contacts) > 0) $db->free_result($res_contacts); $where_clause = substr($where_clause, 0, -4); // delete the last " OR " if ($where_clause != "") { $sql = $select . " WHERE " . $where_clause; } else { // no duplication $sql = ""; } // end else* } else { // no unique keys $sql = ""; } // end else return $sql; }