Пример #1
0
 public static function get_body($entry, $form)
 {
     $body = array();
     foreach ($form["fields"] as $field) {
         if ($field["type"] == "honeypot") {
             //skip the honeypot field
             continue;
         }
         $field_value = GFFormsModel::get_lead_field_value($entry, $field);
         if (!empty($entry)) {
             $field_value = apply_filters("gform_zapier_field_value", $field_value, $form["id"], $field["id"], $entry);
         }
         $field_label = GFFormsModel::get_label($field);
         if (is_array($field["inputs"])) {
             //handling multi-input fields
             $non_blank_items = array();
             //field has inputs, complex field like name, address and checkboxes. Get individual inputs
             foreach ($field["inputs"] as $input) {
                 $input_label = GFFormsModel::get_label($field, $input["id"]);
                 $field_id = (string) $input["id"];
                 $input_value = $field_value == null ? "" : $field_value[$field_id];
                 $body[$input_label] = $input_value;
                 if (!rgblank($input_value)) {
                     $non_blank_items[] = $input_value;
                 }
             }
             //Also adding an item for the "whole" field, which will be a concatenation of the individual inputs
             switch (GFFormsModel::get_input_type($field)) {
                 case "checkbox":
                     //checkboxes will create a comma separated list of values
                     $body[$field_label] = implode(", ", $non_blank_items);
                     break;
                 case "name":
                 case "address":
                     //name and address will separate inputs by a single blank space
                     $body[$field_label] = implode(" ", $non_blank_items);
                     break;
             }
         } else {
             $body[$field_label] = rgblank($field_value) ? "" : $field_value;
         }
     }
     $entry_meta = GFFormsModel::get_entry_meta($form["id"]);
     foreach ($entry_meta as $meta_key => $meta_config) {
         $body[$meta_config["label"]] = empty($entry) ? null : rgar($entry, $meta_key);
     }
     return $body;
 }
 private function get_entry_meta_filters($form_id)
 {
     $filters = array();
     //$entry_meta = is_callable($this->_callbacks["get_entry_meta"]) ? call_user_func($this->_callbacks["get_entry_meta"], array(), $form_id) : array();
     $entry_meta = GFFormsModel::get_entry_meta($form_id);
     if (empty($entry_meta)) {
         return $filters;
     }
     foreach ($entry_meta as $key => $meta) {
         if (isset($meta["filter"])) {
             $filter = array();
             $filter["key"] = $key;
             $filter["type"] = "meta";
             $filter["preventMultiple"] = isset($meta["filter"]["preventMultiple"]) ? $meta["filter"]["preventMultiple"] : false;
             $filter["text"] = rgar($meta, "label");
             $filter["operators"] = isset($meta["filter"]["operators"]) ? $meta["filter"]["operators"] : array("is", "isnot");
             if (isset($meta["filter"]["choices"])) {
                 $filter["values"] = $meta["filter"]["choices"];
             }
             $filters[] = $filter;
         }
     }
     return $filters;
 }
