}
// handle submit
if (isset($_POST['cancel'])) {
    header('Location: index.php');
    exit;
} else {
    if (isset($_POST['save']) || isset($_POST['save_and_close'])) {
        // check syntax
        $func = $stripslashes(trim($_POST['func']));
        if (!CheckFuncUtility::validateSyntax($func)) {
            $msg->addError('SYNTAX_ERROR');
        }
        // Prevent the php built-in functions and php super global variables
        // being called in the check function. Only allows the AChecker-defined
        // check functions being called for the security concern.
        CheckFuncUtility::validateSecurity($func);
        if (!$msg->containsErrors()) {
            $checksDAO = new ChecksDAO();
            $checksDAO->setFunction($check_id, $func);
            $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
            if (isset($_POST['save_and_close'])) {
                header('Location: index.php');
            } else {
                header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $check_id);
            }
            exit;
        }
    }
}
// end of handle submit
// initialize page
 /** private
  * set global vars used in Checks.class.php and BasicFunctions.class.php
  * to fasten the validation process.
  * return nothing.
  */
 private function prepare_global_vars()
 {
     global $header_array, $base_href;
     // find all header tags which are used in BasicFunctions.class.php
     $header_array = $this->content_dom->find("h1, h2, h3, h4, h5, h6, h7");
     // find base href, used to check image size
     $all_base_elements = $this->content_dom->find("base");
     if (is_array($all_base_elements)) {
         foreach ($all_base_elements as $base) {
             if (isset($base->attr['href'])) {
                 $base_href = $base->attr['href'];
                 break;
             }
         }
     }
     // set all check functions
     $checksDAO = new ChecksDAO();
     $rows = $checksDAO->getAllOpenChecks();
     if (is_array($rows)) {
         foreach ($rows as $row) {
             $this->check_func_array[$row['check_id']] = CheckFuncUtility::convertCode($row['func']);
         }
     }
 }