function send_webhook()
 {
     $entry = $this->get_entry();
     $url = $this->url;
     $this->log_debug(__METHOD__ . '() - url before replacing variables: ' . $url);
     $url = GFCommon::replace_variables($url, $this->get_form(), $entry, true, false, false, 'text');
     $this->log_debug(__METHOD__ . '() - url after replacing variables: ' . $url);
     $method = strtoupper($this->method);
     $body = null;
     $headers = array();
     if (in_array($method, array('POST', 'PUT'))) {
         if ($this->format == 'json') {
             $headers = array('Content-type' => 'application/json');
             $body = json_encode($entry);
         } else {
             $headers = array();
             $body = $entry;
         }
     }
     $args = array('method' => $method, 'timeout' => 45, 'redirection' => 3, 'blocking' => true, 'headers' => $headers, 'body' => $body, 'cookies' => array());
     $args = apply_filters('gravityflow_webhook_args', $args, $entry, $this);
     $response = wp_remote_request($url, $args);
     $this->log_debug(__METHOD__ . '() - response: ' . print_r($response, true));
     if (is_wp_error($response)) {
         $step_status = 'error';
     } else {
         $step_status = 'success';
     }
     $note = esc_html__('Webhook sent. Url: ' . $url);
     $this->add_note($note, 0, 'webhook');
     do_action('gravityflow_post_webhook', $response, $args, $entry, $this);
     return $step_status;
 }
 /**
  * Check for merge tags before passing to Gravity Forms to improve speed.
  *
  * GF doesn't check for whether `{` exists before it starts diving in. They not only replace fields, they do `str_replace()` on things like ip address, which is a lot of work just to check if there's any hint of a replacement variable.
  *
  * We check for the basics first, which is more efficient.
  *
  * @since 1.8.4 - Moved to GravityView_Merge_Tags
  * @since 1.15.1 - Add support for $url_encode and $esc_html arguments
  *
  * @param  string      $text       Text to replace variables in
  * @param  array      $form        GF Form array
  * @param  array      $entry        GF Entry array
  * @param  bool       $url_encode   Pass return value through `url_encode()`
  * @param  bool       $esc_html     Pass return value through `esc_html()`
  * @return string                  Text with variables maybe replaced
  */
 public static function replace_variables($text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true)
 {
     /**
      * @filter `gravityview_do_replace_variables` Turn off merge tag variable replacements.\n
      * Useful where you want to process variables yourself. We do this in the Math Extension.
      * @since 1.13
      * @param[in,out] boolean $do_replace_variables True: yes, replace variables for this text; False: do not replace variables.
      * @param[in] string $text       Text to replace variables in
      * @param[in]  array      $form        GF Form array
      * @param[in]  array      $entry        GF Entry array
      */
     $do_replace_variables = apply_filters('gravityview/merge_tags/do_replace_variables', true, $text, $form, $entry);
     if (strpos($text, '{') === false || !$do_replace_variables) {
         return $text;
     }
     /**
      * Replace GravityView merge tags before going to Gravity Forms
      * This allows us to replace our tags first.
      * @since 1.15
      */
     $text = self::replace_gv_merge_tags($text, $form, $entry);
     // Check for fields - if they exist, we let Gravity Forms handle it.
     preg_match_all('/{[^{]*?:(\\d+(\\.\\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER);
     if (empty($matches)) {
         // Check for form variables
         if (!preg_match('/\\{(all_fields(:(.*?))?|all_fields_display_empty|pricing_fields|form_title|entry_url|ip|post_id|admin_email|post_edit_url|form_id|entry_id|embed_url|date_mdy|date_dmy|embed_post:(.*?)|custom_field:(.*?)|user_agent|referer|gv:(.*?)|get:(.*?)|user:(.*?)|created_by:(.*?))\\}/ism', $text)) {
             return $text;
         }
     }
     return GFCommon::replace_variables($text, $form, $entry, $url_encode, $esc_html);
 }
 function replace_merge_tags($post_content)
 {
     $entry = $this->get_entry();
     if (!$entry) {
         return $post_content;
     }
     $form = GFFormsModel::get_form_meta($entry['form_id']);
     $post_content = $this->replace_field_label_merge_tags($post_content, $form);
     $post_content = GFCommon::replace_variables($post_content, $form, $entry, false, false, false);
     return $post_content;
 }
 /**
  * Check for merge tags before passing to Gravity Forms to improve speed.
  *
  * GF doesn't check for whether `{` exists before it starts diving in. They not only replace fields, they do `str_replace()` on things like ip address, which is a lot of work just to check if there's any hint of a replacement variable.
  *
  * We check for the basics first, which is more efficient.
  *
  * @since 1.8.4 - Moved to GravityView_Merge_Tags
  *
  * @param  string      $text       Text to replace variables in
  * @param  array      $form        GF Form array
  * @param  array      $entry        GF Entry array
  * @return string                  Text with variables maybe replaced
  */
 public static function replace_variables($text, $form, $entry)
 {
     if (strpos($text, '{') === false) {
         return $text;
     }
     // Check for fields - if they exist, we let Gravity Forms handle it.
     preg_match_all('/{[^{]*?:(\\d+(\\.\\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER);
     if (empty($matches)) {
         // Check for form variables
         if (!preg_match('/\\{(all_fields(:(.*?))?|pricing_fields|form_title|entry_url|ip|post_id|admin_email|post_edit_url|form_id|entry_id|embed_url|date_mdy|date_dmy|embed_post:(.*?)|custom_field:(.*?)|user_agent|referer|gv:(.*?)|user:(.*?)|created_by:(.*?))\\}/ism', $text)) {
             return $text;
         }
     }
     return GFCommon::replace_variables($text, $form, $entry, false, false, false, "html");
 }
 /**
  * We want to make sure that GravityView doesn't mess with Texas
  * @since 1.15.1
  */
 function test_gf_merge_tags()
 {
     remove_all_filters('gform_pre_replace_merge_tags');
     remove_all_filters('gform_merge_tag_filter');
     global $post;
     $form = $this->factory->form->create_and_get();
     $post = $this->factory->post->create_and_get();
     $entry = $this->factory->entry->create_and_get(array('post_id' => $post->ID, 'form_id' => $form['id']));
     $tests = array('{form_title}' => $form['title'], '{entry_id}' => $entry['id'], '{entry_url}' => get_bloginfo('wpurl') . '/wp-admin/admin.php?page=gf_entries&view=entry&id=' . $form['id'] . '&lid=' . rgar($entry, 'id'), '{admin_email}' => get_bloginfo('admin_email'), '{post_id}' => $post->ID, '{embed_post:post_title}' => $post->post_title);
     foreach ($tests as $merge_tag => $expected) {
         $this->assertEquals($expected, GravityView_Merge_Tags::replace_variables($merge_tag, $form, $entry));
         $this->assertEquals(urlencode($expected), GravityView_Merge_Tags::replace_variables($merge_tag, $form, $entry, true));
         remove_filter('gform_replace_merge_tags', array('GravityView_Merge_Tags', 'replace_gv_merge_tags'), 10);
         $this->assertEquals($expected, GFCommon::replace_variables($merge_tag, $form, $entry));
         $this->assertEquals(urlencode($expected), GFCommon::replace_variables($merge_tag, $form, $entry, true));
         add_filter('gform_replace_merge_tags', array('GravityView_Merge_Tags', 'replace_gv_merge_tags'), 10, 7);
     }
     wp_reset_postdata();
 }
 public static function handle_confirmation($form, $lead, $ajax = false)
 {
     if ($form["confirmation"]["type"] == "message") {
         $default_anchor = self::has_pages($form) ? 1 : 0;
         $anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)) ? "<a id='gf_{$form["id"]}' name='gf_{$form["id"]}' class='gform_anchor' ></a>" : "";
         $nl2br = rgar($form["confirmation"], "disableAutoformat") ? false : true;
         $confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gforms_confirmation_message' class='gform_confirmation_message_{$form["id"]}'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "</div>";
     } else {
         if (!empty($form["confirmation"]["pageId"])) {
             $url = get_permalink($form["confirmation"]["pageId"]);
         } else {
             $url = GFCommon::replace_variables(trim($form["confirmation"]["url"]), $form, $lead, false, true);
             $url_info = parse_url($url);
             $query_string = $url_info["query"];
             $dynamic_query = GFCommon::replace_variables(trim($form["confirmation"]["queryString"]), $form, $lead, true);
             $query_string .= empty($url_info["query"]) || empty($dynamic_query) ? $dynamic_query : "&" . $dynamic_query;
             if (!empty($url_info["fragment"])) {
                 $query_string .= "#" . $url_info["fragment"];
             }
             $url = $url_info["scheme"] . "://" . $url_info["host"];
             if (!empty($url_info["port"])) {
                 $url .= ":{$url_info["port"]}";
             }
             $url .= rgar($url_info, "path");
             if (!empty($query_string)) {
                 $url .= "?{$query_string}";
             }
         }
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($url, $ajax);
         } else {
             $confirmation = array("redirect" => $url);
         }
     }
     $confirmation = apply_filters("gform_confirmation_{$form["id"]}", apply_filters("gform_confirmation", $confirmation, $form, $lead, $ajax), $form, $lead, $ajax);
     if (!is_array($confirmation)) {
         $confirmation = GFCommon::gform_do_shortcode($confirmation);
         //enabling shortcodes
     } else {
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($confirmation["redirect"], $ajax);
             //redirecting via client side
         }
     }
     return $confirmation;
 }
Beispiel #7
0
 public static function handle_save_email_confirmation($form, $ajax)
 {
     $resume_email = $_POST['gform_resume_email'];
     if (!GFCommon::is_valid_email($resume_email)) {
         GFCommon::log_debug('GFFormDisplay::handle_save_email_confirmation(): Invalid email address: ' . $resume_email);
         return new WP_Error('invalid_email');
     }
     $resume_token = $_POST['gform_resume_token'];
     $submission_details = GFFormsModel::get_incomplete_submission_values($resume_token);
     $submission_json = $submission_details['submission'];
     $submission = json_decode($submission_json, true);
     $entry = $submission['partial_entry'];
     $form = self::update_confirmation($form, $entry, 'form_save_email_sent');
     $confirmation = '<div class="form_saved_message_sent"><span>' . rgar($form['confirmation'], 'message') . '</span></div>';
     $nl2br = rgar($form['confirmation'], 'disableAutoformat') ? false : true;
     $save_email_confirmation = self::replace_save_variables($confirmation, $form, $resume_token, $resume_email);
     $save_email_confirmation = GFCommon::replace_variables($save_email_confirmation, $form, $entry, false, true, $nl2br);
     $save_email_confirmation = GFCommon::gform_do_shortcode($save_email_confirmation);
     $form_id = absint($form['id']);
     $has_pages = self::has_pages($form);
     $default_anchor = $has_pages || $ajax ? true : false;
     $use_anchor = gf_apply_filters(array('gform_confirmation_anchor', $form_id), $default_anchor);
     if ($use_anchor !== false) {
         $save_email_confirmation = "<a id='gf_{$form_id}' class='gform_anchor' ></a>" . $save_email_confirmation;
     }
     if ($ajax) {
         $save_email_confirmation = "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'>" . $save_email_confirmation . '</body></html>';
     }
     GFCommon::log_debug('GFFormDisplay::handle_save_email_confirmation(): Confirmation => ' . print_r($save_email_confirmation, true));
     return $save_email_confirmation;
 }
 public static function create_post($form, &$lead)
 {
     $has_post_field = false;
     foreach ($form["fields"] as $field) {
         $is_hidden = self::is_field_hidden($form, $field, array(), $lead);
         if (!$is_hidden && in_array($field["type"], array("post_category", "post_title", "post_content", "post_excerpt", "post_tags", "post_custom_field", "post_image"))) {
             $has_post_field = true;
             break;
         }
     }
     //if this form does not have any post fields, don't create a post
     if (!$has_post_field) {
         return $lead;
     }
     //processing post fields
     $post_data = self::get_post_fields($form, $lead);
     //allowing users to change post fields before post gets created
     $post_data = apply_filters("gform_post_data_{$form["id"]}", apply_filters("gform_post_data", $post_data, $form, $lead), $form, $lead);
     //adding default title if none of the required post fields are in the form (will make sure wp_insert_post() inserts the post)
     if (empty($post_data["post_title"]) && empty($post_data["post_content"]) && empty($post_data["post_excerpt"])) {
         $post_data["post_title"] = self::get_default_post_title();
     }
     //inserting post
     if (GFCommon::is_bp_active()) {
         //disable buddy press action so save_post is not called because the post data is not yet complete at this point
         remove_action("save_post", "bp_blogs_record_post");
     }
     $post_id = wp_insert_post($post_data);
     //adding form id and entry id hidden custom fields
     add_post_meta($post_id, "_gform-form-id", $form["id"]);
     add_post_meta($post_id, "_gform-entry-id", $lead["id"]);
     //creating post images
     $post_images = array();
     foreach ($post_data["images"] as $image) {
         $image_meta = array("post_excerpt" => $image["caption"], "post_content" => $image["description"]);
         //adding title only if it is not empty. It will default to the file name if it is not in the array
         if (!empty($image["title"])) {
             $image_meta["post_title"] = $image["title"];
         }
         if (!empty($image["url"])) {
             $media_id = self::media_handle_upload($image["url"], $post_id, $image_meta);
             if ($media_id) {
                 //save media id for post body/title template variable replacement (below)
                 $post_images[$image["field_id"]] = $media_id;
                 $lead[$image["field_id"]] .= "|:|{$media_id}";
                 // set featured image
                 $field = RGFormsModel::get_field($form, $image["field_id"]);
                 if (rgar($field, 'postFeaturedImage')) {
                     set_post_thumbnail($post_id, $media_id);
                 }
             }
         }
     }
     //adding custom fields
     foreach ($post_data["post_custom_fields"] as $meta_name => $meta_value) {
         if (!is_array($meta_value)) {
             $meta_value = array($meta_value);
         }
         $meta_index = 0;
         foreach ($meta_value as $value) {
             $custom_field = self::get_custom_field($form, $meta_name, $meta_index);
             //replacing template variables if template is enabled
             if ($custom_field && rgget("customFieldTemplateEnabled", $custom_field)) {
                 //replacing post image variables
                 $value = GFCommon::replace_variables_post_image($custom_field["customFieldTemplate"], $post_images, $lead);
                 //replacing all other variables
                 $value = GFCommon::replace_variables($value, $form, $lead, false, false, false);
                 // replace conditional shortcodes
                 $value = do_shortcode($value);
             }
             switch (RGFormsModel::get_input_type($custom_field)) {
                 case "list":
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (is_array($item)) {
                                 $item = implode("|", $item);
                             }
                             if (!rgblank($item)) {
                                 add_post_meta($post_id, $meta_name, $item);
                             }
                         }
                     }
                     break;
                 case "multiselect":
                 case "checkbox":
                     $value = explode(",", $value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (!rgblank($item)) {
                                 add_post_meta($post_id, $meta_name, $item);
                             }
                         }
                     }
                     break;
                 case "date":
                     $value = GFCommon::date_display($value, rgar($custom_field, "dateFormat"));
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
                 default:
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
             }
             $meta_index++;
         }
     }
     $has_content_field = sizeof(GFCommon::get_fields_by_type($form, array("post_content"))) > 0;
     $has_title_field = sizeof(GFCommon::get_fields_by_type($form, array("post_title"))) > 0;
     //if a post field was configured with a content or title template, process template
     if (rgar($form, "postContentTemplateEnabled") && $has_content_field || rgar($form, "postTitleTemplateEnabled") && $has_title_field) {
         $post = get_post($post_id);
         if ($form["postContentTemplateEnabled"] && $has_content_field) {
             //replacing post image variables
             $post_content = GFCommon::replace_variables_post_image($form["postContentTemplate"], $post_images, $lead);
             //replacing all other variables
             $post_content = GFCommon::replace_variables($post_content, $form, $lead, false, false, false);
             //updating post content
             $post->post_content = $post_content;
         }
         if ($form["postTitleTemplateEnabled"] && $has_title_field) {
             //replacing post image variables
             $post_title = GFCommon::replace_variables_post_image($form["postTitleTemplate"], $post_images, $lead);
             //replacing all other variables
             $post_title = GFCommon::replace_variables($post_title, $form, $lead, false, false, false);
             // replace conditional shortcodes
             $post_title = do_shortcode($post_title);
             //updating post
             $post->post_title = $post_title;
             $post->post_name = $post_title;
         }
         if (GFCommon::is_bp_active()) {
             //re-enable buddy press action for save_post since the post data is complete at this point
             add_action('save_post', 'bp_blogs_record_post', 10, 2);
         }
         wp_update_post($post);
     }
     //adding post format
     if (current_theme_supports('post-formats') && rgar($form, 'postFormat')) {
         $formats = get_theme_support('post-formats');
         $post_format = rgar($form, 'postFormat');
         if (is_array($formats)) {
             $formats = $formats[0];
             if (in_array($post_format, $formats)) {
                 set_post_format($post_id, $post_format);
             } else {
                 if ('0' == $post_format) {
                     set_post_format($post_id, false);
                 }
             }
         }
     }
     //update post_id field if a post was created
     $lead["post_id"] = $post_id;
     self::update_lead($lead);
     return $post_id;
 }
 /**
  * Process feed.
  * 
  * @access public
  * @param array $feed
  * @param array $entry
  * @param array $form
  * @return void
  */
 public function process_feed($feed, $entry, $form)
 {
     $this->log_debug(__METHOD__ . '(): Processing feed.');
     /* If HipChat instance is not initialized, exit. */
     if (!$this->initialize_api()) {
         $this->add_feed_error(esc_html__('Feed was not processed because API was not initialized.', 'gravityformsslack'), $feed, $entry, $form);
         return;
     }
     /* Prepare notification array. */
     $notification = array('color' => $feed['meta']['color'], 'from' => 'Gravity Forms', 'message' => $feed['meta']['message'], 'notify' => $feed['meta']['notify'], 'room_id' => $feed['meta']['room']);
     /* Replace merge tags on notification message. */
     $notification['message'] = GFCommon::replace_variables($notification['message'], $form, $entry);
     /* Strip unallowed tags */
     $notification['message'] = strip_tags($notification['message'], '<a><b><i><strong><em><br><img><pre><code><lists><tables>');
     /* If message is empty, exit. */
     if (rgblank($notification['message'])) {
         $this->add_feed_error(esc_html__('Notification was not posted to room because message was empty.', 'gravityformshipchat'), $feed, $entry, $form);
         return;
     }
     /* If message is too long, cut it off at 10,000 characters. */
     if (strlen($notification['message']) > 10000) {
         $notification['message'] = substr($notification['message'], 0, 10000);
     }
     /* Post notification to room. */
     $this->log_debug(__METHOD__ . '(): Posting notification: ' . print_r($notification, true));
     $notify_room = $this->api->notify_room($notification);
     if (isset($notify_room['status']) && $notify_room['status'] == 'sent') {
         $this->log_debug(__METHOD__ . '(): Notification was posted to room.');
     } else {
         $this->add_feed_error(esc_html__('Notification was not posted to room.', 'gravityformshipchat'), $feed, $entry, $form);
     }
 }