Пример #3
0
    public static function notification_edit_page($form_id, $notification_id)
    {
        if (!rgempty("gform_notification_id")) {
            $notification_id = rgpost("gform_notification_id");
        }
        $form = RGFormsModel::get_form_meta($form_id);
        $form = apply_filters("gform_form_notification_page_{$form_id}", apply_filters("gform_form_notification_page", $form, $notification_id), $notification_id);
        $notification = !$notification_id ? array() : self::get_notification($form, $notification_id);
        // added second condition to account for new notifications with errors as notification ID will
        // be available in $_POST but the notification has not actually been saved yet
        $is_new_notification = empty($notification_id) || empty($notification);
        $is_valid = true;
        $is_update = false;
        if (rgpost("save")) {
            check_admin_referer('gforms_save_notification', 'gforms_save_notification');
            //clear out notification because it could have legacy data populated
            $notification = array('isActive' => isset($notification['isActive']) ? rgar($notification, 'isActive') : true);
            $is_update = true;
            if ($is_new_notification) {
                $notification_id = uniqid();
                $notification["id"] = $notification_id;
            } else {
                $notification["id"] = $notification_id;
            }
            $notification["name"] = rgpost("gform_notification_name");
            $notification["event"] = rgpost("gform_notification_event");
            $notification["to"] = rgpost("gform_notification_to_type") == "field" ? rgpost("gform_notification_to_field") : rgpost("gform_notification_to_email");
            $notification["toType"] = rgpost("gform_notification_to_type");
            $notification["bcc"] = rgpost("gform_notification_bcc");
            $notification["subject"] = rgpost("gform_notification_subject");
            $notification["message"] = rgpost("gform_notification_message");
            $notification["from"] = rgpost("gform_notification_from");
            $notification["fromName"] = rgpost("gform_notification_from_name");
            $notification["replyTo"] = rgpost("gform_notification_reply_to");
            $notification["routing"] = !rgempty("gform_routing_meta") ? GFCommon::json_decode(rgpost("gform_routing_meta"), true) : null;
            $notification["conditionalLogic"] = !rgempty("gform_conditional_logic_meta") ? GFCommon::json_decode(rgpost("gform_conditional_logic_meta"), true) : null;
            $notification["disableAutoformat"] = rgpost("gform_notification_disable_autoformat");
            $notification = apply_filters('gform_pre_notification_save', apply_filters("gform_pre_notification_save{$form['id']}", $notification, $form), $form);
            //validating input...
            $is_valid = self::validate_notification();
            if ($is_valid) {
                //input valid, updating...
                //emptying notification email if it is supposed to be disabled
                if ($_POST["gform_notification_to_type"] == "routing") {
                    $notification["to"] = "";
                } else {
                    $notification["routing"] = null;
                }
                // trim values
                $notification = GFFormsModel::trim_conditional_logic_values_from_element($notification, $form);
                $form["notifications"][$notification_id] = $notification;
                RGFormsModel::save_form_notifications($form_id, $form['notifications']);
            }
        }
        if ($is_update && $is_valid) {
            GFCommon::add_message(sprintf(__('Notification saved successfully. %sBack to notifications.%s', 'gravityforms'), '<a href="' . remove_query_arg('nid') . '">', '</a>'));
        } else {
            if ($is_update && !$is_valid) {
                GFCommon::add_error_message(__('Notification could not be updated. Please enter all required information below.', 'gravityforms'));
            }
        }
        // moved page header loading here so the admin messages can be set upon saving and available for the header to print out
        GFFormSettings::page_header(__('Notifications', 'gravityforms'));
        $notification_ui_settings = self::get_notification_ui_settings($notification);
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css?ver=<?php 
        echo GFCommon::$version;
        ?>
" />

        <script type="text/javascript">

        var gform_has_unsaved_changes = false;
        jQuery(document).ready(function(){

            jQuery("#entry_form input, #entry_form textarea, #entry_form select").change(function(){
                gform_has_unsaved_changes = true;
            });

            window.onbeforeunload = function(){
                if (gform_has_unsaved_changes){
                    return "You have unsaved changes.";
                }
            }

            ToggleConditionalLogic(true, 'notification');

            jQuery(document).on('change', '.gfield_routing_value_dropdown', function(){
                SetRoutingValueDropDown(jQuery(this));
            });

        });

        <?php 
        if (empty($form["notifications"])) {
            $form["notifications"] = array();
        }
        $entry_meta = GFFormsModel::get_entry_meta($form_id);
        $entry_meta = apply_filters("gform_entry_meta_conditional_logic_notifications", $entry_meta, $form, $notification_id);
        ?>

        var form = <?php 
        echo GFCommon::json_encode($form);
        ?>
;
        var current_notification = <?php 
        echo GFCommon::json_encode($notification);
        ?>
;
        var entry_meta = <?php 
        echo GFCommon::json_encode($entry_meta);
        ?>
;

        function SetRoutingValueDropDown(element){
            //parsing ID to get routing Index
            var index = element.attr("id").replace("routing_value_", "");
            SetRouting(index);
        }

        function CreateRouting(routings){
            var str = "";
            for(var i=0; i< routings.length; i++){

                var isSelected = routings[i].operator == "is" ? "selected='selected'" :"";
                var isNotSelected = routings[i].operator == "isnot" ? "selected='selected'" :"";
                var greaterThanSelected = routings[i].operator == ">" ? "selected='selected'" :"";
                var lessThanSelected = routings[i].operator == "<" ? "selected='selected'" :"";
                var containsSelected = routings[i].operator == "contains" ? "selected='selected'" :"";
                var startsWithSelected = routings[i].operator == "starts_with" ? "selected='selected'" :"";
                var endsWithSelected = routings[i].operator == "ends_with" ? "selected='selected'" :"";
                var email = routings[i]["email"] ? routings[i]["email"] : '';

                str += "<div style='width:99%'><?php 
        _e("Send to", "gravityforms");
        ?>
 <input type='text' id='routing_email_" + i +"' value='" + email + "' onkeyup='SetRouting(" + i + ");'/>";
                str += " <?php 
        _e("if", "gravityforms");
        ?>
 " + GetRoutingFields(i, routings[i].fieldId);
                str += "<select id='routing_operator_" + i + "' onchange='SetRouting(" + i + ");' class='gform_routing_operator'>";
                str += "<option value='is' " + isSelected + "><?php 
        _e("is", "gravityforms");
        ?>
</option>";
                str += "<option value='isnot' " + isNotSelected + "><?php 
        _e("is not", "gravityforms");
        ?>
</option>";
                str += "<option value='>' " + greaterThanSelected + "><?php 
        _e("greater than", "gravityforms");
        ?>
</option>";
                str += "<option value='<' " + lessThanSelected + "><?php 
        _e("less than", "gravityforms");
        ?>
</option>";
                str += "<option value='contains' " + containsSelected + "><?php 
        _e("contains", "gravityforms");
        ?>
</option>";
                str += "<option value='starts_with' " + startsWithSelected + "><?php 
        _e("starts with", "gravityforms");
        ?>
</option>";
                str += "<option value='ends_with' " + endsWithSelected + "><?php 
        _e("ends with", "gravityforms");
        ?>
</option>";
                str += "</select>";
                str += GetRoutingValues(i, routings[i].fieldId, routings[i].value);
                str += "<a class='gf_insert_field_choice' title='add another rule' onclick=\"InsertRouting(" + (i+1) + ");\"><i class='fa fa-plus-square'></i></a>";
                if(routings.length > 1 )
                    str += "<a class='gf_delete_field_choice' title='remove this rule' onclick=\"DeleteRouting(" + i + ");\"><i class='fa fa-minus-square'></i></a>";

                str += "</div>";
            }

            jQuery("#gform_notification_to_routing_rules").html(str);
        }

        function GetRoutingValues(index, fieldId, selectedValue){
            str = GetFieldValues(index, fieldId, selectedValue, 16);

            return str;
        }

        function GetRoutingFields(index, selectedItem){
            var str = "<select id='routing_field_id_" + index + "' class='gfield_routing_select' onchange='jQuery(\"#routing_value_" + index + "\").replaceWith(GetRoutingValues(" + index + ", jQuery(this).val())); SetRouting(" + index + "); '>";
            str += GetSelectableFields(selectedItem, 16);
            str += "</select>";

            return str;
        }

        //---------------------- generic ---------------
        function GetSelectableFields(selectedFieldId, labelMaxCharacters){
            var str = "";
            var inputType;
            for(var i=0; i<form.fields.length; i++){
                inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
                //see if this field type can be used for conditionals
                if (IsNotificationConditionalLogicField(form.fields[i])) {
                    var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : "";
                    str += "<option value='" + form.fields[i].id + "' " + selected + ">" + form.fields[i].label + "</option>";
                }
            }
            return str;
        }

        function IsNotificationConditionalLogicField(field){
        	//this function is a duplicate of IsConditionalLogicField from form_editor.js
		    inputType = field.inputType ? field.inputType : field.type;
		    var supported_fields = ["checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title",
		                            "post_tags", "post_custom_field", "post_content", "post_excerpt"];

		    var index = jQuery.inArray(inputType, supported_fields);

		    return index >= 0;
		}

        function GetFirstSelectableField(){
            var inputType;
            for(var i=0; i<form.fields.length; i++){
                inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
                if (IsNotificationConditionalLogicField(form.fields[i])){
                    return form.fields[i].id;
				}
            }

            return 0;
        }

        function TruncateMiddle(text, maxCharacters){
            if(!text)
                return "";

            if(text.length <= maxCharacters)
                return text;
            var middle = parseInt(maxCharacters / 2);
            return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle);

        }

        function GetFieldValues(index, fieldId, selectedValue, labelMaxCharacters){
            if(!fieldId)
                fieldId = GetFirstSelectableField();

            if(!fieldId)
                return "";

            var str = "";
            var field = GetFieldById(fieldId);
            var isAnySelected = false;

            if(!field)
        		return "";

            if(field["type"] == "post_category" && field["displayAllCategories"]){
            	var dropdown_id = "routing_value_" + index;
		        var dropdown = jQuery('#' + dropdown_id + ".gfield_category_dropdown");

		        //don't load category drop down if it already exists (to avoid unecessary ajax requests)
		        if(dropdown.length > 0){

		            var options = dropdown.html();
		            options = options.replace("value=\"" + selectedValue + "\"", "value=\"" + selectedValue + "\" selected=\"selected\"");
		            str = "<select id='" + dropdown_id + "' class='gfield_routing_select gfield_category_dropdown gfield_routing_value_dropdown'>" + options + "</select>";
		        }
		        else{
		            //loading categories via AJAX
		            jQuery.post(ajaxurl,{   action:"gf_get_notification_post_categories",
		                                    ruleIndex: index,
		                                    selectedValue: selectedValue},
		                                function(dropdown_string){
		                                    if(dropdown_string){
		                                        jQuery('#gfield_ajax_placeholder_' + index).replaceWith(dropdown_string.trim());
		                                    }
		                                }
		                        );

		            //will be replaced by real drop down during the ajax callback
		            str = "<select id='gfield_ajax_placeholder_" + index + "' class='gfield_routing_select'><option><?php 
        _e("Loading...", "gravityforms");
        ?>
</option></select>";
		        }
			}
            else if(field.choices){
            	//create a drop down for fields that have choices (i.e. drop down, radio, checkboxes, etc...)
	            str = "<select class='gfield_routing_select gfield_routing_value_dropdown' id='routing_value_" + index + "'>";
	            for(var i=0; i<field.choices.length; i++){
	                var choiceValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text;
	                var isSelected = choiceValue == selectedValue;
	                var selected = isSelected ? "selected='selected'" : "";
	                if(isSelected)
	                    isAnySelected = true;

	                str += "<option value='" + choiceValue.replace(/'/g, "&#039;") + "' " + selected + ">" + field.choices[i].text + "</option>";
	            }

	            if(!isAnySelected && selectedValue){
	                str += "<option value='" + selectedValue.replace(/'/g, "&#039;") + "' selected='selected'>" + selectedValue + "</option>";
	            }
	            str += "</select>";
			}
			else
			{
			    selectedValue = selectedValue ? selectedValue.replace(/'/g, "&#039;") : "";
			    //create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...)
			    str = "<input type='text' placeholder='<?php 
        _e("Enter value", "gravityforms");
        ?>
' class='gfield_routing_select' id='routing_value_" + index + "' value='" + selectedValue.replace(/'/g, "&#039;") + "' onchange='SetRouting(" + index + ");' onkeyup='SetRouting(" + index + ");'>";
			}
            return str;
        }

        function GetFieldById(fieldId){
            for(var i=0; i<form.fields.length; i++){
                if(form.fields[i].id == fieldId)
                    return form.fields[i];
            }
            return null;
        }
        //---------------------------------------------------------------------------------

        function InsertRouting(index){
            var routings = current_notification.routing;
            routings.splice(index, 0, new ConditionalRule());

            CreateRouting(routings);
            SetRouting(index);
        }

        function SetRouting(ruleIndex){
            if(!current_notification.routing && ruleIndex == 0)
                current_notification.routing = [new ConditionalRule()];

            current_notification.routing[ruleIndex]["email"] = jQuery("#routing_email_" + ruleIndex).val();
            current_notification.routing[ruleIndex]["fieldId"] = jQuery("#routing_field_id_" + ruleIndex).val();
            current_notification.routing[ruleIndex]["operator"] = jQuery("#routing_operator_" + ruleIndex).val();
            current_notification.routing[ruleIndex]["value"] =jQuery("#routing_value_" + ruleIndex).val();

            var json = jQuery.toJSON(current_notification.routing);
            jQuery('#gform_routing_meta').val(json);
        }

        function DeleteRouting(ruleIndex){
            current_notification.routing.splice(ruleIndex, 1);
            CreateRouting(current_notification.routing);
        }

        function SetConditionalLogic(isChecked){
            current_notification.conditionalLogic = isChecked ? new ConditionalLogic() : null;
        }

        function SaveJSMeta(){
            jQuery('#gform_routing_meta').val(jQuery.toJSON(current_notification.routing));
            jQuery('#gform_conditional_logic_meta').val(jQuery.toJSON(current_notification.conditionalLogic));
        }

        </script>

        <form method="post" id="gform_notification_form" onsubmit="gform_has_unsaved_changes = false; SaveJSMeta();">

            <?php 
        wp_nonce_field('gforms_save_notification', 'gforms_save_notification');
        ?>
            <input type="hidden" id="gform_routing_meta" name="gform_routing_meta" />
            <input type="hidden" id="gform_conditional_logic_meta" name="gform_conditional_logic_meta" />
            <input type="hidden" id="gform_notification_id" name="gform_notification_id" value="<?php 
        echo $notification_id;
        ?>
" />

            <table class="form-table gform_nofification_edit">
                <?php 
        array_map(array('GFFormSettings', 'output'), $notification_ui_settings);
        ?>
            </table>

            <p class="submit">
                <?php 
        $button_label = $is_new_notification ? __("Save Notification", "gravityforms") : __("Update Notification", "gravityforms");
        $notification_button = '<input class="button-primary" type="submit" value="' . $button_label . '" name="save"/>';
        echo apply_filters("gform_save_notification_button", $notification_button);
        ?>
            </p>
        </form>

        <?php 
        GFFormSettings::page_footer();
    }
Пример #4
0
 private static function get_entry_meta($form)
 {
     $entry_meta = GFFormsModel::get_entry_meta($form['id']);
     $keys = array_keys($entry_meta);
     foreach ($keys as $key) {
         array_push($form['fields'], array('id' => $key, 'label' => $entry_meta[$key]['label']));
     }
     return $form;
 }
Пример #5
0
    public static function confirmations_edit_page($form_id, $confirmation_id)
    {
        $form = gf_apply_filters('gform_admin_pre_render', $form_id, GFFormsModel::get_form_meta($form_id));
        $duplicated_cid = rgget('duplicatedcid');
        $is_duplicate = empty($_POST) && !empty($duplicated_cid);
        if ($is_duplicate) {
            $confirmation_id = $duplicated_cid;
        }
        $confirmation = self::handle_confirmation_edit_submission(rgar($form['confirmations'], $confirmation_id), $form);
        if ($is_duplicate) {
            $count = 2;
            $name = $confirmation['name'];
            $new_name = $name . ' - Copy 1';
            while (!self::is_unique_name($new_name, $form['confirmations'])) {
                $new_name = $name . " - Copy {$count}";
                $count++;
            }
            $confirmation['name'] = $new_name;
            $confirmation['id'] = 'new';
            if ($confirmation['isDefault']) {
                $confirmation['isDefault'] = false;
                $confirmation['conditionalLogic'] = '';
            }
        }
        $confirmation_ui_settings = self::get_confirmation_ui_settings($confirmation);
        $entry_meta = GFFormsModel::get_entry_meta($form_id);
        $entry_meta = apply_filters('gform_entry_meta_conditional_logic_confirmations', $entry_meta, $form, $confirmation_id);
        self::page_header(__('Confirmations', 'gravityforms'));
        ?>

		<script type="text/javascript">

			var confirmation = <?php 
        echo $confirmation ? json_encode($confirmation) : 'new ConfirmationObj()';
        ?>
;
			var form = <?php 
        echo json_encode($form);
        ?>
;
			var entry_meta = <?php 
        echo GFCommon::json_encode($entry_meta);
        ?>
;

			jQuery(document).ready(function ($) {

				if ( confirmation.event == 'form_saved' || confirmation.event == 'form_save_email_sent' ) {
					$('#form_confirmation_redirect, #form_confirmation_show_page').attr('disabled', true);
				}

				SetConfirmationConditionalLogic();
				<?php 
        if (!rgar($confirmation, 'isDefault')) {
            ?>
				ToggleConditionalLogic(true, 'confirmation');
				<?php 
        }
        ?>
				ToggleConfirmation();

				<?php 
        if ($is_duplicate) {
            ?>
				$('#confirmation_conditional_logic_container').pointer({
					content     : '<h3><?php 
            _e('Important', 'gravityforms');
            ?>
</h3><p><?php 
            _e('Ensure that the conditional logic for this confirmation is different from all the other confirmations for this form and then press save to create the new confirmation.', 'gravityforms');
            ?>
</p>',
					position    : {
						edge : 'bottom', // arrow direction
						align: 'center' // vertical alignment
					},
					pointerWidth: 300
				}).pointer('open');
				<?php 
        }
        ?>
			});


			gform.addFilter("gform_merge_tags", "MaybeAddSaveMergeTags");
			function MaybeAddSaveMergeTags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
				var event = confirmation.event;
				if ( event == 'form_saved' || event == 'form_save_email_sent' ) {
					mergeTags["other"].tags.push({ tag: '{save_link}', label: '<?php 
        _e('Save &amp; Continue Link', 'gravityforms');
        ?>
' });
					mergeTags["other"].tags.push({ tag: '{save_token}', label: '<?php 
        _e('Save &amp; Continue Token', 'gravityforms');
        ?>
' });
				}

				if( event == 'form_saved' ) {
					mergeTags["other"].tags.push({ tag: '{save_email_input}', label: '<?php 
        _e('Save &amp; Continue Email Input', 'gravityforms');
        ?>
' });
				}

				return mergeTags;
			}

			<?php 
        self::output_field_scripts();
        ?>

		</script>

		<style type="text/css">
			#confirmation_action_type {
				display: none;
			}
		</style>

		<div id="confirmation-editor">

			<form id="confirmation_edit_form" method="post">

				<table class="form-table gforms_form_settings">
					<?php 
        array_map(array(__CLASS__, 'output'), $confirmation_ui_settings);
        ?>
				</table>

				<?php 
        //DEPRECATED SINCE 1.7 - use gform_confirmation_ui_settings instead
        do_action('gform_confirmation_settings', 100, $form_id);
        do_action('gform_confirmation_settings', 200, $form_id);
        ?>

				<input type="hidden" id="confirmation_id" name="confirmation_id" value="<?php 
        echo $confirmation_id;
        ?>
" />
				<input type="hidden" id="form_id" name="form_id" value="<?php 
        echo $form_id;
        ?>
" />
				<input type="hidden" id="is_default" name="is_default" value="<?php 
        echo rgget('isDefault', $confirmation);
        ?>
" />
				<input type="hidden" id="conditional_logic" name="conditional_logic" value="<?php 
        echo htmlentities(json_encode(rgget('conditionalLogic', $confirmation)));
        ?>
" />

				<p class="submit">
					<input type="submit" name="save" value="<?php 
        _e('Save Confirmation', 'gravityforms');
        ?>
" onclick="StashConditionalLogic(event);" class="button-primary">
				</p>

				<?php 
        wp_nonce_field('gform_confirmation_edit', 'gform_confirmation_edit');
        ?>

			</form>

		</div> <!-- / confirmation-editor -->

		<?php 
        self::page_footer();
    }
Пример #6
0
 public static function get_field_map_choices($form_id, $field_type = null, $exclude_field_types = null)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     // Setup first choice
     if (rgblank($field_type) || is_array($field_type) && count($field_type) > 1) {
         $first_choice_label = __('Select a Field', 'gravityforms');
     } else {
         $type = is_array($field_type) ? $field_type[0] : $field_type;
         $type = ucfirst(GF_Fields::get($type)->get_form_editor_field_title());
         $first_choice_label = sprintf(__('Select a %s Field', 'gravityforms'), $type);
     }
     $fields[] = array('value' => '', 'label' => $first_choice_label);
     // if field types not restricted add the default fields and entry meta
     if (is_null($field_type)) {
         $fields[] = array('value' => 'id', 'label' => esc_html__('Entry ID', 'gravityforms'));
         $fields[] = array('value' => 'date_created', 'label' => esc_html__('Entry Date', 'gravityforms'));
         $fields[] = array('value' => 'ip', 'label' => esc_html__('User IP', 'gravityforms'));
         $fields[] = array('value' => 'source_url', 'label' => esc_html__('Source Url', 'gravityforms'));
         $fields[] = array('value' => 'form_title', 'label' => esc_html__('Form Title', 'gravityforms'));
         $entry_meta = GFFormsModel::get_entry_meta($form['id']);
         foreach ($entry_meta as $meta_key => $meta) {
             $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label"));
         }
     }
     // Populate form fields
     if (is_array($form['fields'])) {
         foreach ($form['fields'] as $field) {
             $input_type = $field->get_input_type();
             $inputs = $field->get_entry_inputs();
             $field_is_valid_type = empty($field_type) || is_array($field_type) && in_array($input_type, $field_type) || !empty($field_type) && $input_type == $field_type;
             if (is_null($exclude_field_types)) {
                 $exclude_field = false;
             } elseif (is_array($exclude_field_types)) {
                 if (in_array($input_type, $exclude_field_types)) {
                     $exclude_field = true;
                 } else {
                     $exclude_field = false;
                 }
             } else {
                 //not array, so should be single string
                 if ($input_type == $exclude_field_types) {
                     $exclude_field = true;
                 } else {
                     $exclude_field = false;
                 }
             }
             if (is_array($inputs) && $field_is_valid_type && !$exclude_field) {
                 //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 && $field_is_valid_type && !$exclude_field) {
                 $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) . ' (' . esc_html(rgar($column, 'text')) . ')');
                     $col_index++;
                 }
             } elseif (!$field->displayOnly && $field_is_valid_type && !$exclude_field) {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field));
             }
         }
     }
     return $fields;
 }
 public static function get_body($entry, $form)
 {
     $current_body = self::$_current_body;
     if (is_array($current_body)) {
         return $current_body;
     }
     $body = array();
     foreach ($form['fields'] as $field) {
         $input_type = GFFormsModel::get_input_type($field);
         if ($input_type == 'honeypot') {
             //skip the honeypot field
             continue;
         }
         $field_value = GFFormsModel::get_lead_field_value($entry, $field);
         if (!empty($entry)) {
             $field_value = apply_filters('gform_zapier_field_value', $field_value, $form['id'], $field->id, $entry);
         }
         $field_label = GFFormsModel::get_label($field);
         $inputs = $field instanceof GF_Field ? $field->get_entry_inputs() : rgar($field, 'inputs');
         if (is_array($inputs) && (is_array($field_value) || empty($entry))) {
             //handling multi-input fields
             $non_blank_items = array();
             //field has inputs, complex field like name, address and checkboxes. Get individual inputs
             foreach ($inputs as $input) {
                 $input_label = GFFormsModel::get_label($field, $input['id']);
                 $field_id = (string) $input['id'];
                 $input_value = rgar($field_value, $field_id);
                 $body[$input_label] = $input_value;
                 if (!rgblank($input_value)) {
                     $non_blank_items[] = $input_value;
                 }
             }
             //Also adding an item for the "whole" field, which will be a concatenation of the individual inputs
             switch ($input_type) {
                 case 'checkbox':
                     //checkboxes will create a comma separated list of values
                     $body[$field_label] = implode(', ', $non_blank_items);
                     break;
                 case 'name':
                 case 'address':
                     //name and address will separate inputs by a single blank space
                     $body[$field_label] = implode(' ', $non_blank_items);
                     break;
             }
         } else {
             $body[$field_label] = rgblank($field_value) ? '' : $field_value;
         }
     }
     $entry_meta = GFFormsModel::get_entry_meta($form['id']);
     foreach ($entry_meta as $meta_key => $meta_config) {
         $body[$meta_config['label']] = empty($entry) ? null : rgar($entry, $meta_key);
     }
     self::$_current_body = $body;
     return $body;
 }
