public static function show()
 {
     FrmAppHelper::permission_check('frm_view_reports');
     remove_action('frm_form_action_reports', 'FrmStatisticsController::list_reports');
     add_filter('frm_form_stop_action_reports', '__return_true');
     global $wpdb;
     $form = false;
     if (isset($_REQUEST['form'])) {
         $form = FrmForm::getOne($_REQUEST['form']);
     }
     if (!$form) {
         require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/select.php';
         return;
     }
     $exclude_types = FrmField::no_save_fields();
     $exclude_types = array_merge($exclude_types, array('rte', 'textarea', 'file', 'grid', 'signature', 'form', 'table'));
     $fields = FrmField::getAll(array('fi.form_id' => (int) $form->id, 'fi.type not' => $exclude_types), 'field_order');
     $js = '';
     $data = array();
     $colors = '#21759B,#EF8C08,#C6C6C6';
     $data['time'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors, 'bg_color' => 'transparent'));
     $data['month'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors, 'bg_color' => 'transparent', 'width' => '100%'), 'MONTH');
     foreach ($fields as $field) {
         $this_data = self::graph_shortcode(array('id' => $field->id, 'field' => $field, 'is3d' => true, 'min' => 0, 'colors' => $colors, 'width' => 650, 'bg_color' => 'transparent'));
         if (strpos($this_data, 'frm_no_data_graph') === false) {
             $data[$field->id] = $this_data;
         }
         unset($field, $this_data);
     }
     $entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('form_id' => $form->id), 'created_at');
     // trigger the scripts to load
     global $frm_vars;
     $frm_vars['forms_loaded'][] = true;
     include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/show.php';
 }
 /**
  * check for duplicate entries created in the last minute
  * @return boolean
  */
 public static function is_duplicate($new_values, $values)
 {
     if (defined('WP_IMPORTING') && WP_IMPORTING) {
         return false;
     }
     $duplicate_entry_time = apply_filters('frm_time_to_check_duplicates', 60, $new_values);
     if (empty($duplicate_entry_time)) {
         return false;
     }
     $check_val = $new_values;
     $check_val['created_at >'] = date('Y-m-d H:i:s', strtotime($new_values['created_at']) - absint($duplicate_entry_time));
     unset($check_val['created_at'], $check_val['updated_at']);
     unset($check_val['is_draft'], $check_val['id'], $check_val['item_key']);
     if ($new_values['item_key'] == $new_values['name']) {
         unset($check_val['name']);
     }
     global $wpdb;
     $entry_exists = FrmDb::get_col($wpdb->prefix . 'frm_items', $check_val, 'id', array('order_by' => 'created_at DESC'));
     if (!$entry_exists || empty($entry_exists) || !isset($values['item_meta'])) {
         return false;
     }
     $is_duplicate = false;
     foreach ($entry_exists as $entry_exist) {
         $is_duplicate = true;
         //add more checks here to make sure it's a duplicate
         $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
         $field_metas = array();
         foreach ($metas as $meta) {
             $field_metas[$meta->field_id] = $meta->meta_value;
         }
         // If prev entry is empty and current entry is not, they are not duplicates
         $filtered_vals = array_filter($values['item_meta']);
         if (empty($field_metas) && !empty($filtered_vals)) {
             return false;
         }
         $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
         foreach ($diff as $field_id => $meta_value) {
             if (!empty($meta_value)) {
                 $is_duplicate = false;
                 continue;
             }
         }
         if ($is_duplicate) {
             break;
         }
     }
     return $is_duplicate;
 }
