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

# Contains all sub routines (functions) for editing the store headers and
# footers. The template set is chosen in the main/core settings.

#######################################################################
#
# 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) = 'template_hdr_ftr_file_editor';
    register_extension( $modname, 'Template Header/Footer Editor', $versions{$modname} );
    register_menu( 'StoreHeaderTemplateFile',
        'write_StoreHeaderTemplate',
        $modname, 'Write Store Header Template File' );
    register_menu( 'StoreFooterTemplateEdits',
        'write_StoreFooterTemplate_file',
        $modname, 'Write Store Footer Template Files' );
    register_menu(
        'CheckoutStoreHeaderTemplateFile',
        'write_CheckoutStoreHeaderTemplate_file',
        $modname, 'Write Secure Header Template Files'
    );
    register_menu(
        'CheckoutStoreFooterTemplateEdits',
        "write_CheckoutStoreFooterTemplate_file",
        $modname, 'Write Secure Footer Template Files'
    );
    register_menu(
        'show_edit_hdrftr_screen', 'display_hdrftr_editor_screen',
        $modname,  'Store Header/Footer File Editor'
    );
    add_merchtools_settings_choice(
        'Store Header/Footer File Editor',
        'Store Header/Footer File Editor',
        'show_edit_hdrftr_screen'
    );
}

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

sub write_StoreHeaderTemplate {
    my $new_store_file = "$in{'changed_store_header_file'}";
    open( NEWSTOREFILE, '>', "$sc_store_header_file" );
    print NEWSTOREFILE $new_store_file;
    close(NEWSTOREFILE);
    display_hdrftr_editor_screen();
}

#######################################################################
sub write_StoreFooterTemplate_file {
    my $new_store_file = "$in{'changed_store_footer_file'}";
    open( NEWSTOREFILE, '>', "$sc_store_footer_file" );
    print NEWSTOREFILE $new_store_file;
    close(NEWSTOREFILE);
    display_hdrftr_editor_screen();
}

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

sub write_CheckoutStoreHeaderTemplate_file {
    my $new_store_file = "$in{'changed_checkout_store_header_file'}";
    open( NEWSTOREFILE, '>', "$sc_secure_store_header_file" );
    print NEWSTOREFILE $new_store_file;
    close(NEWSTOREFILE);
    display_hdrftr_editor_screen();
}

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

sub write_CheckoutStoreFooterTemplate_file {
    my $new_store_file = "$in{'changed_checkout_store_footer_file'}";
    open( NEWSTOREFILE, '>', "$sc_secure_store_footer_file" );
    print NEWSTOREFILE $new_store_file;
    close(NEWSTOREFILE);
    display_hdrftr_editor_screen();
}

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

