X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fajax.inc;h=a8a6981c8553e43c3dda82892094ddebea097e70;hb=8864b1ec0fd3321e510511ef22614bc36845540e;hp=5625fc900c3ba1c3bbda674de07d90f70cf26e30;hpb=b5c4ed7811678c840effecca17be1cce7931d0c4;p=fa-stable.git diff --git a/includes/ajax.inc b/includes/ajax.inc index 5625fc90..a8a6981c 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -1,4 +1,14 @@ . +***********************************************************************/ 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) @@ -106,17 +122,26 @@ class Ajax extends JsHttpRequest { // remove not active commands foreach ($this->aCommands as $idx => $com) { - // display_error( $idx.':'.var_dump($com)); // If we should reload whole page content ignore all commands but the update. // This is page repost equivalent, although header and footer are not reloaded. + if ($com['why'] !== true && !isset($this->triggers[$com['why']])) { + unset($this->aCommands[$idx]); +// display_error('unset '.$com['t']); + } + 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; } - else - if ($com['why'] !== true && !isset($this->triggers[$com['why']])) - unset($this->aCommands[$idx]); } +// display_error('Activate:'.htmlentities(print_r($this->triggers, true))); +// display_error('Commands :'.htmlentities(print_r($this->aCommands, true))); $GLOBALS['_RESULT'] = $this->aCommands; // exit(); } @@ -127,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; +} ?>