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

# Contains all sub routines (functions) to manage static html pages for products, aka Static HTML Product Pages.

#######################################################################
#
# 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) = 'static_html_product_pages_manager';
    register_extension( $modname, 'Static HTML Product Pages Manager',
        $versions{$modname} );
    register_menu( 'display_product_pages_manager_screen', 'display_product_pages_manager_screen',
        $modname, "Display Static HTML Product Pages Manager Screen" );
    register_menu( 'ChangeProductPagesSettings', 'write_product_pages_manager_settings',
        $modname, 'Write Static HTML Product Pages Manager Settings' );
    register_menu( 'CopyAproductPagesLink', 'copy_and_rename_staticproductpags',
        $modname, 'Write - Copy and Rename a Static HTML Product Pages File' );
    register_menu( 'EditAProductPages', 'display_staticproductpags_file_editor',
        $modname, 'Display - Editor for a Selected Static HTML Product Pages File' );
    register_menu( 'CreateAProductPages', 'display_staticproductpags_file_creator',
        $modname, 'Display - Creator for a New Static HTML Product Pages File' );
    register_menu( 'display_staticproductpags_file_editor', 'display_staticproductpags_file_editor',
        $modname, "Display - Editor for a Selected Static HTML Product Pages File" );
    register_menu( 'ChangeAProductPages', 'save_edited_staticproductpags_file',
        $modname, 'Write - Changed Static HTML Product Pages File' );
    register_menu( 'DeleteAProductPages', 'delete_staticproductpags_file',
        $modname, 'Delete - Static HTML Product Pages File' );
    register_menu( 'DeleteAProductPagesBackup', 'delete_staticproductpags_backup_file',
        $modname, 'Delete - Static HTML Product Pages Backup File' );
    register_menu( 'DeleteHTMLproductPages', 'delete_staticproductpags_HTML_file',
        $modname, 'Delete - Legacy Static HTML Product Pages File' );
    register_menu( 'convertHTMLproductPages', 'convert_staticproductpags_HTML_file',
        $modname, 'Convert Legacy Static HTML Product Pages File Editor' );

    add_merchtools_settings_choice(
        'Static HTML Page Manager - Product Pages',
        'Static HTML Page Manager - Product Pages',
        'display_product_pages_manager_screen'
    );
}

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

sub write_product_pages_manager_settings {

    my ( @activate_values, @productpages_order );
    my ( $myset, $temp_key ) = q{};
    my %catlink_name;
    my ( $count, $array_count ) = 0;
    local ( $temp, $my_string ) = q{};

    @productpages_order = split(/\,/, $in{'newOrder'});
    $array_count = @productpages_order;
    @activate_values = param('mgr_staticproductpags_checked');

    foreach $item (@activate_values) {
        $item =~ /([\w\-\_\+]+)(\.html)/i; # untaint
        $item = "$1$2";
        $temp_key = $item;
        $temp_key =~ s/\.html$/\.pl/i;
        require_supporting_libraries( __FILE__, __LINE__, "$sc_html_product_directory_path/$temp_key");
        $catlink_name{"$item"} = $mgr_link_name;

    }

    if ( $array_count < 1 ) { @productpages_order = @activate_values; }
    foreach $item (@productpages_order) {
        $item =~ /([\w\-\_\+]+)(\.html)/i; # untaint
        $item = "$1$2";
        $my_string = qq~$item|$catlink_name{$item}~;
        if ( $count > 0 ) { $temp .= ','; }
        $temp .= qq|'$my_string'|;
        push(@sc_active_staticproductpags, "$my_string");  # for when we display the manager page
        $count++;
    }

    $myset .= "\@sc_active_staticproductpags = ($temp);\n";

    update_store_settings( 'productpages', $myset );  # save Static HTML Product Pages settings
    $mgr_success_message ='Product Pages settings have been successfully updated';
    display_product_pages_manager_screen();
}

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

sub save_edited_staticproductpags_file {

    local $mgr_problem_message = '';
    my ( $myfile, $robotlist_string ) = q{};
    my (@values);
    my $robot_count = 0;
    my $temp_time = time();
    my $clean_file = $in{'prodpage_file_to_save'};
    $clean_file =~ s/\.s?html?$/\.pl/i; # just in case .htm or html is used
    $clean_file =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $clean_file = "$1$2";
    my $file_name = "$1";
    my $content_file_name = $file_name . '.inc';
    my $temp2backup = "$sc_html_product_directory_path" . "/$clean_file";
    my $newbackupfile = "$sc_html_product_directory_path" . "/$file_name" . '_time_' . $temp_time . '.backup';
    my $content2backup = "$sc_html_product_directory_path" . "/$content_file_name";
    my $contentbackupfile = "$sc_html_product_directory_path" . "/$file_name" . '_contentINC_time_' . $temp_time . '.backup';

    # first, create backup of Static HTML Product Pages file, if store admin requests it each change submit
    if ( $in{'make_backup'} eq 'yes' ) {
        copy( $temp2backup, $newbackupfile );
    }

    $myfile .= qq~\$mgr_link_name = qq|$in{'mgr_link_name'}|;\n~;
    $myfile .= qq~\$sc_page_title = qq|$in{'sc_page_title'}|;\n~;
    $myfile .= qq~\$sc_page_meta_description = qq|$in{'sc_page_meta_description'}|;\n~;
    $myfile .= qq~\$sc_page_meta_keywords = qq|$in{'sc_page_meta_keywords'}|;\n~;

    if ( $in{'sc_page_meta_og_image_name'} && $in{'sc_page_meta_og_image_location'} && $in{'sc_page_meta_og_image_mime'} ) {
        $myfile .= qq~\$sc_page_meta_og_image_mime = qq|$in{'sc_page_meta_og_image_mime'}|;\n~;
        $myfile .= qq~\$sc_page_meta_og_image_alt = qq|$in{'sc_page_meta_og_image_alt'}|;\n~;
        $myfile .= qq~\$sc_page_meta_og_image_height = qq|$in{'sc_page_meta_og_image_height'}|;\n~;
        $myfile .= qq~\$sc_page_meta_og_image_width = qq|$in{'sc_page_meta_og_image_width'}|;\n~;
        $myfile .= qq~\$sc_page_meta_og_image_name = qq|$in{'sc_page_meta_og_image_name'}|;\n~;
        $myfile .= qq~\$sc_page_meta_og_image_location = qq|$in{'sc_page_meta_og_image_location'}|;\n~;

        if ( $in{'sc_page_meta_og_image_location'} eq 'product' ) {
            $myfile .= qq~\$sc_page_meta_og_image_url = qq|[[BaseURL]][[URLofImages]]/$in{'sc_page_meta_og_image_name'}|;\n~;
            $myfile .= qq~\$sc_page_meta_og_image_secure_url = qq|[[sslBaseURL]][[URLofImages]]/$in{'sc_page_meta_og_image_name'}|;\n~;
        }
        elsif ( $in{'sc_page_meta_og_image_location'} eq 'template' ) {
            $myfile .= qq~\$sc_page_meta_og_image_url = qq|[[BaseURL]]$sc_template_dir_for_URL/$in{'sc_page_meta_og_image_name'}|;\n~;
            $myfile .= qq~\$sc_page_meta_og_image_secure_url = qq|[[sslBaseURL]]$sc_template_dir_for_URL/$in{'sc_page_meta_og_image_name'}|;\n~;
        }

        if ( $in{'sc_page_meta_og_image_width'} eq '' ) {
            $in{'productpages_name_to_edit'} = $clean_file;
            $mgr_problem_message .= 'OG Image Width needs to be filled out<br>';
        }

        if ( $in{'sc_page_meta_og_image_height'} eq '' ) {
            $in{'productpages_name_to_edit'} = $clean_file;
            $mgr_problem_message .= 'OG Image Height needs to be filled out<br>';
        }
    }

    @values = param('metarobots');
    foreach $robot (@values) {
        if ( $robot_count == 0 ) {
            $robotlist_string = "$robot";
        }
        else {
            $robotlist_string .= ", $robot";
        }
        $robot_count++;

        if ( $robot eq 'noarchive' ) {
            $prodprobot_noarchive_checked = 'checked';
            $myfile .= "\$prodprobot_noarchive_checked = '$prodprobot_noarchive_checked';\n";
        }
        elsif ( $robot eq 'noimageindex' ) {
            $prodprobot_noimageindex_checked = 'checked';
            $myfile .= "\$prodprobot_noimageindex_checked = '$prodprobot_noimageindex_checked';\n";
        }
        elsif ( $robot eq 'nofollow' ) {
            $prodprobot_nofollow_checked = 'checked';
            $myfile .= "\$prodprobot_nofollow_checked = '$prodprobot_nofollow_checked';\n";
        }
        elsif ( $robot eq 'noindex' ) {
            $prodprobot_noindex_checked = 'checked';
            $myfile .= "\$prodprobot_noindex_checked = '$prodprobot_noindex_checked';\n";
        }
    }

    $myfile .= qq~\$sc_robot_meta_tags = qq|<meta name="robots" content="$robotlist_string">|;\n~;
    $myfile .= qq~\$sc_page_is_active = \'$in{'sc_page_is_active'}\';\n~;
    $myfile .= qq~\$sc_static_page_header_file = \'$in{'sc_static_page_header_file'}\';\n~;
    $myfile .= qq~\$sc_static_page_footer_file = \'$in{'sc_static_page_footer_file'}\';\n~;
    $in{'sc_page_content'} =~ s/\[\[textarea\]\]/textarea/ig;
    $in{'sc_page_content'} =~ s/\[\[formtag\]\]/form/ig;
    $in{'sc_page_content'} =~ s/\r//g; # removes ^M
    $myfile .= q~$sc_page_content = '';\n~;
    $myfile .= qq~1;\n~;

    # update the Static HTML Product Pages file
    open( NEWCLFILE, '>', "$temp2backup" );
    print NEWCLFILE $myfile;
    close( NEWCLFILE );

    # update the CartLink contents file
    open( NEWCLCFILE, '>', "$content2backup" );
    print NEWCLCFILE $in{'sc_page_content'};
    close( NEWCLCFILE );

    if ( $mgr_problem_message ) {
        display_staticproductpags_file_editor();
    }
    else {
        $mgr_success_message = "Product Pages File has been successfully Edited and Saved";
        display_product_pages_manager_screen();
    }

}

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

