/
settings_st2.php
256 lines (141 loc) · 7.84 KB
/
settings_st2.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
/**
* Created by Dickson Msaky @ Ifakara Health Insitute (2018)
*/
require_once('includes/load.php');
$page_title = 'Settings';
page_require_level(2);
include_once('layouts/head.php');
$formtype = "ST2";
$table = "custst";
$field = "pc";
$field2 = "ft";
if(isset($_POST['submited2'])){
if(!empty($_POST['fieldsarr'])) {
$fieldsshort_array = array();
foreach($_POST['fieldsarr'] as $field){
preg_match('#\((.*?)\)#', $field, $match);
$my = strtolower($match[1])."\n";
array_push($fieldsshort_array,$my);
}
$fieldsarr = implode(",",$_POST['fieldsarr']);
$fieldsarr = str_replace("\n", "", $fieldsarr);
$fieldsshort_array2 = implode(",",$fieldsshort_array);
$fieldsshort_array2 = str_replace("\n", "", $fieldsshort_array2);
$fieldarraysize = sizeof($_POST['fieldsarr']);
if (!empty($_SESSION['expcode'])){
$resultcust = $db->query("SELECT * FROM {$db->escape($table)} WHERE pc='{$db->escape($_SESSION['expcode'])}' AND ft='{$formtype}' LIMIT 1");
if($db->num_rows($resultcust) === 0){
$result2 = $db->query("INSERT INTO {$db->escape($table)} (pc, ft, num_split, p_attri,p_attri2) VALUES('".$_SESSION['expcode']."','".$formtype."','".$fieldarraysize."','".$fieldsshort_array2."','".$fieldsarr."')");
if($result2){
$_SESSION['msg'] = '<script type="text/javascript">'.
"$.jGrowl('Fields successfuly saved!', { theme: 'growl-success', header: '' });".
'</script>';
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
}else{
$sql = "UPDATE {$db->escape($table)} SET num_split='".$fieldarraysize."',p_attri='".$fieldsshort_array2."',p_attri2='".$fieldsarr."' WHERE pc ='{$_SESSION['expcode']}' AND ft='{$formtype}' LIMIT 1";
$result2 = $db->query($sql);
if($result2){
$_SESSION['msg'] = '<script type="text/javascript">'.
"$.jGrowl('Fields successfuly saved!', { theme: 'growl-success', header: '' });".
'</script>';
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
}
}
}
} else if(isset($_POST['cleared'])){
if (!empty($_SESSION['expcode'])){
$resultcust = $db->query("SELECT * FROM {$db->escape($table)} WHERE pc='{$db->escape($_SESSION['expcode'])}' AND ft='{$formtype}' LIMIT 1");
if($db->num_rows($resultcust) === 0){
}else{
$sql = "DELETE FROM ".$db->escape($table);
$sql .= " WHERE ".$db->escape($field)."=".$_SESSION['expcode']." AND ".$db->escape($field2)."="."'ST2'";
$sql .= " LIMIT 1";
$result2 = $db->query($sql);
if($result2){
$_SESSION['msg'] = '<script type="text/javascript">'.
"$.jGrowl('Fields cleared!', { theme: 'growl-success', header: '' });".
'</script>';
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
}
}
} else if(isset($_POST['downloadtemp'])){
}
?>
<!-- Page content -->
<div class="page-content">
<?php echo display_msg_popup($msg); ?>
<!-- Page title -->
<div class="page-title">
<h5><i class="fa fa-bars"></i> Home <small>Welcome, <?php echo $name; ?> </small></h5>
</div>
<!-- /page title -->
<div class="panel panel-primary">
<div class="panel-heading">
<h6 class="panel-title"> Dataset Table For: <span id="pname"></span> </h6>
<div class="btn-group pull-right">
<?php include_once('scripts/selectproject.php'); ?>
</div>
</div>
</div>
<?php include_once('layouts/settingsmenu.php'); ?>
<br />
<div class="panel panel-default">
<div class="panel-heading"><h6 class="panel-title">Sample Storage</h6>
<div class="btn-group pull-right">
<form action="scripts/exporttemp.php" method="post">
<button type="submit" name='downloadtemp' class="btn btn-default"><i class="fa fa-download"></i>Download Template</button>
<input type="hidden" name="fo" value="<?php echo $formtype; ?>" >
<input type="hidden" name="ta" value="<?php echo $table; ?>" >
</form>
</div>
</div>
<div class="panel-body">
<h3>Sample Storage Customize</h3>
<form method="post" action=""><br/>
<?php
$checked_fields = array();
if(isset($_SESSION['expcode'])){
//fetchcheckedvalues
$fetchfields = $db->query("SELECT * FROM {$db->escape($table)} WHERE pc='{$db->escape($_SESSION['expcode'])}' AND ft='{$formtype}' LIMIT 1");
if($db->num_rows($fetchfields) > 0){
$result = $db->fetch_assoc($fetchfields);
$checked_fields = explode(",",$result['p_attri2']);
}else{
$msg_warn = '<script type="text/javascript">'.
"$.jGrowl('Fields not customized!', { life: 20000, theme: 'growl-error', header: '' });".
'</script>';
echo $msg_warn;
}
}
$fields_array = array("Serial No. (SEN)","Formrow (FR)","Box & Form Serial Number (SSEN)","No. of Samples (NS)");
array_push($fields_array, "Storage Temperature (FST)", "Crate/Freezer/Fridge Number (FF)","Rack/Carton Number (RCN)");
$disabled_fields_array = array("Serial No. (SEN)","Formrow (FR)","Box & Form Serial Number (SSEN)");
echo '<ul style="list-style-type:square">';
foreach($fields_array as $field){
$disable= "";
$checked = "";
if(in_array($field,$checked_fields)){
$checked = "checked";}
if (in_array($field,$disabled_fields_array)){
$checked = "checked";}
if (in_array($field,$disabled_fields_array)){
$disable = 'readonly="readonly"';}
echo '<input type="checkbox" name="fieldsarr[]" value="'.$field.'" '.$disable.' '.$checked.' > '.$field.' <br/>';
}
echo '</ul>';
?>
<div class="panel-footer form-actions text-right">
<button name="cleared" name="cleared" type="submit" id="cleared" class="btn btn-danger btn-lg"> <i class="fa fa-times" aria-hidden="true"></i> Delete saved </button>
<button name="submited2" name="submited2" type="submit" id="submited2" class="btn btn-primary btn-lg"> <i class="fa fa-check" aria-hidden="true"></i> Save fields </button>
</div>
</form>
</div>
</div>
<?php include_once('layouts/foot.php'); ?>