<?php

class TFL_Register_Meta_Box
{
    function __construct()
    {
        add_action('add_meta_boxes', array($this, 'tfl_register_mutiple_fields'));
        add_action('save_post', array($this, 'tfl_save_multiple_fields_metabox'));
    }

    function tfl_register_mutiple_fields() {
        add_meta_box(
            'tfl-metabox-multiple-fields',
            'Metabox Fields',
            array($this, 'tfl_add_multiple_fields'),
            'service'
        );
    }

    function tfl_add_multiple_fields(){
        global $post;
        $tfl_sub_img = get_post_meta( $post->ID, '_tfl_sub_img', true);
        $tfl_sub2_img = get_post_meta( $post->ID, '_tfl_sub2_img', true);
        $tfl_thumb2_img = get_post_meta( $post->ID, '_tfl_thumb2_img', true);
        $tfl_icon_v2 = get_post_meta( $post->ID, '_tfl_icon_v2', true);
        $tfl_icon2_v2 = get_post_meta( $post->ID, '_tfl_icon2_v2', true);

        $tfl_breadcrumb_img = get_post_meta( $post->ID, '_tfl_breadcrumb_img', true);
        $tfl_ceo = get_post_meta( $post->ID, '_tfl_ceo', true);
        $tfl_fone = get_post_meta( $post->ID, '_tfl_fone', true);
        $tfl_location = get_post_meta( $post->ID, '_tfl_location', true);
        $tfl_mail = get_post_meta( $post->ID, '_tfl_mail', true);
        $tfl_download = get_post_meta( $post->ID, '_tfl_download', true);
        $tfl_discover = get_post_meta( $post->ID, '_tfl_discover', true);
        $tfl_textareafield = get_post_meta( $post->ID, '_tfl_textarea_field', true);
        ?>
        <div class="row">
            <div class="label">Background Image Breadcrumb Single Services </div>
            <div class="fields"><input type="text" name="_tfl_breadcrumb_img" value="<?php echo $tfl_breadcrumb_img; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Sub Image</div>
            <div class="fields"><input type="text" name="_tfl_sub_img" value="<?php echo $tfl_sub_img; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Sub2 Image</div>
            <div class="fields"><input type="text" name="_tfl_sub2_img" value="<?php echo $tfl_sub2_img; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Thumbnail V2</div>
            <div class="fields"><input type="text" name="_tfl_thumb2_img" value="<?php echo $tfl_thumb2_img; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Icon V2</div>
            <div class="fields"><input type="text" name="_tfl_icon_v2" value="<?php echo $tfl_icon_v2; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Icon2 V2</div>
            <div class="fields"><input type="text" name="_tfl_icon2_v2" value="<?php echo $tfl_icon2_v2; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Ceo</div>
            <div class="fields"><input type="text" name="_tfl_ceo" value="<?php echo $tfl_ceo; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Phone</div>
            <div class="fields"><input type="text" name="_tfl_fone" value="<?php echo $tfl_fone; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Location</div>
            <div class="fields"><input type="text" name="_tfl_location" value="<?php echo $tfl_location; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Mail</div>
            <div class="fields"><input type="text" name="_tfl_mail" value="<?php echo $tfl_mail; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Download</div>
            <div class="fields"><input type="text" name="_tfl_download" value="<?php echo $tfl_download; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Discover</div>
            <div class="fields"><input type="text" name="_tfl_discover" value="<?php echo $tfl_discover; ?>"</div>
        </div>

        <div class="row">
            <div class="label">Textarea</div>
            <div class="fields">
                <textarea rows="5" name="_tfl_textarea_field"><?php echo $tfl_textareafield; ?></textarea>
            </div>
        </div>
        <?php
    }

    function tfl_save_multiple_fields_metabox(){
        global $post;

        if(isset($_POST["_tfl_breadcrumb_img"])) :
            update_post_meta($post->ID, '_tfl_breadcrumb_img', $_POST["_tfl_breadcrumb_img"]);
        endif;

        if(isset($_POST["_tfl_sub_img"])) :
            update_post_meta($post->ID, '_tfl_sub_img', $_POST["_tfl_sub_img"]);
        endif;

        if(isset($_POST["_tfl_sub2_img"])) :
            update_post_meta($post->ID, '_tfl_sub2_img', $_POST["_tfl_sub2_img"]);
        endif;

        if(isset($_POST["_tfl_thumb2_img"])) :
            update_post_meta($post->ID, '_tfl_thumb2_img', $_POST["_tfl_thumb2_img"]);
        endif;

        if(isset($_POST["_tfl_icon_v2"])) :
            update_post_meta($post->ID, '_tfl_icon_v2', $_POST["_tfl_icon_v2"]);
        endif;

        if(isset($_POST["_tfl_icon2_v2"])) :
            update_post_meta($post->ID, '_tfl_icon2_v2', $_POST["_tfl_icon2_v2"]);
        endif;


        if(isset($_POST["_tfl_ceo"])) :
            update_post_meta($post->ID, '_tfl_ceo', $_POST["_tfl_ceo"]);
        endif;

        if(isset($_POST["_tfl_fone"])) :
            update_post_meta($post->ID, '_tfl_fone', $_POST["_tfl_fone"]);
        endif;

        if(isset($_POST["_tfl_location"])) :
            update_post_meta($post->ID, '_tfl_location', $_POST["_tfl_location"]);
        endif;

        if(isset($_POST["_tfl_mail"])) :
            update_post_meta($post->ID, '_tfl_mail', $_POST["_tfl_mail"]);
        endif;

        if(isset($_POST["_tfl_download"])) :
            update_post_meta($post->ID, '_tfl_download', $_POST["_tfl_download"]);
        endif;

        if(isset($_POST["_tfl_discover"])) :
            update_post_meta($post->ID, '_tfl_discover', $_POST["_tfl_discover"]);
        endif;

        if(isset($_POST["_tfl_textarea_field"])) :
            update_post_meta($post->ID, '_tfl_textarea_field', $_POST["_tfl_textarea_field"]);
        endif;
    }

}

$tfl_register_post_type = new TFL_Register_Meta_Box();