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

global $campoal_options;
global $post;
global $current_user;

$sign_victory = isset($campoal_options['conikal_sign_victory_field']) ? $campoal_options['conikal_sign_victory_field'] : 0;

$post_type = get_post_type($post->ID);
if ($post_type != 'petition') {
    $petition_id = get_post_meta($post->ID, $post_type . '_post_id', true);
} else {
    $petition_id = $post->ID;
}

$goal = get_post_meta($petition_id, 'petition_goal', true);
$supporter_number = conikal_get_supporter_donors_number($petition_id);
$goal = $supporter_number->goal;
$sign_num = $supporter_number->sign;
$status = get_post_meta($petition_id, 'petition_status', true);

// get supporters
$sign = get_user_meta($current_user->ID, 'petition_sign', true);
$sign = $sign != '' ? $sign : array();
?>

<!-- TABLET SIGN PETITION BUTTON -->
<div class="ui sticky tablet-sign-btn display-mobile display-tablet only" id="tablet-sign-btn<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
    <div class="ui attached segment">
        <div class="ui grid mobile tablet only">
            <div class="sixteen wide column">
            <?php if(is_user_logged_in()) { 
                if(in_array($petition_id, $sign) === false && (int)$sign_num < (int)$goal && (int)$status == 0) { ?>
                    <a href="#sign-section" class="ui primary fluid large button"><?php echo conikal_custom_icon('sign') ?><?php esc_html_e('Sign this petition', 'campoal') ?></a>
                <?php } else { ?>
                    <a href="#sign-section" class="ui primary fluid large button"><?php echo conikal_custom_icon('share') ?><?php esc_html_e('Share this petition', 'campoal') ?></a>
                <?php } ?>
            <?php } else if ($sign_victory == 1) { ?>
                <a href="#sign-section" class="ui primary fluid large button"><?php echo conikal_custom_icon('sign') ?><?php esc_html_e('Sign this petition', 'campoal') ?></a>
            <?php } else {
                if((int)$sign_num < (int)$goal && (int)$status == 0) { ?>
                    <a href="#sign-section" class="ui primary fluid large button"><?php echo conikal_custom_icon('sign') ?><?php esc_html_e('Sign this petition', 'campoal') ?></a>
                <?php } else { ?>
                    <a href="#sign-section" class="ui primary fluid large button"><?php echo conikal_custom_icon('share') ?><?php esc_html_e('Share this petition', 'campoal') ?></a>
                <?php } ?>
            <?php } ?>
            </div>
        </div>
    </div>
</div>