/**
  * Get fields with specified field value 'frm_cat' = field key/id,
  * 'frm_cat_id' = order position of selected option
  * @since 2.0.6
  */
 private static function maybe_add_cat_query(&$where)
 {
     $frm_cat = FrmAppHelper::simple_get('frm_cat', 'sanitize_title');
     $frm_cat_id = FrmAppHelper::simple_get('frm_cat_id', 'sanitize_title');
     if (!$frm_cat || !isset($_GET['frm_cat_id'])) {
         return;
     }
     $cat_field = FrmField::getOne($frm_cat);
     if (!$cat_field) {
         return;
     }
     $categories = maybe_unserialize($cat_field->options);
     if (isset($categories[$frm_cat_id])) {
         $cat_entry_ids = FrmEntryMeta::getEntryIds(array('meta_value' => $categories[$frm_cat_id], 'fi.field_key' => $frm_cat));
         if ($cat_entry_ids) {
             $where['it.id'] = $cat_entry_ids;
         } else {
             $where['it.id'] = 0;
         }
     }
 }
 /**
  * Get the displayed value for Dynamic field that imports data from a post field
  * Called from self::get_linked_field_val
  */
 private static function get_linked_post_field_val($value, $atts, $linked_field)
 {
     global $wpdb;
     $post_id = FrmDb::get_var($wpdb->prefix . 'frm_items', array('id' => $value), 'post_id');
     if ($post_id) {
         if (!isset($atts['truncate'])) {
             $atts['truncate'] = false;
         }
         $new_value = FrmProEntryMetaHelper::get_post_value($post_id, $linked_field->field_options['post_field'], $linked_field->field_options['custom_field'], array('form_id' => $linked_field->form_id, 'field' => $linked_field, 'type' => $linked_field->type, 'truncate' => $atts['truncate']));
     } else {
         $new_value = FrmEntryMeta::get_entry_meta_by_field($value, $linked_field->id);
     }
     return $new_value;
 }
Example #3
0
 private function migrate_to_4()
 {
     global $wpdb;
     $user_ids = FrmEntryMeta::getAll(array('fi.type' => 'user_id'));
     foreach ($user_ids as $user_id) {
         $wpdb->update($this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id));
     }
 }
Example #4
0
 public static function update($id, $values)
 {
     global $wpdb, $frm_vars;
     if (isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array((int) $id, (array) $frm_vars['saved_entries'])) {
         return;
     }
     $values = apply_filters('frm_pre_update_entry', $values, $id);
     $user_ID = get_current_user_id();
     $item_name = self::get_new_entry_name($values);
     $new_values = array('name' => $item_name, 'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null, 'is_draft' => isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 || isset($values['is_draft']) && $values['is_draft'] == 1 ? 1 : 0, 'updated_at' => current_time('mysql', 1), 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID);
     if (isset($values['post_id'])) {
         $new_values['post_id'] = (int) $values['post_id'];
     }
     if (isset($values['item_key'])) {
         $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id);
     }
     if (isset($values['parent_item_id'])) {
         $new_values['parent_item_id'] = (int) $values['parent_item_id'];
     }
     if (isset($values['frm_user_id']) && is_numeric($values['frm_user_id'])) {
         $new_values['user_id'] = $values['frm_user_id'];
     }
     $new_values = apply_filters('frm_update_entry', $new_values, $id);
     $query_results = $wpdb->update($wpdb->prefix . 'frm_items', $new_values, compact('id'));
     if ($query_results) {
         self::clear_cache();
     }
     if (!isset($frm_vars['saved_entries'])) {
         $frm_vars['saved_entries'] = array();
     }
     $frm_vars['saved_entries'][] = (int) $id;
     if (isset($values['item_meta'])) {
         FrmEntryMeta::update_entry_metas($id, $values['item_meta']);
     }
     do_action('frm_after_update_entry', $id, $new_values['form_id']);
     do_action('frm_after_update_entry_' . $new_values['form_id'], $id);
     return $query_results;
 }
 public static function trigger_email($action, $entry, $form)
 {
     if (defined('WP_IMPORTING') && WP_IMPORTING) {
         return;
     }
     global $wpdb;
     $notification = $action->post_content;
     $email_key = $action->ID;
     // Set the subject
     if (empty($notification['email_subject'])) {
         $notification['email_subject'] = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, '[sitename]');
     }
     $plain_text = $notification['plain_text'] ? true : false;
     //Filter these fields
     $filter_fields = array('email_to', 'cc', 'bcc', 'reply_to', 'from', 'email_subject', 'email_message');
     add_filter('frm_plain_text_email', $plain_text ? '__return_true' : '__return_false');
     //Get all values in entry in order to get User ID field ID
     $values = FrmEntryMeta::getAll(array('it.field_id !' => 0, 'it.item_id' => $entry->id), ' ORDER BY fi.field_order');
     $user_id_field = $user_id_key = '';
     foreach ($values as $value) {
         if ($value->field_type == 'user_id') {
             $user_id_field = $value->field_id;
             $user_id_key = $value->field_key;
             break;
         }
         unset($value);
     }
     //Filter and prepare the email fields
     foreach ($filter_fields as $f) {
         //Don't allow empty From
         if ($f == 'from' && empty($notification[$f])) {
             $notification[$f] = '[admin_email]';
         } else {
             if (in_array($f, array('email_to', 'cc', 'bcc', 'reply_to', 'from'))) {
                 //Remove brackets
                 //Add a space in case there isn't one
                 $notification[$f] = str_replace('<', ' ', $notification[$f]);
                 $notification[$f] = str_replace(array('"', '>'), '', $notification[$f]);
                 //Switch userID shortcode to email address
                 if (strpos($notification[$f], '[' . $user_id_field . ']') !== false || strpos($notification[$f], '[' . $user_id_key . ']') !== false) {
                     $user_data = get_userdata($entry->metas[$user_id_field]);
                     $user_email = $user_data->user_email;
                     $notification[$f] = str_replace(array('[' . $user_id_field . ']', '[' . $user_id_key . ']'), $user_email, $notification[$f]);
                 }
             }
         }
         $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes($notification[$f], $form, $entry);
     }
     //Put recipients, cc, and bcc into an array if they aren't empty
     $to_emails = self::explode_emails($notification['email_to']);
     $cc = self::explode_emails($notification['cc']);
     $bcc = self::explode_emails($notification['bcc']);
     $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form'));
     // Stop now if there aren't any recipients
     if (empty($to_emails) && empty($cc) && empty($bcc)) {
         return;
     }
     $to_emails = array_unique((array) $to_emails);
     $prev_mail_body = $mail_body = $notification['email_message'];
     $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array('id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, 'user_info' => isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false));
     // Add the user info if it isn't already included
     if ($notification['inc_user_info'] && $prev_mail_body == $mail_body) {
         $data = maybe_unserialize($entry->description);
         $mail_body .= "\r\n\r\n" . __('User Information', 'formidable') . "\r\n";
         $mail_body .= __('IP Address', 'formidable') . ': ' . $entry->ip . "\r\n";
         $mail_body .= __('User-Agent (Browser/OS)', 'formidable') . ': ' . FrmEntryFormat::get_browser($data['browser']) . "\r\n";
         $mail_body .= __('Referrer', 'formidable') . ': ' . $data['referrer'] . "\r\n";
     }
     unset($prev_mail_body);
     // Add attachments
     $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key'));
     if (!empty($notification['email_subject'])) {
         $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
     }
     // check for a phone number
     foreach ((array) $to_emails as $email_key => $e) {
         if ($e != '[admin_email]' && !is_email($e)) {
             $e = explode(' ', $e);
             //If to_email has name <*****@*****.**> format
             if (is_email(end($e))) {
                 continue;
             }
             do_action('frm_send_to_not_email', array('e' => $e, 'subject' => $notification['email_subject'], 'mail_body' => $mail_body, 'reply_to' => $notification['reply_to'], 'from' => $notification['from'], 'plain_text' => $plain_text, 'attachments' => $attachments, 'form' => $form, 'email_key' => $email_key));
             unset($to_emails[$email_key]);
         }
     }
     // Send the email now
     $sent_to = self::send_email(array('to_email' => $to_emails, 'subject' => $notification['email_subject'], 'message' => $mail_body, 'from' => $notification['from'], 'plain_text' => $plain_text, 'reply_to' => $notification['reply_to'], 'attachments' => $attachments, 'cc' => $cc, 'bcc' => $bcc));
     return $sent_to;
 }
 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);
 }