sub display_product_pages_manager_screen {

    %active_staticproductpags_name;
    my (@myfiles);
    my ( $page_output, $old_html_files, $current_files_list, $current_pages, $backup_html_files ) = q{};
    local ( $orig_zfile, $temp_key, $notfound ) = 1;
    local $array_number = @sc_active_staticproductpags;

    print &$manager_page_header( 'Static HTML Product Pages Manager', '', '', '', '' );

    if ( $array_number > 0 ) {
        foreach $clfile (@sc_active_staticproductpags) {
            ( $key, $name ) = split(/\|/, $clfile, 2);
            $active_staticproductpags_name{"$key"}  = $name;
            $current_sortables .= qq|<li id="$key" class="btn btn-success btn-lg">$name</li>|;
            $current_pages .= <<ENDOFTEXT;
        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6" style="margin-bottom: 10px;">
            <div class="input-group">
              <span class="input-group-addon">
                <input type="checkbox" name="mgr_staticproductpags_checked" value="$key" checked>
              </span>
              <label class="form-control">$name</label>
            </div>
        </div>
ENDOFTEXT
        }
    }

    # read main html sub-dir to collect surrently installed pages. Skip any index, license, and error pages.
    opendir( DIRTOREAD, "$sc_html_product_directory_path" );
    @myfiles = readdir(DIRTOREAD);
    closedir(DIRTOREAD);

    my @sorted = sort { lc($a) cmp lc($b) } @myfiles;

    foreach $zfile (@sorted) {
        $clean_zfile = $zfile;
        $clean_zfile =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
        $clean_zfile = "$1$2";
        $temp_key = $zfile;
        $temp_key =~ s/\.pl$/\.html/i;
        $notfound = 1;
        if ( $active_staticproductpags_name{"$temp_key"} ) {
            $notfound = q{};
        }

        if ( ( $zfile =~ /\.s?html?$/i ) && ( $zfile !~ /^error|^index|^license/i ) )
        {
            $old_html_files .= qq~<option value="$zfile">$zfile</option>\n~;
        }
        elsif ( $zfile =~ /\.backup$/i ) {
            $backup_html_files .= qq~<option value="$zfile">$zfile</option>\n~;
        }
        elsif ( ( $zfile =~ /\.pl$/i ) && ( $zfile !~ /^license|^index|^error/i ) && ( $notfound ) ) {
            require_supporting_libraries( __FILE__, __LINE__, "$sc_html_product_directory_path/$clean_zfile");
            $current_files_list .= qq~<option value="$clean_zfile">$temp_key</option>\n~;
            $current_pages .= <<ENDOFTEXT;
            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6" style="margin-bottom: 10px;">
                <div class="input-group">
                  <span class="input-group-addon">
                    <input type="checkbox" name="mgr_staticproductpags_checked" value="$temp_key">
                  </span>
                  <label class="form-control">$mgr_link_name</label>
                </div>
            </div>
ENDOFTEXT
        }
        elsif ( ( $zfile =~ /\.pl$/i ) && $notfound eq '' ) {
            $current_files_list .= qq~<option value="$clean_zfile">$temp_key</option>\n~;
        }
    }



    $page_output .= <<ENDOFTEXT;
<h1 class='mgr-page-title'>Static HTML Product Pages</h1>
<p><br></p>

<p class="well">This manager allows you to manage your Static HTML Product Pages that you create. These types of pages are great for product category list or group pages, a page that give details on a specific product (add a link to the page in you product description). With this manager you can copy, delete, edit, and manually convert older versions to the new format (if older version copied to new store). You may change the settings within as many tabs/groups as needed, then press the <b><i>submit</i></b> button at the very bottom of the page after you are finished making any desired changes. Click on the <i class="fa fa-info-circle"></i> icon next to any setting for more information on the setting.</p>
<p><br></p>

ENDOFTEXT

    if ( $in{'system_edit_success'} ) {
        $page_output .= qq|
<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">$mgr_success_message</h4>
    </div>
</div>
<p><br><br><br><br><br></p>
|;
    }

    $page_output .= <<ENDOFTEXT;

<ul class="nav nav-tabs" id="tabs2" role="tablist">
    <li role="presentation" class="active"><a href="#tabs-1" aria-controls="tabs-2" role="tab" data-toggle="tab">Create/Edit/Copy/Delete</a></li>
ENDOFTEXT


if ( $old_html_files ) {
    $page_output .= <<ENDOFTEXT;
  <li role="presentation"><a href="#tabs-11" aria-controls="tabs-11" role="tab" data-toggle="tab">Legacy HTML</a></li>
ENDOFTEXT
}

    $page_output .= <<ENDOFTEXT;
</ul>

<div class="tab-content">

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

<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Sort/Arrange Currently Active Static HTML Product Pages</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

<p class="col-xs-12 col-sm-12"><b>Drag and Drop the Static HTML Product Pages below to rearrange the order in which they appear in your cart/site links:</b></p>

    <form class="form-horizontal" action="manager.cgi" method="post">
    <input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">
    <input id="newOrder" name="newOrder" type="hidden" value="">
    <ul id="sortable-4" class="col-xs-12 col-sm-12">
        $current_sortables
    </ul>


    <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
    <div><span class="divider"></span></div>
    <h2 class="mgr-page-title"><b>Enable / Disable Viewing for Static HTML Product Pages</b></h2>
    <div><span class="divider2"></span></div>
    <div><span class="divider"></span></div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

    <p class="col-xs-12 col-sm-12"><b>Check or uncheck the boxes below to enable/disable a page from showing as a link:</b>
    <br><br><small>Note: if the page you enable does not show up in the links, make sure to check that the settings for the individual page is enabled with this setting: "Allow this page to be activated in the main Static HTML Product Pages manager?"  You can access the individual file settings in the "Create/Edit/Copy/Delete" tab above.</small><br><br></p>
    <ul class="col-xs-12 col-sm-12">
        $current_pages
    </ul>
    <p class="col-xs-12"><br></p>
    <input type="hidden" name="system_edit_success" value="yes">
    <input name="ChangeProductPagesSettings" type="hidden" value="Submit">
    <button class="btn btn-primary btn-lg mgr-center" style="display: block;">Update Settings</button>
    </form>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

</div>


    <!-- End of tab 1 -->



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

<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Create a New Static HTML Product Pages File</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

<p><b>New File Name: &nbsp; <a data-toggle="collapse" href="#createNewFileName" aria-expanded="false" aria-controls="createNewFileName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="productpages_new_name" type="text" class="form-control" maxlength="50" placeholder="New_Name_Here.pl" required></p>
<div class="collapse" id="createNewFileName">
    <div class="well">
          <p>This is the new file name.</p>
          <p>Capitalize each new word, using underscores for spaces.</p>
          <p>End the file name with <b>.pl</b>. Anything other file extension will be rignored/emoved.</p>
          <p>Do not use special metacharacters (\$,%,&amp;,\@, !, ;, :, commas, etc) nor single &amp; double quotes.</p>
    </div>
</div>
<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

 <input type="hidden" name="system_edit_success" value="yes">
 <input name="CreateAProductPages" type="hidden" value="Submit">
 <button class="btn btn-primary mgr-center" style="display: block;">Create this New Static HTML Product Pages File</button>
 </form>


<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Edit a Static HTML Product Pages File</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

<p><b>Select File to Edit: &nbsp; <a data-toggle="collapse" href="#editProductPagesFile" aria-expanded="false" aria-controls="editProductPagesFile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_name_to_edit" required>
<option></option>
$current_files_list
</select></p>
<div class="collapse" id="editProductPagesFile">
     <div class="well">
         <p>Select the currently installed Static HTML Product Pages (Static HTML File) you wish to edit.</p>
         <p>If you wish to create a new file, you can copy and then edit an existing one or create a brand new page from scratch using the Edit or Create options elsewhere on this page.</p>
     </div>
 </div>
 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

 <input type="hidden" name="system_edit_success" value="yes">
 <input name="EditAProductPages" type="hidden" value="Submit">
 <button class="btn btn-primary mgr-center" style="display: block;">Edit this Static HTML Product Pages File</button>
 </form>


 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
 <div><span class="divider"></span></div>
 <h2 class="mgr-page-title"><b>Copy a Static HTML Product Pages File</b></h2>
 <div><span class="divider2"></span></div>
 <div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>


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

    <p><b>Select File to Copy: &nbsp; <a data-toggle="collapse" href="#copyProductPagesFile" aria-expanded="false" aria-controls="copyProductPagesFile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_old_name" required>
    <option></option>
    $current_files_list
    </select></p>
    <div class="collapse" id="copyProductPagesFile">
         <div class="well">
             <p>Select the currently installed Static HTML Product Pages file you wish to duplicate.</p>
             <p>This will only copy an original file and then save it as the new name you indicate.</p>
             <p>You will still need to edit the file after creating the new one.</p>
         </div>
     </div>
     <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

     <p><b>New File Name: &nbsp; <a data-toggle="collapse" href="#newFileName" aria-expanded="false" aria-controls="newFileName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="productpages_new_name" type="text" class="form-control" maxlength="50" placeholder="New_Name_Here.pl" required></p>
     <div class="collapse" id="newFileName">
         <div class="well">
               <p>This is the new file name the selected file will be copied to.</p>
               <p>Capitalize each new word, using underscores for spaces.</p>
               <p>End the file name with <b>.pl</b>. Anything other file extension will be ignored/removed.</p>
               <p>Do not use special metacharacters (\$,%,&amp;,\@, !, ;, :, commas, etc) nor single &amp; double quotes.</p>
         </div>
     </div>
<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

<input type="hidden" name="system_edit_success" value="yes">
<input name="CopyAproductPagesLink" type="hidden" value="Submit">
<button class="btn btn-primary mgr-center" style="display: block;">Copy this Static HTML Product Pages File</button>
</form>


<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Delete a Static HTML Product Pages File</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

<p><b>Select File to Permanently Delete: &nbsp; <a data-toggle="collapse" href="#deleteProductPagesFile" aria-expanded="false" aria-controls="deleteProductPagesFile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_to_delete" required>
<option></option>
$current_files_list
</select></p>
<div class="collapse" id="deleteProductPagesFile">
     <div class="well">
         <p>Select the currently installed Static HTML Product Pages file you wish to delete.</p>
         <p><b>WARNING:</b> Once a file is deleted, it is lost forever and cannot be retrieved, so you have been WARNED!</p>
     </div>
 </div>
 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 10px;">
     <div class="input-group">
       <span class="input-group-addon">
         <input type="checkbox" name="double_check_delete_checked" value="yes" required>
       </span>
       <label class="form-control"><b>ARE YOU SURE YOU WANT TO PERMANENTLY DELETE THIS FILE?</b></label>
     </div>
 </div>
 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

 <input type="hidden" name="system_edit_success" value="yes">
 <input name="DeleteAProductPages" type="hidden" value="Submit">
 <button class="btn btn-primary mgr-center" style="display: block;">Delete this Static HTML Product Pages File</button>
 </form>

 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
 <div><span class="divider"></span></div>
 <h2 class="mgr-page-title"><b>Delete a Static HTML Product Pages Backup File</b></h2>
 <div><span class="divider2"></span></div>
 <div><span class="divider"></span></div>
 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

 <p><b>Select Backup File to Delete: &nbsp; <a data-toggle="collapse" href="#deleteProductPagesBackupFile" aria-expanded="false" aria-controls="deleteProductPagesBackupFile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_backup_to_delete" required>
 <option></option>
 $backup_html_files
 </select></p>
 <div class="collapse" id="deleteProductPagesBackupFile">
      <div class="well">
          <p>Select the Static HTML Product Pages backup file you wish to delete.</p>
          <p><b>WARNING:</b> Once a file is deleted, it is lost forever and cannot be retrieved, so you have been WARNED!</p>
      </div>
  </div>
  <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 10px;">
      <div class="input-group">
        <span class="input-group-addon">
          <input type="checkbox" name="double_check_delete_backup_checked" value="yes" required>
        </span>
        <label class="form-control"><b>ARE YOU SURE YOU WANT TO PERMANENTLY DELETE THIS FILE?</b></label>
      </div>
  </div>
  <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

  <input type="hidden" name="system_edit_success" value="yes">
  <input name="DeleteAProductPagesBackup" type="hidden" value="Submit">
  <button class="btn btn-primary mgr-center" style="display: block;">Delete this Static HTML Product Pages Backup File</button>
  </form>


     <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

</div>


    <!-- End of tab 2 -->


<div class="tab-pane" id="tabs-11">


<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Manually Convert Legacy Static HTML Product Pages File to New Format</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

<p><b>Select Legacy HTML File to Convert: &nbsp; <a data-toggle="collapse" href="#convertProductPagesHTMLfile" aria-expanded="false" aria-controls="convertProductPagesHTMLfile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_HTML_to_convert" required>
<option></option>
$old_html_files
</select></p>
<div class="collapse" id="convertProductPagesHTMLfile">
     <div class="well">
         <p>Select the Legacy Static HTML Product Pages file you wish to convert. These are the older versions of Static HTML Product Pages files for version 5.x and 6.0x.x</p>
     </div>
 </div>
 <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

 <input type="hidden" name="system_edit_success" value="yes">
 <input name="convertHTMLproductPages" type="hidden" value="Submit">
 <button class="btn btn-primary mgr-center" style="display: block;">Convert Selected Legacy Static HTML Product Pages File</button>
 </form>

 <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>



<p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br><br></p>
<div><span class="divider"></span></div>
<h2 class="mgr-page-title"><b>Delete a Legacy Static HTML Product Pages File</b></h2>
<div><span class="divider2"></span></div>
<div><span class="divider"></span></div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

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

    <p><b>Select Legacy HTML File to Delete: &nbsp; <a data-toggle="collapse" href="#deleteProductPagesHTMLfile" aria-expanded="false" aria-controls="deleteProductPagesHTMLfile"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="productpages_HTML_to_delete" required>
    <option></option>
    $old_html_files
    </select></p>
    <div class="collapse" id="deleteProductPagesHTMLfile">
         <div class="well">
             <p>Select the Legacy Static HTML Product Pages file you wish to delete. These are the older versions of Static HTML Product Pages files for version 5.x and 6.0x.x</p>
             <p><b>WARNING:</b> Once a file is deleted, it is lost forever and cannot be retrieved, so you have been WARNED!</p>
         </div>
     </div>
     <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

     <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 10px;">
         <div class="input-group">
           <span class="input-group-addon">
             <input type="checkbox" name="double_check_delete_HTML_checked" value="yes" required>
           </span>
           <label class="form-control"><b>ARE YOU SURE YOU WANT TO PERMANENTLY DELETE THIS FILE?</b></label>
         </div>
     </div>
     <p class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><br></p>

     <input type="hidden" name="system_edit_success" value="yes">
     <input name="DeleteHTMLproductPages" type="hidden" value="Submit">
     <button class="btn btn-primary mgr-center" style="display: block;">Delete Selected Legacy Static HTML Product Pages File</button>
     </form>

     <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>

</div>


    <!-- End of tab 11 -->



<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br></p></div>
</div>
ENDOFTEXT

    print $page_output;

    print &$manager_page_footer;
}

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

