Beispiel #1
5
    public static function leads_page($form_id)
    {
        global $wpdb;
        //quit if version of wp is not supported
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        $form_id = absint($form_id);
        echo GFCommon::get_remote_message();
        $action = RGForms::post('action');
        $filter = rgget('filter');
        $search = stripslashes(rgget('s'));
        $page_index = empty($_GET['paged']) ? 0 : intval($_GET['paged']) - 1;
        $star = $filter == 'star' ? 1 : null;
        $read = $filter == 'unread' ? 0 : null;
        $status = in_array($filter, array('trash', 'spam')) ? $filter : 'active';
        $form = RGFormsModel::get_form_meta($form_id);
        $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');
        $search_operator = rgget('operator');
        if (isset($_GET['field_id']) && $_GET['field_id'] !== '') {
            $key = $search_field_id;
            $val = stripslashes(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;
            }
            if ('entry_id' == $key) {
                $key = 'id';
            }
            $filter_operator = empty($search_operator) ? 'is' : $search_operator;
            $field = GFFormsModel::get_field($form, $key);
            if ($field) {
                $input_type = GFFormsModel::get_input_type($field);
                if ($field->type == 'product' && in_array($input_type, array('radio', 'select'))) {
                    $filter_operator = 'contains';
                }
            }
            $search_criteria['field_filters'][] = array('key' => $key, 'operator' => $filter_operator, 'value' => $val);
        }
        $update_message = '';
        switch ($action) {
            case 'delete':
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $lead_id = $_POST['action_argument'];
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    RGFormsModel::delete_lead($lead_id);
                    $update_message = esc_html__('Entry deleted.', 'gravityforms');
                } else {
                    $update_message = esc_html__("You don't have adequate permission to delete entries.", 'gravityforms');
                }
                break;
            case 'bulk':
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $bulk_action = !empty($_POST['bulk_action']) ? $_POST['bulk_action'] : $_POST['bulk_action2'];
                $select_all = rgpost('all_entries');
                $leads = empty($select_all) ? $_POST['lead'] : GFFormsModel::search_lead_ids($form_id, $search_criteria);
                $entry_count = count($leads) > 1 ? sprintf(esc_html__('%d entries', 'gravityforms'), count($leads)) : esc_html__('1 entry', 'gravityforms');
                switch ($bulk_action) {
                    case 'delete':
                        if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                            RGFormsModel::delete_leads($leads);
                            $update_message = sprintf(esc_html__('%s deleted.', 'gravityforms'), $entry_count);
                        } else {
                            $update_message = esc_html__("You don't have adequate permission to delete entries.", 'gravityforms');
                        }
                        break;
                    case 'trash':
                        RGFormsModel::update_leads_property($leads, 'status', 'trash');
                        $update_message = sprintf(esc_html__('%s moved to Trash.', 'gravityforms'), $entry_count);
                        break;
                    case 'restore':
                        RGFormsModel::update_leads_property($leads, 'status', 'active');
                        $update_message = sprintf(esc_html__('%s restored from the Trash.', 'gravityforms'), $entry_count);
                        break;
                    case 'unspam':
                        RGFormsModel::update_leads_property($leads, 'status', 'active');
                        $update_message = sprintf(esc_html__('%s restored from the spam.', 'gravityforms'), $entry_count);
                        break;
                    case 'spam':
                        RGFormsModel::update_leads_property($leads, 'status', 'spam');
                        $update_message = sprintf(esc_html__('%s marked as spam.', 'gravityforms'), $entry_count);
                        break;
                    case 'mark_read':
                        RGFormsModel::update_leads_property($leads, 'is_read', 1);
                        $update_message = sprintf(esc_html__('%s marked as read.', 'gravityforms'), $entry_count);
                        break;
                    case 'mark_unread':
                        RGFormsModel::update_leads_property($leads, 'is_read', 0);
                        $update_message = sprintf(esc_html__('%s marked as unread.', 'gravityforms'), $entry_count);
                        break;
                    case 'add_star':
                        RGFormsModel::update_leads_property($leads, 'is_starred', 1);
                        $update_message = sprintf(esc_html__('%s starred.', 'gravityforms'), $entry_count);
                        break;
                    case 'remove_star':
                        RGFormsModel::update_leads_property($leads, 'is_starred', 0);
                        $update_message = sprintf(esc_html__('%s unstarred.', 'gravityforms'), $entry_count);
                        break;
                }
                break;
            case 'change_columns':
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $columns = GFCommon::json_decode(stripslashes($_POST['grid_columns']), true);
                RGFormsModel::update_grid_column_meta($form_id, $columns);
                break;
        }
        if (rgpost('button_delete_permanently')) {
            if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                RGFormsModel::delete_leads_by_form($form_id, $filter);
            }
        }
        $sort_field = empty($_GET['sort']) ? 0 : $_GET['sort'];
        $sort_direction = empty($_GET['dir']) ? 'DESC' : $_GET['dir'];
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta['type'] == 'number';
        $page_size = gf_apply_filters('gform_entry_page_size', $form_id, 20, $form_id);
        $first_item_index = $page_index * $page_size;
        if (!empty($sort_field)) {
            $sorting = array('key' => $_GET['sort'], 'direction' => $sort_direction, 'is_numeric' => $is_numeric);
        } else {
            $sorting = array();
        }
        $paging = array('offset' => $first_item_index, 'page_size' => $page_size);
        $total_count = 0;
        $leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging, $total_count);
        $summary = RGFormsModel::get_form_counts($form_id);
        $active_lead_count = $summary['total'];
        $unread_count = $summary['unread'];
        $starred_count = $summary['starred'];
        $spam_count = $summary['spam'];
        $trash_count = $summary['trash'];
        $columns = RGFormsModel::get_grid_columns($form_id, true);
        $search_qs = empty($search) ? '' : '&s=' . esc_attr(urlencode($search));
        $sort_qs = empty($sort_field) ? '' : '&sort=' . esc_attr($sort_field);
        $dir_qs = empty($sort_direction) ? '' : '&dir=' . esc_attr($sort_direction);
        $star_qs = $star !== null ? '&star=' . esc_attr($star) : '';
        $read_qs = $read !== null ? '&read=' . esc_attr($read) : '';
        $filter_qs = '&filter=' . esc_attr($filter);
        $search_field_id_qs = !isset($_GET['field_id']) ? '' : '&field_id=' . esc_attr($search_field_id);
        $search_operator_urlencoded = urlencode($search_operator);
        $search_operator_qs = empty($search_operator_urlencoded) ? '' : '&operator=' . esc_attr($search_operator_urlencoded);
        $display_total = ceil($total_count / $page_size);
        $page_links = paginate_links(array('base' => admin_url('admin.php') . "?page=gf_entries&view=entries&id={$form_id}&%_%" . $search_qs . $sort_qs . $dir_qs . $star_qs . $read_qs . $filter_qs . $search_field_id_qs . $search_operator_qs, 'format' => 'paged=%#%', 'prev_text' => esc_html__('«', 'gravityforms'), 'next_text' => esc_html__('»', 'gravityforms'), 'total' => $display_total, 'current' => $page_index + 1, 'show_all' => false));
        wp_print_styles(array('thickbox'));
        $field_filters = GFCommon::get_field_filter_settings($form);
        $init_field_id = empty($search_field_id) ? 0 : $search_field_id;
        $init_field_operator = empty($search_operator) ? 'contains' : $search_operator;
        $init_filter_vars = array('mode' => 'off', 'filters' => array(array('field' => $init_field_id, 'operator' => $init_field_operator, 'value' => $search)));
        $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min';
        ?>

		<script type="text/javascript">

		var messageTimeout = false,
			gformFieldFilters = <?php 
        echo json_encode($field_filters);
        ?>
,
			gformInitFilter = <?php 
        echo json_encode($init_filter_vars);
        ?>

				function ChangeColumns(columns) {
					jQuery("#action").val("change_columns");
					jQuery("#grid_columns").val(jQuery.toJSON(columns));
					tb_remove();
					jQuery("#lead_form")[0].submit();
				}

		function Search(sort_field_id, sort_direction, form_id, search, star, read, filter, field_id, operator) {
			var search_qs = search == "" ? "" : "&s=" + encodeURIComponent(search);
			var star_qs = star == "" ? "" : "&star=" + star;
			var read_qs = read == "" ? "" : "&read=" + read;
			var filter_qs = filter == "" ? "" : "&filter=" + filter;
			var field_id_qs = field_id == "" ? "" : "&field_id=" + field_id;
			var operator_qs = operator == "" ? "" : "&operator=" + operator;

			var location = "?page=gf_entries&view=entries&id=" + form_id + "&sort=" + sort_field_id + "&dir=" + sort_direction + search_qs + star_qs + read_qs + filter_qs + field_id_qs + operator_qs;
			document.location = location;
		}

		function ToggleStar(img, lead_id, filter) {
			var is_starred = img.src.indexOf("star1.png") >= 0;
			if (is_starred)
				img.src = img.src.replace("star1.png", "star0.png");
			else
				img.src = img.src.replace("star0.png", "star1.png");

			jQuery("#lead_row_" + lead_id).toggleClass("lead_starred");
			//if viewing the starred entries, hide the row and adjust the paging counts
			if (filter == "star") {
				var title = jQuery("#lead_row_" + lead_id);
				title.css("display", 'none');
				UpdatePagingCounts(1);
			}

			UpdateCount("star_count", is_starred ? -1 : 1);

			UpdateLeadProperty(lead_id, "is_starred", is_starred ? 0 : 1);
		}

		function ToggleRead(lead_id, filter) {
			var title = jQuery("#lead_row_" + lead_id);
			var marking_read = title.hasClass("lead_unread");

			jQuery("#mark_read_" + lead_id).css("display", marking_read ? "none" : "inline");
			jQuery("#mark_unread_" + lead_id).css("display", marking_read ? "inline" : "none");
			jQuery("#is_unread_" + lead_id).css("display", marking_read ? "inline" : "none");
			title.toggleClass("lead_unread");
			//if viewing the unread entries, hide the row and adjust the paging counts
			if (filter == "unread") {
				title.css("display", "none");
				UpdatePagingCounts(1);
			}

			UpdateCount("unread_count", marking_read ? -1 : 1);
			UpdateLeadProperty(lead_id, "is_read", marking_read ? 1 : 0);
		}

		function UpdateLeadProperty(lead_id, name, value) {
			var mysack = new sack("<?php 
        echo admin_url('admin-ajax.php');
        ?>
");
			mysack.execute = 1;
			mysack.method = 'POST';
			mysack.setVar("action", "rg_update_lead_property");
			mysack.setVar("rg_update_lead_property", "<?php 
        echo wp_create_nonce('rg_update_lead_property');
        ?>
");
			mysack.setVar("lead_id", lead_id);
			mysack.setVar("name", name);
			mysack.setVar("value", value);
			mysack.onError = function () {
				alert(<?php 
        echo json_encode(__('Ajax error while setting lead property', 'gravityforms'));
        ?>
)
			};
			mysack.runAJAX();

			return true;
		}

		function UpdateCount(element_id, change) {
			var element = jQuery("#" + element_id);
			var count = parseInt(element.html()) + change
			element.html(count + "");
		}

		function UpdatePagingCounts(change) {
			//update paging header/footer Displaying # - # of #, use counts from header, no need to use footer since they are the same, just update footer paging with header info
			var paging_range_max_header = jQuery("#paging_range_max_header");
			var paging_range_max_footer = jQuery("#paging_range_max_footer");
			var range_change_max = parseInt(paging_range_max_header.html()) - change;
			var paging_total_header = jQuery("#paging_total_header");
			var paging_total_footer = jQuery("#paging_total_footer");
			var total_change = parseInt(paging_total_header.html()) - change;
			var paging_range_min_header = jQuery("#paging_range_min_header");
			var paging_range_min_footer = jQuery("#paging_range_min_footer");
			//if min and max are the same, this is the last entry item on the page, clear out the displaying # - # of # text
			if (parseInt(paging_range_min_header.html()) == parseInt(paging_range_max_header.html())) {
				var paging_header = jQuery("#paging_header");
				paging_header.html("");
				var paging_footer = jQuery("#paging_footer");
				paging_footer.html("");
			}
			else {
				paging_range_max_header.html(range_change_max + "");
				paging_range_max_footer.html(range_change_max + "");
				paging_total_header.html(total_change + "");
				paging_total_footer.html(total_change + "");
			}
			gformVars.countAllEntries = gformVars.countAllEntries - change;
			setSelectAllText();
		}

		function DeleteLead(lead_id) {
			jQuery("#action").val("delete");
			jQuery("#action_argument").val(lead_id);
			jQuery("#lead_form")[0].submit();
			return true;
		}

		function handleBulkApply(actionElement) {

			var action = jQuery("#" + actionElement).val();
			var defaultModalOptions = '';
			var leadIds = getLeadIds();

			if (leadIds.length == 0) {
				alert(<?php 
        echo json_encode(__('Please select at least one entry.', 'gravityforms'));
        ?>
);
				return false;
			}

			switch (action) {

				case 'resend_notifications':
					resetResendNotificationsUI();
					tb_show(<?php 
        echo json_encode(esc_html__('Resend Notifications', 'gravityforms'));
        ?>
, '#TB_inline?width=350&amp;inlineId=notifications_modal_container', '');
					return false;
					break;

				case 'print':
					resetPrintUI();
					tb_show(<?php 
        echo json_encode(esc_html__('Print Entries', 'gravityforms'));
        ?>
, '#TB_inline?width=350&amp;height=250&amp;inlineId=print_modal_container', '');
					return false;
					break;

				default:
					jQuery('#action').val('bulk');
			}

		}

		function getLeadIds() {
			var all = jQuery("#all_entries").val();
			//compare string, the boolean isn't correct, even when casting to a boolean the 0 is set to true
			if (all == "1")
				return 0;

			var leads = jQuery(".check-column input[name='lead[]']:checked");
			var leadIds = new Array();

			jQuery(leads).each(function (i) {
				leadIds[i] = jQuery(leads[i]).val();
			});

			return leadIds;
		}

		function BulkResendNotifications() {


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

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

			if (selectedNotifications.length <= 0) {
				displayMessage(<?php 
        echo json_encode(esc_html__('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                : leadIds,
					filter                 : <?php 
        echo json_encode(rgget('filter'));
        ?>
,
					search                 : <?php 
        echo json_encode(rgget('s'));
        ?>
,
					operator               : <?php 
        echo json_encode(rgget('operator'));
        ?>
,
					fieldId                : <?php 
        echo json_encode(rgget('field_id'));
        ?>
,
					formId                 : <?php 
        echo json_encode($form['id']);
        ?>
				},
				function (response) {

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

					if (response) {
						displayMessage(response, 'error', '#notifications_container');
					} else {
						var message = <?php 
        echo json_encode(__('Notifications for %s were resent successfully.', 'gravityforms'));
        ?>
;
						var c = leadIds == 0 ? gformVars.countAllEntries : leadIds.length;
						displayMessage(message.replace('%s', c + ' ' + getPlural(c, <?php 
        echo json_encode(__('entry', 'gravityforms'));
        ?>
, <?php 
        echo json_encode(__('entries', 'gravityforms'));
        ?>
)), "updated", "#lead_form");
						closeModal(true);
					}

				}
			);

		}

		function resetResendNotificationsUI() {

			jQuery(".gform_notifications").attr('checked', false);
			jQuery('#notifications_container .message, #notifications_override_settings').hide();

		}

		function BulkPrint() {

			var leadIds = getLeadIds();
			if (leadIds != 0)
				leadIds = leadIds.join(',');
			var leadsQS = '&lid=' + leadIds;
			var notesQS = jQuery('#gform_print_notes').is(':checked') ? '&notes=1' : '';
			var pageBreakQS = jQuery('#gform_print_page_break').is(':checked') ? '&page_break=1' : '';
			var filterQS = '&filter=' + <?php 
        echo json_encode(rgget('filter'));
        ?>
;
			var searchQS = '&s=' + <?php 
        echo json_encode(rgget('s'));
        ?>
;
			var searchFieldIdQS = '&field_id=' + <?php 
        echo json_encode(rgget('field_id'));
        ?>
;
			var searchOperatorQS = '&operator=' + <?php 
        echo json_encode(rgget('operator'));
        ?>
;

			var url = '<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=print-entry&fid=<?php 
        echo absint($form['id']);
        ?>
' + leadsQS + notesQS + pageBreakQS + filterQS + searchQS + searchFieldIdQS + searchOperatorQS;
			window.open(url, 'printwindow');

			closeModal(true);
			hideMessage('#lead_form', false);
		}

		function resetPrintUI() {

			jQuery('#print_options input[type="checkbox"]').attr('checked', false);

		}

		function displayMessage(message, messageClass, container) {

			hideMessage(container, true);

			var messageBox = jQuery('<div class="message ' + messageClass + '" style="display:none;"><p>' + message + '</p></div>');
			jQuery(messageBox).prependTo(container).slideDown();

			if (messageClass == 'updated')
				messageTimeout = setTimeout(function () {
					hideMessage(container, false);
				}, 10000);

		}

		function hideMessage(container, messageQueued) {

			if (messageTimeout)
				clearTimeout(messageTimeout);

			var messageBox = jQuery(container).find('.message');

			if (messageQueued)
				jQuery(messageBox).remove();
			else
				jQuery(messageBox).slideUp(function () {
					jQuery(this).remove();
				});

		}

		function closeModal(isSuccess) {

			if (isSuccess)
				jQuery('.check-column input[type="checkbox"]').attr('checked', false);

			tb_remove();

		}

		function getPlural(count, singular, plural) {
			return count > 1 ? plural : singular;
		}

		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('');
				});
			}

		}

		// Select All

		var gformStrings = {
			"allEntriesOnPageAreSelected": <?php 
        echo json_encode(sprintf(esc_html__('All %s{0}%s entries on this page are selected.', 'gravityforms'), '<strong>', '</strong>'));
        ?>
,
			"selectAll"                  : <?php 
        echo json_encode(sprintf(esc_html__('Select all %s{0}%s entries.', 'gravityforms'), '<strong>', '</strong>'));
        ?>
,
			"allEntriesSelected"         : <?php 
        echo json_encode(sprintf(esc_html__('All %s{0}%s entries have been selected.', 'gravityforms'), '<strong>', '</strong>'));
        ?>
,
			"clearSelection"             : <?php 
        echo json_encode(__('Clear selection', 'gravityforms'));
        ?>
		}

		var gformVars = {
			"countAllEntries": <?php 
        echo intval($total_count);
        ?>
,
			"perPage"        : <?php 
        echo intval($page_size);
        ?>
		}

		function setSelectAllText() {
			var tr = getSelectAllText();
			jQuery("#gform-select-all-message td").html(tr);
		}

		function getSelectAllText() {
			var count;
			count = jQuery("#gf_entry_list tr:visible:not('#gform-select-all-message')").length;
			return gformStrings.allEntriesOnPageAreSelected.format(count) + " <a href='javascript:void(0)' onclick='selectAllEntriesOnAllPages();'>" + gformStrings.selectAll.format(gformVars.countAllEntries) + "</a>";
		}

		function getSelectAllTr() {
			var t = getSelectAllText();
			var colspan = jQuery("#gf_entry_list").find("tr:first td").length + 1;
			return "<tr id='gform-select-all-message' style='display:none;background-color:lightyellow;text-align:center;'><td colspan='{0}'>{1}</td></tr>".format(colspan, t);
		}
		function toggleSelectAll(visible) {
			if (gformVars.countAllEntries <= gformVars.perPage) {
				jQuery('#gform-select-all-message').hide();
				return;
			}

			if (visible)
				setSelectAllText();
			jQuery('#gform-select-all-message').toggle(visible);
		}


		function clearSelectAllEntries() {
			jQuery(".check-column input[type=checkbox]").prop('checked', false);
			clearSelectAllMessage();
		}

		function clearSelectAllMessage() {
			jQuery("#all_entries").val("0");
			jQuery("#gform-select-all-message").hide();
			jQuery("#gform-select-all-message td").html('');
		}

		function selectAllEntriesOnAllPages() {
			var trHtmlClearSelection;
			trHtmlClearSelection = gformStrings.allEntriesSelected.format(gformVars.countAllEntries) + " <a href='javascript:void(0);' onclick='clearSelectAllEntries();'>" + gformStrings.clearSelection + "</a>";
			jQuery("#all_entries").val("1");
			jQuery("#gform-select-all-message td").html(trHtmlClearSelection);
		}

		function initSelectAllEntries() {

			if (gformVars.countAllEntries > gformVars.perPage) {
				var tr = getSelectAllTr();
				jQuery("#gf_entry_list").prepend(tr);
				jQuery(".headercb").click(function () {
					toggleSelectAll(jQuery(this).prop('checked'));
				});
				jQuery("#gf_entry_list .check-column input[type=checkbox]").click(function () {
					clearSelectAllMessage();
				})
			}
		}

		String.prototype.format = function () {
			var args = arguments;
			return this.replace(/{(\d+)}/g, function (match, number) {
				return typeof args[number] != 'undefined' ? args[number] : match;
			});
		};

		// end Select All

		jQuery(document).ready(function () {


			var action = <?php 
        echo json_encode($action);
        ?>
;
			var message = <?php 
        echo json_encode($update_message);
        ?>
;
			if (action && message)
				displayMessage(message, 'updated', '#lead_form');

			var list = jQuery("#gf_entry_list").wpList({ alt: <?php 
        echo json_encode(esc_html__('Entry List', 'gravityforms'));
        ?>
});
			list.bind('wpListDelEnd', function (e, s, list) {

				var currentStatus = <?php 
        echo json_encode($filter == 'trash' || $filter == 'spam' ? $filter : 'active');
        ?>
;
				var filter = <?php 
        echo json_encode($filter);
        ?>
;
				var movingTo = "active";
				if (s.data.status == "trash")
					movingTo = "trash";
				else if (s.data.status == "spam")
					movingTo = "spam";
				else if (s.data.status == "delete")
					movingTo = "delete";

				var id = s.data.entry;
				var title = jQuery("#lead_row_" + id);
				var isUnread = title.hasClass("lead_unread");
				var isStarred = title.hasClass("lead_starred");

				if (movingTo != "delete") {
					//Updating All count
					var allCount = currentStatus == "active" ? -1 : 1;
					UpdateCount("all_count", allCount);

					//Updating Unread count
					if (isUnread) {
						var unreadCount = currentStatus == "active" ? -1 : 1;
						UpdateCount("unread_count", unreadCount);
					}

					//Updating Starred count
					if (isStarred) {
						var starCount = currentStatus == "active" ? -1 : 1;
						UpdateCount("star_count", starCount);
					}
				}

				//Updating Spam count
				if (currentStatus == "spam" || movingTo == "spam") {
					var spamCount = movingTo == "spam" ? 1 : -1;
					UpdateCount("spam_count", spamCount);
					//adjust paging counts
					if (filter == "spam") {
						UpdatePagingCounts(1);
					}
					else {
						UpdatePagingCounts(spamCount);
					}
				}

				//Updating trash count
				if (currentStatus == "trash" || movingTo == "trash") {
					var trashCount = movingTo == "trash" ? 1 : -1;
					UpdateCount("trash_count", trashCount);
					//adjust paging counts
					if (filter == "trash") {
						UpdatePagingCounts(1);
					}
					else {
						UpdatePagingCounts(trashCount);
					}
				}

			});

			initSelectAllEntries();

			jQuery('#entry_filters').gfFilterUI(gformFieldFilters, gformInitFilter, false);
			jQuery("#entry_filters").on("keypress", ".gform-filter-value", (function (event) {
				if (event.keyCode == 13) {
					Search(<?php 
        echo json_encode($sort_field);
        ?>
, <?php 
        echo json_encode($sort_direction);
        ?>
, <?php 
        echo absint($form_id);
        ?>
, jQuery('.gform-filter-value').val(), <?php 
        echo json_encode($star);
        ?>
, <?php 
        echo json_encode($read);
        ?>
, <?php 
        echo json_encode($filter);
        ?>
, jQuery('.gform-filter-field').val(), jQuery('.gform-filter-operator').val());
					event.preventDefault();
				}
			}));
		});


		</script>
		<link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin<?php 
        echo $min;
        ?>
.css" type="text/css" />
		<style>
			/*#TB_window { height: 400px !important; }
			#TB_ajaxContent[style] { height: 370px !important; }*/
			.lead_unread a, .lead_unread td {
				font-weight: bold;
			}

			.lead_spam_trash a, .lead_spam_trash td {
				font-weight: normal;
			}

			.row-actions a {
				font-weight: normal;
			}

			.entry_nowrap {
				overflow: hidden;
				white-space: nowrap;
			}
			.gform-filter-operator {
				width: 100px
			}
		</style>


		<div class="wrap <?php 
        echo GFCommon::get_browser_class();
        ?>
">
		<h2 class="gf_admin_page_title">
			<span><?php 
        esc_html_e('Entries', 'gravityforms');
        ?>
</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']);
        ?>
</span></span>
		</h2>

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

		<form id="lead_form" method="post">
		<?php 
        wp_nonce_field('gforms_entry_list', 'gforms_entry_list');
        ?>

		<input type="hidden" value="" name="grid_columns" id="grid_columns" />
		<input type="hidden" value="" name="action" id="action" />
		<input type="hidden" value="" name="action_argument" id="action_argument" />
		<input type="hidden" value="" name="all_entries" id="all_entries" />

		<ul class="subsubsub">
			<li>
				<a class="<?php 
        echo empty($filter) ? 'current' : '';
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo absint($form_id);
        ?>
"><?php 
        _ex('All', 'Entry List', 'gravityforms');
        ?>
					<span class="count">(<span id="all_count"><?php 
        echo $active_lead_count;
        ?>
</span>)</span></a> |
			</li>
			<li>
				<a class="<?php 
        echo $read !== null ? 'current' : '';
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo absint($form_id);
        ?>
&filter=unread"><?php 
        _ex('Unread', 'Entry List', 'gravityforms');
        ?>
					<span class="count">(<span id="unread_count"><?php 
        echo $unread_count;
        ?>
</span>)</span></a> |
			</li>
			<li>
				<a class="<?php 
        echo $star !== null ? 'current' : '';
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo absint($form_id);
        ?>
&filter=star"><?php 
        _ex('Starred', 'Entry List', 'gravityforms');
        ?>
					<span class="count">(<span id="star_count"><?php 
        echo $starred_count;
        ?>
</span>)</span></a> |
			</li>
			<?php 
        if (GFCommon::spam_enabled($form_id)) {
            ?>
				<li>
					<a class="<?php 
            echo $filter == 'spam' ? 'current' : '';
            ?>
" href="?page=gf_entries&view=entries&id=<?php 
            echo absint($form_id);
            ?>
&filter=spam"><?php 
            esc_html_e('Spam', 'gravityforms');
            ?>
						<span class="count">(<span id="spam_count"><?php 
            echo esc_html($spam_count);
            ?>
</span>)</span></a> |
				</li>
			<?php 
        }
        ?>
			<li>
				<a class="<?php 
        echo $filter == 'trash' ? 'current' : '';
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo absint($form_id);
        ?>
&filter=trash"><?php 
        esc_html_e('Trash', 'gravityforms');
        ?>
					<span class="count">(<span id="trash_count"><?php 
        echo esc_html($trash_count);
        ?>
</span>)</span></a></li>
		</ul>
		<div style="margin-top:12px;float:right;">
			<a style="float:right;" class="button" id="lead_search_button" href="javascript:Search('<?php 
        echo esc_js($sort_field);
        ?>