sub display_hdrftr_editor_screen {

    print &$manager_page_header( 'Template Header/ Footer Editor', '', '', '', '' );

    print <<ENDOFTEXT;
<h1 class='mgr-page-title'>Current Header/Footer Templates File Editor</h1>
<p><br></p>

<p class="well">This area allows you to edit the chosen store header and footer template files (sets for shopping and checkout) that will be used in the branding of your store -- the default design applied store wide unless individual product category header and/or footer files are found.
<br><br>Please see the <a href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&show_template_mgr_screen=yes">Store Template Manager</a> to select a different template, change the widget layouts, and edit other template files.
<br><br>Using your own headers/footers is fairly easy, but not recommended for those without HTML editing experience. For faster setup, use a template already available.
<br><br><i>NOTE: You can create and use your own templates if you wish, but this will require you to create your own template package and upload them to the store's <b>$sc_hedfut_templates_dirm</b> sub directory.  If you wish to use custom header and/or footer files by category name, you will need to create those files separately and place them in the $sc_hedfut_templates_dir sub-directory of your store ( using the formats of header-CATEGORY-NAME-HERE.inc and/or footer-CATEGORY-NAME-HERE.inc, which is auto-detected automatically if enabled in the <a href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&change_store_layout_screen=yes">Layout & Design Settings - Misc</a> Manager ).  Make sure to upload all HTML and CSS files in ASCII (text) mode.</i></p>
<p><br></p>

ENDOFTEXT

    if ( $in{'system_edit_success'} ) {
        print <<ENDOFTEXT;
<div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12 hidden-xs">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bg-success">
        <h4 class="text-primary mgr-center">>Template Files has been successfully updated.</h4>
        </div>
    </div>
<div class="row col-xs-12 col-sm-12"><p><br></p></div>
ENDOFTEXT
    }
    open( STOREHEADER, "<$sc_store_header_file" );    # || die ('Could not find file') ;
    local $full_store_header_file;
    while (<STOREHEADER>) {
        $full_store_header_file .= $_;
    }
    close(STOREHEADER);
    open( STOREFOOTER, "<$sc_store_footer_file" );    # || die ('Could not find file') ;
    local $full_store_footer_file;
    while (<STOREFOOTER>) {
        $full_store_footer_file .= $_;
    }
    close(STOREFOOTER);
    open( CheckoutStoreHEADER, "<$sc_checkout_store_header_file" );    # || die ('Could not find file') ;
    local $full_checkout_store_header_file;
    while (<CheckoutStoreHEADER>) {
        $full_checkout_store_header_file .= $_;
    }
    close(CheckoutStoreHEADER);
    open( CheckoutStoreFOOTER, "<$sc_checkout_store_footer_file" );    # || die ('Could not find file') ;
    local $full_checkout_store_footer_file;
    while (<CheckoutStoreFOOTER>) {
        $full_checkout_store_footer_file .= $_;
    }
    close(CheckoutStoreFOOTER);
    print qq~
<ul class="nav nav-tabs" id="tabs2" role="tablist">
    <li role="presentation" class="active"><a href="#tabs-1" aria-controls="tabs-1" role="tab" data-toggle="tab">Store Header</a></li>
    <li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">Store Footer</a></li>
    <li role="presentation"><a href="#tabs-3" aria-controls="tabs-3" role="tab" data-toggle="tab">Checkout Header</a></li>
    <li role="presentation"><a href="#tabs-4" aria-controls="tabs-4" role="tab" data-toggle="tab">Checkout Footer</a></li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="tabs-1">

<p><br></p>
<h2 class="mgr-page-title"><b>Store Header</b></h2>
<p><br></p>

<form class="form-horizontal" action="manager.cgi" method="post">
<input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">

<p><b>Store Header: &nbsp; <a data-toggle="collapse" href="#storeHeader" aria-expanded="false" aria-controls="storeHeader"><i class="fa fa-info-circle"></i></a></b></p>
<div class="collapse" id="storeHeader">
  <div class="well">
  <p>Here is the current file for the global Store Header file (displayed on standard pages) located at: <b>$sc_store_header_file</b> <br>Feel free to do any edits using the file contents box below, or you may download the Store Header file via FTP and make the changes manually.</p>
  </div>
</div>
<textarea name="changed_store_header_file" class="form-control" rows="30" wrap=off>$full_store_header_file</textarea>
<p><br><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<button name="StoreHeaderTemplateFile" class="btn btn-primary btn-lg btn-block mgr-center" value="Submit">Update Store Header File</button>

</form>
<p><br></p>

</div>
<!-- End of tab 1 -->


<div class="tab-pane" id="tabs-2">
<p><br></p>

<h2 class="mgr-page-title"><b>Store Footer</b></h2>
<p><br></p>

<form class="form-horizontal" action="manager.cgi" method="post">
<input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">

<p><b>Store Footer: &nbsp; <a data-toggle="collapse" href="#storeFooter" aria-expanded="false" aria-controls="storeFooter"><i class="fa fa-info-circle"></i></a></b></p>
<div class="collapse" id="storeFooter">
  <div class="well">
  <p>Here is the current file for the global Store Footer file (displayed on standard pages) located at: <b>$sc_store_footer_file</b> <br>Feel free to do any edits using the file contents box below, or you may download the Store Footer file via FTP and make the changes manually.</p>
  </div>
</div>
<textarea name="changed_store_footer_file" class="form-control" rows="30" wrap=off>$full_store_footer_file</textarea>
<p><br><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<button name="StoreFooterTemplateEdits" class="btn btn-primary btn-lg btn-block mgr-center" value="Submit">Update Store Footer File</button>

</form>
<p><br></p>

</div>
<!-- End of tab 2 -->


<div class="tab-pane" id="tabs-3">
<p><br></p>

<h2 class="mgr-page-title"><b>Checkout Header</b></h2>
<p><br></p>

<form class="form-horizontal" action="manager.cgi" method="post">
<input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">

<p><b>Checkout Header: &nbsp; <a data-toggle="collapse" href="#storeHeaderSec" aria-expanded="false" aria-controls="storeHeaderSec"><i class="fa fa-info-circle"></i></a></b></p>
<div class="collapse" id="storeHeaderSec">
  <div class="well">
  <p>Here is the current file for the Checkout Header file (displayed on all order form, order verify, and order thankyou pages) located at: <b>$sc_checkout_store_header_file</b> <br>Feel free to do any edits using the file contents box below, or you may download the Checkout Header file via FTP and make the changes manually.</p>
  </div>
</div>
<textarea name="changed_checkout_store_header_file" class="form-control" rows="30" wrap=off>$full_checkout_store_header_file</textarea>
<p><br><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<button name="CheckoutStoreHeaderTemplateFile" class="btn btn-primary btn-lg btn-block mgr-center" value="Submit">Update Checkout Header File</button>

</form>
<p><br></p>

</div>
<!-- End of tab 3 -->


<div class="tab-pane" id="tabs-4">
<p><br></p>

<h2 class="mgr-page-title"><b>Checkout Footer</b></h2>
<p><br></p>

<form class="form-horizontal" action="manager.cgi" method="post">
<input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">

<p><b>Checkout Footer: &nbsp; <a data-toggle="collapse" href="#storeFooterSec" aria-expanded="false" aria-controls="storeFooterSec"><i class="fa fa-info-circle"></i></a></b></p>
<div class="collapse" id="storeFooterSec">
  <div class="well">
  <p>Here is the current file for the Checkout Footer file (displayed on all order form, order verify, and order thankyou pages) located at: <b>$sc_checkout_store_footer_file</b> <br>Feel free to do any edits using the file contents box below, or you may download the Checkout Header file via FTP and make the changes manually.</p>
  </div>
</div>
<textarea name="changed_checkout_store_footer_file" class="form-control" rows="30" wrap=off>$full_checkout_store_footer_file</textarea>
<p><br><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<button name="CheckoutStoreFooterTemplateEdits" class="btn btn-primary btn-lg btn-block mgr-center" value="Submit">Update Checkout Footer File</button>

</form>
</div>




~;
    print &$manager_page_footer;
}

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

1;