sub copy_and_rename_staticproductpags {

    my (@lines) = q{};
    my ( $page_output, $orig, $new, $new_content, $orig_content) = q{};
    my $x = "File::Copy qw(copy);";
    my $new_staticproductpags_name = "$in{'productpages_new_name'}";
    my $old_staticproductpags_name = "$in{'productpages_old_name'}";
    my $skip = 0;

    if ( $new_staticproductpags_name !~ /\.pl$/i ) {
        $new_staticproductpags_name =~ s/\.s?html?//i;
        $new_staticproductpags_name .= '.pl';
    }

    $new_staticproductpags_name  =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $new_staticproductpags_name  = "$1$2";
    my $new_staticproductpags_content_name  = "$1" . '.inc';
    $old_staticproductpags_name  =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $old_staticproductpags_name  = "$1$2";
    my $old_staticproductpags_content_name  = "$1" . '.inc';
    $orig = "$sc_html_product_directory_path/$old_staticproductpags_name";
    $new = "$sc_html_product_directory_path/$new_staticproductpags_name";
    $orig_content = "$sc_html_product_directory_path/$old_staticproductpags_content_name";
    $new_content = "$sc_html_product_directory_path/$new_staticproductpags_content_name";

    $page_output .= &$manager_page_header( 'Product Pages Manager', '', '', '', '' );
    $page_output .= "<p><br><br><br></p>";

    eval("use $x"); # use in non-fatal way
    if ($@) {
        # just in case we can't use it, but it is a core perl module
        $page_output .=  qq|
        <div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bg-danger">
                <h4 class="text-danger mgr-center">Error:: $result &amp; $@</h4>
            </div>
        </div>|;
        $skip = 1;
    }
    else {
        copy( $orig, $new );
        copy( $orig_content, $new_content );

        if ( -e $new ) {
            $page_output .= qq|
            <div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bg-success">
                    <h4 class="text-primary mgr-center">Success: Static HTML Product Pages File was Copied</h4>
                </div>
            </div>|;
        }
        else {
            # directory does not exist
            $page_output .= qq|
            <div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 bg-danger">
                    <h4 class="text-danger mgr-center">Oops: Something went wrong! The selected file was not copied</h4>
                </div>
            </div>|;
            $skip = 1;
        }

        $page_output .= "<p><br><br><br></p>";
        $page_output .= "<p>Copy attempted from original file at: <b>$orig</b></p>";
        $page_output .= "<p>To new file at: <b>$new</b></p>";

        # add link info for $new name file to be edited
        $page_output .= qq|<div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br><br></p><p><a type="button" class="btn btn-lrg btn-info mgr-center" style="display: block;" href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&display_staticproductpags_file_editor=yes&productpages_name_to_edit=$new_staticproductpags_name">Edit this File Now</a></p></div>|;
    }

  # show link to Static HTML Product Pages manager
    $page_output .= qq|<div class="row col-xs-12 col-sm-12 col-md-12 col-lg-12"><p><br><br><br></p><p><a type="button" class="btn btn-lrg btn-success mgr-center" style="display: block;" href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&display_product_pages_manager_screen=yes">Return to Static HTML Product Pages  Manager</a></p></div>|;

    $page_output .= &$manager_page_footer;
    print $page_output;
}

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

