Example #1
0
/**
 * Function that outputs the edit options for our calculation field
 *
 * @since 2.2.28
 * @return void
 */
function ninja_forms_field_calc_edit($field_id, $data)
{
    $calc_name = isset($data['calc_name']) ? $data['calc_name'] : 'calc_name';
    $default_value = isset($data['default_value']) ? $data['default_value'] : '';
    $calc_payment = isset($data['calc_payment']) ? $data['calc_payment'] : '';
    $calc_autho = isset($data['calc_auto']) ? $data['calc_auto'] : 0;
    // Output calculation display type
    $options = array(array('name' => __('- None', 'ninja-forms'), 'value' => 'hidden'), array('name' => __('Textbox', 'ninja-forms'), 'value' => 'text'), array('name' => __('HTML', 'ninja-forms'), 'value' => 'html'));
    $calc_display_type = isset($data['calc_display_type']) ? $data['calc_display_type'] : 'text';
    ninja_forms_edit_field_el_output($field_id, 'select', __('Output calculation as', 'ninja-forms'), 'calc_display_type', $calc_display_type, 'wide', $options, 'widefat ninja-forms-calc-display');
    // If the calc_display_type is set to text, then we have several options to output.
    // Set the output to hidden for these options if the calc_display_type is not set to text.
    if ($calc_display_type != 'text') {
        $class = 'hidden';
    } else {
        $class = '';
    }
    echo '<div id="ninja_forms_field_' . $field_id . '_calc_text_display" class="' . $class . '">';
    // Output a label input textbox.
    $label = isset($data['label']) ? stripslashes($data['label']) : __('Calculation', 'ninja-forms');
    ninja_forms_edit_field_el_output($field_id, 'text', __('Label', 'ninja-forms'), 'label', $label, 'wide', '', 'widefat');
    // Output a label position select box.
    if (isset($data['label_pos'])) {
        $label_pos = $data['label_pos'];
    } else {
        $label_pos = '';
    }
    $options = array(array('name' => __('Left of Element', 'ninja-forms'), 'value' => 'left'), array('name' => __('Above Element', 'ninja-forms'), 'value' => 'above'), array('name' => __('Below Element', 'ninja-forms'), 'value' => 'below'), array('name' => __('Right of Element', 'ninja-forms'), 'value' => 'right'));
    ninja_forms_edit_field_el_output($field_id, 'select', __('Label Position', 'ninja-forms'), 'label_pos', $label_pos, 'wide', $options, 'widefat');
    // Output a disabled option checkbox.
    if (isset($data['calc_display_text_disabled'])) {
        $calc_display_text_disabled = $data['calc_display_text_disabled'];
    } else {
        $calc_display_text_disabled = 1;
    }
    ninja_forms_edit_field_el_output($field_id, 'checkbox', __('Disable input?', 'ninja-forms'), 'calc_display_text_disabled', $calc_display_text_disabled, 'wide', '', '');
    echo '</div>';
    // Set the output to hidden for the HTML RTE if the calc_display_type is not set to HTML.
    if ($calc_display_type != 'html') {
        $class = 'hidden';
    } else {
        $class = '';
    }
    // Output our RTE. This is the only extra setting needed if the calc_display_type is set to HTML.
    if (isset($data['calc_display_html'])) {
        $calc_display_html = $data['calc_display_html'];
    } else {
        $calc_display_html = '[ninja_forms_calc]';
    }
    echo '<div id="ninja_forms_field_' . $field_id . '_calc_html_display" class="' . $class . '">';
    ninja_forms_edit_field_el_output($field_id, 'rte', '', 'calc_display_html', $calc_display_html, '', '', '', __('Use the following shortcode to insert the final calculation: [ninja_forms_calc]', 'ninja-forms'));
    echo '</div>';
    if (isset($data['calc_method'])) {
        $calc_method = $data['calc_method'];
    } else {
        $calc_method = 'auto';
    }
    switch ($calc_method) {
        case 'auto':
            $eq_class = 'hidden';
            $field_class = 'hidden';
            break;
        case 'fields':
            $eq_class = 'hidden';
            $field_class = '';
            break;
        case 'eq':
            $eq_class = '';
            $field_class = 'hidden';
            break;
    }
    if (isset($data['calc_eq'])) {
        $calc_eq = $data['calc_eq'];
    } else {
        $calc_eq = '';
    }
    if (isset($data['calc']) and $data['calc'] != '') {
        $calc = $data['calc'];
    } else {
        $calc = array();
    }
    $desc = '<p>' . sprintf(__('You can enter calculation equations here using field_x where x is the ID of the field you want to use. For example, %sfield_53 + field_28 + field_65%s.', 'field_ should NOT be translated.', 'ninja-forms'), '<strong>', '</strong>') . '</p>';
    $desc .= '<p>' . sprintf(__('Complex equations can be created by adding parentheses: %s( field_45 * field_2 ) / 2%s.', 'field_ should NOT be translated.', 'ninja-forms'), '<strong>', '</strong>') . '</p>';
    $desc .= '<p>' . __('Please use these operators: + - * /. This is an advanced feature. Watch out for things like division by 0.', 'ninja-forms') . '</p>';
    $options = array(array('name' => __('Automatically Total Calculation Values', 'ninja-forms'), 'value' => 'auto'), array('name' => __('Specify Operations And Fields (Advanced)', 'ninja-forms'), 'value' => 'fields'), array('name' => __('Use An Equation (Advanced)', 'ninja-forms'), 'value' => 'eq'));
    ninja_forms_edit_field_el_output($field_id, 'select', __('Calculation Method', 'ninja-forms'), 'calc_method', $calc_method, 'wide', $options, 'widefat ninja-forms-calc-method');
    ?>

	<div class="ninja-forms-calculations <?php 
    echo $field_class;
    ?>
">
		<div class="label">
			<?php 
    _e('Field Operations', 'ninja-forms');
    ?>
 - <a href="#" name="" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_add_calc" class="ninja-forms-field-add-calc" rel="<?php 
    echo $field_id;
    ?>
"><?php 
    _e('Add Operation', 'ninja-forms');
    ?>
</a>

			<span class="spinner" style="float:left;"></span>
		</div>

		<input type="hidden" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[calc]" value="">
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_calc" class="" name="">
			<?php 
    $x = 0;
    foreach ($calc as $c) {
        ninja_forms_output_field_calc_row($field_id, $c, $x);
        $x++;
    }
    ?>
		</div>
	</div>
	<div class="ninja-forms-eq <?php 
    echo $eq_class;
    ?>
">
		<?php 
    ninja_forms_edit_field_el_output($field_id, 'textarea', __('Advanced Equation', 'ninja-forms'), 'calc_eq', $calc_eq, 'wide', '', 'widefat', $desc);
    ?>
	</div>
	<hr>
	<?php 
}
Example #2
0
function ninja_forms_field_calc_edit($field_id, $data)
{
    if (isset($data['calc_name'])) {
        $calc_name = $data['calc_name'];
    } else {
        $calc_name = 'calc_name';
    }
    if (isset($data['default_value'])) {
        $default_value = $data['default_value'];
    } else {
        $default_value = '';
    }
    if (isset($data['calc_payment'])) {
        $calc_payment = $data['calc_payment'];
    } else {
        $calc_payment = '';
    }
    if (isset($data['calc_auto'])) {
        $calc_auto = $data['calc_auto'];
    } else {
        $calc_auto = 0;
    }
    ninja_forms_edit_field_el_output($field_id, 'text', __('Calculation name', 'ninja-forms'), 'calc_name', $calc_name, 'wide', '', 'widefat ninja-forms-calc-name', __('This is the programmatic name of your field. Examples are: my_calc, price_total, user-total.', 'ninja-forms'));
    ninja_forms_edit_field_el_output($field_id, 'text', __('Default Value', 'ninja-forms'), 'default_value', $default_value, 'wide', '', 'widefat');
    echo '<hr>';
    echo '<h5>' . __('Display Options', 'ninja-forms') . '</h5>';
    // Output calculation display type
    $options = array(array('name' => __('- None', 'ninja-forms'), 'value' => 'hidden'), array('name' => __('Textbox', 'ninja-forms'), 'value' => 'text'), array('name' => __('HTML', 'ninja-forms'), 'value' => 'html'));
    if (isset($data['calc_display_type'])) {
        $calc_display_type = $data['calc_display_type'];
    } else {
        $calc_display_type = 'text';
    }
    ninja_forms_edit_field_el_output($field_id, 'select', __('Output calculation as', 'ninja-forms'), 'calc_display_type', $calc_display_type, 'wide', $options, 'widefat ninja-forms-calc-display');
    // If the calc_display_type is set to text, then we have several options to output.
    // Set the output to hidden for these options if the calc_display_type is not set to text.
    if ($calc_display_type != 'text') {
        $class = 'hidden';
    } else {
        $class = '';
    }
    echo '<div id="ninja_forms_field_' . $field_id . '_clac_text_display" class="' . $class . '">';
    // Output a label input textbox.
    if (isset($data['label'])) {
        $label = stripslashes($data['label']);
    } else {
        $label = '';
    }
    ninja_forms_edit_field_el_output($field_id, 'text', __('Label', 'ninja-forms'), 'label', $label, 'wide', '', 'widefat');
    // Output a label position select box.
    if (isset($data['label_pos'])) {
        $label_pos = $data['label_pos'];
    } else {
        $label_pos = '';
    }
    $options = array(array('name' => __('Left of Element', 'ninja-forms'), 'value' => 'left'), array('name' => __('Above Element', 'ninja-forms'), 'value' => 'above'), array('name' => __('Below Element', 'ninja-forms'), 'value' => 'below'), array('name' => __('Right of Element', 'ninja-forms'), 'value' => 'right'));
    ninja_forms_edit_field_el_output($field_id, 'select', __('Label Position', 'ninja-forms'), 'label_pos', $label_pos, 'wide', $options, 'widefat');
    // Output a disabled option checkbox.
    if (isset($data['calc_display_text_disabled'])) {
        $calc_display_text_disabled = $data['calc_display_text_disabled'];
    } else {
        $calc_display_text_disabled = 1;
    }
    ninja_forms_edit_field_el_output($field_id, 'checkbox', __('Disable input?', 'ninja-forms'), 'calc_display_text_disabled', $calc_display_text_disabled, 'thin', '', '');
    echo '</div>';
    // Set the output to hidden for the HTML RTE if the calc_display_type is not set to HTML.
    if ($calc_display_type != 'html') {
        $class = 'hidden';
    } else {
        $class = '';
    }
    // Output our RTE. This is the only extra setting needed if the calc_display_type is set to HTML.
    if (isset($data['calc_display_html'])) {
        $calc_display_html = $data['calc_display_html'];
    } else {
        $calc_display_html = '[ninja_forms_calc]';
    }
    echo '<div id="ninja_forms_field_' . $field_id . '_clac_html_display" class="' . $class . '">';
    ninja_forms_edit_field_el_output($field_id, 'rte', '', 'calc_display_html', $calc_display_html, '', '', '', __('Use the following shortcode to insert the final calculation: [ninja_forms_calc]', 'ninja-forms'));
    echo '</div>';
    // If any option besides "none" is selected, then show our custom class and help options.
    if ($calc_display_type == 'hidden') {
        $class = 'hidden';
    } else {
        $class = '';
    }
    if (isset($data['class'])) {
        $custom_class = $data['class'];
    } else {
        $custom_class = '';
    }
    if (isset($data['show_help'])) {
        $show_help = $data['show_help'];
    } else {
        $show_help = 0;
    }
    if (isset($data['help_text'])) {
        $help_text = $data['help_text'];
    } else {
        $help_text = '';
    }
    if ($show_help == 1) {
        $display_span = '';
    } else {
        $display_span = 'display:none;';
    }
    echo '<div id="ninja_forms_field_' . $field_id . '_clac_extra_display" class="' . $class . '">';
    // Output our custom class textbox.
    ninja_forms_edit_field_el_output($field_id, 'text', __('Custom CSS Class', 'ninja-forms'), 'class', $custom_class, 'thin', '', '');
    // Output our help text options.
    $help_desc = sprintf(__('If "help text" is enabled, there will be a question mark %s placed next to the input field. Hovering over this question mark will show the help text.', 'ninja-forms'), '<img src="' . NINJA_FORMS_URL . '/images/question-ico.gif">');
    ninja_forms_edit_field_el_output($field_id, 'checkbox', __('Show Help Text', 'ninja-forms'), 'show_help', $show_help, 'wide', '', 'ninja-forms-show-help');
    ?>
	<span id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_help_span" style="<?php 
    echo $display_span;
    ?>
">
		<?php 
    ninja_forms_edit_field_el_output($field_id, 'textarea', __('Help Text', 'ninja-forms'), 'help_text', $help_text, 'wide', '', 'widefat', $help_desc);
    ?>
	</span>
	<?php 
    echo '</div>';
    echo '<div class="description description-wide"><hr></div>';
    //echo '<h5>'.__( 'Calculation Options', 'ninja-forms' ).'</h5>';
    if (isset($data['calc_method'])) {
        $calc_method = $data['calc_method'];
    } else {
        $calc_method = 'auto';
    }
    switch ($calc_method) {
        case 'auto':
            $eq_class = 'hidden';
            $field_class = 'hidden';
            break;
        case 'fields':
            $eq_class = 'hidden';
            $field_class = '';
            break;
        case 'eq':
            $eq_class = '';
            $field_class = 'hidden';
            break;
    }
    if (isset($data['calc_eq'])) {
        $calc_eq = $data['calc_eq'];
    } else {
        $calc_eq = '';
    }
    if (isset($data['calc']) and $data['calc'] != '') {
        $calc = $data['calc'];
    } else {
        $calc = array();
    }
    $desc = '<p>' . __('You can enter calculation equations here using field_x where x is the ID of the field you want to use. For example, <strong>field_53 + field_28 + field_65</strong>.', 'ninja-forms') . '</p>';
    $desc .= '<p>' . __('Complex equations can be created by adding parentheses: <strong>( field_45 * field_2 ) / 2</strong>.', 'ninja-forms') . '</p>';
    $desc .= '<p>' . __('Please use these operators: + - * /. This is an advanced feature. Watch out for things like division by 0.', 'ninja-forms') . '</p>';
    $options = array(array('name' => __('Automatically Total Calculation Values', 'ninja-forms'), 'value' => 'auto'), array('name' => __('Specify Operations And Fields (Advanced)', 'ninja-forms'), 'value' => 'fields'), array('name' => __('Use An Equation (Advanced)', 'ninja-forms'), 'value' => 'eq'));
    ninja_forms_edit_field_el_output($field_id, 'select', __('Calculation Method', 'ninja-forms'), 'calc_method', $calc_method, 'wide', $options, 'widefat ninja-forms-calc-method');
    ?>
	
	<div class="ninja-forms-calculations <?php 
    echo $field_class;
    ?>
">
		<div class="label">
			<?php 
    _e('Field Operations', 'ninja-forms');
    ?>
 - <a href="#" name="" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_add_calc" class="ninja-forms-field-add-calc" rel="<?php 
    echo $field_id;
    ?>
"><?php 
    _e('Add Operation', 'ninja-forms');
    ?>
</a>
			
			<span class="spinner" style="float:left;"></span>
		</div>

		<input type="hidden" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[calc]" value="">
		<div id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_calc" class="" name="">
			<?php 
    $x = 0;
    foreach ($calc as $c) {
        ninja_forms_output_field_calc_row($field_id, $c, $x);
        $x++;
    }
    ?>
		</div>
	</div>
	<div class="ninja-forms-eq <?php 
    echo $eq_class;
    ?>
">
		<?php 
    ninja_forms_edit_field_el_output($field_id, 'textarea', __('Advanced Equation', 'ninja-forms'), 'calc_eq', $calc_eq, 'wide', '', 'widefat', $desc);
    ?>
	</div>
	<hr>
	<?php 
}
Example #3
0
function ninja_forms_add_calc_row()
{
    // Bail if we aren't in the admin
    if (!is_admin()) {
        return false;
    }
    check_ajax_referer('nf_ajax', 'nf_ajax_nonce');
    $field_id = absint($_REQUEST['field_id']);
    $c = array('calc' => '', 'operator' => 'add', 'value' => '', 'when' => '');
    $x = absint($_REQUEST['x']);
    ninja_forms_output_field_calc_row($field_id, $c, $x);
    die;
}
Example #4
0
function ninja_forms_add_calc_row()
{
    $field_id = absint($_REQUEST['field_id']);
    $c = array('calc' => '', 'operator' => 'add', 'value' => '', 'when' => '');
    $x = absint($_REQUEST['x']);
    ninja_forms_output_field_calc_row($field_id, $c, $x);
    die;
}