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

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

// Check user is loggedin or not, if not redirect to login page
if (!is_user_logged_in() || !class_exists('Give')) {
    $login_page = isset($campoal_options['conikal_page_login_field']) ? $campoal_options['conikal_page_login_field'] : 0;

    if ($login_page != 0) {
        $login_page = get_permalink($login_page);
        wp_redirect($login_page);
    } else {
        wp_redirect(home_url('/'));
    }
}

$p_city = isset($campoal_options['conikal_p_city_field']) ? $campoal_options['conikal_p_city_field'] : 1;
$p_city_r = isset($campoal_options['conikal_p_city_r_field']) ? $campoal_options['conikal_p_city_r_field'] : 1;
$p_coordinates = isset($campoal_options['conikal_p_coordinates_field']) ? $campoal_options['conikal_p_coordinates_field'] : 1;
$p_coordinates_r = isset($campoal_options['conikal_p_coordinates_r_field']) ? $campoal_options['conikal_p_coordinates_r_field'] : 1;
$p_address = isset($campoal_options['conikal_p_address_field']) ? $campoal_options['conikal_p_address_field'] : 1;
$p_address_r = isset($campoal_options['conikal_p_address_r_field']) ? $campoal_options['conikal_p_address_r_field'] : 1;
$p_neighborhood = isset($campoal_options['conikal_p_neighborhood_field']) ? $campoal_options['conikal_p_neighborhood_field'] : 1;
$p_neighborhood_r = isset($campoal_options['conikal_p_neighborhood_r_field']) ? $campoal_options['conikal_p_neighborhood_r_field'] : 1;
$p_zip = isset($campoal_options['conikal_p_zip_field']) ? $campoal_options['conikal_p_zip_field'] : 1;
$p_zip_r = isset($campoal_options['conikal_p_zip_r_field']) ? $campoal_options['conikal_p_zip_r_field'] : 1;
$p_state = isset($campoal_options['conikal_p_state_field']) ? $campoal_options['conikal_p_state_field'] : 1;
$p_state_r = isset($campoal_options['conikal_p_state_r_field']) ? $campoal_options['conikal_p_state_r_field'] : 1;
$p_country = isset($campoal_options['conikal_p_country_field']) ? $campoal_options['conikal_p_country_field'] : 1;
$p_country_r = isset($campoal_options['conikal_p_country_r_field']) ? $campoal_options['conikal_p_country_r_field'] : 1;
$p_category_r = isset($campoal_options['conikal_p_category_r_field']) ? $campoal_options['conikal_p_category_r_field'] : 1;
$p_topics_r = isset($campoal_options['conikal_p_topics_r_field']) ? $campoal_options['conikal_p_topics_r_field'] : 1;
$editor_style = isset($campoal_options['conikal_editor_style_field']) ? $campoal_options['conikal_editor_style_field'] : 'markdown';
$button_labels_selection = isset($campoal_options['conikal_button_labels_field']) ? $campoal_options['conikal_button_labels_field'] : '';
$p_media_upload = isset($campoal_options['conikal_p_media_upload_field']) ? $campoal_options['conikal_p_media_upload_field'] : 1;
$maximum_category = isset($campoal_options['conikal_maximum_category_field']) ? $campoal_options['conikal_maximum_category_field'] : 1;
$give_prefix        = '_give_';

if (isset($_GET['id']) && $_GET['id'] != '') {
    $petition_id    = sanitize_text_field($_GET['id']);
    $form_id        = get_post_meta($petition_id, 'petition_contribute', true);
    $title          = get_the_title($petition_id);
    $link           = get_permalink($petition_id);
    $post_type      = get_post_type($petition_id);
}

if (empty($form_id)) {
    $petition_id    = isset($_GET['id']) ? sanitize_text_field($_GET['id']) : '';
    $form_id        = isset($_GET['form_id']) ? sanitize_text_field($_GET['form_id']) : '';
    if ($form_id) {
        $title          = get_the_title($form_id);
        $link           = get_permalink($form_id);
        $post_type      = get_post_type($form_id);
    }
}