Пример #8
0
    public static function confirmations_edit_page($form_id, $confirmation_id)
    {
        $form = apply_filters("gform_admin_pre_render_{$form_id}", apply_filters("gform_admin_pre_render", GFFormsModel::get_form_meta($form_id)));
        $duplicated_cid = rgget("duplicatedcid");
        $is_duplicate = empty($_POST) && !empty($duplicated_cid);
        if ($is_duplicate) {
            $confirmation_id = $duplicated_cid;
        }
        $confirmation = self::handle_confirmation_edit_submission(rgar($form["confirmations"], $confirmation_id), $form);
        if ($is_duplicate) {
            $count = 2;
            $name = $confirmation["name"];
            $new_name = $name . " - Copy 1";
            while (!self::is_unique_name($new_name, $form['confirmations'])) {
                $new_name = $name . " - Copy {$count}";
                $count++;
            }
            $confirmation["name"] = $new_name;
            $confirmation["id"] = "new";
            if ($confirmation["isDefault"]) {
                $confirmation["isDefault"] = false;
                $confirmation["conditionalLogic"] = "";
            }
        }
        $confirmation_ui_settings = self::get_confirmation_ui_settings($confirmation);
        $entry_meta = GFFormsModel::get_entry_meta($form_id);
        $entry_meta = apply_filters("gform_entry_meta_conditional_logic_confirmations", $entry_meta, $form, $confirmation_id);
        self::page_header(__('Confirmations', 'gravityforms'));
        ?>

        <script type="text/javascript">

            var confirmation = <?php 
        echo $confirmation ? json_encode($confirmation) : 'new ConfirmationObj()';
        ?>
;
            var form = <?php 
        echo json_encode($form);
        ?>
;
            var entry_meta = <?php 
        echo GFCommon::json_encode($entry_meta);
        ?>
;

            jQuery(document).ready(function($){
                SetConfirmationConditionalLogic();
                <?php 
        if (!rgar($confirmation, 'isDefault')) {
            ?>
			    ToggleConditionalLogic(true, 'confirmation');
                <?php 
        }
        ?>
                ToggleConfirmation();

                <?php 
        if ($is_duplicate) {
            ?>
                $('#confirmation_conditional_logic_container').pointer({
                    content:		'<h3><?php 
            _e("Important", "gravityforms");
            ?>
</h3><p><?php 
            _e("Ensure that the conditional logic for this confirmation is different from all the other confirmations for this form and then press save to create the new confirmation.", "gravityforms");
            ?>
</p>',
                    position:		{
                        edge:	'bottom', // arrow direction
                        align:	'center' // vertical alignment
                    },
                    pointerWidth:	300
                }).pointer('open');
                <?php 
        }
        ?>
		    });

        </script>

        <style type="text/css">
            #confirmation_action_type { display: none; }
        </style>

        <div id="confirmation-editor">

            <form id="confirmation_edit_form" method="post">

                <table class="form-table gforms_form_settings">
                    <?php 
        array_map(array(__CLASS__, 'output'), $confirmation_ui_settings);
        ?>
                </table>

                <?php 
        //DEPRECATED SINCE 1.7 - use gform_confirmation_ui_settings instead
        do_action("gform_confirmation_settings", 100, $form_id);
        do_action("gform_confirmation_settings", 200, $form_id);
        ?>

                <input type="hidden" id="confirmation_id" name="confirmation_id" value="<?php 
        echo $confirmation_id;
        ?>
" />
                <input type="hidden" id="form_id" name="form_id" value="<?php 
        echo $form_id;
        ?>
" />
                <input type="hidden" id="is_default" name="is_default" value="<?php 
        echo rgget("isDefault", $confirmation);
        ?>
" />
                <input type="hidden" id="conditional_logic" name="conditional_logic" value="<?php 
        echo htmlentities(json_encode(rgget('conditionalLogic', $confirmation)));
        ?>
" />

                <p class="submit">
                    <input type="submit" name="save" value="<?php 
        _e('Save Confirmation', 'gravityforms');
        ?>
" onclick="StashConditionalLogic(event);" class="button-primary">
                </p>

                <?php 
        wp_nonce_field('gform_confirmation_edit', 'gform_confirmation_edit');
        ?>

            </form>

        </div> <!-- / confirmation-editor -->

        <?php 
        self::page_footer();
    }
