Changed license type to GPLv3 in top of files
[fa-stable.git] / includes / ajax.inc
index c07bea6809e25896c0e194f12214d9fa55369b66..a8a6981c8553e43c3dda82892094ddebea097e70 100644 (file)
@@ -1,4 +1,14 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
 require_once($path_to_root. "/includes/JsHttpRequest.php");
 
 class Ajax extends JsHttpRequest {
@@ -25,11 +35,17 @@ 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'), absolute_url($url));
+       }
+       //
        // Adds an executable Javascript code.
        //
        function addScript($trigger, $sJS)
@@ -114,7 +130,13 @@ class Ajax extends JsHttpRequest {
                  }
                  else
                  if($com['n'] == 'up' && $com['t'] == '_page_body') {
-                         $this->aCommands = array($com);
+                         $cmds = array($com);
+                         foreach( $this->aCommands as $k=> $cmd) {
+                               if ($cmd['n'] == 'fc') {        // save focus
+                                       $cmds[] = $cmd; break;
+                               }
+                         }
+                         $this->aCommands = $cmds;
                          break;
                  }
                }
@@ -130,4 +152,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;
+}
 ?>