sub delete_staticproductpags_file {

    my $clean_file = $in{'productpages_to_delete'};
    $clean_file =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $clean_file = "$1$2";
    my $clean_content_file = "$1" . 'inc';
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";
    my $temp_staticproductpags_content_location = "$sc_html_product_directory_path" . "/$clean_content_file";

    if ( $in{'double_check_delete_checked'} eq 'yes') {
        unlink $temp_staticproductpags_location;
        unlink $temp_staticproductpags__content_location;
        $mgr_success_message ="Product Pages File has been successfully deleted";
    }
    else {
        $mgr_success_message ="Product Pages File deletion failed";
    }

    display_product_pages_manager_screen();

}

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

sub delete_staticproductpags_HTML_file {

    my $clean_file = $in{'productpages_HTML_to_delete'};
    $clean_file =~ /([\w\-\_\+]+)(\.s?html?)/i; # untaint
    $clean_file = "$1$2";
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";

    if ( $in{'double_check_delete_HTML_checked'} eq 'yes') {
        unlink $temp_staticproductpags_location;
        $mgr_success_message ="Legacy Static HTML Product Pages File has been successfully deleted";
    }
    else {
        $mgr_success_message ="Legacy Static HTML Product Pages File deletion failed";
    }

    display_product_pages_manager_screen();

}

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

sub delete_staticproductpags_backup_file {

    my $clean_file = $in{'productpages_backup_to_delete'};
    $clean_file =~ /([\w\-\_\+]+)(\.backup)/i; # untaint
    $clean_file = "$1$2";
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";

    if ( $in{'double_check_delete_backup_checked'} eq 'yes') {
        unlink $temp_staticproductpags_location;
        $mgr_success_message ="Product Pages File has been successfully deleted";
    }
    else {
        $mgr_success_message ="Product Pages File deletion failed";
    }

    display_product_pages_manager_screen();

}

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

sub build_sample_token_list_for_page_editor_screens {

    my $token_list = <<ENDOFTEXT;
<p><br><b>Common Tokens to use within your pages:</b><br><br>
[[storeFullURL]] = $sc_store_url<br>
[[sslBaseURL]] = $sc_SSL_base_URL<br>
[[URLofImages]] = $URL_of_images_directory<br>
[[BaseURL]] = $sc_store_base_URL<br>
</p>

ENDOFTEXT
    return $token_list;

}

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

sub display_staticproductpags_file_creator {

    local ($templateheaders, $templatefooters) = q{};
    my $clean_file = $in{'productpages_new_name'};
    if ( $clean_file !~ /\.pl$/i ) {
        $clean_file =~ s/\.s?html?//i;
        $clean_file .= '.pl';
    }
    $clean_file =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $clean_file = "$1$2";
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";
    my $page_tokens_list = &build_sample_token_list_for_page_editor_screens();

    # starting defaults
    $sc_page_is_active = 'yes';
    $prodprobot_noarchive_checked = 'checked';
    $prodprobot_noimageindex_checked = 'checked';
    $sc_page_content =~ s/\<textarea/\<\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<\/textarea/\<\/\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<form/\<\[\[formtag\]\]/ig;
    $sc_page_content =~ s/\<\/form/\<\/\[\[formtag\]\]/ig;

    # Read current template directory for custom product category headers and footers
    opendir( DIRTOREAD, "$sc_prod_cat_templates_dir" );
    @myfiles = readdir(DIRTOREAD);
    closedir(DIRTOREAD);
    @sorted = sort { lc($a) cmp lc($b) } @myfiles;
    @myfiles = @sorted;

    foreach $zfile (@myfiles) {
        if ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^header-/i ) ) {
            $templateheaders .= qq~<option value="$zfile">$zfile</option>\n~;
        }
        elsif ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^footer-/i ) ) {
            $templatefooters .= qq~<option value="$zfile">$zfile</option>\n~;
        }
    }

    my $page_output = &$manager_page_header( 'Product Pages Static HTML Page Creator', '', '', '', '' );

    $page_output .= <<ENDOFTEXT;

    <form class="form-horizontal" action="manager.cgi" method="post">
    <input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">
    <input type="hidden" name="prodpage_file_to_save" value="$clean_file">
    <p><br></p>
    <h2 class="mgr-page-title"><b>Static HTML Product Pages File Creator</b></h2>
    <p><br></p>
    <div class="well">
    <p>Below is where you enter the information that is used to build the actual Static HTML Product Pages file that your store links to and displays. This file will be created at: <b>$temp_staticproductpags_location</b> in your store's file directories, once you save it. <br>Feel free to do any edits using the field boxes below, or you may manually create and upload the Static HTML Product Pages file via FTP.</p>
    <p><br></p><p><a type="button" class="btn btn-lrg btn-success mgr-center" style="display: block;" href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&display_product_pages_manager_screen=yes">Return to Static HTML Product Pages Manager</a></p>
    </div>

    <p><b>Name for this Page's Link: &nbsp; <a data-toggle="collapse" href="#linkName" aria-expanded="false" aria-controls="linkName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="mgr_link_name" type="text" class="form-control" maxlength="50" value="$mgr_link_name"></p>
    <div class="collapse" id="linkName">
        <div class="well">
              <p>This is the name use for the link when the cart builds the link lists for your active pages. This give you more flexibility over the old method of using the file name as the link name (and using underscores for spaces).</p>
              <p>Example: a file named "shipping.pl" could use a link name of: "Our Shipping Policies".</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Page Title: &nbsp; <a data-toggle="collapse" href="#pageTitle" aria-expanded="false" aria-controls="pageTitle"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_title" type="text" class="form-control" maxlength="145" value="$sc_page_title"></p>
    <div class="collapse" id="pageTitle">
        <div class="well">
              <p>This is the page title that shows in specific browser areas such as tabs or other areas. Also the default bookmark name used by most browsers.</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Description Metatag: &nbsp; <a data-toggle="collapse" href="#descriptionMeta" aria-expanded="false" aria-controls="descriptionMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_description" type="text" class="form-control" maxlength="145" value="$sc_page_meta_description"></p>
    <div class="collapse" id="descriptionMeta">
        <div class="well">
              <p>This is the description you wish to use for this page.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Keywords Metatag: &nbsp; <a data-toggle="collapse" href="#keywordsMeta" aria-expanded="false" aria-controls="keywordsMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_keywords" type="text" class="form-control" maxlength="145" value="$sc_page_meta_keywords"></p>
    <div class="collapse" id="keywordsMeta">
        <div class="well">
              <p>This is the list of keywords you wish to use for this page. Separate each word or phrase with a comma.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Optional: OG Image Meta Tag &nbsp; <a data-toggle="collapse" href="#ogImageMetaTag" aria-expanded="false" aria-controls="ogImageMetaTag"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ogImageMetaTag">
        <div class="well">
            <p>This OG (open graph protocol) Image Meta Tag allows you to control the image shown in popular social media posts when this page's URL is entered into a post.</p>
            <p>Facebook and Google both use this data. Other sites may or may not recognize the meta tags when they scrape the page URL. Scrape: collect the page information.</p>
            <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes in any of the fields for the OG image meta tag.</p>
        </div>
        <p><b>OG Image Name: &nbsp; <a data-toggle="collapse" href="#ogImageMetaName" aria-expanded="false" aria-controls="ogImageMetaName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_name" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_name"></p>
        <div class="collapse" id="ogImageMetaName">
            <div class="well">
                <p>The exact name of the image you wish to use. The image name is case sensitive: image.JPG and Image.jpg are technically 2 different images to the server due to the case, yet they both have what appears to be the same name.</p>
                <p>Image must be in the main product images directory of the store or within the active template used by your store.</p>
                <p>If you do not have a specific image in mind, you can use a logo or other image from your template.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Location: &nbsp; <a data-toggle="collapse" href="#ogImageMetaLocation" aria-expanded="false" aria-controls="ogImageMetaLocation"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_location"><option>$sc_page_meta_og_image_location</option>
        <option value=""></option>
        <option value="product">Product Directory</option>
        <option value="template">Current Template</option>
        </select></p>
        <div class="collapse" id="ogImageMetaLocation">
            <div class="well">
                <p>Locations can be within the current product image directory or the active template for the store.</p>
                <p>If using the template location, should the template be changed, the image must be copied over to the new template -- unless automatically done via the template manager's template copy function as it will copy all files in a template directory.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Mime Type: &nbsp; <a data-toggle="collapse" href="#ogImageMetaMime" aria-expanded="false" aria-controls="ogImageMetaMime"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_mime"><option>$sc_page_meta_og_image_mime</option>
        <option value=""></option>
        <option value="jpeg">jpeg/jpg</option>
        <option value="png">png</option>
        <option value="gif">gif</option>
        </select></p>
        <div class="collapse" id="ogImageMetaMime">
            <div class="well">
                <p>This is the type of image, such as jpeg, gif, or png.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Alt Tag: &nbsp; <a data-toggle="collapse" href="#ogImageMetaAlt" aria-expanded="false" aria-controls="ogImageMetaAlt"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_alt" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_alt"></p>
        <div class="collapse" id="ogImageMetaAlt">
            <div class="well">
                <p>A Short description of the image for accessibility or screen reader purposes.</p>
                <p>Example: A shiny red apple with a bite taken out.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Width: &nbsp; <a data-toggle="collapse" href="#ogImageMetaWide" aria-expanded="false" aria-controls="ogImageMetaWide"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_width" type="number" value="$sc_page_meta_og_image_width"></p>
        <div class="collapse" id="ogImageMetaWide">
            <div class="well">
                <p>Indicate how many pixels the image is wide.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Height: &nbsp; <a data-toggle="collapse" href="#ogImageMetaHeight" aria-expanded="false" aria-controls="ogImageMetaHeight"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_height" type="number" value="$sc_page_meta_og_image_height"></p>
        <div class="collapse" id="ogImageMetaHeight">
            <div class="well">
                <p>Indicate how many pixels the image is tall/high.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
    </div>
    <p><hr></p>

    <p><b>Robot Metatags (followed only by friendly search engines such as Google & Bing) &nbsp; <a data-toggle="collapse" href="#robotMetaTags" aria-expanded="false" aria-controls="robotMetaTags"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noarchive" aria-label="noarchive" $prodprobot_noarchive_checked> noarchive <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noimageindex" aria-label="noimageindex" $prodprobot_noimageindex_checked> noimageindex <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="nofollow" aria-label="nofollow" $prodprobot_nofollow_checked> nofollow
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noindex" aria-label="noindex" $prodprobot_noindex_checked> noindex
        </label>
    </div>
    </p>
    <div class="collapse" id="robotMetaTags">
        <div class="well">
              <p>Enter the tags you want friendly robots to adhere to.</p>
              <p>Default: noarchive, noimageindex<br>Note: <i>We suggest that you use these robot tags to make it harder for competitors and others to mine your images and information directly from Google search results without ever visiting your site.</i></p>
              <p><b>noarchive:</b> Do not show a "Cached" link in search results. Recommended for most sites.</p>
              <p><b>noimageindex:</b> Do not index images on this page. Recommended for most sites.</p>
              <p><b>nofollow:</b> Do not follow the links on this page. Recommended if you have lots of links or links you do not wish the search engine to follow.</p>
              <p><b>noindex:</b> Do not show this page in search results and do not show a "Cached" link in search results. For sites or pages whose complete details you do not want shown within search results, such as a privacy page, legal details, personal pages, etc.<br>
              Note: <i>we have observed Google results showing results for the site but no site information/details when this is used sitewide.</i></p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Make Page active? &nbsp; <a data-toggle="collapse" href="#ProductPagesIsActive" aria-expanded="false" aria-controls="ProductPagesIsActive"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_page_is_active">
    <option>$sc_page_is_active</option>
    <option>no</option>
    <option>yes</option>
    </select></p>
    <div class="collapse" id="ProductPagesIsActive">
         <div class="well">
             <p>This allows the page to be displayed by AgoraCart, if active</p>
             <p>Default is YES, disable by setting to NO.</p>
             <p>NOTE: if disabled, the page and link cannot be displayed. This allows it to be displayed for editing purposes or to be saved for a later date without removing the file entirely and/or accidentally activating it in the Static HTML Product Pages Manager.</p>
         </div>
     </div>
     <p><hr></p>

     <p><b>Select Custom Header For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkHeader" aria-expanded="false" aria-controls="cartlinkHeader"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_header_file">
     <option>$sc_static_page_header_file</option>
     <option></option>
     $templateheaders
     </select></p>
     <div class="collapse" id="cartlinkHeader">
          <div class="well">
              <p>This allows the page to use a custom / alternate template header when displayed.</p>
              <p>Default is empty. This would use the default header / wrapper.</p>
              <p>You may use the file editor/manager, under the <b>Custom Headers</b> tab, to copy/edit/create these types of files.</p>
              <p>NOTE: Template header files start with <b>header-</b> in the name, with the unique ID following the dash. These headers can be product category names or something else when you create the header file. Example file name would look like: header-mypageheader.tpl.</p>
          </div>
      </div>
      <p><hr></p>

      <p><b>Select Custom Footer For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkFooter" aria-expanded="false" aria-controls="cartlinkFooter"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_footer_file">
      <option>$sc_static_page_footer_file</option>
      <option></option>
      $templatefooters
      </select></p>
      <div class="collapse" id="cartlinkFooter">
           <div class="well">
               <p>This allows the page to use a custom / alternate template footer when displayed.</p>
               <p>Default is empty. This would use the default footer / wrapper.</p>
               <p>You may use the file editor/manager, under the <b>Custom Footers</b> tab, to copy/edit/create these types of files.</p>
               <p>NOTE: Template footer files start with <b>footer-</b> in the name, with the unique ID following the dash. These footers can be product category names or something else when you create the footer file. Example file name would look like: footer-mypagefooter.tpl.</p>
           </div>
       </div>
       <p><hr></p>


    <p><b>Static HTML Product Pages File Content: &nbsp; <a data-toggle="collapse" href="#ProductPages" aria-expanded="false" aria-controls="ProductPages"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ProductPages">
      <div class="well">
      <p>This is the main content for the HTML page. HTML code is accepted. Agorascript can be added here as well. If you need to add javascript, usually it should be placed in the your template's JS file.</p>
      <p>Your store template headers and footers will be automagically wrapped around this content.</p>
      <p>You only need to include content that is between the <b>body</b> tags, excluding any AgoraCart header or footer tokens: [[StoreHeader]] or %%StoreHeader%%</p>
      <p>DO NOT INCLUDE THE FOLLOWING HTML ELEMENTS:
            <ul>
                <li>Store Header or Footer tokens: [[StoreHeader]] or %%StoreHeader%% - otherwise you will get duplicate headers/footers.</li>
                <li>header/footer/head HTML tags: and contents in those areas.</li>
                <li>meta tags</li>
                <li>body HTML tags</li>
                <li>Javascript script calls, unless specific to that page. If the scripts are already in your template headers or footers, then they are already present</li>
            </ul>
      </p>
      <p>USE THE FOLLOWING TOKENS FOR FORM ELEMENTS IF YOU ARE INCLUDING A NESTED FORM:
            <ul>
                <li>[[textarea]] - for the textarea tag's word for both the opening and closing tags. Example would change from: &lt;/textarea&gt; to &lt;/[[textarea]]&gt; for the closing tag.</li>
                <li>[[formtag]] - for the form tag's word for both the opening and closing tags. Example would change from: &lt;/form&gt; to &lt;/[[formtag]]&gt; for the closing tag.</li>
            </ul>
      </p>
      </div>
    </div>
    $page_tokens_list
    <textarea name="sc_page_content" class="form-control" rows="25" wrap='on'>$sc_page_content</textarea>
    <p><br><br></p>

    <p><br><br></p>
    <input type="hidden" name="system_edit_success" value="yes">
    <input name="ChangeAProductPages" type="hidden" value="Submit">
    <button class="btn btn-primary btn-lg mgr-center" style="display: block;">Create Static HTML Product Pages File</button>
    <p><br><br><br></p>

    </form>