Beispiel #10
0
 public static function handle_confirmation($form, $lead, $ajax = false)
 {
     //run the function to populate the legacy confirmation format to be safe
     $form = self::update_confirmation($form, $lead);
     if ($form["confirmation"]["type"] == "message") {
         $default_anchor = self::has_pages($form) ? 1 : 0;
         $anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)) ? "<a id='gf_{$form["id"]}' name='gf_{$form["id"]}' class='gform_anchor' ></a>" : "";
         $nl2br = rgar($form["confirmation"], "disableAutoformat") ? false : true;
         $cssClass = rgar($form, "cssClass");
         if (function_exists('qtranxf_getLanguage') && !empty($form["confirmation"]["message"])) {
             $form["confirmation"]["message"] = apply_filters('the_title', $form["confirmation"]["message"]);
         }
         //$confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gform_confirmation_wrapper_{$form["id"]}' class='gform_confirmation_wrapper {$cssClass}'><div id='gforms_confirmation_message' class='gform_confirmation_message_{$form["id"]}'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "</div></div>";
         $confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gform_confirmation_wrapper_{$form["id"]}' class='validation_error alert alert-danger alert-dismissible fade in gform_confirmation_wrapper {$cssClass}'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button><div id='gforms_confirmation_message' class='gform_confirmation_message_{$form["id"]}'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "<a onclick='document.location.reload(true)'> Please, click to proceed</a></div></div>";
     } else {
         if (!empty($form["confirmation"]["pageId"])) {
             $url = get_permalink($form["confirmation"]["pageId"]);
         } else {
             $url = GFCommon::replace_variables(trim($form["confirmation"]["url"]), $form, $lead, false, true);
             $url_info = parse_url($url);
             $query_string = $url_info["query"];
             $dynamic_query = GFCommon::replace_variables(trim($form["confirmation"]["queryString"]), $form, $lead, true);
             $query_string .= empty($url_info["query"]) || empty($dynamic_query) ? $dynamic_query : "&" . $dynamic_query;
             if (!empty($url_info["fragment"])) {
                 $query_string .= "#" . $url_info["fragment"];
             }
             $url = $url_info["scheme"] . "://" . $url_info["host"];
             if (!empty($url_info["port"])) {
                 $url .= ":{$url_info["port"]}";
             }
             $url .= rgar($url_info, "path");
             if (!empty($query_string)) {
                 $url .= "?{$query_string}";
             }
         }
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($url, $ajax);
         } else {
             $confirmation = array("redirect" => $url);
         }
     }
     $confirmation = apply_filters("gform_confirmation_{$form["id"]}", apply_filters("gform_confirmation", $confirmation, $form, $lead, $ajax), $form, $lead, $ajax);
     if (!is_array($confirmation)) {
         $confirmation = GFCommon::gform_do_shortcode($confirmation);
         //enabling shortcodes
     } else {
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($confirmation["redirect"], $ajax);
             //redirecting via client side
         }
     }
     return $confirmation;
 }
Beispiel #11
0
 public static function send_admin_notification($form, $lead)
 {
     $form_id = $form["id"];
     //handling admin notification email
     $subject = GFCommon::replace_variables($form["notification"]["subject"], $form, $lead, false, false);
     $message = GFCommon::replace_variables($form["notification"]["message"], $form, $lead, false, false, !$form["notification"]["disableAutoformat"]);
     $message = do_shortcode($message);
     $from = empty($form["notification"]["fromField"]) ? $form["notification"]["from"] : $lead[$form["notification"]["fromField"]];
     if (empty($form["notification"]["fromNameField"])) {
         $from_name = $form["notification"]["fromName"];
     } else {
         $field = RGFormsModel::get_field($form, $form["notification"]["fromNameField"]);
         $value = RGFormsModel::get_lead_field_value($lead, $field);
         $from_name = GFCommon::get_lead_field_display($field, $value);
     }
     $replyTo = empty($form["notification"]["replyToField"]) ? $form["notification"]["replyTo"] : $lead[$form["notification"]["replyToField"]];
     if (empty($form["notification"]["routing"])) {
         $email_to = $form["notification"]["to"];
     } else {
         $email_to = array();
         foreach ($form["notification"]["routing"] as $routing) {
             $source_field = RGFormsModel::get_field($form, $routing["fieldId"]);
             $field_value = RGFormsModel::get_field_value($source_field, array());
             $is_value_match = is_array($field_value) ? in_array($routing["value"], $field_value) : $field_value == $routing["value"];
             if ($routing["operator"] == "is" && $is_value_match || $routing["operator"] == "isnot" && !$is_value_match) {
                 $email_to[] = $routing["email"];
             }
         }
         $email_to = join(",", $email_to);
     }
     //Running through variable replacement
     $email_to = GFCommon::replace_variables($email_to, $form, $lead, false, false);
     $from = GFCommon::replace_variables($from, $form, $lead, false, false);
     $bcc = GFCommon::replace_variables($form["notification"]["bcc"], $form, $lead, false, false);
     $reply_to = GFCommon::replace_variables($replyTo, $form, $lead, false, false);
     $from_name = GFCommon::replace_variables($from_name, $form, $lead, false, false);
     //Filters the admin notification email to address. Allows users to change email address before notification is sent
     $to = apply_filters("gform_notification_email_{$form_id}", apply_filters("gform_notification_email", $email_to, $lead), $lead);
     self::send_email($from, $to, $bcc, $replyTo, $subject, $message, $from_name);
 }
Beispiel #12
0
    public static function lead_detail_page()
    {
        global $wpdb;
        global $current_user;
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        echo GFCommon::get_remote_message();
        $form = RGFormsModel::get_form_meta($_GET["id"]);
        $lead = RGFormsModel::get_lead($_GET["lid"]);
        if (!$lead) {
            _e("OOps! We couldn't find your lead. Please try again", "gravityforms");
            return;
        }
        RGFormsModel::update_lead_property($lead["id"], "is_read", 1);
        $search_qs = empty($_GET["s"]) ? "" : "&s=" . $_GET["s"];
        $sort_qs = empty($_GET["sort"]) ? "" : "&sort=" . $_GET["sort"];
        $dir_qs = empty($_GET["dir"]) ? "" : "&dir=" . $_GET["dir"];
        $page_qs = empty($_GET["paged"]) ? "" : "&paged=" . absint($_GET["paged"]);
        switch (RGForms::post("action")) {
            case "update":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::save_lead($form, $lead);
                $lead = RGFormsModel::get_lead($_GET["lid"]);
                break;
            case "add_note":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["new_note"]));
                //emailing notes if configured
                if (rgpost("gentry_email_notes_to")) {
                    $email_to = $_POST["gentry_email_notes_to"];
                    $email_from = $current_user->user_email;
                    $email_subject = stripslashes($_POST["gentry_email_subject"]);
                    $headers = "From: \"{$email_from}\" <{$email_from}> \r\n";
                    $result = wp_mail($email_to, $email_subject, stripslashes($_POST["new_note"]), $headers);
                }
                break;
            case "add_quick_note":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["quick_note"]));
                break;
            case "bulk":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                if ($_POST["bulk_action"] == "delete") {
                    RGFormsModel::delete_notes($_POST["note"]);
                }
                break;
            case "delete":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::delete_lead($lead["id"]);
                ?>
                <div id="message" class="updated fade" style="background-color: rgb(255, 251, 204); margin-top:50px; padding:50px;">
                    <?php 
                _e("Entry has been deleted.", "gravityforms");
                ?>
 <a href="<?php 
                echo esc_url("admin.php?page=gf_entries&view=entries&id=" . absint($form["id"]) . $search_qs . $sort_qs . $dir_qs . $page_qs);
                ?>
"><?php 
                _e("Back to entries list", "gravityforms");
                ?>
