Ejemplo n.º 1
0
 /**
  * Saves form meta. Note the special requirements for the meta string.
  *
  * @param        $id
  * @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact.
  *
  * @return array
  */
 public static function save_form_info($id, $form_json)
 {
     global $wpdb;
     $form_json = stripslashes($form_json);
     $form_json = nl2br($form_json);
     GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta json: ' . $form_json);
     $form_meta = json_decode($form_json, true);
     $form_meta = GFFormsModel::convert_field_objects($form_meta);
     GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta => ' . print_r($form_meta, true));
     if (!$form_meta) {
         return array('status' => 'invalid_json', 'meta' => null);
     }
     $form_table_name = $wpdb->prefix . 'rg_form';
     //Making sure title is not duplicate
     $forms = RGFormsModel::get_forms();
     foreach ($forms as $form) {
         if (strtolower($form->title) == strtolower($form_meta['title']) && rgar($form_meta, 'id') != $form->id) {
             return array('status' => 'duplicate_title', 'meta' => $form_meta);
         }
     }
     if ($id > 0) {
         $form_meta = GFFormsModel::trim_form_meta_values($form_meta);
         RGFormsModel::update_form_meta($id, $form_meta);
         //updating form title
         $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta['title'], $form_meta['id']));
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, false);
         return array('status' => $id, 'meta' => $form_meta);
     } else {
         //inserting form
         $id = RGFormsModel::insert_form($form_meta['title']);
         //updating object's id property
         $form_meta['id'] = $id;
         //creating default notification
         if (apply_filters('gform_default_notification', true)) {
             $default_notification = array('id' => uniqid(), 'to' => '{admin_email}', 'name' => __('Admin Notification', 'gravityforms'), 'event' => 'form_submission', 'toType' => 'email', 'subject' => __('New submission from', 'gravityforms') . ' {form_title}', 'message' => '{all_fields}');
             $notifications = array($default_notification['id'] => $default_notification);
             //updating notifications form meta
             RGFormsModel::save_form_notifications($id, $notifications);
         }
         // add default confirmation when saving a new form
         $confirmation_id = uniqid();
         $confirmations = array();
         $confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __('Thanks for contacting us! We will get in touch with you shortly.', 'gravityforms'), 'url' => '', 'pageId' => '', 'queryString' => '');
         GFFormsModel::save_form_confirmations($id, $confirmations);
         //updating form meta
         RGFormsModel::update_form_meta($id, $form_meta);
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, true);
         return array('status' => $id * -1, 'meta' => $form_meta);
     }
 }
Ejemplo n.º 2
0
 public static function import_file($filepath)
 {
     $xmlstr = file_get_contents($filepath);
     require_once "xml.php";
     $options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true));
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms["version"], self::$min_import_version, "<")) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => $form) {
         $title = $form["title"];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form["title"] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form["title"] = $title;
         $form["id"] = $form_id;
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Ejemplo n.º 3
0
 public static function import_xml($xmlstr, &$forms = null)
 {
     require_once 'xml.php';
     $options = array('page' => array('unserialize_as_array' => true), 'form' => array('unserialize_as_array' => true), 'field' => array('unserialize_as_array' => true), 'rule' => array('unserialize_as_array' => true), 'choice' => array('unserialize_as_array' => true), 'input' => array('unserialize_as_array' => true), 'routing_item' => array('unserialize_as_array' => true), 'creditCard' => array('unserialize_as_array' => true), 'routin' => array('unserialize_as_array' => true), 'confirmation' => array('unserialize_as_array' => true), 'notification' => array('unserialize_as_array' => true));
     $options = apply_filters('gform_import_form_xml_options', $options);
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms['version'], self::$min_import_version, '<')) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => &$form) {
         $title = $form['title'];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form['title'] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form['title'] = $title;
         $form['id'] = $form_id;
         $form = GFFormsModel::trim_form_meta_values($form);
         if (isset($form['confirmations'])) {
             $form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
             $form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
             GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
             unset($form['confirmations']);
         }
         if (isset($form['notifications'])) {
             $form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
             $form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
             GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
             unset($form['notifications']);
         }
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Ejemplo n.º 4
0
 /**
  * Saves form meta. Note the special requirements for the meta string.
  *
  * @param $id
  * @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact.
  *
  * @return array
  */
 public static function save_form_info($id, $form_json)
 {
     global $wpdb;
     $form_json = stripslashes($form_json);
     $form_json = nl2br($form_json);
     GFCommon::log_debug("form meta json:" . $form_json);
     $form_meta = json_decode($form_json, true);
     GFCommon::log_debug("form meta:");
     GFCommon::log_debug(print_r($form_json, true));
     if (!$form_meta) {
         return array("status" => "invalid_json", "meta" => null);
     }
     $form_table_name = $wpdb->prefix . "rg_form";
     //Making sure title is not duplicate
     $forms = RGFormsModel::get_forms();
     foreach ($forms as $form) {
         if (strtolower($form->title) == strtolower($form_meta["title"]) && rgar($form_meta, "id") != $form->id) {
             return array("status" => "duplicate_title", "meta" => $form_meta);
         }
     }
     if ($id > 0) {
         $form_meta = GFFormsModel::trim_form_meta_values($form_meta);
         RGFormsModel::update_form_meta($id, $form_meta);
         //updating form title
         $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, false);
         return array("status" => $id, "meta" => $form_meta);
     } else {
         //inserting form
         $id = RGFormsModel::insert_form($form_meta["title"]);
         //updating object's id property
         $form_meta["id"] = $id;
         //creating default notification
         if (apply_filters('gform_default_notification', true)) {
             $default_notification = array("id" => uniqid(), "to" => "{admin_email}", "name" => __("Admin Notification", "gravityforms"), "event" => "form_submission", "toType" => "email", "subject" => __("New submission from", "gravityforms") . " {form_title}", "message" => "{all_fields}");
             $notifications = array($default_notification["id"] => $default_notification);
             //updating notifications form meta
             RGFormsModel::save_form_notifications($id, $notifications);
         }
         // add default confirmation when saving a new form
         $confirmation_id = uniqid();
         $confirmations = array();
         $confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __("Thanks for contacting us! We will get in touch with you shortly.", "gravityforms"), 'url' => '', 'pageId' => '', 'queryString' => '');
         GFFormsModel::save_form_confirmations($id, $confirmations);
         //updating form meta
         RGFormsModel::update_form_meta($id, $form_meta);
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, true);
         return array("status" => $id * -1, "meta" => $form_meta);
     }
 }
 public static function save_form_info($id, $form_json)
 {
     global $wpdb;
     $form_json = stripslashes($form_json);
     //$form_json = preg_replace('|\r\n?|', '\n', $form_json);
     $form_json = nl2br($form_json);
     $form_meta = GFCommon::json_decode($form_json, true);
     if (!$form_meta) {
         return array("status" => "invalid_json", "meta" => null);
     }
     $form_table_name = $wpdb->prefix . "rg_form";
     $meta_table_name = $wpdb->prefix . "rg_form_meta";
     //Making sure title is not duplicate
     $forms = RGFormsModel::get_forms();
     foreach ($forms as $form) {
         if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
             return array("status" => "duplicate_title", "meta" => $form_meta);
         }
     }
     if ($id > 0) {
         RGFormsModel::update_form_meta($id, $form_meta);
         //updating form title
         $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, false);
         return array("status" => $id, "meta" => $form_meta);
     } else {
         //inserting form
         $id = RGFormsModel::insert_form($form_meta["title"]);
         //updating object's id property
         $form_meta["id"] = $id;
         //creating default notification
         if (apply_filters('gform_default_notification', true)) {
             $form_meta["notification"]["to"] = get_bloginfo("admin_email");
             $form_meta["notification"]["subject"] = __("New submission from", "gravityforms") . " {form_title}";
             $form_meta["notification"]["message"] = "{all_fields}";
         }
         //updating form meta
         RGFormsModel::update_form_meta($id, $form_meta);
         $form_meta = RGFormsModel::get_form_meta($id);
         do_action('gform_after_save_form', $form_meta, true);
         return array("status" => $id * -1, "meta" => $form_meta);
     }
 }
Ejemplo n.º 6
0
    public static function metarecovery_page()
    {
        if (RGForms::post("gf_metarecovery_submit")) {
            global $wpdb;
            $table_name = RGFormsModel::get_meta_table_name();
            $form_id = RGForms::post("gf_metarecovery_form_id");
            $meta = $wpdb->get_var($wpdb->prepare("SELECT display_meta FROM {$table_name} WHERE form_id=%d", $form_id));
            //fixing meta
            $meta = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $meta);
            //if successfull, store new meta
            $obj = unserialize($meta);
            if ($obj) {
                RGFormsModel::update_form_meta($form_id, $obj);
                $is_success = true;
            } else {
                $is_failure = true;
            }
        }
        ?>
        <style>
            .left_header{float:left; width:200px;}
            .margin_vertical_10{margin: 10px 0;}
        </style>
        <div class="wrap">
            <form method="post">

                <h2><?php 
        _e("Meta Recovery Utility", "gravityformsmetarecovery");
        ?>
