public static function add_form_button_options($values)
 {
     global $frm_vars;
     $page_field = FrmProFormsHelper::has_field('break', $values['id'], true);
     $post_types = FrmProAppHelper::get_custom_post_types();
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-forms/add_form_button_options.php';
 }
 public static function get_search_ids($s, $form_id, $args = array())
 {
     global $wpdb;
     if (empty($s)) {
         return false;
     }
     preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
     $search_terms = array_map('trim', $matches[0]);
     $spaces = '';
     $e_ids = $p_search = array();
     $search = array('or' => 1);
     $data_field = FrmProFormsHelper::has_field('data', $form_id, false);
     foreach ((array) $search_terms as $term) {
         $p_search[] = array($spaces . $wpdb->posts . '.post_title like' => $term, $spaces . $wpdb->posts . '.post_content like' => $term, 'or' => 1);
         $search[$spaces . 'meta_value like'] = $term;
         $spaces .= ' ';
         // add a space to keep the array keys unique
         if (is_numeric($term)) {
             $e_ids[] = (int) $term;
         }
         if ($data_field) {
             $df_form_ids = array();
             //search the joined entry too
             foreach ((array) $data_field as $df) {
                 FrmProFieldsHelper::get_subform_ids($df_form_ids, $df);
                 unset($df);
             }
             $data_form_ids = FrmDb::get_col($wpdb->prefix . 'frm_fields', array('id' => $df_form_ids), 'form_id');
             unset($df_form_ids);
             if ($data_form_ids) {
                 $data_entry_ids = FrmEntryMeta::getEntryIds(array('fi.form_id' => $data_form_ids, 'meta_value like' => $term));
                 if ($data_entry_ids) {
                     if (!isset($search['meta_value'])) {
                         $search['meta_value'] = array();
                     }
                     $search['meta_value'] = array_merge($search['meta_value'], $data_entry_ids);
                 }
             }
             unset($data_form_ids);
         }
     }
     $matching_posts = FrmDb::get_col($wpdb->posts, $p_search, 'ID');
     $p_ids = array($search, 'or' => 1);
     if ($matching_posts) {
         $post_ids = FrmDb::get_col($wpdb->prefix . 'frm_items', array('post_id' => $matching_posts, 'form_id' => (int) $form_id));
         if ($post_ids) {
             $p_ids['item_id'] = $post_ids;
         }
     }
     if (!empty($e_ids)) {
         $p_ids['item_id'] = $e_ids;
     }
     $query = array('fi.form_id' => $form_id);
     $query[] = $p_ids;
     return FrmEntryMeta::getEntryIds($query, '', '', true, $args);
 }
 public static function get_search_str($where_clause = '', $search_str, $form_id = false, $fid = false)
 {
     global $frm_entry_meta, $wpdb;
     $where_item = '';
     $join = ' (';
     if (!is_array($search_str)) {
         $search_str = explode(" ", $search_str);
     }
     foreach ($search_str as $search_param) {
         $unescaped_search_param = $search_param;
         $search_param = FrmAppHelper::esc_like($search_param);
         if (!is_numeric($fid)) {
             $where_item .= empty($where_item) ? ' (' : ' OR';
             if (in_array($fid, array('created_at', 'user_id', 'updated_at', 'id'))) {
                 if ($fid == 'user_id' && !is_numeric($search_param)) {
                     $search_param = FrmProAppHelper::get_user_id_param($unescaped_search_param);
                 }
                 $where_item .= $wpdb->prepare(" it.{$fid} like %s", '%' . $search_param . '%');
             } else {
                 $where_item .= $wpdb->prepare(' it.name like %s OR it.item_key like %s OR it.description like %s OR it.created_at like %s', '%' . $search_param . '%', '%' . $search_param . '%', '%' . $search_param . '%', '%' . $search_param . '%');
             }
         }
         if (empty($fid) || is_numeric($fid)) {
             $where_entries = $wpdb->prepare('(meta_value LIKE %s', '%' . $search_param . '%');
             if ($data_fields = FrmProFormsHelper::has_field('data', $form_id, false)) {
                 $df_form_ids = array();
                 //search the joined entry too
                 foreach ((array) $data_fields as $df) {
                     //don't check if a different field is selected
                     if (is_numeric($fid) && (int) $fid != $df->id) {
                         continue;
                     }
                     $df->field_options = maybe_unserialize($df->field_options);
                     if (isset($df->field_options['form_select']) && is_numeric($df->field_options['form_select'])) {
                         $df_form_ids[] = $df->field_options['form_select'];
                     }
                     unset($df);
                 }
                 unset($data_fields);
                 if (!empty($df_form_ids)) {
                     $data_form_ids = $wpdb->get_col("SELECT form_id FROM {$wpdb->prefix}frm_fields WHERE id in (" . implode(',', array_filter($df_form_ids, 'is_numeric')) . ")");
                     if ($data_form_ids) {
                         $data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ") " . $wpdb->prepare("and meta_value LIKE %s", '%' . $search_param . '%'));
                         if (!empty($data_entry_ids)) {
                             $where_entries .= " OR meta_value in (" . implode(',', $data_entry_ids) . ")";
                         }
                     }
                     unset($data_form_ids);
                 }
                 unset($df_form_ids);
             }
             $where_entries .= ")";
             if (is_numeric($fid)) {
                 $where_entries .= $wpdb->prepare(' AND field_id=%d', $fid);
             }
             if (is_admin() && isset($_GET) && isset($_GET['page']) && $_GET['page'] == 'formidable-entries') {
                 $include_drafts = true;
             } else {
                 $include_drafts = false;
             }
             $meta_ids = $frm_entry_meta->getEntryIds($where_entries, '', '', true, $include_drafts);
             if (!empty($where_clause)) {
                 $where_clause .= " AND" . $join;
                 if (!empty($join)) {
                     $join = '';
                 }
             }
             if (!empty($meta_ids)) {
                 $where_clause .= " it.id in (" . implode(',', $meta_ids) . ")";
             } else {
                 $where_clause .= " it.id=0";
             }
         }
     }
     if (!empty($where_item)) {
         $where_item .= ')';
         if (!empty($where_clause)) {
             $where_clause .= empty($fid) ? ' OR' : ' AND';
         }
         $where_clause .= $where_item;
     }
     if (empty($join)) {
         $where_clause .= ')';
     }
     return $where_clause;
 }