</a>
                </div>
                <?php 
                exit;
                break;
        }
        $mode = empty($_POST["screen_mode"]) ? "view" : $_POST["screen_mode"];
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css" />
        <script type="text/javascript">

            function DeleteFile(leadId, fieldId){
                if(confirm(<?php 
        _e("'Would you like to delete this file? \\'Cancel\\' to stop. \\'OK\\' to delete'", "gravityforms");
        ?>
)){

                    var mysack = new sack("<?php 
        echo admin_url("admin-ajax.php");
        ?>
");
                    mysack.execute = 1;
                    mysack.method = 'POST';
                    mysack.setVar( "action", "rg_delete_file" );
                    mysack.setVar( "rg_delete_file", "<?php 
        echo wp_create_nonce("rg_delete_file");
        ?>
" );
                    mysack.setVar( "lead_id", leadId );
                    mysack.setVar( "field_id", fieldId );
                    mysack.encVar( "cookie", document.cookie, false );
                    mysack.onError = function() { alert('<?php 
        echo esc_js(__("Ajax error while deleting field.", "gravityforms"));
        ?>
' )};
                    mysack.runAJAX();

                    return true;
                }
            }

            function EndDeleteFile(fieldId){
                jQuery('#preview_' + fieldId).hide();
                jQuery('#upload_' + fieldId).show('slow');
            }

            function ToggleShowEmptyFields(){
                if(jQuery("#gentry_display_empty_fields").is(":checked")){
                    createCookie("gf_display_empty_fields", true, 10000);
                    document.location = document.location.href;
                }
                else{
                    eraseCookie("gf_display_empty_fields");
                    document.location = document.location.href;
                }
            }

            function createCookie(name,value,days) {
                if (days) {
                    var date = new Date();
                    date.setTime(date.getTime()+(days*24*60*60*1000));
                    var expires = "; expires="+date.toGMTString();
                }
                else var expires = "";
                document.cookie = name+"="+value+expires+"; path=/";
            }

            function eraseCookie(name) {
                createCookie(name,"",-1);
            }

        </script>

        <form method="post" id="entry_form" enctype='multipart/form-data'>
            <?php 
        wp_nonce_field('gforms_save_entry', 'gforms_save_entry');
        ?>
            <input type="hidden" name="action" id="action" value=""/>
            <input type="hidden" name="screen_mode" id="screen_mode" value="<?php 
        echo esc_attr(rgpost("screen_mode"));
        ?>
" />

            <div class="wrap">
            <img alt="<?php 
        _e("Gravity Forms", "gravityforms");
        ?>
" src="<?php 
        echo GFCommon::get_base_url();
        ?>
/images/gravity-title-icon-32.png" style="float:left; margin:15px 7px 0 0;"/>
            <h2><?php 
        _e("Entry #", "gravityforms");
        echo absint($lead["id"]);
        ?>
</h2>
            <a href="<?php 
        echo esc_url("admin.php?page=gf_entries&view=entries&id=" . absint($form["id"]) . $search_qs . $sort_qs . $dir_qs . $page_qs);
        ?>
"><?php 
        _e("&laquo; back to entries list", "gravityforms");
        ?>
</a>
            <div id="poststuff" class="metabox-holder has-right-sidebar">
                <div id="side-info-column" class="inner-sidebar">
                    <div id="submitdiv" class="stuffbox">
                        <h3>
                            <span class="hndle"><?php 
        _e("Info", "gravityforms");
        ?>
</span>
                        </h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">
                                <div id="minor-publishing" style="padding:10px;">
                                    <br/>
                                    <?php 
        _e("Entry Id", "gravityforms");
        ?>
: <?php 
        echo absint($lead["id"]);
        ?>
<br/><br/>
                                    <?php 
        _e("Submitted on", "gravityforms");
        ?>
: <?php 
        echo esc_html(GFCommon::format_date($lead["date_created"], false, "Y/m/d"));
        ?>
                                    <br/><br/>
                                    <?php 
        _e("User IP", "gravityforms");
        ?>
: <?php 
        echo $lead["ip"];
        ?>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["created_by"]) && ($usermeta = get_userdata($lead["created_by"]))) {
            ?>
                                        <?php 
            _e("User", "gravityforms");
            ?>
: <a href="user-edit.php?user_id=<?php 
            echo absint($lead["created_by"]);
            ?>
" alt="<?php 
            _e("View user profile", "gravityforms");
            ?>
" title="<?php 
            _e("View user profile", "gravityforms");
            ?>
"><?php 
            echo esc_html($usermeta->user_login);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        ?>

                                    <?php 
        _e("Embed Url", "gravityforms");
        ?>
: <a href="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" target="_blank" alt="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" title="<?php 
        echo esc_url($lead["source_url"]);
        ?>
">.../<?php 
        echo esc_html(GFCommon::truncate_url($lead["source_url"]));
        ?>
</a>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["post_id"])) {
            $post = get_post($lead["post_id"]);
            ?>
                                        <?php 
            _e("Edit Post", "gravityforms");
            ?>
: <a href="post.php?action=edit&post=<?php 
            echo absint($post->ID);
            ?>
" alt="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
" title="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
"><?php 
            echo esc_html($post->post_title);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        if (!empty($lead["payment_status"])) {
            echo $lead["transaction_type"] != 2 ? __("Payment Status", "gravityforms") : __("Subscription Status", "gravityforms");
            ?>
: <?php 
            echo $lead["payment_status"];
            ?>
                                        <br/><br/>
                                        <?php 
            if (!empty($lead["payment_date"])) {
                echo $lead["transaction_type"] == 1 ? __("Payment Date", "gravityforms") : __("Start Date", "gravityforms");
                ?>
: <?php 
                echo GFCommon::format_date($lead["payment_date"], false, "Y/m/d", $lead["transaction_type"] == 1);
                ?>
                                            <br/><br/>
                                            <?php 
            }
            if (!empty($lead["transaction_id"])) {
                echo $lead["transaction_type"] == 1 ? __("Transaction Id", "gravityforms") : __("Subscriber Id", "gravityforms");
                ?>
: <?php 
                echo $lead["transaction_id"];
                ?>
                                            <br/><br/>
                                            <?php 
            }
            if (strlen($lead["payment_amount"]) > 0) {
                echo $lead["transaction_type"] == 1 ? __("Payment Amount", "gravityforms") : __("Subscription Amount", "gravityforms");
                ?>
: <?php 
                echo GFCommon::to_money($lead["payment_amount"], $lead["currency"]);
                ?>
                                            <br/><br/>
                                            <?php 
            }
        }
        do_action("gform_entry_info", $form["id"], $lead);
        ?>
                                </div>
                                <div id="major-publishing-actions">
                                    <div id="delete-action">
                                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
            $delete_link = '<a class="submitdelete deletion" onclick="if ( confirm(\'' . __("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", "gravityforms") . '\') ) { jQuery(\'#action\').val(\'delete\'); jQuery(\'#entry_form\')[0].submit();} return false;" href="#">' . __("Delete", "gravityforms") . '</a>';
            echo apply_filters("gform_entrydetail_delete_link", $delete_link);
        }
        ?>
                                    </div>
                                    <div id="publishing-action">
                                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entries")) {
            $button_text = $mode == "view" ? __("Edit Entry", "gravityforms") : __("Update Entry", "gravityforms");
            $button_click = $mode == "view" ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');";
            $update_button = '<input class="button-primary" type="submit" tabindex="4" value="' . $button_text . '" name="save" onclick="' . $button_click . '"/>';
            echo apply_filters("gform_entrydetail_update_button", $update_button);
            if ($mode == "edit") {
                echo '&nbsp;&nbsp;<input class="button" style="color:#bbb;" type="submit" tabindex="5" value="' . __("Cancel", "gravityforms") . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>';
            }
        }
        ?>
                                    </div>
                                    <br/> <br/><br/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entry_notes")) {
            ?>
                        <!-- start side notes -->
                        <div class="postbox" id="tagsdiv-post_tag">
                            <h3 style="cursor:default;"><span>Quick Note</span></h3>
                            <div class="inside">
                                <div id="post_tag" class="tagsdiv">
                                    <div>
                                        <span>
                                            <textarea name="quick_note" style="width:99%; height:180px; margin-bottom:4px;"></textarea>
                                            <input type="submit" name="add_quick_note" value="<?php 
            _e("Add Note", "gravityforms");
            ?>
" class="button" style="width:60px;" onclick="jQuery('#action').val('add_quick_note');"/>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                       <!-- end side notes -->
                   <?php 
        }
        ?>

                   <!-- begin print button -->
                   <div class="detail-view-print">
                       <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '&notes=1' : ''; var url='<?php 
        echo GFCommon::get_base_url();
        ?>
/print-entry.php?fid=<?php 
        echo $form['id'];
        ?>
&lid=<?php 
        echo $lead['id'];
        ?>
' + notes_qs; window.open (url,'printwindow');" class="button">Print</a>
                       <?php 
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                           <input type="checkbox" name="print_notes" value="print_notes" checked="checked" id="gform_print_notes"/>
                           <label for="print_notes">include notes</label>
                       <?php 
        }
        ?>
                   </div>
                   <!-- end print button -->

                </div>

                <div id="post-body" class="has-sidebar">
                    <div id="post-body-content" class="has-sidebar-content">
                        <?php 
        if ($mode == "view") {
            self::lead_detail_grid($form, $lead, true);
        } else {
            self::lead_detail_edit($form, $lead);
        }
        ?>

                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                            <div id="namediv" class="stuffbox">
                                <h3>
                                    <label for="name"><?php 
            _e("Notes", "gravityforms");
            ?>
</label>
                                </h3>

                                <form method="post">
                                    <?php 
            wp_nonce_field('gforms_update_note', 'gforms_update_note');
            ?>
                                    <div class="inside">
                                        <?php 
            $notes = RGFormsModel::get_lead_notes($lead["id"]);
            //getting email values
            $email_fields = GFCommon::get_email_fields($form);
            $emails = array();
            foreach ($email_fields as $email_field) {
                if (!empty($lead[$email_field["id"]])) {
                    $emails[] = $lead[$email_field["id"]];
                }
            }
            //displaying notes grid
            $subject = !empty($form["autoResponder"]["subject"]) ? "RE: " . GFCommon::replace_variables($form["autoResponder"]["subject"], $form, $lead) : "";
            self::notes_grid($notes, true, $emails, $subject);
            ?>
                                    </div>
                                </form>
                            </div>
                        <?php 
        }
        ?>
                    </div>
                </div>
            </div>
        </div>
        </form>
        <?php 
        if (rgpost("action") == "update") {
            ?>
            <div class="updated fade" style="padding:6px;">
                <?php 
            _e("Entry Updated.", "gravityforms");
            ?>
            </div>
            <?php 
        }
    }
 /**
  * Update contact.
  * 
  * @access public
  * @param array $contact
  * @param array $feed
  * @param array $entry
  * @param array $form
  * @return array $contact
  */
 public function update_contact($contact, $feed, $entry, $form)
 {
     $this->log_debug(__METHOD__ . '(): Updating existing contact.');
     /* Setup mapped fields array. */
     $contact_standard_fields = $this->get_field_map_fields($feed, 'contactStandardFields');
     $contact_custom_fields = $this->get_dynamic_field_map_fields($feed, 'contactCustomFields');
     /* Setup base fields. */
     $first_name = $this->get_field_value($form, $entry, $contact_standard_fields['first_name']);
     $last_name = $this->get_field_value($form, $entry, $contact_standard_fields['last_name']);
     $default_email = $this->get_field_value($form, $entry, $contact_standard_fields['email_address']);
     /* If the name is empty, exit. */
     if (rgblank($first_name) || rgblank($last_name)) {
         $this->add_feed_error(esc_html__('Contact could not be created as first and/or last name were not provided.', 'gravityformsagilecrm'), $feed, $entry, $form);
         return null;
     }
     /* If the email address is empty, exit. */
     if (GFCommon::is_invalid_or_empty_email($default_email)) {
         $this->add_feed_error(esc_html__('Contact could not be created as email address was not provided.', 'gravityformsagilecrm'), $feed, $entry, $form);
         return null;
     }
     /* Clear out unneeded data. */
     foreach ($contact as $key => $value) {
         if (!in_array($key, array('tags', 'properties', 'id', 'type'))) {
             unset($contact[$key]);
         }
     }
     /* If we're replacing all data, clear out the properties and add the base properties. */
     if (rgars($feed, 'meta/updateContactAction') == 'replace') {
         $contact['tags'] = array();
         $contact['properties'] = array(array('type' => 'SYSTEM', 'name' => 'first_name', 'value' => $first_name), array('type' => 'SYSTEM', 'name' => 'last_name', 'value' => $last_name), array('type' => 'SYSTEM', 'name' => 'email', 'value' => $default_email));
     }
     /* Add custom field data. */
     foreach ($contact_custom_fields as $field_key => $field_id) {
         /* Get the field value. */
         $this->custom_field_key = $field_key;
         $field_value = $this->get_field_value($form, $entry, $field_id);
         /* If the field value is empty, skip this field. */
         if (rgblank($field_value)) {
             continue;
         }
         $contact = $this->add_contact_property($contact, $field_key, $field_value, rgars($feed, 'meta/updateContactAction') == 'replace');
     }
     /* Prepare tags. */
     if (rgars($feed, 'meta/contactTags')) {
         $tags = GFCommon::replace_variables($feed['meta']['contactTags'], $form, $entry, false, false, false, 'text');
         $tags = array_map('trim', explode(',', $tags));
         $tags = array_merge($contact['tags'], $tags);
         $contact['tags'] = gf_apply_filters('gform_agilecrm_tags', $form['id'], $tags, $feed, $entry, $form);
     }
     $this->log_debug(__METHOD__ . '(): Updating contact: ' . print_r($contact, true));
     try {
         /* Update contact. */
         $this->api->update_contact($contact);
         /* Save contact ID to entry. */
         gform_update_meta($entry['id'], 'agilecrm_contact_id', $contact['id']);
         /* Log that contact was updated. */
         $this->log_debug(__METHOD__ . '(): Contact #' . $contact['id'] . ' updated.');
     } catch (Exception $e) {
         $this->add_feed_error(sprintf(esc_html__('Contact could not be updated. %s', 'gravityformsagilecrm'), $e->getMessage()), $feed, $entry, $form);
         return null;
     }
     return $contact;
 }
 /**
  * Process feed.
  * 
  * @access public
  * @param array $feed
  * @param array $entry
  * @param array $form
  * @return void
  */
 public function process_feed($feed, $entry, $form)
 {
     /* If Campfire instance is not initialized, exit. */
     if (!$this->initialize_api()) {
         $this->add_feed_error(esc_html__('Message was not posted to room because API was not initialized.', 'gravityformscampfire'), $feed, $entry, $form);
         return;
     }
     /* Prepare message. */
     $message = array('type' => 'TextMessage', 'body' => gf_apply_filters('gform_campfire_message', $form['id'], rgars($feed, 'meta/message'), $feed, $entry, $form));
     /* Replace merge tags in message. */
     $message['body'] = GFCommon::replace_variables($message['body'], $form, $entry);
     /* If message is empty, exit. */
     if (rgblank($message['body'])) {
         $this->add_feed_error(esc_html__('Message was not posted to room because it was empty.', 'gravityformscampfire'), $feed, $entry, $form);
         return;
     }
     try {
         /* Post message. */
         $message = $this->api->create_message(rgars($feed, 'meta/room'), $message);
         /* Log that message was posted. */
         $this->log_debug(__METHOD__ . '(): Message #' . $message['id'] . ' was posted to room #' . $message['room_id'] . '.');
     } catch (Exception $e) {
         /* Log that message was not posted. */
         $this->add_feed_error(sprintf(esc_html__('Message was not posted to room: %s', 'gravityformscampfire'), $e->getMessage()), $feed, $entry, $form);
         return false;
     }
     if (rgars($feed, 'meta/highlight') == '1') {
         try {
             /* Highlight message. */
             $this->api->highlight_message($message['id']);
             /* Log that message was posted. */
             $this->log_debug(__METHOD__ . '(): Message #' . $message['id'] . ' was highlighted.');
         } catch (Exception $e) {
             /* Log that message was not posted. */
             $this->add_feed_error(sprintf(esc_html__('Message was not highlighted: %s', 'gravityformscampfire'), $e->getMessage()), $feed, $entry, $form);
             return false;
         }
     }
 }
