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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
<?php import_request_variables('pG', 'p_'); $sel_q = "select * from cms_question where id_sub = '$p_id_sub'"; $que_q = mysql_query($sel_q); $obj_q = mysql_fetch_assoc($que_q); $qid = $obj_q['id_question'];
$navig['question'] = $data_name_menu_sub['name']; $navig['question_edit'] = 'แก้ไขแบบสำรวจ'; navigator($navig); echo"<br>"; bar_header('แก้ไขแบบสำรวจ'); // Bar_Header fieldset_top($obj_q['topic']);
# เพิ่มหัวข้อ if($p_title_new != ''){ $sel_oth = "select * from cms_question_title where title_parent = '$p_parent' and title_other = 1"; $que_oth = mysql_query($sel_oth); $num_oth = mysql_num_rows($que_oth); if($num_oth == 1){ $del_oth = "delete from cms_question_title where title_parent = '$p_parent' and title_other = '1'"; mysql_query($del_oth); } $_data = select_max_query0('title_id', 'cms_question_title'); $data_id = $_data[0] == '' ? 1 : $_data[0]; $ins_new = "insert into cms_question_title values ('$data_id', '$p_title_new', '$p_parent', '$p_order_new', '$qid', '0', '0', '1', '1')"; mysql_query($ins_new); if($num_oth == 1){ $oth_id = $data_id + 1; $oth_order = $p_order_new + 1; $ins_other = "insert into cms_question_title values ('$oth_id', 'อื่นๆ', '$p_parent', '$oth_order', '$qid', '0', '1', '1', '1')"; mysql_query($ins_other); } refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); } # แก้ไขหัวข้อ if($p_title != ''){ $upd_title = "update cms_question_title set title_name = '$p_title' where title_id = '$p_title_id'"; mysql_query($upd_title); } # ลบหัวข้อ if($p_title_del != ''){ $get_order = "select title_order from cms_question_title where title_id = '$p_title_id'"; $que_order = mysql_query($get_order); $obj_order = mysql_fetch_assoc($que_order); $curr_order = $obj_order['title_order']; $del_title = "delete from cms_question_title where title_id = '$p_title_id'"; mysql_query($del_title); $sel_curr = "select * from cms_question_title where title_parent = '$p_parent' and title_order >= '$curr_order'"; $que_curr = mysql_query($sel_curr); while($obj_curr = mysql_fetch_assoc($que_curr)){ mysql_query("update cms_question_title set title_order = (title_order - 1) where title_id = '$obj_curr[title_id]'"); } refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); } # สถานะรายการที่จำเป็นต้องตรวจสอบก่อนส่งแบบสอบถาม if($p_validate != ''){ $upd_validate = "update cms_question_title set title_validate = '$p_validate' where title_id = '$p_title_id'"; mysql_query($upd_validate); refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); }
# มี/ไม่มีรายการอื่นๆ if($p_add_other != ''){ if($p_add_other == '1'){ $_oth = select_max_query0('title_id', 'cms_question_title'); $oth_id = $_oth[0] == '' ? 1 : $_oth[0]; $_oth_order = select_max_query('title_order', 'cms_question_title', 'title_parent', $p_parent); $oth_order = $_oth_order[0] == '' ? 1 : $_oth_order[0]; $ins_other = "insert into cms_question_title values ('$oth_id', 'อื่นๆ', '$p_parent', '$oth_order', '$qid', '0', '1', '1', '1')"; mysql_query($ins_other); }else{ $del_oth = "delete from cms_question_title where title_parent = '$p_parent' and title_other = '1'"; mysql_query($del_oth); } refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); }
# เพิ่มตัวเลือก if($p_choice_new != ''){ $_choice = select_max_query0('choice_id', 'cms_question_choice'); $choice_id = $_choice[0] == '' ? 1 : $_choice[0]; $ins_new = "insert into cms_question_choice values ('$choice_id', '$p_choice_new', '$p_order_new', '$p_parent', '$qid', '1')"; mysql_query($ins_new); refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); } # แก้ไขตัวเลือก if($p_choice != ''){ $upd_choice = "update cms_question_choice set choice_name = '$p_choice' where choice_id = '$p_choice_id'"; mysql_query($upd_choice); } # ลบตัวเลือก if($p_choice_del != ''){ $get_order = "select choice_order from cms_question_choice where choice_id = '$p_choice_id'"; $que_order = mysql_query($get_order); $obj_order = mysql_fetch_assoc($que_order); $curr_order = $obj_order['choice_order']; $del_choice = "delete from cms_question_choice where choice_id = '$p_choice_id'"; mysql_query($del_choice); $sel_curr = "select * from cms_question_choice where title_id = '$p_parent' and choice_order >= '$curr_order'"; $que_curr = mysql_query($sel_curr); while($obj_curr = mysql_fetch_assoc($que_curr)){ mysql_query("update cms_question_choice set choice_order = (choice_order - 1) where choice_id = '$obj_curr[choice_id]'"); } refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); }
# เรียงลำดับ if($p_id_order != ''){ if($p_ch_id != ''){ // เรียงตัวเลือก $get_curr = "select choice_order from cms_question_choice where choice_id = '$p_ch_id'"; $que_curr = mysql_query($get_curr); $obj_curr = mysql_fetch_assoc($que_curr); $curr_order = $obj_curr['choice_order']; $new_order = $p_id_order == '1' ? $curr_order - 1 : $curr_order + 1;
$upd_other = "update cms_question_choice set choice_order = '$curr_order' where title_id = '$p_parent' and choice_order = '$new_order'"; mysql_query($upd_other); $upd_order_new = "update cms_question_choice set choice_order = '$new_order' where choice_id = '$p_ch_id'"; mysql_query($upd_order_new); refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); }else if($p_title_id != ''){ // เรียงหัวข้อ $get_curr = "select title_order from cms_question_title where title_id = '$p_title_id'"; $que_curr = mysql_query($get_curr); $obj_curr = mysql_fetch_assoc($que_curr); $curr_order = $obj_curr['title_order']; $new_order = $p_id_order == '1' ? $curr_order - 1 : $curr_order + 1;
$upd_other = "update cms_question_title set title_order = '$curr_order' where title_parent = '$p_parent' and title_order = '$new_order'"; mysql_query($upd_other); $upd_order_new = "update cms_question_title set title_order = '$new_order' where title_id = '$p_title_id'"; mysql_query($upd_order_new); refresh_data('index.php?mod=question_edit&path=question&id_sub='.$p_id_sub.'&parent='.$p_parent, 1); } }
# question_title $sel_title = "select * from cms_question_title where question_id = '$qid' and title_id = '$p_parent' and title_parent = '0' order by title_order"; $que_title = mysql_query($sel_title); $array_title = mysql_fetch_assoc($que_title);
if($array_title['type_id'] == '2'){ # question_choice $array_choice = array(); $sel_choice = "select * from cms_question_choice where question_id = '$qid' and title_id = '$p_parent' order by choice_order"; $que_choice = mysql_query($sel_choice); while($_choice = mysql_fetch_assoc($que_choice)){ $array_choice[$_choice['choice_order']] = $_choice; } }
# data_title $array_data = array(); $checked_other = ''; $sel_data = "select * from cms_question_title where question_id = '$qid' and title_parent = '$p_parent' order by title_order"; $que_data = mysql_query($sel_data); while($obj = mysql_fetch_assoc($que_data)){ if($obj['title_other'] == '1'){ $checked_other = 'checked="checked"'; }else{ $array_data[$obj['title_order']] = $obj; } } //debuga($array_data);
?> <table width="97%" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td> <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse;" id="tb_title"> <tr bgcolor="#f0e8d0"> <td width="100%"> <?php if($p_title_edit == 'edit' && $p_title_id == ''){ ?> <form NAME='fm_title_edit' METHOD=POST ACTION='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>' onSubmit='return check_title()' style="margin: 0;"> <input type="hidden" name="title_id" value="<?= $p_parent ?>" /> <input type="text" name="title" value="<?= $array_title['title_name'] ?>" size="40" /> <a href="javascript:void(0);" class="title_update"><img src='coremain/images/save.png' title='บันทึกข้อมูล' border='0'></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src='coremain/images/ban.png' title='ยกเลิก' border='0'></a> </form> <?php }else{ ?> <b><?= $array_title['title_name'] ?></b> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_edit=edit"><img src='coremain/images/edit.gif' title='แก้ไขข้อมูล' border='0'></a> <?php } ?> </td> </tr> <?php if(isset($array_data)){ foreach($array_data as $data_order => $data){ $num_data = count($array_data); ?> <tr class="row_data"> <td> <?php if($p_title_edit == 'edit' && $p_title_id == $data['title_id']){ ?> <form NAME='fm_title_edit' METHOD=POST ACTION='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>' onSubmit='return check_title()' style="margin: 0;"> <input type="hidden" name="title_id" value="<?= $data['title_id'] ?>" /> <?php if($array_title['type_id'] == '6'){ ?> <?php text_editor('200', '260', 'คำอธิบาย', 1, $data['title_name'], 'title'); ?> <tr> <td align="right"> <a href="javascript:void(0);" class="title_update"><img src='coremain/images/save.png' title='บันทึกข้อมูล' border='0'></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src='coremain/images/ban.png' title='ยกเลิก' border='0'></a> </td> </tr> <?php }else{ ?> <?= $data_order ?>)<input type="text" name="title" value="<?= $data['title_name'] ?>" size="40" /> <a href="javascript:void(0);" class="title_update"><img src='coremain/images/save.png' title='บันทึกข้อมูล' border='0'></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src='coremain/images/ban.png' title='ยกเลิก' border='0'></a> <?php } ?> </form> <?php }else{ ?> <?php if($array_title['type_id'] != '6'){ ?><?= $data_order ?>) <?php } ?><?= $data['title_name'] ?> <?php if($data['title_other'] == '0'){ ?> <div style="float: right;"> <?php if($array_title['type_id'] == '1'){ ?> <?php if($data['title_validate'] == '1'){ ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_id=<?= $data['title_id'] ?>&validate=0'><img src='coremain/images/true.gif' border='0' title='จำเป็นต้องกรอก'></a> <?php }else{ ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_id=<?= $data['title_id'] ?>&validate=1'><img src='coremain/images/false.gif' border='0' title='กรอกหรือไม่ก็ได้'></a> <?php } ?> <?php } ?> <?php if($data['title_order'] > 1){ # Up ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_id=<?= $data['title_id'] ?>&id_order=1'><img src='coremain/images/up.gif' border='0' title='เลื่อนขึ้น'></a> <?php }else{ ?> <?php } ?> <?php if($data['title_order'] < $num_data){# Down ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_id=<?= $data['title_id'] ?>&id_order=2'><img src='coremain/images/down.gif' border='0' title='เลื่อนลง'></a> <?php }else { ?> <?php } ?> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_edit=edit&title_id=<?= $data['title_id'] ?>"><img src='coremain/images/edit.gif' title='แก้ไขข้อมูล' border='0'></a> <a href="javascript:void(0)" class="del_data" id="<?= $data['title_id'] ?>"><img src='coremain/images/del1.gif' title='ลบข้อมูล' border='0'></a> </div> <?php } ?> <?php } ?> </td> </tr> <?php }} ?> </table> <?php if($array_title['type_id'] != '5' && $array_title['type_id'] != '6'){ ?> <table width="100%"> <tr> <td align="left"> <button type="button" id="add_data" class="ui-button ui-corner-all ui-state-focus" style="padding: 2px;"> <img src='coremain/images/bullet2.gif'> เพิ่มหัวข้อ</button> <?php if($array_title['type_id'] == '3' || $array_title['type_id'] == '4'){ ?> <input type="checkbox" name="add_other" <?= $checked_other ?> /> มีหัวข้ออื่นๆ <?php } ?> </td> </tr> </table> <?php } ?> </td> </tr> <?php if($array_title['type_id'] == '2'){ $num_choice = count($array_choice); ?> <tr> <td align="center"> <br/> <table width="80%" border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse;" id="tb_choice"> <tr bgcolor="#f0e8d0"><th align="left">แก้ไขตัวเลือก</th></tr> <?php foreach($array_choice as $order_choice => $choice){ ?> <tr class="row_choice"> <?php if($p_choice_edit == 'edit' && $p_ch_id == $choice['choice_id']){ ?> <td> <form NAME='fm_choice_edit' METHOD=POST ACTION='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>' onSubmit='return check_choice()' style="margin: 0;"> <input type="hidden" name="choice_id" value="<?= $choice['choice_id'] ?>" /> ตัวเลือก <?= $choice['choice_order'] ?> : <input type="text" name="choice" value="<?= $choice['choice_name'] ?>" size="20" /> <a href="javascript:void(0);" class="choice_update"><img src='coremain/images/save.png' title='บันทึกข้อมูล' border='0'></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src='coremain/images/ban.png' title='ยกเลิก' border='0'></a> </form> </td> <?php }else{ ?> <td> ตัวเลือก <?= $choice['choice_order'] ?> : <?= $choice['choice_name'] ?> <div style="float: right;"> <?php if($choice['choice_order'] > 1){ # Up ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&ch_id=<?= $choice['choice_id'] ?>&id_order=1'><img src='coremain/images/up.gif' border='0' title='เลื่อนขึ้น'></a> <?php }else{ ?> <?php } ?> <?php if($choice['choice_order'] < $num_choice){# Down ?> <a href='index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&ch_id=<?= $choice['choice_id'] ?>&id_order=2'><img src='coremain/images/down.gif' border='0' title='เลื่อนลง'></a> <?php }else { ?> <?php } ?> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&choice_edit=edit&ch_id=<?= $choice['choice_id'] ?>"><img src='coremain/images/edit.gif' title='แก้ไขข้อมูล' border='0'></a> <a href="javascript:void(0)" class="del_choice" id="<?= $choice['choice_id'] ?>"><img src='coremain/images/del1.gif' title='ลบข้อมูล' border='0'></a> </div> </td> <?php } ?> </tr> <?php } ?> </table> <table width="80%"> <tr> <td align="left"> <button type="button" id="add_choice" class="ui-button ui-corner-all ui-state-focus" style="padding: 2px;"> <img src='coremain/images/bullet2.gif'> เพิ่มตัวเลือก</button> </td> </tr> </table> </td> </tr> <?php } ?> </table>
<style> input{ background: #FFFFEE; } </style> <script language="javascript"> $('.topic_update').on('click', function(){ $('form[name="fm_topic_edit"]').submit(); }); function check_topic() { if(document.fm_question_edit.topic.value=="") { alert("กรุณากรอกชื่อแบบสำรวจ !") ; document.fm_question_edit.topic.focus() ; return false ; }else return true ; } $('.title_update').on('click', function(){ $('form[name="fm_title_edit"]').submit(); }); function check_title(){ if($('#fm_title_edit input[name="title"]').val()=='') { alert("กรุณากรอกหัวข้อ !") ; document.fm_title_edit.topic.focus() ; return false ; }else return true ; } $('.choice_update').on('click', function(){ $('form[name="fm_choice_edit"]').submit(); }); function check_choice(){ if(document.fm_choice_edit.choice.value == ''){ alert('กรุณากรอกตัวเลือก !'); document.fm_choice_edit.choice.focus(); return false; }else{ return true; } } function check_title_new(){ if(document.fm_title_add.title_new.value == ''){ alert('กรุณากรอกหัวข้อ !'); document.fm_title_add.title_new.focus(); return false; }else{ return true; } } $('#add_data').on('click', function(){ $('#add_data').css('display', 'none'); var row = $('#tb_title').find('tr.row_data').length; var n = Number(row) + 1; var tr = '<tr class="row_data"><td><form name="fm_title_add" method="post" action="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" onSubmit="return check_title_new()" style="margin: 0"><input type="hidden" name="title_other" /><input type="hidden" name="order_new" value="'+ n +'" /> '+ n +') <input type="text" name="title_new" size="40" /> <a href="javascript:void(0);" class="title_insert"><img src="coremain/images/save.png" title="บันทึกข้อมูล" border="0" /></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src="coremain/images/ban.png" title="ยกเลิก" border="0"></a></form></td></tr>'; $('#tb_title').append(tr); $('input[name="title_new"]').focus(); $('.title_insert').on('click', function(){ if($('input[name="add_other"]').is(':checked')){ document.fm_title_add.title_other.value = '1'; }else{ document.fm_title_add.title_other.value = '0'; } $('form[name="fm_title_add"]').submit(); }); }); $('input[name="add_other"]').on('click', function(){ if($(this).is(':checked')){ window.location.href = "index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&add_other=1"; }else{ window.location.href = "index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&add_other=0"; } }); $('.del_data').on('click', function(){ if(confirm("คุณต้องการลบหัวข้อนี้ ?")){ var id = $(this).attr('id'); window.location.href = "index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&title_del=delete&title_id="+id; } }); $('.del_choice').on('click', function(){ if(confirm("คุณต้องการลบตัวเลือกนี้ ?")){ var id = $(this).attr('id'); window.location.href = "index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>&choice_del=delete&choice_id="+id; } }); function check_choice_new(){ if(document.fm_choice_add.choice_new.value == ''){ alert('กรุณากรอกตัวเลือก !'); document.fm_choice_add.choice_new.focus(); return false; }else{ return true; } } $('#add_choice').on('click', function(){ $('#add_choice').css('display', 'none'); var row = $('#tb_choice').find('tr.row_choice').length; var n = Number(row) + 1; var tr = '<tr class="row_choice"><td><form name="fm_choice_add" method="post" action="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" onSubmit="return check_choice_new()" style="margin: 0"><input type="hidden" name="order_new" value="'+ n +'" /> ตัวเลือก '+ n +' : <input type="text" name="choice_new" size="40" /> <a href="javascript:void(0);" class="choice_insert"><img src="coremain/images/save.png" title="บันทึกข้อมูล" border="0" /></a> <a href="index.php?mod=question_edit&path=question&id_sub=<?= $p_id_sub ?>&parent=<?= $p_parent ?>" class="title_update"><img src="coremain/images/ban.png" title="ยกเลิก" border="0"></a></form></td></tr>'; $('#tb_choice').append(tr); $('input[name="choice_new"]').focus(); $('.choice_insert').on('click', function(){ $('form[name="fm_choice_add"]').submit(); }); }); </script>
|