Пример #9
0
    private static function sort_by_column_query($form_id, $search_criteria, $sorting, $paging) {
        global $wpdb;
        $sort_field      = isset($sorting["key"]) ? $sorting["key"] : "date_created";
        $sort_direction  = isset($sorting["direction"]) ? $sorting["direction"] : "DESC";
        $is_numeric_sort = isset($sorting["is_numeric"]) ? $sorting["is_numeric"] : false;
        $offset          = isset($paging["offset"]) ? $paging["offset"] : 0;
        $page_size       = isset($paging["page_size"]) ? $paging["page_size"] : 20;

        if (!is_numeric($offset) || !is_numeric($page_size)) {
            return "";
        }

        $lead_detail_table_name = GFFormsModel::get_lead_details_table_name();
        $lead_table_name        = GFFormsModel::get_lead_table_name();
        $lead_meta_table_name   = GFFormsModel::get_lead_meta_table_name();

        $entry_meta          = GFFormsModel::get_entry_meta(is_array($form_id) ? 0 : $form_id);
        $entry_meta_sql_join = "";
        $sort_field_is_entry_meta = false;
        if (false === empty($entry_meta) && array_key_exists($sort_field, $entry_meta)) {
            $entry_meta_sql_join = $wpdb->prepare("
                INNER JOIN
                (
                SELECT
                     lead_id, meta_value as $sort_field
                     from $lead_meta_table_name
                     WHERE meta_key=%s
                ) lead_meta_data ON lead_meta_data.lead_id = l.id
                ", $sort_field);
            $is_numeric_sort = $entry_meta[$sort_field]['is_numeric'];
            $sort_field_is_entry_meta = true;
        } else {
            $db_columns = self::get_lead_db_columns();
            if ($sort_field != "date_created" && false === in_array($sort_field, $db_columns))
                $sort_field = "date_created";
        }

        if($sort_field_is_entry_meta){
            $orderby = $is_numeric_sort ? "ORDER BY ($sort_field+0) $sort_direction" : "ORDER BY $sort_field $sort_direction";
        } else {
            $orderby = $is_numeric_sort ? "ORDER BY (l.$sort_field+0) $sort_direction" : "ORDER BY l.$sort_field $sort_direction";
        }

        $where = self::get_search_where($form_id, $search_criteria);

        $sql  = "
            SELECT filtered.sort, l.*, d.field_number, d.value
            FROM $lead_table_name l
            INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id
            INNER JOIN
            (
                SELECT @rownum:=@rownum + 1 as sort, id
                FROM
                (
                    SELECT distinct l.id
                    FROM $lead_table_name l
                    INNER JOIN $lead_detail_table_name d ON d.lead_id = l.id
                    $entry_meta_sql_join
                    $where
                    $orderby
                    LIMIT $offset,$page_size
                ) page
            ) filtered ON filtered.id = l.id

            ORDER BY filtered.sort";

        return $sql;
    }
Пример #10
0
 /**
  * Evaluates a routing rule.
  *
  * @param $routing_rule
  *
  * @return bool Is the routing rule a match?
  */
 public function evaluate_routing_rule($routing_rule)
 {
     gravity_flow()->log_debug(__METHOD__ . '(): rule:' . print_r($routing_rule, true));
     $entry = $this->get_entry();
     $form_id = $this->get_form_id();
     $entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form_id));
     $form = GFAPI::get_form($form_id);
     if (in_array($routing_rule['fieldId'], $entry_meta_keys)) {
         $is_value_match = GFFormsModel::is_value_match(rgar($entry, $routing_rule['fieldId']), $routing_rule['value'], $routing_rule['operator'], null, $routing_rule, $form);
     } else {
         $source_field = GFFormsModel::get_field($form, $routing_rule['fieldId']);
         $field_value = empty($entry) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($entry, $source_field);
         $is_value_match = GFFormsModel::is_value_match($field_value, $routing_rule['value'], $routing_rule['operator'], $source_field, $routing_rule, $form);
     }
     gravity_flow()->log_debug(__METHOD__ . '(): is_match:' . print_r($is_value_match, true));
     return $is_value_match;
 }
Пример #11
0
 public static function evaluate_conditional_logic($logic, $form, $lead)
 {
     if (!$logic || !is_array($logic["rules"])) {
         return true;
     }
     $entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form["id"]));
     $match_count = 0;
     if (is_array($logic["rules"])) {
         foreach ($logic["rules"] as $rule) {
             if (in_array($rule["fieldId"], $entry_meta_keys)) {
                 $is_value_match = GFFormsModel::is_value_match(rgar($lead, $rule["fieldId"]), $rule["value"], $rule["operator"]);
             } else {
                 $source_field = GFFormsModel::get_field($form, $rule["fieldId"]);
                 $field_value = empty($lead) ? GFFormsModel::get_field_value($source_field, array()) : GFFormsModel::get_lead_field_value($lead, $source_field);
                 $is_value_match = GFFormsModel::is_value_match($field_value, $rule["value"], $rule["operator"], $source_field);
             }
             if ($is_value_match) {
                 $match_count++;
             }
         }
     }
     $do_action = $logic["logicType"] == "all" && $match_count == sizeof($logic["rules"]) || $logic["logicType"] == "any" && $match_count > 0;
     return $do_action;
 }
Пример #12
0
 public static function get_field_map_choices($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     // Adding default fields
     $fields[] = array("value" => "", "label" => "");
     $fields[] = array("value" => "date_created", "label" => __("Entry Date", "gravityforms"));
     $fields[] = array("value" => "ip", "label" => __("User IP", "gravityformsmailchimp"));
     $fields[] = array("value" => "source_url", "label" => __("Source Url", "gravityforms"));
     $fields[] = array("value" => "form_title", "label" => __("Form Title", "gravityforms"));
     // Populate entry meta
     $entry_meta = GFFormsModel::get_entry_meta($form["id"]);
     foreach ($entry_meta as $meta_key => $meta) {
         $fields[] = array('value' => $key, 'label' => $meta[$key]['label']);
     }
     // Populate form fields
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (is_array(rgar($field, "inputs"))) {
                 //If this is an address field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == "address") {
                     $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Full", "gravityformsmailchimp") . ")");
                 }
                 //If this is a name field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == "name") {
                     $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Full", "gravityformsmailchimp") . ")");
                 }
                 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 static function get_field_map_choices($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     // Adding default fields
     $fields[] = array('value' => '', 'label' => '');
     $fields[] = array('value' => 'date_created', 'label' => __('Entry Date', 'gravityforms'));
     $fields[] = array('value' => 'ip', 'label' => __('User IP', 'gravityforms'));
     $fields[] = array('value' => 'source_url', 'label' => __('Source Url', 'gravityforms'));
     $fields[] = array('value' => 'form_title', 'label' => __('Form Title', 'gravityforms'));
     // Populate entry meta
     $entry_meta = GFFormsModel::get_entry_meta($form['id']);
     foreach ($entry_meta as $meta_key => $meta) {
         $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label"));
     }
     // Populate form fields
     if (is_array($form['fields'])) {
         foreach ($form['fields'] as $field) {
             if (is_array(rgar($field, 'inputs'))) {
                 //If this is an address field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == '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 (RGFormsModel::get_input_type($field) == 'name') {
                     $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')');
                 }
                 //If this is a checkbox field, add to the list
                 if (RGFormsModel::get_input_type($field) == 'checkbox') {
                     $fields[] = array('value' => $field['id'], 'label' => GFCommon::get_label($field) . ' (' . __('Selected', 'gravityforms') . ')');
                 }
                 foreach ($field['inputs'] as $input) {
                     if (RGFormsModel::get_input_type($field) == 'creditcard') {
                         //only include the credit card type (field_id.4) and number (field_id.1)
                         if ($input['id'] == $field['id'] . '.1' || $input['id'] == $field['id'] . '.4') {
                             $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id']));
                         }
                     } else {
                         $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;
 }
Пример #14
0
 /**
  * Adds a single Entry object.
  *
  * Intended to be used for importing an entry object. The usual hooks that are triggered while saving entries are not fired here.
  * Checks that the form id, field ids and entry meta exist and ignores legacy values (i.e. values for fields that no longer exist).
  *
  * @since  1.8
  * @access public
  * @static
  *
  * @param array $entry The Entry object
  *
  * @return mixed Either the new Entry ID or a WP_Error instance
  */
 public static function add_entry($entry)
 {
     global $wpdb;
     if (!is_array($entry)) {
         return new WP_Error('invalid_entry_object', __('The entry object must be an array', 'gravityforms'));
     }
     // make sure the form id exists
     $form_id = rgar($entry, 'form_id');
     if (empty($form_id)) {
         return new WP_Error('empty_form_id', __('The form id must be specified', 'gravityforms'));
     }
     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']) && $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'] : esc_url_raw(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')) ? sprintf("'%s'", 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();
     $result = $wpdb->query($wpdb->prepare("\n                INSERT INTO {$lead_table}\n                (form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, status, payment_method)\n                VALUES\n                (%d, {$post_id}, {$date_created}, %d,  %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)\n                ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method));
     if (false === $result) {
         return new WP_Error('insert_entry_properties_failed', __('There was a problem while inserting the entry properties', 'gravityforms'), $wpdb->last_error);
     }
     // reading newly created lead id
     $entry_id = $wpdb->insert_id;
     $entry['id'] = $entry_id;
     // only save field values for fields that currently exist in the form
     $form = GFFormsModel::get_form_meta($form_id);
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         if (in_array($field->type, array('html', 'page', 'section'))) {
             continue;
         }
         $inputs = $field->get_entry_inputs();
         if (is_array($inputs)) {
             foreach ($inputs as $input) {
                 $input_id = (string) $input['id'];
                 if (isset($entry[$input_id])) {
                     $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $input_id, $entry[$input_id]);
                     if (false === $result) {
                         return new WP_Error('insert_input_value_failed', __('There was a problem while inserting one of the input values for the entry', 'gravityforms'), $wpdb->last_error);
                     }
                 }
             }
         } else {
             $field_id = $field->id;
             $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : '';
             $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $field_id, $field_value);
             if (false === $result) {
                 return new WP_Error('insert_field_values_failed', __('There was a problem while inserting the field values', 'gravityforms'), $wpdb->last_error);
             }
         }
     }
     // 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], $form['id']);
             }
         }
     }
     // Refresh the entry
     $entry = GFAPI::get_entry($entry['id']);
     /**
      * Fires after the Entry is added using the API.
      *
      * @since  1.9.14.26
      *
      * @param array $entry
      * @param array $form
      */
     do_action('gform_post_add_entry', $entry, $form);
     return $entry_id;
 }