</h2>

                <?php 
        if ($is_success) {
            ?>
                    <div class="updated fade" style="padding:6px"><?php 
            echo sprintf(__("Meta recovered successfully. %sGo to form editor%s", "gravityformsmetarecovery"), "<a href='?page=gf_edit_forms&id={$form_id}'>", "</a>");
            ?>
</div>
                    <?php 
        }
        if ($is_failure) {
            ?>
                    <div class="error" style="padding:6px"><?php 
            echo __("This form's meta could not be recovered.", "gravityformsmetarecovery");
            ?>
</div>
                    <?php 
        }
        ?>
                <div class="margin_vertical_10">
                    <label for="gf_metarecovery_form_id" class="left_header"><?php 
        _e("Gravity Form", "gravityforms_feed");
        ?>
 </label>
                    <select name="gf_metarecovery_form_id" id="gf_metarecovery_form_id">
                        <option value=""><?php 
        _e("Select a form", "gravityforms_feed");
        ?>
 </option>
                        <?php 
        $forms = RGFormsModel::get_forms();
        foreach ($forms as $form) {
            ?>
                            <option value="<?php 
            echo absint($form->id);
            ?>
"><?php 
            echo esc_html($form->title);
            ?>
</option>
                            <?php 
        }
        ?>
                    </select>
                </div>
                <div class="margin_vertical_10">
                    <input type="submit" class="button-primary" name="gf_metarecovery_submit" value="<?php 
        _e("Submit", "gravityformsmetarecovery");
        ?>
" />
                </div>

            </form>
        </div>
        <?php 
    }
Ejemplo n.º 7
0
 public static function save_form()
 {
     global $wpdb;
     check_ajax_referer('rg_save_form', 'rg_save_form');
     $id = $_POST["id"];
     $form_json = $_POST["form"];
     $form_json = stripslashes($form_json);
     //$form_json = preg_replace('|\r\n?|', '\n', $form_json);
     $form_json = nl2br($form_json);
     $form_meta = GFCommon::json_decode($form_json, true);
     if (!$form_meta) {
         die("EndUpdateForm(0);");
     }
     $form_table_name = $wpdb->prefix . "rg_form";
     $meta_table_name = $wpdb->prefix . "rg_form_meta";
     //Making sure title is not duplicate
     $forms = RGFormsModel::get_forms();
     foreach ($forms as $form) {
         if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
             die('DuplicateTitleMessage();');
         }
     }
     if ($id > 0) {
         RGFormsModel::update_form_meta($id, $form_meta);
         //updating form title
         $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
         die("EndUpdateForm({$id});");
     } else {
         //inserting form
         $id = RGFormsModel::insert_form($form_meta["title"]);
         //updating object's id property
         $form_meta["id"] = $id;
         //creating default notification
         if (apply_filters('gform_default_notification', true)) {
             $form_meta["notification"]["to"] = get_bloginfo("admin_email");
             $form_meta["notification"]["subject"] = __("New submission from", "gravityforms") . " {form_title}";
             $form_meta["notification"]["message"] = "{all_fields}";
         }
         //updating form meta
         RGFormsModel::update_form_meta($id, $form_meta);
         die("EndInsertForm({$id});");
     }
 }
Ejemplo n.º 8
0
    public static function notification_page($form_id)
    {
        $form = RGFormsModel::get_form_meta($form_id);
        if ($_POST["save"]) {
            check_admin_referer('gforms_save_notification', 'gforms_save_notification');
            $form["notification"]["to"] = stripslashes($_POST["form_notification_to"]);
            $form["notification"]["bcc"] = stripslashes($_POST["form_notification_bcc"]);
            $form["notification"]["subject"] = stripslashes($_POST["form_notification_subject"]);
            $form["notification"]["message"] = stripslashes($_POST["form_notification_message"]);
            $form["notification"]["from"] = empty($_POST["form_notification_from_field"]) ? stripslashes($_POST["form_notification_from"]) : "";
            $form["notification"]["fromField"] = stripslashes($_POST["form_notification_from_field"]);
            $form["notification"]["fromName"] = empty($_POST["form_notification_from_name_field"]) ? stripslashes($_POST["form_notification_from_name"]) : "";
            $form["notification"]["fromNameField"] = stripslashes($_POST["form_notification_from_name_field"]);
            $form["notification"]["replyTo"] = empty($_POST["form_notification_reply_to_field"]) ? stripslashes($_POST["form_notification_reply_to"]) : "";
            $form["notification"]["replyToField"] = stripslashes($_POST["form_notification_reply_to_field"]);
            $form["notification"]["routing"] = !empty($_POST["gform_routing_meta"]) ? GFCommon::json_decode(stripslashes($_POST["gform_routing_meta"]), true) : null;
            $form["notification"]["disableAutoformat"] = $_POST["form_notification_disable_autoformat"];
            $form["autoResponder"]["toField"] = stripslashes($_POST["form_autoresponder_to"]);
            $form["autoResponder"]["bcc"] = stripslashes($_POST["form_autoresponder_bcc"]);
            $form["autoResponder"]["fromName"] = stripslashes($_POST["form_autoresponder_from_name"]);
            $form["autoResponder"]["from"] = stripslashes($_POST["form_autoresponder_from"]);
            $form["autoResponder"]["replyTo"] = stripslashes($_POST["form_autoresponder_reply_to"]);
            $form["autoResponder"]["subject"] = stripslashes($_POST["form_autoresponder_subject"]);
            $form["autoResponder"]["message"] = stripslashes($_POST["form_autoresponder_message"]);
            $form["autoResponder"]["disableAutoformat"] = $_POST["form_autoresponder_disable_autoformat"];
            //validating input...
            $invalid_tab = self::validate_notification();
            if ($invalid_tab == 0) {
                //input valid, updating...
                //emptying notification email if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_admin"]) || $_POST["notification_to"] == "routing") {
                    $form["notification"]["to"] = "";
                }
                //emptying notification routing if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_admin"]) || $_POST["notification_to"] == "email") {
                    $form["notification"]["routing"] = null;
                }
                //emptying autoResponder settings if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_user"])) {
                    $form["autoResponder"]["toField"] = "";
                }
                RGFormsModel::update_form_meta($form_id, $form);
            }
        }
        $wp_email = get_bloginfo("admin_email");
        $email_fields = GFCommon::get_email_fields($form);
        $name_fields = GFCommon::get_fields_by_type($form, array("name"));
        $has_admin_notification_fields = (!empty($form["notification"]["to"]) || !empty($form["notification"]["routing"])) && (!empty($form["notification"]["subject"]) || !empty($form["notification"]["message"]));
        $has_user_notification_fields = !empty($form["autoResponder"]["toField"]) && (!empty($form["autoResponder"]["subject"]) || !empty($form["autoResponder"]["message"]));
        $is_admin_notification_enabled = $has_admin_notification_fields && empty($_POST["save"]) || !empty($_POST["form_notification_enable_admin"]);
        $is_user_notification_enabled = $has_user_notification_fields && empty($_POST["save"]) || !empty($_POST["form_notification_enable_user"]);
        $is_routing_enabled = !empty($form["notification"]["routing"]) && $_POST["notification_to"] != "email";
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css?ver=<?php 
        echo GFCommon::$version;
        ?>
" />
        <script type="text/javascript" src="<?php 
        echo GFCommon::get_base_url();
        ?>
/js/forms.js?ver=<?php 
        echo GFCommon::$version;
        ?>
"></script>
        <script src="<?php 
        echo GFCommon::get_base_url();
        ?>
/js/jquery.json-1.3.js?ver=<?php 
        echo GFCommon::$version;
        ?>
"></script>

        <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.";
                }
            }
        });

        <?php 
        if (empty($form["notification"])) {
            $form["notification"] = array();
        }
        ?>

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

        function InsertVariable(element_id){
            var variable = jQuery('#' + element_id + '_variable_select').val();
            var messageElement = jQuery("#" + element_id);

            if(document.selection) {
                // Go the IE way
                messageElement[0].focus();
                document.selection.createRange().text=variable;
            }
            else if(messageElement[0].selectionStart) {
                // Go the Gecko way
                obj = messageElement[0]
                obj.value = obj.value.substr(0, obj.selectionStart) + variable + obj.value.substr(obj.selectionEnd, obj.value.length);
            }
            else {
                messageElement.val(variable + messageElement.val());
            }
            jQuery('#' + element_id + '_variable_select')[0].selectedIndex = 0;
        }


        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 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 + ");'><option value='is' " + isSelected + "><?php 
        _e("is", "gravityforms");
        ?>
</option><option value='isnot' " + isNotSelected + "><?php 
        _e("is not", "gravityforms");
        ?>
</option></select>";
                str += GetRoutingValues(i, routings[i].fieldId, routings[i].value);
                str += "<img src='<?php 
        echo GFCommon::get_base_url();
        ?>
/images/add.png' class='add_field_choice' title='add another rule' alt='add another rule' style='cursor:pointer; margin:0 3px;' onclick=\"InsertRouting(" + (i+1) + ");\" />";
                if(routings.length > 1 )
                    str += "<img src='<?php 
        echo GFCommon::get_base_url();
        ?>
/images/remove.png' title='remove this rule' alt='remove this rule' class='delete_field_choice' style='cursor:pointer;' onclick=\"DeleteRouting(" + i + ");\" /></li>";

                str += "</div>";
            }

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

        function GetRoutingValues(index, fieldId, selectedValue){
            var str = "<select class='gfield_routing_select' id='routing_value_" + index + "' onchange='SetRouting(" + index + ");'>";
            str += GetFieldValues(fieldId, selectedValue, 16);
            str += "</select>";

            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;
                if(inputType == "checkbox" || inputType == "radio" || inputType == "select"){
                    var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : "";
                    str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(form.fields[i].label, labelMaxCharacters) + "</option>";
                }
            }
            return str;
        }

        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(inputType == "checkbox" || inputType == "radio" || inputType == "select")
                    return form.fields[i].id;
            }

            return 0;
        }

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

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

            if(!fieldId)
                return "";

            var str = "";
            var field = GetFieldById(fieldId);
            var isAnySelected = false;
            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("'", "&#039;") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>";
            }

            if(!isAnySelected && selectedValue){
                str += "<option value='" + selectedValue.replace("'", "&#039;") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>";
            }

            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 = form.notification.routing;
            routings.splice(index, 0, new ConditionalRule());
            CreateRouting(routings);
            SetRouting(index);
        }

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

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

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

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


        </script>
        <?php 
        echo GFCommon::get_remote_message();
        ?>

        <form method="post" id="entry_form" onsubmit="gform_has_unsaved_changes = false; jQuery('#gform_routing_meta').val(jQuery.toJSON(form.notification.routing));">
            <?php 
        wp_nonce_field('gforms_save_notification', 'gforms_save_notification');
        ?>
            <input type="hidden" id="gform_routing_meta" name="gform_routing_meta" />
            <div class="wrap">
                <img alt="<?php 
        _e("Gravity Forms", "gravityforms");
        ?>