Example #7
0
if (!isset($new_field) || !$new_field) {
    ?>
<input type="text" name="<?php 
    echo isset($current_field_id) ? 'field_options[hide_opt_' . $current_field_id . ']' : $field_name;
    ?>
" value="" />
<?php 
    return;
}
if (!isset($is_settings_page)) {
    $is_settings_page = FrmAppHelper::simple_get('frm_action') == 'settings';
    $anything = $is_settings_page ? '' : __('Anything', 'formidable');
}
if ($new_field->type == 'data') {
    if (isset($new_field->field_options['form_select']) && is_numeric($new_field->field_options['form_select'])) {
        $new_entries = FrmEntryMeta::getAll(array('it.field_id' => (int) $new_field->field_options['form_select']), '', ' LIMIT 300', true);
    }
    $new_field->options = array();
    if (isset($new_entries) && !empty($new_entries)) {
        foreach ($new_entries as $ent) {
            $new_field->options[$ent->item_id] = $ent->meta_value;
        }
    }
} else {
    if (isset($new_field->field_options['post_field']) && $new_field->field_options['post_field'] == 'post_status') {
        $new_field->options = FrmProFieldsHelper::get_status_options($new_field);
    }
}
if (isset($new_field->field_options['post_field']) && $new_field->field_options['post_field'] == 'post_category') {
    if (!isset($field_name)) {
        $field_name = 'field_options[hide_opt_' . $current_field_id . ']';
 public static function replace_content_shortcodes($content, $entry, $shortcodes)
 {
     $shortcode_values = array('id' => $entry->id, 'key' => $entry->item_key, 'ip' => $entry->ip);
     foreach ($shortcodes[0] as $short_key => $tag) {
         $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
         if (!empty($shortcodes[3][$short_key])) {
             $tag = str_replace(array('[', ']'), '', $shortcodes[0][$short_key]);
             $tags = explode(' ', $tag);
             if (is_array($tags)) {
                 $tag = $tags[0];
             }
         } else {
             $tag = $shortcodes[2][$short_key];
         }
         switch ($tag) {
             case 'id':
             case 'key':
             case 'ip':
                 $replace_with = $shortcode_values[$tag];
                 break;
             case 'user_agent':
             case 'user-agent':
                 $entry->description = maybe_unserialize($entry->description);
                 $replace_with = FrmEntryFormat::get_browser($entry->description['browser']);
                 break;
             case 'created_at':
             case 'created-at':
             case 'updated_at':
             case 'updated-at':
                 if (isset($atts['format'])) {
                     $time_format = ' ';
                 } else {
                     $atts['format'] = get_option('date_format');
                     $time_format = '';
                 }
                 $this_tag = str_replace('-', '_', $tag);
                 $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
                 unset($this_tag);
                 break;
             case 'created_by':
             case 'created-by':
             case 'updated_by':
             case 'updated-by':
                 $this_tag = str_replace('-', '_', $tag);
                 $replace_with = self::get_display_value($entry->{$this_tag}, (object) array('type' => 'user_id'), $atts);
                 unset($this_tag);
                 break;
             case 'admin_email':
             case 'siteurl':
             case 'frmurl':
             case 'sitename':
             case 'get':
                 $replace_with = self::dynamic_default_values($tag, $atts);
                 break;
             default:
                 $field = FrmField::getOne($tag);
                 if (!$field) {
                     break;
                 }
                 $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
                 $replace_with = FrmEntryMeta::get_meta_value($entry, $field->id);
                 $atts['entry_id'] = $entry->id;
                 $atts['entry_key'] = $entry->item_key;
                 //$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
                 if (is_array($replace_with)) {
                     $replace_with = implode($sep, $replace_with);
                 }
                 if (isset($atts['show']) && $atts['show'] == 'field_label') {
                     $replace_with = $field->name;
                 } else {
                     if (isset($atts['show']) && $atts['show'] == 'description') {
                         $replace_with = $field->description;
                     } else {
                         if (empty($replace_with) && $replace_with != '0') {
                             $replace_with = '';
                         } else {
                             $replace_with = self::get_display_value($replace_with, $field, $atts);
                         }
                     }
                 }
                 unset($field);
                 break;
         }
         if (isset($replace_with)) {
             $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         }
         unset($atts, $conditional, $replace_with);
     }
     return $content;
 }
Example #9
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 = $wpdb->get_col("SELECT ID FROM {$wpdb->users} ORDER BY display_name ASC");
                $submitted_user_ids = FrmEntryMeta::get_entry_metas_for_field($field->id, '', '', false, 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 admin_url('user-edit.php');
                ?>
" method="get">
            <p><?php 
                _e('Users with no entry', 'formidable');
 function ajax_time_options()
 {
     global $frmpro_settings, $frmdb, $wpdb;
     //posted vars = $time_field, $date_field, $step, $start, $end, $date, $clock
     extract($_POST);
     $time_key = str_replace('field_', '', $time_field);
     $date_key = str_replace('field_', '', $date_field);
     if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($date))) {
         $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
     }
     $date_entries = FrmEntryMeta::getEntryIds("fi.field_key='{$date_key}' and meta_value='{$date}'");
     $opts = array('' => '');
     $time = strtotime($start);
     $end = strtotime($end);
     $step = explode(':', $step);
     $step = isset($step[1]) ? $step[0] * 3600 + $step[1] * 60 : $step[0] * 60;
     $format = $clock ? 'H:i' : 'h:i A';
     while ($time <= $end) {
         $opts[date($format, $time)] = date($format, $time);
         $time += $step;
     }
     if ($date_entries and !empty($date_entries)) {
         $used_times = $wpdb->get_col("SELECT meta_value FROM {$frmdb->entry_metas} it LEFT JOIN {$frmdb->fields} fi ON (it.field_id = fi.id) WHERE fi.field_key='{$time_key}' and it.item_id in (" . implode(',', $date_entries) . ")");
         if ($used_times and !empty($used_times)) {
             $number_allowed = apply_filters('frm_allowed_time_count', 1, $time_key, $date_key);
             $count = array();
             foreach ($used_times as $used) {
                 if (!isset($opts[$used])) {
                     continue;
                 }
                 if (!isset($count[$used])) {
                     $count[$used] = 0;
                 }
                 $count[$used]++;
                 if ((int) $count[$used] >= $number_allowed) {
                     unset($opts[$used]);
                 }
             }
             unset($count);
         }
     }
     echo json_encode($opts);
     die;
 }
 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 add_comments_to_csv(&$row)
 {
     if (!self::$comment_count) {
         // don't continue if we already know there are no comments
         return;
     }
     $comments = FrmEntryMeta::getAll(array('item_id' => (int) self::$entry->id, 'field_id' => 0), ' ORDER BY it.created_at ASC');
     $i = 0;
     if ($comments) {
         foreach ($comments as $comment) {
             $c = maybe_unserialize($comment->meta_value);
             if (!isset($c['comment'])) {
                 continue;
             }
             $row['comment' . $i] = $c['comment'];
             unset($co);
             $row['comment_user_id' . $i] = FrmProFieldsHelper::get_display_name($c['user_id'], 'user_login');
             unset($c);
             $row['comment_created_at' . $i] = FrmAppHelper::get_formatted_time($comment->created_at, self::$wp_date_format, ' ');
             unset($v, $comment);
             $i++;
         }
     }
     for ($i; $i <= self::$comment_count; $i++) {
         $row['comment' . $i] = '';
         $row['comment_user_id' . $i] = '';
         $row['comment_created_at' . $i] = '';
     }
 }
Example #13
0
 function widget($args, $instance)
 {
     global $wpdb;
     $display = FrmProDisplay::getOne($instance['display_id'], false, true);
     $title = apply_filters('widget_title', empty($instance['title']) && $display ? $display->post_title : $instance['title']);
     $limit = empty($instance['limit']) ? ' LIMIT 100' : " LIMIT {$instance['limit']}";
     $post_id = !$display || empty($display->frm_post_id) ? $instance['post_id'] : $display->frm_post_id;
     $page_url = get_permalink($post_id);
     $order_by = '';
     $cat_field = false;
     if ($display && is_numeric($display->frm_form_id) && !empty($display->frm_form_id)) {
         //Set up order for Entries List Widget
         if (isset($display->frm_order_by) && !empty($display->frm_order_by)) {
             //Get only the first order field and order
             $order_field = reset($display->frm_order_by);
             $order = reset($display->frm_order);
             FrmAppHelper::esc_order_by($order);
             if ($order_field == 'rand') {
                 //If random is set, set the order to random
                 $order_by = ' RAND()';
             } else {
                 if (is_numeric($order_field)) {
                     //If ordering by a field
                     //Get all post IDs for this form
                     $posts = FrmDb::get_results($wpdb->prefix . 'frm_items', array('form_id' => $display->frm_form_id, 'post_id >' => 1, 'is_draft' => 0), 'id, post_id');
                     $linked_posts = array();
                     foreach ($posts as $post_meta) {
                         $linked_posts[$post_meta->post_id] = $post_meta->id;
                     }
                     //Get all field information
                     $o_field = FrmField::getOne($order_field);
                     $query = 'SELECT m.id FROM ' . $wpdb->prefix . 'frm_items m INNER JOIN ';
                     $where = array();
                     //create query with ordered values
                     //if field is some type of post field
                     if (isset($o_field->field_options['post_field']) && $o_field->field_options['post_field']) {
                         if ($o_field->field_options['post_field'] == 'post_custom' && !empty($linked_posts)) {
                             //if field is custom field
                             $where['pm.post_id'] = array_keys($linked_posts);
                             FrmDb::get_where_clause_and_values($where);
                             array_unshift($where['values'], $o_field->field_options['custom_field']);
                             $query .= $wpdb->postmeta . ' pm ON pm.post_id=m.post_id AND pm.meta_key=%s ' . $where['where'] . ' ORDER BY CASE when pm.meta_value IS NULL THEN 1 ELSE 0 END, pm.meta_value ' . $order;
                         } else {
                             if ($o_field->field_options['post_field'] != 'post_category' && !empty($linked_posts)) {
                                 //if field is a non-category post field
                                 $where['p.ID'] = array_keys($linked_posts);
                                 FrmDb::get_where_clause_and_values($where);
                                 $query .= $wpdb->posts . ' p ON p.ID=m.post_id ' . $where['where'] . ' ORDER BY CASE p.' . sanitize_title($o_field->field_options['post_field']) . ' WHEN "" THEN 1 ELSE 0 END, p.' . sanitize_title($o_field->field_options['post_field']) . ' ' . $order;
                             }
                         }
                     } else {
                         //if field is a normal, non-post field
                         $where['em.field_id'] = $o_field->id;
                         FrmDb::get_where_clause_and_values($where);
                         $query .= $wpdb->prefix . 'frm_item_metas em ON em.item_id=m.id ' . $where['where'] . ' ORDER BY CASE when em.meta_value IS NULL THEN 1 ELSE 0 END, em.meta_value' . ($o_field->type == 'number' ? ' +0 ' : '') . ' ' . $order;
                     }
                     //Get ordered values
                     if (!empty($where)) {
                         $metas = $wpdb->get_results($wpdb->prepare($query, $where['values']));
                     } else {
                         $metas = false;
                     }
                     unset($query, $where);
                     if (!empty($metas)) {
                         $order_by_array = array();
                         foreach ($metas as $meta) {
                             $order_by_array[] = $wpdb->prepare('it.id=%d DESC', $meta->id);
                         }
                         $order_by = implode(', ', $order_by_array);
                         unset($order_by_array);
                     } else {
                         $order_by .= 'it.created_at ' . $order;
                     }
                     unset($metas);
                 } else {
                     if (!empty($order_field)) {
                         //If ordering by created_at or updated_at
                         $order_by = 'it.' . sanitize_title($order_field) . ' ' . $order;
                     }
                 }
             }
             if (!empty($order_by)) {
                 $order_by = ' ORDER BY ' . $order_by;
             }
         }
         if (isset($instance['cat_list']) && (int) $instance['cat_list'] == 1 && is_numeric($instance['cat_id'])) {
             if ($cat_field = FrmField::getOne($instance['cat_id'])) {
                 $categories = maybe_unserialize($cat_field->options);
             }
         }
     }
     echo $args['before_widget'];
     if ($title) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo '<ul id="frm_entry_list' . ($display ? $display->frm_form_id : '') . '">' . "\n";
     //if Listing entries by category
     if (isset($instance['cat_list']) && (int) $instance['cat_list'] == 1 && isset($categories) && is_array($categories)) {
         foreach ($categories as $cat_order => $cat) {
             if ($cat == '') {
                 continue;
             }
             echo '<li>';
             if (isset($instance['cat_name']) && (int) $instance['cat_name'] == 1 && $cat_field) {
                 echo '<a href="' . esc_url(add_query_arg(array('frm_cat' => $cat_field->field_key, 'frm_cat_id' => $cat_order), $page_url)) . '">';
             }
             echo $cat;
             if (isset($instance['cat_count']) && (int) $instance['cat_count'] == 1) {
                 echo ' (' . FrmProFieldsHelper::get_field_stats($instance['cat_id'], 'count', false, $cat) . ')';
             }
             if (isset($instance['cat_name']) && (int) $instance['cat_name'] == 1) {
                 echo '</a>';
             } else {
                 $entry_ids = FrmEntryMeta::getEntryIds(array('meta_value like' => $cat, 'fi.id' => $instance['cat_id']));
                 $items = false;
                 if ($entry_ids) {
                     $items = FrmEntry::getAll(array('it.id' => $entry_ids, 'it.form_id' => (int) $display->frm_form_id), $order_by, $limit);
                 }
                 if ($items) {
                     echo '<ul>';
                     foreach ($items as $item) {
                         $url_id = $display->frm_type == 'id' ? $item->id : $item->item_key;
                         $current = FrmAppHelper::simple_get($display->frm_param) == $url_id ? ' class="current_page"' : '';
                         if ($item->post_id) {
                             $entry_link = get_permalink($item->post_id);
                         } else {
                             $entry_link = add_query_arg(array($display->frm_param => $url_id), $page_url);
                         }
                         echo '<li' . $current . '><a href="' . esc_url($entry_link) . '">' . FrmAppHelper::kses($item->name) . '</a></li>' . "\n";
                     }
                     echo '</ul>';
                 }
             }
             echo '</li>';
         }
     } else {
         // if not listing entries by category
         if ($display) {
             $items = FrmEntry::getAll(array('it.form_id' => $display->frm_form_id, 'is_draft' => '0'), $order_by, $limit);
         } else {
             $items = array();
         }
         foreach ($items as $item) {
             $url_id = $display->frm_type == 'id' ? $item->id : $item->item_key;
             $current = FrmAppHelper::simple_get($display->frm_param) == $url_id ? ' class="current_page"' : '';
             echo '<li' . $current . '><a href="' . esc_url(add_query_arg(array($display->frm_param => $url_id), $page_url)) . '">' . FrmAppHelper::kses($item->name) . '</a></li>' . "\n";
         }
     }
     echo "</ul>\n";
     echo $args['after_widget'];
 }
Example #14
0
 function create($values)
 {
     global $wpdb, $frmdb, $frm_entry_meta;
     $new_values = array();
     $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $frmdb->entries, 'item_key');
     $new_values['name'] = isset($values['name']) ? $values['name'] : $values['item_key'];
     $new_values['ip'] = $_SERVER['REMOTE_ADDR'];
     if (isset($values['description']) and !empty($values['description'])) {
         $new_values['description'] = $values['description'];
     } else {
         $referrerinfo = FrmAppHelper::get_referer_info();
         $new_values['description'] = serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $referrerinfo));
     }
     $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
     $new_values['created_at'] = $new_values['updated_at'] = isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1);
     //if(isset($values['id']) and is_numeric($values['id']))
     //    $new_values['id'] = $values['id'];
     if (isset($values['frm_user_id']) and is_numeric($values['frm_user_id'])) {
         $new_values['user_id'] = $new_values['updated_by'] = $values['frm_user_id'];
     } else {
         global $user_ID;
         if ($user_ID) {
             $new_values['user_id'] = $new_values['updated_by'] = $user_ID;
         }
     }
     //check for duplicate entries created in the last 5 minutes
     $create_entry = true;
     if (!defined('WP_IMPORTING')) {
         $check_val = $new_values;
         $check_val['created_at >'] = date('Y-m-d H:i:s', strtotime($new_values['created_at']) - 60 * 60 * 5);
         unset($check_val['created_at']);
         unset($check_val['id']);
         unset($check_val['item_key']);
         if ($new_values['item_key'] == $new_values['name']) {
             unset($check_val['name']);
         }
         $entry_exists = $frmdb->get_records($frmdb->entries, $check_val, 'created_at DESC', '', 'id');
         if ($entry_exists and !empty($entry_exists)) {
             foreach ($entry_exists as $entry_exist) {
                 if ($create_entry) {
                     $create_entry = false;
                     //add more checks here to make sure it's a duplicate
                     if (isset($values['item_meta'])) {
                         $metas = FrmEntryMeta::get_entry_meta_info($entry_exist->id);
                         $field_metas = array();
                         foreach ($metas as $meta) {
                             $field_metas[$meta->field_id] = $meta->meta_value;
                         }
                         $diff = array_diff_assoc($field_metas, $values['item_meta']);
                         foreach ($diff as $field_id => $meta_value) {
                             if (!empty($meta_value) and !$create_entry) {
                                 $create_entry = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($create_entry) {
         $query_results = $wpdb->insert($frmdb->entries, $new_values);
     }
     if (isset($query_results) and $query_results) {
         $entry_id = $wpdb->insert_id;
         global $frm_saved_entries;
         $frm_saved_entries[] = (int) $entry_id;
         if (isset($values['item_meta'])) {
             $frm_entry_meta->update_entry_metas($entry_id, $values['item_meta']);
         }
         do_action('frm_after_create_entry', $entry_id, $new_values['form_id']);
         return $entry_id;
     } else {
         return false;
     }
 }
 function show_frm_date($entry)
 {
     $metas = FrmEntryMeta::getAll("item_id={$entry->id} and field_id=0", ' ORDER BY it.created_at DESC');
     $initials = '';
     foreach ($metas as $meta) {
         if (!empty($initials)) {
             continue;
         }
         $value = maybe_unserialize($meta->meta_value);
         if (!isset($value['initials'])) {
             continue;
         }
         $initials = $value['initials'];
         $date = $meta->created_at;
         unset($meta);
         unset($value);
     }
     if (!empty($initials)) {
         TouAppHelper::show_date($date, $initials);
     }
 }
Example #16
0
 private static function filter_entry_ids($args, $where_field, $entry_ids, &$new_ids)
 {
     $where_statement = array('fi.id' => (int) $args['where_opt']);
     $field_key = 'meta_value ' . (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : '') . FrmDb::append_where_is($args['temp_where_is']);
     $nested_where = array($field_key => $args['where_val']);
     if (isset($args['where_val_esc']) && $args['where_val_esc'] != $args['where_val']) {
         $nested_where['or'] = 1;
         $nested_where[' ' . $field_key] = $args['where_val_esc'];
     }
     $where_statement[] = $nested_where;
     $args['entry_ids'] = $entry_ids;
     $where_statement = apply_filters('frm_where_filter', $where_statement, $args);
     $filter_args = array('is_draft' => $args['drafts']);
     self::add_group_by($filter_args, $args);
     // If the field is from a repeating section (or embedded form?) get the parent ID
     $filter_args['return_parent_id'] = $where_field->form_id != $args['form_id'];
     // Add entry IDs to $where_statement. Meant for use when showing one entry.
     if ($args['use_ids']) {
         if (is_array($where_statement)) {
             if ($filter_args['return_parent_id']) {
                 $where_statement['parent_item_id'] = $entry_ids;
             } else {
                 $where_statement['item_id'] = $entry_ids;
             }
         } else {
             // if the filter changed the query to a string, allow it
             $where_statement .= FrmAppHelper::prepend_and_or_where(' AND ', array('item_id' => $entry_ids));
         }
     }
     $new_ids = FrmEntryMeta::getEntryIds($where_statement, '', '', true, $filter_args);
     if ($args['where_is'] != $args['temp_where_is']) {
         $new_ids = array_diff((array) $entry_ids, $new_ids);
     }
 }
Example #17
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 
            esc_html_e('Users with no entry:', 'formidable');
 function update_field_ajax($entry_id, $field_id, $value)
 {
     global $frmdb, $wpdb, $frm_field;
     $entry_id = (int) $entry_id;
     if (!$entry_id) {
         return false;
     }
     $where = '';
     if (is_numeric($field_id)) {
         $where .= "fi.id={$field_id}";
     } else {
         $where .= "field_key='{$field_id}'";
     }
     $field = $frm_field->getAll($where, '', ' LIMIT 1');
     if (!$field or !FrmProEntry::user_can_edit($entry_id, $field->form_id)) {
         return false;
     }
     $post_id = false;
     $field->field_options = maybe_unserialize($field->field_options);
     if (isset($field->field_options['post_field']) and !empty($field->field_options['post_field'])) {
         $post_id = $frmdb->get_var($frmdb->entries, array('id' => $entry_id), 'post_id');
     }
     if (!$post_id) {
         $updated = $wpdb->update($frmdb->entry_metas, array('meta_value' => $value), array('item_id' => $entry_id, 'field_id' => $field_id));
         if (!$updated) {
             $wpdb->query($wpdb->prepare("DELETE FROM {$frmdb->entry_metas} WHERE item_id = %d and field_id = %d", $entry_id, $field_id));
             $updated = FrmEntryMeta::add_entry_meta($entry_id, $field_id, '', $value);
         }
         wp_cache_delete($entry_id, 'frm_entry');
     } else {
         switch ($field->field_options['post_field']) {
             case 'post_custom':
                 $updated = update_post_meta($post_id, $field->field_options['post_custom'], maybe_serialize($value));
                 break;
             case 'post_category':
                 $taxonomy = (isset($field->field_options['taxonomy']) and !empty($field->field_options['taxonomy'])) ? $field->field_options['taxonomy'] : 'category';
                 $updated = wp_set_post_terms($post_id, $value, $taxonomy);
                 break;
             default:
                 $post = get_post($post_id, ARRAY_A);
                 $post[$field->field_options['post_field']] = maybe_serialize($value);
                 $updated = wp_insert_post($post);
         }
     }
     do_action('frm_after_update_field', compact('entry_id', 'field_id', 'value'));
     return $updated;
 }
Example #19
0
                echo esc_attr($field_name);
                ?>
" />
<?php 
            } else {
                if ($field['data_type'] == 'text' && is_numeric($field['form_select'])) {
                    $get_id = FrmAppHelper::simple_get('id');
                    if ($_POST && isset($_POST['item_meta'])) {
                        $observed_field_val = $_POST['item_meta'][$field['hide_field']];
                    } else {
                        if ($get_id) {
                            $observed_field_val = FrmEntryMeta::get_entry_meta_by_field($get_id, $field['hide_field']);
                        }
                    }
                    if (isset($observed_field_val) && is_numeric($observed_field_val)) {
                        $value = FrmEntryMeta::get_entry_meta_by_field($observed_field_val, $field['form_select']);
                    } else {
                        $value = '';
                    }
                    ?>
<input type="text" value="<?php 
                    echo esc_attr($value);
                    ?>
" name="<?php 
                    echo esc_attr($field_name);
                    ?>
" />

<?php 
                } else {
                    if ($field['data_type'] == 'checkbox') {
Example #20
0
 /**
  * Perform some actions right after updating an entry
  *
  * @since 2.0.16
  * @param boolean|int $query_results
  * @param int $id
  * @param array $values
  * @param array $new_values
  */
 private static function after_update_entry($query_results, $id, $values, $new_values)
 {
     if ($query_results) {
         self::clear_cache();
     }
     global $frm_vars;
     if (!isset($frm_vars['saved_entries'])) {
         $frm_vars['saved_entries'] = array();
     }
     $frm_vars['saved_entries'][] = (int) $id;
     if (isset($values['item_meta'])) {
         FrmEntryMeta::update_entry_metas($id, $values['item_meta']);
     }
     do_action('frm_after_update_entry', $id, $new_values['form_id']);
     do_action('frm_after_update_entry_' . $new_values['form_id'], $id);
 }
 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 #22
0
    function upgrade($old_db_version = false)
    {
        global $wpdb, $frm_db_version;
        //$frm_db_version is the version of the database we're moving to
        $old_db_version = (double) $old_db_version;
        if (!$old_db_version) {
            $old_db_version = get_option('frm_db_version');
        }
        if ($frm_db_version != $old_db_version) {
            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            $charset_collate = '';
            if ($wpdb->has_cap('collation')) {
                if (!empty($wpdb->charset)) {
                    $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
                }
                if (!empty($wpdb->collate)) {
                    $charset_collate .= " COLLATE {$wpdb->collate}";
                }
            }
            /* Create/Upgrade Fields Table */
            $sql = "CREATE TABLE {$this->fields} (\n                id int(11) NOT NULL auto_increment,\n                field_key varchar(255) default NULL,\n                name text default NULL,\n                description text default NULL,\n                type text default NULL,\n                default_value longtext default NULL,\n                options longtext default NULL,\n                field_order int(11) default 0,\n                required int(1) default NULL,\n                field_options longtext default NULL,\n                form_id int(11) default NULL,\n                created_at datetime NOT NULL,\n                PRIMARY KEY  (id),\n                KEY form_id (form_id),\n                UNIQUE KEY field_key (field_key)\n              ) {$charset_collate};";
            dbDelta($sql);
            /* Create/Upgrade Forms Table */
            $sql = "CREATE TABLE {$this->forms} (\n                id int(11) NOT NULL auto_increment,\n                form_key varchar(255) default NULL,\n                name varchar(255) default NULL,\n                description text default NULL,\n                logged_in boolean default NULL,\n                editable boolean default NULL,\n                is_template boolean default 0,\n                default_template boolean default 0,\n                status varchar(255) default NULL,\n                prli_link_id int(11) default NULL,\n                options longtext default NULL,\n                created_at datetime NOT NULL,\n                PRIMARY KEY  (id),\n                UNIQUE KEY form_key (form_key)\n              ) {$charset_collate};";
            dbDelta($sql);
            /* Create/Upgrade Items Table */
            $sql = "CREATE TABLE {$this->entries} (\n                id int(11) NOT NULL auto_increment,\n                item_key varchar(255) default NULL,\n                name varchar(255) default NULL,\n                description text default NULL,\n                ip text default NULL,\n                form_id int(11) default NULL,\n                post_id int(11) default NULL,\n                user_id int(11) default NULL,\n                parent_item_id int(11) default NULL,\n                updated_by int(11) default NULL,\n                created_at datetime NOT NULL,\n                updated_at datetime NOT NULL,\n                PRIMARY KEY  (id),\n                KEY form_id (form_id),\n                KEY post_id (post_id),\n                KEY user_id (user_id),\n                KEY parent_item_id (parent_item_id),\n                UNIQUE KEY item_key (item_key)\n              ) {$charset_collate};";
            dbDelta($sql);
            /* Create/Upgrade Meta Table */
            $sql = "CREATE TABLE {$this->entry_metas} (\n                id int(11) NOT NULL auto_increment,\n                meta_value longtext default NULL,\n                field_id int(11) NOT NULL,\n                item_id int(11) NOT NULL,\n                created_at datetime NOT NULL,\n                PRIMARY KEY  (id),\n                KEY field_id (field_id),\n                KEY item_id (item_id)\n              ) {$charset_collate};";
            dbDelta($sql);
            /**** MIGRATE DATA ****/
            if ($frm_db_version >= 1.03 and $old_db_version < 1.03) {
                global $frm_entry;
                $all_entries = $frm_entry->getAll();
                foreach ($all_entries as $ent) {
                    $opts = maybe_unserialize($ent->description);
                    if (is_array($opts)) {
                        $wpdb->update($this->entries, array('ip' => $opts['ip']), array('id' => $ent->id));
                    }
                }
            }
            if ($frm_db_version >= 4 and $old_db_version < 4) {
                $user_ids = FrmEntryMeta::getAll("fi.type='user_id'");
                foreach ($user_ids as $user_id) {
                    $wpdb->update($this->entries, array('user_id' => $user_id->meta_value), array('id' => $user_id->item_id));
                }
            }
            if ($frm_db_version >= 6 and $old_db_version < 6) {
                $fields = $wpdb->get_results("SELECT id, field_options FROM {$this->fields} WHERE type not in ('hidden', 'user_id', 'break', 'divider', 'html', 'captcha', 'form')");
                $default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
    <label class="frm_pos_[label_position]">[field_name]
        <span class="frm_required">[required_label]</span>
    </label>
    [input]
    [if description]<div class="frm_description">[description]</div>[/if description]
</div>
DEFAULT_HTML;
                $old_default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
    <label class="frm_pos_[label_position]">[field_name]
        <span class="frm_required">[required_label]</span>
    </label>
    [input]
    [if description]<p class="frm_description">[description]</p>[/if description]
</div>
DEFAULT_HTML;
                $new_default_html = FrmFieldsHelper::get_default_html('text');
                foreach ($fields as $field) {
                    $field->field_options = maybe_unserialize($field->field_options);
                    if (!isset($field->field_options['custom_html']) or empty($field->field_options['custom_html']) or stripslashes($field->field_options['custom_html']) == $default_html or stripslashes($field->field_options['custom_html']) == $old_default_html) {
                        $field->field_options['custom_html'] = $new_default_html;
                        $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array('id' => $field->id));
                    }
                    unset($field);
                }
                unset($default_html);
            }
            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
            FrmFormsController::add_default_templates(FRM_TEMPLATES_PATH);
            /***** SAVE DB VERSION *****/
            update_option('frm_db_version', $frm_db_version);
        }
        do_action('frm_after_install');
    }
Example #23
0
 public static function validate_check_confirmation_field(&$errors, $field, $value, $args)
 {
     $conf_val = '';
     // Temporarily swtich $field->id in order to get and set the value posted in confirmation field
     $field_id = $field->id;
     $field->id = 'conf_' . $field_id;
     FrmEntriesHelper::get_posted_value($field, $conf_val, $args);
     // Switch $field->id back to original id
     $field->id = $field_id;
     unset($field_id);
     //If editing entry or if user hits Next/Submit on a draft
     if ($args['action'] == 'update') {
         //If in repeating section
         if (isset($args['key_pointer']) && ($args['key_pointer'] || $args['key_pointer'] === 0)) {
             $entry_id = str_replace('i', '', $args['key_pointer']);
         } else {
             $entry_id = $_POST && isset($_POST['id']) ? $_POST['id'] : false;
         }
         $prev_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field->id);
         if ($prev_value != $value && $conf_val != $value) {
             $errors['conf_field' . $field->temp_id] = isset($field->field_options['conf_msg']) ? $field->field_options['conf_msg'] : __('The entered values do not match', 'formidable');
             $errors['field' . $field->temp_id] = '';
         }
     } else {
         if ($args['action'] == 'create' && $conf_val != $value) {
             //If creating entry
             $errors['conf_field' . $field->temp_id] = isset($field->field_options['conf_msg']) ? $field->field_options['conf_msg'] : __('The entered values do not match', 'formidable');
             $errors['field' . $field->temp_id] = '';
         }
     }
 }
Example #24
0
            <?php 
                                                }
                                            } else {
                                                ?>
                <option value="">&mdash; <?php 
                                                _e('This data is dynamic on change', 'formidable');
                                                ?>
 &mdash;</option>
            <?php 
                                            }
                                            ?>
        </select>
    <?php 
                                        } else {
                                            if ($field['data_type'] == 'data' && is_numeric($field['hide_opt'])) {
                                                echo FrmEntryMeta::get_entry_meta_by_field($field['hide_opt'], $field['form_select']);
                                            } else {
                                                if ($field['data_type'] == 'checkbox') {
                                                    $checked_values = $field['default_value'];
                                                    if ($field['options']) {
                                                        foreach ($field['options'] as $opt_key => $opt) {
                                                            $checked = FrmAppHelper::check_selected($checked_values, $opt_key) ? ' checked="checked"' : '';
                                                            ?>
                <label for="<?php 
                                                            echo $field_name;
                                                            ?>
"><input type="checkbox" name="<?php 
                                                            echo $field_name;
                                                            ?>
[]" id="<?php 
                                                            echo $field_name;
 private static function get_entry_link_entries($atts)
 {
     $s = FrmAppHelper::get_param('frm_search', false, 'get', 'sanitize_text_field');
     // Convert logged_in parameter to user_id for other functions
     $atts['user_id'] = false;
     if ($atts['logged_in']) {
         global $wpdb;
         $atts['user_id'] = get_current_user_id();
     }
     if ($s) {
         $entry_ids = FrmProEntriesHelper::get_search_ids($s, $atts['id'], array('is_draft' => $atts['drafts'], 'user_id' => $atts['user_id']));
     } else {
         $entry_ids = FrmEntryMeta::getEntryIds(array('fi.form_id' => (int) $atts['id']), '', '', true, array('is_draft' => $atts['drafts'], 'user_id' => $atts['user_id']));
     }
     if (empty($entry_ids)) {
         return;
     }
     $order = $atts['type'] == 'collapse' || $atts['order'] == 'DESC' ? ' ORDER BY it.created_at DESC' : '';
     $entries = FrmEntry::getAll(array('it.id' => $entry_ids), $order, '', true);
     return $entries;
 }
Example #26
0
 public static function get_meta_value($field_id, $entry)
 {
     _deprecated_function(__FUNCTION__, '2.0.9', 'FrmEntryMeta::get_meta_value');
     return FrmEntryMeta::get_meta_value($entry, $field_id);
 }
Example #27
0
 /**
  * After an entry is duplicated, also duplicate the sub entries
  * @since 2.0
  */
 public static function duplicate_sub_entries($entry_id, $form_id, $args)
 {
     $form_fields = FrmProFormsHelper::has_field('form', $form_id, false);
     $section_fields = FrmProFormsHelper::has_repeat_field($form_id, false);
     $form_fields = array_merge($section_fields, $form_fields);
     if (empty($form_fields)) {
         // there are no fields for child entries
         return;
     }
     $entry = FrmEntry::getOne($entry_id, true);
     $sub_ids = array();
     foreach ($form_fields as $field) {
         if (!isset($entry->metas[$field->id])) {
             continue;
         }
         $field_ids = array();
         $ids = maybe_unserialize($entry->metas[$field->id]);
         if (!empty($ids)) {
             // duplicate all entries for this field
             foreach ((array) $ids as $sub_id) {
                 $field_ids[] = FrmEntry::duplicate($sub_id);
                 unset($sub_id);
             }
             FrmEntryMeta::update_entry_meta($entry_id, $field->id, null, $field_ids);
             $sub_ids = array_merge($field_ids, $sub_ids);
         }
         unset($field, $field_ids);
     }
     if (!empty($sub_ids)) {
         // update the parent id for new entries
         global $wpdb;
         $where = array('id' => $sub_ids);
         FrmDb::get_where_clause_and_values($where);
         array_unshift($where['values'], $entry_id);
         $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'frm_items SET parent_item_id = %d ' . $where['where'], $where['values']));
     }
 }