', '<?php 
        echo esc_js($sort_direction);
        ?>
', <?php 
        echo absint($form_id);
        ?>
, jQuery('.gform-filter-value').val(), '<?php 
        echo esc_js($star);
        ?>
', '<?php 
        echo esc_js($read);
        ?>
', '<?php 
        echo esc_js($filter);
        ?>
', jQuery('.gform-filter-field').val(), jQuery('.gform-filter-operator').val());"><?php 
        esc_html_e('Search', 'gravityforms');
        ?>
</a>

			<div id="entry_filters" style="float:right"></div>
		</div>
		<div class="tablenav">

			<div class="alignleft actions" style="padding:8px 0 7px 0;">
				<label class="hidden" for="bulk_action"> <?php 
        esc_html_e('Bulk action', 'gravityforms');
        ?>
</label>
				<select name="bulk_action" id="bulk_action">
					<option value=''><?php 
        esc_html_e(' Bulk action ', 'gravityforms');
        ?>
</option>
					<?php 
        switch ($filter) {
            case 'trash':
                ?>
							<option value='restore'><?php 
                esc_html_e('Restore', 'gravityforms');
                ?>
</option>
							<?php 
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='delete'><?php 
                    esc_html_e('Delete Permanently', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                break;
            case 'spam':
                ?>
							<option value='unspam'><?php 
                esc_html_e('Not Spam', 'gravityforms');
                ?>
</option>
							<?php 
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='delete'><?php 
                    esc_html_e('Delete Permanently', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                break;
            default:
                ?>
								<option value='mark_read'><?php 
                esc_html_e('Mark as Read', 'gravityforms');
                ?>
</option>
								<option value='mark_unread'><?php 
                esc_html_e('Mark as Unread', 'gravityforms');
                ?>
</option>
								<option value='add_star'><?php 
                esc_html_e('Add Star', 'gravityforms');
                ?>
</option>
								<option value='remove_star'><?php 
                esc_html_e('Remove Star', 'gravityforms');
                ?>
</option>
								<option value='resend_notifications'><?php 
                esc_html_e('Resend Notifications', 'gravityforms');
                ?>
</option>
								<option value='print'><?php 
                esc_html_e('Print', 'gravityforms');
                ?>
</option>

							<?php 
                if (GFCommon::spam_enabled($form_id)) {
                    ?>
								<option value='spam'><?php 
                    esc_html_e('Spam', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='trash'><?php 
                    esc_html_e('Trash', 'gravityforms');
                    ?>
</option>
							<?php 
                }
        }
        ?>
				</select>
				<?php 
        $apply_button = '<input type="submit" class="button" value="' . esc_attr__('Apply', 'gravityforms') . '" onclick="return handleBulkApply(\'bulk_action\');" />';
        /**
         * Allows for the modification of the Entry apply button HTML (When modifying entries)
         *
         * @param string $apply_button The Entry apply button HTML
         */
        echo apply_filters('gform_entry_apply_button', $apply_button);
        if (in_array($filter, array('trash', 'spam'))) {
            $message = $filter == 'trash' ? esc_html__("WARNING! This operation cannot be undone. Empty trash? 'Ok' to empty trash. 'Cancel' to abort.", 'gravityforms') : esc_html__("WARNING! This operation cannot be undone. Permanently delete all spam? 'Ok' to delete. 'Cancel' to abort.", 'gravityforms');
            $button_label = $filter == 'trash' ? __('Empty Trash', 'gravityforms') : __('Delete All Spam', 'gravityforms');
            ?>
					<input type="submit" class="button" name="button_delete_permanently" value="<?php 
            echo esc_attr($button_label);
            ?>
" onclick="return confirm('<?php 
            echo esc_js($message);
            ?>
');" />
				<?php 
        }
        ?>
				<div id="notifications_modal_container" style="display:none;">
					<div id="notifications_container">

						<div id="post_tag" class="tagsdiv">
							<div id="resend_notifications_options">

								<?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 these entries because this form does not currently have any notifications configured.', 'gravityforms');
            ?>
</p>

									<a href="<?php 
            echo esc_url(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 {
            ?>
									<p class="description"><?php 
            esc_html_e('Specify which notifications you would like to resend for the selected entries.', 'gravityforms');
            ?>
</p>
									<?php 
            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;">
											<?php 
            esc_html_e('You may override the default notification settings by entering a comma delimited list of emails to which the selected notifications should be sent.', 'gravityforms');
            ?>
										</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" id="notification_resend" value="<?php 
            esc_attr_e('Resend Notifications', 'gravityforms');
            ?>
" class="button" style="" onclick="BulkResendNotifications();" />
									<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 id="resend_notifications_close" style="display:none;margin:10px 0 0;">
								<input type="button" name="resend_notifications_close_button" value="<?php 
        esc_attr_e('Close Window', 'gravityforms');
        ?>
" class="button" style="" onclick="closeModal(true);" />
							</div>

						</div>

					</div>
				</div>
				<!-- / Resend Notifications -->

				<div id="print_modal_container" style="display:none;">
					<div id="print_container">

						<div class="tagsdiv">
							<div id="print_options">

								<p class="description"><?php 
        esc_html_e('Print all of the selected entries at once.', 'gravityforms');
        ?>
</p>

								<?php 
        if (GFCommon::current_user_can_any('gravityforms_view_entry_notes')) {
            ?>
									<input type="checkbox" name="gform_print_notes" value="print_notes" checked="checked" id="gform_print_notes" />
									<label for="gform_print_notes"><?php 
            esc_html_e('Include notes', 'gravityforms');
            ?>
</label>
									<br /><br />
								<?php 
        }
        ?>

								<input type="checkbox" name="gform_print_page_break" value="print_notes" checked="checked" id="gform_print_page_break" />
								<label for="gform_print_page_break"><?php 
        esc_html_e('Add page break between entries', 'gravityforms');
        ?>
</label>
								<br /><br />

								<input type="button" value="<?php 
        esc_attr_e('Print', 'gravityforms');
        ?>
" class="button" onclick="BulkPrint();" />

							</div>
						</div>

					</div>
				</div>
				<!-- / Print -->

			</div>

			<?php 
        echo self::display_paging_links('header', $page_links, $first_item_index, $page_size, $total_count);
        ?>

			<div class="clear"></div>
		</div>

		<table class="widefat fixed" cellspacing="0">
		<thead>
		<tr>
			<th scope="col" id="cb" class="manage-column column-cb check-column">
				<input type="checkbox" class="headercb" /></th>
			<?php 
        if (!in_array($filter, array('spam', 'trash'))) {
            ?>
				<th scope="col" id="cb" class="manage-column column-cb check-column">&nbsp;</th>
			<?php 
        }
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? 'DESC' : 'ASC';
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == 'ASC' ? 'DESC' : 'ASC';
            }
            ?>
				<th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo esc_js($field_id);
            ?>
', '<?php 
            echo esc_js($dir);
            ?>
', <?php 
            echo absint($form_id);
            ?>
, '<?php 
            echo esc_js($search);
            ?>
', '<?php 
            echo esc_js($star);
            ?>
', '<?php 
            echo esc_js($read);
            ?>
', '<?php 
            echo esc_js($filter);
            ?>
', '<?php 
            echo esc_js($search_field_id);
            ?>
', '<?php 
            echo esc_js($search_operator);
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info['label']);
            ?>
</th>
			<?php 
        }
        ?>
			<th scope="col" align="right" width="50">
				<a title="<?php 
        esc_attr_e('click to select columns to display', 'gravityforms');
        ?>
" href="<?php 
        echo trailingslashit(site_url(null, 'admin'));
        ?>
?gf_page=select_columns&id=<?php 
        echo absint($form_id);
        ?>
&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon"><i class="fa fa-cog"></i></a>
			</th>
		</tr>
		</thead>
		<tfoot>
		<tr>
			<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
			<?php 
        if (!in_array($filter, array('spam', 'trash'))) {
            ?>
				<th scope="col" id="cb" class="manage-column column-cb check-column">&nbsp;</th>
			<?php 
        }
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? 'DESC' : 'ASC';
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == 'ASC' ? 'DESC' : 'ASC';
            }
            ?>
				<th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo esc_js($field_id);
            ?>
', '<?php 
            echo esc_js($dir);
            ?>
', <?php 
            echo absint($form_id);
            ?>
, '<?php 
            echo esc_js($search);
            ?>
', '<?php 
            echo esc_js($star);
            ?>
', '<?php 
            echo esc_js($read);
            ?>
', '<?php 
            echo esc_js($filter);
            ?>
', '<?php 
            echo esc_js($search_field_id);
            ?>
', '<?php 
            echo esc_js($search_operator);
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info['label']);
            ?>
</th>
			<?php 
        }
        ?>
			<th scope="col" style="width:15px;">
				<a title="<?php 
        esc_attr_e('click to select columns to display', 'gravityforms');
        ?>
" href="<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=select_columns&id=<?php 
        echo absint($form_id);
        ?>
&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon"><i class=fa-cog"></i></a>
			</th>
		</tr>
		</tfoot>

		<tbody data-wp-lists="list:gf_entry" class="user-list" id="gf_entry_list">
		<?php 
        if (sizeof($leads) > 0) {
            $field_ids = array_keys($columns);
            $gf_entry_locking = new GFEntryLocking();
            $alternate_row = false;
            foreach ($leads as $position => $lead) {
                $position = $page_size * $page_index + $position;
                ?>
				<tr id="lead_row_<?php 
                echo esc_attr($lead['id']);
                ?>
" class='author-self status-inherit <?php 
                echo $lead['is_read'] ? '' : 'lead_unread';
                ?>
 <?php 
                echo $lead['is_starred'] ? 'lead_starred' : '';
                ?>
 <?php 
                echo in_array($filter, array('trash', 'spam')) ? 'lead_spam_trash' : '';
                ?>
 <?php 
                $gf_entry_locking->list_row_class($lead['id']);
                ?>
 <?php 
                echo ($alternate_row = !$alternate_row) ? 'alternate' : '';
                ?>
' valign="top" data-id="<?php 
                echo esc_attr($lead['id']);
                ?>
">
				<th scope="row" class="check-column">
					<input type="checkbox" name="lead[]" value="<?php 
                echo esc_attr($lead['id']);
                ?>
" />
					<?php 
                $gf_entry_locking->lock_indicator();
                ?>
				</th>
				<?php 
                if (!in_array($filter, array('spam', 'trash'))) {
                    ?>
					<td>
						<img id="star_image_<?php 
                    echo esc_attr($lead['id']);
                    ?>
" src="<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/star<?php 
                    echo intval($lead['is_starred']);
                    ?>
.png" onclick="ToggleStar(this, '<?php 
                    echo esc_js($lead['id']);
                    ?>
','<?php 
                    echo esc_js($filter);
                    ?>
');" />
					</td>
				<?php 
                }
                $is_first_column = true;
                $nowrap_class = 'entry_nowrap';
                foreach ($field_ids as $field_id) {
                    $field = RGFormsModel::get_field($form, $field_id);
                    $value = rgar($lead, $field_id);
                    if (!empty($field) && $field->type == 'post_category') {
                        $value = GFCommon::prepare_post_category_value($value, $field, 'entry_list');
                    }
                    //filtering lead value
                    $value = apply_filters('gform_get_field_value', $value, $lead, $field);
                    $input_type = !empty($columns[$field_id]['inputType']) ? $columns[$field_id]['inputType'] : $columns[$field_id]['type'];
                    switch ($input_type) {
                        case 'source_url':
                            $value = "<a href='" . esc_attr($lead['source_url']) . "' target='_blank' alt='" . esc_attr($lead['source_url']) . "' title='" . esc_attr($lead['source_url']) . "'>.../" . esc_attr(GFCommon::truncate_url($lead['source_url'])) . '</a>';
                            break;
                        case 'date_created':
                        case 'payment_date':
                            $value = GFCommon::format_date($value, false);
                            break;
                        case 'payment_amount':
                            $value = GFCommon::to_money($value, $lead['currency']);
                            break;
                        case 'created_by':
                            if (!empty($value)) {
                                $userdata = get_userdata($value);
                                if (!empty($userdata)) {
                                    $value = $userdata->user_login;
                                }
                            }
                            break;
                        default:
                            if ($field !== null) {
                                $value = $field->get_value_entry_list($value, $lead, $field_id, $columns, $form);
                            } else {
                                $value = esc_html($value);
                            }
                    }
                    $value = apply_filters('gform_entries_field_value', $value, $form_id, $field_id, $lead);
                    /* ^ maybe move to function */
                    $query_string = "gf_entries&view=entry&id={$form_id}&lid={$lead['id']}{$search_qs}{$sort_qs}{$dir_qs}{$filter_qs}&paged=" . ($page_index + 1);
                    if ($is_first_column) {
                        ?>
						<td class="column-title">
							<a href="admin.php?page=gf_entries&view=entry&id=<?php 
                        echo absint($form_id);
                        ?>
&lid=<?php 
                        echo esc_attr($lead['id'] . $search_qs . $sort_qs . $dir_qs . $filter_qs);
                        ?>
&paged=<?php 
                        echo $page_index + 1;
                        ?>
&pos=<?php 
                        echo $position;
                        ?>
&field_id=<?php 
                        echo esc_attr($search_field_id);
                        ?>
&operator=<?php 
                        echo esc_attr($search_operator);
                        ?>
"><?php 
                        echo $value;
                        ?>
</a>

							<?php 
                        $gf_entry_locking->lock_info($lead['id']);
                        ?>

							<div class="row-actions">
								<?php 
                        switch ($filter) {
                            case 'trash':
                                ?>
										<span class="edit">
                                            <a title="<?php 
                                esc_attr_e('View this entry', 'gravityforms');
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo absint($form_id);
                                ?>
&lid=<?php 
                                echo esc_attr($lead['id'] . $search_qs . $sort_qs . $dir_qs . $filter_qs);
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
&field_id=<?php 
                                echo esc_attr($search_field_id);
                                ?>
&operator=<?php 
                                echo esc_attr($search_operator);
                                ?>
"><?php 
                                esc_html_e('View', 'gravityforms');
                                ?>
</a>
                                            |
                                        </span>

										<span class="edit">
                                            <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                echo esc_attr($lead['id']);
                                ?>
::status=active&entry=<?php 
                                echo esc_attr($lead['id']);
                                ?>
' title="<?php 
                                esc_attr_e('Restore this entry', 'gravityforms');
                                ?>
" href="<?php 
                                echo wp_nonce_url('?page=gf_entries', 'gf_delete_entry');
                                ?>
"><?php 
                                esc_html_e('Restore', 'gravityforms');
                                ?>
</a>
											<?php 
                                echo GFCommon::current_user_can_any('gravityforms_delete_entries') ? '|' : '';
                                ?>
                                        </span>

										<?php 
                                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                                    ?>
											<span class="delete">
                                                <?php 
                                    $delete_link = '<a data-wp-lists="delete:gf_entry_list:lead_row_' . esc_attr($lead['id']) . '::status=delete&entry=' . esc_attr($lead['id']) . '" title="' . esc_attr__('Delete this entry permanently', 'gravityforms') . '"  href="' . wp_nonce_url('?page=gf_entries', 'gf_delete_entry') . '">' . esc_html__('Delete Permanently', 'gravityforms') . '</a>';
                                    /**
                                     * Allows for modification of a Form entry "delete" link
                                     *
                                     * @param string $delete_link The Entry Delete Link (Formatted in HTML)
                                     */
                                    echo apply_filters('gform_delete_entry_link', $delete_link);
                                    ?>
                                            </span>
										<?php 
                                }
                                break;
                            case 'spam':
                                ?>
										<span class="edit">
                                            <a title="<?php 
                                esc_attr_e('View this entry', 'gravityforms');
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo absint($form_id);
                                ?>
&lid=<?php 
                                echo esc_attr($lead['id'] . $search_qs . $sort_qs . $dir_qs . $filter_qs);
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
"><?php 
                                esc_html_e('View', 'gravityforms');
                                ?>
</a>
                                            |
                                        </span>

										<span class="unspam">
                                            <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                echo esc_attr($lead['id']);
                                ?>
::status=unspam&entry=<?php 
                                echo esc_attr($lead['id']);
                                ?>
' title="<?php 
                                esc_attr_e('Mark this entry as not spam', 'gravityforms');
                                ?>
" href="<?php 
                                echo wp_nonce_url('?page=gf_entries', 'gf_delete_entry');
                                ?>
"><?php 
                                esc_html_e('Not Spam', 'gravityforms');
                                ?>
</a>
											<?php 
                                echo GFCommon::current_user_can_any('gravityforms_delete_entries') ? '|' : '';
                                ?>
                                        </span>

										<?php 
                                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                                    ?>
											<span class="delete">
                                                <?php 
                                    $delete_link = '<a data-wp-lists="delete:gf_entry_list:lead_row_' . esc_attr($lead['id']) . '::status=delete&entry=' . esc_attr($lead['id']) . '" title="' . esc_attr__('Delete this entry permanently', 'gravityforms') . '"  href="' . wp_nonce_url('?page=gf_entries', 'gf_delete_entry') . '">' . esc_html__('Delete Permanently', 'gravityforms') . '</a>';
                                    /**
                                     * Allows for modification of a Form entry "delete" link
                                     *
                                     * @param string $delete_link The Entry Delete Link (Formatted in HTML)
                                     */
                                    echo apply_filters('gform_delete_entry_link', $delete_link);
                                    ?>
                                            </span>
										<?php 
                                }
                                break;
                            default:
                                ?>
											<span class="edit">
                                                <a title="<?php 
                                esc_attr_e('View this entry', 'gravityforms');
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo absint($form_id);
                                ?>
&lid=<?php 
                                echo esc_attr($lead['id'] . $search_qs . $sort_qs . $dir_qs . $filter_qs);
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
&field_id=<?php 
                                echo esc_attr($search_field_id);
                                ?>
&operator=<?php 
                                echo esc_attr($search_operator);
                                ?>
"><?php 
                                esc_html_e('View', 'gravityforms');
                                ?>
</a>
                                                |
                                            </span>
											<span class="edit">
                                                <a id="mark_read_<?php 
                                echo esc_attr($lead['id']);
                                ?>
" title="Mark this entry as read" href="javascript:ToggleRead('<?php 
                                echo esc_js($lead['id']);
                                ?>
', '<?php 
                                echo esc_js($filter);
                                ?>
');" style="display:<?php 
                                echo $lead['is_read'] ? 'none' : 'inline';
                                ?>
;"><?php 
                                esc_html_e('Mark read', 'gravityforms');
                                ?>
</a><a id="mark_unread_<?php 
                                echo absint($lead['id']);
                                ?>
" title="<?php 
                                esc_attr_e('Mark this entry as unread', 'gravityforms');
                                ?>
" href="javascript:ToggleRead('<?php 
                                echo esc_js($lead['id']);
                                ?>
', '<?php 
                                echo esc_js($filter);
                                ?>
');" style="display:<?php 
                                echo $lead['is_read'] ? 'inline' : 'none';
                                ?>
;"><?php 
                                esc_html_e('Mark unread', 'gravityforms');
                                ?>
</a>
											<?php 
                                echo GFCommon::current_user_can_any('gravityforms_delete_entries') || GFCommon::akismet_enabled($form_id) ? '|' : '';
                                ?>
                                            </span>
										<?php 
                                if (GFCommon::spam_enabled($form_id)) {
                                    ?>
											<span class="spam">
                                                <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                    echo esc_attr($lead['id']);
                                    ?>
::status=spam&entry=<?php 
                                    echo esc_attr($lead['id']);
                                    ?>
' title="<?php 
                                    esc_attr_e('Mark this entry as spam', 'gravityforms');
                                    ?>
" href="<?php 
                                    echo wp_nonce_url('?page=gf_entries', 'gf_delete_entry');
                                    ?>
"><?php 
                                    esc_html_e('Spam', 'gravityforms');
                                    ?>
</a>
												<?php 
                                    echo GFCommon::current_user_can_any('gravityforms_delete_entries') ? '|' : '';
                                    ?>
                                            </span>

										<?php 
                                }
                                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                                    ?>
											<span class="trash">
                                                <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                    echo esc_attr($lead['id']);
                                    ?>
::status=trash&entry=<?php 
                                    echo esc_attr($lead['id']);
                                    ?>
' title="<?php 
                                    esc_attr_e('Move this entry to the trash', 'gravityforms');
                                    ?>
" href="<?php 
                                    echo wp_nonce_url('?page=gf_entries', 'gf_delete_entry');
                                    ?>
"><?php 
                                    esc_html_e('Trash', 'gravityforms');
                                    ?>
</a>
                                            </span>
										<?php 
                                }
                                break;
                        }
                        do_action('gform_entries_first_column_actions', $form_id, $field_id, $value, $lead, $query_string);
                        ?>

							</div>
							<?php 
                        do_action('gform_entries_first_column', $form_id, $field_id, $value, $lead, $query_string);
                        ?>
						</td>
					<?php 
                    } else {
                        ?>
						<td class="<?php 
                        echo $nowrap_class;
                        ?>
">
							<?php 
                        echo apply_filters('gform_entries_column_filter', $value, $form_id, $field_id, $lead, $query_string);
                        ?>
&nbsp;
							<?php 
                        do_action('gform_entries_column', $form_id, $field_id, $value, $lead, $query_string);
                        ?>
						</td>
					<?php 
                    }
                    $is_first_column = false;
                }
                ?>
				<td>&nbsp;</td>
				</tr>
			<?php 
            }
        } else {
            $column_count = sizeof($columns) + 3;
            switch ($filter) {
                case 'unread':
                    $message = isset($_GET['field_id']) ? esc_html__('This form does not have any unread entries matching the search criteria.', 'gravityforms') : esc_html__('This form does not have any unread entries.', 'gravityforms');
                    break;
                case 'star':
                    $message = isset($_GET['field_id']) ? esc_html__('This form does not have any starred entries matching the search criteria.', 'gravityforms') : esc_html__('This form does not have any starred entries.', 'gravityforms');
                    break;
                case 'spam':
                    $message = esc_html__('This form does not have any spam.', 'gravityforms');
                    $column_count = sizeof($columns) + 2;
                    break;
                case 'trash':
                    $message = isset($_GET['field_id']) ? esc_html__('This form does not have any entries in the trash matching the search criteria.', 'gravityforms') : esc_html__('This form does not have any entries in the trash.', 'gravityforms');
                    $column_count = sizeof($columns) + 2;
                    break;
                default:
                    $message = isset($_GET['field_id']) ? esc_html__('This form does not have any entries matching the search criteria.', 'gravityforms') : esc_html__('This form does not have any entries yet.', 'gravityforms');
            }
            ?>
			<tr>
				<td colspan="<?php 
            echo esc_attr($column_count);
            ?>
" style="padding:20px;"><?php 
            echo esc_html($message);
            ?>
</td>
			</tr>
		<?php 
        }
        ?>
		</tbody>
		</table>

		<div class="clear"></div>

		<div class="tablenav">

			<div class="alignleft actions" style="padding:8px 0 7px 0;">
				<label class="hidden" for="bulk_action2"> <?php 
        esc_html_e('Bulk action', 'gravityforms');
        ?>
</label>
				<select name="bulk_action2" id="bulk_action2">
					<option value=''><?php 
        esc_html_e(' Bulk action ', 'gravityforms');
        ?>