Beispiel #15
0
 public static function handle_confirmation($form, $lead, $ajax = false)
 {
     GFCommon::log_debug("Sending confirmation");
     //run the function to populate the legacy confirmation format to be safe
     $form = self::update_confirmation($form, $lead);
     if ($form["confirmation"]["type"] == "message") {
         $default_anchor = self::has_pages($form) ? 1 : 0;
         $anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)) ? "<a id='gf_{$form["id"]}' name='gf_{$form["id"]}' class='gform_anchor' ></a>" : "";
         $nl2br = rgar($form["confirmation"], "disableAutoformat") ? false : true;
         $cssClass = rgar($form, "cssClass");
         $confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gform_confirmation_wrapper_{$form["id"]}' class='gform_confirmation_wrapper {$cssClass}'><div id='gform_confirmation_message_{$form["id"]}' class='gform_confirmation_message_{$form["id"]} gform_confirmation_message'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "</div></div>";
     } else {
         if (!empty($form['confirmation']['pageId'])) {
             $url = get_permalink($form['confirmation']['pageId']);
         } else {
             $url = GFCommon::replace_variables(trim($form['confirmation']['url']), $form, $lead, false, true, true, 'text');
         }
         $url_info = parse_url($url);
         $query_string = rgar($url_info, 'query');
         $dynamic_query = GFCommon::replace_variables(trim($form['confirmation']['queryString']), $form, $lead, true, false, false, 'text');
         $query_string .= rgempty('query', $url_info) || empty($dynamic_query) ? $dynamic_query : '&' . $dynamic_query;
         if (!empty($url_info['fragment'])) {
             $query_string .= '#' . rgar($url_info, 'fragment');
         }
         $url = $url_info['scheme'] . '://' . rgar($url_info, 'host');
         if (!empty($url_info['port'])) {
             $url .= ':' . rgar($url_info, 'port');
         }
         $url .= rgar($url_info, 'path');
         if (!empty($query_string)) {
             $url .= "?{$query_string}";
         }
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($url, $ajax);
         } else {
             $confirmation = array('redirect' => $url);
         }
     }
     $confirmation = apply_filters("gform_confirmation_{$form["id"]}", apply_filters("gform_confirmation", $confirmation, $form, $lead, $ajax), $form, $lead, $ajax);
     if (!is_array($confirmation)) {
         $confirmation = GFCommon::gform_do_shortcode($confirmation);
         //enabling shortcodes
     } else {
         if (headers_sent() || $ajax) {
             //Perform client side redirect for AJAX forms, of if headers have already been sent
             $confirmation = self::get_js_redirect_confirmation($confirmation["redirect"], $ajax);
             //redirecting via client side
         }
     }
     GFCommon::log_debug("Confirmation: " . print_r($confirmation, true));
     return $confirmation;
 }
 /**
  * Show confirmations
  *
  */
 function stickylist_gform_confirmation($original_confirmation, $form, $lead, $ajax)
 {
     $settings = $this->get_form_settings($form);
     if (isset($settings["enable_list"]) && true == $settings["enable_list"]) {
         $confirmations = $form["confirmations"];
         $new_confirmation = "";
         if (!isset($_POST["action"])) {
             $_POST["action"] = "new";
         }
         if (isset($_POST["edit_id"]) && $_POST["edit_id"] != "") {
             if (true != $settings["new_entry_id"]) {
                 $lead["id"] = $_POST["edit_id"];
             }
         }
         foreach ($confirmations as $confirmation) {
             if (isset($confirmation["stickylist_confirmation_type"])) {
                 $confirmation_type = $confirmation["stickylist_confirmation_type"];
             } else {
                 $confirmation_type = "";
             }
             if ($confirmation_type == $_POST["action"] || $confirmation_type == "all" || !isset($confirmation["stickylist_confirmation_type"])) {
                 if (!isset($confirmation["event"])) {
                     if ($confirmation["type"] == "message") {
                         $new_confirmation .= $confirmation["message"] . " ";
                     } else {
                         $new_confirmation = $original_confirmation;
                         break;
                     }
                 }
             }
         }
         if (!isset($new_confirmation["redirect"])) {
             $new_confirmation = GFCommon::replace_variables($new_confirmation, $form, $lead);
             $new_confirmation = '<div id="gform_confirmation_message_' . $form["id"] . '" class="gform_confirmation_message_' . $form["id"] . ' gform_confirmation_message">' . $new_confirmation . '</div>';
             return $new_confirmation;
         } else {
             return $new_confirmation;
         }
     } else {
         return $original_confirmation;
     }
 }
 public static function handle_confirmation($form, $lead, $ajax = false)
 {
     if ($form["confirmation"]["type"] == "message") {
         $default_anchor = self::has_pages($form) ? 1 : 0;
         $anchor = apply_filters("gform_confirmation_anchor_{$form["id"]}", apply_filters("gform_confirmation_anchor", $default_anchor)) ? "<a name='gf_{$form["id"]}' class='gform_anchor' ></a>" : "";
         $nl2br = rgar($form["confirmation"], "disableAutoformat") ? false : true;
         $confirmation = empty($form["confirmation"]["message"]) ? "{$anchor} " : "{$anchor}<div id='gforms_confirmation_message' class='gform_confirmation_message_{$form["id"]}'>" . GFCommon::replace_variables($form["confirmation"]["message"], $form, $lead, false, true, $nl2br) . "</div>";
     } else {
         if (!empty($form["confirmation"]["pageId"])) {
             $url = get_permalink($form["confirmation"]["pageId"]);
         } else {
             $url = GFCommon::replace_variables(trim($form["confirmation"]["url"]), $form, $lead, false, true);
             $url_info = parse_url($url);
             $query_string = $url_info["query"];
             $dynamic_query = GFCommon::replace_variables(trim($form["confirmation"]["queryString"]), $form, $lead, true);
             $query_string .= empty($url_info["query"]) || empty($dynamic_query) ? $dynamic_query : "&" . $dynamic_query;
             if (!empty($url_info["fragment"])) {
                 $query_string .= "#" . $url_info["fragment"];
             }
             $url = $url_info["scheme"] . "://" . $url_info["host"] . $url_info["path"] . "?" . $query_string;
         }
         if (headers_sent() || $ajax) {
             $confirmation = "<script type=\"text/javascript\">//<![CDATA[\n function gformRedirect(){document.location.href='{$url}';}";
             if (!$ajax) {
                 $confirmation .= "gformRedirect();";
             }
             $confirmation .= "\n//]]></script>";
         } else {
             $confirmation = array("redirect" => $url);
         }
     }
     $confirmation = apply_filters("gform_confirmation_{$form["id"]}", apply_filters("gform_confirmation", $confirmation, $form, $lead, $ajax), $form, $lead, $ajax);
     if (!is_array($confirmation)) {
         $confirmation = GFCommon::gform_do_shortcode($confirmation);
     }
     return $confirmation;
 }
 public static function do_mergetags($string, $form_id, $lead_id)
 {
     /*
      * Unconvert { and } symbols from HTML entities 
      */
     $string = str_replace('&#123;', '{', $string);
     $string = str_replace('&#125;', '}', $string);
     /* strip {all_fields} merge tag from $string */
     $string = str_replace('{all_fields}', '', $string);
     /*
      * Get form and lead data
      */
     $form = RGFormsModel::get_form_meta($form_id);
     $lead = RGFormsModel::get_lead($lead_id);
     $results = trim(GFCommon::replace_variables($string, $form, $lead, false, false, false));
     /*
      * Return results 
      */
     return $results;
 }
Beispiel #19
0
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     $value = false;
     foreach ($filters as $filter) {
         if (is_numeric($value)) {
             //value found, exit loop
             break;
         }
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     }
     if (!$value || !is_numeric($value)) {
         $value = 0;
     }
     return $value;
 }
 /**
  * During export, create an export array based on the feed mappings.
  * @param  array      $entry Entry array
  * @param  array      $form  Form array
  * @param  array      $feed  Feed array
  * @return [type]             [description]
  */
 private static function process_merge_vars($entry, $form, $feed)
 {
     self::log_debug('process_merge_vars(): Starting...');
     $merge_vars = array();
     foreach ($feed["meta"]["field_map"] as $var_tag => $field_id) {
         $field = RGFormsModel::get_field($form, $field_id);
         $input_type = RGFormsModel::get_input_type($field);
         if ($var_tag == 'address_full') {
             $merge_vars[$var_tag] = self::get_address($entry, $field_id);
         } else {
             if ($var_tag == 'country') {
                 $merge_vars[$var_tag] = empty($entry[$field_id]) ? '' : GFCommon::get_country_code(trim($entry[$field_id]));
             } else {
                 if (isset($entry[$field_id]) && $entry[$field_id] === "0") {
                     $merge_vars[$var_tag] = "0";
                 } else {
                     if ($var_tag != "email") {
                         if (!empty($entry[$field_id]) && !($entry[$field_id] == "0")) {
                             switch ($input_type) {
                                 // Thanks to Scott Kingsley Clark
                                 // http://wordpress.org/support/topic/likert-field-compatibility-with-survey-add-on
                                 case 'likert':
                                     $value = $entry[$field_id];
                                     foreach ($field['choices'] as $choice) {
                                         if ($value === $choice['value']) {
                                             $value = $choice['text'];
                                             break;
                                         }
                                     }
                                     $value = htmlspecialchars($value);
                                     break;
                                 case 'multiselect':
                                     // If there are commas in the value, this makes it so it can be comma exploded.
                                     // Values cannot contain semicolons: http://boards.developerforce.com/t5/NET-Development/Salesforce-API-inserting-values-into-multiselect-fields-using/td-p/125910
                                     foreach ($field['choices'] as $choice) {
                                         $entry[$field_id] = str_replace($choice, str_replace(',', '&#44;', $choice), $entry[$field_id]);
                                     }
                                     // Break into an array
                                     $elements = explode(",", $entry[$field_id]);
                                     // We decode first so that the commas are commas again, then
                                     // implode the array to be picklist format for SF
                                     $value = implode(';', array_map('html_entity_decode', array_map('htmlspecialchars', $elements)));
                                     break;
                                 default:
                                     $value = htmlspecialchars($entry[$field_id]);
                             }
                             $merge_vars[$var_tag] = GFCommon::replace_variables($value, $form, $entry, false, false, false);
                         } else {
                             if (array_key_exists($field_id, self::$foreign_keys)) {
                                 $merge_vars[$var_tag] = self::$foreign_keys[$field_id];
                             } else {
                                 // This is for checkboxes
                                 $elements = array();
                                 foreach ($entry as $key => $value) {
                                     if (floor($key) == floor($field_id) && !empty($value)) {
                                         $elements[] = htmlspecialchars($value);
                                     }
                                 }
                                 $value = implode(';', array_map('htmlspecialchars', $elements));
                                 $merge_vars[$var_tag] = GFCommon::replace_variables($value, $form, $entry, false, false, false);
                             }
                         }
                     }
                 }
             }
         }
         $merge_vars[$var_tag] = apply_filters('gf_salesforce_mapped_value_' . $var_tag, $merge_vars[$var_tag], $field, $var_tag, $form, $entry);
         $merge_vars[$var_tag] = apply_filters('gf_salesforce_mapped_value', $merge_vars[$var_tag], $field, $var_tag, $form, $entry);
     }
     self::log_debug('process_merge_vars(): Completed.');
     return $merge_vars;
 }
Beispiel #21
0
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     do {
         $filter = isset($filter) ? next($filters) : reset($filters);
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     } while (!is_numeric($value) && $filter !== false);
     if (!$value || !is_numeric($value)) {
         $value = 0;
     }
     return $value;
 }
    public static function lead_detail_page()
    {
        global $wpdb;
        global $current_user;
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        echo GFCommon::get_remote_message();
        $form = RGFormsModel::get_form_meta($_GET["id"]);
        $lead_id = rgget('lid');
        $filter = rgget("filter");
        $status = in_array($filter, array("trash", "spam")) ? $filter : "active";
        $search = rgget("s");
        $position = rgget('pos') ? rgget('pos') : 0;
        $sort_direction = rgget('dir') ? rgget('dir') : 'DESC';
        $sort_field = empty($_GET["sort"]) ? 0 : $_GET["sort"];
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta["type"] == "number";
        $star = $filter == "star" ? 1 : null;
        $read = $filter == "unread" ? 0 : null;
        // added status as an optional parameter to get_lead_count because the counts are inaccurate without using the status
        $lead_count = RGFormsModel::get_lead_count($form['id'], $search, $star, $read, null, null, $status);
        $prev_pos = !rgblank($position) && $position > 0 ? $position - 1 : false;
        $next_pos = !rgblank($position) && $position < $lead_count - 1 ? $position + 1 : false;
        // unread filter requires special handling for pagination since entries are filter out of the query as they are read
        if ($filter == 'unread') {
            $next_pos = $position;
            if ($next_pos + 1 == $lead_count) {
                $next_pos = false;
            }
        }
        // get the lead
        $leads = RGFormsModel::get_leads($form['id'], $sort_field, $sort_direction, $search, $position, 1, $star, $read, $is_numeric, null, null, $status);
        if (!$lead_id) {
            $lead = !empty($leads) ? $leads[0] : false;
        } else {
            $lead = RGFormsModel::get_lead($lead_id);
        }
        if (!$lead) {
            _e("Oops! We couldn't find your lead. Please try again", "gravityforms");
            return;
        }
        RGFormsModel::update_lead_property($lead["id"], "is_read", 1);
        switch (RGForms::post("action")) {
            case "update":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::save_lead($form, $lead);
                do_action("gform_after_update_entry", $form, $lead["id"]);
                do_action("gform_after_update_entry_{$form["id"]}", $form, $lead["id"]);
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "add_note":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["new_note"]));
                //emailing notes if configured
                if (rgpost("gentry_email_notes_to")) {
                    $email_to = $_POST["gentry_email_notes_to"];
                    $email_from = $current_user->user_email;
                    $email_subject = stripslashes($_POST["gentry_email_subject"]);
                    $headers = "From: \"{$email_from}\" <{$email_from}> \r\n";
                    $result = wp_mail($email_to, $email_subject, stripslashes($_POST["new_note"]), $headers);
                }
                break;
            case "add_quick_note":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["quick_note"]));
                break;
            case "bulk":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                if ($_POST["bulk_action"] == "delete") {
                    RGFormsModel::delete_notes($_POST["note"]);
                }
                break;
            case "trash":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "trash");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "restore":
            case "unspam":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "active");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "spam":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "spam");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "delete":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::delete_lead($lead["id"]);
                ?>
                <script type="text/javascript">
                    document.location.href='<?php 
                echo "admin.php?page=gf_entries&view=entries&id=" . absint($form["id"]);
                ?>
