/** * private * generate html output with decision. In html output, the errors with no decision made are display at the top, * followed by errors that decisions have been made. This method also calculates number of errors based on made decisions. * If a decision is made as pass, the error is ignored without adding into number of errors. * parameters: * $check_row: table row of the check * $line_number: line number that the error happens * $col_number: column number that the error happens * $html_tag: html tag that the error happens * $error_type: IS_WARNING or IS_INFO */ private function generate_cell_with_decision($check_row, $line_number, $col_number, $html_code, $image, $image_alt, $error_type) { $css_code = ""; // generate decision section $userDecisionsDAO = new UserDecisionsDAO(); $row = $userDecisionsDAO->getByUserLinkIDAndLineNumAndColNumAndCheckID($this->user_link_id, $line_number, $col_number, $check_row['check_id']); if (!$row || $row['decision'] == AC_DECISION_FAIL) { // no decision or decision of fail if ($error_type == IS_WARNING) { $this->num_of_likely_problems_fail++; } if ($error_type == IS_INFO) { $this->num_of_potential_problems_fail++; } } if (!$row) { if ($this->allow_set_decision == 'true') { $decision_section = str_replace(array("{LINE_NUM}", "{COL_NUM}", "{CHECK_ID}", "{PASS_CHECKED}", "{FAIL_CHECKED}", "{NODECISION_CHECKED}", "{QUESTION}", "{DECISION_PASS}", "{DECISION_FAIL}", "{DECISION_NO}"), array($line_number, $col_number, $check_row['check_id'], "", "", 'checked="checked"', _AC($check_row['question']), _AC($check_row['decision_pass']), _AC($check_row['decision_fail']), _AC('no_decision')), $this->html_decision_not_made); } // generate problem section $problem_section = $this->generate_problem_section($check_row['check_id'], $line_number, $col_number, $html_code, $image, $image_alt, $css_code, _AC($check_row['err']), _AC($check_row['how_to_repair']), $decision_section, $error_type); if ($error_type == IS_WARNING) { $this->rpt_likely_decision_not_made .= $problem_section; } if ($error_type == IS_INFO) { $this->rpt_potential_decision_not_made .= $problem_section; } $this->num_of_no_decisions++; } else { if ($row['decision'] == AC_DECISION_PASS) { $decision = $check_row['decision_pass']; } if ($row['decision'] == AC_DECISION_FAIL) { $decision = $check_row['decision_fail']; } if ($this->allow_set_decision == 'true') { $reverse_decision = str_replace(array("{LABEL_REVERSE_DECISION}", "{LINE_NUM}", "{COL_NUM}", "{CHECK_ID}"), array(_AC('reverse_decision'), $line_number, $col_number, $check_row['check_id']), $this->html_reverse_decision); } $decision_section = str_replace(array("{LABEL_DECISION}", "{QUESTION}", "{DECISION}", "{LABEL_QUESTION}", "{LABEL_USER}", "{LABEL_DATE}", "{DATE}", "{REVERSE_DECISION}"), array(_AC('decision'), _AC($check_row['question']), _AC($decision), _AC('question'), _AC('user'), _AC('date'), $row['last_update'], $reverse_decision), $this->html_decision_made); // generate problem section $problem_section = $this->generate_problem_section($check_row['check_id'], $line_number, $col_number, $html_code, $image, $image_alt, $css_code, _AC($check_row['err']), _AC($check_row['how_to_repair']), $decision_section, $error_type); if ($error_type == IS_WARNING) { $this->rpt_likely_decision_made .= $problem_section; } if ($error_type == IS_INFO) { $this->rpt_potential_decision_made .= $problem_section; } $this->num_of_made_decisions++; } }
/** * private * generate html table rows for all errors on one check * @param * $errors_for_this_check: all errors * $check_id * $confidence: KNOWN, LIKELY, POTENTIAL @ see include/constants.inc.php * @return html table rows */ private function get_table_rows_for_one_check($errors_for_this_check, $check_id, $confidence) { if (!is_array($errors_for_this_check)) { // no problem found for this check return ''; } $th_row = ""; $tr_rows = ""; // generate decision section if ($this->allow_set_decision == 'true' && $confidence != KNOWN) { $th_row = str_replace(array("{PASS_TEXT}", "{SELECT_ALL_TEXT}", "{CHECK_ID}", "{SELECT_ALL_TEXT}"), array(_AC("pass_header"), _AC("select_all"), $check_id, _AC("select_all")), $this->html_tr_header); } foreach ($errors_for_this_check as $error) { $html_image = ""; $msg_type = ""; $img_type = ""; $img_src = ""; if ($confidence == KNOWN) { $this->num_of_errors++; $img_type = _AC('error'); $img_src = "error.png"; } else { if ($confidence == LIKELY) { $this->num_of_likely_problems++; $img_type = _AC('warning'); $img_src = "warning.png"; } else { if ($confidence == POTENTIAL) { $this->num_of_potential_problems++; $img_type = _AC('manual_check'); $img_src = "info.png"; } } } if ($this->show_source == 'true') { $line_number_to_source = '<a href="checker/index.php#line-' . $error["line_number"] . '">' . $error["line_number"] . '</a>'; } else { $line_number_to_source = $error["line_number"]; } // only display first 100 chars of $html_code if (strlen($error["html_code"]) > 100) { $html_code = substr($error["html_code"], 0, 100) . " ..."; } if ($error["image"] != '') { $height = DISPLAY_PREVIEW_IMAGE_HEIGHT; if ($error["image_alt"] == '_NOT_DEFINED') { $alt = ''; } else { if ($error["image_alt"] == '_EMPTY') { $alt = 'alt=""'; } else { $alt = 'alt="' . $error["image_alt"] . '"'; } } $html_image = str_replace(array("{SRC}", "{HEIGHT}", "{ALT}"), array($error["image"], $height, $alt), $this->html_image); } $userDecisionsDAO = new UserDecisionsDAO(); $row = $userDecisionsDAO->getByUserLinkIDAndLineNumAndColNumAndCheckID($this->user_link_id, $error["line_number"], $error["col_number"], $error['check_id']); if (!$row || $row['decision'] == AC_DECISION_FAIL) { // no decision or decision of fail if ($confidence == LIKELY) { $this->num_of_likely_problems_fail++; } if ($confidence == POTENTIAL) { $this->num_of_potential_problems_fail++; } } if ($row && $row['decision'] == AC_DECISION_PASS) { // pass decision has been made, display "congrats" icon $msg_type = "msg_info"; $img_type = _AC('passed_decision'); $img_src = "feedback.gif"; } // generate individual problem string $problem_cell = str_replace(array("{IMG_SRC}", "{IMG_TYPE}", "{LINE_TEXT}", "{LINE_NUMBER}", "{LINE_NUMBER_TO_SOURCE}", "{COL_TEXT}", "{COL_NUMBER}", "{CHECK_ID}", "{HTML_CODE}", "{CSS_CODE}", "{BASE_HREF}", "{IMAGE}"), array($img_src, $img_type, _AC('line'), $error['line_number'], $line_number_to_source, _AC('column'), $error["col_number"], $check_id, htmlentities($error["html_code"], ENT_COMPAT, 'UTF-8'), $error['css_code'], AC_BASE_HREF, $html_image), $this->html_problem); // compose all <tr> rows // checkboxes only appear // 1. when user is login. In other words, user can make decision. // 2. likely or potential reports, not error report if ($this->allow_set_decision == "true" && $confidence != KNOWN) { $checkbox_name = "d[" . $error["line_number"] . "_" . $error["col_number"] . "_" . $error["check_id"] . "]"; $checkbox_html = '<input type="checkbox" class="AC_childCheckBox" id="' . $checkbox_name . '" name="' . $checkbox_name . '" value="1" '; $row_selected = ""; if ($row && $row['decision'] == AC_DECISION_PASS) { $checkbox_html .= 'checked="checked" '; $row_selected = ' class="selected"'; } $checkbox_html .= '/>'; // associate checkbox label $label_start = str_replace("{CHECKBOX_ID}", $checkbox_name, $this->label_start); $problem_cell = str_replace(array("{LABEL_START}", "{LABEL_END}"), array($label_start, $this->label_end), $problem_cell); $tr_rows .= str_replace(array("{ROW_SELECTED}", "{CHECKBOX}", "{PROBLEM_DETAIL}"), array($row_selected, $checkbox_html, $problem_cell), $this->html_tr_with_decision); } else { $problem_cell = str_replace(array("{LABEL_START}", "{LABEL_END}"), array("", ""), $problem_cell); $tr_rows .= str_replace(array("{PROBLEM_DETAIL}"), array($problem_cell), $this->html_tr_without_decision); } } return $th_row . $tr_rows; }
/** * Delete by user ID. This function deletes from tables user_links, user_decisions * @access public * @param user_id : required * @return true, if successful * false and add error into global var $msg, if unsuccessful * @author Cindy Qi Li */ public function DeleteByUserID($userIDs) { // delete customized guidelines created by user but yet open to public include_once AC_INCLUDE_PATH . 'classes/DAO/UserDecisionsDAO.class.php'; $userDecisionsDAO = new UserDecisionsDAO(); // delete according records from table user_decisions if (!$userDecisionsDAO->DeleteByUserIDs($userIDs)) { return false; } $sql = "DELETE FROM " . TABLE_PREFIX . "user_links\n\t\t WHERE user_id in (" . implode(",", $userIDs) . ")"; return $this->execute($sql); }
/** * private * generate array for all errors on one check * @param * $errors_for_this_check: all errors * $check_id * $confidence: KNOWN, LIKELY, POTENTIAL @ see include/constants.inc.php * @return html table rows */ private function get_table_rows_for_one_check($errors_for_this_check, $check_id, $confidence) { if (!is_array($errors_for_this_check)) { // no problem found for this check return ''; } foreach ($errors_for_this_check as $error) { if ($confidence == KNOWN) { $this->nr_known_problems++; $img_type = _AC('error'); $img_src = "error.png"; } else { if ($confidence == LIKELY) { $img_type = _AC('warning'); $img_src = "warning.png"; } else { if ($confidence == POTENTIAL) { $img_type = _AC('manual_check'); $img_src = "info.png"; } } } // only display first 100 chars of $html_code if (strlen($error["html_code"]) > 100) { $html_code = substr($error["html_code"], 0, 100) . " ..."; } if ($error["image"] != '') { $height = DISPLAY_PREVIEW_IMAGE_HEIGHT; if ($error["image_alt"] == '_NOT_DEFINED') { $alt = ''; } else { if ($error["image_alt"] == '_EMPTY') { $alt = 'alt=""'; } else { $alt = 'alt="' . $error["image_alt"] . '"'; } } $error_img['img_src'] = $error["image"]; $error_img['height'] = $height; } $userDecisionsDAO = new UserDecisionsDAO(); $row = $userDecisionsDAO->getByUserLinkIDAndLineNumAndColNumAndCheckID($this->user_link_id, $error["line_number"], $error["col_number"], $error['check_id']); if (!$row || $row['decision'] == AC_DECISION_FAIL) { // no decision or decision of fail if ($confidence == LIKELY) { $this->nr_likely_problems++; } if ($confidence == POTENTIAL) { $this->nr_potential_problems++; } } $passed = FALSE; if (!$row) { $passed = 'none'; } if ($row && $row['decision'] == AC_DECISION_PASS) { // pass decision has been made, display "congrats" icon $msg_type = "msg_info"; $img_type = _AC('passed_decision'); $img_src = "feedback.gif"; $passed = TRUE; } $problem_cell['img_src'] = $img_src; $problem_cell['line_text'] = _AC('line'); $problem_cell['line_nr'] = $error['line_number']; $problem_cell['col_text'] = _AC('column'); $problem_cell['col_nr'] = $error["col_number"]; $problem_cell['check_id'] = $check_id; $problem_cell['html_code'] = htmlentities($error["html_code"], ENT_COMPAT, 'UTF-8'); $problem_cell['css_code'] = $error['css_code']; $problem_cell['base_href'] = AC_BASE_HREF; $problem_cell['error_img'] = $error_img; $problem_cell['test_passed'] = $passed; $array[] = $problem_cell; } return $array; }
/** * private * generate array with decision * parameters: * $check_row: table row of the check * $line_number: line number that the error happens * $col_number: column number that the error happens * $html_tag: html tag that the error happens * $error_type: IS_WARNING or IS_INFO */ private function generate_cell_with_decision($check_row, $line_number, $col_number, $html_code, $image, $image_alt, $error_type) { // generate decision section $userDecisionsDAO = new UserDecisionsDAO(); $row = $userDecisionsDAO->getByUserLinkIDAndLineNumAndColNumAndCheckID($this->user_link_id, $line_number, $col_number, $check_row['check_id']); if (!$row || $row['decision'] == AC_DECISION_FAIL) { // no decision or decision of fail if ($error_type == IS_WARNING) { $this->nr_likely_problems++; } if ($error_type == IS_INFO) { $this->nr_potential_problems++; } } if (!$row) { $decision_section = 'none'; // generate problem section $problem_section = $this->generate_problem_section($check_row['check_id'], $line_number, $col_number, $html_code, $image, $image_alt, $css_code, _AC($check_row['err']), _AC($check_row['how_to_repair']), $decision_section, $error_type); if ($error_type == IS_WARNING) { $this->group_likely_problems_no_decision[] = $problem_section; } if ($error_type == IS_INFO) { $this->group_potential_problems_no_decision[] = $problem_section; } } if ($row && $row['decision'] == AC_DECISION_PASS) { // pass decision has been made, display "congrats" icon $decision_section = TRUE; // generate problem section $problem_section = $this->generate_problem_section($check_row['check_id'], $line_number, $col_number, $html_code, $image, $image_alt, $css_code, _AC($check_row['err']), _AC($check_row['how_to_repair']), $decision_section, $error_type); if ($error_type == IS_WARNING) { $this->group_likely_problems_with_decision[] = $problem_section; } if ($error_type == IS_INFO) { $this->group_potential_problems_with_decision[] = $problem_section; } } if ($row && $row['decision'] == AC_DECISION_FAIL) { // pass decision has been made, display "congrats" icon $decision_section = FALSE; // generate problem section $problem_section = $this->generate_problem_section($check_row['check_id'], $line_number, $col_number, $html_code, $image, $image_alt, $css_code, _AC($check_row['err']), _AC($check_row['how_to_repair']), $decision_section, $error_type); if ($error_type == IS_WARNING) { $this->group_likely_problems_with_decision[] = $problem_section; } if ($error_type == IS_INFO) { $this->group_potential_problems_with_decision[] = $problem_section; } } }
/** * private * main process to generate report in html format */ private function generateRESTRpt() { $num_of_errors = 0; $num_of_likely_problems = 0; $num_of_potential_problems = 0; $checksDAO = new ChecksDAO(); $userDecisionsDAO = new UserDecisionsDAO(); // generate section details foreach ($this->errors as $error) { // generate each error result $result_type = ''; $repair = ''; $decision = ''; $decision_questions = ''; $decision_made = ''; $row_check = $checksDAO->getCheckByID($error["check_id"]); if ($row_check["confidence"] == KNOWN) { // only known errors have <repair> $num_of_errors++; $result_type = _AC('error'); $repair = str_replace('{REPAIR}', htmlentities(_AC($row_check["how_to_repair"])), $this->rest_repair); } else { // generate user's decision. only likely and potential problems have decisions to make $row_userDecision = $userDecisionsDAO->getByUserLinkIDAndLineNumAndColNumAndCheckID($this->userLinkID, $error["line_number"], $error["col_number"], $error['check_id']); if ($row_userDecision['decision'] == AC_DECISION_PASS || $row_userDecision['decision'] == AC_DECISION_FAIL) { if ($row_userDecision['decision'] == AC_DECISION_PASS) { $decision_text = _AC('pass'); } if ($row_userDecision['decision'] == AC_DECISION_FAIL) { $decision_text = _AC('fail'); } $decision_made = str_replace(array('{DECISIONMADE}', '{DECISIONMADEDATE}'), array(htmlentities($decision_text), $row_userDecision['last_update']), $this->rest_decision_made); } if ($row_check["confidence"] == LIKELY) { $result_type = _AC('likely_problem'); if (!$row_userDecision || $row_userDecision['decision'] == AC_DECISION_FAIL) { $num_of_likely_problems++; } } if ($row_check["confidence"] == POTENTIAL) { $result_type = _AC('potential_problem'); if (!$row_userDecision || $row_userDecision['decision'] == AC_DECISION_FAIL) { $num_of_potential_problems++; } } $decision_questions = str_replace(array('{SEQUENCEID}', '{DECISIONPASS}', '{DECISIONFAIL}'), array($error['line_number'] . '_' . $error['col_number'] . '_' . $error['check_id'], htmlentities(_AC($row_check['decision_pass'])), htmlentities(_AC($row_check['decision_fail']))), $this->rest_decision_questions); $decision = $decision_questions . $decision_made; // end of generating user's decision } $result .= str_replace(array('{RESULTTYPE}', '{LINENUM}', '{COLUMNNUM}', '{BASE_HREF}', '{CHECK_ID}', '{TITLE}', '{ERRORMSG}', '{ERRORSOURCECODE}', '{REPAIR}', '{DECISION}'), array($result_type, $error["line_number"], $error["col_number"], htmlentities(AC_BASE_HREF), $error['check_id'], htmlentities(_AC("suggest_improvements")), htmlentities(_AC($row_check['err'])), htmlentities($error["html_code"], ENT_QUOTES, "UTF-8"), $repair, $decision), $this->rest_result); } // retrieve session id $userLinksDAO = new UserLinksDAO(); $row = $userLinksDAO->getByUserLinkID($this->userLinkID); $sessionID = $row['last_sessionID']; // generate guidelines $guidelinesDAO = new GuidelinesDAO(); foreach ($this->guidelineArray as $gid) { $row_guideline = $guidelinesDAO->getGuidelineByIDs($gid); $guidelines .= str_replace('{GUIDELINE}', htmlentities($row_guideline[0]['title']), $this->rest_guideline); } // find out result status: pass, fail, conditional pass if ($num_of_errors > 0) { $status = _AC('fail'); } else { if ($num_of_likely_problems + $num_of_potential_problems > 0) { $status = _AC('conditional_pass'); } else { $status = _AC('pass'); } } // generate final output $this->output = str_replace(array('{STATUS}', '{SESSIONID}', '{NUMOFERRORS}', '{NUMOFLIKELYPROBLEMS}', '{NUMOFPOTENTIALPROBLEMS}', '{GUIDELINES}', '{RESULTS}'), array($status, $sessionID, $num_of_errors, $num_of_likely_problems, $num_of_potential_problems, $guidelines, $result), $this->rest_main); }