Пример #1
0
 private static function upload_files($form, $files)
 {
     //Creating temp folder if it does not exist
     $target_path = RGFormsModel::get_upload_path($form["id"]) . "/tmp/";
     wp_mkdir_p($target_path);
     foreach ($form["fields"] as $field) {
         $input_name = "input_{$field["id"]}";
         //skip fields that are not file upload fields or that don't have a file to be uploaded or that have failed validation
         $input_type = RGFormsModel::get_input_type($field);
         if (!in_array($input_type, array("fileupload", "post_image")) || $field["failed_validation"] || empty($_FILES[$input_name]["name"])) {
             GFCommon::log_debug("upload_files() - skipping field: {$field["label"]}({$field["id"]} - {$field["type"]})");
             continue;
         }
         $file_info = RGFormsModel::get_temp_filename($form["id"], $input_name);
         GFCommon::log_debug("upload_files() - temp file info: " . print_r($file_info, true));
         if ($file_info && move_uploaded_file($_FILES[$input_name]['tmp_name'], $target_path . $file_info["temp_filename"])) {
             $files[$input_name] = $file_info["uploaded_filename"];
             GFCommon::log_debug("upload_files() - file uploaded successfully:  {$file_info["uploaded_filename"]}");
         } else {
             GFCommon::log_error("upload_files() - file could not be uploaded: tmp_name: {$_FILES[$input_name]['tmp_name']} - target location: " . $target_path . $file_info["temp_filename"]);
         }
     }
     return $files;
 }
Пример #2
0
    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 = apply_filters('gform_admin_pre_render_' . $form_id, apply_filters('gform_admin_pre_render', $form));
        $lead_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';
        $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;
            }
            $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';
                }
            }
        }
        $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();
                }
                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')) {
                    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.');
                    }
                    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'));
        ?>
" />

		<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 
                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 . '"/>';
            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="' . esc_attr__('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 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') ? '&notes=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);
        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 
        }
    }
Пример #3
0
 private static function upload_files($form, $files)
 {
     $form_upload_path = GFFormsModel::get_upload_path($form['id']);
     GFCommon::log_debug("GFFormDisplay::upload_files(): Upload path {$form_upload_path}");
     //Creating temp folder if it does not exist
     $target_path = $form_upload_path . '/tmp/';
     wp_mkdir_p($target_path);
     GFCommon::recursive_add_index_file($form_upload_path);
     foreach ($form['fields'] as $field) {
         $input_name = "input_{$field->id}";
         //skip fields that are not file upload fields or that don't have a file to be uploaded or that have failed validation
         $input_type = RGFormsModel::get_input_type($field);
         if (!in_array($input_type, array('fileupload', 'post_image')) || $field->multipleFiles) {
             continue;
         }
         /*if ( $field->failed_validation || empty( $_FILES[ $input_name ]['name'] ) ) {
         			GFCommon::log_debug( "GFFormDisplay::upload_files(): Skipping field: {$field->label}({$field->id} - {$field->type})." );
         			continue;
         		}*/
         if ($field->failed_validation) {
             GFCommon::log_debug("GFFormDisplay::upload_files(): Skipping field because it failed validation: {$field->label}({$field->id} - {$field->type}).");
             continue;
         }
         if (empty($_FILES[$input_name]['name'])) {
             GFCommon::log_debug("GFFormDisplay::upload_files(): Skipping field because " . $_FILES[$input_name]['name'] . " could not be found: {$field->label}({$field->id} - {$field->type}).");
             continue;
         }
         $file_name = $_FILES[$input_name]['name'];
         if (GFCommon::file_name_has_disallowed_extension($file_name)) {
             GFCommon::log_debug(__METHOD__ . "(): Illegal file extension: {$file_name}");
             continue;
         }
         $allowed_extensions = !empty($field->allowedExtensions) ? GFCommon::clean_extensions(explode(',', strtolower($field->allowedExtensions))) : array();
         if (!empty($allowed_extensions)) {
             if (!GFCommon::match_file_extension($file_name, $allowed_extensions)) {
                 GFCommon::log_debug(__METHOD__ . "(): The uploaded file type is not allowed: {$file_name}");
                 continue;
             }
         }
         /**
          * Allows the disabling of file upload whitelisting
          *
          * @param bool false Set to 'true' to disable whitelisting.  Defaults to 'false'.
          */
         $whitelisting_disabled = apply_filters('gform_file_upload_whitelisting_disabled', false);
         if (empty($allowed_extensions) && !$whitelisting_disabled) {
             // Whitelist the file type
             $valid_file_name = GFCommon::check_type_and_ext($_FILES[$input_name], $file_name);
             if (is_wp_error($valid_file_name)) {
                 GFCommon::log_debug(__METHOD__ . "(): The uploaded file type is not allowed: {$file_name}");
                 continue;
             }
         }
         $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name);
         GFCommon::log_debug('GFFormDisplay::upload_files(): Temp file info: ' . print_r($file_info, true));
         if ($file_info && move_uploaded_file($_FILES[$input_name]['tmp_name'], $target_path . $file_info['temp_filename'])) {
             GFFormsModel::set_permissions($target_path . $file_info['temp_filename']);
             $files[$input_name] = $file_info['uploaded_filename'];
             GFCommon::log_debug("GFFormDisplay::upload_files(): File uploaded successfully: {$file_info['uploaded_filename']}");
         } else {
             GFCommon::log_error("GFFormDisplay::upload_files(): File could not be uploaded: tmp_name: {$_FILES[$input_name]['tmp_name']} - target location: " . $target_path . $file_info['temp_filename']);
         }
     }
     return $files;
 }
