private static function get_ajax_time_options($values, array &$remove)
 {
     $time_key = str_replace('field_', '', $values['time_field']);
     $date_key = str_replace('field_', '', $values['date_field']);
     $values['date'] = FrmProAppHelper::maybe_convert_to_db_date($values['date'], 'Y-m-d');
     $date_entries = FrmEntryMeta::getEntryIds(array('fi.field_key' => $date_key, 'meta_value' => $values['date']));
     $remove = apply_filters('frm_allowed_times', $remove, $values);
     if (!$date_entries || empty($date_entries)) {
         return;
     }
     global $wpdb;
     $query = array('fi.field_key' => $time_key, 'it.item_id' => $date_entries);
     if (isset($values['entry_id']) && is_numeric($values['entry_id'])) {
         $query['it.item_id !'] = $values['entry_id'];
     }
     $used_times = FrmDb::get_col($wpdb->prefix . 'frm_item_metas it LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $query, 'meta_value');
     if (!$used_times || empty($used_times)) {
         return;
     }
     $number_allowed = apply_filters('frm_allowed_time_count', 1, $time_key, $date_key);
     $count = array();
     foreach ($used_times as $used) {
         if (isset($remove[$used])) {
             continue;
         }
         if (!isset($count[$used])) {
             $count[$used] = 0;
         }
         $count[$used]++;
         if ((int) $count[$used] >= $number_allowed) {
             $remove[$used] = $used;
         }
     }
 }
Example #2
0
 /**
  * Make sure this value is unique
  */
 public static function validate_unique_field(&$errors, $field, $value)
 {
     if (empty($value) || !FrmField::is_option_true($field, 'unique')) {
         return;
     }
     $entry_id = $_POST && isset($_POST['id']) ? $_POST['id'] : false;
     // get the child entry id for embedded or repeated fields
     if (isset($field->temp_id)) {
         $temp_id_parts = explode('-i', $field->temp_id);
         if (isset($temp_id_parts[1])) {
             $entry_id = $temp_id_parts[1];
         }
     }
     if ($field->type == 'time') {
         //TODO: add server-side validation for unique date-time
     } else {
         if ($field->type == 'date') {
             $value = FrmProAppHelper::maybe_convert_to_db_date($value, 'Y-m-d');
             if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) {
                 $errors['field' . $field->temp_id] = FrmFieldsHelper::get_error_msg($field, 'unique_msg');
             }
         } else {
             if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) {
                 $errors['field' . $field->temp_id] = FrmFieldsHelper::get_error_msg($field, 'unique_msg');
             }
         }
     }
 }
Example #3
0
 /**
  * Add custom fields to the post array
  */
 private static function populate_custom_fields($action, $entry, $fields, &$new_post)
 {
     // populate custom fields
     foreach ($action->post_content['post_custom_fields'] as $custom_field) {
         if (empty($custom_field['field_id']) || empty($custom_field['meta_name']) || !isset($fields[$custom_field['field_id']])) {
             continue;
         }
         $value = isset($entry->metas[$custom_field['field_id']]) ? $entry->metas[$custom_field['field_id']] : '';
         if ($fields[$custom_field['field_id']]->type == 'date') {
             $value = FrmProAppHelper::maybe_convert_to_db_date($value);
         }
         if (isset($new_post['post_custom'][$custom_field['meta_name']])) {
             $new_post['post_custom'][$custom_field['meta_name']] = (array) $new_post['post_custom'][$custom_field['meta_name']];
             $new_post['post_custom'][$custom_field['meta_name']][] = $value;
         } else {
             $new_post['post_custom'][$custom_field['meta_name']] = $value;
         }
         unset($value);
     }
 }