forked from esjoo/SchedLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
175 lines (153 loc) · 6.36 KB
/
insert.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
<head>
<link rel="stylesheet" type="text/css" href="style/protocol.css">
</head>
<body>
<?php
include 'header.php';
?>
<div>
<h1 id="demofont3">Create a new protocol</h1>
<div class="color">
<form action="showProtocol.php" method='post' onsubmit="return checkip()">
<!-- Protocol name -->
<div>
<h5 id="demofont4"><label for="name">Protocol name</label></h5>
<input type="text" class="form-control" style="width:600px;margin:auto" placeholder="Enter name" name="protName" id="protName">
</div>
<!-- Equipment -->
<div id="equipmentArea" class="form-group">
<h5 id="demofont4"><label for="equipment">Equipment</label></h5>
<textarea name="equipment" id="equipment" style="width:600px;height:200px;" placeholder="Insert all equipments"></textarea>
</div>
<!-- Procedure -->
<div class="form-group">
<h5 id="demofont4"><label for="procedure">Procedure</label></h5>
<textarea name="procedure" id="procedure" style="width:600px;height:200px;" placeholder="Insert procedure"></textarea>
</div>
<!-- chemicals-->
<div>
<h5 id="demofont4">Chemicals</h5>
<div class="search-box" style="margin:0px">
<input style="height:40px" type="text" autocomplete="off" placeholder="Search Chemicals" id="chem_name" /><button type="button" class="add-row button" id="add"><span>ADD</span></button><button type="button" class="delete-row button"><span>REMOVE</span></button>
<div class="result"></div>
</div>
<table style="width:600px;margin:auto">
<thead>
<tr>
<th><h6 class="font">Select</h6></th>
<th><h6 class="font">Chemical</h6></th>
<th><h6 class="font">Dosage</h6></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- Protocol Creater -->
<div>
<input type="hidden" name="ProtCreater" value="<?php echo $_SESSION['userName']?>">
</div>
<!-- Submit -->
<div>
<div class="form-group" style="text-align: center;">
<button name="submit" type="submit" class="button" style="width:200px"><span>Show protocol</span></button>
</div>
</div>
</form>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('.search-box input[type="text"]').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("livesearchFORprotocol.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
resultDropdown.html(data);
});
} else{
resultDropdown.empty();
}
});
// Set search input value on click of result item
$(document).on("click", ".result p", function(){
$(this).parents(".search-box").find('input[type="text"]').val($(this).text());
$(this).parent(".result").empty();
});
});
</script>
<!-- add the row of chemicals and dosages + check if there is same chemical name -->
<script>
$(document).ready(function(){
$(".add-row").click(function(){
var name = $("#chem_name").val();
var markup = '<tr> '+
'<td><input type="checkbox" name="record"></td>' +
'<td><input type="text" placeholder="Enter Chemical" style="color:black" name="chemicals[]" id="To_che" value="'+ name +'"/>' + '</td>'+
'<td style="color:black"><input type="number" step="0.0001" oninput="validity.valid||(value=``);" onpress="isNumber(event)" placeholder="Enter Dosage" name="dosages[]"></td></tr>';
var objs = document.getElementsByName("chemicals[]");
var my_chem = new Array();
for(var i = 0; i < objs.length; i++){
my_chem.push(objs[i].value);
};
if(objs.length == 0){
$("table tbody").prepend(markup);
}else{
if(my_chem.indexOf(name)>-1){
alert("There are reduplicate chemical names!");
return false;
}else{
$("table tbody").prepend(markup);
};
return true;
}
});
// Find and remove selected table rows
$(".delete-row").click(function(){
$("table tbody").find('input[name="record"]').each(function(){
if($(this).is(":checked")){
$(this).parents("tr").remove();
}
});
});
});
</script>
<!-- check if there are empty value -->
<script language="javascript">
function checkip() {
var protName = $('#protName').val()
var procedure = $('#procedure').val()
var equipment = $('#equipment').val()
var chemical = $('#chem_name').val()
if (protName==""){
alert('Protocal name cannot be empty')
return false;
}else if(procedure==""){
alert('Procedure cannot be empty')
return false;
}else if(equipment==""){
alert('Equipment cannot be empty')
return false;
}else if(chemical.length==0){
alert('Chemicals cannot be empty')
return false;
}else{
return true;
}
}
</script>
<!-- dosage value control -->
<script language="javascript">
function isNumber(evt) {
evt = (evt) ? evt : window.event;
let charCode = (evt.which) ? evt.which : evt.keyCode;
if ((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode !== 46) {
evt.preventDefault();
} else {
return true;
}
}
</script>