Пример #4
0
 private static function upload_files($form, $files)
 {
     $form_upload_path = GFFormsModel::get_upload_path($form['id']);
     //Creating temp folder if it does not exist
     $target_path = $form_upload_path . '/tmp/';
     wp_mkdir_p($target_path);
     GFCommon::recursive_add_index_file($form_upload_path);
     foreach ($form['fields'] as $field) {
         $input_name = "input_{$field->id}";
         //skip fields that are not file upload fields or that don't have a file to be uploaded or that have failed validation
         $input_type = RGFormsModel::get_input_type($field);
         if (!in_array($input_type, array('fileupload', 'post_image')) || $field->multipleFiles) {
             continue;
         }
         if ($field->failed_validation || empty($_FILES[$input_name]['name'])) {
             GFCommon::log_debug("GFFormDisplay::upload_files(): Skipping field: {$field->label}({$field->id} - {$field->type}).");
             continue;
         }
         $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name);
         GFCommon::log_debug('GFFormDisplay::upload_files(): Temp file info: ' . print_r($file_info, true));
         if ($file_info && move_uploaded_file($_FILES[$input_name]['tmp_name'], $target_path . $file_info['temp_filename'])) {
             GFFormsModel::set_permissions($target_path . $file_info['temp_filename']);
             $files[$input_name] = $file_info['uploaded_filename'];
             GFCommon::log_debug("GFFormDisplay::upload_files(): File uploaded successfully: {$file_info['uploaded_filename']}");
         } else {
             GFCommon::log_error("GFFormDisplay::upload_files(): File could not be uploaded: tmp_name: {$_FILES[$input_name]['tmp_name']} - target location: " . $target_path . $file_info['temp_filename']);
         }
     }
     return $files;
 }
 private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '', $entry = false, $notification = false)
 {
     global $phpmailer;
     $to = str_replace(' ', '', $to);
     $bcc = str_replace(' ', '', $bcc);
     $error = false;
     if (!GFCommon::is_valid_email($from)) {
         $from = get_bloginfo('admin_email');
     }
     if (!GFCommon::is_valid_email_list($to)) {
         $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.');
     } else {
         if (empty($subject) && empty($message)) {
             $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.');
         } else {
             if (!GFCommon::is_valid_email($from)) {
                 $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.');
             }
         }
     }
     if (is_wp_error($error)) {
         GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message());
         GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true));
         /**
          * Fires when an email from Gravity Forms has failed to send
          *
          * @since 1.8.10
          *
          * @param string $error   The Error message returned after the email fails to send
          * @param array  $details The details of the message that failed
          * @param array  $entry   The Entry object
          *
          */
         do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments'), $entry);
         return;
     }
     $content_type = $message_format == 'html' ? 'text/html' : 'text/plain';
     $name = empty($from_name) ? $from : $from_name;
     $headers = array();
     $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>";
     if (GFCommon::is_valid_email_list($reply_to)) {
         $headers['Reply-To'] = "Reply-To: {$reply_to}";
     }
     if (GFCommon::is_valid_email_list($bcc)) {
         $headers['Bcc'] = "Bcc: {$bcc}";
     }
     $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset');
     $abort_email = false;
     extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format, $notification));
     $is_success = false;
     if (!$abort_email) {
         GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().');
         GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true));
         $is_success = wp_mail($to, $subject, $message, $headers, $attachments);
         $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success;
         GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}");
         if (!is_wp_error($is_success) && $is_success) {
             GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.');
         } else {
             GFCommon::log_error('GFCommon::send_email(): 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.');
         }
         if (!empty($phpmailer->ErrorInfo)) {
             GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo);
         }
     } else {
         GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.');
     }
     self::add_emails_sent();
     /**
      * Fires after an email is sent
      *
      * @param bool   $is_success     True is successfully sent.  False if failed
      * @param string $to             Recipient address
      * @param string $subject        Subject line
      * @param string $message        Message body
      * @param string $headers        Email headers
      * @param string $attachments    Email attachments
      * @param string $message_format Format of the email.  Ex: text, html
      * @param string $from           Address of the sender
      * @param string $from_name      Displayed name of the sender
      * @param string $bcc            BCC recipients
      * @param string $reply_to       Reply-to address
      * @param array  $entry          Entry object associated with the sent email
      *
      */
     do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to, $entry);
 }
