Overview

Packages

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

Functions

  • build_change_table_form_archiv
  • Overview
  • Package
  • Function
  • Tree
  1: <?php
  2: /**
  3:  * functions/archive.php
  4:  *
  5:  * This script is an enhancement to DaDaBIK from Eugenio Tacchini,
  6:  * which automatically archives all updates and deletions of records from the database
  7:  * and gives the possibility of restore previous versions.
  8:  *
  9:  * PHP version 8
 10:  *
 11:  * LICENSE: This program is free software: you can redistribute itThis script is an enhancement to DaDaBIK from Eugenio Tacchini  and/or modify
 12:  * it under the terms of the GNU Affero General Public License as
 13:  * published by the Free Software Foundation, either version 3 of the
 14:  * License, or (at your option) any later version.
 15:  * This program is distributed in the hope that it will be useful,
 16:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18:  * GNU Affero General Public License for more details.
 19:  * You should have received a copy of the GNU Affero General Public License
 20:  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 21:  *
 22:  * @category  Database
 23:  * @package   Archive
 24:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 25:  * @copyright 2007-2014 Henri Schumacher
 26:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 27:  * @version   1.0
 28:  * @link      https://research.openhomeo.info/download/OpenHomeopath_1.0.2.tar.gz
 29:  * @see       datadmin.php
 30:  */
 31: 
 32: function build_change_table_form_archiv($table_infos_ar, $table_name)
 33: // goal: build a form to choose the table
 34: // input: $table_infos_ar, $table_name
 35: // output: the listbox
 36: {
 37:     global $url;
 38:     $change_table_form = "    <form method='get' action='$url' name='change_table_form'>\n";
 39:     $change_table_form .= "      <select name='table_name' class='select_change_table' onchange=\"document.change_table_form.submit()\">\n";
 40: 
 41:     $count_temp = count($table_infos_ar);
 42:     for($i=0; $i<$count_temp; $i++){
 43:         $change_table_form .= "        <option value='".htmlspecialchars($table_infos_ar[$i]['table_name'])."'";
 44:         if ($table_name == $table_infos_ar[$i]['table_name']){
 45:             $change_table_form .= " selected";
 46:         }
 47:         $change_table_form .= ">".$table_infos_ar[$i]['table_alias']."</option>\n";
 48:     } // end for
 49:     $change_table_form .= "      </select>\n";
 50:     $change_table_form .= "    </form>\n";
 51: 
 52:     if ($count_temp == 1){
 53:         return "";
 54:     } // end if
 55:     else{
 56:         return $change_table_form;
 57:     } // end else
 58: 
 59: } // end function build_change_table_form_archiv
 60: 
 61: function build_results_table_archiv($fields_labels_ar, $table_name, $result, $action, $where_clause, $page, $order, $order_type, $table_infos_ar, $details)
 62: // goal: build an HTML table for basicly displaying the results of a select query or show a check mailing results
 63: // input: $table_name, $result, the results of the query, $action (e.g. index.php), $where_clause, $page (o......n), $order, $order_type, $table_infos_ar
 64: // output: $results_table, the HTML results table
 65: // global: $submit_buttons_ar, the array containing the values of the submit buttons, $edit_target_window, the target window for edit/details (self, new......), $restore_icon, $details_icon (the image files to use as icons)
 66: {
 67:     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;
 68: 
 69:     $function = "search";
 70: 
 71:     $unique_field_name = $db->get_primary_key($table_name);
 72: 
 73:     // build the results HTML table
 74:     ///////////////////////////////
 75: 
 76:     $results_table = "";
 77:     $results_table .= "<table class='results'>\n";
 78: 
 79:     // build the table heading
 80:     $results_table .= "<tr>\n";
 81: 
 82:     
 83:     $results_table .= "<th class='results'>&nbsp;</th>\n"; // skip the first column for edit, delete and details
 84:     $count_temp = count($fields_labels_ar);
 85:     for ($i=0; $i<$count_temp; $i++){
 86:         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
 87:             $label_to_display = $fields_labels_ar[$i]["label_" . $lang . "_field"];
 88:             if ($word_wrap_fix_width === 1){
 89:                 $spaces_to_add = $word_wrap_col-strlen($label_to_display);
 90:                 if ( $spaces_to_add > 0) {
 91:                     for ($j=0; $j<$spaces_to_add; $j++) {
 92:                         $label_to_display .= '&nbsp;';
 93:                     }
 94:                 }
 95:             } // end if
 96:             
 97:             $results_table .= "<th class='results'>";
 98:             $field_is_current_order_by = 0;
 99:             if ($order != $fields_labels_ar[$i]["name_field"]){ // the results are not ordered by this field at the moment
100:                 $link_class="order_link";
101:                 $new_order_type = "ASC";
102:             }
103:             else{
104:                 $field_is_current_order_by = 1;
105:                 $link_class="order_link_selected";
106:                 if ( $order_type == "DESC") {
107:                     $new_order_type = "ASC";
108:                 }
109:                 else{
110:                     $new_order_type = "DESC";
111:                 }
112:             } // end elseif ($order != $fields_labels_ar[$i]["name_field"])
113:             
114:             $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"])."&amp;order_type=$new_order_type'>";
115: 
116:             if ($field_is_current_order_by === 1) {
117:                 if ($order_type === 'ASC') {
118:                     $results_table .= '<span class="arrow">&uarr;</span> ';
119:                 } // end if
120:                 else {
121:                     $results_table .= '<span class="arrow">&darr;</span> ';
122:                 } // end if
123:             } // end if
124:             
125:             $results_table .= "$label_to_display</a></th>\n"; // insert the linked name of the field in the <th>
126:         } // end if
127:     } // end for
128:     $results_table .= "</tr>\n";
129:     if ($details == "1") {
130:         $sql = build_select_part($fields_labels_ar, $table_name);
131:         $where_clause_aktuell = str_replace("archive__", "", $where_clause);
132:         $sql .= " WHERE $where_clause_aktuell";
133:         display_sql($sql);
134:         // execute the select query
135:         $res_details = $db->send_query($sql);
136:         while ($details_row = $db->db_fetch_assoc($res_details)){
137:             $results_table .= "<tr class='tr_results_current'>\n";
138:             $results_table .= "<td class='controls_current'></td>\n";
139:             for ($i=0; $i<$count_temp; $i++){
140:                 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") {
141:                     $results_table .= "<td>"; // start the cell
142:                     
143:                     $field_name_temp = $fields_labels_ar[$i]["name_field"];
144:                     $field_type = $fields_labels_ar[$i]["type_field"];
145:                     $field_content = $fields_labels_ar[$i]["content_field"];
146:                     $field_separator = $fields_labels_ar[$i]["separator_field"];
147:     
148:                     $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values
149:     
150:                     $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
151:                     if (!empty($primary_key_field_field)){
152:                         $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
153:                         $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
154:                         $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
155:                         $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
156:                         $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
157:                         
158:                         // get the list of all the installed tables
159:                         $k = 0;
160:                         foreach ($table_infos_ar as $table_infos) {
161:                             $tables_names_ar[$k] = $table_infos['table_name'];
162:                             $k++;
163:                         }
164:     
165:                         // if the linked table is installed I can get type content and separator of the linked field
166:                         if (in_array($primary_key_table_field, $tables_names_ar)) {
167:                             $linked_table_installed = 1;
168:     
169:                             $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table.$primary_key_table_field, 1);
170:                         } // end if
171:                         else {
172:                             $linked_table_installed = 0;
173:                         } // end else
174:                         for ($j=0;$j<count($linked_fields_ar);$j++) {
175:                             $field_values_ar[$j] = $details_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
176:                         } // end for
177:                     } elseif ($field_name_temp === "archive_type") {
178:                         $field_values_ar[0] = "";
179:                     } else {
180:                         $field_values_ar[0] = $details_row[$field_name_temp];
181:                     } // end else
182:                     $count_temp_2 = count($field_values_ar);
183:                     for ($j=0; $j<$count_temp_2; $j++) {
184:                         // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator
185:                         if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1){
186:                             foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element){
187:                                 if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) {
188:                                     $linked_field_type = $fields_labels_linked_field_ar_element['type_field'];
189:                                     $linked_field_content = $fields_labels_linked_field_ar_element['content_field'];
190:                                     $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field'];
191:                                 } // end if
192:                             } // end foreach
193:     
194:                             reset($fields_labels_linked_field_ar);  
195:                             $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
196:                         } // end if
197:                         else {
198:                             $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
199:                         } // end else
200:                         if ($field_name_temp === "archive_type") {
201:                             $field_to_display = "<div class='center'><strong>" . _("Current record") . "</strong></div>";
202:                         } elseif (empty($field_to_display)) {
203:                             $field_to_display = "&nbsp;";
204:                         }
205:                         $results_table .= $field_to_display."&nbsp;"; // at the field value to the table
206:                     } // end for
207:                     $results_table = substr($results_table, 0, -6); // delete the last &nbsp;
208:                     $results_table .= "</td>\n"; // end the cell
209:                 } // end if
210:             } // end for
211:             $results_table .= "</tr>\n";
212:         } // end while
213:     }
214:     $tr_results_class = 'tr_results_1';
215:     $td_controls_class = 'controls_1';
216: 
217:     // build the table body
218:     while ($records_row = $db->db_fetch_assoc($result)){
219: 
220:         if ($details == "1" && strpos($records_row['archive_type'], "_delete") !== false) {
221:             $td_controls_class = 'controls_delete';
222:             $tr_results_class = 'tr_results_delete';
223:         } // end if
224:         elseif ($tr_results_class === 'tr_results_1') {
225:             $td_controls_class = 'controls_2';
226:             $tr_results_class = 'tr_results_2';
227:         } // end elseif
228:         else {
229:             $td_controls_class = 'controls_1';
230:             $tr_results_class = 'tr_results_1';
231:         } // end else
232:         // set where clause for details and update
233:         ///////////////////////////////////////////
234:         if (!empty($unique_field_name)){ // exists a unique number
235:             $where_field = $unique_field_name;
236:             $where_value = $records_row[$unique_field_name];
237:         } // end if
238:         if (!empty($records_row['timestamp'])){
239:             $timestamp = $records_row['timestamp'];
240:         } // end if
241:         ///////////////////////////////////////////
242:         // end build where clause for details and update
243: 
244:         if ($enable_row_highlighting === 1) {
245:             $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";
246:         } // end if
247:         else {
248:             $results_table .= "<tr class='$tr_results_class'>\n";
249:         } // end else
250:         
251:         $results_table .= "<td class='$td_controls_class'>";
252:         if (!empty($unique_field_name)){ // exists a unique number: restore, details make sense
253:             // display the restore icon
254:             if ($details == "1") {
255:                 $from_function = "details";
256:             } else {
257:                 $from_function = "search";
258:             }
259:             $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)."&timestamp=".urlencode($timestamp)."&from_function=$from_function";
260:             $results_table .= "'><img src='$restore_icon' alt='" . _("Restore record") . "' title='" . _("Restore record") . "'></a>";
261:             if ($details != "1") {  // display the details icon
262:                 $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>";
263:             }
264:         } // end if
265:         $results_table .= "</td>\n";
266:         for ($i=0; $i<$count_temp; $i++){
267:             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
268:                 $results_table .= "<td>"; // start the cell
269:                 
270:                 $field_name_temp = $fields_labels_ar[$i]["name_field"];
271:                 $field_type = $fields_labels_ar[$i]["type_field"];
272:                 $field_content = $fields_labels_ar[$i]["content_field"];
273:                 $field_separator = $fields_labels_ar[$i]["separator_field"];
274: 
275:                 $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values
276: 
277:                 $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
278:                 if (!empty($primary_key_field_field)){
279:                     $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
280:                     $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
281:                     $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
282:                     $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
283:                     $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);
284:                     
285:                     // get the list of all the installed tables
286:                     $k = 0;
287:                     foreach ($table_infos_ar as $table_infos) {
288:                         $tables_names_ar[$k] = $table_infos['table_name'];
289:                         $k++;
290:                     }
291: 
292:                     // if the linked table is installed I can get type content and separator of the linked field
293:                     if (in_array($primary_key_table_field, $tables_names_ar)) {
294:                         $linked_table_installed = 1;
295: 
296:                         $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table.$primary_key_table_field, 1);
297:                     } // end if
298:                     else {
299:                         $linked_table_installed = 0;
300:                     } // end else
301:                     for ($j=0;$j<count($linked_fields_ar);$j++) {
302:                         $field_values_ar[$j] = $records_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
303:                     } // end for
304:                 } else {
305:                     $field_values_ar[0] = $records_row[$field_name_temp];
306:                 } // end else
307:                 $count_temp_2 = count($field_values_ar);
308:                 for ($j=0; $j<$count_temp_2; $j++) {
309:                     // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator
310:                     if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1){
311:                         foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element){
312:                             if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) {
313:                                 $linked_field_type = $fields_labels_linked_field_ar_element['type_field'];
314:                                 $linked_field_content = $fields_labels_linked_field_ar_element['content_field'];
315:                                 $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field'];
316:                             } // end if
317:                         } // end foreach
318: 
319:                         reset($fields_labels_linked_field_ar);  
320:                         $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
321:                     } // end if
322:                     else {
323:                         $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
324:                     } // end else
325:                     if (empty($field_to_display)) {
326:                         $field_to_display = "&nbsp;";
327:                     } elseif ($field_name_temp === "archive_type") {
328:                         $archive_type_ar = array (
329:                             "admin_delete" => _("Deleting records of a user by Administrator"),
330:                             "datadmin_update"  => _("Updating the record by Data Maintenance"),
331:                             "datadmin_delete"  => _("Deleting the record by Data Maintenance"),
332:                             "datadmin_multi_delete"  => _("Deleting records by Data Maintenance"),
333:                             "express_update" => _("Update the record by Express-Tool"),
334:                             "BZH_restruct" => _("Restructuring of the symptoms from BZH")
335:                         );
336:                         if (substr($field_to_display, 0, 8) == "restore_") {
337:                             $time = substr($field_to_display, 8);
338:                             if (substr($time, 0, 10) !== '0000-00-00') {
339:                                 $time = date("d.m.Y  H:i", strtotime($time));
340:                                 if (substr($time, 0, 10) !== '01.01.1970') {
341:                                     $field_to_display = _("Replaced by version from") . " $time";
342:                                 } else {
343:                                     $field_to_display = _("Replaced by original version");
344:                                 }
345:                             } else {
346:                                 $field_to_display = _("Replaced by original version");
347:                             }
348:                         } else {
349:                             $field_to_display = $archive_type_ar[$field_to_display];
350:                         }
351:                     }
352:                     $results_table .= $field_to_display."&nbsp;"; // at the field value to the table
353:                 } // end for
354:                 $results_table = substr($results_table, 0, -6); // delete the last &nbsp;
355:                 $results_table .= "</td>\n"; // end the cell
356:             } // end if
357:         } // end for
358:         $results_table .= "</tr>\n";
359:     } // end while
360:     $results_table .= "</table>\n";
361:     
362:     return $results_table;
363: 
364: } // end function build_results_table_archiv
365: 
OpenHomeopath PHP code documentation API documentation generated by ApiGen 2.8.0