';
                </script>
                <?php 
                break;
        }
        $mode = empty($_POST["screen_mode"]) ? "view" : $_POST["screen_mode"];
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css" />
         <script type="text/javascript">

            jQuery(document).ready(function(){
                toggleNotificationOverride(true);
            });

            function DeleteFile(leadId, fieldId){
                if(confirm(<?php 
        _e("'Would you like to delete this file? \\'Cancel\\' to stop. \\'OK\\' to delete'", "gravityforms");
        ?>
)){

                    var mysack = new sack("<?php 
        echo admin_url("admin-ajax.php");
        ?>
");
                    mysack.execute = 1;
                    mysack.method = 'POST';
                    mysack.setVar( "action", "rg_delete_file" );
                    mysack.setVar( "rg_delete_file", "<?php 
        echo wp_create_nonce("rg_delete_file");
        ?>
" );
                    mysack.setVar( "lead_id", leadId );
                    mysack.setVar( "field_id", fieldId );
                    mysack.encVar( "cookie", document.cookie, false );
                    mysack.onError = function() { alert('<?php 
        echo esc_js(__("Ajax error while deleting field.", "gravityforms"));
        ?>
' )};
                    mysack.runAJAX();

                    return true;
                }
            }

            function EndDeleteFile(fieldId){
                jQuery('#preview_' + fieldId).hide();
                jQuery('#upload_' + fieldId).show('slow');
            }

            function ToggleShowEmptyFields(){
                if(jQuery("#gentry_display_empty_fields").is(":checked")){
                    createCookie("gf_display_empty_fields", true, 10000);
                    document.location = document.location.href;
                }
                else{
                    eraseCookie("gf_display_empty_fields");
                    document.location = document.location.href;
                }
            }

            function createCookie(name,value,days) {
                if (days) {
                    var date = new Date();
                    date.setTime(date.getTime()+(days*24*60*60*1000));
                    var expires = "; expires="+date.toGMTString();
                }
                else var expires = "";
                document.cookie = name+"="+value+expires+"; path=/";
            }

            function eraseCookie(name) {
                createCookie(name,"",-1);
            }

            function ResendNotifications() {

                var sendAdmin = jQuery("#notification_admin").is(":checked") ? 1 : 0;
                var sendUser = jQuery("#notification_user").is(":checked") ? 1 : 0;

                var sendTo = jQuery('#notification_override_email').val();

                if(!sendAdmin && !sendUser) {
                    displayMessage("<?php 
        _e("You must select at least one type of notification to resend.", "gravityforms");
        ?>
", "error", "#notifications_container");
                    return;
                }

                jQuery('#please_wait_container').fadeIn();

                jQuery.post(ajaxurl, {
                        action : "gf_resend_notifications",
                        gf_resend_notifications : '<?php 
        echo wp_create_nonce('gf_resend_notifications');
        ?>
',
                        sendAdmin : sendAdmin,
                        sendUser : sendUser,
                        sendTo : sendTo,
                        leadIds : '<?php 
        echo $lead['id'];
        ?>
',
                        formId : '<?php 
        echo $form['id'];
        ?>
'
                    },
                    function(response) {
                        if(response) {
                            displayMessage(response, "error", "#notifications_container");
                        } else {
                            displayMessage("<?php 
        _e("Notifications were resent successfully.", "gravityforms");
        ?>
", "updated", "#notifications_container");

                            // reset UI
                            jQuery("#notification_admin, #notification_user").attr('checked', false);
                            jQuery('#notification_override_email').val('');
                        }

                        jQuery('#please_wait_container').hide();
                        setTimeout(function(){jQuery('#notifications_container').find('.message').slideUp();}, 5000);
                    }
                );

            }

            function displayMessage(message, messageClass, container){

                jQuery(container).find('.message').hide().html(message).attr('class', 'message ' + messageClass).slideDown();

            }

            function toggleNotificationOverride(isInit) {

                if(isInit)
                    jQuery('#notification_override_email').val('');

                if(jQuery('#notification_admin').is(':checked') || jQuery('#notification_user').is(':checked')) {
                    jQuery('#notifications_override_settings').slideDown();
                } else {
                    jQuery('#notifications_override_settings').slideUp(function(){
                        jQuery('#notification_override_email').val('');
                    });
                }

            }

        </script>

        <form method="post" id="entry_form" enctype='multipart/form-data'>
            <?php 
        wp_nonce_field('gforms_save_entry', 'gforms_save_entry');
        ?>
            <input type="hidden" name="action" id="action" value=""/>
            <input type="hidden" name="screen_mode" id="screen_mode" value="<?php 
        echo esc_attr(rgpost("screen_mode"));
        ?>
" />

            <div class="wrap gf_entry_wrap">
            <div class="icon32" id="gravity-title-icon"><br></div>
            <h2><?php 
        _e("Entry #", "gravityforms");
        echo absint($lead["id"]);
        ?>
</h2>

            <?php 
        if (isset($_GET["pos"])) {
            ?>
            <div class="gf_entry_detail_pagination">
                <ul>
                    <li class="gf_entry_count"><span>entry <strong><?php 
            echo $position + 1;
            ?>
</strong> of <strong><?php 
            echo $lead_count;
            ?>
</strong></span></li>
                    <li class="gf_entry_prev gf_entry_pagination"><?php 
            echo GFEntryDetail::entry_detail_pagination_link($prev_pos, 'Previous Entry', 'gf_entry_prev_link');
            ?>
</li>
                    <li class="gf_entry_next gf_entry_pagination"><?php 
            echo GFEntryDetail::entry_detail_pagination_link($next_pos, 'Next Entry', 'gf_entry_next_link');
            ?>
</li>
                </ul>
            </div>
            <?php 
        }
        ?>

            <?php 
        RGForms::top_toolbar();
        ?>

            <div id="poststuff" class="metabox-holder has-right-sidebar">
                <div id="side-info-column" class="inner-sidebar">
                    <div id="submitdiv" class="stuffbox">
                        <h3>
                            <span class="hndle"><?php 
        _e("Info", "gravityforms");
        ?>
</span>
                        </h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">
                                <div id="minor-publishing" style="padding:10px;">
                                    <br/>
                                    <?php 
        _e("Entry Id", "gravityforms");
        ?>
: <?php 
        echo absint($lead["id"]);
        ?>
<br/><br/>
                                    <?php 
        _e("Submitted on", "gravityforms");
        ?>
: <?php 
        echo esc_html(GFCommon::format_date($lead["date_created"], false, "Y/m/d"));
        ?>
                                    <br/><br/>
                                    <?php 
        _e("User IP", "gravityforms");
        ?>
: <?php 
        echo $lead["ip"];
        ?>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["created_by"]) && ($usermeta = get_userdata($lead["created_by"]))) {
            ?>
                                        <?php 
            _e("User", "gravityforms");
            ?>
: <a href="user-edit.php?user_id=<?php 
            echo absint($lead["created_by"]);
            ?>
" alt="<?php 
            _e("View user profile", "gravityforms");
            ?>
" title="<?php 
            _e("View user profile", "gravityforms");
            ?>
"><?php 
            echo esc_html($usermeta->user_login);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        ?>

                                    <?php 
        _e("Embed Url", "gravityforms");
        ?>
: <a href="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" target="_blank" alt="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" title="<?php 
        echo esc_url($lead["source_url"]);
        ?>
">.../<?php 
        echo esc_html(GFCommon::truncate_url($lead["source_url"]));
        ?>
</a>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["post_id"])) {
            $post = get_post($lead["post_id"]);
            ?>
                                        <?php 
            _e("Edit Post", "gravityforms");
            ?>
: <a href="post.php?action=edit&post=<?php 
            echo absint($post->ID);
            ?>
" alt="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
" title="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
"><?php 
            echo esc_html($post->post_title);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        if (!empty($lead["payment_status"])) {
            echo $lead["transaction_type"] != 2 ? __("Payment Status", "gravityforms") : __("Subscription Status", "gravityforms");
            ?>
: <span id="gform_payment_status"><?php 
            echo apply_filters("gform_payment_status", $lead["payment_status"], $form, $lead);
            ?>
</span>
                                        <br/><br/>
                                        <?php 
            if (!empty($lead["payment_date"])) {
                echo $lead["transaction_type"] == 1 ? __("Payment Date", "gravityforms") : __("Start Date", "gravityforms");
                ?>
: <?php 
                echo GFCommon::format_date($lead["payment_date"], false, "Y/m/d", $lead["transaction_type"] == 1);
                ?>
                                            <br/><br/>
                                            <?php 
            }
            if (!empty($lead["transaction_id"])) {
                echo $lead["transaction_type"] == 1 ? __("Transaction Id", "gravityforms") : __("Subscriber Id", "gravityforms");
                ?>
: <?php 
                echo $lead["transaction_id"];
                ?>
                                            <br/><br/>
                                            <?php 
            }
            if (!rgblank($lead["payment_amount"])) {
                echo $lead["transaction_type"] == 1 ? __("Payment Amount", "gravityforms") : __("Subscription Amount", "gravityforms");
                ?>
: <?php 
                echo GFCommon::to_money($lead["payment_amount"], $lead["currency"]);
                ?>
                                            <br/><br/>
                                            <?php 
            }
        }
        do_action("gform_entry_info", $form["id"], $lead);
        ?>
                                </div>
                                <div id="major-publishing-actions">
                                    <div>
                                        <?php 
        switch ($lead["status"]) {
            case "spam":
                if (GFCommon::akismet_enabled($form['id'])) {
                    ?>
                                                    <a onclick="jQuery('#action').val('unspam'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Not Spam", "gravityforms");
                    ?>
</a>
                                                    <?php 
                    echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                }
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="if ( confirm('<?php 
                    _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", "gravityforms");
                    ?>
') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</a>
                                                    <?php 
                }
                break;
            case "trash":
                ?>
                                                <a onclick="jQuery('#action').val('restore'); jQuery('#entry_form').submit()" href="#"><?php 
                _e("Restore", "gravityforms");
                ?>
</a>
                                                <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    |
                                                    <a class="submitdelete deletion" onclick="if ( confirm('<?php 
                    _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", "gravityforms");
                    ?>
') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</a>
                                                    <?php 
                }
                break;
            default:
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="jQuery('#action').val('trash'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Move to Trash", "gravityforms");
                    ?>
</a>
                                                    <?php 
                    echo GFCommon::akismet_enabled($form['id']) ? "|" : "";
                }
                if (GFCommon::akismet_enabled($form['id'])) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="jQuery('#action').val('spam'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Mark as Spam", "gravityforms");
                    ?>
</a>
                                                <?php 
                }
        }
        /*if(GFCommon::current_user_can_any("gravityforms_delete_entries")){
              $delete_link = '<a class="submitdelete deletion" onclick="if ( confirm(\''. __("You are about to delete this entry. \'Cancel\' to stop, \'OK\' to delete.", "gravityforms") .'\') ) { jQuery(\'#action\').val(\'delete\'); jQuery(\'#entry_form\')[0].submit();} return false;" href="#">' . __("Delete", "gravityforms") . '</a>';
              echo apply_filters("gform_entrydetail_delete_link", $delete_link);
          }*/
        ?>
                                    </div>
                                    <div id="publishing-action">
                                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entries") && $lead["status"] != "trash") {
            $button_text = $mode == "view" ? __("Edit", "gravityforms") : __("Update", "gravityforms");
            $button_click = $mode == "view" ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');";
            $update_button = '<input class="button-primary" type="submit" tabindex="4" value="' . $button_text . '" name="save" onclick="' . $button_click . '"/>';
            echo apply_filters("gform_entrydetail_update_button", $update_button);
            if ($mode == "edit") {
                echo '&nbsp;&nbsp;<input class="button" style="color:#bbb;" type="submit" tabindex="5" value="' . __("Cancel", "gravityforms") . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>';
            }
        }
        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entry_notes") && (GFCommon::has_admin_notification($form) || GFCommon::has_user_notification($form))) {
            // TODO: do we need to set a permission for this?
            ?>
                        <!-- start notifications -->
                        <div class="postbox" id="notifications_container">
                            <h3 style="cursor:default;"><span><?php 
            _e("Notifications", "gravityforms");
            ?>
</span></h3>
                            <div class="inside">
                                <div class="message" style="display:none;padding:10px;margin:10px 0 0;"></div>
                                <div>

                                    <br />
                                    <?php 
            if (GFCommon::has_admin_notification($form)) {
                ?>
                                        <input type="checkbox" name="notification_admin" id="notification_admin" onclick="toggleNotificationOverride();" /> <label for="notification_admin"><?php 
                _e("Admin Notification", "gravityforms");
                ?>
</label> <br /><br />
                                    <?php 
            }
            ?>
                                    <?php 
            if (GFCommon::has_user_notification($form)) {
                ?>
                                        <input type="checkbox" name="notification_user" id="notification_user" onclick="toggleNotificationOverride();" /> <label for="notification_user"><?php 
                _e("User Notification", "gravityforms");
                ?>
</label> <br /><br />
                                    <?php 
            }
            ?>

                                    <div id="notifications_override_settings" style="display:none;">

                                        <p class="description" style="padding-top:0; margin-top:0; width:99%;">You may override the default notification settings
                                         by entering a comma delimited list of emails to which the selected notifications should be sent.</p>
                                        <label for="notification_override_email"><?php 
            _e("Send To", "gravityforms");
            ?>
 <?php 
            gform_tooltip("notification_override_email");
            ?>
</label><br />
                                        <input type="text" name="notification_override_email" id="notification_override_email" style="width:99%;" />
                                        <br /><br />

                                    </div>

                                    <input type="button" name="notification_resend" value="<?php 
            _e("Resend Notifications", "gravityforms");
            ?>
" class="button" style="" onclick="ResendNotifications();"/>
                                    <span id="please_wait_container" style="display:none; margin-left: 5px;">
                                        <img src="<?php 
            echo GFCommon::get_base_url();
            ?>
/images/loading.gif"> <?php 
            _e("Resending...", "gravityforms");
            ?>
                                    </span>

                                </div>
                            </div>
                        </div>
                       <!-- / end notifications -->
                   <?php 
        }
        ?>

                   <!-- begin print button -->
                   <div class="detail-view-print">
                       <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '&notes=1' : ''; var url='<?php 
        echo site_url();
        ?>
/?gf_page=print-entry&fid=<?php 
        echo $form['id'];
        ?>
&lid=<?php 
        echo $lead['id'];
        ?>
' + notes_qs; window.open (url,'printwindow');" class="button"><?php 
        _e("Print", "gravityforms");
        ?>
</a>
                       <?php 
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                           <input type="checkbox" name="print_notes" value="print_notes" checked="checked" id="gform_print_notes"/>
                           <label for="print_notes"><?php 
            _e("include notes", "gravityforms");
            ?>