Пример #15
0
 public static function get_field_map_choices($form_id, $field_type = null)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     // Adding default fields
     if (is_null($field_type)) {
         $fields[] = array('value' => '', 'label' => '');
         $fields[] = array('value' => 'date_created', 'label' => __('Entry Date', 'gravityforms'));
         $fields[] = array('value' => 'ip', 'label' => __('User IP', 'gravityforms'));
         $fields[] = array('value' => 'source_url', 'label' => __('Source Url', 'gravityforms'));
         $fields[] = array('value' => 'form_title', 'label' => __('Form Title', 'gravityforms'));
     }
     // Populate entry meta
     $entry_meta = GFFormsModel::get_entry_meta($form['id']);
     foreach ($entry_meta as $meta_key => $meta) {
         $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label"));
     }
     // Populate form fields
     if (is_array($form['fields'])) {
         foreach ($form['fields'] as $field) {
             $inputs = $field->get_entry_inputs();
             $field_is_valid_type = is_null($field_type) || is_array($field_type) && in_array(RGFormsModel::get_input_type($field), $field_type) || !is_null($field_type) && RGFormsModel::get_input_type($field) == $field_type;
             if (is_array($inputs) && $field_is_valid_type) {
                 //If this is an address field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == '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 (RGFormsModel::get_input_type($field) == 'name') {
                     $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . __('Full', 'gravityforms') . ')');
                 }
                 //If this is a checkbox field, add to the list
                 if (RGFormsModel::get_input_type($field) == 'checkbox') {
                     $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . __('Selected', 'gravityforms') . ')');
                 }
                 foreach ($inputs as $input) {
                     $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id']));
                 }
             } elseif (!rgar($field, 'displayOnly') && $field_is_valid_type) {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field));
             }
         }
     }
     return $fields;
 }
Пример #16
0
 /**
  * Adds a single Entry object.
  *
  * Intended to be used for importing an entry object. The usual hooks that are triggered while saving entries are not fired here.
  * Checks that the form id, field ids and entry meta exist and ignores legacy values (i.e. values for fields that no longer exist).
  *
  * @since  1.8
  * @access public
  * @static
  *
  * @param array $entry The Entry object
  *
  * @return mixed Either the new Entry ID or a WP_Error instance
  */
 public static function add_entry($entry)
 {
     global $wpdb;
     if (!is_array($entry)) {
         return new WP_Error("invalid_entry_object", __("The entry object must be an array", "gravityforms"));
     }
     // make sure the form id exists
     $form_id = rgar($entry, "form_id");
     if (empty($form_id)) {
         return new WP_Error("empty_form_id", __("The form id must be specified", "gravityforms"));
     }
     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"]) && $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")) ? sprintf("'%s'", 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                INSERT INTO {$lead_table}\n                (form_id, post_id, date_created, is_starred, is_read, ip, source_url, user_agent, currency, payment_status, payment_date, payment_amount, transaction_id, is_fulfilled, created_by, transaction_type, status, payment_method)\n                VALUES\n                (%d, {$post_id}, {$date_created}, %d,  %d, %s, %s, %s, %s, {$payment_status}, {$payment_date}, {$payment_amount}, {$transaction_id}, {$is_fulfilled}, {$user_id}, {$transaction_type}, %s, %s)\n                ", $form_id, $is_starred, $is_read, $ip, $source_url, $user_agent, $currency, $status, $payment_method));
     if (false === $result) {
         return new WP_Error("insert_entry_properties_failed", __("There was a problem while inserting the entry properties", "gravityforms"), $wpdb->last_error);
     }
     // reading newly created lead id
     $entry_id = $wpdb->insert_id;
     $entry["id"] = $entry_id;
     // only save field values for fields that currently exist in the form
     $form = GFFormsModel::get_form_meta($form_id);
     foreach ($form["fields"] as $field) {
         if (in_array($field["type"], array("html", "page", "section"))) {
             continue;
         }
         if (isset($field["inputs"]) && is_array($field["inputs"])) {
             foreach ($field["inputs"] as $input) {
                 $input_id = $input["id"];
                 if (isset($entry[(string) $input_id])) {
                     $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $input_id, $entry[(string) $input_id]);
                     if (false === $result) {
                         return new WP_Error("insert_input_value_failed", __("There was a problem while inserting one of the input values for the entry", "gravityforms"), $wpdb->last_error);
                     }
                 }
             }
         } else {
             $field_id = $field["id"];
             $field_value = isset($entry[(string) $field_id]) ? $entry[(string) $field_id] : "";
             $result = GFFormsModel::update_lead_field_value($form, $entry, $field, 0, $field_id, $field_value);
             if (false === $result) {
                 return new WP_Error("insert_field_values_failed", __("There was a problem while inserting the field values", "gravityforms"), $wpdb->last_error);
             }
         }
     }
     // 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]);
             }
         }
     }
     return $entry_id;
 }
Пример #17
0
 public static function get_entry_meta_filter_settings($form_id)
 {
     $filters = array();
     $entry_meta = GFFormsModel::get_entry_meta($form_id);
     if (empty($entry_meta)) {
         return $filters;
     }
     foreach ($entry_meta as $key => $meta) {
         if (isset($meta["filter"])) {
             $filter = array();
             $filter["key"] = $key;
             $filter["preventMultiple"] = isset($meta["filter"]["preventMultiple"]) ? $meta["filter"]["preventMultiple"] : false;
             $filter["text"] = rgar($meta, "label");
             $filter["operators"] = isset($meta["filter"]["operators"]) ? $meta["filter"]["operators"] : array("is", "isnot");
             if (isset($meta["filter"]["choices"])) {
                 $filter["values"] = $meta["filter"]["choices"];
             }
             $filters[] = $filter;
         }
     }
     return $filters;
 }
Пример #18
0
 private static function sort_by_column_query($form_id, $search_criteria, $sorting, $paging)
 {
     global $wpdb;
     $sort_field = isset($sorting["key"]) ? $sorting["key"] : "date_created";
     $sort_direction = isset($sorting["direction"]) ? $sorting["direction"] : "DESC";
     $is_numeric_sort = isset($sorting["is_numeric"]) ? $sorting["is_numeric"] : false;
     $offset = isset($paging["offset"]) ? $paging["offset"] : 0;
     $page_size = isset($paging["page_size"]) ? $paging["page_size"] : 20;
     if (!is_numeric($form_id) || !is_numeric($offset) || !is_numeric($page_size)) {
         return "";
     }
     $lead_detail_table_name = GFFormsModel::get_lead_details_table_name();
     $lead_table_name = GFFormsModel::get_lead_table_name();
     $lead_meta_table_name = GFFormsModel::get_lead_meta_table_name();
     $entry_meta = GFFormsModel::get_entry_meta($form_id);
     $entry_meta_sql_join = "";
     if (false === empty($entry_meta) && array_key_exists($sort_field, $entry_meta)) {
         $entry_meta_sql_join = $wpdb->prepare("INNER JOIN\n                                                    (\n                                                    SELECT\n                                                         lead_id, meta_value as {$sort_field}\n                                                         from {$lead_meta_table_name}\n                                                         WHERE meta_key=%s\n                                                    ) lead_meta_data ON lead_meta_data.lead_id = l.id\n                                                    ", $sort_field);
         $is_numeric_sort = $entry_meta[$sort_field]['is_numeric'];
     }
     $grid_columns = RGFormsModel::get_grid_columns($form_id);
     if ($sort_field != "date_created" && false === array_key_exists($sort_field, $grid_columns)) {
         $sort_field = "date_created";
     }
     $orderby = $is_numeric_sort ? "ORDER BY ({$sort_field}+0) {$sort_direction}" : "ORDER BY {$sort_field} {$sort_direction}";
     $where_arr = array();
     $search_where = self::get_search_where($form_id, $search_criteria);
     if (!empty($search_where)) {
         $where_arr[] = $search_where;
     }
     $info_search_where = self::get_info_search_where($search_criteria);
     if (!empty($info_search_where)) {
         $where_arr[] = $info_search_where;
     }
     $form_id_where = $form_id > 0 ? $wpdb->prepare("l.form_id=%d", $form_id) : "";
     if (!empty($form_id_where)) {
         $where_arr[] = $form_id_where;
     }
     $where = empty($where_arr) ? "" : "WHERE " . join($where_arr, " AND ");
     $sql = "\n            SELECT filtered.sort, l.*, d.field_number, d.value\n            FROM {$lead_table_name} l\n            INNER JOIN {$lead_detail_table_name} d ON d.lead_id = l.id\n            INNER JOIN\n            (\n                SELECT @rownum:=@rownum + 1 as sort, id\n                FROM\n                (\n                    SELECT distinct l.id\n                    FROM {$lead_table_name} l\n                    INNER JOIN {$lead_detail_table_name} d ON d.lead_id = l.id\n                    {$entry_meta_sql_join}\n\t\t\t\t\t{$where}\n                    {$orderby}\n                    LIMIT {$offset},{$page_size}\n                ) page\n            ) filtered ON filtered.id = l.id\n\n            ORDER BY filtered.sort";
     return $sql;
 }