Пример #6
0
 private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '')
 {
     global $phpmailer;
     $to = str_replace(' ', '', $to);
     $bcc = str_replace(' ', '', $bcc);
     $error = false;
     if (!GFCommon::is_valid_email($from)) {
         $from = get_bloginfo('admin_email');
     }
     if (!GFCommon::is_valid_email_list($to)) {
         $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.');
     } else {
         if (empty($subject) && empty($message)) {
             $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.');
         } else {
             if (!GFCommon::is_valid_email($from)) {
                 $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.');
             }
         }
     }
     if (is_wp_error($error)) {
         GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message());
         GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true));
         /**
          * Fires when an email from Gravity Forms has failed to send
          *
          * @param string $error The Error message returned after the email fails to send
          */
         do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments'));
         return;
     }
     $content_type = $message_format == 'html' ? 'text/html' : 'text/plain';
     $name = empty($from_name) ? $from : $from_name;
     $headers = array();
     $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>";
     if (GFCommon::is_valid_email_list($reply_to)) {
         $headers['Reply-To'] = "Reply-To: {$reply_to}";
     }
     if (GFCommon::is_valid_email_list($bcc)) {
         $headers['Bcc'] = "Bcc: {$bcc}";
     }
     $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset');
     $abort_email = false;
     extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format));
     $is_success = false;
     if (!$abort_email) {
         GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().');
         GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true));
         $is_success = wp_mail($to, $subject, $message, $headers, $attachments);
         $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success;
         GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}");
         if (!is_wp_error($is_success) && $is_success) {
             GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.');
         } else {
             GFCommon::log_error('GFCommon::send_email(): 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.');
         }
         if (!empty($phpmailer->ErrorInfo)) {
             GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo);
         }
     } else {
         GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.');
     }
     self::add_emails_sent();
     /**
      * Fires after Gravity Forms has sent an email
      *
      * @param bool $is_success Check if the email was successfully sent
      * @param string $to The user Email to send to
      * @param string $subject The Subject of the email sent out
      * @param string $message The Message sent with a notification, alert, etc.
      * @param string $headers The email headers (the content-type and charset)
      * @param string $attachments The email attachments sent along
      * @param string $message_fomrat The Message format (HTML/Plain Text)
      * @param string $from Who the email is coming from
      * @param string $form_name The Name of the user who is associated with the from email
      * @param string $bcc The blind carbon copy which is an extra email that won't appear in the email header
      * @param string $reply_to A header that allows you to reply to another email
      */
     do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to);
 }