// get form option
$give_excerpt       = get_the_excerpt($form_id);
$goal_option        = get_post_meta($form_id, $give_prefix . 'goal_option', true);
$set_goal           = get_post_meta($form_id, $give_prefix . 'set_goal', true);
$set_goal           = give_format_decimal((int)give_maybe_sanitize_amount($set_goal), false, false);
$goal_format        = get_post_meta($form_id, $give_prefix . 'goal_format', true);
$close_form_when_goal_achieved = get_post_meta($form_id, $give_prefix . 'close_form_when_goal_achieved', true);
$goal_achieved_message = get_post_meta($form_id, $give_prefix . 'form_goal_achieved_message', true);
$custom_amount_minimum = get_post_meta($form_id, $give_prefix . 'custom_amount_minimum', true);
$custom_amount_minimum = give_format_decimal((int)give_maybe_sanitize_amount($custom_amount_minimum), false, false );
$donation_levels    = get_post_meta($form_id, $give_prefix . 'donation_levels', true);
$reveal_label       = get_post_meta($form_id, $give_prefix . 'reveal_label', true);
$form_content       = get_post_meta($form_id, $give_prefix . 'form_content', true);
$status             = get_post_status($form_id);
$gallery            = get_post_meta($form_id, $give_prefix . 'gallery', true);
$video              = get_post_meta($form_id, $give_prefix . 'video', true);
$attach_id          = get_post_thumbnail_id($form_id);
$categories         = wp_get_post_terms($form_id, 'give_forms_category', true);
$category_id        = (is_array($categories) && isset($categories[0]) ? $categories[0]->term_id : '');
$tags               = wp_get_post_terms($form_id, 'give_forms_tag');

$address        = get_post_meta($form_id, $give_prefix . 'address', true);
$city           = get_post_meta($form_id, $give_prefix . 'city', true);
$state          = get_post_meta($form_id, $give_prefix . 'state', true);
$neighborhood   = get_post_meta($form_id, $give_prefix . 'neighborhood', true);
$zip            = get_post_meta($form_id, $give_prefix . 'zip', true);
$country        = get_post_meta($form_id, $give_prefix . 'country', true);
$lat            = get_post_meta($form_id, $give_prefix . 'lat', true);
$lng            = get_post_meta($form_id, $give_prefix . 'lng', true);

// Does the user want category?
$enable_category = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) );

// Does the user want tag?
$enable_tag = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) );

// get category object
if ( $enable_category ) {
    $cat_taxonomies = array('give_forms_category');
    $cat_args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'hide_empty'        => false
    );
    $cat_terms = get_terms($cat_taxonomies, $cat_args);
}

if ($enable_tag) {
    // get topcis object
    $type_taxonomies = array('give_forms_tag');
    $type_args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'hide_empty'        => false
    );
    $type_terms = get_terms($type_taxonomies, $type_args);
}

$goal_format_selection = array('amount' => esc_html__('Amount', 'campoal'), 'percentage' => esc_html__('Percentage', 'campoal'));
$close_form_selection = array('enabled' => esc_html__('Enable', 'campoal'), 'disabled' => esc_html__('Disable', 'campoal'));

// get currency format
$currency_position = give_get_option( 'currency_position', 'before' );
$currency_symbol = give_currency_symbol();