</label>
                       <?php 
        }
        ?>
                   </div>
                   <!-- end print button -->

                </div>

                <div id="post-body" class="has-sidebar">
                    <div id="post-body-content" class="has-sidebar-content">
                        <?php 
        if ($mode == "view") {
            self::lead_detail_grid($form, $lead, true);
        } else {
            self::lead_detail_edit($form, $lead);
        }
        do_action("gform_entry_detail", $form, $lead);
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                            <div id="namediv" class="stuffbox">
                                <h3>
                                    <label for="name"><?php 
            _e("Notes", "gravityforms");
            ?>
</label>
                                </h3>

                                <form method="post">
                                    <?php 
            wp_nonce_field('gforms_update_note', 'gforms_update_note');
            ?>
                                    <div class="inside">
                                        <?php 
            $notes = RGFormsModel::get_lead_notes($lead["id"]);
            //getting email values
            $email_fields = GFCommon::get_email_fields($form);
            $emails = array();
            foreach ($email_fields as $email_field) {
                if (!empty($lead[$email_field["id"]])) {
                    $emails[] = $lead[$email_field["id"]];
                }
            }
            //displaying notes grid
            $subject = !empty($form["autoResponder"]["subject"]) ? "RE: " . GFCommon::replace_variables($form["autoResponder"]["subject"], $form, $lead) : "";
            self::notes_grid($notes, true, $emails, $subject);
            ?>
                                    </div>
                                </form>
                            </div>
                        <?php 
        }
        ?>
                    </div>
                </div>
            </div>
        </div>
        </form>
        <?php 
        if (rgpost("action") == "update") {
            ?>
            <div class="updated fade" style="padding:6px;">
                <?php 
            _e("Entry Updated.", "gravityforms");
            ?>
            </div>
            <?php 
        }
    }
 /**
  * Handle the form after submission before sending to the event push
  * 
  * @since 1.4.0
  * @param array $entry Gravity Forms entry object
  * @param array $form Gravity Forms form object
  */
 private function track_form_after_submission($entry, $form, $ga_event_data)
 {
     // Try to get payment amount
     // This needs to go here in case something changes with the amount
     if (!$ga_event_data['gaEventValue']) {
         $ga_event_data['gaEventValue'] = $this->get_event_value($entry, $form);
     }
     $event_vars = array('gaEventCategory', 'gaEventAction', 'gaEventLabel', 'gaEventValue');
     foreach ($event_vars as $var) {
         if ($ga_event_data[$var]) {
             $ga_event_data[$var] = GFCommon::replace_variables($ga_event_data[$var], $form, $entry, false, false, true, 'text');
         }
     }
     // Push the event to google
     $this->push_event($entry, $form, $ga_event_data);
 }
 /**
  * Export the entry on submit.
  *
  * @filter gf_salesforce_implode_glue Change how array values are passed to Salesforce. By default they're sent using `;` (semicolons) to separate the items. You may want to convert that to using `,` (commas) instead. The filter passes the existing "glue" and the name of the input (for example, `Multiple_Picklist__c`)
  * @param  array $feed  Feed array
  * @param  array $entry Entry array
  * @param  array $form  Form array
  */
 public function process_feed($feed, $entry, $form)
 {
     // The settings are only normally available on the admin page.
     // We want it available everywhere.
     $this->set_settings($feed['meta']);
     self::log_debug(sprintf("Opt-in condition met; adding entry {$entry["id"]} to %s", $this->_service_name));
     try {
         foreach ($feed['meta'] as $key => $value) {
             // The field names have a trailing underscore for some reason.
             $trimmed_key = ltrim($key, '_');
             $feed['meta'][$trimmed_key] = $value;
             unset($feed['meta'][$key]);
         }
         $temp_merge_vars = $this->get_merge_vars_from_entry($feed, $entry, $form);
         self::log_debug(sprintf("Temp Merge Vars: %s", print_r($temp_merge_vars, true)));
         $merge_vars = array();
         foreach ($temp_merge_vars as $key => $value) {
             // Get the field ID for the current value
             $field_id = $feed['meta'][$key];
             // We need to specially format some data going to Salesforce
             // If it's a field ID, get the field data
             if (is_numeric($field_id) && !empty($value)) {
                 $field = RGFormsModel::get_field($form, $field_id);
                 $field_type = RGFormsModel::get_input_type($field);
                 // Right now, we only have special cases for dates.
                 switch ($field_type) {
                     case 'date':
                         $value = $this->get_date_format($value, $key, compact('form', 'entry', 'field', 'feed'));
                         break;
                 }
             }
             if (is_array($value)) {
                 // Filter the implode glue
                 $glue = apply_filters('gf_salesforce_implode_glue', ';', $key);
                 $value = implode($glue, $value);
                 // Get rid of empty array values that would result in
                 // List Item 1;;List Item 2 - that causes weird things to happen in
                 // Salesforce
                 $value = preg_replace('/' . preg_quote($glue) . '+/', $glue, $data[$label]);
                 unset($glue);
             } else {
                 $value = GFCommon::trim_all($value);
             }
             // If the value is empty, don't send it.
             if (empty($value) && $value !== '0') {
                 unset($merge_vars[$key]);
             } else {
                 // Add the value to the data being sent
                 $merge_vars[$key] = GFCommon::replace_variables($value, $form, $entry, false, false, false);
             }
         }
         // Process Boolean opt-out fields
         if (isset($merge_vars['emailOptOut'])) {
             $merge_vars['emailOptOut'] = !empty($merge_vars['emailOptOut']);
         }
         if (isset($merge_vars['faxOptOut'])) {
             $merge_vars['faxOptOut'] = !empty($merge_vars['faxOptOut']);
         }
         if (isset($merge_vars['doNotCall'])) {
             $merge_vars['doNotCall'] = !empty($merge_vars['doNotCall']);
         }
         // Add Address Line 2 to the street address
         if (!empty($merge_vars['street2'])) {
             $merge_vars['street'] .= "\n" . $merge_vars['street2'];
         }
         // You can tap into the data and filter it.
         $merge_vars = apply_filters('gf_salesforce_push_data', $merge_vars, $form, $entry);
         // Remove any empty items
         $merge_vars = array_filter($merge_vars);
         $return = $this->send_request($merge_vars);
         // If it returns false, there was an error.
         if (empty($return)) {
             self::log_error(sprintf("There was an error adding {$entry['id']} to Salesforce. Here's what was sent: %s", print_r($merge_vars, true)));
             return false;
         } else {
             // Otherwise, it was a success.
             self::log_debug(sprintf("Entry {$entry['id']} was added to Salesforce. Here's the available data:\n%s", print_r($return, true)));
             return true;
         }
     } catch (Exception $e) {
         // Otherwise, it was a success.
         self::log_error(sprintf("Error: %s", $e->getMessage()));
     }
     return;
 }
Beispiel #25
0
    public static function lead_detail_page()
    {
        global $wpdb;
        global $current_user;
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        echo GFCommon::get_remote_message();
        $form = RGFormsModel::get_form_meta($_GET["id"]);
        $form_id = $form["id"];
        $form = apply_filters("gform_admin_pre_render_" . $form["id"], apply_filters("gform_admin_pre_render", $form));
        $lead_id = rgget('lid');
        $filter = rgget("filter");
        $status = in_array($filter, array("trash", "spam")) ? $filter : "active";
        $position = rgget('pos') ? rgget('pos') : 0;
        $sort_direction = rgget('dir') ? rgget('dir') : 'DESC';
        $sort_field = empty($_GET["sort"]) ? 0 : $_GET["sort"];
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta["type"] == "number";
        $star = $filter == "star" ? 1 : null;
        $read = $filter == "unread" ? 0 : null;
        $search_criteria["status"] = $status;
        if ($star) {
            $search_criteria["field_filters"][] = array("key" => "is_starred", "value" => (bool) $star);
        }
        if (!is_null($read)) {
            $search_criteria["field_filters"][] = array("key" => "is_read", "value" => (bool) $read);
        }
        $search_field_id = rgget("field_id");
        if (isset($_GET["field_id"]) && $_GET["field_id"] !== '') {
            $key = $search_field_id;
            $val = rgget("s");
            $strpos_row_key = strpos($search_field_id, "|");
            if ($strpos_row_key !== false) {
                //multi-row likert
                $key_array = explode("|", $search_field_id);
                $key = $key_array[0];
                $val = $key_array[1] . ":" . $val;
            }
            $type = rgget("type");
            if (empty($type)) {
                $type = rgget("field_id") == "0" ? "global" : "field";
            }
            $search_criteria["field_filters"][] = array("key" => $key, "type" => $type, "operator" => rgempty("operator", $_GET) ? "is" : rgget("operator"), "value" => $val);
        }
        $paging = array('offset' => $position, 'page_size' => 1);
        if (!empty($sort_field)) {
            $sorting = array('key' => $_GET["sort"], 'direction' => $sort_direction, 'is_numeric' => $is_numeric);
        } else {
            $sorting = array();
        }
        $total_count = 0;
        $leads = GFAPI::get_entries($form['id'], $search_criteria, $sorting, $paging, $total_count);
        $prev_pos = !rgblank($position) && $position > 0 ? $position - 1 : false;
        $next_pos = !rgblank($position) && $position < $total_count - 1 ? $position + 1 : false;
        // unread filter requires special handling for pagination since entries are filter out of the query as they are read
        if ($filter == 'unread') {
            $next_pos = $position;
            if ($next_pos + 1 == $total_count) {
                $next_pos = false;
            }
        }
        if (!$lead_id) {
            $lead = !empty($leads) ? $leads[0] : false;
        } else {
            $lead = GFAPI::get_entry($lead_id);
        }
        if (!$lead) {
            _e("Oops! We couldn't find your entry. Please try again", "gravityforms");
            return;
        }
        RGFormsModel::update_lead_property($lead["id"], "is_read", 1);
        switch (RGForms::post("action")) {
            case "update":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                //Loading files that have been uploaded to temp folder
                $files = GFCommon::json_decode(stripslashes(RGForms::post("gform_uploaded_files")));
                if (!is_array($files)) {
                    $files = array();
                }
                GFFormsModel::$uploaded_files[$form_id] = $files;
                GFFormsModel::save_lead($form, $lead);
                do_action("gform_after_update_entry", $form, $lead["id"]);
                do_action("gform_after_update_entry_{$form["id"]}", $form, $lead["id"]);
                $lead = RGFormsModel::get_lead($lead["id"]);
                $lead = GFFormsModel::set_entry_meta($lead, $form);
                break;
            case "add_note":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["new_note"]));
                //emailing notes if configured
                if (rgpost("gentry_email_notes_to")) {
                    $email_to = $_POST["gentry_email_notes_to"];
                    $email_from = $current_user->user_email;
                    $email_subject = stripslashes($_POST["gentry_email_subject"]);
                    $headers = "From: \"{$email_from}\" <{$email_from}> \r\n";
                    $result = wp_mail($email_to, $email_subject, stripslashes($_POST["new_note"]), $headers);
                }
                break;
            case "add_quick_note":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                $user_data = get_userdata($current_user->ID);
                RGFormsModel::add_note($lead["id"], $current_user->ID, $user_data->display_name, stripslashes($_POST["quick_note"]));
                break;
            case "bulk":
                check_admin_referer('gforms_update_note', 'gforms_update_note');
                if ($_POST["bulk_action"] == "delete") {
                    RGFormsModel::delete_notes($_POST["note"]);
                }
                break;
            case "trash":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "trash");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "restore":
            case "unspam":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "active");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "spam":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                RGFormsModel::update_lead_property($lead["id"], "status", "spam");
                $lead = RGFormsModel::get_lead($lead["id"]);
                break;
            case "delete":
                check_admin_referer('gforms_save_entry', 'gforms_save_entry');
                if (!GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    die(__("You don't have adequate permissions to delete entries.", "gravityforms"));
                }
                RGFormsModel::delete_lead($lead["id"]);
                ?>
                <script type="text/javascript">
                    document.location.href='<?php 
                echo "admin.php?page=gf_entries&view=entries&id=" . absint($form["id"]);
                ?>
