Fixed ajax popup/redirection.
[fa-stable.git] / includes / ajax.inc
index ce8c965519e3ab62f0429649e8f0d50fe4ca4808..b95d1928a353b702c882b1c266eed11b43b2e117 100644 (file)
@@ -25,15 +25,15 @@ class Ajax extends JsHttpRequest {
        //
        function redirect($url) {
            if(in_ajax()) {
-                       $this->_addCommand(true, array('n'=>'rd'),$url);
-                 $this->run();
+                       $this->_addCommand(true, array('n'=>'rd'), absolute_url($url));
+                       $this->run();
            }
        }
        //
        // Popup window (target=_blank)
        //
        function popup($url) {
-                 $this->_addCommand(true, array('n'=>'pu'),$url);
+                 $this->_addCommand(true, array('n'=>'pu'), absolute_url($url));
        }
        //
        // Adds an executable Javascript code.
@@ -142,4 +142,11 @@ function in_ajax() {
     return $Ajax->isActive();
 }
 
+// Returns absolute path of relative $url. To be used in ajax calls
+// for proper redirection from any referer page.
+//
+function absolute_url($url) 
+{
+   return strpos($url, '..')===0 ? dirname($_SERVER['PHP_SELF']).'/'.$url : $url;
+}
 ?>