<?php 
/**
 * @package WordPress
 * @subpackage Campoal
 */
global $post;

$give_prefix        = '_give_';

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

// get petition citation status
$citation = conikal_citation_status($petition_id);

// get form option
if (get_post_type($petition_id) != 'give_forms') {
    $form_id = get_post_meta($petition_id, 'petition_contribute', true);
    $contribute_approve = get_post_status($form_id);
    if ($contribute_approve != 'publish') {
        $form_id = '';
    }
} else {
    $form_id = $petition_id;
}

$reveal_label = get_post_meta($form_id, '_give_reveal_label', true);

// get fundraising mode setting
$fundraising_mode = conikal_fundraising_mode_setting($petition_id);

// check user has purchases
$user_contribute = conikal_user_purchased_donation($form_id);

$goal_option        = get_post_meta($form_id, $give_prefix . 'goal_option', true);
$raise_number       = conikal_get_supporter_donors_number($form_id, 'donor', true);

$give_attrs['id'] = $form_id;
$give_attrs['show_goal'] = false;

if (isset($form_id) && $form_id != '' && class_exists('Give')) { ?>
    <?php if ($fundraising_mode == 0) : ?>
        <?php if (give_is_setting_enabled( $goal_option )) : ?>
            <div class="ui tiny header">
                <?php echo sprintf( esc_html__('%1$s of %2$s raised', 'campoal'), esc_html($raise_number->sign_format), esc_html($raise_number->goal_format) ) ?>
            </div>
            <div class="ui tiny primary progress petition-goal" data-value="<?php echo esc_attr($raise_number->sign) ?>" data-total="<?php echo esc_attr($raise_number->goal) ?>">
                <div class="bar">
                    <div class="progress"></div>
                </div>
            </div>
        <?php endif; ?>
    <?php endif; ?>
    <?php echo give_form_shortcode($give_attrs);
} 
?>
<div class="ui hidden divider"></div>

<?php if ($citation && is_user_logged_in()) { ?>
    <form class="ui form">
        <?php get_template_part('templates/citation-opinion', 'add'); ?>
    </form>
<?php } ?>
