$versions{'freeform_logic-ext_lib.pl'} = '06.6.00.0000';

# Contains all sub routines (functions) for the freeform logic manager.

#######################################################################
#
# AgoraCart and all associated files, except where noted, are
# Copyright 2001 to Present jointly by K-Factor Technologies, Inc.
# and by C E Mayo (aka Mister Ed) at AgoraCart.com & K-Factor.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This copyright notice may not be removed or altered in any way.
#
#######################################################################

{
    local ($modname) = 'freeform_logic';
    register_extension( $modname, 'Custom Store Logic', $versions{$modname} );
    add_settings_choice(
        'free form logic',
        ' Free Form Logic ',
        'freeform_settings_screen'
    );
    register_menu( 'freeform_settings_screen', 'change_free_settings_screen',
        $modname, 'Display Free Form (custom) Logic' );
    register_menu(
        'ChangeFreeSettings', 'action_change_free_settings',
        $modname,  'Write Free Form (custom) Logic'
    );
}

#######################################################################

sub action_change_free_settings {
    local ($info);
    local ($myset) = q{};
    $info = my_escape( $in{'sc_free_form_logic'} );
    $myset .= "\$sc_free_form_logic = " . "\"$info\";\n";
    $myset .= "#\n";
    $info = my_escape( $in{'sc_free_form_logic_too'} );
    $myset .= "\$sc_free_form_logic_too = " . "\"$info\";\n";
    $myset .= "#\n";
    $myset .= "\$sc_free_form_logic_done = 0; \n";
    update_store_settings( 'freeformlogic', $myset );
    change_free_settings_screen();
}

################################################################################

sub change_free_settings_screen {

    print &$manager_page_header( 'FreeForm Logic', '', '', '', '' );
    print <<ENDOFTEXT;
<form action="manager.cgi" method="post">
<input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">

ENDOFTEXT

    if ( $in{'system_edit_success'} ) {
        print <<ENDOFTEXT;
    <div class='row'>
        <p class='col-md-12 bg-success text-center' style='padding:10px;'>Settings have been successfully updated.</p>
    </div>
    <p><br></p>
ENDOFTEXT
    }

    print <<ENDOFTEXT;
<h1 class='mgr-page-title'>Free Form Logic Settings</h1>
<br><br>
<p class="well">This is an advanced feature. In the areas below, you can enter variables, new subroutines (aka functions) and other programming items that you might need without editing the core code directly. If the additions are extensive, such as a long subroutine, then we advise that you create a separate perl library, and then attach it to a <i>code hook</i> at the appropriate place.</p>
<p><br></p>

<p><b>Free Form Logic One: &nbsp; <a data-toggle="collapse" href="#freeFormOne" aria-expanded="false" aria-controls="freeFormOne"><i class="fa fa-info-circle"></i></a></b><textarea name="sc_free_form_logic" class="form-control" rows="14">$sc_free_form_logic</textarea></p>
<div class="collapse" id="freeFormOne">
     <div class="well">
         <p>"Free Form Logic One" runs earlier in the startup process, called inside the <i>startup_sys_.pl</i> file.</p>
         <p><b>Runs After:</b> initial setup files are loaded, form post/get is parsed, core language and libraries are loaded, and enabled payment gateways are loaded.</p>
         <p><b>Runs Before:</b> Any enabled plug-ins ( aka custom libraries ) are loaded, cookies and cart_id are read/created, payment API switches.</p>
         <p>NOTE: "Free Form Logic Two" ( the next setting below this one ) is the most common place to use any free form logic.</p>
     </div>
 </div>
<p><hr></p>

<p><b>Free Form Logic Two: &nbsp; <a data-toggle="collapse" href="#freeFormTwo" aria-expanded="false" aria-controls="freeFormTwo"><i class="fa fa-info-circle"></i></a></b><textarea name="sc_free_form_logic_too" class="form-control" rows="9">$sc_free_form_logic_too</textarea></p>
<div class="collapse" id="freeFormTwo">
     <div class="well">
         <p>"Free Form Logic Two" is the most common place to add free form logic, called inside the <i>startup_sys_.pl</i> file.</p>
         <p><b>Runs After:</b> "Free Form Logic One", any enabled plug-ins ( aka custom libraries ) are loaded, and the payment API switches</p>
         <p><b>Runs Before:</b> cookies and cart_id are read/created, search results are parsed, and page display</p>
         <p>NOTE: "Free Form Logic Two" run just before the 'open_for_business' code hook it was previously attached to.</p>
     </div>
 </div>
<p><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<input name="ChangeFreeSettings" type="hidden" value="Submit">
<button class="btn btn-primary btn-lg mgr-center" style="display: block;"> Submit Free Form Logic Updates</button>

<p><br><br><br></p>
</form>
ENDOFTEXT
    print &$manager_page_footer;
}

#######################################################################

1;