';
                </script>
                <?php 
                break;
        }
        $mode = empty($_POST["screen_mode"]) ? "view" : $_POST["screen_mode"];
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css" />
         <script type="text/javascript">

            jQuery(document).ready(function(){
                toggleNotificationOverride(true);
            });

            function DeleteFile(leadId, fieldId, deleteButton){
                if(confirm(<?php 
        _e("'Would you like to delete this file? \\'Cancel\\' to stop. \\'OK\\' to delete'", "gravityforms");
        ?>
)){
                    var fileIndex = jQuery(deleteButton).parent().index();
                    var mysack = new sack("<?php 
        echo admin_url("admin-ajax.php");
        ?>
");
                    mysack.execute = 1;
                    mysack.method = 'POST';
                    mysack.setVar( "action", "rg_delete_file" );
                    mysack.setVar( "rg_delete_file", "<?php 
        echo wp_create_nonce("rg_delete_file");
        ?>
" );
                    mysack.setVar( "lead_id", leadId );
                    mysack.setVar( "field_id", fieldId );
                    mysack.setVar( "file_index", fileIndex );
                    mysack.onError = function() { alert('<?php 
        echo esc_js(__("Ajax error while deleting field.", "gravityforms"));
        ?>
' )};
                    mysack.runAJAX();

                    return true;
                }
            }

            function EndDeleteFile(fieldId, fileIndex){
                var previewFileSelector = "#preview_existing_files_" + fieldId + " .ginput_preview";
                var $previewFiles = jQuery(previewFileSelector);
                var rr = $previewFiles.eq(fileIndex);
                $previewFiles.eq(fileIndex).remove();
                var $visiblePreviewFields = jQuery(previewFileSelector);
                if($visiblePreviewFields.length == 0){
                    jQuery('#preview_' + fieldId).hide();
                    jQuery('#upload_' + fieldId).show('slow');
                }
            }

            function ToggleShowEmptyFields(){
                if(jQuery("#gentry_display_empty_fields").is(":checked")){
                    createCookie("gf_display_empty_fields", true, 10000);
                    document.location = document.location.href;
                }
                else{
                    eraseCookie("gf_display_empty_fields");
                    document.location = document.location.href;
                }
            }

            function createCookie(name,value,days) {
                if (days) {
                    var date = new Date();
                    date.setTime(date.getTime()+(days*24*60*60*1000));
                    var expires = "; expires="+date.toGMTString();
                }
                else var expires = "";
                document.cookie = name+"="+value+expires+"; path=/";
            }

            function eraseCookie(name) {
                createCookie(name,"",-1);
            }

            function ResendNotifications() {

                var selectedNotifications = new Array();
                jQuery(".gform_notifications:checked").each(function(){
                    selectedNotifications.push(jQuery(this).val());
                });

                var sendTo = jQuery('#notification_override_email').val();

                if(selectedNotifications.length <=0) {
                    displayMessage("<?php 
        _e("You must select at least one type of notification to resend.", "gravityforms");
        ?>
", "error", "#notifications_container");
                    return;
                }

                jQuery('#please_wait_container').fadeIn();

                jQuery.post(ajaxurl, {
                        action : "gf_resend_notifications",
                        gf_resend_notifications : '<?php 
        echo wp_create_nonce('gf_resend_notifications');
        ?>
',
                        notifications: jQuery.toJSON(selectedNotifications),
                        sendTo : sendTo,
                        leadIds : '<?php 
        echo $lead['id'];
        ?>
',
                        formId : '<?php 
        echo $form['id'];
        ?>
'
                    },
                    function(response) {
                        if(response) {
                            displayMessage(response, "error", "#notifications_container");
                        } else {
                            displayMessage("<?php 
        _e("Notifications were resent successfully.", "gravityforms");
        ?>
", "updated", "#notifications_container");

                            // reset UI
                            jQuery(".gform_notifications").attr('checked', false);
                            jQuery('#notification_override_email').val('');
                        }

                        jQuery('#please_wait_container').hide();
                        setTimeout(function(){jQuery('#notifications_container').find('.message').slideUp();}, 5000);
                    }
                );

            }

            function displayMessage(message, messageClass, container){

                jQuery(container).find('.message').hide().html(message).attr('class', 'message ' + messageClass).slideDown();

            }

            function toggleNotificationOverride(isInit) {

                if(isInit)
                    jQuery('#notification_override_email').val('');

                if(jQuery(".gform_notifications:checked").length > 0 ) {
                    jQuery('#notifications_override_settings').slideDown();
                }
                else {
                    jQuery('#notifications_override_settings').slideUp(function(){
                        jQuery('#notification_override_email').val('');
                    });
                }
            }

        </script>

        <form method="post" id="entry_form" enctype='multipart/form-data'>
            <?php 
        wp_nonce_field('gforms_save_entry', 'gforms_save_entry');
        ?>
            <input type="hidden" name="action" id="action" value=""/>
            <input type="hidden" name="screen_mode" id="screen_mode" value="<?php 
        echo esc_attr(rgpost("screen_mode"));
        ?>
" />

            <div class="wrap gf_entry_wrap">
            <h2 class="gf_admin_page_title"><span><?php 
        echo __("Entry #", "gravityforms") . absint($lead["id"]);
        ?>
</span><span class="gf_admin_page_subtitle"><span class="gf_admin_page_formid">ID: <?php 
        echo $form['id'];
        ?>
</span><?php 
        echo $form['title'];
        $gf_entry_locking = new GFEntryLocking();
        $gf_entry_locking->lock_info($lead_id);
        ?>
</span></h2>

            <?php 
        if (isset($_GET["pos"])) {
            ?>
            <div class="gf_entry_detail_pagination">
                <ul>
                    <li class="gf_entry_count"><span>entry <strong><?php 
            echo $position + 1;
            ?>
</strong> of <strong><?php 
            echo $total_count;
            ?>
</strong></span></li>
                    <li class="gf_entry_prev gf_entry_pagination"><?php 
            echo GFEntryDetail::entry_detail_pagination_link($prev_pos, 'Previous Entry', 'gf_entry_prev_link', "fa fa-arrow-circle-o-left");
            ?>
</li>
                    <li class="gf_entry_next gf_entry_pagination"><?php 
            echo GFEntryDetail::entry_detail_pagination_link($next_pos, 'Next Entry', 'gf_entry_next_link', "fa fa-arrow-circle-o-right");
            ?>
</li>
                </ul>
            </div>
            <?php 
        }
        ?>

            <?php 
        RGForms::top_toolbar();
        ?>

            <div id="poststuff" class="metabox-holder has-right-sidebar">
                <div id="side-info-column" class="inner-sidebar">
                	<?php 
        do_action("gform_entry_detail_sidebar_before", $form, $lead);
        ?>

                    <!-- INFO BOX -->
                    <div id="submitdiv" class="stuffbox">
                        <h3>
                            <span class="hndle"><?php 
        _e("Entry", "gravityforms");
        ?>
</span>
                        </h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">
                                <div id="minor-publishing" style="padding:10px;">
                                    <br/>
                                    <?php 
        _e("Entry Id", "gravityforms");
        ?>
: <?php 
        echo absint($lead["id"]);
        ?>
<br/><br/>
                                    <?php 
        _e("Submitted on", "gravityforms");
        ?>
: <?php 
        echo esc_html(GFCommon::format_date($lead["date_created"], false, "Y/m/d"));
        ?>
                                    <br/><br/>
                                    <?php 
        _e("User IP", "gravityforms");
        ?>
: <?php 
        echo $lead["ip"];
        ?>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["created_by"]) && ($usermeta = get_userdata($lead["created_by"]))) {
            ?>
                                        <?php 
            _e("User", "gravityforms");
            ?>
: <a href="user-edit.php?user_id=<?php 
            echo absint($lead["created_by"]);
            ?>
" alt="<?php 
            _e("View user profile", "gravityforms");
            ?>
" title="<?php 
            _e("View user profile", "gravityforms");
            ?>
"><?php 
            echo esc_html($usermeta->user_login);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        ?>

                                    <?php 
        _e("Embed Url", "gravityforms");
        ?>
: <a href="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" target="_blank" alt="<?php 
        echo esc_url($lead["source_url"]);
        ?>
" title="<?php 
        echo esc_url($lead["source_url"]);
        ?>
">.../<?php 
        echo esc_html(GFCommon::truncate_url($lead["source_url"]));
        ?>
</a>
                                    <br/><br/>
                                    <?php 
        if (!empty($lead["post_id"])) {
            $post = get_post($lead["post_id"]);
            ?>
                                        <?php 
            _e("Edit Post", "gravityforms");
            ?>
: <a href="post.php?action=edit&post=<?php 
            echo absint($post->ID);
            ?>
" alt="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
" title="<?php 
            _e("Click to edit post", "gravityforms");
            ?>
"><?php 
            echo esc_html($post->post_title);
            ?>
</a>
                                        <br/><br/>
                                        <?php 
        }
        if (apply_filters("gform_enable_entry_info_payment_details", true, $lead)) {
            if (!empty($lead["payment_status"])) {
                echo $lead["transaction_type"] == 2 ? __("Subscription Status", "gravityforms") : __("Payment Status", "gravityforms");
                ?>
: <span id="gform_payment_status"><?php 
                echo apply_filters("gform_payment_status", $lead["payment_status"], $form, $lead);
                ?>
</span>
                                            <br/><br/>
                                            <?php 
                if (!empty($lead["payment_date"])) {
                    echo $lead["transaction_type"] == 2 ? __("Start Date", "gravityforms") : __("Payment Date", "gravityforms");
                    ?>
: <?php 
                    echo GFCommon::format_date($lead["payment_date"], false, "Y/m/d", $lead["transaction_type"] != 2);
                    ?>
                                                <br/><br/>
                                                <?php 
                }
                if (!empty($lead["transaction_id"])) {
                    echo $lead["transaction_type"] == 2 ? __("Subscriber Id", "gravityforms") : __("Transaction Id", "gravityforms");
                    ?>
: <?php 
                    echo $lead["transaction_id"];
                    ?>
                                                <br/><br/>
                                                <?php 
                }
                if (!rgblank($lead["payment_amount"])) {
                    echo $lead["transaction_type"] == 2 ? __("Subscription Amount", "gravityforms") : __("Payment Amount", "gravityforms");
                    ?>
: <?php 
                    echo GFCommon::to_money($lead["payment_amount"], $lead["currency"]);
                    ?>
                                                <br/><br/>
                                                <?php 
                }
            }
        }
        do_action("gform_entry_info", $form["id"], $lead);
        ?>
                                </div>
                                <div id="major-publishing-actions">
                                    <div id="delete-action">
                                        <?php 
        switch ($lead["status"]) {
            case "spam":
                if (GFCommon::akismet_enabled($form['id'])) {
                    ?>
                                                    <a onclick="jQuery('#action').val('unspam'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Not Spam", "gravityforms");
                    ?>
</a>
                                                    <?php 
                    echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                }
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="if ( confirm('<?php 
                    _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", "gravityforms");
                    ?>
') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</a>
                                                    <?php 
                }
                break;
            case "trash":
                ?>
                                                <a onclick="jQuery('#action').val('restore'); jQuery('#entry_form').submit()" href="#"><?php 
                _e("Restore", "gravityforms");
                ?>
</a>
                                                <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    |
                                                    <a class="submitdelete deletion" onclick="if ( confirm('<?php 
                    _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", "gravityforms");
                    ?>
') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</a>
                                                    <?php 
                }
                break;
            default:
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="jQuery('#action').val('trash'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Move to Trash", "gravityforms");
                    ?>
</a>
                                                    <?php 
                    echo GFCommon::akismet_enabled($form['id']) ? "|" : "";
                }
                if (GFCommon::akismet_enabled($form['id'])) {
                    ?>
                                                    <a class="submitdelete deletion" onclick="jQuery('#action').val('spam'); jQuery('#entry_form').submit()" href="#"><?php 
                    _e("Mark as Spam", "gravityforms");
                    ?>
</a>
                                                <?php 
                }
        }
        ?>
                                    </div>
                                    <div id="publishing-action">
                                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entries") && $lead["status"] != "trash") {
            $button_text = $mode == "view" ? __("Edit", "gravityforms") : __("Update", "gravityforms");
            $button_click = $mode == "view" ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');";
            $update_button = '<input class="button button-large button-primary" type="submit" tabindex="4" value="' . $button_text . '" name="save" onclick="' . $button_click . '"/>';
            echo apply_filters("gform_entrydetail_update_button", $update_button);
            if ($mode == "edit") {
                echo '&nbsp;&nbsp;<input class="button button-large" type="submit" tabindex="5" value="' . __("Cancel", "gravityforms") . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>';
            }
        }
        ?>
                                    </div>
                                    <div class="clear"></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php 
        if (!empty($lead["payment_status"]) && !apply_filters("gform_enable_entry_info_payment_details", true, $lead)) {
            self::payment_details_box($lead, $form);
        }
        ?>

                    <?php 
        do_action("gform_entry_detail_sidebar_middle", $form, $lead);
        ?>

                    <?php 
        if (GFCommon::current_user_can_any("gravityforms_edit_entry_notes")) {
            ?>
                        <!-- start notifications -->
                        <div class="postbox" id="notifications_container">
                            <h3 style="cursor:default;"><span><?php 
            _e("Notifications", "gravityforms");
            ?>
</span></h3>
                            <div class="inside">
                                <div class="message" style="display:none; padding:10px; margin:10px 0px;"></div>
                                <div>
                                    <?php 
            if (!is_array($form["notifications"]) || count($form["notifications"]) <= 0) {
                ?>
                                        <p class="description"><?php 
                _e("You cannot resend notifications for this entry because this form does not currently have any notifications configured.", "gravityforms");
                ?>
</p>

                                        <a href="<?php 
                echo admin_url("admin.php?page=gf_edit_forms&view=settings&subview=notification&id={$form["id"]}");
                ?>
" class="button"><?php 
                _e("Configure Notifications", "gravityforms");
                ?>
</a>
                                    <?php 
            } else {
                foreach ($form["notifications"] as $notification) {
                    ?>
                                            <input type="checkbox" class="gform_notifications" value="<?php 
                    echo $notification["id"];
                    ?>
" id="notification_<?php 
                    echo $notification["id"];
                    ?>
" onclick="toggleNotificationOverride();" />
                                            <label for="notification_<?php 
                    echo $notification["id"];
                    ?>
"><?php 
                    echo $notification["name"];
                    ?>
</label> <br /><br />
                                        <?php 
                }
                ?>

                                        <div id="notifications_override_settings" style="display:none;">

                                            <p class="description" style="padding-top:0; margin-top:0; width:99%;">You may override the default notification settings
                                                by entering a comma delimited list of emails to which the selected notifications should be sent.</p>
                                            <label for="notification_override_email"><?php 
                _e("Send To", "gravityforms");
                ?>
 <?php 
                gform_tooltip("notification_override_email");
                ?>
</label><br />
                                            <input type="text" name="notification_override_email" id="notification_override_email" style="width:99%;" />
                                            <br /><br />

                                        </div>

                                        <input type="button" name="notification_resend" value="<?php 
                _e("Resend Notifications", "gravityforms");
                ?>
" class="button" style="" onclick="ResendNotifications();"/>
                                        <span id="please_wait_container" style="display:none; margin-left: 5px;">
                                            <img src="<?php 
                echo GFCommon::get_base_url();
                ?>
/images/loading.gif"> <?php 
                _e("Resending...", "gravityforms");
                ?>
                                        </span>
                                    <?php 
            }
            ?>

                                </div>
                            </div>
                        </div>
                       <!-- / end notifications -->
                   <?php 
        }
        ?>

                   <!-- begin print button -->
                   <div class="detail-view-print">
                       <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '&notes=1' : ''; var url='<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=print-entry&fid=<?php 
        echo $form['id'];
        ?>
&lid=<?php 
        echo $lead['id'];
        ?>
' + notes_qs; window.open (url,'printwindow');" class="button"><?php 
        _e("Print", "gravityforms");
        ?>
</a>
                       <?php 
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                           <input type="checkbox" name="print_notes" value="print_notes" checked="checked" id="gform_print_notes"/>
                           <label for="print_notes"><?php 
            _e("include notes", "gravityforms");
            ?>
</label>
                       <?php 
        }
        ?>
                   </div>
                   <!-- end print button -->
				   <?php 
        do_action("gform_entry_detail_sidebar_after", $form, $lead);
        ?>
                </div>

                <div id="post-body" class="has-sidebar">
                    <div id="post-body-content" class="has-sidebar-content">
                        <?php 
        do_action("gform_entry_detail_content_before", $form, $lead);
        if ($mode == "view") {
            self::lead_detail_grid($form, $lead, true);
        } else {
            self::lead_detail_edit($form, $lead);
        }
        do_action("gform_entry_detail", $form, $lead);
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                            <div class="postbox">
                                <h3>
                                    <label for="name"><?php 
            _e("Notes", "gravityforms");
            ?>
