<%@page import="java.net.URLEncoder"%>
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.session.*, com.csc.library.utilities.*, com.csc.library.entry.*"%>
<%
   UProfile up = null;
   if (session!=null){
      up = (UProfile)session.getAttribute("userprofile");
   }
%>
<html ng-app='EXAM'>
   <head>
      <link href="../JS/QueryBuilder/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
      <link rel="stylesheet" href="../CSS/TISCO.css" />
      <link rel='stylesheet' href='CSS/ManageExam.css' />
      <script type='text/javascript' src='../JS/SCREEN.js'></script>
      <script type='text/javascript' src='../JS/HOTKEY.js'></script>
      <script type='text/javascript' src='../JS/ICONSMENU.js'></script>
      <script type="text/javascript" src='../JS/jquery-2.1.3.min.js'></script>
      <script type="text/javascript" src='../public/lib/angular/angular.min.js'></script>
      <script type="text/javascript" src="../JS/ANGULAR/SCREEN_ANGULAR.js"></script>
      <script type="text/javascript" src='../public/lib/angular-resource/angular-resource.min.js'></script>
      <script type='text/javascript' src='../public/lib/angular-sanitize/angular-sanitize.min.js'></script>
      <script type="text/javascript" src='../CSS/Bootstrap/js/bootstrap.min.js'></script>
      <script type='text/javascript' src='JS/Module.js'></script>
      <script type='text/javascript' src='JS/services.js'></script>
       <script type='text/javascript' src='JS/filter.js'></script>
      <script type='text/javascript' src='JS/EXAM001/Exam001.Controller.js'></script>
      <script type='text/javascript'>
         setLang("<%=up.get("lang")%>");
         getTitleName();

         function linkHelp(help, input){
            with (document.cscform) {
               obj = eval("document.cscform." + input);
               var param = "PRU084_NEW_APS_ANG.jsp?__helpName=" + help + "&__fieldSearch=" + input + "&__pageCall=" + __screen.value + "&__fixCon=" + __fixCon.value + "&tdeq=1";
               if (obj.value === "") {
                  param = "PRU084_NEW_APS_ANG.jsp?__helpName=" + help + "&__fieldSearch=" + input + "&__pageCall=" + __screen.value + "&__fixCon=" + __fixCon.value + "&tdeq=1";
               }
               win = window.open(param, "Help", "left=300,top=150,width=700,height=400,resizable=yes,scrollbars=yes,toolbar=no,status=yes");
               if (window.focus) {
                  win.focus();
               }
            }
         }

         function postReturnAngular(returnValue){
            var returnval = returnValue.split('#');
            var keyval = returnval[1].substring(0, returnval[1].length-1);
            var scope = angular.element($("form[name=cscform]")).scope();
            scope.$apply(function(){
               scope.queryByKey(returnval[0], keyval);
            });
         }

         function putNewChild(result){
            var scope = angular.element($('form[name="cscform"]')).scope();
            scope.$apply(function(){
               scope.putNewChild(result);
            });
         }

         //put new child for mquestion
         function newChild(questionobj){
            var scope = angular.element($('form[name="cscform"]')).scope();
            scope.$apply(function(){
               scope.putNewQuestion(questionobj);
            });
         }

         function GoSave(){
            if (confirm(MyCode[1])){
               var scope = angular.element($('form[name="cscform"]')).scope();
               scope.$apply(function(){
                  scope.save();
               });
            }
         }

         function GoDelete(){
            if (confirm(MyCode[4])){
               var scope = angular.element($('form[name="cscform"]')).scope();
               scope.$apply(function(){
                  scope.delete();
               });
            }
         }

         $(document).ready(function(){
            $('#add').click(function(){
               if ( $('select[name="__question_type"]').val() == 0 ){
                  window.open("EXAM001_ADD.jsp", "ADD_QUESTION", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=300, width=800, height=500");
               }else if ( $('select[name="__question_type"]').val() == 1){
                  window.open("EXAM_ADD_QUESTION.jsp?hasAddQuestion=1", "ADD_QUESTION", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=300, width=1200, height=800");
               }
            });
         });
      </script>
   </head>
   <body ng-controller='Exam001'>
      <div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
      <script>initToolTips();</script>
      <form name='cscform'>
         <input type="hidden" name="__screen" value="EXAM001" />
         <input type="hidden" name="__help" value="" />
         <input type="hidden" name="__fixCon" value="" />
         <input type="hidden" name="__cmd" value="">
         <input type='hidden' name="__helpReturn" value="" />

         <script>document.write(Icons("EXAM001, ทะเบียนรายวิชา"));</script>
         <div class='container'>
            <br/>
            <table style="border-spacing: 0;border-collapse: 0;width: 100%;">
               <tr>
                  <td class='header' colspan='2'>EXAM001, ทะเบียนรายวิชา&nbsp;</td>
               </tr>
               <tr>
                  <td class="blankspace" colspan="2"></td>
               </tr>
               <tr>
                  <td class='right'>รหัสรายวิชา</td>
                  <td>
                     <input type='text' name='__questionset1id' ng-model='questset1.questionset1id'/>
                     <a href="javascript:linkHelp('MQUESTIONSET1HELP','__questionset1id');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__questionset2id_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)">
                        <img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__questionset2id_image" width="20" height="20" border="0" align="absmiddle">
                     </a>
                  </td>
               </tr>
               <tr>
                  <td class='right'>รายละเอียด</td>
                  <td><input type='text' size='100' maxlength='500' ng-model='questset1.questionset1_name'/></td>
               </tr>
               <tr>
                  <td class='right'>หมายเหตุ</td>
                  <td><input type='text' size='100' maxlength='500' ng-model='questset1.remark' /></td>
               </tr>
               <tr>
                  <td class='right'>วิชาบังคับ</td>
                  <td>
                     <label><input type='radio' ng-model='questset1.subject_req' value='1' />ใช่</label>
                     <label><input type='radio' ng-model='questset1.subject_req' value='0' />ไม่ใช่</label>
                  </td>
               </tr>
               <tr>
                  <td class='right'>คะแนนเต็ม</td>
                  <td> {{ questset1.total_score }} คะแนนที่ผ่านเกณฑ์ <input type='text' ng-model='questset1.pass_score' ng-blur='checkPassScore()'/></td>
               </tr>
               <tr>
                  <td class='right'>กำหนดเวลาในการทำข้อสอบ</td>
                  <td>
                     <label><input type='radio' ng-model='questset1.settime' value='1' />กำหนด</label>
                     <label><input type='radio' ng-model='questset1.settime' value='0' />ไม่กำหนด</label>
                  </td>
               </tr>
               <tr ng-if='questset1.settime == 1'>
                  <td class='right'>เวลาในการทำข้อสอบ</td>
                  <td>
                     <select ng-model='questset1.hour' ng-disabled='questset1.settime != 1'>
                        <option ng-repeat='hours in selhour' value='{{ hours }}'>{{ hours }}</option>
                     </select>
                     <span> ชั่วโมง </span>
                     <select ng-model='questset1.minute' ng-disabled='questset1.settime != 1'>
                        <option ng-repeat='minutes in selminute' value='{{ minutes }}'>{{ minutes }}</option>
                     </select>
                     <span> นาที </span>
                  </td>
               </tr>
               <tr>
                  <td class='right'>แจ้งคะแนนสอบ</td>
                  <td>
                     <label><input type='radio' ng-model='questset1.score_report' value='1' />แจ้ง</label>
                     <label><input type='radio' ng-model='questset1.score_report' value='0' />ไม่แจ้ง</label>
                  </td>
               </tr>
               <tr>
                  <td class='right'>สถานะ</td>
                  <td>
                     <label><input type='radio' ng-model='questset1.status' value='1' />ใช้งาน</label>
                     <label><input type='radio' ng-model='questset1.status' value='0' />ไม่ใช้งาน</label>
                  </td>
               </tr>
               <tr>
                  <td class='right'>สถานะการทำข้อสอบ</td>
                  <td>
                     <label><input type='radio' ng-model='questset1.examworkstatus' value='1' />สอบทันที</label>
                     <label><input type='radio' ng-model='questset1.examworkstatus' value='0' />รอการอนุมัติ</label>
                  </td>
               </tr>
               <tr>
                  <td class='right'><span swlang code='SW012909'>ประเภทคำถาม</span></td>
                  <td>
                     <select name='__question_type' ng-model='questset1.question_type' ng-click="checkBeforeChange()">
                        <option value='0'>ทะเบียนส่วน</option>
                        <option value='1' swlang code='SW000105'>คำถาม</option>
                     </select>
                  </td>
               </tr>
               <tr>
                  <td colspan='2'>
                     <table id='tb' class='table' style='width: 98%; margin: 0 auto;'>
                        <tr class='hasborder'>
                           <td class='detailHeader'><span swlang code='SW000015'>select</span></td>
                           <td class='detailHeader'><span swlang code='SW012906'>Question ID</span></td>
                           <td class='detailHeader'><span swlang code='SW000012'>Description</span></td>
                           <td class='detailHeader'><span swlang code='SW000013'>Score</span></td>
                        </tr>
                        <tr ng-repeat='q2 in questset1ch' class='hasborder'>
                           <td class='center'><input type='checkbox' ng-model='q2.ischeck' /> </td>
                           <td ng-bind-html='q2.questionid'></td>
                           <td>
                              <strong ng-bind-html='q2.question_name'></strong>
                              <span ng-if='questset1.question_type == 0'>
                                 <ol ng-repeat='q3 in q2.question_body'>
                                    <strong ng-bind-html='q3.questionset3_name'></strong>
                                    <ol ng-if='q3.question_type == 0' ng-repeat='q4 in q3.questionset4'>
                                       <strong ng-bind-html='q4.questionset4_name'></strong>
                                       <ol>
                                          <li ng-repeat='qbody in q4.question_body' ng-bind-html='qbody.question'></li>
                                       </ol>
                                    </ol>
                                    <ol ng-if='q3.question_type == 1'>
                                       <li ng-repeat='qbody in q3.question_body' ng-bind-html='qbody.question'></li>
                                    </ol>
                                 </ol>
                                 <ol ng-if='q2.question_type == 1'>
                                    <li ng-repeat='qbody in q2.question_body' ng-bind-html='qbody.question'></li>
                                 </ol>
                              </span>
                           </td>
                           <td class='center' ng-bind-html='q2.score'></td>
                        </tr>
                        <tr>
                           <td colspan="4" class="text-center" style="padding-top: 10px; padding-bottom: 10px;">
                              <a id="selectAll" class="btn btn-primary btn-sm" ng-click='selectAll()'>
                                 <span class="glyphicon glyphicon-asterisk"></span> Select All
                              </a>
                              <a id="deselectAll" class="btn btn-primary btn-sm" ng-click='deSelectAll()'>
                                 <span class="glyphicon glyphicon-ban-circle"></span> Deselect All
                              </a>
                              <a id="add" class="btn btn-primary btn-sm">
                                 <span class="glyphicon glyphicon-plus"></span> Add
                              </a>
                              <a id="del" class="btn btn-primary btn-sm" ng-click='delSelect()'>
                                 <span class="glyphicon glyphicon-trash"></span> Delete
                              </a>
                           </td>
                        </tr>
                     </table>
                  </td>
               </tr>
            </table>
         </div>
      </form>
   </body>
</html>