Пример #7
0
 public static function save_lead($form, &$lead)
 {
     global $wpdb;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry.');
     $is_form_editor = GFCommon::is_form_editor();
     $is_entry_detail = GFCommon::is_entry_detail();
     $is_admin = $is_form_editor || $is_entry_detail;
     if ($is_admin && !GFCommon::current_user_can_any('gravityforms_edit_entries')) {
         die(esc_html__("You don't have adequate permission to edit entries.", 'gravityforms'));
     }
     $lead_detail_table = self::get_lead_details_table_name();
     $is_new_lead = $lead == null;
     //Inserting lead if null
     if ($is_new_lead) {
         global $current_user;
         $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
         $lead_table = RGFormsModel::get_lead_table_name();
         $user_agent = self::truncate(rgar($_SERVER, 'HTTP_USER_AGENT'), 250);
         $user_agent = sanitize_text_field($user_agent);
         $source_url = self::truncate(self::get_current_page_url(), 200);
         /**
          * Allow the currency code to be overridden.
          *
          * @param string $currency The three character ISO currency code to be stored in the entry. Default is value returned by GFCommon::get_currency()
          * @param array $form The form currently being processed.
          *
          */
         $currency = gf_apply_filters(array('gform_currency_pre_save_entry', $form['id']), GFCommon::get_currency(), $form);
         $wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form['id'], self::get_ip(), $source_url, $user_agent, $currency));
         //reading newly created lead id
         $lead_id = $wpdb->insert_id;
         if ($lead_id == 0) {
             GFCommon::log_error(__METHOD__ . '(): Unable to save entry. ' . $wpdb->last_error);
             die(esc_html__('An error prevented the entry for this form submission being saved. Please contact support.', 'gravityforms'));
         }
         $lead = array('id' => $lead_id);
         GFCommon::log_debug(__METHOD__ . "(): Entry record created in the database. ID: {$lead_id}.");
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
     $total_fields = array();
     /* @var $calculation_fields GF_Field[] */
     $calculation_fields = array();
     $recalculate_total = false;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
     foreach ($form['fields'] as $field) {
         /* @var $field GF_Field */
         // ignore the honeypot field
         if ($field->type == 'honeypot') {
             continue;
         }
         //Ignore fields that are marked as display only
         if ($field->displayOnly && $field->type != 'password') {
             continue;
         }
         // Ignore pricing fields in the entry detail
         if ($is_entry_detail && GFCommon::is_pricing_field($field->type)) {
             continue;
         }
         // Process total field after all fields have been saved
         if ($field->type == 'total') {
             $total_fields[] = $field;
             continue;
         }
         $read_value_from_post = $is_new_lead || !isset($lead['date_created']);
         // Only save fields that are not hidden (except when updating an entry)
         if ($is_entry_detail || !GFFormsModel::is_field_hidden($form, $field, array(), $read_value_from_post ? null : $lead)) {
             // process calculation fields after all fields have been saved (moved after the is hidden check)
             if ($field->has_calculation()) {
                 $calculation_fields[] = $field;
                 continue;
             }
             if ($field->type == 'post_category') {
                 $field = GFCommon::add_categories_as_choices($field, '');
             }
             $inputs = $field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     self::save_input($form, $field, $lead, $current_fields, $input['id']);
                 }
             } else {
                 self::save_input($form, $field, $lead, $current_fields, $field->id);
             }
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             $inputs = $calculation_field->get_entry_inputs();
             if (is_array($inputs)) {
                 foreach ($inputs as $input) {
                     self::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
                     self::refresh_lead_field_value($lead['id'], $input['id']);
                 }
             } else {
                 self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
                 self::refresh_lead_field_value($lead['id'], $calculation_field->id);
             }
         }
         self::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     }
     //saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             self::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
             self::refresh_lead_field_value($lead['id'], $total_field->id);
         }
     }
     GFCommon::log_debug(__METHOD__ . '(): Finished saving entry fields.');
 }
