/home/banprang/domains/plai.go.th/public_html/coremain/module/question/question_show.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
<?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&id_sub='.$p_id_sub] = $obj_q['topic'];
$navig['question_show'] = 'ผลสำรวจ';
navigator($navig);
echo
"<br>";
bar_header($obj_q['topic']); // Bar_Header
fieldset_top($obj_q['topic']);

# question_title
$array_title = array();
$sel_title "select * from cms_question_title where question_id = '$qid' and title_parent = '0' order by title_order";
$que_title mysql_query($sel_title);
while(
$obj mysql_fetch_assoc($que_title)){
  
$array_title[$obj['title_order']]['title'] = $obj;

  
# question_choice
  
$choice = array();
  
$sel_choice "select * from cms_question_choice where question_id = '$qid' and title_id = '$obj[title_id]' order by choice_order";
  
$que_choice mysql_query($sel_choice);
  while(
$_choice mysql_fetch_assoc($que_choice)){
    
$choice[$_choice['choice_order']] = $_choice;
  }
  
$array_title[$obj['title_order']]['choice'] = $choice;
}

# data_title
$sel_data "select * from cms_question_title where question_id = '$qid' and title_parent > '0' order by title_order";
$que_data mysql_query($sel_data);
while(
$obj mysql_fetch_assoc($que_data)){
  
$array_data[$obj['title_parent']][$obj['title_order']] = $obj;
}
$num_question count($array_title);

$array_header = array();
$sel_header "select * from cms_question_ansheader where question_id = '$qid'";
$que_header mysql_query($sel_header);
while(
$obj_header mysql_fetch_assoc($que_header)){
  
$array_header[$obj_header['header_id']] = $obj_header;
}
$array_answer = array();
$sel_answer "select * from cms_question_answer where question_id = '$qid'";
$que_answer mysql_query($sel_answer);
while(
$obj_answer mysql_fetch_assoc($que_answer)){
  if(
$obj_answer['type_id'] == '5'){
    
$array_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['header_id']] = $obj_answer;
  }else{
    
$array_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']] = $obj_answer;
  }
  
  if(
$obj_answer['type_id'] == '2'){
    
$answer $obj_answer['answer'];
    if(isset(
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer])){
      
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer] += 1;
    }else{
      
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer] = 1;
    }
  }else if(
$obj_answer['type_id'] == '3' || $obj_answer['type_id'] == '4'){
    
$_arr explode('::'$obj_answer['answer']);
    
$answer $_arr[0];
    if(isset(
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer])){
      
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer] += 1;
    }else{
      
$count_answer[$obj_answer['type_id']][$obj_answer['parent_id']][$obj_answer['title_id']][$answer] = 1;
    }
  }
}

$array_color = array(1=>'sky'2=>'pink'3=>'green'4=>'orange'5=>'teal'6=>'navy'7=>'red'8=>'purple'9=>'blue'0=>'yellow');
?>
<table width="97%" border="0" cellpadding="0" cellspacing="0" align="center">
<?php
  
foreach($array_title as $title_order => $title){
    
$t_id $title['title']['title_id'];
    
$type $title['title']['type_id'];
?>
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
      <?php if($type == '1'){ ?>
        <tr bgcolor="#f0e8d0">
          <td><?= $title['title']['title_name'?></td>
        </tr>
        <tr>
          <td style="text-indent: 20px;">จำนวนผู้ตอบแบบสอบถามทั้งหมด <?= count($array_header?> เสียง</td>
        </tr>
      <?php }else if($type == '2'){ ?>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
              <tr bgcolor="#f0e8d0">
                <td><?= $title['title']['title_name'?></td>
                <?php foreach($title['choice'] as $order_choice => $choice){ ?>
                <td width="10%" align="center"><?= $choice['choice_name'?></td>
                <?php ?>
              </tr>
            <?php
              
if(isset($array_data[$t_id])){
                foreach(
$array_data[$t_id] as $data_order => $data){
            
?>
              <tr>
                <td style="text-indent: 20px;"><?= $data_order ?><?= $data['title_name'?></td>
                <?php foreach($title['choice'] as $order_choice => $choice){ ?>
                  <td align="center"><?= $count_answer[$type][$t_id][$data['title_id']][$choice['choice_id']] ?></td>
                <?php ?>
              </tr>
            <?php }} ?>
            </table>
          </td>
        </tr>
      <?php }else if($type == '3' || $type == '4'){ ?>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
              <tr bgcolor="#f0e8d0">
                <td><?= $title['title']['title_name'?></td>
              </tr>
            <?php
              
if(isset($array_data[$t_id])){
                foreach(
$array_data[$t_id] as $data_order => $data){
                  
$n $data_order%10;
            
?>
              <tr>
                <td style="text-indent: 20px;">&bullet; <?= $data['title_name'?></td>
              </tr>
              <?php
                
if($count_answer[$type][$t_id][$t_id][$data['title_id']] > 0){
                  
$point $count_answer[$type][$t_id][$t_id][$data['title_id']];
                  
$point_pc = ($point array_sum($count_answer[$type][$t_id][$t_id])) * 100;
                  
$point_width $point_pc 2;
              
?>
              <tr>
                <td style="padding-left: 50px;">
                  <?php if($point >= 1){ ?>
                    <img src='coremain/module/question/img/<?= $array_color[$n?>.gif' width='<?= $point_width ?>' height='10'>
                    &nbsp;&nbsp;<?= $point ?>&nbsp;เสียง &nbsp;&nbsp;<?= number_format($point_pc2?>
                  <?php }else{ ?>
                    &nbsp;&nbsp;0&nbsp;เสียง &nbsp;&nbsp;0
                  <?php ?>
                  %
                </td>
              </tr>
              <?php ?>
            <?php }} ?>
            </table>
          </td>
        </tr>
      <?php }else if($type == '5'){ ?>
        <tr bgcolor="#f0e8d0">
          <td><?= $title['title']['title_name'?></td>
        </tr>
        <?php if(isset($array_answer[$type][$t_id])){ foreach($array_answer[$type][$t_id] as $text_remark){ ?>
        <tr>
          <td style="text-indent: 20px; word-wrap: break-word;">&bullet;&nbsp;<?= $text_remark['answer'?></td>
        </tr>
        <?php }} ?>
      <?php }else if($type == '6'){ ?>
        <tr bgcolor="#f0e8d0">
          <td><?= $title['title']['title_name'?></td>
        </tr>
        <?php
          
if(isset($array_data[$t_id])){
            foreach(
$array_data[$t_id] as $data_order => $data){
        
?>
          <tr>
            <td style="text-indent: 20px;"><?= $data['title_name'?></td>
          </tr>
        <?php }
          }
        
?>
      <?php ?>
      </table>
    </td>
  </tr>
<?php ?>
</table>

<?php if($_SESSION['admin_web']=="admin" || $_SESSION['per']=="ok"){ ?>
<center>
  <table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#eff3f7' style="padding: 15px;">
    <tr>
      <td align="center">&nbsp;<button type="button" onclick="window.location.href='index.php?mod=question_detail&path=question&id_sub=<?= $_SESSION['id_sub'?>&question=<?= $qid ?>'" class="ui-button ui-widget ui-corner-all ui-state-focus" style="padding: 5px 10px;">ผลสำรวจแบบละเอียด</button></td>
    </tr>
  </table>
</center>
<?php ?>