public static function set_post_fields($field, $value, &$errors)
 {
     $errors = FrmProEntryMetaHelper::set_post_fields($field, $value, $errors);
     return $errors;
 }
 function set_post_fields($field, $value, $errors = null)
 {
     _deprecated_function(__FUNCTION__, '1.07.05', 'FrmProEntryMetaHelper::set_post_fields');
     return FrmProEntryMetaHelper::set_post_fields($field, $value, $errors);
 }
 public static function import_csv($path, $form_id, $field_ids, $entry_key = 0, $start_row = 2, $del = ',', $max = 250)
 {
     global $importing_fields, $wpdb, $frmpro_settings;
     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, $frm_field;
         $row = 0;
         //setlocale(LC_ALL, get_locale());
         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 (is_numeric($field_id)) {
                     if (isset($importing_fields[$field_id])) {
                         $field = $importing_fields[$field_id];
                     } else {
                         $field = $frm_field->getOne($field_id);
                         $importing_fields[$field_id] = $field;
                     }
                     $values['item_meta'][$field_id] = apply_filters('frm_import_val', $data[$key], $field);
                     switch ($field->type) {
                         case 'user_id':
                             $values['item_meta'][$field_id] = FrmProAppHelper::get_user_id_param(trim($values['item_meta'][$field_id]));
                             $_POST['frm_user_id'] = $values['frm_user_id'] = $values['item_meta'][$field_id];
                             break;
                         case 'checkbox':
                         case 'select':
                             $values['item_meta'][$field_id] = self::get_multi_opts($values['item_meta'][$field_id], $field);
                             break;
                         case 'data':
                             $values['item_meta'][$field_id] = self::get_dfe_id($values['item_meta'][$field_id], $field, array(), $values);
                             break;
                         case 'file':
                             $values['item_meta'][$field_id] = self::get_file_id($values['item_meta'][$field_id]);
                             break;
                         case 'date':
                             $values['item_meta'][$field_id] = self::get_date($values['item_meta'][$field_id]);
                             break;
                     }
                     if (isset($_POST['item_meta'][$field_id]) and ($field->type == 'checkbox' or $field->type == 'data' and $field->field_options['data_type'] != 'checkbox')) {
                         if (empty($values['item_meta'][$field_id])) {
                             $values['item_meta'][$field_id] = $_POST['item_meta'][$field_id];
                         } else {
                             if (!empty($_POST['item_meta'][$field_id])) {
                                 $values['item_meta'][$field_id] = array_merge((array) $_POST['item_meta'][$field_id], (array) $values['item_meta'][$field_id]);
                             }
                         }
                     }
                     $_POST['item_meta'][$field_id] = $values['item_meta'][$field_id];
                     FrmProEntryMetaHelper::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];
             }
             $offset = get_option('gmt_offset') * 60 * 60;
             foreach (array('created_at', 'updated_at') as $stamp) {
                 if (!isset($values[$stamp])) {
                     continue;
                 }
                 // adjust the date format if it starts with the day
                 if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}/', trim($values[$stamp])) && substr($frmpro_settings->date_format, 0, 1) == 'd') {
                     $reg_ex = str_replace(array('/', '.', '-', 'd', 'j', 'm', 'y', 'Y'), array('\\/', '\\.', '\\-', '\\d{2}', '\\d', '\\d{2}', '\\d{2}', '\\d{4}'), $frmpro_settings->date_format);
                     if (preg_match('/^' . $reg_ex . '/', trim($values[$stamp]))) {
                         $values[$stamp] = FrmProAppHelper::convert_date($values[$stamp], $frmpro_settings->date_format, 'Y-m-d H:i:s');
                     }
                 }
                 $values[$stamp] = date('Y-m-d H:i:s', strtotime($values[$stamp]) - $offset);
                 unset($stamp);
             }
             unset($offset);
             if (isset($values['user_id'])) {
                 $values['user_id'] = FrmProAppHelper::get_user_id_param($values['user_id']);
             }
             if (isset($values['updated_by'])) {
                 $values['updated_by'] = FrmProAppHelper::get_user_id_param($values['updated_by']);
             }
             if (isset($values['is_draft'])) {
                 $values['is_draft'] = (int) $values['is_draft'];
             }
             $editing = false;
             if (isset($values['id']) && $values['item_key']) {
                 //check for updating by entry ID
                 $editing = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d AND id=%d", $values['form_id'], $values['id']));
             }
             if ($editing) {
                 $created = $frm_entry->update($values['id'], $values);
             } else {
                 $created = $frm_entry->create($values);
             }
             unset($_POST);
             unset($values);
             unset($created);
             if ($row - $start_row >= $max) {
                 fclose($f);
                 return $row;
             }
         }
         fclose($f);
         return $row;
     }
 }