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

// common donation form 
$common_donation_form  	= isset($campoal_options['conikal_common_donation_form_field']) ? $campoal_options['conikal_common_donation_form_field'] : 0;
$common_form_id     	= isset($campoal_options['conikal_common_form_id_field']) ? $campoal_options['conikal_common_form_id_field'] : 0;

$petition_id = $post->ID;

// get form id
$form_id = get_post_meta($petition_id, 'petition_contribute', true);
$contribute_approve = get_post_status($form_id);
if ($contribute_approve === 'pending') {
    $form_id = '';
}

if ( is_user_logged_in() && (get_the_author_meta('ID') == $current_user->ID || current_user_can('administrator') || current_user_can('editor') || conikal_co_author_permission($petition_id)) ) { 
    $page_dashboard_petition = isset($campoal_options['conikal_page_dashboard_petition_field']) ? $campoal_options['conikal_page_dashboard_petition_field'] : 0;
    $page_dashboard_petition = get_permalink($page_dashboard_petition); ?>
    <div class="color silver">
        <div class="ui large secondary pointing menu" id="control-menu">
            <div class="ui container">
                <!-- Campaign link -->
                <a href="javascript:void(0)" class="active item" data-bjax><?php esc_html_e('Campaign', 'campoal') ?></a>

                <!-- Dashboard link -->
                <?php if ($page_dashboard_petition) {
                    $page_dashboard = add_query_arg(array('section' => 'dashboard', 'id' => $petition_id), $page_dashboard_petition); ?>
                    <a class="item" href="<?php echo esc_url($page_dashboard); ?>" data-bjax><?php esc_html_e('Dashboard', 'campoal') ?></a>
                <?php } ?>

                <!-- Supporter list -->
                <?php if ($page_dashboard_petition) {
                    $page_dashboard = add_query_arg(array('section' => 'supporters', 'id' => $petition_id, 'type' => 'supporter'), $page_dashboard_petition); ?>
                    <a class="<?php echo esc_attr($section == 'supporters' ? 'active ' : '') ?>item" href="<?php echo esc_url($page_dashboard); ?>" data-bjax><?php esc_html_e('Supporters', 'campoal') ?></a>
                <?php } ?>

                <!-- Donors list -->
                <?php if (class_exists('Give') && $page_dashboard_petition && empty($common_donation_form) && empty($common_form_id) && !empty($form_id)) {
                    $page_dashboard = add_query_arg(array('section' => 'donors', 'id' => $petition_id, 'type' => 'donor'), $page_dashboard_petition); ?>
                    <a class="<?php echo esc_attr($section == 'donors' ? 'active ' : '') ?>item" href="<?php echo esc_url($page_dashboard); ?>" data-bjax><?php esc_html_e('Donors', 'campoal') ?></a>
                <?php } ?>

                <!-- Update petition link -->
                <?php if ($page_dashboard_petition) {
                    $page_add_update = add_query_arg(array('section' => 'add_update', 'id' => $petition_id, 'type' => 'update'), $page_dashboard_petition); ?>
                    <a class="<?php echo esc_attr($section == 'add_update' ? 'active ' : '') ?>item" href="<?php echo esc_url($page_add_update); ?>" data-bjax><?php esc_html_e('Add Update', 'campoal') ?></a>
                <?php } ?>

                <!-- Contribute link -->
                <?php if (class_exists('Give') && $page_dashboard_petition && empty($common_donation_form) && empty($common_form_id)) {
                    $page_contribute = add_query_arg(array('section' => 'contribute', 'id' => $petition_id), $page_dashboard_petition); ?>
                    <a class="<?php echo esc_attr($section == 'contribute' ? 'active ' : '') ?>item" href="<?php echo esc_url($page_contribute); ?>" data-bjax><?php esc_html_e('Fundraising', 'campoal') ?></a>
                <?php } ?>

                <!-- Edit petition link -->
                <?php if ($page_dashboard_petition) {
                    $page_edit_petition = add_query_arg(array('section' => 'edit_petition', 'id' => $petition_id), $page_dashboard_petition); ?>
                    <a class="<?php echo esc_attr($section == 'edit_petition' ? 'active ' : '') ?>item" href="<?php echo esc_url($page_edit_petition); ?>" data-bjax><?php esc_html_e('Edit Petition', 'campoal') ?></a>
                <?php } ?>
            </div>
        </div>
    </div>
<?php } ?>