added function for setting the uri vars ([&\?] something=value.
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 5 Jul 2002 10:40:30 +0000 (10:40 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 5 Jul 2002 10:40:30 +0000 (10:40 +0000)
By using $PHP_SELF and the specified var and value we no longer need to set
all the vars by hand. Just use this function and it only alters / remove the
specified var.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3032 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/html.php

index 6666cd6..40799d2 100644 (file)
@@ -22,7 +22,7 @@
        GLOBAL $languages, $squirrelmail_language;
        
        $align = strtolower( $align );
-       $dir   = strtolower( $dir );
+       $bgc = '';
        $tag = strtoupper( $tag );
        
        if ( isset( $languages[$squirrelmail_language]['DIR']) ) {
         return( $ret );
     }
 
-?>
\ No newline at end of file
+    /* handy function to set url vars */
+    /* especially usefull when $url = $PHP_SELF */
+    function set_url_var($url, $var, $val=0) {
+      $k = '';
+      $ret = '';
+      $url = trim(preg_replace('/&amp;/','&',$url));
+
+      $pat_a = array (
+                       '/.+(\\&'.$var.')=(.*)\\&/AU',   /* in the middle */
+                      '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
+                      '/.+(\\?'.$var.')=(.*)$/AU',     /* at front and only var */
+                      '/.+(\\&'.$var.')=(.*)$/AU'      /* at the end */
+                    );
+      switch (true) {
+        case (preg_match($pat_a[0],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+         break;
+        case (preg_match($pat_a[1],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+         break;
+       case (preg_match($pat_a[2],$url,$regs)): 
+          $k = $regs[1];
+          $v = $regs[2];
+         break;
+        case (preg_match($pat_a[3],$url,$regs)):
+          $k = $regs[1];
+          $v = $regs[2];
+         break;
+       default:
+          if ($val) {
+            if (strpos($url,'?')) {
+           
+    $url .= "&$var=$val";
+           } else {
+           
+   $url .= "?$var=$val";
+           }   
+          }
+         break;
+      }
+
+      if ($k) {
+        if ($val) {
+           $pat = "/$k=$v/";
+          $rpl = "$k=$val";
+          echo "<B>$pat , $rpl </b><BR>";
+           $url = preg_replace($pat,$rpl,$url);
+        } else {
+           $pat = "/$k=$v/";
+           $url = preg_replace($pat,'',$url);
+        }
+      }        
+      return  preg_replace('/&/','&amp;',$url);
+    } 
+
+?>