Exemple #3
0
 function form($form_action, $args = array())
 {
     global $wpdb;
     extract($args);
     $post_types = FrmProAppHelper::get_custom_post_types();
     if (!$post_types) {
         return;
     }
     $post_type = FrmProFormsHelper::post_type($args['values']['id']);
     $taxonomies = get_object_taxonomies($post_type);
     $action_control = $this;
     $echo = true;
     $form_id = $form->id;
     $display = false;
     $displays = array();
     $display_ids = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID');
     if ($display_ids) {
         $query_args = array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => array('publish', 'private'), 'p.ID' => $display_ids);
         $displays = FrmDb::get_results($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', $query_args, 'p.ID, p.post_title', array('order_by' => 'p.post_title ASC'));
         if (isset($form_action->post_content['display_id'])) {
             // get view from settings
             if (is_numeric($form_action->post_content['display_id'])) {
                 $display = FrmProDisplay::getOne($form_action->post_content['display_id'], false, true);
             }
         } else {
             if (!is_numeric($form_action->post_content['post_content']) && !empty($display_ids)) {
                 // get auto view
                 $display = FrmProDisplay::get_form_custom_display($form_id);
                 if ($display) {
                     $display = FrmProDisplaysHelper::setup_edit_vars($display, true);
                 }
             }
         }
     }
     // Get array of all custom fields
     $custom_fields = array();
     if (isset($form_action->post_content['post_custom_fields'])) {
         foreach ($form_action->post_content['post_custom_fields'] as $custom_field_opts) {
             if (isset($custom_field_opts['meta_name'])) {
                 $custom_fields[] = $custom_field_opts['meta_name'];
             }
             unset($custom_field_opts);
         }
     }
     unset($display_ids);
     include dirname(__FILE__) . '/post_options.php';
 }
 public static function formidable_shortcode_atts($atts, $all_atts)
 {
     global $frm_vars, $wpdb;
     // reset globals
     $frm_vars['readonly'] = $atts['readonly'];
     $frm_vars['editing_entry'] = false;
     $frm_vars['show_fields'] = array();
     $frm_vars['editing_entry'] = false;
     if (!is_array($atts['fields'])) {
         $frm_vars['show_fields'] = explode(',', $atts['fields']);
     }
     if (!empty($atts['exclude_fields'])) {
         if (!is_array($atts['exclude_fields'])) {
             $atts['exclude_fields'] = explode(',', $atts['exclude_fields']);
         }
         $query = array('form_id' => (int) $atts['id'], 'id NOT' => $atts['exclude_fields'], 'field_key NOT' => $atts['exclude_fields']);
         $frm_vars['show_fields'] = FrmDb::get_col($wpdb->prefix . 'frm_fields', $query);
     }
     if ($atts['entry_id'] && $atts['entry_id'] == 'last') {
         $user_ID = get_current_user_id();
         if ($user_ID) {
             $frm_vars['editing_entry'] = FrmDb::get_var($wpdb->prefix . 'frm_items', array('form_id' => $atts['id'], 'user_id' => $user_ID), 'id', array('order_by' => 'created_at DESC'));
         }
     } else {
         if ($atts['entry_id']) {
             $frm_vars['editing_entry'] = $atts['entry_id'];
         }
     }
     foreach ($atts as $unset => $val) {
         if (is_array($all_atts) && isset($all_atts[$unset])) {
             unset($all_atts[$unset]);
         }
         unset($unset, $val);
     }
     if (is_array($all_atts)) {
         foreach ($all_atts as $att => $val) {
             $_GET[$att] = urlencode($val);
             unset($att, $val);
         }
     }
 }
 public static function get_field_matches($args)
 {
     extract($args);
     $f = $orig_f;
     $where_is = '=';
     //If using <, >, <=, >=, or != TODO: %, !%.
     //Note: $f will be numeric if using <, >, <=, >=, != OR if using x=val, but the code in the if/else statement will not actually do anything to x=val.
     if (is_numeric($f)) {
         //Note: $f will count up for certain atts
         $orig_val = $val;
         $lpos = strpos($val, '<');
         $gpos = strpos($val, '>');
         $not_pos = strpos($val, '!=');
         $dash_pos = strpos($val, '-');
         if ($not_pos !== false) {
             //If string contains !=
             //If entry IDs have not been set by a previous $atts
             if (empty($entry_ids) && $after_where == 0) {
                 $query = array('form_id' => $field->form_id);
                 //By default, don't get drafts
                 if ($drafts != 'both') {
                     $query['is_draft'] = $drafts;
                 }
                 $entry_ids = FrmDb::get_col('frm_items', $query);
                 unset($query);
             }
             $where_is = '!=';
             $str = explode($where_is, $orig_val);
             $f = $str[0];
             $val = $str[1];
         } else {
             if ($lpos !== false || $gpos !== false) {
                 //If string contains greater than or less than
                 $where_is = $gpos !== false && $lpos !== false && $lpos > $gpos || $lpos === false ? '>' : '<';
                 $str = explode($where_is, $orig_val);
                 if (count($str) == 2) {
                     $f = $str[0];
                     $val = $str[1];
                 } else {
                     if (count($str) == 3) {
                         //3 parts assumes a structure like '-1 month'<255<'1 month'
                         $val = str_replace($str[0] . $where_is, '', $orig_val);
                         $entry_ids = self::get_field_matches(compact('entry_ids', 'orig_f', 'val', 'id', 'atts', 'field', 'form_posts', 'after_where', 'drafts'));
                         $after_where = true;
                         $f = $str[1];
                         $val = $str[0];
                         $where_is = $where_is == '<' ? '>' : '<';
                     }
                 }
                 if (strpos($val, '=') === 0) {
                     $where_is .= '=';
                     $val = substr($val, 1);
                 }
                 // If field key contains a dash, then it won't be put in as $f automatically (WordPress quirk maybe?)
                 // Use $f < 5 to decrease the likelihood of this section being used when $f is a field ID (like x=val)
             } else {
                 if ($dash_pos !== false && strpos($val, '=') !== false && $f < 5) {
                     $str = explode($where_is, $orig_val);
                     $f = $str[0];
                     $val = $str[1];
                 }
             }
         }
     }
     // If this function has looped through at least once, and there aren't any entry IDs
     if ($after_where && !$entry_ids) {
         return array();
     }
     //If using field key
     if (!is_numeric($f)) {
         if (in_array($f, array('created_at', 'updated_at'))) {
             global $wpdb;
             $val = FrmAppHelper::replace_quotes($val);
             $val = str_replace(array('"', "'"), "", $val);
             $val = date('Y-m-d', strtotime($val));
             $query = array('form_id' => $field->form_id, $f . FrmDb::append_where_is($where_is) => $val);
             // Entry IDs may be set even if after_where isn't true
             if ($entry_ids) {
                 $query['id'] = $entry_ids;
             }
             $entry_ids = FrmDb::get_col('frm_items', $query);
             return $entry_ids;
         } else {
             //check for field keys
             $this_field = FrmField::getOne($f);
             if ($this_field) {
                 $f = $this_field->id;
             } else {
                 //If no field ID
                 return $entry_ids;
             }
             unset($this_field);
         }
     }
     unset($orig_f);
     //Prepare val
     $val = FrmAppHelper::replace_quotes($val);
     $val = trim(trim($val, "'"), '"');
     $where_atts = apply_filters('frm_stats_where', array('where_is' => $where_is, 'where_val' => $val), array('id' => $id, 'atts' => $atts));
     $val = $where_atts['where_val'];
     $where_is = $where_atts['where_is'];
     unset($where_atts);
     $entry_ids = FrmProAppHelper::filter_where($entry_ids, array('where_opt' => $f, 'where_is' => $where_is, 'where_val' => $val, 'form_id' => $field->form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'drafts' => $drafts));
     unset($f);
     unset($val);
     return $entry_ids;
 }
 public static function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array())
 {
     if (post_password_required($display)) {
         return get_the_password_form($display);
     }
     add_action('frm_load_view_hooks', 'FrmProDisplaysController::trigger_load_view_hooks');
     FrmAppHelper::trigger_hook_load('view', $display);
     global $frm_vars, $post;
     $frm_vars['forms_loaded'][] = true;
     if (!isset($display->frm_empty_msg)) {
         $display = FrmProDisplaysHelper::setup_edit_vars($display, false);
     }
     if (!isset($display->frm_form_id) || empty($display->frm_form_id)) {
         return $content;
     }
     //for backwards compatability
     $display->id = $display->frm_old_id;
     $display->display_key = $display->post_name;
     $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '', 'drafts' => false, 'auto_id' => '');
     $extra_atts = wp_parse_args($extra_atts, $defaults);
     extract($extra_atts);
     //if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
     //    self::parse_pretty_entry_url();
     if ($display->frm_show_count == 'one' && is_numeric($display->frm_entry_id) && $display->frm_entry_id > 0 && !$entry_id) {
         $entry_id = $display->frm_entry_id;
     }
     $entry = false;
     $show = 'all';
     // Don't filter with $entry_ids by default because the query gets too long.
     // Only filter with $entry_ids when showing one entry
     $use_ids = false;
     global $wpdb;
     $where = array('it.form_id' => $display->frm_form_id);
     if (in_array($display->frm_show_count, array('dynamic', 'calendar', 'one'))) {
         $one_param = FrmAppHelper::simple_get('entry', 'sanitize_title', $extra_atts['auto_id']);
         $get_param = FrmAppHelper::simple_get($display->frm_param, 'sanitize_title', $display->frm_show_count == 'one' ? $one_param : $extra_atts['auto_id']);
         unset($one_param);
         if ($get_param) {
             if (($display->frm_type == 'id' || $display->frm_show_count == 'one') && is_numeric($get_param)) {
                 $where['it.id'] = $get_param;
             } else {
                 $where['it.item_key'] = $get_param;
             }
             $entry = FrmEntry::getAll($where, '', 1, 0);
             if ($entry) {
                 $entry = reset($entry);
             }
             if ($entry && $entry->post_id) {
                 //redirect to single post page if this entry is a post
                 if (in_the_loop() && $display->frm_show_count != 'one' && !is_single($entry->post_id) && $post->ID != $entry->post_id) {
                     $this_post = get_post($entry->post_id);
                     if (in_array($this_post->post_status, array('publish', 'private'))) {
                         die(FrmAppHelper::js_redirect(get_permalink($entry->post_id)));
                     }
                 }
             }
         }
         unset($get_param);
     }
     if ($entry && in_array($display->frm_show_count, array('dynamic', 'calendar'))) {
         $new_content = $display->frm_dyncontent;
         $show = 'one';
     } else {
         $new_content = $display->post_content;
     }
     $show = $display->frm_show_count == 'one' ? 'one' : $show;
     $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->frm_form_id);
     //don't let page size and limit override single entry displays
     if ($display->frm_show_count == 'one') {
         $display->frm_page_size = $display->frm_limit = '';
     }
     //don't keep current content if post type is frm_display
     if ($post && $post->post_type == self::$post_type) {
         $display->frm_insert_loc = '';
     }
     $pagination = '';
     $form_query = array('form_id' => $display->frm_form_id, 'post_id >' => 1);
     if ($extra_atts['drafts'] != 'both') {
         $is_draft = empty($extra_atts['drafts']) ? 0 : 1;
         $form_query['is_draft'] = $is_draft;
     } else {
         $is_draft = 'both';
     }
     if ($entry && $entry->form_id == $display->frm_form_id) {
         $form_query['id'] = $entry->id;
     }
     $form_posts = FrmDb::get_results('frm_items', $form_query, 'id, post_id');
     unset($form_query);
     $getting_entries = !$entry || !$post || empty($extra_atts['auto_id']);
     $check_filter_opts = !empty($display->frm_where) && $getting_entries;
     if ($entry && $entry->form_id == $display->frm_form_id) {
         $entry_ids = array($entry->id);
         // Filter by this entry ID to make query faster
         $use_ids = true;
     } else {
         if ($check_filter_opts || isset($_GET['frm_search'])) {
             //Only get $entry_ids if filters are set or if frm_search parameter is set
             $entry_query = array('form_id' => $display->frm_form_id);
             if ($extra_atts['drafts'] != 'both') {
                 $entry_query['is_draft'] = $is_draft;
             }
             $entry_ids = FrmDb::get_col('frm_items', $entry_query);
             unset($entry_query);
         }
     }
     $empty_msg = isset($display->frm_empty_msg) && !empty($display->frm_empty_msg) ? '<div class="frm_no_entries">' . FrmProFieldsHelper::get_default_value($display->frm_empty_msg, false) . '</div>' : '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $empty_msg = $message . $empty_msg;
     }
     $after_where = false;
     $user_id = $extra_atts['user_id'];
     if (!empty($user_id)) {
         $user_id = FrmAppHelper::get_user_id_param($user_id);
         $uid_used = false;
     }
     self::add_group_by_filter($display, $getting_entries);
     unset($getting_entries);
     if ($check_filter_opts) {
         $display->frm_where = apply_filters('frm_custom_where_opt', $display->frm_where, array('display' => $display, 'entry' => $entry));
         $continue = false;
         foreach ($display->frm_where as $where_key => $where_opt) {
             $where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : '';
             if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                 //if this param doesn't exist, then don't include it
                 if ($where_val == '') {
                     if (!$after_where) {
                         $continue = true;
                     }
                     continue;
                 }
             } else {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
             }
             $continue = false;
             if ($where_val == 'current_user') {
                 if ($user_id && is_numeric($user_id)) {
                     $where_val = $user_id;
                     $uid_used = true;
                 } else {
                     $where_val = get_current_user_id();
                 }
             } else {
                 if (!is_array($where_val)) {
                     $where_val = do_shortcode($where_val);
                 }
             }
             if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) {
                 $where_val = explode(',', $where_val);
                 $where_val = array_filter($where_val);
             }
             if (is_array($where_val) && !empty($where_val)) {
                 if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) {
                     $display->frm_where_is[$where_key] = ' in ';
                 } else {
                     $display->frm_where_is[$where_key] = 'not in';
                 }
             }
             if (is_numeric($where_opt)) {
                 $filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft, 'use_ids' => $use_ids));
                 $entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts);
                 unset($filter_opts);
                 $after_where = true;
                 $continue = false;
                 if (empty($entry_ids)) {
                     break;
                 }
             } else {
                 if (in_array($where_opt, array('created_at', 'updated_at'))) {
                     if ($where_val == 'NOW') {
                         $where_val = current_time('mysql', 1);
                     }
                     if (strpos($display->frm_where_is[$where_key], 'LIKE') === false) {
                         $where_val = date('Y-m-d H:i:s', strtotime($where_val));
                         // If using less than or equal to, set the time to the end of the day
                         if ($display->frm_where_is[$where_key] == '<=') {
                             $where_val = str_replace('00:00:00', '23:59:59', $where_val);
                         }
                         // Convert date to GMT since that is the format in the DB
                         $where_val = get_gmt_from_date($where_val);
                     }
                     $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val;
                     $continue = true;
                 } else {
                     if (in_array($where_opt, array('id', 'item_key', 'post_id', 'ip'))) {
                         $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val;
                         // Update entry IDs if the entry ID filter is set to "equal to"
                         if ($where_opt == 'id' && in_array($display->frm_where_is[$where_key], array('=', ' in '))) {
                             $entry_ids = $where_val;
                         }
                         $continue = true;
                     }
                 }
             }
         }
         if (!$continue && empty($entry_ids)) {
             if ($display->frm_insert_loc == 'after') {
                 $content .= $empty_msg;
             } else {
                 if ($display->frm_insert_loc == 'before') {
                     $content = $empty_msg . $content;
                 } else {
                     if ($filter) {
                         $empty_msg = apply_filters('the_content', $empty_msg);
                     }
                     if ($post && $post->post_type == self::$post_type && in_the_loop()) {
                         $content = '';
                     }
                     $content .= $empty_msg;
                 }
             }
             return $content;
         }
     }
     if ($user_id && is_numeric($user_id) && !$uid_used) {
         $where['it.user_id'] = $user_id;
     }
     $s = FrmAppHelper::get_param('frm_search', false, 'get', 'sanitize_text_field');
     if ($s) {
         $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->frm_form_id, array('is_draft' => $extra_atts['drafts']));
         if ($after_where && isset($entry_ids) && !empty($entry_ids)) {
             $entry_ids = array_intersect($new_ids, $entry_ids);
         } else {
             $entry_ids = $new_ids;
         }
         if (empty($entry_ids)) {
             if ($post->post_type == self::$post_type && in_the_loop()) {
                 $content = '';
             }
             return $content . ' ' . $empty_msg;
         }
     }
     if (isset($entry_ids) && !empty($entry_ids)) {
         $where['it.id'] = $entry_ids;
     }
     self::maybe_add_entry_query($entry_id, $where);
     if ($extra_atts['drafts'] != 'both') {
         $where['is_draft'] = $is_draft;
     }
     unset($is_draft);
     if ($show == 'one') {
         $limit = ' LIMIT 1';
     } else {
         self::maybe_add_cat_query($where);
     }
     if (!empty($limit) && is_numeric($limit)) {
         $display->frm_limit = (int) $limit;
     }
     if (is_numeric($display->frm_limit)) {
         $num_limit = (int) $display->frm_limit;
         $limit = ' LIMIT ' . $display->frm_limit;
     }
     if (!empty($order_by)) {
         $display->frm_order_by = explode(',', $order_by);
     }
     if (!empty($order)) {
         $display->frm_order = explode(',', $order);
         if (!isset($display->frm_order_by[0])) {
             $display->frm_order_by = FrmProAppHelper::reset_keys($display->frm_order_by);
         }
     }
     unset($order);
     if (!empty($page_size) && is_numeric($page_size)) {
         $display->frm_page_size = (int) $page_size;
     }
     // if limit is lower than page size, ignore the page size
     if (isset($num_limit) && $display->frm_page_size > $num_limit) {
         $display->frm_page_size = '';
     }
     $display_page_query = array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'posts' => $form_posts, 'display' => $display);
     if (isset($display->frm_page_size) && is_numeric($display->frm_page_size)) {
         $page_param = $_GET && isset($_GET['frm-page-' . $display->ID]) ? 'frm-page-' . $display->ID : 'frm-page';
         $current_page = FrmAppHelper::simple_get($page_param, 'absint', 1);
         $record_count = FrmEntry::getRecordCount($where);
         if (isset($num_limit) && $record_count > (int) $num_limit) {
             $record_count = (int) $num_limit;
         }
         $page_count = FrmEntry::getPageCount($display->frm_page_size, $record_count);
         $entry_ids = FrmProEntry::get_view_page($current_page, $display->frm_page_size, $where, $display_page_query);
         $page_last_record = FrmAppHelper::get_last_record_num($record_count, $current_page, $display->frm_page_size);
         $page_first_record = FrmAppHelper::get_first_record_num($record_count, $current_page, $display->frm_page_size);
         if ($page_count > 1) {
             $page_param = 'frm-page-' . $display->ID;
             $pagination = FrmAppHelper::get_file_contents(FrmAppHelper::plugin_path() . '/pro/classes/views/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record', 'page_param'));
         }
     } else {
         $display_page_query['limit'] = $limit;
         //Get all entries
         $entry_ids = FrmProEntry::get_view_results($where, $display_page_query);
     }
     $total_count = count($entry_ids);
     $sc_atts = array();
     if (isset($record_count)) {
         $sc_atts['record_count'] = $record_count;
     } else {
         $sc_atts['record_count'] = $total_count;
     }
     $display_content = '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $display_content .= $message;
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_before_content) ? $display->frm_before_content : '';
     }
     add_filter('frm_before_display_content', 'FrmProDisplaysController::calendar_header', 10, 3);
     add_filter('frm_before_display_content', 'FrmProDisplaysController::filter_after_content', 10, 4);
     $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     add_filter('frm_display_entries_content', 'FrmProDisplaysController::build_calendar', 10, 5);
     $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entry_ids, $shortcodes, $display, $show, $sc_atts);
     if ($filtered_content != $new_content) {
         $display_content .= $filtered_content;
     } else {
         $odd = 'odd';
         $count = 0;
         if (!empty($entry_ids)) {
             $loop_entry_ids = $entry_ids;
             while ($next_set = array_splice($loop_entry_ids, 0, 30)) {
                 $entries = FrmEntry::getAll(array('id' => $next_set), ' ORDER BY FIELD(it.id,' . implode(',', $next_set) . ')', '', true, false);
                 foreach ($entries as $entry) {
                     $count++;
                     //TODO: use the count with conditionals
                     $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd, array('count' => $count, 'total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'pagination' => $pagination, 'entry_ids' => $entry_ids));
                     $odd = $odd == 'odd' ? 'even' : 'odd';
                     unset($entry);
                 }
                 unset($entries);
             }
             unset($loop_entry_ids, $count);
         } else {
             if ($post && $post->post_type == self::$post_type && in_the_loop()) {
                 $display_content = '';
             }
             if (!isset($message) || FrmAppHelper::get_param('frm_action', '', 'get', 'sanitize_title') != 'destroy') {
                 $display_content .= $empty_msg;
             }
         }
     }
     if (isset($message)) {
         unset($message);
     }
     if ($show == 'all' && isset($display->frm_after_content)) {
         add_filter('frm_after_content', 'FrmProDisplaysController::filter_after_content', 10, 4);
         $display_content .= apply_filters('frm_after_content', $display->frm_after_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     }
     if (!isset($sc_atts)) {
         $sc_atts = array('record_count' => 0);
     }
     if (!isset($total_count)) {
         $total_count = 0;
     }
     $pagination = self::calendar_footer($pagination, $display, $show);
     $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     unset($sc_atts);
     $display_content = FrmProFieldsHelper::get_default_value($display_content, false, true, false);
     if ($display->frm_insert_loc == 'after') {
         $content .= $display_content;
     } else {
         if ($display->frm_insert_loc == 'before') {
             $content = $display_content . $content;
         } else {
             if ($filter) {
                 $display_content = apply_filters('the_content', $display_content);
             }
             $content = $display_content;
         }
     }
     // load the styling for css classes and pagination
     FrmStylesController::enqueue_style();
     return $content;
 }
 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 function destroy($form_id = false, $type = 'default')
 {
     global $wpdb;
     $this->form_id = $form_id;
     $query = array('post_type' => FrmFormActionsController::$action_post_type);
     if ($form_id) {
         $query['menu_order'] = $form_id;
     }
     if ('all' != $type) {
         $query['post_excerpt'] = $this->id_base;
     }
     $post_ids = FrmDb::get_col($wpdb->posts, $query, 'ID');
     foreach ($post_ids as $id) {
         wp_delete_post($id);
     }
     self::clear_cache();
 }
 /**
  * Export to CSV
  * @since 2.0.19
  */
 public static function csv($form_id = false, $search = '', $fid = '')
 {
     FrmAppHelper::permission_check('frm_view_entries');
     if (!$form_id) {
         $form_id = FrmAppHelper::get_param('form', '', 'get', 'sanitize_text_field');
         $search = FrmAppHelper::get_param(isset($_REQUEST['s']) ? 's' : 'search', '', 'get', 'sanitize_text_field');
         $fid = FrmAppHelper::get_param('fid', '', 'get', 'sanitize_text_field');
     }
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
         //Remove time limit to execute this function
         $mem_limit = str_replace('M', '', ini_get('memory_limit'));
         if ((int) $mem_limit < 256) {
             ini_set('memory_limit', '256M');
         }
     }
     global $wpdb;
     $form = FrmForm::getOne($form_id);
     $form_id = $form->id;
     $form_cols = self::get_fields_for_csv_export($form_id, $form);
     $item_id = FrmAppHelper::get_param('item_id', 0, 'get', 'sanitize_text_field');
     if (!empty($item_id)) {
         $item_id = explode(',', $item_id);
     }
     $query = array('form_id' => $form_id);
     if ($item_id) {
         $query['id'] = $item_id;
     }
     /**
      * Allows the query to be changed for fetching the entry ids to include in the export
      *
      * $query is the array of options to be filtered. It includes form_id, and maybe id (array of entry ids),
      * and the search query. This should return an array, but it can be handled as a string as well.
      */
     $query = apply_filters('frm_csv_where', $query, compact('form_id', 'search', 'fid', 'item_id'));
     $entry_ids = FrmDb::get_col($wpdb->prefix . 'frm_items it', $query);
     unset($query);
     if (empty($entry_ids)) {
         esc_html_e('There are no entries for that form.', 'formidable');
     } else {
         FrmCSVExportHelper::generate_csv(compact('form', 'entry_ids', 'form_cols'));
     }
     wp_die();
 }
 public static function get_file_id($value)
 {
     global $wpdb;
     if (!is_array($value)) {
         $value = explode(',', $value);
     }
     foreach ((array) $value as $pos => $m) {
         $m = trim($m);
         if (empty($m)) {
             continue;
         }
         if (!is_numeric($m)) {
             //get the ID from the URL if on this site
             $m = FrmDb::get_col($wpdb->posts, array('guid' => $m), 'ID');
         }
         if (!is_numeric($m)) {
             unset($value[$pos]);
         } else {
             $value[$pos] = $m;
         }
         unset($pos);
         unset($m);
     }
     return $value;
 }