Пример #8
0
 private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '')
 {
     global $phpmailer;
     $to = str_replace(' ', '', $to);
     $bcc = str_replace(' ', '', $bcc);
     $error = false;
     if (!GFCommon::is_valid_email($from)) {
         $from = get_bloginfo('admin_email');
     }
     if (!GFCommon::is_valid_email_list($to)) {
         $error = new WP_Error('invalid_to', 'Cannot send email because the TO address is invalid.');
     } else {
         if (empty($subject) && empty($message)) {
             $error = new WP_Error('missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.');
         } else {
             if (!GFCommon::is_valid_email($from)) {
                 $error = new WP_Error('invalid_from', 'Cannot send email because the FROM address is invalid.');
             }
         }
     }
     if (is_wp_error($error)) {
         GFCommon::log_error('GFCommon::send_email(): ' . $error->get_error_message());
         GFCommon::log_error(print_r(compact('to', 'subject', 'message'), true));
         do_action('gform_send_email_failed', $error, compact('from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments'));
         return;
     }
     $content_type = $message_format == 'html' ? 'text/html' : 'text/plain';
     $name = empty($from_name) ? $from : $from_name;
     $headers = array();
     $headers['From'] = "From: \"" . wp_strip_all_tags($name, true) . "\" <{$from}>";
     if (GFCommon::is_valid_email_list($reply_to)) {
         $headers['Reply-To'] = "Reply-To: {$reply_to}";
     }
     if (GFCommon::is_valid_email_list($bcc)) {
         $headers['Bcc'] = "Bcc: {$bcc}";
     }
     $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option('blog_charset');
     $abort_email = false;
     extract(apply_filters('gform_pre_send_email', compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), $message_format));
     $is_success = false;
     if (!$abort_email) {
         GFCommon::log_debug('GFCommon::send_email(): Sending email via wp_mail().');
         GFCommon::log_debug(print_r(compact('to', 'subject', 'message', 'headers', 'attachments', 'abort_email'), true));
         $is_success = wp_mail($to, $subject, $message, $headers, $attachments);
         $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success;
         GFCommon::log_debug("GFCommon::send_email(): Result from wp_mail(): {$result}");
         if (!is_wp_error($is_success) && $is_success) {
             GFCommon::log_debug('GFCommon::send_email(): Mail was passed from WordPress to the mail server.');
         } else {
             GFCommon::log_error('GFCommon::send_email(): 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.');
         }
         if (!empty($phpmailer->ErrorInfo)) {
             GFCommon::log_debug(__METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo);
         }
     } else {
         GFCommon::log_debug('GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.');
     }
     self::add_emails_sent();
     do_action('gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to);
 }
Пример #9
0
    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') ? '&notes=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 
        }
    }
Пример #10
0
 /**
  * Appends lines to to the csv file for the given Export ID.
  *
  * @param string $lines
  * @param string $export_id A unique ID for the export.
  */
 public static function write_file($lines, $export_id)
 {
     $uploads_folder = RGFormsModel::get_upload_root();
     if (!is_dir($uploads_folder)) {
         wp_mkdir_p($uploads_folder);
     }
     $export_folder = $uploads_folder . 'export';
     if (!is_dir($export_folder)) {
         wp_mkdir_p($export_folder);
     }
     $export_folder = trailingslashit($export_folder);
     self::maybe_create_htaccess_file($export_folder);
     self::maybe_create_index_file($export_folder);
     $file = $export_folder . sanitize_file_name('export-' . $export_id . '.csv');
     GFCommon::log_debug(__METHOD__ . '(): Writing to file.');
     $result = file_put_contents($file, $lines, FILE_APPEND);
     if ($result === false) {
         GFCommon::log_error(__METHOD__ . '(): An issue occurred whilst writing to the file.');
     } else {
         GFCommon::log_debug(__METHOD__ . '(): Number of bytes written to the file: ' . print_r($result, 1));
     }
 }
Пример #11
0
 /**
  * Handles the download request from the export entries page.
  *
  * @since 2.0.0
  */
 public static function ajax_download_export()
 {
     check_admin_referer('gform_download_export');
     if (!GFCommon::current_user_can_any('gravityforms_export_entries')) {
         die;
     }
     $form_id = absint(rgget('form-id'));
     if (empty($form_id)) {
         die;
     }
     $form = GFAPI::get_form($form_id);
     if (empty($form)) {
         die;
     }
     $filename = sanitize_title_with_dashes($form['title']) . '-' . gmdate('Y-m-d', GFCommon::get_local_timestamp(time())) . '.csv';
     GFCommon::log_debug(__METHOD__ . '(): Starting download of file: ' . $filename);
     $charset = get_option('blog_charset');
     header('Content-Description: File Transfer');
     header("Content-Disposition: attachment; filename={$filename}");
     header('Content-Type: text/csv; charset=' . $charset, true);
     $buffer_length = ob_get_length();
     //length or false if no buffer
     if ($buffer_length > 1) {
         ob_clean();
     }
     $export_folder = RGFormsModel::get_upload_root() . 'export/';
     $export_id = rgget('export-id');
     $file = $export_folder . sanitize_file_name('export-' . $export_id . '.csv');
     $result = readfile($file);
     if ($result === false) {
         GFCommon::log_error(__METHOD__ . '(): An issue occurred whilst reading the file.');
     } else {
         @unlink($file);
         GFCommon::log_debug(__METHOD__ . '(): Number of bytes read from the file: ' . print_r($result, 1));
     }
     exit;
 }