diff common-functions.inc @ 5:18aafb1a8986

Better handling of errors and globals.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 20 May 2011 13:25:53 +0200
parents 74196528fc64
children 6c0162497d56
line wrap: on
line diff
--- a/common-functions.inc	Thu May 19 18:04:33 2011 +0200
+++ b/common-functions.inc	Fri May 20 13:25:53 2011 +0200
@@ -1,4 +1,6 @@
 <?php
+include_once 'http-response-status-codes.inc';
+
 function loadFile($sFilename, $sCharset = 'UTF-8')
 {
     if (floatval(phpversion()) >= 4.3) {
@@ -21,4 +23,32 @@
     }
     return $sData;
 }
-?>
+
+function errorPage($errorText, $errorCode=403)
+{
+  header(StatusCodes::httpHeaderFor($errorCode));
+  print "<div id=\"page\"><h1>${errorText}</h1></div>";
+  exit;
+}
+
+function genUrl($keys=array()) {
+	 $out="?";
+	 $first=1;
+	 $URL_PARAMS=$GLOBALS['URL_PARAMS'];
+	 $new_params=array();
+	 foreach($URL_PARAMS as $param) {
+		 $new_params[$param]=$GLOBALS[$param];
+	 }
+	 foreach($keys as $param => $val) {
+		 $new_params[$param]=$val;
+	 }
+	 foreach($new_params as $param => $val) {
+	         if($first) 
+		   $first=0;
+		 else 
+		   $out.="&amp;";	     
+	 	 $out.=urlencode($param).'='.urlencode($val);
+	 }
+	 return $out;
+}
+?>
\ No newline at end of file