</option>
					<?php 
        switch ($filter) {
            case 'trash':
                ?>
							<option value='restore'><?php 
                esc_html_e('Restore', 'gravityforms');
                ?>
</option>
							<?php 
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='delete'><?php 
                    esc_html_e('Delete Permanently', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                break;
            case 'spam':
                ?>
							<option value='unspam'><?php 
                esc_html_e('Not Spam', 'gravityforms');
                ?>
</option>
							<?php 
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='delete'><?php 
                    esc_html_e('Delete Permanently', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                break;
            default:
                ?>
								<option value='mark_read'><?php 
                esc_html_e('Mark as Read', 'gravityforms');
                ?>
</option>
								<option value='mark_unread'><?php 
                esc_html_e('Mark as Unread', 'gravityforms');
                ?>
</option>
								<option value='add_star'><?php 
                esc_html_e('Add Star', 'gravityforms');
                ?>
</option>
								<option value='remove_star'><?php 
                esc_html_e('Remove Star', 'gravityforms');
                ?>
</option>
								<option value='resend_notifications'><?php 
                esc_html_e('Resend Notifications', 'gravityforms');
                ?>
</option>
								<option value='print'><?php 
                esc_html_e('Print Entries', 'gravityforms');
                ?>
</option>
							<?php 
                if (GFCommon::spam_enabled($form_id)) {
                    ?>
								<option value='spam'><?php 
                    esc_html_e('Spam', 'gravityforms');
                    ?>
</option>
							<?php 
                }
                if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                    ?>
								<option value='trash'><?php 
                    esc_html_e('Move to Trash', 'gravityforms');
                    ?>
</option>
							<?php 
                }
        }
        ?>
				</select>
				<?php 
        $apply_button = '<input type="submit" class="button" value="' . esc_attr__('Apply', 'gravityforms') . '" onclick="return handleBulkApply(\'bulk_action2\');" />';
        /**
         * Allows for the modification of the Entry apply button HTML (When modifying entries)
         *
         * @param string $apply_button The Entry apply button HTML
         */
        echo apply_filters('gform_entry_apply_button', $apply_button);
        ?>
			</div>

			<?php 
        echo self::display_paging_links('footer', $page_links, $first_item_index, $page_size, $total_count);
        ?>

			<div class="clear"></div>
		</div>

		</form>
		</div>
	<?php 
    }
 public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
 {
     $use_value = $modifier == 'value';
     $use_price = in_array($modifier, array('price', 'currency'));
     $format_currency = $modifier == 'currency';
     if (is_array($raw_value) && (string) intval($input_id) != $input_id) {
         $items = array($input_id => $value);
         //float input Ids. (i.e. 4.1 ). Used when targeting specific checkbox items
     } elseif (is_array($raw_value)) {
         $items = $raw_value;
     } else {
         $items = array($input_id => $raw_value);
     }
     $ary = array();
     foreach ($items as $input_id => $item) {
         if ($use_value) {
             list($val, $price) = rgexplode('|', $item, 2);
         } elseif ($use_price) {
             list($name, $val) = rgexplode('|', $item, 2);
             if ($format_currency) {
                 $val = GFCommon::to_money($val, rgar($entry, 'currency'));
             }
         } elseif ($this->type == 'post_category') {
             $use_id = strtolower($modifier) == 'id';
             $item_value = GFCommon::format_post_category($item, $use_id);
             $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : $item_value;
         } else {
             $val = RGFormsModel::is_field_hidden($form, $this, array(), $entry) ? '' : RGFormsModel::get_choice_text($this, $raw_value, $input_id);
         }
         $ary[] = GFCommon::format_variable_value($val, $url_encode, $esc_html, $format);
     }
     return GFCommon::implode_non_blank(', ', $ary);
 }
 /**
  * Add {payment_amount} merge tag
  *
  * @since 1.16
  **
  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
  * @param string $text Text to replace
  * @param array $form Gravity Forms form array
  * @param array $entry Entry array
  * @param bool $url_encode Whether to URL-encode output
  *
  * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
  */
 public function replace_merge_tag($matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false)
 {
     $return = $text;
     foreach ($matches as $match) {
         $full_tag = $match[0];
         $modifier = isset($match[1]) ? $match[1] : false;
         $amount = rgar($entry, 'payment_amount');
         $formatted_amount = 'raw' === $modifier ? $amount : GFCommon::to_money($amount, rgar($entry, 'currency'));
         $return = str_replace($full_tag, $formatted_amount, $return);
     }
     unset($formatted_amount, $amount, $full_tag, $matches);
     return $return;
 }
 public function get_field_input($form, $value = '', $entry = null)
 {
     $form_id = $form['id'];
     $is_entry_detail = $this->is_entry_detail();
     $is_form_editor = $this->is_form_editor();
     $id = (int) $this->id;
     $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}";
     $product_name = !is_array($value) || empty($value[$this->id . '.1']) ? esc_attr($this->label) : esc_attr($value[$this->id . '.1']);
     $price = !is_array($value) || empty($value[$this->id . '.2']) ? $this->basePrice : esc_attr($value[$this->id . '.2']);
     $quantity = is_array($value) ? esc_attr($value[$this->id . '.3']) : '';
     if (empty($price)) {
         $price = 0;
     }
     $has_quantity = sizeof(GFCommon::get_product_fields_by_type($form, array('quantity'), $this->id)) > 0;
     if ($has_quantity) {
         $this->disableQuantity = true;
     }
     $currency = $is_entry_detail && !empty($entry) ? $entry['currency'] : '';
     $quantity_field = '';
     $qty_input_type = GFFormsModel::is_html5_enabled() ? 'number' : 'text';
     $qty_min_attr = GFFormsModel::is_html5_enabled() ? "min='0'" : '';
     $product_quantity_sub_label = apply_filters("gform_product_quantity_{$form_id}", apply_filters('gform_product_quantity', __('Quantity:', 'gravityforms'), $form_id), $form_id);
     if ($is_entry_detail || $is_form_editor) {
         $disabled_text = $is_form_editor ? 'disabled="disabled"' : '';
         $style = $this->disableQuantity ? "style='display:none;'" : '';
         $quantity_field = " <span class='ginput_quantity_label' {$style}>{$product_quantity_sub_label}</span> <input type='{$qty_input_type}' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$this->id}' class='ginput_quantity' size='10' {$disabled_text}/>";
     } else {
         if (!$this->disableQuantity) {
             $tabindex = $this->get_tabindex();
             $quantity_field .= " <span class='ginput_quantity_label'>" . $product_quantity_sub_label . "</span> <input type='{$qty_input_type}' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$this->id}' class='ginput_quantity' size='10' {$qty_min_attr} {$tabindex}/>";
         } else {
             if (!is_numeric($quantity)) {
                 $quantity = 1;
             }
             if (!$has_quantity) {
                 $quantity_field .= "<input type='hidden' name='input_{$id}.3' value='{$quantity}' class='ginput_quantity_{$form_id}_{$this->id} gform_hidden' />";
             }
         }
     }
     return "<div class='ginput_container'>\n\t\t\t\t\t<input type='hidden' name='input_{$id}.1' value='{$product_name}' class='gform_hidden' />\n\t\t\t\t\t<span class='ginput_product_price_label'>" . apply_filters("gform_product_price_{$form_id}", apply_filters('gform_product_price', __('Price', 'gravityforms'), $form_id), $form_id) . ":</span> <span class='ginput_product_price' id='{$field_id}'>" . esc_html(GFCommon::to_money($price, $currency)) . "</span>\n\t\t\t\t\t<input type='hidden' name='input_{$id}.2' id='ginput_base_price_{$form_id}_{$this->id}' class='gform_hidden' value='" . esc_attr($price) . "'/>\n\t\t\t\t\t{$quantity_field}\n\t\t\t\t</div>";
 }
    public static function leads_page($form_id)
    {
        global $wpdb;
        //quit if version of wp is not supported
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        echo GFCommon::get_remote_message();
        $action = RGForms::post("action");
        $filter = rgget("filter");
        $search = rgget("s");
        $page_index = empty($_GET["paged"]) ? 0 : intval($_GET["paged"]) - 1;
        $star = $filter == "star" ? 1 : null;
        // is_numeric(RGForms::get("star")) ? intval(RGForms::get("star")) : null;
        $read = $filter == "unread" ? 0 : null;
        //is_numeric(RGForms::get("read")) ? intval(RGForms::get("read")) : null;
        $status = in_array($filter, array("trash", "spam")) ? $filter : "active";
        $update_message = "";
        switch ($action) {
            case "delete":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $lead_id = $_POST["action_argument"];
                RGFormsModel::delete_lead($lead_id);
                $update_message = __("Entry deleted.", "gravityforms");
                break;
            case "bulk":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $bulk_action = !empty($_POST["bulk_action"]) ? $_POST["bulk_action"] : $_POST["bulk_action2"];
                $select_all = rgpost("all_entries");
                $leads = empty($select_all) ? $_POST["lead"] : GFFormsModel::get_lead_ids($form_id, $search, $star, $read, null, null, $status);
                $entry_count = count($leads) > 1 ? sprintf(__("%d entries", "gravityforms"), count($leads)) : __("1 entry", "gravityforms");
                switch ($bulk_action) {
                    case "delete":
                        RGFormsModel::delete_leads($leads);
                        $update_message = sprintf(__("%s deleted.", "gravityforms"), $entry_count);
                        break;
                    case "trash":
                        RGFormsModel::update_leads_property($leads, "status", "trash");
                        $update_message = sprintf(__("%s moved to Trash.", "gravityforms"), $entry_count);
                        break;
                    case "restore":
                        RGFormsModel::update_leads_property($leads, "status", "active");
                        $update_message = sprintf(__("%s restored from the Trash.", "gravityforms"), $entry_count);
                        break;
                    case "unspam":
                        RGFormsModel::update_leads_property($leads, "status", "active");
                        $update_message = sprintf(__("%s restored from the spam.", "gravityforms"), $entry_count);
                        break;
                    case "spam":
                        RGFormsModel::update_leads_property($leads, "status", "spam");
                        $update_message = sprintf(__("%s marked as spam.", "gravityforms"), $entry_count);
                        break;
                    case "mark_read":
                        RGFormsModel::update_leads_property($leads, "is_read", 1);
                        $update_message = sprintf(__("%s marked as read.", "gravityforms"), $entry_count);
                        break;
                    case "mark_unread":
                        RGFormsModel::update_leads_property($leads, "is_read", 0);
                        $update_message = sprintf(__("%s marked as unread.", "gravityforms"), $entry_count);
                        break;
                    case "add_star":
                        RGFormsModel::update_leads_property($leads, "is_starred", 1);
                        $update_message = sprintf(__("%s starred.", "gravityforms"), $entry_count);
                        break;
                    case "remove_star":
                        RGFormsModel::update_leads_property($leads, "is_starred", 0);
                        $update_message = sprintf(__("%s unstarred.", "gravityforms"), $entry_count);
                        break;
                }
                break;
            case "change_columns":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $columns = GFCommon::json_decode(stripslashes($_POST["grid_columns"]), true);
                RGFormsModel::update_grid_column_meta($form_id, $columns);
                break;
        }
        if (rgpost("button_delete_permanently")) {
            RGFormsModel::delete_leads_by_form($form_id, $filter);
        }
        $sort_field = empty($_GET["sort"]) ? 0 : $_GET["sort"];
        $sort_direction = empty($_GET["dir"]) ? "DESC" : $_GET["dir"];
        $form = RGFormsModel::get_form_meta($form_id);
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta["type"] == "number";
        $page_size = apply_filters("gform_entry_page_size", apply_filters("gform_entry_page_size_{$form_id}", 20, $form_id), $form_id);
        $first_item_index = $page_index * $page_size;
        $leads = RGFormsModel::get_leads($form_id, $sort_field, $sort_direction, $search, $first_item_index, $page_size, $star, $read, $is_numeric, null, null, $status);
        $lead_count = RGFormsModel::get_lead_count($form_id, $search, $star, $read, null, null, $status);
        $summary = RGFormsModel::get_form_counts($form_id);
        $active_lead_count = $summary["total"];
        $unread_count = $summary["unread"];
        $starred_count = $summary["starred"];
        $spam_count = $summary["spam"];
        $trash_count = $summary["trash"];
        $columns = RGFormsModel::get_grid_columns($form_id, true);
        $search_qs = empty($search) ? "" : "&s=" . urlencode($search);
        $sort_qs = empty($sort_field) ? "" : "&sort={$sort_field}";
        $dir_qs = empty($sort_field) ? "" : "&dir={$sort_direction}";
        $star_qs = $star !== null ? "&star={$star}" : "";
        $read_qs = $read !== null ? "&read={$read}" : "";
        $filter_qs = "&filter=" . $filter;
        $display_total = ceil($lead_count / $page_size);
        $page_links = paginate_links(array('base' => admin_url("admin.php") . "?page=gf_entries&view=entries&id={$form_id}&%_%" . $search_qs . $sort_qs . $dir_qs . $star_qs . $read_qs . $filter_qs, 'format' => 'paged=%#%', 'prev_text' => __('&laquo;', 'gravityforms'), 'next_text' => __('&raquo;', 'gravityforms'), 'total' => $display_total, 'current' => $page_index + 1, 'show_all' => false));
        wp_print_styles(array("thickbox"));
        ?>

        <script type="text/javascript">

            var messageTimeout = false;

            function ChangeColumns(columns){
                jQuery("#action").val("change_columns");
                jQuery("#grid_columns").val(jQuery.toJSON(columns));
                tb_remove();
                jQuery("#lead_form")[0].submit();
            }

            function Search(sort_field_id, sort_direction, form_id, search, star, read, filter){
                var search_qs = search == "" ? "" : "&s=" + search;
                var star_qs = star == "" ? "" : "&star=" + star;
                var read_qs = read == "" ? "" : "&read=" + read;
                var filter_qs = filter == "" ? "" : "&filter=" + filter;

                var location = "?page=gf_entries&view=entries&id=" + form_id + "&sort=" + sort_field_id + "&dir=" + sort_direction + search_qs + star_qs + read_qs + filter_qs;
                document.location = location;
            }

            function ToggleStar(img, lead_id, filter){
                var is_starred = img.src.indexOf("star1.png") >=0
                if(is_starred)
                    img.src = img.src.replace("star1.png", "star0.png");
                else
                    img.src = img.src.replace("star0.png", "star1.png");

                jQuery("#lead_row_" + lead_id).toggleClass("lead_starred");
                //if viewing the starred entries, hide the row and adjust the paging counts
                if (filter == "star")
                {
                	var title = jQuery("#lead_row_" + lead_id);
                	title.css("display", "none");
                	UpdatePagingCounts(1);
				}

                UpdateCount("star_count", is_starred ? -1 : 1);

                UpdateLeadProperty(lead_id, "is_starred", is_starred ? 0 : 1);
            }

            function ToggleRead(lead_id, filter){
                var title = jQuery("#lead_row_" + lead_id);
                marking_read = title.hasClass("lead_unread");

                jQuery("#mark_read_" + lead_id).css("display", marking_read ? "none" : "inline");
                jQuery("#mark_unread_" + lead_id).css("display", marking_read ? "inline" : "none");
                jQuery("#is_unread_" + lead_id).css("display", marking_read ? "inline" : "none");
                title.toggleClass("lead_unread");
                //if viewing the unread entries, hide the row and adjust the paging counts
                if (filter == "unread")
                {
                	title.css("display", "none");
                	UpdatePagingCounts(1);
				}

                UpdateCount("unread_count", marking_read ? -1 : 1);
                UpdateLeadProperty(lead_id, "is_read", marking_read ? 1 : 0);
            }

            function UpdateLeadProperty(lead_id, name, value){
                var mysack = new sack("<?php 
        echo admin_url("admin-ajax.php");
        ?>
" );
                mysack.execute = 1;
                mysack.method = 'POST';
                mysack.setVar( "action", "rg_update_lead_property" );
                mysack.setVar( "rg_update_lead_property", "<?php 
        echo wp_create_nonce("rg_update_lead_property");
        ?>
" );
                mysack.setVar( "lead_id", lead_id);
                mysack.setVar( "name", name);
                mysack.setVar( "value", value);
                mysack.onError = function() { alert('<?php 
        echo esc_js(__("Ajax error while setting lead property", "gravityforms"));
        ?>
' )};
                mysack.runAJAX();

                return true;
            }

            function UpdateCount(element_id, change){
                var element = jQuery("#" + element_id);
                var count = parseInt(element.html()) + change
                element.html(count + "");
            }

            function UpdatePagingCounts(change){
				//update paging header/footer Displaying # - # of #, use counts from header, no need to use footer since they are the same, just update footer paging with header info
                var paging_range_max_header = jQuery("#paging_range_max_header");
                var paging_range_max_footer = jQuery("#paging_range_max_footer");
                var range_change_max = parseInt(paging_range_max_header.html()) - change;
                var paging_total_header = jQuery("#paging_total_header");
                var paging_total_footer = jQuery("#paging_total_footer");
                var total_change = parseInt(paging_total_header.html()) - change;
                var paging_range_min_header = jQuery("#paging_range_min_header");
                var paging_range_min_footer = jQuery("#paging_range_min_footer");
				//if min and max are the same, this is the last entry item on the page, clear out the displaying # - # of # text
                if (parseInt(paging_range_min_header.html()) == parseInt(paging_range_max_header.html()))
                {
					var paging_header = jQuery("#paging_header");
					paging_header.html("");
					var paging_footer = jQuery("#paging_footer");
					paging_footer.html("");
                }
                else
                {
                	paging_range_max_header.html(range_change_max + "");
                	paging_range_max_footer.html(range_change_max + "");
                	paging_total_header.html(total_change + "");
                	paging_total_footer.html(total_change + "");
				}
                gformVars.countAllEntries = gformVars.countAllEntries - change;
                setSelectAllText();
            }

            function DeleteLead(lead_id){
                jQuery("#action").val("delete");
                jQuery("#action_argument").val(lead_id);
                jQuery("#lead_form")[0].submit();
                return true;
            }

            function handleBulkApply(actionElement){

                var action = jQuery("#" + actionElement).val();
                var defaultModalOptions = '';
                var leadIds = getLeadIds();

                if(leadIds.length == 0){
                    alert('<?php 
        _e('Please select at least one entry.', 'gravityforms');
        ?>
');
                    return false;
                }

                switch(action){

                case 'resend_notifications':
                    resetResendNotificationsUI();
                    tb_show('<?php 
        _e("Resend Notifications", "gravityforms");
        ?>
', '#TB_inline?width=350&amp;inlineId=notifications_modal_container', '');
                    return false;
                    break;

                case 'print':
                    resetPrintUI();
                    tb_show('<?php 
        _e("Print Entries", "gravityforms");
        ?>
', '#TB_inline?width=350&amp;height=250&amp;inlineId=print_modal_container', '');
                    return false;
                    break;

                default:
                    jQuery('#action').val('bulk');
                }

            }

            function getLeadIds(){
                var all = jQuery("#all_entries").val();
                //compare string, the boolean isn't correct, even when casting to a boolean the 0 is set to true
                if(all == "1")
                    return 0;

                var leads = jQuery(".check-column input[name='lead[]']:checked");
                var leadIds = new Array();

                jQuery(leads).each(function(i){
                    leadIds[i] = jQuery(leads[i]).val();
                });

                return leadIds;
            }

            function BulkResendNotifications(){


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

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

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

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

                jQuery.post(ajaxurl, {
                    action : "gf_resend_notifications",
                    gf_resend_notifications : '<?php 
        echo wp_create_nonce('gf_resend_notifications');
        ?>
',
                    notifications: jQuery.toJSON(selectedNotifications),
                    sendTo : sendTo,
                    leadIds : leadIds,
                    filter: '<?php 
        echo esc_attr(rgget("filter"));
        ?>
',
                    search: '<?php 
        echo esc_attr(rgget("s"));
        ?>
',
                    formId : '<?php 
        echo $form['id'];
        ?>
'
                    },
                    function(response){

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

                        if(response) {
                            displayMessage(response, "error", "#notifications_container");
                        } else {
                            var message = '<?php 
        _e("Notifications for %s were resent successfully.", "gravityforms");
        ?>
';
                            displayMessage(message.replace('%s', leadIds.length + ' ' + getPlural(leadIds.length, '<?php 
        _e('entry', 'gravityforms');
        ?>
', '<?php 
        _e('entries', 'gravityforms');
        ?>
')), "updated", "#lead_form");
                            closeModal(true);
                        }

                    }
                );

            }

            function resetResendNotificationsUI(){

                jQuery('#notification_admin, #notification_user').attr('checked', false);
                jQuery('#notifications_container .message, #notifications_override_settings').hide();

            }

            function BulkPrint(){

                var leadIds = getLeadIds();
                if(leadIds != 0)
                    leadIds = leadIds.join(',');
                var leadsQS = '&lid=' + leadIds;
                var notesQS = jQuery('#gform_print_notes').is(':checked') ? '&notes=1' : '';
                var pageBreakQS = jQuery('#gform_print_page_break').is(':checked') ? '&page_break=1' : '';
                var filterQS = '&filter=<?php 
        echo esc_attr(rgget("filter"));
        ?>
';
                var searchQS = '&search=<?php 
        echo esc_attr(rgget("s"));
        ?>
';

                var url = '<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=print-entry&fid=<?php 
        echo $form['id'];
        ?>
' + leadsQS + notesQS + pageBreakQS + filterQS + searchQS;
                window.open (url,'printwindow');

                closeModal(true);
                hideMessage('#lead_form', false);
            }

            function resetPrintUI(){

                jQuery('#print_options input[type="checkbox"]').attr('checked', false);

            }

            function displayMessage(message, messageClass, container){

                hideMessage(container, true);

                var messageBox = jQuery('<div class="message ' + messageClass + '" style="display:none;"><p>' + message + '</p></div>');
                jQuery(messageBox).prependTo(container).slideDown();

                if(messageClass == 'updated')
                    messageTimeout = setTimeout(function(){ hideMessage(container, false); }, 10000);

            }

            function hideMessage(container, messageQueued){

                if(messageTimeout)
                    clearTimeout(messageTimeout);

                var messageBox = jQuery(container).find('.message');

                if(messageQueued)
                    jQuery(messageBox).remove();
                else
                    jQuery(messageBox).slideUp(function(){ jQuery(this).remove(); });

            }

            function closeModal(isSuccess) {

                if(isSuccess)
                    jQuery('.check-column input[type="checkbox"]').attr('checked', false);

                tb_remove();

            }

            function getPlural(count, singular, plural) {
                return count > 1 ? plural : singular;
            }

            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('');
                    });
                }

            }

            // Select All

            var gformStrings = {
                "allEntriesOnPageAreSelected" : "<?php 
        printf(__("All %s{0}%s entries on this page are selected.", "gravityforms"), "<strong>", "</strong>");
        ?>
",
                "selectAll" : "<?php 
        printf(__("Select all %s{0}%s entries.", "gravityforms"), "<strong>", "</strong>");
        ?>
",
                "allEntriesSelected" : "<?php 
        printf(__("All %s{0}%s entries have been selected.", "gravityforms"), "<strong>", "</strong>");
        ?>
",
                "clearSelection" : "<?php 
        _e("Clear selection", "gravityforms");
        ?>
"
            }

            var gformVars = {
                "countAllEntries" : <?php 
        echo intval($lead_count);
        ?>
,
                "perPage" : <?php 
        echo intval($page_size);
        ?>
            }

            function setSelectAllText(){
                var tr = getSelectAllText();
                jQuery("#gform-select-all-message td").html(tr);
            }

            function getSelectAllText(){
                var count;
                count = jQuery("#gf_entry_list tr:visible:not('#gform-select-all-message')").length;
                return gformStrings.allEntriesOnPageAreSelected.format(count) + " <a href='javascript:void(0)' onclick='selectAllEntriesOnAllPages();'>" + gformStrings.selectAll.format(gformVars.countAllEntries) + "</a>";
            }

            function getSelectAllTr(){
                var t = getSelectAllText();
                var colspan = jQuery("#gf_entry_list").find("tr:first td").length + 1;
                return "<tr id='gform-select-all-message' style='display:none;background-color:lightyellow;text-align:center;'><td colspan='{0}'>{1}</td></tr>".format(colspan, t);
            }
            function toggleSelectAll(visible){
                if(gformVars.countAllEntries <= gformVars.perPage){
                    jQuery('#gform-select-all-message').hide();
                    return;
                }

                if(visible)
                    setSelectAllText();
                jQuery('#gform-select-all-message').toggle(visible);
            }


            function clearSelectAllEntries(){
                jQuery(".check-column input[type=checkbox]").prop('checked', false);
                clearSelectAllMessage();
            }

            function clearSelectAllMessage(){
                jQuery("#all_entries").val("0");
                jQuery("#gform-select-all-message").hide();
                jQuery("#gform-select-all-message td").html('');
            }

            function selectAllEntriesOnAllPages (){
                var trHtmlClearSelection;
                trHtmlClearSelection = gformStrings.allEntriesSelected.format(gformVars.countAllEntries) + " <a href='javascript:void(0);' onclick='clearSelectAllEntries();'>" + gformStrings.clearSelection + "</a>";
                jQuery("#all_entries").val("1");
                jQuery("#gform-select-all-message td").html(trHtmlClearSelection);
            }

            function SetUpSelectAllEntries(){

                if(gformVars.countAllEntries > gformVars.perPage){
                    var tr = getSelectAllTr();
                    jQuery("#gf_entry_list").prepend(tr);
                    jQuery(".headercb").click(function(){
                        toggleSelectAll(jQuery(this).prop('checked'));
                    });
                    jQuery("#gf_entry_list .check-column input[type=checkbox]").click(function(){
                        clearSelectAllMessage();
                    })
                }
            }

            String.prototype.format = function() {
                var args = arguments;
                return this.replace(/{(\d+)}/g, function (match, number) {
                    return typeof args[number] != 'undefined' ? args[number] : match;
                });
            };

            // end Select All

            jQuery(document).ready(function(){
                jQuery("#lead_search").keypress(function(event){
                    if(event.keyCode == 13){
                        Search('<?php 
        echo $sort_field;
        ?>
', '<?php 
        echo $sort_direction;
        ?>
', <?php 
        echo $form_id;
        ?>
, this.value, '<?php 
        echo $star;
        ?>
', '<?php 
        echo $read;
        ?>
', '<?php 
        echo $filter;
        ?>
');
                        event.preventDefault();
                    }
                });

                var action = '<?php 
        echo $action;
        ?>
';
                var message = '<?php 
        echo $update_message;
        ?>
';
                if(action && message)
                    displayMessage(message, 'updated', '#lead_form');

                var list = jQuery("#gf_entry_list").wpList( { alt: '<?php 
        echo esc_js(__('Entry List', 'gravityforms'));
        ?>
'} );
                list.bind('wpListDelEnd', function(e, s, list){

                    var currentStatus = "<?php 
        echo $filter == "trash" || $filter == "spam" ? $filter : "active";
        ?>
";
                    var filter = "<?php 
        echo $filter;
        ?>
";
                    var movingTo = "active";
                    if(s.data.status == "trash")
                        movingTo = "trash";
                    else if(s.data.status == "spam")
                        movingTo = "spam";
                    else if(s.data.status == "delete")
                        movingTo = "delete";

                    var id = s.data.entry;
                    var title = jQuery("#lead_row_" + id);
                    var isUnread = title.hasClass("lead_unread");
                    var isStarred = title.hasClass("lead_starred");

                    if(movingTo != "delete"){
                        //Updating All count
                        var allCount = currentStatus == "active" ? -1 : 1;
                        UpdateCount("all_count", allCount);

                        //Updating Unread count
                        if(isUnread){
                            var unreadCount = currentStatus == "active" ? -1 : 1;
                            UpdateCount("unread_count", unreadCount);
                        }

                        //Updating Starred count
                        if(isStarred){
                            var starCount = currentStatus == "active" ? -1 : 1;
                            UpdateCount("star_count", starCount);
                        }
                    }

                    //Updating Spam count
                    if(currentStatus == "spam" || movingTo == "spam"){
                        var spamCount = movingTo == "spam" ? 1 : -1;
                        UpdateCount("spam_count", spamCount);
                        //adjust paging counts
                        if (filter == "spam")
                        {
                        	UpdatePagingCounts(1);
						}
						else
						{
							UpdatePagingCounts(spamCount);
						}
                    }

                    //Updating trash count
                    if(currentStatus == "trash" || movingTo == "trash"){
                        var trashCount = movingTo == "trash" ? 1 : -1;
                        UpdateCount("trash_count", trashCount);
                        //adjust paging counts
                        if (filter == "trash")
                        {
                        	UpdatePagingCounts(1);
						}
						else
						{
							UpdatePagingCounts(trashCount);
						}
                    }

                });

                SetUpSelectAllEntries();
            });

        </script>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css" type="text/css" />
        <style>
            /*#TB_window { height: 400px !important; }
            #TB_ajaxContent[style] { height: 370px !important; }*/
            .lead_unread a, .lead_unread td{font-weight: bold;}
            .lead_spam_trash a, .lead_spam_trash td{font-weight:normal;}
            .row-actions a { font-weight:normal;}
            .entry_nowrap{ overflow:hidden; white-space:nowrap; }
            .message { margin: 15px 0 0 !important; }
        </style>


        <div class="wrap">

            <div class="icon32" id="gravity-entry-icon"><br></div>
            <h2 class="gf_admin_page_title"><span><?php 
        _e("Entries", "gravityforms");
        ?>
</span><span class="gf_admin_page_subtitle"><span class="gf_admin_page_formid">ID: <?php 
        echo $form['id'];
        ?>
</span><?php 
        echo $form['title'];
        ?>
</span></h2>

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

            <form id="lead_form" method="post">
                <?php 
        wp_nonce_field('gforms_entry_list', 'gforms_entry_list');
        ?>

                <input type="hidden" value="" name="grid_columns" id="grid_columns" />
                <input type="hidden" value="" name="action" id="action" />
                <input type="hidden" value="" name="action_argument" id="action_argument" />
                <input type="hidden" value="" name="all_entries" id="all_entries" />

                <ul class="subsubsub">
                    <li><a class="<?php 
        echo empty($filter) ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
"><?php 
        _e("All", "gravityforms");
        ?>
 <span class="count">(<span id="all_count"><?php 
        echo $active_lead_count;
        ?>
</span>)</span></a> | </li>
                    <li><a class="<?php 
        echo $read !== null ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
&filter=unread"><?php 
        _e("Unread", "gravityforms");
        ?>
 <span class="count">(<span id="unread_count"><?php 
        echo $unread_count;
        ?>
</span>)</span></a> | </li>
                    <li><a class="<?php 
        echo $star !== null ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
&filter=star"><?php 
        _e("Starred", "gravityforms");
        ?>
 <span class="count">(<span id="star_count"><?php 
        echo $starred_count;
        ?>
</span>)</span></a> | </li>
                    <?php 
        if (GFCommon::akismet_enabled($form_id)) {
            ?>
                        <li><a class="<?php 
            echo $filter == "spam" ? "current" : "";
            ?>
" href="?page=gf_entries&view=entries&id=<?php 
            echo $form_id;
            ?>
&filter=spam"><?php 
            _e("Spam", "gravityforms");
            ?>
 <span class="count">(<span id="spam_count"><?php 
            echo $spam_count;
            ?>
</span>)</span></a> | </li>
                        <?php 
        }
        ?>
                    <li><a class="<?php 
        echo $filter == "trash" ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
&filter=trash"><?php 
        _e("Trash", "gravityforms");
        ?>
 <span class="count">(<span id="trash_count"><?php 
        echo $trash_count;
        ?>
</span>)</span></a></li>
                </ul>
                <p class="search-box">
                    <label class="hidden" for="lead_search"><?php 
        _e("Search Entries:", "gravityforms");
        ?>
</label>
                    <input type="text" id="lead_search" value="<?php 
        echo $search;
        ?>
"><a class="button" id="lead_search_button" href="javascript:Search('<?php 
        echo $sort_field;
        ?>
', '<?php 
        echo $sort_direction;
        ?>
', <?php 
        echo $form_id;
        ?>
, jQuery('#lead_search').val(), '<?php 
        echo $star;
        ?>
', '<?php 
        echo $read;
        ?>
', '<?php 
        echo $filter;
        ?>
');"><?php 
        _e("Search", "gravityforms");
        ?>
</a>

                </p>
                <div class="tablenav">

                    <div class="alignleft actions" style="padding:8px 0 7px 0;">
                        <label class="hidden" for="bulk_action"> <?php 
        _e("Bulk action", "gravityforms");
        ?>
</label>
                        <select name="bulk_action" id="bulk_action">
                            <option value=''><?php 
        _e(" Bulk action ", "gravityforms");
        ?>
</option>
                            <?php 
        switch ($filter) {
            case "trash":
                ?>
                                    <option value='restore'><?php 
                _e("Restore", "gravityforms");
                ?>
</option>
                                    <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                        <option value='delete'><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
                break;
            case "spam":
                ?>
                                    <option value='unspam'><?php 
                _e("Not Spam", "gravityforms");
                ?>
</option>
                                    <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                        <option value='delete'><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
                break;
            default:
                ?>
                                    <option value='mark_read'><?php 
                _e("Mark as Read", "gravityforms");
                ?>
</option>
                                    <option value='mark_unread'><?php 
                _e("Mark as Unread", "gravityforms");
                ?>
</option>
                                    <option value='add_star'><?php 
                _e("Add Star", "gravityforms");
                ?>
</option>
                                    <option value='remove_star'><?php 
                _e("Remove Star", "gravityforms");
                ?>
</option>
                                    <option value='resend_notifications'><?php 
                _e("Resend Notifications", "gravityforms");
                ?>
</option>
                                    <option value='print'><?php 
                _e("Print", "gravityforms");
                ?>
</option>

                                    <?php 
                if (GFCommon::akismet_enabled($form_id)) {
                    ?>
                                        <option value='spam'><?php 
                    _e("Spam", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                        <option value='trash'><?php 
                    _e("Trash", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
        }
        ?>
                        </select>
                        <?php 
        $apply_button = '<input type="submit" class="button" value="' . __("Apply", "gravityforms") . '" onclick="return handleBulkApply(\'bulk_action\');" />';
        echo apply_filters("gform_entry_apply_button", $apply_button);
        if (in_array($filter, array("trash", "spam"))) {
            $message = $filter == "trash" ? __("WARNING! This operation cannot be undone. Empty trash? \\'Ok\\' to empty trash. \\'Cancel\\' to abort.", "gravityforms") : __("WARNING! This operation cannot be undone. Permanently delete all spam? \\'Ok\\' to delete. \\'Cancel\\' to abort.", "gravityforms");
            $button_label = $filter == "trash" ? __("Empty Trash", "gravityforms") : __("Delete All Spam", "gravityforms");
            ?>
                            <input type="submit" class="button" name="button_delete_permanently" value="<?php 
            echo $button_label;
            ?>
" onclick="return confirm('<?php 
            echo esc_attr($message);
            ?>
');" />
                            <?php 
        }
        ?>

                        <div id="notifications_modal_container" style="display:none;">
                            <div id="notifications_container">

                                <div id="post_tag" class="tagsdiv">
                                    <div id="resend_notifications_options">

                                        <?php 
        if (!is_array($form["notifications"]) || count($form["notifications"]) <= 0) {
            ?>
                                            <p class="description"><?php 
            _e("You cannot resend notifications for these entries because this form does not currently have any notifications configured.", "gravityforms");
            ?>
</p>

                                            <a href="<?php 
            echo admin_url("admin.php?page=gf_edit_forms&view=settings&subview=notification&id={$form["id"]}");
            ?>
" class="button"><?php 
            _e("Configure Notifications", "gravityforms");
            ?>
</a>
                                        <?php 
        } else {
            ?>
                                            <p class="description"><?php 
            _e("Specify which notifications you would like to resend for the selected entries.", "gravityforms");
            ?>
</p>
                                            <?php 
            foreach ($form["notifications"] as $notification) {
                ?>
                                                <input type="checkbox" class="gform_notifications" value="<?php 
                echo $notification["id"];
                ?>
" id="notification_<?php 
                echo $notification["id"];
                ?>
" onclick="toggleNotificationOverride();" />
                                                <label for="notification_<?php 
                echo $notification["id"];
                ?>
"><?php 
                echo $notification["name"];
                ?>
</label> <br /><br />
                                            <?php 
            }
            ?>
                                            <div id="notifications_override_settings" style="display:none;">

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

                                            </div>

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

                                    </div>

                                    <div id="resend_notifications_close" style="display:none;margin:10px 0 0;">
                                        <input type="button" name="resend_notifications_close_button" value="<?php 
        _e("Close Window", "gravityforms");
        ?>
" class="button" style="" onclick="closeModal(true);"/>
                                    </div>

                                </div>

                            </div>
                        </div> <!-- / Resend Notifications -->

                        <div id="print_modal_container" style="display:none;">
                            <div id="print_container">

                                <div class="tagsdiv">
                                    <div id="print_options">

                                        <p class="description"><?php 
        _e("Print all of the selected entries at once.", "gravityforms");
        ?>
</p>

                                        <?php 
        if (GFCommon::current_user_can_any("gravityforms_view_entry_notes")) {
            ?>
                                            <input type="checkbox" name="gform_print_notes" value="print_notes" checked="checked" id="gform_print_notes" />
                                            <label for="gform_print_notes"><?php 
            _e("Include notes", "gravityforms");
            ?>
</label>
                                            <br /><br />
                                        <?php 
        }
        ?>

                                        <input type="checkbox" name="gform_print_page_break" value="print_notes" checked="checked" id="gform_print_page_break" />
                                        <label for="gform_print_page_break"><?php 
        _e("Add page break between entries", "gravityforms");
        ?>
</label>
                                        <br /><br />

                                        <input type="button" value="<?php 
        _e("Print", "gravityforms");
        ?>
" class="button" onclick="BulkPrint();" />

                                    </div>
                                </div>

                            </div>
                        </div> <!-- / Print -->

                    </div>

                    <?php 
        echo self::display_paging_links("header", $page_links, $first_item_index, $page_size, $lead_count);
        ?>

                    <div class="clear"></div>
                </div>

                <table class="widefat fixed" cellspacing="0">
                <thead>
                    <tr>
                        <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" class="headercb" /></th>
                        <?php 
        if (!in_array($filter, array("spam", "trash"))) {
            ?>
                            <th scope="col" id="cb" class="manage-column column-cb check-column" >&nbsp;</th>
                            <?php 
        }
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? "DESC" : "ASC";
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
            }
            ?>
                            <th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo $field_id;
            ?>
', '<?php 
            echo $dir;
            ?>
', <?php 
            echo $form_id;
            ?>
, '<?php 
            echo $search;
            ?>
', '<?php 
            echo $star;
            ?>
', '<?php 
            echo $read;
            ?>
', '<?php 
            echo $filter;
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info["label"]);
            ?>
</th>
                            <?php 
        }
        ?>
                        <th scope="col" align="right" width="50">
                            <a title="<?php 
        _e("Select Columns", "gravityforms");
        ?>
" href="<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=select_columns&id=<?php 
        echo $form_id;
        ?>
&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon"><?php 
        _e("Edit", "gravityforms");
        ?>
</a>
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
                        <?php 
        if (!in_array($filter, array("spam", "trash"))) {
            ?>
                            <th scope="col" id="cb" class="manage-column column-cb check-column" >&nbsp;</th>
                        <?php 
        }
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? "DESC" : "ASC";
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
            }
            ?>
                            <th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo $field_id;
            ?>
', '<?php 
            echo $dir;
            ?>
', <?php 
            echo $form_id;
            ?>
, '<?php 
            echo $search;
            ?>
', '<?php 
            echo $star;
            ?>
', '<?php 
            echo $read;
            ?>
', '<?php 
            echo $filter;
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info["label"]);
            ?>
</th>
                            <?php 
        }
        ?>
                        <th scope="col" style="width:15px;">
                            <a href="<?php 
        echo trailingslashit(site_url());
        ?>
?gf_page=select_columns&id=<?php 
        echo $form_id;
        ?>
&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon"><?php 
        _e("Edit", "gravityforms");
        ?>
</a>
                        </th>
                    </tr>
                </tfoot>

                <tbody data-wp-lists="list:gf_entry" class="user-list" id="gf_entry_list">
                    <?php 
        if (sizeof($leads) > 0) {
            $field_ids = array_keys($columns);
            foreach ($leads as $position => $lead) {
                $position = $page_size * $page_index + $position;
                ?>
                            <tr id="lead_row_<?php 
                echo $lead["id"];
                ?>
" class='author-self status-inherit <?php 
                echo $lead["is_read"] ? "" : "lead_unread";
                ?>
 <?php 
                echo $lead["is_starred"] ? "lead_starred" : "";
                ?>
 <?php 
                echo in_array($filter, array("trash", "spam")) ? "lead_spam_trash" : "";
                ?>
'  valign="top">
                                <th scope="row" class="check-column">
                                    <input type="checkbox" name="lead[]" value="<?php 
                echo $lead["id"];
                ?>
" />
                                </th>
                                <?php 
                if (!in_array($filter, array("spam", "trash"))) {
                    ?>
                                    <td >
                                        <img id="star_image_<?php 
                    echo $lead["id"];
                    ?>
" src="<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/star<?php 
                    echo intval($lead["is_starred"]);
                    ?>
.png" onclick="ToggleStar(this, <?php 
                    echo $lead["id"] . ",'" . $filter . "'";
                    ?>
);" />
                                    </td>
                                <?php 
                }
                $is_first_column = true;
                $nowrap_class = "entry_nowrap";
                foreach ($field_ids as $field_id) {
                    /* maybe move to function */
                    $field = RGFormsModel::get_field($form, $field_id);
                    $value = rgar($lead, $field_id);
                    if ($field['type'] == 'post_category') {
                        $value = GFCommon::prepare_post_category_value($value, $field, 'entry_list');
                    }
                    //filtering lead value
                    $value = apply_filters("gform_get_field_value", $value, $lead, $field);
                    $input_type = !empty($columns[$field_id]["inputType"]) ? $columns[$field_id]["inputType"] : $columns[$field_id]["type"];
                    switch ($input_type) {
                        case "checkbox":
                            $value = "";
                            //if this is the main checkbox field (not an input), display a comma separated list of all inputs
                            if (absint($field_id) == $field_id) {
                                $lead_field_keys = array_keys($lead);
                                $items = array();
                                foreach ($lead_field_keys as $input_id) {
                                    if (is_numeric($input_id) && absint($input_id) == $field_id) {
                                        $items[] = GFCommon::selection_display(rgar($lead, $input_id), null, $lead["currency"], false);
                                    }
                                }
                                $value = GFCommon::implode_non_blank(", ", $items);
                                // special case for post category checkbox fields
                                if ($field['type'] == 'post_category') {
                                    $value = GFCommon::prepare_post_category_value($value, $field, 'entry_list');
                                }
                            } else {
                                $value = "";
                                //looping through lead detail values trying to find an item identical to the column label. Mark with a tick if found.
                                $lead_field_keys = array_keys($lead);
                                foreach ($lead_field_keys as $input_id) {
                                    //mark as a tick if input label (from form meta) is equal to submitted value (from lead)
                                    if (is_numeric($input_id) && absint($input_id) == absint($field_id)) {
                                        if ($lead[$input_id] == $columns[$field_id]["label"]) {
                                            $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                        } else {
                                            $field = RGFormsModel::get_field($form, $field_id);
                                            if (rgar($field, "enableChoiceValue") || rgar($field, "enablePrice")) {
                                                foreach ($field["choices"] as $choice) {
                                                    if ($choice["value"] == $lead[$field_id]) {
                                                        $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                                        break;
                                                    } else {
                                                        if (rgar($field, "enablePrice")) {
                                                            $ary = explode("|", $lead[$field_id]);
                                                            $val = count($ary) > 0 ? $ary[0] : "";
                                                            $price = count($ary) > 1 ? $ary[1] : "";
                                                            if ($val == $choice["value"]) {
                                                                $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case "post_image":
                            list($url, $title, $caption, $description) = rgexplode("|:|", $value, 4);
                            if (!empty($url)) {
                                //displaying thumbnail (if file is an image) or an icon based on the extension
                                $thumb = self::get_icon_url($url);
                                $value = "<a href='" . esc_attr($url) . "' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$thumb}'/></a>";
                            }
                            break;
                        case "fileupload":
                            $file_path = $value;
                            if (!empty($file_path)) {
                                //displaying thumbnail (if file is an image) or an icon based on the extension
                                $thumb = self::get_icon_url($file_path);
                                $file_path = esc_attr($file_path);
                                $value = "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$thumb}'/></a>";
                            }
                            break;
                        case "source_url":
                            $value = "<a href='" . esc_attr($lead["source_url"]) . "' target='_blank' alt='" . esc_attr($lead["source_url"]) . "' title='" . esc_attr($lead["source_url"]) . "'>.../" . esc_attr(GFCommon::truncate_url($lead["source_url"])) . "</a>";
                            break;
                        case "textarea":
                        case "post_content":
                        case "post_excerpt":
                            $value = esc_html($value);
                            break;
                        case "date_created":
                        case "payment_date":
                            $value = GFCommon::format_date($value, false);
                            break;
                        case "date":
                            $field = RGFormsModel::get_field($form, $field_id);
                            $value = GFCommon::date_display($value, rgar($field, "dateFormat"));
                            break;
                        case "radio":
                        case "select":
                            $field = RGFormsModel::get_field($form, $field_id);
                            $value = GFCommon::selection_display($value, $field, $lead["currency"]);
                            break;
                        case "number":
                            $field = RGFormsModel::get_field($form, $field_id);
                            $value = GFCommon::format_number($value, rgar($field, "numberFormat"));
                            break;
                        case "total":
                        case "payment_amount":
                            $value = GFCommon::to_money($value, $lead["currency"]);
                            break;
                        case "created_by":
                            if (!empty($value)) {
                                $userdata = get_userdata($value);
                                $value = $userdata->user_login;
                            }
                            break;
                        case "multiselect":
                            // add space after comma-delimited values
                            $value = implode(', ', explode(',', $value));
                            break;
                        default:
                            $value = esc_html($value);
                    }
                    $value = apply_filters("gform_entries_field_value", $value, $form_id, $field_id, $lead);
                    /* ^ maybe move to function */
                    $query_string = "gf_entries&view=entry&id={$form_id}&lid={$lead["id"]}{$search_qs}{$sort_qs}{$dir_qs}{$filter_qs}&paged=" . ($page_index + 1);
                    if ($is_first_column) {
                        ?>
                                        <td class="column-title" >
                                            <a href="admin.php?page=gf_entries&view=entry&id=<?php 
                        echo $form_id;
                        ?>
&lid=<?php 
                        echo $lead["id"] . $search_qs . $sort_qs . $dir_qs . $filter_qs;
                        ?>
&paged=<?php 
                        echo $page_index + 1;
                        ?>
&pos=<?php 
                        echo $position;
                        ?>
"><?php 
                        echo $value;
                        ?>
</a>
                                            <div class="row-actions">
                                                <?php 
                        switch ($filter) {
                            case "trash":
                                ?>
                                                        <span class="edit">
                                                            <a title="<?php 
                                _e("View this entry", "gravityforms");
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo $form_id;
                                ?>
&lid=<?php 
                                echo $lead["id"] . $search_qs . $sort_qs . $dir_qs . $filter_qs;
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
"><?php 
                                _e("View", "gravityforms");
                                ?>
</a>
                                                            |
                                                        </span>

                                                        <span class="edit">
                                                            <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                echo $lead["id"];
                                ?>
::status=active&entry=<?php 
                                echo $lead["id"];
                                ?>
' title="<?php 
                                echo _e("Restore this entry", "gravityforms");
                                ?>
" href="<?php 
                                echo wp_nonce_url("?page=gf_entries", "gf_delete_entry");
                                ?>
"><?php 
                                _e("Restore", "gravityforms");
                                ?>
</a>
                                                            <?php 
                                echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                                ?>
                                                        </span>

                                                        <?php 
                                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                                    ?>
                                                            <span class="delete">
                                                                <?php 
                                    $delete_link = '<a data-wp-lists="delete:gf_entry_list:lead_row_' . $lead["id"] . '::status=delete&entry=' . $lead["id"] . '" title="' . __("Delete this entry permanently", "gravityforms") . '"  href="' . wp_nonce_url("?page=gf_entries", "gf_delete_entry") . '">' . __("Delete Permanently", "gravityforms") . '</a>';
                                    echo apply_filters("gform_delete_entry_link", $delete_link);
                                    ?>
                                                            </span>
                                                            <?php 
                                }
                                break;
                            case "spam":
                                ?>
                                                        <span class="edit">
                                                            <a title="<?php 
                                _e("View this entry", "gravityforms");
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo $form_id;
                                ?>
&lid=<?php 
                                echo $lead["id"] . $search_qs . $sort_qs . $dir_qs . $filter_qs;
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
"><?php 
                                _e("View", "gravityforms");
                                ?>
</a>
                                                            |
                                                        </span>

                                                        <span class="unspam">
                                                            <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                echo $lead["id"];
                                ?>
::status=unspam&entry=<?php 
                                echo $lead["id"];
                                ?>
' title="<?php 
                                echo _e("Mark this entry as not spam", "gravityforms");
                                ?>
" href="<?php 
                                echo wp_nonce_url("?page=gf_entries", "gf_delete_entry");
                                ?>
"><?php 
                                _e("Not Spam", "gravityforms");
                                ?>
</a>
                                                            <?php 
                                echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                                ?>
                                                        </span>

                                                        <?php 
                                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                                    ?>
                                                            <span class="delete">
                                                                <?php 
                                    $delete_link = '<a data-wp-lists="delete:gf_entry_list:lead_row_' . $lead["id"] . '::status=delete&entry=' . $lead["id"] . '" title="' . __("Delete this entry permanently", "gravityforms") . '"  href="' . wp_nonce_url("?page=gf_entries", "gf_delete_entry") . '">' . __("Delete Permanently", "gravityforms") . '</a>';
                                    echo apply_filters("gform_delete_entry_link", $delete_link);
                                    ?>
                                                            </span>
                                                            <?php 
                                }
                                break;
                            default:
                                ?>
                                                        <span class="edit">
                                                            <a title="<?php 
                                _e("View this entry", "gravityforms");
                                ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                                echo $form_id;
                                ?>
&lid=<?php 
                                echo $lead["id"] . $search_qs . $sort_qs . $dir_qs . $filter_qs;
                                ?>
&paged=<?php 
                                echo $page_index + 1;
                                ?>
&pos=<?php 
                                echo $position;
                                ?>
"><?php 
                                _e("View", "gravityforms");
                                ?>
</a>
                                                            |
                                                        </span>
                                                        <span class="edit">
                                                            <a id="mark_read_<?php 
                                echo $lead["id"];
                                ?>
" title="Mark this entry as read" href="javascript:ToggleRead(<?php 
                                echo $lead["id"] . ",'" . $filter . "'";
                                ?>
);" style="display:<?php 
                                echo $lead["is_read"] ? "none" : "inline";
                                ?>
;"><?php 
                                _e("Mark read", "gravityforms");
                                ?>
</a><a id="mark_unread_<?php 
                                echo $lead["id"];
                                ?>
" title="<?php 
                                _e("Mark this entry as unread", "gravityforms");
                                ?>
" href="javascript:ToggleRead(<?php 
                                echo $lead["id"] . ",'" . $filter . "'";
                                ?>
);" style="display:<?php 
                                echo $lead["is_read"] ? "inline" : "none";
                                ?>
;"><?php 
                                _e("Mark unread", "gravityforms");
                                ?>
</a>
                                                            <?php 
                                echo GFCommon::current_user_can_any("gravityforms_delete_entries") || GFCommon::akismet_enabled($form_id) ? "|" : "";
                                ?>
                                                        </span>
                                                        <?php 
                                if (GFCommon::akismet_enabled($form_id)) {
                                    ?>
                                                            <span class="spam">
                                                                <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                    echo $lead["id"];
                                    ?>
::status=spam&entry=<?php 
                                    echo $lead["id"];
                                    ?>
' title="<?php 
                                    _e("Mark this entry as spam", "gravityforms");
                                    ?>
" href="<?php 
                                    echo wp_nonce_url("?page=gf_entries", "gf_delete_entry");
                                    ?>
"><?php 
                                    _e("Spam", "gravityforms");
                                    ?>
</a>
                                                                <?php 
                                    echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                                    ?>
                                                            </span>

                                                        <?php 
                                }
                                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                                    ?>
                                                            <span class="trash">
                                                                <a data-wp-lists='delete:gf_entry_list:lead_row_<?php 
                                    echo $lead["id"];
                                    ?>
::status=trash&entry=<?php 
                                    echo $lead["id"];
                                    ?>
' title="<?php 
                                    _e("Move this entry to the trash", "gravityforms");
                                    ?>
" href="<?php 
                                    echo wp_nonce_url("?page=gf_entries", "gf_delete_entry");
                                    ?>
"><?php 
                                    _e("Trash", "gravityforms");
                                    ?>
</a>
                                                            </span>
                                                            <?php 
                                }
                                break;
                        }
                        do_action("gform_entries_first_column_actions", $form_id, $field_id, $value, $lead, $query_string);
                        ?>

                                            </div>
                                            <?php 
                        do_action("gform_entries_first_column", $form_id, $field_id, $value, $lead, $query_string);
                        ?>
                                        </td>
                                        <?php 
                    } else {
                        ?>
                                        <td class="<?php 
                        echo $nowrap_class;
                        ?>
">
                                            <?php 
                        echo apply_filters("gform_entries_column_filter", $value, $form_id, $field_id, $lead, $query_string);
                        ?>
&nbsp;
                                            <?php 
                        do_action("gform_entries_column", $form_id, $field_id, $value, $lead, $query_string);
                        ?>
                                        </td>
                                        <?php 
                    }
                    $is_first_column = false;
                }
                ?>
                                <td>&nbsp;</td>
                            </tr>
                            <?php 
            }
        } else {
            $message = "";
            $column_count = sizeof($columns) + 3;
            switch ($filter) {
                case "unread":
                    $message = __("This form does not have any unread entries.", "gravityforms");
                    break;
                case "star":
                    $message = __("This form does not have any starred entries.", "gravityforms");
                    break;
                case "spam":
                    $message = __("This form does not have any spam.", "gravityforms");
                    $column_count = sizeof($columns) + 2;
                    break;
                case "trash":
                    $message = __("This form does not have any entries in the trash.", "gravityforms");
                    $column_count = sizeof($columns) + 2;
                    break;
                default:
                    $message = __("This form does not have any entries yet.", "gravityforms");
            }
            ?>
                        <tr>
                            <td colspan="<?php 
            echo $column_count;
            ?>
" style="padding:20px;"><?php 
            echo $message;
            ?>
</td>
                        </tr>
                        <?php 
        }
        ?>
                </tbody>
                </table>

                <div class="clear"></div>

                <div class="tablenav">

                    <div class="alignleft actions" style="padding:8px 0 7px 0;">
                        <label class="hidden" for="bulk_action2"> <?php 
        _e("Bulk action", "gravityforms");
        ?>
</label>
                        <select name="bulk_action2" id="bulk_action2">
                            <option value=''><?php 
        _e(" Bulk action ", "gravityforms");
        ?>
</option>
                            <?php 
        switch ($filter) {
            case "trash":
                ?>
                                    <option value='restore'><?php 
                _e("Restore", "gravityforms");
                ?>
</option>
                                    <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                        <option value='delete'><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
                break;
            case "spam":
                ?>
                                    <option value='unspam'><?php 
                _e("Not Spam", "gravityforms");
                ?>
</option>
                                    <?php 
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                        <option value='delete'><?php 
                    _e("Delete Permanently", "gravityforms");
                    ?>
</option>
                                        <?php 
                }
                break;
            default:
                ?>
                                <option value='mark_read'><?php 
                _e("Mark as Read", "gravityforms");
                ?>
</option>
                                <option value='mark_unread'><?php 
                _e("Mark as Unread", "gravityforms");
                ?>
</option>
                                <option value='add_star'><?php 
                _e("Add Star", "gravityforms");
                ?>
</option>
                                <option value='remove_star'><?php 
                _e("Remove Star", "gravityforms");
                ?>
</option>
                                <option value='resend_notifications'><?php 
                _e("Resend Notifications", "gravityforms");
                ?>
</option>
                                <option value='print'><?php 
                _e("Print", "gravityforms");
                ?>
</option>
                                <?php 
                if (GFCommon::akismet_enabled($form_id)) {
                    ?>
                                    <option value='spam'><?php 
                    _e("Spam", "gravityforms");
                    ?>
</option>
                                    <?php 
                }
                if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                    ?>
                                    <option value='trash'><?php 
                    _e("Trash", "gravityforms");
                    ?>
</option>
                                    <?php 
                }
        }
        ?>
                        </select>
                        <?php 
        $apply_button = '<input type="submit" class="button" value="' . __("Apply", "gravityforms") . '" onclick="return handleBulkApply(\'bulk_action2\');" />';
        echo apply_filters("gform_entry_apply_button", $apply_button);
        ?>
                    </div>

                    <?php 
        echo self::display_paging_links("footer", $page_links, $first_item_index, $page_size, $lead_count);
        ?>

                    <div class="clear"></div>
                </div>

            </form>
        </div>
        <?php 
    }
 protected function get_sales_summary($form_id)
 {
     global $wpdb;
     $tz_offset = $this->get_mysql_tz_offset();
     $summary = $wpdb->get_results($wpdb->prepare("\n                    SELECT lead.date, lead.orders, lead.subscriptions, transaction.revenue\n                    FROM (\n                       SELECT  date( CONVERT_TZ(date_created, '+00:00', '" . $tz_offset . "') ) as date,\n                               sum( if(transaction_type = 1,1,0) ) as orders,\n                               sum( if(transaction_type = 2,1,0) ) as subscriptions\n                       FROM {$wpdb->prefix}rg_lead\n                       WHERE form_id = %d and datediff(now(), CONVERT_TZ(date_created, '+00:00', '" . $tz_offset . "') ) <= 30\n                       GROUP BY date\n                     ) AS lead\n\n                     LEFT OUTER JOIN(\n                       SELECT  date( CONVERT_TZ(t.date_created, '+00:00', '" . $tz_offset . "') ) as date,\n                               sum(t.amount) as revenue\n                       FROM {$wpdb->prefix}gf_addon_payment_transaction t\n                         INNER JOIN {$wpdb->prefix}rg_lead l ON l.id = t.lead_id\n                       WHERE l.form_id=%d\n                       GROUP BY date\n                     ) AS transaction on lead.date = transaction.date\n                    ORDER BY date desc", $form_id, $form_id), ARRAY_A);
     $total_summary = $wpdb->get_results($wpdb->prepare("\n                    SELECT sum( if(transaction_type = 1,1,0) ) as orders,\n                         sum( if(transaction_type = 2,1,0) ) as subscriptions\n                    FROM {$wpdb->prefix}rg_lead\n                    WHERE form_id=%d", $form_id), ARRAY_A);
     $total_revenue = $wpdb->get_var($wpdb->prepare("\n                    SELECT sum(t.amount) as revenue\n                    FROM {$wpdb->prefix}gf_addon_payment_transaction t\n                    INNER JOIN {$wpdb->prefix}rg_lead l ON l.id = t.lead_id\n                    WHERE l.form_id=%d", $form_id));
     $result = array("today" => array("revenue" => GFCommon::to_money(0), "orders" => 0, "subscriptions" => 0), "yesterday" => array("revenue" => GFCommon::to_money(0), "orders" => 0, "subscriptions" => 0), "last30" => array("revenue" => 0, "orders" => 0, "subscriptions" => 0), "total" => array("revenue" => GFCommon::to_money($total_revenue), "orders" => $total_summary[0]["orders"], "subscriptions" => $total_summary[0]["subscriptions"]));
     $local_time = GFCommon::get_local_timestamp();
     $today = gmdate("Y-m-d", $local_time);
     $yesterday = gmdate("Y-m-d", strtotime("-1 day", $local_time));
     foreach ($summary as $day) {
         if ($day["date"] == $today) {
             $result["today"]["revenue"] = GFCommon::to_money($day["revenue"]);
             $result["today"]["orders"] = $day["orders"];
             $result["today"]["subscriptions"] = $day["subscriptions"];
         } else {
             if ($day["date"] == $yesterday) {
                 $result["yesterday"]["revenue"] = GFCommon::to_money($day["revenue"]);
                 $result["yesterday"]["orders"] = $day["orders"];
                 $result["yesterday"]["subscriptions"] = $day["subscriptions"];
             }
         }
         $is_within_30_days = strtotime($day["date"]) >= strtotime($local_time . " -30 days");
         if ($is_within_30_days) {
             $result["last30"]["revenue"] += floatval($day["revenue"]);
             $result["last30"]["orders"] += floatval($day["orders"]);
             $result["last30"]["subscriptions"] += floatval($day["subscriptions"]);
         }
     }
     $result["last30"]["revenue"] = GFCommon::to_money($result["last30"]["revenue"]);
     return $result;
 }
    public static function lead_detail($Form, $lead, $allow_display_empty_fields = false, $inline = true, $options = array())
    {
        if (!class_exists('GFEntryList')) {
            require_once GFCommon::get_base_path() . "/entry_list.php";
        }
        global $current_user, $_gform_directory_approvedcolumn;
        get_currentuserinfo();
        $display_empty_fields = '';
        $allow_display_empty_fields = true;
        if ($allow_display_empty_fields) {
            $display_empty_fields = @rgget("gf_display_empty_fields", $_COOKIE);
        }
        if (empty($options)) {
            $options = self::directory_defaults();
        }
        // There is no edit link
        if (isset($_GET['edit']) || RGForms::post("action") === "update") {
            // Process editing leads
            $lead = self::edit_lead_detail($Form, $lead, $options);
            if (RGForms::post("action") !== "update") {
                return;
            }
        }
        extract($options);
        ?>
			<table cellspacing="0" class="widefat fixed entry-detail-view">
			<?php 
        $title = str_replace('%%formtitle%%', $Form["title"], str_replace('%%leadid%%', $lead['id'], $entrydetailtitle));
        if (!empty($title) && $inline) {
            ?>
				<thead>
					<tr>
						<th id="details" colspan="2" scope="col">
						<?php 
            $title = apply_filters('kws_gf_directory_detail_title', apply_filters('kws_gf_directory_detail_title_' . (int) $lead['id'], array($title, $lead), true), true);
            if (is_array($title)) {
                echo $title[0];
            } else {
                echo $title;
            }
            ?>
						</th>
					</tr>
				</thead>
				<?php 
        }
        ?>
				<tbody>
					<?php 
        $count = 0;
        $has_product_fields = false;
        $field_count = sizeof($Form["fields"]);
        $display_value = '';
        foreach ($Form["fields"] as $field) {
            // Don't show fields defined as hide in single.
            if (!empty($field['hideInSingle'])) {
                if (self::has_access("gravityforms_directory")) {
                    echo "\n\t\t\t\t\t\t\t\t\t" . '<!-- ' . sprintf(esc_html__('(Admin-only notice) Field #%d not shown: "Hide This Field in Single Entry View" was selected.', 'gravity-forms-addons'), $field['id']) . ' -->' . "\n\n";
                }
                continue;
            }
            $count++;
            $is_last = $count >= $field_count ? true : false;
            switch (RGFormsModel::get_input_type($field)) {
                case "section":
                    if (!GFCommon::is_section_empty($field, $Form, $lead) || $display_empty_fields) {
                        $count++;
                        $is_last = $count >= $field_count ? true : false;
                        ?>
	                                <tr>
	                                    <td colspan="2" class="entry-view-section-break<?php 
                        echo $is_last ? " lastrow" : "";
                        ?>
"><?php 
                        echo esc_html(GFCommon::get_label($field));
                        ?>
</td>
	                                </tr>
	                                <?php 
                    }
                    break;
                case "captcha":
                case "html":
                case "password":
                case "page":
                    //ignore captcha, html, password, page field
                    break;
                case "post_image":
                    $value = RGFormsModel::get_lead_field_value($lead, $field);
                    $valueArray = explode("|:|", $value);
                    @(list($url, $title, $caption, $description) = $valueArray);
                    if (!empty($url)) {
                        $value = $display_value = self::render_image_link($url, $lead, $options, $title, $caption, $description);
                    }
                    break;
                default:
                    //ignore product fields as they will be grouped together at the end of the grid
                    if (GFCommon::is_product_field($field["type"])) {
                        $has_product_fields = true;
                        continue;
                    }
                    $value = RGFormsModel::get_lead_field_value($lead, $field);
                    $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]);
                    break;
            }
            // end switch
            $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $Form);
            if ($display_empty_fields || !empty($display_value) || $display_value === "0") {
                $count++;
                $is_last = $count >= $field_count && !$has_product_fields ? true : false;
                $last_row = $is_last ? " lastrow" : "";
                $display_value = empty($display_value) && $display_value !== "0" ? "&nbsp;" : $display_value;
                $content = '
                            <tr>
                                <th colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</th>
                            </tr>
                            <tr>
                                <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td>
                            </tr>';
                $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $Form["id"]);
                echo $content;
            }
        }
        // End foreach
        $products = array();
        if ($has_product_fields) {
            $products = GFCommon::get_product_fields($Form, $lead);
            if (!empty($products["products"])) {
                ?>
                        <tr>
                            <td colspan="2" class="entry-view-field-name"><?php 
                echo apply_filters("gform_order_label_{$Form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $Form["id"]), $Form["id"]);
                ?>
</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="entry-view-field-value lastrow">
                                <table class="entry-products" cellspacing="0" width="97%">
                                    <colgroup>
                                          <col class="entry-products-col1">
                                          <col class="entry-products-col2">
                                          <col class="entry-products-col3">
                                          <col class="entry-products-col4">
                                    </colgroup>
                                    <thead>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_{$Form['id']}", apply_filters("gform_product", __("Product", "gravityforms"), $Form['id']), $Form['id']);
                ?>
</th>
                                        <th scope="col" class="textcenter"><?php 
                echo apply_filters("gform_product_qty_{$Form['id']}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $Form['id']), $Form['id']);
                ?>
</th>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_unitprice_{$Form['id']}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $Form['id']), $Form['id']);
                ?>
</th>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_price_{$Form['id']}", apply_filters("gform_product_price", __("Price", "gravityforms"), $Form['id']), $Form['id']);
                ?>
</th>
                                    </thead>
                                    <tbody>
                                    <?php 
                $total = 0;
                foreach ($products["products"] as $product) {
                    ?>
                                            <tr>
                                                <td>
                                                    <div class="product_name"><?php 
                    echo esc_html($product["name"]);
                    ?>
</div>
                                                    <ul class="product_options">
                                                        <?php 
                    $price = GFCommon::to_number($product["price"]);
                    if (is_array(rgar($product, "options"))) {
                        $count = sizeof($product["options"]);
                        $index = 1;
                        foreach ($product["options"] as $option) {
                            $price += GFCommon::to_number($option["price"]);
                            $class = $index == $count ? " class='lastitem'" : "";
                            $index++;
                            ?>
                                                                <li<?php 
                            echo $class;
                            ?>
><?php 
                            echo $option["option_label"];
                            ?>
</li>
                                                                <?php 
                        }
                    }
                    $subtotal = floatval($product["quantity"]) * $price;
                    $total += $subtotal;
                    ?>
                                                    </ul>
                                                </td>
                                                <td class="textcenter"><?php 
                    echo $product["quantity"];
                    ?>
</td>
                                                <td><?php 
                    echo GFCommon::to_money($price, $lead["currency"]);
                    ?>
</td>
                                                <td><?php 
                    echo GFCommon::to_money($subtotal, $lead["currency"]);
                    ?>
</td>
                                            </tr>
                                            <?php 
                }
                $total += floatval($products["shipping"]["price"]);
                ?>
                                    </tbody>
                                    <tfoot>
                                        <?php 
                if (!empty($products["shipping"]["name"])) {
                    ?>
                                            <tr>
                                                <td colspan="2" rowspan="2" class="emptycell">&nbsp;</td>
                                                <td class="textright shipping"><?php 
                    echo $products["shipping"]["name"];
                    ?>
</td>
                                                <td class="shipping_amount"><?php 
                    echo GFCommon::to_money($products["shipping"]["price"], $lead["currency"]);
                    ?>
&nbsp;</td>
                                            </tr>
                                        <?php 
                }
                ?>
                                        <tr>
                                            <?php 
                if (empty($products["shipping"]["name"])) {
                    ?>
                                                <td colspan="2" class="emptycell">&nbsp;</td>
                                            <?php 
                }
                ?>
                                            <td class="textright grandtotal"><?php 
                esc_html_e("Total", "gravityforms");
                ?>
</td>
                                            <td class="grandtotal_amount"><?php 
                echo GFCommon::to_money($total, $lead["currency"]);
                ?>
</td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </td>
                        </tr>

                        <?php 
            }
        }
        // Edit link
        if (!empty($options['useredit']) && is_user_logged_in() && intval($current_user->ID) === intval($lead['created_by']) || !empty($options['adminedit']) && self::has_access("gravityforms_directory")) {
            if (!empty($options['adminedit']) && self::has_access("gravityforms_directory")) {
                $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_admin', __("Edit Entry", 'gravity-forms-addons'));
            } else {
                $editbuttontext = apply_filters('kws_gf_directory_edit_entry_text_user', __("Edit Your Entry", 'gravity-forms-addons'));
            }
            ?>
						<tr>
							<th scope="row" class="entry-view-field-name"><?php 
            echo esc_html(apply_filters('kws_gf_directory_edit_entry_th', __("Edit", "gravity-forms-addons")));
            ?>
</th>
							<td class="entry-view-field-value useredit"><a href="<?php 
            echo add_query_arg(array('edit' => wp_create_nonce('edit' . $lead['id'] . $Form["id"])));
            ?>
"><?php 
            echo $editbuttontext;
            ?>
</a></td>
						</tr>
					<?php 
        }
        ?>
				</tbody>
			</table>
			<?php 
    }
 public function sanitize_settings()
 {
     parent::sanitize_settings();
     $price_number = GFCommon::to_number($this->basePrice);
     $this->basePrice = GFCommon::to_money($price_number);
 }
Beispiel #9
0
 /**
  * Replace merge tags
  *
  * @param string $text
  * @param array $form
  * @param array $entry
  * @param boolean $url_encode
  * @param boolean $esc_html
  * @param boolean $nl2br
  * @param string $format
  */
 public function replace_merge_tags($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format)
 {
     $search = array('{payment_status}', '{payment_date}', '{transaction_id}', '{payment_amount}');
     $replace = array(rgar($entry, 'payment_status'), rgar($entry, 'payment_date'), rgar($entry, 'transaction_id'), GFCommon::to_money(rgar($entry, 'payment_amount'), rgar($entry, 'currency')));
     if ($url_encode) {
         foreach ($replace as &$value) {
             $value = urlencode($value);
         }
     }
     $text = str_replace($search, $replace, $text);
     return $text;
 }
Beispiel #10
0
    /**
     * @param $lead
     * @param $form
     * @return mixed
     */
    public static function payment_details_box($lead, $form)
    {
        ?>
        <!-- PAYMENT BOX -->
        <div id="submitdiv" class="stuffbox">
            <h3>
                <span
                    class="hndle"><?php 
        echo $lead["transaction_type"] == 2 ? __("Subscription Details", "gravityforms") : __("Payment Details", "gravityforms");
        ?>
</span>
            </h3>

            <div class="inside">
                <div id="submitcomment" class="submitbox">
                    <div id="minor-publishing" style="padding:10px;">
                        <br/>
                        <?php 
        if (!empty($lead["payment_status"])) {
            echo __("Status", "gravityforms");
            ?>
: <span
                                id="gform_payment_status"><?php 
            echo apply_filters("gform_payment_status", $lead["payment_status"], $form, $lead);
            ?>
</span>
                            <br/><br/>
                            <?php 
            if (!empty($lead["payment_date"])) {
                echo $lead["transaction_type"] == 2 ? __("Start Date", "gravityforms") : __("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 ? __("Subscription Id", "gravityforms") : __("Transaction Id", "gravityforms");
                ?>
: <?php 
                echo $lead["transaction_id"];
                ?>
                                <br/><br/>
                            <?php 
            }
            if (!rgblank($lead["payment_amount"])) {
                echo $lead["transaction_type"] == 2 ? __("Recurring Amount", "gravityforms") : __("Amount", "gravityforms");
                ?>
: <?php 
                echo GFCommon::to_money($lead["payment_amount"], $lead["currency"]);
                ?>
                                <br/><br/>
                            <?php 
            }
        }
        do_action("gform_payment_details", $form["id"], $lead);
        ?>
                    </div>
                </div>
            </div>
        </div>
        <?php 
    }
Beispiel #11
0
 public static function set_payment_status($config, $entry, $status, $transaction_type, $transaction_id, $parent_transaction_id, $subscriber_id, $amount, $pending_reason, $reason)
 {
     global $current_user;
     $user_id = 0;
     $user_name = "System";
     if ($current_user && ($user_data = get_userdata($current_user->ID))) {
         $user_id = $current_user->ID;
         $user_name = $user_data->display_name;
     }
     self::$log->LogDebug("Payment status: {$status} - Transaction Type: {$transaction_type} - Transaction ID: {$transaction_id} - Parent Transaction: {$parent_transaction_id} - Subscriber ID: {$subscriber_id} - Amount: {$amount} - Pending reason: {$pending_reason} - Reason: {$reason}");
     self::$log->LogDebug("Entry: " . print_r($entry, true));
     switch (strtolower($transaction_type)) {
         case "subscr_payment":
             if ($entry["payment_status"] != "Active") {
                 self::$log->LogDebug("Starting subscription");
                 self::start_subscription($entry, $subscriber_id, $amount, $user_id, $user_name);
             } else {
                 self::$log->LogDebug("Payment status is already active, so simply adding a Note");
                 RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription payment has been made. Amount: %s. Transaction Id: %s", "gravityforms"), GFCommon::to_money($amount, $entry["currency"]), $transaction_id));
             }
             self::$log->LogDebug("Inserting payment transaction");
             GFPayPalData::insert_transaction($entry["id"], "payment", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
             break;
         case "subscr_signup":
             $trial_amount = GFCommon::to_number($config["meta"]["trial_amount"]);
             //Starting subscription if there is a free trial period. Otherwise, subscription will be started when payment is received (i.e. sbscr_payment)
             if ($entry["payment_status"] != "Active" && $config["meta"]["trial_period_enabled"] && empty($trial_amount)) {
                 self::$log->LogDebug("Starting subscription");
                 self::start_subscription($entry, $subscriber_id, $amount, $user_id, $user_name);
             }
             break;
         case "subscr_cancel":
             if ($entry["payment_status"] != "Cancelled") {
                 $entry["payment_status"] = "Cancelled";
                 self::$log->LogDebug("Cancelling subscription");
                 RGFormsModel::update_lead($entry);
                 RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription has been cancelled. Subscriber Id: %s", "gravityforms"), $subscriber_id));
                 if ($config["meta"]["update_post_action"] == "draft" && !empty($entry["post_id"])) {
                     $post = get_post($entry["post_id"]);
                     $post->post_status = 'draft';
                     wp_update_post($post);
                     self::$log->LogDebug("Marking associated post as a Draft");
                 }
                 if ($config["meta"]["update_post_action"] == "delete" && !empty($entry["post_id"])) {
                     wp_delete_post($entry["post_id"]);
                     self::$log->LogDebug("Deleting associated post");
                 }
                 do_action("gform_subscription_canceled", $entry, $config, $transaction_id);
             }
             break;
         case "subscr_eot":
             if ($entry["payment_status"] != "Expired") {
                 $entry["payment_status"] = "Expired";
                 self::$log->LogDebug("Setting entry as expired");
                 RGFormsModel::update_lead($entry);
                 RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription has expired. Subscriber Id: %s", "gravityforms"), $subscriber_id));
             }
             break;
         case "subscr_failed":
             if ($entry["payment_status"] != "Failed") {
                 $entry["payment_status"] = "Failed";
                 self::$log->LogDebug("Marking entry as Failed");
                 RGFormsModel::update_lead($entry);
                 RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Subscription signup has failed. Subscriber Id: %s", "gravityforms"), $subscriber_id));
             }
             break;
         default:
             //handles products and donation
             switch (strtolower($status)) {
                 case "completed":
                     self::$log->LogDebug("Processing a completed payment");
                     if ($entry["payment_status"] != "Approved") {
                         self::$log->LogDebug("Entry is not already approved. Proceeding...");
                         $entry["payment_status"] = "Approved";
                         $entry["payment_amount"] = $amount;
                         $entry["payment_date"] = gmdate("y-m-d H:i:s");
                         $entry["transaction_id"] = $transaction_id;
                         $entry["transaction_type"] = 1;
                         //payment
                         if (!$entry["is_fulfilled"]) {
                             self::$log->LogDebug("Payment has been made. Fulfilling order.");
                             self::fulfill_order($entry, $transaction_id, $amount);
                             self::$log->LogDebug("Order has been fulfilled");
                             $entry["is_fulfilled"] = true;
                         }
                         self::$log->LogDebug("Updating entry.");
                         RGFormsModel::update_lead($entry);
                         self::$log->LogDebug("Adding note.");
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has been approved. Amount: %s. Transaction Id: %s", "gravityforms"), GFCommon::to_money($entry["payment_amount"], $entry["currency"]), $transaction_id));
                     }
                     self::$log->LogDebug("Inserting transaction.");
                     GFPayPalData::insert_transaction($entry["id"], "payment", "", $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "reversed":
                     self::$log->LogDebug("Processing reversal.");
                     if ($entry["payment_status"] != "Reversed") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Reversed";
                             self::$log->LogDebug("Setting entry as Reversed");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has been reversed. Transaction Id: %s. Reason: %s", "gravityforms"), $transaction_id, self::get_reason($reason)));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "reversal", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "canceled_reversal":
                     self::$log->LogDebug("Processing a reversal cancellation");
                     if ($entry["payment_status"] != "Approved") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Approved";
                             self::$log->LogDebug("Setting entry as approved");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment reversal has been canceled and the funds have been transferred to your account. Transaction Id: %s", "gravityforms"), $entry["transaction_id"]));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "reinstated", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "denied":
                     self::$log->LogDebug("Processing a Denied request.");
                     if ($entry["payment_status"] != "Denied") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Denied";
                             self::$log->LogDebug("Setting entry as Denied.");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has been denied. Transaction Id: %s", "gravityforms"), $transaction_id));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "denied", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "pending":
                     self::$log->LogDebug("Processing a pending transaction.");
                     if ($entry["payment_status"] != "Pending") {
                         if ($entry["transaction_type"] != 2) {
                             $entry["payment_status"] = "Pending";
                             $entry["payment_amount"] = $amount;
                             $entry["transaction_type"] = 1;
                             //payment
                             self::$log->LogDebug("Setting entry as Pending.");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment is pending. Amount: %s. Transaction Id: %s. Reason: %s", "gravityforms"), GFCommon::to_money($amount, $entry["currency"]), $transaction_id, self::get_pending_reason($pending_reason)));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "pending", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "refunded":
                     self::$log->LogDebug("Processing a Refund request.");
                     if ($entry["payment_status"] != "Refunded") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Refunded";
                             self::$log->LogDebug("Setting entry as Refunded.");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has been refunded. Refunded amount: %s. Transaction Id: %s", "gravityforms"), $amount, $transaction_id));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "refund", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "voided":
                     self::$log->LogDebug("Processing a Voided request.");
                     if ($entry["payment_status"] != "Voided") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Voided";
                             self::$log->LogDebug("Setting entry as Voided.");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Authorization has been voided. Transaction Id: %s", "gravityforms"), $transaction_id));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "void", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "processed":
                     self::$log->LogDebug("Processing a 'processed' request.");
                     if ($entry["transaction_type"] != 2) {
                         $entry["payment_status"] = "Pending";
                         self::$log->LogDebug("Setting entry as Pending.");
                         RGFormsModel::update_lead($entry);
                         $entry["transaction_type"] = 1;
                         //payment
                     }
                     RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has been authorized. You can capture funds from your PayPal control panel. Transaction Id: %s", "gravityforms"), $transaction_id));
                     GFPayPalData::insert_transaction($entry["id"], "processed", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
                 case "failed":
                     self::$log->LogDebug("Processed a Failed request.");
                     if ($entry["payment_status"] != "Failed") {
                         if ($entry["transaction_type"] == 1) {
                             $entry["payment_status"] = "Failed";
                             self::$log->LogDebug("Setting entry as Failed.");
                             RGFormsModel::update_lead($entry);
                         }
                         RGFormsModel::add_note($entry["id"], $user_id, $user_name, sprintf(__("Payment has Failed. Failed payments occur when they are made via your customer's bank account and could not be completed. Transaction Id: %s", "gravityforms"), $transaction_id));
                     }
                     GFPayPalData::insert_transaction($entry["id"], "failed", $subscriber_id, $transaction_id, $parent_transaction_id, $amount);
                     break;
             }
             break;
     }
     self::$log->LogDebug("Before gform_post_payment_status.");
     do_action("gform_post_payment_status", $config, $entry, $status, $transaction_id, $subscriber_id, $amount, $pending_reason, $reason);
 }
 public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format)
 {
     $format_numeric = $modifier == 'price';
     $value = $format_numeric ? GFCommon::to_number($value) : GFCommon::to_money($value);
     return GFCommon::format_variable_value($value, $url_encode, $esc_html, $format);
 }
 public function authorize($feed, $submission_data, $form, $entry)
 {
     $this->populateCreditCardLastFour($form);
     $this->includeSecureSubmitSDK();
     if ($this->getSecureSubmitJsError()) {
         return $this->authorization_error($this->getSecureSubmitJsError());
     }
     $isAuth = $this->getAuthorizeOrCharge($feed) == 'authorize';
     $config = new HpsServicesConfig();
     $config->secretApiKey = $this->getSecretApiKey($feed);
     $config->developerId = '002914';
     $config->versionNumber = '1916';
     $service = new HpsCreditService($config);
     $cardHolder = $this->buildCardHolder($feed, $submission_data, $entry);
     try {
         $response = $this->getSecureSubmitJsResponse();
         $token = new HpsTokenData();
         $token->tokenValue = $response != null ? $response->token_value : '';
         $transaction = null;
         if ($isAuth) {
             $transaction = $service->authorize($submission_data['payment_amount'], GFCommon::get_currency(), $token, $cardHolder);
         } else {
             $transaction = $service->charge($submission_data['payment_amount'], GFCommon::get_currency(), $token, $cardHolder);
         }
         self::get_instance()->transaction_response = $transaction;
         if ($this->getSendEmail() == 'yes') {
             $this->sendEmail($form, $entry, $transaction, $cardHolder);
         }
         $type = $isAuth ? 'Authorization' : 'Payment';
         $amount_formatted = GFCommon::to_money($submission_data['payment_amount'], GFCommon::get_currency());
         $note = sprintf(__('%s has been completed. Amount: %s. Transaction Id: %s.', 'gravityforms-securesubmit'), $type, $amount_formatted, $transaction->transactionId);
         if ($isAuth) {
             $note .= sprintf(__(' Authorization Code: %s', 'gravityforms-securesubmit'), $transaction->authorizationCode);
         }
         $auth = array('is_authorized' => true, 'captured_payment' => array('is_success' => true, 'transaction_id' => $transaction->transactionId, 'amount' => $submission_data['payment_amount'], 'payment_method' => $response->card_type, 'securesubmit_payment_action' => $this->getAuthorizeOrCharge($feed), 'note' => $note));
     } catch (HpsException $e) {
         $auth = $this->authorization_error($e->getMessage());
     }
     return $auth;
 }
Beispiel #14
0
    public static function leads_page($form_id)
    {
        global $wpdb;
        //quit if version of wp is not supported
        if (!GFCommon::ensure_wp_version()) {
            return;
        }
        echo GFCommon::get_remote_message();
        $action = RGForms::post("action");
        switch ($action) {
            case "delete":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $lead_id = $_POST["action_argument"];
                RGFormsModel::delete_lead($lead_id);
                break;
            case "bulk":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $bulk_action = !empty($_POST["bulk_action"]) ? $_POST["bulk_action"] : $_POST["bulk_action2"];
                $leads = $_POST["lead"];
                switch ($bulk_action) {
                    case "delete":
                        RGFormsModel::delete_leads($leads);
                        break;
                    case "mark_read":
                        RGFormsModel::update_leads_property($leads, "is_read", 1);
                        break;
                    case "mark_unread":
                        RGFormsModel::update_leads_property($leads, "is_read", 0);
                        break;
                    case "add_star":
                        RGFormsModel::update_leads_property($leads, "is_starred", 1);
                        break;
                    case "remove_star":
                        RGFormsModel::update_leads_property($leads, "is_starred", 0);
                        break;
                }
                break;
            case "change_columns":
                check_admin_referer('gforms_entry_list', 'gforms_entry_list');
                $columns = GFCommon::json_decode(stripslashes($_POST["grid_columns"]), true);
                RGFormsModel::update_grid_column_meta($form_id, $columns);
                break;
        }
        $sort_field = empty($_GET["sort"]) ? 0 : $_GET["sort"];
        $sort_direction = empty($_GET["dir"]) ? "DESC" : $_GET["dir"];
        $search = RGForms::get("s");
        $page_index = empty($_GET["paged"]) ? 0 : intval($_GET["paged"]) - 1;
        $star = is_numeric(RGForms::get("star")) ? intval(RGForms::get("star")) : null;
        $read = is_numeric(RGForms::get("read")) ? intval(RGForms::get("read")) : null;
        $page_size = 20;
        $first_item_index = $page_index * $page_size;
        $form = RGFormsModel::get_form_meta($form_id);
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta["type"] == "number";
        $leads = RGFormsModel::get_leads($form_id, $sort_field, $sort_direction, $search, $first_item_index, $page_size, $star, $read, $is_numeric);
        $lead_count = RGFormsModel::get_lead_count($form_id, $search, $star, $read);
        $summary = RGFormsModel::get_form_counts($form_id);
        $total_lead_count = $summary["total"];
        $unread_count = $summary["unread"];
        $starred_count = $summary["starred"];
        $columns = RGFormsModel::get_grid_columns($form_id, true);
        $search_qs = empty($search) ? "" : "&s=" . urlencode($search);
        $sort_qs = empty($sort_field) ? "" : "&sort={$sort_field}";
        $dir_qs = empty($sort_field) ? "" : "&dir={$sort_direction}";
        $star_qs = $star !== null ? "&star={$star}" : "";
        $read_qs = $read !== null ? "&read={$read}" : "";
        $page_links = paginate_links(array('base' => admin_url("admin.php") . "?page=gf_entries&view=entries&id={$form_id}&%_%" . $search_qs . $sort_qs . $dir_qs . $star_qs . $read_qs, 'format' => 'paged=%#%', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => ceil($lead_count / $page_size), 'current' => $page_index + 1, 'show_all' => false));
        wp_print_scripts(array("thickbox"));
        wp_print_styles(array("thickbox"));
        ?>

        <script src="<?php 
        echo GFCommon::get_base_url();
        ?>
/js/jquery.json-1.3.js?ver=<?php 
        echo GFCommon::$version;
        ?>
"></script>

        <script>
            function ChangeColumns(columns){
                jQuery("#action").val("change_columns");
                jQuery("#grid_columns").val(jQuery.toJSON(columns));
                tb_remove();
                jQuery("#lead_form")[0].submit();
            }

            function Search(sort_field_id, sort_direction, form_id, search, star, read){
                var search_qs = search == "" ? "" : "&s=" + search;
                var star_qs = star == "" ? "" : "&star=" + star;
                var read_qs = read == "" ? "" : "&read=" + read;

                var location = "?page=gf_entries&view=entries&id=" + form_id + "&sort=" + sort_field_id + "&dir=" + sort_direction + search_qs + star_qs + read_qs;
                document.location = location;
            }

            function ToggleStar(img, lead_id){
                var is_starred = img.src.indexOf("star1.png") >=0
                if(is_starred)
                    img.src = img.src.replace("star1.png", "star0.png");
                else
                    img.src = img.src.replace("star0.png", "star1.png");

                UpdateCount("star_count", is_starred ? -1 : 1);

                UpdateLeadProperty(lead_id, "is_starred", is_starred ? 0 : 1);
            }

            function ToggleRead(lead_id){
                var title = jQuery("#lead_row_" + lead_id);

                marking_read = title.hasClass("lead_unread");

                jQuery("#mark_read_" + lead_id).css("display", marking_read ? "none" : "inline");
                jQuery("#mark_unread_" + lead_id).css("display", marking_read ? "inline" : "none");
                title.toggleClass("lead_unread");

                UpdateCount("unread_count", marking_read ? -1 : 1);

                UpdateLeadProperty(lead_id, "is_read", marking_read ? 1 : 0);
            }

            function UpdateLeadProperty(lead_id, name, value){
                var mysack = new sack("<?php 
        echo admin_url("admin-ajax.php");
        ?>
" );
                mysack.execute = 1;
                mysack.method = 'POST';
                mysack.setVar( "action", "rg_update_lead_property" );
                mysack.setVar( "rg_update_lead_property", "<?php 
        echo wp_create_nonce("rg_update_lead_property");
        ?>
" );
                mysack.setVar( "lead_id", lead_id);
                mysack.setVar( "name", name);
                mysack.setVar( "value", value);
                mysack.encVar( "cookie", document.cookie, false );
                mysack.onError = function() { alert('<?php 
        echo esc_js(__("Ajax error while setting lead property", "gravityforms"));
        ?>
' )};
                mysack.runAJAX();

                return true;
            }

            function UpdateCount(element_id, change){
                var element = jQuery("#" + element_id);
                var count = parseInt(element.html()) + change
                element.html(count + "");
            }

            function DeleteLead(lead_id){
                jQuery("#action").val("delete");
                jQuery("#action_argument").val(lead_id);
                jQuery("#lead_form")[0].submit();
                return true;
            }



            jQuery(document).ready(function(){
                jQuery("#lead_search").keyup(function(event){
                  if(event.keyCode == 13)
                    Search('<?php 
        echo $sort_field;
        ?>
', '<?php 
        echo $sort_direction;
        ?>
', <?php 
        echo $form_id;
        ?>
, this.value, '<?php 
        echo $star;
        ?>
', '<?php 
        echo $read;
        ?>
');
                });

            });

        </script>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css" type="text/css" />
        <style>
            .lead_unread a, .lead_unread td{font-weight: bold;}
            .row-actions a{ font-weight:normal;}
            .entry_nowrap{
                overflow:hidden; white-space:nowrap;
            }
        </style>


        <div class="wrap">
            <img alt="<?php 
        _e("Gravity Forms", "gravityforms");
        ?>
" src="<?php 
        echo GFCommon::get_base_url();
        ?>
/images/gravity-entry-icon-32.png" style="float:left; margin:15px 7px 0 0;"/>
            <h2><?php 
        _e("Entries", "gravityforms");
        ?>
 : <?php 
        echo $form["title"];
        ?>
 </h2>

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

            <form id="lead_form" method="post">
                <?php 
        wp_nonce_field('gforms_entry_list', 'gforms_entry_list');
        ?>

                <input type="hidden" value="" name="grid_columns" id="grid_columns" />
                <input type="hidden" value="" name="action" id="action" />
                <input type="hidden" value="" name="action_argument" id="action_argument" />

                <ul class="subsubsub">
                    <li><a class="<?php 
        echo $star === null && $read === null ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
"><?php 
        _e("All", "gravityforms");
        ?>
 <span class="count">(<span id="all_count"><?php 
        echo $total_lead_count;
        ?>
</span>)</span></a> | </li>
                    <li><a class="<?php 
        echo $read !== null ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
&read=0"><?php 
        _e("Unread", "gravityforms");
        ?>
 <span class="count">(<span id="unread_count"><?php 
        echo $unread_count;
        ?>
</span>)</span></a> | </li>
                    <li><a class="<?php 
        echo $star !== null ? "current" : "";
        ?>
" href="?page=gf_entries&view=entries&id=<?php 
        echo $form_id;
        ?>
&star=1"><?php 
        _e("Starred", "gravityforms");
        ?>
 <span class="count">(<span id="star_count"><?php 
        echo $starred_count;
        ?>
</span>)</span></a></li>
                </ul>
                <p class="search-box">
                    <label class="hidden" for="lead_search"><?php 
        _e("Search Entries:", "gravityforms");
        ?>
</label>
                    <input type="text" id="lead_search" value="<?php 
        echo $search;
        ?>
"><a class="button" id="lead_search_button" href="javascript:Search('<?php 
        echo $sort_field;
        ?>
', '<?php 
        echo $sort_direction;
        ?>
', <?php 
        echo $form_id;
        ?>
, jQuery('#lead_search').val(), '<?php 
        echo $star;
        ?>
', '<?php 
        echo $read;
        ?>
');"><?php 
        _e("Search", "gravityforms");
        ?>
</a>
                </p>
                <div class="tablenav">

                    <div class="alignleft actions" style="padding:8px 0 7px 0;">
                        <label class="hidden" for="bulk_action"> <?php 
        _e("Bulk action", "gravityforms");
        ?>
</label>
                        <select name="bulk_action" id="bulk_action">
                            <option value=''><?php 
        _e(" Bulk action ", "gravityforms");
        ?>
</option>

                            <?php 
        if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
            ?>
                            <option value='delete'><?php 
            _e("Delete", "gravityforms");
            ?>
</option>
                            <?php 
        }
        ?>

                            <option value='mark_read'><?php 
        _e("Mark as Read", "gravityforms");
        ?>
</option>
                            <option value='mark_unread'><?php 
        _e("Mark as Unread", "gravityforms");
        ?>
</option>
                            <option value='add_star'><?php 
        _e("Add Star", "gravityforms");
        ?>
</option>
                            <option value='remove_star'><?php 
        _e("Remove Star", "gravityforms");
        ?>
</option>
                        </select>
                        <?php 
        $apply_button = '<input type="submit" class="button" value="' . __("Apply", "gravityforms") . '" onclick="jQuery(\'#action\').val(\'bulk\');" />';
        echo apply_filters("gform_entry_apply_button", $apply_button);
        ?>

                    </div>

                    <?php 
        //Displaying paging links if appropriate
        if ($page_links) {
            ?>
                        <div class="tablenav-pages">
                            <span class="displaying-num"><?php 
            printf(__("Displaying %d - %d of %d", "gravityforms"), $first_item_index + 1, $first_item_index + $page_size > $lead_count ? $lead_count : $first_item_index + $page_size, $lead_count);
            ?>
</span>
                            <?php 
            echo $page_links;
            ?>
                        </div>
                        <?php 
        }
        ?>
                    <div class="clear"></div>
                </div>

                <table class="widefat fixed" cellspacing="0">
                <thead>
                    <tr>
                        <th scope="col" id="cb" class="manage-column column-cb check-column" style="vertical-align:middle;"><input type="checkbox" class="headercb" /></th>
                        <th scope="col" class="manage-column column-cb check-column" >&nbsp;</th>
                        <?php 
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? "DESC" : "ASC";
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
            }
            ?>
                            <th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo $field_id;
            ?>
', '<?php 
            echo $dir;
            ?>
', <?php 
            echo $form_id;
            ?>
, '<?php 
            echo $search;
            ?>
', '<?php 
            echo $star;
            ?>
', '<?php 
            echo $read;
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info["label"]);
            ?>
</th>
                            <?php 
        }
        ?>
                        <th scope="col" align="right" width="50">
                            <a title="<?php 
        _e("Select Columns", "gravityforms");
        ?>
" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/select_columns.php?id=<?php 
        echo $form_id;
        ?>
&TB_iframe=true&height=365&width=600" class="thickbox entries_edit_icon">Edit</a>
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
                        <th scope="col" id="cb" class="manage-column column-cb check-column" >&nbsp;</th>
                        <?php 
        foreach ($columns as $field_id => $field_info) {
            $dir = $field_id == 0 ? "DESC" : "ASC";
            //default every field so ascending sorting except date_created (id=0)
            if ($field_id == $sort_field) {
                //reverting direction if clicking on the currently sorted field
                $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
            }
            ?>
                            <th scope="col" class="manage-column entry_nowrap" onclick="Search('<?php 
            echo $field_id;
            ?>
', '<?php 
            echo $dir;
            ?>
', <?php 
            echo $form_id;
            ?>
, '<?php 
            echo $search;
            ?>
', '<?php 
            echo $star;
            ?>
', '<?php 
            echo $read;
            ?>
');" style="cursor:pointer;"><?php 
            echo esc_html($field_info["label"]);
            ?>
</th>
                            <?php 
        }
        ?>
                        <th scope="col" style="width:15px;">
                            <a href="<?php 
        echo GFCommon::get_base_url();
        ?>
/select_columns.php?id=<?php 
        echo $form_id;
        ?>
&TB_iframe=true&height=350&width=500" class="thickbox entries_edit_icon">Edit</a>
                        </th>
                    </tr>
                </tfoot>

                <tbody class="list:user user-list">
                    <?php 
        if (sizeof($leads) > 0) {
            $field_ids = array_keys($columns);
            foreach ($leads as $lead) {
                ?>
                            <tr id="lead_row_<?php 
                echo $lead["id"];
                ?>
" class='author-self status-inherit <?php 
                echo $lead["is_read"] ? "" : "lead_unread";
                ?>
' valign="top">
                                <th scope="row" class="check-column">
                                    <input type="checkbox" name="lead[]" value="<?php 
                echo $lead["id"];
                ?>
" />
                                </th>
                                <td >
                                    <img src="<?php 
                echo GFCommon::get_base_url();
                ?>
/images/star<?php 
                echo intval($lead["is_starred"]);
                ?>
.png" onclick="ToggleStar(this, <?php 
                echo $lead["id"];
                ?>
);" />
                                </td>
                                <?php 
                $is_first_column = true;
                $nowrap_class = "entry_nowrap";
                foreach ($field_ids as $field_id) {
                    $value = RGForms::get($field_id, $lead);
                    //filtering lead value
                    $value = apply_filters("gform_get_field_value", $value, $lead, RGFormsModel::get_field($form, $field_id));
                    $input_type = !empty($columns[$field_id]["inputType"]) ? $columns[$field_id]["inputType"] : $columns[$field_id]["type"];
                    switch ($input_type) {
                        case "checkbox":
                            $value = "";
                            //looping through lead detail values trying to find an item identical to the column label. Mark with a tick if found.
                            $lead_field_keys = array_keys($lead);
                            foreach ($lead_field_keys as $input_id) {
                                //mark as a tick if input label (from form meta) is equal to submitted value (from lead)
                                if (is_numeric($input_id) && absint($input_id) == absint($field_id)) {
                                    if ($lead[$input_id] == $columns[$field_id]["label"]) {
                                        $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                    } else {
                                        $field = RGFormsModel::get_field($form, $field_id);
                                        if ($field["enableChoiceValue"] || $field["enablePrice"]) {
                                            foreach ($field["choices"] as $choice) {
                                                if ($choice["value"] == $lead[$field_id]) {
                                                    $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                                    break;
                                                } else {
                                                    if ($field["enablePrice"]) {
                                                        list($val, $price) = explode("|", $lead[$field_id]);
                                                        if ($val == $choice["value"]) {
                                                            $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case "post_image":
                            list($url, $title, $caption, $description) = explode("|:|", $value);
                            if (!empty($url)) {
                                //displaying thumbnail (if file is an image) or an icon based on the extension
                                $thumb = self::get_icon_url($url);
                                $value = "<a href='" . esc_attr($url) . "' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$thumb}'/></a>";
                            }
                            break;
                        case "post_category":
                            $ary = explode(":", $value);
                            $cat_name = count($ary) > 0 ? $ary[0] : "";
                            $value = $cat_name;
                            break;
                        case "fileupload":
                            $file_path = $value;
                            if (!empty($file_path)) {
                                //displaying thumbnail (if file is an image) or an icon based on the extension
                                $thumb = self::get_icon_url($file_path);
                                $file_path = esc_attr($file_path);
                                $value = "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$thumb}'/></a>";
                            }
                            break;
                        case "source_url":
                            $value = "<a href='" . esc_attr($lead["source_url"]) . "' target='_blank' alt='" . esc_attr($lead["source_url"]) . "' title='" . esc_attr($lead["source_url"]) . "'>.../" . esc_attr(GFCommon::truncate_url($lead["source_url"])) . "</a>";
                            break;
                        case "textarea":
                        case "post_content":
                        case "post_excerpt":
                            $value = esc_html($value);
                            break;
                        case "date_created":
                        case "payment_date":
                            $value = GFCommon::format_date($value, false);
                            break;
                        case "date":
                            $field = RGFormsModel::get_field($form, $field_id);
                            $value = GFCommon::date_display($value, $field["dateFormat"]);
                            break;
                        case "radio":
                        case "select":
                            $field = RGFormsModel::get_field($form, $field_id);
                            $value = GFCommon::selection_display($value, $field, $lead["currency"]);
                            break;
                        case "total":
                        case "payment_amount":
                            $value = GFCommon::to_money($value, $lead["currency"]);
                            break;
                        case "created_by":
                            if (!empty($value)) {
                                $userdata = get_userdata($value);
                                $value = $userdata->user_login;
                            }
                            break;
                        default:
                            $value = esc_html($value);
                    }
                    $value = apply_filters("gform_entries_field_value", $value, $form_id, $field_id, $lead);
                    $query_string = "gf_entries&view=entry&id={$form_id}&lid={$lead["id"]}{$search_qs}{$sort_qs}{$dir_qs}&paged=" . $page_index + 1;
                    if ($is_first_column) {
                        ?>
                                        <td class="column-title" >
                                            <a href="admin.php?page=gf_entries&view=entry&id=<?php 
                        echo $form_id;
                        ?>
&lid=<?php 
                        echo $lead["id"] . $search_qs . $sort_qs . $dir_qs;
                        ?>
&paged=<?php 
                        echo $page_index + 1;
                        ?>
"><?php 
                        echo $value;
                        ?>
</a>
                                            <div class="row-actions">
                                                <span class="edit">
                                                    <a title="<?php 
                        _e("View this entry", "gravityforms");
                        ?>
" href="admin.php?page=gf_entries&view=entry&id=<?php 
                        echo $form_id;
                        ?>
&lid=<?php 
                        echo $lead["id"] . $search_qs . $sort_qs . $dir_qs;
                        ?>
&paged=<?php 
                        echo $page_index + 1;
                        ?>
"><?php 
                        _e("View", "gravityforms");
                        ?>
</a>
                                                    |
                                                </span>
                                                <span class="edit">
                                                    <a id="mark_read_<?php 
                        echo $lead["id"];
                        ?>
" title="Mark this entry as read" href="javascript:ToggleRead(<?php 
                        echo $lead["id"];
                        ?>
);" style="display:<?php 
                        echo $lead["is_read"] ? "none" : "inline";
                        ?>
;"><?php 
                        _e("Mark read", "gravityforms");
                        ?>
</a><a id="mark_unread_<?php 
                        echo $lead["id"];
                        ?>
" title="<?php 
                        _e("Mark this entry as unread", "gravityforms");
                        ?>
" href="javascript:ToggleRead(<?php 
                        echo $lead["id"];
                        ?>
);" style="display:<?php 
                        echo $lead["is_read"] ? "inline" : "none";
                        ?>
;"><?php 
                        _e("Mark unread", "gravityforms");
                        ?>
</a>
                                                    <?php 
                        echo GFCommon::current_user_can_any("gravityforms_delete_entries") ? "|" : "";
                        ?>
                                                </span>

                                                <?php 
                        if (GFCommon::current_user_can_any("gravityforms_delete_entries")) {
                            ?>
                                                    <span class="edit">
                                                        <?php 
                            $delete_link = '<a title="' . __("Delete this entry", "gravityforms") . '"  href="javascript:if ( confirm(' . __("'You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.'", "gravityforms") . ') ) { DeleteLead(' . $lead["id"] . ')};">' . __("Delete", "gravityforms") . '</a>';
                            echo apply_filters("gform_delete_entry_link", $delete_link);
                            ?>
                                                    </span>
                                                    <?php 
                        }
                        do_action("gform_entries_first_column_actions", $form_id, $field_id, $value, $lead, $query_string);
                        ?>

                                            </div>
                                            <?php 
                        do_action("gform_entries_first_column", $form_id, $field_id, $value, $lead, $query_string);
                        ?>
                                        </td>
                                        <?php 
                    } else {
                        ?>
                                        <td class="<?php 
                        echo $nowrap_class;
                        ?>
">
                                            <?php 
                        echo $value;
                        ?>
&nbsp;
                                            <?php 
                        do_action("gform_entries_column", $form_id, $field_id, $value, $lead, $query_string);
                        ?>
                                        </td>
                                        <?php 
                    }
                    $is_first_column = false;
                }
                ?>
                                <td>&nbsp;</td>
                            </tr>
                            <?php 
            }
        } else {
            ?>
                        <tr>
                            <td colspan="<?php 
            echo sizeof($columns) + 3;
            ?>
" style="padding:20px;"><?php 
            _e("This form does not have any entries yet.", "gravityforms");
            ?>
</td>
                        </tr>
                        <?php 
        }
        ?>
                </tbody>
                </table>

                <div class="clear"></div>

                <div class="tablenav">

                    <div class="alignleft actions" style="padding:8px 0 7px 0;">
                        <label class="hidden" for="bulk_action2"> <?php 
        _e("Bulk action", "gravityforms");
        ?>
</label>
                        <select name="bulk_action2" id="bulk_action2">
                        <option value=''><?php 
        _e("Bulk action ", "gravityforms");
        ?>
</option>
                            <option value='delete'><?php 
        _e("Delete", "gravityforms");
        ?>
</option>
                            <option value='mark_read'><?php 
        _e("Mark as Read", "gravityforms");
        ?>
</option>
                            <option value='mark_unread'><?php 
        _e("Mark as Unread", "gravityforms");
        ?>
</option>
                            <option value='add_star'><?php 
        _e("Add Star", "gravityforms");
        ?>
</option>
                            <option value='remove_star'><?php 
        _e("Remove Star", "gravityforms");
        ?>
</option>
                        </select>
                        <?php 
        $apply_button = '<input type="submit" class="button" value="' . __("Apply", "gravityforms") . '" onclick="jQuery(\'#action\').val(\'bulk\');" />';
        echo apply_filters("gform_entry_apply_button", $apply_button);
        ?>
                    </div>

                    <?php 
        //Displaying paging links if appropriate
        if ($page_links) {
            ?>
                        <div class="tablenav-pages">
                            <span class="displaying-num"><?php 
            printf(__("Displaying %d - %d of %d", "gravityforms"), $first_item_index + 1, $first_item_index + $page_size > $lead_count ? $lead_count : $first_item_index + $page_size, $lead_count);
            ?>
</span>
                            <?php 
            echo $page_links;
            ?>
                        </div>
                        <?php 
        }
        ?>
                    <div class="clear"></div>
                </div>

            </form>
        </div>
        <?php 
    }
Beispiel #15
0
    public static function meta_box_payment_details($args)
    {
        $entry = $args['entry'];
        $form = $args['form'];
        ?>

		<div id="submitcomment" class="submitbox">
			<div id="minor-publishing">
				<?php 
        $payment_status = apply_filters('gform_payment_status', $entry['payment_status'], $form, $entry);
        if (!empty($payment_status)) {
            ?>
					<div id="gf_payment_status" class="gf_payment_detail">
						<?php 
            esc_html_e('Status', 'gravityforms');
            ?>
:
						<span id="gform_payment_status"><?php 
            echo $payment_status;
            // May contain HTML
            ?>
</span>
					</div>

					<?php 
            /**
             * Allows for modification on the form payment date format
             *
             * @param array $form The Form object to filter through
             * @param array $entry The Lead object to filter through
             */
            $payment_date = apply_filters('gform_payment_date', GFCommon::format_date($entry['payment_date'], false, 'Y/m/d', $entry['transaction_type'] != 2), $form, $entry);
            if (!empty($payment_date)) {
                ?>
						<div id="gf_payment_date" class="gf_payment_detail">
							<?php 
                echo $entry['transaction_type'] == 2 ? esc_html__('Start Date', 'gravityforms') : esc_html__('Date', 'gravityforms');
                ?>
:
							<span id='gform_payment_date'><?php 
                echo $payment_date;
                // May contain HTML
                ?>
</span>
						</div>
						<?php 
            }
            /**
             * Allows filtering through a payment transaction ID
             *
             * @param int   $entry['transaction_id'] The transaction ID that can be modified
             * @param array $form                   The Form object to be filtered when modifying the transaction ID
             * @param array $entry                   The Lead object to be filtered when modifying the transaction ID
             */
            $transaction_id = apply_filters('gform_payment_transaction_id', $entry['transaction_id'], $form, $entry);
            if (!empty($transaction_id)) {
                ?>
						<div id="gf_payment_transaction_id" class="gf_payment_detail">
							<?php 
                echo $entry['transaction_type'] == 2 ? esc_html__('Subscription Id', 'gravityforms') : esc_html__('Transaction Id', 'gravityforms');
                ?>
:
							<span id='gform_payment_transaction_id'><?php 
                echo $transaction_id;
                // May contain HTML
                ?>
</span>
						</div>
						<?php 
            }
            /**
             * Filter through the way the Payment Amount is rendered
             *
             * @param string $entry['payment_amount'] The payment amount taken from the lead object
             * @param string $entry['currency']       The payment currency taken from the lead object
             * @param array  $form                   The Form object to filter through
             * @param array  $entry                   The lead object to filter through
             */
            $payment_amount = apply_filters('gform_payment_amount', GFCommon::to_money($entry['payment_amount'], $entry['currency']), $form, $entry);
            if (!rgblank($payment_amount)) {
                ?>
						<div id="gf_payment_amount" class="gf_payment_detail">
							<?php 
                echo $entry['transaction_type'] == 2 ? esc_html__('Recurring Amount', 'gravityforms') : esc_html__('Amount', 'gravityforms');
                ?>
:
							<span id='gform_payment_amount'><?php 
                echo $payment_amount;
                // May contain HTML
                ?>
</span>
						</div>
						<?php 
            }
        }
        /**
         * Fires after the Form Payment Details (The type of payment, the cost, the ID, etc)
         *
         * @param int   $form['id'] The current Form ID
         * @param array $entry       The current Lead object
         */
        do_action('gform_payment_details', $form['id'], $entry);
        ?>
			</div>
		</div>

		<?php 
    }
 private static function monthly_chart_info($config)
 {
     global $wpdb;
     $tz_offset = self::get_mysql_tz_offset();
     $results = $wpdb->get_results("SELECT date_format(CONVERT_TZ(t.date_created, '+00:00', '" . $tz_offset . "'), '%Y-%m-02') date, sum(t.amount) as amount_sold, sum(is_renewal) as renewals, sum(is_renewal=0) as new_sales\r\n                                            FROM {$wpdb->prefix}rg_lead l\r\n                                            INNER JOIN {$wpdb->prefix}rg_authorizenet_transaction t ON l.id = t.entry_id\r\n                                            WHERE form_id={$config["form_id"]} AND t.transaction_type='payment'\r\n                                            group by date\r\n                                            order by date desc\r\n                                            LIMIT 30");
     $sales_month = 0;
     $revenue_month = 0;
     if (!empty($results)) {
         $data = "[";
         foreach ($results as $result) {
             $timestamp = self::get_graph_timestamp($result->date);
             if (self::matches_current_date("Y-m", $timestamp)) {
                 $sales_month += $result->new_sales;
                 $revenue_month += $result->amount_sold;
             }
             $data .= "[{$timestamp},{$result->amount_sold}],";
             if ($config["meta"]["type"] == "subscription") {
                 $sales_line = " <div class='authorizenet_tooltip_subscription'><span class='authorizenet_tooltip_heading'>" . __("New Subscriptions", "gravityformsauthorizenet") . ": </span><span class='authorizenet_tooltip_value'>" . $result->new_sales . "</span></div><div class='authorizenet_tooltip_subscription'><span class='authorizenet_tooltip_heading'>" . __("Renewals", "gravityformsauthorizenet") . ": </span><span class='authorizenet_tooltip_value'>" . $result->renewals . "</span></div>";
             } else {
                 $sales_line = "<div class='authorizenet_tooltip_sales'><span class='authorizenet_tooltip_heading'>" . __("Orders", "gravityformsauthorizenet") . ": </span><span class='authorizenet_tooltip_value'>" . $result->new_sales . "</span></div>";
             }
             $tooltips .= "\"<div class='authorizenet_tooltip_date'>" . GFCommon::format_date($result->date, false, "F, Y", false) . "</div>{$sales_line}<div class='authorizenet_tooltip_revenue'><span class='authorizenet_tooltip_heading'>" . __("Revenue", "gravityformsauthorizenet") . ": </span><span class='authorizenet_tooltip_value'>" . GFCommon::to_money($result->amount_sold) . "</span></div>\",";
         }
         $data = substr($data, 0, strlen($data) - 1);
         $tooltips = substr($tooltips, 0, strlen($tooltips) - 1);
         $data .= "]";
         $series = "[{data:" . $data . "}]";
         $month_names = self::get_chart_month_names();
         $options = "\r\n                {\r\n                    xaxis: {mode: 'time', monthnames: {$month_names}, timeformat: '%b %y', minTickSize: [1, 'month']},\r\n                    yaxis: {tickFormatter: convertToMoney},\r\n                    bars: {show:true, align:'center', barWidth: (24 * 60 * 60 * 30 * 1000) - 130000000},\r\n                    colors: ['#a3bcd3', '#14568a'],\r\n                    grid: {hoverable: true, clickable: true, tickColor: '#F1F1F1', backgroundColor:'#FFF', borderWidth: 1, borderColor: '#CCC'}\r\n                }";
     }
     switch ($config["meta"]["type"]) {
         case "product":
             $sales_label = __("Orders this Month", "gravityformsauthorizenet");
             break;
         case "donation":
             $sales_label = __("Donations this Month", "gravityformsauthorizenet");
             break;
         case "subscription":
             $sales_label = __("Subscriptions this Month", "gravityformsauthorizenet");
             break;
     }
     $revenue_month = GFCommon::to_money($revenue_month);
     return array("series" => $series, "options" => $options, "tooltips" => "[{$tooltips}]", "revenue_label" => __("Revenue this Month", "gravityformsauthorizenet"), "revenue" => $revenue_month, "sales_label" => $sales_label, "sales" => $sales_month);
 }
Beispiel #17
0
 public static function pdf_get_lead_field_display($field, $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
 {
     if ($field['type'] == 'post_category') {
         $value = GFCommon::prepare_post_category_value($value, $field);
     }
     switch (RGFormsModel::get_input_type($field)) {
         case 'name':
             if (is_array($value)) {
                 $prefix = trim(rgget($field['id'] . '.2', $value));
                 $first = trim(rgget($field['id'] . '.3', $value));
                 $middle = trim(rgget($field['id'] . '.4', $value));
                 $last = trim(rgget($field['id'] . '.6', $value));
                 $suffix = trim(rgget($field['id'] . '.8', $value));
                 $name = $prefix;
                 $name .= !empty($name) && !empty($first) ? " {$first}" : $first;
                 $name .= !empty($name) && !empty($middle) ? " {$middle}" : $middle;
                 $name .= !empty($name) && !empty($last) ? " {$last}" : $last;
                 $name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
                 return $name;
             } else {
                 return $value;
             }
             break;
         case 'creditcard':
             if (is_array($value)) {
                 $card_number = trim(rgget($field['id'] . '.1', $value));
                 $card_type = trim(rgget($field['id'] . '.4', $value));
                 $separator = $format == 'html' ? '<br/>' : '\\n';
                 return empty($card_number) ? '' : $card_type . $separator . $card_number;
             } else {
                 return '';
             }
             break;
         case 'address':
             if (is_array($value)) {
                 $street_value = trim(rgget($field['id'] . '.1', $value));
                 $street2_value = trim(rgget($field['id'] . '.2', $value));
                 $city_value = trim(rgget($field['id'] . '.3', $value));
                 $state_value = trim(rgget($field['id'] . '.4', $value));
                 $zip_value = trim(rgget($field['id'] . '.5', $value));
                 $country_value = trim(rgget($field['id'] . '.6', $value));
                 $line_break = $format == 'html' ? '<br />' : '\\n';
                 $address_display_format = apply_filters('gform_address_display_format', 'default');
                 if ($address_display_format == 'zip_before_city') {
                     /*
                     Sample:
                     3333 Some Street
                     suite 16
                     2344 City, State
                     Country
                     */
                     $addr_ary = array();
                     $addr_ary[] = $street_value;
                     if (!empty($street2_value)) {
                         $addr_ary[] = $street2_value;
                     }
                     $zip_line = trim($zip_value . ' ' . $city_value);
                     $zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $zip_line = trim($zip_line);
                     if (!empty($zip_line)) {
                         $addr_ary[] = $zip_line;
                     }
                     if (!empty($country_value)) {
                         $addr_ary[] = $country_value;
                     }
                     $address = implode('<br />', $addr_ary);
                 } else {
                     $address = $street_value;
                     $address .= !empty($address) && !empty($street2_value) ? $line_break . $street2_value : $street2_value;
                     $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? $line_break . $city_value : $city_value;
                     $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
                     $address .= !empty($address) && !empty($country_value) ? $line_break . $country_value : $country_value;
                 }
                 return $address;
             } else {
                 return '';
             }
             break;
         case 'email':
             return GFCommon::is_valid_email($value) && $format == 'html' ? '<a href="mailto:' . $value . '">' . $value . '</a>' : $value;
             break;
         case 'website':
             return GFCommon::is_valid_url($value) && $format == 'html' ? '<a href="' . $value . '" target="_blank">' . $value . '</a>' : $value;
             break;
         case 'checkbox':
             if (is_array($value)) {
                 $items = '';
                 foreach ($value as $key => $item) {
                     if (!empty($item)) {
                         switch ($format) {
                             case 'text':
                                 $items .= GFCommon::selection_display($item, $field, $currency, true) . ', ';
                                 break;
                             default:
                                 $items .= '<li>' . GFCommon::selection_display($item, $field, $currency, true) . '</li>';
                                 break;
                         }
                     }
                 }
                 if (empty($items)) {
                     return '';
                 } else {
                     if ($format == 'text') {
                         return substr($items, 0, strlen($items) - 2);
                         //removing last comma
                     } else {
                         return '<ul class="bulleted">' . $items . '</ul>';
                     }
                 }
             } else {
                 return $value;
             }
             break;
         case 'post_image':
             $ary = explode('|:|', $value);
             $url = count($ary) > 0 ? $ary[0] : '';
             $title = count($ary) > 1 ? $ary[1] : '';
             $caption = count($ary) > 2 ? $ary[2] : '';
             $description = count($ary) > 3 ? $ary[3] : '';
             if (!empty($url)) {
                 $url = str_replace(' ', '%20', $url);
                 switch ($format) {
                     case 'text':
                         $value = $url;
                         $value .= !empty($title) ? '\\n\\n' . $field['label'] . ' (' . __('Title', 'gravityforms') . '): ' . $title : '';
                         $value .= !empty($caption) ? '\\n\\n' . $field['label'] . ' (' . __('Caption', 'gravityforms') . '): ' . $caption : '';
                         $value .= !empty($description) ? '\\n\\n' . $field['label'] . ' (' . __('Description', 'gravityforms') . '): ' . $description : '';
                         break;
                     default:
                         $path = str_replace(site_url() . '/', ABSPATH, $url);
                         $value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$path}' width='100' /></a>";
                         $value .= !empty($title) ? "<div>Title: {$title}</div>" : "";
                         $value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : "";
                         $value .= !empty($description) ? "<div>Description: {$description}</div>" : "";
                         break;
                 }
             }
             return $value;
         case 'fileupload':
             $output = '';
             $output_arr = array();
             if (!empty($value)) {
                 $output .= '<ul>';
                 $file_paths = rgar($field, 'multipleFiles') ? json_decode($value) : array($value);
                 foreach ($file_paths as $file_path) {
                     $info = pathinfo($file_path);
                     $file_path = esc_attr(str_replace(' ', '%20', $file_path));
                     $output_arr[] = '<li><a href="' . $file_path . '" target="_blank" title="' . __('Click to view', 'gravityforms') . '">' . $info['basename'] . '</a></li>';
                 }
                 $output .= join(PHP_EOL, $output_arr);
                 $output .= '</ul>';
             }
             return $output;
             break;
         case 'date':
             return GFCommon::date_display($value, rgar($field, 'dateFormat'));
             break;
         case 'radio':
         case 'select':
             return GFCommon::selection_display($value, $field, $currency, true);
             break;
         case 'multiselect':
             if (empty($value) || $format == 'text') {
                 return $value;
             }
             if (!is_array($value)) {
                 $value = explode(',', $value);
             }
             $items = '';
             foreach ($value as $item) {
                 $items .= '<li>' . GFCommon::selection_display($item, $field, $currency, true) . '</li>';
             }
             return '<ul class="bulleted">' . $items . '</ul>';
             break;
         case 'calculation':
         case 'singleproduct':
             if (is_array($value)) {
                 $product_name = trim($value[$field['id'] . '.1']);
                 $price = trim($value[$field['id'] . '.2']);
                 $quantity = trim($value[$field['id'] . '.3']);
                 $product = $product_name . ', ' . __('Qty: ', 'gravityforms') . $quantity . ', ' . __('Price: ', 'gravityforms') . $price;
                 return $product;
             } else {
                 return '';
             }
             break;
         case 'number':
             return GFCommon::format_number($value, rgar($field, 'numberFormat'));
             break;
         case 'singleshipping':
         case 'donation':
         case 'total':
         case 'price':
             return GFCommon::to_money($value, $currency);
         case 'list':
             if (empty($value)) {
                 return '';
             }
             $value = unserialize($value);
             $has_columns = is_array($value[0]);
             if (!$has_columns) {
                 $items = '';
                 foreach ($value as $key => $item) {
                     if (!empty($item)) {
                         switch ($format) {
                             case 'text':
                                 $items .= $item . ', ';
                                 break;
                             case 'url':
                                 $items .= $item . ',';
                                 break;
                             default:
                                 if ($media == 'email') {
                                     $items .= '<li>' . htmlspecialchars($item) . '</li>';
                                 } else {
                                     $items .= '<li>' . htmlspecialchars($item) . '</li>';
                                 }
                                 break;
                         }
                     }
                 }
                 if (empty($items)) {
                     return '';
                 } else {
                     if ($format == 'text') {
                         return substr($items, 0, strlen($items) - 2);
                         //removing last comma
                     } else {
                         if ($format == 'url') {
                             return substr($items, 0, strlen($items) - 1);
                             //removing last comma
                         } else {
                             return '<ul class="bulleted">' . $items . '</ul>';
                         }
                     }
                 }
             } else {
                 if (is_array($value)) {
                     $columns = array_keys($value[0]);
                     $list = '';
                     switch ($format) {
                         case 'text':
                             $is_first_row = true;
                             foreach ($value as $item) {
                                 if (!$is_first_row) {
                                     $list .= '\\n\\n' . $field['label'] . ': ';
                                 }
                                 $list .= implode(',', array_values($item));
                                 $is_first_row = false;
                             }
                             break;
                         case 'url':
                             foreach ($value as $item) {
                                 $list .= implode('|', array_values($item)) . ',';
                             }
                             if (!empty($list)) {
                                 $list = substr($list, 0, strlen($list) - 1);
                             }
                             break;
                         default:
                             if ($media == 'email') {
                                 $list = '<table autosize="1" class="gfield_list" style="border-top: 1px solid #DFDFDF; border-left: 1px solid #DFDFDF; border-spacing: 0; padding: 0; margin: 2px 0 6px; width: 100%"><thead><tr>';
                                 //reading columns from entry data
                                 foreach ($columns as $column) {
                                     $list .= '<th style="background-image: none; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; padding: 6px 10px; font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #F1F1F1; color:#333; text-align:left">' . esc_html($column) . '</th>';
                                 }
                                 $list .= '</tr></thead>';
                                 $list .= '<tbody style="background-color: #F9F9F9">';
                                 foreach ($value as $item) {
                                     $list .= '<tr>';
                                     foreach ($columns as $column) {
                                         $val = rgar($item, $column);
                                         $list .= '<td style="padding: 6px 10px; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; border-top: 1px solid #FFF; font-family: sans-serif; font-size:12px;">{$val}</td>';
                                     }
                                     $list .= '</tr>';
                                 }
                                 $list .= '</tbody></table>';
                             } else {
                                 $list = '<table autosize="1" class="gfield_list"><thead><tr>';
                                 //reading columns from entry data
                                 foreach ($columns as $column) {
                                     $list .= '<th>' . esc_html($column) . '</th>';
                                 }
                                 $list .= '</tr></thead>';
                                 $list .= '<tbody>';
                                 foreach ($value as $item) {
                                     $list .= '<tr>';
                                     foreach ($columns as $column) {
                                         $val = rgar($item, $column);
                                         $list .= '<td>' . htmlspecialchars($val) . '</td>';
                                     }
                                     $list .= '</tr>';
                                 }
                                 $list .= '</tbody></table>';
                             }
                             break;
                     }
                     return $list;
                 }
             }
             return '';
             break;
         default:
             if (!is_array($value)) {
                 return nl2br($value);
             }
             break;
     }
 }
Beispiel #18
0
 public static function get_lead_field_display($field, $value, $currency = "", $use_text = false, $format = "html", $media = "screen")
 {
     if ($field['type'] == 'post_category') {
         $value = self::prepare_post_category_value($value, $field);
     }
     switch (RGFormsModel::get_input_type($field)) {
         case "name":
             if (is_array($value)) {
                 $prefix = trim(rgget($field["id"] . ".2", $value));
                 $first = trim(rgget($field["id"] . ".3", $value));
                 $last = trim(rgget($field["id"] . ".6", $value));
                 $suffix = trim(rgget($field["id"] . ".8", $value));
                 $name = $prefix;
                 $name .= !empty($name) && !empty($first) ? " {$first}" : $first;
                 $name .= !empty($name) && !empty($last) ? " {$last}" : $last;
                 $name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
                 return $name;
             } else {
                 return $value;
             }
             break;
         case "creditcard":
             if (is_array($value)) {
                 $card_number = trim(rgget($field["id"] . ".1", $value));
                 $card_type = trim(rgget($field["id"] . ".4", $value));
                 $separator = $format == "html" ? "<br/>" : "\n";
                 return empty($card_number) ? "" : $card_type . $separator . $card_number;
             } else {
                 return "";
             }
             break;
         case "address":
             if (is_array($value)) {
                 $street_value = trim(rgget($field["id"] . ".1", $value));
                 $street2_value = trim(rgget($field["id"] . ".2", $value));
                 $city_value = trim(rgget($field["id"] . ".3", $value));
                 $state_value = trim(rgget($field["id"] . ".4", $value));
                 $zip_value = trim(rgget($field["id"] . ".5", $value));
                 $country_value = trim(rgget($field["id"] . ".6", $value));
                 $line_break = $format == "html" ? "<br />" : "\n";
                 $address_display_format = apply_filters("gform_address_display_format", "default");
                 if ($address_display_format == "zip_before_city") {
                     /*
                     Sample:
                     3333 Some Street
                     suite 16
                     2344 City, State
                     Country
                     */
                     $addr_ary = array();
                     $addr_ary[] = $street_value;
                     if (!empty($street2_value)) {
                         $addr_ary[] = $street2_value;
                     }
                     $zip_line = trim($zip_value . " " . $city_value);
                     $zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $zip_line = trim($zip_line);
                     if (!empty($zip_line)) {
                         $addr_ary[] = $zip_line;
                     }
                     if (!empty($country_value)) {
                         $addr_ary[] = $country_value;
                     }
                     $address = implode("<br />", $addr_ary);
                 } else {
                     $address = $street_value;
                     $address .= !empty($address) && !empty($street2_value) ? $line_break . $street2_value : $street2_value;
                     $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? $line_break . $city_value : $city_value;
                     $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
                     $address .= !empty($address) && !empty($country_value) ? $line_break . $country_value : $country_value;
                 }
                 //adding map link
                 if (!empty($address) && $format == "html") {
                     $address_qs = str_replace($line_break, " ", $address);
                     //replacing <br/> and \n with spaces
                     $address_qs = urlencode($address_qs);
                     $address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
                 }
                 return $address;
             } else {
                 return "";
             }
             break;
         case "email":
             return GFCommon::is_valid_email($value) && $format == "html" ? "<a href='mailto:{$value}'>{$value}</a>" : $value;
             break;
         case "website":
             return GFCommon::is_valid_url($value) && $format == "html" ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
             break;
         case "checkbox":
             if (is_array($value)) {
                 $items = '';
                 foreach ($value as $key => $item) {
                     if (!empty($item)) {
                         switch ($format) {
                             case "text":
                                 $items .= GFCommon::selection_display($item, $field, $currency, $use_text) . ", ";
                                 break;
                             default:
                                 $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>";
                                 break;
                         }
                     }
                 }
                 if (empty($items)) {
                     return "";
                 } else {
                     if ($format == "text") {
                         return substr($items, 0, strlen($items) - 2);
                         //removing last comma
                     } else {
                         return "<ul class='bulleted'>{$items}</ul>";
                     }
                 }
             } else {
                 return $value;
             }
             break;
         case "post_image":
             $ary = explode("|:|", $value);
             $url = count($ary) > 0 ? $ary[0] : "";
             $title = count($ary) > 1 ? $ary[1] : "";
             $caption = count($ary) > 2 ? $ary[2] : "";
             $description = count($ary) > 3 ? $ary[3] : "";
             if (!empty($url)) {
                 $url = str_replace(" ", "%20", $url);
                 switch ($format) {
                     case "text":
                         $value = $url;
                         $value .= !empty($title) ? "\n\n" . $field["label"] . " (" . __("Title", "gravityforms") . "): " . $title : "";
                         $value .= !empty($caption) ? "\n\n" . $field["label"] . " (" . __("Caption", "gravityforms") . "): " . $caption : "";
                         $value .= !empty($description) ? "\n\n" . $field["label"] . " (" . __("Description", "gravityforms") . "): " . $description : "";
                         break;
                     default:
                         $value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$url}' width='100' /></a>";
                         $value .= !empty($title) ? "<div>Title: {$title}</div>" : "";
                         $value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : "";
                         $value .= !empty($description) ? "<div>Description: {$description}</div>" : "";
                         break;
                 }
             }
             return $value;
         case "fileupload":
             $file_path = $value;
             if (!empty($file_path)) {
                 $info = pathinfo($file_path);
                 $file_path = esc_attr(str_replace(" ", "%20", $file_path));
                 $value = $format == "text" ? $file_path : "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $info["basename"] . "</a>";
             }
             return $value;
             break;
         case "date":
             return GFCommon::date_display($value, rgar($field, "dateFormat"));
             break;
         case "radio":
         case "select":
             return GFCommon::selection_display($value, $field, $currency, $use_text);
             break;
         case "multiselect":
             if (empty($value) || $format == "text") {
                 return $value;
             }
             $value = explode(",", $value);
             $items = '';
             foreach ($value as $item) {
                 $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>";
             }
             return "<ul class='bulleted'>{$items}</ul>";
             break;
         case "calculation":
         case "singleproduct":
             if (is_array($value)) {
                 $product_name = trim($value[$field["id"] . ".1"]);
                 $price = trim($value[$field["id"] . ".2"]);
                 $quantity = trim($value[$field["id"] . ".3"]);
                 $product = $product_name . ", " . __("Qty: ", "gravityforms") . $quantity . ", " . __("Price: ", "gravityforms") . $price;
                 return $product;
             } else {
                 return "";
             }
             break;
         case "number":
             return GFCommon::format_number($value, rgar($field, "numberFormat"));
             break;
         case "singleshipping":
         case "donation":
         case "total":
         case "price":
             return GFCommon::to_money($value, $currency);
         case "list":
             if (empty($value)) {
                 return "";
             }
             $value = unserialize($value);
             $has_columns = is_array($value[0]);
             if (!$has_columns) {
                 $items = '';
                 foreach ($value as $key => $item) {
                     if (!empty($item)) {
                         switch ($format) {
                             case "text":
                                 $items .= $item . ", ";
                                 break;
                             case "url":
                                 $items .= $item . ",";
                                 break;
                             default:
                                 if ($media == "email") {
                                     $items .= "<li>{$item}</li>";
                                 } else {
                                     $items .= "<li>{$item}</li>";
                                 }
                                 break;
                         }
                     }
                 }
                 if (empty($items)) {
                     return "";
                 } else {
                     if ($format == "text") {
                         return substr($items, 0, strlen($items) - 2);
                         //removing last comma
                     } else {
                         if ($format == "url") {
                             return substr($items, 0, strlen($items) - 1);
                             //removing last comma
                         } else {
                             if ($media == "email") {
                                 return "<ul class='bulleted'>{$items}</ul>";
                             } else {
                                 return "<ul class='bulleted'>{$items}</ul>";
                             }
                         }
                     }
                 }
             } else {
                 if (is_array($value)) {
                     $columns = array_keys($value[0]);
                     $list = "";
                     switch ($format) {
                         case "text":
                             $is_first_row = true;
                             foreach ($value as $item) {
                                 if (!$is_first_row) {
                                     $list .= "\n\n" . $field["label"] . ": ";
                                 }
                                 $list .= implode(",", array_values($item));
                                 $is_first_row = false;
                             }
                             break;
                         case "url":
                             foreach ($value as $item) {
                                 $list .= implode("|", array_values($item)) . ",";
                             }
                             if (!empty($list)) {
                                 $list = substr($list, 0, strlen($list) - 1);
                             }
                             break;
                         default:
                             if ($media == "email") {
                                 $list = "<table class='gfield_list' style='border-top: 1px solid #DFDFDF; border-left: 1px solid #DFDFDF; border-spacing: 0; padding: 0; margin: 2px 0 6px; width: 100%'><thead><tr>";
                                 //reading columns from entry data
                                 foreach ($columns as $column) {
                                     $list .= "<th style='background-image: none; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; padding: 6px 10px; font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #F1F1F1; color:#333; text-align:left'>" . esc_html($column) . "</th>";
                                 }
                                 $list .= "</tr></thead>";
                                 $list .= "<tbody style='background-color: #F9F9F9'>";
                                 foreach ($value as $item) {
                                     $list .= "<tr>";
                                     foreach ($columns as $column) {
                                         $val = rgar($item, $column);
                                         $list .= "<td style='padding: 6px 10px; border-right: 1px solid #DFDFDF; border-bottom: 1px solid #DFDFDF; border-top: 1px solid #FFF; font-family: sans-serif; font-size:12px;'>{$val}</td>";
                                     }
                                     $list .= "</tr>";
                                 }
                                 $list .= "<tbody></table>";
                             } else {
                                 $list = "<table class='gfield_list'><thead><tr>";
                                 //reading columns from entry data
                                 foreach ($columns as $column) {
                                     $list .= "<th>" . esc_html($column) . "</th>";
                                 }
                                 $list .= "</tr></thead>";
                                 $list .= "<tbody>";
                                 foreach ($value as $item) {
                                     $list .= "<tr>";
                                     foreach ($columns as $column) {
                                         $val = rgar($item, $column);
                                         $list .= "<td>{$val}</td>";
                                     }
                                     $list .= "</tr>";
                                 }
                                 $list .= "<tbody></table>";
                             }
                             break;
                     }
                     return $list;
                 }
             }
             return "";
             break;
         default:
             if (!is_array($value)) {
                 return nl2br($value);
             }
             break;
     }
 }
Beispiel #19
0
 /**
  * Process Stripe webhooks. Convert raw response into standard Gravity Forms $action.
  *
  * @return array|bool Return a valid GF $action or false if you have processed the callback yourself.
  */
 public function callback()
 {
     $body = @file_get_contents('php://input');
     $response = json_decode($body, true);
     if (empty($response)) {
         if (strpos($body, 'ipn_is_json') !== false) {
             $response = json_decode($_POST, true);
         }
         if (empty($response)) {
             return false;
         }
     }
     //Handling test webhooks
     if ($response['id'] == 'evt_00000000000000') {
         return new WP_Error('test_webhook_succeeded', __('Test webhook succeeded. Your Stripe Account and Stripe Add-On are configured correctly to process webhooks.', 'gravityformsstripe'), array('status_header' => 200));
     }
     $settings = $this->get_plugin_settings();
     $mode = $this->get_setting('api_mode', '', $settings);
     if ($response['livemode'] == false && $mode == 'live') {
         return new WP_Error('invalid_request', __('Webhook from test transaction. Bypassed.', 'gravityformsstripe'));
     }
     try {
         //To make sure the request came from Stripe, getting the event object again from Stripe (based on the ID in the response)
         $event = $this->get_stripe_event($response['id']);
     } catch (Stripe_Error $e) {
         return new WP_Error('invalid_request', __('Invalid webhook data. Webhook could not be processed.', 'gravityformsstripe'), array('status_header' => 500));
     }
     $action = array('id' => $event['id']);
     $type = rgar($event, 'type');
     switch ($type) {
         case 'charge.refunded':
             $action['transaction_id'] = rgars($event, 'data/object/id');
             $entry_id = $this->get_entry_by_transaction_id($action['transaction_id']);
             if (!$entry_id) {
                 return new WP_Error('entry_not_found', sprintf(__('Entry for transaction id: %s was not found. Webhook cannot be processed.', 'gravityformsstripe'), $action['transaction_id']));
             }
             $action['entry_id'] = $entry_id;
             $action['type'] = 'refund_payment';
             $action['amount'] = rgars($event, 'data/object/amount_refunded') / 100;
             break;
         case 'customer.subscription.deleted':
             $action['subscription_id'] = rgars($event, 'data/object/id');
             $entry_id = $this->get_entry_by_transaction_id($action['subscription_id']);
             if (!$entry_id) {
                 return new WP_Error('entry_not_found', sprintf(__('Entry for subscription id: %s was not found. Webhook cannot be processed.', 'gravityformsstripe'), $action['subscription_id']));
             }
             $action['entry_id'] = $entry_id;
             $action['type'] = 'cancel_subscription';
             $action['amount'] = rgars($event, 'data/object/plan/amount') / 100;
             break;
         case 'invoice.payment_succeeded':
             $subscription = $this->get_subscription_line_item($event);
             if (!$subscription) {
                 return new WP_Error('invalid_request', sprintf(__('Subscription line item not found in request', 'gravityformsstripe')));
             }
             $action['subscription_id'] = rgar($subscription, 'id');
             $entry_id = $this->get_entry_by_transaction_id($action['subscription_id']);
             if (!$entry_id) {
                 return new WP_Error('entry_not_found', sprintf(__('Entry for subscription id: %s was not found. Webhook cannot be processed.', 'gravityformsstripe'), $action['subscription_id']));
             }
             $action['transaction_id'] = rgars($event, 'data/object/charge');
             $action['entry_id'] = $entry_id;
             $action['type'] = 'add_subscription_payment';
             $action['amount'] = rgars($event, 'data/object/amount_due') / 100;
             $action['note'] = '';
             // get starting balance, assume this balance represents a setup fee or trial
             $starting_balance = rgars($event, 'data/object/starting_balance') / 100;
             if ($starting_balance > 0) {
                 $action['note'] = $this->get_captured_payment_note($action['entry_id']) . ' ';
             }
             $entry = GFAPI::get_entry($action['entry_id']);
             $amount_formatted = GFCommon::to_money($action['amount'], $entry['currency']);
             $action['note'] .= sprintf(__('Subscription payment has been paid. Amount: %s. Subscriber Id: %s', 'gravityforms'), $amount_formatted, $action['subscription_id']);
             break;
         case 'invoice.payment_failed':
             $subscription = $this->get_subscription_line_item($event);
             if (!$subscription) {
                 return new WP_Error('invalid_request', sprintf(__('Subscription line item not found in request', 'gravityformsstripe')));
             }
             $action['subscription_id'] = rgar($subscription, 'id');
             $entry_id = $this->get_entry_by_transaction_id($action['subscription_id']);
             if (!$entry_id) {
                 return new WP_Error('entry_not_found', sprintf(__('Entry for subscription id: %s was not found. Webhook cannot be processed.', 'gravityformsstripe'), $action['subscription_id']));
             }
             $action['type'] = 'fail_subscription_payment';
             $action['amount'] = rgar($subscription, 'amount') / 100;
             $action['entry_id'] = $this->get_entry_by_transaction_id($action['subscription_id']);
             break;
     }
     $action = apply_filters('gform_stripe_webhook', $action, $event);
     if (rgempty('entry_id', $action)) {
         return false;
     }
     return $action;
 }
 public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
 {
     return GFCommon::to_money($value, $currency);
 }
 function column_revenue($item)
 {
     return GFCommon::to_money($item['revenue']);
 }
Beispiel #22
0
    public static function payment_details_box($lead, $form)
    {
        ?>
		<!-- PAYMENT BOX -->
		<div id="submitdiv" class="stuffbox">
			<h3 class="hndle" style="cursor:default;">
                <span><?php 
        echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Details', 'gravityforms') : esc_html__('Payment Details', 'gravityforms');
        ?>
</span>
			</h3>

			<div class="inside">
				<div id="submitcomment" class="submitbox">
					<div id="minor-publishing" style="padding:10px;">
						<?php 
        $payment_status = apply_filters('gform_payment_status', $lead['payment_status'], $form, $lead);
        if (!empty($payment_status)) {
            ?>
							<div id="gf_payment_status" class="gf_payment_detail">
								<?php 
            esc_html_e('Status', 'gravityforms');
            ?>
:
								<span id="gform_payment_status"><?php 
            echo $payment_status;
            // May contain HTML
            ?>
</span>
							</div>

							<?php 
            /**
             * Allows for modification on the form payment date format
             *
             * @param array $form The Form object to filter through
             * @param array $lead The Lead object to filter through
             */
            $payment_date = apply_filters('gform_payment_date', GFCommon::format_date($lead['payment_date'], false, 'Y/m/d', $lead['transaction_type'] != 2), $form, $lead);
            if (!empty($payment_date)) {
                ?>
								<div id="gf_payment_date" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Start Date', 'gravityforms') : esc_html__('Date', 'gravityforms');
                ?>
:
									<span id='gform_payment_date'><?php 
                echo $payment_date;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            /**
             * Allows filtering through a payment transaction ID
             *
             * @param int $lead['transaction_id'] The transaction ID that can be modified
             * @param array $form The Form object to be filtered when modifying the transaction ID
             * @param array $lead The Lead object to be filtered when modifying the transaction ID
             */
            $transaction_id = apply_filters('gform_payment_transaction_id', $lead['transaction_id'], $form, $lead);
            if (!empty($transaction_id)) {
                ?>
								<div id="gf_payment_transaction_id" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Id', 'gravityforms') : esc_html__('Transaction Id', 'gravityforms');
                ?>
:
									<span id='gform_payment_transaction_id'><?php 
                echo $transaction_id;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            /**
             * Filter through the way the Payment Amount is rendered
             *
             * @param string $lead['payment_amount'] The payment amount taken from the lead object
             * @param string $lead['currency'] The payment currency taken from the lead object
             * @param array $form The Form onject to filter through
             * @param array $lead The lead object to filter through
             */
            $payment_amount = apply_filters('gform_payment_amount', GFCommon::to_money($lead['payment_amount'], $lead['currency']), $form, $lead);
            if (!rgblank($payment_amount)) {
                ?>
								<div id="gf_payment_amount" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Recurring Amount', 'gravityforms') : esc_html__('Amount', 'gravityforms');
                ?>
:
									<span id='gform_payment_amount'><?php 
                echo $payment_amount;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
        }
        /**
         * Fires after the Form Payment Details (The type of payment, the cost, the ID, etc)
         *
         * @param int $form['id'] The current Form ID
         * @param array $lead The current Lead object
         */
        do_action('gform_payment_details', $form['id'], $lead);
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
Beispiel #23
0
 /**
  * Sanitize the field choices property.
  *
  * @param array|null $choices The field choices property.
  *
  * @return array|null
  */
 public function sanitize_settings_choices($choices = null)
 {
     if (is_null($choices)) {
         $choices =& $this->choices;
     }
     if (!is_array($choices)) {
         return $choices;
     }
     foreach ($choices as &$choice) {
         if (isset($choice['isSelected'])) {
             $choice['isSelected'] = (bool) $choice['isSelected'];
         }
         if (isset($choice['price']) && !empty($choice['price'])) {
             $price_number = GFCommon::to_number($choice['price']);
             $choice['price'] = GFCommon::to_money($price_number);
         }
         if (isset($choice['text'])) {
             $choice['text'] = $this->maybe_wp_kses($choice['text']);
         }
         if (isset($choice['value'])) {
             // Strip scripts but don't encode
             $allowed_protocols = wp_allowed_protocols();
             $choice['value'] = wp_kses_no_null($choice['value'], array('slash_zero' => 'keep'));
             $choice['value'] = wp_kses_hook($choice['value'], 'post', $allowed_protocols);
             $choice['value'] = wp_kses_split($choice['value'], 'post', $allowed_protocols);
         }
     }
     return $choices;
 }
Beispiel #24
0
 /**
  * Displays the entry value.
  *
  * @param object $entry
  * @param string $field_id
  */
 function column_default($entry, $column_id)
 {
     $field_id = (string) str_replace('field_id-', '', $column_id);
     $form = $this->get_form();
     $form_id = $this->get_form_id();
     $field = GFFormsModel::get_field($form, $field_id);
     $columns = GFFormsModel::get_grid_columns($form_id, true);
     $value = rgar($entry, $field_id);
     if (!empty($field) && $field->type == 'post_category') {
         $value = GFCommon::prepare_post_category_value($value, $field, 'entry_list');
     }
     // Filtering lead value
     $value = apply_filters('gform_get_field_value', $value, $entry, $field);
     switch ($field_id) {
         case 'source_url':
             $value = "<a href='" . esc_attr($entry['source_url']) . "' target='_blank' alt='" . esc_attr($entry['source_url']) . "' title='" . esc_attr($entry['source_url']) . "'>.../" . esc_attr(GFCommon::truncate_url($entry['source_url'])) . '</a>';
             break;
         case 'date_created':
         case 'payment_date':
             $value = GFCommon::format_date($value, false);
             break;
         case 'payment_amount':
             $value = GFCommon::to_money($value, $entry['currency']);
             break;
         case 'created_by':
             if (!empty($value)) {
                 $userdata = get_userdata($value);
                 if (!empty($userdata)) {
                     $value = $userdata->user_login;
                 }
             }
             break;
         default:
             if ($field !== null) {
                 $value = $field->get_value_entry_list($value, $entry, $field_id, $columns, $form);
             } else {
                 $value = esc_html($value);
             }
     }
     $value = apply_filters('gform_entries_field_value', $value, $form_id, $field_id, $entry);
     $primary = $this->get_primary_column_name();
     $query_string = $this->get_detail_query_string($entry);
     if ($column_id == $primary) {
         $edit_url = $this->get_detail_url($entry);
         echo '<a title="' . esc_attr__('View this entry', 'gravityforms') . '" href="' . $edit_url . '">' . $value . '</a>';
     } else {
         /**
          * Used to inject markup and replace the value of any non-first column in the entry list grid.
          *
          * @param string $value        The value of the field
          * @param int    $form_id      The ID of the current form
          * @param int    $field_id     The ID of the field
          * @param array  $entry        The Entry object
          * @param string $query_string The current page's query string
          */
         echo apply_filters('gform_entries_column_filter', $value, $form_id, $field_id, $entry, $query_string);
         // Maintains gap between value and content from gform_entries_column which existed when using 1.9 and earlier.
         echo '&nbsp; ';
         /**
          * Fired within the entries column
          *
          * Used to insert additional entry details
          *
          * @param int    $form_id      The ID of the current form
          * @param int    $field_id     The ID of the field
          * @param string $value        The value of the field
          * @param array  $entry        The Entry object
          * @param string $query_string The current page's query string
          */
         do_action('gform_entries_column', $form_id, $field_id, $value, $entry, $query_string);
     }
 }
Beispiel #25
0
 public static function admin_update_payment($form, $lead_id)
 {
     check_admin_referer('gforms_save_entry', 'gforms_save_entry');
     //update payment information in admin, need to use this function so the lead data is updated before displayed in the sidebar info section
     //check meta to see if this entry is paypal
     $payment_gateway = gform_get_meta($lead_id, "payment_gateway");
     $form_action = strtolower(rgpost("save"));
     if ($payment_gateway != "paypal" || $form_action != "update") {
         return;
     }
     //get lead
     $lead = RGFormsModel::get_lead($lead_id);
     //get payment fields to update
     $payment_status = rgpost("payment_status");
     //when updating, payment status may not be editable, if no value in post, set to lead payment status
     if (empty($payment_status)) {
         $payment_status = $lead["payment_status"];
     }
     $payment_amount = rgpost("payment_amount");
     $payment_transaction = rgpost("paypal_transaction_id");
     $payment_date = rgpost("payment_date");
     if (empty($payment_date)) {
         $payment_date = gmdate("y-m-d H:i:s");
     } else {
         //format date entered by user
         $payment_date = date("Y-m-d H:i:s", strtotime($payment_date));
     }
     global $current_user;
     $user_id = 0;
     $user_name = "System";
     if ($current_user && ($user_data = get_userdata($current_user->ID))) {
         $user_id = $current_user->ID;
         $user_name = $user_data->display_name;
     }
     $lead["payment_status"] = $payment_status;
     $lead["payment_amount"] = $payment_amount;
     $lead["payment_date"] = $payment_date;
     $lead["transaction_id"] = $payment_transaction;
     // if payment status does not equal approved or the lead has already been fulfilled, do not continue with fulfillment
     if ($payment_status == 'Approved' && !$lead["is_fulfilled"]) {
         //call fulfill order, mark lead as fulfilled
         self::fulfill_order($lead, $payment_transaction, $payment_amount);
         $lead["is_fulfilled"] = true;
     }
     //update lead, add a note
     RGFormsModel::update_lead($lead);
     RGFormsModel::add_note($lead["id"], $user_id, $user_name, sprintf(__("Payment information was manually updated. Status: %s. Amount: %s. Transaction Id: %s. Date: %s", "gravityforms"), $lead["payment_status"], GFCommon::to_money($lead["payment_amount"], $lead["currency"]), $payment_transaction, $lead["payment_date"]));
 }
Beispiel #26
0
 public static function get_lead_field_display($field, $value, $currency = "", $use_text = false)
 {
     switch (RGFormsModel::get_input_type($field)) {
         case "name":
             if (is_array($value)) {
                 $prefix = trim($value[$field["id"] . ".2"]);
                 $first = trim($value[$field["id"] . ".3"]);
                 $last = trim($value[$field["id"] . ".6"]);
                 $suffix = trim($value[$field["id"] . ".8"]);
                 $name = $prefix;
                 $name .= !empty($name) && !empty($first) ? " {$first}" : $first;
                 $name .= !empty($name) && !empty($last) ? " {$last}" : $last;
                 $name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix;
                 return $name;
             } else {
                 return $value;
             }
             break;
         case "address":
             if (is_array($value)) {
                 $street_value = trim($value[$field["id"] . ".1"]);
                 $street2_value = trim($value[$field["id"] . ".2"]);
                 $city_value = trim($value[$field["id"] . ".3"]);
                 $state_value = trim($value[$field["id"] . ".4"]);
                 $zip_value = trim($value[$field["id"] . ".5"]);
                 $country_value = trim($value[$field["id"] . ".6"]);
                 $address_display_format = apply_filters("gform_address_display_format", "street,city,state,zip,country");
                 if ($address_display_format == "zip_before_city") {
                     /*
                     Sample:
                     3333 Some Street
                     suite 16
                     2344 City, State
                     Country
                     */
                     $addr_ary = array();
                     $addr_ary[] = $street_value;
                     if (!empty($street2_value)) {
                         $addr_ary[] = $street2_value;
                     }
                     $zip_line = trim($zip_value . " " . $city_value);
                     $zip_line .= !empty($zip_line) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $zip_line = trim($zip_line);
                     if (!empty($zip_line)) {
                         $addr_ary[] = $zip_line;
                     }
                     if (!empty($country_value)) {
                         $addr_ary[] = $country_value;
                     }
                     $address = implode("<br />", $addr_ary);
                 } else {
                     $address = $street_value;
                     $address .= !empty($address) && !empty($street2_value) ? "<br />{$street2_value}" : $street2_value;
                     $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? "<br />{$city_value}" : $city_value;
                     $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", {$state_value}" : $state_value;
                     $address .= !empty($address) && !empty($zip_value) ? " {$zip_value}" : $zip_value;
                     $address .= !empty($address) && !empty($country_value) ? "<br />{$country_value}" : $country_value;
                 }
                 //adding map link
                 if (!empty($address)) {
                     $address_qs = str_replace("<br />", " ", $address);
                     //replacing <br/> with spaces
                     $address_qs = urlencode($address_qs);
                     $address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
                 }
                 return $address;
             } else {
                 return "";
             }
             break;
         case "email":
             return GFCommon::is_valid_email($value) ? "<a href='mailto:{$value}'>{$value}</a>" : $value;
             break;
         case "website":
             return GFCommon::is_valid_url($value) ? "<a href='{$value}' target='_blank'>{$value}</a>" : $value;
             break;
         case "checkbox":
             if (is_array($value)) {
                 foreach ($value as $key => $item) {
                     if (!empty($item)) {
                         $items .= "<li>" . GFCommon::selection_display($item, $field, $currency, $use_text) . "</li>";
                     }
                 }
                 return empty($items) ? "" : "<ul class='bulleted'>{$items}</ul>";
             } else {
                 return $value;
             }
             break;
         case "post_image":
             list($url, $title, $caption, $description) = explode("|:|", $value);
             if (!empty($url)) {
                 $url = str_replace(" ", "%20", $url);
                 $value = "<a href='{$url}' target='_blank' title='" . __("Click to view", "gravityforms") . "'><img src='{$url}' width='100' /></a>";
                 $value .= !empty($title) ? "<div>Title: {$title}</div>" : "";
                 $value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : "";
                 $value .= !empty($description) ? "<div>Description: {$description}</div>" : "";
             }
             return $value;
         case "fileupload":
             $file_path = $value;
             if (!empty($file_path)) {
                 $info = pathinfo($file_path);
                 $file_path = esc_attr(str_replace(" ", "%20", $file_path));
                 $value = "<a href='{$file_path}' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $info["basename"] . "</a>";
             }
             return $value;
             break;
         case "date":
             return GFCommon::date_display($value, $field["dateFormat"]);
             break;
         case "radio":
         case "select":
             return GFCommon::selection_display($value, $field, $currency, $use_text);
             break;
         case "singleproduct":
             if (is_array($value)) {
                 $product_name = trim($value[$field["id"] . ".1"]);
                 $price = trim($value[$field["id"] . ".2"]);
                 $quantity = trim($value[$field["id"] . ".3"]);
                 $product = $product_name . ", " . __("Qty: ", "gravityforms") . $quantity . ", " . __("Price: ", "gravityforms") . $price;
                 return $product;
             } else {
                 return "";
             }
             break;
         case "singleshipping":
         case "donation":
         case "total":
         case "price":
             return GFCommon::to_money($value, $currency);
         default:
             return nl2br($value);
             break;
     }
 }
Beispiel #27
0
 /**
  * Sanitize the field choices property.
  *
  * @param array|null $choices The field choices property.
  *
  * @return array|null
  */
 public function sanitize_settings_choices($choices = null)
 {
     if (is_null($choices)) {
         $choices =& $this->choices;
     }
     if (!is_array($choices)) {
         return $choices;
     }
     $allowed_tags = wp_kses_allowed_html('post');
     foreach ($choices as &$choice) {
         if (isset($choice['isSelected'])) {
             $choice['isSelected'] = (bool) $choice['isSelected'];
         }
         if (isset($choice['price']) && !empty($choice['price'])) {
             $price_number = GFCommon::to_number($choice['price']);
             $choice['price'] = GFCommon::to_money($price_number);
         }
         if (isset($choice['text'])) {
             $choice['text'] = wp_kses($choice['text'], $allowed_tags);
         }
         if (isset($choice['value'])) {
             $choice['value'] = wp_kses($choice['value'], $allowed_tags);
         }
     }
     return $choices;
 }
 public function admin_update_payment($form, $entry_id)
 {
     check_admin_referer('gforms_save_entry', 'gforms_save_entry');
     //update payment information in admin, need to use this function so the lead data is updated before displayed in the sidebar info section
     $entry = GFFormsModel::get_lead($entry_id);
     if ($this->payment_details_editing_disabled($entry, 'update')) {
         return;
     }
     //get payment fields to update
     $payment_status = rgpost('payment_status');
     //when updating, payment status may not be editable, if no value in post, set to lead payment status
     if (empty($payment_status)) {
         $payment_status = $entry['payment_status'];
     }
     $payment_amount = GFCommon::to_number(rgpost('payment_amount'));
     $payment_transaction = rgpost('paypal_transaction_id');
     $payment_date = rgpost('payment_date');
     if (empty($payment_date)) {
         $payment_date = gmdate('y-m-d H:i:s');
     } else {
         //format date entered by user
         $payment_date = date('Y-m-d H:i:s', strtotime($payment_date));
     }
     global $current_user;
     $user_id = 0;
     $user_name = 'System';
     if ($current_user && ($user_data = get_userdata($current_user->ID))) {
         $user_id = $current_user->ID;
         $user_name = $user_data->display_name;
     }
     $entry['payment_status'] = $payment_status;
     $entry['payment_amount'] = $payment_amount;
     $entry['payment_date'] = $payment_date;
     $entry['transaction_id'] = $payment_transaction;
     // if payment status does not equal approved/paid or the lead has already been fulfilled, do not continue with fulfillment
     if (($payment_status == 'Approved' || $payment_status == 'Paid') && !$entry['is_fulfilled']) {
         $action['id'] = $payment_transaction;
         $action['type'] = 'complete_payment';
         $action['transaction_id'] = $payment_transaction;
         $action['amount'] = $payment_amount;
         $action['entry_id'] = $entry['id'];
         $this->complete_payment($entry, $action);
         $this->fulfill_order($entry, $payment_transaction, $payment_amount);
     }
     //update lead, add a note
     GFAPI::update_entry($entry);
     GFFormsModel::add_note($entry['id'], $user_id, $user_name, sprintf(__('Payment information was manually updated. Status: %s. Amount: %s. Transaction Id: %s. Date: %s', 'gravityformspaypal'), $entry['payment_status'], GFCommon::to_money($entry['payment_amount'], $entry['currency']), $payment_transaction, $entry['payment_date']));
 }
    public static function payment_details_box($lead, $form)
    {
        ?>
		<!-- PAYMENT BOX -->
		<div id="submitdiv" class="stuffbox">
			<h3 class="hndle" style="cursor:default;">
                <span><?php 
        echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Details', 'gravityforms') : esc_html__('Payment Details', 'gravityforms');
        ?>
</span>
			</h3>

			<div class="inside">
				<div id="submitcomment" class="submitbox">
					<div id="minor-publishing" style="padding:10px;">
						<?php 
        $payment_status = apply_filters('gform_payment_status', $lead['payment_status'], $form, $lead);
        if (!empty($payment_status)) {
            ?>
							<div id="gf_payment_status" class="gf_payment_detail">
								<?php 
            esc_html_e('Status', 'gravityforms');
            ?>
:
								<span id="gform_payment_status"><?php 
            echo $payment_status;
            // May contain HTML
            ?>
</span>
							</div>

							<?php 
            $payment_date = apply_filters('gform_payment_date', GFCommon::format_date($lead['payment_date'], false, 'Y/m/d', $lead['transaction_type'] != 2), $form, $lead);
            if (!empty($payment_date)) {
                ?>
								<div id="gf_payment_date" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Start Date', 'gravityforms') : esc_html__('Date', 'gravityforms');
                ?>
:
									<span id='gform_payment_date'><?php 
                echo $payment_date;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            $transaction_id = apply_filters('gform_payment_transaction_id', $lead['transaction_id'], $form, $lead);
            if (!empty($transaction_id)) {
                ?>
								<div id="gf_payment_transaction_id" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Subscription Id', 'gravityforms') : esc_html__('Transaction Id', 'gravityforms');
                ?>
:
									<span id='gform_payment_transaction_id'><?php 
                echo $transaction_id;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
            $payment_amount = apply_filters('gform_payment_amount', GFCommon::to_money($lead['payment_amount'], $lead['currency']), $form, $lead);
            if (!rgblank($payment_amount)) {
                ?>
								<div id="gf_payment_amount" class="gf_payment_detail">
									<?php 
                echo $lead['transaction_type'] == 2 ? esc_html__('Recurring Amount', 'gravityforms') : esc_html__('Amount', 'gravityforms');
                ?>
:
									<span id='gform_payment_amount'><?php 
                echo $payment_amount;
                // May contain HTML
                ?>
</span>
								</div>
							<?php 
            }
        }
        do_action('gform_payment_details', $form['id'], $lead);
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
Beispiel #30
0
    public static function lead_detail_grid($form, $lead, $allow_display_empty_fields = false)
    {
        $form_id = $form["id"];
        $display_empty_fields = false;
        if ($allow_display_empty_fields) {
            $display_empty_fields = rgget("gf_display_empty_fields", $_COOKIE);
        }
        ?>
        <table cellspacing="0" class="widefat fixed entry-detail-view">
            <thead>
                <tr>
                    <th id="details">
                    <?php 
        echo $form["title"];
        ?>
 : <?php 
        _e("Entry # ", "gravityforms");
        ?>
 <?php 
        echo $lead["id"];
        ?>
                    </th>
                    <th style="width:140px; font-size:10px; text-align: right;">
                    <?php 
        if ($allow_display_empty_fields) {
            ?>
                            <input type="checkbox" id="gentry_display_empty_fields" <?php 
            echo $display_empty_fields ? "checked='checked'" : "";
            ?>
 onclick="ToggleShowEmptyFields();"/>&nbsp;&nbsp;<label for="gentry_display_empty_fields"><?php 
            _e("show empty fields", "gravityforms");
            ?>
</label>
                            <?php 
        }
        ?>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php 
        $count = 0;
        $field_count = sizeof($form["fields"]);
        $has_product_fields = false;
        foreach ($form["fields"] as $field) {
            switch (RGFormsModel::get_input_type($field)) {
                case "section":
                    if (!GFCommon::is_section_empty($field, $form, $lead) || $display_empty_fields) {
                        $count++;
                        $is_last = $count >= $field_count ? true : false;
                        ?>
                                <tr>
                                    <td colspan="2" class="entry-view-section-break<?php 
                        echo $is_last ? " lastrow" : "";
                        ?>
"><?php 
                        echo esc_html(GFCommon::get_label($field));
                        ?>
</td>
                                </tr>
                                <?php 
                    }
                    break;
                case "captcha":
                case "html":
                case "password":
                case "page":
                    //ignore captcha, html, password, page field
                    break;
                default:
                    //ignore product fields as they will be grouped together at the end of the grid
                    if (GFCommon::is_product_field($field["type"])) {
                        $has_product_fields = true;
                        continue;
                    }
                    $value = RGFormsModel::get_lead_field_value($lead, $field);
                    $display_value = GFCommon::get_lead_field_display($field, $value, $lead["currency"]);
                    $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $lead, $form);
                    if ($display_empty_fields || !empty($display_value) || $display_value === "0") {
                        $count++;
                        $is_last = $count >= $field_count && !$has_product_fields ? true : false;
                        $last_row = $is_last ? " lastrow" : "";
                        $display_value = empty($display_value) && $display_value !== "0" ? "&nbsp;" : $display_value;
                        $content = '
                                <tr>
                                    <td colspan="2" class="entry-view-field-name">' . esc_html(GFCommon::get_label($field)) . '</td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="entry-view-field-value' . $last_row . '">' . $display_value . '</td>
                                </tr>';
                        $content = apply_filters("gform_field_content", $content, $field, $value, $lead["id"], $form["id"]);
                        echo $content;
                    }
                    break;
            }
        }
        $products = array();
        if ($has_product_fields) {
            $products = GFCommon::get_product_fields($form, $lead);
            if (!empty($products["products"])) {
                ?>
                        <tr>
                            <td colspan="2" class="entry-view-field-name"><?php 
                echo apply_filters("gform_order_label_{$form["id"]}", apply_filters("gform_order_label", __("Order", "gravityforms"), $form["id"]), $form["id"]);
                ?>
</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="entry-view-field-value lastrow">
                                <table class="entry-products" cellspacing="0" width="97%">
                                    <colgroup>
                                          <col class="entry-products-col1">
                                          <col class="entry-products-col2">
                                          <col class="entry-products-col3">
                                          <col class="entry-products-col4">
                                    </colgroup>
                                    <thead>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_{$form_id}", apply_filters("gform_product", __("Product", "gravityforms"), $form_id), $form_id);
                ?>
</th>
                                        <th scope="col" class="textcenter"><?php 
                echo apply_filters("gform_product_qty_{$form_id}", apply_filters("gform_product_qty", __("Qty", "gravityforms"), $form_id), $form_id);
                ?>
</th>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_unitprice_{$form_id}", apply_filters("gform_product_unitprice", __("Unit Price", "gravityforms"), $form_id), $form_id);
                ?>
</th>
                                        <th scope="col"><?php 
                echo apply_filters("gform_product_price_{$form_id}", apply_filters("gform_product_price", __("Price", "gravityforms"), $form_id), $form_id);
                ?>
</th>
                                    </thead>
                                    <tbody>
                                    <?php 
                $total = 0;
                foreach ($products["products"] as $product) {
                    ?>
                                            <tr>
                                                <td>
                                                    <div class="product_name"><?php 
                    echo $product["name"];
                    ?>
</div>
                                                    <ul class="product_options">
                                                        <?php 
                    $price = GFCommon::to_number($product["price"]);
                    if (is_array(rgar($product, "options"))) {
                        $count = sizeof($product["options"]);
                        $index = 1;
                        foreach ($product["options"] as $option) {
                            $price += GFCommon::to_number($option["price"]);
                            $class = $index == $count ? " class='lastitem'" : "";
                            $index++;
                            ?>
                                                                <li<?php 
                            echo $class;
                            ?>
><?php 
                            echo $option["option_label"];
                            ?>
</li>
                                                                <?php 
                        }
                    }
                    $subtotal = floatval($product["quantity"]) * $price;
                    $total += $subtotal;
                    ?>
                                                    </ul>
                                                </td>
                                                <td class="textcenter"><?php 
                    echo $product["quantity"];
                    ?>
</td>
                                                <td><?php 
                    echo GFCommon::to_money($price, $lead["currency"]);
                    ?>
</td>
                                                <td><?php 
                    echo GFCommon::to_money($subtotal, $lead["currency"]);
                    ?>
</td>
                                            </tr>
                                            <?php 
                }
                $total += floatval($products["shipping"]["price"]);
                ?>
                                    </tbody>
                                    <tfoot>
                                        <?php 
                if (!empty($products["shipping"]["name"])) {
                    ?>
                                            <tr>
                                                <td colspan="2" rowspan="2" class="emptycell">&nbsp;</td>
                                                <td class="textright shipping"><?php 
                    echo $products["shipping"]["name"];
                    ?>
</td>
                                                <td class="shipping_amount"><?php 
                    echo GFCommon::to_money($products["shipping"]["price"], $lead["currency"]);
                    ?>
&nbsp;</td>
                                            </tr>
                                        <?php 
                }
                ?>
                                        <tr>
                                            <?php 
                if (empty($products["shipping"]["name"])) {
                    ?>
                                                <td colspan="2" class="emptycell">&nbsp;</td>
                                            <?php 
                }
                ?>
                                            <td class="textright grandtotal"><?php 
                _e("Total", "gravityforms");
                ?>
</td>
                                            <td class="grandtotal_amount"><?php 
                echo GFCommon::to_money($total, $lead["currency"]);
                ?>
</td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </td>
                        </tr>

                        <?php 
            }
        }
        ?>
            </tbody>
        </table>
        <?php 
    }