ENDOFTEXT

    $page_output .= &$manager_page_footer;
    print $page_output;
}

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

sub display_staticproductpags_file_editor {

    local ( $templateheaders, $templatefooters ) = q{};
    my $clean_file = $in{'productpages_name_to_edit'};
    $clean_file =~ /([\w\-\_\+]+)(\.pl)/i; # untaint
    $clean_file = "$1$2";
    my $file_name = "$1";
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";
    my $page_tokens_list = &build_sample_token_list_for_page_editor_screens();
    require_supporting_libraries( __FILE__, __LINE__, "$temp_staticproductpags_location" );
    if ( $sc_page_content eq '' ) {
        my $temp_cartlink_contents_location = "$sc_html_product_directory_path" . "/$file_name.inc";
        open( MYFILE, "$temp_cartlink_contents_location" );
        read( MYFILE, $sc_page_content, 256000 );
        close(MYFILE);
    }

    # defaults enforced if missing
    if ( $sc_page_is_active eq '' ) {
        $sc_page_is_active = 'yes';
    }
    if ( $prodprobot_noarchive_checked eq '' ) {
        $prodprobot_noarchive_checked = 'checked';
    }
    if ( $prodprobot_noimageindex_checked eq '' ) {
        $prodprobot_noimageindex_checked = 'checked';
    }
    $sc_page_content =~ s/\<textarea/\<\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<\/textarea/\<\/\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<form/\<\[\[formtag\]\]/ig;
    $sc_page_content =~ s/\<\/form/\<\/\[\[formtag\]\]/ig;

    # Read current template directory for custom product category headers and footers
    opendir( DIRTOREAD, "$sc_prod_cat_templates_dir" );
    @myfiles = readdir(DIRTOREAD);
    closedir(DIRTOREAD);
    @sorted = sort { lc($a) cmp lc($b) } @myfiles;
    @myfiles = @sorted;

    foreach $zfile (@myfiles) {
        if ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^header-/i ) ) {
            $templateheaders .= qq~<option value="$zfile">$zfile</option>\n~;
        }
        elsif ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^footer-/i ) ) {
            $templatefooters .= qq~<option value="$zfile">$zfile</option>\n~;
        }
    }

    my $page_output = &$manager_page_header( 'Product Pages Static HTML Page Editor', '', '', '', '' );

    $page_output .= <<ENDOFTEXT;

    <form class="form-horizontal" action="manager.cgi" method="post">
    <input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">
    <input type="hidden" name="prodpage_file_to_save" value="$clean_file">
    <p><br></p>
    <h2 class="mgr-page-title"><b>Product Pages File Editor</b></h2>
    <p><br></p>
    <div class="well">
    <p>Below is the current file that holds the information that is used to build the actual Static HTML Product Pages file that your store links to and displays. This file is located at: <b>$temp_staticproductpags_location</b> in your store's file directories. <br>Feel free to do any edits using the field boxes below, or for better control and reduced problems, you may manually download the Static HTML Product Pages file via FTP and make the changes manually.</p>
    <p><br></p><p><a type="button" class="btn btn-lrg btn-success mgr-center" style="display: block;" href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&display_product_pages_manager_screen=yes">Return to Static HTML Product Pages  Manager</a></p>
    </div>

