Code

Do not remove invalid user accounts.
[gosa.git] / include / accept-to-gettext.inc
index f04bb4f0b5a243e8c5b85808c776fef83cf4d587..ff8e2425e3ac7cae29d47c7ed925f31d6de61906 100644 (file)
@@ -84,17 +84,27 @@ function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval,
 }
 
 
-function al2gt($gettextlangs, $mime) {
-  error_reporting(0);
+function al2gt($gettextlangs, $mime) 
+{
+  /* Check if ACCEPT_LANGUAGE isset */
+  if(!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
+    $_SERVER["HTTP_ACCEPT_LANGUAGE"] = "";
+  }
+  if(!isset($_SERVER["HTTP_ACCEPT_CHARSET"])){
+    $_SERVER["HTTP_ACCEPT_CHARSET"] = "";
+  }
 
   /* default to "everything is acceptable", as RFC2616 specifies */
   $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' :
     $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
-  $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' :
+  /* Commented out due to problems with IE7, defaulting to the one below... */
+  #$acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' :
+  #  $_SERVER["HTTP_ACCEPT_CHARSET"]);
+  $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' :
     $_SERVER["HTTP_ACCEPT_CHARSET"]);
   $alparts=@preg_split("/,/",$acceptLang);
   $acparts=@preg_split("/,/",$acceptChar);
-  
+
   /* Parse the contents of the Accept-Language header.*/
   foreach($alparts as $part) {
     $part=trim($part);
@@ -149,6 +159,21 @@ function al2gt($gettextlangs, $mime) {
     $gtcs=strtoupper($tmp2[1]);
     $noct=@preg_split("/-/",$allang);
 
+    if(!isset($alscores["*"])){
+      $alscores["*"] = "";
+    }
+
+    if(!isset($alscores[$allang])){
+      $alscores[$allang] = "";
+    }
+    
+    if(!isset($alscores[$noct[0]])){
+      $alscores[$noct[0]] = "";
+    }
+  
+    if(!isset($acscores[$gtcs])){
+      $acscores[$gtcs] = "";
+    }
     $testvals=array(
         array($alscores[$allang], $acscores[$gtcs]),
         array($alscores[$noct[0]], $acscores[$gtcs]),
@@ -172,17 +197,18 @@ function al2gt($gettextlangs, $mime) {
 
   /* We must re-parse the gettext-string now, since we may have found it
    * through a "*" qualifier.*/
-  
   $gtparts=@preg_split("/\./",$curgtlang);
   $tmp=strtolower($gtparts[0]);
   $lang=preg_replace("/\_/", "-", $tmp);
-  $charset=$gtparts[1];
-
-  header("Content-Language: $lang");
-  header("Content-Type: $mime; charset=$charset");
-
-  error_reporting(E_ALL);
+  if (!headers_sent()){
+    header("Content-Language: $lang");
+    if(isset($gtparts[1])){
+      $charset=$gtparts[1];
+      header("Content-Type: $mime; charset=$charset");
+    }
+  }
   return $curgtlang;
 }
 
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>