function autoresponder($entry_id, $form_id)
 {
     if (defined('WP_IMPORTING')) {
         return;
     }
     global $frm_form, $frm_entry, $frm_entry_meta, $frm_notification;
     $form = $frm_form->getOne($form_id);
     $form_options = maybe_unserialize($form->options);
     if (!isset($form_options['auto_responder']) or !$form_options['auto_responder'] or !isset($form_options['ar_email_message']) or $form_options['ar_email_message'] == '') {
         return;
     }
     //don't continue forward unless a message has been inserted
     $entry = $frm_entry->getOne($entry_id, true);
     $entry_ids = array($entry->id);
     $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
     if (preg_match('/|/', $email_field)) {
         $email_fields = explode('|', $email_field);
         if (isset($email_fields[1])) {
             if (isset($entry->metas[$email_fields[0]])) {
                 $add_id = $entry->metas[$email_fields[0]];
                 $add_id = maybe_unserialize($add_id);
                 if (is_array($add_id)) {
                     foreach ($add_id as $add) {
                         $entry_ids[] = $add;
                     }
                 } else {
                     $entry_ids[] = $add_id;
                 }
             }
             $email_field = $email_fields[1];
         }
         unset($email_fields);
     }
     $inc_fields = array();
     foreach (array($email_field) as $inc_field) {
         if ($inc_field) {
             $inc_fields[] = $inc_field;
         }
     }
     $where = "it.item_id in (" . implode(',', $entry_ids) . ")";
     if (!empty($inc_fields)) {
         $inc_fields = implode(',', $inc_fields);
         $where .= " and it.field_id in ({$inc_fields})";
     }
     $values = $frm_entry_meta->getAll($where, " ORDER BY fi.field_order");
     $plain_text = (isset($form_options['ar_plain_text']) and $form_options['ar_plain_text']) ? true : false;
     $message = apply_filters('frm_ar_message', $form_options['ar_email_message'], array('entry' => $entry, 'form' => $form));
     $shortcodes = FrmProAppHelper::get_shortcodes($message, $form_id);
     $mail_body = FrmProFieldsHelper::replace_shortcodes($message, $entry, $shortcodes);
     $frm_blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $reply_to_name = isset($form_options['ar_reply_to_name']) ? $form_options['ar_reply_to_name'] : $frm_blogname;
     //default sender name
     $reply_to = isset($form_options['ar_reply_to']) ? $form_options['ar_reply_to'] : '[admin_email]';
     //default sender email
     foreach ($values as $value) {
         /*
                     if((int)$reply_field == $value->field_id){
                         if($value->field_type == 'user_id'){
                             $user_data = get_userdata($value->meta_value);
                             $reply_to = $user_data->user_email;
                         }else{
                             $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                             if(is_email($val))
                                 $reply_to = $val;
                         }
                     }
                     
                     if((int)$reply_name_field == $value->field_id){
                         if($value->field_type == 'user_id'){
                             $user_data = get_userdata($value->meta_value);
                             $reply_to_name = $user_data->display_name;
                         }else
                             $reply_to_name = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                     } */
         if ((int) $email_field == $value->field_id) {
             if ($value->field_type == 'user_id') {
                 $user_data = get_userdata($value->meta_value);
                 $to_email = $user_data->user_email;
             } else {
                 $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                 if (is_email($val)) {
                     $to_email = $val;
                 }
             }
         }
     }
     if (!isset($to_email)) {
         return;
     }
     if (isset($form_options['ar_email_subject']) and $form_options['ar_email_subject'] != '') {
         $shortcodes = FrmProAppHelper::get_shortcodes($form_options['ar_email_subject'], $form_id);
         $subject = FrmProFieldsHelper::replace_shortcodes($form_options['ar_email_subject'], $entry, $shortcodes);
     } else {
         $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), stripslashes($form->name), $frm_blogname);
         //subject
     }
     $attachments = apply_filters('frm_autoresponder_attachment', array(), $form);
     $frm_notification->send_notification_email($to_email, $subject, $mail_body, $reply_to, $reply_to_name, $plain_text, $attachments);
     return $to_email;
 }
 public static function do_mergetags($string, $form_id, $entry_id)
 {
     global $frm_entry;
     /* strip {all_fields} merge tag from $string */
     $string = str_replace('[default-message]', '', $string);
     $entry = $frm_entry->getOne($entry_id, true);
     $shortcodes = FrmProAppHelper::get_shortcodes($string, $form_id);
     return FrmProFieldsHelper::replace_shortcodes($string, $entry, $shortcodes);
 }
 public static function filter_content($content, $form, $entry = false)
 {
     if ($entry and is_numeric($entry)) {
         global $frm_entry;
         $entry = $frm_entry->getOne($entry);
     } else {
         $entry_id = (isset($_POST) and isset($_POST['id'])) ? $_POST['id'] : false;
         if ($entry_id) {
             global $frm_entry;
             $entry = $frm_entry->getOne($entry_id);
         }
     }
     if (!$entry) {
         return $content;
     }
     if (is_object($form)) {
         $form = $form->id;
     }
     $shortcodes = FrmProAppHelper::get_shortcodes($content, $form);
     $content = FrmProFieldsHelper::replace_shortcodes($content, $entry, $shortcodes);
     return $content;
 }