public static function fill_entry_values($atts, $f, array &$values)
 {
     if (FrmField::is_no_save_field($f->type)) {
         return;
     }
     if ($atts['default_email']) {
         self::get_field_shortcodes_for_default_email($f, $values);
         return;
     }
     if ($atts['entry'] && !isset($atts['entry']->metas[$f->id])) {
         // In case include_blank is set
         $atts['entry']->metas[$f->id] = '';
         if (FrmAppHelper::pro_is_installed()) {
             FrmProEntryMeta::add_post_value_to_entry($f, $atts['entry']);
             FrmProEntryMeta::add_repeating_value_to_entry($f, $atts['entry']);
         }
     }
     $val = '';
     if ($atts['entry']) {
         $prev_val = maybe_unserialize($atts['entry']->metas[$f->id]);
         $meta = array('item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
         //This filter applies to the default-message shortcode and frm-show-entry shortcode only
         if (isset($atts['filter']) && $atts['filter'] == false) {
             $val = $prev_val;
         } else {
             $val = apply_filters('frm_email_value', $prev_val, (object) $meta, $atts['entry']);
         }
     }
     // Don't include blank values
     if (!$atts['include_blank'] && FrmAppHelper::is_empty_value($val)) {
         return;
     }
     self::textarea_display_value($f->type, $atts['plain_text'], $val);
     $val = apply_filters('frm_display_' . $f->type . '_value_custom', $val, array('field' => $f, 'atts' => $atts));
     if (is_array($val)) {
         if ($atts['format'] == 'text') {
             $val = implode(', ', $val);
         } else {
             if ($f->type == 'checkbox') {
                 $val = array_values($val);
             }
         }
     }
     self::maybe_strip_html($atts['plain_text'], $val);
     if ($atts['format'] != 'text') {
         $values[$f->field_key] = $val;
         if (isset($prev_val) && $prev_val != $val && $f->type != 'textarea') {
             $values[$f->field_key . '-value'] = $prev_val;
         }
     } else {
         $values[$f->id] = array('label' => $f->name, 'val' => $val);
     }
 }
 function import_csv($path, $form_id, $field_ids, $entry_key = 0, $start_row = 2, $del = ',')
 {
     global $importing_fields, $wpdb;
     if (!defined('WP_IMPORTING')) {
         define('WP_IMPORTING', true);
     }
     $form_id = (int) $form_id;
     if (!$form_id) {
         return $start_row;
     }
     if (!$importing_fields) {
         $importing_fields = array();
     }
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     //Remove time limit to execute this function
     if ($f = fopen($path, "r")) {
         unset($path);
         global $frm_entry, $frmdb;
         $row = 0;
         //setlocale(LC_ALL, 'ja_JP.UTF8');
         while (($data = fgetcsv($f, 100000, $del)) !== FALSE) {
             $row++;
             if ($start_row > $row) {
                 continue;
             }
             $values = array('form_id' => $form_id);
             $values['item_meta'] = array();
             foreach ($field_ids as $key => $field_id) {
                 $data[$key] = isset($data[$key]) ? $data[$key] : '';
                 //if($data[$key] == ''){
                 //    error_log($row .' key:'. $key .' $data[$key] empty');
                 //    return $row-1;
                 //}
                 if (is_numeric($field_id)) {
                     if (isset($importing_fields[$field_id])) {
                         $field = $importing_fields[$field_id];
                     } else {
                         $field = FrmField::getOne($field_id);
                         $importing_fields[$field_id] = $field;
                     }
                     $values['item_meta'][$field_id] = $data[$key];
                     if ($field->type == 'user_id') {
                         if (!is_numeric($values['item_meta'][$field_id])) {
                             if (!isset($user_array)) {
                                 $users = $wpdb->get_results("SELECT ID, user_login, display_name FROM {$wpdb->users} ORDER BY display_name ASC");
                                 $user_array = array();
                                 foreach ($users as $user) {
                                     $ukey = !empty($user->display_name) ? $user->display_name : $user->user_login;
                                     $user_array[$ukey] = $user->ID;
                                     unset($ukey);
                                     unset($user);
                                 }
                             }
                             if (isset($user_array[$values['item_meta'][$field_id]])) {
                                 $values['item_meta'][$field_id] = (int) $user_array[$values['item_meta'][$field_id]];
                             }
                         }
                         $values['user_id'] = $values['item_meta'][$field_id];
                     } else {
                         if ($field->type == 'checkbox' and !empty($values['item_meta'][$field_id])) {
                             if (!in_array($values['item_meta'][$field_id], (array) $field->options)) {
                                 $checked = maybe_unserialize($values['item_meta'][$field_id]);
                                 if (!is_array($checked)) {
                                     $checked = explode(',', $checked);
                                 }
                                 if ($checked and count($checked) > 1) {
                                     $values['item_meta'][$field_id] = array_map('trim', $checked);
                                 }
                             }
                         }
                     }
                     $_POST['item_meta'][$field_id] = $values['item_meta'][$field_id];
                     FrmProEntryMeta::set_post_fields($field, $values['item_meta'][$field_id]);
                     unset($field);
                 } else {
                     if (is_array($field_id)) {
                         $field_type = isset($field_id['type']) ? $field_id['type'] : false;
                         $linked = isset($field_id['linked']) ? $field_id['linked'] : false;
                         $field_id = $field_id['field_id'];
                         if ($field_type == 'data') {
                             if ($linked) {
                                 $entry_id = $frmdb->get_var($frmdb->entry_metas, array('meta_value' => $data[$key], 'field_id' => $linked), 'item_id');
                             } else {
                                 //get entry id of entry with item_key == $data[$key]
                                 $entry_id = $frmdb->get_var($frmdb->entries, array('item_key' => $data[$key]));
                             }
                             if ($entry_id) {
                                 $values['item_meta'][$field_id] = $entry_id;
                             }
                         }
                         unset($field_type);
                         unset($linked);
                     } else {
                         $values[$field_id] = $data[$key];
                     }
                 }
             }
             if (!isset($values['item_key']) or empty($values['item_key'])) {
                 $values['item_key'] = $data[$entry_key];
             }
             if (isset($values['created_at'])) {
                 $values['created_at'] = date('Y-m-d H:i:s', strtotime($values['created_at']));
             }
             if (isset($values['updated_at'])) {
                 $values['updated_at'] = date('Y-m-d H:i:s', strtotime($values['updated_at']));
             }
             $created = $frm_entry->create($values);
             unset($_POST);
             unset($values);
             unset($created);
             if ($row - $start_row >= 250) {
                 //change max rows here
                 fclose($f);
                 return $row;
             }
         }
         fclose($f);
         return $row;
     }
 }
 public static function update_field_ajax()
 {
     //check_ajax_referer( 'frm_ajax', 'nonce' );
     $entry_id = FrmAppHelper::get_param('entry_id', 0, 'post', 'absint');
     $field_id = FrmAppHelper::get_param('field_id', 0, 'post', 'sanitize_title');
     $value = FrmAppHelper::get_param('value');
     FrmField::maybe_get_field($field_id);
     if ($field_id && FrmProEntriesHelper::user_can_edit($entry_id, $field_id->form_id)) {
         $updated = FrmProEntryMeta::update_single_field(compact('entry_id', 'field_id', 'value'));
         echo $updated;
     }
     wp_die();
 }
 public static function validate_meta($errors, $field)
 {
     $frmpro_entry_meta = new FrmProEntryMeta();
     return $frmpro_entry_meta->validate($errors, $field);
 }
 /**
  * Get inputs for graph (when no x-axis is set and only one field is graphed)
  *
  * @since 2.0
  *
  * @param object $field
  * @param array $args
  * @return array $inputs all values for field
  */
 public static function get_generic_inputs($field, $args)
 {
     $meta_args = array('entry_ids', 'user_id', 'start_date', 'end_date');
     foreach ($meta_args as $key => $arg) {
         if ($args[$arg]) {
             $meta_args[$arg] = $args[$arg];
         }
         unset($meta_args[$key], $key, $arg);
     }
     // Get the metas
     $inputs = FrmProEntryMeta::get_all_metas_for_field($field, $meta_args);
     // Clean up multi-dimensional array
     self::clean_inputs($inputs, $field, $args);
     return $inputs;
 }