コード例 #1
0
 function ShowTemplate($s_name, $a_specs)
 {
     global $TEMPLATEURL, $TEMPLATEDIR, $bIsUserError, $bAlerted, $aGetVars;
     global $php_errormsg;
     if (empty($TEMPLATEDIR) && empty($TEMPLATEURL)) {
         ReportError("neither TEMPLATEDIR nor TEMPLATEURL is set");
         return false;
     }
     if (!empty($TEMPLATEDIR)) {
         $s_name = "{$TEMPLATEDIR}/" . basename($s_name);
         @($fp = fopen($s_name, "r"));
         if ($fp === false) {
             ReportError("Cannot open template '{$s_name}': {$php_errormsg}");
             return false;
         }
         //
         // load the whole template into a string
         //
         $s_buf = fread($fp, filesize($s_name));
         fclose($fp);
     } else {
         $s_name = AddUserAgent("{$TEMPLATEURL}/" . basename($s_name));
         if (session_id() !== "") {
             $s_name = AddURLParam($s_name, "sessid=" . urlencode(session_id()));
         }
         if (defined("SID")) {
             $s_name = AddURLParam($s_name, SID);
         }
         @($fp = fopen($s_name, "r"));
         if ($fp === false) {
             ReportError("Cannot open template '{$s_name}': {$php_errormsg}");
             return false;
         }
         //
         // load the whole template into a string
         //
         $s_buf = "";
         while (!feof($fp)) {
             $s_buf .= fread($fp, 4096);
         }
         fclose($fp);
     }
     //
     // now look for the tags to replace
     //
     foreach ($a_specs as $s_tag => $s_value) {
         //
         // search for
         //		<tagname/>
         // with optional whitespace
         //
         $s_buf = preg_replace('/<\\s*' . preg_quote($s_tag, "/") . '\\s*\\/\\s*>/ims', nl2br($s_value), $s_buf);
     }
     if ($bIsUserError) {
         //
         // put the form link just before the </body> end tag or replace
         // a <return_link/> tag
         //
         $s_link = GetFormLink($s_url);
         if (!empty($s_link)) {
             //
             // Replace any "$return_link" strings with the
             // return link URL.
             //
             if (preg_match('/\\$return_link\\b/ms', $s_buf) > 0) {
                 $s_buf = preg_replace('/\\$return_link\\b/ms', "{$s_url}", $s_buf);
             } else {
                 //
                 // Look for a "<return_link/>" tag and replace that.
                 // If it doesn't exist, put the return link before
                 // the body end tag.
                 //
                 if (preg_match('/<\\s*return_link\\s*\\/\\s*>/ims', $s_buf) > 0) {
                     $s_buf = preg_replace('/<\\s*return_link\\s*\\/\\s*>/ims', "{$s_link}\n", $s_buf);
                 } else {
                     $s_buf = preg_replace('/<\\s*\\/\\s*body\\s*>/ims', "{$s_link}\n" . '$0', $s_buf);
                 }
             }
         }
         // strip any <fmusererror> and </fmusererror> tags
         //
         // You can show information that's specific to user
         // errors between these special tags.
         //
         $s_buf = preg_replace('/<\\s*\\/?\\s*fmusererror\\s*>/ims', '', $s_buf);
         //
         // since this isn't a system error, strip anything between
         // <fmsyserror> and </fmsyserror>
         //
         $s_buf = preg_replace('/<\\s*fmsyserror\\s*>.*<\\s*\\/\\s*fmsyserror\\s*>/ims', '', $s_buf);
     } else {
         // strip any <fmsyserror> and </fmsyserror> tags
         //
         // You can show information that's specific to system
         // errors between these special tags.
         //
         $s_buf = preg_replace('/<\\s*\\/?\\s*fmsyserror\\s*>/ims', '', $s_buf);
         //
         // since this isn't a user error, strip anything between
         // <fmusererror> and </fmusererror>
         //
         $s_buf = preg_replace('/<\\s*fmusererror\\s*>.*<\\s*\\/\\s*fmusererror\\s*>/ims', '', $s_buf);
     }
     //
     // output the modified page
     //
     echo $s_buf;
     return true;
 }
コード例 #2
0
function ProcessReturnToForm($s_url, $a_values, $a_strip = array())
{
    global $php_errormsg;
    //
    // read the original form, and modify it to provide values
    // for the fields
    //
    if (!CheckValidURL($s_url)) {
        Error("invalid_url", GetMessage(MSG_RETURN_URL_INVALID, array("URL" => $s_url)), false, false);
    }
    $s_form_url = AddUserAgent($s_url);
    $s_error = "";
    $s_form_buf = GetURL($s_form_url, $s_error);
    if ($s_form_buf === false) {
        Error("invalid_url", GetMessage(MSG_OPEN_URL, array("URL" => $s_form_url, "ERROR" => $s_error . ": " . (isset($php_errormsg) ? $php_errormsg : ""))), false, false);
    }
    //
    // Next, we replace or set actual field values.
    //
    echo SetPreviousValues($s_form_buf, $a_values, $a_strip);
}
コード例 #3
0
ファイル: InfoCapture.php プロジェクト: JGrubb/Almond-Tree
function ProcessReturnToForm($s_url, $a_values)
{
    global $aSubstituteErrors, $aSubstituteValues, $sSubstituteMissing;
    global $php_errormsg;
    //
    // read the original form, and modify it to provide values
    // for the fields
    //
    if (!CheckValidURL($s_url)) {
        Error("invalid_url", GetMessage(MSG_RETURN_URL_INVALID, array("URL" => $s_url)), false, false);
    }
    $s_form_url = AddUserAgent($s_url);
    $s_error = "";
    $s_form_buf = GetURL($s_form_url, $s_error);
    if ($s_form_buf === false) {
        Error("invalid_url", GetMessage(MSG_OPEN_URL, array("URL" => $s_form_url, "ERROR" => $s_error . ": " . (isset($php_errormsg) ? $php_errormsg : ""))), false, false);
    }
    /*****
            This is not correct here, because this function is only called
            for non-template URLs.
            //
            // First, we do any "$var" substitutions
            //
    
            //
            // initialize the errors list
            //
        $aSubstituteErrors = array();
            //
            // initialize the values
            //
        $aSubstituteValues = $a_values;
        $sSubstituteMissing = $s_missing;
    
            //
            // search for words in this form:
            //      $word
            // where word begins with an alphabetic character and
            // consists of alphanumeric and underscore
            //
    //    $s_form_buf = preg_replace_callback('/\$([a-z][a-z0-9_]*)/i',
    //                                      'SubstituteValueForPage',$s_form_buf);
    
    //  SendAlert("Error count=".count($aSubstituteErrors));
        if (count($aSubstituteErrors) != 0)
            Error("template_failed",
                        GetMessage(MSG_TEMPLATE_ERRORS,array("NAME"=>$s_template)).
                                implode("\n",$aSubstituteErrors),false,false);
        ******/
    //
    // Next, we replace or set actual field values.
    //
    echo SetPreviousValues($s_form_buf, $a_values);
}