<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
?>
<?php
$current_user = wp_get_current_user();
$upload_dir = wp_upload_dir();
$profile_type = get_user_meta($current_user->ID, 'user_type', true);
$profile_type = $profile_type != '' ? $profile_type : 'petitioner';
$user_decisionmakers = get_user_meta($current_user->ID, 'user_decision', true);

$prefix = 'decisionmaker_';
$decision_title     =  wp_get_post_terms($user_decisionmakers, 'decisionmakers_title', true);
$decision_title     = ($decision_title ? $decision_title[0]->name : '');
$organization       =  wp_get_post_terms($user_decisionmakers, 'decisionmakers_organization', true);
$organization       = ($organization ? $organization[0]->name : '');

$indentify_verified             = get_post_meta($user_decisionmakers, $prefix . 'indentify_verified', true);
$indentify_type                 = get_post_meta($user_decisionmakers, $prefix . 'indentify_type', true);
$indentify_name                 = get_post_meta($user_decisionmakers, $prefix . 'indentify_name', true);
$indentify_id                   = get_post_meta($user_decisionmakers, $prefix . 'indentify_id', true);
$indentify_frontside_photo_id   = get_post_meta($user_decisionmakers, $prefix . 'indentify_frontside_photo', true);
$indentify_frontside_photo      = wp_get_attachment_image_src($indentify_frontside_photo_id, 'large');
$indentify_frontside_photo      = ($indentify_frontside_photo ? $indentify_frontside_photo[0] : '');
$indentify_backside_photo_id    = get_post_meta($user_decisionmakers, $prefix . 'indentify_backside_photo', true);
$indentify_backside_photo       = wp_get_attachment_image_src($indentify_backside_photo_id, 'large');
$indentify_backside_photo       = ($indentify_backside_photo ? $indentify_backside_photo[0] : '');
$indentify_other_photo_id       = get_post_meta($user_decisionmakers, $prefix . 'indentify_other_photo', true);
$indentify_other_photo          = wp_get_attachment_image_src($indentify_other_photo_id, 'large');
$indentify_other_photo          = ($indentify_other_photo ? $indentify_other_photo[0] : '');


// set indentity document correct with document side
$tab = isset($_GET['tab']) ? $_GET['tab'] : '';
$upload_tab = isset($_GET['upload']) ? $_GET['upload'] : 'front';
switch ($upload_tab) {
    case 'front':
        $indentify_document_id  = $indentify_frontside_photo_id;
        $indentify_document_url = $indentify_frontside_photo;
        break;

    case 'back':
        $indentify_document_id  = $indentify_backside_photo_id;
        $indentify_document_url = $indentify_backside_photo;
        break;

    case 'other':
        $indentify_document_id  = $indentify_other_photo_id;
        $indentify_document_url = $indentify_other_photo;
        break;
    
    default:
        $indentify_document_id  = '';
        $indentify_document_url = '';
        break;
}

// parse document photo is url or not
$parse_document_photo = wp_parse_url($indentify_document_url, PHP_URL_SCHEME);
?>
<div class="<?php echo esc_attr(!empty($indentify_document_url) ? '' : 'box-upload') ?>" id="box-upload">
    <div id="upload-container">
        <div id="aaiu-upload-container">
            <div id="aaiu-upload-imagelist"></div>
            <div id="imagelist">
                <?php if (!empty($indentify_document_url)) { ?>
                    <div class="ui fluid bordered image">
                        <img src="<?php echo esc_url($parse_document_photo ? $indentify_document_url : $upload_dir['baseurl'] . '/' . $indentify_document_url); ?>" file="<?php echo esc_attr($indentify_document_url) ?>" alt="<?php echo esc_attr($indentify_document_url) ?>" />
                        <label class="ui top right attached label deleteImage"><i class="right trash icon"></i><?php esc_html_e('Delete', 'campoal') ?></label>
                    </div>
                <?php } ?>
            </div>
            <div class="clearfix"></div>
            <div class="ui center aligned basic segment <?php echo esc_attr($indentify_document_url ? 'display none' : 'display block') ?>" id="upload-tool">
                <img src="<?php echo get_template_directory_uri() ?>/images/passport-placeholder.svg" width="128" class="position-block-center">
                <div class="ui divider hidden"></div>
                <a href="javascript:void(0);" id="aaiu-uploader" class="ui basic button"><i class="folder outline open icon"></i><?php esc_html_e('Browse Images', 'campoal');?></a>
            </div>
            <input type="hidden" name="new_gallery" id="new_gallery" value="<?php echo esc_attr($indentify_document_url ? '~~~' . $indentify_document_url : '') ?>">
            <input type="hidden" id="new_attach" name="new_attach" value="<?php echo esc_attr($indentify_document_id ? $indentify_document_id : '') ?>">
        </div>
    </div>
</div>