<?php
if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}
?>

<form method="post" action="options.php" id="" class="egps_email_options">

<?php 
    settings_fields( 'egps_email_data' );
    do_settings_sections( 'egps_email_data' ); 


    $egps_email_opt = get_option('egps_email_options');

    if($egps_email_opt == null){
        Egps::egps_errordump( array("Form not saved" => "Please modify and save the form by clicking on the 'Save Changes' button.") );
    }

    $mailform = new EgpsEmailSend;

    $field_array = $mailform->egpsEmailGetFields();

    $dataout = $mailform->egpsEmailFieldData($egps_email_opt, $field_array);

    ?>


<h3>EGPS Registration email</h3>

    <p>
        Write a <b>single #</b> character in the field you want to leave out of the email<br>
        Subject and Title are mandatory.
    </p>
  
    <table class="form-table" role="presentation">
        <tbody>

            <tr>
                <th scope="row">Subject</th>
                <td>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[subject]" 
                        value="<?php echo esc_html($dataout["subject"]); ?>">                  
                </td>
            </tr>

            <tr>
                <th scope="row">Title</th>
                <td>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[title]" 
                        value="<?php echo esc_html($dataout["title"]); ?>">                  
                </td>
            </tr>

            <tr>
                <th scope="row">Main text</th>
                <td>
                    <textarea 
                        rows="7" cols="50"  
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[intro]" 
                        value=""><?php echo esc_html($dataout["intro"]); ?></textarea>               
                </td>
            </tr>

            <tr>
                <th scope="row">URL</th>
                <td>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[url_text]" 
                        value="<?php echo esc_html($dataout["url_text"]); ?>"><br>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[url]" 
                        value="<?php echo esc_html($dataout["url"]); ?>">               
                </td>
            </tr>

            <tr>
                <th scope="row">Sub text</th>
                <td>
                    <textarea 
                        rows="7" cols="50"  
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[text_main]" 
                        value=""><?php echo esc_html($dataout["text_main"]); ?></textarea>               
                </td>
            </tr>

            <tr>
                <th scope="row">Footer text</th>
                <td>
                    <textarea 
                        rows="7" cols="50"  
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[text_bottom]" 
                        value=""><?php echo esc_html($dataout["text_bottom"]); ?></textarea>               
                </td>
            </tr>

            <tr>
                <th scope="row">Facebook link</th>
                <td>
                    
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[link_fb]" 
                        value="<?php echo esc_html($dataout["link_fb"]); ?>">               
                </td>
            </tr>

            <tr>
                <th scope="row">X (Twitter) link</th>
                <td>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[link_twit]" 
                        value="<?php echo esc_html($dataout["link_twit"]); ?>">               
                </td>
            </tr>

            <tr>
                <th scope="row">Instagram link</th>
                <td>
                    <input 
                        type="text" 
                        class="egps_admin_fields_500" 
                        name="egps_email_options[link_insta]" 
                        value="<?php echo esc_html($dataout["link_insta"]); ?>">              
                </td>
            </tr>

        </tbody>
    </table>

    <?php submit_button(); ?>

</form>


<?php

echo "<h3>Email preview:</h3>";

$out = $mailform->egpsEmailTemplate();

$arr_allowed = Egps::egps_email_admin_out_allowed();

echo '<body class="clean-body u_body" style="
margin: 0;
padding: 0;
padding-top: 25px;
-webkit-text-size-adjust: 100%;
background-image: linear-gradient(to bottom, #116466, #00c9cc);
color: #000000
">';
echo '<div style="background-image: linear-gradient(to bottom, #116466, #00c9cc); padding-top:25px;">' . wp_kses($out, $arr_allowed) . "</div>";
echo '</body>';