Example #4
0
 public static function has_field($type, $form_id, $single = true)
 {
     _deprecated_function(__FUNCTION__, '1.07.05', 'FrmProFormsHelper::has_field');
     return FrmProFormsHelper::has_field($type, $form_id, $single);
 }
 public static function get_search_ids($s, $form_id)
 {
     global $wpdb, $frm_entry_meta;
     if (empty($s)) {
         return false;
     }
     preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
     $search_terms = array_map('trim', $matches[0]);
     $n = '%';
     //!empty($q['exact']) ? '' : '%';
     $p_search = $search = '';
     $search_or = '';
     $e_ids = array();
     $data_field = FrmProFormsHelper::has_field('data', $form_id, false);
     foreach ((array) $search_terms as $term) {
         $term = FrmAppHelper::esc_like($term);
         $p_search .= $wpdb->prepare(" AND (({$wpdb->posts}.post_title LIKE %s) OR ({$wpdb->posts}.post_content LIKE %s))", $n . $term . $n, $n . $term . $n);
         $search .= $wpdb->prepare($search_or . 'meta_value LIKE %s', $n . $term . $n);
         $search_or = ' OR ';
         if (is_numeric($term)) {
             $e_ids[] = (int) $term;
         }
         if ($data_field) {
             $df_form_ids = array();
             //search the joined entry too
             foreach ((array) $data_field as $df) {
                 if (is_numeric($df->field_options['form_select'])) {
                     $df_form_ids[] = (int) $df->field_options['form_select'];
                 }
                 unset($df);
             }
             $data_form_ids = $wpdb->get_col("SELECT form_id FROM {$wpdb->prefix}frm_fields WHERE id in (" . implode(',', $df_form_ids) . ")");
             unset($df_form_ids);
             if ($data_form_ids) {
                 $data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ")" . $wpdb->prepare(' AND meta_value LIKE %s', '%' . $term . '%'));
                 if ($data_entry_ids) {
                     $search .= "{$search_or}meta_value in (" . implode(',', $data_entry_ids) . ")";
                 }
             }
             unset($data_form_ids);
         }
     }
     $p_ids = '';
     $matching_posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE 1=1 {$p_search}");
     if ($matching_posts) {
         $p_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}frm_items WHERE post_id in (" . implode(',', $matching_posts) . ") AND form_id=" . (int) $form_id);
         $p_ids = $p_ids ? " OR item_id in (" . implode(',', $p_ids) . ")" : '';
     }
     if (!empty($e_ids)) {
         $p_ids .= " OR item_id in (" . implode(',', $e_ids) . ")";
     }
     return $frm_entry_meta->getEntryIds("(({$search}){$p_ids}) and fi.form_id=" . (int) $form_id);
 }
Example #6
0
 /**
  * After the sub entry and parent entry are created, we can update the parent id field
  * @since 2.0
  */
 public static function update_parent_id($entry_id, $form_id)
 {
     $form_fields = FrmProFormsHelper::has_field('form', $form_id, false);
     $section_fields = FrmProFormsHelper::has_repeat_field($form_id, false);
     if (!$form_fields && !$section_fields) {
         return;
     }
     $form_fields = array_merge($section_fields, $form_fields);
     $entry = FrmEntry::getOne($entry_id, true);
     if (!$entry || $entry->form_id != $form_id) {
         return;
     }
     $sub_ids = array();
     foreach ($form_fields as $field) {
         if (!isset($entry->metas[$field->id])) {
             continue;
         }
         $ids = maybe_unserialize($entry->metas[$field->id]);
         if (!empty($ids)) {
             $sub_ids = array_merge($ids, $sub_ids);
         }
         unset($field);
     }
     if (!empty($sub_ids)) {
         $where = array('id' => $sub_ids);
         FrmDb::get_where_clause_and_values($where);
         array_unshift($where['values'], $entry_id);
         global $wpdb;
         $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_items SET parent_item_id = %d' . $where['where'], $where['values']));
     }
 }