ENDOFTEXT

        if ( $mgr_problem_message ) {
            $page_output .= qq|
    <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-danger">
        <h4 class="text-danger mgr-center">$mgr_problem_message</h4>
        </div>
    </div>
    <p><br><br><br><br><br></p>
    |;
        }

        $page_output .= <<ENDOFTEXT;

    <div class="checkbox">
        <label>
            <input type="checkbox" name="make_backup" value="yes" aria-label="make_backup"> <b>Create backup</b> of existing file before saving changes? <i>(recommended only when massive changes made)</i>
        </label>
    </div>
    <p><hr></p>

    <p><b>Name for this Page's Link: &nbsp; <a data-toggle="collapse" href="#linkName" aria-expanded="false" aria-controls="linkName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="mgr_link_name" type="text" class="form-control" maxlength="50" value="$mgr_link_name"></p>
    <div class="collapse" id="linkName">
        <div class="well">
              <p>This is the name use for the link when the cart builds the link lists for your active pages. This give you more flexibility over the old method of using the file name as the link name (and using underscores for spaces).</p>
              <p>Example: a file named "shipping.pl" could use a link name of: "Our Shipping Policies".</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Page Title: &nbsp; <a data-toggle="collapse" href="#pageTitle" aria-expanded="false" aria-controls="pageTitle"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_title" type="text" class="form-control" maxlength="145" value="$sc_page_title"></p>
    <div class="collapse" id="pageTitle">
        <div class="well">
              <p>This is the page title that shows in specific browser areas such as tabs or other areas. Also the default bookmark name used by most browsers.</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Description Metatag: &nbsp; <a data-toggle="collapse" href="#descriptionMeta" aria-expanded="false" aria-controls="descriptionMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_description" type="text" class="form-control" maxlength="145" value="$sc_page_meta_description"></p>
    <div class="collapse" id="descriptionMeta">
        <div class="well">
              <p>This is the description you wish to use for this page.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Keywords Metatag: &nbsp; <a data-toggle="collapse" href="#keywordsMeta" aria-expanded="false" aria-controls="keywordsMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_keywords" type="text" class="form-control" maxlength="145" value="$sc_page_meta_keywords"></p>
    <div class="collapse" id="keywordsMeta">
        <div class="well">
              <p>This is the list of keywords you wish to use for this page. Separate each word or phrase with a comma.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Optional: OG Image Meta Tag &nbsp; <a data-toggle="collapse" href="#ogImageMetaTag" aria-expanded="false" aria-controls="ogImageMetaTag"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ogImageMetaTag">
        <div class="well">
            <p>This OG (open graph protocol) Image Meta Tag allows you to control the image shown in popular social media posts when this page's URL is entered into a post.</p>
            <p>Facebook and Google both use this data. Other sites may or may not recognize the meta tags when they scrape the page URL. Scrape: collect the page information.</p>
            <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes in any of the fields for the OG image meta tag.</p>
        </div>
        <p><b>OG Image Name: &nbsp; <a data-toggle="collapse" href="#ogImageMetaName" aria-expanded="false" aria-controls="ogImageMetaName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_name" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_name"></p>
        <div class="collapse" id="ogImageMetaName">
            <div class="well">
                <p>The exact name of the image you wish to use. The image name is case sensitive: image.JPG and Image.jpg are technically 2 different images to the server due to the case, yet they both have what appears to be the same name.</p>
                <p>Image must be in the main product images directory of the store or within the active template used by your store.</p>
                <p>If you do not have a specific image in mind, you can use a logo or other image from your template.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Location: &nbsp; <a data-toggle="collapse" href="#ogImageMetaLocation" aria-expanded="false" aria-controls="ogImageMetaLocation"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_location"><option>$sc_page_meta_og_image_location</option>
        <option value=""></option>
        <option value="product">Product Directory</option>
        <option value="template">Current Template</option>
        </select></p>
        <div class="collapse" id="ogImageMetaLocation">
            <div class="well">
                <p>Locations can be within the current product image directory or the active template for the store.</p>
                <p>If using the template location, should the template be changed, the image must be copied over to the new template -- unless automatically done via the template manager's template copy function as it will copy all files in a template directory.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Mime Type: &nbsp; <a data-toggle="collapse" href="#ogImageMetaMime" aria-expanded="false" aria-controls="ogImageMetaMime"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_mime"><option>$sc_page_meta_og_image_mime</option>
        <option value=""></option>
        <option value="jpeg">jpeg/jpg</option>
        <option value="png">png</option>
        <option value="gif">gif</option>
        </select></p>
        <div class="collapse" id="ogImageMetaMime">
            <div class="well">
                <p>This is the type of image, such as jpeg, gif, or png.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Alt Tag: &nbsp; <a data-toggle="collapse" href="#ogImageMetaAlt" aria-expanded="false" aria-controls="ogImageMetaAlt"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_alt" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_alt"></p>
        <div class="collapse" id="ogImageMetaAlt">
            <div class="well">
                <p>A Short description of the image for accessibility or screen reader purposes.</p>
                <p>Example: A shiny red apple with a bite taken out.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Width: &nbsp; <a data-toggle="collapse" href="#ogImageMetaWide" aria-expanded="false" aria-controls="ogImageMetaWide"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_width" type="number" value="$sc_page_meta_og_image_width"></p>
        <div class="collapse" id="ogImageMetaWide">
            <div class="well">
                <p>Indicate how many pixels the image is wide.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Height: &nbsp; <a data-toggle="collapse" href="#ogImageMetaHeight" aria-expanded="false" aria-controls="ogImageMetaHeight"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_height" type="number" value="$sc_page_meta_og_image_height"></p>
        <div class="collapse" id="ogImageMetaHeight">
            <div class="well">
                <p>Indicate how many pixels the image is tall/high.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
    </div>
    <p><hr></p>

    <p><b>Robot Metatags (followed only by friendly search engines such as Google & Bing) &nbsp; <a data-toggle="collapse" href="#robotMetaTags" aria-expanded="false" aria-controls="robotMetaTags"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noarchive" aria-label="noarchive" $prodprobot_noarchive_checked> noarchive <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noimageindex" aria-label="noimageindex" $prodprobot_noimageindex_checked> noimageindex <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="nofollow" aria-label="nofollow" $prodprobot_nofollow_checked> nofollow
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noindex" aria-label="noindex" $prodprobot_noindex_checked> noindex
        </label>
    </div>
    </p>
    <div class="collapse" id="robotMetaTags">
        <div class="well">
              <p>Enter the tags you want friendly robots to adhere to.</p>
              <p>Default: noarchive, noimageindex<br>Note: <i>We suggest that you use these robot tags to make it harder for competitors and others to mine your images and information directly from Google search results without ever visiting your site.</i></p>
              <p><b>noarchive:</b> Do not show a "Cached" link in search results. Recommended for most sites.</p>
              <p><b>noimageindex:</b> Do not index images on this page. Recommended for most sites.</p>
              <p><b>nofollow:</b> Do not follow the links on this page. Recommended if you have lots of links or links you do not wish the search engine to follow.</p>
              <p><b>noindex:</b> Do not show this page in search results and do not show a "Cached" link in search results. For sites or pages whose complete details you do not want shown within search results, such as a privacy page, legal details, personal pages, etc.<br>
              Note: <i>we have observed Google results showing results for the site but no site information/details when this is used sitewide.</i></p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Allow this page to be activated in the main Static HTML Product Pages manager? &nbsp; <a data-toggle="collapse" href="#ProductPagesIsActive" aria-expanded="false" aria-controls="ProductPagesIsActive"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_page_is_active">
    <option>$sc_page_is_active</option>
    <option>no</option>
    <option>yes</option>
    </select></p>
    <div class="collapse" id="ProductPagesIsActive">
         <div class="well">
             <p>This allows the page to be displayed by AgoraCart, if active</p>
             <p>Default is YES, disable by setting to NO.</p>
             <p>NOTE: if disabled, the page and link cannot be displayed. This allows it to be displayed for editing purposes or to be saved for a later date without removing the file entirely and/or accidentally activating it in the Static HTML Product Pages Manager.</p>
         </div>
     </div>
     <p><hr></p>

     <p><b>Select Custom Header For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkHeader" aria-expanded="false" aria-controls="cartlinkHeader"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_header_file">
     <option>$sc_static_page_header_file</option>
     <option></option>
     $templateheaders
     </select></p>
     <div class="collapse" id="cartlinkHeader">
          <div class="well">
              <p>This allows the page to use a custom / alternate template header when displayed.</p>
              <p>Default is empty. This would use the default header / wrapper.</p>
              <p>You may use the file editor/manager, under the <b>Custom Headers</b> tab, to copy/edit/create these types of files.</p>
              <p>NOTE: Template header files start with <b>header-</b> in the name, with the unique ID following the dash. These headers can be product category names or something else when you create the header file. Example file name would look like: header-mypageheader.tpl.</p>
          </div>
      </div>
      <p><hr></p>

      <p><b>Select Custom Footer For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkFooter" aria-expanded="false" aria-controls="cartlinkFooter"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_footer_file">
      <option>$sc_static_page_footer_file</option>
      <option></option>
      $templatefooters
      </select></p>
      <div class="collapse" id="cartlinkFooter">
           <div class="well">
               <p>This allows the page to use a custom / alternate template footer when displayed.</p>
               <p>Default is empty. This would use the default footer / wrapper.</p>
               <p>You may use the file editor/manager, under the <b>Custom Footers</b> tab, to copy/edit/create these types of files.</p>
               <p>NOTE: Template footer files start with <b>footer-</b> in the name, with the unique ID following the dash. These footers can be product category names or something else when you create the footer file. Example file name would look like: footer-mypagefooter.tpl.</p>
           </div>
       </div>
       <p><hr></p>


    <p><b>Static HTML Product Pages File Content: &nbsp; <a data-toggle="collapse" href="#ProductPages" aria-expanded="false" aria-controls="ProductPages"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ProductPages">
      <div class="well">
      <p>This is the main content for the HTML page. HTML code is accepted. Agorascript can be added here as well. If you need to add javascript, usually it should be placed in the your template's JS file.</p>
      <p>Your store template headers and footers will be automagically wrapped around this content.</p>
      <p>You only need to include content that is between the <b>body</b> tags, excluding any AgoraCart header or footer tokens: [[StoreHeader]] or %%StoreHeader%%</p>
      <p>DO NOT INCLUDE THE FOLLOWING HTML ELEMENTS:
            <ul>
                <li>Store Header or Footer tokens: [[StoreHeader]] or %%StoreHeader%% - otherwise you will get duplicate headers/footers.</li>
                <li>header/footer/head HTML tags: and contents in those areas.</li>
                <li>meta tags</li>
                <li>body HTML tags</li>
                <li>Javascript script calls, unless specific to that page. If the scripts are already in your template headers or footers, then they are already present</li>
            </ul>
      </p>
      <p>USE THE FOLLOWING TOKENS FOR FORM ELEMENTS IF YOU ARE INCLUDING A NESTED FORM:
            <ul>
                <li>[[textarea]] - for the textarea tag's word for both the opening and closing tags. Example would change from: &lt;/textarea&gt; to &lt;/[[textarea]]&gt; for the closing tag.</li>
                <li>[[formtag]] - for the form tag's word for both the opening and closing tags. Example would change from: &lt;/form&gt; to &lt;/[[formtag]]&gt; for the closing tag.</li>
            </ul>
      </p>
      </div>
    </div>
    $page_tokens_list
    <textarea name="sc_page_content" class="form-control" rows="25" wrap='on'>$sc_page_content</textarea>
    <p><br><br></p>

    <p><br><br></p>
    <input type="hidden" name="system_edit_success" value="yes">
    <input name="ChangeAProductPages" type="hidden" value="Submit">
    <button class="btn btn-primary btn-lg mgr-center" style="display: block;">Update Static HTML Product Pages File</button>
    <p><br><br><br></p>

    </form>
