<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Script successfully calls to create record, but re-displays form after]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8122&amp;type=atom" />
	<updated>2019-04-26T20:34:03Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=8122</id>
		<entry>
			<title type="html"><![CDATA[Script successfully calls to create record, but re-displays form after]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=34815#p34815" />
			<content type="html"><![CDATA[<p>This script below is called by the following:</p><p>&nbsp; &nbsp; new_links.php?link_id=KAD&amp;batch_ref=2019-01-04%20PEYSON&amp;trans_id=1901002</p><p>It displays correctly when called.</p><p>When the &quot;Add new&quot; is clicked it successfully calls the db function and creates a new record.<br />It also correctly shows the &quot;display_notification&quot; which follows.<br />It does not display the link that follows, but goes on to re-display the form and the&quot;Transaction 1901002 will be added...&quot; dialog.</p><p>If the &quot;submit&quot; is supposed to re-call the script, then the vars that initiate the form display should have been cleared.</p><p>Seems like I am missing something about the operation of the &quot;submit&quot; processing.</p><p>Any help appreciated.</p><br /><div class="codebox"><pre><code>&lt;?php
/*===================================================================\
|                         FrontBatchProcessing                       |
|--------------------------------------------------------------------|
|  Copyright (C) 2019 NEH Systems                                    |
|  Date:  07-March-2019                                              |
|  Description: FrontAccounting Transaction Batch Control Module     |
|  Released under GNU GPL License.                                   |
|                                                                    |
\===================================================================*/

$page_security = &#039;SA_NEWLNKS&#039;;
$path_to_root  = &#039;../../..&#039;;

$module_root = $path_to_root . &quot;/modules/BatchControl&quot;;

include_once($path_to_root . &quot;/includes/session.inc&quot;);
include_once($path_to_root . &quot;/includes/ui.inc&quot;);
include_once($path_to_root . &quot;/includes/date_functions.inc&quot;);
include_once($module_root  . &quot;/includes/batches_db.inc&quot;);

add_access_extensions();

$js = &quot;&quot;;
if ($SysPrefs-&gt;use_popup_windows)
    $js .= get_js_open_window(720, 640);
if (user_use_date_picker())
    $js .= get_js_date_picker();

page(_($help_context = &quot;Batch Control&quot;));

simple_page_mode(true);

$link_id   = &#039;&#039;;
$batch_ref = &#039;&#039;;
$trans_id  = &#039;&#039;;
$target    = &#039;&#039;;
$link      = &#039;&#039;;

//-----------------------------------------------------------------------------

function can_process()
{
    global $selected_id;

    if (!isset($_POST[&#039;link_id&#039;]) || !isset($_POST[&#039;batch_ref&#039;]) 
                                    || !isset($_POST[&#039;trans_id&#039;]))
    {
        display_error(_(&quot;Your POST variables are not set!&quot;), $center=true);
        return false;
    }

    if (isset($_POST[&#039;link_id&#039;]) &amp;&amp; strlen($_POST[&#039;link_id&#039;]) &lt; 3)
    {
        display_error(_(&quot;Invalid Link ID.&quot;));
        return false;
    }
    elseif (isset($_POST[&#039;batch_ref&#039;]) &amp;&amp; strlen($_POST[&#039;batch_ref&#039;]) &lt; 15)
    {
        display_error(_(&quot;Incomplete Batch Reference.&quot;));
        return false;
    }
    elseif (isset($_POST[&#039;trans_id&#039;]) &amp;&amp; strlen($_POST[&#039;trans_id&#039;]) &lt; 7)
    {
        display_error(_(&quot;Invalid Trans ID.&quot;));
        return false;
    }
    return true;
}

//-----------------------------------------------------------------------------

if ($Mode==&#039;ADD_ITEM&#039; || $Mode==&#039;UPDATE_ITEM&#039;)
{
    $_POST[&#039;link_id&#039;]   = $_SESSION[&#039;link_id&#039;];    // recover post vars
    $_POST[&#039;batch_ref&#039;] = $_SESSION[&#039;batch_ref&#039;];
    $_POST[&#039;trans_id&#039;]  = $_SESSION[&#039;trans_id&#039;];

    $_SESSION[&#039;link_id&#039;]   = NULL;            // clear session vars
    $_SESSION[&#039;batch_ref&#039;] = NULL;
    $_SESSION[&#039;trans_id&#039;]  = NULL;


    if ($Mode==&#039;ADD_ITEM&#039; &amp;&amp; can_process())
    {
        // function in BatchControl/includes
        create_new_link($_POST[&#039;link_id&#039;], $_POST[&#039;batch_ref&#039;], $_POST[&#039;trans_id&#039;]);

        display_notification(_(&#039;New transaction link &#039; . $_POST[&#039;trans_id&#039;] . 
                                   &#039; added to selected batch &#039; . $_POST[&#039;link_id&#039;]));

        $link_id   = $_POST[&#039;link_id&#039;];
        $batch_ref = $_POST[&#039;batch_ref&#039;];

        $target = &quot;&lt;a href=&#039;view_links.php?link_id=$link&amp;batch_ref=$batch_ref&gt;&quot;;
        $link   = &quot;View Links&quot;;

        $_GET[&#039;trans_id&#039;] = NULL;            // kill so no tab after add

        $_POST[&#039;link_id&#039;]   = NULL;            // kill so no tab after add
        $_POST[&#039;batch_ref&#039;] = NULL;            // after new link created
        $_POST[&#039;trans_id&#039;]  = NULL;

        echo &quot;&lt;center&gt;&lt;td&gt;&quot;;
        echo $target . $link . &quot;&lt;/a&gt;\n&quot;;
        echo &quot;&lt;/center&gt;&lt;/td&gt;\n&quot;;

        $Mode = &#039;RESET&#039;;
    }
    else
    {
        // will decide after consult whether editing and/or deletion allowed
    }
}

//-----------------------------------------------------------------------------
// detect if new_links was called from batch_control with trans_id.
// after adding a new transaction link this should not execute again.
//

if (isset($_GET[&#039;trans_id&#039;]) &amp;&amp; !empty($_GET[&#039;trans_id&#039;]))
{
    $trans_id = $_GET[&#039;trans_id&#039;];

    echo &quot;Transaction ID: &quot; . $trans_id . &quot;&lt;br /&gt;&quot;;    // testing on reload

    if (isset($_GET[&#039;batch_ref&#039;]) &amp;&amp; !empty($_GET[&#039;batch_ref&#039;]))
        $batch_ref = $_GET[&#039;batch_ref&#039;];

    if (isset($_GET[&#039;link_id&#039;]) &amp;&amp; !empty($_GET[&#039;link_id&#039;]))
        $link_id = $_GET[&#039;link_id&#039;];

    $_POST[&#039;link_id&#039;]   = $link_id;
    $_POST[&#039;batch_ref&#039;] = $batch_ref;
    $_POST[&#039;trans_id&#039;]  = $trans_id;
}

//-----------------------------------------------------------------------------
// displays the table ONLY if new_links has been called from batch_control
// with a trans_id to be added to the batch_links table.
// after adding a new link this script should call view_links.php so that
// the updated batch_link entries can be displayed

if (isset($_POST[&#039;trans_id&#039;]) &amp;&amp; !empty($_POST[&#039;trans_id&#039;]))
{
    start_form($multi=true);

    start_table(TABLESTYLE2);
 
    $th = array(_(&quot;Batch ID&quot;), _(&quot;Reference&quot;), _(&quot;Transaction ID&quot;), &quot;&quot;, &quot;&quot;);

    inactive_control_column($th);
    table_header($th);

    start_row();
    echo &quot;&lt;td&gt;&quot; . $_POST[&#039;link_id&#039;] . &quot;&lt;/td&gt;&lt;td&gt;&quot; . $_POST[&#039;batch_ref&#039;] .
           &quot;&lt;/td&gt;&lt;td&gt;&quot; . $_POST[&#039;trans_id&#039;] . &quot;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&quot;;
    end_row();
    br(1);

    end_table(1);

    $msg = &quot;Transaction &quot; . $_POST[&#039;trans_id&#039;] . &quot; will be added to Batch &quot; . 
                              $_POST[&#039;link_id&#039;] .  &quot; &quot; . $_POST[&#039;batch_ref&#039;];
    display_note($msg, 1, 1, &quot;&quot;);

    $_SESSION[&#039;link_id&#039;]   = $_POST[&#039;link_id&#039;];    // keep data in session
    $_SESSION[&#039;batch_ref&#039;] = $_POST[&#039;batch_ref&#039;];    // must unset after add
    $_SESSION[&#039;trans_id&#039;]  = $_POST[&#039;trans_id&#039;];

    submit_add_or_update_center($selected_id == -1, &#039;&#039;, &#039;both&#039;);

    end_form();

    end_page();
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[neholtz]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=42211</uri>
			</author>
			<updated>2019-04-26T20:34:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=34815#p34815</id>
		</entry>
</feed>
