<?php
/*
Template Name: Submit Petition
*/

/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
$custom_fields_mode = isset($campoal_options['conikal_custom_fields_mode_field']) ? $campoal_options['conikal_custom_fields_mode_field'] : 0;

if (!is_user_logged_in()) {
    conikal_redirect_login();
} else {
    $admin_submit_petition_only = isset($campoal_options['conikal_admin_submit_petition_only_field']) ? $campoal_options['conikal_admin_submit_petition_only_field'] : 0;

    if ($admin_submit_petition_only == 1) { 
        if (!current_user_can('manage_options')) {
            wp_redirect(home_url('/'));
        }
    }
}

$step_name = isset($_GET['step']) ? sanitize_text_field($_GET['step']) : '';
$petition_id = isset($_GET['petition_id']) ? sanitize_text_field($_GET['petition_id']) : false;

// Validate and save the submitted form data created by the acf_form() function
if (class_exists('ACF') && $step_name == 'infomations' && !empty($petition_id)) {
   acf_form_head(); 
}

get_header();
?>

    <?php if (class_exists('ACF') && $step_name == 'infomations' && !empty($petition_id) && $custom_fields_mode) {
        get_template_part( 'templates/submition/submit', 'infomations' ); 
    } else { 
        get_template_part( 'templates/submition/submit', 'petition' ); 
    } ?>

<?php get_footer(); ?>