$post_author_id = get_post_field('post_author', $petition_id);
$tab_active = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'general';
?>
<?php if (($petition_id != '' || $form_id != '') && ($post_author_id == $current_user->ID || current_user_can('editor') || current_user_can('administrator') || conikal_co_author_permission($petition_id))) { ?>
	<div class="ui container submit-petition">
		<div class="ui left aligned header submit-petition-title">
            <div class="content">
                <?php esc_html_e('Fundraising', 'campoal') ?>
            </div>
        </div>
		<div class="ui grid">
            <div class="sixteen wide mobile five wide tablet four wide computer column">
                <div class="ui hidden divider"></div>
                <div class="ui vertical secondary fluid large menu" id="contribute-tab">
                    <a href="#general" class="item<?php echo esc_attr($tab_active == 'general' ? ' active' : '') ?>" data-tab="general">
                        <i class="heading icon"></i>
                        <?php esc_html_e('Title', 'campoal') ?>
                    </a>
                    <a href="#level" class="item<?php echo esc_attr($tab_active == 'level' ? ' active' : '') ?>" data-tab="level">
                        <i class="user circle icon"></i>
                        <?php esc_html_e('Level', 'campoal') ?>
                    </a>
                    <a href="#content" class="item<?php echo esc_attr($tab_active == 'content' ? ' active' : '') ?>" data-tab="content">
                        <i class="list alternate icon"></i>
                        <?php esc_html_e('Content', 'campoal') ?>
                    </a>
                    <a href="#photo" class="item<?php echo esc_attr($tab_active == 'photo' ? ' active' : '') ?>" data-tab="photo">
                        <i class="image icon"></i>
                        <?php esc_html_e('Photo', 'campoal') ?>
                    </a>
                </div>
            </div>
            <div class="sixteen wide mobile eleven wide tablet ten wide computer left aligned column">
	            <?php if ($status == 'pending') { ?>
	                <div class="ui large warning message">
	                    <i class="warning icon"></i>
	                    <?php esc_html_e('Contribute & Donation is pending approval!', 'campoal') ?>
	                </div>
	            <?php } ?>
	        	<div id="save-response" class="respon-message"></div>
	        	<div class="ui form">
	        		<?php wp_nonce_field('submit_contribute_ajax_nonce', 'securitySubmitContribute', true); ?>
	        		<input type="hidden" id="form_id" name="form_id" value="<?php echo esc_attr($form_id && get_permalink($form_id) ? $form_id : '') ?>">
	        		<input type="hidden" id="petition_id" name="petition_id" value="<?php echo esc_attr($petition_id && !isset($_GET['form_id']) ? $petition_id : '') ?>">
	        		<?php if ($petition_id != '' && $petition_id != $form_id) { ?>
                    <input type="hidden" id="give_title" name="give_title" value="<?php echo esc_attr($title) ?>">
                    <?php } ?>

                    <!-- STEP GENERAL -->
                    <div class="ui<?php echo esc_attr($tab_active == 'general' ? ' active' : '') ?> tab" data-tab="general">
    	        		<div class="fields ui large message">
    	        			<div class="eleven wide field">
    						  	<div class="ui toggle checkbox<?php echo esc_attr($goal_option && $goal_option === 'enabled' ? ' checked' : '') ?>" id="goal_option">
    					        	<input type="checkbox" tabindex="0" name="goal_option" class="hidden" <?php echo esc_attr($goal_option && $goal_option === 'enabled' ? ' checked' : '') ?>>
    					        	<label><?php esc_html_e('Show Goal', 'campoal') ?></label>
    					      	</div>
                            </div>
                            <?php if ($form_id != '' && $status != 'pending') { ?>
                            <div class="five wide field">
                                <div class="ui <?php echo esc_attr($status == 'draft' ? 'checked ' : '') ?>checkbox" id="draft_status">
                                    <input type="checkbox" tabindex="0" name="draft_status" class="hidden" <?php echo esc_attr($status == 'draft' ? 'checked' : '') ?>>
                                    <label><?php esc_html_e("Close fundraising", 'campoal') ?></label>
                                </div>
    				      	</div>
                            <?php } else { ?>
                                <input type="hidden" name="draft_status" id="draft_status" value="">
                            <?php } ?>
    			      	</div>

                        <?php if ($post_type == 'give_forms') { ?>
                        <div class="required field">
                            <label><?php esc_html_e('Title', 'campoal') ?></label>
                            <div class="ui large fluid input">
                                <input type="text" id="give_title" name="give_title" value="<?php echo esc_attr($title) ?>" placeholder="<?php esc_attr_e('What do you bring for life?', 'campoal'); ?>" value="">
                            </div>
                        </div>

                        <div class="field">
                            <label><?php esc_html_e('Excerpt', 'campoal') ?></label>
                            <div class="ui large fluid input">
                                <textarea type="text" id="give_excerpt" name="give_excerpt" rows="3" placeholder="<?php esc_attr_e('Short description about project', 'campoal'); ?>"><?php echo esc_html($give_excerpt) ?></textarea>
                            </div>
                        </div>
                        <?php } ?>

                        <?php if ($enable_category) { ?>
                        <div class="<?php echo esc_attr($p_category_r == 1 ? 'required ' : '') ?>field">
                            <label><?php esc_html_e('Category', 'campoal') ?></label>                        
                            <select class="ui dropdown large fluid input category-select" name="new_category" id="new_category"<?php echo esc_attr($maximum_category > 1 ? ' multiple' : '') ?>>
                                <option value=""><?php esc_html_e('Select a category', 'campoal') ?></option>
                                <?php foreach ($cat_terms as $cat_term) { ?>
                                    <option value="<?php echo esc_attr($cat_term->term_id); ?>"><?php echo esc_html($cat_term->name); ?></option>
                                <?php } ?>
                            </select>
                            <?php if (isset($categories) && isset($categories[0]) && (count($categories) > 1) || ($maximum_category > 1)) { ?>
                                <?php foreach($categories as $category) {
                                    echo '<input type="hidden" name="category_ids[]" value="' . esc_attr($category->term_id) . '">'; 
                                } ?>
                            <?php } else { ?>
                                <input type="hidden" name="category_id" id="category_id" value="<?php echo esc_attr(isset($category_id) ? esc_attr($category_id) : ''); ?>">
                            <?php } ?>
                        </div>
                        <?php } ?>

                        <?php if($p_address == 1) { ?>
                        <div class="<?php echo esc_attr($p_address_r == 1 ? 'required ' : '') ?>field">
                            <label><?php esc_html_e('Add a place', 'campoal') ?></label>
                            <div class="ui large fluid input">
                                <input type="text" id="new_address" name="new_address" value="<?php echo esc_attr(isset($address) ? $address : ''); ?>" placeholder="<?php esc_attr_e('Add a neighborhood, state, city or country', 'campoal'); ?>">
                            <?php if($p_city != '' && $p_city == 1) { ?>
                                <input type="hidden" id="new_city" name="new_city" value="<?php echo esc_attr(isset($city) ? $city : ''); ?>">
                            <?php } ?>
                            <?php if($p_state != '' && $p_state == 1) { ?>
                                <input type="hidden" id="new_state" name="new_state" value="<?php echo esc_attr(isset($state) ? $state : ''); ?>">
                            <?php } ?>
                            <?php if($p_neighborhood != '' && $p_neighborhood == 1) { ?>
                                <input type="hidden" id="new_neighborhood" name="new_neighborhood" value="<?php echo esc_attr(isset($neighborhood) ? $neighborhood : ''); ?>">
                            <?php } ?>
                            <?php if($p_country != '' && $p_country == 1) { ?>
                                <input type="hidden" id="new_country" name="new_country" value="<?php echo esc_attr(isset($country) ? $country : ''); ?>">
                            <?php } ?>
                            <?php if($p_zip != '' && $p_zip == 1) { ?>
                                <input type="hidden" id="new_zip" name="new_zip" value="<?php echo esc_attr(isset($zip) ? $zip : ''); ?>">
                            <?php } ?>
                            <?php if($p_coordinates != '' && $p_coordinates == 1) { ?>
                                <input type="hidden" id="new_lat" name="new_lat" value="<?php echo esc_attr(isset($lat) ? $lat : ''); ?>">
                                <input type="hidden" id="new_lng" name="new_lng" value="<?php echo esc_attr(isset($lng) ? $lng : ''); ?>">
                            <?php } ?>
                            </div>
                        </div>
                        <?php } ?>

    			      	<div class="two fields">
    				      	<div class="required field">
    			      			<label><?php esc_html_e('Goal', 'campoal') ?></label>
    				      		<div class="ui <?php echo esc_attr($currency_position == 'after' ? 'right' : 'left') ?> labeled large input">
    							  	<?php if ($currency_position == 'before') { ?>
                                        <label for="set_goal" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                    <?php } ?>
    							        <input type="number" placeholder="<?php esc_attr_e('Amount of Goal', 'campoal') ?>" name="set_goal" id="set_goal" value="<?php echo esc_attr($set_goal ? $set_goal : 0) ?>">
                                    <?php if ($currency_position == 'after') { ?>
                                        <label for="set_goal" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                    <?php } ?>
    							</div>
    			      		</div>
    		      			<div class="field">
    				  			<label><?php esc_html_e('Goal format', 'campoal') ?></label>
    				  			<select class="ui dropdown large fluid input" name="goal_format" id="goal_format">
    				  				<?php foreach ($goal_format_selection as $key => $format) { ?>
    				  					<option value="<?php echo esc_attr($key) ?>"<?php echo esc_attr($goal_format == $key ? ' selected' : '') ?>><?php  echo esc_html($format) ?></option>
    				  				<?php } ?>
    							</select>
    						</div>
    					</div>

                        <div class="ui hidden divider"></div>
                    </div>


                    <!-- STEP LEVEL -->
                    <div class="ui<?php echo esc_attr($tab_active == 'level' ? ' active' : '') ?> tab" data-tab="level">
    			      	<div class="ui dividing header">
                            <div class="content"><?php esc_html_e('Contribute level', 'campoal') ?></div>
                        </div>
    			      	<div class="input-fields-wrap" id="new-donate-level">
                            <div class="ui grid search">
                                <div class="sixteen wide mobile eight wide tablet eight wide computer column">
                                    <div class="required field">
                                        <label><?php esc_html_e('Amount', 'campoal') ?></label>
                                        <div class="ui large fluid <?php echo esc_attr($currency_position == 'after' ? 'right' : 'left') ?> labeled input">
                                            <?php if ($currency_position == 'before') { ?>
                                        	   <label for="amount_level" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                            <?php } ?>
                                                <input type="number" id="amount_level" name="amount_level[]" placeholder="<?php esc_attr_e('Amount of level', 'campoal'); ?>" value="<?php echo esc_attr(isset($donation_levels[0]['_give_amount']) ? give_format_decimal((int)give_maybe_sanitize_amount($donation_levels[0]['_give_amount']), false, false) : ''); ?>">
                                            <?php if ($currency_position == 'after') { ?>
                                                <label for="amount_level" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="sixteen wide mobile eight wide tablet eight wide computer column">
                                    <div class="required field">
                                        <?php if (!wp_is_mobile()) { ?>
                                            <label><?php esc_html_e('Title', 'campoal') ?></label>
                                        <?php } ?>
                                        <div class="ui large fluid input">
                                            <input type="text" id="name_level" name="name_level[]" placeholder="<?php esc_attr_e('Level name', 'campoal'); ?>" value="<?php echo esc_attr(isset($donation_levels[0]['_give_text']) ? $donation_levels[0]['_give_text'] : ''); ?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="sixteen wide column field">
                                    <label><?php esc_html_e('Description', 'campoal') ?></label>
                                    <textarea name="description_level[]" id="description_level" placeholder="<?php esc_attr_e('Description of level', 'campoal'); ?>" rows="3"><?php echo esc_textarea(isset($donation_levels[0]['_give_description']) ? $donation_levels[0]['_give_description'] : ''); ?></textarea>
                                </div>
                            </div>

                            <?php if(isset($donation_levels) && $donation_levels != '') {
                                foreach ($donation_levels as $key => $level) {
                                    if ($level['_give_amount'] && $key != 0) { ?>
                                    <div class="ui grid search">
                                        <div class="sixteen wide mobile eight wide tablet eight wide computer column">
                                            <div class="required field">
                                                <div class="ui large fluid <?php echo esc_attr($currency_position == 'after' ? 'right' : 'left') ?> labeled input">
                                                    <?php if ($currency_position == 'before') { ?>
                                                        <label for="amount_level" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                                    <?php } ?>
                                                       <input type="number" id="amount_level" name="amount_level[]" value="<?php echo esc_attr(isset($level['_give_amount']) ? give_format_decimal((int)give_maybe_sanitize_amount( $level['_give_amount'] ), false, false) : ''); ?>">
                                                    <?php if ($currency_position == 'after') { ?>
                                                        <label for="amount_level" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="sixteen wide mobile eight wide tablet eight wide computer column">
                                            <div class="required field">
                                                <div class="ui large fluid input">
                                                    <input type="text" id="name_level" name="name_level[]" value="<?php echo esc_attr(isset($level['_give_text']) ? $level['_give_text'] : ''); ?>">
                                                </div>
                                            </div>
                                        </div>
                                        <a href="#" class="remove-field"><i class="inverted circular close link icon"></i></a>

                                        <div class="sixteen wide column field">
                                            <textarea name="description_level[]" id="description_level" placeholder="<?php esc_attr_e('Description of level', 'campoal'); ?>" rows="3"><?php echo esc_textarea(isset($level['_give_description']) ? $level['_give_description'] : ''); ?></textarea>
                                        </div>
                                    </div>
                            <?php   }
                                }
                            } ?>
                        </div>

                        <div class="ui vertical basic segment">
                            <button class="ui primary tiny right floated button add-level-button"><i class="plus icon"></i><?php esc_html_e('Add', 'campoal') ?></button>
                        </div>

                        <div class="required field">
                            <label><?php esc_html_e('Minimum', 'campoal') ?></label>
                            <div class="ui <?php echo esc_attr($currency_position == 'after' ? 'right' : 'left') ?> labeled large input">
                                <?php if ($currency_position == 'before') { ?>
                                    <label for="custom_amount_minimum" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                <?php } ?>
                                  <input type="number" placeholder="<?php esc_attr_e('Amount of minimum', 'campoal') ?>" name="custom_amount_minimum" id="custom_amount_minimum" value="<?php echo esc_attr($custom_amount_minimum ? $custom_amount_minimum : 0) ?>">
                                <?php if ($currency_position == 'after') { ?>
                                    <label for="custom_amount_minimum" class="ui label"><?php echo esc_html($currency_symbol) ?></label>
                                <?php } ?>
                            </div>
                        </div>

                        <div class="two fields">
                            <div class="field">
                                <label><?php esc_html_e('Button label', 'campoal') ?></label>
                                <select class="ui dropdown large fluid input" name="button_label" id="button_label">
                                    <?php if ($button_labels_selection) {
                                    foreach ($button_labels_selection as $label) { ?>
                                        <option value="<?php echo esc_attr($label) ?>"<?php echo esc_attr($reveal_label == $label ? ' selected' : '') ?>><?php echo esc_html($label) ?></option>
                                    <?php }
                                    } ?>
                                </select>
                            </div>
                            <div class="field">
                                <label><?php esc_html_e('Close when met goal', 'campoal') ?></label>
                                <select class="ui dropdown large fluid input" name="close_form_when_goal_achieved" id="close_form_when_goal_achieved">
                                    <?php foreach ($close_form_selection as $key => $option) { ?>
                                        <option value="<?php echo esc_attr($key) ?>"<?php echo esc_attr($close_form_when_goal_achieved == $key ? ' selected' : '') ?>><?php echo esc_html($option) ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="ui hidden divider"></div>
                    </div>

                    <!-- STEP CONTENT -->
                    <div class="ui<?php echo esc_attr($tab_active == 'content' ? ' active' : '') ?> tab" data-tab="content">
                        <div class="ui dividing header">
                            <div class="content"><?php esc_html_e('Content', 'campoal') ?></div>
                        </div>

    		      		<div class="field">
    		      			<label><?php esc_html_e('Content or Tips', 'campoal') ?></label>
                            <div id="isDesc">
                            <?php
                            $form_content = isset($form_content) && $form_content != '' ? $form_content : esc_html__('Within an hour, this petition could have thousands more supporters if everyone chipped in the price of a coffee. Can you help reach this petition’s signature goal?', 'campoal');
                            if ($editor_style == 'classic') {
                                $settings = array(
                                    'media_buttons'         => $p_media_upload,
                                    'textarea_rows'         => 10,
                                    'drag_drop_upload'      => true,
                                    'quicktags'             => false,
                                    'dfw'                   => true,
                                );
                                wp_editor($form_content, 'form_content', $settings);
                            } else { ?>
                                <textarea id="form_content" name="form_content"><?php echo esc_textarea($form_content) ?></textarea>
                            <?php } ?>
                            </div>
    		      		</div>

                        <?php if($enable_tag) { ?>
                        <div class="<?php echo esc_attr($p_topics_r == 1 ? 'required ' : '') ?>field">
                            <label><?php esc_html_e('Add tags', 'campoal') ?></label>
                            <div class="ui fluid multiple search selection large dropdown" id="give-tags-search">
                                <input name="new_tags" id="new_tags" type="hidden">
                                <i class="dropdown icon"></i>
                                <div class="default text"><?php esc_html_e('Keywords related this crowdfunding', 'campoal') ?></div>
                                <div class="menu">
                                </div>
                            </div>
                        </div>

                        <?php if (isset($tags)) { ?>
                            <?php foreach($tags as $tag) { ?>
                                <input type="hidden" name="current_topics[]" value="<?php echo esc_attr($tag->name) ?>">
                            <?php } ?>
                        <?php } ?>
                        <?php } ?>

                        <div class="required field">
                            <label><?php esc_html_e('Goal Achieved Message', 'campoal') ?></label>
                            <textarea name="goal_achieved_message" id="goal_achieved_message" rows="3" maxlength="300"><?php echo esc_textarea($goal_achieved_message ? $goal_achieved_message : esc_html__('Thank you to all our donors, we have met our fundraising goal.', 'campoal')) ?></textarea>
                        </div>
                        <div class="ui hidden divider"></div>
                    </div>

                    <!-- STEP PHOTO -->
                    <div class="ui<?php echo esc_attr($tab_active == 'photo' ? ' active' : '') ?> tab" data-tab="photo">
                        <div class="ui dividing header">
                            <div class="content"><?php esc_html_e('Photo or Video', 'campoal') ?></div>
                        </div>

                        <input type="hidden" id="edit_gallery" value="<?php echo esc_attr(isset($gallery) ? esc_attr($gallery) : ''); ?>">
                        <input type="hidden" id="edit_attach" value="<?php echo esc_attr(isset($attach_id) ? esc_attr($attach_id) : ''); ?>">
                        <input type="hidden" id="edit_video" value="<?php echo esc_attr(isset($video) ? esc_attr($video) : ''); ?>">
                        <?php get_template_part('templates/gallery-upload'); ?>
                    </div>

		      		<div class="ui vertical basic segment">
                        <button class="ui primary large right floated labeled icon button" id="submit-contribute"><i class="save icon"></i><?php esc_html_e('Save', 'campoal') ?></button>
                    </div>
				</div>
	        </div>
	    </div>
	</div>
<?php } else { ?>
    <?php get_template_part('404') ?>
<?php } ?>