" src="<?php 
        echo GFCommon::get_base_url();
        ?>
/images/gravity-notification-icon-32.png" style="float:left; margin:15px 7px 0 0;"/>
                <h2><?php 
        _e("Notifications", "gravityforms");
        ?>
 : <?php 
        echo esc_html($form["title"]);
        ?>
</h2>

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

                <div id="poststuff" class="metabox-holder">
                    <div id="submitdiv" class="stuffbox">
                        <h3><span class="hndle"><?php 
        _e("Notification to Administrator", "gravityforms");
        ?>
</span></h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">

                                <div id="minor-publishingx" style="padding:10px;">
                                    <input type="checkbox" name="form_notification_enable_admin" id="form_notification_enable_admin" value="1" <?php 
        echo $is_admin_notification_enabled ? "checked='checked'" : "";
        ?>
 onclick="if(this.checked) {jQuery('#form_notification_admin_container').show('slow');} else {jQuery('#form_notification_to').val(''); jQuery('#form_notification_admin_container').hide('slow');}"/> <label for="form_notification_enable_admin"><?php 
        _e("Enable email notification to administrators", "gravityforms");
        ?>
</label>
                                    <div id="form_notification_admin_container" style="display:<?php 
        echo $is_admin_notification_enabled ? "block" : "none";
        ?>
;">
                                        <br/>
                                        <?php 
        _e("Enter a message below to receive a notification email when users submit this form.", "gravityforms");
        ?>
