1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23: ?>
24: <?php
25:
26: function current_user_is_owner($where_field, $where_value, $table_name, $fields_labels_ar) {
27:
28:
29:
30:
31: 32: 33: 34: 35: 36: 37:
38: global $current_user, $current_user_is_editor, $db;
39:
40:
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;
44: }
45: else {
46:
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: }
56: else {
57: return false;
58: }
59: }
60:
61: }
62:
63: function get_ID_user_field_name($fields_labels_ar)
64:
65:
66:
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: }
77: $i++;
78: }
79:
80: return $ID_user_field_name;
81: }
82:
83: function build_fields_names_array($table_name)
84:
85:
86:
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: }
98:
99: function build_tables_names_array($exclude_not_allowed = 1, $exclude_not_installed = 1, $include_users_table = 0)
100:
101:
102:
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 ) {
110: $sql = "SELECT name_table FROM `$table_list_name`";
111: if ( $exclude_not_allowed == 1) {
112: $sql .= " WHERE allowed_table = '1'";
113: }
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: }
121: }
122: $db->free_result();
123: }
124: else {
125: $sql = "SHOW TABLES";
126: $db->send_query($sql);
127: while ($row = $db->db_fetch_row()) {
128: $table_name_temp = $row[0];
129:
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: }
134: }
135: $db->free_result();
136: }
137: return $tables_names_ar;
138: }
139:
140: function build_fields_labels_array($table_internal_name, $order_type)
141:
142:
143:
144:
145: {
146: global $db, $error_messages_ar;
147:
148: $table_alias_suffixes_ar = array();
149:
150:
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: }
156: elseif ($order_type == "2") {
157: $sql .= " ORDER BY `id_field`";
158: }
159:
160: $db->send_query($sql);
161: $num_rows = $db->db_num_rows();
162: $i = 0;
163: if ($num_rows > 0) {
164: while($field_row = $db->db_fetch_assoc()) {
165: $fields_labels_ar[$i]["name_field"] = $field_row["name_field"];
166: $fields_labels_ar[$i]["present_insert_form_field"] = $field_row["present_insert_form_field"];
167: $fields_labels_ar[$i]["present_ext_update_form_field"] = $field_row["present_ext_update_form_field"];
168: $fields_labels_ar[$i]["present_search_form_field"] = $field_row["present_search_form_field"];
169: $fields_labels_ar[$i]["required_field"] = $field_row["required_field"];
170: $fields_labels_ar[$i]["present_results_search_field"] = $field_row["present_results_search_field"];
171: $fields_labels_ar[$i]["present_details_form_field"] = $field_row["present_details_form_field"];
172: $fields_labels_ar[$i]["check_duplicated_insert_field"] = $field_row["check_duplicated_insert_field"];
173:
174: $fields_labels_ar[$i]["label_de_field"] = $field_row["label_de_field"];
175: $fields_labels_ar[$i]["label_en_field"] = $field_row["label_en_field"];
176:
177: $fields_labels_ar[$i]["type_field"] = $field_row["type_field"];
178: $fields_labels_ar[$i]["other_choices_field"] = $field_row["other_choices_field"];
179: $fields_labels_ar[$i]["content_field"] = $field_row["content_field"];
180: $fields_labels_ar[$i]["select_options_field"] = $field_row["select_options_field"];
181: $fields_labels_ar[$i]["separator_field"] = $field_row["separator_field"];
182: $fields_labels_ar[$i]["primary_key_field_field"] = $field_row["primary_key_field_field"];
183: $fields_labels_ar[$i]["primary_key_table_field"] = $field_row["primary_key_table_field"];
184: $fields_labels_ar[$i]["primary_key_db_field"] = $field_row["primary_key_db_field"];
185: $fields_labels_ar[$i]["linked_fields_field"] = $field_row["linked_fields_field"];
186: $fields_labels_ar[$i]["linked_fields_order_by_field"] = $field_row["linked_fields_order_by_field"];
187: $fields_labels_ar[$i]["linked_fields_order_type_field"] = $field_row["linked_fields_order_type_field"];
188: $fields_labels_ar[$i]["select_type_field"] = $field_row["select_type_field"];
189: $fields_labels_ar[$i]["prefix_field"] = $field_row["prefix_field"];
190: $fields_labels_ar[$i]["default_value_field"] = $field_row["default_value_field"];
191: $fields_labels_ar[$i]["width_field"] = $field_row["width_field"];
192: $fields_labels_ar[$i]["height_field"] = $field_row["height_field"];
193: $fields_labels_ar[$i]["maxlength_field"] = $field_row["maxlength_field"];
194: $fields_labels_ar[$i]["hint_insert_de_field"] = $field_row["hint_insert_de_field"];
195: $fields_labels_ar[$i]["hint_insert_en_field"] = $field_row["hint_insert_en_field"];
196: $fields_labels_ar[$i]["order_form_field"] = $field_row["order_form_field"];
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: }
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: }
209:
210: }
211:
212: $i++;
213: }
214: }
215: else {
216: echo $error_messages_ar["int_db_empty"];
217: }
218: $db->free_result();
219: return $fields_labels_ar;
220: }
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:
224:
225:
226:
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: }
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);
269: }
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);
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: }
288: else {
289: $form .= "<input type='hidden' name='operator' value='$default_operator'>";
290: }
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: }
296: for ($i=0; $i<count($fields_labels_ar); $i++) {
297: if ($fields_labels_ar[$i][$field_to_ceck] == "1") {
298:
299:
300:
301:
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: }
306: $form .= $fields_labels_ar[$i]["label_" . $lang . "_field"]." ";
307: $form .= "</td></tr></table></td>";
308:
309:
310:
311: $field_name_temp = $fields_labels_ar[$i]["name_field"];
312:
313:
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:
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: }
332: else {
333: unset($linked_fields_order_by_ar);
334: }
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);
353: $sql .= " ".$linked_fields_order_type_field;
354: }
355: $res_primary_key = $db->send_query($sql);
356: $fields_number = $db->db_num_fields();
357: }
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);
361: $select_type_date_select = build_select_type_select($field_name_temp, $fields_labels_ar[$i]["select_type_field"], 1);
362: }
363: else {
364: $select_type_select = "";
365: $select_type_date_select = "";
366: }
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: }
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: }
381: }
382: else {
383: $form .= " value='".htmlspecialchars($details_row[$field_name_temp])."'";
384: }
385: }
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: }
390: else {
391: $form .= " value='".$fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"]."'";
392: }
393: }
394: $form .= ">";
395: $form .= "</td>";
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: }
405: }
406: else {
407: $form .= htmlspecialchars($details_row[$field_name_temp]);
408: }
409: }
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: }
415: else {
416: $form .= $fields_labels_ar[$i]["prefix_field"].$fields_labels_ar[$i]["default_value_field"];
417: }
418:
419: }
420:
421: $form .= "</textarea></td>";
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: }
431: $form .= "<td class='td_input_form'>$select_type_date_select</td>$date_select</td>";
432: break;
433: case "select_single":
434: $form .= "<td class='td_input_form'>$select_type_select<select name='$field_name_temp'>";
435:
436: $form .= "<option value=''></option>";
437:
438: $field_temp = substr($fields_labels_ar[$i]["select_options_field"], 1, -1);
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: }
452: }
453: else {
454: if ($select_values_ar[$j] == $details_row[$field_name_temp]) {
455: $form .= " selected";
456: }
457: }
458: }
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: }
463:
464: $form .= ">".$select_values_ar[$j]."</option>";
465: }
466: }
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: }
478: $linked_fields_value = substr($linked_fields_value, 0, -3);
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: }
487: }
488: else {
489: if ($primary_key_value == $details_row[$field_name_temp]) {
490: $form .= " selected";
491: }
492: }
493: }
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: }
498:
499: $form .= ">$linked_fields_value</option>";
500: }
501: }
502: }
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: }
509: if ($form_type === 'update' && $show_edit_form_after_error === 1 && isset($_POST[$field_name_temp]) && $_POST[$field_name_temp] === '......') {
510: $form .= " selected";
511: }
512: $form .= ">".$normal_messages_ar["other...."]."</option>";
513: }
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: }
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: }
529: }
530: }
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: }
537: }
538: }
539:
540: $form .= ">";
541: }
542:
543: $form .= "</td>";
544: break;
545: }
546:
547:
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>";
551: }
552: $form .= "</tr></table></td></tr>";
553: }
554: }
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: }
559:
560: function build_select_type_select($field_name, $select_type, $first_option_blank)
561:
562:
563:
564:
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) {
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: }
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: }
581: $select_type_select .= "</select>";
582: }
583: else {
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: }
589:
590: function check_required_fields($fields_labels_ar)
591:
592:
593:
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') {
604: $check = 0;
605: }
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: }
614: }
615: else {
616: if ($_POST[$field_name_temp] == "") {
617: $check = 0;
618: }
619: }
620: break;
621: default:
622: if ($_POST[$field_name_temp] == $fields_labels_ar[$i]["prefix_field"]) {
623: $_POST[$field_name_temp] = "";
624: }
625: if ($_POST[$field_name_temp] == "") {
626: $check = 0;
627: }
628: break;
629: }
630: }
631: }
632: $i++;
633: }
634: return $check;
635: }
636:
637: function check_length_fields($fields_labels_ar)
638:
639:
640:
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:
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: }
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: }
662: }
663: else {
664: if (strlen($_POST[$field_name_temp]) > $fields_labels_ar[$i]["maxlength_field"]) {
665: $check = 0;
666: }
667: }
668: break;
669: }
670: }
671: $i++;
672: }
673: return $check;
674: }
675:
676: function check_fields_types($fields_labels_ar, &$content_error_type)
677:
678:
679:
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') {
690: $check = 1;
691: }
692: elseif (isset($_POST[$field_name_temp])) {
693: if ($_POST[$field_name_temp] == $fields_labels_ar[$i]["prefix_field"]) {
694: $_POST[$field_name_temp] = "";
695: }
696: if ($fields_labels_ar[$i]["type_field"] == "select_single" && $fields_labels_ar[$i]["other_choices_field"] == "1" and $_POST[$field_name_temp] == "......") {
697: $field_name_temp = $field_name_temp."_other____";
698: }
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: }
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: }
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: }
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: }
725: break;
726: }
727: }
728: }
729: $i++;
730: }
731: return $check;
732: }
733:
734: function build_select_duplicated_query($table_name, $fields_labels_ar, &$string1_similar_ar, &$string2_similar_ar)
735:
736:
737:
738:
739: {
740: global $percentage_similarity, $number_duplicated_records, $db, $enable_authentication, $enable_browse_authorization, $current_user, $null_checkbox_prefix;
741:
742:
743: $unique_field_name = $db->get_primary_key($table_name);
744:
745: if ($unique_field_name != "" && $unique_field_name != NULL) {
746:
747: $sql = "";
748: $sql_select_all = "";
749: $sql_select_all = "SELECT `$unique_field_name`, ";
750:
751: $select = build_select_part($fields_labels_ar, $table_name);
752: $where_clause = "";
753:
754:
755: $j = 0;
756:
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"];
763: }
764: $sql_select_all .= "`".$fields_labels_ar[$i]["name_field"]."`, ";
765: $j++;
766: }
767: }
768: $sql_select_all = substr ($sql_select_all, 0, -2);
769: $sql_select_all .= " FROM `$table_name`";
770:
771: if ($enable_authentication === 1 && $enable_browse_authorization === 1) {
772: $ID_user_field_name = get_ID_user_field_name($fields_labels_ar);
773:
774: if ($ID_user_field_name !== false) {
775: if ($where_clause === '') {
776: $sql_select_all .= " WHERE `$table_name`.`$ID_user_field_name` = '".$db->escape_string($current_user)."'";
777: }
778: }
779: }
780:
781:
782:
783:
784:
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)) {
789: $count_temp = count($fields_to_check_ar);
790: for ($i=0; $i<$count_temp; $i++) {
791: if (!isset($_POST[$null_checkbox_prefix.$fields_to_check_ar[$i]]) || $_POST[$null_checkbox_prefix.$fields_to_check_ar[$i]] !== '1') {
792: $z=0;
793: $found_similarity =0;
794:
795:
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]];
799: $string2_temp = $contacts_row[$z+1];
800:
801: similar_text(strtolower($string1_temp), strtolower($string2_temp), $percentage);
802: if ($percentage >= $percentage_similarity) {
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: }
808: $z++;
809: }
810: }
811: }
812: }
813: }
814: $db->free_result($res_contacts);
815:
816: $where_clause = substr($where_clause, 0, -4);
817: if ($where_clause != "") {
818: $sql = $select." WHERE ".$where_clause;
819: }
820: else {
821: $sql = "";
822: }
823: }
824: else {
825: $sql = "";
826: }
827: return $sql;
828: }
829:
830: function build_insert_duplication_form($fields_labels_ar, $table_name)
831:
832:
833:
834:
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] == "......") {
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: }
866: else {
867: $form .= "<input type='hidden' name='$field_name_temp' value='".htmlspecialchars(stripslashes($_POST[$field_name_temp]))."'>";
868: }
869: break;
870: default:
871: if ($_POST[$fields_labels_ar[$i]["name_field"]] == $fields_labels_ar[$i]["prefix_field"]) {
872: $_POST[$fields_labels_ar[$i]["name_field"]] = "";
873: }
874:
875: $form .= "<input type='hidden' name='$field_name_temp' value='".htmlspecialchars(stripslashes($_POST[$fields_labels_ar[$i]["name_field"]]))."'>";
876: break;
877: }
878: }
879: }
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: }
888:
889: function build_change_table_form()
890:
891:
892:
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: }
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: }
917: $change_table_form .= "</select>\n";
918: $change_table_form .= "</form>\n";
919:
920: if ($count_temp == 1) {
921: return "";
922: }
923: else {
924: return $change_table_form;
925: }
926:
927: }
928:
929: function build_change_table_select()
930:
931:
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:
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: }
952: $change_table_select .= "</select>";
953: if ($count_temp == 1) {
954: return "";
955: }
956: else {
957: return $change_table_select;
958: }
959: }
960:
961: function table_contains($table_name, $field_name, $value)
962:
963:
964:
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: }
973: return false;
974: }
975:
976: function insert_record($fields_labels_ar, $table_name, $table_internal_name)
977:
978:
979:
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:
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") {
993: $sql .= "`".$fields_labels_ar[$i]["name_field"]."`, ";
994: }
995: }
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") {
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] != "") {
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."', ";
1019: }
1020: else {
1021: $sql .= "'".$_POST[$field_name_other_temp]."', ";
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) ) {
1023:
1024: update_options($fields_labels_ar[$i], $field_name_temp, $_POST[$field_name_other_temp]);
1025:
1026:
1027: $fields_labels_ar = build_fields_labels_array($table_internal_name, "1");
1028: }
1029: }
1030: }
1031: else {
1032: $sql .= "'".$_POST[$field_name_temp]."', ";
1033: }
1034: break;
1035: default:
1036: if ($_POST[$fields_labels_ar[$i]["name_field"]] == $fields_labels_ar[$i]["prefix_field"]) {
1037: $_POST[$fields_labels_ar[$i]["name_field"]] = "";
1038: }
1039: $sql .= "'".$_POST[$fields_labels_ar[$i]["name_field"]]."', ";
1040: break;
1041: }
1042: }
1043: elseif ($fields_labels_ar[$i]["type_field"] == "insert_timestamp" or $fields_labels_ar[$i]["type_field"] == "update_timestamp") {
1044: $timestamp = time();
1045: $sql .= "'".$timestamp."', ";
1046:
1047: }
1048: elseif ($fields_labels_ar[$i]["type_field"] == "ID_user") {
1049: $sql .= "'".$current_user."', ";
1050: }
1051: }
1052:
1053: $sql = substr($sql, 0, (strlen($sql)-2));
1054:
1055: $sql .= ")";
1056:
1057:
1058:
1059: display_sql($sql);
1060:
1061:
1062: $db->send_query($sql);
1063: }
1064:
1065: function update_record($fields_labels_ar, $table_name, $table_internal_name, $where_field, $where_value)
1066:
1067:
1068:
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:
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") {
1087:
1088: switch ($fields_labels_ar[$i]["type_field"]) {
1089: case "update_timestamp":
1090: $sql .= "`$field_name_temp` = ";
1091: $timestamp = time();
1092: $sql .= "'".$timestamp."', ";
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] != "") {
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."` = ";
1105: $sql .= "'".$primary_key_field_field."', ";
1106: }
1107: else {
1108: $sql .= "`".$field_name_temp."` = ";
1109: $sql .= "'".$_POST[$field_name_other_temp]."', ";
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) {
1111:
1112: update_options($fields_labels_ar[$i], $field_name_temp, $_POST[$field_name_other_temp]);
1113:
1114:
1115: $fields_labels_ar = build_fields_labels_array($table_internal_name, "1");
1116: }
1117: }
1118: }
1119: else {
1120: $sql .= "`".$field_name_temp."` = ";
1121: $sql .= "'".$_POST[$field_name_temp]."', ";
1122: }
1123:
1124: break;
1125: default:
1126: $sql .= "`".$field_name_temp."` = ";
1127: $sql .= "'".$_POST[$field_name_temp]."', ";
1128: break;
1129: }
1130: }
1131: }
1132: $sql = substr($sql, 0, -2);
1133: $sql .= " WHERE `".$where_field."` = '".$where_value."'";
1134:
1135:
1136:
1137: display_sql($sql);
1138:
1139:
1140: $db->send_query($sql);
1141: }
1142:
1143: function build_where_clause($fields_labels_ar, $table_name)
1144:
1145:
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:
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') {
1161: $where_clause .= "`$table_name`.`$field_name_temp` =''";
1162:
1163: $where_clause .= " ".$_POST["operator"]." ";
1164: }
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: }
1187:
1188: $where_clause .= " ".$_POST["operator"]." ";
1189: }
1190: break;
1191: default:
1192: $select_type_field_name_temp = $field_name_temp.$select_type_select_suffix;
1193: if ($_POST[$field_name_temp] != "") {
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: }
1214:
1215: $where_clause .= " ".$_POST["operator"]." ";
1216: }
1217: break;
1218: }
1219: }
1220: }
1221: }
1222:
1223: if ($where_clause !== '') {
1224: $where_clause = substr($where_clause, 0, -(strlen($_POST["operator" ])+2));
1225: }
1226:
1227: return $where_clause;
1228: }
1229:
1230: function get_field_correct_displaying($field_value, $field_type, $field_content, $display_mode)
1231:
1232:
1233:
1234:
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: }
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: }
1251: else {
1252: $field_to_display = date ("d.m.Y", $unix_timestamp) . " " . date ("H:i:s", $unix_timestamp);
1253: }
1254: } else {
1255: $field_to_display = " 0 ";
1256: }
1257: break;
1258:
1259: default:
1260: if ($display_mode === 'plain_text') {
1261: $field_to_display = $field_value;
1262: }
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: }
1270: else {
1271: $displayed_part = $field_value;
1272: }
1273:
1274: }
1275: else {
1276: $displayed_part = $field_value;
1277: }
1278:
1279: if ($field_content == "email" && $field_value != "") {
1280: $field_to_display = "<a href='mailto:".$field_value."'>".$displayed_part."</a>";
1281: }
1282: elseif ($field_content == "url" && $field_value != "") {
1283: $field_to_display = "<a href='".$field_value."'>".$displayed_part."</a>";
1284: }
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: }
1291: break;
1292: }
1293: }
1294: return $field_to_display;
1295: }
1296:
1297: function get_field_correct_csv_displaying($field_value)
1298:
1299:
1300:
1301: {
1302: $field_to_display = str_replace("\r", '', $field_value);
1303: return $field_to_display;
1304: }
1305:
1306: function build_results_table($fields_labels_ar, $table_name, $res_records, $results_type, $action, $where_clause, $page, $order, $order_type)
1307:
1308:
1309:
1310:
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:
1319:
1320:
1321: $results_table = "";
1322: $results_table .= "<table class='results'>";
1323:
1324:
1325: $results_table .= "<tr>";
1326:
1327:
1328: $results_table .= "<th class='results'> </th>";
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") {
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 .= ' ';
1343: }
1344: }
1345: }
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"]) {
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: }
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"])."&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">↑</span> ';
1372: }
1373: else {
1374: $results_table .= '<span class="arrow">↓</span> ';
1375: }
1376: }
1377:
1378: $results_table .= $label_to_display."</a></th>";
1379: }
1380: else {
1381: $results_table .= $label_to_display."</th>";
1382: }
1383:
1384: }
1385: }
1386: $results_table .= "</tr>";
1387:
1388: $tr_results_class = 'tr_results_1';
1389: $td_controls_class = 'controls_1';
1390:
1391:
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: }
1398: else {
1399: $td_controls_class = 'controls_1';
1400: $tr_results_class = 'tr_results_1';
1401: }
1402:
1403:
1404:
1405: if (!empty($unique_field_name)) {
1406: $where_field = $unique_field_name;
1407: $where_value = $records_row[$unique_field_name];
1408: }
1409:
1410:
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: }
1415: else {
1416: $results_table .= "<tr class='".$tr_results_class."'>";
1417: }
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")) {
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") {
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: }
1431:
1432: if ($enable_delete == "1" && $show_edit_delete == "1") {
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: }
1439:
1440: if ($enable_details == "1") {
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: }
1443:
1444: }
1445: $results_table .= "</td>";
1446: for ($i=0; $i<$count_temp; $i++) {
1447: if ($fields_labels_ar[$i]["present_results_search_field"] == "1") {
1448: $results_table .= "<td>";
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();
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:
1466: $tables_names_ar = build_tables_names_array(0);
1467:
1468:
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: }
1474: else {
1475: $linked_table_installed = 0;
1476: }
1477:
1478: for ($j=0;$j<count($linked_fields_ar);$j++) {
1479:
1480: $field_values_ar[$j] = $records_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1481: }
1482: }
1483: else {
1484:
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:
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: }
1501: }
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");
1506: }
1507: else {
1508: $field_to_display = get_field_correct_displaying($field_values_ar[$j], $field_type, $field_content, "results_table");
1509: }
1510:
1511: if (empty($field_to_display)) {
1512: $field_to_display = " ";
1513: }
1514: $results_table .= $field_to_display." ";
1515: }
1516: $results_table = substr($results_table, 0, -6);
1517: $results_table .= "</td>";
1518: }
1519: }
1520:
1521: $results_table .= "</tr>";
1522: }
1523: $results_table .= "</table>";
1524:
1525: return $results_table;
1526:
1527: }
1528:
1529: function build_csv($res_records, $fields_labels_ar)
1530:
1531:
1532: {
1533: global $csv_separator, $alias_prefix, $db, $lang;
1534: $csv = "";
1535: $count_temp = count($fields_labels_ar);
1536:
1537:
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);
1544: $csv .= "\n";
1545:
1546:
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();
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:
1569: $field_values_ar[$j] .= $records_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1570: }
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);
1585: $csv .= "'".$csv_separator;
1586: }
1587: }
1588: $csv = substr($csv, 0, -1);
1589: $csv .= "\n";
1590: }
1591: return $csv;
1592: }
1593:
1594: function build_details_table($fields_labels_ar, $res_details)
1595:
1596:
1597:
1598: {
1599: global $db, $alias_prefix, $prefix_internal_table, $lang;
1600:
1601:
1602: $details_table = "";
1603:
1604: $details_table .= "<table>";
1605:
1606: while ($details_row = $db->db_fetch_assoc($res_details)) {
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();
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:
1625: $tables_names_ar = build_tables_names_array(0);
1626:
1627:
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: }
1633: else {
1634: $linked_table_installed = 0;
1635: }
1636:
1637: for ($j=0;$j<count($linked_fields_ar);$j++) {
1638:
1639: $field_values_ar[$j] = $details_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
1640:
1641: }
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:
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: }
1660: }
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");
1665: }
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");
1668: }
1669:
1670: $details_table .= $field_to_display." ";
1671: }
1672: $details_table = substr($details_table, 0, -6);
1673: $details_table .= "</td></tr>";
1674: }
1675: }
1676: }
1677:
1678: $details_table .= "</table>";
1679:
1680: return $details_table;
1681: }
1682:
1683: function build_insert_update_notice_email_record_details($fields_labels_ar, $res_details)
1684:
1685:
1686:
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)) {
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();
1703:
1704: $primary_key_field_field = $fields_labels_ar[$i]['primary_key_field_field'];
1705:
1706: if ($primary_key_field_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: }
1716: }
1717: else {
1718: $field_values_ar[0] = $details_row[$field_name_temp];
1719: }
1720:
1721: $count_temp_2 = count($field_values_ar);
1722:
1723: $notice_email .= $fields_labels_ar[$i]["label_" . $lang . "_field"].':';
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');
1727:
1728: $notice_email .= ' '.$field_to_display;
1729: }
1730:
1731: $notice_email .= "\n";
1732:
1733: }
1734: }
1735: $notice_email .= "\n\n--------------------------------------------\n" . _("The OpenHomeopath-Team") . " ;-)";
1736: }
1737: return $notice_email;
1738: }
1739:
1740: function build_navigation_tool($table_name, $where_clause, $pages_number, $page, $action, $order, $order_type)
1741:
1742:
1743:
1744: {
1745: $function = "search";
1746:
1747: $navigation_tool = "";
1748:
1749: $page_group = (int)($page/10);
1750: $total_groups = ((int)(($pages_number-1)/10))+1;
1751: $start_page = $page_group*10;
1752: if ($start_page+10 > $pages_number) {
1753: $end_page = $pages_number;
1754: }
1755: else {
1756: $end_page = $start_page+10;
1757: }
1758:
1759: $variables_to_pass = 'table_name='. urlencode($table_name).'&function='.$function.'&where_clause='.urlencode($where_clause).'&order='.urlencode($order).'&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'><<</a> ";
1763: }
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)."'><</a> ";
1766: }
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: }
1772: else {
1773: $navigation_tool .= "<span class='navig'>".($i+1)."</span> ";
1774: }
1775: }
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)."'>></a> ";
1779: }
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."'>>></a> ";
1782: }
1783: return $navigation_tool;
1784: }
1785:
1786: function delete_record($table_name, $where_field, $where_value)
1787:
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:
1797: $db->send_query($sql);
1798:
1799: }
1800:
1801: function delete_multiple_records ($table_name, $where_clause, $ID_user_field_name)
1802:
1803:
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) {
1808: if ($where_clause !== '') {
1809: $where_clause .= ' AND ';
1810: }
1811: $where_clause .= "`$ID_user_field_name` = '$current_user'";
1812: }
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: }
1820: display_sql($sql);
1821:
1822:
1823: $db->send_query($sql);
1824:
1825: }
1826:
1827: function create_internal_table($table_internal_name)
1828:
1829:
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: }
1875:
1876: function create_table_list_table()
1877:
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: }
1902:
1903: function create_users_table()
1904:
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: }
1925:
1926:
1927: function table_allowed($table_name)
1928:
1929:
1930:
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: }
1942: else {
1943: return true;
1944: }
1945: }
1946: elseif ($db->db_num_rows($res_allowed) == 0) {
1947: return false;
1948: }
1949: else {
1950: exit;
1951: }
1952: }
1953: else {
1954: return false;
1955: }
1956: }
1957:
1958: function build_enabled_features_ar($table_name)
1959:
1960:
1961:
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: }
1976: else {
1977: exit;
1978: }
1979: }
1980:
1981: function build_enable_features_checkboxes($table_name)
1982:
1983:
1984:
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: }
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: }
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: }
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: }
2009: $enable_features_checkboxes .= ">Details ";
2010:
2011: return $enable_features_checkboxes;
2012: }
2013:
2014: function build_change_field_select($fields_labels_ar, $field_position)
2015:
2016:
2017:
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: }
2029: $change_field_select .= ">".$fields_labels_ar[$i]["name_field"]."</option>";
2030: }
2031: $change_field_select .= "</select>";
2032:
2033: return $change_field_select;
2034: }
2035:
2036: function build_int_table_field_form($field_position, $int_fields_ar, $fields_labels_ar)
2037:
2038:
2039:
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) {
2049: $int_table_form .= $fields_labels_ar[$field_position][$int_field_name_temp];
2050: }
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: }
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: }
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: }
2079: $int_table_form .= ">".$temp_ar[$j]."</option>";
2080: }
2081: $int_table_form .= "</select>";
2082: break;
2083: }
2084: }
2085: $int_table_form .= "</td>";
2086: $int_table_form .= "</tr>";
2087: }
2088: $int_table_form .= "</table></td></tr></table><p> </p>";
2089:
2090: return $int_table_form;
2091: }
2092:
2093: function insert_other_field($primary_key_table, $field_name, $field_value_other)
2094:
2095:
2096:
2097: {
2098: global $db;
2099:
2100: if (!table_contains($primary_key_table, $field_name, $field_value_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:
2107: $db->send_query($sql_insert_other);
2108:
2109: return $db->db_insert_id();
2110: } else {
2111: return false;
2112: }
2113: }
2114:
2115: function update_options($fields_labels_ar_i, $field_name, $field_value_other)
2116:
2117:
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:
2126: $db->send_query($sql_update_other);
2127: }
2128:
2129: function build_select_part($fields_labels_ar, $table_name)
2130:
2131:
2132:
2133: {
2134: global $alias_prefix, $db;
2135:
2136:
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"))) {
2144:
2145:
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: }
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: }
2158:
2159: else {
2160: $sql_fields_part .= "`$table_name`.`".$field['name_field']."`, ";
2161: }
2162: }
2163: }
2164:
2165: $sql_fields_part = substr($sql_fields_part, 0, -2);
2166:
2167:
2168: $sql = "SELECT $sql_fields_part FROM `$table_name`$sql_from_part" ;
2169:
2170: return $sql;
2171: }
2172:
2173: function build_records_per_page_form($action, $records_per_page, $table_name)
2174:
2175:
2176:
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: }
2194: $records_per_page_form .= ">$records_per_page_item</option>";
2195: }
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: }
2203:
2204: function build_installed_table_infos_ar($only_include_allowed, $exclude_users_tab_if_not_admin)
2205:
2206:
2207:
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: }
2214: else {
2215: $sql = "SELECT name_table, alias_table_$lang FROM `$table_list_name`";
2216: }
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: }
2228: }
2229: $db->free_result($res);
2230:
2231: return $installed_table_infos_ar;
2232:
2233: }
2234: ?>
2235: