APS_NEW_002_PREVIEW.jsp 13.3 KB
Newer Older
Thitichaipun Wutthisak committed
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
<%@page import="java.util.Iterator"%>
<%@page import="java.util.LinkedHashMap"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="com.csc.library.utilities.CheckNull"%>
<%@page import="com.csc.library.utilities.MyLog"%>
<%@page import="com.csc.library.session.InitialInquiry"%>
<%@page import="com.csc.library.session.DbInquiry"%>
<%@page import="com.csc.library.entry.HelpEntry"%>
<%@page contentType="text/html; charset=UTF-8"%>
<jsp:useBean id="APS_NEW_002_PREVIEW" class="com.csc.library.system.Task" scope="page"/>
<%
    APS_NEW_002_PREVIEW.setChannel(request,response);
    APS_NEW_002_PREVIEW.checkProfile();
    HelpEntry screen = (HelpEntry) APS_NEW_002_PREVIEW.process("HelpEntry","MQUESTIONHELP");
    screen.referLangOff();
    CheckNull chk = new CheckNull();
    String lang = screen.getUProfile().get("lang");
    String questionid = chk.chkNullString(request.getParameter("questionid"));
    MyLog.debug(screen, screen.getUProfile(),"^^ Nut Freedom ^^ ----> questionid ==== " + questionid);
    screen.getInquiry().setFilter("1=2");
    screen.process();
    int tmpLineObjective = 1;
    int tmpLineSubjective = 1;
    int tmpLineSortSentence = 1;
    int tmpLineQuestionnaire = 1;
    int tmpLineQuestionnaireMulti = 1;
    int tmpLineQuestionnaireSubjective = 1;
    int tmpLineMatch = 1;
    
    if(!questionid.equals("")) {
        String[] sp = questionid.split(",");
        for (short i = 0; i < sp.length; i++) {
            try {
                DbInquiry mq = new InitialInquiry(screen.getUProfile()).getDbInquiry("mquestion");
                mq.setColumn("*");
                mq.clearOldCondition();
                mq.setFilter("questionid='" + sp[i] + "'");
                mq.refresh();
                while (mq.next()) {
                    String headQuestion = mq.getString("question");
                    String msgHeadFirst = headQuestion.substring(0, headQuestion.indexOf(">") + 1);
                    String msgHeadLast = headQuestion.substring(headQuestion.indexOf(">") + 1);
                    out.print("<br><strong>" + msgHeadFirst + (i + 1) + ". " + msgHeadLast + "</strong><br>");
                    MyLog.debug(screen, screen.getUProfile(), "^^ Nut Freedom ^^ ----> question ==== " + mq.getString("question"));
                    try {
                        DbInquiry dbi = new InitialInquiry(screen.getUProfile()).getDbInquiry("mquestion_detail");
                        dbi.setColumn("*");
                        dbi.clearOldCondition();
                        dbi.setFilter("questionid='" + mq.getString("questionid") + "'");
                        dbi.refresh();
                        // ---------- for จับคู่ ----------
                        LinkedHashMap<Integer, String> fieldQuestionDetail = new LinkedHashMap<Integer, String>();
                        LinkedHashMap<Integer, String> fieldAnswerMatchDetail = new LinkedHashMap<Integer, String>();
                        int lineMatch = 1;

                        // ---------- for เรียงประโยค ----------
                        LinkedHashMap<Integer, String> fieldSortSentence = new LinkedHashMap<Integer, String>();
                        int lineSortSentence = 1;

                        String titleType = mq.getString("title_type");
                        String queryType = mq.getString("query_type");

                        while (dbi.next()) {
                            String questionDetail = dbi.getString("question_detail");
                            String answerMatchDetail = dbi.getString("answer_match_detail");

                            if (titleType.equals("0")) { // ปรนัย
                                String msgFirst = questionDetail.substring(0, questionDetail.indexOf(">") + 1);
                                String msgLast = questionDetail.substring(questionDetail.indexOf(">") + 1);
                                out.print(msgFirst + "<input type=\"radio\" name=\"objective" + tmpLineObjective + "\">&nbsp;" + msgLast);
                            } else if (titleType.equals("1")) { // อัตนัย
                                tmpLineSubjective++;
                                out.print("<textarea id=\"subjective" + tmpLineSubjective + "\" name=\"subjective" + tmpLineSubjective + "\" cols=\"140\" rows=\"5\"></textarea>");
                            } else if (titleType.equals("2")) { // จับคู่
                                fieldQuestionDetail.put(lineMatch, questionDetail);
                                fieldAnswerMatchDetail.put(lineMatch, answerMatchDetail);
                                lineMatch++;

                            } else if (titleType.equals("3")) { // เรียงประโยค
                                fieldSortSentence.put(lineSortSentence, dbi.getString("result_sort_sentence"));
                                lineSortSentence++;

                            } else if (titleType.equals("4")) { // แบบสอบถาม
                                if (queryType.equals("0")) { // เลือกคำตอบได้ข้อเดียว
                                    String msgFirst = questionDetail.substring(0, questionDetail.indexOf(">") + 1);
                                    String msgLast = questionDetail.substring(questionDetail.indexOf(">") + 1);
                                    out.print(msgFirst + "<input type=\"radio\" name=\"questionnaire_objective" + tmpLineQuestionnaire + "\">&nbsp;" + msgLast);
                                } else if (queryType.equals("1")) { // เลือกคำตอบได้หลายข้อ
                                    String msgFirst = questionDetail.substring(0, questionDetail.indexOf(">") + 1);
                                    String msgLast = questionDetail.substring(questionDetail.indexOf(">") + 1);
                                    out.print(msgFirst + "<input type=\"checkbox\" name=\"questionnaire_objective_multi" + tmpLineQuestionnaireMulti + "\">&nbsp;" + msgLast);
                                } else if (queryType.equals("2")) { // ความคิดเห็น
                                    out.print("<textarea id=\"questionnaire_subjective" + tmpLineQuestionnaireSubjective + "\" name=\"questionnaire_subjective" + tmpLineQuestionnaireSubjective + "\" cols=\"140\" rows=\"5\"></textarea>");
                                    tmpLineQuestionnaireSubjective++;
                                }
                            }
                        }

                        if (titleType.equals("0")) { // ปรนัย
                            tmpLineObjective++;
                        }

                        if (titleType.equals("2")) { // จับคู่
                            Iterator<Integer> it = fieldQuestionDetail.keySet().iterator();
                            out.print("<table class=\"table-preview\" style=\"width: 100%;border-style: none;\">");
                            String option = "";
                            int size = fieldAnswerMatchDetail.size();
                            for (short j = 1; j <= size; j++ ) {
                                option += "<option value=\"" + j + "\">" + j + "</option>";
                            }
                            String tmpRandom = "";
                            int line = 1;
                            while (it.hasNext()) {
                                int key = it.next();
                                String value = fieldQuestionDetail.get(key);
                                int random = (int)(Math.random() * size + 1);
                                boolean statusFound = true;
                                while (statusFound) {
                                    if (tmpRandom.indexOf("," + random + ",") == -1 || tmpRandom.equals("")) {
                                        statusFound = false;
                                        tmpRandom += "," + random + ",";
                                        String msgQuestionFirst = value.substring(0, value.indexOf('>') + 1);
                                        String msgQuestionLast = value.substring(value.indexOf('>') + 1);
                                        String answerDetail = fieldAnswerMatchDetail.get(random);
                                        String msgAnswerFirst = answerDetail.substring(0, answerDetail.indexOf('>') + 1);
                                        String msgAnswerLast = answerDetail.substring(answerDetail.indexOf('>') + 1);
                                        if (!value.equals("")) {
                                            tmpLineMatch++;
                                            StringBuilder data = new StringBuilder();
                                            data.append("<tr>");
                                                data.append("<td width=\"40%\">");
                                                    data.append(msgQuestionFirst + "<select id=\"match" + tmpLineMatch + "\" name=\"match" + tmpLineMatch + "\">" + option + "</select>&nbsp;" + msgQuestionLast);
                                                data.append("</td>");
                                                data.append("<td width=\"3%\">");
                                                    data.append(msgAnswerFirst + line + ".");
                                                data.append("</td>");
                                                data.append("<td>");
                                                    data.append(msgAnswerLast);
                                                data.append("</td>");
                                            data.append("</tr>");
                                            out.print(data.toString()); 
                                        } else {
                                            StringBuilder data = new StringBuilder();
                                            data.append("<tr>");
                                                data.append("<td width=\"40%\">");
                                                    data.append("&nbsp;");
                                                data.append("</td>");
                                                data.append("<td width=\"3%\">");
                                                    data.append(msgAnswerFirst + line + ".");
                                                data.append("</td>");
                                                data.append("<td>");
                                                    data.append(msgAnswerLast);
                                                data.append("</td>");
                                            data.append("</tr>");
                                            out.print(data.toString());
                                        }
                                        line++;
                                    } else {
                                        random = (int)(Math.random() * size + 1);
                                    }
                                }
                            }
                            out.print("</table>");
                        }

                        if (titleType.equals("3")) { // เรียงประโยค
                            out.print("<div id=\"result" + tmpLineSortSentence + "\" style=\"height: 25px;border-bottom: 1px solid #000000;\"></div><br>");
                            Iterator<Integer> it = fieldSortSentence.keySet().iterator();
                            int size = fieldSortSentence.size();
                            String tmpRandom = "";
                            String question = "";
                            while (it.hasNext()) {
                                int key = it.next();
                                String value = fieldSortSentence.get(key);
                                int random = (int)(Math.random() * size + 1);
                                boolean statusFound = true;
                                while (statusFound) {
                                    if (tmpRandom.indexOf("," + random + ",") == -1 || tmpRandom.equals("")) {
                                        statusFound = false;
                                        tmpRandom += "," + random + ",";
                                        question += "<span class=\"plus\">" + fieldSortSentence.get(random) + "</span>";
                                    } else {
                                        random = (int)(Math.random() * size + 1);
                                    }
                                }
                            }
                            out.print("<div id=\"question" + tmpLineSortSentence + "\">" + question + "</div>");
                            tmpLineSortSentence++;
                        }

                        if (titleType.equals("4")) { // แบบสอบถาม
                            if (queryType.equals("0")) { // เลือกคำตอบได้ข้อเดียว
                                tmpLineQuestionnaire++;
                            } else if (queryType.equals("1")) { // เลือกคำตอบได้หลายข้อ
                                tmpLineQuestionnaireMulti++;
                            }
                        }

                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

%>