Path : /var/www/html/main/ap/questionnaire/
File Upload :
Current File : /var/www/html/main/ap/questionnaire/index.php

<?php
if($_GET['nu']!="products"){
  include('../../head2.php');
  $sql = "select * from ap_products where code='$_GET[xcode]'";
  $query = mysqli_query($conn,$sql);
  $num_rows = mysqli_num_rows($query);
  $rows = mysqli_fetch_array($query);
  
  $questionnaire_name = $rows['name'];
  $line_notify_questionnaire = $rows['linenotify'];
}else{
  include('../../head.php');
}
?>
<div class="container theme-showcase body-main-row-body" role="main">
<?php
if($_GET['nu']==""){
  if($num_rows<1){
  ?>
    <br>
    <center><a href="<?php echo $ap_site.$ap_folder;?>"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></a><br><?php echo $title;?></center>
  <?php
  }else{
    $days = date(Ymd);
    if($days>=$rows['date_start'] && $days<=$rows['date_expire']){
    ?>
      <p><p>
      <div class="breadcrumbx">
      <?php //include('../../translate.php'); ?>
      <p align="center"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></p>
      <h3 align="center" style="display: none">แบบสอบถาม / Questionnaire</h3>
      <h4 align="center"><?php echo $questionnaire_name; ?></h4>
      <hr>
      <form id="f" name="f" action="ap/questionnaire/?nu=insert" method="post" enctype="multipart/form-data">
      <input type="hidden" name="code" value="<?php echo $rows[code]?>">
      <?php
      $sql = "select * from ap_questionnaire_part where code='$rows[code]' order by code_part asc";
      $query = mysqli_query($conn,$sql);
      while($rows = mysqli_fetch_array($query)){
        echo "<p><b>$rows[name]</b></p>";
        echo "<p>$rows[details]</p>";
        $sql_2 = "select * from ap_questionnaire_question where code='$rows[code]' and code_part='$rows[code_part]' order by code_question asc";
        $query_2 = mysqli_query($conn,$sql_2);
        $num_rows_2 = mysqli_num_rows($query_2);
        $i = 0;
        $i2 = 0;
        $i3 = 0;
        while($rows_2 = mysqli_fetch_array($query_2)){
          $i3++;
          $qid = $rows_2[id];
          if($rows_2['format']==1){
            $i++;
            echo "<p><b>$i. $rows_2[title]</b></p>";
            if(!empty($rows_2['choice_1'])){
              if(empty($rows_2['choice_1_status'])){
                echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"1\"> $rows_2[choice_1]</p>";
              }else{
                echo "<p><input class='form-control' type=\"text\" name=\"choice[$qid]\" value=\"\" placeholder='$rows_2[choice_1]' required></p>";
              }
            }
            if(!empty($rows_2['choice_2'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"2\"> $rows_2[choice_2]</p>";
            }
            if(!empty($rows_2['choice_3'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"3\"> $rows_2[choice_3]</p>";
            }
            if(!empty($rows_2['choice_4'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"4\"> $rows_2[choice_4]</p>";
            }
            if(!empty($rows_2['choice_5'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"5\"> $rows_2[choice_5]</p>";
            }
            if(!empty($rows_2['choice_6'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"6\"> $rows_2[choice_6]</p>";
            }
            if(!empty($rows_2['choice_7'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"7\"> $rows_2[choice_7]</p>";
            }if(!empty($rows_2['choice_8'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"8\"> $rows_2[choice_8]</p>";
            }if(!empty($rows_2['choice_9'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"9\"> $rows_2[choice_9]</p>";
            }if(!empty($rows_2['choice_10'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"10\"> $rows_2[choice_10]</p>";
            }if(!empty($rows_2['choice_11'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"11\"> $rows_2[choice_11]</p>";
            }if(!empty($rows_2['choice_12'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"12\"> $rows_2[choice_12]</p>";
            }if(!empty($rows_2['choice_13'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"13\"> $rows_2[choice_13]</p>";
            }if(!empty($rows_2['choice_14'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"14\"> $rows_2[choice_14]</p>";
            }if(!empty($rows_2['choice_15'])){
              echo "<p><input type=\"radio\" name=\"choice[$qid]\" value=\"15\"> $rows_2[choice_15]</p>";
            }
            echo "<hr>";
          }

          if($rows_2['format']==2){
            $i++;
            $i2++;
            if($i2==1){
            ?>
              <div class="table-responsive">
              <table class="table table-striped">
                <thead style="display: none">
                  <tr>
                    <?php /* ?><th width="70" rowspan="2">ข้อที่</th><?php */ ?>
                    <th rowspan="2">รายการ</th>
                    <th colspan="5"><center>ระดับความพึงพอใจ / Level</center></th>
                  </tr>
                  <tr>
                    <th>1</th>
                    <th>2</th>
                    <th>3</th>
                    <th>4</th>
                    <th>5</th>
                    <?php /* ?><th>1</th>
                    <th>2</th>
                    <th>3</th>
                    <th>4</th>
                    <th>5</th><?php */ ?>
                  </tr>
                </thead>
                <tbody>
            <?php
            }
            if($rows_2['title_status']==1){
              ?>
                <tr>
                  <?php /* ?><td bgcolor="#E59866"></td><?php */ ?>
                  <td class="slideanimx" bgcolor="#E59866" colspan="11"><b><?php echo $rows_2['title'];?></b></td>
                </tr>
            <?php
            }else{
              if(empty($rows_2['format_status'])){
                if($rows_2['title_status']==1){
                  $i2 = 0;
                }
              ?>
                <tr class="slideanimx">
                  <?php /* ?><td><?php echo ($i2-1);?>.</td><?php */ ?>
                  
                  <!-- <td><?php echo $rows_2['title'];?></td>
                  <td><input type="radio" name="level[<?php echo $qid?>]" value="1" aria-label="..."></td>
                  <td><input type="radio" name="level[<?php echo $qid?>]" value="2" aria-label="..."></td>
                  <td><input type="radio" name="level[<?php echo $qid?>]" value="3" aria-label="..."></td>
                  <td><input type="radio" name="level[<?php echo $qid?>]" value="4" aria-label="..."></td>
                  <td><input type="radio" name="level[<?php echo $qid?>]" value="5" aria-label="..."></td> -->

                  <td>
                    <?php echo $rows_2['title'];?>
                    <hr style="margin: 5px">
                    <div><p><strong>ระดับความพึงพอใจ / Level</strong> 1 <input type="radio" name="level[<?php echo $qid?>]" value="1" aria-label="..."> 
                    2 <input type="radio" name="level[<?php echo $qid?>]" value="2" aria-label="..."> 
                    3 <input type="radio" name="level[<?php echo $qid?>]" value="3" aria-label="..."> 
                    4 <input type="radio" name="level[<?php echo $qid?>]" value="4" aria-label="..."> 
                    5 <input type="radio" name="level[<?php echo $qid?>]" value="5" aria-label="..."></p></div>
                  </td>

                  <?php /* ?><td><input type="radio" name="need[<?php echo $qid?>]" value="1"<?php if($rows_answer[need]==1){ echo " selected checked"; }?> aria-label="..."></td>
                  <td><input type="radio" name="need[<?php echo $qid?>]" value="2"<?php if($rows_answer[need]==2){ echo " selected checked"; }?> aria-label="..."></td>
                  <td><input type="radio" name="need[<?php echo $qid?>]" value="3"<?php if($rows_answer[need]==3){ echo " selected checked"; }?> aria-label="..."></td>
                  <td><input type="radio" name="need[<?php echo $qid?>]" value="4"<?php if($rows_answer[need]==4){ echo " selected checked"; }?> aria-label="..."></td>
                  <td><input type="radio" name="need[<?php echo $qid?>]" value="5"<?php if($rows_answer[need]==5){ echo " selected checked"; }?> aria-label="..."></td><?php */ ?>
                </tr>
              <?php
              }else{
                $i2 = 0;
                echo "<tr><td colspan=\"12\"><lable><b>$rows_2[title]</b></label>";
                echo "<textarea style='width:100%;height:50px' name=\"open_ended[$qid]\"></textarea></td></tr>";
              }
            }
            if($i==$num_rows_2){
            ?>
                </tbody>
              </table>
              </div>
              <hr>
            <?php
            }
          }
          if($rows_2['format']==3){
            $i++;
            echo "<p></p><lable><b>$rows_2[title]</b></label>";
            echo "<textarea style='width:100%;height:150px' name=\"open_ended[$qid]\"></textarea><p></p>";
          }
        }
      }
      ?>
      <p align="center"><input class="btn btn-danger" type="submit" value="ส่งแบบสอบถาม / Send" onclick="return confirm('ท่านตอบแบบสอบถามทุกข้อแล้วใช่หรือไม่?');">
      </form>
      </div>
    <?php
    }else{
    ?> 
      <p align="center"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></p>
      <h3 align="center">แบบสอบถาม / Questionnaire</h3>
      <h4 align="center"><?php echo $questionnaire_name; ?> ปิด!!!</h4>
    <?php
    }
  }
}

if($_GET['nu']=="insert"){
  $date_time = date(YmdHis);
  echo "<div class=\"content\">";
  $sql = "select * from ap_questionnaire_part where code='$_POST[code]' order by code_part asc";
  $query = mysqli_query($conn,$sql);
  while($rows = mysqli_fetch_array($query)){
    $sql_2 = "select * from ap_questionnaire_question where code='$rows[code]'
     and code_part='$rows[code_part]' order by code_question asc";
    $query_2 = mysqli_query($conn,$sql_2);
    while($rows_2 = mysqli_fetch_array($query_2)){
      $xsql = "insert into ap_questionnaire_answer set code_answer='$date_time', code='$_POST[code]',";
      $a = 1;
      if (@trim($_POST["choice"]["$rows_2[id]"])!="") {
          $xsql .= "code_question='".addslashes($rows_2["id"])."' ,choice='".addslashes($_POST["choice"]["$rows_2[id]"])."'";
      } elseif (@trim($_POST["level"]["$rows_2[id]"])!="") {
          $xsql .= "code_question='".addslashes($rows_2["id"])."' ,level='".addslashes($_POST["level"]["$rows_2[id]"])."',need='".addslashes($_POST["need"]["$rows_2[id]"])."'";
      } elseif (@trim($_POST["open_ended"]["$rows_2[id]"])!="") {
          $xsql .= "code_question='".addslashes($rows_2["id"])."' ,open_ended='".addslashes($_POST["open_ended"]["$rows_2[id]"])."'";
      } else {
          $xsql .= "code_question='0'";
          $a = 0;
      }
      if($a>0){
        $xsql = rtrim($xsql,","); /*echo $xsql."<br>";*/
      }
      mysqli_query($conn,"$xsql");
      echo mysql_error();
    }
  }
  echo "<br><CENTER><B>กรุณารอสักครู่</B></CENTER><br>";
  echo "<meta http-equiv='refresh' content='1;URL=$ap_site$ap_folder"."ap/questionnaire/?nu=success&xcode=$_POST[code]'>";
  echo "</div>";
}

if($_GET['nu']=="success"){
  $sql = "select * from ap_questionnaire_answer where code='$_GET[xcode]' group by code_answer";
  $query = mysqli_query($conn,$sql);
  $num_rows = mysqli_num_rows($query);
?>
  <p><p>
  <div class="breadcrumbx">
  <center><a href="<?php echo $ap_site.$ap_folder;?>"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></a><br><?php echo $title;?></center>
  <h1 align="center">ขอบคุณครับ >> <a href="<?php echo $ap_site.$ap_folder;?>ap/questionnaire/?nu=result&xcode=<?php echo $_GET[xcode]?>">สรุปผลความพึงพอใจ</a></h1>
  </div>
  <?php
  $message = array(
   'message' => "ผู้ตอบแบบสอบถาม $questionnaire_name จำนวน $num_rows ชุด --> $ap_site$ap_folder"."ap/questionnaire/?nu=result&xcode=$_GET[xcode]",
   'imageThumbnail' => '',
   'imageFullsize' => '',
   'stickerPackageId' => '',
   'stickerId' => ''
  );

  $token = "tn4tthSdCi521nNZg0ahWFZZtEHUJW7UoD2Qa7X6K2Q"; /* Anucha Puangpaka */
  /*line_notify($message, $token, $rows_line['id']);*/
  /*$line_notify = $token;*/
  if(!empty($line_notify_questionnaire)){
    if($last != $line_notify_questionnaire){
      line_notify_questionnaire($message, $line_notify_questionnaire);
    }
    $last = $line_notify_questionnaire;
  }
}

if($_GET['nu']=="result"){
  if($num_rows<1){
  ?>
    <br>
    <center><a href="<?php echo $ap_site.$ap_folder;?>"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></a><br><?php echo $title;?></center>
  <?php
  }else{
    $sqla = "select * from ap_questionnaire_answer where code='$_GET[xcode]' group by code_answer";
    $querya = mysqli_query($conn,$sqla);
    $num_rowsa = mysqli_num_rows($querya);
    ?>
    <p><p>
    <div class="breadcrumbx">
      <?php //include('../../translate.php'); ?>
      <center>
        <a href="<?php echo $ap_site.$ap_folder;?>"><img style="width: 100px;" src="<?php echo $logo;?>" alt="<?php echo $title;?>"></a><br>
        <h3>สรุปผล</h3>
        <h4><?php echo $questionnaire_name; ?></h4>
        <h4><?php echo "วันที่-เวลา ".date('Y-m-d H:i:s')." แบบสอบถามจำนวน ".$num_rowsa?> ชุด</h4>
      </center>
      <div class="table-responsive">
      <table class="table table-striped">
      <?php
      $sql = "select * from ap_questionnaire_part where code='$rows[code]' order by code_part asc";
      $query = mysqli_query($conn,$sql);
      while($rows = mysqli_fetch_array($query)){
        echo "<tr><td bgcolor='#cccccc' colspan='3'><strong>$rows[name]</strong></td></tr>";
        echo "<tr><td colspan='3'>$rows[details]</td></tr>";
        $sql_2 = "select * from ap_questionnaire_question where code='$rows[code]' and code_part='$rows[code_part]' order by code_question asc";
        $query_2 = mysqli_query($conn,$sql_2);
        $num_rows_2 = mysqli_num_rows($query_2);
        $i = 0;
        $i2 = 0;
        $i3 = 0;
        while($rows_2 = mysqli_fetch_array($query_2)){
          $i3++;

          $sql_answer = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='1'";
          $query_answer = mysqli_query($conn,$sql_answer);
          $num_rows_answer = mysqli_num_rows($query_answer);
          $sql_answer2 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='2'";
          $query_answer2 = mysqli_query($conn,$sql_answer2);
          $num_rows_answer2 = mysqli_num_rows($query_answer2);
          $sql_answer3 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='3'";
          $query_answer3 = mysqli_query($conn,$sql_answer3);
          $num_rows_answer3 = mysqli_num_rows($query_answer3);
          $sql_answer4 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='4'";
          $query_answer4 = mysqli_query($conn,$sql_answer4);
          $num_rows_answer4 = mysqli_num_rows($query_answer4);
          $sql_answer5 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='5'";
          $query_answer5 = mysqli_query($conn,$sql_answer5);
          $num_rows_answer5 = mysqli_num_rows($query_answer5);
          $sql_answer6 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='6'";
          $query_answer6 = mysqli_query($conn,$sql_answer6);
          $num_rows_answer6 = mysqli_num_rows($query_answer6);
          $sql_answer7 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='7'";
          $query_answer7 = mysqli_query($conn,$sql_answer7);
          $num_rows_answer7 = mysqli_num_rows($query_answer7);
          $sql_answer8 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='8'";
          $query_answer8 = mysqli_query($conn,$sql_answer8);
          $num_rows_answer8 = mysqli_num_rows($query_answer8);
          $sql_answer9 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='9'";
          $query_answer9 = mysqli_query($conn,$sql_answer9);
          $num_rows_answer9 = mysqli_num_rows($query_answer9);
          $sql_answer10 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='10'";
          $query_answer10 = mysqli_query($conn,$sql_answer10);
          $num_rows_answer10 = mysqli_num_rows($query_answer10);
          $sql_answer11 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='11'";
          $query_answer11 = mysqli_query($conn,$sql_answer11);
          $num_rows_answer11 = mysqli_num_rows($query_answer11);
          $sql_answer12 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='12'";
          $query_answer12 = mysqli_query($conn,$sql_answer12);
          $num_rows_answer12 = mysqli_num_rows($query_answer12);
          $sql_answer13 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='13'";
          $query_answer13 = mysqli_query($conn,$sql_answer13);
          $num_rows_answer13 = mysqli_num_rows($query_answer13);
          $sql_answer14 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='14'";
          $query_answer14 = mysqli_query($conn,$sql_answer14);
          $num_rows_answer14 = mysqli_num_rows($query_answer14);
          $sql_answer15 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='15'";
          $query_answer15 = mysqli_query($conn,$sql_answer15);
          $num_rows_answer15 = mysqli_num_rows($query_answer15);

          $sql_answer_2 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and level='1'";
      	  $query_answer_2 = mysqli_query($conn,$sql_answer_2);
      	  $num_rows_answer_2 = mysqli_num_rows($query_answer_2);
      		$sql_answer_2_2 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and level='2'";
      		$query_answer_2_2 = mysqli_query($conn,$sql_answer_2_2);
      		$num_rows_answer_2_2 = mysqli_num_rows($query_answer_2_2);
      		$sql_answer_2_3 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and level='3'";
      		$query_answer_2_3 = mysqli_query($conn,$sql_answer_2_3);
      		$num_rows_answer_2_3 = mysqli_num_rows($query_answer_2_3);
      		$sql_answer_2_4 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and level='4'";
      		$query_answer_2_4 = mysqli_query($conn,$sql_answer_2_4);
      		$num_rows_answer_2_4 = mysqli_num_rows($query_answer_2_4);
      		$sql_answer_2_5 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and level='5'";
      		$query_answer_2_5 = mysqli_query($conn,$sql_answer_2_5);
      		$num_rows_answer_2_5 = mysqli_num_rows($query_answer_2_5);

      		$sql_answer_21 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and need='1'";
      	  	$query_answer_21 = mysqli_query($conn,$sql_answer_21);
      	  	$num_rows_answer_21 = mysqli_num_rows($query_answer_21);
      		$sql_answer_21_2 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and need='2'";
      		$query_answer_21_2 = mysqli_query($conn,$sql_answer_21_2);
      		$num_rows_answer_21_2 = mysqli_num_rows($query_answer_21_2);
      		$sql_answer_21_3 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and need='3'";
      		$query_answer_21_3 = mysqli_query($conn,$sql_answer_21_3);
      		$num_rows_answer_21_3 = mysqli_num_rows($query_answer_21_3);
      		$sql_answer_21_4 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and need='4'";
      		$query_answer_21_4 = mysqli_query($conn,$sql_answer_21_4);
      		$num_rows_answer_21_4 = mysqli_num_rows($query_answer_21_4);
      		$sql_answer_21_5 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and need='5'";
      		$query_answer_21_5 = mysqli_query($conn,$sql_answer_21_5);
      		$num_rows_answer_21_5 = mysqli_num_rows($query_answer_21_5);

          $qid = $rows_2[id];
          if($rows_2['format']==1){
            $i++;
            echo "<tr><td bgcolor='#E59866'><b>$i. $rows_2[title]</b></td><td bgcolor='#E59866'><b>จำนวน</b></td><td bgcolor='#E59866'><b>ค่าร้อยละ</b></td></tr>";
            if(!empty($rows_2[choice_1])){
              if(empty($rows_2['choice_1_status'])){
                echo "<tr><td>$rows_2[choice_1]</td><td>$num_rows_answer</td><td>".number_format(($num_rows_answer*100)/$num_rowsa,2)."%</td></tr>";
              }else{
                $sql_answer1 = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') group by choice asc";
                $query_answer1 = mysqli_query($conn,$sql_answer1);
                $num_rows_answer1 = mysqli_num_rows($query_answer1);
                while($rows_answer1 = mysqli_fetch_array($query_answer1)){
                  $sql_answer1a = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and choice='$rows_answer1[choice]'";
                  $query_answer1a = mysqli_query($conn,$sql_answer1a);
                  $num_rows_answer1a = mysqli_num_rows($query_answer1a);
                  echo "<tr><td>$rows_answer1[choice]</td><td>$num_rows_answer1a</td><td>".number_format(($num_rows_answer1a*100)/$num_rows_answer1,2)."%</td></tr>";
                }
              }
            }
            if(!empty($rows_2[choice_2])){
              echo "<tr><td>$rows_2[choice_2]</td><td>$num_rows_answer2</td><td>".number_format(($num_rows_answer2*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_3])){
              echo "<tr><td>$rows_2[choice_3]</td><td>$num_rows_answer3</td><td>".number_format(($num_rows_answer3*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_4])){
              echo "<tr><td>$rows_2[choice_4]</td><td>$num_rows_answer4</td><td>".number_format(($num_rows_answer4*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_5])){
              echo "<tr><td>$rows_2[choice_5]</td><td>$num_rows_answer5</td><td>".number_format(($num_rows_answer5*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_6])){
              echo "<tr><td>$rows_2[choice_6]</td><td>$num_rows_answer6</td><td>".number_format(($num_rows_answer6*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_7])){
              echo "<tr><td>$rows_2[choice_7]</td><td>$num_rows_answer7</td><td>".number_format(($num_rows_answer7*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_8])){
              echo "<tr><td>$rows_2[choice_8]</td><td>$num_rows_answer8</td><td>".number_format(($num_rows_answer8*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_9])){
              echo "<tr><td>$rows_2[choice_9]</td><td>$num_rows_answer9</td><td>".number_format(($num_rows_answer9*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_10])){
              echo "<tr><td>$rows_2[choice_10]</td><td>$num_rows_answer10</td><td>".number_format(($num_rows_answer10*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_11])){
              echo "<tr><td>$rows_2[choice_11]</td><td>$num_rows_answer11</td><td>".number_format(($num_rows_answer11*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_12])){
              echo "<tr><td>$rows_2[choice_12]</td><td>$num_rows_answer12</td><td>".number_format(($num_rows_answer12*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_13])){
              echo "<tr><td>$rows_2[choice_13]</td><td>$num_rows_answer13</td><td>".number_format(($num_rows_answer13*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_14])){
              echo "<tr><td>$rows_2[choice_14]</td><td>$num_rows_answer14</td><td>".number_format(($num_rows_answer14*100)/$num_rowsa,2)."%</td></tr>";
            }
            if(!empty($rows_2[choice_15])){
              echo "<tr><td>$rows_2[choice_15]</td><td>$num_rows_answer15</td><td>".number_format(($num_rows_answer15*100)/$num_rowsa,2)."%</td></tr>";
            }
          }

          if($rows_2['format']==2){
            $i++;
            $i2++;
            if($i2==1){
            ?>
              </table>
              </div>
              <div class="table-responsive">
              <table class="table table-striped">
                <thead>
                  <tr>
                    <?php /* ?><th width="70" rowspan="2">ข้อที่</th><?php */ ?>
                    <th rowspan="2">รายการ</th>
                    <th colspan="6"><center>ระดับความพึงพอใจ n=<?php echo $num_rowsa?></center></th>
                    <?php /* ?><th colspan="5"><center>ระดับความต้องการ</center></th><?php */ ?>
                  </tr>
                  <tr>
                    <th width="60">1</th>
                    <th width="60">2</th>
                    <th width="60">3</th>
                    <th width="60">4</th>
                    <th width="60">5</th>
                    <th width="100">Mean</th>
                    <th width="100">S.D.</th>
                    <th width="100" style="display: none">Percentage</th>
                    <?php /* ?><th>1</th>
                    <th>2</th>
                    <th>3</th>
                    <th>4</th>
                    <th>5</th><?php */ ?>
                  </tr>
                </thead>
                <tbody>
            <?php
            }
            
            if($rows_2['title_status']==1){
              //$i2 = 0;
              $x = 0;

              $sql_2x = "select * from ap_questionnaire_question where code='$rows[code]' and code_part='$rows[code_part]' and code_question like '$rows_2[code_question]%'";
              $query_2x = mysqli_query($conn,$sql_2x);
              $num_rows_2x = mysqli_num_rows($query_2x);
              $rows_2x = mysqli_fetch_array($query_2x);
              ?>
                <tr>
                  <?php /* ?><td bgcolor="#E59866"></td><?php */ ?>
                  <td bgcolor="#E59866" colspan="12"><strong><?php echo $rows_2['title'].' ('.($num_rows_2x-1).')'; ?></strong></td>
                </tr>
            <?php
            }else{
              if(empty($rows_2['format_status'])){
                if($rows_2['title_status']==1){
                  $i2 = 0;
                }

                $total = (($num_rows_answer_2*1)+($num_rows_answer_2_2*2)+($num_rows_answer_2_3*3)+($num_rows_answer_2_4*4)+($num_rows_answer_2_5*5))/$num_rowsa;
                
                $total_1 = (($num_rows_answer_2*1)+($num_rows_answer_2_2*2)+($num_rows_answer_2_3*3)+($num_rows_answer_2_4*4)+($num_rows_answer_2_5*5));

                $totalx += $total;
                $totalx_1 += $total_1;

                $x++;
                $code_question = substr($rows_2['code_question'],0,1);
                $sql_3 = "select * from ap_questionnaire_question where (code='$rows_2[code]' and code_part='$rows_2[code_part]') and code_question like '$code_question%' order by code_question asc";
                $query_3 = mysqli_query($conn,$sql_3);
                $num_rows_3 = mysqli_num_rows($query_3);

                $totalC1 += $num_rows_answer_2;
                $totalC2 += $num_rows_answer_2_2;
                $totalC3 += $num_rows_answer_2_3;
                $totalC4 += $num_rows_answer_2_4;
                $totalC5 += $num_rows_answer_2_5;
                ?>
                <tr>
                  <?php /* ?><td><?php echo ($i2-1);?></td><?php */ ?>
                  <td><?php echo $rows_2['title'];?></td>
                  <td><?php echo $num_rows_answer_2;?><hr><?php $c1 = number_format(($num_rows_answer_2*100)/$num_rowsa,2); echo $c1; ?>%</td>
                  <td><?php echo $num_rows_answer_2_2;?><hr><?php $c2 = number_format(($num_rows_answer_2_2*100)/$num_rowsa,2); echo $c2; ?>%</td>
                  <td><?php echo $num_rows_answer_2_3;?><hr><?php $c3 = number_format(($num_rows_answer_2_3*100)/$num_rowsa,2); echo $c3; ?>%</td>
                  <td><?php echo $num_rows_answer_2_4;?><hr><?php $c4 = number_format(($num_rows_answer_2_4*100)/$num_rowsa,2); echo $c4; ?>%</td>
                  <td><?php echo $num_rows_answer_2_5;?><hr><?php $c5 = number_format(($num_rows_answer_2_5*100)/$num_rowsa,2); echo $c5; ?>%</td>
                  <td><?php echo number_format($total,2);?></td>
                  <td></td>
                  <td style="display: none"><?php echo number_format($c1+$c2+$c3+$c4+$c5,2) /*number_format((($total*100)/5),2)*/; ?>%</td>
                </tr>
                <?php
                if($x==($num_rows_2x-1)){

                  $totalC = $totalC1+$totalC2+$totalC3+$totalC4+$totalC5;

                  /*$array_total = array($totalC1,$totalC2,$totalC3,$totalC4,$totalC5);
                  $average_total = array_sum($array_total)/count($array_total);*/
                  ?>
                  <tr class="warning">
                    <td><strong>รวม</strong></td>
                    <td><?php echo $totalC1; ?><hr><?php $c1x = number_format(($totalC1*100)/$totalC,2); echo $c1x; ?>%</td>
                    <td><?php echo $totalC2; ?><hr><?php $c2x = number_format(($totalC2*100)/$totalC,2); echo $c2x; ?>%</td>
                    <td><?php echo $totalC3; ?><hr><?php $c3x = number_format(($totalC3*100)/$totalC,2); echo $c3x; ?>%</td>
                    <td><?php echo $totalC4; ?><hr><?php $c4x = number_format(($totalC4*100)/$totalC,2); echo $c4x; ?>%</td>
                    <td><?php echo $totalC5; ?><hr><?php $c5x = number_format(($totalC5*100)/$totalC,2); echo $c5x; ?>%</td>
                    <td><?php echo number_format(($totalx_1/($num_rowsa*($num_rows_2x-1))),2); ?></td>
                    <td><?php 
                      ?>
                    </td>
                    <td style="display: none"></td>
                  </tr>
                  <?php
                  $totalx_1 = 0;
                  $totalC1 = 0;
                  $totalC2 = 0;
                  $totalC3 = 0;
                  $totalC4 = 0;
                  $totalC5 = 0;
                  $totalC = 0;
                }
              }else{
                $i2 = 0;
                echo "<tr><td colspan=\"8\"><lable><b>$rows_2[title]</b></label>";
                echo "$rows_answer_[open_ended]</td></tr>";
              }
            }
            if($i==$num_rows_2){
            ?>
                <!-- <tr bgcolor="#cccccc">
                  <td>รวม</td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td><?php echo number_format($totalx,4); ?></td>
                </tr> -->
                </tbody>
              </table>
              </div>
              <!-- </div> -->
              <div class="table-responsive">
              <table class="table table-striped">
            <?php
            }
          }
          
          if($rows_2['format']==3){
            $i++;
            if($rows_2['title']!=""){
              echo "<tr><td bgcolor='#cccccc' colspan='2'><strong>".$rows_2['title']."</strong></td></tr>";
            }
            
            //echo "<tr><td colspan='2'>$open_ended</td></tr>";
            echo "<tr><td colspan='2'>";
            $sql_answer_ = "select * from ap_questionnaire_answer where (code='$rows[code]' and code_question='$rows_2[id]') and open_ended!='-' and open_ended!=''";
            $query_answer_ = mysqli_query($conn,$sql_answer_);
            $i4 = 0;
            while($rows_answer_ = mysqli_fetch_array($query_answer_)){
              $i4++;
              if(!empty($rows_answer_['open_ended'])){
                echo "<p>$i4) $rows_answer_[open_ended]</p>";
              }
            }
            echo "</td></tr>";

          }
        }
      }
      ?>
      </table>
      </div>
    </div>
  <?php
  }

}

if($_GET['nu']=="products"){
  if($_GET['type']=="Questionnaire"){
    $ptitle = "แบบสอบถาม";
  }
  if($_GET['type']=="Quiz"){
    $ptitle = "ข้อสอบ";
  }
  if($_GET['type']=="Register"){
    $ptitle = "ลงทะเบียน";
  }
  ?>
  <div class="breadcrumbx">
    <?php //include('../../translate.php'); ?>
    <h2 class="sub-header"><?php echo $ptitle; ?>ออนไลน์</h2>
    <div class="table-responsive">
      <table class="table table-striped">
        <thead>
          <tr>
            <th width="70">ลำดับ</th>
            <th><?php echo $ptitle;?></th>
            <th>จำนวน</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $days = date(Ymd); /*date(Ymd,strtotime("+30 day"));*/
          $sql = "select * from ap_products where type='$_GET[type]' and code like 'QN%' order by code desc";
          $query = mysqli_query($conn,$sql);
          $i = 0;
          while($rows = mysqli_fetch_array($query)){
            $i++;
            if($days>=$rows['date_start'] && $days<=$rows['date_expire']){
              $warning = " class=\"label label-success\"";
            }else{
              $warning = " class=\"label label-danger\"";
            }

            if($_GET['type']=="Quiz"){
              $sql1 = "select * from ap_quiz_question where code='$rows[code]'";
            }
            if($_GET['type']=="Questionnaire"){
              $sql1 = "select * from ap_questionnaire_answer where code='$rows[code]' group by code_answer";
            }
            $query1 = mysqli_query($conn,$sql1);
            $num_rows1 = mysqli_num_rows($query1);
            ?>
            <tr>
              <td><?php echo $i;?>.</td>
              <td><?php
                if($_GET['type']=="Questionnaire"){
                  echo "<a href=\"$ap_site$ap_folder"."ap/questionnaire/?xcode=$rows[code]\" target=\"_blank\">$rows[name]</a> ";
                  echo "[ <a href=\"$ap_site$ap_folder"."ap/questionnaire/?nu=result&xcode=$rows[code]\" target=\"_blank\">สรุปผล</a> ] ";
                  echo "[ <a href=\"$ap_site$ap_folder"."ap/questionnaire/print.php?nu=&type=$_GET[type]&xcode=$rows[code]\" target=\"_blank\">QRCODE</a> ] ";
                  echo "[ <a href=\"$ap_site$ap_folder"."ap/questionnaire/print.php?nu=print&xcode=$rows[code]\" target=\"_blank\">พิมพ์สรุปผล</a> ] ";
                }elseif($_GET['type']=="Quiz"){
                  echo "<a href=\"../quiz.php?xcode=$rows[code]\" target=\"_blank\">$rows[name]</a> / <a href=\"../quiz.php?nu=info&xcode=$rows[code]\" target=\"_blank\">รายชื่อ</a> ";
                }else{
                  echo "<a href=\"?nu=products&type=Register&regCode=$rows[code]\">เขตข้อมูล</a> / <a href=\"$ap_site$ap_folder"."ap/register/?xcode=$rows[code]\" target=\"_blank\">$rows[name]</a> / <a href=\"$ap_site$ap_folder"."ap/register/?nu=info&xcode=$rows[code]\" target=\"_blank\">รายชื่อ</a> ";
                }
                ?>
              </td>
              <td><?php echo $num_rows1 ?></td>
            </tr>
          <?php
          }
          ?>
        </tbody>
      </table>
    </div>
  </div>
<?php
}

if($_GET['nu']!="products"){
?>
  <p align="center"><img src='<?php echo $ap_site.$ap_folder;?>ap/qrcode/qrcode.php?data=<?php echo htmlspecialchars($ap_site.$_SERVER['REQUEST_URI']);?>&size=114x114&logo=<?php echo $logo;?>' border='0' alt="" /></p><p align="center"><a href="<?php echo $ap_site.$ap_folder;?>"><?php echo $title; ?></a></p>
  </div>
<?php
}else{
  echo "<p></p></div>";
  include('../../footText.php');
}

include('../../foot.php');
?>