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&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&height=250&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') ? '¬es=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"> </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"> </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); ?> <?php do_action('gform_entries_column', $form_id, $field_id, $value, $lead, $query_string); ?> </td> <?php } $is_first_column = false; } ?> <td> </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 display_survey_fields_on_entry_detail($value, $field, $lead, $form) { if (rgar($field, 'type') !== 'survey') { return $value; } $new_value = $value; $field_type = GFFormsModel::get_input_type($field); switch ($field_type) { case 'likert': $new_value = $this->get_survey_field_content('', $field, $value, $lead['id'], $form['id'], $lead); // if original response is not in results display below // TODO - handle orphaned responses (original choice is deleted) break; case 'rank': $new_value = $this->get_rank_entry_value_formatted($field, $value); break; case 'rating': $new_value = GFCommon::selection_display($value, $field, $currency = '', $use_text = true); break; case 'radio': case 'checkbox': case 'select': if (isset($field['inputs']) && is_array($field['inputs'])) { foreach ($field['choices'] as $choice) { $val = rgar($choice, 'value'); $text = RGFormsModel::get_choice_text($field, $val); $new_value = str_replace($val, $text, $new_value); } } else { $new_value = RGFormsModel::get_choice_text($field, $value); } break; } return $new_value; }
public static function is_duplicate($form_id, $field, $value) { global $wpdb; $lead_detail_table_name = self::get_lead_details_table_name(); $lead_table_name = self::get_lead_table_name(); $lead_detail_long = self::get_lead_details_long_table_name(); $is_long = !is_array($value) && strlen($value) > GFORMS_MAX_FIELD_LENGTH - 10; $sql_comparison = $is_long ? '( ld.value = %s OR ldl.value = %s )' : 'ld.value = %s'; switch (GFFormsModel::get_input_type($field)) { case 'time': $value = sprintf("%02d:%02d %s", $value[0], $value[1], $value[2]); break; case 'date': $value = self::prepare_date($field->dateFormat, $value); break; case 'number': $value = GFCommon::clean_number($value, $field->numberFormat); break; case 'phone': $value = str_replace(array(')', '(', '-', ' '), '', $value); $sql_comparison = 'replace( replace( replace( replace( ld.value, ")", "" ), "(", "" ), "-", "" ), " ", "" ) = %s'; break; case 'email': $value = is_array($value) ? rgar($value, 0) : $value; break; } $inner_sql_template = "SELECT %s as input, ld.lead_id\n FROM {$lead_detail_table_name} ld\n INNER JOIN {$lead_table_name} l ON l.id = ld.lead_id\n"; if ($is_long) { $inner_sql_template .= "INNER JOIN {$lead_detail_long} ldl ON ldl.lead_detail_id = ld.id\n"; } $inner_sql_template .= "WHERE l.form_id=%d AND ld.form_id=%d\n AND ld.field_number between %s AND %s\n AND status='active' AND {$sql_comparison}"; $sql = "SELECT count(distinct input) as match_count FROM ( "; $input_count = 1; if (is_array($field->get_entry_inputs())) { $input_count = sizeof($field->inputs); foreach ($field->inputs as $input) { $union = empty($inner_sql) ? '' : ' UNION ALL '; $inner_sql .= $union . $wpdb->prepare($inner_sql_template, $input['id'], $form_id, $form_id, $input['id'] - 0.0001, $input['id'] + 0.0001, $value[$input['id']], $value[$input['id']]); } } else { $inner_sql = $wpdb->prepare($inner_sql_template, $field->id, $form_id, $form_id, doubleval($field->id) - 0.0001, doubleval($field->id) + 0.0001, $value, $value); } $sql .= $inner_sql . "\n ) as count\n GROUP BY lead_id\n ORDER BY match_count DESC"; $count = gf_apply_filters('gform_is_duplicate', $form_id, $wpdb->get_var($sql), $form_id, $field, $value); return $count != null && $count >= $input_count; }
public function get_results_data($form, $fields, $search_criteria = array(), $state_array = array(), $max_execution_time = 15) { // todo: add hooks to modify $max_execution_time and $page_size? $page_size = 150; $time_start = microtime(true); $form_id = $form["id"]; $data = array(); $offset = 0; $entry_count = 0; $field_data = array(); if ($state_array) { //get counts from state $data = $state_array; $offset = (int) rgar($data, "offset"); unset($data["offset"]); $entry_count = $offset; $field_data = rgar($data, "field_data"); } else { //initialize counts foreach ($fields as $field) { $field_type = GFFormsModel::get_input_type($field); if (false === isset($field["choices"])) { $field_data[$field["id"]] = 0; continue; } $choices = $field["choices"]; if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) { foreach ($field["gsurveyLikertRows"] as $row) { foreach ($choices as $choice) { $field_data[$field["id"]][$row["value"]][$choice['value']] = 0; } } } else { foreach ($choices as $choice) { $field_data[$field["id"]][$choice['value']] = 0; } } if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableScoring")) { $field_data[$field["id"]]["sum_of_scores"] = 0; } } } $count_search_leads = GFAPI::count_entries($form_id, $search_criteria); $data["entry_count"] = $count_search_leads; $entries_left = $count_search_leads - $offset; while ($entries_left >= 0) { $paging = array('offset' => $offset, 'page_size' => $page_size); $search_leads_time_start = microtime(true); $leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging); $search_leads_time_end = microtime(true); $search_leads_time = $search_leads_time_end - $search_leads_time_start; $leads_in_search = count($leads); $entry_count += $leads_in_search; foreach ($leads as $lead) { foreach ($fields as $field) { $field_type = GFFormsModel::get_input_type($field); $field_id = $field["id"]; $value = RGFormsModel::get_lead_field_value($lead, $field); if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) { if (empty($value)) { continue; } foreach ($value as $value_vector) { if (empty($value_vector)) { continue; } list($row_val, $col_val) = explode(":", $value_vector, 2); if (isset($field_data[$field["id"]][$row_val]) && isset($field_data[$field["id"]][$row_val][$col_val])) { $field_data[$field["id"]][$row_val][$col_val]++; } } } elseif ($field_type == "rank") { $score = count(rgar($field, "choices")); $values = explode(",", $value); foreach ($values as $ranked_value) { $field_data[$field["id"]][$ranked_value] += $score; $score--; } } else { if (false === isset($field["choices"])) { if (false === empty($value)) { $field_data[$field_id]++; } continue; } $choices = $field["choices"]; foreach ($choices as $choice) { $choice_is_selected = false; if (is_array($value)) { $choice_value = rgar($choice, "value"); if (in_array($choice_value, $value)) { $choice_is_selected = true; } } else { if (RGFormsModel::choice_value_match($field, $choice, $value)) { $choice_is_selected = true; } } if ($choice_is_selected) { $field_data[$field_id][$choice['value']]++; } } } if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableScoring")) { $field_data[$field["id"]]["sum_of_scores"] += $this->get_likert_score($field, $lead); } } } $data["field_data"] = $field_data; if (isset($this->_callbacks["calculation"])) { $data = call_user_func($this->_callbacks["calculation"], $data, $form, $fields, $leads); $field_data = $data["field_data"]; } $offset += $page_size; $entries_left -= $page_size; $time_end = microtime(true); $execution_time = $time_end - $time_start; if ($entries_left > 0 && $execution_time + $search_leads_time > $max_execution_time) { $data["status"] = "incomplete"; $data["offset"] = $offset; $progress = $data["entry_count"] > 0 ? round($data["offset"] / $data["entry_count"] * 100) : 0; $data["progress"] = $progress; break; } if ($entries_left <= 0) { $data["status"] = "complete"; } } $data["timestamp"] = time(); return $data; }
public function results_data_add_labels($form, $fields) { // replace the values/ids with text labels foreach ($fields as $field_id => $choice_counts) { $field = GFFormsModel::get_field($form, $field_id); $type = GFFormsModel::get_input_type($field); if (is_array($choice_counts)) { $i = 0; foreach ($choice_counts as $choice_value => $choice_count) { if (class_exists("GFSurvey") && "likert" == $type && rgar($field, "gsurveyLikertEnableMultipleRows")) { $row_text = GFSurvey::get_likert_row_text($field, $i++); $counts_for_row = array(); foreach ($choice_count as $col_val => $col_count) { $text = GFSurvey::get_likert_column_text($field, $choice_value . ":" . $col_val); $counts_for_row[$col_val] = array("text" => $text, "data" => $col_count); } $counts_for_row[$choice_value]["data"] = $counts_for_row; $fields[$field_id][$choice_value] = array("text" => $row_text, "value" => "{$choice_value}", "count" => $counts_for_row); } else { $text = GFFormsModel::get_choice_text($field, $choice_value); $fields[$field_id][$choice_value] = array("text" => $text, "value" => "{$choice_value}", "count" => $choice_count); } } } } return $fields; }
/** * Retrieve an array of form fields formatted for select, radio and checkbox settings fields. * * @access public * @param array $form - The form object * @param array $args - Additional settings to check for (field and input types to include, callback for applicable input type) * * @return array The array of formatted form fields */ public function get_form_fields_as_choices($form, $args = array()) { $fields = array(); if (!is_array($form['fields'])) { return $fields; } $args = wp_parse_args($args, array('field_types' => array(), 'input_types' => array(), 'callback' => false)); foreach ($form['fields'] as $field) { $input_type = GFFormsModel::get_input_type($field); $is_applicable_input_type = empty($args['input_types']) || in_array($input_type, $args['input_types']); if (is_callable($args['callback'])) { $is_applicable_input_type = call_user_func($args['callback'], $is_applicable_input_type, $field, $form); } if (!$is_applicable_input_type) { continue; } if (!empty($args['property']) && (!isset($field->{$args}['property']) || $field->{$args}['property'] != $args['property_value'])) { continue; } $inputs = $field->get_entry_inputs(); if (is_array($inputs)) { // if this is an address field, add full name to the list if ($input_type == 'address') { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')'); } // if this is a name field, add full name to the list if ($input_type == 'name') { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')'); } // if this is a checkbox field, add to the list if ($input_type == 'checkbox') { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Selected', 'gravityforms') . ')'); } foreach ($inputs as $input) { $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id'])); } } elseif ($input_type == 'list' && $field->enableColumns) { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . esc_html__('Full', 'gravityforms') . ')'); $col_index = 0; foreach ($field->choices as $column) { $fields[] = array('value' => $field->id . '.' . $col_index, 'label' => GFCommon::get_label($field) . ' (' . rgar($column, 'text') . ')'); $col_index++; } } elseif (!$field->displayOnly) { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field)); } else { $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field)); } } return $fields; }
/** * Add input field for credit card token response. * * @access public * * @param string $content * @param array $field * @param string $value * @param string $entry_id * @param string $form_id * * @return string */ public function add_creditcard_token_input($content, $field, $value, $entry_id, $form_id) { if (!$this->has_feed($form_id) || GFFormsModel::get_input_type($field) != 'creditcard') { return $content; } $form = GFAPI::get_form($form_id); if (!$this->creditcard_token_info($form)) { return $content; } $slug = str_replace('gravityforms', '', $this->_slug); $content .= '<input type=\'hidden\' name=\'' . $slug . '_response\' id=\'gf_' . $slug . '_response\' value=\'' . rgpost($slug . '_response') . '\' />'; return $content; }
/** * Generates a map of fields IDs and their corresponding number formats used by the GFCalc JS object for correctly * converting field values to clean numbers. * * - Number fields have a 'numberFormat' setting (w/ UI). * - Single-input product fields (i.e. 'singleproduct', 'calculation', 'price' and 'hiddenproduct') should default to * the number format of the configured currency. * - All other product fields will default to 'decimal_dot' for the number format. * - All other fields will have no format (false) and inherit the format of the formula field when the formula is * calculated. * * @param mixed $form */ public static function get_number_formats_script( $form ) { $number_formats = array(); $currency = RGCurrency::get_currency( GFCommon::get_currency() ); foreach( $form['fields'] as $field ) { // default format is false, fields with no format will inherit the format of the formula field when calculated $format = false; switch( GFFormsModel::get_input_type( $field ) ) { case 'number': $format = rgar( $field, 'numberFormat' ) ? rgar( $field, 'numberFormat' ) : 'decimal_dot'; break; case 'singleproduct': case 'singleproduct': case 'calculation': case 'price': case 'hiddenproduct': case 'singleshipping': $format = $currency['decimal_separator'] == ',' ? 'decimal_comma' : 'decimal_dot'; break; default: // we check above for all single-input product types, for all other products, assume decimal format if( in_array( $field['type'], array( 'product', 'option', 'shipping' ) ) ) $format = 'decimal_dot'; } $number_formats[$field['id']] = $format; } return 'gf_global["number_formats"][' . $form['id'] . '] = ' . json_encode( $number_formats ) . ';'; }
public static function get_field_filter_settings($form) { $all_fields = $form["fields"]; // set up filters $fields = $all_fields; $exclude_types = array("rank", "page", "html"); $operators_by_field_type = array("default" => array("is", "isnot", ">", "<"), "checkbox" => array("is"), "multiselect" => array("contains"), "number" => array("is", "isnot", ">", "<"), "likert" => array("is", "isnot"), "list" => array("contains")); for ($i = 0; $i < count($all_fields); $i++) { $field_type = GFFormsmodel::get_input_type($all_fields[$i]); if (in_array($field_type, $exclude_types)) { unset($fields[$i]); } } $fields = array_values($fields); $field_filters = array(array("key" => "0", "text" => __("Any form field", "gravityforms"), "operators" => array("contains", "is"))); foreach ($fields as $field) { $field_type = GFFormsModel::get_input_type($field); $operators = isset($operators_by_field_type[$field_type]) ? $operators_by_field_type[$field_type] : $operators_by_field_type["default"]; if (!isset($field["choices"]) && !in_array("contains", $operators)) { $operators[] = "contains"; } $field_filter = array(); $key = $field["id"]; if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) { // multi-row likert fields $field_filter["key"] = $key; $field_filter["group"] = true; $field_filter["text"] = GFFormsModel::get_label($field); $sub_filters = array(); $rows = rgar($field, "gsurveyLikertRows"); foreach ($rows as $row) { $sub_filter = array(); $sub_filter["key"] = $key . "|" . rgar($row, "value"); $sub_filter["text"] = rgar($row, "text"); $sub_filter["type"] = "field"; $sub_filter["preventMultiple"] = false; $sub_filter["operators"] = $operators; $sub_filter["values"] = $field["choices"]; $sub_filters[] = $sub_filter; } $field_filter["filters"] = $sub_filters; } elseif ($field_type == "name" && rgar($field, "nameFormat") == "" || $field_type == "address") { // standard two input name field $field_filter["key"] = $key; $field_filter["group"] = true; $field_filter["text"] = GFFormsModel::get_label($field); $sub_filters = array(); $inputs = rgar($field, "inputs"); foreach ($inputs as $input) { $sub_filter = array(); $sub_filter["key"] = rgar($input, "id"); $sub_filter["text"] = rgar($input, "label"); $sub_filter["preventMultiple"] = false; $sub_filter["operators"] = $operators; $sub_filters[] = $sub_filter; } $field_filter["filters"] = $sub_filters; } else { $field_filter["key"] = $key; $field_filter["preventMultiple"] = false; $field_filter["text"] = GFFormsModel::get_label($field); $field_filter["operators"] = $operators; if (isset($field["choices"])) { $field_filter["values"] = $field["choices"]; } } $field_filters[] = $field_filter; } $form_id = $form["id"]; $entry_meta_filters = self::get_entry_meta_filter_settings($form_id); $field_filters = array_merge($field_filters, $entry_meta_filters); $field_filters = array_values($field_filters); // reset the numeric keys in case some filters have been unset $info_filters = self::get_entry_info_filter_settings(); $field_filters = array_merge($field_filters, $info_filters); $field_filters = array_values($field_filters); return $field_filters; }
public function get_conditional_logic_fields() { $form = $this->get_current_form(); $fields = array(); foreach ($form['fields'] as $field) { $type = GFFormsModel::get_input_type($field); $conditional_logic_fields = array('checkbox', 'radio', 'select', 'text', 'website', 'textarea', 'email', 'hidden', 'number', 'phone', 'multiselect', 'post_title', 'post_tags', 'post_custom_field', 'post_content', 'post_excerpt'); if (in_array($type, $conditional_logic_fields)) { $fields[] = array('value' => $field['id'], 'label' => $field['label']); } } return $fields; }
/** * Returns the array of search criteria. * * @return array */ function get_search_criteria() { $search_criteria = array(); $filter_links = $this->get_filter_links(false); foreach ($filter_links as $filter_link) { if ($this->filter == $filter_link['id']) { $search_criteria['field_filters'] = $filter_link['field_filters']; break; } } $search_field_id = rgget('field_id'); $search_operator = rgget('operator'); $status = in_array($this->filter, array('trash', 'spam')) ? $this->filter : 'active'; $search_criteria['status'] = $status; 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; $form = $this->get_form(); $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); } $form_id = $this->get_form_id(); /** * Allow the entry list search criteria to be overridden. * * @since 1.9.14.30 * * @param array $search_criteria An array containing the search criteria. * @param int $form_id The ID of the current form. */ $search_criteria = gf_apply_filters(array('gform_search_criteria_entry_list', $form_id), $search_criteria, $form_id); return $search_criteria; }
private static function get_conditional_logic($form, $field_values = array()) { $logics = ""; $dependents = ""; $fields_with_logic = array(); $default_values = array(); foreach ($form["fields"] as $field) { //use section's logic if one exists $section = RGFormsModel::get_section($form, $field["id"]); $section_logic = !empty($section) ? rgar($section, "conditionalLogic") : null; $field_logic = $field["type"] != "page" ? RGForms::get("conditionalLogic", $field) : null; //page break conditional logic will be handled during the next button click $next_button_logic = isset($field["nextButton"]) && isset($field["nextButton"]["conditionalLogic"]) ? $field["nextButton"]["conditionalLogic"] : null; if (!empty($field_logic) || !empty($next_button_logic)) { $field_section_logic = array("field" => $field_logic, "nextButton" => $next_button_logic, "section" => $section_logic); $logics .= $field["id"] . ": " . GFCommon::json_encode($field_section_logic) . ","; $fields_with_logic[] = $field["id"]; $peers = $field["type"] == "section" ? GFCommon::get_section_fields($form, $field["id"]) : array($field); $peer_ids = array(); foreach ($peers as $peer) { $peer_ids[] = $peer["id"]; } $dependents .= $field["id"] . ": " . GFCommon::json_encode($peer_ids) . ","; } //-- Saving default values so that they can be restored when toggling conditional logic --- $field_val = ""; $input_type = RGFormsModel::get_input_type($field); //get parameter value if pre-populate is enabled if (rgar($field, "allowsPrepopulate")) { if (is_array(rgar($field, "inputs"))) { $field_val = array(); foreach ($field["inputs"] as $input) { $field_val["input_{$input["id"]}"] = RGFormsModel::get_parameter_value(rgar($input, "name"), $field_values, $field); } } else { if ($input_type == "time") { $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field_values, $field); if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) { $field_val = array(); $field_val[] = esc_attr($matches[1]); //hour $field_val[] = esc_attr($matches[2]); //minute $field_val[] = rgar($matches, 3); //am or pm } } else { if ($input_type == "list") { $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field_values, $field); $field_val = is_array($parameter_val) ? $parameter_val : explode(",", str_replace("|", ",", $parameter_val)); } else { $field_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field_values, $field); } } } } //use default value if pre-populated value is empty $field_val = self::default_if_empty($field, $field_val); if (is_array(rgar($field, "choices")) && $input_type != "list") { //radio buttons start at 0 and checkboxes start at 1 $choice_index = $input_type == "radio" ? 0 : 1; foreach ($field["choices"] as $choice) { if (rgar($choice, "isSelected") && $input_type == "select") { $val = isset($choice["price"]) ? $choice["value"] . "|" . GFCommon::to_number($choice["price"]) : $choice["value"]; $default_values[$field["id"]] = $val; } else { if (rgar($choice, "isSelected")) { if (!isset($default_values[$field["id"]])) { $default_values[$field["id"]] = array(); } $default_values[$field["id"]][] = "choice_{$field["id"]}_{$choice_index}"; } } $choice_index++; } } else { if (!empty($field_val)) { if (GFFormsModel::get_input_type($field) == "date") { //format date $format = empty($field["dateFormat"]) ? "mdy" : esc_attr($field["dateFormat"]); $date_info = GFcommon::parse_date($field_val, $format); switch ($format) { case "mdy": $field_val = $date_info["month"] . "/" . $date_info["day"] . "/" . $date_info["year"]; break; case "dmy": $field_val = $date_info["day"] . "/" . $date_info["month"] . "/" . $date_info["year"]; break; case "ymd": $field_val = $date_info["year"] . "/" . $date_info["month"] . "/" . $date_info["day"]; break; } } $default_values[$field["id"]] = $field_val; } } } $button_conditional_script = ""; //adding form button conditional logic if enabled if (isset($form["button"]["conditionalLogic"])) { $logics .= "0: " . GFCommon::json_encode(array("field" => $form["button"]["conditionalLogic"], "section" => null)) . ","; $dependents .= "0: " . GFCommon::json_encode(array(0)) . ","; $fields_with_logic[] = 0; $button_conditional_script = "jQuery('#gform_{$form['id']}').submit(" . "function(event, isButtonPress){" . " var visibleButton = jQuery('.gform_next_button:visible, .gform_button:visible, .gform_image_button:visible');" . " return visibleButton.length > 0 || isButtonPress == true;" . "}" . ");"; } if (!empty($logics)) { $logics = substr($logics, 0, strlen($logics) - 1); } //removing last comma; if (!empty($dependents)) { $dependents = substr($dependents, 0, strlen($dependents) - 1); } //removing last comma; $animation = rgar($form, "enableAnimation") ? "1" : "0"; global $wp_locale; $number_format = $wp_locale->number_format['decimal_point'] == "," ? "decimal_comma" : "decimal_dot"; $str = "if(window['jQuery']){" . "if(!window['gf_form_conditional_logic'])" . "window['gf_form_conditional_logic'] = new Array();" . "window['gf_form_conditional_logic'][{$form['id']}] = {'logic' : {" . $logics . " }, 'dependents' : {" . $dependents . " }, 'animation' : " . $animation . " , 'defaults' : " . json_encode($default_values) . " }; " . "if(!window['gf_number_format'])" . "window['gf_number_format'] = '" . $number_format . "';" . "jQuery(document).ready(function(){" . "gf_apply_rules({$form['id']}, " . json_encode($fields_with_logic) . ", true);" . "jQuery('#gform_wrapper_{$form['id']}').show();" . "jQuery(document).trigger('gform_post_conditional_logic', [{$form['id']}, null, true]);" . $button_conditional_script . "} );" . "} "; return $str; }
public function pre_render($form) { $poll_fields = GFCommon::get_fields_by_type($form, array('poll')); if (false === empty($poll_fields)) { $form_css = 'gpoll_enabled'; $show_results_link = $this->get_form_setting($form, 'showResultsLink'); if ($show_results_link) { $form_css .= ' gpoll_show_results_link'; } $block_repeat_voters = $this->get_form_setting($form, 'blockRepeatVoters'); if ($block_repeat_voters && rgget('gf_page') != 'preview') { $form_css .= ' gpoll_block_repeat_voters'; } $form['cssClass'] = empty($form['cssClass']) ? $form_css . ' gpoll' : $form_css . ' ' . $form['cssClass']; if (isset($form['fields']) && false === empty($form['fields'])) { foreach ($form['fields'] as &$field) { if ('poll' != rgar($field, 'type')) { continue; } $input_type = GFFormsModel::get_input_type($field); if ('select' == $input_type) { $choices = $field['choices']; if (isset($choices) && is_array($choices)) { array_unshift($choices, array('isSelected' => true, 'text' => __('Select one', 'gravityformspolls'), 'value' => '')); $field['choices'] = $choices; } } } } } return $form; }
private function _get_random_value($field) { $type = GFFormsModel::get_input_type($field); switch ($type) { case "number": $value = rand(0, 10); break; case "date": $value = date('Y-m-d', strtotime('+' . mt_rand(0, 30) . ' days')); break; case "time": $ampm = array("am", "pm"); $value = sprintf("%02d:%02d %s", rand(1, 12), rand(1, 60), $ampm[array_rand($ampm)]); break; case "list": $value = serialize(array("testvalue" . uniqid(), "testvalue" . uniqid(), "testvalue" . uniqid())); break; case "website": $value = "http://website" . uniqid() . ".com"; break; case "phone": $value = sprintf("(%03d)%03d-%04d", rand(1, 999), rand(1, 999), rand(1, 9999)); break; default: $value = "testvalue" . uniqid(); } return $value; }
/** * Add address contact data to person. * * @access public * @param array $person * @param array $feed * @param array $entry * @param array $form * @param bool $check_for_existing (default: false) * @return array $person */ public function add_person_address_data($person, $feed, $entry, $form, $check_for_existing = false) { $person_custom_fields = $this->get_dynamic_field_map_fields($feed, 'person_custom_fields'); /* Add any mapped addresses. */ foreach ($person_custom_fields as $field_key => $field) { /* If this is not an address mapped field, move on. */ if (strpos($field_key, 'address_') !== 0) { continue; } $address_field = GFFormsModel::get_field($form, $field); /* If the selected field is not an address field, move on. */ if (GFFormsModel::get_input_type($address_field) !== 'address') { continue; } /* Prepare the type field. */ $type = ucfirst(str_replace('address_', '', $field_key)); /* Get the address field ID. */ $address_field_id = $address_field->id; /* If any of the fields are empty, move on. */ if (rgblank($entry[$address_field_id . '.1']) || rgblank($entry[$address_field_id . '.3']) || rgblank($entry[$address_field_id . '.4']) || rgblank($entry[$address_field_id . '.5'])) { continue; } /* Check if this address is already in the address data. */ if ($check_for_existing && !empty($person['contacts']['address']) && $this->exists_in_array($person['contacts']['address'], 'street', $entry[$address_field_id . '.1'] . ' ' . $entry[$address_field_id . '.2'])) { continue; } /* Add the address to the contact. */ $person['contacts']['address'][] = array('type' => $type, 'street' => $entry[$address_field_id . '.1'] . ' ' . $entry[$address_field_id . '.2'], 'city' => $entry[$address_field_id . '.3'], 'state' => $entry[$address_field_id . '.4'], 'zip' => $entry[$address_field_id . '.5'], 'country' => $entry[$address_field_id . '.6']); } return $person; }
/** * Updates an entire single Entry object. * * If the date_created value is not set then the current time UTC will be used. * The date_created value, if set, is expected to be in 'Y-m-d H:i:s' format (UTC). * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * @param int $entry_id Optional. If specified, the ID in the Entry object will be ignored * * @return mixed Either True or a WP_Error instance */ public static function update_entry($entry, $entry_id = null) { global $wpdb; if (empty($entry_id)) { if (rgar($entry, 'id')) { $entry_id = absint($entry['id']); } } else { $entry['id'] = absint($entry_id); } if (empty($entry_id)) { return new WP_Error('missing_entry_id', __('Missing entry id', 'gravityforms')); } $current_entry = $original_entry = self::get_entry($entry_id); if (!$current_entry) { return new WP_Error('not_found', __('Entry not found', 'gravityforms'), $entry_id); } if (is_wp_error($current_entry)) { return $current_entry; } // make sure the form id exists $form_id = rgar($entry, 'form_id'); if (empty($form_id)) { $form_id = rgar($current_entry, 'form_id'); } if (false === self::form_id_exists($form_id)) { return new WP_Error('invalid_form_id', __('The form for this entry does not exist', 'gravityforms')); } $entry = apply_filters('gform_entry_pre_update', $entry, $original_entry); // use values in the entry object if present $post_id = isset($entry['post_id']) ? intval($entry['post_id']) : 'NULL'; $date_created = isset($entry['date_created']) ? sprintf("'%s'", esc_sql($entry['date_created'])) : 'utc_timestamp()'; $is_starred = isset($entry['is_starred']) ? $entry['is_starred'] : 0; $is_read = isset($entry['is_read']) ? $entry['is_read'] : 0; $ip = isset($entry['ip']) ? $entry['ip'] : GFFormsModel::get_ip(); $source_url = isset($entry['source_url']) ? $entry['source_url'] : GFFormsModel::get_current_page_url(); $user_agent = isset($entry['user_agent']) ? $entry['user_agent'] : 'API'; $currency = isset($entry['currency']) ? $entry['currency'] : GFCommon::get_currency(); $payment_status = isset($entry['payment_status']) ? sprintf("'%s'", esc_sql($entry['payment_status'])) : 'NULL'; $payment_date = strtotime(rgar($entry, 'payment_date')) ? "'" . gmdate('Y-m-d H:i:s', strtotime("{$entry['payment_date']}")) . "'" : 'NULL'; $payment_amount = isset($entry['payment_amount']) ? (double) $entry['payment_amount'] : 'NULL'; $payment_method = isset($entry['payment_method']) ? $entry['payment_method'] : ''; $transaction_id = isset($entry['transaction_id']) ? sprintf("'%s'", esc_sql($entry['transaction_id'])) : 'NULL'; $is_fulfilled = isset($entry['is_fulfilled']) ? intval($entry['is_fulfilled']) : 'NULL'; $status = isset($entry['status']) ? $entry['status'] : 'active'; global $current_user; $user_id = isset($entry['created_by']) ? absint($entry['created_by']) : ''; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? absint($current_user->ID) : 'NULL'; } $transaction_type = isset($entry['transaction_type']) ? intval($entry['transaction_type']) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $sql = $wpdb->prepare("\n UPDATE {$lead_table}\n SET\n form_id = %d,\n post_id = {$post_id},\n date_created = {$date_created},\n is_starred = %d,\n is_read = %d,\n ip = %s,\n source_url = %s,\n user_agent = %s,\n currency = %s,\n payment_status = {$payment_status},\n payment_date = {$payment_date},\n payment_amount = {$payment_amount},\n transaction_id = {$transaction_id},\n is_fulfilled = {$is_fulfilled},\n created_by = {$user_id},\n transaction_type = {$transaction_type},\n status = %s,\n payment_method = %s\n WHERE\n id = %d\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method, $entry_id); $result = $wpdb->query($sql); if (false === $result) { return new WP_Error('update_entry_properties_failed', __('There was a problem while updating the entry properties', 'gravityforms'), $wpdb->last_error); } // only save field values for fields that currently exist in the form. The rest in $entry will be ignored. The rest in $current_entry will get deleted. $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $entry_id)); $form = GFFormsModel::get_form_meta($form_id); $form = gf_apply_filters(array('gform_form_pre_update_entry', $form_id), $form, $entry, $entry_id); foreach ($form['fields'] as $field) { /* @var GF_Field $field */ $type = GFFormsModel::get_input_type($field); if (in_array($type, array('html', 'page', 'section'))) { continue; } $inputs = $field->get_entry_inputs(); if (is_array($inputs)) { foreach ($field->inputs as $input) { $input_id = (string) $input['id']; if (isset($entry[$input_id])) { if ($entry[$input_id] != $current_entry[$input_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $input_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error('update_input_value_failed', __('There was a problem while updating one of the input values for the entry', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$input_id]); } } } else { $field_id = $field->id; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ''; if ($field_value != $current_entry[$field_id]) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $field_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $field_id, $field_value); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } unset($current_entry[$field_id]); } } // save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { if ($entry[$key] != $current_entry[$key]) { gform_update_meta($entry_id, $key, $entry[$key]); } unset($current_entry[$key]); } } } // now delete remaining values from the old entry if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $meta_key) { if (isset($current_entry[$meta_key])) { gform_delete_meta($entry_id, $meta_key); unset($current_entry[$meta_key]); } } } foreach ($current_entry as $k => $v) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $k); $field = GFFormsModel::get_field($form, $k); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $k, ''); if (false === $result) { return new WP_Error('update_field_values_failed', __('There was a problem while updating the field values', 'gravityforms'), $wpdb->last_error); } } /** * Fires after the Entry is updated. * * @param array $lead The entry object after being updated. * @param array $original_entry The entry object before being updated. */ gf_do_action(array('gform_post_update_entry', $form_id), $entry, $original_entry); return true; }
/** * Updates a single Entry object. * * @since 1.8 * @access public * @static * * @param array $entry The Entry object * @param int $entry_id Optional. If specified, the ID in the Entry object will be ignored * * @return mixed Either True or a WP_Error instance */ public static function update_entry($entry, $entry_id = null) { global $wpdb; if (empty($entry_id)) { $entry_id = $entry["id"]; } if (empty($entry_id)) { return new WP_Error("missing_entry_id", __("Missing entry id", "gravityforms")); } $current_entry = self::get_entry($entry_id); if (!$current_entry) { return new WP_Error("not_found", __("Entry not found", "gravityforms"), $entry_id); } if (is_wp_error($current_entry)) { return $current_entry; } // make sure the form id exists $form_id = rgar($entry, "form_id"); if (empty($form_id)) { $form_id = rgar($current_entry, "form_id"); } if (false === self::form_id_exists($form_id)) { return new WP_Error("invalid_form_id", __("The form for this entry does not exist", "gravityforms")); } // use values in the entry object if present $post_id = isset($entry["post_id"]) ? intval($entry["post_id"]) : 'NULL'; $date_created = isset($entry["date_created"]) ? sprintf("'%s'", mysql_real_escape_string($entry["date_created"])) : "utc_timestamp()"; $is_starred = isset($entry["is_starred"]) ? $entry["is_starred"] : 0; $is_read = isset($entry["is_read"]) ? $entry["is_read"] : 0; $ip = isset($entry["ip"]) ? $entry["ip"] : GFFormsModel::get_ip(); $source_url = isset($entry["source_url"]) ? $entry["source_url"] : GFFormsModel::get_current_page_url(); $user_agent = isset($entry["user_agent"]) ? $entry["user_agent"] : "API"; $currency = isset($entry["currency"]) ? $entry["currency"] : GFCommon::get_currency(); $payment_status = isset($entry["payment_status"]) ? sprintf("'%s'", mysql_real_escape_string($entry["payment_status"])) : 'NULL'; $payment_date = strtotime(rgar($entry, "payment_date")) ? "'" . gmdate('Y-m-d H:i:s', strtotime("{$entry["payment_date"]}")) . "'" : "NULL"; $payment_amount = isset($entry["payment_amount"]) ? (double) $entry["payment_amount"] : 'NULL'; $payment_method = isset($entry["payment_method"]) ? $entry["payment_method"] : ''; $transaction_id = isset($entry["transaction_id"]) ? sprintf("'%s'", mysql_real_escape_string($entry["transaction_id"])) : 'NULL'; $is_fulfilled = isset($entry["is_fulfilled"]) ? intval($entry["is_fulfilled"]) : 'NULL'; $status = isset($entry["status"]) ? $entry["status"] : "active"; global $current_user; $user_id = isset($entry["created_by"]) ? mysql_real_escape_string($entry["created_by"]) : ""; if (empty($user_id)) { $user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL'; } $transaction_type = isset($entry["transaction_type"]) ? intval($entry["transaction_type"]) : 'NULL'; $lead_table = GFFormsModel::get_lead_table_name(); $result = $wpdb->query($wpdb->prepare("\n UPDATE {$lead_table}\n SET\n form_id = %d,\n post_id = {$post_id},\n date_created = {$date_created},\n is_starred = %d,\n is_read = %d,\n ip = %s,\n source_url = %s,\n user_agent = %s,\n currency = %s,\n payment_status = {$payment_status},\n payment_date = {$payment_date},\n payment_amount = {$payment_amount},\n transaction_id = {$transaction_id},\n is_fulfilled = {$is_fulfilled},\n created_by = {$user_id},\n transaction_type = {$transaction_type},\n status = %s,\n payment_method = %s\n WHERE\n id = %d\n ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method, $entry_id)); if (false === $result) { return new WP_Error("update_entry_properties_failed", __("There was a problem while updating the entry properties", "gravityforms"), $wpdb->last_error); } // only save field values for fields that currently exist in the form. The rest in entry_id will be ignored. The rest in current_entry will get deleted. $lead_detail_table = GFFormsModel::get_lead_details_table_name(); $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $entry_id)); $form = GFFormsModel::get_form_meta($form_id); foreach ($form["fields"] as $field) { $type = GFFormsModel::get_input_type($field); if (in_array($type, array("html", "page", "section"))) { continue; } if (isset($field["inputs"]) && is_array($field["inputs"])) { foreach ($field["inputs"] as $input) { $input_id = (string) $input["id"]; if (isset($entry[$input_id])) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $input_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $input_id, $entry[$input_id]); if (false === $result) { return new WP_Error("update_input_value_failed", __("There was a problem while updating one of the input values for the entry", "gravityforms"), $wpdb->last_error); } unset($current_entry[$input_id]); } } } else { $field_id = $field["id"]; $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : ""; $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $field_id); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $field_id, $field_value); if (false === $result) { return new WP_Error("update_field_values_failed", __("There was a problem while updating the field values", "gravityforms"), $wpdb->last_error); } unset($current_entry[$field_id]); } } // add save the entry meta values - only for the entry meta currently available for the form, ignore the rest $entry_meta = GFFormsModel::get_entry_meta($form_id); if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $key) { if (isset($entry[$key])) { gform_update_meta($entry_id, $key, $entry[$key]); unset($current_entry[$key]); } } } // now delete remaining values from the old entry if (is_array($entry_meta)) { foreach (array_keys($entry_meta) as $meta_key) { if (isset($current_entry[$meta_key])) { gform_delete_meta($entry_id, $meta_key); unset($current_entry[$meta_key]); } } } foreach ($current_entry as $k => $v) { $lead_detail_id = GFFormsModel::get_lead_detail_id($current_fields, $k); $result = GFFormsModel::update_lead_field_value($form, $entry, $field, $lead_detail_id, $k, ""); if (false === $result) { return new WP_Error("update_field_values_failed", __("There was a problem while updating the field values", "gravityforms"), $wpdb->last_error); } } return true; }
public static function get_field_filters_from_post($form) { $field_filters = array(); $filter_fields = rgpost('f'); if (is_array($filter_fields)) { $filter_operators = rgpost('o'); $filter_values = rgpost('v'); for ($i = 0; $i < count($filter_fields); $i++) { $field_filter = array(); $key = $filter_fields[$i]; if ('entry_id' == $key) { $key = 'id'; } $operator = $filter_operators[$i]; $val = $filter_values[$i]; $strpos_row_key = strpos($key, '|'); if ($strpos_row_key !== false) { //multi-row likert $key_array = explode('|', $key); $key = $key_array[0]; $val = $key_array[1] . ':' . $val; } $field_filter['key'] = $key; $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'))) { $operator = 'contains'; } } $field_filter['operator'] = $operator; $field_filter['value'] = $val; $field_filters[] = $field_filter; } } $field_filters['mode'] = rgpost('mode'); return $field_filters; }
/** * load the form data we care about from the form array * @param array $form */ private function loadForm(&$form) { foreach ($form['fields'] as &$field) { $id = $field['id']; switch (GFFormsModel::get_input_type($field)) { case 'name': // only pick up the first name field (assume later ones are additional info) if (empty($this->firstName) && empty($this->lastName)) { $this->namePrefix = trim(rgpost("input_{$id}_2")); $this->firstName = trim(rgpost("input_{$id}_3")); $this->lastName = trim(rgpost("input_{$id}_6")); } break; case 'email': // only pick up the first email address field (assume later ones are additional info) if (empty($this->email)) { $this->email = trim(rgpost("input_{$id}")); } break; case 'phone': // only pick up the first phone number field (assume later ones are additional info) if (empty($this->phone)) { $this->phone = trim(rgpost("input_{$id}")); } break; case 'address': // only pick up the first address field (assume later ones are additional info, e.g. shipping) if (empty($this->address) && empty($this->postcode)) { $parts = array(trim(rgpost("input_{$id}_1")), trim(rgpost("input_{$id}_2"))); $this->address_street = implode(', ', array_filter($parts, 'strlen')); $this->address_suburb = trim(rgpost("input_{$id}_3")); $this->address_state = trim(rgpost("input_{$id}_4")); $this->address_country = trim(rgpost("input_{$id}_6")); $this->postcode = trim(rgpost("input_{$id}_5")); // aggregate street, city, state, country into a single string (for regular one-off payments) $parts = array($this->address_street, $this->address_suburb, $this->address_state, $this->address_country); $this->address = implode(', ', array_filter($parts, 'strlen')); } break; case 'creditcard': $this->isCcHiddenFlag = GFFormsModel::is_field_hidden($form, $field, RGForms::post('gform_field_values')); $this->ccField =& $field; $this->ccName = trim(rgpost("input_{$id}_5")); $this->ccNumber = self::cleanCcNumber(trim(rgpost("input_{$id}_1"))); $ccExp = rgpost("input_{$id}_2"); if (is_array($ccExp)) { list($this->ccExpMonth, $this->ccExpYear) = $ccExp; } $this->ccCVN = trim(rgpost("input_{$id}_3")); break; case 'total': $this->total = GFCommon::to_number(rgpost("input_{$id}")); $this->hasPurchaseFieldsFlag = true; break; case GFEWAY_FIELD_RECURRING: // only pick it up if it isn't hidden if (!GFFormsModel::is_field_hidden($form, $field, RGForms::post('gform_field_values'))) { $this->recurring = GFEwayRecurringField::getPost($id); } break; default: // check for shipping field if ($field['type'] == 'shipping') { $this->shipping += self::getShipping($form, $field); $this->hasPurchaseFieldsFlag = true; } elseif (in_array($field['type'], array('option', 'donation', 'product', 'calculation'))) { $this->amount += self::getProductPrice($form, $field); $this->hasPurchaseFieldsFlag = true; } break; } } // if form didn't pass the total, use sum of the product and shipping fields if ($this->total === 0) { $this->total = $this->amount + $this->shipping; } }
/** * @used-by Filters\"gform_merge_tag_filter" * @param mixed $value * @param int $input_id * @param array $match * @param array $field * @param mixed $raw_value */ public function gform_merge_tag_filter($value, $input_id, $match, $field, $raw_value) { if (\GFFormsModel::get_input_type($field) != 'multiselect') { return $value; } $options = []; $value = explode(',', $value); foreach ($value as $selected) { $options[] = GFCommon::selection_display($selected, $field, $currency = null, $use_text = true); } return implode(', ', $options); }
public static function clear_field_value_cache($form) { if (!class_exists('GFCache')) { return; } foreach ($form['fields'] as &$field) { if (GFFormsModel::get_input_type($field) == 'total') { GFCache::delete('GFFormsModel::get_lead_field_value__' . $field['id']); } } }
public function validate_credit_card($validation_result) { if (!$this->has_feed($validation_result['form']['id'], true)) { return $validation_result; } foreach ($validation_result['form']['fields'] as &$field) { $current_page = GFFormDisplay::get_source_page($validation_result['form']['id']); $field_on_curent_page = $current_page > 0 && $field['pageNumber'] == $current_page; if (GFFormsModel::get_input_type($field) != 'creditcard' || !$field_on_curent_page) { continue; } if ($this->get_stripe_js_error()) { $field['failed_validation'] = true; $field['validation_message'] = $this->get_stripe_js_error(); } else { // override validation in case user has marked field as required allowing stripe to handle cc validation $field['failed_validation'] = false; } // only one cc field per form, break once we've found it break; } // revalidate the validaiton result $validation_result['is_valid'] = true; foreach ($validation_result['form']['fields'] as &$field) { if ($field['failed_validation']) { $validation_result['is_valid'] = false; break; } } return $validation_result; }
public static function lead_detail_page() { global $current_user; do_action('gform_admin_pre_render_action'); if (!GFCommon::ensure_wp_version()) { return; } /* Change Lead_ID Logic */ if (isset($_GET['lid'])) { $lead_id = rgget('lid'); if (!$lead_id) { $lead = !empty($leads) ? $leads[0] : false; } else { $lead = GFAPI::get_entry($lead_id); } if (!$lead) { _e("Oops! We couldn't find your entry. Please try again", 'gravityforms'); return; } } echo GFCommon::get_remote_message(); if (isset($_GET['lid'])) { //Change form from different ID $form_id = isset($lead['form_id']) ? $lead['form_id'] : 0; $form = RGFormsModel::get_form_meta($form_id); $form = apply_filters('gform_admin_pre_render_' . $form['id'], apply_filters('gform_admin_pre_render', $form)); } else { $form = RGFormsModel::get_form_meta(absint($_GET['id'])); $form_id = absint($form['id']); $form = apply_filters('gform_admin_pre_render_' . $form_id, apply_filters('gform_admin_pre_render', $form)); } $lead_id = rgget('lid'); $filter = rgget('filter'); $status = in_array($filter, array('trash', 'spam')) ? $filter : 'active'; $position = rgget('pos') ? rgget('pos') : 0; $sort_direction = rgget('dir') ? rgget('dir') : 'DESC'; $sort_field = empty($_GET['sort']) ? 0 : $_GET['sort']; $sort_field_meta = RGFormsModel::get_field($form, $sort_field); $is_numeric = $sort_field_meta['type'] == 'number'; $all_forms = empty($_GET['allforms']) ? 0 : $_GET['allforms']; $star = $filter == 'star' ? 1 : null; $read = $filter == 'unread' ? 0 : null; $search_criteria['status'] = $status; if ($star) { $search_criteria['field_filters'][] = array('key' => 'is_starred', 'value' => (bool) $star); } if (!is_null($read)) { $search_criteria['field_filters'][] = array('key' => 'is_read', 'value' => (bool) $read); } $search_field_id = rgget('field_id'); /*logic to allow multiple filters to be set */ if (isset($_GET['filterField']) && is_array($_GET['filterField'])) { foreach ($_GET['filterField'] as $key => $value) { $filterValues = explode("|", $value); $key = $filterValues[0]; $search_operator = $filterValues[1]; $val = $filterValues[2]; 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); } } /* if ( isset( $_GET['field_id'] ) && $_GET['field_id'] !== '' ) { $key = $search_field_id; $val = rgget( 's' ); $strpos_row_key = strpos( $search_field_id, '|' ); if ( $strpos_row_key !== false ) { //multi-row likert $key_array = explode( '|', $search_field_id ); $key = $key_array[0]; $val = $key_array[1] . ':' . $val; } $search_criteria['field_filters'][] = array( 'key' => $key, 'operator' => rgempty( 'operator', $_GET ) ? 'is' : rgget( 'operator' ), 'value' => $val, ); $type = rgget( 'type' ); if ( empty( $type ) ) { if ( rgget( 'field_id' ) == '0' ) { $search_criteria['type'] = 'global'; } } }*/ $paging = array('offset' => $position, 'page_size' => 1); if (!empty($sort_field)) { $sorting = array('key' => $_GET['sort'], 'direction' => $sort_direction, 'is_numeric' => $is_numeric); } else { $sorting = array(); } $total_count = 0; global $wpdb; $form_ids = $form_id; $faire = isset($_GET['faire']) ? $_GET['faire'] : ''; if ($faire != '') { $form_id = 9; //let's get the form id's for this faire $sql = "select * from wp_mf_faire where faire='" . $faire . "'"; $Fresults = $wpdb->get_results($sql); if (!empty($Fresults)) { $form_ids = explode(',', $Fresults[0]->form_ids); } else { $form_ids = 99999999; } } $leads = GFAPI::get_entries($form_ids, $search_criteria, $sorting, $paging, $total_count); $prev_pos = !rgblank($position) && $position > 0 ? $position - 1 : false; $next_pos = !rgblank($position) && $position < $total_count - 1 ? $position + 1 : false; // unread filter requires special handling for pagination since entries are filter out of the query as they are read if ($filter == 'unread') { $next_pos = $position; if ($next_pos + 1 == $total_count) { $next_pos = false; } } if (!$lead_id) { $lead = !empty($leads) ? $leads[0] : false; } else { $lead = GFAPI::get_entry($lead_id); } if (!$lead) { _e("Oops! We couldn't find your entry. Please try again", 'gravityforms'); return; } RGFormsModel::update_lead_property($lead['id'], 'is_read', 1); switch (RGForms::post('action')) { case 'update': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); //Loading files that have been uploaded to temp folder $files = GFCommon::json_decode(stripslashes(RGForms::post('gform_uploaded_files'))); if (!is_array($files)) { $files = array(); } GFFormsModel::$uploaded_files[$form_id] = $files; GFFormsModel::save_lead($form, $lead); do_action('gform_after_update_entry', $form, $lead['id']); do_action("gform_after_update_entry_{$form['id']}", $form, $lead['id']); $lead = RGFormsModel::get_lead($lead['id']); $lead = GFFormsModel::set_entry_meta($lead, $form); break; case 'add_note': check_admin_referer('gforms_update_note', 'gforms_update_note'); $user_data = get_userdata($current_user->ID); RGFormsModel::add_note($lead['id'], $current_user->ID, $user_data->display_name, stripslashes($_POST['new_note'])); //emailing notes if configured if (rgpost('gentry_email_notes_to')) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Preparing to email entry notes.'); $email_to = $_POST['gentry_email_notes_to']; $email_from = $current_user->user_email; $email_subject = stripslashes($_POST['gentry_email_subject']); $body = stripslashes($_POST['new_note']); $headers = "From: \"{$email_from}\" <{$email_from}> \r\n"; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Emailing notes - TO: {$email_to} SUBJECT: {$email_subject} BODY: {$body} HEADERS: {$headers}"); $is_success = wp_mail($email_to, $email_subject, $body, $headers); $result = is_wp_error($is_success) ? $is_success->get_error_message() : $is_success; GFCommon::log_debug("GFEntryDetail::lead_detail_page(): Result from wp_mail(): {$result}"); if (!is_wp_error($is_success) && $is_success) { GFCommon::log_debug('GFEntryDetail::lead_detail_page(): Mail was passed from WordPress to the mail server.'); } else { GFCommon::log_error('GFEntryDetail::lead_detail_page(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.'); } if (has_filter('phpmailer_init')) { GFCommon::log_debug(__METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.'); } do_action('gform_post_send_entry_note', $result, $email_to, $email_from, $email_subject, $body, $form, $lead); } break; case 'add_quick_note': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); $user_data = get_userdata($current_user->ID); RGFormsModel::add_note($lead['id'], $current_user->ID, $user_data->display_name, stripslashes($_POST['quick_note'])); break; case 'bulk': check_admin_referer('gforms_update_note', 'gforms_update_note'); if ($_POST['bulk_action'] == 'delete') { if (!GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { die(__("You don't have adequate permission to delete notes.", 'gravityforms')); } RGFormsModel::delete_notes($_POST['note']); } break; case 'trash': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'trash'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'restore': case 'unspam': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'active'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'spam': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); RGFormsModel::update_lead_property($lead['id'], 'status', 'spam'); $lead = RGFormsModel::get_lead($lead['id']); break; case 'delete': check_admin_referer('gforms_save_entry', 'gforms_save_entry'); if (!GFCommon::current_user_can_any('gravityforms_delete_entries')) { die(__("You don't have adequate permission to delete entries.", 'gravityforms')); } RGFormsModel::delete_lead($lead['id']); ?> <script type="text/javascript"> document.location.href = '<?php echo 'admin.php?page=gf_entries&view=entries&id=' . absint($form['id']); ?> '; </script> <?php break; } $mode = empty($_POST['screen_mode']) ? 'view' : $_POST['screen_mode']; ?> <link rel="stylesheet" href="<?php echo GFCommon::get_base_url(); ?> /css/admin.css" /> <script type="text/javascript"> jQuery(document).ready(function () { toggleNotificationOverride(true); jQuery('#gform_update_button').prop('disabled', false); }); function DeleteFile(leadId, fieldId, deleteButton) { if (confirm(<?php _e("'Would you like to delete this file? \\'Cancel\\' to stop. \\'OK\\' to delete'", 'gravityforms'); ?> )) { var fileIndex = jQuery(deleteButton).parent().index(); var mysack = new sack("<?php echo admin_url('admin-ajax.php'); ?> "); mysack.execute = 1; mysack.method = 'POST'; mysack.setVar("action", "rg_delete_file"); mysack.setVar("rg_delete_file", "<?php echo wp_create_nonce('rg_delete_file'); ?> "); mysack.setVar("lead_id", leadId); mysack.setVar("field_id", fieldId); mysack.setVar("file_index", fileIndex); mysack.onError = function () { alert('<?php echo esc_js(__('Ajax error while deleting field.', 'gravityforms')); ?> ') }; mysack.runAJAX(); return true; } } function EndDeleteFile(fieldId, fileIndex) { var previewFileSelector = "#preview_existing_files_" + fieldId + " .ginput_preview"; var $previewFiles = jQuery(previewFileSelector); var rr = $previewFiles.eq(fileIndex); $previewFiles.eq(fileIndex).remove(); var $visiblePreviewFields = jQuery(previewFileSelector); if ($visiblePreviewFields.length == 0) { jQuery('#preview_' + fieldId).hide(); jQuery('#upload_' + fieldId).show('slow'); } } function ToggleShowEmptyFields() { if (jQuery("#gentry_display_empty_fields").is(":checked")) { createCookie("gf_display_empty_fields", true, 10000); document.location = document.location.href; } else { eraseCookie("gf_display_empty_fields"); document.location = document.location.href; } } function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function eraseCookie(name) { createCookie(name, "", -1); } function ResendNotifications() { var selectedNotifications = new Array(); jQuery(".gform_notifications:checked").each(function () { selectedNotifications.push(jQuery(this).val()); }); var sendTo = jQuery('#notification_override_email').val(); if (selectedNotifications.length <= 0) { displayMessage("<?php _e('You must select at least one type of notification to resend.', 'gravityforms'); ?> ", 'error', '#notifications_container'); return; } jQuery('#please_wait_container').fadeIn(); jQuery.post(ajaxurl, { action : "gf_resend_notifications", gf_resend_notifications: '<?php echo wp_create_nonce('gf_resend_notifications'); ?> ', notifications : jQuery.toJSON(selectedNotifications), sendTo : sendTo, leadIds : '<?php echo $lead['id']; ?> ', formId : '<?php echo $form['id']; ?> ' }, function (response) { if (response) { displayMessage(response, "error", "#notifications_container"); } else { displayMessage("<?php _e('Notifications were resent successfully.', 'gravityforms'); ?> ", "updated", "#notifications_container"); // reset UI jQuery(".gform_notifications").attr('checked', false); jQuery('#notification_override_email').val(''); } jQuery('#please_wait_container').hide(); setTimeout(function () { jQuery('#notifications_container').find('.message').slideUp(); }, 5000); } ); } function displayMessage(message, messageClass, container) { jQuery(container).find('.message').hide().html(message).attr('class', 'message ' + messageClass).slideDown(); } function toggleNotificationOverride(isInit) { if (isInit) jQuery('#notification_override_email').val(''); if (jQuery(".gform_notifications:checked").length > 0) { jQuery('#notifications_override_settings').slideDown(); } else { jQuery('#notifications_override_settings').slideUp(function () { jQuery('#notification_override_email').val(''); }); } } </script> <form method="post" id="entry_form" enctype='multipart/form-data'> <?php wp_nonce_field('gforms_save_entry', 'gforms_save_entry'); ?> <input type="hidden" name="action" id="action" value="" /> <input type="hidden" name="screen_mode" id="screen_mode" value="<?php echo esc_attr(rgpost('screen_mode')); ?> " /> <div class="wrap gf_entry_wrap"> <h2 class="gf_admin_page_title"> <span><?php echo __('Entry #', 'gravityforms') . absint($lead['id']); ?> </span><span class="gf_admin_page_subtitle"><span class="gf_admin_page_formid">ID: <?php echo $form['id']; ?> </span><span class='gf_admin_page_formname'><?php _e('Form Name', 'gravityforms'); ?> : <?php echo $form['title']; $gf_entry_locking = new GFEntryLocking(); $gf_entry_locking->lock_info($lead_id); ?> </span> <?php $statuscount = get_makerfaire_status_counts($form['id']); foreach ($statuscount as $statuscount) { ?> <span class="gf_admin_page_formname"><?php echo $statuscount['label']; ?> (<?php echo $statuscount['entries']; ?> )</span><?php } ?> </span></h2> <?php if (isset($_GET['pos'])) { ?> <div class="gf_entry_detail_pagination"> <ul> <li class="gf_entry_count"> <span>entry <strong><?php echo $position + 1; ?> </strong> of <strong><?php echo $total_count; ?> </strong></span> </li> <li class="gf_entry_prev gf_entry_pagination"><?php echo GFEntryDetail::entry_detail_pagination_link($prev_pos, 'Previous Entry', 'gf_entry_prev_link', 'fa fa-arrow-circle-o-left'); ?> </li> <li class="gf_entry_next gf_entry_pagination"><?php echo GFEntryDetail::entry_detail_pagination_link($next_pos, 'Next Entry', 'gf_entry_next_link', 'fa fa-arrow-circle-o-right'); ?> </li> </ul> <?php $outputVar = ''; if (isset($_GET['filterField'])) { foreach ($_GET['filterField'] as $newValue) { $outputVar .= '&filterField[]=' . $newValue; } } $outputURL = admin_url('admin.php') . "?page=mf_entries&view=entries&id=" . $form_id . $outputVar; if (isset($_GET['sort'])) { $outputURL .= '&sort=' . rgget('sort'); } if (isset($_GET['filter'])) { $outputURL .= '&filter=' . rgget('filter'); } if (isset($_GET['dir'])) { $outputURL .= '&dir=' . rgget('dir'); } if (isset($_GET['star'])) { $outputURL .= '&star=' . rgget('star'); } if (isset($_GET['read'])) { $outputURL .= '&read=' . rgget('read'); } if (isset($_GET['paged'])) { $outputURL .= '&paged=' . rgget('paged'); } if (isset($_GET['faire'])) { $outputURL .= '&faire=' . rgget('faire'); } ?> <a href="<?php echo $outputURL; ?> ">Return to entries list</a> </div> <?php } ?> <?php RGForms::top_toolbar(); ?> <div id="poststuff" class="metabox-holder has-right-sidebar"> <div id="side-info-column" class="inner-sidebar"> <?php do_action('gform_entry_detail_sidebar_before', $form, $lead); ?> <!-- INFO BOX --> <div id="submitdiv" class="stuffbox"> <h3> <span class="hndle"><?php _e('Entry', 'gravityforms'); ?> </span> </h3> <div class="inside"> <div id="submitcomment" class="submitbox"> <div id="minor-publishing" style="padding:10px;"> <?php _e('Submitted on', 'gravityforms'); ?> : <?php echo esc_html(GFCommon::format_date($lead['date_created'], false, 'Y/m/d')); ?> <?php do_action('gform_entry_info', $form['id'], $lead); ?> </div> <div id="major-publishing-actions"> <div id="delete-action"> <?php switch ($lead['status']) { case 'spam': if (GFCommon::spam_enabled($form['id'])) { ?> <a onclick="jQuery('#action').val('unspam'); jQuery('#entry_form').submit()" href="#"><?php _e('Not Spam', 'gravityforms'); ?> </a> <?php echo GFCommon::current_user_can_any('gravityforms_delete_entries') ? '|' : ''; } if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> <a class="submitdelete deletion" onclick="if ( confirm('<?php _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", 'gravityforms'); ?> ') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php _e('Delete Permanently', 'gravityforms'); ?> </a> <?php } break; case 'trash': ?> <a onclick="jQuery('#action').val('restore'); jQuery('#entry_form').submit()" href="#"><?php _e('Restore', 'gravityforms'); ?> </a> <?php if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> | <a class="submitdelete deletion" onclick="if ( confirm('<?php _e("You are about to delete this entry. \\'Cancel\\' to stop, \\'OK\\' to delete.", 'gravityforms'); ?> ') ) {jQuery('#action').val('delete'); jQuery('#entry_form').submit(); return true;} return false;" href="#"><?php _e('Delete Permanently', 'gravityforms'); ?> </a> <?php } break; default: if (GFCommon::current_user_can_any('gravityforms_delete_entries')) { ?> <a class="submitdelete deletion" onclick="jQuery('#action').val('trash'); jQuery('#entry_form').submit()" href="#"><?php _e('Move to Trash', 'gravityforms'); ?> </a> <?php echo GFCommon::spam_enabled($form['id']) ? '|' : ''; } if (GFCommon::spam_enabled($form['id'])) { ?> <a class="submitdelete deletion" onclick="jQuery('#action').val('spam'); jQuery('#entry_form').submit()" href="#"><?php _e('Mark as Spam', 'gravityforms'); ?> </a> <?php } } ?> </div> <div id="publishing-action"> <?php if (GFCommon::current_user_can_any('gravityforms_edit_entries') && $lead['status'] != 'trash') { $button_text = $mode == 'view' ? __('Edit', 'gravityforms') : __('Update', 'gravityforms'); $disabled = $mode == 'view' ? '' : ' disabled="disabled" '; $update_button_id = $mode == 'view' ? 'gform_edit_button' : 'gform_update_button'; $button_click = $mode == 'view' ? "jQuery('#screen_mode').val('edit');" : "jQuery('#action').val('update'); jQuery('#screen_mode').val('view');"; $update_button = '<input id="' . $update_button_id . '" ' . $disabled . ' class="button button-large button-primary" type="submit" tabindex="4" value="' . $button_text . '" name="save" onclick="' . $button_click . '"/>'; echo apply_filters('gform_entrydetail_update_button', $update_button); if ($mode == 'edit') { echo ' <input class="button button-large" type="submit" tabindex="5" value="' . __('Cancel', 'gravityforms') . '" name="cancel" onclick="jQuery(\'#screen_mode\').val(\'view\');"/>'; } } ?> </div> <div class="clear"></div> </div> </div> </div> </div> <?php if (!empty($lead['payment_status']) && !apply_filters('gform_enable_entry_info_payment_details', true, $lead)) { self::payment_details_box($lead, $form); } ?> <?php do_action('gform_entry_detail_sidebar_middle', $form, $lead); ?> <?php if (GFCommon::current_user_can_any('gravityforms_edit_entry_notes')) { ?> <!-- start notifications --> <div class="postbox" id="notifications_container"> <h3 style="cursor:default;"><span><?php _e('Notifications', 'gravityforms'); ?> </span></h3> <div class="inside"> <div class="message" style="display:none; padding:10px; margin:10px 0px;"></div> <div> <?php $notifications = GFCommon::get_notifications('form_submission', $form); if (!is_array($notifications) || count($form['notifications']) <= 0) { ?> <p class="description"><?php _e('You cannot resend notifications for this entry because this form does not currently have any notifications configured.', 'gravityforms'); ?> </p> <a href="<?php echo admin_url("admin.php?page=gf_edit_forms&view=settings&subview=notification&id={$form['id']}"); ?> " class="button"><?php _e('Configure Notifications', 'gravityforms'); ?> </a> <?php } else { foreach ($notifications as $notification) { ?> <input type="checkbox" class="gform_notifications" value="<?php echo $notification['id']; ?> " id="notification_<?php echo $notification['id']; ?> " onclick="toggleNotificationOverride();" /> <label for="notification_<?php echo $notification['id']; ?> "><?php echo $notification['name']; ?> </label> <br /><br /> <?php } ?> <div id="notifications_override_settings" style="display:none;"> <p class="description" style="padding-top:0; margin-top:0; width:99%;">You may override the default notification settings by entering a comma delimited list of emails to which the selected notifications should be sent.</p> <label for="notification_override_email"><?php _e('Send To', 'gravityforms'); ?> <?php gform_tooltip('notification_override_email'); ?> </label><br /> <input type="text" name="notification_override_email" id="notification_override_email" style="width:99%;" /> <br /><br /> </div> <input type="button" name="notification_resend" value="<?php _e('Resend Notifications', 'gravityforms'); ?> " class="button" style="" onclick="ResendNotifications();" /> <span id="please_wait_container" style="display:none; margin-left: 5px;"> <i class='gficon-gravityforms-spinner-icon gficon-spin'></i> <?php _e('Resending...', 'gravityforms'); ?> </span> <?php } ?> </div> </div> </div> <!-- / end notifications --> <?php } ?> <!-- begin print button --> <div class="detail-view-print"> <a href="javascript:;" onclick="var notes_qs = jQuery('#gform_print_notes').is(':checked') ? '¬es=1' : ''; var url='<?php echo trailingslashit(site_url()); ?> ?gf_page=print-entry&fid=<?php echo $form['id']; ?> &lid=<?php echo $lead['id']; ?> ' + notes_qs; window.open (url,'printwindow');" class="button"><?php _e('Print', 'gravityforms'); ?> </a> <?php if (GFCommon::current_user_can_any('gravityforms_view_entry_notes')) { ?> <input type="checkbox" name="print_notes" value="print_notes" checked="checked" id="gform_print_notes" /> <label for="print_notes"><?php _e('include notes', 'gravityforms'); ?> </label> <?php } ?> </div> <!-- end print button --> <?php do_action('gform_entry_detail_sidebar_after', $form, $lead); ?> </div> <div id="post-body" class="has-sidebar"> <div id="post-body-content" class="has-sidebar-content"> <?php do_action('gform_entry_detail_content_before', $form, $lead); if ($mode == 'view') { self::lead_detail_grid($form, $lead, true); } else { self::lead_detail_edit($form, $lead); } do_action('gform_entry_detail', $form, $lead); do_action('gform_entry_detail_content_after', $form, $lead); ?> </div> </div> </div> </div> </form> <?php if (rgpost('action') == 'update') { ?> <div class="updated fade" style="padding:6px;"> <?php _e('Entry Updated.', 'gravityforms'); ?> </div> <?php } }
/** * Returns the value of the selected field. * * @access private * * @param array $form * @param array $entry * @param string $field_id * * @return string field value */ public function get_field_value($form, $entry, $field_id) { switch (strtolower($field_id)) { case 'form_title': return rgar($form, 'title'); case 'date_created': $date_created = rgar($entry, strtolower($field_id)); if (empty($date_created)) { //the date created may not yet be populated if this function is called during the validation phase and the entry is not yet created return gmdate('Y-m-d H:i:s'); } else { return $date_created; } case 'ip': case 'source_url': return rgar($entry, strtolower($field_id)); default: $field = GFFormsModel::get_field($form, $field_id); $is_integer = $field_id == intval($field_id); $input_type = GFFormsModel::get_input_type($field); if ($is_integer && $input_type == 'address') { return $this->get_full_address($entry, $field_id); } elseif ($is_integer && $input_type == 'name') { return $this->get_full_name($entry, $field_id); } elseif ($is_integer && $input_type == 'checkbox') { $selected = array(); foreach ($field->inputs as $input) { $index = (string) $input['id']; if (!rgempty($index, $entry)) { $selected[] = rgar($entry, $index); } } return implode(', ', $selected); } elseif ($input_type == 'list') { return $this->get_list_field_value($entry, $field_id, $field); } else { return rgar($entry, $field_id); } } }
public function get_form_fields_as_choices($form, $args = array()) { $fields = array(); if (!is_array($form['fields'])) { return $fields; } $args = wp_parse_args($args, array('field_types' => array(), 'input_types' => array())); foreach ($form['fields'] as $field) { $input_type = GFFormsModel::get_input_type($field); if (!empty($args['input_types']) && !in_array($input_type, $args['input_types'])) { continue; } if (is_array(rgar($field, 'inputs'))) { // if this is an address field, add full name to the list if ($input_type == 'address') { $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')'); } // if this is a name field, add full name to the list if ($input_type == 'name') { $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')'); } // if this is a checkbox field, add to the list if ($input_type == 'checkbox') { $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Selected', 'gravityforms') . ')'); } foreach ($field['inputs'] as $input) { $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id'])); } } else { if (!rgar($field, 'displayOnly')) { $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field)); } } } return $fields; }
public function has_calculation() { if ($this->type == 'number') { return $this->enableCalculation && $this->calculationFormula; } return GFFormsModel::get_input_type($this) == 'calculation'; }
/** * @param GF_Field $field * @param string $value * @param bool $force_frontend_label * @param int $form_id * @param null|array $form * * @return string */ public static function get_field_content($field, $value = '', $force_frontend_label = false, $form_id = 0, $form = null) { $field_label = $field->get_field_label($form, $value); $admin_buttons = $field->get_admin_buttons(); $input_type = GFFormsModel::get_input_type($field); $is_form_editor = GFCommon::is_form_editor(); $is_entry_detail = GFCommon::is_entry_detail(); $is_admin = $is_form_editor || $is_entry_detail; if ($input_type == 'adminonly_hidden') { $field_content = !$is_admin ? '{FIELD}' : sprintf("%s<label class='gfield_label' >%s</label>{FIELD}", $admin_buttons, esc_html($field_label)); } else { $field_content = $field->get_field_content($value, $force_frontend_label, $form); } if ($input_type == 'creditcard' && !GFCommon::is_ssl() && !$is_admin) { $field_content = "<div class='gfield_creditcard_warning_message'><span>" . esc_html__('This page is unsecured. Do not enter a real credit card number! Use this field only for testing purposes. ', 'gravityforms') . '</span></div>' . $field_content; } $value = $field->get_value_default_if_empty($value); $field_content = str_replace('{FIELD}', GFCommon::get_field_input($field, $value, 0, $form_id, $form), $field_content); $field_content = apply_filters('gform_field_content', $field_content, $field, $value, 0, $form_id); return $field_content; }
public static function upload() { GFCommon::log_debug('GFAsyncUpload::upload(): Starting.'); if ($_SERVER['REQUEST_METHOD'] != 'POST') { status_header(404); die; } header('Content-Type: text/html; charset=' . get_option('blog_charset')); send_nosniff_header(); nocache_headers(); status_header(200); // If the file is bigger than the server can accept then the form_id might not arrive. // This might happen if the file is bigger than the max post size ini setting. // Validation in the browser reduces the risk of this happening. if (!isset($_REQUEST['form_id'])) { GFCommon::log_debug('GFAsyncUpload::upload(): File upload aborted because the form_id was not found. The file may have been bigger than the max post size ini setting.'); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } $form_id = absint($_REQUEST['form_id']); $form_unique_id = rgpost('gform_unique_id'); $form = GFAPI::get_form($form_id); if (empty($form) || !$form['is_active']) { die; } if (rgar($form, 'requireLogin')) { if (!is_user_logged_in()) { die; } check_admin_referer('gform_file_upload_' . $form_id, '_gform_file_upload_nonce_' . $form_id); } if (!ctype_alnum($form_unique_id)) { die; } $target_dir = GFFormsModel::get_upload_path($form_id) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; if (!is_dir($target_dir)) { if (!wp_mkdir_p($target_dir)) { GFCommon::log_debug("GFAsyncUpload::upload(): Couldn't create the tmp folder: " . $target_dir); self::die_error(500, __('Failed to upload file.', 'gravityforms')); } } $time = current_time('mysql'); $y = substr($time, 0, 4); $m = substr($time, 5, 2); //adding index.html files to all subfolders if (!file_exists(GFFormsModel::get_upload_root() . '/index.html')) { GFForms::add_security_files(); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . '/index.html')) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id)); } else { if (!file_exists(GFFormsModel::get_upload_path($form_id) . "/{$y}/index.html")) { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}"); } else { GFCommon::recursive_add_index_file(GFFormsModel::get_upload_path($form_id) . "/{$y}/{$m}"); } } } if (!file_exists($target_dir . '/index.html')) { GFCommon::recursive_add_index_file($target_dir); } $uploaded_filename = $_FILES['file']['name']; $file_name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; $field_id = rgpost('field_id'); $field_id = absint($field_id); $field = GFFormsModel::get_field($form, $field_id); if (empty($field) || GFFormsModel::get_input_type($field) != 'fileupload') { die; } $file_name = sanitize_file_name($file_name); $uploaded_filename = sanitize_file_name($uploaded_filename); $allowed_extensions = !empty($field->allowedExtensions) ? GFCommon::clean_extensions(explode(',', strtolower($field->allowedExtensions))) : array(); $max_upload_size_in_bytes = $field->maxFileSize > 0 ? $field->maxFileSize * 1048576 : wp_max_upload_size(); $max_upload_size_in_mb = $max_upload_size_in_bytes / 1048576; if ($_FILES['file']['size'] > 0 && $_FILES['file']['size'] > $max_upload_size_in_bytes) { self::die_error(104, sprintf(__('File exceeds size limit. Maximum file size: %dMB', 'gravityforms'), $max_upload_size_in_mb)); } if (GFCommon::file_name_has_disallowed_extension($file_name) || GFCommon::file_name_has_disallowed_extension($uploaded_filename)) { GFCommon::log_debug("GFAsyncUpload::upload(): Illegal file extension: {$file_name}"); self::die_error(104, __('The uploaded file type is not allowed.', 'gravityforms')); } if (!empty($allowed_extensions)) { if (!GFCommon::match_file_extension($file_name, $allowed_extensions) || !GFCommon::match_file_extension($uploaded_filename, $allowed_extensions)) { GFCommon::log_debug("GFAsyncUpload::upload(): The uploaded file type is not allowed: {$file_name}"); self::die_error(104, sprintf(__('The uploaded file type is not allowed. Must be one of the following: %s', 'gravityforms'), strtolower($field['allowedExtensions']))); } } $whitelisting_disabled = apply_filters('gform_file_upload_whitelisting_disabled', false); if (empty($allowed_extensions) && !$whitelisting_disabled) { // Whitelist the file type $valid_uploaded_filename = GFCommon::check_type_and_ext($_FILES['file'], $uploaded_filename); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_uploaded_filename->get_error_code(), $valid_uploaded_filename->get_error_message()); } $valid_file_name = GFCommon::check_type_and_ext($_FILES['file'], $file_name); if (is_wp_error($valid_uploaded_filename)) { self::die_error($valid_file_name->get_error_code(), $valid_file_name->get_error_message()); } } $tmp_file_name = $form_unique_id . '_input_' . $field_id . '_' . $file_name; $tmp_file_name = sanitize_file_name($tmp_file_name); $file_path = $target_dir . $tmp_file_name; $cleanup_target_dir = true; // Remove old files $max_file_age = 5 * 3600; // Temp file age in seconds // Remove old temp files if ($cleanup_target_dir) { if (is_dir($target_dir) && ($dir = opendir($target_dir))) { while (($file = readdir($dir)) !== false) { $tmp_file_path = $target_dir . $file; // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\\.part$/', $file) && filemtime($tmp_file_path) < time() - $max_file_age && $tmp_file_path != "{$file_path}.part") { GFCommon::log_debug('GFAsyncUpload::upload(): Deleting file: ' . $tmp_file_path); @unlink($tmp_file_path); } } closedir($dir); } else { GFCommon::log_debug('GFAsyncUpload::upload(): Failed to open temp directory: ' . $target_dir); self::die_error(100, __('Failed to open temp directory.', 'gravityforms')); } } if (isset($_SERVER['HTTP_CONTENT_TYPE'])) { $contentType = $_SERVER['HTTP_CONTENT_TYPE']; } if (isset($_SERVER['CONTENT_TYPE'])) { $contentType = $_SERVER['CONTENT_TYPE']; } $chunk = isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0; $chunks = isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0; // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, 'multipart') !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen($_FILES['file']['tmp_name'], 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); @unlink($_FILES['file']['tmp_name']); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } else { self::die_error(103, __('Failed to move uploaded file.', 'gravityforms')); } } else { // Open temp file $out = @fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if ($out) { // Read binary input stream and append it to temp file $in = @fopen('php://input', 'rb'); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { self::die_error(101, __('Failed to open input stream.', 'gravityforms')); } @fclose($in); @fclose($out); } else { self::die_error(102, __('Failed to open output stream.', 'gravityforms')); } } // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$file_path}.part", $file_path); } if (file_exists($file_path)) { GFFormsModel::set_permissions($file_path); } else { self::die_error(105, __('Upload unsuccessful', 'gravityforms') . ' ' . $uploaded_filename); } $output = array('status' => 'ok', 'data' => array('temp_filename' => $tmp_file_name, 'uploaded_filename' => str_replace("\\'", "'", urldecode($uploaded_filename)))); $output = json_encode($output); GFCommon::log_debug(sprintf('GFAsyncUpload::upload(): File upload complete. temp_filename: %s uploaded_filename: %s ', $tmp_file_name, $uploaded_filename)); gf_do_action('gform_post_multifile_upload', $form['id'], $form, $field, $uploaded_filename, $tmp_file_name, $file_path); die($output); }
public function get_results_data($form, $fields, $search_criteria = array(), $state_array = array(), $max_execution_time = 15) { // todo: add hooks to modify $max_execution_time and $page_size? $page_size = 150; $time_start = microtime(true); $form_id = $form['id']; $data = array(); $offset = 0; $entry_count = 0; $field_data = array(); if ($state_array) { //get counts from state $data = $state_array; $offset = (int) rgar($data, 'offset'); unset($data['offset']); $entry_count = $offset; $field_data = rgar($data, 'field_data'); } else { //initialize counts foreach ($fields as $field) { $field_type = GFFormsModel::get_input_type($field); if (false === isset($field->choices)) { $field_data[$field->id] = 0; continue; } $choices = $field->choices; if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableMultipleRows')) { foreach ($field->gsurveyLikertRows as $row) { foreach ($choices as $choice) { $field_data[$field->id][$row['value']][$choice['value']] = 0; } if (rgar($field, 'gsurveyLikertEnableScoring')) { $field_data[$field->id][$row['value']]['row_score_sum'] = 0; } } } else { if (!empty($choices) && is_array($choices)) { foreach ($choices as $choice) { $field_data[$field->id][$choice['value']] = 0; } } else { $field_data[$field->id] = 0; } } if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableScoring')) { $field_data[$field->id]['sum_of_scores'] = 0; } } } $count_search_leads = GFAPI::count_entries($form_id, $search_criteria); $data['entry_count'] = $count_search_leads; $entries_left = $count_search_leads - $offset; while ($entries_left > 0) { $paging = array('offset' => $offset, 'page_size' => $page_size); $search_leads_time_start = microtime(true); $leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging); $search_leads_time_end = microtime(true); $search_leads_time = $search_leads_time_end - $search_leads_time_start; $leads_in_search = count($leads); $entry_count += $leads_in_search; $leads_processed = 0; foreach ($leads as $lead) { $lead_time_start = microtime(true); foreach ($fields as $field) { $field_type = GFFormsModel::get_input_type($field); $field_id = $field->id; $value = RGFormsModel::get_lead_field_value($lead, $field); if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableMultipleRows')) { if (empty($value)) { continue; } foreach ($value as $value_vector) { if (empty($value_vector)) { continue; } list($row_val, $col_val) = explode(':', $value_vector, 2); if (isset($field_data[$field->id][$row_val]) && isset($field_data[$field->id][$row_val][$col_val])) { $field_data[$field->id][$row_val][$col_val]++; if ($field->gsurveyLikertEnableScoring) { $field_data[$field->id][$row_val]['row_score_sum'] += $this->get_likert_row_score($row_val, $field, $lead); } } } } elseif ($field_type == 'rank') { $score = count(rgar($field, 'choices')); $values = explode(',', $value); foreach ($values as $ranked_value) { $field_data[$field->id][$ranked_value] += $score; $score--; } } else { if (empty($field->choices)) { if (false === empty($value)) { $field_data[$field_id]++; } continue; } $choices = $field->choices; foreach ($choices as $choice) { $choice_is_selected = false; if (is_array($value)) { $choice_value = rgar($choice, 'value'); if (in_array($choice_value, $value)) { $choice_is_selected = true; } } else { if (RGFormsModel::choice_value_match($field, $choice, $value)) { $choice_is_selected = true; } } if ($choice_is_selected) { $field_data[$field_id][$choice['value']]++; } } } if ($field_type == 'likert' && rgar($field, 'gsurveyLikertEnableScoring')) { $field_data[$field->id]['sum_of_scores'] += $this->get_likert_score($field, $lead); } } $leads_processed++; $lead_time_end = microtime(true); $total_execution_time = $lead_time_end - $search_leads_time_start; $lead_execution_time = $lead_time_end - $lead_time_start; if ($total_execution_time + $lead_execution_time > $max_execution_time) { break; } } $data['field_data'] = $field_data; if (isset($this->_callbacks['calculation'])) { $data = call_user_func($this->_callbacks['calculation'], $data, $form, $fields, $leads); $field_data = $data['field_data']; } $offset += $leads_processed; $entries_left -= $leads_processed; $time_end = microtime(true); $execution_time = $time_end - $time_start; if ($entries_left > 0 && $execution_time + $search_leads_time > $max_execution_time) { $data['status'] = 'incomplete'; $data['offset'] = $offset; $progress = $data['entry_count'] > 0 ? round($data['offset'] / $data['entry_count'] * 100) : 0; $data['progress'] = $progress; break; } if ($entries_left <= 0) { $data['status'] = 'complete'; } } $data['timestamp'] = time(); return $data; }
/** * Generate the data source array for a given form with form ID which is compatible with Google Charts. * * @param $form_id * @param $chart_type * @param $selected_fields * @param array $labels * * @return array|null */ static function generate_data_source($form_id, $chart_type, $selected_fields, $labels = array()) { // save user options // generate data source - make a query // Save chart in user meta / flat table $leads = array(); $fields = array(); if (class_exists('GFFormsModel') && class_exists('RGFormsModel')) { $leads = GFFormsModel::get_leads($form_id); $meta = RGFormsModel::get_form_meta($form_id); $fields = isset($meta['fields']) ? $meta['fields'] : array(); } $data_source = array(); switch ($chart_type) { case 'table': $cols = array(); foreach ($fields as $f_id => $field) { if ('all_fields_table' !== $selected_fields && !in_array($field['id'], $selected_fields)) { continue; } switch ($field['type']) { case 'address': case 'name': $inputs = self::get_field_inputs($field); foreach ($inputs as $i_id => $input) { $cols[] = array('type' => self::$data_type_map['text'], 'label' => isset($input['label']) ? $input['label'] : 'Input ' . ($i_id + 1)); } break; case 'select': case 'radio': case 'multiselect': case 'checkbox': $choices = self::get_field_choices($field); foreach ($choices as $ch_id => $choice) { $cols[] = array('type' => self::$data_type_map['text'], 'label' => isset($choice['text']) ? $choice['text'] : 'Choice ' . ($ch_id + 1)); } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice']) { $cols[] = array('type' => self::$data_type_map['text'], 'label' => __('Others')); } if ('checkbox' == $field['type'] && 1 === sizeof($choices)) { $cols[] = array('type' => self::$data_type_map['text'], 'label' => __('Others')); } break; default: $cols[] = array('type' => class_exists('GFFormsModel') ? self::$data_type_map[GFFormsModel::get_input_type($field)] : self::$data_type_map['text'], 'label' => isset($field['label']) ? $field['label'] : 'Column ' . ($f_id + 1)); break; } } $rows = array(); foreach ($leads as $lead) { $temp = array(); foreach ($fields as $field) { if ('all_fields_table' !== $selected_fields && !in_array($field['id'], $selected_fields)) { continue; } switch ($field['type']) { case 'checkbox': $choices = self::get_field_choices($field); $inputs = self::get_field_inputs($field); $options = self::array_merge_recursive_distinct($choices, $inputs); foreach ($options as $option) { $val = isset($lead[strval($option['id'])]) ? $lead[strval($option['id'])] : ''; if (isset($option['value']) && $val == $option['value']) { $temp[] = '✔'; } else { $temp[] = ''; } } if (1 === sizeof($options)) { if (!isset($lead[strval($options[0]['id'])]) || empty($lead[strval($options[0]['id'])])) { $temp[] = '✔'; } else { $temp[] = ''; } } break; case 'address': case 'name': $inputs = self::get_field_inputs($field); foreach ($inputs as $input) { $temp[] = isset($lead[strval($input['id'])]) ? $lead[strval($input['id'])] : 'NA'; } break; case 'multiselect': $vals = isset($lead[$field['id']]) ? explode(',', $lead[$field['id']]) : array(); $choices = self::get_field_choices($field); foreach ($choices as $choice) { if (isset($choice['value']) && in_array($choice['value'], $vals)) { $temp[] = '✔'; } else { $temp[] = ''; } } break; case 'select': case 'radio': $val = isset($lead[$field['id']]) ? $lead[$field['id']] : ''; $choices = self::get_field_choices($field); $others_flag = false; foreach ($choices as $choice) { if (isset($choice['value']) && $val == $choice['value']) { $temp[] = '✔'; $others_flag = true; } else { $temp[] = ''; } } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice']) { if (!$others_flag) { $temp[] = '✔'; } else { $temp[] = ''; } } break; default: $temp[] = isset($lead[$field['id']]) ? 'number' == $field['type'] ? floatval($lead[$field['id']]) : $lead[$field['id']] : 'NA'; break; } } $rows[] = $temp; } $data_source['cols'] = $cols; $data_source['rows'] = $rows; break; case 'pie': case 'gauge': $field = self::get_field_by_id($selected_fields[0], $fields); $cols = array($field['label'], __('Count')); $counts = array(); switch ($field['type']) { case 'select': case 'radio': case 'multiselect': $choices = self::get_field_choices($field); foreach ($choices as $choice) { $counts[] = array('label' => $choice['text'], 'value' => $choice['value'], 'count' => 0); } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice']) { $counts[] = array('label' => __('Others'), 'value' => 'others', 'count' => 0); } break; case 'checkbox': $choices = self::get_field_choices($field); $inputs = self::get_field_inputs($field); $options = self::array_merge_recursive_distinct($choices, $inputs); foreach ($options as $option) { $counts[] = array('id' => $option['id'], 'label' => $option['label'], 'value' => $option['value'], 'count' => 0); } if (1 === sizeof($options)) { $counts['others'] = array('id' => 'others', 'label' => __('Others'), 'value' => '', 'count' => 0); } break; case 'number': if (empty($labels)) { $data_source = null; break; } $label = self::get_field_by_id($labels[0], $fields); switch ($label['type']) { case 'select': case 'radio': case 'multiselect': $choices = self::get_field_choices($label); foreach ($choices as $choice) { $counts[] = array('label' => $choice['text'], 'value' => $choice['value'], 'count' => 0); } if (isset($label['enableOtherChoice']) && $label['enableOtherChoice']) { $counts[] = array('label' => __('Others'), 'value' => 'others', 'count' => 0); } break; case 'checkbox': $choices = self::get_field_choices($label); $inputs = self::get_field_inputs($label); $options = self::array_merge_recursive_distinct($choices, $inputs); foreach ($options as $option) { $counts[] = array('id' => $option['id'], 'label' => $option['label'], 'value' => $option['value'], 'count' => 0); } if (1 === sizeof($options)) { $counts['others'] = array('id' => 'others', 'label' => __('Others'), 'value' => '', 'count' => 0); } break; default: $data_source = null; break; } break; default: $data_source = null; break; } foreach ($leads as $lead) { switch ($field['type']) { case 'multiselect': $vals = isset($lead[$field['id']]) ? explode(',', $lead[$field['id']]) : array(); foreach ($counts as $key => $count) { if (in_array($count['value'], $vals)) { $counts[$key]['count']++; } } break; case 'select': case 'radio': $others_flag = false; foreach ($counts as $key => $count) { if (isset($lead[$field['id']]) && $lead[$field['id']] == $count['value']) { $counts[$key]['count']++; $others_flag = true; } } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice'] && !$others_flag) { foreach ($counts as $key => $count) { if ('others' == $count['value']) { $counts[$key]['count']++; } } } break; case 'checkbox': if (array_key_exists('others', $counts)) { if (isset($lead[$counts[0]['id']]) && $lead[$counts[0]['id']] == $counts[0]['value']) { $counts[0]['count']++; } else { $counts['others']['count']++; } } else { foreach ($counts as $key => $count) { if (isset($lead[$count['id']]) && $lead[$count['id']] == $count['value']) { $counts[$key]['count']++; } } } break; case 'number': if (empty($labels)) { $data_source = null; break; } $label = self::get_field_by_id($labels[0], $fields); switch ($label['type']) { case 'multiselect': $vals = isset($lead[$label['id']]) ? explode(',', $lead[$label['id']]) : array(); foreach ($counts as $key => $count) { if (in_array($count['value'], $vals)) { $counts[$key]['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; } } break; case 'select': case 'radio': $others_flag = false; foreach ($counts as $key => $count) { if (isset($lead[$label['id']]) && $lead[$label['id']] == $count['value']) { $counts[$key]['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; $others_flag = true; } } if (isset($label['enableOtherChoice']) && $label['enableOtherChoice'] && !$others_flag) { foreach ($counts as $key => $count) { if ('others' == $count['value']) { $counts[$key]['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; } } } break; case 'checkbox': if (array_key_exists('others', $counts)) { if (isset($lead[$counts[0]['id']]) && $lead[$counts[0]['id']] == $counts[0]['value']) { $counts[0]['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; } else { $counts['others']['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; } } else { foreach ($counts as $key => $count) { if (isset($lead[$count['id']]) && $lead[$count['id']] == $count['value']) { $counts[$key]['count'] += isset($lead[$field['id']]) && !empty($lead[$field['id']]) ? $lead[$field['id']] : 0; } } } break; default: $data_source = null; break; } break; default: $data_source = null; break; } } $rows = array(); $data_source['total_count'] = 0; foreach ($counts as $count) { $rows[] = array($count['label'], $count['count']); $data_source['total_count'] += $count['count']; } if ('gauge' == $chart_type) { foreach ($rows as $key => $value) { $rows[$key][1] = round($rows[$key][1] * 100 / $data_source['total_count'], 2); } } $data_source['cols'] = $cols; $data_source['rows'] = $rows; break; case 'line': case 'bar': case 'column': case 'area': case 'stepped_area': if ('all_fields_table' === $selected_fields || !is_array($selected_fields)) { $data_source = null; break; } $cols = array(array()); $counts = array(); foreach ($selected_fields as $selected_field) { $field = self::get_field_by_id($selected_field, $fields); switch ($field['type']) { case 'select': case 'radio': case 'multiselect': $cols[0][] = $field['label']; $cols[] = __('Count'); $choices = self::get_field_choices($field); foreach ($choices as $choice) { $counts[] = array('label' => $choice['text'], 'value' => $choice['value'], 'count' => 0); } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice']) { $counts[] = array('label' => __('Others'), 'value' => 'others', 'count' => 0); } break; case 'checkbox': $cols[0][] = $field['label']; $cols[] = __('Count'); $choices = self::get_field_choices($field); $inputs = self::get_field_inputs($field); $options = self::array_merge_recursive_distinct($choices, $inputs); foreach ($options as $option) { $counts[] = array('id' => $option['id'], 'label' => $option['label'], 'value' => $option['value'], 'count' => 0); } if (1 === sizeof($options)) { $counts['others'] = array('id' => 'others', 'label' => __('Others'), 'value' => '', 'count' => 0); } break; case 'number': $cols[0][] = $field['label']; $cols[] = __($field['label']); break; default: $data_source = null; break; } } foreach ($leads as $lead) { $temp = array(); foreach ($selected_fields as $selected_field) { $field = self::get_field_by_id($selected_field, $fields); switch ($field['type']) { case 'multiselect': $vals = isset($lead[$field['id']]) ? explode(',', $lead[$field['id']]) : array(); foreach ($counts as $key => $count) { if (in_array($count['value'], $vals)) { $counts[$key]['count']++; } } break; case 'select': case 'radio': $others_flag = false; foreach ($counts as $key => $count) { if (isset($lead[$field['id']]) && $lead[$field['id']] == $count['value']) { $counts[$key]['count']++; $others_flag = true; } } if (isset($field['enableOtherChoice']) && $field['enableOtherChoice'] && !$others_flag) { foreach ($counts as $key => $count) { if ('others' == $count['value']) { $counts[$key]['count']++; } } } break; case 'checkbox': if (array_key_exists('others', $counts)) { if (isset($lead[$counts[0]['id']]) && $lead[$counts[0]['id']] == $counts[0]['value']) { $counts[0]['count']++; } else { $counts['others']['count']++; } } else { foreach ($counts as $key => $count) { if (isset($lead[$count['id']]) && $lead[$count['id']] == $count['value']) { $counts[$key]['count']++; } } } break; case 'number': $temp[] = floatval($lead[$field['id']]); break; default: $data_source = null; break; } } if (!empty($temp)) { $date = new DateTime($lead['date_created']); $user = get_user_by('id', $lead['created_by']); $counts[] = array('label' => __((isset($user->display_name) ? $user->display_name : 'Annonymous') . ' - ' . $date->format('j M Y')), 'count' => $temp); $temp = array(); } } $rows = array(); foreach ($counts as $count) { if (is_array($count['count'])) { $rows[] = array_merge(array($count['label']), $count['count']); } else { $rows[] = array($count['label'], $count['count']); } } $cols[0] = implode(' & ', $cols[0]); $data_source['cols'] = $cols; $data_source['rows'] = $rows; break; default: $data_source = null; break; } return $data_source; }