-
Notifications
You must be signed in to change notification settings - Fork 9
/
add-database-checkbox-field.php
89 lines (51 loc) · 3.32 KB
/
add-database-checkbox-field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require 'class.base.php';
require 'class.html.php';
$base_instance=new base();
$html_instance=new html();
$userid=$base_instance->get_userid();
$category_id=isset($_REQUEST['category_id']) ? (int)$_REQUEST['category_id'] : exit;
if (isset($_POST['add_fields'])) {
$number_of_fields=(int)$_POST['number_of_fields'];
$number_of_fields+=3;
for ($index=1; $index <= $number_of_fields; $index++) {
if (isset($_POST['name_checkbox_field_item_'.$index])) { $item_value[$index]=sql_safe($_POST['name_checkbox_field_item_'.$index]); }
else { $item_value[$index]=''; }
}
}
else if (isset($_POST['save_it'])) {
$title_checkbox_field=sql_safe($_POST['title_checkbox_field']);
$number_of_fields=sql_safe($_POST['number_of_fields']);
$base_instance->query("INSERT INTO {$base_instance->entity['DATABASE']['CHECKBOX_FIELDS']} (user,title,category_id) VALUES ($userid,'$title_checkbox_field',$category_id)");
$checkbox_field_id=mysqli_insert_id($base_instance->db_link);
for ($index=1; $index <= $number_of_fields; $index++) {
$name_item=sql_safe($_POST['name_checkbox_field_item_'.$index]);
if ($name_item) {
$base_instance->query("INSERT INTO {$base_instance->entity['DATABASE']['CHECKBOX_ITEMS']} (title,user,checkbox_field_id) VALUES ('$name_item',$userid,$checkbox_field_id)");
}
}
$base_instance->show_message('Field saved','<a href="add-database-number-field.php?category_id='.$category_id.'">[Add Number Field]</a> <a href="add-database-text-field.php?category_id='.$category_id.'">[Add Text Field]</a><p>
<a href="add-database-select-field.php?category_id='.$category_id.'">[Add Select Field]</a> <a href="add-database-checkbox-field.php?category_id='.$category_id.'">[Add Checkbox Field]</a><p><a href="add-database-data.php?category_id='.$category_id.'">[Add Data]</a> <a href="edit-database-checkbox-field.php?checkbox_field_id='.$checkbox_field_id.'">[Edit Field]</a> <a href="show-database-data.php?category_id='.$category_id.'">[Show all Data]</a>');
}
if (empty($number_of_fields)) { $number_of_fields=5; }
if (isset($_POST['title_checkbox_field'])) { $title_checkbox_field=sql_safe($_POST['title_checkbox_field']); } else { $title_checkbox_field=''; }
$html_instance->add_parameter(
array('ACTION'=>'show_form',
'HEADER'=>'Add Checkbox Fields',
'FORM_ACTION'=>$_SERVER['PHP_SELF'],
'INNER_TABLE_WIDTH'=>'400',
'TD_WIDTH'=>'30%',
'BUTTON_TEXT'=>'Save Field'
));
$html_instance->add_form_field(array('TYPE'=>'hidden','NAME'=>'save_it','VALUE'=>1));
$html_instance->add_form_field(array('TYPE'=>'hidden','NAME'=>'number_of_fields','VALUE'=>"$number_of_fields"));
$html_instance->add_form_field(array('TYPE'=>'hidden','NAME'=>'category_id','VALUE'=>"$category_id"));
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>'title_checkbox_field','VALUE'=>"$title_checkbox_field",'SIZE'=>35,'TEXT'=>'Name of Field'));
for ($index=1; $index <= $number_of_fields; $index++) {
$name='name_checkbox_field_item_'.$index;
if (isset($item_value[$index])) { $value=$item_value[$index]; } else { $value=''; }
$html_instance->add_form_field(array('TYPE'=>'text','NAME'=>$name,'VALUE'=>$value,'SIZE'=>35,'TEXT'=>'Name Item '.$index));
}
$html_instance->add_form_field(array('TYPE'=>'label','TEXT'=>'<input type="submit" name="add_fields" value="More Item Fields">'));
$html_instance->process();
?>