ENDOFTEXT

    $page_output .= &$manager_page_footer;
    print $page_output;
}

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

sub convert_staticproductpags_HTML_file {

    local ( $templateheaders, $templatefooters ) = q{};
    my $clean_file = $in{'productpages_HTML_to_convert'};
    $clean_file =~ /([\w\-\_\+]+)(\.s?html?)/i; # untaint
    $clean_file = "$1$2";
    my $temp_staticproductpags_location = "$sc_html_product_directory_path" . "/$clean_file";
    my $new_name = $clean_file;
    $new_name =~ s/\.s?html?$/\.pl/i;
    my $new_file_location = "$sc_html_product_directory_path" . "/$new_name";
    my $page_tokens_list = &build_sample_token_list_for_page_editor_screens();

    open( HTMLPRODUCTPAGEFILE, "<$temp_staticproductpags_location" ) || file_open_error(
        "$temp_staticproductpags_location", 'Could not find legacy Static HTML Product Pages file', __FILE__, __LINE__ );
    while (<HTMLPRODUCTPAGEFILE>) {
        $full_legacy_staticproductpags_file .= $_;
    }
    close(HTMLPRODUCTPAGEFILE);

    # defaults enforced if missing
    if ( $sc_page_is_active eq '' ) {
        $sc_page_is_active = 'yes';
    }
    if ( $prodprobot_noarchive_checked eq '' ) {
        $prodprobot_noarchive_checked = 'checked';
    }
    if ( $prodprobot_noimageindex_checked eq '' ) {
        $prodprobot_noimageindex_checked = 'checked';
    }
    $sc_page_content =~ s/\<textarea/\<\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<\/textarea/\<\/\[\[textarea\]\]/ig;
    $sc_page_content =~ s/\<form/\<\[\[formtag\]\]/ig;
    $sc_page_content =~ s/\<\/form/\<\/\[\[formtag\]\]/ig;

    # Read current template directory for custom product category headers and footers
    opendir( DIRTOREAD, "$sc_prod_cat_templates_dir" );
    @myfiles = readdir(DIRTOREAD);
    closedir(DIRTOREAD);
    @sorted = sort { lc($a) cmp lc($b) } @myfiles;
    @myfiles = @sorted;

    foreach $zfile (@myfiles) {
        if ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^header-/i ) ) {
            $templateheaders .= qq~<option value="$zfile">$zfile</option>\n~;
        }
        elsif ( ( $zfile =~ /\.tpl$/i ) && ( $zfile =~ /^footer-/i ) ) {
            $templatefooters .= qq~<option value="$zfile">$zfile</option>\n~;
        }
    }

    my $page_output = &$manager_page_header( 'Static HTML Product Pages File Conversion Editor', '', '', '', '' );

    $page_output .= <<ENDOFTEXT;
    <p><br></p>
    <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">New Version</a></li>
        <li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">Old Version</a></li>
    </ul>

    <div class="tab-content">

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

    <form class="form-horizontal" action="manager.cgi" method="post">
    <input type="hidden" name="mgr_seshun" value="$in{'mgr_seshun'}">
    <input type="hidden" name="prodpage_file_to_save" value="$new_name">
    <p><br></p>
    <h2 class="mgr-page-title"><b>Product Pages HTML Page Converter</b></h2>
    <p><br></p>
    <div class="well">
    <p>
    <p>The "Old Version" tab is the current file that holds the information that is used to build the actual Static HTML Product Pages file that your store links to and displays. This legacy file is located at: <b>$temp_staticproductpags_location</b> in your store's file directories and the new version will be saved to $new_file_location. <br>Feel free to do cut and paste (and edit) what you need from the "Old Version" tab into the "Static HTML Product Pages File Content" box below.  Or you may manually download and create the Static HTML Product Pages files via FTP and make any changes and then upload the new/changed files via FTP to the appropriate location (listed above).</p>
    <p><br></p><p><a type="button" class="btn btn-lrg btn-success mgr-center" style="display: block;" href="manager.cgi?mgr_seshun=$in{'mgr_seshun'}&display_product_pages_manager_screen=yes">Return to Static HTML Product Pages Manager</a></p>
    </div>

    <p><b>Name for this Page's Link: &nbsp; <a data-toggle="collapse" href="#linkName" aria-expanded="false" aria-controls="linkName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="mgr_link_name" type="text" class="form-control" maxlength="50" value="$mgr_link_name"></p>
    <div class="collapse" id="linkName">
        <div class="well">
              <p>This is the name use for the link when the cart builds the link lists for your active pages. This give you more flexibility over the old method of using the file name as the link name (and using underscores for spaces).</p>
              <p>Example: a file named "shipping.pl" could use a link name of: "Our Shipping Policies".</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Page Title: &nbsp; <a data-toggle="collapse" href="#pageTitle" aria-expanded="false" aria-controls="pageTitle"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_title" type="text" class="form-control" maxlength="145" value="$sc_page_title"></p>
    <div class="collapse" id="pageTitle">
        <div class="well">
              <p>This is the page title that shows in specific browser areas such as tabs or other areas. Also the default bookmark name used by most browsers.</p>
              <p>Do not use these special metacharacters (\$,%,&,\@).</p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Description Metatag: &nbsp; <a data-toggle="collapse" href="#descriptionMeta" aria-expanded="false" aria-controls="descriptionMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_description" type="text" class="form-control" maxlength="145" value="$sc_page_meta_description"></p>
    <div class="collapse" id="descriptionMeta">
        <div class="well">
              <p>This is the description you wish to use for this page.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Keywords Metatag: &nbsp; <a data-toggle="collapse" href="#keywordsMeta" aria-expanded="false" aria-controls="keywordsMeta"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_keywords" type="text" class="form-control" maxlength="145" value="$sc_page_meta_keywords"></p>
    <div class="collapse" id="keywordsMeta">
        <div class="well">
              <p>This is the list of keywords you wish to use for this page. Separate each word or phrase with a comma.</p>
              <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes.</p>
        </div>
    </div>
    <p><hr></p>

    <p><b>Optional: OG Image Meta Tag &nbsp; <a data-toggle="collapse" href="#ogImageMetaTag" aria-expanded="false" aria-controls="ogImageMetaTag"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ogImageMetaTag">
        <div class="well">
            <p>This OG (open graph protocol) Image Meta Tag allows you to control the image shown in popular social media posts when this page's URL is entered into a post.</p>
            <p>Facebook and Google both use this data. Other sites may or may not recognize the meta tags when they scrape the page URL. Scrape: collect the page information.</p>
            <p>Do not use special metacharacters (\$,%,&,\@ etc) nor double quotes in any of the fields for the OG image meta tag.</p>
        </div>
        <p><b>OG Image Name: &nbsp; <a data-toggle="collapse" href="#ogImageMetaName" aria-expanded="false" aria-controls="ogImageMetaName"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_name" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_name"></p>
        <div class="collapse" id="ogImageMetaName">
            <div class="well">
                <p>The exact name of the image you wish to use. The image name is case sensitive: image.JPG and Image.jpg are technically 2 different images to the server due to the case, yet they both have what appears to be the same name.</p>
                <p>Image must be in the main product images directory of the store or within the active template used by your store.</p>
                <p>If you do not have a specific image in mind, you can use a logo or other image from your template.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Location: &nbsp; <a data-toggle="collapse" href="#ogImageMetaLocation" aria-expanded="false" aria-controls="ogImageMetaLocation"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_location"><option>$sc_page_meta_og_image_location</option>
        <option value=""></option>
        <option value="product">Product Directory</option>
        <option value="template">Current Template</option>
        </select></p>
        <div class="collapse" id="ogImageMetaLocation">
            <div class="well">
                <p>Locations can be within the current product image directory or the active template for the store.</p>
                <p>If using the template location, should the template be changed, the image must be copied over to the new template -- unless automatically done via the template manager's template copy function as it will copy all files in a template directory.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Mime Type: &nbsp; <a data-toggle="collapse" href="#ogImageMetaMime" aria-expanded="false" aria-controls="ogImageMetaMime"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><select name="sc_page_meta_og_image_mime"><option>$sc_page_meta_og_image_mime</option>
        <option value=""></option>
        <option value="jpeg">jpeg/jpg</option>
        <option value="png">png</option>
        <option value="gif">gif</option>
        </select></p>
        <div class="collapse" id="ogImageMetaMime">
            <div class="well">
                <p>This is the type of image, such as jpeg, gif, or png.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Alt Tag: &nbsp; <a data-toggle="collapse" href="#ogImageMetaAlt" aria-expanded="false" aria-controls="ogImageMetaAlt"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_alt" type="text" class="form-control" maxlength="100" value="$sc_page_meta_og_image_alt"></p>
        <div class="collapse" id="ogImageMetaAlt">
            <div class="well">
                <p>A Short description of the image for accessibility or screen reader purposes.</p>
                <p>Example: A shiny red apple with a bite taken out.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Width: &nbsp; <a data-toggle="collapse" href="#ogImageMetaWide" aria-expanded="false" aria-controls="ogImageMetaWide"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_width" type="number" value="$sc_page_meta_og_image_width"></p>
        <div class="collapse" id="ogImageMetaWide">
            <div class="well">
                <p>Indicate how many pixels the image is wide.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
        <p><b>OG Image Height: &nbsp; <a data-toggle="collapse" href="#ogImageMetaHeight" aria-expanded="false" aria-controls="ogImageMetaHeight"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span><input name="sc_page_meta_og_image_height" type="number" value="$sc_page_meta_og_image_height"></p>
        <div class="collapse" id="ogImageMetaHeight">
            <div class="well">
                <p>Indicate how many pixels the image is tall/high.</p>
                <p>This is required if the image tag is filled in.</p>
            </div>
        </div>
        <p><hr></p>
    </div>
    <p><hr></p>

    <p><b>Robot Metatags (followed only by friendly search engines such as Google & Bing) &nbsp; <a data-toggle="collapse" href="#robotMetaTags" aria-expanded="false" aria-controls="robotMetaTags"><i class="fa fa-info-circle"></i></a></b><span style="padding-left: 25px;"></span>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noarchive" aria-label="noarchive" $prodprobot_noarchive_checked> noarchive <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noimageindex" aria-label="noimageindex" $prodprobot_noimageindex_checked> noimageindex <i>(recommended)</i>
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="nofollow" aria-label="nofollow" $prodprobot_nofollow_checked> nofollow
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" name="metarobots" value="noindex" aria-label="noindex" $prodprobot_noindex_checked> noindex
        </label>
    </div>
    </p>
    <div class="collapse" id="robotMetaTags">
        <div class="well">
              <p>Enter the tags you want friendly robots to adhere to.</p>
              <p>Default: noarchive, noimageindex<br>Note: <i>We suggest that you use these robot tags to make it harder for competitors and others to mine your images and information directly from Google search results without ever visiting your site.</i></p>
              <p><b>noarchive:</b> Do not show a "Cached" link in search results. Recommended for most sites.</p>
              <p><b>noimageindex:</b> Do not index images on this page. Recommended for most sites.</p>
              <p><b>nofollow:</b> Do not follow the links on this page. Recommended if you have lots of links or links you do not wish the search engine to follow.</p>
              <p><b>noindex:</b> Do not show this page in search results and do not show a "Cached" link in search results. For sites or pages whose complete details you do not want shown within search results, such as a privacy page, legal details, personal pages, etc.<br>
              Note: <i>we have observed Google results showing results for the site but no site information/details when this is used sitewide.</i></p>
        </div>
    </div>
    <p><hr></p>


    <p><b>Allow this page to be activated in the main Static HTML Product Pages manager? &nbsp; <a data-toggle="collapse" href="#ProductPagesIsActive" aria-expanded="false" aria-controls="ProductPagesIsActive"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_page_is_active">
    <option>$sc_page_is_active</option>
    <option>no</option>
    <option>yes</option>
    </select></p>
    <div class="collapse" id="ProductPagesIsActive">
         <div class="well">
             <p>This allows the page to be displayed by AgoraCart, if active</p>
             <p>Default is YES, disable by setting to NO.</p>
             <p>NOTE: if disabled, the page and link cannot be displayed. This allows it to be displayed for editing purposes or to be saved for a later date without removing the file entirely and/or accidentally activating it in the Static HTML Product Pages Manager.</p>
         </div>
     </div>
     <p><hr></p>

     <p><b>Select Custom Header For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkHeader" aria-expanded="false" aria-controls="cartlinkHeader"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_header_file">
     <option>$sc_static_page_header_file</option>
     <option></option>
     $templateheaders
     </select></p>
     <div class="collapse" id="cartlinkHeader">
          <div class="well">
              <p>This allows the page to use a custom / alternate template header when displayed.</p>
              <p>Default is empty. This would use the default header / wrapper.</p>
              <p>You may use the file editor/manager, under the <b>Custom Headers</b> tab, to copy/edit/create these types of files.</p>
              <p>NOTE: Template header files start with <b>header-</b> in the name, with the unique ID following the dash. These headers can be product category names or something else when you create the header file. Example file name would look like: header-mypageheader.tpl.</p>
          </div>
      </div>
      <p><hr></p>

      <p><b>Select Custom Footer For This Page &nbsp; <a data-toggle="collapse" href="#cartlinkFooter" aria-expanded="false" aria-controls="cartlinkFooter"><i class="fa fa-info-circle"></i></a></b> <span style="padding-left: 25px;"></span><select name="sc_static_page_footer_file">
      <option>$sc_static_page_footer_file</option>
      <option></option>
      $templatefooters
      </select></p>
      <div class="collapse" id="cartlinkFooter">
           <div class="well">
               <p>This allows the page to use a custom / alternate template footer when displayed.</p>
               <p>Default is empty. This would use the default footer / wrapper.</p>
               <p>You may use the file editor/manager, under the <b>Custom Footers</b> tab, to copy/edit/create these types of files.</p>
               <p>NOTE: Template footer files start with <b>footer-</b> in the name, with the unique ID following the dash. These footers can be product category names or something else when you create the footer file. Example file name would look like: footer-mypagefooter.tpl.</p>
           </div>
       </div>
       <p><hr></p>


    <p><b>Static HTML Product Pages File Content: &nbsp; <a data-toggle="collapse" href="#ProductPages" aria-expanded="false" aria-controls="ProductPages"><i class="fa fa-info-circle"></i></a></b></p>
    <div class="collapse" id="ProductPages">
      <div class="well">
      <p>This is the main content for the HTML page. HTML code is accepted. Agorascript can be added here as well. If you need to add javascript, usually it should be placed in the your template's JS file.</p>
      <p>Your store template headers and footers will be automagically wrapped around this content.</p>
      <p>You only need to include content that is between the <b>body</b> tags, excluding any AgoraCart header or footer tokens: [[StoreHeader]] or %%StoreHeader%%</p>
      <p>DO NOT INCLUDE THE FOLLOWING HTML ELEMENTS:
            <ul>
                <li>Store Header or Footer tokens: [[StoreHeader]] or %%StoreHeader%% - otherwise you will get duplicate headers/footers.</li>
                <li>header/footer/head HTML tags: and contents in those areas.</li>
                <li>meta tags</li>
                <li>body HTML tags</li>
                <li>Javascript script calls, unless specific to that page. If the scripts are already in your template headers or footers, then they will be included automagically via the template during display.</li>
            </ul>
      </p>
      <p>USE THE FOLLOWING TOKENS FOR FORM ELEMENTS IF YOU ARE INCLUDING A NESTED FORM:
            <ul>
                <li>[[textarea]] - for the textarea tag's word for both the opening and closing tags. Example would change from: &lt;/textarea&gt; to &lt;/[[textarea]]&gt; for the closing tag.</li>
                <li>[[formtag]] - for the form tag's word for both the opening and closing tags. Example would change from: &lt;/form&gt; to &lt;/[[formtag]]&gt; for the closing tag.</li>
            </ul>
      </p>
      </div>
    </div>
    $page_tokens_list
    <textarea name="sc_page_content" class="form-control" rows="25" wrap='on'>$sc_page_content</textarea>
    <p><br><br></p>

    <p><br><br></p>
    <input type="hidden" name="system_edit_success" value="yes">
    <input name="ChangeAProductPages" type="hidden" value="Submit">
    <button class="btn btn-primary btn-lg mgr-center" style="display: block;">Convert Static HTML Product Pages File</button>
    <p><br><br><br></p>

    </form>
</div>


    <!-- End of tab 1 -->


<div class="tab-pane" id="tabs-2">
<form class="form-horizontal">


<p><br></p>
<h2 class="mgr-page-title"><b>Legacy Static HTML Product Pages File</b></h2>

<p>This area allows you to view the Legacy Static HTML Product Pages file. Use it to copy information you need to transfer to the new version.</p>

<p><hr></p>

<p><b>Legacy HTML File:</b></p>
<textarea name="changed_template_manifest_file" class="form-control" rows="30" wrap="off">$full_legacy_staticproductpags_file</textarea>
<p><br><br></p>



    <!-- End of tab 12 -->

</div>
<p><br><br></p>
</div>
ENDOFTEXT

    $page_output .= &$manager_page_footer;
    print $page_output;
}

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

1;
