-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorialentry.php
More file actions
387 lines (377 loc) · 19.4 KB
/
tutorialentry.php
File metadata and controls
387 lines (377 loc) · 19.4 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<html>
<head>
</title>
<?php
if ($_COOKIE['username']=='') {
header("Location:index.php");
}
include './includefiles/header.php';
include './includefiles/nav_menu.php';
?>
<title>Tutorial</title>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<script>
var tutorial_key = "";
var Dbconnect = "includefiles/DBconnect.php";
function set_key(str)
{
debugger;
str.cells[0]
//var Cells = str.getElementsByTagName("td");
tutorial_key = str.cells[0].innerHTML;
$('#txt_sub_title').val(str.cells[2].innerHTML);
$('#txt_sub_title_name').val(str.cells[3].innerHTML);
$('#txt_content').val(str.cells[4].innerHTML);
$('#txt_example').val(str.cells[5].innerHTML);
$('#txt_example_detail').val(str.cells[6].innerHTML);
}
function validation(clas)
{
var f = true;
$('.' + clas).each(function ()
{
if ($(this).val() == "")
{
f = false;
$(this).focus();
return f;
}
});
return f;
}
function save_click()
{
var str = "";
var f = validation("required");
if (!f) {
return false;
}
if (tutorial_key != "") {
$.post(Dbconnect, {
title_code: $('#sel_tutorial_title').val(),
sub_title: $('#txt_sub_title').val(),
sub_title_name: $('#txt_sub_title_name').val(),
content: $('#txt_content').val(),
example: $('#txt_example').val(),
example_detail: $('#txt_example_detail').val(),
tbl: 'tutorial_tbl',
method: 'update',
tutorial_key: tutorial_key
}, function (response) {
alert(response);
$('.required').val("");
tutorial_key = "";
});
} else
{
// alert('inser');
$.post(Dbconnect, {
title_code: $('#sel_tutorial_title').val(),
sub_title: $('#txt_sub_title').val(),
sub_title_name: $('#txt_sub_title_name').val(),
content: $('#txt_content').val(),
example: $('#txt_example').val(),
example_detail: $('#txt_example_detail').val(),
tutorial_type: $('#tutorial_type').val(),
tbl: 'tutorial_tbl',
method: 'insert',
}, function (response) {
alert(response);
$('.required').val("");
});
}
return false;
}
function view(str_1)
{
str_query = "select tutorial_key as 'ID',tt.title_code as 'TITLE',sub_title as 'SUB TITLE',";
str_query += "sub_title_name,content as 'Content',example as 'Example',example_detail as 'Example Detail' from tutorial_tbl tt\n\
inner join tutorial_title_tbl ttt on tt.title_code=ttt.title_code \n\
inner join tutorial_type ty on ty.tutorial_code =ttt.tutorial_code";
if (str_1 != "") {
str_query += " where tt.title_code='" + str_1 + "'";
}
// alert(str_query);
$.post(Dbconnect, {
method: 'json',
query: str_query,
}, function (response) {
// alert(response);
$('#tbl').text('');
var mydata = eval(response);
var table = $.makeTable(mydata);
$(table).appendTo("#tbl");
});
return false;
}
$.makeTable = function (mydata) {
var table = $('<table class="table table-bordered table-hover table-condensed">');
var tblHeader = " <thead><tr>";
for (var k in mydata[0])
tblHeader += "<th>" + k + "</th>";
tblHeader += "</thead>";
$(tblHeader).appendTo(table);
$.each(mydata, function (index, value) {
var TableRow = "<tr onclick='set_key(this)' >";
$.each(value, function (key, val) {
TableRow += "<td >" + val + "</td>";
});
TableRow += "</tr>";
$(table).append(TableRow);
});
return ($(table));
};
function PageLoad()
{
alert('s');
}
function save_title()
{
var f = validation("tuttitle");
if (!f)
return false;
$.post(Dbconnect, {
tutorial_code: $('#sel_tutorial_type').val(),
title_code: $('#sel_tutorial_type').val() + "-" + $('#txt_title_code').val(),
title: $('#txt_title').val(),
title_name: $('#txt_title_name').val(),
method: 'insert',
tbl: 'tutorial_title_tbl',
}, function (response) {
alert(response);
$('.tuttitle').val("");
});
}
function save_tut()
{
var f = validation("tuttype");
if (!f)
return false;
$.post(Dbconnect, {
tutorial_code: $('#txt_tutorial_code').val(),
tutorial_name: $('#txt_tutorial_name').val(),
method: 'insert',
tbl: 'tutorial_type',
}, function (response) {
alert(response);
$('.tuttype').val("");
});
loaddropdown('tutorial_code', 'tutorial_name', 'tutorial_type', 'sel_tutorial_type');
loaddropdown('tutorial_code', 'tutorial_name', 'tutorial_type', 'sel_tutorial_type_2');
return false;
}
function execute_query()
{
$.post(Dbconnect, {
method: 'query',
query: $('#txt_query').val(),
}, function (response) {
alert(response);
});
}
</script>
</head>
<body style="color:white;"> <br><br>
<form class="form-horizontal" >
<div class="container-fluid">
<div class="row">
<div class="container" style='padding:10px' >
<b>Tutorial Entry</b>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-6 shadow">
<fieldset>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-5">
<select id="sel_tutorial_type_2" class="form-control">
<option value="">CHOOSE OPTION</option>
</select>
</div>
<div class="col-md-5">
<select id="sel_tutorial_title" onchange="return view(this.value);" class="form-control required">
<option value="">CHOOSE OPTION</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="name">Sub Title</label>
<div class="col-md-10">
<input id="txt_sub_title" type="text" placeholder="Enter SubTitle" class="form-control input-md required" >
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label" for="email">Sub Title name</label>
<div class="col-md-10">
<input id="txt_sub_title_name" type="text" placeholder="Enter SubTitle" class="form-control input-md required" >
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="street">Content</label>
<div class="col-md-10">
<textarea style="height: 15%;" id="txt_content" type="text" class="form-control input-md required" >
</textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="street">Example</label>
<div class="col-md-10">
<textarea style="height: 20%;" id="txt_example" type="text" class="form-control input-md required" >
</textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="street">Example Details</label>
<div class="col-md-10">
<textarea style="height: 10%;" id="txt_example_detail" type="text" class="form-control input-md required" >
</textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-10 control-label" for=""></label>
<div class="col-md-2">
<button onclick="return save_click()" class="btn btn-success">Save</button>
</div>
</div>
</fieldset>
</div>
<div class="col-md-1"></div>
<div class="col-md-5 shadow" >
<div data- style="height:79%;overflow:auto; ">
<div class="container">
<div class="panel panel-default trans">
<div class="panel-heading">
<div class="form-inline" style="float:left">
<button onclick="return showpop_cat();" class="btn btn-sm btn-danger">New </button>
</div>
click any row to edit
</div>
<div class="" id="tbl">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="modal_cat" class="modal fade ">
<div class="modal-dialog" style="width:80%;">
<div class="modal-content ">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<i class="glyphicon glyphicon-picture">
</i>
Create tutorial and title
</div>
<div class="modal-body" >
<div class="row">
<div class="container-fluid">
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label" for="street">Tutorial code</label>
<div class="col-md-8">
<input id="txt_tutorial_code" type="text" class="form-control input-md tuttype" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="street">Tutorial name</label>
<div class="col-md-8">
<input id="txt_tutorial_name" type="text" class="form-control input-md tuttype" >
</div>
</div>
<div class="form-group">
<div class="col-md-8"></div>
<button type="button" onclick="return save_tut();" class="btn btn-success" >save</button>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea id="txt_query" style="height:20%;overflow:auto; " type="text" class="form-control input-md tuttype" >
</textarea>
</div>
</div>
<button type="button" onclick="return execute_query();" class="btn btn-danger" >execute</button>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label" for="street">choose tutorial</label>
<div class="col-md-8">
<select id="sel_tutorial_type" class="form-control tuttitle">
<option value="">choose tutorial</option>
</select></div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="street">Title code</label>
<div class="col-md-8">
<input id="txt_title_code" type="text" class="form-control input-md tuttitle" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="street">Title</label>
<div class="col-md-8">
<input id="txt_title" type="text" class="form-control input-md tuttitle" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="street">Title name</label>
<div class="col-md-8">
<input id="txt_title_name" type="text" class="form-control input-md tuttitle" >
</div>
</div>
<div class="form-group">
<div class="col-md-8"></div>
<button type="button" onclick="return save_title()" class="btn btn-success" >save</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>-->
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function showpop_cat() {
$("#modal_cat").modal('show');
return false;
}
$(document).ready(function ()
{
loaddropdown('tutorial_code', 'tutorial_name', 'tutorial_type', 'sel_tutorial_type');
loaddropdown('tutorial_code', 'tutorial_name', 'tutorial_type', 'sel_tutorial_type_2');
});
$('#sel_tutorial_type_2').change(function ()
{
var tbl = "tutorial_title_tbl where tutorial_code='" + $('#sel_tutorial_type_2').val() + "'";
loaddropdown('title_code', 'title', tbl, 'sel_tutorial_title');
});
function loaddropdown(dropkey, dropvalue, tbl_condition, controlid)
{
var options = "";
str_query = "select " + dropkey + "," + dropvalue + " from " + tbl_condition;
$.post(Dbconnect, {
method: 'json',
query: str_query,
}, function (response) {
var resdata = JSON.parse(response);
for (var i = 0; i < resdata.length; i++) {
//alert(resdata[i]["cal_date"]);
var key = resdata[i][dropkey];
var value = resdata[i][dropvalue];
options += "<option value='" + key + "'>" + value + "</option>";
}
$('#' + controlid).html("<option value=''>CHOOSE OPTION</option>" + options);
});
}
</script>
</body>
</html>