function ShowError($error_code, $error_mesg, $b_user_error, $b_alerted = false, $a_item_list = array(), $s_extra_info = "")
{
    global $SPECIAL_FIELDS, $SPECIAL_MULTI, $SPECIAL_VALUES;
    global $aServerVars, $aStrippedFormVars;
    //
    // Testing with PHP 4.0.6 indicates that sessions don't always work.
    // So, we'll also add the error to the URL, unless
    // PUT_DATA_IN_URL is false.
    //
    SetSession("FormError", $error_mesg);
    SetSession("FormErrorInfo", $s_extra_info);
    SetSession("FormErrorCode", $error_code);
    SetSession("FormErrorItems", $a_item_list);
    SetSession("FormIsUserError", $b_user_error);
    SetSession("FormAlerted", $b_alerted);
    SetSession("FormData", array());
    $bad_url = $SPECIAL_VALUES["bad_url"];
    $bad_template = $SPECIAL_VALUES["bad_template"];
    $this_form = $SPECIAL_VALUES["this_form"];
    if (IsAjax()) {
        JSON_Result("ERROR", array("ErrorCode" => $error_code, "UserError" => $b_user_error, "ErrorMesg" => $error_mesg, "Alerted" => $b_alerted, "ErrorItems" => $a_item_list));
        ZapSession();
    } elseif (!empty($bad_url)) {
        $a_params = array();
        if (PUT_DATA_IN_URL) {
            $a_params[] = "this_form=" . urlencode("{$this_form}");
            $a_params[] = "bad_template=" . urlencode("{$bad_template}");
            $a_params[] = "error=" . urlencode("{$error_mesg}");
            $a_params[] = "extra=" . urlencode("{$s_extra_info}");
            $a_params[] = "errcode=" . urlencode("{$error_code}");
            $a_params[] = "isusererror=" . ($b_user_error ? "1" : "0");
            $a_params[] = "alerted=" . ($b_alerted ? "1" : "0");
            $i_count = 1;
            foreach ($a_item_list as $s_item) {
                $a_params[] = "erroritem{$i_count}=" . urlencode("{$s_item}");
                $i_count++;
            }
        } else {
            $a_sess_data = GetSession("FormData");
            $a_sess_data["this_form"] = "{$this_form}";
            $a_sess_data["bad_template"] = "{$bad_template}";
            SetSession("FormData", $a_sess_data);
            //
            // tell the bad_url to look in the session only
            //
            $a_params[] = "insession=1";
        }
        //
        // Add the posted data to the URL so that an intelligent
        // $bad_url can call the form again
        //
        foreach ($aStrippedFormVars as $s_name => $m_value) {
            //
            // skip special fields
            //
            $b_special = false;
            if (in_array($s_name, $SPECIAL_FIELDS)) {
                $b_special = true;
            } else {
                foreach ($SPECIAL_MULTI as $s_multi_fld) {
                    $i_len = strlen($s_multi_fld);
                    if (substr($s_name, 0, $i_len) == $s_multi_fld) {
                        $i_index = (int) substr($s_name, $i_len);
                        if ($i_index > 0) {
                            $b_special = true;
                            break;
                        }
                    }
                }
            }
            if (!$b_special) {
                if (PUT_DATA_IN_URL) {
                    if (is_array($m_value)) {
                        foreach ($m_value as $s_value) {
                            $a_params[] = "{$s_name}" . '[]=' . urlencode(substr($s_value, 0, MAXSTRING));
                        }
                    } else {
                        $a_params[] = "{$s_name}=" . urlencode(substr($m_value, 0, MAXSTRING));
                    }
                } else {
                    $a_sess_data = GetSession("FormData");
                    if (is_array($m_value)) {
                        $a_sess_data["{$s_name}"] = $m_value;
                    } else {
                        $a_sess_data["{$s_name}"] = substr($m_value, 0, MAXSTRING);
                    }
                    SetSession("FormData", $a_sess_data);
                }
            }
        }
        //
        // Now add the authentication data, if any
        //
        if (isset($aServerVars["PHP_AUTH_USER"]) && $aServerVars["PHP_AUTH_USER"] !== "" || isset($aServerVars["PHP_AUTH_PW"]) && $aServerVars["PHP_AUTH_PW"] !== "") {
            if (PUT_DATA_IN_URL) {
                if (isset($aServerVars["PHP_AUTH_USER"])) {
                    $a_params[] = "PHP_AUTH_USER="******"PHP_AUTH_USER"]);
                }
                if (isset($aServerVars["PHP_AUTH_PW"])) {
                    $a_params[] = "PHP_AUTH_PW=" . urlencode($aServerVars["PHP_AUTH_PW"]);
                }
                if (isset($aServerVars["PHP_AUTH_TYPE"])) {
                    $a_params[] = "PHP_AUTH_TYPE=" . urlencode($aServerVars["PHP_AUTH_TYPE"]);
                }
            } else {
                $a_sess_data = GetSession("FormData");
                if (isset($aServerVars["PHP_AUTH_USER"])) {
                    $a_sess_data["PHP_AUTH_USER"] = $aServerVars["PHP_AUTH_USER"];
                }
                if (isset($aServerVars["PHP_AUTH_PW"])) {
                    $a_sess_data["PHP_AUTH_PW"] = $aServerVars["PHP_AUTH_PW"];
                }
                if (isset($aServerVars["PHP_AUTH_TYPE"])) {
                    $a_sess_data["PHP_AUTH_TYPE"] = $aServerVars["PHP_AUTH_TYPE"];
                }
                SetSession("FormData", $a_sess_data);
            }
        }
        $bad_url = AddURLParams($bad_url, $a_params, false);
        Redirect($bad_url, GetMessage(MSG_FORM_ERROR));
    } else {
        if (!empty($bad_template)) {
            $a_specs = array("fmerror" => htmlspecialchars("{$error_mesg}"), "fmerrorcode" => htmlspecialchars("{$error_code}"), "fmfullerror" => htmlspecialchars("{$error_mesg}") . "\n" . htmlspecialchars("{$s_extra_info}"), "fmerrorextra" => htmlspecialchars("{$s_extra_info}"));
            for ($i_count = 1; $i_count <= 20; $i_count++) {
                $a_specs["fmerroritem{$i_count}"] = "";
            }
            $i_count = 1;
            foreach ($a_item_list as $s_item) {
                $a_specs["fmerroritem{$i_count}"] = htmlspecialchars($s_item);
                $i_count++;
            }
            $s_list = "";
            foreach ($a_item_list as $s_item) {
                $s_list .= "<li>" . htmlspecialchars($s_item) . "</li>";
            }
            $a_specs["fmerroritemlist"] = $s_list;
            if (ShowErrorTemplate($bad_template, $a_specs, $b_user_error)) {
                return;
            }
        }
        $s_text = GetMessage(MSG_ERROR_PROC);
        if ($b_user_error) {
            $s_text .= $error_mesg . "\n" . FixedHTMLEntities($s_extra_info);
        } else {
            global $SERVER;
            if ($b_alerted) {
                $s_text .= GetMessage(MSG_ALERT_DONE, array("SERVER" => $SERVER));
            } else {
                $s_text .= GetMessage(MSG_PLS_CONTACT, array("SERVER" => $SERVER));
            }
            $s_text .= GetMessage(MSG_APOLOGY, array("SERVER" => $SERVER));
        }
        CreatePage($s_text, GetMessage(MSG_FORM_ERROR), false);
        //
        // the session data is not needed now
        //
        ZapSession();
    }
}
Esempio n. 2
0
function ShowError($error_code, $error_mesg, $b_user_error, $b_alerted = false, $a_item_list = array(), $s_extra_info = "")
{
    global $SPECIAL_FIELDS, $SPECIAL_MULTI, $SPECIAL_VALUES, $aSessionVars, $aStrippedFormVars;
    //
    // Testing with PHP 4.0.6 indicates that sessions don't always work.
    // So, we'll also add the error to the URL, unless
    // PUT_DATA_IN_URL is false.
    //
    $aSessionVars["FormError"] = $error_mesg;
    $aSessionVars["FormErrorInfo"] = $s_extra_info;
    $aSessionVars["FormErrorCode"] = $error_code;
    $aSessionVars["FormErrorItems"] = $a_item_list;
    $aSessionVars["FormIsUserError"] = $b_user_error;
    $aSessionVars["FormAlerted"] = $b_alerted;
    $aSessionVars["FormData"] = array();
    $bad_url = $SPECIAL_VALUES["bad_url"];
    $bad_template = $SPECIAL_VALUES["bad_template"];
    $this_form = $SPECIAL_VALUES["this_form"];
    if (!empty($bad_url)) {
        $a_params = array();
        $a_params[] = "this_form=" . urlencode("{$this_form}");
        $a_params[] = "bad_template=" . urlencode("{$bad_template}");
        if (PUT_DATA_IN_URL) {
            $a_params[] = "error=" . urlencode("{$error_mesg}");
            $a_params[] = "extra=" . urlencode("{$s_extra_info}");
            $a_params[] = "errcode=" . urlencode("{$error_code}");
            $a_params[] = "isusererror=" . ($b_user_error ? "1" : "0");
            $a_params[] = "alerted=" . ($b_alerted ? "1" : "0");
            $i_count = 1;
            foreach ($a_item_list as $s_item) {
                $a_params[] = "erroritem{$i_count}=" . urlencode("{$s_item}");
                $i_count++;
            }
        } else {
            //
            // tell the bad_url to look in the session only
            //
            $a_params[] = "insession=1";
        }
        //
        // Add the posted data to the URL so that an intelligent
        // $bad_url can call the form again
        //
        foreach ($aStrippedFormVars as $s_name => $m_value) {
            //
            // skip special fields
            //
            $b_special = false;
            if (in_array($s_name, $SPECIAL_FIELDS)) {
                $b_special = true;
            } else {
                foreach ($SPECIAL_MULTI as $s_multi_fld) {
                    $i_len = strlen($s_multi_fld);
                    if (substr($s_name, 0, $i_len) == $s_multi_fld) {
                        $i_index = (int) substr($s_name, $i_len);
                        if ($i_index > 0) {
                            $b_special = true;
                            break;
                        }
                    }
                }
            }
            if (!$b_special) {
                if (PUT_DATA_IN_URL) {
                    if (is_array($m_value)) {
                        foreach ($m_value as $s_value) {
                            $a_params[] = "{$s_name}" . '[]=' . urlencode(substr($s_value, 0, MAXSTRING));
                        }
                    } else {
                        $a_params[] = "{$s_name}=" . urlencode(substr($m_value, 0, MAXSTRING));
                    }
                } else {
                    if (is_array($m_value)) {
                        $aSessionVars["FormData"]["{$s_name}"] = $m_value;
                    } else {
                        $aSessionVars["FormData"]["{$s_name}"] = substr($m_value, 0, MAXSTRING);
                    }
                }
            }
        }
        $bad_url = AddURLParams($bad_url, $a_params, false);
        Redirect($bad_url);
    } else {
        if (!empty($bad_template)) {
            $a_specs = array("fmerror" => htmlspecialchars("{$error_mesg}"), "fmerrorcode" => htmlspecialchars("{$error_code}"), "fmfullerror" => htmlspecialchars("{$error_mesg}") . "\n" . htmlspecialchars("{$s_extra_info}"), "fmerrorextra" => htmlspecialchars("{$s_extra_info}"));
            $i_count = 1;
            foreach ($a_item_list as $s_item) {
                $a_specs["fmerroritem{$i_count}"] = htmlspecialchars($s_item);
                $i_count++;
            }
            $s_list = "";
            foreach ($a_item_list as $s_item) {
                $s_list .= "<li>" . htmlspecialchars($s_item) . "</li>\n";
            }
            $a_specs["fmerroritemlist"] = $s_list;
            if (ShowTemplate($bad_template, $a_specs)) {
                return;
            }
        }
        $s_text = GetMessage(MSG_ERROR_PROC);
        if ($b_user_error) {
            $s_text .= $error_mesg . "\n" . $s_extra_info;
        } else {
            if ($b_alerted) {
                $s_text .= GetMessage(MSG_ALERT_DONE);
            } else {
                $s_text .= GetMessage(MSG_PLS_CONTACT);
            }
            $s_text .= GetMessage(MSG_APOLOGY);
        }
        CreatePage($s_text);
        //
        // the session data is not needed now
        //
        ZapSession();
    }
}