Exemple #11
0
        ?>
: <?php 
        echo FrmProFieldsHelper::get_field_stats($field->id, 'average');
        ?>
</p>
            <p><?php 
        _e('Median', 'formidable');
        ?>
: <?php 
        echo FrmProFieldsHelper::get_field_stats($field->id, 'median');
        ?>
</p>
            <?php 
    } else {
        if ($field->type == 'user_id') {
            $user_ids = FrmDb::get_col($wpdb->users, array(), 'ID', 'display_name ASC');
            $submitted_user_ids = FrmEntryMeta::get_entry_metas_for_field($field->id, '', '', array('unique' => true));
            $not_submitted = array_diff($user_ids, $submitted_user_ids);
            ?>
            <p><?php 
            _e('Percent of users submitted', 'formidable');
            ?>
: <?php 
            echo round(count($submitted_user_ids) / count($user_ids) * 100, 2);
            ?>
%</p>
			<form action="<?php 
            echo esc_url(admin_url('user-edit.php'));
            ?>
" method="get">
            <p><?php 
Exemple #12
0
 public static function destroy_post($entry_id, $entry = false)
 {
     global $wpdb;
     if ($entry) {
         $post_id = $entry->post_id;
     } else {
         $post_id = FrmDb::get_var($wpdb->prefix . 'frm_items', array('id' => $entry_id), 'post_id');
     }
     // delete child entries
     $child_entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('parent_item_id' => $entry_id));
     foreach ($child_entries as $child_entry) {
         FrmEntry::destroy($child_entry);
     }
     // Remove hook to make things consistent
     // Due to a WP bug, this hook won't be used for parent entry when there are child entries
     remove_action('frm_before_destroy_entry', 'FrmProFormActionsController::trigger_delete_actions', 20, 2);
     // Trigger delete actions for parent entry
     FrmProFormActionsController::trigger_delete_actions($entry_id, $entry);
     if ($post_id) {
         wp_delete_post($post_id);
     }
 }
 /**
  * @covers FrmProFieldsHelper::move_entries_to_parent_form
  */
 function _check_if_child_entries_moved($args)
 {
     global $wpdb;
     // First check if old frm_items are gone from child form
     $items = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "frm_items WHERE form_id=" . $args['form_id']);
     $this->assertEmpty($items, 'Rows in wp_frm_items were not deleted when switching from repeating to non-repeating.');
     // Check if frm_item_metas were moved to parent entries
     $new_child_metas = FrmDb::get_col($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items it ON it.id=m.item_id', array('field_id' => $args['children']), 'it.form_id', array('order_by' => 'it.created_at ASC'));
     $this->assertNotEmpty($new_child_metas, 'No entries to check (when switching divider to non-repeatable).');
     foreach ($new_child_metas as $new_form_id) {
         $this->assertEquals($args['parent_form_id'], $new_form_id, 'Child entries are not moved to parent form (' . $args['parent_form_id'] . ') when a divider is switched from repeating to non-repeating.');
     }
     // Make sure frm_item_metas for repeating section are cleaned up
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertEmpty($rep_meta_values, 'frm_item_metas for repeating section were not deleted when switching to non-repeatable.');
     self::_check_if_child_form_deleted($args['form_id']);
 }
 public static function meta_through_join($hide_field, $selected_field, $observed_field_val, $this_field = false, &$metas)
 {
     if (is_array($observed_field_val)) {
         $observed_field_val = array_filter($observed_field_val);
     }
     if (empty($observed_field_val) || !is_numeric($observed_field_val) && !is_array($observed_field_val)) {
         return;
     }
     $observed_info = FrmField::getOne($hide_field);
     if (!$selected_field || !$observed_info) {
         return;
     }
     $form_id = FrmProFieldsHelper::get_parent_form_id($selected_field);
     $join_fields = FrmField::get_all_types_in_form($form_id, 'data');
     if (empty($join_fields)) {
         return;
     }
     foreach ($join_fields as $jf) {
         if (isset($jf->field_options['form_select']) && isset($observed_info->field_options['form_select']) && $jf->field_options['form_select'] == $observed_info->field_options['form_select']) {
             $join_field = $jf->id;
         }
     }
     if (!isset($join_field)) {
         return;
     }
     $observed_field_val = array_filter((array) $observed_field_val);
     $query = array('field_id' => (int) $join_field);
     $sub_query = array('it.meta_value' => $observed_field_val);
     foreach ($observed_field_val as $obs_val) {
         $sub_query['or'] = 1;
         $sub_query['it.meta_value LIKE'] = ':"' . $obs_val . '"';
     }
     $query[] = $sub_query;
     $user_id = '';
     if ($this_field && isset($this_field->field_options['restrict']) && $this_field->field_options['restrict']) {
         $query['e.user_id'] = get_current_user_id();
     }
     // the ids of all the entries that have been selected in the linked form
     $entry_ids = FrmEntryMeta::getEntryIds($query);
     if (!empty($entry_ids)) {
         if ($form_id != $selected_field->form_id) {
             // this is a child field so we need to get the child entries
             global $wpdb;
             $entry_ids = FrmDb::get_col($wpdb->prefix . 'frm_items', array('parent_item_id' => $entry_ids));
         }
         if (!empty($entry_ids)) {
             $metas = FrmEntryMeta::getAll(array('item_id' => $entry_ids, 'field_id' => $selected_field->id), ' ORDER BY meta_value');
         }
     }
 }
 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;
         }
     }
 }
 /**
  * if there are posts linked to entries for this form
  */
 private static function prepare_post_filter($args, $where_field, &$new_ids)
 {
     if (empty($args['form_posts'])) {
         // there are not posts related to this view
         return;
     }
     if (!isset($where_field->field_options['post_field']) || !in_array($where_field->field_options['post_field'], array('post_category', 'post_custom', 'post_status', 'post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date'))) {
         // this is not a post field
         return;
     }
     $post_ids = array();
     foreach ($args['form_posts'] as $form_post) {
         $post_ids[$form_post->post_id] = $form_post->id;
         if (!in_array($form_post->id, $new_ids)) {
             $new_ids[] = $form_post->id;
         }
     }
     if (empty($post_ids)) {
         return;
     }
     global $wpdb;
     $filter_args = array();
     if ($where_field->field_options['post_field'] == 'post_category') {
         //check categories
         $args['temp_where_is'] = FrmDb::append_where_is(str_replace(array('!', 'not '), '', $args['where_is']));
         $t_where = array('or' => 1, 't.term_id ' . $args['temp_where_is'] => $args['where_val'], 't.slug ' . $args['temp_where_is'] => $args['where_val'], 't.name ' . $args['temp_where_is'] => $args['where_val']);
         unset($args['temp_where_is']);
         $query = array('tt.taxonomy' => $where_field->field_options['taxonomy']);
         $query[] = $t_where;
         self::add_group_by($filter_args, $args, 'tr.object_id');
         $add_posts = FrmDb::get_col($wpdb->terms . ' AS t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tt.term_id = t.term_id INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id', $query, 'tr.object_id', $filter_args);
         $add_posts = array_intersect($add_posts, array_keys($post_ids));
         if (in_array($args['where_is'], array('!=', 'not LIKE'))) {
             $remove_posts = $add_posts;
             $add_posts = false;
         } else {
             if (empty($add_posts)) {
                 $new_ids = array();
                 return;
             }
         }
     } else {
         $query = array();
         if ($where_field->field_options['post_field'] == 'post_custom' && $where_field->field_options['custom_field'] != '') {
             //check custom fields
             $get_field = 'post_id';
             $get_table = $wpdb->postmeta;
             $query['meta_key'] = $where_field->field_options['custom_field'];
             $query_key = 'meta_value';
         } else {
             //if field is post field
             $get_field = 'ID';
             $get_table = $wpdb->posts;
             $query_key = sanitize_title($where_field->field_options['post_field']);
         }
         self::add_group_by($filter_args, $args, $query_key);
         $query_key .= (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : ' ') . FrmDb::append_where_is($args['where_is']);
         $query[$query_key] = $args['where_val'];
         $add_posts = FrmDb::get_col($get_table, $query, $get_field, $filter_args);
         $add_posts = array_intersect($add_posts, array_keys($post_ids));
     }
     if ($add_posts && !empty($add_posts)) {
         $new_ids = array();
         foreach ($add_posts as $add_post) {
             if (!in_array($post_ids[$add_post], $new_ids)) {
                 $new_ids[] = $post_ids[$add_post];
             }
         }
     }
     if (isset($remove_posts)) {
         if (!empty($remove_posts)) {
             foreach ($remove_posts as $remove_post) {
                 $key = array_search($post_ids[$remove_post], $new_ids);
                 if ($key && $new_ids[$key] == $post_ids[$remove_post]) {
                     unset($new_ids[$key]);
                 }
                 unset($key);
             }
         }
     } else {
         if (!$add_posts) {
             $new_ids = array();
         }
     }
 }
