Support for calling external pages during document entry (e.g. for adding/viewing...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 18 Sep 2008 19:43:52 +0000 (19:43 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 18 Sep 2008 19:43:52 +0000 (19:43 +0000)
includes/ui/ui_controls.inc
includes/ui/ui_input.inc
includes/ui/ui_lists.inc
index.php
js/inserts.js

index c9bae54f55133455af9b2abbbdee89584545512f..1883ba2aeafc12ebdff7334f7161f8ddb0aa1ac8 100644 (file)
@@ -53,7 +53,8 @@ function meta_forward($forward_to, $params="")
        echo "<meta http-equiv='Refresh' content='0; url=$forward_to?$params'>\n";
        echo "<center><br>" . _("You should automatically be forwarded.");
        echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
-       $Ajax->redirect($forward_to.'?'.$params);
+       if ($params !='') $params = '?'.$params;
+       $Ajax->redirect($forward_to.$params);
        exit;
 }
 
@@ -163,15 +164,21 @@ function delete_link_cell($param, $title=false)
        .($title ? " title='$title'":'') .">" . _("Delete") . "</a>", "nowrap");
 }
 
-function edit_button_cell($name, $value, $title=false)
+function edit_button($name, $value, $title=false)
 {
 // php silently changes dots,spaces,'[' and characters 128-159
 // to underscore in POST names, to maintain compatibility with register_globals
-
-    label_cell("<input type=\"submit\" class=\"editbutton\" name=\""
+       echo "<input type=\"submit\" class=\"editbutton\" name=\""
                .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
                ."\" value=\"$value\""
-               .($title ? " title='$title'":'')." />\n");
+               .($title ? " title='$title'":'')." />\n";
+}
+
+function edit_button_cell($name, $value, $title=false)
+{
+       echo "<td>";
+       edit_button($name, $value, $title);
+       echo "</td>";
 }
 
 //-----------------------------------------------------------------------------------
@@ -223,4 +230,79 @@ function div_end()
                echo "</div>";
     }
 }
+
+/*
+       External page call with saving current context.
+       $call - url of external page
+       $ctx - optional. name of SESSION context object or array of names of POST 
+               variables saved on call
+*/
+function context_call($call, $ctx='')
+{
+       if (is_array($ctx)) 
+       {
+               foreach($ctx as $postname)
+               {
+                       $context[$postname] = get_post($postname);
+               }
+       } else 
+               $context = isset($_SESSION[$ctx]) ? $_SESSION[$ctx] : null;
+
+       array_unshift($_SESSION['Context'], array('name' => $ctx, 
+               'ctx' => $context,
+               'caller' => $_SERVER['PHP_SELF'],
+               'ret' => array()));
+       meta_forward($call);
+}
+/*
+       Restores context after external page call and
+       returns array of data passed by external page.
+*/
+function context_restore()
+{
+       if ( count($_SESSION['Context'])) {
+               if ($_SERVER['PHP_SELF'] == $_SESSION['Context'][0]['caller']) {
+                       $ctx = array_shift($_SESSION['Context']);
+                       if ($ctx) {
+                               if (is_array($ctx['ctx'])) {
+                                       foreach($ctx['ctx'] as $name => $val) 
+                                       {
+                                               $_POST[$name] = $val;
+                                       }
+                               } else
+                                       if ($ctx['name']!='')
+                                               $_SESSION[$ctx['name']] = $ctx['ctx'];
+                               return $ctx['ret'];
+                       }
+               }
+       }
+       return false;
+}
+
+/*
+       Return to caller page if the page was called from external context.
+*/
+function context_return($ret)
+{
+       if ( count($_SESSION['Context'])) {
+               $ctx = &$_SESSION['Context'][0];
+               $ctx['ret'] = $ret;
+               meta_forward( $ctx['caller'] );
+       }
+}
+/*
+       Clearing context stack after page cancel.
+*/
+function context_reset()
+{
+       $_SESSION['Context'] = array();
+}
+
+/*
+       Context stack initialization
+*/
+if (!isset($_SESSION['Context'])) {
+               context_reset();
+}
+
 ?>
\ No newline at end of file
index f1fb3691c1d6d45914a4b602ac49e6e0f0001e99..a4f8c5e1d2550a70702cf0992cab8e33bb15d7dc 100644 (file)
@@ -191,6 +191,13 @@ function submit_row($name, $value, $right=true, $extra="", $title=false, $async=
        submit_cells($name, $value, $extra, $title, $async);
        echo "</tr>\n";
 }
+
+function submit_return($name, $value, $title=false, $async=false)
+{
+       if (count($_SESSION['Context'])) {
+               submit($name, $value, true, $title, $async);
+       }
+}
 //---------------------------------------------------------------------------------
 
 function button($name, $value, $onclick, $title=false)