Пример #19
0
    /**
     * Builds the Notification Edit page.
     *
     * Called from GFNotification::notification_page
     *
     * @access public
     * @static
     * @see RGFormsModel::get_form_meta
     * @see GFNotification::get_notification
     * @see GFNotification::validate_notification
     * @see GFNotification::get_notification_ui_settings
     * @see GFFormsModel::sanitize_conditional_logic
     *
     * @param int $form_id         The ID of the form that the notification belongs to
     * @param int $notification_id The ID of the notification being edited
     */
    public static function notification_edit_page($form_id, $notification_id)
    {
        if (!rgempty('gform_notification_id')) {
            $notification_id = rgpost('gform_notification_id');
        }
        $form = RGFormsModel::get_form_meta($form_id);
        /**
         * Filters the form to be used in the notification page
         *
         * @since 1.8.6
         *
         * @param array $form            The Form Object
         * @param int   $notification_id The notification ID
         */
        $form = gf_apply_filters(array('gform_form_notification_page', $form_id), $form, $notification_id);
        $notification = !$notification_id ? array() : self::get_notification($form, $notification_id);
        // added second condition to account for new notifications with errors as notification ID will
        // be available in $_POST but the notification has not actually been saved yet
        $is_new_notification = empty($notification_id) || empty($notification);
        $is_valid = true;
        $is_update = false;
        if (rgpost('save')) {
            check_admin_referer('gforms_save_notification', 'gforms_save_notification');
            //clear out notification because it could have legacy data populated
            $notification = array('isActive' => isset($notification['isActive']) ? rgar($notification, 'isActive') : true);
            $is_update = true;
            if ($is_new_notification) {
                $notification_id = uniqid();
                $notification['id'] = $notification_id;
            } else {
                $notification['id'] = $notification_id;
            }
            $notification['name'] = sanitize_text_field(rgpost('gform_notification_name'));
            $notification['service'] = sanitize_text_field(rgpost('gform_notification_service'));
            $notification['event'] = sanitize_text_field(rgpost('gform_notification_event'));
            $notification['to'] = rgpost('gform_notification_to_type') == 'field' ? rgpost('gform_notification_to_field') : rgpost('gform_notification_to_email');
            $to_type = rgpost('gform_notification_to_type');
            if (!in_array($to_type, array('email', 'field', 'routing', 'hidden'))) {
                $to_type = 'email';
            }
            $notification['toType'] = $to_type;
            $notification['bcc'] = rgpost('gform_notification_bcc');
            $notification['subject'] = sanitize_text_field(rgpost('gform_notification_subject'));
            $notification['message'] = rgpost('gform_notification_message');
            $notification['from'] = sanitize_text_field(rgpost('gform_notification_from'));
            $notification['fromName'] = sanitize_text_field(rgpost('gform_notification_from_name'));
            $notification['replyTo'] = rgpost('gform_notification_reply_to');
            $routing = !rgempty('gform_routing_meta') ? GFCommon::json_decode(rgpost('gform_routing_meta'), true) : null;
            if (!empty($routing)) {
                $routing_logic = array('rules' => $routing);
                $routing_logic = GFFormsModel::sanitize_conditional_logic($routing_logic);
                $notification['routing'] = $routing_logic['rules'];
            }
            $notification['routing'] = $routing;
            $conditional_logic = !rgempty('gform_conditional_logic_meta') ? GFCommon::json_decode(rgpost('gform_conditional_logic_meta'), true) : null;
            $notification['conditionalLogic'] = GFFormsModel::sanitize_conditional_logic($conditional_logic);
            $notification['disableAutoformat'] = (bool) rgpost('gform_notification_disable_autoformat');
            if (rgpost('gform_is_default')) {
                $notification['isDefault'] = true;
            }
            /**
             * Filters the notification before it is saved
             *
             * @since 1.7
             *
             * @param array $notification        The Notification Object
             * @param array $form                The Form Object
             * @param bool  $is_new_notification True if it is a new notification.  False otherwise.
             */
            $notification = gf_apply_filters(array('gform_pre_notification_save', $form_id), $notification, $form, $is_new_notification);
            //validating input...
            $is_valid = self::validate_notification();
            /**
             * Allows overriding of if the notification passes validation
             *
             * @since 1.9.16
             *
             * @param bool $is_valid      True if it is valid.  False otherwise.
             * @param array $notification The Notification Object
             * @param array $form         The Form Object
             */
            $is_valid = gf_apply_filters(array('gform_notification_validation', $form_id), $is_valid, $notification, $form);
            if ($is_valid) {
                //input valid, updating...
                //emptying notification email if it is supposed to be disabled
                if ($_POST['gform_notification_to_type'] == 'routing') {
                    $notification['to'] = '';
                } else {
                    $notification['routing'] = null;
                }
                // trim values
                $notification = GFFormsModel::trim_conditional_logic_values_from_element($notification, $form);
                $form['notifications'][$notification_id] = $notification;
                RGFormsModel::save_form_notifications($form_id, $form['notifications']);
            }
        }
        if ($is_update && $is_valid) {
            $url = remove_query_arg('nid');
            GFCommon::add_message(sprintf(esc_html__('Notification saved successfully. %sBack to notifications.%s', 'gravityforms'), '<a href="' . esc_url($url) . '">', '</a>'));
            /**
             * Fires an action after a notification has been saved
             *
             * @since 1.9.16
             *
             * @param array $notification        The Notification Object
             * @param array $form                The Form Object
             * @param bool  $is_new_notification True if this is a new notification.  False otherwise.
             */
            gf_do_action(array('gform_post_notification_save', $form_id), $notification, $form, $is_new_notification);
        } else {
            if ($is_update && !$is_valid) {
                GFCommon::add_error_message(esc_html__('Notification could not be updated. Please enter all required information below.', 'gravityforms'));
            }
        }
        // moved page header loading here so the admin messages can be set upon saving and available for the header to print out
        GFFormSettings::page_header(esc_html__('Notifications', 'gravityforms'));
        $notification_ui_settings = self::get_notification_ui_settings($notification, $is_valid);
        $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min';
        ?>
		<link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin<?php 
        echo $min;
        ?>
.css?ver=<?php 
        echo GFCommon::$version;
        ?>
" />

		<script type="text/javascript">

		var gform_has_unsaved_changes = false;
		jQuery(document).ready(function () {

			jQuery("#entry_form input, #entry_form textarea, #entry_form select").change(function () {
				gform_has_unsaved_changes = true;
			});

			window.onbeforeunload = function () {
				if (gform_has_unsaved_changes) {
					return "You have unsaved changes.";
				}
			};

			ToggleConditionalLogic(true, 'notification');

			jQuery(document).on('change', '.gfield_routing_value_dropdown', function () {
				SetRoutingValueDropDown(jQuery(this));
			});

		});

		gform.addFilter("gform_merge_tags", "MaybeAddSaveLinkMergeTag");
		function MaybeAddSaveLinkMergeTag(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
			var event = document.getElementById('gform_notification_event').value;
			if ( event == 'form_saved' || event == 'form_save_email_requested' ) {
				mergeTags["other"].tags.push({ tag: '{save_link}', label: <?php 
        echo json_encode(esc_html__('Save & Continue Link', 'gravityforms'));
        ?>
 });
				mergeTags["other"].tags.push({ tag: '{save_token}', label: <?php 
        echo json_encode(esc_html__('Save & Continue Token', 'gravityforms'));
        ?>
 });
			}

			return mergeTags;
		}

		<?php 
        if (empty($form['notifications'])) {
            $form['notifications'] = array();
        }
        $entry_meta = GFFormsModel::get_entry_meta($form_id);
        /**
         * Filters the entry meta when notification conditional logic is being edited
         *
         * @since 1.7.6
         *
         * @param array $entry_meta      The Entry meta
         * @param array $form            The Form Object
         * @param int   $notification_id The notification ID
         */
        $entry_meta = apply_filters('gform_entry_meta_conditional_logic_notifications', $entry_meta, $form, $notification_id);
        ?>

		var form = <?php 
        echo json_encode($form);
        ?>
;
		var current_notification = <?php 
        echo GFCommon::json_encode($notification);
        ?>
;
		var entry_meta = <?php 
        echo GFCommon::json_encode($entry_meta);
        ?>
;


		function SetRoutingValueDropDown(element) {
			//parsing ID to get routing Index
			var index = element.attr("id").replace("routing_value_", '');
			SetRouting(index);
		}

		function CreateRouting(routings) {
			var str = '';
			for (var i = 0; i < routings.length; i++) {

				var isSelected = routings[i].operator == 'is' ? "selected='selected'" : '';
				var isNotSelected = routings[i].operator == 'isnot' ? "selected='selected'" : '';
				var greaterThanSelected = routings[i].operator == '>' ? "selected='selected'" : '';
				var lessThanSelected = routings[i].operator == '<' ? "selected='selected'" : '';
				var containsSelected = routings[i].operator == 'contains' ? "selected='selected'" : '';
				var startsWithSelected = routings[i].operator == 'starts_with' ? "selected='selected'" : '';
				var endsWithSelected = routings[i].operator == 'ends_with' ? "selected='selected'" : '';
				var email = routings[i]["email"] ? routings[i]["email"] : '';

				str += "<div style='width:99%'>" + <?php 
        echo json_encode(esc_html__('Send to', 'gravityforms'));
        ?>
 + " <input type='text' id='routing_email_" + i + "' value='" + email + "' onkeyup='SetRouting(" + i + ");'/>";
				str += " " + <?php 
        echo json_encode(esc_html__('if', 'gravityforms'));
        ?>
 + " " + GetRoutingFields(i, routings[i].fieldId);
				str += "<select id='routing_operator_" + i + "' onchange='SetRouting(" + i + ");' class='gform_routing_operator'>";
				str += "<option value='is' " + isSelected + ">" + <?php 
        echo json_encode(esc_html__('is', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='isnot' " + isNotSelected + ">" + <?php 
        echo json_encode(esc_html__('is not', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='>' " + greaterThanSelected + ">" + <?php 
        echo json_encode(esc_html__('greater than', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='<' " + lessThanSelected + ">" + <?php 
        echo json_encode(esc_html__('less than', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='contains' " + containsSelected + ">" + <?php 
        echo json_encode(esc_html__('contains', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='starts_with' " + startsWithSelected + ">" + <?php 
        echo json_encode(esc_html__('starts with', 'gravityforms'));
        ?>
 + "</option>";
				str += "<option value='ends_with' " + endsWithSelected + ">" + <?php 
        echo json_encode(esc_html__('ends with', 'gravityforms'));
        ?>
 + "</option>";
				str += "</select>";
				str += GetRoutingValues(i, routings[i].fieldId, routings[i].value);
				str += "<a class='gf_insert_field_choice' title='add another rule' onclick=\"InsertRouting(" + (i + 1) + ");\" onkeypress=\"InsertRouting(" + (i + 1) + ");\"><i class='gficon-add'></i></a>";
				if (routings.length > 1)
					str += "<a class='gf_delete_field_choice' title='remove this rule' onclick=\"DeleteRouting(" + i + ");\" onkeypress=\"DeleteRouting(" + i + ");\"><i class='gficon-subtract'></i></a>";

				str += "</div>";
			}

			jQuery("#gform_notification_to_routing_rules").html(str);
		}

		function GetRoutingValues(index, fieldId, selectedValue) {
			var str = GetFieldValues(index, fieldId, selectedValue, 16);

			return str;
		}

		function GetRoutingFields(index, selectedItem) {
			var str = "<select id='routing_field_id_" + index + "' class='gfield_routing_select' onchange='jQuery(\"#routing_value_" + index + "\").replaceWith(GetRoutingValues(" + index + ", jQuery(this).val())); SetRouting(" + index + "); '>";
			str += GetSelectableFields(selectedItem, 16);
			str += "</select>";

			return str;
		}

		//---------------------- generic ---------------
		function GetSelectableFields(selectedFieldId, labelMaxCharacters) {
			var str = "";
			var inputType;
			for (var i = 0; i < form.fields.length; i++) {
				inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
				//see if this field type can be used for conditionals
				if (IsNotificationConditionalLogicField(form.fields[i])) {
					var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : "";
					str += "<option value='" + form.fields[i].id + "' " + selected + ">" + form.fields[i].label + "</option>";
				}
			}
			return str;
		}

		function IsNotificationConditionalLogicField(field) {
			//this function is a duplicate of IsConditionalLogicField from form_editor.js
			inputType = field.inputType ? field.inputType : field.type;
			var supported_fields = ['checkbox', 'radio', 'select', 'text', 'website', 'textarea', 'email', 'hidden', 'number', 'phone', 'multiselect', 'post_title',
				'post_tags', 'post_custom_field', 'post_content', 'post_excerpt'];

			var index = jQuery.inArray(inputType, supported_fields);

			return index >= 0;
		}

		function GetFirstSelectableField() {
			var inputType;
			for (var i = 0; i < form.fields.length; i++) {
				inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
				if (IsNotificationConditionalLogicField(form.fields[i])) {
					return form.fields[i].id;
				}
			}

			return 0;
		}

		function TruncateMiddle(text, maxCharacters) {
			if (!text)
				return "";

			if (text.length <= maxCharacters)
				return text;
			var middle = parseInt(maxCharacters / 2);
			return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle);

		}

		function GetFieldValues(index, fieldId, selectedValue, labelMaxCharacters) {
			if (!fieldId)
				fieldId = GetFirstSelectableField();

			if (!fieldId)
				return "";

			var str = '';
			var field = GetFieldById(fieldId);
			var isAnySelected = false;

			if (!field)
				return "";

			if (field["type"] == 'post_category' && field["displayAllCategories"]) {
				var dropdown_id = 'routing_value_' + index;
				var dropdown = jQuery('#' + dropdown_id + ".gfield_category_dropdown");

				//don't load category drop down if it already exists (to avoid unecessary ajax requests)
				if (dropdown.length > 0) {

					var options = dropdown.html();
					options = options.replace("value=\"" + selectedValue + "\"", "value=\"" + selectedValue + "\" selected=\"selected\"");
					str = "<select id='" + dropdown_id + "' class='gfield_routing_select gfield_category_dropdown gfield_routing_value_dropdown'>" + options + "</select>";
				}
				else {
					//loading categories via AJAX
					jQuery.post(ajaxurl, {   action: "gf_get_notification_post_categories",
							ruleIndex              : index,
							selectedValue          : selectedValue},
						function (dropdown_string) {
							if (dropdown_string) {
								jQuery('#gfield_ajax_placeholder_' + index).replaceWith(dropdown_string.trim());
							}
						}
					);

					//will be replaced by real drop down during the ajax callback
					str = "<select id='gfield_ajax_placeholder_" + index + "' class='gfield_routing_select'><option>" + <?php 
        json_encode(esc_html__('Loading...', 'gravityforms'));
        ?>
 + "</option></select>";
				}
			}
			else if (field.choices) {
				//create a drop down for fields that have choices (i.e. drop down, radio, checkboxes, etc...)
				str = "<select class='gfield_routing_select gfield_routing_value_dropdown' id='routing_value_" + index + "'>";
				for (var i = 0; i < field.choices.length; i++) {
					var choiceValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text;
					var isSelected = choiceValue == selectedValue;
					var selected = isSelected ? "selected='selected'" : '';
					if (isSelected)
						isAnySelected = true;

					str += "<option value='" + choiceValue.replace(/'/g, "&#039;") + "' " + selected + ">" + field.choices[i].text + "</option>";
				}

				if (!isAnySelected && selectedValue) {
					str += "<option value='" + selectedValue.replace(/'/g, "&#039;") + "' selected='selected'>" + selectedValue + "</option>";
				}
				str += "</select>";
			}
			else {
				selectedValue = selectedValue ? selectedValue.replace(/'/g, "&#039;") : "";
				//create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...)
				str = "<input type='text' placeholder='" + <?php 
        echo json_encode(esc_html__('Enter value', 'gravityforms'));
        ?>
 +"' class='gfield_routing_select' id='routing_value_" + index + "' value='" + selectedValue.replace(/'/g, "&#039;") + "' onchange='SetRouting(" + index + ");' onkeyup='SetRouting(" + index + ");'>";
			}
			return str;
		}

		//---------------------------------------------------------------------------------

		function InsertRouting(index) {
			var routings = current_notification.routing;
			routings.splice(index, 0, new ConditionalRule());

			CreateRouting(routings);
			SetRouting(index);
		}

		function SetRouting(ruleIndex) {
			if (!current_notification.routing && ruleIndex == 0)
				current_notification.routing = [new ConditionalRule()];

			current_notification.routing[ruleIndex]["email"] = jQuery("#routing_email_" + ruleIndex).val();
			current_notification.routing[ruleIndex]["fieldId"] = jQuery("#routing_field_id_" + ruleIndex).val();
			current_notification.routing[ruleIndex]["operator"] = jQuery("#routing_operator_" + ruleIndex).val();
			current_notification.routing[ruleIndex]["value"] = jQuery("#routing_value_" + ruleIndex).val();

			var json = jQuery.toJSON(current_notification.routing);
			jQuery('#gform_routing_meta').val(json);
		}

		function DeleteRouting(ruleIndex) {
			current_notification.routing.splice(ruleIndex, 1);
			CreateRouting(current_notification.routing);
		}

		function SetConditionalLogic(isChecked) {
			current_notification.conditionalLogic = isChecked ? new ConditionalLogic() : null;
		}

		function SaveJSMeta() {
			jQuery('#gform_routing_meta').val(jQuery.toJSON(current_notification.routing));
			jQuery('#gform_conditional_logic_meta').val(jQuery.toJSON(current_notification.conditionalLogic));
		}

		<?php 
        GFFormSettings::output_field_scripts();
        ?>

		</script>

		<form method="post" id="gform_notification_form" onsubmit="gform_has_unsaved_changes = false; SaveJSMeta();">

			<?php 
        wp_nonce_field('gforms_save_notification', 'gforms_save_notification');
        ?>
			<?php 
        if (rgar($notification, 'isDefault')) {
            echo '<input type="hidden" id="gform_is_default" name="gform_is_default" value="1"/>';
        }
        ?>
			<input type="hidden" id="gform_routing_meta" name="gform_routing_meta" />
			<input type="hidden" id="gform_conditional_logic_meta" name="gform_conditional_logic_meta" />
			<input type="hidden" id="gform_notification_id" name="gform_notification_id" value="<?php 
        echo esc_attr($notification_id);
        ?>
" />

			<table class="form-table gform_nofification_edit">
				<?php 
        array_map(array('GFFormSettings', 'output'), $notification_ui_settings);
        ?>
			</table>

			<p class="submit">
				<?php 
        $button_label = $is_new_notification ? __('Save Notification', 'gravityforms') : __('Update Notification', 'gravityforms');
        $notification_button = '<input class="button-primary" type="submit" value="' . esc_attr($button_label) . '" name="save"/>';
        /**
         * Filters the "Save Notification" button
         *
         * @param string $notification_button The notification button HTML
         */
        echo apply_filters('gform_save_notification_button', $notification_button);
        ?>
			</p>
		</form>

		<?php 
        GFFormSettings::page_footer();
    }
Пример #20
0
 public static function get_grid_columns($form_id, $input_label_only = false)
 {
     $form = self::get_form_meta($form_id);
     $field_ids = self::get_grid_column_meta($form_id);
     if (!is_array($field_ids)) {
         $field_ids = array();
         for ($i = 0, $count = sizeof($form["fields"]); $i < $count && $i < 5; $i++) {
             $field = $form["fields"][$i];
             if (RGForms::get("displayOnly", $field) || self::get_input_type($field) == "list") {
                 continue;
             }
             if (isset($field["inputs"]) && is_array($field["inputs"])) {
                 if ($field["type"] == "name") {
                     $field_ids[] = $field["id"] . '.3';
                     //adding first name
                     $field_ids[] = $field["id"] . '.6';
                     //adding last name
                 } else {
                     if (isset($field["inputs"][0])) {
                         $field_ids[] = $field["inputs"][0]["id"];
                         //getting first input
                     }
                 }
             } else {
                 $field_ids[] = $field["id"];
             }
         }
         //adding default entry meta columns
         $entry_metas = GFFormsModel::get_entry_meta($form_id);
         foreach ($entry_metas as $key => $entry_meta) {
             if (rgar($entry_meta, "is_default_column")) {
                 $field_ids[] = $key;
             }
         }
     }
     $columns = array();
     $entry_meta = self::get_entry_meta($form_id);
     foreach ($field_ids as $field_id) {
         switch ($field_id) {
             case "id":
                 $columns[$field_id] = array("label" => "Entry Id", "type" => "id");
                 break;
             case "ip":
                 $columns[$field_id] = array("label" => "User IP", "type" => "ip");
                 break;
             case "date_created":
                 $columns[$field_id] = array("label" => "Entry Date", "type" => "date_created");
                 break;
             case "source_url":
                 $columns[$field_id] = array("label" => "Source Url", "type" => "source_url");
                 break;
             case "payment_status":
                 $columns[$field_id] = array("label" => "Payment Status", "type" => "payment_status");
                 break;
             case "transaction_id":
                 $columns[$field_id] = array("label" => "Transaction Id", "type" => "transaction_id");
                 break;
             case "payment_date":
                 $columns[$field_id] = array("label" => "Payment Date", "type" => "payment_date");
                 break;
             case "payment_amount":
                 $columns[$field_id] = array("label" => "Payment Amount", "type" => "payment_amount");
                 break;
             case "created_by":
                 $columns[$field_id] = array("label" => "User", "type" => "created_by");
                 break;
             case (is_string($field_id) || is_int($field_id)) && array_key_exists($field_id, $entry_meta):
                 $columns[$field_id] = array("label" => $entry_meta[$field_id]["label"], "type" => $field_id);
                 break;
             default:
                 $field = self::get_field($form, $field_id);
                 if ($field) {
                     $columns[strval($field_id)] = array("label" => self::get_label($field, $field_id, $input_label_only), "type" => rgget("type", $field), "inputType" => rgget("inputType", $field));
                 }
         }
     }
     return $columns;
 }
Пример #21
0
 public static function get_entry_meta_filter_settings($form_id)
 {
     $filters = array();
     $entry_meta = GFFormsModel::get_entry_meta($form_id);
     if (empty($entry_meta)) {
         return $filters;
     }
     foreach ($entry_meta as $key => $meta) {
         if (isset($meta['filter'])) {
             $filter = array();
             $filter['key'] = $key;
             $filter['preventMultiple'] = isset($meta['filter']['preventMultiple']) ? $meta['filter']['preventMultiple'] : false;
             $filter['text'] = rgar($meta, 'label');
             $filter['operators'] = isset($meta['filter']['operators']) ? $meta['filter']['operators'] : array('is', 'isnot');
             if (isset($meta['filter']['choices'])) {
                 $filter['values'] = $meta['filter']['choices'];
             }
             $filters[] = $filter;
         }
     }
     return $filters;
 }
Пример #22
0
 /**
  * get extra fields from entry meta
  * @param  string $form_id (default: '')
  * @return array
  */
 public static function get_entry_meta($form_id, $only_default_column = true)
 {
     $extra_fields = GFFormsModel::get_entry_meta($form_id);
     $fields = array();
     foreach ($extra_fields as $key => $field) {
         if (!empty($only_default_column) && !empty($field['is_default_column'])) {
             $fields[$key] = array('label' => $field['label'], 'type' => 'entry_meta');
         }
     }
     return $fields;
 }
Пример #23
0
    public static function confirmations_edit_page($form_id, $confirmation_id)
    {
        $form = apply_filters("gform_admin_pre_render_{$form_id}", apply_filters("gform_admin_pre_render", GFFormsModel::get_form_meta($form_id)));
        $confirmation = self::handle_confirmation_edit_submission(rgar($form["confirmations"], $confirmation_id), $form);
        $confirmation_ui_settings = self::get_confirmation_ui_settings($confirmation);
        $entry_meta = GFFormsModel::get_entry_meta($form_id);
        $entry_meta = apply_filters("gform_entry_meta_conditional_logic_confirmations", $entry_meta, $form, $confirmation_id);
        self::page_header(__('Confirmations', 'gravityforms'));
        ?>



        <script type="text/javascript">



            var confirmation = <?php 
        echo $confirmation ? json_encode($confirmation) : 'new ConfirmationObj()';
        ?>
;

            var form = <?php 
        echo json_encode($form);
        ?>
;

            var entry_meta = <?php 
        echo GFCommon::json_encode($entry_meta);
        ?>
;



            jQuery(document).ready(function($){



                SetConfirmationConditionalLogic();

                <?php 
        if (!rgar($confirmation, 'isDefault')) {
            ?>

			    ToggleConditionalLogic(true, 'confirmation');

                <?php 
        }
        ?>

                ToggleConfirmation();



		    });



        </script>



        <style type="text/css">

            #confirmation_action_type { display: none; }

        </style>



        <div id="confirmation-editor">



            <form id="confirmation_edit_form" method="post">



                <table class="form-table gforms_form_settings">

                    <?php 
        array_map(array(__CLASS__, 'output'), $confirmation_ui_settings);
        ?>

                </table>



                <?php 
        //DEPRECATED SINCE 1.7 - use gform_confirmation_ui_settings instead
        do_action("gform_confirmation_settings", 100, $form_id);
        do_action("gform_confirmation_settings", 200, $form_id);
        ?>



                <input type="hidden" id="confirmation_id" name="confirmation_id" value="<?php 
        echo $confirmation_id;
        ?>
" />

                <input type="hidden" id="form_id" name="form_id" value="<?php 
        echo $form_id;
        ?>
" />

                <input type="hidden" id="is_default" name="is_default" value="<?php 
        echo rgget("isDefault", $confirmation);
        ?>
" />

                <input type="hidden" id="conditional_logic" name="conditional_logic" value='<?php 
        echo json_encode(rgget('conditionalLogic', $confirmation));
        ?>
' />



                <p class="submit">

                    <input type="submit" name="save" value="<?php 
        _e('Save Confirmation', 'gravityforms');
        ?>
" onclick="StashConditionalLogic(event);" class="button-primary">

                </p>



                <?php 
        wp_nonce_field('gform_confirmation_edit', 'gform_confirmation_edit');
        ?>



            </form>



        </div> <!-- / confirmation-editor -->



        <?php 
        self::page_footer();
    }
Пример #24
0
 public static function get_field_map_choices($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     // Adding default fields
     $fields[] = array("value" => "", "label" => "");
     $fields[] = array("value" => "date_created", "label" => __("Entry Date", "gravityforms"));
     $fields[] = array("value" => "ip", "label" => __("User IP", "gravityforms"));
     $fields[] = array("value" => "source_url", "label" => __("Source Url", "gravityforms"));
     $fields[] = array("value" => "form_title", "label" => __("Form Title", "gravityforms"));
     // Populate entry meta
     $entry_meta = GFFormsModel::get_entry_meta($form["id"]);
     foreach ($entry_meta as $meta_key => $meta) {
         $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label"));
     }
     // Populate form fields
     if (is_array($form["fields"])) {
         foreach ($form["fields"] as $field) {
             if (is_array(rgar($field, "inputs"))) {
                 //If this is an address field, add full name to the list
                 if (RGFormsModel::get_input_type($field) == "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 (RGFormsModel::get_input_type($field) == "name") {
                     $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Full", "gravityforms") . ")");
                 }
                 //If this is a checkbox field, add to the list
                 if (RGFormsModel::get_input_type($field) == "checkbox") {
                     $fields[] = array('value' => $field["id"], 'label' => GFCommon::get_label($field) . " (" . __("Selected", "gravityforms") . ")");
                 }
                 foreach ($field['inputs'] as $input) {
                     if (RGFormsModel::get_input_type($field) == 'creditcard') {
                         //only include the credit card type (field_id.4) and number (field_id.1)
                         if ($input['id'] == $field['id'] . '.1' || $input['id'] == $field['id'] . '.4') {
                             $fields[] = array('value' => $input["id"], 'label' => GFCommon::get_label($field, $input['id']));
                         }
                     } else {
                         $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;
 }
Пример #25
0
 private static function get_entry_meta($form)
 {
     $entry_meta = GFFormsModel::get_entry_meta($form["id"]);
     $keys = array_keys($entry_meta);
     foreach ($keys as $key) {
         array_push($form["fields"], array("id" => $key, "label" => $entry_meta[$key]['label']));
     }
     return $form;
 }
 private static function sort_by_column_query($form_id, $search_criteria, $sorting, $paging)
 {
     global $wpdb;
     $sort_field = isset($sorting['key']) ? $sorting['key'] : 'date_created';
     $sort_direction = isset($sorting['direction']) ? $sorting['direction'] : 'DESC';
     $is_numeric_sort = isset($sorting['is_numeric']) ? $sorting['is_numeric'] : false;
     $offset = isset($paging['offset']) ? $paging['offset'] : 0;
     $page_size = isset($paging['page_size']) ? $paging['page_size'] : 20;
     if (!is_numeric($offset) || !is_numeric($page_size)) {
         return '';
     }
     $lead_detail_table_name = GFFormsModel::get_lead_details_table_name();
     $lead_table_name = GFFormsModel::get_lead_table_name();
     $lead_meta_table_name = GFFormsModel::get_lead_meta_table_name();
     $entry_meta = GFFormsModel::get_entry_meta(is_array($form_id) ? 0 : $form_id);
     $entry_meta_sql_join = '';
     $sort_field_is_entry_meta = false;
     if (false === empty($entry_meta) && array_key_exists($sort_field, $entry_meta)) {
         $entry_meta_sql_join = $wpdb->prepare("\n                INNER JOIN\n                (\n                SELECT\n                     lead_id, meta_value as {$sort_field}\n                     from {$lead_meta_table_name}\n                     WHERE meta_key=%s\n                ) lead_meta_data ON lead_meta_data.lead_id = l.id\n                ", $sort_field);
         $is_numeric_sort = $entry_meta[$sort_field]['is_numeric'];
         $sort_field_is_entry_meta = true;
     } else {
         $db_columns = self::get_lead_db_columns();
         if ($sort_field != 'date_created' && false === in_array($sort_field, $db_columns)) {
             $sort_field = 'date_created';
         }
     }
     if ($sort_field_is_entry_meta) {
         $orderby = $is_numeric_sort ? "ORDER BY ({$sort_field}+0) {$sort_direction}" : "ORDER BY {$sort_field} {$sort_direction}";
     } else {
         $orderby = $is_numeric_sort ? "ORDER BY (l.{$sort_field}+0) {$sort_direction}" : "ORDER BY l.{$sort_field} {$sort_direction}";
     }
     $where = self::get_search_where($form_id, $search_criteria);
     $sql = "\n            SELECT filtered.sort, l.*, d.field_number, d.value\n            FROM {$lead_table_name} l\n            INNER JOIN {$lead_detail_table_name} d ON d.lead_id = l.id\n            INNER JOIN\n            (\n                SELECT @rownum:=@rownum + 1 as sort, id\n                FROM\n                (\n                    SELECT distinct l.id\n                    FROM {$lead_table_name} l\n                    INNER JOIN {$lead_detail_table_name} d ON d.lead_id = l.id\n                    {$entry_meta_sql_join}\n                    {$where}\n                    {$orderby}\n                    LIMIT {$offset},{$page_size}\n                ) page\n            ) filtered ON filtered.id = l.id\n\n            ORDER BY filtered.sort";
     return $sql;
 }
Пример #27
0
 public static function get_field_map_choices($form_id, $field_type = null, $exclude_field_types = null)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     $fields = array();
     $fields[] = array('value' => '', 'label' => '');
     // Adding default fields
     if (is_null($field_type)) {
         $fields[] = array('value' => 'date_created', 'label' => __('Entry Date', 'gravityforms'));
         $fields[] = array('value' => 'ip', 'label' => __('User IP', 'gravityforms'));
         $fields[] = array('value' => 'source_url', 'label' => __('Source Url', 'gravityforms'));
         $fields[] = array('value' => 'form_title', 'label' => __('Form Title', 'gravityforms'));
     }
     // Populate entry meta
     $entry_meta = GFFormsModel::get_entry_meta($form['id']);
     foreach ($entry_meta as $meta_key => $meta) {
         $fields[] = array('value' => $meta_key, 'label' => rgars($entry_meta, "{$meta_key}/label"));
     }
     // Populate form fields
     if (is_array($form['fields'])) {
         foreach ($form['fields'] as $field) {
             $input_type = $field->get_input_type();
             $inputs = $field->get_entry_inputs();
             $field_is_valid_type = is_null($field_type) || is_array($field_type) && in_array($input_type, $field_type) || !is_null($field_type) && $input_type == $field_type;
             if (is_null($exclude_field_types)) {
                 $exclude_field = false;
             } elseif (is_array($exclude_field_types)) {
                 if (in_array($input_type, $exclude_field_types)) {
                     $exclude_field = true;
                 } else {
                     $exclude_field = false;
                 }
             } else {
                 //not array, so should be single string
                 if ($input_type == $exclude_field_types) {
                     $exclude_field = true;
                 } else {
                     $exclude_field = false;
                 }
             }
             if (is_array($inputs) && $field_is_valid_type && !$exclude_field) {
                 //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 ($inputs as $input) {
                     $fields[] = array('value' => $input['id'], 'label' => GFCommon::get_label($field, $input['id']));
                 }
             } elseif ($input_type == 'list' && $field->enableColumns && $field_is_valid_type && !$exclude_field) {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field) . ' (' . __('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 (!rgar($field, 'displayOnly') && $field_is_valid_type && !$exclude_field) {
                 $fields[] = array('value' => $field->id, 'label' => GFCommon::get_label($field));
             }
         }
     }
     return $fields;
 }