Exemplo n.º 1
0
function leyka_fake_scale_ultra($campaign)
{
    if (!is_a($campaign, 'Leyka_Campaign')) {
        $campaign = new Leyka_Campaign($campaign);
    }
    $curr_label = leyka_get_currency_label('rur');
    $collected = number_format(intval($campaign->get_collected_amount()), 0, '.', ' ');
    ?>


<div class="leyka-scale-ultra-fake">
    <div class="leyka-scale-scale">
        <div class="target"> </div>
    </div>
    <div class="leyka-scale-label"><span>
        <?php 
    printf(_x('Collected: %s', 'Label on ultra-compact fake scale', 'leyka'), "<b>{$collected}</b> {$curr_label}");
    ?>

    </span></div>
</div>
<?php 
}
    public function data_meta_box($post)
    {
        $campaign = new Leyka_Campaign($post);
        $cur_template = $campaign->template;
        if (empty($cur_template)) {
            $cur_template = 'default';
        }
        ?>

        <fieldset id="payment-title" class="metabox-field campaign-field campaign-purpose">
            <label for="payment_title">
                <?php 
        _e('Campaign title meant for payment system', 'leyka');
        ?>
                <br />
                <small><?php 
        echo __('If empty, main campaign title will be used', 'leyka');
        ?>
</small>
            </label>

            <input type="text" class="widefat" name="payment_title" id="payment_title" value="<?php 
        echo $campaign->payment_title ? $campaign->payment_title : $campaign->title;
        ?>
">
        </fieldset>
		
		<h4 class="metabox-field-title campaign-template"><?php 
        _e('Template settings', 'leyka');
        ?>
</h4>

		<fieldset id="campaign-template" class="metabox-field campaign-field campaign-template">
			<label for="campaign_template"><?php 
        _e('Template for payment form', 'leyka');
        ?>
</label>
			<select id="campaign_template" name="campaign_template">
				<option value="default" <?php 
        selected($cur_template, 'default');
        ?>
>
                    <?php 
        _e('Default template', 'leyka');
        ?>
                </option>

            <?php 
        $templates = leyka()->get_templates();
        if ($templates) {
            foreach ($templates as $template) {
                ?>
                <option value="<?php 
                echo esc_attr($template['id']);
                ?>
" <?php 
                selected($cur_template, $template['id']);
                ?>
>
                    <?php 
                echo esc_attr($template['name']);
                ?>
                </option>
                <?php 
            }
        }
        ?>

			</select>
		</fieldset>

		<fieldset id="ignore-global-template" class="metabox-field campaign-field campaign-ignorance">
			<label for="ignore_global_template">
			<input type="checkbox" name="ignore_global_template" id="ignore_global_template" value="1" <?php 
        checked($campaign->ignore_global_template_settings, 1);
        ?>
>&nbsp;
			<?php 
        _e('Ignore global template settings', 'leyka');
        ?>
</label>
		</fieldset>

		<h4 class="metabox-field-title campaign-target"><?php 
        _e('Campaign target', 'leyka');
        ?>
</h4>

		<fieldset id="target-amount" class="metabox-field campaign-field campaign-target">
			<label for="campaign_target">
                <?php 
        echo sprintf(__('Target (%s)', 'leyka'), leyka_options()->opt('currency_rur_label'));
        ?>
            </label>
			<input type="text" name="campaign_target" id="campaign_target" value="<?php 
        echo $campaign->target;
        ?>
" class="widefat">
		</fieldset>
		
		<fieldset id="collected-amount" class="metabox-field campaign-field campaign-target-collected">
			<label for="collected_target">
                <?php 
        echo sprintf(__('Collected (%s)', 'leyka'), leyka_get_currency_label('rur'));
        ?>
            </label>			
			<input type="text" id="collected_target" disabled="disabled" value="<?php 
        echo $campaign->total_funded;
        ?>
" class="widefat">
            <?php 
        if (get_current_screen()->action != 'add') {
            ?>
            <div class="recalculate-total-funded">
                <a href="<?php 
            echo add_query_arg(array('recalculate_total_funded' => 1));
            ?>
" id="recalculate_total_funded" data-nonce="<?php 
            echo wp_create_nonce('leyka_recalculate_total_funded_amount');
            ?>
" data-campaign-id="<?php 
            echo $campaign->id;
            ?>
"><?php 
            _e('Recalculate collected amount', 'leyka');
            ?>
</a>
                <img src="<?php 
            echo LEYKA_PLUGIN_BASE_URL . '/img/ajax-loader-h.gif';
            ?>
" id="recalculate_total_funded_loader" style="display: none;">
                <div class="message error-message" id="recalculate_message"></div>
            </div>
            <?php 
        }
        ?>
		</fieldset>

		<fieldset id="d-scale-demo" class="metabox-field campaign-field campaign-target-scale">
		<?php 
        if ($campaign->target > 0) {
            $percentage = round(100 * $campaign->total_funded / $campaign->target);
            $percentage = $percentage > 100 ? 100 : $percentage;
            ?>

			<div class="d-scale-scale">
				<div class="target">
					<div style="width:<?php 
            echo $percentage;
            ?>
%" class="collected">&nbsp;</div>
				</div>
			</div>
			
			<?php 
            if ($campaign->target_state == 'is_reached') {
                ?>
        
			<p>
				<?php 
                printf(__('Reached at: %s', 'leyka'), '<b>' . $campaign->date_target_reached . '</b>');
                ?>
			</p>            
			<?php 
            }
            ?>

		<?php 
        }
        ?>
		</fieldset>

        <?php 
        $curr_page = get_current_screen();
        if ($curr_page->action != 'add') {
            ?>

        <fieldset id="campaign-finished" class="metabox-field campaign-field campaign-finished">
            <label for="is-finished">
                <input type="checkbox" id="is-finished" name="is_finished" value="1" <?php 
            echo $campaign->is_finished ? 'checked' : '';
            ?>
 /> <?php 
            _e('Campaign is finished, donations collection is stopped', 'leyka');
            ?>
            </label>
        </fieldset>
	<?php 
        }
    }