/home/banprang/domains/plai.go.th/public_html/coremain/module/question/question_title.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
<?php
import_request_variables
('pG''p_');
$sel_q "select * from cms_question where id_question = '$p_question_id'";
$que_q mysql_query($sel_q);
$obj_q mysql_fetch_assoc($que_q);

$navig['question&id_sub='.$p_id_sub] = $p_sub_name;
$navig['question_title'] = 'เพิ่มหัวข้อ';
navigator($navig);
echo
"<br>";
bar_header($p_sub_name); // Bar_Header
fieldset_top($obj_q['topic']);

$select "select * from cms_question_type";
$query mysql_query($select);
while(
$object mysql_fetch_array($query)){
  
$question_type[$object['type_id']] = $object['type_name'];
}
//debuga($_POST);

?>
<table width="97%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td>
      <center>
        <FORM NAME='formupdate' METHOD=POST ACTION='index.php?mod=question_choice&path=question' onSubmit='return check()'>
          <input type="hidden" name="id_sub" value="<?php echo $p_id_sub?>" />
          <input type="hidden" name="sub_name" value="<?php echo $p_sub_name?>" />
          <input type="hidden" name="question_id" value="<?php echo $p_question_id?>" />
          <table width='98%' border='0' cellpadding='0' cellspacing='1' bgcolor='#eff3f7' id="tb_title">
            <tr>
              <td width='25%' height='30' bgcolor='ffffff'>&nbsp;<img src='coremain/images/bullet2.gif'>&nbsp;หัวข้อ</td>
              <td width='75%' height='30' bgcolor='ffffff'><INPUT TYPE='text' NAME='title' size='50' value=''></td>
            </tr>
            <tr>
              <td height='30' bgcolor='ffffff'>&nbsp;<img src="coremain/images/marker.gif"> ประเภทแบบสำรวจ</td>
              <td height='30' bgcolor='ffffff'>
                <select name="question_type">
                  <option value="">- เลือกประเภท -</option>
                <?php foreach($question_type as $type_id => $type_name){ ?>
                  <option value="<?= $type_id ?>"><?= $type_name ?></option>
                <?php ?>
                </select>
              </td>
            </tr>
            
            <tr id="choice_select" style="display: none;">
              <td height='30' bgcolor='ffffff'>&nbsp;<img src="coremain/images/marker.gif"> จำนวนตัวเลือก</td>
              <td><input type="text" name="choice_number" /> ( ตัวเลข ) <button type="button" id="choice_cal" class="ui-corner-all">เพิ่มตัวเลือก</button></td>
            </tr>
          </table>
          
          <table width="100%" id="bt_question_title" style="display: none;">
            <tr>
              <td>
                <?php button_text('เพิ่มหัวข้อ''Submit'2); ?>
              </td>
            </tr>
          </table>
        </FORM>
      </center>
    </td>
  </tr>
</table>

<script language="javascript">
  
  $('input[name="title"]').focus();
  
  $('select[name="question_type"]').on('change', function(){
    var val = $(this).val();
    if(val == '2'){
      $('#choice_select').css('display', '');
      $('#bt_question_title').css('display', 'none');
    }else{
      $('input[name="choice_number"]').val('');
      $('.tr_choice').remove();
      $('#choice_select').css('display', 'none');
      $('#bt_question_title').css('display', '');
    }
  });
  $('input[name="choice_number"]').on('keyup', function(){
    if(isNaN($('input[name="choice_number"]').val())){
      alert('กรุณากรอกตัวเลขเท่านั้น !');
      $(this).select();
      $('#choice_cal').attr('disabled', true);
    }else{
      $('#choice_cal').attr('disabled', false);
    }
  });
  
  $('#choice_cal').on('click', function(){
    $('.tr_choice').remove();
      
    var n = Number($('input[name="choice_number"]').val());
    var tr = '';
    for(var i = 1; i <= n; i++){
      tr += '<tr class="tr_choice"><td height="30" bgcolor="ffffff" align="right">&nbsp;<img src="coremain/images/marker.gif"> ตัวเลือก '+ i +' :&nbsp;</td><td bgcolor="ffffff"><input type="text" class="choice_no" name="choice_no_'+ i +'" /></td></tr>';
    }
    $('#tb_title').append(tr);
    $('#bt_question_title').css('display', '');
  });
  
  function check() {
    if($('button[name="Submit"]:visible').length == 1){
      if(document.formupdate.title.value=="") {
        alert("กรุณากรอกหัวข้อ !") ;
        document.formupdate.title.focus() ;
        return false ;
      }else if(document.formupdate.question_type.value=='2'){
        var chk_text = true;
        $.each($('.choice_no'), function(){
          chk_text &= $(this).val() == '' ? false : true;
        });
        if(!chk_text){
          alert('กรุณากรอกตัวเลือกให้ครบทุกช่อง !');
          return false;
        }
      }else if(document.formupdate.question_type.value == '5'){
        $('form[name="formupdate"]').attr('action', 'index.php?mod=question_output&path=question');
        return true;
      }else{
        return true ;
      }
    }else{
      return false;
    }
  }
  
</script>