<%@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/EXAM002/Exam002.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);
            });
         }

         // put new child for EXAM002_ADD
         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() == '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");
               }else if ( $('select[name="__question_type"]').val() == '0' ){
                  window.open("EXAM002_ADD.jsp", "ADD_QUESTION", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=300, width=800, height=500");
               }

            });
         });
      </script>
   </head>
   <body ng-controller='Exam002'>
      <div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
      <script>initToolTips();</script>
      <form name='cscform'>
         <input type="hidden" name="__screen" value="EXAM002" />
         <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("EXAM002, ทะเบียนส่วน"));</script>
         <div class='container'>
            <br/>
            <table style="border-spacing: 0;border-collapse: 0;width: 100%;">
               <tr>
                  <td class='header' colspan='2'>EXAM002, ทะเบียนส่วน&nbsp;</td>
               </tr>
               <tr>
                  <td class="blankspace" colspan="2"></td>
               </tr>
               <tr>
                  <td class='right'><span>รหัสส่วน</span></td>
                  <td>
                     <input type='text' ng-model='questset2.questionset2id' />
                     <input type='hidden' name='__questionset2id' />
                     <a href="javascript:linkHelp('MQUESTIONSET2HELP','__questionset2id');" 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'><span>รายละเอียด</span></td>
                  <td><textarea ng-model='questset2.questionset2_name' rows="5" cols="100"></textarea></td>
               </tr>
               <tr>
                  <td class='right'><span>วัตถุประสงค์</span></td>
                  <td><textarea ng-model='questset2.objective' rows="5" cols="100"></textarea></td>
               </tr>
               <tr>
                  <td class='right'><span>ข้อแนะนำ</span></td>
                  <td><textarea ng-model='questset2.recommend' rows="5" cols="100"></textarea></td>
               </tr>
               <tr>
                  <td class='right'><span>สถานะ</span></td>
                  <td>
                     <label><input type='radio' name='__status' ng-model='questset2.status' value='1'/> ใช้งาน</label>
                     <label><input type='radio' name='__status' ng-model='questset2.status' value='0'/> ไม่ใช้งาน</label>
                  </td>
               </tr>
               <tr>
                  <td class='right'><span>คะแนนรวม</span></td>
                  <td>{{ questset2.total_score }}</td>
               </tr>
               <tr>
                  <td class='right'><span swlang code='SW012909'>ประเภทคำถาม</span></td>
                  <td>
                     <select name='__question_type' ng-model='questset2.question_type' ng-change='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='q3 in questset2ch' class='hasborder'>
                           <td class='center'><input type='checkbox' ng-model='q3.ischeck' value='q3.questionid'></td>
                           <td>{{ q3.questionid }}</td>
                           <td>
                              <strong ng-bind-html='q3.question_name'></strong>
                              <span ng-if='questset2.question_type == 0'>
                                 <ol ng-if='q3.question_type == 0' ng-repeat='q4 in q3.question_body'>
                                    <strong ng-bind-html='q4.questionset4_name'></strong>
                                    <ol>
                                       <li ng-repeat='q in q4.question_body' ng-bind-html='q.question'></li>
                                    </ol>
                                 </ol>
                                 <ol ng-if='q3.question_type == 1'>
                                    <li ng-repeat='q4 in q3.question_body' ng-bind-html='q4.question'></li>
                                 </ol>
                              </span>
                           </td>
                           <td class='center'>{{ q3.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>