<br/><br/><br/>

                                        <ul id="form_notification_container">
                                            <?php 
        $is_invalid_email_to = $invalid_tab == 1 && !self::is_valid_admin_to();
        $class = $is_invalid_email_to ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <label for="notification_to_email">
                                                    <?php 
        _e("Send To Email", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    <?php 
        gform_tooltip("notification_send_to_email");
        ?>
                                                </label>

                                                <input type="radio" id="notification_to_email" name="notification_to" <?php 
        echo !$is_routing_enabled ? "checked='checked'" : "";
        ?>
 value="email" onclick="jQuery('#notification_to_routing_container').hide(); jQuery('#notification_to_email_container').show('slow');"/>
                                                <label for="notification_to_email" class="inline">
                                                    <?php 
        _e("Email", "gravityforms");
        ?>
                                                </label>
                                                &nbsp;&nbsp;
                                                <input type="radio" id="notification_to_routing" name="notification_to" <?php 
        echo $is_routing_enabled ? "checked='checked'" : "";
        ?>
 value="routing" onclick="jQuery('#notification_to_email_container').hide(); jQuery('#notification_to_routing_container').show('slow');"/>
                                                <label for="form_button_image" class="inline">
                                                    <?php 
        _e("Routing", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_send_to_routing");
        ?>
                                                </label>

                                                <div id="notification_to_email_container" style="margin-top:5px; display:<?php 
        echo $is_routing_enabled ? "none" : "block";
        ?>
;">
                                                    <input type="text" name="form_notification_to" id="form_notification_to" value="<?php 
        echo esc_attr($form["notification"]["to"]);
        ?>
" class="fieldwidth-1" />

                                                    <?php 
        if ($_POST["notification_to"] == "email" && $is_invalid_email_to) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a valid email address");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>

                                                <div id="notification_to_routing_container" style="margin-top:5px;  display:<?php 
        echo $is_routing_enabled ? "block" : "none";
        ?>
;">
                                                    <div>
                                                        <?php 
        $routing_fields = self::get_routing_fields($form, "0");
        if (empty($routing_fields)) {
            //if(empty(){
            ?>
                                                            <div class="gold_notice">
                                                                <p><?php 
            _e("To use notification routing, your form must have a drop down, checkbox or multiple choice field.", "gravityforms");
            ?>
</p>
                                                            </div>
                                                            <?php 
        } else {
            if (empty($form["notification"]["routing"])) {
                $form["notification"]["routing"] = array(array());
            }
            $count = sizeof($form["notification"]["routing"]);
            $routing_list = ",";
            for ($i = 0; $i < $count; $i++) {
                $routing_list .= $i . ",";
                $routing = $form["notification"]["routing"][$i];
                $is_invalid_rule = $invalid_tab == 1 && $_POST["notification_to"] == "routing" && !self::is_valid_notification_email($routing["email"]);
                $class = $is_invalid_rule ? "class='grouting_rule_error'" : "";
                ?>
                                                                <div style='width:99%' <?php 
                echo $class;
                ?>
>
                                                                    <?php 
                _e("Send to", "gravityforms");
                ?>
 <input type="text" id="routing_email_<?php 
                echo $i;
                ?>
" value="<?php 
                echo $routing["email"];
                ?>
" onkeyup="SetRouting(<?php 
                echo $i;
                ?>
);"/>
                                                                    <?php 
                _e("if", "gravityforms");
                ?>
 <select id="routing_field_id_<?php 
                echo $i;
                ?>
" class='gfield_routing_select' onchange='jQuery("#routing_value_<?php 
                echo $i;
                ?>
").replaceWith(GetRoutingValues(<?php 
                echo $i;
                ?>
, jQuery(this).val())); SetRouting(<?php 
                echo $i;
                ?>
); '><?php 
                echo self::get_routing_fields($form, $routing["fieldId"]);
                ?>
</select>
                                                                    <select id="routing_operator_<?php 
                echo $i;
                ?>
" onchange="SetRouting(<?php 
                echo $i;
                ?>
);"/>
                                                                        <option value="is" <?php 
                echo $routing["operator"] == "is" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is", "gravityforms");
                ?>
</option>
                                                                        <option value="isnot" <?php 
                echo $routing["operator"] == "isnot" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is not", "gravityforms");
                ?>
</option>
                                                                    </select>
                                                                    <select id="routing_value_<?php 
                echo $i;
                ?>
" class='gfield_routing_select' onchange="SetRouting(<?php 
                echo $i;
                ?>
);">
                                                                        <?php 
                echo self::get_field_values($form, $routing["fieldId"], $routing["value"]);
                ?>
                                                                    </select>
                                                                    <img src='<?php 
                echo GFCommon::get_base_url();
                ?>
/images/add.png' class='add_field_choice' title='add another email routing' alt='add another email routing' style='cursor:pointer; margin:0 3px;' onclick='SetRouting(<?php 
                echo $i;
                ?>
); InsertRouting(<?php 
                echo $i + 1;
                ?>
);' />
                                                                    <?php 
                if ($count > 1) {
                    ?>
                                                                        <img src='<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/remove.png' id='routing_delete_<?php 
                    echo $i;
                    ?>
' title='remove this email routing' alt='remove this email routing' class='delete_field_choice' style='cursor:pointer;' onclick='DeleteRouting(<?php 
                    echo $i;
                    ?>
);' />
                                                                    <?php 
                }
                ?>
                                                                </div>
                                                            <?php 
            }
            if ($is_invalid_rule) {
                ?>
                                                                <span class="validation_message"><?php 
                _e("Please enter a valid email address for all highlighted routing rules above.");
                ?>
</span>
                                                            <?php 
            }
            ?>
                                                            <input type="hidden" name="routing_count" id="routing_count" value="<?php 
            echo $routing_list;
            ?>
"/>
                                                        <?php 
        }
        ?>
                                                    </div>

                                                </div>
                                            </li>
                                            <li>
                                                <label for="form_notification_from">
                                                    <?php 
        _e("From Name", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_from_name");
        ?>
                                                </label>
                                                <input type="text" class="fieldwidth-2" name="form_notification_from_name" id="form_notification_from_name" onkeydown="jQuery('#form_notification_from_name_field').val('');" onchange="jQuery('#form_notification_from_name_field').val('');" value="<?php 
        echo esc_attr($form["notification"]["fromName"]);
        ?>
"/>
                                                <?php 
        if (!empty($name_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_from_name_field" id="form_notification_from_name_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_from_name').val('');">
                                                        <option value=""><?php 
            _e("Select a name field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($name_fields as $field) {
                $selected = $form["notification"]["fromNameField"] == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>
                                            <li>
                                                <label for="form_notification_from">
                                                    <?php 
        _e("From Email", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_from_email");
        ?>
                                                </label>
                                                <input type="text" class="fieldwidth-2" name="form_notification_from" id="form_notification_from" onkeydown="jQuery('#form_notification_from_field').val('');" onchange="jQuery('#form_notification_from_field').val('');" value="<?php 
        echo empty($form["notification"]["from"]) && empty($form["notification"]["fromField"]) ? esc_attr($wp_email) : esc_attr($form["notification"]["from"]);
        ?>
"/>
                                                <?php 
        if (!empty($email_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_from_field" id="form_notification_from_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_from').val('');">
                                                        <option value=""><?php 
            _e("Select an email field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = $form["notification"]["fromField"] == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>

                                            <li>
                                                <label for="form_notification_reply_to">
                                                    <?php 
        _e("Reply To", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_reply_to");
        ?>
                                                </label>
                                                <input type="text" name="form_notification_reply_to" id="form_notification_reply_to" onkeydown="jQuery('#form_notification_reply_to_field').val('');" onchange="jQuery('#form_notification_reply_to_field').val('');" value="<?php 
        echo esc_attr($form["notification"]["replyTo"]);
        ?>
" class="fieldwidth-2" />
                                                <?php 
        if (!empty($email_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_reply_to_field" id="form_notification_reply_to_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_reply_to').val('');">
                                                        <option value=""><?php 
            _e("Select an email field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = $form["notification"]["replyToField"] == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>
                                            <li>
                                                <label for="form_notification_bcc">
                                                    <?php 
        _e("BCC", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_bcc");
        ?>
                                                </label>
                                                <input type="text" name="form_notification_bcc" id="form_notification_bcc" value="<?php 
        echo esc_attr($form["notification"]["bcc"]);
        ?>
" class="fieldwidth-1" />
                                            </li>
                                            <?php 
        $is_invalid_subject = $invalid_tab == 1 && empty($_POST["form_notification_subject"]);
        $class = $is_invalid_subject ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <div>
                                                    <label for="form_notification_subject">
                                                        <?php 
        _e("Subject", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <div>
                                                        <?php 
        GFCommon::insert_variables($form["fields"], "form_notification_subject", true);
        ?>
                                                    </div>
                                                    <input type="text" name="form_notification_subject" id="form_notification_subject" value="<?php 
        echo esc_attr($form["notification"]["subject"]);
        ?>
" class="fieldwidth-1" />

                                                    <?php 
        if ($is_invalid_subject) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a subject for the notification email");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>
                                            </li>
                                            <?php 
        $is_invalid_message = $invalid_tab == 1 && empty($_POST["form_notification_message"]);
        $class = $is_invalid_message ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <div>
                                                    <label for="form_notification_message">
                                                        <?php 
        _e("Message", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <div>
                                                        <?php 
        GFCommon::insert_variables($form["fields"], "form_notification_message");
        ?>
                                                    </div>
                                                    <textarea name="form_notification_message" id="form_notification_message" class="fieldwidth-1 fieldheight-1" ><?php 
        echo esc_html($form["notification"]["message"]);
        ?>
</textarea>

                                                    <?php 
        if ($is_invalid_message) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a message for the notification email");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>
                                            </li>
                                            <li>
                                                <div>
                                                    <input type="checkbox" name="form_notification_disable_autoformat" id="form_notification_disable_autoformat" value="1" <?php 
        echo empty($form["notification"]["disableAutoformat"]) ? "" : "checked='checked'";
        ?>
/>
                                                    <label for="form_notification_disable_autoformat" class="inline">
                                                        <?php 
        _e("Disable Auto-formatting", "gravityforms");
        ?>
                                                        <?php 
        gform_tooltip("notification_autoformat");
        ?>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div id="submitdiv" class="stuffbox">
                        <h3><span class="hndle"><?php 
        _e("Notification to User", "gravityforms");
        ?>
</span></h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">
                                <div id="minor-publishingx" style="padding:10px;">
                                    <?php 
        if (empty($email_fields)) {
            ?>
                                        <div class="gold_notice">
                                        <p><?php 
            echo sprintf(__("Your form does not have any %semail%s field.", "gravityforms"), "<strong>", "</strong>");
            ?>
</p>
                                        <p>
                                        <?php 
            echo sprintf(__("Sending notifications to users require that the form has at least one email field. %sEdit your form%s", "gravityforms"), '<a href="?page=gf_edit_forms&id=' . absint($form_id) . '">', '</a>');
            ?>
                                        </p>
                                        </div>
                                        <?php 
        } else {
            ?>

                                        <input type="checkbox" name="form_notification_enable_user" id="form_notification_enable_user" value="1" <?php 
            echo $is_user_notification_enabled ? "checked='checked'" : "";
            ?>
 onclick="if(this.checked) {jQuery('#form_notification_user_container').show('slow');} else {jQuery('#form_notification_user_container').hide('slow');}"/> <label for="form_notification_enable_user"><?php 
            _e("Enable email notification to users", "gravityforms");
            ?>
</label>

                                        <div id="form_notification_user_container" style="display:<?php 
            echo $is_user_notification_enabled ? "block" : "none";
            ?>
;">
                                            <br/>
                                            <?php 
            _e("Enter a message below to send users an automatic response when they submit this form.", "gravityforms");
            ?>
<br/><br/><br/>
                                            <ul id="form_autoresponder_container">
                                                <li>
                                                    <label for="form_autoresponder_to">
                                                        <?php 
            _e("Send To Field", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                        <?php 
            gform_tooltip("autoresponder_send_to_email");
            ?>
                                                    </label>
                                                    <select name="form_autoresponder_to" id="form_autoresponder_to">
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = $form["autoResponder"]["toField"] == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo esc_html(GFCommon::get_label($field));
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_from_name">
                                                        <?php 
            _e("From Name", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_from_name");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_from_name" id="form_autoresponder_from_name" value="<?php 
            echo esc_attr($form["autoResponder"]["fromName"]);
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_from">
                                                        <?php 
            _e("From Email", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_from");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_from" id="form_autoresponder_from" value="<?php 
            echo empty($form["autoResponder"]["from"]) ? esc_attr($wp_email) : esc_attr($form["autoResponder"]["from"]);
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_reply_to" style="display:block;">
                                                        <?php 
            _e("Reply To (optional)", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_reply_to");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_reply_to" id="form_autoresponder_reply_to" value="<?php 
            echo esc_attr($form["autoResponder"]["replyTo"]);
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_bcc">
                                                        <?php 
            _e("BCC", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_bcc");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_bcc" id="form_autoresponder_bcc" value="<?php 
            echo esc_attr($form["autoResponder"]["bcc"]);
            ?>
" class="fieldwidth-1" />
                                                </li>

                                                <?php 
            $is_invalid_subject = $invalid_tab == 2 && empty($_POST["form_autoresponder_subject"]);
            $class = $is_invalid_subject ? "class='gfield_error'" : "";
            ?>
                                                <li <?php 
            echo $class;
            ?>
>

                                                    <label for="form_autoresponder_subject">
                                                        <?php 
            _e("Subject", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <div>
                                                        <?php 
            GFCommon::insert_variables($form["fields"], "form_autoresponder_subject", true);
            ?>
                                                    </div>
                                                    <input type="text" name="form_autoresponder_subject" id="form_autoresponder_subject" value="<?php 
            echo esc_attr($form["autoResponder"]["subject"]);
            ?>
" class="fieldwidth-1" />

                                                    <?php 
            if ($is_invalid_subject) {
                ?>
                                                        <span class="validation_message"><?php 
                _e("Please enter a subject for the user notification email");
                ?>
</span>
                                                    <?php 
            }
            ?>

                                                 </li>
                                                 <?php 
            $is_invalid_message = $invalid_tab == 2 && empty($_POST["form_autoresponder_message"]);
            $class = $is_invalid_message ? "class='gfield_error'" : "";
            ?>
                                                <li <?php 
            echo $class;
            ?>
>
                                                    <div>
                                                        <label for="form_autoresponder_message">
                                                            <?php 
            _e("Message", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                        </label>
                                                        <div>
                                                            <?php 
            GFCommon::insert_variables($form["fields"], "form_autoresponder_message");
            ?>
                                                        </div>
                                                        <textarea name="form_autoresponder_message" id="form_autoresponder_message" class="fieldwidth-1 fieldheight-1"><?php 
            echo esc_html($form["autoResponder"]["message"]);
            ?>
</textarea>

                                                        <?php 
            if ($is_invalid_message) {
                ?>
                                                            <span class="validation_message"><?php 
                _e("Please enter a message for the user notification email");
                ?>
</span>
                                                        <?php 
            }
            ?>
                                                    </div>
                                                </li>
                                                <li>
                                                    <div>
                                                        <input type="checkbox" name="form_autoresponder_disable_autoformat" id="form_autoresponder_disable_autoformat" value="1" <?php 
            echo empty($form["autoResponder"]["disableAutoformat"]) ? "" : "checked='checked'";
            ?>
/>
                                                        <label for="form_notification_disable_autoformat" class="inline">
                                                            <?php 
            _e("Disable Auto-formatting", "gravityforms");
            ?>
                                                            <?php 
            gform_tooltip("notification_autoformat");
            ?>
                                                        </label>
                                                    </div>
                                                </li>
                                            </ul>
                                        </div>
                                        <?php 
        }
        ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <br class="clear" />
                    <div>
                        <?php 
        $notification_button = '<input class="button-primary" type="submit" value="' . __("Save Settings", "gravityforms") . '" name="save"/>';
        echo apply_filters("gform_save_notification_button", $notification_button);
        ?>
                    </div>
                </div>
            </div>
        </form>
        <?php 
        if ($_POST["save"]) {
            if ($invalid_tab == 0) {
                ?>
                <div class="updated fade" style="padding:6px;">
                    <?php 
                _e("Notification Updated.", "gravityforms");
                ?>
                </div>
                <?php 
            } else {
                ?>
                <div class="error" style="padding:6px;">
                    <?php 
                _e("Notification could not be updated. Please enter all required information below.", "gravityforms");
                ?>
                </div>
                <?php 
            }
        }
    }
Ejemplo n.º 9
0
 public static function import_file($filepath, &$forms = null)
 {
     $xmlstr = file_get_contents($filepath);
     require_once "xml.php";
     $options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "creditCard" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true), "confirmation" => array("unserialize_as_array" => true), "notification" => array("unserialize_as_array" => true));
     $options = apply_filters('gform_import_form_xml_options', $options);
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms["version"], self::$min_import_version, "<")) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => &$form) {
         $title = $form["title"];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form["title"] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form["title"] = $title;
         $form["id"] = $form_id;
         $form = GFFormsModel::trim_form_meta_values($form);
         if (isset($form['confirmations'])) {
             $form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
             $form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
             GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
             unset($form['confirmations']);
         }
         if (isset($form['notifications'])) {
             $form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
             $form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
             GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
             unset($form['notifications']);
         }
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Ejemplo n.º 10
0
    public static function notification_page($form_id)
    {
        add_action('media_buttons', array('GFNotification', 'media_buttons'), 40);
        $form = RGFormsModel::get_form_meta($form_id);
        $invalid_tab = "";
        if (rgpost("save")) {
            check_admin_referer('gforms_save_notification', 'gforms_save_notification');
            $form["notification"]["to"] = rgpost("form_notification_to");
            $form["notification"]["bcc"] = rgpost("form_notification_bcc");
            $form["notification"]["subject"] = rgpost("form_notification_subject");
            $form["notification"]["message"] = rgpost("form_notification_message");
            $form["notification"]["from"] = rgempty("form_notification_from_field") ? rgpost("form_notification_from") : "";
            $form["notification"]["fromField"] = rgpost("form_notification_from_field");
            $form["notification"]["fromName"] = rgempty("form_notification_from_name_field") ? rgpost("form_notification_from_name") : "";
            $form["notification"]["fromNameField"] = rgpost("form_notification_from_name_field");
            $form["notification"]["replyTo"] = rgempty("form_notification_reply_to_field") ? rgpost("form_notification_reply_to") : "";
            $form["notification"]["replyToField"] = rgpost("form_notification_reply_to_field");
            $form["notification"]["routing"] = !rgempty("gform_routing_meta") ? GFCommon::json_decode(rgpost("gform_routing_meta"), true) : null;
            $form["notification"]["disableAutoformat"] = rgpost("form_notification_disable_autoformat");
            $form["autoResponder"]["toField"] = rgpost("form_autoresponder_to");
            $form["autoResponder"]["bcc"] = rgpost("form_autoresponder_bcc");
            $form["autoResponder"]["fromName"] = rgpost("form_autoresponder_from_name");
            $form["autoResponder"]["from"] = rgpost("form_autoresponder_from");
            $form["autoResponder"]["replyTo"] = rgpost("form_autoresponder_reply_to");
            $form["autoResponder"]["subject"] = rgpost("form_autoresponder_subject");
            $form["autoResponder"]["message"] = rgpost("form_autoresponder_message");
            $form["autoResponder"]["disableAutoformat"] = rgpost("form_autoresponder_disable_autoformat");
            //validating input...
            $invalid_tab = self::validate_notification();
            if ($invalid_tab == 0) {
                //input valid, updating...
                //emptying notification email if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_admin"]) || $_POST["notification_to"] == "routing") {
                    $form["notification"]["to"] = "";
                }
                //emptying notification routing if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_admin"]) || $_POST["notification_to"] == "email") {
                    $form["notification"]["routing"] = null;
                }
                //emptying autoResponder settings if it is supposed to be disabled
                if (empty($_POST["form_notification_enable_user"])) {
                    $form["autoResponder"]["toField"] = "";
                }
                RGFormsModel::update_form_meta($form_id, $form);
            }
        }
        $wp_email = "{admin_email}";
        $email_fields = GFCommon::get_email_fields($form);
        $name_fields = GFCommon::get_fields_by_type($form, array("name"));
        $has_admin_notification_fields = GFCommon::has_admin_notification($form);
        $has_user_notification_fields = GFCommon::has_user_notification($form);
        $is_admin_notification_enabled = $has_admin_notification_fields && empty($_POST["save"]) || !empty($_POST["form_notification_enable_admin"]);
        $is_user_notification_enabled = $has_user_notification_fields && empty($_POST["save"]) || !empty($_POST["form_notification_enable_user"]);
        $is_routing_enabled = !empty($form["notification"]["routing"]) && rgpost("notification_to") != "email";
        ?>
        <link rel="stylesheet" href="<?php 
        echo GFCommon::get_base_url();
        ?>
/css/admin.css?ver=<?php 
        echo GFCommon::$version;
        ?>
" />
        <script type="text/javascript" src="<?php 
        echo GFCommon::get_base_url();
        ?>
/js/forms.js?ver=<?php 
        echo GFCommon::$version;
        ?>
"></script>
        <script src="<?php 
        echo GFCommon::get_base_url();
        ?>
/js/jquery.json-1.3.js?ver=<?php 
        echo GFCommon::$version;
        ?>
"></script>

        <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.";
                }
            }


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


        <?php 
        if (empty($form["notification"])) {
            $form["notification"] = array();
        }
        ?>

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

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

        function InsertVariable(element_id, callback, variable){
                if(!variable)
                    variable = jQuery('#' + element_id + '_variable_select').val();

                var messageElement = jQuery("#" + element_id);

                if(document.selection) {
                    // Go the IE way
                    messageElement[0].focus();
                    document.selection.createRange().text=variable;
                }
                else if(messageElement[0].selectionStart) {
                    // Go the Gecko way
                    obj = messageElement[0]
                    obj.value = obj.value.substr(0, obj.selectionStart) + variable + obj.value.substr(obj.selectionEnd, obj.value.length);
                }
                else {
                    messageElement.val(variable + messageElement.val());
                }

                jQuery('#' + element_id + '_variable_select')[0].selectedIndex = 0;


                if(callback && window[callback]){
                    window[callback].call(null, element_id, variable);
                }
        }

        function InsertEditorVariable(elementId){
            var select = jQuery("#" + elementId + "_variable_select");
            var variable = select.val();
            select[0].selectedIndex = 0;

            wpActiveEditor = elementId;
            window.send_to_editor(variable);
        }

        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 + ");'>";
                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 += "<img src='<?php 
        echo GFCommon::get_base_url();
        ?>
/images/add.png' class='add_field_choice' title='add another rule' alt='add another rule' style='cursor:pointer; margin:0 3px;' onclick=\"InsertRouting(" + (i+1) + ");\" />";
                if(routings.length > 1 )
                    str += "<img src='<?php 
        echo GFCommon::get_base_url();
        ?>
/images/remove.png' title='remove this rule' alt='remove this rule' class='delete_field_choice' style='cursor:pointer;' onclick=\"DeleteRouting(" + i + ");\" /></li>";

                str += "</div>";
            }

            jQuery("#notification_to_routing_container").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 = form.notification.routing;
            routings.splice(index, 0, new ConditionalRule());

            CreateRouting(routings);
            SetRouting(index);
        }

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

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

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

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

        </script>
        <?php 
        echo GFCommon::get_remote_message();
        ?>

        <form method="post" id="entry_form" onsubmit="gform_has_unsaved_changes = false; jQuery('#gform_routing_meta').val(jQuery.toJSON(form.notification.routing));">
            <?php 
        wp_nonce_field('gforms_save_notification', 'gforms_save_notification');
        ?>
            <input type="hidden" id="gform_routing_meta" name="gform_routing_meta" />
            <div class="wrap">

                <div class="icon32" id="gravity-notification-icon"><br></div>

                <h2><?php 
        _e("Notifications", "gravityforms");
        ?>
 : <?php 
        echo esc_html($form["title"]);
        ?>
</h2>

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

                <div id="poststuff" class="metabox-holder">
                    <div id="submitdiv" class="stuffbox">
                        <h3><span class="hndle"><?php 
        _e("Notification to Administrator", "gravityforms");
        ?>
</span></h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">

                                <div id="minor-publishingx" style="padding:10px;">
                                    <input type="checkbox" name="form_notification_enable_admin" id="form_notification_enable_admin" value="1" <?php 
        echo $is_admin_notification_enabled ? "checked='checked'" : "";
        ?>
 onclick="if(this.checked) {jQuery('#form_notification_admin_container').show('slow');} else {jQuery('#form_notification_to').val(''); jQuery('#form_notification_admin_container').hide('slow');}"/> <label for="form_notification_enable_admin"><?php 
        _e("Enable email notification to administrators", "gravityforms");
        ?>
</label>
                                    <div id="form_notification_admin_container" style="display:<?php 
        echo $is_admin_notification_enabled ? "block" : "none";
        ?>
;">
                                        <br/>
                                        <?php 
        _e("Enter a message below to receive a notification email when users submit this form.", "gravityforms");
        ?>
<br/><br/><br/>

                                        <ul id="form_notification_container">
                                            <?php 
        $is_invalid_email_to = $invalid_tab == 1 && !self::is_valid_admin_to();
        $class = $is_invalid_email_to ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <label for="notification_to_email">
                                                    <?php 
        _e("Send To Email", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    <?php 
        gform_tooltip("notification_send_to_email");
        ?>
                                                </label>

                                                <input type="radio" id="notification_to_email" name="notification_to" <?php 
        echo !$is_routing_enabled ? "checked='checked'" : "";
        ?>
 value="email" onclick="jQuery('#notification_to_routing_container').hide(); jQuery('#notification_to_email_container').show('slow');"/>
                                                <label for="notification_to_email" class="inline">
                                                    <?php 
        _e("Email", "gravityforms");
        ?>
                                                </label>
                                                &nbsp;&nbsp;
                                                <input type="radio" id="notification_to_routing" name="notification_to" <?php 
        echo $is_routing_enabled ? "checked='checked'" : "";
        ?>
 value="routing" onclick="jQuery('#notification_to_email_container').hide(); jQuery('#notification_to_routing_container').show('slow');"/>
                                                <label for="form_button_image" class="inline">
                                                    <?php 
        _e("Routing", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_send_to_routing");
        ?>
                                                </label>

                                                <div id="notification_to_email_container" style="margin-top:5px; display:<?php 
        echo $is_routing_enabled ? "none" : "block";
        ?>
;">
                                                    <input type="text" name="form_notification_to" id="form_notification_to" value="<?php 
        echo esc_attr($form["notification"]["to"]);
        ?>
" class="fieldwidth-1" />

                                                    <?php 
        if (rgpost("notification_to") == "email" && $is_invalid_email_to) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a valid email address");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>

                                                <div id="notification_to_routing_container" style="margin-top:5px;  display:<?php 
        echo $is_routing_enabled ? "block" : "none";
        ?>
;">
                                                    <div>
                                                        <?php 
        $routing_fields = self::get_routing_fields($form, "0");
        if (empty($routing_fields)) {
            //if(empty(){
            ?>
                                                            <div class="gold_notice">
                                                                <p><?php 
            _e("To use notification routing, your form must have a field supported by conditional logic.", "gravityforms");
            ?>
</p>
                                                            </div>
                                                            <?php 
        } else {
            if (empty($form["notification"]["routing"])) {
                $form["notification"]["routing"] = array(array());
            }
            $count = sizeof($form["notification"]["routing"]);
            $routing_list = ",";
            for ($i = 0; $i < $count; $i++) {
                $routing_list .= $i . ",";
                $routing = $form["notification"]["routing"][$i];
                $is_invalid_rule = $invalid_tab == 1 && $_POST["notification_to"] == "routing" && !self::is_valid_notification_email($routing["email"]);
                $class = $is_invalid_rule ? "class='grouting_rule_error'" : "";
                ?>
                                                                <div style='width:99%' <?php 
                echo $class;
                ?>
>
                                                                    <?php 
                _e("Send to", "gravityforms");
                ?>
 <input type="text" id="routing_email_<?php 
                echo $i;
                ?>
" value="<?php 
                echo rgar($routing, "email");
                ?>
" onkeyup="SetRouting(<?php 
                echo $i;
                ?>
);"/>
                                                                    <?php 
                _e("if", "gravityforms");
                ?>
 <select id="routing_field_id_<?php 
                echo $i;
                ?>
" class='gfield_routing_select' onchange='jQuery("#routing_value_<?php 
                echo $i;
                ?>
").replaceWith(GetRoutingValues(<?php 
                echo $i;
                ?>
, jQuery(this).val())); SetRouting(<?php 
                echo $i;
                ?>
); '><?php 
                echo self::get_routing_fields($form, rgar($routing, "fieldId"));
                ?>
</select>
                                                                    <select id="routing_operator_<?php 
                echo $i;
                ?>
" onchange="SetRouting(<?php 
                echo $i;
                ?>
)" >
                                                                        <option value="is" <?php 
                echo rgar($routing, "operator") == "is" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is", "gravityforms");
                ?>
</option>
                                                                        <option value="isnot" <?php 
                echo rgar($routing, "operator") == "isnot" ? "selected='selected'" : "";
                ?>
><?php 
                _e("is not", "gravityforms");
                ?>
</option>
                                                                        <option value=">" <?php 
                echo rgar($routing, "operator") == ">" ? "selected='selected'" : "";
                ?>
><?php 
                _e("greater than", "gravityforms");
                ?>
</option>
                                                                        <option value="<" <?php 
                echo rgar($routing, "operator") == "<" ? "selected='selected'" : "";
                ?>
><?php 
                _e("less than", "gravityforms");
                ?>
</option>
                                                                        <option value="contains" <?php 
                echo rgar($routing, "operator") == "contains" ? "selected='selected'" : "";
                ?>
><?php 
                _e("contains", "gravityforms");
                ?>
</option>
                                                                        <option value="starts_with" <?php 
                echo rgar($routing, "operator") == "starts_with" ? "selected='selected'" : "";
                ?>
><?php 
                _e("starts with", "gravityforms");
                ?>
</option>
                                                                        <option value="ends_with" <?php 
                echo rgar($routing, "operator") == "ends_with" ? "selected='selected'" : "";
                ?>
><?php 
                _e("ends with", "gravityforms");
                ?>
</option>
                                                                    </select>
                                                                    <?php 
                echo self::get_field_values($i, $form, rgar($routing, "fieldId"), rgar($routing, "value"));
                ?>
                                                                    <img src='<?php 
                echo GFCommon::get_base_url();
                ?>
/images/add.png' class='add_field_choice' title='add another email routing' alt='add another email routing' style='cursor:pointer; margin:0 3px;' onclick='SetRouting(<?php 
                echo $i;
                ?>
); InsertRouting(<?php 
                echo $i + 1;
                ?>
);' />
                                                                    <?php 
                if ($count > 1) {
                    ?>
                                                                        <img src='<?php 
                    echo GFCommon::get_base_url();
                    ?>
/images/remove.png' id='routing_delete_<?php 
                    echo $i;
                    ?>
' title='remove this email routing' alt='remove this email routing' class='delete_field_choice' style='cursor:pointer;' onclick='DeleteRouting(<?php 
                    echo $i;
                    ?>
);' />
                                                                    <?php 
                }
                ?>
                                                                </div>
                                                            <?php 
            }
            if ($is_invalid_rule) {
                ?>
                                                                <span class="validation_message"><?php 
                _e("Please enter a valid email address for all highlighted routing rules above.");
                ?>
</span>
                                                            <?php 
            }
            ?>
                                                            <input type="hidden" name="routing_count" id="routing_count" value="<?php 
            echo $routing_list;
            ?>
"/>
                                                        <?php 
        }
        ?>
                                                    </div>

                                                </div>
                                            </li>
                                            <li>
                                                <label for="form_notification_from">
                                                    <?php 
        _e("From Name", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_from_name");
        ?>
                                                </label>
                                                <input type="text" class="fieldwidth-2" name="form_notification_from_name" id="form_notification_from_name" onkeydown="jQuery('#form_notification_from_name_field').val('');" onchange="jQuery('#form_notification_from_name_field').val('');" value="<?php 
        echo esc_attr(rgget("fromName", $form["notification"]));
        ?>
"/>
                                                <?php 
        if (!empty($name_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_from_name_field" id="form_notification_from_name_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_from_name').val('');">
                                                        <option value=""><?php 
            _e("Select a name field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($name_fields as $field) {
                $selected = rgget("fromNameField", $form["notification"]) == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>
                                            <li>
                                                <label for="form_notification_from">
                                                    <?php 
        _e("From Email", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_from_email");
        ?>
                                                </label>
                                                <input type="text" class="fieldwidth-2" name="form_notification_from" id="form_notification_from" onkeydown="jQuery('#form_notification_from_field').val('');" onchange="jQuery('#form_notification_from_field').val('');" value="<?php 
        echo rgempty("from", $form["notification"]) && rgempty("fromField", $form["notification"]) ? esc_attr($wp_email) : esc_attr(rgget("from", $form["notification"]));
        ?>
"/>
                                                <?php 
        if (!empty($email_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_from_field" id="form_notification_from_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_from').val('');">
                                                        <option value=""><?php 
            _e("Select an email field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = rgget("fromField", $form["notification"]) == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>

                                            <li>
                                                <label for="form_notification_reply_to">
                                                    <?php 
        _e("Reply To", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_reply_to");
        ?>
                                                </label>
                                                <input type="text" name="form_notification_reply_to" id="form_notification_reply_to" onkeydown="jQuery('#form_notification_reply_to_field').val('');" onchange="jQuery('#form_notification_reply_to_field').val('');" value="<?php 
        echo esc_attr(rgget("replyTo", $form["notification"]));
        ?>
" class="fieldwidth-2" />
                                                <?php 
        if (!empty($email_fields)) {
            ?>
                                                    <?php 
            _e("OR", "gravityforms");
            ?>
                                                    <select name="form_notification_reply_to_field" id="form_notification_reply_to_field" onchange="if(jQuery(this).val().length > 0 ) jQuery('#form_notification_reply_to').val('');">
                                                        <option value=""><?php 
            _e("Select an email field", "gravityforms");
            ?>
</option>
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = rgar($form["notification"], "replyToField") == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo GFCommon::get_label($field);
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                <?php 
        }
        ?>
                                            </li>
                                            <li>
                                                <label for="form_notification_bcc">
                                                    <?php 
        _e("BCC", "gravityforms");
        ?>
                                                    <?php 
        gform_tooltip("notification_bcc");
        ?>
                                                </label>
                                                <input type="text" name="form_notification_bcc" id="form_notification_bcc" value="<?php 
        echo esc_attr(rgget("bcc", $form["notification"]));
        ?>
" class="fieldwidth-1" />
                                            </li>
                                            <?php 
        $is_invalid_subject = $invalid_tab == 1 && empty($_POST["form_notification_subject"]);
        $class = $is_invalid_subject ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <div>
                                                    <label for="form_notification_subject">
                                                        <?php 
        _e("Subject", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <div>
                                                        <?php 
        GFCommon::insert_variables($form["fields"], "form_notification_subject", true);
        ?>
                                                    </div>
                                                    <input type="text" name="form_notification_subject" id="form_notification_subject" value="<?php 
        echo esc_attr($form["notification"]["subject"]);
        ?>
" class="fieldwidth-1" />

                                                    <?php 
        if ($is_invalid_subject) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a subject for the notification email");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>
                                            </li>
                                            <?php 
        $is_invalid_message = $invalid_tab == 1 && empty($_POST["form_notification_message"]);
        $class = $is_invalid_message ? "class='gfield_error'" : "";
        ?>
                                            <li <?php 
        echo $class;
        ?>
>
                                                <div>
                                                    <label for="form_notification_message">
                                                        <?php 
        _e("Message", "gravityforms");
        ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <?php 
        if (GFCommon::is_wp_version("3.3")) {
            wp_editor($form["notification"]["message"], "form_notification_message", array("autop" => false));
        } else {
            ?>
                                                        <textarea name="form_notification_message" id="form_notification_message" class="fieldwidth-1 fieldheight-1" ><?php 
            echo esc_html($form["notification"]["message"]);
            ?>
</textarea>
                                                        <?php 
        }
        if ($is_invalid_message) {
            ?>
                                                        <span class="validation_message"><?php 
            _e("Please enter a message for the notification email");
            ?>
</span>
                                                    <?php 
        }
        ?>
                                                </div>
                                            </li>
                                            <li>
                                                <div>
                                                    <input type="checkbox" name="form_notification_disable_autoformat" id="form_notification_disable_autoformat" value="1" <?php 
        echo empty($form["notification"]["disableAutoformat"]) ? "" : "checked='checked'";
        ?>
/>
                                                    <label for="form_notification_disable_autoformat" class="inline">
                                                        <?php 
        _e("Disable Auto-formatting", "gravityforms");
        ?>
                                                        <?php 
        gform_tooltip("notification_autoformat");
        ?>
                                                    </label>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div id="submitdiv" class="stuffbox">
                        <h3><span class="hndle"><?php 
        _e("Notification to User", "gravityforms");
        ?>
</span></h3>
                        <div class="inside">
                            <div id="submitcomment" class="submitbox">
                                <div id="minor-publishingx" style="padding:10px;">
                                    <?php 
        if (!isset($form["autoResponder"])) {
            $form["autoResponder"] = array();
        }
        if (empty($email_fields)) {
            ?>
                                        <div class="gold_notice">
                                        <p><?php 
            echo sprintf(__("Your form does not have any %semail%s field.", "gravityforms"), "<strong>", "</strong>");
            ?>
</p>
                                        <p>
                                        <?php 
            echo sprintf(__("Sending notifications to users require that the form has at least one email field. %sEdit your form%s", "gravityforms"), '<a href="?page=gf_edit_forms&id=' . absint($form_id) . '">', '</a>');
            ?>
                                        </p>
                                        </div>
                                        <?php 
        } else {
            ?>

                                        <input type="checkbox" name="form_notification_enable_user" id="form_notification_enable_user" value="1" <?php 
            echo $is_user_notification_enabled ? "checked='checked'" : "";
            ?>
 onclick="if(this.checked) {jQuery('#form_notification_user_container').show('slow');} else {jQuery('#form_notification_user_container').hide('slow');}"/> <label for="form_notification_enable_user"><?php 
            _e("Enable email notification to users", "gravityforms");
            ?>
</label>

                                        <div id="form_notification_user_container" style="display:<?php 
            echo $is_user_notification_enabled ? "block" : "none";
            ?>
;">
                                            <br/>
                                            <?php 
            _e("Enter a message below to send users an automatic response when they submit this form.", "gravityforms");
            ?>
<br/><br/><br/>
                                            <ul id="form_autoresponder_container">
                                                <li>
                                                    <label for="form_autoresponder_to">
                                                        <?php 
            _e("Send To Field", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                        <?php 
            gform_tooltip("autoresponder_send_to_email");
            ?>
                                                    </label>
                                                    <select name="form_autoresponder_to" id="form_autoresponder_to">
                                                        <?php 
            foreach ($email_fields as $field) {
                $selected = rgget("toField", $form["autoResponder"]) == $field["id"] ? "selected='selected'" : "";
                ?>
                                                            <option value="<?php 
                echo $field["id"];
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo esc_html(GFCommon::get_label($field));
                ?>
</option>
                                                            <?php 
            }
            ?>
                                                    </select>
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_from_name">
                                                        <?php 
            _e("From Name", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_from_name");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_from_name" id="form_autoresponder_from_name" value="<?php 
            echo esc_attr(rgget("fromName", $form["autoResponder"]));
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_from">
                                                        <?php 
            _e("From Email", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_from");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_from" id="form_autoresponder_from" value="<?php 
            echo rgempty("from", $form["autoResponder"]) ? esc_attr($wp_email) : esc_attr(rgget("from", $form["autoResponder"]));
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_reply_to" style="display:block;">
                                                        <?php 
            _e("Reply To (optional)", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_reply_to");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_reply_to" id="form_autoresponder_reply_to" value="<?php 
            echo esc_attr(rgget("replyTo", $form["autoResponder"]));
            ?>
" class="fieldwidth-2" />
                                                </li>
                                                <li>
                                                    <label for="form_autoresponder_bcc">
                                                        <?php 
            _e("BCC", "gravityforms");
            ?>
                                                        <?php 
            gform_tooltip("autoresponder_bcc");
            ?>
                                                    </label>
                                                    <input type="text" name="form_autoresponder_bcc" id="form_autoresponder_bcc" value="<?php 
            echo esc_attr(rgget("bcc", $form["autoResponder"]));
            ?>
" class="fieldwidth-1" />
                                                </li>

                                                <?php 
            $is_invalid_subject = $invalid_tab == 2 && rgempty("form_autoresponder_subject");
            $class = $is_invalid_subject ? "class='gfield_error'" : "";
            ?>
                                                <li <?php 
            echo $class;
            ?>
>

                                                    <label for="form_autoresponder_subject">
                                                        <?php 
            _e("Subject", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                    </label>
                                                    <div>
                                                        <?php 
            GFCommon::insert_variables($form["fields"], "form_autoresponder_subject", true);
            ?>
                                                    </div>
                                                    <input type="text" name="form_autoresponder_subject" id="form_autoresponder_subject" value="<?php 
            echo esc_attr(rgget("subject", $form["autoResponder"]));
            ?>
" class="fieldwidth-1" />

                                                    <?php 
            if ($is_invalid_subject) {
                ?>
                                                        <span class="validation_message"><?php 
                _e("Please enter a subject for the user notification email");
                ?>
</span>
                                                    <?php 
            }
            ?>

                                                 </li>
                                                 <?php 
            $is_invalid_message = $invalid_tab == 2 && rgempty("form_autoresponder_message");
            $class = $is_invalid_message ? "class='gfield_error'" : "";
            ?>
                                                <li <?php 
            echo $class;
            ?>
>
                                                    <div>
                                                        <label for="form_autoresponder_message">
                                                            <?php 
            _e("Message", "gravityforms");
            ?>
<span class="gfield_required">*</span>
                                                        </label>
                                                        <?php 
            if (GFCommon::is_wp_version("3.3")) {
                wp_editor(rgget("message", $form["autoResponder"]), "form_autoresponder_message", array("autop" => false));
            } else {
                ?>
                                                            <textarea name="form_autoresponder_message" id="form_autoresponder_message" class="fieldwidth-1 fieldheight-1"><?php 
                echo esc_html(rgget("message", $form["autoResponder"]));
                ?>
</textarea>
                                                            <?php 
            }
            if ($is_invalid_message) {
                ?>
                                                            <span class="validation_message"><?php 
                _e("Please enter a message for the user notification email");
                ?>
</span>
                                                        <?php 
            }
            ?>
                                                    </div>
                                                </li>
                                                <li>
                                                    <div>
                                                        <input type="checkbox" name="form_autoresponder_disable_autoformat" id="form_autoresponder_disable_autoformat" value="1" <?php 
            echo rgempty("disableAutoformat", $form["autoResponder"]) ? "" : "checked='checked'";
            ?>
/>
                                                        <label for="form_notification_disable_autoformat" class="inline">
                                                            <?php 
            _e("Disable Auto-formatting", "gravityforms");
            ?>
                                                            <?php 
            gform_tooltip("notification_autoformat");
            ?>
                                                        </label>
                                                    </div>
                                                </li>
                                            </ul>
                                        </div>
                                        <?php 
        }
        ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <br class="clear" />
                    <div>
                        <?php 
        $notification_button = '<input class="button-primary" type="submit" value="' . __("Save Settings", "gravityforms") . '" name="save"/>';
        echo apply_filters("gform_save_notification_button", $notification_button);
        ?>
                    </div>
                </div>
            </div>
        </form>
        <?php 
        if (rgpost("save")) {
            if ($invalid_tab == 0) {
                ?>
                <div class="updated fade" style="padding:6px;">
                    <?php 
                _e("Notification Updated.", "gravityforms");
                ?>
                </div>
                <?php 
            } else {
                ?>
                <div class="error" style="padding:6px;">
                    <?php 
                _e("Notification could not be updated. Please enter all required information below.", "gravityforms");
                ?>
                </div>
                <?php 
            }
        }
    }
Ejemplo n.º 11
0
Archivo: main.php Proyecto: jekv/devia
 /**
  * Convert settings from v1.x of the plugin
  *
  * @return void
  * @author James Inman
  */
 public function convert_old_settings()
 {
     $options_to_delete = array('gravityforms_sms');
     $old_options = get_option('gravityforms_sms');
     foreach ($this->forms as $form) {
         $meta = RGFormsModel::get_form_meta($form->id);
         $meta['clockwork_active'] = $meta['mediaburst_active'];
         $meta['clockwork_to'] = $meta['mediaburst_to'];
         if (isset($old_options['message'])) {
             $meta['clockwork_message'] = $old_options['message'];
         }
         unset($meta['mediaburst_active']);
         unset($meta['mediaburst_to']);
         RGFormsModel::update_form_meta($form->id, $meta);
     }
     foreach ($options_to_delete as $option) {
         delete_option($option);
     }
 }
Ejemplo n.º 12
0
 /** Sends an e-mail out, good stuff */
 public function send_notifications($form_id)
 {
     $form = RGFormsModel::get_form_meta($form_id);
     if (!$form) {
         // TODO: Yet, groups will only be sent out in the next schedule
         // TODO: perhaps add a $now = 'group' flag for instant turnaround?
         $this->reschedule_existing();
         return;
     }
     $digest_group = isset($form['digests']['digest_group']) ? $form['digests']['digest_group'] : false;
     $digest_interval = isset($form['digests']['digest_interval']) ? $form['digests']['digest_interval'] : false;
     $digest_report_always = isset($form['digests']['digest_report_always']) ? $form['digests']['digest_report_always'] : false;
     $digest_export_all_fields = isset($form['digests']['digest_export_all_fields']) ? $form['digests']['digest_export_all_fields'] : true;
     $digest_export_field_list = isset($form['digests']['digest_export_field_list']) ? $form['digests']['digest_export_field_list'] : array();
     $forms = array($form['id'] => $form);
     if ($digest_group) {
         /* We may want to send out a group of forms in one e-mail if possible */
         foreach (RGFormsModel::get_forms(true) as $existing_form) {
             if ($existing_form->id == $form_id) {
                 continue;
             }
             // It is I!
             $existing_form = RGFormsModel::get_form_meta($existing_form->id);
             if (!isset($existing_form['digests']['enable_digest'])) {
                 continue;
             }
             // Meh, not interesting
             if (!isset($existing_form['digests']['digest_group'])) {
                 continue;
             }
             // Meh, not interesting
             if (!isset($existing_form['digests']['digest_interval'])) {
                 continue;
             }
             // Meh, not interesting
             if ($existing_form['digests']['digest_group'] == $digest_group) {
                 if ($existing_form['digests']['digest_interval'] == $digest_interval) {
                     $forms[$existing_form['id']] = $existing_form;
                     // Add them all
                 }
             }
         }
     }
     $emails = array();
     /* Gather all the leads and update the last_sent counters */
     foreach ($forms as $i => $form) {
         $last_sent = isset($form['digests']['digest_last_sent']) ? $form['digests']['digest_last_sent'] : 0;
         /* Retrieve form entries newer than the last sent ID */
         global $wpdb;
         $leads_table = RGFormsModel::get_lead_table_name();
         $leads = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$leads_table} WHERE form_id = %d AND id > %d AND status = 'active';", $form['id'], $last_sent));
         if (!sizeof($leads)) {
             if (!$digest_report_always) {
                 continue;
                 // Nothing to report on
             }
         } else {
             /* Update the reported id counter */
             $form['digests']['digest_last_sent'] = $leads[sizeof($leads) - 1]->id;
         }
         if (version_compare(GFCommon::$version, '1.7') >= 0) {
             /* Seems like 1.7 really messed up the meta structure */
             unset($form['notifications']);
             unset($form['confirmations']);
         }
         RGFormsModel::update_form_meta($form['id'], $form);
         $forms[$i]['leads'] = $leads;
         /* Also make a lookup table of all e-mail addresses to forms */
         foreach ($form['digests']['digest_emails'] as $email) {
             if (!isset($emails[$email])) {
                 $emails[$email] = array();
             }
             $emails[$email][] = $form['id'];
         }
     }
     /* Now, let's try and mail stuff */
     foreach ($emails as $email => $form_ids) {
         /* CSV e-mails */
         $report = 'Report generated at ' . date('Y-m-d H:i:s') . "\n";
         $csv_attachment = tempnam(sys_get_temp_dir(), '');
         $csv = fopen($csv_attachment, 'w');
         $from = null;
         $to = null;
         $names = array();
         foreach ($form_ids as $form_id) {
             $form = $forms[$form_id];
             $names[] = $form['title'];
             fputcsv($csv, array('Form: ' . $form['title'] . ' (#' . $form_id . ')'));
             $headers = array('Date Submitted');
             if ($digest_export_all_fields) {
                 foreach ($form['fields'] as $field) {
                     if ($field['label']) {
                         $headers[] = $field['label'];
                     }
                 }
             } else {
                 foreach ($form['fields'] as $field) {
                     if ($field['label'] && in_array($field['id'], $digest_export_field_list)) {
                         $headers[] = $field['label'];
                     }
                 }
             }
             fputcsv($csv, $headers);
             if (!$form['leads']) {
                 /* No new entries (but user has opted to receive digests always) */
                 fputcsv($csv, array(__('No new entries.', self::$textdomain)));
             } else {
                 foreach ($form['leads'] as $lead) {
                     $data = array();
                     $lead_data = RGFormsModel::get_lead($lead->id);
                     $data[] = $lead->date_created;
                     if (!$from) {
                         $from = $lead->date_created;
                     } else {
                         $to = $lead->date_created;
                     }
                     foreach ($form['fields'] as $field) {
                         if (!$field['label']) {
                             continue;
                         }
                         if (!$digest_export_all_fields && !in_array($field['id'], $digest_export_field_list)) {
                             continue;
                         }
                         $raw_data = RGFormsModel::get_lead_field_value($lead_data, $field);
                         if (!is_array($raw_data)) {
                             $data[] = $raw_data;
                         } else {
                             $data[] = implode(', ', array_filter($raw_data));
                         }
                     }
                     fputcsv($csv, $data);
                 }
             }
             fputcsv($csv, array('--'));
             /* new line */
         }
         if (!$to) {
             $to = $from;
         }
         $report .= 'Contains entries from ' . $from . " to {$to}\n";
         $report .= 'See CSV attachment';
         fclose($csv);
         $new_csv_attachment = $csv_attachment . '-' . date('YmdHis') . '.csv';
         rename($csv_attachment, $new_csv_attachment);
         wp_mail($email, apply_filters('gf_digest_email_subject', 'Form Digest Report (CSV): ' . implode(', ', $names), $names, array($from, $to), $new_csv_attachment), $report, null, array($new_csv_attachment));
         if (!defined('GF_DIGEST_DOING_TESTS')) {
             unlink($new_csv_attachment);
         }
     }
     if (version_compare(GFCommon::$version, '1.7') >= 0) {
         /* In 1.7 there seems to be an issue with saving */
         GFFormsModel::flush_current_forms();
     }
 }
Ejemplo n.º 13
0
 public static function save_form()
 {
     global $wpdb;
     check_ajax_referer('rg_save_form', 'rg_save_form');
     $id = $_POST["id"];
     $form_json = $_POST["form"];
     $form_json = stripslashes($form_json);
     $form_meta = GFCommon::json_decode($form_json, true);
     if (!$form_meta) {
         die("EndUpdateForm(0);");
     }
     $form_table_name = $wpdb->prefix . "rg_form";
     $meta_table_name = $wpdb->prefix . "rg_form_meta";
     //Making sure title is not duplicate
     $forms = RGFormsModel::get_forms();
     foreach ($forms as $form) {
         if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
             die('DuplicateTitleMessage();');
         }
     }
     if ($id > 0) {
         RGFormsModel::update_form_meta($id, $form_meta);
         //updating form title
         $wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
         die("EndUpdateForm({$id});");
     } else {
         //inserting form
         $id = RGFormsModel::insert_form($form_meta["title"]);
         //updating object's id property
         $form_meta["id"] = $id;
         //updating form meta
         RGFormsModel::update_form_meta($id, $form_meta);
         die("EndInsertForm({$id});");
     }
 }
Ejemplo n.º 14
0
 public static function generateForm()
 {
     if (class_exists('GFAPI')) {
         $thankyouPage = get_page_by_path('events/thank-you', OBJECT, 'page');
         $form = array('labelPlacement' => 'top_label', 'useCurrentUserAsAuthor' => '1', 'title' => self::$formTitle, 'descriptionPlacement' => 'below', 'button' => array('type' => 'text', 'text' => 'Submit'), 'fields' => array(array('id' => '1', 'isRequired' => '1', 'size' => 'medium', 'type' => 'name', 'nameFormat' => 'simple', 'label' => 'First Name'), array('id' => '2', 'isRequired' => '1', 'size' => 'medium', 'type' => 'name', 'nameFormat' => 'simple', 'label' => 'Last Name'), array('id' => '3', 'isRequired' => '1', 'size' => 'medium', 'type' => 'email', 'label' => 'Email'), array('id' => '4', 'isRequired' => '1', 'size' => 'medium', 'type' => 'phone', 'phoneFormat' => 'standard', 'label' => 'Phone'), array('id' => '5', 'isRequired' => '1', 'size' => 'medium', 'type' => 'select', 'label' => 'Number Attending', 'choices' => array(array('text' => '1', 'value' => '1'), array('text' => '2', 'value' => '2'), array('text' => '3', 'value' => '3'), array('text' => '4', 'value' => '4'), array('text' => '5', 'value' => '5'), array('text' => '6', 'value' => '6'), array('text' => '7', 'value' => '7'), array('text' => '8', 'value' => '8'))), array('id' => '6', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{embed_post:post_title}', 'label' => 'Event Name'), array('id' => '7', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{embed_post:ID}', 'label' => 'Event Post ID'), array('id' => '8', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventStartDate}', 'label' => 'Event Start Date'), array('id' => '9', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventEndDate}', 'label' => 'Event End Date'), array('id' => '10', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventRecurrence}', 'label' => 'Event Recurrence'), array('id' => '11', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventAllDay}', 'label' => 'All Day Event'), array('id' => '90', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '', 'label' => 'Event Formatted Date'), array('id' => '91', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '', 'label' => 'Event Formatted Time')), 'cssClass' => 'contact-form-gfec-form', 'enableHoneypot' => '1', 'confirmations' => array(array('id' => '5316355c6c8c1', 'isDefault' => '1', 'type' => 'page', 'name' => 'Default Confirmation', 'pageId' => $thankyouPage->ID, 'queryString' => 'eventID={post_id:7}')), 'notifications' => array(array('id' => '53163750d13d3', 'to' => '3', 'name' => 'RSVP', 'event' => 'form_submission', 'toType' => 'field', 'subject' => 'Thank You for Registering for (Event Name:5} - {Event Date:6}', 'message' => '{all_fields}', 'from' => '{admin_email}', 'fromName' => get_bloginfo('name'))));
         if (RGFormsModel::is_unique_title($form['title'])) {
             $form_id = RGFormsModel::insert_form($form['title']);
             $form["id"] = $form_id;
             GFFormsModel::trim_form_meta_values($form);
             if (isset($form['confirmations'])) {
                 $form['confirmations'] = GFExport::set_property_as_key($form['confirmations'], 'id');
                 $form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
                 GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
                 unset($form['confirmations']);
             }
             if (isset($form['notifications'])) {
                 $form['notifications'] = GFExport::set_property_as_key($form['notifications'], 'id');
                 $form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
                 GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
                 unset($form['notifications']);
             }
             RGFormsModel::update_form_meta($form_id, $form);
         }
     }
 }