Esempio n. 1
0
 public static function getMobileQuestionAnswerControls($questions, $form_id, $eprogress_id = 0)
 {
     global $db;
     $output = "";
     $output .= "<div data-role=\"content\" id=\"form-content-questions-holder\">\n";
     $output .= "\t<ol id=\"form-questions-list\">\n";
     if ($eprogress_id) {
         $current_progress_record = Models_Evaluation::loadProgress($eprogress_id);
     } else {
         $current_progress_record = false;
     }
     $rubric_id = 0;
     $show_rubric_headers = false;
     $show_rubric_footers = false;
     $rubric_table_open = false;
     $original_question_id = 0;
     $comments_enabled = false;
     $modified_count = 0;
     $desctext_count = 0;
     foreach ($questions as $key => $question) {
         if (isset($question["questiontype_id"]) && $question["questiontype_id"]) {
             $query = "SELECT * FROM `evaluations_lu_questiontypes`\n                            WHERE `questiontype_id` = " . $db->qstr($question["questiontype_id"]);
             $questiontype = $db->GetRow($query);
         } else {
             $questiontype = array("questiontype_shortname" => "matrix_single");
         }
         switch ($questiontype["questiontype_shortname"]) {
             case "rubric":
                 $query = "SELECT * FROM `evaluation_rubric_questions` AS a\n                                JOIN `evaluations_lu_rubrics` AS b\n                                ON a.`erubric_id` = b.`erubric_id`\n                                WHERE a.`equestion_id` = " . $db->qstr($question["equestion_id"]);
                 $rubric = $db->GetRow($query);
                 if ($rubric) {
                     if ($rubric["erubric_id"] != $rubric_id) {
                         if ($rubric_id) {
                             $show_rubric_footers = true;
                         }
                         $rubric_id = $rubric["erubric_id"];
                         $show_rubric_headers = true;
                         $original_question_id = $question["equestion_id"];
                         $comments_enabled = $question["allow_comments"];
                     }
                     if ($show_rubric_footers) {
                         $show_rubric_footers = false;
                         $rubric_table_open = false;
                         $output .= "</table></div>";
                         if ($comments_enabled) {
                             $output .= "\t<div class=\"clear\"></div>\n";
                             $output .= "\t<div class=\"comments\">\n";
                             $output .= "\t<label for=\"" . $original_question_id . "_comment\" class=\"form-nrequired\">Comments:</label>\n";
                             $output .= "\t<textarea name=\"comments[" . $original_question_id . "]\" id=\"" . $original_question_id . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$original_question_id]["comments"]) ? $current_progress_record[$original_question_id]["comments"] : "") . "</textarea>\n";
                             $output .= "\t</div>\n";
                         } else {
                             $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                         }
                         $original_question_id = $question["equestion_id"];
                         $comments_enabled = $question["allow_comments"];
                         $output .= "</li>";
                     }
                     if ($show_rubric_headers) {
                         $rubric_table_open = true;
                         $output .= "<li id=\"question_" . $question["equestion_id"] . "\"" . ($modified_count % 2 ? " class=\"odd\"" : "") . ">\n";
                         $output .= "<span id=\"question_text_" . $question["equestion_id"] . "\" style=\"display: none;\">" . $rubric["rubric_title"] . (stripos($rubric["rubric_title"], "rubric") === false ? " Rubric" : "") . "</span>";
                         $output .= (isset($rubric["rubric_title"]) && $rubric["rubric_title"] ? "<h2>" . $rubric["rubric_title"] : "") . "<span style=\"font-weight: normal; margin-left: 10px; padding-right: 30px;\" class=\"content-small\">" . $rubric["rubric_description"] . "</span>" . (isset($rubric["rubric_title"]) && $rubric["rubric_title"] ? "</h2>\n" : "\n");
                         $modified_count++;
                         $output .= "<br /><div class=\"question\"><table class=\"rubric\">\n";
                         $output .= "\t<tr>\n";
                         $columns = 0;
                         $query = "\tSELECT a.*\n                                        FROM `evaluations_lu_question_responses` AS a\n                                        WHERE a.`equestion_id` = " . $db->qstr($question["equestion_id"]) . "\n                                        ORDER BY a.`response_order` ASC";
                         $responses = $db->GetAll($query);
                         if ($responses) {
                             $response_width = floor(100 / (count($responses) + 1));
                             $output .= "\t\t<th style=\"width: " . $response_width . "%; text-align: left; border-bottom: \">\n";
                             $output .= "\t\t\tCategories";
                             $output .= "\t\t</th>\n";
                             foreach ($responses as $response) {
                                 $columns++;
                                 $output .= "<th style=\"width: " . $response_width . "%; text-align: left;\">\n";
                                 $output .= clean_input($response["response_text"], "specialchars");
                                 $output .= "</th>\n";
                             }
                         }
                         $output .= "\t</tr>\n";
                         $show_rubric_headers = false;
                     }
                     $question_number = $key + 1;
                     $output .= "<tr id=\"question_" . $question["equestion_id"] . "\">";
                     $query = "\tSELECT b.*, a.`equestion_id`, a.`minimum_passing_level`\n                                    FROM `evaluations_lu_question_responses` AS a\n                                    LEFT JOIN `evaluations_lu_question_response_criteria` AS b\n                                    ON a.`eqresponse_id` = b.`eqresponse_id`\n                                    WHERE a.`equestion_id` = " . $db->qstr($question["equestion_id"]) . "\n                                    ORDER BY a.`response_order` ASC";
                     $criteriae = $db->GetAll($query);
                     if ($criteriae) {
                         $criteria_width = floor(100 / (count($criteriae) + 1));
                         $output .= "\t\t<td style=\"width: " . $criteria_width . "%\">\n";
                         $output .= "\t\t\t<div class=\"td-stretch\" style=\"position: relative; width: 100%; vertical-align: middle;\">\n";
                         echo "\t\t\t\t        <div style=\"position: relative; top: 50%;\">\n";
                         echo "                          <strong>" . $question["question_text"] . "</strong>\n";
                         echo "                          <div class=\"space-above content-small\">" . nl2br($question["question_description"]) . "</div>";
                         echo "                      </div>\n";
                         $output .= "\t\t\t</div>\n";
                         $output .= "\t\t</td>\n";
                         $blank_lines = "\n";
                         foreach ($criteriae as $criteria) {
                             $new_blank_lines = preg_replace('/\\S/', " ", $criteria["criteria_text"]);
                             if (strlen($blank_lines) < strlen($new_blank_lines)) {
                                 $blank_lines = $new_blank_lines;
                             }
                         }
                         $output .= "\t<fieldset data-role=\"controlgroup\">";
                         foreach ($criteriae as $criteria) {
                             $criteria_text = clean_input(nl2br($criteria["criteria_text"]), "allowedtags");
                             if (!trim($criteria_text)) {
                                 $criteria_text = nl2br($blank_lines);
                             }
                             $output .= "<td style=\"width: " . $criteria_width . "%; vertical-align: top;\" >\n";
                             $output .= "\t<div style=\"width: 3em; margin: 0 auto;\">";
                             $output .= "\t\t<input data-theme=\"b\" type=\"radio\" id=\"" . $form_id . "_" . $criteria["equestion_id"] . "_" . $criteria["eqresponse_id"] . "\" name=\"responses[" . $question["equestion_id"] . "]\"" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["eqresponse_id"]) && $current_progress_record[$question["equestion_id"]]["eqresponse_id"] == $criteria["eqresponse_id"] ? " checked=\"checked\"" : "") . " value=\"" . $criteria["eqresponse_id"] . "\" />";
                             $output .= "\t\t<label for=\"" . $form_id . "_" . $criteria["equestion_id"] . "_" . $criteria["eqresponse_id"] . "\" >&nbsp;</label>";
                             $output .= "\t</div>\n";
                             $output .= "\t" . $criteria_text;
                             $output .= "</td>\n";
                         }
                         $output .= "\t</fieldset>\n";
                     }
                     $output .= "</tr>";
                 }
                 break;
             case "descriptive_text":
             case "free_text":
                 if ($rubric_table_open) {
                     $rubric_table_open = false;
                     $rubric_id = 0;
                     $output .= "</table></div>";
                     if ($comments_enabled) {
                         $output .= "\t<div class=\"clear\"></div>\n";
                         $output .= "\t<div class=\"comments\">\n";
                         $output .= "\t<label for=\"" . $original_question_id . "_comment\" class=\"form-nrequired\">Comments:</label>\n";
                         $output .= "\t<textarea name=\"comments[" . $original_question_id . "]\" id=\"" . $original_question_id . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$original_question_id]["comments"]) ? $current_progress_record[$original_question_id]["comments"] : "") . "</textarea>\n";
                         $output .= "\t</div>\n";
                     } else {
                         $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                     }
                     $original_question_id = 0;
                     $comments_enabled = false;
                     $output .= "</li>";
                 }
                 $question_number = $key + 1;
                 $output .= "<li id=\"question_" . $question["equestion_id"] . "\"" . ($modified_count % 2 ? " class=\"odd\"" : "") . ">";
                 $output .= "\t<div id=\"question_text_" . $question["equestion_id"] . "\" for=\"" . $question["equestion_id"] . "_comment\" class=\"question\">\n";
                 $output .= "\t\t" . clean_input($question["question_text"], "specialchars");
                 $output .= "\t</div>\n";
                 $output .= "\t<div class=\"clear\"></div>";
                 if ($questiontype["questiontype_shortname"] == "free_text") {
                     $output .= "\t<div class=\"comments\">";
                     $output .= "\t<textarea name=\"comments[" . $question["equestion_id"] . "]\" id=\"" . $question["equestion_id"] . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["comments"]) ? $current_progress_record[$question["equestion_id"]]["comments"] : "") . "</textarea>";
                     $output .= "\t</div>";
                 }
                 $output .= "</li>\n";
                 $modified_count++;
                 break;
             case "selectbox":
                 if ($rubric_table_open) {
                     $rubric_table_open = false;
                     $rubric_id = 0;
                     $output .= "</table></div>";
                     if ($comments_enabled) {
                         $output .= "\t<div class=\"clear\"></div>\n";
                         $output .= "\t<div class=\"comments\">\n";
                         $output .= "\t<label for=\"" . $original_question_id . "_comment\" class=\"form-nrequired\">Comments:</label>\n";
                         $output .= "\t<textarea id=\"" . $original_question_id . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$original_question_id]["comments"]) ? $current_progress_record[$original_question_id]["comments"] : "") . "</textarea>\n";
                         $output .= "\t</div>\n";
                     } else {
                         $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                     }
                     $original_question_id = 0;
                     $comments_enabled = false;
                     $output .= "</li>";
                 }
                 $question_number = $key + 1;
                 $output .= "<li id=\"question_" . $question["equestion_id"] . "\"" . ($modified_count % 2 ? " class=\"odd\"" : "") . ">";
                 $output .= "\t<div id=\"question_text_" . $question["equestion_id"] . "\" class=\"question\">\n";
                 $output .= "\t\t" . clean_input($question["question_text"], "specialchars");
                 $output .= "\t</div>\n";
                 $output .= "\t<div class=\"responses\">\n";
                 $query = "\tSELECT a.*\n                                FROM `evaluations_lu_question_responses` AS a\n                                WHERE a.`equestion_id` = " . $db->qstr($question["equestion_id"]) . "\n                                ORDER BY a.`response_order` ASC";
                 $responses = $db->GetAll($query);
                 if ($responses) {
                     $response_width = floor(100 / count($responses)) - 1;
                     //echo "<div class=\"clearfix\">\n";
                     $output .= "<fieldset data-role=\"controlgroup\">\n";
                     $output .= "<select id=\"responses_" . $question["equestion_id"] . "\" name=\"responses[" . $question["equestion_id"] . "]\">\n";
                     $output .= "  <option value=\"0\">-- Select a response --</option>\n";
                     foreach ($responses as $response) {
                         $output .= "  <option value=\"" . $response["eqresponse_id"] . "\"" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["eqresponse_id"]) && $current_progress_record[$question["equestion_id"]]["eqresponse_id"] == $response["eqresponse_id"] ? " selected=\"selected\"" : "") . ">" . clean_input($response["response_text"], "specialchars") . "</option>\n";
                     }
                     $output .= "</select>\n";
                     $output .= "</fieldset>\n";
                     //echo "</div>\n";
                 }
                 $output .= "\t</div>\n";
                 if ($question["allow_comments"]) {
                     $output .= "\t<div class=\"clear\"></div>";
                     $output .= "\t<div class=\"comments\">";
                     $output .= "\t<label for=\"" . $question["equestion_id"] . "_comment\" class=\"form-nrequired\">Comments:</label>";
                     $output .= "\t<textarea name=\"comments[" . $question["equestion_id"] . "]\" id=\"" . $question["equestion_id"] . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["comments"]) ? $current_progress_record[$question["equestion_id"]]["comments"] : "") . "</textarea>";
                     $output .= "\t</div>";
                 } else {
                     $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                 }
                 $output .= "</li>\n";
                 $modified_count++;
                 break;
             case "vertical_matrix":
             case "matrix_single":
             default:
                 if ($rubric_table_open) {
                     $rubric_table_open = false;
                     $rubric_id = 0;
                     $output .= "</table></div>";
                     if ($comments_enabled) {
                         $output .= "\t<div class=\"clear\"></div>\n";
                         $output .= "\t<div class=\"comments\">\n";
                         $output .= "\t<label for=\"" . $original_question_id . "_comment\" class=\"form-nrequired\">Comments:</label>\n";
                         $output .= "\t<textarea id=\"" . $original_question_id . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$original_question_id]["comments"]) ? $current_progress_record[$original_question_id]["comments"] : "") . "</textarea>\n";
                         $output .= "\t</div>\n";
                     } else {
                         $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                     }
                     $original_question_id = 0;
                     $comments_enabled = false;
                     $output .= "</li>";
                 }
                 $question_number = $key + 1;
                 $output .= "<li id=\"question_" . $question["equestion_id"] . "\"" . ($modified_count % 2 ? " class=\"odd\"" : "") . ">";
                 $output .= "\t<div id=\"question_text_" . $question["equestion_id"] . "\" class=\"question\">\n";
                 $output .= "\t\t" . clean_input($question["question_text"], "specialchars");
                 $output .= "\t</div>\n";
                 $output .= "\t<div class=\"responses\">\n";
                 $query = "\tSELECT a.*\n                                FROM `evaluations_lu_question_responses` AS a\n                                WHERE a.`equestion_id` = " . $db->qstr($question["equestion_id"]) . "\n                                ORDER BY a.`response_order` ASC";
                 $responses = $db->GetAll($query);
                 if ($responses) {
                     $output .= "<fieldset data-role=\"controlgroup\">\n";
                     foreach ($responses as $response) {
                         $output .= "\t<input type=\"radio\" id=\"response_" . $question["equestion_id"] . "_" . $response["eqresponse_id"] . "\" name=\"responses[" . $response["equestion_id"] . "]\"" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["eqresponse_id"]) && $current_progress_record[$question["equestion_id"]]["eqresponse_id"] == $response["eqresponse_id"] ? " checked=\"checked\"" : "") . " value=\"" . $response["eqresponse_id"] . "\" />";
                         $output .= "\t<label for=\"response_" . $question["equestion_id"] . "_" . $response["eqresponse_id"] . "\">" . clean_input($response["response_text"], "specialchars") . "</label>";
                     }
                     $output .= "</fieldset>\n";
                 }
                 $output .= "\t</div>\n";
                 if ($question["allow_comments"]) {
                     $output .= "\t<div class=\"clear\"></div>";
                     $output .= "\t<div class=\"comments\">";
                     $output .= "\t<label for=\"" . $question["equestion_id"] . "_comment\" class=\"form-nrequired\">Comments:</label>";
                     $output .= "\t<textarea name=\"comments[" . $question["equestion_id"] . "]\" id=\"" . $question["equestion_id"] . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$question["equestion_id"]]["comments"]) ? $current_progress_record[$question["equestion_id"]]["comments"] : "") . "</textarea>";
                     $output .= "\t</div>";
                 } else {
                     $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
                 }
                 $output .= "</li>\n";
                 $modified_count++;
                 break;
         }
     }
     if ($rubric_table_open) {
         $output .= "</table></div>";
         if ($comments_enabled) {
             $output .= "\t<div class=\"clear\"></div>\n";
             $output .= "\t<div class=\"comments\">\n";
             $output .= "\t<label for=\"" . $original_question_id . "_comment\" class=\"form-nrequired\">Comments:</label>\n";
             $output .= "\t<textarea name=\"comments[" . $original_question_id . "]\" id=\"" . $original_question_id . "_comment\" class=\"expandable\" style=\"width:95%; height:40px;\">" . ($current_progress_record && isset($current_progress_record[$original_question_id]["comments"]) ? $current_progress_record[$original_question_id]["comments"] : "") . "</textarea>\n";
             $output .= "\t</div>\n";
         } else {
             $output .= "<input data-theme=\"b\" type=\"hidden\" value=\"\" id=\"" . $original_question_id . "_comment\" />\n";
         }
         $output .= "</li>";
     }
     $output .= "    </ol>\n";
     $output .= "</div>\n";
     return $output;
 }