index ddcd10033ca2296f8ec6963f46113f266d02c192..0ce2546a3e8c469c5618a39654aeb67ffe6b1249 100644 (file)
@@ -32,6 +32,7 @@ $opts = array(                // default options
                // submit on select parameters
        'default' => '', // default value when $_POST is not set
        'select_submit' => false, //submit on select: true/false
+       'edit_submit' => false, // call editor on F4
        'async' => true,        // select update via ajax (true) vs _page_body reload
                // search box parameters
        'sel_hint' => null,
@@ -67,7 +68,7 @@ $opts = array(                // default options
        if(!count($opts['search'])) {
                $opts['search'] = array($by_id ? $valfield : $namefield);
        }
-       if ($opts['sel_hint'] === null)
+       if ($opts['sel_hint'] === null) 
                $opts['sel_hint'] = $by_id || $search_box==false ?
                        '' : _('Press Space tab for search pattern entry');
 
@@ -142,10 +143,13 @@ $opts = array(            // default options
                        if (get_post($search_submit) && ($txt === $value)) {
                                        $selected_id = $value; 
                        } 
-                        if ((string)($selected_id) === $value) {
+                       if (get_post($search_submit) && ($txt === $value)) {
+                               $selected_id = $value;
+                       }
+                       if      ((string)($selected_id) === $value) {
                                $sel = 'selected';
                                $found = $value;
-                        }
+                       }
                        if ($first_id === false) {
                                $first_id = $value;
                                $first_opt = $descr;
@@ -173,8 +177,9 @@ $opts = array(              // default options
                $txt = $found;
                $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
        }
+       $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
        $selector = "<select $disabled name='$name' class='$class' title='"
-               . $opts['sel_hint']."' $rel>".$selector."</select>\n";
+               . $opts['sel_hint']."'$aspect $rel>".$selector."</select>\n";
 
        $Ajax->addUpdate($name, "_{$name}_sel", $selector);
 
@@ -237,6 +242,7 @@ $opts = array(              // default options
        'spec_option'=>false,   // option text or false
        'spec_id' => 0,         // option id
        'select_submit' => false, //submit on select: true/false
+       'edit_submit' => false, // call editor on F4
        'async' => true,        // select update via ajax (true) vs _page_body reload
        'default' => '', // default value when $_POST is not set
                // search box parameters
@@ -293,8 +299,9 @@ $opts = array(              // default options
                $_POST[$name] = $first_id;
        }
 
+       $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
        $selector = "<select $disabled name='$name' class='combo' title='"
-               . $opts['sel_hint']."' >".$selector."</select>\n";
+               . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
 
        $Ajax->addUpdate($name, "_{$name}_sel", $selector);
 
@@ -337,6 +344,7 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
        array(
                'format' => '_format_add_curr',
                'search_box' => $mode!=0,
+               'edit_submit' => true, 
                'type' => 1,
                'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
                'spec_id' => $all_items,
@@ -382,8 +390,9 @@ return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
                'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
                'spec_id' => $all_items,
                'select_submit'=> $submit_on_change,
+               'edit_submit' => true, // call editor on F4
                'async' => false,
-               'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
+               'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F4 - entry new customer') :
                _('Select customer')
        ) );
 }
@@ -767,7 +776,8 @@ function stock_purchasable_items_list($name, $selected_id=null,
        $all_option=false, $submit_on_change=false)
 {
        $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("mb_flag!= 'M'")));
+               array('where'=>array("mb_flag!= 'M'"), 
+                       'edit_submit' => true));
        return $str;
 }
 
@@ -777,7 +787,9 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
        if ($label != null)
                echo "<td>$label</td>\n";
        $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("mb_flag!= 'M'"), 'cells'=>true));
+               array('where'=>array("mb_flag!= 'M'"), 
+                        'edit_submit' => true,
+                        'cells'=>true));
        return $str;
 }
 
index 8afa8b929d44a007677d117a3adb924a27529b58..3ff73e1cd95950b91ef899b027c242d0651c5ed0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -11,4 +11,5 @@
        if (isset($_GET['application']))
                $app->selected_application = $_GET['application'];
        $app->display();
+       context_reset();
 ?>
\ No newline at end of file
index ff479f30da60f652b708d94eee55a6453b3d6999..27329ea3e8a0fedd6299f6a326fbb5f9b0d2f730 100644 (file)
@@ -138,6 +138,12 @@ function _set_combo_select(e) {
                                setFocus(box.name);
                            return false;
                         }
+                       if (this.getAttribute('aspect') == 'editable' && key==115) {
+                               // F4: call related database editor - not available in non-js fallback mode
+                               JsHttpRequest.request('_'+this.name+'_editor', this.form);
+                               return false; // prevent default binding
+                               // TODO: preventDefault, stopPropagation when needed
+                       }
                }
 }