Commit 3ac377b9 authored by Kevin Stover's avatar Kevin Stover

Merge branch 'release/v2.2.49'

parents e9a77c5b 1ded91d2
......@@ -100,6 +100,7 @@ function ninja_forms_export_subs_to_csv( $sub_ids = '', $return = false ){
header("Content-Disposition: attachment; filename=".$filename);
header("Pragma: no-cache");
header("Expires: 0");
echo "\xEF\xBB\xBF"; // Byte Order Mark
echo str_putcsv($array);
die();
......
......@@ -240,6 +240,15 @@ function ninja_forms_calc_after_import_form( $form ){
}
}
}
if ( isset ( $field_rows[$y]['data']['calc_eq'] ) AND $field_rows[$y]['data']['calc_eq'] != '' ) {
$calc_eq = $field_rows[$y]['data']['calc_eq'];
foreach( $form['field'] as $inserted_field ){
$calc_eq = str_replace( 'field_'.$inserted_field['old_id'], 'field_'.$inserted_field['id'], $calc_eq );
}
$field_rows[$y]['data']['calc_eq'] = $calc_eq;
}
$field_rows[$y]['data'] = serialize( $field_rows[$y]['data'] );
$args = array(
'update_array' => array(
......@@ -251,6 +260,64 @@ function ninja_forms_calc_after_import_form( $form ){
);
ninja_forms_update_field($args);
}
if ( isset ( $form['data']['success_msg'] ) AND $form['data']['success_msg'] != '' ) {
$success_msg = $form['data']['success_msg'];
foreach( $form['field'] as $inserted_field ){
$success_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $success_msg );
}
$form['data']['success_msg'] = $success_msg;
}
if ( isset ( $form['data']['user_email_msg'] ) AND $form['data']['user_email_msg'] != '' ) {
$user_email_msg = $form['data']['user_email_msg'];
foreach( $form['field'] as $inserted_field ){
$user_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $user_email_msg );
}
$form['data']['user_email_msg'] = $user_email_msg;
}
if ( isset ( $form['data']['admin_email_msg'] ) AND $form['data']['admin_email_msg'] != '' ) {
$admin_email_msg = $form['data']['admin_email_msg'];
foreach( $form['field'] as $inserted_field ){
$admin_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $admin_email_msg );
}
$form['data']['admin_email_msg'] = $admin_email_msg;
}
if ( isset ( $form['data']['mp_confirm_msg'] ) AND $form['data']['mp_confirm_msg'] != '' ) {
$mp_confirm_msg = $form['data']['mp_confirm_msg'];
foreach( $form['field'] as $inserted_field ){
$mp_confirm_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $mp_confirm_msg );
}
$form['data']['mp_confirm_msg'] = $mp_confirm_msg;
}
if ( isset ( $form['data']['save_msg'] ) AND $form['data']['save_msg'] != '' ) {
$save_msg = $form['data']['save_msg'];
foreach( $form['field'] as $inserted_field ){
$save_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $save_msg );
}
$form['data']['save_msg'] = $save_msg;
}
if ( isset ( $form['data']['save_email_msg'] ) AND $form['data']['save_email_msg'] != '' ) {
$save_email_msg = $form['data']['save_email_msg'];
foreach( $form['field'] as $inserted_field ){
$save_email_msg = str_replace( '[ninja_forms_field id='.$inserted_field['old_id'].']', '[ninja_forms_field id='.$inserted_field['id'].']', $save_email_msg );
}
$form['data']['save_email_msg'] = $save_email_msg;
}
$args = array(
'update_array' => array(
'data' => serialize( $form['data'] ),
),
'where' => array(
'id' => $form['id'],
),
);
ninja_forms_update_form($args);
}
}
}
\ No newline at end of file
......@@ -346,6 +346,7 @@ function ninja_forms_tab_view_subs(){
add_filter('ninja_forms_field', 'ninja_forms_edit_sub_default_value', 15, 2);
add_filter('ninja_forms_field', 'ninja_forms_edit_sub_hide_fields', 99, 2);
add_filter( 'ninja_forms_display_form_form_data', 'ninja_forms_edit_sub_remove_ajax' );
remove_action('ninja_forms_display_before_fields', 'ninja_forms_display_req_items');
remove_action('ninja_forms_display_open_form_tag', 'ninja_forms_display_open_form_tag');
remove_action('ninja_forms_display_close_form_tag', 'ninja_forms_display_close_form_tag');
......@@ -430,9 +431,17 @@ function ninja_forms_tab_view_subs(){
if(isset($_POST['_ninja_forms_edit_sub']) AND $_POST['_ninja_forms_edit_sub'] == 1){
add_action( 'init', 'ninja_forms_setup_processing_class', 5 );
add_action( 'init', 'ninja_forms_set_save_sub' );
add_action( 'init', 'ninja_forms_edit_sub_remove_ajax_processing', 7 );
add_action( 'init', 'ninja_forms_edit_sub_pre_process', 999 );
}
function ninja_forms_edit_sub_remove_ajax_processing(){
global $ninja_forms_processing;
$ninja_forms_processing->update_form_setting( 'ajax', 0 );
}
function ninja_forms_edit_sub_pre_process(){
global $ninja_forms_processing;
......@@ -630,4 +639,9 @@ function ninja_forms_view_subs_default_filter( $sub_results ) {
}
add_filter( 'ninja_forms_view_subs_results', 'ninja_forms_view_subs_default_filter' );
add_filter( 'ninja_forms_download_all_subs_results', 'ninja_forms_view_subs_default_filter' );
\ No newline at end of file
add_filter( 'ninja_forms_download_all_subs_results', 'ninja_forms_view_subs_default_filter' );
function ninja_forms_edit_sub_remove_ajax( $form ){
$form['data']['ajax'] = 0;
return $form;
}
\ No newline at end of file
......@@ -12,22 +12,10 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
global $ninja_forms_processing;
if ( !is_object ( $ninja_forms_processing ) ) {
$field_row = ninja_forms_get_field_by_id( $field_id );
$form_id = $field_row['form_id'];
if ( $field_row['type'] == '_calc' ) {
if ( !isset ( $ninja_forms_processing ) ) {
$form_row = ninja_forms_get_form_by_field_id( $field_id );
$form_id = $form_row['id'];
$all_fields = ninja_forms_get_fields_by_form_id( $form_id );
$calc_array = array();
foreach ( $all_fields as $field ) {
if ( $field['type'] == '_calc' ) {
$calc_array[] = $field['id'];
}
}
}
//echo "Calc Filter";
// Figure out which method we are using to calculate this field.
if ( isset ( $calc_data['calc_method'] ) ) {
$calc_method = $calc_data['calc_method'];
......@@ -53,8 +41,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
$all_fields = ninja_forms_get_fields_by_form_id( $form_id );
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11 );
// Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto.
$tax = false;
$sub_total = false;
......@@ -79,6 +66,7 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
// Figure out how many calculation fields we have and run
$result = $calc_data['default_value'];
foreach ( $all_fields as $field ) {
if ( $field['id'] != $field_id ) {
$field_data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] );
......@@ -122,16 +110,16 @@ function ninja_forms_field_calc_filter( $calc_data, $field_id ){
$calc_value = ninja_forms_calc_field_loop( $field['id'], $calc_eq );
} else {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
}
}
if ( $calc_value !== false ) {
$calc_eq = preg_replace('/\bfield_'.$field['id'].'\b/', $calc_value, $calc_eq );
}
}
break;
}
}
}
}
if ( $calc_method == 'eq' ) {
$eq = new eqEOS();
$result = $eq->solveIF($calc_eq);
......@@ -196,6 +184,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){
// Figure out if there is a sub_total and a tax field. If there are, and this is a total field set to calc_method auto, we're using an equation, not auto.
$tax = false;
$sub_total = false;
foreach ( $all_fields as $field ) {
$data = apply_filters( 'ninja_forms_field', $field['data'], $field['id'] );
......@@ -207,7 +196,7 @@ function ninja_forms_calc_field_loop( $field_id, $calc_eq = '', $result = '' ){
$sub_total = $field['id'];
}
}
// If the tax and sub_total have been found, and this is a total field set to auto, change the calc_method and calc_eq.
if ( $tax AND $sub_total AND isset ( $calc_data['payment_total'] ) AND $calc_data['payment_total'] == 1 AND $calc_method == 'auto' ) {
$calc_method = 'eq';
......@@ -380,11 +369,11 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
} else {
$field = ninja_forms_get_field_by_id( $field_id );
}
//$field_data = $field['data'];
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 2 );
//remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
$field_data = apply_filters( 'ninja_forms_field', $field['data'], $field_id );
add_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
//add_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
if ( isset ( $field_data['default_value'] ) ) {
$default_value = $field_data['default_value'];
......@@ -395,7 +384,7 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
if ( $field_value == '' ) {
$field_value = $default_value;
}
$calc_value = 0;
if ( $field['type'] == '_list' ) {
if ( isset ( $field_data['list']['options'] ) ) {
......@@ -424,9 +413,9 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
if ( !$field_value OR $field_value == '' ) {
$field_value = 0;
}
$calc_value = $field_value;
$calc_value = (float) preg_replace('/[^0-9.]*/','',$field_value);
}
if ( is_string( $calc_value ) AND strpos( $calc_value, "%" ) !== false ) {
$calc_value = str_replace( "%", "", $calc_value );
$calc_value = $calc_value / 100;
......
<?php
/*
*
* Function that filters default values, replacing defined strings with the approparite values.
*
* @since 2.2.49
* @return $data
*/
function ninja_forms_default_value_filter( $data, $field_id ) {
global $current_user;
if(isset($data['default_value'])){
$default_value = $data['default_value'];
}else{
$default_value = '';
}
get_currentuserinfo();
$user_ID = $current_user->ID;
$user_firstname = $current_user->user_firstname;
$user_lastname = $current_user->user_lastname;
$user_display_name = $current_user->display_name;
$user_email = $current_user->user_email;
switch( $default_value ){
case '_user_id':
$default_value = $user_ID;
break;
case 'user_firstname':
$default_value = $user_firstname;
break;
case 'user_lastname':
$default_value = $user_lastname;
break;
case '_user_display_name':
$default_value = $user_display_name;
break;
case 'user_email':
$default_value = $user_email;
break;
}
$data['default_value'] = $default_value;
return $data;
}
add_filter( 'ninja_forms_field', 'ninja_forms_default_value_filter', 9, 2 );
\ No newline at end of file
......@@ -74,6 +74,10 @@ function ninja_forms_display_fields($form_id){
$display_style = '';
}
if ( $display_style != '' ) {
$display_style = 'style="'.$display_style.'"';
}
if ( $display_function != '' AND $show_field ) {
if ( isset( $data['label_pos'] ) ) {
$label_pos = $data['label_pos'];
......@@ -92,7 +96,7 @@ function ninja_forms_display_fields($form_id){
$field_wrap_class = apply_filters( 'ninja_forms_field_wrap_class', $field_wrap_class, $field_id );
do_action( 'ninja_forms_display_before_opening_field_wrap', $field_id, $data );
?>
<div class="<?php echo $field_wrap_class;?>" style="<?php echo $display_style;?>" id="ninja_forms_field_<?php echo $field_id;?>_div_wrap">
<div class="<?php echo $field_wrap_class;?>" <?php echo $display_style;?> id="ninja_forms_field_<?php echo $field_id;?>_div_wrap">
<?php
do_action( 'ninja_forms_display_after_opening_field_wrap', $field_id, $data );
}
......
......@@ -21,7 +21,7 @@ function ninja_forms_display_field_help( $field_id, $data ){
if($show_help){
?>
<img id="" class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>/images/question-ico.gif" title="<?php echo $help_text;?>">
<img class='ninja-forms-help-text' src="<?php echo NINJA_FORMS_URL;?>/images/question-ico.gif" title="<?php echo $help_text;?>">
<?php
}
}
......
......@@ -120,6 +120,7 @@ function ninja_forms_display_form( $form_id = '' ){
}
if($form_id != ''){ //Make sure that we have an active form_id.
$form_row = ninja_forms_get_form_by_id($form_id);
$form_row = apply_filters( 'ninja_forms_display_form_form_data', $form_row );
if( isset( $form_row['data']['ajax'] ) ){
$ajax = $form_row['data']['ajax'];
}else{
......
......@@ -24,7 +24,7 @@ function ninja_forms_display_form_title( $form_id ){
$form_title = '';
}
$title_class = '';
$title_class = 'ninja-forms-form-title';
$title_class = apply_filters( 'ninja_forms_form_title_class', $title_class, $form_id );
......
......@@ -819,6 +819,7 @@ class Ninja_Forms_Processing {
$data = $field['data'];
$field_id = $field['id'];
$user_value = $this->get_field_value( $field_id );
if ( isset ( $data['payment_total'] ) AND $data['payment_total'] == 1 ) {
$calc_method = $data['calc_method'];
if ( isset ( $data['calc'] ) ) {
......@@ -827,8 +828,9 @@ class Ninja_Forms_Processing {
$calc_eq = $data['calc_eq'];
$places = $data['calc_places'];
$total_field = $field_id;
$total_value = number_format( round( $user_value, $places ), $places );
break;
}
}
......@@ -1032,57 +1034,70 @@ class Ninja_Forms_Processing {
// Loop through the fields
foreach ( $this->data['field_data'] as $field ) {
$field_value = $this->get_field_value( $field['id'] );
switch ( $calc_method ) {
case 'auto':
// If this field's calc_auto_include is set to 1, then add this field's ID to the list.
if ( isset ( $field['data']['calc_auto_include'] ) AND $field['data']['calc_auto_include'] == 1 ) {
if ( $field['type'] != '_calc' ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
// We don't want our field to be added if it's a tax field.
if ( $field['type'] != '_tax' ) {
switch ( $calc_method ) {
case 'auto':
// If this field's calc_auto_include is set to 1, then add this field's ID to the list.
if ( isset ( $field['data']['calc_auto_include'] ) AND $field['data']['calc_auto_include'] == 1 ) {
if ( $field['type'] != '_calc' ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
} else {
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
break;
case 'fields':
// If this field is in our list of field operations, add this field's ID to our list.
if ( $calc_fields != '' ) {
foreach ( $calc_fields as $calc ) {
if ( $field['id'] == $calc['field'] ) {
break;
case 'fields':
// If this field is in our list of field operations, add this field's ID to our list.
if ( $calc_fields != '' ) {
foreach ( $calc_fields as $calc ) {
if ( $field['id'] == $calc['field'] ) {
if ( $field['type'] != '_calc' ) {
//echo "FIELD ID: ".$field['id'];
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
}
}
break;
case 'eq':
// If this field exists in our equation, then add this field's ID to our list.
if ( $calc_eq != '' ) {
if ( preg_match("/\bfield_".$field['id']."\b/i", $calc_eq ) ) {
if ( $field['type'] != '_calc' ) {
//echo "FIELD ID: ".$field['id'];
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
if ( $this->get_field_value( $field['id'] ) ) {
$tmp_array[] = array( $field['id'] => $this->get_field_value( $field['id'] ) );
}
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
}
}
break;
case 'eq':
// If this field exists in our equation, then add this field's ID to our list.
if ( $calc_eq != '' ) {
if ( preg_match("/\bfield_".$field['id']."\b/i", $calc_eq ) ) {
if ( $field['type'] != '_calc' ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value ) {
$tmp_array[] = array( $field['id'] => $calc_value );
}
} else {
// If this is a calc field, then call this same function so that we can get all the fields that contributed to that.
$tmp_array[] = $this->get_calc_fields( $field['id'] );
}
}
}
break;
break;
}
}
}
// Loop through our array and make sure that it's not multi-dimensional.
......@@ -1098,7 +1113,7 @@ class Ninja_Forms_Processing {
}
}
}
return $calc_array;
}
......
<?php
add_action('init', 'ninja_forms_register_fields_pre_process');
function ninja_forms_register_fields_pre_process(){
add_action('ninja_forms_pre_process', 'ninja_forms_fields_pre_process', 11 );
add_action( 'ninja_forms_pre_process', 'ninja_forms_fields_pre_process' );
}
function ninja_forms_fields_pre_process(){
......
......@@ -156,6 +156,7 @@ function ninja_forms_display_js($form_id, $local_vars = ''){
}
$form_row = ninja_forms_get_form_by_id($form_id);
$form_row = apply_filters( 'ninja_forms_display_form_form_data', $form_row );
if( isset( $form_row['data']['ajax'] ) ){
$ajax = $form_row['data']['ajax'];
}else{
......
......@@ -20,7 +20,7 @@ function ninja_forms_register_field_calc(){
'edit_custom_class' => false,
'edit_help' => false,
//'process_field' => false,
//'pre_process' => 'ninja_forms_field_calc_pre_process',
//'pre_process' => 'ninja_forms_field_calc_strip_currency_symbol',
'edit_options' => array(
array(
'type' => 'hidden',
......@@ -317,7 +317,7 @@ function ninja_forms_field_calc_edit( $field_id, $data ){
*/
function ninja_forms_field_calc_display( $field_id, $data ){
if ( isset( $data['default_value'] ) ) {
$default_value = $data['default_value'];
} else {
......@@ -486,6 +486,13 @@ function ninja_forms_field_calc_pre_process(){
$calc_eq = $field_data['calc_eq'];
} else {
$calc_eq = array();
}
// Get our calculation equation if it exists.
if ( isset ( $field_data['calc_places'] ) ) {
$calc_places = $field_data['calc_places'];
} else {
$calc_places = 0;
}
$all_fields = $ninja_forms_processing->get_all_fields();
......@@ -533,12 +540,11 @@ function ninja_forms_field_calc_pre_process(){
case 'auto': // We are automatically totalling the fields that have a calc_auto_include set to 1.
if ( isset ( $field_data['calc_auto_include'] ) AND $field_data['calc_auto_include'] == 1 ) {
if ( $field['type'] == '_calc' ) {
$result = ninja_forms_calc_field_loop2( $field['id'], '', $result );
} else {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( 'add', $result, $calc_value );
}
$calc_value = ninja_forms_calc_field_loop2( $field['id'], '', $result );
}
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( 'add', $result, $calc_value );
}
}
break;
......@@ -547,13 +553,12 @@ function ninja_forms_field_calc_pre_process(){
foreach ( $calc_fields as $c ) {
if ( $c['field'] == $field['id'] ) {
if ( $field['type'] == '_calc' ) {
$result = ninja_forms_calc_field_loop2( $field['id'], '', $result );
} else {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( $c['op'], $result, $calc_value );
}
}
$calc_value = ninja_forms_calc_field_loop2( $field['id'], '', $result );
}
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( $c['op'], $result, $calc_value );
}
}
}
}
......@@ -570,49 +575,19 @@ function ninja_forms_field_calc_pre_process(){
}
}
break;
}
/*
switch ( $calc_method ) {
case 'auto': // We are automatically totalling the fields that have a calc_auto_include set to 1.
if ( isset ( $data['calc_auto_include'] ) AND $data['calc_auto_include'] == 1 ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( 'add', $result, $calc_value );
}
}
break;
case 'fields': // We are performing a specific set of operations on a set of fields.
if ( is_array ( $calc_fields ) ) {
foreach ( $calc_fields as $c ) {
if ( $c['field'] == $field['id'] ) {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$result = ninja_forms_calc_evaluate( $c['op'], $result, $calc_value );
}
}
}
}
break;
case 'eq':
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
if ( $calc_value !== false ) {
$calc_eq = preg_replace('/\bfield_'.$field['id'].'\b/', $calc_value, $calc_eq );
}
break;
}
*/
}
}
if ( $calc_method == 'eq' ) {
$eq = new eqEOS();
$result = $eq->solveIF($calc_eq);
}
if ( isset ( $field_data['calc_places'] ) ) {
$places = $field_data['calc_places'];
$result = number_format( round( $result, $places ), $places );
if ( isset ( $calc_places ) ) {
$result = number_format( round( $result, $calc_places ), $calc_places );
}
$result = str_replace( ',', '', $result );
$ninja_forms_processing->update_field_value( $field_id, $result );
}
}
......@@ -648,7 +623,7 @@ function ninja_forms_calc_field_loop2( $field_id, $calc_eq = '', $result = '' ){
} else {
$calc_eq = array();
}
$form_id = $ninja_forms_processing->get_form_ID();
$all_fields = $ninja_forms_processing->get_all_fields();
......@@ -712,7 +687,7 @@ function ninja_forms_calc_field_loop2( $field_id, $calc_eq = '', $result = '' ){
case 'eq':
if (preg_match("/\bfield_".$field['id']."\b/i", $calc_eq ) ) {
if ( $field['type'] == '_calc' ) {
$calc_value = ninja_forms_calc_field_loop2( $field['id'], $calc_eq );
$calc_value = ninja_forms_calc_field_loop2( $field['id'], $calc_eq, $result );
} else {
$calc_value = ninja_forms_field_calc_value( $field['id'], $field_value, $calc_method );
}
......
......@@ -301,7 +301,7 @@ function ninja_forms_field_list_display( $field_id, $data ){
$disabled = '';
}
$label = htmlentities( $label );
$label = htmlspecialchars( $label );
$label = stripslashes( $label );
......@@ -529,8 +529,8 @@ function ninja_forms_field_list_option_output($field_id, $x, $option = '', $hidd
$hidden = 'display:none';
}
if(is_array($option)){
$label = htmlentities( $option['label'] );
$value = htmlentities( $option['value'] );
$label = htmlspecialchars( $option['label'] );
$value = htmlspecialchars( $option['value'] );
if ( isset ( $option['calc'] ) ) {
$calc = $option['calc'];
} else {
......
......@@ -155,20 +155,13 @@ jQuery(document).ready(function(jQuery) {
* Calculation Field JS
*/
// Listen to the input elements with our calculation class for focus.
jQuery('body').on( 'focus', '.ninja-forms-field-calc-listen', function(e){
jQuery(this).data( "oldValue", jQuery(this).val() );
});
// Listen to the input elements with our calculation class for focus.
jQuery('body').on( 'mousedown', '.ninja-forms-field-calc-listen', function(e){
jQuery(this).data( "oldValue", jQuery(this).val() );
});
var selects = jQuery(".ninja-forms-field-calc-listen");
// Listen to the input elements with our calculation class for focus.
jQuery('body').on( 'keydown', '.ninja-forms-field-calc-listen', function(e){
if( this.type == 'select-multiple' ) {
jQuery(this).data( "oldValue", jQuery(this).val() );
selects.each(function (i, element) {
var select = jQuery(element);
var previousValue = jQuery(this).val();
if ( this.type !== 'checkbox' ) {
jQuery(element).data("oldValue", previousValue);
}
});
......@@ -184,7 +177,9 @@ jQuery(document).ready(function(jQuery) {
// Listen to the input elements for our auto-calculation fields and change the total.
jQuery('body').on( 'change', '.ninja-forms-field-calc-listen', function(event){
if ( this == event.target ) {
// Get our calc settings.
var form_id = ninja_forms_get_form_id( this );
var field_id = jQuery(this).attr("rel");
......@@ -225,10 +220,11 @@ jQuery(document).ready(function(jQuery) {
var new_value = '';
// Set our old_value to the previous one for this field.
old_value = jQuery(this).data('oldValue');
// Check to see if we are in a list field. If we are, we can grab the calc values.
if ( jQuery('#ninja_forms_field_' + field_id + '_type' ).val() == 'list' ) {
var key = jQuery(this).val();
// See if we have any old values. If we do, compare them to our current selectino for this field and see if we need to subtract anything.
// See if we have any old values. If we do, compare them to our current selection for this field and see if we need to subtract anything.