Exemple #17
0
 public static function get_display_ids_by_form($form_id)
 {
     global $wpdb;
     return FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID');
 }
 static function generate_xml($type, $xml_args)
 {
     // Code copied from FrmXMLController::generate_xml
     global $wpdb;
     $type = (array) $type;
     if (in_array('items', $type) && !in_array('forms', $type)) {
         // make sure the form is included if there are entries
         $type[] = 'forms';
     }
     if (in_array('forms', $type)) {
         // include actions with forms
         $type[] = 'actions';
     }
     $tables = array('items' => $wpdb->prefix . 'frm_items', 'forms' => $wpdb->prefix . 'frm_forms', 'posts' => $wpdb->posts, 'styles' => $wpdb->posts, 'actions' => $wpdb->posts);
     $defaults = array('ids' => false);
     $args = wp_parse_args($xml_args, $defaults);
     //make sure ids are numeric
     if (is_array($args['ids']) && !empty($args['ids'])) {
         $args['ids'] = array_filter($args['ids'], 'is_numeric');
     }
     $records = array();
     foreach ($type as $tb_type) {
         $where = array();
         $join = '';
         $table = $tables[$tb_type];
         $select = $table . '.id';
         $query_vars = array();
         switch ($tb_type) {
             case 'forms':
                 //add forms
                 if ($args['ids']) {
                     $where[] = array('or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids']);
                 } else {
                     $where[$table . '.status !'] = 'draft';
                 }
                 break;
             case 'actions':
                 $select = $table . '.ID';
                 $where['post_type'] = FrmFormActionsController::$action_post_type;
                 if (!empty($args['ids'])) {
                     $where['menu_order'] = $args['ids'];
                 }
                 break;
             case 'items':
                 //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
                 if ($args['ids']) {
                     $where[$table . '.form_id'] = $args['ids'];
                 }
                 break;
             case 'styles':
                 // Loop through all exported forms and get their selected style IDs
                 $form_ids = $args['ids'];
                 $style_ids = array();
                 foreach ($form_ids as $form_id) {
                     $form_data = FrmForm::getOne($form_id);
                     // For forms that have not been updated while running 2.0, check if custom_style is set
                     if (isset($form_data->options['custom_style'])) {
                         $style_ids[] = $form_data->options['custom_style'];
                     }
                     unset($form_id, $form_data);
                 }
                 $select = $table . '.ID';
                 $where['post_type'] = 'frm_styles';
                 // Only export selected styles
                 if (!empty($style_ids)) {
                     $where['ID'] = $style_ids;
                 }
                 break;
             default:
                 $select = $table . '.ID';
                 $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
                 $where['pm.meta_key'] = 'frm_form_id';
                 if (empty($args['ids'])) {
                     $where['pm.meta_value >'] = 1;
                 } else {
                     $where['pm.meta_value'] = $args['ids'];
                 }
                 break;
         }
         $records[$tb_type] = FrmDb::get_col($table . $join, $where, $select);
         unset($tb_type);
     }
     $xml_header = '<?xml version="1.0" encoding="' . esc_attr(get_bloginfo('charset')) . "\" ?>\n";
     ob_start();
     include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
     $xml_body = ob_get_contents();
     ob_end_clean();
     $xml = $xml_header . $xml_body;
     $cwd = getcwd();
     $path = "{$cwd}" . '/' . "temp.xml";
     @chmod($path, 0755);
     $fw = fopen($path, "w");
     fputs($fw, $xml, strlen($xml));
     fclose($fw);
     return $path;
 }
 /**
  * Get metas for post or non-post fields
  *
  * @since 2.0
  */
 public static function get_all_metas_for_field($field, $args = array())
 {
     global $wpdb;
     $query = array();
     if (!FrmField::is_option_true($field, 'post_field')) {
         // If field is not a post field
         $get_field = 'em.meta_value';
         $get_table = $wpdb->prefix . 'frm_item_metas em INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
         $query['em.field_id'] = $field->id;
         $query['e.is_draft'] = 0;
     } else {
         if ($field->field_options['post_field'] == 'post_custom') {
             // If field is a custom field
             $get_field = 'pm.meta_value';
             $get_table = $wpdb->postmeta . ' pm INNER JOIN ' . $wpdb->prefix . 'frm_items e ON pm.post_id=e.post_id';
             $query['pm.meta_key'] = $field->field_options['custom_field'];
             // Make sure to only get post metas that are linked to this form
             $query['e.form_id'] = $field->form_id;
         } else {
             if ($field->field_options['post_field'] != 'post_category') {
                 // If field is a non-category post field
                 $get_field = 'p.' . sanitize_title($field->field_options['post_field']);
                 $get_table = $wpdb->posts . ' p INNER JOIN ' . $wpdb->prefix . 'frm_items e ON p.ID=e.post_id';
                 // Make sure to only get post metas that are linked to this form
                 $query['e.form_id'] = $field->form_id;
             } else {
                 // If field is a category field
                 //TODO: Make this work
                 return array();
                 //$field_options = FrmProFieldsHelper::get_category_options( $field );
             }
         }
     }
     // Add queries for additional args
     self::add_meta_query($query, $args);
     // Get the metas
     $metas = FrmDb::get_col($get_table, $query, $get_field);
     // Maybe unserialize
     foreach ($metas as $k => $v) {
         $metas[$k] = maybe_unserialize($v);
         unset($k, $v);
     }
     // Strip slashes
     $metas = stripslashes_deep($metas);
     return $metas;
 }
 public static function destroy_all()
 {
     if (!current_user_can('frm_delete_entries')) {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     global $wpdb;
     $params = FrmForm::get_admin_params();
     $message = '';
     $errors = array();
     $form_id = (int) $params['form'];
     if ($form_id) {
         $entry_ids = FrmDb::get_col('frm_items', array('form_id' => $form_id));
         $action = FrmFormAction::get_action_for_form($form_id, 'wppost', 1);
         if ($action) {
             // this action takes a while, so only trigger it if there are posts to delete
             foreach ($entry_ids as $entry_id) {
                 do_action('frm_before_destroy_entry', $entry_id);
                 unset($entry_id);
             }
         }
         $wpdb->query($wpdb->prepare("DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id));
         $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
         if ($results) {
             $message = __('Entries were Successfully Destroyed', 'formidable');
         }
     } else {
         $errors = __('No entries were specified', 'formidable');
     }
     self::display_list($message, $errors);
 }
Exemple #21
0
 public static function get_entry_metas($entry_id)
 {
     _deprecated_function(__FUNCTION__, '1.07.10');
     global $wpdb;
     return FrmDb::get_col($wpdb->prefix . 'frm_item_metas', array('item_id' => $entry_id), 'meta_value');
 }
 /**
  * @covers FrmProFieldsHelper::move_entries_to_child_form
  */
 function _check_if_child_entries_created($args, $child_form_id)
 {
     global $wpdb;
     // Check for value in repeating section
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertNotEmpty($rep_meta_values, 'When switching from non-repeating to repeating, the repeating section frm_item_metas is not saving the IDs of the child entries.');
     // Check if entries were created in child form
     $child_items = FrmEntry::getAll(array('it.form_id' => $child_form_id));
     $parent_items = FrmEntry::getAll(array('it.form_id' => $args['parent_form_id']));
     $this->assertEquals(count($parent_items), count($child_items), 'When switching from non-repeating to repeating section, child entries are not created. ');
     // Check if entries in child form match IDs saved in repeating section frm_item_metas
     $child_ids = array_keys($child_items);
     $this->assertEquals($child_ids, $rep_meta_values, 'When switching from non-repeating to repeating, created entry IDs do not match IDs saved in repeating section field frm_item_metas.');
     // Check if the item_id for child field frm_item_metas was updated to match new child entry IDs
     $new_child_metas = FrmDb::get_col($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items it ON it.id=m.item_id', array('field_id' => $args['children']), 'm.item_id', array('order_by' => 'it.created_at ASC'));
     $new_child_metas = array_unique($new_child_metas);
     $this->assertEquals($child_ids, $new_child_metas, 'When switching from non-repeating to repeating, the item_id is not updated on frm_item_metas for child fields');
 }
 public static function entry_link_shortcode($atts)
 {
     $atts = shortcode_atts(array('id' => false, 'field_key' => 'created_at', 'type' => 'list', 'logged_in' => true, 'edit' => true, 'class' => '', 'link_type' => 'page', 'blank_label' => '', 'param_name' => 'entry', 'param_value' => 'key', 'page_id' => false, 'show_delete' => false, 'confirm' => __('Are you sure you want to delete that entry?', 'formidable'), 'drafts' => false, 'order' => ''), $atts);
     $user_ID = get_current_user_id();
     if (!$atts['id'] || $atts['logged_in'] && !$user_ID) {
         return;
     }
     $atts = self::fill_entry_links_atts($atts);
     $action = isset($_GET) && isset($_GET['frm_action']) ? 'frm_action' : 'action';
     $entry_action = FrmAppHelper::simple_get($action, 'sanitize_title');
     $entry_key = FrmAppHelper::simple_get('entry', 'sanitize_title');
     if ($entry_action == 'destroy') {
         self::maybe_delete_entry($entry_key);
     }
     $entries = self::get_entry_link_entries($atts);
     if (empty($entries)) {
         return;
     }
     $public_entries = array();
     $post_status_check = array();
     foreach ($entries as $k => $entry) {
         if ($entry_action == 'destroy' && in_array($entry_key, array($entry->item_key, $entry->id))) {
             continue;
         }
         if ($entry->post_id) {
             $post_status_check[$entry->post_id] = $entry->id;
         }
         $public_entries[$entry->id] = $entry;
     }
     if (!empty($post_status_check)) {
         global $wpdb;
         $query = array('post_status !' => 'publish', 'ID' => array_keys($post_status_check));
         $remove_entries = FrmDb::get_col($wpdb->posts, $query, 'ID');
         unset($query);
         foreach ($remove_entries as $entry_post_id) {
             unset($public_entries[$post_status_check[$entry_post_id]]);
         }
         unset($remove_entries);
     }
     $entries = $public_entries;
     unset($public_entries);
     $content = array();
     switch ($atts['type']) {
         case 'list':
             self::entry_link_list($entries, $atts, $content);
             break;
         case 'select':
             self::entry_link_select($entries, $atts, $content);
             break;
         case 'collapse':
             self::entry_link_collapse($entries, $atts, $content);
     }
     $content = implode('', $content);
     return $content;
 }
 public static function generate_xml($type, $args = array())
 {
     global $wpdb;
     $type = (array) $type;
     if (in_array('items', $type) && !in_array('forms', $type)) {
         // make sure the form is included if there are entries
         $type[] = 'forms';
     }
     if (in_array('forms', $type)) {
         // include actions with forms
         $type[] = 'actions';
     }
     $tables = array('items' => $wpdb->prefix . 'frm_items', 'forms' => $wpdb->prefix . 'frm_forms', 'posts' => $wpdb->posts, 'styles' => $wpdb->posts, 'actions' => $wpdb->posts);
     $defaults = array('ids' => false);
     $args = wp_parse_args($args, $defaults);
     $sitename = sanitize_key(get_bloginfo('name'));
     if (!empty($sitename)) {
         $sitename .= '.';
     }
     $filename = $sitename . 'formidable.' . date('Y-m-d') . '.xml';
     header('Content-Description: File Transfer');
     header('Content-Disposition: attachment; filename=' . $filename);
     header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
     //make sure ids are numeric
     if (is_array($args['ids']) && !empty($args['ids'])) {
         $args['ids'] = array_filter($args['ids'], 'is_numeric');
     }
     $records = array();
     foreach ($type as $tb_type) {
         $where = array();
         $join = '';
         $table = $tables[$tb_type];
         $select = $table . '.id';
         $query_vars = array();
         switch ($tb_type) {
             case 'forms':
                 //add forms
                 if ($args['ids']) {
                     $where[] = array('or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids']);
                 } else {
                     $where[$table . '.status !'] = 'draft';
                 }
                 break;
             case 'actions':
                 $select = $table . '.ID';
                 $where['post_type'] = FrmFormActionsController::$action_post_type;
                 if (!empty($args['ids'])) {
                     $where['menu_order'] = $args['ids'];
                 }
                 break;
             case 'items':
                 //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
                 if ($args['ids']) {
                     $where[$table . '.form_id'] = $args['ids'];
                 }
                 break;
             case 'styles':
                 // Loop through all exported forms and get their selected style IDs
                 $form_ids = $args['ids'];
                 $style_ids = array();
                 foreach ($form_ids as $form_id) {
                     $form_data = FrmForm::getOne($form_id);
                     // For forms that have not been updated while running 2.0, check if custom_style is set
                     if (isset($form_data->options['custom_style'])) {
                         $style_ids[] = $form_data->options['custom_style'];
                     }
                     unset($form_id, $form_data);
                 }
                 $select = $table . '.ID';
                 $where['post_type'] = 'frm_styles';
                 // Only export selected styles
                 if (!empty($style_ids)) {
                     $where['ID'] = $style_ids;
                 }
                 break;
             default:
                 $select = $table . '.ID';
                 $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
                 $where['pm.meta_key'] = 'frm_form_id';
                 if (empty($args['ids'])) {
                     $where['pm.meta_value >'] = 1;
                 } else {
                     $where['pm.meta_value'] = $args['ids'];
                 }
                 break;
         }
         $records[$tb_type] = FrmDb::get_col($table . $join, $where, $select);
         unset($tb_type);
     }
     echo '<?xml version="1.0" encoding="' . esc_attr(get_bloginfo('charset')) . "\" ?>\n";
     include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
 }
Exemple #25
0
 /**
  * @return int|boolean
  */
 public static function destroy($id)
 {
     global $wpdb;
     $form = self::getOne($id);
     if (!$form) {
         return false;
     }
     // Disconnect the entries from this form
     $entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('form_id' => $id));
     foreach ($entries as $entry_id) {
         FrmEntry::destroy($entry_id);
         unset($entry_id);
     }
     // Disconnect the fields from this form
     $wpdb->query($wpdb->prepare('DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id));
     $query_results = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
     if ($query_results) {
         // Delete all form actions linked to this form
         $action_control = FrmFormActionsController::get_form_actions('email');
         $action_control->destroy($id, 'all');
         // Clear form caching
         self::clear_form_cache();
         do_action('frm_destroy_form', $id);
         do_action('frm_destroy_form_' . $id);
     }
     return $query_results;
 }
 public static function update_settings($form_id)
 {
     global $wpdb;
     $registered_actions = self::$registered_actions->actions;
     $old_actions = FrmDb::get_col($wpdb->posts, array('post_type' => self::$action_post_type, 'menu_order' => $form_id), 'ID');
     $new_actions = array();
     foreach ($registered_actions as $registered_action) {
         $action_ids = $registered_action->update_callback($form_id);
         if (!empty($action_ids)) {
             $new_actions[] = $action_ids;
         }
     }
     //Only use array_merge if there are new actions
     if (!empty($new_actions)) {
         $new_actions = call_user_func_array('array_merge', $new_actions);
     }
     $old_actions = array_diff($old_actions, $new_actions);
     self::delete_missing_actions($old_actions);
 }
Exemple #27
0
 /**
  * Get the entry ID from a linked field
  *
  * @since 2.0.15
  * @param int $linked_field_id
  * @param string $where_val
  * @param string $where_is
  * @return int $linked_id
  */
 public static function get_dynamic_field_entry_id($linked_field_id, $where_val, $where_is)
 {
     $query = array('field_id' => $linked_field_id, 'meta_value' . FrmDb::append_where_is($where_is) => $where_val);
     $linked_id = FrmDb::get_col('frm_item_metas', $query, 'item_id');
     return $linked_id;
 }