</label>
                                </h3>

                                <form method="post">
                                    <?php 
            wp_nonce_field('gforms_update_note', 'gforms_update_note');
            ?>
                                    <div class="inside">
                                        <?php 
            $notes = RGFormsModel::get_lead_notes($lead["id"]);
            //getting email values
            $email_fields = GFCommon::get_email_fields($form);
            $emails = array();
            foreach ($email_fields as $email_field) {
                if (!empty($lead[$email_field["id"]])) {
                    $emails[] = $lead[$email_field["id"]];
                }
            }
            //displaying notes grid
            $subject = !empty($form["autoResponder"]["subject"]) ? "RE: " . GFCommon::replace_variables($form["autoResponder"]["subject"], $form, $lead) : "";
            self::notes_grid($notes, true, $emails, $subject);
            ?>
                                    </div>
                                </form>
                            </div>
                        <?php 
        }
        do_action("gform_entry_detail_content_after", $form, $lead);
        ?>
                    </div>
                </div>
            </div>
        </div>
        </form>
        <?php 
        if (rgpost("action") == "update") {
            ?>
            <div class="updated fade" style="padding:6px;">
                <?php 
            _e("Entry Updated.", "gravityforms");
            ?>
            </div>
            <?php 
        }
    }
 /**
  * Process any merge tags and shortcodes found in the template.
  *
  * @param string $template The template.
  * @param string $field_type The field type currently being processed. Possible values: post_custom_field, post_content, or post_title.
  * @param array $post_images The uploaded post images.
  * @param array $post_data The post data prepared from the current entry.
  * @param array $form The form currently being processed.
  * @param array $entry The entry currently being processed.
  *
  * @return string
  */
 public static function process_post_template($template, $field_type, $post_images, $post_data, $form, $entry)
 {
     GFCommon::log_debug(__METHOD__ . "(): Processing {$field_type} template.");
     //replacing post image variables
     $template = GFCommon::replace_variables_post_image($template, $post_images, $entry);
     //replacing all other variables
     $template = GFCommon::replace_variables($template, $form, $entry, false, false, false);
     if ($field_type != 'post_content') {
         $process_template_shortcodes = true;
         /**
          * Allow shortcode processing of custom field and post title templates to be disabled.
          *
          * @param boolean $process_template_shortcodes Should the shortcodes be processed? Default is true.
          * @param string $field_type The field type currently being processed. Possible values: post_custom_field, post_content, or post_title.
          * @param array $post_data The post data prepared from the current entry.
          * @param array $form The form currently being processed.
          * @param array $entry The entry currently being processed.
          *
          * @since 2.0.0.4
          */
         $process_template_shortcodes = apply_filters('gform_process_template_shortcodes_pre_create_post', $process_template_shortcodes, $field_type, $post_data, $form, $entry);
         $process_template_shortcodes = apply_filters('gform_process_template_shortcodes_pre_create_post_' . $form['id'], $process_template_shortcodes, $field_type, $post_data, $form, $entry);
         if ($process_template_shortcodes) {
             $template = do_shortcode($template);
         }
     }
     return $template;
 }
 /**
  * Create a new task from a feed.
  * 
  * @access public
  * @param int $record_id
  * @param string $module
  * @param array $feed
  * @param array $entry
  * @param array $form
  * @return void
  */
 public function create_task($record_id, $module, $feed, $entry, $form)
 {
     if (rgars($feed, 'meta/createTask') != '1') {
         return;
     }
     /* Create task object. */
     $task = array('Subject' => GFCommon::replace_variables($feed['meta']['taskSubject'], $form, $entry, false, false, false, 'text'), 'Status' => rgars($feed, 'meta/taskStatus'), 'SMOWNERID' => rgars($feed, 'meta/taskOwner'), 'Description' => GFCommon::replace_variables($feed['meta']['taskDescription'], $form, $entry, false, false, false, 'text'));
     if (rgars($feed, 'meta/taskDueDate')) {
         $due_date = GFCommon::replace_variables($feed['meta']['taskDueDate'], $form, $entry, false, false, false, 'text');
         if (is_numeric($due_date)) {
             $task['Due Date'] = date('Y-m-d', strtotime('+' . $due_date . ' days'));
         }
     }
     /* Add lead or contact ID. */
     if ($module === 'Contacts') {
         $task['CONTACTID'] = $record_id;
     } else {
         if ($module === 'Leads') {
             $task['SEID'] = $record_id;
             $task['SEMODULE'] = $module;
         }
     }
     /* Filter task. */
     $task = gf_apply_filters('gform_zohocrm_task', $form['id'], $task, $feed, $entry, $form);
     /* Remove SMOWNERID if not set. */
     if (rgblank($task['SMOWNERID'])) {
         unset($task['SMOWNERID']);
     }
     /* Prepare task record XML. */
     $task_xml = '<Tasks>' . "\r\n";
     $task_xml .= '<row no="1">' . "\r\n";
     foreach ($task as $field_key => $field_value) {
         $task_xml .= $this->get_field_xml($field_key, $field_value);
     }
     $task_xml .= '</row>' . "\r\n";
     $task_xml .= '</Tasks>' . "\r\n";
     $this->log_debug(__METHOD__ . '(): Creating task: ' . print_r($task, true));
     $this->log_debug(__METHOD__ . '(): Creating task XML: ' . print_r($task_xml, true));
     try {
         /* Insert task record. */
         $task_record = $this->api->insert_record('Tasks', $task_xml);
         /* Get ID of new task record. */
         $task_id = 0;
         foreach ($task_record->result->recorddetail as $detail) {
             foreach ($detail->children() as $field) {
                 if ($field['val'] == 'Id') {
                     $task_id = (string) $field;
                 }
             }
         }
         /* Save task ID to entry meta. */
         gform_update_meta($entry['id'], 'zohocrm_task_id', $task_id);
         /* Log that task was created. */
         $this->log_debug(__METHOD__ . '(): Task #' . $task_id . ' created and assigned to ' . $module . ' #' . $record_id . '.');
         return $task_id;
     } catch (Exception $e) {
         $this->log_error(__METHOD__ . '(): Could not create task; ' . $e->getMessage());
         return null;
     }
 }
 public static function get_calculation_value($field_id, $form, $lead, $number_format = '')
 {
     $filters = array('price', 'value', '');
     $value = false;
     $field = RGFormsModel::get_field($form, $field_id);
     $is_pricing_field = self::has_currency_value($field);
     if ($field->numberFormat) {
         $number_format = $field->numberFormat;
     } elseif (empty($number_format)) {
         $number_format = 'decimal_dot';
     }
     foreach ($filters as $filter) {
         if (is_numeric($value)) {
             //value found, exit loop
             break;
         }
         $replaced_value = GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead);
         if ($is_pricing_field) {
             $value = self::to_number($replaced_value);
         } else {
             $value = self::clean_number($replaced_value, $number_format);
         }
     }
     if (!$value || !is_numeric($value)) {
         GFCommon::log_debug("GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead.");
         $value = 0;
     }
     return $value;
 }
 public static function create_post($form, &$lead)
 {
     GFCommon::log_debug('GFFormsModel::create_post(): Starting.');
     $has_post_field = false;
     foreach ($form['fields'] as $field) {
         $is_hidden = self::is_field_hidden($form, $field, array(), $lead);
         if (!$is_hidden && in_array($field->type, array('post_category', 'post_title', 'post_content', 'post_excerpt', 'post_tags', 'post_custom_field', 'post_image'))) {
             $has_post_field = true;
             break;
         }
     }
     //if this form does not have any post fields, don't create a post
     if (!$has_post_field) {
         GFCommon::log_debug("GFFormsModel::create_post(): Stopping. The form doesn't have any post fields.");
         return $lead;
     }
     //processing post fields
     GFCommon::log_debug('GFFormsModel::create_post(): Getting post fields.');
     $post_data = self::get_post_fields($form, $lead);
     //allowing users to change post fields before post gets created
     $post_data = gf_apply_filters('gform_post_data', $form['id'], $post_data, $form, $lead);
     //adding default title if none of the required post fields are in the form (will make sure wp_insert_post() inserts the post)
     if (empty($post_data['post_title']) && empty($post_data['post_content']) && empty($post_data['post_excerpt'])) {
         $post_data['post_title'] = self::get_default_post_title();
     }
     // remove original post status and save it for later
     $post_status = $post_data['post_status'];
     // replace original post status with 'draft' so other plugins know this post is not fully populated yet
     $post_data['post_status'] = 'draft';
     // inserting post
     GFCommon::log_debug('GFFormsModel::create_post(): Inserting post via wp_insert_post().');
     $post_id = wp_insert_post($post_data);
     GFCommon::log_debug("GFFormsModel::create_post(): Result from wp_insert_post(): {$post_id}.");
     //adding form id and entry id hidden custom fields
     add_post_meta($post_id, '_gform-form-id', $form['id']);
     add_post_meta($post_id, '_gform-entry-id', $lead['id']);
     //creating post images
     GFCommon::log_debug('GFFormsModel::create_post(): Creating post images.');
     $post_images = array();
     foreach ($post_data['images'] as $image) {
         $image_meta = array('post_excerpt' => $image['caption'], 'post_content' => $image['description']);
         //adding title only if it is not empty. It will default to the file name if it is not in the array
         if (!empty($image['title'])) {
             $image_meta['post_title'] = $image['title'];
         }
         if (!empty($image['url'])) {
             GFCommon::log_debug('GFFormsModel::create_post(): Adding image: ' . $image['url']);
             $media_id = self::media_handle_upload($image['url'], $post_id, $image_meta);
             if ($media_id) {
                 //save media id for post body/title template variable replacement (below)
                 $post_images[$image['field_id']] = $media_id;
                 $lead[$image['field_id']] .= "|:|{$media_id}";
                 // set featured image
                 $field = RGFormsModel::get_field($form, $image['field_id']);
                 if ($field->postFeaturedImage) {
                     set_post_thumbnail($post_id, $media_id);
                 }
             }
         }
     }
     //adding custom fields
     GFCommon::log_debug('GFFormsModel::create_post(): Adding custom fields.');
     foreach ($post_data['post_custom_fields'] as $meta_name => $meta_value) {
         if (!is_array($meta_value)) {
             $meta_value = array($meta_value);
         }
         $meta_index = 0;
         foreach ($meta_value as $value) {
             GFCommon::log_debug('GFFormsModel::create_post(): Getting custom field: ' . $meta_name);
             $custom_field = self::get_custom_field($form, $meta_name, $meta_index);
             //replacing template variables if template is enabled
             if ($custom_field && rgget('customFieldTemplateEnabled', $custom_field)) {
                 //replacing post image variables
                 GFCommon::log_debug('GFFormsModel::create_post(): Replacing post image variables.');
                 $value = GFCommon::replace_variables_post_image($custom_field['customFieldTemplate'], $post_images, $lead);
                 //replacing all other variables
                 $value = GFCommon::replace_variables($value, $form, $lead, false, false, false);
                 // replace conditional shortcodes
                 $value = do_shortcode($value);
             }
             switch (RGFormsModel::get_input_type($custom_field)) {
                 case 'list':
                     $value = maybe_unserialize($value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (is_array($item)) {
                                 $item = implode('|', $item);
                             }
                             if (!rgblank($item)) {
                                 add_post_meta($post_id, $meta_name, $item);
                             }
                         }
                     }
                     break;
                 case 'multiselect':
                 case 'checkbox':
                     $value = explode(',', $value);
                     if (is_array($value)) {
                         foreach ($value as $item) {
                             if (!rgblank($item)) {
                                 // add post meta and replace HTML symbol in $item with real comma
                                 add_post_meta($post_id, $meta_name, str_replace('&#44;', ',', $item));
                             }
                         }
                     }
                     break;
                 case 'date':
                     $value = GFCommon::date_display($value, rgar($custom_field, 'dateFormat'));
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
                 default:
                     if (!rgblank($value)) {
                         add_post_meta($post_id, $meta_name, $value);
                     }
                     break;
             }
             $meta_index++;
         }
     }
     $has_content_field = sizeof(self::get_fields_by_type($form, array('post_content'))) > 0;
     $has_title_field = sizeof(self::get_fields_by_type($form, array('post_title'))) > 0;
     $post = false;
     //if a post field was configured with a content or title template, process template
     if (rgar($form, 'postContentTemplateEnabled') && $has_content_field || rgar($form, 'postTitleTemplateEnabled') && $has_title_field) {
         GFCommon::log_debug('GFFormsModel::create_post(): Processing template.');
         $post = get_post($post_id);
         if (rgar($form, 'postContentTemplateEnabled') && $has_content_field) {
             //replacing post image variables
             $post_content = GFCommon::replace_variables_post_image($form['postContentTemplate'], $post_images, $lead);
             //replacing all other variables
             $post_content = GFCommon::replace_variables($post_content, $form, $lead, false, false, false);
             //updating post content
             $post->post_content = $post_content;
         }
         if (rgar($form, 'postTitleTemplateEnabled') && $has_title_field) {
             //replacing post image variables
             $post_title = GFCommon::replace_variables_post_image($form['postTitleTemplate'], $post_images, $lead);
             //replacing all other variables
             $post_title = GFCommon::replace_variables($post_title, $form, $lead, false, false, false);
             // replace conditional shortcodes
             $post_title = do_shortcode($post_title);
             //updating post
             $post->post_title = $post_title;
             $post->post_name = $post_title;
         }
     }
     // update post status back to original status (if not draft)
     if ($post_status != 'draft') {
         $post = is_object($post) ? $post : get_post($post_id);
         $post->post_status = $post_status;
     }
     // if post has been modified since creation, save updates
     if (is_object($post)) {
         GFCommon::log_debug('GFFormsModel::create_post(): Updating post.');
         wp_update_post($post);
     }
     //adding post format
     if (current_theme_supports('post-formats') && rgar($form, 'postFormat')) {
         $formats = get_theme_support('post-formats');
         $post_format = rgar($form, 'postFormat');
         if (is_array($formats)) {
             $formats = $formats[0];
             if (in_array($post_format, $formats)) {
                 set_post_format($post_id, $post_format);
             } else {
                 if ('0' == $post_format) {
                     set_post_format($post_id, false);
                 }
             }
         }
     }
     //update post_id field if a post was created
     $lead['post_id'] = $post_id;
     GFCommon::log_debug('GFFormsModel::create_post(): Updating entry with post id.');
     self::update_lead_property($lead['id'], 'post_id', $post_id);
     do_action('gform_after_create_post', $post_id);
     return $post_id;
 }
 public static function get_calculation_value($field_id, $form, $lead)
 {
     $filters = array('price', 'value', '');
     $value = false;
     foreach ($filters as $filter) {
         if (is_numeric($value)) {
             //value found, exit loop
             break;
         }
         $value = GFCommon::to_number(GFCommon::replace_variables("{:{$field_id}:{$filter}}", $form, $lead));
     }
     if (!$value || !is_numeric($value)) {
         GFCommon::log_debug("GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead.");
         $value = 0;
     }
     return $value;
 }