public static function update_form_meta($form_id, $form_meta, $meta_name = 'display_meta') { global $wpdb; $form_meta = gf_apply_filters('gform_form_update_meta', $form_id, $form_meta, $form_id, $meta_name); $meta_table_name = self::get_meta_table_name(); $form_meta = json_encode($form_meta); if (intval($wpdb->get_var($wpdb->prepare("SELECT count(0) FROM {$meta_table_name} WHERE form_id=%d", $form_id))) > 0) { $result = $wpdb->query($wpdb->prepare("UPDATE {$meta_table_name} SET {$meta_name}=%s WHERE form_id=%d", $form_meta, $form_id)); } else { $result = $wpdb->query($wpdb->prepare("INSERT INTO {$meta_table_name}(form_id, {$meta_name}) VALUES(%d, %s)", $form_id, $form_meta)); } self::$_current_forms[$form_id] = null; gf_do_action('gform_post_update_form_meta', $form_id, $form_meta, $form_id, $meta_name); return $result; }
public static function lead_detail_page() { global $current_user; if (!GFCommon::ensure_wp_version()) { return; } echo GFCommon::get_remote_message(); $form = RGFormsModel::get_form_meta(absint($_GET['id'])); $form_id = absint($form['id']); $form = gf_apply_filters(array('gform_admin_pre_render', $form_id), $form); $lead_id = rgpost('entry_id') ? absint(rgpost('entry_id')) : absint(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'; $search_criteria['status'] = $status; require_once 'entry_list.php'; $filter_links = GFEntryList::get_filter_links($form, false); foreach ($filter_links as $filter_link) { if ($filter == $filter_link['id']) { $search_criteria['field_filters'] = $filter_link['field_filters']; break; } } $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; } $search_criteria['field_filters'][] = array('key' => $key, 'operator' => rgempty('operator', $_GET) ? 'is' : rgget('operator'), 'value' => $val); $type = rgget('type'); if (empty($type)) { if (rgget('field_id') == '0') { $search_criteria['type'] = 'global'; } } } /** * Allow the entry list search criteria to be overridden. * * @since 1.9.14.30 * * @param array $search_criteria An array containing the search criteria. * @param int $form_id The ID of the current form. */ $search_criteria = gf_apply_filters(array('gform_search_criteria_entry_list', $form_id), $search_criteria, $form_id); $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) { esc_html_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(); } $original_entry = $lead; GFFormsModel::$uploaded_files[$form_id] = $files; GFFormsModel::save_lead($form, $lead); /** * Fires after the Entry is updated from the entry detail page. * * @param array $form The form object for the entry. * @param integer $lead['id'] The entry ID. * @param array $original_entry The entry object before being updated. */ gf_do_action(array('gform_after_update_entry', $form['id']), $form, $lead['id'], $original_entry); $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')) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Preparing to email entry notes.'); $email_to = $_POST['gentry_email_notes_to']; $email_from = $current_user->user_email; $email_subject = stripslashes($_POST['gentry_email_subject']); $body = stripslashes($_POST['new_note']); $headers = "From: \"{$email_from}\" <{$email_from}> \r\n"; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Emailing notes - TO: {$email_to} SUBJECT: {$email_subject} BODY: {$body} HEADERS: {$headers}"); $is_success = wp_mail($email_to, $email_subject, $body, $headers); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFEntryDetail::lead_detail_page(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } /** * Fires after a note is attached to an entry and sent as an email * * @param string $result The Error message or success message when the entry note is sent * @param string $email_to The email address to send the entry note to * @param string $email_from The email address from which the email is sent from * @param string $email_subject The subject of the email that is sent * @param mixed $body The Full body of the email containing the message after the note is sent * @param array $form The current form object * @param array $lead The Current lead object */ do_action('gform_post_send_entry_note', $result, $email_to, $email_from, $email_subject, $body, $form, $lead); } 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') { if (!GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { die(esc_html__("You don't have adequate permission to delete notes.", 'gravityforms')); } 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(esc_html__("You don't have adequate permission 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']; $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min'; ?> <link rel="stylesheet" href="<?php echo GFCommon::get_base_url(); ?> /css/admin<?php echo $min; ?> .css" /> <script type="text/javascript"> jQuery(document).ready(function () { toggleNotificationOverride(true); jQuery('#gform_update_button').prop('disabled', false); }); function DeleteFile(leadId, fieldId, deleteButton) { if (confirm(<?php echo json_encode(__("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 json_encode(__('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 echo json_encode(__('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 absint($lead['id']); ?> ', formId : '<?php echo absint($form['id']); ?> ' }, function (response) { if (response) { displayMessage(response, "error", "#notifications_container"); } else { displayMessage(<?php echo json_encode(esc_html__('Notifications were resent successfully.', 'gravityforms')); ?> , "updated", "#notifications_container" ); // reset UI jQuery(".gform_notifications").attr( 'checked', false ); jQuery('#notification_override_email').val(''); toggleNotificationOverride(); } 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')); ?> " /> <input type="hidden" name="entry_id" id="entry_id" value="<?php echo absint($lead['id']); ?> " /> <div class="wrap gf_entry_wrap"> <h2 class="gf_admin_page_title"> <span><?php echo esc_html__('Entry #', 'gravityforms') . absint($lead['id']); ?> </span><span class="gf_admin_page_subtitle"><span class="gf_admin_page_formid">ID: <?php echo absint($form['id']); ?> </span><span class='gf_admin_page_formname'><?php esc_html_e('Form Name', 'gravityforms'); ?> : <?php echo esc_html($form['title']); $gf_entry_locking = new GFEntryLocking(); $gf_entry_locking->lock_info($lead_id); ?> </span></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 class="hndle" style="cursor:default;"> <span><?php esc_html_e('Entry', 'gravityforms'); ?> </span> </h3> <div class="inside"> <div id="submitcomment" class="submitbox"> <div id="minor-publishing" style="padding:10px;"> <?php esc_html_e('Entry Id', 'gravityforms'); ?> : <?php echo absint($lead['id']); ?> <br /><br /> <?php esc_html_e('Submitted on', 'gravityforms'); ?> : <?php echo esc_html(GFCommon::format_date($lead['date_created'], false, 'Y/m/d')); ?> <br /><br /> <?php esc_html_e('User IP', 'gravityforms'); ?> : <?php echo esc_html($lead['ip']); ?> <br /><br /> <?php if (!empty($lead['created_by']) && ($usermeta = get_userdata($lead['created_by']))) { ?> <?php esc_html_e('User', 'gravityforms'); ?> : <a href="user-edit.php?user_id=<?php echo absint($lead['created_by']); ?> " alt="<?php esc_attr_e('View user profile', 'gravityforms'); ?> " title="<?php esc_attr_e('View user profile', 'gravityforms'); ?> "><?php echo esc_html($usermeta->user_login); ?> </a> <br /><br /> <?php } ?> <?php esc_html_e('Embed Url', 'gravityforms'); ?> : <a href="<?php echo esc_url($lead['source_url']); ?> " target="_blank" alt="<?php echo esc_attr($lead['source_url']); ?> " title="<?php echo esc_attr($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 esc_html_e('Edit Post', 'gravityforms'); ?> : <a href="post.php?action=edit&post=<?php echo absint($post->ID); ?> " alt="<?php esc_attr_e('Click to edit post', 'gravityforms'); ?> " title="<?php esc_attr_e('Click to edit post', 'gravityforms'); ?> "><?php echo esc_html($post->post_title); ?> </a> <br /><br /> <?php } if (do_action('gform_enable_entry_info_payment_details', true, $lead)) { if (!empty($lead['payment_status'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Payment Status', 'gravityforms') : esc_html__('Subscription Status', 'gravityforms'); ?> : <span id="gform_payment_status"><?php /** * Filters through a form payment status and allows modification * * @param string $lead['payment_status] A payment status to filter though * @param array $form The Form Object to filter through * @param array $lead The Lead Object to filter through */ 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 ? esc_html__('Payment Date', 'gravityforms') : esc_html__('Start 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 ? esc_html__('Transaction Id', 'gravityforms') : esc_html__('Subscriber Id', 'gravityforms'); ?> : <?php echo esc_html($lead['transaction_id']); ?> <br /><br /> <?php } if (!rgblank($lead['payment_amount'])) { echo $lead['transaction_type'] != 2 ? esc_html__('Payment Amount', 'gravityforms') : esc_html__('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 switch ($lead['status']) { case 'spam': if (GFCommon::spam_enabled($form['id'])) { ?> <a onclick="jQuery('#action').val('unspam'); jQuery('#entry_form').submit()" href="#"><?php esc_html_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 echo esc_js(__("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 esc_html_e('Delete Permanently', 'gravityforms'); ?> </a> <?php } break; case 'trash': ?> <a onclick="jQuery('#action').val('restore'); jQuery('#entry_form').submit()" href="#"><?php esc_html_e('Restore', 'gravityforms'); ?> </a> <?php if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> | <a class="submitdelete deletion" onclick="if ( confirm('<?php echo esc_js(__("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 esc_html_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 esc_html_e('Move to Trash', 'gravityforms'); ?> </a> <?php echo GFCommon::spam_enabled($form['id']) ? '|' : ''; } if (GFCommon::spam_enabled($form['id'])) { ?> <a class="submitdelete deletion" onclick="jQuery('#action').val('spam'); jQuery('#entry_form').submit()" href="#"><?php esc_html_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'); $disabled = $mode == 'view' ? '' : ' disabled="disabled" '; $update_button_id = $mode == 'view' ? 'gform_edit_button' : 'gform_update_button'; $button_click = $mode == 'view' ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');"; $update_button = '<input id="' . $update_button_id . '" ' . $disabled . ' class="button button-large button-primary" type="submit" tabindex="4" value="' . esc_attr($button_text) . '" name="save" onclick="' . $button_click . '"/>'; /** * A filter to allow the modification of the button to update an entry detail * * @param string $update_button The HTML Rendered for the Entry Detail update button */ echo apply_filters('gform_entrydetail_update_button', $update_button); if ($mode == 'edit') { echo ' <input class="button button-large" type="submit" tabindex="5" value="' . esc_attr__('Cancel', 'gravityforms') . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>'; } } ?> </div> <div class="clear"></div> </div> </div> </div> </div> <?php /** * A filter to enable or disable the extra payment details box in an entry * * @param bool To enable (true) or disable (false) * @param array $lead The Lead object to filter */ 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 class="hndle" style="cursor:default;"> <span><?php esc_html_e('Notifications', 'gravityforms'); ?> </span> </h3> <div class="inside"> <div class="message" style="display:none;padding:10px;"></div> <div> <?php $notifications = GFCommon::get_notifications('resend_notifications', $form); if (!is_array($notifications) || count($form['notifications']) <= 0) { ?> <p class="description"><?php esc_html_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 esc_html_e('Configure Notifications', 'gravityforms'); ?> </a> <?php } else { foreach ($notifications as $notification) { ?> <input type="checkbox" class="gform_notifications" value="<?php echo esc_attr($notification['id']); ?> " id="notification_<?php echo esc_attr($notification['id']); ?> " onclick="toggleNotificationOverride();" /> <label for="notification_<?php echo esc_attr($notification['id']); ?> "><?php echo esc_html($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 esc_html_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 esc_attr_e('Resend Notifications', 'gravityforms'); ?> " class="button" style="" onclick="ResendNotifications();" /> <span id="please_wait_container" style="display:none; margin-left: 5px;"> <i class='gficon-gravityforms-spinner-icon gficon-spin'></i> <?php esc_html_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') ? '¬es=1' : ''; var url='<?php echo trailingslashit(site_url()); ?> ?gf_page=print-entry&fid=<?php echo absint($form['id']); ?> &lid=<?php echo absint($lead['id']); ?> ' + notes_qs; window.open (url,'printwindow');" class="button"><?php esc_html_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 esc_html_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); $form = gf_apply_filters(array('gform_admin_pre_render', $form['id']), $form); 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 esc_html_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 = ''; 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 esc_html_e('Entry Updated.', 'gravityforms'); ?> </div> <?php } }
/** * Enqueue and retrieve all inline scripts that should be executed when the form is rendered. * Use add_init_script() function to enqueue scripts. * * @param array $form * @param array $field_values * @param bool $is_ajax */ private static function register_form_init_scripts($form, $field_values = array(), $is_ajax = false) { if (rgars($form, 'save/enabled')) { $save_script = "jQuery('#gform_save_{$form['id']}').val('');"; self::add_init_script($form['id'], 'save', self::ON_PAGE_RENDER, $save_script); } // adding conditional logic script if conditional logic is configured for this form. // get_conditional_logic also adds the chosen script for the enhanced dropdown option. // if this form does not have conditional logic, add chosen script separately if (self::has_conditional_logic($form)) { self::add_init_script($form['id'], 'number_formats', self::ON_PAGE_RENDER, self::get_number_formats_script($form)); self::add_init_script($form['id'], 'conditional_logic', self::ON_PAGE_RENDER, self::get_conditional_logic($form, $field_values)); } //adding currency config if there are any product fields in the form if (self::has_price_field($form)) { self::add_init_script($form['id'], 'pricing', self::ON_PAGE_RENDER, self::get_pricing_init_script($form)); } if (self::has_password_strength($form)) { $password_script = self::get_password_strength_init_script($form); self::add_init_script($form['id'], 'password', self::ON_PAGE_RENDER, $password_script); } if (self::has_enhanced_dropdown($form)) { $chosen_script = self::get_chosen_init_script($form); self::add_init_script($form['id'], 'chosen', self::ON_PAGE_RENDER, $chosen_script); self::add_init_script($form['id'], 'chosen', self::ON_CONDITIONAL_LOGIC, $chosen_script); } if (self::has_character_counter($form)) { self::add_init_script($form['id'], 'character_counter', self::ON_PAGE_RENDER, self::get_counter_init_script($form)); } if (self::has_input_mask($form)) { self::add_init_script($form['id'], 'input_mask', self::ON_PAGE_RENDER, self::get_input_mask_init_script($form)); } if (self::has_calculation_field($form)) { self::add_init_script($form['id'], 'number_formats', self::ON_PAGE_RENDER, self::get_number_formats_script($form)); self::add_init_script($form['id'], 'calculation', self::ON_PAGE_RENDER, self::get_calculations_init_script($form)); } if (self::has_currency_format_number_field($form)) { self::add_init_script($form['id'], 'currency_format', self::ON_PAGE_RENDER, self::get_currency_format_init_script($form)); } if (self::has_currency_copy_values_option($form)) { self::add_init_script($form['id'], 'copy_values', self::ON_PAGE_RENDER, self::get_copy_values_init_script($form)); } if (self::has_placeholder($form)) { self::add_init_script($form['id'], 'placeholders', self::ON_PAGE_RENDER, self::get_placeholders_init_script($form)); } if (isset($form['fields']) && is_array($form['fields'])) { foreach ($form['fields'] as $field) { /* @var GF_Field $field */ if (is_subclass_of($field, 'GF_Field')) { $field->register_form_init_scripts($form); } } } /** * Fires when inline Gravity Forms scripts are enqueued * * Used to enqueue additional inline scripts * * @param array $form The Form object * @param string $field_vale The current value of the selected field * @param bool $is_ajax Returns true if using AJAX. Otherwise, false */ gf_do_action(array('gform_register_init_scripts', $form['id']), $form, $field_values, $is_ajax); }
/** * Updates an entire single Entry object. * * If the date_created value is not set then the current time UTC will be used. * The date_created value, if set, is expected to be in 'Y-m-d H:i:s' format (UTC). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * @param int $entry_id Optional. If specified, the ID in the Entry object will be ignored * * @return mixed Either True or a WP_Error instance */ public static function update_entry($entry, $entry_id = null) { global $wpdb; if (empty($entry_id)) { if (rgar($entry, 'id')) { $entry_id = absint($entry['id']); } } else { $entry['id'] = absint($entry_id); } if (empty($entry_id)) { return new WP_Error('missing_entry_id', __('Missing entry id', 'gravityforms')); } $current_entry = $original_entry = self::get_entry($entry_id); if (!$current_entry) { return new WP_Error('not_found', __('Entry not found', 'gravityforms'), $entry_id); } if (is_wp_error($current_entry)) { return $current_entry; } // make sure the form id exists $form_id = rgar($entry, 'form_id'); if (empty($form_id)) { $form_id = rgar($current_entry, 'form_id'); } if (false === self::form_id_exists($form_id)) { return new WP_Error('invalid_form_id', __('The form for this entry does not exist', 'gravityforms')); } $entry = apply_filters('gform_entry_pre_update', $entry, $original_entry); // use values in the entry object if present $post_id = isset($entry['post_id']) ? intval($entry['post_id']) : 'NULL'; $date_created = isset($entry['date_created']) ? sprintf("'%s'", esc_sql($entry['date_created'])) : 'utc_timestamp()'; $is_starred = isset($entry['is_starred']) ? $entry['is_starred'] : 0; $is_read = isset($entry['is_read']) ? $entry['is_read'] : 0; $ip = isset($entry['ip']) ? $entry['ip'] : GFFormsModel::get_ip(); $source_url = isset($entry['source_url']) ? $entry['source_url'] : GFFormsModel::get_current_page_url(); $user_agent = isset($entry['user_agent']) ? $entry['user_agent'] : 'API'; $currency = isset($entry['currency']) ? $entry['currency'] : GFCommon::get_currency(); $payment_status = isset($entry['payment_status']) ? sprintf("'%s'", esc_sql($entry['payment_status'])) : 'NULL'; $payment_date = strtotime(rgar($entry, 'payment_date')) ? "'" . gmdate('Y-m-d H:i:s', strtotime("{$entry['payment_date']}")) . "'" : 'NULL'; $payment_amount = isset($entry['payment_amount']) ? (double) $entry['payment_amount'] : 'NULL'; $payment_method = isset($entry['payment_method']) ? $entry['payment_method'] : ''; $transaction_id = isset($entry['transaction_id']) ? sprintf("'%s'", esc_sql($entry['transaction_id'])) : 'NULL'; $is_fulfilled = isset($entry['is_fulfilled']) ? intval($entry['is_fulfilled']) : 'NULL'; $status = isset($entry['status']) ? $entry['status'] : 'active'; global $current_user; $user_id = isset($entry['created_by']) ? absint($entry['created_by']) : ''; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? absint($current_user->ID) : 'NULL'; } $transaction_type = isset($entry['transaction_type']) ? intval($entry['transaction_type']) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $sql = $wpdb->prepare("\n UPDATE {$lead_table}\n SET\n form_id = %d,\n post_id = {$post_id},\n date_created = {$date_created},\n is_starred = %d,\n is_read = %d,\n ip = %s,\n source_url = %s,\n user_agent = %s,\n currency = %s,\n payment_status = {$payment_status},\n payment_date = {$payment_date},\n payment_amount = {$payment_amount},\n transaction_id = {$transaction_id},\n is_fulfilled = {$is_fulfilled},\n created_by = {$user_id},\n transaction_type = {$transaction_type},\n status = %s,\n payment_method = %s\n WHERE\n id = %d\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method, $entry_id); $result = $wpdb->query($sql); if (false === $result) { return new WP_Error('update_entry_properties_failed', __('There was a problem while updating the entry properties', 'gravityforms'), $wpdb->last_error); } // only save field values for fields that currently exist in the form. The rest in $entry will be ignored. The rest in $current_entry will get deleted. $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $entry_id)); $form = GFFormsModel::get_form_meta($form_id); $form = gf_apply_filters(array('gform_form_pre_update_entry', $form_id), $form, $entry, $entry_id); foreach ($form['fields'] as $field) { /* @var GF_Field $field */ $type = GFFormsModel::get_input_type($field); if (in_array($type, array('html', 'page', 'section'))) { continue; } $inputs = $field->get_entry_inputs(); if (is_array($inputs)) { foreach ($field->inputs as $input) { $input_id = (string) $input['id']; if (isset($entry[$input_id])) { if ($entry[$input_id] != $current_entry[$input_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $input_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error('update_input_value_failed', __('There was a problem while updating one of the input values for the entry', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$input_id]); } } } else { $field_id = $field->id; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ''; if ($field_value != $current_entry[$field_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $field_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $field_id, $field_value); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$field_id]); } } // save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { if ($entry[$key] != $current_entry[$key]) { gform_update_meta($entry_id, $key, $entry[$key]); } unset($current_entry[$key]); } } } // now delete remaining values from the old entry if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $meta_key) { if (isset($current_entry[$meta_key])) { gform_delete_meta($entry_id, $meta_key); unset($current_entry[$meta_key]); } } } foreach ($current_entry as $k => $v) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $k); $field = GFFormsModel::get_field($form, $k); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $k, ''); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } /** * Fires after the Entry is updated. * * @param array $lead The entry object after being updated. * @param array $original_entry The entry object before being updated. */ gf_do_action(array('gform_post_update_entry', $form_id), $entry, $original_entry); return true; }
public function add_feed_error($error_message, $feed, $entry, $form) { /* Log debug error before we prepend the error name. */ $backtrace = debug_backtrace(); $method = $backtrace[1]['class'] . '::' . $backtrace[1]['function']; $this->log_error($method . '(): ' . $error_message); /* Prepend feed name to the error message. */ $feed_name = rgars($feed, 'meta/feed_name') ? rgars($feed, 'meta/feed_name') : rgars($feed, 'meta/feedName'); $error_message = $feed_name . ': ' . $error_message; /* Add error note to the entry. */ $this->add_note($entry['id'], $error_message, 'error'); /* Get Add-On slug */ $slug = str_replace('gravityforms', '', $this->_slug); /* Process any error actions. */ gf_do_action(array("gform_{$slug}_error", $form['id']), $feed, $entry, $form); }
public static function upload() { GFCommon::log_debug('GFAsyncUpload::upload(): Starting.'); if ($_SERVER['REQUEST_METHOD'] != 'POST') { status_header(404); die; } header('Content-Type: text/html; charset=' . get_option('blog_charset')); send_nosniff_header(); nocache_headers(); status_header(200); // If the file is bigger than the server can accept then the form_id might not arrive. // This might happen if the file is bigger than the max post size ini setting. // Validation in the browser reduces the risk of this happening. if (!isset($_REQUEST['form_id'])) { GFCommon::log_debug('GFAsyncUpload::upload(): File upload aborted because the form_id was not found. The file may have been bigger than the max post size ini setting.'); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } $form_id = absint($_REQUEST['form_id']); $form_unique_id = rgpost('gform_unique_id'); $form = GFAPI::get_form($form_id); if (empty($form) || !$form['is_active']) { die; } if (rgar($form, 'requireLogin')) { if (!is_user_logged_in()) { die; } check_admin_referer('gform_file_upload_' . $form_id, '_gform_file_upload_nonce_' . $form_id); } if (!ctype_alnum($form_unique_id)) { die; } $target_dir = GFFormsModel::get_upload_path($form_id) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; if (!is_dir($target_dir)) { if (!wp_mkdir_p($target_dir)) { GFCommon::log_debug("GFAsyncUpload::upload(): Couldn't create the tmp folder: " . $target_dir); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } } $time = current_time('mysql'); $y = substr($time, 0, 4); $m = substr($time, 5, 2); //adding index.html files to all subfolders if (!file_exists(GFFormsModel::get_upload_root() . '/index.html')) { GFForms::add_security_files(); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . '/index.html')) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id)); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . "/{$y}/index.html")) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}"); } else { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}/{$m}"); } } } if (!file_exists($target_dir . '/index.html')) { GFCommon::recursive_add_index_file($target_dir); } $uploaded_filename = $_FILES['file']['name']; $file_name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; $field_id = rgpost('field_id'); $field_id = absint($field_id); $field = GFFormsModel::get_field($form, $field_id); if (empty($field) || GFFormsModel::get_input_type($field) != 'fileupload') { die; } $file_name = sanitize_file_name($file_name); $uploaded_filename = sanitize_file_name($uploaded_filename); $allowed_extensions = !empty($field->allowedExtensions) ? GFCommon::clean_extensions(explode(',', strtolower($field->allowedExtensions))) : array(); $max_upload_size_in_bytes = $field->maxFileSize > 0 ? $field->maxFileSize * 1048576 : wp_max_upload_size(); $max_upload_size_in_mb = $max_upload_size_in_bytes / 1048576; if ($_FILES['file']['size'] > 0 && $_FILES['file']['size'] > $max_upload_size_in_bytes) { self::die_error(104, sprintf(__('File exceeds size limit. Maximum file size: %dMB', 'gravityforms'), $max_upload_size_in_mb)); } if (GFCommon::file_name_has_disallowed_extension($file_name) || GFCommon::file_name_has_disallowed_extension($uploaded_filename)) { GFCommon::log_debug("GFAsyncUpload::upload(): Illegal file extension: {$file_name}"); self::die_error(104, __('The uploaded file type is not allowed.', 'gravityforms')); } if (!empty($allowed_extensions)) { if (!GFCommon::match_file_extension($file_name, $allowed_extensions) || !GFCommon::match_file_extension($uploaded_filename, $allowed_extensions)) { GFCommon::log_debug("GFAsyncUpload::upload(): The uploaded file type is not allowed: {$file_name}"); self::die_error(104, sprintf(__('The uploaded file type is not allowed. Must be one of the following: %s', 'gravityforms'), strtolower($field['allowedExtensions']))); } } $whitelisting_disabled = apply_filters('gform_file_upload_whitelisting_disabled', false); if (empty($allowed_extensions) && !$whitelisting_disabled) { // Whitelist the file type $valid_uploaded_filename = GFCommon::check_type_and_ext($_FILES['file'], $uploaded_filename); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_uploaded_filename->get_error_code(), $valid_uploaded_filename->get_error_message()); } $valid_file_name = GFCommon::check_type_and_ext($_FILES['file'], $file_name); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_file_name->get_error_code(), $valid_file_name->get_error_message()); } } $tmp_file_name = $form_unique_id . '_input_' . $field_id . '_' . $file_name; $tmp_file_name = sanitize_file_name($tmp_file_name); $file_path = $target_dir . $tmp_file_name; $cleanup_target_dir = true; // Remove old files $max_file_age = 5 * 3600; // Temp file age in seconds // Remove old temp files if ($cleanup_target_dir) { if (is_dir($target_dir) && ($dir = opendir($target_dir))) { while (($file = readdir($dir)) !== false) { $tmp_file_path = $target_dir . $file; // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\\.part$/', $file) && filemtime($tmp_file_path) < time() - $max_file_age && $tmp_file_path != "{$file_path}.part") { GFCommon::log_debug('GFAsyncUpload::upload(): Deleting file: ' . $tmp_file_path); @unlink($tmp_file_path); } } closedir($dir); } else { GFCommon::log_debug('GFAsyncUpload::upload(): Failed to open temp directory: ' . $target_dir); self::die_error(100, __('Failed to open temp directory.', 'gravityforms')); } } if (isset($_SERVER['HTTP_CONTENT_TYPE'])) { $contentType = $_SERVER['HTTP_CONTENT_TYPE']; } if (isset($_SERVER['CONTENT_TYPE'])) { $contentType = $_SERVER['CONTENT_TYPE']; } $chunk = isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0; $chunks = isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0; // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, 'multipart') !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen($_FILES['file']['tmp_name'], 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); @unlink($_FILES['file']['tmp_name']); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } else { self::die_error(103, __('Failed to move uploaded file.', 'gravityforms')); } } else { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen('php://input', 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$file_path}.part", $file_path); } if (file_exists($file_path)) { GFFormsModel::set_permissions($file_path); } else { self::die_error(105, __('Upload unsuccessful', 'gravityforms') . ' ' . $uploaded_filename); } $output = array('status' => 'ok', 'data' => array('temp_filename' => $tmp_file_name, 'uploaded_filename' => str_replace("\\'", "'", urldecode($uploaded_filename)))); $output = json_encode($output); GFCommon::log_debug(sprintf('GFAsyncUpload::upload(): File upload complete. temp_filename: %s uploaded_filename: %s ', $tmp_file_name, $uploaded_filename)); gf_do_action('gform_post_multifile_upload', $form['id'], $form, $field, $uploaded_filename, $tmp_file_name, $file_path); die($output); }
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(',', ',', $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); /** * Fires after a post, from a form with post fields, is created * * @param int $form['id'] The ID of the form where the new post was created * @param int $post_id The new Post ID created after submission * @param array $lead The Lead Object * @param array $form The Form Object for the form used to create the post */ gf_do_action('gform_after_create_post', $form['id'], $post_id, $lead, $form); return $post_id; }
/** * Builds the Notification Edit page. * * Called from GFNotification::notification_page * * @access public * @static * @see RGFormsModel::get_form_meta * @see GFNotification::get_notification * @see GFNotification::validate_notification * @see GFNotification::get_notification_ui_settings * @see GFFormsModel::sanitize_conditional_logic * * @param int $form_id The ID of the form that the notification belongs to * @param int $notification_id The ID of the notification being edited */ public static function notification_edit_page($form_id, $notification_id) { if (!rgempty('gform_notification_id')) { $notification_id = rgpost('gform_notification_id'); } $form = RGFormsModel::get_form_meta($form_id); /** * Filters the form to be used in the notification page * * @since 1.8.6 * * @param array $form The Form Object * @param int $notification_id The notification ID */ $form = gf_apply_filters(array('gform_form_notification_page', $form_id), $form, $notification_id); $notification = !$notification_id ? array() : self::get_notification($form, $notification_id); // added second condition to account for new notifications with errors as notification ID will // be available in $_POST but the notification has not actually been saved yet $is_new_notification = empty($notification_id) || empty($notification); $is_valid = true; $is_update = false; if (rgpost('save')) { check_admin_referer('gforms_save_notification', 'gforms_save_notification'); //clear out notification because it could have legacy data populated $notification = array('isActive' => isset($notification['isActive']) ? rgar($notification, 'isActive') : true); $is_update = true; if ($is_new_notification) { $notification_id = uniqid(); $notification['id'] = $notification_id; } else { $notification['id'] = $notification_id; } $notification['name'] = sanitize_text_field(rgpost('gform_notification_name')); $notification['service'] = sanitize_text_field(rgpost('gform_notification_service')); $notification['event'] = sanitize_text_field(rgpost('gform_notification_event')); $notification['to'] = rgpost('gform_notification_to_type') == 'field' ? rgpost('gform_notification_to_field') : rgpost('gform_notification_to_email'); $to_type = rgpost('gform_notification_to_type'); if (!in_array($to_type, array('email', 'field', 'routing', 'hidden'))) { $to_type = 'email'; } $notification['toType'] = $to_type; $notification['bcc'] = rgpost('gform_notification_bcc'); $notification['subject'] = sanitize_text_field(rgpost('gform_notification_subject')); $notification['message'] = rgpost('gform_notification_message'); $notification['from'] = sanitize_text_field(rgpost('gform_notification_from')); $notification['fromName'] = sanitize_text_field(rgpost('gform_notification_from_name')); $notification['replyTo'] = rgpost('gform_notification_reply_to'); $routing = !rgempty('gform_routing_meta') ? GFCommon::json_decode(rgpost('gform_routing_meta'), true) : null; if (!empty($routing)) { $routing_logic = array('rules' => $routing); $routing_logic = GFFormsModel::sanitize_conditional_logic($routing_logic); $notification['routing'] = $routing_logic['rules']; } $notification['routing'] = $routing; $conditional_logic = !rgempty('gform_conditional_logic_meta') ? GFCommon::json_decode(rgpost('gform_conditional_logic_meta'), true) : null; $notification['conditionalLogic'] = GFFormsModel::sanitize_conditional_logic($conditional_logic); $notification['disableAutoformat'] = (bool) rgpost('gform_notification_disable_autoformat'); if (rgpost('gform_is_default')) { $notification['isDefault'] = true; } /** * Filters the notification before it is saved * * @since 1.7 * * @param array $notification The Notification Object * @param array $form The Form Object * @param bool $is_new_notification True if it is a new notification. False otherwise. */ $notification = gf_apply_filters(array('gform_pre_notification_save', $form_id), $notification, $form, $is_new_notification); //validating input... $is_valid = self::validate_notification(); /** * Allows overriding of if the notification passes validation * * @since 1.9.16 * * @param bool $is_valid True if it is valid. False otherwise. * @param array $notification The Notification Object * @param array $form The Form Object */ $is_valid = gf_apply_filters(array('gform_notification_validation', $form_id), $is_valid, $notification, $form); if ($is_valid) { //input valid, updating... //emptying notification email if it is supposed to be disabled if ($_POST['gform_notification_to_type'] == 'routing') { $notification['to'] = ''; } else { $notification['routing'] = null; } // trim values $notification = GFFormsModel::trim_conditional_logic_values_from_element($notification, $form); $form['notifications'][$notification_id] = $notification; RGFormsModel::save_form_notifications($form_id, $form['notifications']); } } if ($is_update && $is_valid) { $url = remove_query_arg('nid'); GFCommon::add_message(sprintf(esc_html__('Notification saved successfully. %sBack to notifications.%s', 'gravityforms'), '<a href="' . esc_url($url) . '">', '</a>')); /** * Fires an action after a notification has been saved * * @since 1.9.16 * * @param array $notification The Notification Object * @param array $form The Form Object * @param bool $is_new_notification True if this is a new notification. False otherwise. */ gf_do_action(array('gform_post_notification_save', $form_id), $notification, $form, $is_new_notification); } else { if ($is_update && !$is_valid) { GFCommon::add_error_message(esc_html__('Notification could not be updated. Please enter all required information below.', 'gravityforms')); } } // moved page header loading here so the admin messages can be set upon saving and available for the header to print out GFFormSettings::page_header(esc_html__('Notifications', 'gravityforms')); $notification_ui_settings = self::get_notification_ui_settings($notification, $is_valid); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min'; ?> <link rel="stylesheet" href="<?php echo GFCommon::get_base_url(); ?> /css/admin<?php echo $min; ?> .css?ver=<?php echo GFCommon::$version; ?> " /> <script type="text/javascript"> var gform_has_unsaved_changes = false; jQuery(document).ready(function () { jQuery("#entry_form input, #entry_form textarea, #entry_form select").change(function () { gform_has_unsaved_changes = true; }); window.onbeforeunload = function () { if (gform_has_unsaved_changes) { return "You have unsaved changes."; } }; ToggleConditionalLogic(true, 'notification'); jQuery(document).on('change', '.gfield_routing_value_dropdown', function () { SetRoutingValueDropDown(jQuery(this)); }); }); gform.addFilter("gform_merge_tags", "MaybeAddSaveLinkMergeTag"); function MaybeAddSaveLinkMergeTag(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){ var event = document.getElementById('gform_notification_event').value; if ( event == 'form_saved' || event == 'form_save_email_requested' ) { mergeTags["other"].tags.push({ tag: '{save_link}', label: <?php echo json_encode(esc_html__('Save & Continue Link', 'gravityforms')); ?> }); mergeTags["other"].tags.push({ tag: '{save_token}', label: <?php echo json_encode(esc_html__('Save & Continue Token', 'gravityforms')); ?> }); } return mergeTags; } <?php if (empty($form['notifications'])) { $form['notifications'] = array(); } $entry_meta = GFFormsModel::get_entry_meta($form_id); /** * Filters the entry meta when notification conditional logic is being edited * * @since 1.7.6 * * @param array $entry_meta The Entry meta * @param array $form The Form Object * @param int $notification_id The notification ID */ $entry_meta = apply_filters('gform_entry_meta_conditional_logic_notifications', $entry_meta, $form, $notification_id); ?> var form = <?php echo json_encode($form); ?> ; var current_notification = <?php echo GFCommon::json_encode($notification); ?> ; var entry_meta = <?php echo GFCommon::json_encode($entry_meta); ?> ; function SetRoutingValueDropDown(element) { //parsing ID to get routing Index var index = element.attr("id").replace("routing_value_", ''); SetRouting(index); } function CreateRouting(routings) { var str = ''; for (var i = 0; i < routings.length; i++) { var isSelected = routings[i].operator == 'is' ? "selected='selected'" : ''; var isNotSelected = routings[i].operator == 'isnot' ? "selected='selected'" : ''; var greaterThanSelected = routings[i].operator == '>' ? "selected='selected'" : ''; var lessThanSelected = routings[i].operator == '<' ? "selected='selected'" : ''; var containsSelected = routings[i].operator == 'contains' ? "selected='selected'" : ''; var startsWithSelected = routings[i].operator == 'starts_with' ? "selected='selected'" : ''; var endsWithSelected = routings[i].operator == 'ends_with' ? "selected='selected'" : ''; var email = routings[i]["email"] ? routings[i]["email"] : ''; str += "<div style='width:99%'>" + <?php echo json_encode(esc_html__('Send to', 'gravityforms')); ?> + " <input type='text' id='routing_email_" + i + "' value='" + email + "' onkeyup='SetRouting(" + i + ");'/>"; str += " " + <?php echo json_encode(esc_html__('if', 'gravityforms')); ?> + " " + GetRoutingFields(i, routings[i].fieldId); str += "<select id='routing_operator_" + i + "' onchange='SetRouting(" + i + ");' class='gform_routing_operator'>"; str += "<option value='is' " + isSelected + ">" + <?php echo json_encode(esc_html__('is', 'gravityforms')); ?> + "</option>"; str += "<option value='isnot' " + isNotSelected + ">" + <?php echo json_encode(esc_html__('is not', 'gravityforms')); ?> + "</option>"; str += "<option value='>' " + greaterThanSelected + ">" + <?php echo json_encode(esc_html__('greater than', 'gravityforms')); ?> + "</option>"; str += "<option value='<' " + lessThanSelected + ">" + <?php echo json_encode(esc_html__('less than', 'gravityforms')); ?> + "</option>"; str += "<option value='contains' " + containsSelected + ">" + <?php echo json_encode(esc_html__('contains', 'gravityforms')); ?> + "</option>"; str += "<option value='starts_with' " + startsWithSelected + ">" + <?php echo json_encode(esc_html__('starts with', 'gravityforms')); ?> + "</option>"; str += "<option value='ends_with' " + endsWithSelected + ">" + <?php echo json_encode(esc_html__('ends with', 'gravityforms')); ?> + "</option>"; str += "</select>"; str += GetRoutingValues(i, routings[i].fieldId, routings[i].value); str += "<a class='gf_insert_field_choice' title='add another rule' onclick=\"InsertRouting(" + (i + 1) + ");\" onkeypress=\"InsertRouting(" + (i + 1) + ");\"><i class='gficon-add'></i></a>"; if (routings.length > 1) str += "<a class='gf_delete_field_choice' title='remove this rule' onclick=\"DeleteRouting(" + i + ");\" onkeypress=\"DeleteRouting(" + i + ");\"><i class='gficon-subtract'></i></a>"; str += "</div>"; } jQuery("#gform_notification_to_routing_rules").html(str); } function GetRoutingValues(index, fieldId, selectedValue) { var str = GetFieldValues(index, fieldId, selectedValue, 16); return str; } function GetRoutingFields(index, selectedItem) { var str = "<select id='routing_field_id_" + index + "' class='gfield_routing_select' onchange='jQuery(\"#routing_value_" + index + "\").replaceWith(GetRoutingValues(" + index + ", jQuery(this).val())); SetRouting(" + index + "); '>"; str += GetSelectableFields(selectedItem, 16); str += "</select>"; return str; } //---------------------- generic --------------- function GetSelectableFields(selectedFieldId, labelMaxCharacters) { var str = ""; var inputType; for (var i = 0; i < form.fields.length; i++) { inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type; //see if this field type can be used for conditionals if (IsNotificationConditionalLogicField(form.fields[i])) { var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : ""; str += "<option value='" + form.fields[i].id + "' " + selected + ">" + form.fields[i].label + "</option>"; } } return str; } function IsNotificationConditionalLogicField(field) { //this function is a duplicate of IsConditionalLogicField from form_editor.js inputType = field.inputType ? field.inputType : field.type; var supported_fields = ['checkbox', 'radio', 'select', 'text', 'website', 'textarea', 'email', 'hidden', 'number', 'phone', 'multiselect', 'post_title', 'post_tags', 'post_custom_field', 'post_content', 'post_excerpt']; var index = jQuery.inArray(inputType, supported_fields); return index >= 0; } function GetFirstSelectableField() { var inputType; for (var i = 0; i < form.fields.length; i++) { inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type; if (IsNotificationConditionalLogicField(form.fields[i])) { return form.fields[i].id; } } return 0; } function TruncateMiddle(text, maxCharacters) { if (!text) return ""; if (text.length <= maxCharacters) return text; var middle = parseInt(maxCharacters / 2); return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle); } function GetFieldValues(index, fieldId, selectedValue, labelMaxCharacters) { if (!fieldId) fieldId = GetFirstSelectableField(); if (!fieldId) return ""; var str = ''; var field = GetFieldById(fieldId); var isAnySelected = false; if (!field) return ""; if (field["type"] == 'post_category' && field["displayAllCategories"]) { var dropdown_id = 'routing_value_' + index; var dropdown = jQuery('#' + dropdown_id + ".gfield_category_dropdown"); //don't load category drop down if it already exists (to avoid unecessary ajax requests) if (dropdown.length > 0) { var options = dropdown.html(); options = options.replace("value=\"" + selectedValue + "\"", "value=\"" + selectedValue + "\" selected=\"selected\""); str = "<select id='" + dropdown_id + "' class='gfield_routing_select gfield_category_dropdown gfield_routing_value_dropdown'>" + options + "</select>"; } else { //loading categories via AJAX jQuery.post(ajaxurl, { action: "gf_get_notification_post_categories", ruleIndex : index, selectedValue : selectedValue}, function (dropdown_string) { if (dropdown_string) { jQuery('#gfield_ajax_placeholder_' + index).replaceWith(dropdown_string.trim()); } } ); //will be replaced by real drop down during the ajax callback str = "<select id='gfield_ajax_placeholder_" + index + "' class='gfield_routing_select'><option>" + <?php json_encode(esc_html__('Loading...', 'gravityforms')); ?> + "</option></select>"; } } else if (field.choices) { //create a drop down for fields that have choices (i.e. drop down, radio, checkboxes, etc...) str = "<select class='gfield_routing_select gfield_routing_value_dropdown' id='routing_value_" + index + "'>"; for (var i = 0; i < field.choices.length; i++) { var choiceValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text; var isSelected = choiceValue == selectedValue; var selected = isSelected ? "selected='selected'" : ''; if (isSelected) isAnySelected = true; str += "<option value='" + choiceValue.replace(/'/g, "'") + "' " + selected + ">" + field.choices[i].text + "</option>"; } if (!isAnySelected && selectedValue) { str += "<option value='" + selectedValue.replace(/'/g, "'") + "' selected='selected'>" + selectedValue + "</option>"; } str += "</select>"; } else { selectedValue = selectedValue ? selectedValue.replace(/'/g, "'") : ""; //create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...) str = "<input type='text' placeholder='" + <?php echo json_encode(esc_html__('Enter value', 'gravityforms')); ?> +"' class='gfield_routing_select' id='routing_value_" + index + "' value='" + selectedValue.replace(/'/g, "'") + "' onchange='SetRouting(" + index + ");' onkeyup='SetRouting(" + index + ");'>"; } return str; } //--------------------------------------------------------------------------------- function InsertRouting(index) { var routings = current_notification.routing; routings.splice(index, 0, new ConditionalRule()); CreateRouting(routings); SetRouting(index); } function SetRouting(ruleIndex) { if (!current_notification.routing && ruleIndex == 0) current_notification.routing = [new ConditionalRule()]; current_notification.routing[ruleIndex]["email"] = jQuery("#routing_email_" + ruleIndex).val(); current_notification.routing[ruleIndex]["fieldId"] = jQuery("#routing_field_id_" + ruleIndex).val(); current_notification.routing[ruleIndex]["operator"] = jQuery("#routing_operator_" + ruleIndex).val(); current_notification.routing[ruleIndex]["value"] = jQuery("#routing_value_" + ruleIndex).val(); var json = jQuery.toJSON(current_notification.routing); jQuery('#gform_routing_meta').val(json); } function DeleteRouting(ruleIndex) { current_notification.routing.splice(ruleIndex, 1); CreateRouting(current_notification.routing); } function SetConditionalLogic(isChecked) { current_notification.conditionalLogic = isChecked ? new ConditionalLogic() : null; } function SaveJSMeta() { jQuery('#gform_routing_meta').val(jQuery.toJSON(current_notification.routing)); jQuery('#gform_conditional_logic_meta').val(jQuery.toJSON(current_notification.conditionalLogic)); } <?php GFFormSettings::output_field_scripts(); ?> </script> <form method="post" id="gform_notification_form" onsubmit="gform_has_unsaved_changes = false; SaveJSMeta();"> <?php wp_nonce_field('gforms_save_notification', 'gforms_save_notification'); ?> <?php if (rgar($notification, 'isDefault')) { echo '<input type="hidden" id="gform_is_default" name="gform_is_default" value="1"/>'; } ?> <input type="hidden" id="gform_routing_meta" name="gform_routing_meta" /> <input type="hidden" id="gform_conditional_logic_meta" name="gform_conditional_logic_meta" /> <input type="hidden" id="gform_notification_id" name="gform_notification_id" value="<?php echo esc_attr($notification_id); ?> " /> <table class="form-table gform_nofification_edit"> <?php array_map(array('GFFormSettings', 'output'), $notification_ui_settings); ?> </table> <p class="submit"> <?php $button_label = $is_new_notification ? __('Save Notification', 'gravityforms') : __('Update Notification', 'gravityforms'); $notification_button = '<input class="button-primary" type="submit" value="' . esc_attr($button_label) . '" name="save"/>'; /** * Filters the "Save Notification" button * * @param string $notification_button The notification button HTML */ echo apply_filters('gform_save_notification_button', $notification_button); ?> </p> </form> <?php GFFormSettings::page_footer(); }
public static function lead_detail_page() { global $current_user; if (!GFCommon::ensure_wp_version()) { return; } echo GFCommon::get_remote_message(); $requested_form_id = absint($_GET['id']); if (empty($requested_form_id)) { return; } $lead = self::get_current_entry(); if (is_wp_error($lead) || !$lead) { esc_html_e("Oops! We couldn't find your entry. Please try again", 'gravityforms'); return; } $lead_id = $lead['id']; $form = self::get_current_form(); $form_id = absint($form['id']); $total_count = self::get_total_count(); $position = rgget('pos') ? rgget('pos') : 0; $prev_pos = !rgblank($position) && $position > 0 ? $position - 1 : false; $next_pos = !rgblank($position) && $position < self::$_total_count - 1 ? $position + 1 : false; $filter = rgget('filter'); // 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; } } 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(); } $original_entry = $lead; GFFormsModel::$uploaded_files[$form_id] = $files; GFFormsModel::save_lead($form, $lead); /** * Fires after the Entry is updated from the entry detail page. * * @param array $form The form object for the entry. * @param integer $lead['id'] The entry ID. * @param array $original_entry The entry object before being updated. */ gf_do_action(array('gform_after_update_entry', $form['id']), $form, $lead['id'], $original_entry); $lead = RGFormsModel::get_lead($lead['id']); $lead = GFFormsModel::set_entry_meta($lead, $form); self::set_current_entry($lead); 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')) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Preparing to email entry notes.'); $email_to = $_POST['gentry_email_notes_to']; $email_from = $current_user->user_email; $email_subject = stripslashes($_POST['gentry_email_subject']); $body = stripslashes($_POST['new_note']); $headers = "From: \"{$email_from}\" <{$email_from}> \r\n"; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Emailing notes - TO: {$email_to} SUBJECT: {$email_subject} BODY: {$body} HEADERS: {$headers}"); $is_success = wp_mail($email_to, $email_subject, $body, $headers); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFEntryDetail::lead_detail_page(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } /** * Fires after a note is attached to an entry and sent as an email * * @param string $result The Error message or success message when the entry note is sent * @param string $email_to The email address to send the entry note to * @param string $email_from The email address from which the email is sent from * @param string $email_subject The subject of the email that is sent * @param mixed $body The Full body of the email containing the message after the note is sent * @param array $form The current form object * @param array $lead The Current lead object */ do_action('gform_post_send_entry_note', $result, $email_to, $email_from, $email_subject, $body, $form, $lead); } 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') { if (!GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { die(esc_html__("You don't have adequate permission to delete notes.", 'gravityforms')); } 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']); self::set_current_entry($lead); 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']); self::set_current_entry($lead); 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']); self::set_current_entry($lead); break; case 'delete': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); if (!GFCommon::current_user_can_any('gravityforms_delete_entries')) { die(esc_html__("You don't have adequate permission 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']; $screen = get_current_screen(); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min'; ?> <link rel="stylesheet" href="<?php echo GFCommon::get_base_url(); ?> /css/admin<?php echo $min; ?> .css?ver=<?php echo GFForms::$version; ?> " /> <script type="text/javascript"> jQuery(document).ready(function () { toggleNotificationOverride(true); jQuery('#gform_update_button').prop('disabled', false); if(typeof postboxes != 'undefined'){ jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed'); postboxes.add_postbox_toggles( <?php echo json_encode($screen->id); ?> ); } }); function DeleteFile(leadId, fieldId, deleteButton) { if (confirm(<?php echo json_encode(__("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 json_encode(__('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 echo json_encode(__('You must select at least one type of notification to resend.', 'gravityforms')); ?> , 'error', '#notifications'); 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 absint($lead['id']); ?> ', formId : '<?php echo absint($form['id']); ?> ' }, function (response) { if (response) { displayMessage(response, "error", "#notifications"); } else { displayMessage(<?php echo json_encode(esc_html__('Notifications were resent successfully.', 'gravityforms')); ?> , "updated", "#notifications" ); // reset UI jQuery(".gform_notifications").attr( 'checked', false ); jQuery('#notification_override_email').val(''); toggleNotificationOverride(); } 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')); ?> " /> <input type="hidden" name="entry_id" id="entry_id" value="<?php echo absint($lead['id']); ?> " /> <div class="wrap gf_entry_wrap"> <h2 class="gf_admin_page_title"> <span><?php echo esc_html(rgar($form, 'title')); ?> </span> <?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 } ?> <span class="gf_admin_page_subtitle"> <span class="gf_admin_page_formid">ID: <?php echo absint($form['id']); ?> </span> </span> <?php $gf_entry_locking = new GFEntryLocking(); $gf_entry_locking->lock_info($lead_id); ?> </h2> <?php GFCommon::display_dismissible_message(); ?> <?php RGForms::top_toolbar(); ?> <div id="poststuff"> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <?php /** * Fires before the entry detail content is displayed * * @param array $form The Form object * @param array $lead The Entry object */ 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); } /** * Fires when entry details are displayed * * @param array $form The Form object * @param array $lead The Entry object */ do_action('gform_entry_detail', $form, $lead); ?> </div> <div id="postbox-container-1" class="postbox-container"> <?php /** * Fires before the entry detail sidebar is generated * * @param array $form The Form object * @param array $lead The Entry object */ do_action('gform_entry_detail_sidebar_before', $form, $lead); ?> <?php do_meta_boxes($screen->id, 'side', array('form' => $form, 'entry' => $lead, 'mode' => $mode)); ?> <?php /** * Inserts information into the middle of the entry detail sidebar * * @param array $form The Form object * @param array $lead The Entry object */ do_action('gform_entry_detail_sidebar_middle', $form, $lead); ?> <!-- begin print button --> <div class="detail-view-print"> <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '¬es=1' : ''; var url='<?php echo trailingslashit(site_url()); ?> ?gf_page=print-entry&fid=<?php echo absint($form['id']); ?> &lid=<?php echo absint($lead['id']); ?> ' + notes_qs; window.open (url,'printwindow');" class="button"><?php esc_html_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 esc_html_e('include notes', 'gravityforms'); ?> </label> <?php } ?> </div> <!-- end print button --> <?php /** * Fires after the entry detail sidebar information. * * @param array $form The Form object * @param array $lead The Entry object */ do_action('gform_entry_detail_sidebar_after', $form, $lead); ?> </div> <div id="postbox-container-2" class="postbox-container"> <?php do_meta_boxes($screen->id, 'normal', array('form' => $form, 'entry' => $lead, 'mode' => $mode)); ?> <?php /** * Fires after the entry detail content is displayed * * @param array $form The Form object * @param array $lead The Entry object */ 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 esc_html_e('Entry Updated.', 'gravityforms'); ?> </div> <?php } }
/** * Enqueue and retrieve all inline scripts that should be executed when the form is rendered. * Use add_init_script() function to enqueue scripts. * * @param array $form * @param array $field_values * @param bool $is_ajax */ private static function register_form_init_scripts($form, $field_values = array(), $is_ajax = false) { // adding conditional logic script if conditional logic is configured for this form. // get_conditional_logic also adds the chosen script for the enhanced dropdown option. // if this form does not have conditional logic, add chosen script separately if (self::has_conditional_logic($form)) { self::add_init_script($form['id'], 'number_formats', self::ON_PAGE_RENDER, self::get_number_formats_script($form)); self::add_init_script($form['id'], 'conditional_logic', self::ON_PAGE_RENDER, self::get_conditional_logic($form, $field_values)); } //adding currency config if there are any product fields in the form if (self::has_price_field($form)) { self::add_init_script($form['id'], 'pricing', self::ON_PAGE_RENDER, self::get_pricing_init_script($form)); } if (self::has_password_strength($form)) { $password_script = self::get_password_strength_init_script($form); self::add_init_script($form['id'], 'password', self::ON_PAGE_RENDER, $password_script); } if (self::has_enhanced_dropdown($form)) { $chosen_script = self::get_chosen_init_script($form); self::add_init_script($form['id'], 'chosen', self::ON_PAGE_RENDER, $chosen_script); self::add_init_script($form['id'], 'chosen', self::ON_CONDITIONAL_LOGIC, $chosen_script); } if (self::has_character_counter($form)) { self::add_init_script($form['id'], 'character_counter', self::ON_PAGE_RENDER, self::get_counter_init_script($form)); } if (self::has_input_mask($form)) { self::add_init_script($form['id'], 'input_mask', self::ON_PAGE_RENDER, self::get_input_mask_init_script($form)); } if (self::has_calculation_field($form)) { self::add_init_script($form['id'], 'number_formats', self::ON_PAGE_RENDER, self::get_number_formats_script($form)); self::add_init_script($form['id'], 'calculation', self::ON_PAGE_RENDER, self::get_calculations_init_script($form)); } if (self::has_currency_format_number_field($form)) { self::add_init_script($form['id'], 'currency_format', self::ON_PAGE_RENDER, self::get_currency_format_init_script($form)); } if (self::has_currency_copy_values_option($form)) { self::add_init_script($form['id'], 'copy_values', self::ON_PAGE_RENDER, self::get_copy_values_init_script($form)); } if (self::has_placeholder($form)) { self::add_init_script($form['id'], 'placeholders', self::ON_PAGE_RENDER, self::get_placeholders_init_script($form)); } if (isset($form['fields']) && is_array($form['fields'])) { foreach ($form['fields'] as $field) { /* @var GF_Field $field */ if (is_subclass_of($field, 'GF_Field')) { $field->register_form_init_scripts($form); } } } gf_do_action('gform_register_init_scripts', $form['id'], $form, $field_values, $is_ajax); }