@@ -14,27 +14,27 @@  | 
                                                    ||
| 14 | 14 | class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | 16 | |
| 17 | - /**  | 
                                                        |
| 18 | - * @param array $input_settings  | 
                                                        |
| 19 | - * @throws InvalidArgumentException  | 
                                                        |
| 20 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException  | 
                                                        |
| 21 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException  | 
                                                        |
| 22 | - */  | 
                                                        |
| 23 | - public function __construct($input_settings = array())  | 
                                                        |
| 24 | -    { | 
                                                        |
| 25 | - $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy());  | 
                                                        |
| 26 | - $this->_set_normalization_strategy(new EE_Text_Normalization());  | 
                                                        |
| 27 | - $this->_add_validation_strategy(  | 
                                                        |
| 28 | - LoaderFactory::getLoader()->getNew(  | 
                                                        |
| 29 | - 'EE_URL_Validation_Strategy',  | 
                                                        |
| 30 | - array(  | 
                                                        |
| 31 | - isset($input_settings['validation_error_message'])  | 
                                                        |
| 32 | - ? $input_settings['validation_error_message']  | 
                                                        |
| 33 | - : null,  | 
                                                        |
| 34 | - false  | 
                                                        |
| 35 | - )  | 
                                                        |
| 36 | - )  | 
                                                        |
| 37 | - );  | 
                                                        |
| 38 | - parent::__construct($input_settings);  | 
                                                        |
| 39 | - }  | 
                                                        |
| 17 | + /**  | 
                                                        |
| 18 | + * @param array $input_settings  | 
                                                        |
| 19 | + * @throws InvalidArgumentException  | 
                                                        |
| 20 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException  | 
                                                        |
| 21 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException  | 
                                                        |
| 22 | + */  | 
                                                        |
| 23 | + public function __construct($input_settings = array())  | 
                                                        |
| 24 | +	{ | 
                                                        |
| 25 | + $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy());  | 
                                                        |
| 26 | + $this->_set_normalization_strategy(new EE_Text_Normalization());  | 
                                                        |
| 27 | + $this->_add_validation_strategy(  | 
                                                        |
| 28 | + LoaderFactory::getLoader()->getNew(  | 
                                                        |
| 29 | + 'EE_URL_Validation_Strategy',  | 
                                                        |
| 30 | + array(  | 
                                                        |
| 31 | + isset($input_settings['validation_error_message'])  | 
                                                        |
| 32 | + ? $input_settings['validation_error_message']  | 
                                                        |
| 33 | + : null,  | 
                                                        |
| 34 | + false  | 
                                                        |
| 35 | + )  | 
                                                        |
| 36 | + )  | 
                                                        |
| 37 | + );  | 
                                                        |
| 38 | + parent::__construct($input_settings);  | 
                                                        |
| 39 | + }  | 
                                                        |
| 40 | 40 | }  | 
                                                        
@@ -44,7 +44,7 @@ discard block  | 
                                                    ||
| 44 | 44 |      { | 
                                                        
| 45 | 45 |          $this->singlular_item = __('Payment Method', 'event_espresso'); | 
                                                        
| 46 | 46 |          $this->plural_item = __('Payment Methods', 'event_espresso'); | 
                                                        
| 47 | -        $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); | 
                                                        |
| 47 | +        $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); | 
                                                        |
| 48 | 48 | $this->_fields = array(  | 
                                                        
| 49 | 49 | 'Payment_Method' => array(  | 
                                                        
| 50 | 50 |                  'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), | 
                                                        
@@ -78,7 +78,7 @@ discard block  | 
                                                    ||
| 78 | 78 | */  | 
                                                        
| 79 | 79 | public function get_one_by_slug($slug)  | 
                                                        
| 80 | 80 |      { | 
                                                        
| 81 | - return $this->get_one(array( array( 'PMD_slug' => $slug ) ));  | 
                                                        |
| 81 | +        return $this->get_one(array(array('PMD_slug' => $slug))); | 
                                                        |
| 82 | 82 | }  | 
                                                        
| 83 | 83 | |
| 84 | 84 | |
@@ -109,7 +109,7 @@ discard block  | 
                                                    ||
| 109 | 109 | public function is_valid_scope($scope)  | 
                                                        
| 110 | 110 |      { | 
                                                        
| 111 | 111 | $scopes = $this->scopes();  | 
                                                        
| 112 | -        if (isset($scopes[ $scope ])) { | 
                                                        |
| 112 | +        if (isset($scopes[$scope])) { | 
                                                        |
| 113 | 113 | return true;  | 
                                                        
| 114 | 114 |          } else { | 
                                                        
| 115 | 115 | return false;  | 
                                                        
@@ -127,8 +127,8 @@ discard block  | 
                                                    ||
| 127 | 127 | */  | 
                                                        
| 128 | 128 | public function get_all_active($scope = null, $query_params = array())  | 
                                                        
| 129 | 129 |      { | 
                                                        
| 130 | -        if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { | 
                                                        |
| 131 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );  | 
                                                        |
| 130 | +        if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { | 
                                                        |
| 131 | +            $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); | 
                                                        |
| 132 | 132 | }  | 
                                                        
| 133 | 133 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        
| 134 | 134 | }  | 
                                                        
@@ -156,7 +156,7 @@ discard block  | 
                                                    ||
| 156 | 156 |      { | 
                                                        
| 157 | 157 |          if ($scope) { | 
                                                        
| 158 | 158 |              if ($this->is_valid_scope($scope)) { | 
                                                        
| 159 | - return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);  | 
                                                        |
| 159 | +                return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); | 
                                                        |
| 160 | 160 |              } else { | 
                                                        
| 161 | 161 |                  throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); | 
                                                        
| 162 | 162 | }  | 
                                                        
@@ -165,9 +165,9 @@ discard block  | 
                                                    ||
| 165 | 165 | $count = 0;  | 
                                                        
| 166 | 166 |              foreach ($this->scopes() as $scope_name => $desc) { | 
                                                        
| 167 | 167 | $count++;  | 
                                                        
| 168 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );  | 
                                                        |
| 168 | +                $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); | 
                                                        |
| 169 | 169 | }  | 
                                                        
| 170 | - return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);  | 
                                                        |
| 170 | +            return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); | 
                                                        |
| 171 | 171 | }  | 
                                                        
| 172 | 172 | }  | 
                                                        
| 173 | 173 | |
@@ -205,7 +205,7 @@ discard block  | 
                                                    ||
| 205 | 205 | */  | 
                                                        
| 206 | 206 | public function get_one_of_type($type)  | 
                                                        
| 207 | 207 |      { | 
                                                        
| 208 | - return $this->get_one(array( array( 'PMD_type' => $type ) ));  | 
                                                        |
| 208 | +        return $this->get_one(array(array('PMD_type' => $type))); | 
                                                        |
| 209 | 209 | }  | 
                                                        
| 210 | 210 | |
| 211 | 211 | |
@@ -298,7 +298,7 @@ discard block  | 
                                                    ||
| 298 | 298 | $usable_payment_methods = array();  | 
                                                        
| 299 | 299 |          foreach ($payment_methods as $key => $payment_method) { | 
                                                        
| 300 | 300 |              if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { | 
                                                        
| 301 | - $usable_payment_methods[ $key ] = $payment_method;  | 
                                                        |
| 301 | + $usable_payment_methods[$key] = $payment_method;  | 
                                                        |
| 302 | 302 | // some payment methods enqueue their scripts in EE_PMT_*::__construct  | 
                                                        
| 303 | 303 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue  | 
                                                        
| 304 | 304 | // its scripts). but for backwards-compat we should continue to do that  | 
                                                        
@@ -312,7 +312,7 @@ discard block  | 
                                                    ||
| 312 | 312 | $payment_method  | 
                                                        
| 313 | 313 | );  | 
                                                        
| 314 | 314 | new PersistentAdminNotice(  | 
                                                        
| 315 | - 'auto-deactivated-' . $payment_method->type(),  | 
                                                        |
| 315 | + 'auto-deactivated-'.$payment_method->type(),  | 
                                                        |
| 316 | 316 | sprintf(  | 
                                                        
| 317 | 317 | __(  | 
                                                        
| 318 | 318 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',  | 
                                                        
@@ -320,7 +320,7 @@ discard block  | 
                                                    ||
| 320 | 320 | ),  | 
                                                        
| 321 | 321 | $payment_method->admin_name(),  | 
                                                        
| 322 | 322 | '<br />',  | 
                                                        
| 323 | -                        '<a href="' . admin_url('plugins.php') . '">', | 
                                                        |
| 323 | +                        '<a href="'.admin_url('plugins.php').'">', | 
                                                        |
| 324 | 324 | '</a>'  | 
                                                        
| 325 | 325 | ),  | 
                                                        
| 326 | 326 | true  | 
                                                        
@@ -345,7 +345,7 @@ discard block  | 
                                                    ||
| 345 | 345 | // give addons a chance to override what payment methods are chosen based on the transaction  | 
                                                        
| 346 | 346 | return apply_filters(  | 
                                                        
| 347 | 347 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        
| 348 | - $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),  | 
                                                        |
| 348 | +            $this->get_all_active($scope, array('group_by' => 'PMD_type')), | 
                                                        |
| 349 | 349 | $transaction,  | 
                                                        
| 350 | 350 | $scope  | 
                                                        
| 351 | 351 | );  | 
                                                        
@@ -369,7 +369,7 @@ discard block  | 
                                                    ||
| 369 | 369 | 0 => array(  | 
                                                        
| 370 | 370 | 'Payment.Registration.REG_ID' => $registration_id,  | 
                                                        
| 371 | 371 | ),  | 
                                                        
| 372 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' )  | 
                                                        |
| 372 | +            'order_by' => array('Payment.PAY_ID' => 'DESC') | 
                                                        |
| 373 | 373 | );  | 
                                                        
| 374 | 374 | return $this->get_one($query_params);  | 
                                                        
| 375 | 375 | }  | 
                                                        
@@ -20,363 +20,363 @@  | 
                                                    ||
| 20 | 20 | class EEM_Payment_Method extends EEM_Base  | 
                                                        
| 21 | 21 |  { | 
                                                        
| 22 | 22 | |
| 23 | - const scope_cart = 'CART';  | 
                                                        |
| 24 | -  | 
                                                        |
| 25 | - const scope_admin = 'ADMIN';  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | - const scope_api = 'API';  | 
                                                        |
| 28 | -  | 
                                                        |
| 29 | - /**  | 
                                                        |
| 30 | - *  | 
                                                        |
| 31 | - * @type EEM_Payment_Method  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - protected static $_instance = null;  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | -  | 
                                                        |
| 36 | -  | 
                                                        |
| 37 | - /**  | 
                                                        |
| 38 | - * private constructor to prevent direct creation  | 
                                                        |
| 39 | - * @Constructor  | 
                                                        |
| 40 | - * @access protected  | 
                                                        |
| 41 | - * @return EEM_Payment_Method  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - protected function __construct($timezone = null)  | 
                                                        |
| 44 | -    { | 
                                                        |
| 45 | -        $this->singlular_item = __('Payment Method', 'event_espresso'); | 
                                                        |
| 46 | -        $this->plural_item = __('Payment Methods', 'event_espresso'); | 
                                                        |
| 47 | -        $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); | 
                                                        |
| 48 | - $this->_fields = array(  | 
                                                        |
| 49 | - 'Payment_Method' => array(  | 
                                                        |
| 50 | -                'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), | 
                                                        |
| 51 | -                'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), | 
                                                        |
| 52 | -                'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), | 
                                                        |
| 53 | -                'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), | 
                                                        |
| 54 | -                'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), | 
                                                        |
| 55 | -                'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), | 
                                                        |
| 56 | -                'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), | 
                                                        |
| 57 | -                'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), | 
                                                        |
| 58 | -                'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), | 
                                                        |
| 59 | -                'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), | 
                                                        |
| 60 | -                'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), | 
                                                        |
| 61 | -                'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' | 
                                                        |
| 62 | - ) );  | 
                                                        |
| 63 | - $this->_model_relations = array(  | 
                                                        |
| 64 | - 'Payment' => new EE_Has_Many_Relation(),  | 
                                                        |
| 65 | -            'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), | 
                                                        |
| 66 | - 'Transaction' => new EE_Has_Many_Relation(),  | 
                                                        |
| 67 | - 'WP_User' => new EE_Belongs_To_Relation(),  | 
                                                        |
| 68 | - );  | 
                                                        |
| 69 | - parent::__construct($timezone);  | 
                                                        |
| 70 | - }  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /**  | 
                                                        |
| 75 | - * Gets one by the slug provided  | 
                                                        |
| 76 | - * @param string $slug  | 
                                                        |
| 77 | - * @return EE_Payment_Method  | 
                                                        |
| 78 | - */  | 
                                                        |
| 79 | - public function get_one_by_slug($slug)  | 
                                                        |
| 80 | -    { | 
                                                        |
| 81 | - return $this->get_one(array( array( 'PMD_slug' => $slug ) ));  | 
                                                        |
| 82 | - }  | 
                                                        |
| 83 | -  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | - /**  | 
                                                        |
| 87 | - * Gets all the acceptable scopes for payment methods.  | 
                                                        |
| 88 | - * Keys are their names as store din the DB, and values are nice names for displaying them  | 
                                                        |
| 89 | - * @return array  | 
                                                        |
| 90 | - */  | 
                                                        |
| 91 | - public function scopes()  | 
                                                        |
| 92 | -    { | 
                                                        |
| 93 | - return apply_filters(  | 
                                                        |
| 94 | - 'FHEE__EEM_Payment_Method__scopes',  | 
                                                        |
| 95 | - array(  | 
                                                        |
| 96 | -                self::scope_cart        => __("Front-end Registration Page", 'event_espresso'), | 
                                                        |
| 97 | -                self::scope_admin   => __("Admin Registration Page (no online processing)", 'event_espresso') | 
                                                        |
| 98 | - )  | 
                                                        |
| 99 | - );  | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - /**  | 
                                                        |
| 105 | - * Determines if this is an valid scope  | 
                                                        |
| 106 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes()  | 
                                                        |
| 107 | - * @return boolean  | 
                                                        |
| 108 | - */  | 
                                                        |
| 109 | - public function is_valid_scope($scope)  | 
                                                        |
| 110 | -    { | 
                                                        |
| 111 | - $scopes = $this->scopes();  | 
                                                        |
| 112 | -        if (isset($scopes[ $scope ])) { | 
                                                        |
| 113 | - return true;  | 
                                                        |
| 114 | -        } else { | 
                                                        |
| 115 | - return false;  | 
                                                        |
| 116 | - }  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | -  | 
                                                        |
| 120 | -  | 
                                                        |
| 121 | - /**  | 
                                                        |
| 122 | - * Gets all active payment methods  | 
                                                        |
| 123 | - * @param string $scope one of  | 
                                                        |
| 124 | - * @param array $query_params  | 
                                                        |
| 125 | - * @throws EE_Error  | 
                                                        |
| 126 | - * @return EE_Payment_Method[]  | 
                                                        |
| 127 | - */  | 
                                                        |
| 128 | - public function get_all_active($scope = null, $query_params = array())  | 
                                                        |
| 129 | -    { | 
                                                        |
| 130 | -        if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { | 
                                                        |
| 131 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );  | 
                                                        |
| 132 | - }  | 
                                                        |
| 133 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 134 | - }  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | - /**  | 
                                                        |
| 137 | - * Counts all active gateways in the specified scope  | 
                                                        |
| 138 | - * @param string $scope one of EEM_Payment_Method::scope_*  | 
                                                        |
| 139 | - * @param array $query_params  | 
                                                        |
| 140 | - * @return int  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | - public function count_active($scope = null, $query_params = array())  | 
                                                        |
| 143 | -    { | 
                                                        |
| 144 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 145 | - }  | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - /**  | 
                                                        |
| 148 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params  | 
                                                        |
| 149 | - * argument to get all active for a given scope  | 
                                                        |
| 150 | - * @param string $scope one of the constants EEM_Payment_Method::scope_*  | 
                                                        |
| 151 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 152 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 153 | - * @throws EE_Error  | 
                                                        |
| 154 | - */  | 
                                                        |
| 155 | - protected function _get_query_params_for_all_active($scope = null, $query_params = array())  | 
                                                        |
| 156 | -    { | 
                                                        |
| 157 | -        if ($scope) { | 
                                                        |
| 158 | -            if ($this->is_valid_scope($scope)) { | 
                                                        |
| 159 | - return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);  | 
                                                        |
| 160 | -            } else { | 
                                                        |
| 161 | -                throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); | 
                                                        |
| 162 | - }  | 
                                                        |
| 163 | -        } else { | 
                                                        |
| 164 | - $acceptable_scopes = array();  | 
                                                        |
| 165 | - $count = 0;  | 
                                                        |
| 166 | -            foreach ($this->scopes() as $scope_name => $desc) { | 
                                                        |
| 167 | - $count++;  | 
                                                        |
| 168 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );  | 
                                                        |
| 169 | - }  | 
                                                        |
| 170 | - return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);  | 
                                                        |
| 171 | - }  | 
                                                        |
| 172 | - }  | 
                                                        |
| 173 | -  | 
                                                        |
| 174 | - /**  | 
                                                        |
| 175 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params  | 
                                                        |
| 176 | - * argument to get all active for a given scope  | 
                                                        |
| 177 | - * @param string $scope one of the constants EEM_Payment_Method::scope_*  | 
                                                        |
| 178 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 179 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 180 | - * @throws EE_Error  | 
                                                        |
| 181 | - */  | 
                                                        |
| 182 | - public function get_query_params_for_all_active($scope = null, $query_params = array())  | 
                                                        |
| 183 | -    { | 
                                                        |
| 184 | - return $this->_get_query_params_for_all_active($scope, $query_params);  | 
                                                        |
| 185 | - }  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | -  | 
                                                        |
| 188 | - /**  | 
                                                        |
| 189 | - * Gets one active payment method. see @get_all_active for documentation  | 
                                                        |
| 190 | - * @param string $scope  | 
                                                        |
| 191 | - * @param array $query_params  | 
                                                        |
| 192 | - * @return EE_Payment_Method  | 
                                                        |
| 193 | - */  | 
                                                        |
| 194 | - public function get_one_active($scope = null, $query_params = array())  | 
                                                        |
| 195 | -    { | 
                                                        |
| 196 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 197 | - }  | 
                                                        |
| 198 | -  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | -  | 
                                                        |
| 201 | - /**  | 
                                                        |
| 202 | - * Gets one payment method of that type, regardless of whether its active or not  | 
                                                        |
| 203 | - * @param string $type  | 
                                                        |
| 204 | - * @return EE_Payment_Method  | 
                                                        |
| 205 | - */  | 
                                                        |
| 206 | - public function get_one_of_type($type)  | 
                                                        |
| 207 | -    { | 
                                                        |
| 208 | - return $this->get_one(array( array( 'PMD_type' => $type ) ));  | 
                                                        |
| 209 | - }  | 
                                                        |
| 210 | -  | 
                                                        |
| 211 | -  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - /**  | 
                                                        |
| 214 | - * Overrides parent ot also check by the slug  | 
                                                        |
| 215 | - * @see EEM_Base::ensure_is_obj()  | 
                                                        |
| 216 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id  | 
                                                        |
| 217 | - * @param boolean $ensure_is_in_db  | 
                                                        |
| 218 | - * @return EE_Payment_Method  | 
                                                        |
| 219 | - * @throws EE_Error  | 
                                                        |
| 220 | - */  | 
                                                        |
| 221 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)  | 
                                                        |
| 222 | -    { | 
                                                        |
| 223 | - // first: check if it's a slug  | 
                                                        |
| 224 | -        if (is_string($base_class_obj_or_id)) { | 
                                                        |
| 225 | - $obj = $this->get_one_by_slug($base_class_obj_or_id);  | 
                                                        |
| 226 | -            if ($obj) { | 
                                                        |
| 227 | - return $obj;  | 
                                                        |
| 228 | - }  | 
                                                        |
| 229 | - }  | 
                                                        |
| 230 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)  | 
                                                        |
| 231 | -        try { | 
                                                        |
| 232 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);  | 
                                                        |
| 233 | -        } catch (EE_Error $e) { | 
                                                        |
| 234 | - // handle it outside the catch  | 
                                                        |
| 235 | - }  | 
                                                        |
| 236 | -        throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); | 
                                                        |
| 237 | - }  | 
                                                        |
| 238 | -  | 
                                                        |
| 239 | -  | 
                                                        |
| 240 | -  | 
                                                        |
| 241 | - /**  | 
                                                        |
| 242 | - * Gets the ID of this object, or if its a string finds the object's id  | 
                                                        |
| 243 | - * associated with that slug  | 
                                                        |
| 244 | - * @param mixed $base_obj_or_id_or_slug  | 
                                                        |
| 245 | - * @return int  | 
                                                        |
| 246 | - */  | 
                                                        |
| 247 | - public function ensure_is_ID($base_obj_or_id_or_slug)  | 
                                                        |
| 248 | -    { | 
                                                        |
| 249 | -        if (is_string($base_obj_or_id_or_slug)) { | 
                                                        |
| 250 | - // assume it's a slug  | 
                                                        |
| 251 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);  | 
                                                        |
| 252 | - }  | 
                                                        |
| 253 | - return parent::ensure_is_ID($base_obj_or_id_or_slug);  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | -  | 
                                                        |
| 256 | -  | 
                                                        |
| 257 | -  | 
                                                        |
| 258 | - /**  | 
                                                        |
| 259 | - * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.  | 
                                                        |
| 260 | - * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart  | 
                                                        |
| 261 | - */  | 
                                                        |
| 262 | - public function verify_button_urls($payment_methods = null)  | 
                                                        |
| 263 | -    { | 
                                                        |
| 264 | - $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);  | 
                                                        |
| 265 | -        foreach ($payment_methods as $payment_method) { | 
                                                        |
| 266 | -            try { | 
                                                        |
| 267 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even  | 
                                                        |
| 268 | - // though this is a caffeinated install, reset it to the default.  | 
                                                        |
| 269 | - $current_button_url = $payment_method->button_url();  | 
                                                        |
| 270 | - if (empty($current_button_url)  | 
                                                        |
| 271 | - || (  | 
                                                        |
| 272 | - strpos($current_button_url, 'decaf') !== false  | 
                                                        |
| 273 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false  | 
                                                        |
| 274 | - )  | 
                                                        |
| 275 | -                ) { | 
                                                        |
| 276 | - $payment_method->save(  | 
                                                        |
| 277 | - [  | 
                                                        |
| 278 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url()  | 
                                                        |
| 279 | - ]  | 
                                                        |
| 280 | - );  | 
                                                        |
| 281 | - }  | 
                                                        |
| 282 | -            } catch (EE_Error $e) { | 
                                                        |
| 283 | - $payment_method->set_active(false);  | 
                                                        |
| 284 | - }  | 
                                                        |
| 285 | - }  | 
                                                        |
| 286 | - }  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | -  | 
                                                        |
| 289 | -  | 
                                                        |
| 290 | - /**  | 
                                                        |
| 291 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,  | 
                                                        |
| 292 | - * but also verifies the payment method type of each is a usable object. If not,  | 
                                                        |
| 293 | - * deactivate it, sets a notification, and deactivates it  | 
                                                        |
| 294 | - *  | 
                                                        |
| 295 | - * @param array $rows  | 
                                                        |
| 296 | - * @return EE_Payment_Method[]  | 
                                                        |
| 297 | - * @throws InvalidDataTypeException  | 
                                                        |
| 298 | - */  | 
                                                        |
| 299 | - protected function _create_objects($rows = array())  | 
                                                        |
| 300 | -    { | 
                                                        |
| 301 | -        EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 302 | - $payment_methods = parent::_create_objects($rows);  | 
                                                        |
| 303 | - /* @var $payment_methods EE_Payment_Method[] */  | 
                                                        |
| 304 | - $usable_payment_methods = array();  | 
                                                        |
| 305 | -        foreach ($payment_methods as $key => $payment_method) { | 
                                                        |
| 306 | -            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { | 
                                                        |
| 307 | - $usable_payment_methods[ $key ] = $payment_method;  | 
                                                        |
| 308 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct  | 
                                                        |
| 309 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue  | 
                                                        |
| 310 | - // its scripts). but for backwards-compat we should continue to do that  | 
                                                        |
| 311 | - $payment_method->type_obj();  | 
                                                        |
| 312 | -            } elseif ($payment_method->active()) { | 
                                                        |
| 313 | - // only deactivate and notify the admin if the payment is active somewhere  | 
                                                        |
| 314 | - $payment_method->deactivate();  | 
                                                        |
| 315 | - $payment_method->save();  | 
                                                        |
| 316 | - do_action(  | 
                                                        |
| 317 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',  | 
                                                        |
| 318 | - $payment_method  | 
                                                        |
| 319 | - );  | 
                                                        |
| 320 | - new PersistentAdminNotice(  | 
                                                        |
| 321 | - 'auto-deactivated-' . $payment_method->type(),  | 
                                                        |
| 322 | - sprintf(  | 
                                                        |
| 323 | - __(  | 
                                                        |
| 324 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',  | 
                                                        |
| 325 | - 'event_espresso'  | 
                                                        |
| 326 | - ),  | 
                                                        |
| 327 | - $payment_method->admin_name(),  | 
                                                        |
| 328 | - '<br />',  | 
                                                        |
| 329 | -                        '<a href="' . admin_url('plugins.php') . '">', | 
                                                        |
| 330 | - '</a>'  | 
                                                        |
| 331 | - ),  | 
                                                        |
| 332 | - true  | 
                                                        |
| 333 | - );  | 
                                                        |
| 334 | - }  | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | - return $usable_payment_methods;  | 
                                                        |
| 337 | - }  | 
                                                        |
| 338 | -  | 
                                                        |
| 339 | -  | 
                                                        |
| 340 | -  | 
                                                        |
| 341 | - /**  | 
                                                        |
| 342 | - * Gets all the payment methods which can be used for transaction  | 
                                                        |
| 343 | - * (according to the relations between payment methods and events, and  | 
                                                        |
| 344 | - * the currencies used for the transaction and their relation to payment methods)  | 
                                                        |
| 345 | - * @param EE_Transaction $transaction  | 
                                                        |
| 346 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events  | 
                                                        |
| 347 | - * @return EE_Payment_Method[]  | 
                                                        |
| 348 | - */  | 
                                                        |
| 349 | - public function get_all_for_transaction($transaction, $scope)  | 
                                                        |
| 350 | -    { | 
                                                        |
| 351 | - // give addons a chance to override what payment methods are chosen based on the transaction  | 
                                                        |
| 352 | - return apply_filters(  | 
                                                        |
| 353 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 354 | - $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),  | 
                                                        |
| 355 | - $transaction,  | 
                                                        |
| 356 | - $scope  | 
                                                        |
| 357 | - );  | 
                                                        |
| 358 | - }  | 
                                                        |
| 359 | -  | 
                                                        |
| 360 | -  | 
                                                        |
| 361 | - /**  | 
                                                        |
| 362 | - * Returns the payment method used for the last payment made for a registration.  | 
                                                        |
| 363 | - *  | 
                                                        |
| 364 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned.  | 
                                                        |
| 365 | - * It will ONLY return a payment method for a PAYMENT recorded against the registration.  | 
                                                        |
| 366 | - *  | 
                                                        |
| 367 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration.  | 
                                                        |
| 368 | - * @return EE_Payment|null  | 
                                                        |
| 369 | - */  | 
                                                        |
| 370 | - public function get_last_used_for_registration($registration_or_reg_id)  | 
                                                        |
| 371 | -    { | 
                                                        |
| 372 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);  | 
                                                        |
| 373 | -  | 
                                                        |
| 374 | - $query_params = array(  | 
                                                        |
| 375 | - 0 => array(  | 
                                                        |
| 376 | - 'Payment.Registration.REG_ID' => $registration_id,  | 
                                                        |
| 377 | - ),  | 
                                                        |
| 378 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' )  | 
                                                        |
| 379 | - );  | 
                                                        |
| 380 | - return $this->get_one($query_params);  | 
                                                        |
| 381 | - }  | 
                                                        |
| 23 | + const scope_cart = 'CART';  | 
                                                        |
| 24 | +  | 
                                                        |
| 25 | + const scope_admin = 'ADMIN';  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | + const scope_api = 'API';  | 
                                                        |
| 28 | +  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + *  | 
                                                        |
| 31 | + * @type EEM_Payment_Method  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + protected static $_instance = null;  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | +  | 
                                                        |
| 36 | +  | 
                                                        |
| 37 | + /**  | 
                                                        |
| 38 | + * private constructor to prevent direct creation  | 
                                                        |
| 39 | + * @Constructor  | 
                                                        |
| 40 | + * @access protected  | 
                                                        |
| 41 | + * @return EEM_Payment_Method  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + protected function __construct($timezone = null)  | 
                                                        |
| 44 | +	{ | 
                                                        |
| 45 | +		$this->singlular_item = __('Payment Method', 'event_espresso'); | 
                                                        |
| 46 | +		$this->plural_item = __('Payment Methods', 'event_espresso'); | 
                                                        |
| 47 | +		$this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); | 
                                                        |
| 48 | + $this->_fields = array(  | 
                                                        |
| 49 | + 'Payment_Method' => array(  | 
                                                        |
| 50 | +				'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), | 
                                                        |
| 51 | +				'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), | 
                                                        |
| 52 | +				'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), | 
                                                        |
| 53 | +				'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), | 
                                                        |
| 54 | +				'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), | 
                                                        |
| 55 | +				'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), | 
                                                        |
| 56 | +				'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), | 
                                                        |
| 57 | +				'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), | 
                                                        |
| 58 | +				'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), | 
                                                        |
| 59 | +				'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), | 
                                                        |
| 60 | +				'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), | 
                                                        |
| 61 | +				'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' | 
                                                        |
| 62 | + ) );  | 
                                                        |
| 63 | + $this->_model_relations = array(  | 
                                                        |
| 64 | + 'Payment' => new EE_Has_Many_Relation(),  | 
                                                        |
| 65 | +			'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), | 
                                                        |
| 66 | + 'Transaction' => new EE_Has_Many_Relation(),  | 
                                                        |
| 67 | + 'WP_User' => new EE_Belongs_To_Relation(),  | 
                                                        |
| 68 | + );  | 
                                                        |
| 69 | + parent::__construct($timezone);  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /**  | 
                                                        |
| 75 | + * Gets one by the slug provided  | 
                                                        |
| 76 | + * @param string $slug  | 
                                                        |
| 77 | + * @return EE_Payment_Method  | 
                                                        |
| 78 | + */  | 
                                                        |
| 79 | + public function get_one_by_slug($slug)  | 
                                                        |
| 80 | +	{ | 
                                                        |
| 81 | + return $this->get_one(array( array( 'PMD_slug' => $slug ) ));  | 
                                                        |
| 82 | + }  | 
                                                        |
| 83 | +  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | + /**  | 
                                                        |
| 87 | + * Gets all the acceptable scopes for payment methods.  | 
                                                        |
| 88 | + * Keys are their names as store din the DB, and values are nice names for displaying them  | 
                                                        |
| 89 | + * @return array  | 
                                                        |
| 90 | + */  | 
                                                        |
| 91 | + public function scopes()  | 
                                                        |
| 92 | +	{ | 
                                                        |
| 93 | + return apply_filters(  | 
                                                        |
| 94 | + 'FHEE__EEM_Payment_Method__scopes',  | 
                                                        |
| 95 | + array(  | 
                                                        |
| 96 | +				self::scope_cart        => __("Front-end Registration Page", 'event_espresso'), | 
                                                        |
| 97 | +				self::scope_admin   => __("Admin Registration Page (no online processing)", 'event_espresso') | 
                                                        |
| 98 | + )  | 
                                                        |
| 99 | + );  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + /**  | 
                                                        |
| 105 | + * Determines if this is an valid scope  | 
                                                        |
| 106 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes()  | 
                                                        |
| 107 | + * @return boolean  | 
                                                        |
| 108 | + */  | 
                                                        |
| 109 | + public function is_valid_scope($scope)  | 
                                                        |
| 110 | +	{ | 
                                                        |
| 111 | + $scopes = $this->scopes();  | 
                                                        |
| 112 | +		if (isset($scopes[ $scope ])) { | 
                                                        |
| 113 | + return true;  | 
                                                        |
| 114 | +		} else { | 
                                                        |
| 115 | + return false;  | 
                                                        |
| 116 | + }  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | +  | 
                                                        |
| 120 | +  | 
                                                        |
| 121 | + /**  | 
                                                        |
| 122 | + * Gets all active payment methods  | 
                                                        |
| 123 | + * @param string $scope one of  | 
                                                        |
| 124 | + * @param array $query_params  | 
                                                        |
| 125 | + * @throws EE_Error  | 
                                                        |
| 126 | + * @return EE_Payment_Method[]  | 
                                                        |
| 127 | + */  | 
                                                        |
| 128 | + public function get_all_active($scope = null, $query_params = array())  | 
                                                        |
| 129 | +	{ | 
                                                        |
| 130 | +		if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { | 
                                                        |
| 131 | + $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );  | 
                                                        |
| 132 | + }  | 
                                                        |
| 133 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 134 | + }  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | + /**  | 
                                                        |
| 137 | + * Counts all active gateways in the specified scope  | 
                                                        |
| 138 | + * @param string $scope one of EEM_Payment_Method::scope_*  | 
                                                        |
| 139 | + * @param array $query_params  | 
                                                        |
| 140 | + * @return int  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | + public function count_active($scope = null, $query_params = array())  | 
                                                        |
| 143 | +	{ | 
                                                        |
| 144 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 145 | + }  | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + /**  | 
                                                        |
| 148 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params  | 
                                                        |
| 149 | + * argument to get all active for a given scope  | 
                                                        |
| 150 | + * @param string $scope one of the constants EEM_Payment_Method::scope_*  | 
                                                        |
| 151 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 152 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 153 | + * @throws EE_Error  | 
                                                        |
| 154 | + */  | 
                                                        |
| 155 | + protected function _get_query_params_for_all_active($scope = null, $query_params = array())  | 
                                                        |
| 156 | +	{ | 
                                                        |
| 157 | +		if ($scope) { | 
                                                        |
| 158 | +			if ($this->is_valid_scope($scope)) { | 
                                                        |
| 159 | + return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params);  | 
                                                        |
| 160 | +			} else { | 
                                                        |
| 161 | +				throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); | 
                                                        |
| 162 | + }  | 
                                                        |
| 163 | +		} else { | 
                                                        |
| 164 | + $acceptable_scopes = array();  | 
                                                        |
| 165 | + $count = 0;  | 
                                                        |
| 166 | +			foreach ($this->scopes() as $scope_name => $desc) { | 
                                                        |
| 167 | + $count++;  | 
                                                        |
| 168 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );  | 
                                                        |
| 169 | + }  | 
                                                        |
| 170 | + return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params);  | 
                                                        |
| 171 | + }  | 
                                                        |
| 172 | + }  | 
                                                        |
| 173 | +  | 
                                                        |
| 174 | + /**  | 
                                                        |
| 175 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params  | 
                                                        |
| 176 | + * argument to get all active for a given scope  | 
                                                        |
| 177 | + * @param string $scope one of the constants EEM_Payment_Method::scope_*  | 
                                                        |
| 178 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 179 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md  | 
                                                        |
| 180 | + * @throws EE_Error  | 
                                                        |
| 181 | + */  | 
                                                        |
| 182 | + public function get_query_params_for_all_active($scope = null, $query_params = array())  | 
                                                        |
| 183 | +	{ | 
                                                        |
| 184 | + return $this->_get_query_params_for_all_active($scope, $query_params);  | 
                                                        |
| 185 | + }  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | +  | 
                                                        |
| 188 | + /**  | 
                                                        |
| 189 | + * Gets one active payment method. see @get_all_active for documentation  | 
                                                        |
| 190 | + * @param string $scope  | 
                                                        |
| 191 | + * @param array $query_params  | 
                                                        |
| 192 | + * @return EE_Payment_Method  | 
                                                        |
| 193 | + */  | 
                                                        |
| 194 | + public function get_one_active($scope = null, $query_params = array())  | 
                                                        |
| 195 | +	{ | 
                                                        |
| 196 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));  | 
                                                        |
| 197 | + }  | 
                                                        |
| 198 | +  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | +  | 
                                                        |
| 201 | + /**  | 
                                                        |
| 202 | + * Gets one payment method of that type, regardless of whether its active or not  | 
                                                        |
| 203 | + * @param string $type  | 
                                                        |
| 204 | + * @return EE_Payment_Method  | 
                                                        |
| 205 | + */  | 
                                                        |
| 206 | + public function get_one_of_type($type)  | 
                                                        |
| 207 | +	{ | 
                                                        |
| 208 | + return $this->get_one(array( array( 'PMD_type' => $type ) ));  | 
                                                        |
| 209 | + }  | 
                                                        |
| 210 | +  | 
                                                        |
| 211 | +  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + /**  | 
                                                        |
| 214 | + * Overrides parent ot also check by the slug  | 
                                                        |
| 215 | + * @see EEM_Base::ensure_is_obj()  | 
                                                        |
| 216 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id  | 
                                                        |
| 217 | + * @param boolean $ensure_is_in_db  | 
                                                        |
| 218 | + * @return EE_Payment_Method  | 
                                                        |
| 219 | + * @throws EE_Error  | 
                                                        |
| 220 | + */  | 
                                                        |
| 221 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)  | 
                                                        |
| 222 | +	{ | 
                                                        |
| 223 | + // first: check if it's a slug  | 
                                                        |
| 224 | +		if (is_string($base_class_obj_or_id)) { | 
                                                        |
| 225 | + $obj = $this->get_one_by_slug($base_class_obj_or_id);  | 
                                                        |
| 226 | +			if ($obj) { | 
                                                        |
| 227 | + return $obj;  | 
                                                        |
| 228 | + }  | 
                                                        |
| 229 | + }  | 
                                                        |
| 230 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)  | 
                                                        |
| 231 | +		try { | 
                                                        |
| 232 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);  | 
                                                        |
| 233 | +		} catch (EE_Error $e) { | 
                                                        |
| 234 | + // handle it outside the catch  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | +		throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); | 
                                                        |
| 237 | + }  | 
                                                        |
| 238 | +  | 
                                                        |
| 239 | +  | 
                                                        |
| 240 | +  | 
                                                        |
| 241 | + /**  | 
                                                        |
| 242 | + * Gets the ID of this object, or if its a string finds the object's id  | 
                                                        |
| 243 | + * associated with that slug  | 
                                                        |
| 244 | + * @param mixed $base_obj_or_id_or_slug  | 
                                                        |
| 245 | + * @return int  | 
                                                        |
| 246 | + */  | 
                                                        |
| 247 | + public function ensure_is_ID($base_obj_or_id_or_slug)  | 
                                                        |
| 248 | +	{ | 
                                                        |
| 249 | +		if (is_string($base_obj_or_id_or_slug)) { | 
                                                        |
| 250 | + // assume it's a slug  | 
                                                        |
| 251 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);  | 
                                                        |
| 252 | + }  | 
                                                        |
| 253 | + return parent::ensure_is_ID($base_obj_or_id_or_slug);  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | +  | 
                                                        |
| 256 | +  | 
                                                        |
| 257 | +  | 
                                                        |
| 258 | + /**  | 
                                                        |
| 259 | + * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.  | 
                                                        |
| 260 | + * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart  | 
                                                        |
| 261 | + */  | 
                                                        |
| 262 | + public function verify_button_urls($payment_methods = null)  | 
                                                        |
| 263 | +	{ | 
                                                        |
| 264 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);  | 
                                                        |
| 265 | +		foreach ($payment_methods as $payment_method) { | 
                                                        |
| 266 | +			try { | 
                                                        |
| 267 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even  | 
                                                        |
| 268 | + // though this is a caffeinated install, reset it to the default.  | 
                                                        |
| 269 | + $current_button_url = $payment_method->button_url();  | 
                                                        |
| 270 | + if (empty($current_button_url)  | 
                                                        |
| 271 | + || (  | 
                                                        |
| 272 | + strpos($current_button_url, 'decaf') !== false  | 
                                                        |
| 273 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false  | 
                                                        |
| 274 | + )  | 
                                                        |
| 275 | +				) { | 
                                                        |
| 276 | + $payment_method->save(  | 
                                                        |
| 277 | + [  | 
                                                        |
| 278 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url()  | 
                                                        |
| 279 | + ]  | 
                                                        |
| 280 | + );  | 
                                                        |
| 281 | + }  | 
                                                        |
| 282 | +			} catch (EE_Error $e) { | 
                                                        |
| 283 | + $payment_method->set_active(false);  | 
                                                        |
| 284 | + }  | 
                                                        |
| 285 | + }  | 
                                                        |
| 286 | + }  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | +  | 
                                                        |
| 289 | +  | 
                                                        |
| 290 | + /**  | 
                                                        |
| 291 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,  | 
                                                        |
| 292 | + * but also verifies the payment method type of each is a usable object. If not,  | 
                                                        |
| 293 | + * deactivate it, sets a notification, and deactivates it  | 
                                                        |
| 294 | + *  | 
                                                        |
| 295 | + * @param array $rows  | 
                                                        |
| 296 | + * @return EE_Payment_Method[]  | 
                                                        |
| 297 | + * @throws InvalidDataTypeException  | 
                                                        |
| 298 | + */  | 
                                                        |
| 299 | + protected function _create_objects($rows = array())  | 
                                                        |
| 300 | +	{ | 
                                                        |
| 301 | +		EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 302 | + $payment_methods = parent::_create_objects($rows);  | 
                                                        |
| 303 | + /* @var $payment_methods EE_Payment_Method[] */  | 
                                                        |
| 304 | + $usable_payment_methods = array();  | 
                                                        |
| 305 | +		foreach ($payment_methods as $key => $payment_method) { | 
                                                        |
| 306 | +			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { | 
                                                        |
| 307 | + $usable_payment_methods[ $key ] = $payment_method;  | 
                                                        |
| 308 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct  | 
                                                        |
| 309 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue  | 
                                                        |
| 310 | + // its scripts). but for backwards-compat we should continue to do that  | 
                                                        |
| 311 | + $payment_method->type_obj();  | 
                                                        |
| 312 | +			} elseif ($payment_method->active()) { | 
                                                        |
| 313 | + // only deactivate and notify the admin if the payment is active somewhere  | 
                                                        |
| 314 | + $payment_method->deactivate();  | 
                                                        |
| 315 | + $payment_method->save();  | 
                                                        |
| 316 | + do_action(  | 
                                                        |
| 317 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',  | 
                                                        |
| 318 | + $payment_method  | 
                                                        |
| 319 | + );  | 
                                                        |
| 320 | + new PersistentAdminNotice(  | 
                                                        |
| 321 | + 'auto-deactivated-' . $payment_method->type(),  | 
                                                        |
| 322 | + sprintf(  | 
                                                        |
| 323 | + __(  | 
                                                        |
| 324 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',  | 
                                                        |
| 325 | + 'event_espresso'  | 
                                                        |
| 326 | + ),  | 
                                                        |
| 327 | + $payment_method->admin_name(),  | 
                                                        |
| 328 | + '<br />',  | 
                                                        |
| 329 | +						'<a href="' . admin_url('plugins.php') . '">', | 
                                                        |
| 330 | + '</a>'  | 
                                                        |
| 331 | + ),  | 
                                                        |
| 332 | + true  | 
                                                        |
| 333 | + );  | 
                                                        |
| 334 | + }  | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | + return $usable_payment_methods;  | 
                                                        |
| 337 | + }  | 
                                                        |
| 338 | +  | 
                                                        |
| 339 | +  | 
                                                        |
| 340 | +  | 
                                                        |
| 341 | + /**  | 
                                                        |
| 342 | + * Gets all the payment methods which can be used for transaction  | 
                                                        |
| 343 | + * (according to the relations between payment methods and events, and  | 
                                                        |
| 344 | + * the currencies used for the transaction and their relation to payment methods)  | 
                                                        |
| 345 | + * @param EE_Transaction $transaction  | 
                                                        |
| 346 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events  | 
                                                        |
| 347 | + * @return EE_Payment_Method[]  | 
                                                        |
| 348 | + */  | 
                                                        |
| 349 | + public function get_all_for_transaction($transaction, $scope)  | 
                                                        |
| 350 | +	{ | 
                                                        |
| 351 | + // give addons a chance to override what payment methods are chosen based on the transaction  | 
                                                        |
| 352 | + return apply_filters(  | 
                                                        |
| 353 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 354 | + $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )),  | 
                                                        |
| 355 | + $transaction,  | 
                                                        |
| 356 | + $scope  | 
                                                        |
| 357 | + );  | 
                                                        |
| 358 | + }  | 
                                                        |
| 359 | +  | 
                                                        |
| 360 | +  | 
                                                        |
| 361 | + /**  | 
                                                        |
| 362 | + * Returns the payment method used for the last payment made for a registration.  | 
                                                        |
| 363 | + *  | 
                                                        |
| 364 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned.  | 
                                                        |
| 365 | + * It will ONLY return a payment method for a PAYMENT recorded against the registration.  | 
                                                        |
| 366 | + *  | 
                                                        |
| 367 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration.  | 
                                                        |
| 368 | + * @return EE_Payment|null  | 
                                                        |
| 369 | + */  | 
                                                        |
| 370 | + public function get_last_used_for_registration($registration_or_reg_id)  | 
                                                        |
| 371 | +	{ | 
                                                        |
| 372 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);  | 
                                                        |
| 373 | +  | 
                                                        |
| 374 | + $query_params = array(  | 
                                                        |
| 375 | + 0 => array(  | 
                                                        |
| 376 | + 'Payment.Registration.REG_ID' => $registration_id,  | 
                                                        |
| 377 | + ),  | 
                                                        |
| 378 | + 'order_by' => array( 'Payment.PAY_ID' => 'DESC' )  | 
                                                        |
| 379 | + );  | 
                                                        |
| 380 | + return $this->get_one($query_params);  | 
                                                        |
| 381 | + }  | 
                                                        |
| 382 | 382 | }  | 
                                                        
@@ -38,103 +38,103 @@  | 
                                                    ||
| 38 | 38 | * @since 4.0  | 
                                                        
| 39 | 39 | */  | 
                                                        
| 40 | 40 |  if (function_exists('espresso_version')) { | 
                                                        
| 41 | -    if (! function_exists('espresso_duplicate_plugin_error')) { | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * espresso_duplicate_plugin_error  | 
                                                        |
| 44 | - * displays if more than one version of EE is activated at the same time  | 
                                                        |
| 45 | - */  | 
                                                        |
| 46 | - function espresso_duplicate_plugin_error()  | 
                                                        |
| 47 | -        { | 
                                                        |
| 48 | - ?>  | 
                                                        |
| 41 | +	if (! function_exists('espresso_duplicate_plugin_error')) { | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * espresso_duplicate_plugin_error  | 
                                                        |
| 44 | + * displays if more than one version of EE is activated at the same time  | 
                                                        |
| 45 | + */  | 
                                                        |
| 46 | + function espresso_duplicate_plugin_error()  | 
                                                        |
| 47 | +		{ | 
                                                        |
| 48 | + ?>  | 
                                                        |
| 49 | 49 | <div class="error">  | 
                                                        
| 50 | 50 | <p>  | 
                                                        
| 51 | 51 | <?php  | 
                                                        
| 52 | - echo esc_html__(  | 
                                                        |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',  | 
                                                        |
| 54 | - 'event_espresso'  | 
                                                        |
| 55 | - ); ?>  | 
                                                        |
| 52 | + echo esc_html__(  | 
                                                        |
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',  | 
                                                        |
| 54 | + 'event_espresso'  | 
                                                        |
| 55 | + ); ?>  | 
                                                        |
| 56 | 56 | </p>  | 
                                                        
| 57 | 57 | </div>  | 
                                                        
| 58 | 58 | <?php  | 
                                                        
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); | 
                                                        |
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); | 
                                                        |
| 63 | 63 |  } else { | 
                                                        
| 64 | -    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); | 
                                                        |
| 65 | -    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { | 
                                                        |
| 66 | - /**  | 
                                                        |
| 67 | - * espresso_minimum_php_version_error  | 
                                                        |
| 68 | - *  | 
                                                        |
| 69 | - * @return void  | 
                                                        |
| 70 | - */  | 
                                                        |
| 71 | - function espresso_minimum_php_version_error()  | 
                                                        |
| 72 | -        { | 
                                                        |
| 73 | - ?>  | 
                                                        |
| 64 | +	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); | 
                                                        |
| 65 | +	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * espresso_minimum_php_version_error  | 
                                                        |
| 68 | + *  | 
                                                        |
| 69 | + * @return void  | 
                                                        |
| 70 | + */  | 
                                                        |
| 71 | + function espresso_minimum_php_version_error()  | 
                                                        |
| 72 | +		{ | 
                                                        |
| 73 | + ?>  | 
                                                        |
| 74 | 74 | <div class="error">  | 
                                                        
| 75 | 75 | <p>  | 
                                                        
| 76 | 76 | <?php  | 
                                                        
| 77 | - printf(  | 
                                                        |
| 78 | - esc_html__(  | 
                                                        |
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',  | 
                                                        |
| 80 | - 'event_espresso'  | 
                                                        |
| 81 | - ),  | 
                                                        |
| 82 | - EE_MIN_PHP_VER_REQUIRED,  | 
                                                        |
| 83 | - PHP_VERSION,  | 
                                                        |
| 84 | - '<br/>',  | 
                                                        |
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'  | 
                                                        |
| 86 | - );  | 
                                                        |
| 87 | - ?>  | 
                                                        |
| 77 | + printf(  | 
                                                        |
| 78 | + esc_html__(  | 
                                                        |
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',  | 
                                                        |
| 80 | + 'event_espresso'  | 
                                                        |
| 81 | + ),  | 
                                                        |
| 82 | + EE_MIN_PHP_VER_REQUIRED,  | 
                                                        |
| 83 | + PHP_VERSION,  | 
                                                        |
| 84 | + '<br/>',  | 
                                                        |
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'  | 
                                                        |
| 86 | + );  | 
                                                        |
| 87 | + ?>  | 
                                                        |
| 88 | 88 | </p>  | 
                                                        
| 89 | 89 | </div>  | 
                                                        
| 90 | 90 | <?php  | 
                                                        
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 92 | - }  | 
                                                        |
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 92 | + }  | 
                                                        |
| 93 | 93 | |
| 94 | -        add_action('admin_notices', 'espresso_minimum_php_version_error', 1); | 
                                                        |
| 95 | -    } else { | 
                                                        |
| 96 | -        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); | 
                                                        |
| 97 | - /**  | 
                                                        |
| 98 | - * espresso_version  | 
                                                        |
| 99 | - * Returns the plugin version  | 
                                                        |
| 100 | - *  | 
                                                        |
| 101 | - * @return string  | 
                                                        |
| 102 | - */  | 
                                                        |
| 103 | - function espresso_version()  | 
                                                        |
| 104 | -        { | 
                                                        |
| 105 | -            return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.023'); | 
                                                        |
| 106 | - }  | 
                                                        |
| 94 | +		add_action('admin_notices', 'espresso_minimum_php_version_error', 1); | 
                                                        |
| 95 | +	} else { | 
                                                        |
| 96 | +		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); | 
                                                        |
| 97 | + /**  | 
                                                        |
| 98 | + * espresso_version  | 
                                                        |
| 99 | + * Returns the plugin version  | 
                                                        |
| 100 | + *  | 
                                                        |
| 101 | + * @return string  | 
                                                        |
| 102 | + */  | 
                                                        |
| 103 | + function espresso_version()  | 
                                                        |
| 104 | +		{ | 
                                                        |
| 105 | +			return apply_filters('FHEE__espresso__espresso_version', '4.9.78.rc.023'); | 
                                                        |
| 106 | + }  | 
                                                        |
| 107 | 107 | |
| 108 | - /**  | 
                                                        |
| 109 | - * espresso_plugin_activation  | 
                                                        |
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page  | 
                                                        |
| 111 | - */  | 
                                                        |
| 112 | - function espresso_plugin_activation()  | 
                                                        |
| 113 | -        { | 
                                                        |
| 114 | -            update_option('ee_espresso_activation', true); | 
                                                        |
| 115 | - }  | 
                                                        |
| 108 | + /**  | 
                                                        |
| 109 | + * espresso_plugin_activation  | 
                                                        |
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page  | 
                                                        |
| 111 | + */  | 
                                                        |
| 112 | + function espresso_plugin_activation()  | 
                                                        |
| 113 | +		{ | 
                                                        |
| 114 | +			update_option('ee_espresso_activation', true); | 
                                                        |
| 115 | + }  | 
                                                        |
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');  | 
                                                        |
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');  | 
                                                        |
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php';  | 
                                                        |
| 120 | - bootstrap_espresso();  | 
                                                        |
| 121 | - }  | 
                                                        |
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php';  | 
                                                        |
| 120 | + bootstrap_espresso();  | 
                                                        |
| 121 | + }  | 
                                                        |
| 122 | 122 | }  | 
                                                        
| 123 | 123 |  if (! function_exists('espresso_deactivate_plugin')) { | 
                                                        
| 124 | - /**  | 
                                                        |
| 125 | - * deactivate_plugin  | 
                                                        |
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ ));  | 
                                                        |
| 127 | - *  | 
                                                        |
| 128 | - * @access public  | 
                                                        |
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file  | 
                                                        |
| 130 | - * @return void  | 
                                                        |
| 131 | - */  | 
                                                        |
| 132 | - function espresso_deactivate_plugin($plugin_basename = '')  | 
                                                        |
| 133 | -    { | 
                                                        |
| 134 | -        if (! function_exists('deactivate_plugins')) { | 
                                                        |
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php';  | 
                                                        |
| 136 | - }  | 
                                                        |
| 137 | - unset($_GET['activate'], $_REQUEST['activate']);  | 
                                                        |
| 138 | - deactivate_plugins($plugin_basename);  | 
                                                        |
| 139 | - }  | 
                                                        |
| 124 | + /**  | 
                                                        |
| 125 | + * deactivate_plugin  | 
                                                        |
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ ));  | 
                                                        |
| 127 | + *  | 
                                                        |
| 128 | + * @access public  | 
                                                        |
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file  | 
                                                        |
| 130 | + * @return void  | 
                                                        |
| 131 | + */  | 
                                                        |
| 132 | + function espresso_deactivate_plugin($plugin_basename = '')  | 
                                                        |
| 133 | +	{ | 
                                                        |
| 134 | +		if (! function_exists('deactivate_plugins')) { | 
                                                        |
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php';  | 
                                                        |
| 136 | + }  | 
                                                        |
| 137 | + unset($_GET['activate'], $_REQUEST['activate']);  | 
                                                        |
| 138 | + deactivate_plugins($plugin_basename);  | 
                                                        |
| 139 | + }  | 
                                                        |
| 140 | 140 | }  | 
                                                        
@@ -14,1323 +14,1323 @@  | 
                                                    ||
| 14 | 14 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | 16 | |
| 17 | - /**  | 
                                                        |
| 18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.  | 
                                                        |
| 19 | - */  | 
                                                        |
| 20 | - public function __construct($routing = true)  | 
                                                        |
| 21 | -    { | 
                                                        |
| 22 | -        define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); | 
                                                        |
| 23 | -        define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); | 
                                                        |
| 24 | -        define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); | 
                                                        |
| 25 | -        define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); | 
                                                        |
| 26 | -        define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); | 
                                                        |
| 27 | - parent::__construct($routing);  | 
                                                        |
| 28 | - }  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | -  | 
                                                        |
| 31 | - /**  | 
                                                        |
| 32 | - * @return void  | 
                                                        |
| 33 | - */  | 
                                                        |
| 34 | - protected function _extend_page_config()  | 
                                                        |
| 35 | -    { | 
                                                        |
| 36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;  | 
                                                        |
| 37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])  | 
                                                        |
| 38 | - ? $this->_req_data['QST_ID'] : 0;  | 
                                                        |
| 39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])  | 
                                                        |
| 40 | - ? $this->_req_data['QSG_ID'] : 0;  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - $new_page_routes = array(  | 
                                                        |
| 43 | - 'question_groups' => array(  | 
                                                        |
| 44 | - 'func' => '_question_groups_overview_list_table',  | 
                                                        |
| 45 | - 'capability' => 'ee_read_question_groups',  | 
                                                        |
| 46 | - ),  | 
                                                        |
| 47 | - 'add_question' => array(  | 
                                                        |
| 48 | - 'func' => '_edit_question',  | 
                                                        |
| 49 | - 'capability' => 'ee_edit_questions',  | 
                                                        |
| 50 | - ),  | 
                                                        |
| 51 | - 'insert_question' => array(  | 
                                                        |
| 52 | - 'func' => '_insert_or_update_question',  | 
                                                        |
| 53 | -                'args'       => array('new_question' => true), | 
                                                        |
| 54 | - 'capability' => 'ee_edit_questions',  | 
                                                        |
| 55 | - 'noheader' => true,  | 
                                                        |
| 56 | - ),  | 
                                                        |
| 57 | - 'duplicate_question' => array(  | 
                                                        |
| 58 | - 'func' => '_duplicate_question',  | 
                                                        |
| 59 | - 'capability' => 'ee_edit_questions',  | 
                                                        |
| 60 | - 'noheader' => true,  | 
                                                        |
| 61 | - ),  | 
                                                        |
| 62 | - 'trash_question' => array(  | 
                                                        |
| 63 | - 'func' => '_trash_question',  | 
                                                        |
| 64 | - 'capability' => 'ee_delete_question',  | 
                                                        |
| 65 | - 'obj_id' => $qst_id,  | 
                                                        |
| 66 | - 'noheader' => true,  | 
                                                        |
| 67 | - ),  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - 'restore_question' => array(  | 
                                                        |
| 70 | - 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 71 | - 'capability' => 'ee_delete_question',  | 
                                                        |
| 72 | - 'obj_id' => $qst_id,  | 
                                                        |
| 73 | -                'args'       => array('trash' => false), | 
                                                        |
| 74 | - 'noheader' => true,  | 
                                                        |
| 75 | - ),  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - 'delete_question' => array(  | 
                                                        |
| 78 | - 'func' => '_delete_question',  | 
                                                        |
| 79 | - 'capability' => 'ee_delete_question',  | 
                                                        |
| 80 | - 'obj_id' => $qst_id,  | 
                                                        |
| 81 | - 'noheader' => true,  | 
                                                        |
| 82 | - ),  | 
                                                        |
| 83 | -  | 
                                                        |
| 84 | - 'trash_questions' => array(  | 
                                                        |
| 85 | - 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 86 | - 'capability' => 'ee_delete_questions',  | 
                                                        |
| 87 | -                'args'       => array('trash' => true), | 
                                                        |
| 88 | - 'noheader' => true,  | 
                                                        |
| 89 | - ),  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - 'restore_questions' => array(  | 
                                                        |
| 92 | - 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 93 | - 'capability' => 'ee_delete_questions',  | 
                                                        |
| 94 | -                'args'       => array('trash' => false), | 
                                                        |
| 95 | - 'noheader' => true,  | 
                                                        |
| 96 | - ),  | 
                                                        |
| 97 | -  | 
                                                        |
| 98 | - 'delete_questions' => array(  | 
                                                        |
| 99 | - 'func' => '_delete_questions',  | 
                                                        |
| 100 | - 'args' => array(),  | 
                                                        |
| 101 | - 'capability' => 'ee_delete_questions',  | 
                                                        |
| 102 | - 'noheader' => true,  | 
                                                        |
| 103 | - ),  | 
                                                        |
| 104 | -  | 
                                                        |
| 105 | - 'add_question_group' => array(  | 
                                                        |
| 106 | - 'func' => '_edit_question_group',  | 
                                                        |
| 107 | - 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 108 | - ),  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - 'edit_question_group' => array(  | 
                                                        |
| 111 | - 'func' => '_edit_question_group',  | 
                                                        |
| 112 | - 'capability' => 'ee_edit_question_group',  | 
                                                        |
| 113 | - 'obj_id' => $qsg_id,  | 
                                                        |
| 114 | -                'args'       => array('edit'), | 
                                                        |
| 115 | - ),  | 
                                                        |
| 116 | -  | 
                                                        |
| 117 | - 'delete_question_groups' => array(  | 
                                                        |
| 118 | - 'func' => '_delete_question_groups',  | 
                                                        |
| 119 | - 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 120 | - 'noheader' => true,  | 
                                                        |
| 121 | - ),  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - 'delete_question_group' => array(  | 
                                                        |
| 124 | - 'func' => '_delete_question_groups',  | 
                                                        |
| 125 | - 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 126 | - 'obj_id' => $qsg_id,  | 
                                                        |
| 127 | - 'noheader' => true,  | 
                                                        |
| 128 | - ),  | 
                                                        |
| 129 | -  | 
                                                        |
| 130 | - 'trash_question_group' => array(  | 
                                                        |
| 131 | - 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 132 | -                'args'       => array('trash' => true), | 
                                                        |
| 133 | - 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 134 | - 'obj_id' => $qsg_id,  | 
                                                        |
| 135 | - 'noheader' => true,  | 
                                                        |
| 136 | - ),  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | - 'restore_question_group' => array(  | 
                                                        |
| 139 | - 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 140 | -                'args'       => array('trash' => false), | 
                                                        |
| 141 | - 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 142 | - 'obj_id' => $qsg_id,  | 
                                                        |
| 143 | - 'noheader' => true,  | 
                                                        |
| 144 | - ),  | 
                                                        |
| 145 | -  | 
                                                        |
| 146 | - 'insert_question_group' => array(  | 
                                                        |
| 147 | - 'func' => '_insert_or_update_question_group',  | 
                                                        |
| 148 | -                'args'       => array('new_question_group' => true), | 
                                                        |
| 149 | - 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 150 | - 'noheader' => true,  | 
                                                        |
| 151 | - ),  | 
                                                        |
| 152 | -  | 
                                                        |
| 153 | - 'update_question_group' => array(  | 
                                                        |
| 154 | - 'func' => '_insert_or_update_question_group',  | 
                                                        |
| 155 | -                'args'       => array('new_question_group' => false), | 
                                                        |
| 156 | - 'capability' => 'ee_edit_question_group',  | 
                                                        |
| 157 | - 'obj_id' => $qsg_id,  | 
                                                        |
| 158 | - 'noheader' => true,  | 
                                                        |
| 159 | - ),  | 
                                                        |
| 160 | -  | 
                                                        |
| 161 | - 'trash_question_groups' => array(  | 
                                                        |
| 162 | - 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 163 | -                'args'       => array('trash' => true), | 
                                                        |
| 164 | - 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 165 | -                'noheader'   => array('trash' => false), | 
                                                        |
| 166 | - ),  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | - 'restore_question_groups' => array(  | 
                                                        |
| 169 | - 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 170 | -                'args'       => array('trash' => false), | 
                                                        |
| 171 | - 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 172 | - 'noheader' => true,  | 
                                                        |
| 173 | - ),  | 
                                                        |
| 174 | -  | 
                                                        |
| 175 | -  | 
                                                        |
| 176 | - 'espresso_update_question_group_order' => array(  | 
                                                        |
| 177 | - 'func' => 'update_question_group_order',  | 
                                                        |
| 178 | - 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 179 | - 'noheader' => true,  | 
                                                        |
| 180 | - ),  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - 'view_reg_form_settings' => array(  | 
                                                        |
| 183 | - 'func' => '_reg_form_settings',  | 
                                                        |
| 184 | - 'capability' => 'manage_options',  | 
                                                        |
| 185 | - ),  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - 'update_reg_form_settings' => array(  | 
                                                        |
| 188 | - 'func' => '_update_reg_form_settings',  | 
                                                        |
| 189 | - 'capability' => 'manage_options',  | 
                                                        |
| 190 | - 'noheader' => true,  | 
                                                        |
| 191 | - ),  | 
                                                        |
| 192 | - );  | 
                                                        |
| 193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);  | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | - $new_page_config = array(  | 
                                                        |
| 196 | -  | 
                                                        |
| 197 | - 'question_groups' => array(  | 
                                                        |
| 198 | - 'nav' => array(  | 
                                                        |
| 199 | -                    'label' => esc_html__('Question Groups', 'event_espresso'), | 
                                                        |
| 200 | - 'order' => 20,  | 
                                                        |
| 201 | - ),  | 
                                                        |
| 202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table',  | 
                                                        |
| 203 | - 'help_tabs' => array(  | 
                                                        |
| 204 | - 'registration_form_question_groups_help_tab' => array(  | 
                                                        |
| 205 | -                        'title'    => esc_html__('Question Groups', 'event_espresso'), | 
                                                        |
| 206 | - 'filename' => 'registration_form_question_groups',  | 
                                                        |
| 207 | - ),  | 
                                                        |
| 208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array(  | 
                                                        |
| 209 | -                        'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'), | 
                                                        |
| 210 | - 'filename' => 'registration_form_question_groups_table_column_headings',  | 
                                                        |
| 211 | - ),  | 
                                                        |
| 212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(  | 
                                                        |
| 213 | -                        'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), | 
                                                        |
| 214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search',  | 
                                                        |
| 215 | - ),  | 
                                                        |
| 216 | - ),  | 
                                                        |
| 217 | -                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'), | 
                                                        |
| 218 | - 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 219 | - 'require_nonce' => false,  | 
                                                        |
| 220 | - 'qtips' => array(  | 
                                                        |
| 221 | - 'EE_Registration_Form_Tips',  | 
                                                        |
| 222 | - ),  | 
                                                        |
| 223 | - ),  | 
                                                        |
| 224 | -  | 
                                                        |
| 225 | - 'add_question' => array(  | 
                                                        |
| 226 | - 'nav' => array(  | 
                                                        |
| 227 | -                    'label'      => esc_html__('Add Question', 'event_espresso'), | 
                                                        |
| 228 | - 'order' => 5,  | 
                                                        |
| 229 | - 'persistent' => false,  | 
                                                        |
| 230 | - ),  | 
                                                        |
| 231 | -                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 232 | - 'help_tabs' => array(  | 
                                                        |
| 233 | - 'registration_form_add_question_help_tab' => array(  | 
                                                        |
| 234 | -                        'title'    => esc_html__('Add Question', 'event_espresso'), | 
                                                        |
| 235 | - 'filename' => 'registration_form_add_question',  | 
                                                        |
| 236 | - ),  | 
                                                        |
| 237 | - ),  | 
                                                        |
| 238 | -                'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'), | 
                                                        |
| 239 | - 'require_nonce' => false,  | 
                                                        |
| 240 | - ),  | 
                                                        |
| 241 | -  | 
                                                        |
| 242 | - 'add_question_group' => array(  | 
                                                        |
| 243 | - 'nav' => array(  | 
                                                        |
| 244 | -                    'label'      => esc_html__('Add Question Group', 'event_espresso'), | 
                                                        |
| 245 | - 'order' => 5,  | 
                                                        |
| 246 | - 'persistent' => false,  | 
                                                        |
| 247 | - ),  | 
                                                        |
| 248 | -                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 249 | - 'help_tabs' => array(  | 
                                                        |
| 250 | - 'registration_form_add_question_group_help_tab' => array(  | 
                                                        |
| 251 | -                        'title'    => esc_html__('Add Question Group', 'event_espresso'), | 
                                                        |
| 252 | - 'filename' => 'registration_form_add_question_group',  | 
                                                        |
| 253 | - ),  | 
                                                        |
| 254 | - ),  | 
                                                        |
| 255 | -                'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'), | 
                                                        |
| 256 | - 'require_nonce' => false,  | 
                                                        |
| 257 | - ),  | 
                                                        |
| 258 | -  | 
                                                        |
| 259 | - 'edit_question_group' => array(  | 
                                                        |
| 260 | - 'nav' => array(  | 
                                                        |
| 261 | -                    'label'      => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 262 | - 'order' => 5,  | 
                                                        |
| 263 | - 'persistent' => false,  | 
                                                        |
| 264 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(  | 
                                                        |
| 265 | -                        array('question_group_id' => $this->_req_data['question_group_id']), | 
                                                        |
| 266 | - $this->_current_page_view_url  | 
                                                        |
| 267 | - ) : $this->_admin_base_url,  | 
                                                        |
| 268 | - ),  | 
                                                        |
| 269 | -                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 270 | - 'help_tabs' => array(  | 
                                                        |
| 271 | - 'registration_form_edit_question_group_help_tab' => array(  | 
                                                        |
| 272 | -                        'title'    => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 273 | - 'filename' => 'registration_form_edit_question_group',  | 
                                                        |
| 274 | - ),  | 
                                                        |
| 275 | - ),  | 
                                                        |
| 276 | -                'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'), | 
                                                        |
| 277 | - 'require_nonce' => false,  | 
                                                        |
| 278 | - ),  | 
                                                        |
| 279 | -  | 
                                                        |
| 280 | - 'view_reg_form_settings' => array(  | 
                                                        |
| 281 | - 'nav' => array(  | 
                                                        |
| 282 | -                    'label' => esc_html__('Reg Form Settings', 'event_espresso'), | 
                                                        |
| 283 | - 'order' => 40,  | 
                                                        |
| 284 | - ),  | 
                                                        |
| 285 | - 'labels' => array(  | 
                                                        |
| 286 | -                    'publishbox' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 287 | - ),  | 
                                                        |
| 288 | -                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 289 | - 'help_tabs' => array(  | 
                                                        |
| 290 | - 'registration_form_reg_form_settings_help_tab' => array(  | 
                                                        |
| 291 | -                        'title'    => esc_html__('Registration Form Settings', 'event_espresso'), | 
                                                        |
| 292 | - 'filename' => 'registration_form_reg_form_settings',  | 
                                                        |
| 293 | - ),  | 
                                                        |
| 294 | - ),  | 
                                                        |
| 295 | -                'help_tour'     => array('Registration_Form_Settings_Help_Tour'), | 
                                                        |
| 296 | - 'require_nonce' => false,  | 
                                                        |
| 297 | - ),  | 
                                                        |
| 298 | -  | 
                                                        |
| 299 | - );  | 
                                                        |
| 300 | - $this->_page_config = array_merge($this->_page_config, $new_page_config);  | 
                                                        |
| 301 | -  | 
                                                        |
| 302 | - // change the list table we're going to use so it's the NEW list table!  | 
                                                        |
| 303 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';  | 
                                                        |
| 304 | -  | 
                                                        |
| 305 | -  | 
                                                        |
| 306 | - // additional labels  | 
                                                        |
| 307 | - $new_labels = array(  | 
                                                        |
| 308 | -            'add_question'          => esc_html__('Add New Question', 'event_espresso'), | 
                                                        |
| 309 | -            'delete_question'       => esc_html__('Delete Question', 'event_espresso'), | 
                                                        |
| 310 | -            'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'), | 
                                                        |
| 311 | -            'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 312 | -            'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), | 
                                                        |
| 313 | - );  | 
                                                        |
| 314 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);  | 
                                                        |
| 315 | - }  | 
                                                        |
| 316 | -  | 
                                                        |
| 317 | -  | 
                                                        |
| 318 | - /**  | 
                                                        |
| 319 | - * @return void  | 
                                                        |
| 320 | - */  | 
                                                        |
| 321 | - protected function _ajax_hooks()  | 
                                                        |
| 322 | -    { | 
                                                        |
| 323 | -        add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); | 
                                                        |
| 324 | - }  | 
                                                        |
| 325 | -  | 
                                                        |
| 326 | -  | 
                                                        |
| 327 | - /**  | 
                                                        |
| 328 | - * @return void  | 
                                                        |
| 329 | - */  | 
                                                        |
| 330 | - public function load_scripts_styles_question_groups()  | 
                                                        |
| 331 | -    { | 
                                                        |
| 332 | -        wp_enqueue_script('espresso_ajax_table_sorting'); | 
                                                        |
| 333 | - }  | 
                                                        |
| 334 | -  | 
                                                        |
| 335 | -  | 
                                                        |
| 336 | - /**  | 
                                                        |
| 337 | - * @return void  | 
                                                        |
| 338 | - */  | 
                                                        |
| 339 | - public function load_scripts_styles_add_question_group()  | 
                                                        |
| 340 | -    { | 
                                                        |
| 341 | - $this->load_scripts_styles_forms();  | 
                                                        |
| 342 | - $this->load_sortable_question_script();  | 
                                                        |
| 343 | - }  | 
                                                        |
| 344 | -  | 
                                                        |
| 345 | -  | 
                                                        |
| 346 | - /**  | 
                                                        |
| 347 | - * @return void  | 
                                                        |
| 348 | - */  | 
                                                        |
| 349 | - public function load_scripts_styles_edit_question_group()  | 
                                                        |
| 350 | -    { | 
                                                        |
| 351 | - $this->load_scripts_styles_forms();  | 
                                                        |
| 352 | - $this->load_sortable_question_script();  | 
                                                        |
| 353 | - }  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | -  | 
                                                        |
| 356 | - /**  | 
                                                        |
| 357 | - * registers and enqueues script for questions  | 
                                                        |
| 358 | - *  | 
                                                        |
| 359 | - * @return void  | 
                                                        |
| 360 | - */  | 
                                                        |
| 361 | - public function load_sortable_question_script()  | 
                                                        |
| 362 | -    { | 
                                                        |
| 363 | - wp_register_script(  | 
                                                        |
| 364 | - 'ee-question-sortable',  | 
                                                        |
| 365 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',  | 
                                                        |
| 366 | -            array('jquery-ui-sortable'), | 
                                                        |
| 367 | - EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 368 | - true  | 
                                                        |
| 369 | - );  | 
                                                        |
| 370 | -        wp_enqueue_script('ee-question-sortable'); | 
                                                        |
| 371 | - }  | 
                                                        |
| 372 | -  | 
                                                        |
| 373 | -  | 
                                                        |
| 374 | - /**  | 
                                                        |
| 375 | - * @return void  | 
                                                        |
| 376 | - */  | 
                                                        |
| 377 | - protected function _set_list_table_views_default()  | 
                                                        |
| 378 | -    { | 
                                                        |
| 379 | - $this->_views = array(  | 
                                                        |
| 380 | - 'all' => array(  | 
                                                        |
| 381 | - 'slug' => 'all',  | 
                                                        |
| 382 | -                'label'       => esc_html__('View All Questions', 'event_espresso'), | 
                                                        |
| 383 | - 'count' => 0,  | 
                                                        |
| 384 | - 'bulk_action' => array(  | 
                                                        |
| 385 | -                    'trash_questions' => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 386 | - ),  | 
                                                        |
| 387 | - ),  | 
                                                        |
| 388 | - );  | 
                                                        |
| 389 | -  | 
                                                        |
| 390 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 391 | - 'ee_delete_questions',  | 
                                                        |
| 392 | - 'espresso_registration_form_trash_questions'  | 
                                                        |
| 393 | - )  | 
                                                        |
| 394 | -        ) { | 
                                                        |
| 395 | - $this->_views['trash'] = array(  | 
                                                        |
| 396 | - 'slug' => 'trash',  | 
                                                        |
| 397 | -                'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 398 | - 'count' => 0,  | 
                                                        |
| 399 | - 'bulk_action' => array(  | 
                                                        |
| 400 | -                    'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 401 | -                    'restore_questions' => esc_html__('Restore', 'event_espresso'), | 
                                                        |
| 402 | - ),  | 
                                                        |
| 403 | - );  | 
                                                        |
| 404 | - }  | 
                                                        |
| 405 | - }  | 
                                                        |
| 406 | -  | 
                                                        |
| 407 | -  | 
                                                        |
| 408 | - /**  | 
                                                        |
| 409 | - * @return void  | 
                                                        |
| 410 | - */  | 
                                                        |
| 411 | - protected function _set_list_table_views_question_groups()  | 
                                                        |
| 412 | -    { | 
                                                        |
| 413 | - $this->_views = array(  | 
                                                        |
| 414 | - 'all' => array(  | 
                                                        |
| 415 | - 'slug' => 'all',  | 
                                                        |
| 416 | -                'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 417 | - 'count' => 0,  | 
                                                        |
| 418 | - 'bulk_action' => array(  | 
                                                        |
| 419 | -                    'trash_question_groups' => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 420 | - ),  | 
                                                        |
| 421 | - ),  | 
                                                        |
| 422 | - );  | 
                                                        |
| 423 | -  | 
                                                        |
| 424 | - if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 425 | - 'ee_delete_question_groups',  | 
                                                        |
| 426 | - 'espresso_registration_form_trash_question_groups'  | 
                                                        |
| 427 | - )  | 
                                                        |
| 428 | -        ) { | 
                                                        |
| 429 | - $this->_views['trash'] = array(  | 
                                                        |
| 430 | - 'slug' => 'trash',  | 
                                                        |
| 431 | -                'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 432 | - 'count' => 0,  | 
                                                        |
| 433 | - 'bulk_action' => array(  | 
                                                        |
| 434 | -                    'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 435 | -                    'restore_question_groups' => esc_html__('Restore', 'event_espresso'), | 
                                                        |
| 436 | - ),  | 
                                                        |
| 437 | - );  | 
                                                        |
| 438 | - }  | 
                                                        |
| 439 | - }  | 
                                                        |
| 440 | -  | 
                                                        |
| 441 | -  | 
                                                        |
| 442 | - /**  | 
                                                        |
| 443 | - * @return void  | 
                                                        |
| 444 | - * @throws EE_Error  | 
                                                        |
| 445 | - * @throws InvalidArgumentException  | 
                                                        |
| 446 | - * @throws InvalidDataTypeException  | 
                                                        |
| 447 | - * @throws InvalidInterfaceException  | 
                                                        |
| 448 | - */  | 
                                                        |
| 449 | - protected function _questions_overview_list_table()  | 
                                                        |
| 450 | -    { | 
                                                        |
| 451 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 452 | - 'add_question',  | 
                                                        |
| 453 | - 'add_question',  | 
                                                        |
| 454 | - array(),  | 
                                                        |
| 455 | - 'add-new-h2'  | 
                                                        |
| 456 | - );  | 
                                                        |
| 457 | - parent::_questions_overview_list_table();  | 
                                                        |
| 458 | - }  | 
                                                        |
| 459 | -  | 
                                                        |
| 460 | -  | 
                                                        |
| 461 | - /**  | 
                                                        |
| 462 | - * @return void  | 
                                                        |
| 463 | - * @throws DomainException  | 
                                                        |
| 464 | - * @throws EE_Error  | 
                                                        |
| 465 | - * @throws InvalidArgumentException  | 
                                                        |
| 466 | - * @throws InvalidDataTypeException  | 
                                                        |
| 467 | - * @throws InvalidInterfaceException  | 
                                                        |
| 468 | - */  | 
                                                        |
| 469 | - protected function _question_groups_overview_list_table()  | 
                                                        |
| 470 | -    { | 
                                                        |
| 471 | -        $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); | 
                                                        |
| 472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 473 | - 'add_question_group',  | 
                                                        |
| 474 | - 'add_question_group',  | 
                                                        |
| 475 | - array(),  | 
                                                        |
| 476 | - 'add-new-h2'  | 
                                                        |
| 477 | - );  | 
                                                        |
| 478 | - $this->display_admin_list_table_page_with_sidebar();  | 
                                                        |
| 479 | - }  | 
                                                        |
| 480 | -  | 
                                                        |
| 481 | -  | 
                                                        |
| 482 | - /**  | 
                                                        |
| 483 | - * @return void  | 
                                                        |
| 484 | - * @throws EE_Error  | 
                                                        |
| 485 | - * @throws InvalidArgumentException  | 
                                                        |
| 486 | - * @throws InvalidDataTypeException  | 
                                                        |
| 487 | - * @throws InvalidInterfaceException  | 
                                                        |
| 488 | - */  | 
                                                        |
| 489 | - protected function _delete_question()  | 
                                                        |
| 490 | -    { | 
                                                        |
| 491 | - $success = $this->_delete_items($this->_question_model);  | 
                                                        |
| 492 | - $this->_redirect_after_action(  | 
                                                        |
| 493 | - $success,  | 
                                                        |
| 494 | - $this->_question_model->item_name($success),  | 
                                                        |
| 495 | - 'deleted',  | 
                                                        |
| 496 | -            array('action' => 'default', 'status' => 'all') | 
                                                        |
| 497 | - );  | 
                                                        |
| 498 | - }  | 
                                                        |
| 499 | -  | 
                                                        |
| 500 | -  | 
                                                        |
| 501 | - /**  | 
                                                        |
| 502 | - * @return void  | 
                                                        |
| 503 | - * @throws EE_Error  | 
                                                        |
| 504 | - * @throws InvalidArgumentException  | 
                                                        |
| 505 | - * @throws InvalidDataTypeException  | 
                                                        |
| 506 | - * @throws InvalidInterfaceException  | 
                                                        |
| 507 | - */  | 
                                                        |
| 508 | - protected function _delete_questions()  | 
                                                        |
| 509 | -    { | 
                                                        |
| 510 | - $success = $this->_delete_items($this->_question_model);  | 
                                                        |
| 511 | - $this->_redirect_after_action(  | 
                                                        |
| 512 | - $success,  | 
                                                        |
| 513 | - $this->_question_model->item_name($success),  | 
                                                        |
| 514 | - 'deleted permanently',  | 
                                                        |
| 515 | -            array('action' => 'default', 'status' => 'trash') | 
                                                        |
| 516 | - );  | 
                                                        |
| 517 | - }  | 
                                                        |
| 518 | -  | 
                                                        |
| 519 | -  | 
                                                        |
| 520 | - /**  | 
                                                        |
| 521 | - * Performs the deletion of a single or multiple questions or question groups.  | 
                                                        |
| 522 | - *  | 
                                                        |
| 523 | - * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 524 | - * @return int number of items deleted permanently  | 
                                                        |
| 525 | - * @throws EE_Error  | 
                                                        |
| 526 | - * @throws InvalidArgumentException  | 
                                                        |
| 527 | - * @throws InvalidDataTypeException  | 
                                                        |
| 528 | - * @throws InvalidInterfaceException  | 
                                                        |
| 529 | - */  | 
                                                        |
| 530 | - private function _delete_items(EEM_Soft_Delete_Base $model)  | 
                                                        |
| 531 | -    { | 
                                                        |
| 532 | - $success = 0;  | 
                                                        |
| 533 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 534 | -        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 535 | - // if array has more than one element than success message should be plural  | 
                                                        |
| 536 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 537 | - // cycle thru bulk action checkboxes  | 
                                                        |
| 538 | -            while (list($ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 539 | -                if (! $this->_delete_item($ID, $model)) { | 
                                                        |
| 540 | - $success = 0;  | 
                                                        |
| 541 | - }  | 
                                                        |
| 542 | - }  | 
                                                        |
| 543 | -        } elseif (! empty($this->_req_data['QSG_ID'])) { | 
                                                        |
| 544 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);  | 
                                                        |
| 545 | -        } elseif (! empty($this->_req_data['QST_ID'])) { | 
                                                        |
| 546 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model);  | 
                                                        |
| 547 | -        } else { | 
                                                        |
| 548 | - EE_Error::add_error(  | 
                                                        |
| 549 | - sprintf(  | 
                                                        |
| 550 | - esc_html__(  | 
                                                        |
| 551 | - "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",  | 
                                                        |
| 552 | - "event_espresso"  | 
                                                        |
| 553 | - )  | 
                                                        |
| 554 | - ),  | 
                                                        |
| 555 | - __FILE__,  | 
                                                        |
| 556 | - __FUNCTION__,  | 
                                                        |
| 557 | - __LINE__  | 
                                                        |
| 558 | - );  | 
                                                        |
| 559 | - }  | 
                                                        |
| 560 | - return $success;  | 
                                                        |
| 561 | - }  | 
                                                        |
| 562 | -  | 
                                                        |
| 563 | -  | 
                                                        |
| 564 | - /**  | 
                                                        |
| 565 | - * Deletes the specified question (and its associated question options) or question group  | 
                                                        |
| 566 | - *  | 
                                                        |
| 567 | - * @param int $id  | 
                                                        |
| 568 | - * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 569 | - * @return boolean  | 
                                                        |
| 570 | - * @throws EE_Error  | 
                                                        |
| 571 | - * @throws InvalidArgumentException  | 
                                                        |
| 572 | - * @throws InvalidDataTypeException  | 
                                                        |
| 573 | - * @throws InvalidInterfaceException  | 
                                                        |
| 574 | - */  | 
                                                        |
| 575 | - protected function _delete_item($id, $model)  | 
                                                        |
| 576 | -    { | 
                                                        |
| 577 | -        if ($model instanceof EEM_Question) { | 
                                                        |
| 578 | -            EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); | 
                                                        |
| 579 | - }  | 
                                                        |
| 580 | - return $model->delete_permanently_by_ID(absint($id));  | 
                                                        |
| 581 | - }  | 
                                                        |
| 582 | -  | 
                                                        |
| 583 | -  | 
                                                        |
| 584 | - /****************************** QUESTION GROUPS ******************************/  | 
                                                        |
| 585 | -  | 
                                                        |
| 586 | -  | 
                                                        |
| 587 | - /**  | 
                                                        |
| 588 | - * @param string $type  | 
                                                        |
| 589 | - * @return void  | 
                                                        |
| 590 | - * @throws DomainException  | 
                                                        |
| 591 | - * @throws EE_Error  | 
                                                        |
| 592 | - * @throws InvalidArgumentException  | 
                                                        |
| 593 | - * @throws InvalidDataTypeException  | 
                                                        |
| 594 | - * @throws InvalidInterfaceException  | 
                                                        |
| 595 | - */  | 
                                                        |
| 596 | - protected function _edit_question_group($type = 'add')  | 
                                                        |
| 597 | -    { | 
                                                        |
| 598 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 599 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])  | 
                                                        |
| 600 | - ? absint($this->_req_data['QSG_ID'])  | 
                                                        |
| 601 | - : false;  | 
                                                        |
| 602 | -  | 
                                                        |
| 603 | -        switch ($this->_req_action) { | 
                                                        |
| 604 | - case 'add_question_group':  | 
                                                        |
| 605 | -                $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); | 
                                                        |
| 606 | - break;  | 
                                                        |
| 607 | - case 'edit_question_group':  | 
                                                        |
| 608 | -                $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); | 
                                                        |
| 609 | - break;  | 
                                                        |
| 610 | - default:  | 
                                                        |
| 611 | -                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); | 
                                                        |
| 612 | - }  | 
                                                        |
| 613 | - // add ID to title if editing  | 
                                                        |
| 614 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;  | 
                                                        |
| 615 | -        if ($ID) { | 
                                                        |
| 616 | - /** @var EE_Question_Group $questionGroup */  | 
                                                        |
| 617 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID);  | 
                                                        |
| 618 | -            $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); | 
                                                        |
| 619 | -            $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); | 
                                                        |
| 620 | -        } else { | 
                                                        |
| 621 | - /** @var EE_Question_Group $questionGroup */  | 
                                                        |
| 622 | - $questionGroup = EEM_Question_Group::instance()->create_default_object();  | 
                                                        |
| 623 | - $questionGroup->set_order_to_latest();  | 
                                                        |
| 624 | -            $this->_set_add_edit_form_tags('insert_question_group'); | 
                                                        |
| 625 | - }  | 
                                                        |
| 626 | - $this->_template_args['values'] = $this->_yes_no_values;  | 
                                                        |
| 627 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();  | 
                                                        |
| 628 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true;  | 
                                                        |
| 629 | - $this->_template_args['question_group'] = $questionGroup;  | 
                                                        |
| 630 | -  | 
                                                        |
| 631 | -        $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); | 
                                                        |
| 632 | -        $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); | 
                                                        |
| 633 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 634 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',  | 
                                                        |
| 635 | - $this->_template_args,  | 
                                                        |
| 636 | - true  | 
                                                        |
| 637 | - );  | 
                                                        |
| 638 | -  | 
                                                        |
| 639 | - // the details template wrapper  | 
                                                        |
| 640 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 641 | - }  | 
                                                        |
| 642 | -  | 
                                                        |
| 643 | -  | 
                                                        |
| 644 | - /**  | 
                                                        |
| 645 | - * @return void  | 
                                                        |
| 646 | - * @throws EE_Error  | 
                                                        |
| 647 | - * @throws InvalidArgumentException  | 
                                                        |
| 648 | - * @throws InvalidDataTypeException  | 
                                                        |
| 649 | - * @throws InvalidInterfaceException  | 
                                                        |
| 650 | - */  | 
                                                        |
| 651 | - protected function _delete_question_groups()  | 
                                                        |
| 652 | -    { | 
                                                        |
| 653 | - $success = $this->_delete_items($this->_question_group_model);  | 
                                                        |
| 654 | - $this->_redirect_after_action(  | 
                                                        |
| 655 | - $success,  | 
                                                        |
| 656 | - $this->_question_group_model->item_name($success),  | 
                                                        |
| 657 | - 'deleted permanently',  | 
                                                        |
| 658 | -            array('action' => 'question_groups', 'status' => 'trash') | 
                                                        |
| 659 | - );  | 
                                                        |
| 660 | - }  | 
                                                        |
| 661 | -  | 
                                                        |
| 662 | -  | 
                                                        |
| 663 | - /**  | 
                                                        |
| 664 | - * @param bool $new_question_group  | 
                                                        |
| 665 | - * @throws EE_Error  | 
                                                        |
| 666 | - * @throws InvalidArgumentException  | 
                                                        |
| 667 | - * @throws InvalidDataTypeException  | 
                                                        |
| 668 | - * @throws InvalidInterfaceException  | 
                                                        |
| 669 | - */  | 
                                                        |
| 670 | - protected function _insert_or_update_question_group($new_question_group = true)  | 
                                                        |
| 671 | -    { | 
                                                        |
| 672 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 673 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model);  | 
                                                        |
| 674 | -        if ($new_question_group) { | 
                                                        |
| 675 | - // make sure identifier is unique  | 
                                                        |
| 676 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : '';  | 
                                                        |
| 677 | - $identifier_exists = ! empty($identifier_value)  | 
                                                        |
| 678 | - ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0  | 
                                                        |
| 679 | - : false;  | 
                                                        |
| 680 | -            if ($identifier_exists) { | 
                                                        |
| 681 | -                $set_column_values['QSG_identifier'] .= uniqid('id', true); | 
                                                        |
| 682 | - }  | 
                                                        |
| 683 | - $QSG_ID = $this->_question_group_model->insert($set_column_values);  | 
                                                        |
| 684 | - $success = $QSG_ID ? 1 : 0;  | 
                                                        |
| 685 | -            if ($success === 0) { | 
                                                        |
| 686 | - EE_Error::add_error(  | 
                                                        |
| 687 | -                    esc_html__('Something went wrong saving the question group.', 'event_espresso'), | 
                                                        |
| 688 | - __FILE__,  | 
                                                        |
| 689 | - __FUNCTION__,  | 
                                                        |
| 690 | - __LINE__  | 
                                                        |
| 691 | - );  | 
                                                        |
| 692 | - $this->_redirect_after_action(  | 
                                                        |
| 693 | - false,  | 
                                                        |
| 694 | - '',  | 
                                                        |
| 695 | - '',  | 
                                                        |
| 696 | -                    array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), | 
                                                        |
| 697 | - true  | 
                                                        |
| 698 | - );  | 
                                                        |
| 699 | - }  | 
                                                        |
| 700 | -        } else { | 
                                                        |
| 701 | - $QSG_ID = absint($this->_req_data['QSG_ID']);  | 
                                                        |
| 702 | - unset($set_column_values['QSG_ID']);  | 
                                                        |
| 703 | -            $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); | 
                                                        |
| 704 | - }  | 
                                                        |
| 705 | -  | 
                                                        |
| 706 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(  | 
                                                        |
| 707 | - EEM_Attendee::system_question_phone  | 
                                                        |
| 708 | - );  | 
                                                        |
| 709 | - // update the existing related questions  | 
                                                        |
| 710 | - // BUT FIRST... delete the phone question from the Question_Group_Question  | 
                                                        |
| 711 | - // if it is being added to this question group (therefore removed from the existing group)  | 
                                                        |
| 712 | -        if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { | 
                                                        |
| 713 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group  | 
                                                        |
| 714 | - EEM_Question_Group_Question::instance()->delete(  | 
                                                        |
| 715 | - array(  | 
                                                        |
| 716 | - array(  | 
                                                        |
| 717 | - 'QST_ID' => $phone_question_id,  | 
                                                        |
| 718 | -                        'QSG_ID' => array('!=', $QSG_ID), | 
                                                        |
| 719 | - ),  | 
                                                        |
| 720 | - )  | 
                                                        |
| 721 | - );  | 
                                                        |
| 722 | - }  | 
                                                        |
| 723 | - /** @type EE_Question_Group $question_group */  | 
                                                        |
| 724 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);  | 
                                                        |
| 725 | - $questions = $question_group->questions();  | 
                                                        |
| 726 | - // make sure system phone question is added to list of questions for this group  | 
                                                        |
| 727 | -        if (! isset($questions[ $phone_question_id ])) { | 
                                                        |
| 728 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);  | 
                                                        |
| 729 | - }  | 
                                                        |
| 730 | -  | 
                                                        |
| 731 | -        foreach ($questions as $question_ID => $question) { | 
                                                        |
| 732 | - // first we always check for order.  | 
                                                        |
| 733 | -            if (! empty($this->_req_data['question_orders'][ $question_ID ])) { | 
                                                        |
| 734 | - // update question order  | 
                                                        |
| 735 | - $question_group->update_question_order(  | 
                                                        |
| 736 | - $question_ID,  | 
                                                        |
| 737 | - $this->_req_data['question_orders'][ $question_ID ]  | 
                                                        |
| 738 | - );  | 
                                                        |
| 739 | - }  | 
                                                        |
| 740 | -  | 
                                                        |
| 741 | - // then we always check if adding or removing.  | 
                                                        |
| 742 | -            if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { | 
                                                        |
| 743 | - $question_group->add_question($question_ID);  | 
                                                        |
| 744 | -            } else { | 
                                                        |
| 745 | - // not found, remove it (but only if not a system question for the personal group  | 
                                                        |
| 746 | - // with the exception of lname system question - we allow removal of it)  | 
                                                        |
| 747 | - if (in_array(  | 
                                                        |
| 748 | - $question->system_ID(),  | 
                                                        |
| 749 | - EEM_Question::instance()->required_system_questions_in_system_question_group(  | 
                                                        |
| 750 | - $question_group->system_group()  | 
                                                        |
| 751 | - )  | 
                                                        |
| 752 | -                )) { | 
                                                        |
| 753 | - continue;  | 
                                                        |
| 754 | -                } else { | 
                                                        |
| 755 | - $question_group->remove_question($question_ID);  | 
                                                        |
| 756 | - }  | 
                                                        |
| 757 | - }  | 
                                                        |
| 758 | - }  | 
                                                        |
| 759 | - // save new related questions  | 
                                                        |
| 760 | -        if (isset($this->_req_data['questions'])) { | 
                                                        |
| 761 | -            foreach ($this->_req_data['questions'] as $QST_ID) { | 
                                                        |
| 762 | - $question_group->add_question($QST_ID);  | 
                                                        |
| 763 | -                if (isset($this->_req_data['question_orders'][ $QST_ID ])) { | 
                                                        |
| 764 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);  | 
                                                        |
| 765 | - }  | 
                                                        |
| 766 | - }  | 
                                                        |
| 767 | - }  | 
                                                        |
| 768 | -  | 
                                                        |
| 769 | -        if ($success !== false) { | 
                                                        |
| 770 | - $msg = $new_question_group  | 
                                                        |
| 771 | - ? sprintf(  | 
                                                        |
| 772 | -                    esc_html__('The %s has been created', 'event_espresso'), | 
                                                        |
| 773 | - $this->_question_group_model->item_name()  | 
                                                        |
| 774 | - )  | 
                                                        |
| 775 | - : sprintf(  | 
                                                        |
| 776 | - esc_html__(  | 
                                                        |
| 777 | - 'The %s has been updated',  | 
                                                        |
| 778 | - 'event_espresso'  | 
                                                        |
| 779 | - ),  | 
                                                        |
| 780 | - $this->_question_group_model->item_name()  | 
                                                        |
| 781 | - );  | 
                                                        |
| 782 | - EE_Error::add_success($msg);  | 
                                                        |
| 783 | - }  | 
                                                        |
| 784 | - $this->_redirect_after_action(  | 
                                                        |
| 785 | - false,  | 
                                                        |
| 786 | - '',  | 
                                                        |
| 787 | - '',  | 
                                                        |
| 788 | -            array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), | 
                                                        |
| 789 | - true  | 
                                                        |
| 790 | - );  | 
                                                        |
| 791 | - }  | 
                                                        |
| 792 | -  | 
                                                        |
| 793 | -  | 
                                                        |
| 794 | - /**  | 
                                                        |
| 795 | - * duplicates a question and all its question options and redirects to the new question.  | 
                                                        |
| 796 | - *  | 
                                                        |
| 797 | - * @return void  | 
                                                        |
| 798 | - * @throws EE_Error  | 
                                                        |
| 799 | - * @throws InvalidArgumentException  | 
                                                        |
| 800 | - * @throws ReflectionException  | 
                                                        |
| 801 | - * @throws InvalidDataTypeException  | 
                                                        |
| 802 | - * @throws InvalidInterfaceException  | 
                                                        |
| 803 | - */  | 
                                                        |
| 804 | - public function _duplicate_question()  | 
                                                        |
| 805 | -    { | 
                                                        |
| 806 | - $question_ID = (int) $this->_req_data['QST_ID'];  | 
                                                        |
| 807 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID);  | 
                                                        |
| 808 | -        if ($question instanceof EE_Question) { | 
                                                        |
| 809 | - $new_question = $question->duplicate();  | 
                                                        |
| 810 | -            if ($new_question instanceof EE_Question) { | 
                                                        |
| 811 | - $this->_redirect_after_action(  | 
                                                        |
| 812 | - true,  | 
                                                        |
| 813 | -                    esc_html__('Question', 'event_espresso'), | 
                                                        |
| 814 | -                    esc_html__('Duplicated', 'event_espresso'), | 
                                                        |
| 815 | -                    array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), | 
                                                        |
| 816 | - true  | 
                                                        |
| 817 | - );  | 
                                                        |
| 818 | -            } else { | 
                                                        |
| 819 | - global $wpdb;  | 
                                                        |
| 820 | - EE_Error::add_error(  | 
                                                        |
| 821 | - sprintf(  | 
                                                        |
| 822 | - esc_html__(  | 
                                                        |
| 823 | - 'Could not duplicate question with ID %1$d because: %2$s',  | 
                                                        |
| 824 | - 'event_espresso'  | 
                                                        |
| 825 | - ),  | 
                                                        |
| 826 | - $question_ID,  | 
                                                        |
| 827 | - $wpdb->last_error  | 
                                                        |
| 828 | - ),  | 
                                                        |
| 829 | - __FILE__,  | 
                                                        |
| 830 | - __FUNCTION__,  | 
                                                        |
| 831 | - __LINE__  | 
                                                        |
| 832 | - );  | 
                                                        |
| 833 | -                $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); | 
                                                        |
| 834 | - }  | 
                                                        |
| 835 | -        } else { | 
                                                        |
| 836 | - EE_Error::add_error(  | 
                                                        |
| 837 | - sprintf(  | 
                                                        |
| 838 | - esc_html__(  | 
                                                        |
| 839 | - 'Could not duplicate question with ID %d because it didn\'t exist!',  | 
                                                        |
| 840 | - 'event_espresso'  | 
                                                        |
| 841 | - ),  | 
                                                        |
| 842 | - $question_ID  | 
                                                        |
| 843 | - ),  | 
                                                        |
| 844 | - __FILE__,  | 
                                                        |
| 845 | - __FUNCTION__,  | 
                                                        |
| 846 | - __LINE__  | 
                                                        |
| 847 | - );  | 
                                                        |
| 848 | -            $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); | 
                                                        |
| 849 | - }  | 
                                                        |
| 850 | - }  | 
                                                        |
| 851 | -  | 
                                                        |
| 852 | -  | 
                                                        |
| 853 | - /**  | 
                                                        |
| 854 | - * @param bool $trash  | 
                                                        |
| 855 | - * @throws EE_Error  | 
                                                        |
| 856 | - */  | 
                                                        |
| 857 | - protected function _trash_or_restore_question_groups($trash = true)  | 
                                                        |
| 858 | -    { | 
                                                        |
| 859 | - $this->_trash_or_restore_items($this->_question_group_model, $trash);  | 
                                                        |
| 860 | - }  | 
                                                        |
| 861 | -  | 
                                                        |
| 862 | -  | 
                                                        |
| 863 | - /**  | 
                                                        |
| 864 | - *_trash_question  | 
                                                        |
| 865 | - *  | 
                                                        |
| 866 | - * @return void  | 
                                                        |
| 867 | - * @throws EE_Error  | 
                                                        |
| 868 | - */  | 
                                                        |
| 869 | - protected function _trash_question()  | 
                                                        |
| 870 | -    { | 
                                                        |
| 871 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);  | 
                                                        |
| 872 | -        $query_args = array('action' => 'default', 'status' => 'all'); | 
                                                        |
| 873 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);  | 
                                                        |
| 874 | - }  | 
                                                        |
| 875 | -  | 
                                                        |
| 876 | -  | 
                                                        |
| 877 | - /**  | 
                                                        |
| 878 | - * @param bool $trash  | 
                                                        |
| 879 | - * @throws EE_Error  | 
                                                        |
| 880 | - */  | 
                                                        |
| 881 | - protected function _trash_or_restore_questions($trash = true)  | 
                                                        |
| 882 | -    { | 
                                                        |
| 883 | - $this->_trash_or_restore_items($this->_question_model, $trash);  | 
                                                        |
| 884 | - }  | 
                                                        |
| 885 | -  | 
                                                        |
| 886 | -  | 
                                                        |
| 887 | - /**  | 
                                                        |
| 888 | - * Internally used to delete or restore items, using the request data. Meant to be  | 
                                                        |
| 889 | - * flexible between question or question groups  | 
                                                        |
| 890 | - *  | 
                                                        |
| 891 | - * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 892 | - * @param boolean $trash whether to trash or restore  | 
                                                        |
| 893 | - * @throws EE_Error  | 
                                                        |
| 894 | - */  | 
                                                        |
| 895 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)  | 
                                                        |
| 896 | -    { | 
                                                        |
| 897 | -  | 
                                                        |
| 898 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 899 | -  | 
                                                        |
| 900 | - $success = 1;  | 
                                                        |
| 901 | - // Checkboxes  | 
                                                        |
| 902 | - // echo "trash $trash";  | 
                                                        |
| 903 | - // var_dump($this->_req_data['checkbox']);die;  | 
                                                        |
| 904 | -        if (isset($this->_req_data['checkbox'])) { | 
                                                        |
| 905 | -            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 906 | - // if array has more than one element than success message should be plural  | 
                                                        |
| 907 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 908 | - // cycle thru bulk action checkboxes  | 
                                                        |
| 909 | -                while (list($ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 910 | -                    if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { | 
                                                        |
| 911 | - $success = 0;  | 
                                                        |
| 912 | - }  | 
                                                        |
| 913 | - }  | 
                                                        |
| 914 | -            } else { | 
                                                        |
| 915 | - // grab single id and delete  | 
                                                        |
| 916 | - $ID = absint($this->_req_data['checkbox']);  | 
                                                        |
| 917 | -                if (! $model->delete_or_restore_by_ID($trash, $ID)) { | 
                                                        |
| 918 | - $success = 0;  | 
                                                        |
| 919 | - }  | 
                                                        |
| 920 | - }  | 
                                                        |
| 921 | -        } else { | 
                                                        |
| 922 | - // delete via trash link  | 
                                                        |
| 923 | - // grab single id and delete  | 
                                                        |
| 924 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]);  | 
                                                        |
| 925 | -            if (! $model->delete_or_restore_by_ID($trash, $ID)) { | 
                                                        |
| 926 | - $success = 0;  | 
                                                        |
| 927 | - }  | 
                                                        |
| 928 | - }  | 
                                                        |
| 929 | -  | 
                                                        |
| 930 | -  | 
                                                        |
| 931 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );  | 
                                                        |
| 932 | - // echo "action :$action";  | 
                                                        |
| 933 | - // $action = 'questions' ? 'default' : $action;  | 
                                                        |
| 934 | -        if ($trash) { | 
                                                        |
| 935 | - $action_desc = 'trashed';  | 
                                                        |
| 936 | - $status = 'trash';  | 
                                                        |
| 937 | -        } else { | 
                                                        |
| 938 | - $action_desc = 'restored';  | 
                                                        |
| 939 | - $status = 'all';  | 
                                                        |
| 940 | - }  | 
                                                        |
| 941 | - $this->_redirect_after_action(  | 
                                                        |
| 942 | - $success,  | 
                                                        |
| 943 | - $model->item_name($success),  | 
                                                        |
| 944 | - $action_desc,  | 
                                                        |
| 945 | -            array('action' => $action, 'status' => $status) | 
                                                        |
| 946 | - );  | 
                                                        |
| 947 | - }  | 
                                                        |
| 948 | -  | 
                                                        |
| 949 | -  | 
                                                        |
| 950 | - /**  | 
                                                        |
| 951 | - * @param $per_page  | 
                                                        |
| 952 | - * @param int $current_page  | 
                                                        |
| 953 | - * @param bool|false $count  | 
                                                        |
| 954 | - * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 955 | - * @throws EE_Error  | 
                                                        |
| 956 | - * @throws InvalidArgumentException  | 
                                                        |
| 957 | - * @throws InvalidDataTypeException  | 
                                                        |
| 958 | - * @throws InvalidInterfaceException  | 
                                                        |
| 959 | - */  | 
                                                        |
| 960 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 961 | -    { | 
                                                        |
| 962 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);  | 
                                                        |
| 963 | -  | 
                                                        |
| 964 | -        if ($count) { | 
                                                        |
| 965 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items  | 
                                                        |
| 966 | - $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 967 | - $results = $this->_question_model->count_deleted($where);  | 
                                                        |
| 968 | -        } else { | 
                                                        |
| 969 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items  | 
                                                        |
| 970 | - $results = $this->_question_model->get_all_deleted($query_params);  | 
                                                        |
| 971 | - }  | 
                                                        |
| 972 | - return $results;  | 
                                                        |
| 973 | - }  | 
                                                        |
| 974 | -  | 
                                                        |
| 975 | -  | 
                                                        |
| 976 | - /**  | 
                                                        |
| 977 | - * @param $per_page  | 
                                                        |
| 978 | - * @param int $current_page  | 
                                                        |
| 979 | - * @param bool|false $count  | 
                                                        |
| 980 | - * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 981 | - * @throws EE_Error  | 
                                                        |
| 982 | - * @throws InvalidArgumentException  | 
                                                        |
| 983 | - * @throws InvalidDataTypeException  | 
                                                        |
| 984 | - * @throws InvalidInterfaceException  | 
                                                        |
| 985 | - */  | 
                                                        |
| 986 | - public function get_question_groups($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 987 | -    { | 
                                                        |
| 988 | - $questionGroupModel = EEM_Question_Group::instance();  | 
                                                        |
| 989 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);  | 
                                                        |
| 990 | -        if ($count) { | 
                                                        |
| 991 | - $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 992 | - $results = $questionGroupModel->count($where);  | 
                                                        |
| 993 | -        } else { | 
                                                        |
| 994 | - $results = $questionGroupModel->get_all($query_params);  | 
                                                        |
| 995 | - }  | 
                                                        |
| 996 | - return $results;  | 
                                                        |
| 997 | - }  | 
                                                        |
| 998 | -  | 
                                                        |
| 999 | -  | 
                                                        |
| 1000 | - /**  | 
                                                        |
| 1001 | - * @param $per_page  | 
                                                        |
| 1002 | - * @param int $current_page  | 
                                                        |
| 1003 | - * @param bool $count  | 
                                                        |
| 1004 | - * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 1005 | - * @throws EE_Error  | 
                                                        |
| 1006 | - * @throws InvalidArgumentException  | 
                                                        |
| 1007 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1008 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1009 | - */  | 
                                                        |
| 1010 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 1011 | -    { | 
                                                        |
| 1012 | - $questionGroupModel = EEM_Question_Group::instance();  | 
                                                        |
| 1013 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);  | 
                                                        |
| 1014 | -        if ($count) { | 
                                                        |
| 1015 | - $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 1016 | - $query_params['limit'] = null;  | 
                                                        |
| 1017 | - $results = $questionGroupModel->count_deleted($where);  | 
                                                        |
| 1018 | -        } else { | 
                                                        |
| 1019 | - $results = $questionGroupModel->get_all_deleted($query_params);  | 
                                                        |
| 1020 | - }  | 
                                                        |
| 1021 | - return $results;  | 
                                                        |
| 1022 | - }  | 
                                                        |
| 1023 | -  | 
                                                        |
| 1024 | -  | 
                                                        |
| 1025 | - /**  | 
                                                        |
| 1026 | - * method for performing updates to question order  | 
                                                        |
| 1027 | - *  | 
                                                        |
| 1028 | - * @return void results array  | 
                                                        |
| 1029 | - * @throws EE_Error  | 
                                                        |
| 1030 | - * @throws InvalidArgumentException  | 
                                                        |
| 1031 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1032 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1033 | - */  | 
                                                        |
| 1034 | - public function update_question_group_order()  | 
                                                        |
| 1035 | -    { | 
                                                        |
| 1036 | -  | 
                                                        |
| 1037 | -        $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); | 
                                                        |
| 1038 | -  | 
                                                        |
| 1039 | - // grab our row IDs  | 
                                                        |
| 1040 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])  | 
                                                        |
| 1041 | -            ? explode(',', rtrim($this->_req_data['row_ids'], ',')) | 
                                                        |
| 1042 | - : array();  | 
                                                        |
| 1043 | -  | 
                                                        |
| 1044 | - $perpage = ! empty($this->_req_data['perpage'])  | 
                                                        |
| 1045 | - ? (int) $this->_req_data['perpage']  | 
                                                        |
| 1046 | - : null;  | 
                                                        |
| 1047 | - $curpage = ! empty($this->_req_data['curpage'])  | 
                                                        |
| 1048 | - ? (int) $this->_req_data['curpage']  | 
                                                        |
| 1049 | - : null;  | 
                                                        |
| 1050 | -  | 
                                                        |
| 1051 | -        if (! empty($row_ids)) { | 
                                                        |
| 1052 | - // figure out where we start the row_id count at for the current page.  | 
                                                        |
| 1053 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;  | 
                                                        |
| 1054 | -  | 
                                                        |
| 1055 | - $row_count = count($row_ids);  | 
                                                        |
| 1056 | -            for ($i = 0; $i < $row_count; $i++) { | 
                                                        |
| 1057 | - // Update the questions when re-ordering  | 
                                                        |
| 1058 | - $updated = EEM_Question_Group::instance()->update(  | 
                                                        |
| 1059 | -                    array('QSG_order' => $qsgcount), | 
                                                        |
| 1060 | -                    array(array('QSG_ID' => $row_ids[ $i ])) | 
                                                        |
| 1061 | - );  | 
                                                        |
| 1062 | -                if ($updated === false) { | 
                                                        |
| 1063 | - $success = false;  | 
                                                        |
| 1064 | - }  | 
                                                        |
| 1065 | - $qsgcount++;  | 
                                                        |
| 1066 | - }  | 
                                                        |
| 1067 | -        } else { | 
                                                        |
| 1068 | - $success = false;  | 
                                                        |
| 1069 | - }  | 
                                                        |
| 1070 | -  | 
                                                        |
| 1071 | - $errors = ! $success  | 
                                                        |
| 1072 | -            ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') | 
                                                        |
| 1073 | - : false;  | 
                                                        |
| 1074 | -  | 
                                                        |
| 1075 | -        echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); | 
                                                        |
| 1076 | - die();  | 
                                                        |
| 1077 | - }  | 
                                                        |
| 1078 | -  | 
                                                        |
| 1079 | -  | 
                                                        |
| 1080 | -  | 
                                                        |
| 1081 | - /*************************************** REGISTRATION SETTINGS ***************************************/  | 
                                                        |
| 1082 | -  | 
                                                        |
| 1083 | -  | 
                                                        |
| 1084 | - /**  | 
                                                        |
| 1085 | - * @throws DomainException  | 
                                                        |
| 1086 | - * @throws EE_Error  | 
                                                        |
| 1087 | - * @throws InvalidArgumentException  | 
                                                        |
| 1088 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1089 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1090 | - */  | 
                                                        |
| 1091 | - protected function _reg_form_settings()  | 
                                                        |
| 1092 | -    { | 
                                                        |
| 1093 | - $this->_template_args['values'] = $this->_yes_no_values;  | 
                                                        |
| 1094 | - add_action(  | 
                                                        |
| 1095 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',  | 
                                                        |
| 1096 | - array($this, 'email_validation_settings_form'),  | 
                                                        |
| 1097 | - 2  | 
                                                        |
| 1098 | - );  | 
                                                        |
| 1099 | - $this->_template_args = (array) apply_filters(  | 
                                                        |
| 1100 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',  | 
                                                        |
| 1101 | - $this->_template_args  | 
                                                        |
| 1102 | - );  | 
                                                        |
| 1103 | -        $this->_set_add_edit_form_tags('update_reg_form_settings'); | 
                                                        |
| 1104 | - $this->_set_publish_post_box_vars(null, false, false, null, false);  | 
                                                        |
| 1105 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 1106 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',  | 
                                                        |
| 1107 | - $this->_template_args,  | 
                                                        |
| 1108 | - true  | 
                                                        |
| 1109 | - );  | 
                                                        |
| 1110 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1111 | - }  | 
                                                        |
| 1112 | -  | 
                                                        |
| 1113 | -  | 
                                                        |
| 1114 | - /**  | 
                                                        |
| 1115 | - * @return void  | 
                                                        |
| 1116 | - * @throws EE_Error  | 
                                                        |
| 1117 | - * @throws InvalidArgumentException  | 
                                                        |
| 1118 | - * @throws ReflectionException  | 
                                                        |
| 1119 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1120 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1121 | - */  | 
                                                        |
| 1122 | - protected function _update_reg_form_settings()  | 
                                                        |
| 1123 | -    { | 
                                                        |
| 1124 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(  | 
                                                        |
| 1125 | - EE_Registry::instance()->CFG->registration  | 
                                                        |
| 1126 | - );  | 
                                                        |
| 1127 | - EE_Registry::instance()->CFG->registration = apply_filters(  | 
                                                        |
| 1128 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',  | 
                                                        |
| 1129 | - EE_Registry::instance()->CFG->registration  | 
                                                        |
| 1130 | - );  | 
                                                        |
| 1131 | - $success = $this->_update_espresso_configuration(  | 
                                                        |
| 1132 | -            esc_html__('Registration Form Options', 'event_espresso'), | 
                                                        |
| 1133 | - EE_Registry::instance()->CFG,  | 
                                                        |
| 1134 | - __FILE__,  | 
                                                        |
| 1135 | - __FUNCTION__,  | 
                                                        |
| 1136 | - __LINE__  | 
                                                        |
| 1137 | - );  | 
                                                        |
| 1138 | - $this->_redirect_after_action(  | 
                                                        |
| 1139 | - $success,  | 
                                                        |
| 1140 | -            esc_html__('Registration Form Options', 'event_espresso'), | 
                                                        |
| 1141 | - 'updated',  | 
                                                        |
| 1142 | -            array('action' => 'view_reg_form_settings') | 
                                                        |
| 1143 | - );  | 
                                                        |
| 1144 | - }  | 
                                                        |
| 1145 | -  | 
                                                        |
| 1146 | -  | 
                                                        |
| 1147 | - /**  | 
                                                        |
| 1148 | - * @return void  | 
                                                        |
| 1149 | - * @throws EE_Error  | 
                                                        |
| 1150 | - * @throws InvalidArgumentException  | 
                                                        |
| 1151 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1152 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1153 | - */  | 
                                                        |
| 1154 | - public function email_validation_settings_form()  | 
                                                        |
| 1155 | -    { | 
                                                        |
| 1156 | - echo $this->_email_validation_settings_form()->get_html();  | 
                                                        |
| 1157 | - }  | 
                                                        |
| 1158 | -  | 
                                                        |
| 1159 | -  | 
                                                        |
| 1160 | - /**  | 
                                                        |
| 1161 | - * _email_validation_settings_form  | 
                                                        |
| 1162 | - *  | 
                                                        |
| 1163 | - * @access protected  | 
                                                        |
| 1164 | - * @return EE_Form_Section_Proper  | 
                                                        |
| 1165 | - * @throws \EE_Error  | 
                                                        |
| 1166 | - */  | 
                                                        |
| 1167 | - protected function _email_validation_settings_form()  | 
                                                        |
| 1168 | -    { | 
                                                        |
| 1169 | - return new EE_Form_Section_Proper(  | 
                                                        |
| 1170 | - array(  | 
                                                        |
| 1171 | - 'name' => 'email_validation_settings',  | 
                                                        |
| 1172 | - 'html_id' => 'email_validation_settings',  | 
                                                        |
| 1173 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 1174 | - 'subsections' => apply_filters(  | 
                                                        |
| 1175 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',  | 
                                                        |
| 1176 | - array(  | 
                                                        |
| 1177 | - 'email_validation_hdr' => new EE_Form_Section_HTML(  | 
                                                        |
| 1178 | -                            EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) | 
                                                        |
| 1179 | - ),  | 
                                                        |
| 1180 | - 'email_validation_level' => new EE_Select_Input(  | 
                                                        |
| 1181 | - array(  | 
                                                        |
| 1182 | -                                'basic'      => esc_html__('Basic', 'event_espresso'), | 
                                                        |
| 1183 | -                                'wp_default' => esc_html__('WordPress Default', 'event_espresso'), | 
                                                        |
| 1184 | -                                'i18n'       => esc_html__('International', 'event_espresso'), | 
                                                        |
| 1185 | -                                'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'), | 
                                                        |
| 1186 | - ),  | 
                                                        |
| 1187 | - array(  | 
                                                        |
| 1188 | -                                'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') | 
                                                        |
| 1189 | -                                                     . EEH_Template::get_help_tab_link('email_validation_info'), | 
                                                        |
| 1190 | - 'html_help_text' => esc_html__(  | 
                                                        |
| 1191 | - 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',  | 
                                                        |
| 1192 | - 'event_espresso'  | 
                                                        |
| 1193 | - ),  | 
                                                        |
| 1194 | - 'default' => isset(  | 
                                                        |
| 1195 | - EE_Registry::instance()->CFG->registration->email_validation_level  | 
                                                        |
| 1196 | - )  | 
                                                        |
| 1197 | - ? EE_Registry::instance()->CFG->registration->email_validation_level  | 
                                                        |
| 1198 | - : 'wp_default',  | 
                                                        |
| 1199 | - 'required' => false,  | 
                                                        |
| 1200 | - )  | 
                                                        |
| 1201 | - ),  | 
                                                        |
| 1202 | - )  | 
                                                        |
| 1203 | - ),  | 
                                                        |
| 1204 | - )  | 
                                                        |
| 1205 | - );  | 
                                                        |
| 1206 | - }  | 
                                                        |
| 1207 | -  | 
                                                        |
| 1208 | -  | 
                                                        |
| 1209 | - /**  | 
                                                        |
| 1210 | - * @param EE_Registration_Config $EE_Registration_Config  | 
                                                        |
| 1211 | - * @return EE_Registration_Config  | 
                                                        |
| 1212 | - * @throws EE_Error  | 
                                                        |
| 1213 | - * @throws InvalidArgumentException  | 
                                                        |
| 1214 | - * @throws ReflectionException  | 
                                                        |
| 1215 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1216 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1217 | - */  | 
                                                        |
| 1218 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)  | 
                                                        |
| 1219 | -    { | 
                                                        |
| 1220 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level;  | 
                                                        |
| 1221 | -        try { | 
                                                        |
| 1222 | - $email_validation_settings_form = $this->_email_validation_settings_form();  | 
                                                        |
| 1223 | - // if not displaying a form, then check for form submission  | 
                                                        |
| 1224 | -            if ($email_validation_settings_form->was_submitted()) { | 
                                                        |
| 1225 | - // capture form data  | 
                                                        |
| 1226 | - $email_validation_settings_form->receive_form_submission();  | 
                                                        |
| 1227 | - // validate form data  | 
                                                        |
| 1228 | -                if ($email_validation_settings_form->is_valid()) { | 
                                                        |
| 1229 | - // grab validated data from form  | 
                                                        |
| 1230 | - $valid_data = $email_validation_settings_form->valid_data();  | 
                                                        |
| 1231 | -                    if (isset($valid_data['email_validation_level'])) { | 
                                                        |
| 1232 | - $email_validation_level = $valid_data['email_validation_level'];  | 
                                                        |
| 1233 | - // now if they want to use international email addresses  | 
                                                        |
| 1234 | -                        if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { | 
                                                        |
| 1235 | - // in case we need to reset their email validation level,  | 
                                                        |
| 1236 | - // make sure that the previous value wasn't already set to one of the i18n options.  | 
                                                        |
| 1237 | -                            if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { | 
                                                        |
| 1238 | - // if so, then reset it back to "basic" since that is the only other option that,  | 
                                                        |
| 1239 | - // despite offering poor validation, supports i18n email addresses  | 
                                                        |
| 1240 | - $prev_email_validation_level = 'basic';  | 
                                                        |
| 1241 | - }  | 
                                                        |
| 1242 | - // confirm our i18n email validation will work on the server  | 
                                                        |
| 1243 | -                            if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { | 
                                                        |
| 1244 | - // or reset email validation level to previous value  | 
                                                        |
| 1245 | - $email_validation_level = $prev_email_validation_level;  | 
                                                        |
| 1246 | - }  | 
                                                        |
| 1247 | - }  | 
                                                        |
| 1248 | - $EE_Registration_Config->email_validation_level = $email_validation_level;  | 
                                                        |
| 1249 | -                    } else { | 
                                                        |
| 1250 | - EE_Error::add_error(  | 
                                                        |
| 1251 | - esc_html__(  | 
                                                        |
| 1252 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.',  | 
                                                        |
| 1253 | - 'event_espresso'  | 
                                                        |
| 1254 | - ),  | 
                                                        |
| 1255 | - __FILE__,  | 
                                                        |
| 1256 | - __FUNCTION__,  | 
                                                        |
| 1257 | - __LINE__  | 
                                                        |
| 1258 | - );  | 
                                                        |
| 1259 | - }  | 
                                                        |
| 1260 | -                } else { | 
                                                        |
| 1261 | -                    if ($email_validation_settings_form->submission_error_message() !== '') { | 
                                                        |
| 1262 | - EE_Error::add_error(  | 
                                                        |
| 1263 | - $email_validation_settings_form->submission_error_message(),  | 
                                                        |
| 1264 | - __FILE__,  | 
                                                        |
| 1265 | - __FUNCTION__,  | 
                                                        |
| 1266 | - __LINE__  | 
                                                        |
| 1267 | - );  | 
                                                        |
| 1268 | - }  | 
                                                        |
| 1269 | - }  | 
                                                        |
| 1270 | - }  | 
                                                        |
| 1271 | -        } catch (EE_Error $e) { | 
                                                        |
| 1272 | - $e->get_error();  | 
                                                        |
| 1273 | - }  | 
                                                        |
| 1274 | - return $EE_Registration_Config;  | 
                                                        |
| 1275 | - }  | 
                                                        |
| 1276 | -  | 
                                                        |
| 1277 | -  | 
                                                        |
| 1278 | - /**  | 
                                                        |
| 1279 | - * confirms that the server's PHP version has the PCRE module enabled,  | 
                                                        |
| 1280 | - * and that the PCRE version works with our i18n email validation  | 
                                                        |
| 1281 | - *  | 
                                                        |
| 1282 | - * @param EE_Registration_Config $EE_Registration_Config  | 
                                                        |
| 1283 | - * @param string $email_validation_level  | 
                                                        |
| 1284 | - * @return bool  | 
                                                        |
| 1285 | - */  | 
                                                        |
| 1286 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)  | 
                                                        |
| 1287 | -    { | 
                                                        |
| 1288 | - // first check that PCRE is enabled  | 
                                                        |
| 1289 | -        if (! defined('PREG_BAD_UTF8_ERROR')) { | 
                                                        |
| 1290 | - EE_Error::add_error(  | 
                                                        |
| 1291 | - sprintf(  | 
                                                        |
| 1292 | - esc_html__(  | 
                                                        |
| 1293 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',  | 
                                                        |
| 1294 | - 'event_espresso'  | 
                                                        |
| 1295 | - ),  | 
                                                        |
| 1296 | - '<br />'  | 
                                                        |
| 1297 | - ),  | 
                                                        |
| 1298 | - __FILE__,  | 
                                                        |
| 1299 | - __FUNCTION__,  | 
                                                        |
| 1300 | - __LINE__  | 
                                                        |
| 1301 | - );  | 
                                                        |
| 1302 | - return false;  | 
                                                        |
| 1303 | -        } else { | 
                                                        |
| 1304 | - // PCRE support is enabled, but let's still  | 
                                                        |
| 1305 | - // perform a test to see if the server will support it.  | 
                                                        |
| 1306 | - // but first, save the updated validation level to the config,  | 
                                                        |
| 1307 | - // so that the validation strategy picks it up.  | 
                                                        |
| 1308 | - // this will get bumped back down if it doesn't work  | 
                                                        |
| 1309 | - $EE_Registration_Config->email_validation_level = $email_validation_level;  | 
                                                        |
| 1310 | -            try { | 
                                                        |
| 1311 | - $email_validator = new EE_Email_Validation_Strategy();  | 
                                                        |
| 1312 | - $i18n_email_address = apply_filters(  | 
                                                        |
| 1313 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',  | 
                                                        |
| 1314 | - 'jägerjü[email protected]'  | 
                                                        |
| 1315 | - );  | 
                                                        |
| 1316 | - $email_validator->validate($i18n_email_address);  | 
                                                        |
| 1317 | -            } catch (Exception $e) { | 
                                                        |
| 1318 | - EE_Error::add_error(  | 
                                                        |
| 1319 | - sprintf(  | 
                                                        |
| 1320 | - esc_html__(  | 
                                                        |
| 1321 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',  | 
                                                        |
| 1322 | - 'event_espresso'  | 
                                                        |
| 1323 | - ),  | 
                                                        |
| 1324 | - '<br />',  | 
                                                        |
| 1325 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'  | 
                                                        |
| 1326 | - ),  | 
                                                        |
| 1327 | - __FILE__,  | 
                                                        |
| 1328 | - __FUNCTION__,  | 
                                                        |
| 1329 | - __LINE__  | 
                                                        |
| 1330 | - );  | 
                                                        |
| 1331 | - return false;  | 
                                                        |
| 1332 | - }  | 
                                                        |
| 1333 | - }  | 
                                                        |
| 1334 | - return true;  | 
                                                        |
| 1335 | - }  | 
                                                        |
| 17 | + /**  | 
                                                        |
| 18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.  | 
                                                        |
| 19 | + */  | 
                                                        |
| 20 | + public function __construct($routing = true)  | 
                                                        |
| 21 | +	{ | 
                                                        |
| 22 | +		define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); | 
                                                        |
| 23 | +		define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); | 
                                                        |
| 24 | +		define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); | 
                                                        |
| 25 | +		define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); | 
                                                        |
| 26 | +		define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); | 
                                                        |
| 27 | + parent::__construct($routing);  | 
                                                        |
| 28 | + }  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | +  | 
                                                        |
| 31 | + /**  | 
                                                        |
| 32 | + * @return void  | 
                                                        |
| 33 | + */  | 
                                                        |
| 34 | + protected function _extend_page_config()  | 
                                                        |
| 35 | +	{ | 
                                                        |
| 36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN;  | 
                                                        |
| 37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID'])  | 
                                                        |
| 38 | + ? $this->_req_data['QST_ID'] : 0;  | 
                                                        |
| 39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID'])  | 
                                                        |
| 40 | + ? $this->_req_data['QSG_ID'] : 0;  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + $new_page_routes = array(  | 
                                                        |
| 43 | + 'question_groups' => array(  | 
                                                        |
| 44 | + 'func' => '_question_groups_overview_list_table',  | 
                                                        |
| 45 | + 'capability' => 'ee_read_question_groups',  | 
                                                        |
| 46 | + ),  | 
                                                        |
| 47 | + 'add_question' => array(  | 
                                                        |
| 48 | + 'func' => '_edit_question',  | 
                                                        |
| 49 | + 'capability' => 'ee_edit_questions',  | 
                                                        |
| 50 | + ),  | 
                                                        |
| 51 | + 'insert_question' => array(  | 
                                                        |
| 52 | + 'func' => '_insert_or_update_question',  | 
                                                        |
| 53 | +				'args'       => array('new_question' => true), | 
                                                        |
| 54 | + 'capability' => 'ee_edit_questions',  | 
                                                        |
| 55 | + 'noheader' => true,  | 
                                                        |
| 56 | + ),  | 
                                                        |
| 57 | + 'duplicate_question' => array(  | 
                                                        |
| 58 | + 'func' => '_duplicate_question',  | 
                                                        |
| 59 | + 'capability' => 'ee_edit_questions',  | 
                                                        |
| 60 | + 'noheader' => true,  | 
                                                        |
| 61 | + ),  | 
                                                        |
| 62 | + 'trash_question' => array(  | 
                                                        |
| 63 | + 'func' => '_trash_question',  | 
                                                        |
| 64 | + 'capability' => 'ee_delete_question',  | 
                                                        |
| 65 | + 'obj_id' => $qst_id,  | 
                                                        |
| 66 | + 'noheader' => true,  | 
                                                        |
| 67 | + ),  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + 'restore_question' => array(  | 
                                                        |
| 70 | + 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 71 | + 'capability' => 'ee_delete_question',  | 
                                                        |
| 72 | + 'obj_id' => $qst_id,  | 
                                                        |
| 73 | +				'args'       => array('trash' => false), | 
                                                        |
| 74 | + 'noheader' => true,  | 
                                                        |
| 75 | + ),  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + 'delete_question' => array(  | 
                                                        |
| 78 | + 'func' => '_delete_question',  | 
                                                        |
| 79 | + 'capability' => 'ee_delete_question',  | 
                                                        |
| 80 | + 'obj_id' => $qst_id,  | 
                                                        |
| 81 | + 'noheader' => true,  | 
                                                        |
| 82 | + ),  | 
                                                        |
| 83 | +  | 
                                                        |
| 84 | + 'trash_questions' => array(  | 
                                                        |
| 85 | + 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 86 | + 'capability' => 'ee_delete_questions',  | 
                                                        |
| 87 | +				'args'       => array('trash' => true), | 
                                                        |
| 88 | + 'noheader' => true,  | 
                                                        |
| 89 | + ),  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + 'restore_questions' => array(  | 
                                                        |
| 92 | + 'func' => '_trash_or_restore_questions',  | 
                                                        |
| 93 | + 'capability' => 'ee_delete_questions',  | 
                                                        |
| 94 | +				'args'       => array('trash' => false), | 
                                                        |
| 95 | + 'noheader' => true,  | 
                                                        |
| 96 | + ),  | 
                                                        |
| 97 | +  | 
                                                        |
| 98 | + 'delete_questions' => array(  | 
                                                        |
| 99 | + 'func' => '_delete_questions',  | 
                                                        |
| 100 | + 'args' => array(),  | 
                                                        |
| 101 | + 'capability' => 'ee_delete_questions',  | 
                                                        |
| 102 | + 'noheader' => true,  | 
                                                        |
| 103 | + ),  | 
                                                        |
| 104 | +  | 
                                                        |
| 105 | + 'add_question_group' => array(  | 
                                                        |
| 106 | + 'func' => '_edit_question_group',  | 
                                                        |
| 107 | + 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 108 | + ),  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + 'edit_question_group' => array(  | 
                                                        |
| 111 | + 'func' => '_edit_question_group',  | 
                                                        |
| 112 | + 'capability' => 'ee_edit_question_group',  | 
                                                        |
| 113 | + 'obj_id' => $qsg_id,  | 
                                                        |
| 114 | +				'args'       => array('edit'), | 
                                                        |
| 115 | + ),  | 
                                                        |
| 116 | +  | 
                                                        |
| 117 | + 'delete_question_groups' => array(  | 
                                                        |
| 118 | + 'func' => '_delete_question_groups',  | 
                                                        |
| 119 | + 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 120 | + 'noheader' => true,  | 
                                                        |
| 121 | + ),  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + 'delete_question_group' => array(  | 
                                                        |
| 124 | + 'func' => '_delete_question_groups',  | 
                                                        |
| 125 | + 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 126 | + 'obj_id' => $qsg_id,  | 
                                                        |
| 127 | + 'noheader' => true,  | 
                                                        |
| 128 | + ),  | 
                                                        |
| 129 | +  | 
                                                        |
| 130 | + 'trash_question_group' => array(  | 
                                                        |
| 131 | + 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 132 | +				'args'       => array('trash' => true), | 
                                                        |
| 133 | + 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 134 | + 'obj_id' => $qsg_id,  | 
                                                        |
| 135 | + 'noheader' => true,  | 
                                                        |
| 136 | + ),  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | + 'restore_question_group' => array(  | 
                                                        |
| 139 | + 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 140 | +				'args'       => array('trash' => false), | 
                                                        |
| 141 | + 'capability' => 'ee_delete_question_group',  | 
                                                        |
| 142 | + 'obj_id' => $qsg_id,  | 
                                                        |
| 143 | + 'noheader' => true,  | 
                                                        |
| 144 | + ),  | 
                                                        |
| 145 | +  | 
                                                        |
| 146 | + 'insert_question_group' => array(  | 
                                                        |
| 147 | + 'func' => '_insert_or_update_question_group',  | 
                                                        |
| 148 | +				'args'       => array('new_question_group' => true), | 
                                                        |
| 149 | + 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 150 | + 'noheader' => true,  | 
                                                        |
| 151 | + ),  | 
                                                        |
| 152 | +  | 
                                                        |
| 153 | + 'update_question_group' => array(  | 
                                                        |
| 154 | + 'func' => '_insert_or_update_question_group',  | 
                                                        |
| 155 | +				'args'       => array('new_question_group' => false), | 
                                                        |
| 156 | + 'capability' => 'ee_edit_question_group',  | 
                                                        |
| 157 | + 'obj_id' => $qsg_id,  | 
                                                        |
| 158 | + 'noheader' => true,  | 
                                                        |
| 159 | + ),  | 
                                                        |
| 160 | +  | 
                                                        |
| 161 | + 'trash_question_groups' => array(  | 
                                                        |
| 162 | + 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 163 | +				'args'       => array('trash' => true), | 
                                                        |
| 164 | + 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 165 | +				'noheader'   => array('trash' => false), | 
                                                        |
| 166 | + ),  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | + 'restore_question_groups' => array(  | 
                                                        |
| 169 | + 'func' => '_trash_or_restore_question_groups',  | 
                                                        |
| 170 | +				'args'       => array('trash' => false), | 
                                                        |
| 171 | + 'capability' => 'ee_delete_question_groups',  | 
                                                        |
| 172 | + 'noheader' => true,  | 
                                                        |
| 173 | + ),  | 
                                                        |
| 174 | +  | 
                                                        |
| 175 | +  | 
                                                        |
| 176 | + 'espresso_update_question_group_order' => array(  | 
                                                        |
| 177 | + 'func' => 'update_question_group_order',  | 
                                                        |
| 178 | + 'capability' => 'ee_edit_question_groups',  | 
                                                        |
| 179 | + 'noheader' => true,  | 
                                                        |
| 180 | + ),  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + 'view_reg_form_settings' => array(  | 
                                                        |
| 183 | + 'func' => '_reg_form_settings',  | 
                                                        |
| 184 | + 'capability' => 'manage_options',  | 
                                                        |
| 185 | + ),  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + 'update_reg_form_settings' => array(  | 
                                                        |
| 188 | + 'func' => '_update_reg_form_settings',  | 
                                                        |
| 189 | + 'capability' => 'manage_options',  | 
                                                        |
| 190 | + 'noheader' => true,  | 
                                                        |
| 191 | + ),  | 
                                                        |
| 192 | + );  | 
                                                        |
| 193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);  | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | + $new_page_config = array(  | 
                                                        |
| 196 | +  | 
                                                        |
| 197 | + 'question_groups' => array(  | 
                                                        |
| 198 | + 'nav' => array(  | 
                                                        |
| 199 | +					'label' => esc_html__('Question Groups', 'event_espresso'), | 
                                                        |
| 200 | + 'order' => 20,  | 
                                                        |
| 201 | + ),  | 
                                                        |
| 202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table',  | 
                                                        |
| 203 | + 'help_tabs' => array(  | 
                                                        |
| 204 | + 'registration_form_question_groups_help_tab' => array(  | 
                                                        |
| 205 | +						'title'    => esc_html__('Question Groups', 'event_espresso'), | 
                                                        |
| 206 | + 'filename' => 'registration_form_question_groups',  | 
                                                        |
| 207 | + ),  | 
                                                        |
| 208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array(  | 
                                                        |
| 209 | +						'title'    => esc_html__('Question Groups Table Column Headings', 'event_espresso'), | 
                                                        |
| 210 | + 'filename' => 'registration_form_question_groups_table_column_headings',  | 
                                                        |
| 211 | + ),  | 
                                                        |
| 212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array(  | 
                                                        |
| 213 | +						'title'    => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), | 
                                                        |
| 214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search',  | 
                                                        |
| 215 | + ),  | 
                                                        |
| 216 | + ),  | 
                                                        |
| 217 | +				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'), | 
                                                        |
| 218 | + 'metaboxes' => $this->_default_espresso_metaboxes,  | 
                                                        |
| 219 | + 'require_nonce' => false,  | 
                                                        |
| 220 | + 'qtips' => array(  | 
                                                        |
| 221 | + 'EE_Registration_Form_Tips',  | 
                                                        |
| 222 | + ),  | 
                                                        |
| 223 | + ),  | 
                                                        |
| 224 | +  | 
                                                        |
| 225 | + 'add_question' => array(  | 
                                                        |
| 226 | + 'nav' => array(  | 
                                                        |
| 227 | +					'label'      => esc_html__('Add Question', 'event_espresso'), | 
                                                        |
| 228 | + 'order' => 5,  | 
                                                        |
| 229 | + 'persistent' => false,  | 
                                                        |
| 230 | + ),  | 
                                                        |
| 231 | +				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 232 | + 'help_tabs' => array(  | 
                                                        |
| 233 | + 'registration_form_add_question_help_tab' => array(  | 
                                                        |
| 234 | +						'title'    => esc_html__('Add Question', 'event_espresso'), | 
                                                        |
| 235 | + 'filename' => 'registration_form_add_question',  | 
                                                        |
| 236 | + ),  | 
                                                        |
| 237 | + ),  | 
                                                        |
| 238 | +				'help_tour'     => array('Registration_Form_Add_Question_Help_Tour'), | 
                                                        |
| 239 | + 'require_nonce' => false,  | 
                                                        |
| 240 | + ),  | 
                                                        |
| 241 | +  | 
                                                        |
| 242 | + 'add_question_group' => array(  | 
                                                        |
| 243 | + 'nav' => array(  | 
                                                        |
| 244 | +					'label'      => esc_html__('Add Question Group', 'event_espresso'), | 
                                                        |
| 245 | + 'order' => 5,  | 
                                                        |
| 246 | + 'persistent' => false,  | 
                                                        |
| 247 | + ),  | 
                                                        |
| 248 | +				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 249 | + 'help_tabs' => array(  | 
                                                        |
| 250 | + 'registration_form_add_question_group_help_tab' => array(  | 
                                                        |
| 251 | +						'title'    => esc_html__('Add Question Group', 'event_espresso'), | 
                                                        |
| 252 | + 'filename' => 'registration_form_add_question_group',  | 
                                                        |
| 253 | + ),  | 
                                                        |
| 254 | + ),  | 
                                                        |
| 255 | +				'help_tour'     => array('Registration_Form_Add_Question_Group_Help_Tour'), | 
                                                        |
| 256 | + 'require_nonce' => false,  | 
                                                        |
| 257 | + ),  | 
                                                        |
| 258 | +  | 
                                                        |
| 259 | + 'edit_question_group' => array(  | 
                                                        |
| 260 | + 'nav' => array(  | 
                                                        |
| 261 | +					'label'      => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 262 | + 'order' => 5,  | 
                                                        |
| 263 | + 'persistent' => false,  | 
                                                        |
| 264 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(  | 
                                                        |
| 265 | +						array('question_group_id' => $this->_req_data['question_group_id']), | 
                                                        |
| 266 | + $this->_current_page_view_url  | 
                                                        |
| 267 | + ) : $this->_admin_base_url,  | 
                                                        |
| 268 | + ),  | 
                                                        |
| 269 | +				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 270 | + 'help_tabs' => array(  | 
                                                        |
| 271 | + 'registration_form_edit_question_group_help_tab' => array(  | 
                                                        |
| 272 | +						'title'    => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 273 | + 'filename' => 'registration_form_edit_question_group',  | 
                                                        |
| 274 | + ),  | 
                                                        |
| 275 | + ),  | 
                                                        |
| 276 | +				'help_tour'     => array('Registration_Form_Edit_Question_Group_Help_Tour'), | 
                                                        |
| 277 | + 'require_nonce' => false,  | 
                                                        |
| 278 | + ),  | 
                                                        |
| 279 | +  | 
                                                        |
| 280 | + 'view_reg_form_settings' => array(  | 
                                                        |
| 281 | + 'nav' => array(  | 
                                                        |
| 282 | +					'label' => esc_html__('Reg Form Settings', 'event_espresso'), | 
                                                        |
| 283 | + 'order' => 40,  | 
                                                        |
| 284 | + ),  | 
                                                        |
| 285 | + 'labels' => array(  | 
                                                        |
| 286 | +					'publishbox' => esc_html__('Update Settings', 'event_espresso'), | 
                                                        |
| 287 | + ),  | 
                                                        |
| 288 | +				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), | 
                                                        |
| 289 | + 'help_tabs' => array(  | 
                                                        |
| 290 | + 'registration_form_reg_form_settings_help_tab' => array(  | 
                                                        |
| 291 | +						'title'    => esc_html__('Registration Form Settings', 'event_espresso'), | 
                                                        |
| 292 | + 'filename' => 'registration_form_reg_form_settings',  | 
                                                        |
| 293 | + ),  | 
                                                        |
| 294 | + ),  | 
                                                        |
| 295 | +				'help_tour'     => array('Registration_Form_Settings_Help_Tour'), | 
                                                        |
| 296 | + 'require_nonce' => false,  | 
                                                        |
| 297 | + ),  | 
                                                        |
| 298 | +  | 
                                                        |
| 299 | + );  | 
                                                        |
| 300 | + $this->_page_config = array_merge($this->_page_config, $new_page_config);  | 
                                                        |
| 301 | +  | 
                                                        |
| 302 | + // change the list table we're going to use so it's the NEW list table!  | 
                                                        |
| 303 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table';  | 
                                                        |
| 304 | +  | 
                                                        |
| 305 | +  | 
                                                        |
| 306 | + // additional labels  | 
                                                        |
| 307 | + $new_labels = array(  | 
                                                        |
| 308 | +			'add_question'          => esc_html__('Add New Question', 'event_espresso'), | 
                                                        |
| 309 | +			'delete_question'       => esc_html__('Delete Question', 'event_espresso'), | 
                                                        |
| 310 | +			'add_question_group'    => esc_html__('Add New Question Group', 'event_espresso'), | 
                                                        |
| 311 | +			'edit_question_group'   => esc_html__('Edit Question Group', 'event_espresso'), | 
                                                        |
| 312 | +			'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), | 
                                                        |
| 313 | + );  | 
                                                        |
| 314 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels);  | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | +  | 
                                                        |
| 317 | +  | 
                                                        |
| 318 | + /**  | 
                                                        |
| 319 | + * @return void  | 
                                                        |
| 320 | + */  | 
                                                        |
| 321 | + protected function _ajax_hooks()  | 
                                                        |
| 322 | +	{ | 
                                                        |
| 323 | +		add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); | 
                                                        |
| 324 | + }  | 
                                                        |
| 325 | +  | 
                                                        |
| 326 | +  | 
                                                        |
| 327 | + /**  | 
                                                        |
| 328 | + * @return void  | 
                                                        |
| 329 | + */  | 
                                                        |
| 330 | + public function load_scripts_styles_question_groups()  | 
                                                        |
| 331 | +	{ | 
                                                        |
| 332 | +		wp_enqueue_script('espresso_ajax_table_sorting'); | 
                                                        |
| 333 | + }  | 
                                                        |
| 334 | +  | 
                                                        |
| 335 | +  | 
                                                        |
| 336 | + /**  | 
                                                        |
| 337 | + * @return void  | 
                                                        |
| 338 | + */  | 
                                                        |
| 339 | + public function load_scripts_styles_add_question_group()  | 
                                                        |
| 340 | +	{ | 
                                                        |
| 341 | + $this->load_scripts_styles_forms();  | 
                                                        |
| 342 | + $this->load_sortable_question_script();  | 
                                                        |
| 343 | + }  | 
                                                        |
| 344 | +  | 
                                                        |
| 345 | +  | 
                                                        |
| 346 | + /**  | 
                                                        |
| 347 | + * @return void  | 
                                                        |
| 348 | + */  | 
                                                        |
| 349 | + public function load_scripts_styles_edit_question_group()  | 
                                                        |
| 350 | +	{ | 
                                                        |
| 351 | + $this->load_scripts_styles_forms();  | 
                                                        |
| 352 | + $this->load_sortable_question_script();  | 
                                                        |
| 353 | + }  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | +  | 
                                                        |
| 356 | + /**  | 
                                                        |
| 357 | + * registers and enqueues script for questions  | 
                                                        |
| 358 | + *  | 
                                                        |
| 359 | + * @return void  | 
                                                        |
| 360 | + */  | 
                                                        |
| 361 | + public function load_sortable_question_script()  | 
                                                        |
| 362 | +	{ | 
                                                        |
| 363 | + wp_register_script(  | 
                                                        |
| 364 | + 'ee-question-sortable',  | 
                                                        |
| 365 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js',  | 
                                                        |
| 366 | +			array('jquery-ui-sortable'), | 
                                                        |
| 367 | + EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 368 | + true  | 
                                                        |
| 369 | + );  | 
                                                        |
| 370 | +		wp_enqueue_script('ee-question-sortable'); | 
                                                        |
| 371 | + }  | 
                                                        |
| 372 | +  | 
                                                        |
| 373 | +  | 
                                                        |
| 374 | + /**  | 
                                                        |
| 375 | + * @return void  | 
                                                        |
| 376 | + */  | 
                                                        |
| 377 | + protected function _set_list_table_views_default()  | 
                                                        |
| 378 | +	{ | 
                                                        |
| 379 | + $this->_views = array(  | 
                                                        |
| 380 | + 'all' => array(  | 
                                                        |
| 381 | + 'slug' => 'all',  | 
                                                        |
| 382 | +				'label'       => esc_html__('View All Questions', 'event_espresso'), | 
                                                        |
| 383 | + 'count' => 0,  | 
                                                        |
| 384 | + 'bulk_action' => array(  | 
                                                        |
| 385 | +					'trash_questions' => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 386 | + ),  | 
                                                        |
| 387 | + ),  | 
                                                        |
| 388 | + );  | 
                                                        |
| 389 | +  | 
                                                        |
| 390 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 391 | + 'ee_delete_questions',  | 
                                                        |
| 392 | + 'espresso_registration_form_trash_questions'  | 
                                                        |
| 393 | + )  | 
                                                        |
| 394 | +		) { | 
                                                        |
| 395 | + $this->_views['trash'] = array(  | 
                                                        |
| 396 | + 'slug' => 'trash',  | 
                                                        |
| 397 | +				'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 398 | + 'count' => 0,  | 
                                                        |
| 399 | + 'bulk_action' => array(  | 
                                                        |
| 400 | +					'delete_questions'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 401 | +					'restore_questions' => esc_html__('Restore', 'event_espresso'), | 
                                                        |
| 402 | + ),  | 
                                                        |
| 403 | + );  | 
                                                        |
| 404 | + }  | 
                                                        |
| 405 | + }  | 
                                                        |
| 406 | +  | 
                                                        |
| 407 | +  | 
                                                        |
| 408 | + /**  | 
                                                        |
| 409 | + * @return void  | 
                                                        |
| 410 | + */  | 
                                                        |
| 411 | + protected function _set_list_table_views_question_groups()  | 
                                                        |
| 412 | +	{ | 
                                                        |
| 413 | + $this->_views = array(  | 
                                                        |
| 414 | + 'all' => array(  | 
                                                        |
| 415 | + 'slug' => 'all',  | 
                                                        |
| 416 | +				'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 417 | + 'count' => 0,  | 
                                                        |
| 418 | + 'bulk_action' => array(  | 
                                                        |
| 419 | +					'trash_question_groups' => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 420 | + ),  | 
                                                        |
| 421 | + ),  | 
                                                        |
| 422 | + );  | 
                                                        |
| 423 | +  | 
                                                        |
| 424 | + if (EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 425 | + 'ee_delete_question_groups',  | 
                                                        |
| 426 | + 'espresso_registration_form_trash_question_groups'  | 
                                                        |
| 427 | + )  | 
                                                        |
| 428 | +		) { | 
                                                        |
| 429 | + $this->_views['trash'] = array(  | 
                                                        |
| 430 | + 'slug' => 'trash',  | 
                                                        |
| 431 | +				'label'       => esc_html__('Trash', 'event_espresso'), | 
                                                        |
| 432 | + 'count' => 0,  | 
                                                        |
| 433 | + 'bulk_action' => array(  | 
                                                        |
| 434 | +					'delete_question_groups'  => esc_html__('Delete Permanently', 'event_espresso'), | 
                                                        |
| 435 | +					'restore_question_groups' => esc_html__('Restore', 'event_espresso'), | 
                                                        |
| 436 | + ),  | 
                                                        |
| 437 | + );  | 
                                                        |
| 438 | + }  | 
                                                        |
| 439 | + }  | 
                                                        |
| 440 | +  | 
                                                        |
| 441 | +  | 
                                                        |
| 442 | + /**  | 
                                                        |
| 443 | + * @return void  | 
                                                        |
| 444 | + * @throws EE_Error  | 
                                                        |
| 445 | + * @throws InvalidArgumentException  | 
                                                        |
| 446 | + * @throws InvalidDataTypeException  | 
                                                        |
| 447 | + * @throws InvalidInterfaceException  | 
                                                        |
| 448 | + */  | 
                                                        |
| 449 | + protected function _questions_overview_list_table()  | 
                                                        |
| 450 | +	{ | 
                                                        |
| 451 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 452 | + 'add_question',  | 
                                                        |
| 453 | + 'add_question',  | 
                                                        |
| 454 | + array(),  | 
                                                        |
| 455 | + 'add-new-h2'  | 
                                                        |
| 456 | + );  | 
                                                        |
| 457 | + parent::_questions_overview_list_table();  | 
                                                        |
| 458 | + }  | 
                                                        |
| 459 | +  | 
                                                        |
| 460 | +  | 
                                                        |
| 461 | + /**  | 
                                                        |
| 462 | + * @return void  | 
                                                        |
| 463 | + * @throws DomainException  | 
                                                        |
| 464 | + * @throws EE_Error  | 
                                                        |
| 465 | + * @throws InvalidArgumentException  | 
                                                        |
| 466 | + * @throws InvalidDataTypeException  | 
                                                        |
| 467 | + * @throws InvalidInterfaceException  | 
                                                        |
| 468 | + */  | 
                                                        |
| 469 | + protected function _question_groups_overview_list_table()  | 
                                                        |
| 470 | +	{ | 
                                                        |
| 471 | +		$this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); | 
                                                        |
| 472 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(  | 
                                                        |
| 473 | + 'add_question_group',  | 
                                                        |
| 474 | + 'add_question_group',  | 
                                                        |
| 475 | + array(),  | 
                                                        |
| 476 | + 'add-new-h2'  | 
                                                        |
| 477 | + );  | 
                                                        |
| 478 | + $this->display_admin_list_table_page_with_sidebar();  | 
                                                        |
| 479 | + }  | 
                                                        |
| 480 | +  | 
                                                        |
| 481 | +  | 
                                                        |
| 482 | + /**  | 
                                                        |
| 483 | + * @return void  | 
                                                        |
| 484 | + * @throws EE_Error  | 
                                                        |
| 485 | + * @throws InvalidArgumentException  | 
                                                        |
| 486 | + * @throws InvalidDataTypeException  | 
                                                        |
| 487 | + * @throws InvalidInterfaceException  | 
                                                        |
| 488 | + */  | 
                                                        |
| 489 | + protected function _delete_question()  | 
                                                        |
| 490 | +	{ | 
                                                        |
| 491 | + $success = $this->_delete_items($this->_question_model);  | 
                                                        |
| 492 | + $this->_redirect_after_action(  | 
                                                        |
| 493 | + $success,  | 
                                                        |
| 494 | + $this->_question_model->item_name($success),  | 
                                                        |
| 495 | + 'deleted',  | 
                                                        |
| 496 | +			array('action' => 'default', 'status' => 'all') | 
                                                        |
| 497 | + );  | 
                                                        |
| 498 | + }  | 
                                                        |
| 499 | +  | 
                                                        |
| 500 | +  | 
                                                        |
| 501 | + /**  | 
                                                        |
| 502 | + * @return void  | 
                                                        |
| 503 | + * @throws EE_Error  | 
                                                        |
| 504 | + * @throws InvalidArgumentException  | 
                                                        |
| 505 | + * @throws InvalidDataTypeException  | 
                                                        |
| 506 | + * @throws InvalidInterfaceException  | 
                                                        |
| 507 | + */  | 
                                                        |
| 508 | + protected function _delete_questions()  | 
                                                        |
| 509 | +	{ | 
                                                        |
| 510 | + $success = $this->_delete_items($this->_question_model);  | 
                                                        |
| 511 | + $this->_redirect_after_action(  | 
                                                        |
| 512 | + $success,  | 
                                                        |
| 513 | + $this->_question_model->item_name($success),  | 
                                                        |
| 514 | + 'deleted permanently',  | 
                                                        |
| 515 | +			array('action' => 'default', 'status' => 'trash') | 
                                                        |
| 516 | + );  | 
                                                        |
| 517 | + }  | 
                                                        |
| 518 | +  | 
                                                        |
| 519 | +  | 
                                                        |
| 520 | + /**  | 
                                                        |
| 521 | + * Performs the deletion of a single or multiple questions or question groups.  | 
                                                        |
| 522 | + *  | 
                                                        |
| 523 | + * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 524 | + * @return int number of items deleted permanently  | 
                                                        |
| 525 | + * @throws EE_Error  | 
                                                        |
| 526 | + * @throws InvalidArgumentException  | 
                                                        |
| 527 | + * @throws InvalidDataTypeException  | 
                                                        |
| 528 | + * @throws InvalidInterfaceException  | 
                                                        |
| 529 | + */  | 
                                                        |
| 530 | + private function _delete_items(EEM_Soft_Delete_Base $model)  | 
                                                        |
| 531 | +	{ | 
                                                        |
| 532 | + $success = 0;  | 
                                                        |
| 533 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 534 | +		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 535 | + // if array has more than one element than success message should be plural  | 
                                                        |
| 536 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 537 | + // cycle thru bulk action checkboxes  | 
                                                        |
| 538 | +			while (list($ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 539 | +				if (! $this->_delete_item($ID, $model)) { | 
                                                        |
| 540 | + $success = 0;  | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | + }  | 
                                                        |
| 543 | +		} elseif (! empty($this->_req_data['QSG_ID'])) { | 
                                                        |
| 544 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model);  | 
                                                        |
| 545 | +		} elseif (! empty($this->_req_data['QST_ID'])) { | 
                                                        |
| 546 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model);  | 
                                                        |
| 547 | +		} else { | 
                                                        |
| 548 | + EE_Error::add_error(  | 
                                                        |
| 549 | + sprintf(  | 
                                                        |
| 550 | + esc_html__(  | 
                                                        |
| 551 | + "No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.",  | 
                                                        |
| 552 | + "event_espresso"  | 
                                                        |
| 553 | + )  | 
                                                        |
| 554 | + ),  | 
                                                        |
| 555 | + __FILE__,  | 
                                                        |
| 556 | + __FUNCTION__,  | 
                                                        |
| 557 | + __LINE__  | 
                                                        |
| 558 | + );  | 
                                                        |
| 559 | + }  | 
                                                        |
| 560 | + return $success;  | 
                                                        |
| 561 | + }  | 
                                                        |
| 562 | +  | 
                                                        |
| 563 | +  | 
                                                        |
| 564 | + /**  | 
                                                        |
| 565 | + * Deletes the specified question (and its associated question options) or question group  | 
                                                        |
| 566 | + *  | 
                                                        |
| 567 | + * @param int $id  | 
                                                        |
| 568 | + * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 569 | + * @return boolean  | 
                                                        |
| 570 | + * @throws EE_Error  | 
                                                        |
| 571 | + * @throws InvalidArgumentException  | 
                                                        |
| 572 | + * @throws InvalidDataTypeException  | 
                                                        |
| 573 | + * @throws InvalidInterfaceException  | 
                                                        |
| 574 | + */  | 
                                                        |
| 575 | + protected function _delete_item($id, $model)  | 
                                                        |
| 576 | +	{ | 
                                                        |
| 577 | +		if ($model instanceof EEM_Question) { | 
                                                        |
| 578 | +			EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); | 
                                                        |
| 579 | + }  | 
                                                        |
| 580 | + return $model->delete_permanently_by_ID(absint($id));  | 
                                                        |
| 581 | + }  | 
                                                        |
| 582 | +  | 
                                                        |
| 583 | +  | 
                                                        |
| 584 | + /****************************** QUESTION GROUPS ******************************/  | 
                                                        |
| 585 | +  | 
                                                        |
| 586 | +  | 
                                                        |
| 587 | + /**  | 
                                                        |
| 588 | + * @param string $type  | 
                                                        |
| 589 | + * @return void  | 
                                                        |
| 590 | + * @throws DomainException  | 
                                                        |
| 591 | + * @throws EE_Error  | 
                                                        |
| 592 | + * @throws InvalidArgumentException  | 
                                                        |
| 593 | + * @throws InvalidDataTypeException  | 
                                                        |
| 594 | + * @throws InvalidInterfaceException  | 
                                                        |
| 595 | + */  | 
                                                        |
| 596 | + protected function _edit_question_group($type = 'add')  | 
                                                        |
| 597 | +	{ | 
                                                        |
| 598 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 599 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID'])  | 
                                                        |
| 600 | + ? absint($this->_req_data['QSG_ID'])  | 
                                                        |
| 601 | + : false;  | 
                                                        |
| 602 | +  | 
                                                        |
| 603 | +		switch ($this->_req_action) { | 
                                                        |
| 604 | + case 'add_question_group':  | 
                                                        |
| 605 | +				$this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); | 
                                                        |
| 606 | + break;  | 
                                                        |
| 607 | + case 'edit_question_group':  | 
                                                        |
| 608 | +				$this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); | 
                                                        |
| 609 | + break;  | 
                                                        |
| 610 | + default:  | 
                                                        |
| 611 | +				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); | 
                                                        |
| 612 | + }  | 
                                                        |
| 613 | + // add ID to title if editing  | 
                                                        |
| 614 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;  | 
                                                        |
| 615 | +		if ($ID) { | 
                                                        |
| 616 | + /** @var EE_Question_Group $questionGroup */  | 
                                                        |
| 617 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID);  | 
                                                        |
| 618 | +			$additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); | 
                                                        |
| 619 | +			$this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); | 
                                                        |
| 620 | +		} else { | 
                                                        |
| 621 | + /** @var EE_Question_Group $questionGroup */  | 
                                                        |
| 622 | + $questionGroup = EEM_Question_Group::instance()->create_default_object();  | 
                                                        |
| 623 | + $questionGroup->set_order_to_latest();  | 
                                                        |
| 624 | +			$this->_set_add_edit_form_tags('insert_question_group'); | 
                                                        |
| 625 | + }  | 
                                                        |
| 626 | + $this->_template_args['values'] = $this->_yes_no_values;  | 
                                                        |
| 627 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group();  | 
                                                        |
| 628 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true;  | 
                                                        |
| 629 | + $this->_template_args['question_group'] = $questionGroup;  | 
                                                        |
| 630 | +  | 
                                                        |
| 631 | +		$redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); | 
                                                        |
| 632 | +		$this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); | 
                                                        |
| 633 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 634 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php',  | 
                                                        |
| 635 | + $this->_template_args,  | 
                                                        |
| 636 | + true  | 
                                                        |
| 637 | + );  | 
                                                        |
| 638 | +  | 
                                                        |
| 639 | + // the details template wrapper  | 
                                                        |
| 640 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 641 | + }  | 
                                                        |
| 642 | +  | 
                                                        |
| 643 | +  | 
                                                        |
| 644 | + /**  | 
                                                        |
| 645 | + * @return void  | 
                                                        |
| 646 | + * @throws EE_Error  | 
                                                        |
| 647 | + * @throws InvalidArgumentException  | 
                                                        |
| 648 | + * @throws InvalidDataTypeException  | 
                                                        |
| 649 | + * @throws InvalidInterfaceException  | 
                                                        |
| 650 | + */  | 
                                                        |
| 651 | + protected function _delete_question_groups()  | 
                                                        |
| 652 | +	{ | 
                                                        |
| 653 | + $success = $this->_delete_items($this->_question_group_model);  | 
                                                        |
| 654 | + $this->_redirect_after_action(  | 
                                                        |
| 655 | + $success,  | 
                                                        |
| 656 | + $this->_question_group_model->item_name($success),  | 
                                                        |
| 657 | + 'deleted permanently',  | 
                                                        |
| 658 | +			array('action' => 'question_groups', 'status' => 'trash') | 
                                                        |
| 659 | + );  | 
                                                        |
| 660 | + }  | 
                                                        |
| 661 | +  | 
                                                        |
| 662 | +  | 
                                                        |
| 663 | + /**  | 
                                                        |
| 664 | + * @param bool $new_question_group  | 
                                                        |
| 665 | + * @throws EE_Error  | 
                                                        |
| 666 | + * @throws InvalidArgumentException  | 
                                                        |
| 667 | + * @throws InvalidDataTypeException  | 
                                                        |
| 668 | + * @throws InvalidInterfaceException  | 
                                                        |
| 669 | + */  | 
                                                        |
| 670 | + protected function _insert_or_update_question_group($new_question_group = true)  | 
                                                        |
| 671 | +	{ | 
                                                        |
| 672 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 673 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model);  | 
                                                        |
| 674 | +		if ($new_question_group) { | 
                                                        |
| 675 | + // make sure identifier is unique  | 
                                                        |
| 676 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : '';  | 
                                                        |
| 677 | + $identifier_exists = ! empty($identifier_value)  | 
                                                        |
| 678 | + ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0  | 
                                                        |
| 679 | + : false;  | 
                                                        |
| 680 | +			if ($identifier_exists) { | 
                                                        |
| 681 | +				$set_column_values['QSG_identifier'] .= uniqid('id', true); | 
                                                        |
| 682 | + }  | 
                                                        |
| 683 | + $QSG_ID = $this->_question_group_model->insert($set_column_values);  | 
                                                        |
| 684 | + $success = $QSG_ID ? 1 : 0;  | 
                                                        |
| 685 | +			if ($success === 0) { | 
                                                        |
| 686 | + EE_Error::add_error(  | 
                                                        |
| 687 | +					esc_html__('Something went wrong saving the question group.', 'event_espresso'), | 
                                                        |
| 688 | + __FILE__,  | 
                                                        |
| 689 | + __FUNCTION__,  | 
                                                        |
| 690 | + __LINE__  | 
                                                        |
| 691 | + );  | 
                                                        |
| 692 | + $this->_redirect_after_action(  | 
                                                        |
| 693 | + false,  | 
                                                        |
| 694 | + '',  | 
                                                        |
| 695 | + '',  | 
                                                        |
| 696 | +					array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), | 
                                                        |
| 697 | + true  | 
                                                        |
| 698 | + );  | 
                                                        |
| 699 | + }  | 
                                                        |
| 700 | +		} else { | 
                                                        |
| 701 | + $QSG_ID = absint($this->_req_data['QSG_ID']);  | 
                                                        |
| 702 | + unset($set_column_values['QSG_ID']);  | 
                                                        |
| 703 | +			$success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); | 
                                                        |
| 704 | + }  | 
                                                        |
| 705 | +  | 
                                                        |
| 706 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(  | 
                                                        |
| 707 | + EEM_Attendee::system_question_phone  | 
                                                        |
| 708 | + );  | 
                                                        |
| 709 | + // update the existing related questions  | 
                                                        |
| 710 | + // BUT FIRST... delete the phone question from the Question_Group_Question  | 
                                                        |
| 711 | + // if it is being added to this question group (therefore removed from the existing group)  | 
                                                        |
| 712 | +		if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { | 
                                                        |
| 713 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group  | 
                                                        |
| 714 | + EEM_Question_Group_Question::instance()->delete(  | 
                                                        |
| 715 | + array(  | 
                                                        |
| 716 | + array(  | 
                                                        |
| 717 | + 'QST_ID' => $phone_question_id,  | 
                                                        |
| 718 | +						'QSG_ID' => array('!=', $QSG_ID), | 
                                                        |
| 719 | + ),  | 
                                                        |
| 720 | + )  | 
                                                        |
| 721 | + );  | 
                                                        |
| 722 | + }  | 
                                                        |
| 723 | + /** @type EE_Question_Group $question_group */  | 
                                                        |
| 724 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID);  | 
                                                        |
| 725 | + $questions = $question_group->questions();  | 
                                                        |
| 726 | + // make sure system phone question is added to list of questions for this group  | 
                                                        |
| 727 | +		if (! isset($questions[ $phone_question_id ])) { | 
                                                        |
| 728 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id);  | 
                                                        |
| 729 | + }  | 
                                                        |
| 730 | +  | 
                                                        |
| 731 | +		foreach ($questions as $question_ID => $question) { | 
                                                        |
| 732 | + // first we always check for order.  | 
                                                        |
| 733 | +			if (! empty($this->_req_data['question_orders'][ $question_ID ])) { | 
                                                        |
| 734 | + // update question order  | 
                                                        |
| 735 | + $question_group->update_question_order(  | 
                                                        |
| 736 | + $question_ID,  | 
                                                        |
| 737 | + $this->_req_data['question_orders'][ $question_ID ]  | 
                                                        |
| 738 | + );  | 
                                                        |
| 739 | + }  | 
                                                        |
| 740 | +  | 
                                                        |
| 741 | + // then we always check if adding or removing.  | 
                                                        |
| 742 | +			if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { | 
                                                        |
| 743 | + $question_group->add_question($question_ID);  | 
                                                        |
| 744 | +			} else { | 
                                                        |
| 745 | + // not found, remove it (but only if not a system question for the personal group  | 
                                                        |
| 746 | + // with the exception of lname system question - we allow removal of it)  | 
                                                        |
| 747 | + if (in_array(  | 
                                                        |
| 748 | + $question->system_ID(),  | 
                                                        |
| 749 | + EEM_Question::instance()->required_system_questions_in_system_question_group(  | 
                                                        |
| 750 | + $question_group->system_group()  | 
                                                        |
| 751 | + )  | 
                                                        |
| 752 | +				)) { | 
                                                        |
| 753 | + continue;  | 
                                                        |
| 754 | +				} else { | 
                                                        |
| 755 | + $question_group->remove_question($question_ID);  | 
                                                        |
| 756 | + }  | 
                                                        |
| 757 | + }  | 
                                                        |
| 758 | + }  | 
                                                        |
| 759 | + // save new related questions  | 
                                                        |
| 760 | +		if (isset($this->_req_data['questions'])) { | 
                                                        |
| 761 | +			foreach ($this->_req_data['questions'] as $QST_ID) { | 
                                                        |
| 762 | + $question_group->add_question($QST_ID);  | 
                                                        |
| 763 | +				if (isset($this->_req_data['question_orders'][ $QST_ID ])) { | 
                                                        |
| 764 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]);  | 
                                                        |
| 765 | + }  | 
                                                        |
| 766 | + }  | 
                                                        |
| 767 | + }  | 
                                                        |
| 768 | +  | 
                                                        |
| 769 | +		if ($success !== false) { | 
                                                        |
| 770 | + $msg = $new_question_group  | 
                                                        |
| 771 | + ? sprintf(  | 
                                                        |
| 772 | +					esc_html__('The %s has been created', 'event_espresso'), | 
                                                        |
| 773 | + $this->_question_group_model->item_name()  | 
                                                        |
| 774 | + )  | 
                                                        |
| 775 | + : sprintf(  | 
                                                        |
| 776 | + esc_html__(  | 
                                                        |
| 777 | + 'The %s has been updated',  | 
                                                        |
| 778 | + 'event_espresso'  | 
                                                        |
| 779 | + ),  | 
                                                        |
| 780 | + $this->_question_group_model->item_name()  | 
                                                        |
| 781 | + );  | 
                                                        |
| 782 | + EE_Error::add_success($msg);  | 
                                                        |
| 783 | + }  | 
                                                        |
| 784 | + $this->_redirect_after_action(  | 
                                                        |
| 785 | + false,  | 
                                                        |
| 786 | + '',  | 
                                                        |
| 787 | + '',  | 
                                                        |
| 788 | +			array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), | 
                                                        |
| 789 | + true  | 
                                                        |
| 790 | + );  | 
                                                        |
| 791 | + }  | 
                                                        |
| 792 | +  | 
                                                        |
| 793 | +  | 
                                                        |
| 794 | + /**  | 
                                                        |
| 795 | + * duplicates a question and all its question options and redirects to the new question.  | 
                                                        |
| 796 | + *  | 
                                                        |
| 797 | + * @return void  | 
                                                        |
| 798 | + * @throws EE_Error  | 
                                                        |
| 799 | + * @throws InvalidArgumentException  | 
                                                        |
| 800 | + * @throws ReflectionException  | 
                                                        |
| 801 | + * @throws InvalidDataTypeException  | 
                                                        |
| 802 | + * @throws InvalidInterfaceException  | 
                                                        |
| 803 | + */  | 
                                                        |
| 804 | + public function _duplicate_question()  | 
                                                        |
| 805 | +	{ | 
                                                        |
| 806 | + $question_ID = (int) $this->_req_data['QST_ID'];  | 
                                                        |
| 807 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID);  | 
                                                        |
| 808 | +		if ($question instanceof EE_Question) { | 
                                                        |
| 809 | + $new_question = $question->duplicate();  | 
                                                        |
| 810 | +			if ($new_question instanceof EE_Question) { | 
                                                        |
| 811 | + $this->_redirect_after_action(  | 
                                                        |
| 812 | + true,  | 
                                                        |
| 813 | +					esc_html__('Question', 'event_espresso'), | 
                                                        |
| 814 | +					esc_html__('Duplicated', 'event_espresso'), | 
                                                        |
| 815 | +					array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), | 
                                                        |
| 816 | + true  | 
                                                        |
| 817 | + );  | 
                                                        |
| 818 | +			} else { | 
                                                        |
| 819 | + global $wpdb;  | 
                                                        |
| 820 | + EE_Error::add_error(  | 
                                                        |
| 821 | + sprintf(  | 
                                                        |
| 822 | + esc_html__(  | 
                                                        |
| 823 | + 'Could not duplicate question with ID %1$d because: %2$s',  | 
                                                        |
| 824 | + 'event_espresso'  | 
                                                        |
| 825 | + ),  | 
                                                        |
| 826 | + $question_ID,  | 
                                                        |
| 827 | + $wpdb->last_error  | 
                                                        |
| 828 | + ),  | 
                                                        |
| 829 | + __FILE__,  | 
                                                        |
| 830 | + __FUNCTION__,  | 
                                                        |
| 831 | + __LINE__  | 
                                                        |
| 832 | + );  | 
                                                        |
| 833 | +				$this->_redirect_after_action(false, '', '', array('action' => 'default'), false); | 
                                                        |
| 834 | + }  | 
                                                        |
| 835 | +		} else { | 
                                                        |
| 836 | + EE_Error::add_error(  | 
                                                        |
| 837 | + sprintf(  | 
                                                        |
| 838 | + esc_html__(  | 
                                                        |
| 839 | + 'Could not duplicate question with ID %d because it didn\'t exist!',  | 
                                                        |
| 840 | + 'event_espresso'  | 
                                                        |
| 841 | + ),  | 
                                                        |
| 842 | + $question_ID  | 
                                                        |
| 843 | + ),  | 
                                                        |
| 844 | + __FILE__,  | 
                                                        |
| 845 | + __FUNCTION__,  | 
                                                        |
| 846 | + __LINE__  | 
                                                        |
| 847 | + );  | 
                                                        |
| 848 | +			$this->_redirect_after_action(false, '', '', array('action' => 'default'), false); | 
                                                        |
| 849 | + }  | 
                                                        |
| 850 | + }  | 
                                                        |
| 851 | +  | 
                                                        |
| 852 | +  | 
                                                        |
| 853 | + /**  | 
                                                        |
| 854 | + * @param bool $trash  | 
                                                        |
| 855 | + * @throws EE_Error  | 
                                                        |
| 856 | + */  | 
                                                        |
| 857 | + protected function _trash_or_restore_question_groups($trash = true)  | 
                                                        |
| 858 | +	{ | 
                                                        |
| 859 | + $this->_trash_or_restore_items($this->_question_group_model, $trash);  | 
                                                        |
| 860 | + }  | 
                                                        |
| 861 | +  | 
                                                        |
| 862 | +  | 
                                                        |
| 863 | + /**  | 
                                                        |
| 864 | + *_trash_question  | 
                                                        |
| 865 | + *  | 
                                                        |
| 866 | + * @return void  | 
                                                        |
| 867 | + * @throws EE_Error  | 
                                                        |
| 868 | + */  | 
                                                        |
| 869 | + protected function _trash_question()  | 
                                                        |
| 870 | +	{ | 
                                                        |
| 871 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']);  | 
                                                        |
| 872 | +		$query_args = array('action' => 'default', 'status' => 'all'); | 
                                                        |
| 873 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args);  | 
                                                        |
| 874 | + }  | 
                                                        |
| 875 | +  | 
                                                        |
| 876 | +  | 
                                                        |
| 877 | + /**  | 
                                                        |
| 878 | + * @param bool $trash  | 
                                                        |
| 879 | + * @throws EE_Error  | 
                                                        |
| 880 | + */  | 
                                                        |
| 881 | + protected function _trash_or_restore_questions($trash = true)  | 
                                                        |
| 882 | +	{ | 
                                                        |
| 883 | + $this->_trash_or_restore_items($this->_question_model, $trash);  | 
                                                        |
| 884 | + }  | 
                                                        |
| 885 | +  | 
                                                        |
| 886 | +  | 
                                                        |
| 887 | + /**  | 
                                                        |
| 888 | + * Internally used to delete or restore items, using the request data. Meant to be  | 
                                                        |
| 889 | + * flexible between question or question groups  | 
                                                        |
| 890 | + *  | 
                                                        |
| 891 | + * @param EEM_Soft_Delete_Base $model  | 
                                                        |
| 892 | + * @param boolean $trash whether to trash or restore  | 
                                                        |
| 893 | + * @throws EE_Error  | 
                                                        |
| 894 | + */  | 
                                                        |
| 895 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true)  | 
                                                        |
| 896 | +	{ | 
                                                        |
| 897 | +  | 
                                                        |
| 898 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 899 | +  | 
                                                        |
| 900 | + $success = 1;  | 
                                                        |
| 901 | + // Checkboxes  | 
                                                        |
| 902 | + // echo "trash $trash";  | 
                                                        |
| 903 | + // var_dump($this->_req_data['checkbox']);die;  | 
                                                        |
| 904 | +		if (isset($this->_req_data['checkbox'])) { | 
                                                        |
| 905 | +			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 906 | + // if array has more than one element than success message should be plural  | 
                                                        |
| 907 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 908 | + // cycle thru bulk action checkboxes  | 
                                                        |
| 909 | +				while (list($ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 910 | +					if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { | 
                                                        |
| 911 | + $success = 0;  | 
                                                        |
| 912 | + }  | 
                                                        |
| 913 | + }  | 
                                                        |
| 914 | +			} else { | 
                                                        |
| 915 | + // grab single id and delete  | 
                                                        |
| 916 | + $ID = absint($this->_req_data['checkbox']);  | 
                                                        |
| 917 | +				if (! $model->delete_or_restore_by_ID($trash, $ID)) { | 
                                                        |
| 918 | + $success = 0;  | 
                                                        |
| 919 | + }  | 
                                                        |
| 920 | + }  | 
                                                        |
| 921 | +		} else { | 
                                                        |
| 922 | + // delete via trash link  | 
                                                        |
| 923 | + // grab single id and delete  | 
                                                        |
| 924 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]);  | 
                                                        |
| 925 | +			if (! $model->delete_or_restore_by_ID($trash, $ID)) { | 
                                                        |
| 926 | + $success = 0;  | 
                                                        |
| 927 | + }  | 
                                                        |
| 928 | + }  | 
                                                        |
| 929 | +  | 
                                                        |
| 930 | +  | 
                                                        |
| 931 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) );  | 
                                                        |
| 932 | + // echo "action :$action";  | 
                                                        |
| 933 | + // $action = 'questions' ? 'default' : $action;  | 
                                                        |
| 934 | +		if ($trash) { | 
                                                        |
| 935 | + $action_desc = 'trashed';  | 
                                                        |
| 936 | + $status = 'trash';  | 
                                                        |
| 937 | +		} else { | 
                                                        |
| 938 | + $action_desc = 'restored';  | 
                                                        |
| 939 | + $status = 'all';  | 
                                                        |
| 940 | + }  | 
                                                        |
| 941 | + $this->_redirect_after_action(  | 
                                                        |
| 942 | + $success,  | 
                                                        |
| 943 | + $model->item_name($success),  | 
                                                        |
| 944 | + $action_desc,  | 
                                                        |
| 945 | +			array('action' => $action, 'status' => $status) | 
                                                        |
| 946 | + );  | 
                                                        |
| 947 | + }  | 
                                                        |
| 948 | +  | 
                                                        |
| 949 | +  | 
                                                        |
| 950 | + /**  | 
                                                        |
| 951 | + * @param $per_page  | 
                                                        |
| 952 | + * @param int $current_page  | 
                                                        |
| 953 | + * @param bool|false $count  | 
                                                        |
| 954 | + * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 955 | + * @throws EE_Error  | 
                                                        |
| 956 | + * @throws InvalidArgumentException  | 
                                                        |
| 957 | + * @throws InvalidDataTypeException  | 
                                                        |
| 958 | + * @throws InvalidInterfaceException  | 
                                                        |
| 959 | + */  | 
                                                        |
| 960 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 961 | +	{ | 
                                                        |
| 962 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);  | 
                                                        |
| 963 | +  | 
                                                        |
| 964 | +		if ($count) { | 
                                                        |
| 965 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items  | 
                                                        |
| 966 | + $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 967 | + $results = $this->_question_model->count_deleted($where);  | 
                                                        |
| 968 | +		} else { | 
                                                        |
| 969 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items  | 
                                                        |
| 970 | + $results = $this->_question_model->get_all_deleted($query_params);  | 
                                                        |
| 971 | + }  | 
                                                        |
| 972 | + return $results;  | 
                                                        |
| 973 | + }  | 
                                                        |
| 974 | +  | 
                                                        |
| 975 | +  | 
                                                        |
| 976 | + /**  | 
                                                        |
| 977 | + * @param $per_page  | 
                                                        |
| 978 | + * @param int $current_page  | 
                                                        |
| 979 | + * @param bool|false $count  | 
                                                        |
| 980 | + * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 981 | + * @throws EE_Error  | 
                                                        |
| 982 | + * @throws InvalidArgumentException  | 
                                                        |
| 983 | + * @throws InvalidDataTypeException  | 
                                                        |
| 984 | + * @throws InvalidInterfaceException  | 
                                                        |
| 985 | + */  | 
                                                        |
| 986 | + public function get_question_groups($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 987 | +	{ | 
                                                        |
| 988 | + $questionGroupModel = EEM_Question_Group::instance();  | 
                                                        |
| 989 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);  | 
                                                        |
| 990 | +		if ($count) { | 
                                                        |
| 991 | + $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 992 | + $results = $questionGroupModel->count($where);  | 
                                                        |
| 993 | +		} else { | 
                                                        |
| 994 | + $results = $questionGroupModel->get_all($query_params);  | 
                                                        |
| 995 | + }  | 
                                                        |
| 996 | + return $results;  | 
                                                        |
| 997 | + }  | 
                                                        |
| 998 | +  | 
                                                        |
| 999 | +  | 
                                                        |
| 1000 | + /**  | 
                                                        |
| 1001 | + * @param $per_page  | 
                                                        |
| 1002 | + * @param int $current_page  | 
                                                        |
| 1003 | + * @param bool $count  | 
                                                        |
| 1004 | + * @return EE_Soft_Delete_Base_Class[]|int  | 
                                                        |
| 1005 | + * @throws EE_Error  | 
                                                        |
| 1006 | + * @throws InvalidArgumentException  | 
                                                        |
| 1007 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1008 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1009 | + */  | 
                                                        |
| 1010 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false)  | 
                                                        |
| 1011 | +	{ | 
                                                        |
| 1012 | + $questionGroupModel = EEM_Question_Group::instance();  | 
                                                        |
| 1013 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);  | 
                                                        |
| 1014 | +		if ($count) { | 
                                                        |
| 1015 | + $where = isset($query_params[0]) ? array($query_params[0]) : array();  | 
                                                        |
| 1016 | + $query_params['limit'] = null;  | 
                                                        |
| 1017 | + $results = $questionGroupModel->count_deleted($where);  | 
                                                        |
| 1018 | +		} else { | 
                                                        |
| 1019 | + $results = $questionGroupModel->get_all_deleted($query_params);  | 
                                                        |
| 1020 | + }  | 
                                                        |
| 1021 | + return $results;  | 
                                                        |
| 1022 | + }  | 
                                                        |
| 1023 | +  | 
                                                        |
| 1024 | +  | 
                                                        |
| 1025 | + /**  | 
                                                        |
| 1026 | + * method for performing updates to question order  | 
                                                        |
| 1027 | + *  | 
                                                        |
| 1028 | + * @return void results array  | 
                                                        |
| 1029 | + * @throws EE_Error  | 
                                                        |
| 1030 | + * @throws InvalidArgumentException  | 
                                                        |
| 1031 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1032 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1033 | + */  | 
                                                        |
| 1034 | + public function update_question_group_order()  | 
                                                        |
| 1035 | +	{ | 
                                                        |
| 1036 | +  | 
                                                        |
| 1037 | +		$success = esc_html__('Question group order was updated successfully.', 'event_espresso'); | 
                                                        |
| 1038 | +  | 
                                                        |
| 1039 | + // grab our row IDs  | 
                                                        |
| 1040 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids'])  | 
                                                        |
| 1041 | +			? explode(',', rtrim($this->_req_data['row_ids'], ',')) | 
                                                        |
| 1042 | + : array();  | 
                                                        |
| 1043 | +  | 
                                                        |
| 1044 | + $perpage = ! empty($this->_req_data['perpage'])  | 
                                                        |
| 1045 | + ? (int) $this->_req_data['perpage']  | 
                                                        |
| 1046 | + : null;  | 
                                                        |
| 1047 | + $curpage = ! empty($this->_req_data['curpage'])  | 
                                                        |
| 1048 | + ? (int) $this->_req_data['curpage']  | 
                                                        |
| 1049 | + : null;  | 
                                                        |
| 1050 | +  | 
                                                        |
| 1051 | +		if (! empty($row_ids)) { | 
                                                        |
| 1052 | + // figure out where we start the row_id count at for the current page.  | 
                                                        |
| 1053 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage;  | 
                                                        |
| 1054 | +  | 
                                                        |
| 1055 | + $row_count = count($row_ids);  | 
                                                        |
| 1056 | +			for ($i = 0; $i < $row_count; $i++) { | 
                                                        |
| 1057 | + // Update the questions when re-ordering  | 
                                                        |
| 1058 | + $updated = EEM_Question_Group::instance()->update(  | 
                                                        |
| 1059 | +					array('QSG_order' => $qsgcount), | 
                                                        |
| 1060 | +					array(array('QSG_ID' => $row_ids[ $i ])) | 
                                                        |
| 1061 | + );  | 
                                                        |
| 1062 | +				if ($updated === false) { | 
                                                        |
| 1063 | + $success = false;  | 
                                                        |
| 1064 | + }  | 
                                                        |
| 1065 | + $qsgcount++;  | 
                                                        |
| 1066 | + }  | 
                                                        |
| 1067 | +		} else { | 
                                                        |
| 1068 | + $success = false;  | 
                                                        |
| 1069 | + }  | 
                                                        |
| 1070 | +  | 
                                                        |
| 1071 | + $errors = ! $success  | 
                                                        |
| 1072 | +			? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') | 
                                                        |
| 1073 | + : false;  | 
                                                        |
| 1074 | +  | 
                                                        |
| 1075 | +		echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); | 
                                                        |
| 1076 | + die();  | 
                                                        |
| 1077 | + }  | 
                                                        |
| 1078 | +  | 
                                                        |
| 1079 | +  | 
                                                        |
| 1080 | +  | 
                                                        |
| 1081 | + /*************************************** REGISTRATION SETTINGS ***************************************/  | 
                                                        |
| 1082 | +  | 
                                                        |
| 1083 | +  | 
                                                        |
| 1084 | + /**  | 
                                                        |
| 1085 | + * @throws DomainException  | 
                                                        |
| 1086 | + * @throws EE_Error  | 
                                                        |
| 1087 | + * @throws InvalidArgumentException  | 
                                                        |
| 1088 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1089 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1090 | + */  | 
                                                        |
| 1091 | + protected function _reg_form_settings()  | 
                                                        |
| 1092 | +	{ | 
                                                        |
| 1093 | + $this->_template_args['values'] = $this->_yes_no_values;  | 
                                                        |
| 1094 | + add_action(  | 
                                                        |
| 1095 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',  | 
                                                        |
| 1096 | + array($this, 'email_validation_settings_form'),  | 
                                                        |
| 1097 | + 2  | 
                                                        |
| 1098 | + );  | 
                                                        |
| 1099 | + $this->_template_args = (array) apply_filters(  | 
                                                        |
| 1100 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args',  | 
                                                        |
| 1101 | + $this->_template_args  | 
                                                        |
| 1102 | + );  | 
                                                        |
| 1103 | +		$this->_set_add_edit_form_tags('update_reg_form_settings'); | 
                                                        |
| 1104 | + $this->_set_publish_post_box_vars(null, false, false, null, false);  | 
                                                        |
| 1105 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 1106 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php',  | 
                                                        |
| 1107 | + $this->_template_args,  | 
                                                        |
| 1108 | + true  | 
                                                        |
| 1109 | + );  | 
                                                        |
| 1110 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1111 | + }  | 
                                                        |
| 1112 | +  | 
                                                        |
| 1113 | +  | 
                                                        |
| 1114 | + /**  | 
                                                        |
| 1115 | + * @return void  | 
                                                        |
| 1116 | + * @throws EE_Error  | 
                                                        |
| 1117 | + * @throws InvalidArgumentException  | 
                                                        |
| 1118 | + * @throws ReflectionException  | 
                                                        |
| 1119 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1120 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1121 | + */  | 
                                                        |
| 1122 | + protected function _update_reg_form_settings()  | 
                                                        |
| 1123 | +	{ | 
                                                        |
| 1124 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form(  | 
                                                        |
| 1125 | + EE_Registry::instance()->CFG->registration  | 
                                                        |
| 1126 | + );  | 
                                                        |
| 1127 | + EE_Registry::instance()->CFG->registration = apply_filters(  | 
                                                        |
| 1128 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',  | 
                                                        |
| 1129 | + EE_Registry::instance()->CFG->registration  | 
                                                        |
| 1130 | + );  | 
                                                        |
| 1131 | + $success = $this->_update_espresso_configuration(  | 
                                                        |
| 1132 | +			esc_html__('Registration Form Options', 'event_espresso'), | 
                                                        |
| 1133 | + EE_Registry::instance()->CFG,  | 
                                                        |
| 1134 | + __FILE__,  | 
                                                        |
| 1135 | + __FUNCTION__,  | 
                                                        |
| 1136 | + __LINE__  | 
                                                        |
| 1137 | + );  | 
                                                        |
| 1138 | + $this->_redirect_after_action(  | 
                                                        |
| 1139 | + $success,  | 
                                                        |
| 1140 | +			esc_html__('Registration Form Options', 'event_espresso'), | 
                                                        |
| 1141 | + 'updated',  | 
                                                        |
| 1142 | +			array('action' => 'view_reg_form_settings') | 
                                                        |
| 1143 | + );  | 
                                                        |
| 1144 | + }  | 
                                                        |
| 1145 | +  | 
                                                        |
| 1146 | +  | 
                                                        |
| 1147 | + /**  | 
                                                        |
| 1148 | + * @return void  | 
                                                        |
| 1149 | + * @throws EE_Error  | 
                                                        |
| 1150 | + * @throws InvalidArgumentException  | 
                                                        |
| 1151 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1152 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1153 | + */  | 
                                                        |
| 1154 | + public function email_validation_settings_form()  | 
                                                        |
| 1155 | +	{ | 
                                                        |
| 1156 | + echo $this->_email_validation_settings_form()->get_html();  | 
                                                        |
| 1157 | + }  | 
                                                        |
| 1158 | +  | 
                                                        |
| 1159 | +  | 
                                                        |
| 1160 | + /**  | 
                                                        |
| 1161 | + * _email_validation_settings_form  | 
                                                        |
| 1162 | + *  | 
                                                        |
| 1163 | + * @access protected  | 
                                                        |
| 1164 | + * @return EE_Form_Section_Proper  | 
                                                        |
| 1165 | + * @throws \EE_Error  | 
                                                        |
| 1166 | + */  | 
                                                        |
| 1167 | + protected function _email_validation_settings_form()  | 
                                                        |
| 1168 | +	{ | 
                                                        |
| 1169 | + return new EE_Form_Section_Proper(  | 
                                                        |
| 1170 | + array(  | 
                                                        |
| 1171 | + 'name' => 'email_validation_settings',  | 
                                                        |
| 1172 | + 'html_id' => 'email_validation_settings',  | 
                                                        |
| 1173 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 1174 | + 'subsections' => apply_filters(  | 
                                                        |
| 1175 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections',  | 
                                                        |
| 1176 | + array(  | 
                                                        |
| 1177 | + 'email_validation_hdr' => new EE_Form_Section_HTML(  | 
                                                        |
| 1178 | +							EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) | 
                                                        |
| 1179 | + ),  | 
                                                        |
| 1180 | + 'email_validation_level' => new EE_Select_Input(  | 
                                                        |
| 1181 | + array(  | 
                                                        |
| 1182 | +								'basic'      => esc_html__('Basic', 'event_espresso'), | 
                                                        |
| 1183 | +								'wp_default' => esc_html__('WordPress Default', 'event_espresso'), | 
                                                        |
| 1184 | +								'i18n'       => esc_html__('International', 'event_espresso'), | 
                                                        |
| 1185 | +								'i18n_dns'   => esc_html__('International + DNS Check', 'event_espresso'), | 
                                                        |
| 1186 | + ),  | 
                                                        |
| 1187 | + array(  | 
                                                        |
| 1188 | +								'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') | 
                                                        |
| 1189 | +													 . EEH_Template::get_help_tab_link('email_validation_info'), | 
                                                        |
| 1190 | + 'html_help_text' => esc_html__(  | 
                                                        |
| 1191 | + 'These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.',  | 
                                                        |
| 1192 | + 'event_espresso'  | 
                                                        |
| 1193 | + ),  | 
                                                        |
| 1194 | + 'default' => isset(  | 
                                                        |
| 1195 | + EE_Registry::instance()->CFG->registration->email_validation_level  | 
                                                        |
| 1196 | + )  | 
                                                        |
| 1197 | + ? EE_Registry::instance()->CFG->registration->email_validation_level  | 
                                                        |
| 1198 | + : 'wp_default',  | 
                                                        |
| 1199 | + 'required' => false,  | 
                                                        |
| 1200 | + )  | 
                                                        |
| 1201 | + ),  | 
                                                        |
| 1202 | + )  | 
                                                        |
| 1203 | + ),  | 
                                                        |
| 1204 | + )  | 
                                                        |
| 1205 | + );  | 
                                                        |
| 1206 | + }  | 
                                                        |
| 1207 | +  | 
                                                        |
| 1208 | +  | 
                                                        |
| 1209 | + /**  | 
                                                        |
| 1210 | + * @param EE_Registration_Config $EE_Registration_Config  | 
                                                        |
| 1211 | + * @return EE_Registration_Config  | 
                                                        |
| 1212 | + * @throws EE_Error  | 
                                                        |
| 1213 | + * @throws InvalidArgumentException  | 
                                                        |
| 1214 | + * @throws ReflectionException  | 
                                                        |
| 1215 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1216 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1217 | + */  | 
                                                        |
| 1218 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config)  | 
                                                        |
| 1219 | +	{ | 
                                                        |
| 1220 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level;  | 
                                                        |
| 1221 | +		try { | 
                                                        |
| 1222 | + $email_validation_settings_form = $this->_email_validation_settings_form();  | 
                                                        |
| 1223 | + // if not displaying a form, then check for form submission  | 
                                                        |
| 1224 | +			if ($email_validation_settings_form->was_submitted()) { | 
                                                        |
| 1225 | + // capture form data  | 
                                                        |
| 1226 | + $email_validation_settings_form->receive_form_submission();  | 
                                                        |
| 1227 | + // validate form data  | 
                                                        |
| 1228 | +				if ($email_validation_settings_form->is_valid()) { | 
                                                        |
| 1229 | + // grab validated data from form  | 
                                                        |
| 1230 | + $valid_data = $email_validation_settings_form->valid_data();  | 
                                                        |
| 1231 | +					if (isset($valid_data['email_validation_level'])) { | 
                                                        |
| 1232 | + $email_validation_level = $valid_data['email_validation_level'];  | 
                                                        |
| 1233 | + // now if they want to use international email addresses  | 
                                                        |
| 1234 | +						if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { | 
                                                        |
| 1235 | + // in case we need to reset their email validation level,  | 
                                                        |
| 1236 | + // make sure that the previous value wasn't already set to one of the i18n options.  | 
                                                        |
| 1237 | +							if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { | 
                                                        |
| 1238 | + // if so, then reset it back to "basic" since that is the only other option that,  | 
                                                        |
| 1239 | + // despite offering poor validation, supports i18n email addresses  | 
                                                        |
| 1240 | + $prev_email_validation_level = 'basic';  | 
                                                        |
| 1241 | + }  | 
                                                        |
| 1242 | + // confirm our i18n email validation will work on the server  | 
                                                        |
| 1243 | +							if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { | 
                                                        |
| 1244 | + // or reset email validation level to previous value  | 
                                                        |
| 1245 | + $email_validation_level = $prev_email_validation_level;  | 
                                                        |
| 1246 | + }  | 
                                                        |
| 1247 | + }  | 
                                                        |
| 1248 | + $EE_Registration_Config->email_validation_level = $email_validation_level;  | 
                                                        |
| 1249 | +					} else { | 
                                                        |
| 1250 | + EE_Error::add_error(  | 
                                                        |
| 1251 | + esc_html__(  | 
                                                        |
| 1252 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.',  | 
                                                        |
| 1253 | + 'event_espresso'  | 
                                                        |
| 1254 | + ),  | 
                                                        |
| 1255 | + __FILE__,  | 
                                                        |
| 1256 | + __FUNCTION__,  | 
                                                        |
| 1257 | + __LINE__  | 
                                                        |
| 1258 | + );  | 
                                                        |
| 1259 | + }  | 
                                                        |
| 1260 | +				} else { | 
                                                        |
| 1261 | +					if ($email_validation_settings_form->submission_error_message() !== '') { | 
                                                        |
| 1262 | + EE_Error::add_error(  | 
                                                        |
| 1263 | + $email_validation_settings_form->submission_error_message(),  | 
                                                        |
| 1264 | + __FILE__,  | 
                                                        |
| 1265 | + __FUNCTION__,  | 
                                                        |
| 1266 | + __LINE__  | 
                                                        |
| 1267 | + );  | 
                                                        |
| 1268 | + }  | 
                                                        |
| 1269 | + }  | 
                                                        |
| 1270 | + }  | 
                                                        |
| 1271 | +		} catch (EE_Error $e) { | 
                                                        |
| 1272 | + $e->get_error();  | 
                                                        |
| 1273 | + }  | 
                                                        |
| 1274 | + return $EE_Registration_Config;  | 
                                                        |
| 1275 | + }  | 
                                                        |
| 1276 | +  | 
                                                        |
| 1277 | +  | 
                                                        |
| 1278 | + /**  | 
                                                        |
| 1279 | + * confirms that the server's PHP version has the PCRE module enabled,  | 
                                                        |
| 1280 | + * and that the PCRE version works with our i18n email validation  | 
                                                        |
| 1281 | + *  | 
                                                        |
| 1282 | + * @param EE_Registration_Config $EE_Registration_Config  | 
                                                        |
| 1283 | + * @param string $email_validation_level  | 
                                                        |
| 1284 | + * @return bool  | 
                                                        |
| 1285 | + */  | 
                                                        |
| 1286 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level)  | 
                                                        |
| 1287 | +	{ | 
                                                        |
| 1288 | + // first check that PCRE is enabled  | 
                                                        |
| 1289 | +		if (! defined('PREG_BAD_UTF8_ERROR')) { | 
                                                        |
| 1290 | + EE_Error::add_error(  | 
                                                        |
| 1291 | + sprintf(  | 
                                                        |
| 1292 | + esc_html__(  | 
                                                        |
| 1293 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.',  | 
                                                        |
| 1294 | + 'event_espresso'  | 
                                                        |
| 1295 | + ),  | 
                                                        |
| 1296 | + '<br />'  | 
                                                        |
| 1297 | + ),  | 
                                                        |
| 1298 | + __FILE__,  | 
                                                        |
| 1299 | + __FUNCTION__,  | 
                                                        |
| 1300 | + __LINE__  | 
                                                        |
| 1301 | + );  | 
                                                        |
| 1302 | + return false;  | 
                                                        |
| 1303 | +		} else { | 
                                                        |
| 1304 | + // PCRE support is enabled, but let's still  | 
                                                        |
| 1305 | + // perform a test to see if the server will support it.  | 
                                                        |
| 1306 | + // but first, save the updated validation level to the config,  | 
                                                        |
| 1307 | + // so that the validation strategy picks it up.  | 
                                                        |
| 1308 | + // this will get bumped back down if it doesn't work  | 
                                                        |
| 1309 | + $EE_Registration_Config->email_validation_level = $email_validation_level;  | 
                                                        |
| 1310 | +			try { | 
                                                        |
| 1311 | + $email_validator = new EE_Email_Validation_Strategy();  | 
                                                        |
| 1312 | + $i18n_email_address = apply_filters(  | 
                                                        |
| 1313 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address',  | 
                                                        |
| 1314 | + 'jägerjü[email protected]'  | 
                                                        |
| 1315 | + );  | 
                                                        |
| 1316 | + $email_validator->validate($i18n_email_address);  | 
                                                        |
| 1317 | +			} catch (Exception $e) { | 
                                                        |
| 1318 | + EE_Error::add_error(  | 
                                                        |
| 1319 | + sprintf(  | 
                                                        |
| 1320 | + esc_html__(  | 
                                                        |
| 1321 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s',  | 
                                                        |
| 1322 | + 'event_espresso'  | 
                                                        |
| 1323 | + ),  | 
                                                        |
| 1324 | + '<br />',  | 
                                                        |
| 1325 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>'  | 
                                                        |
| 1326 | + ),  | 
                                                        |
| 1327 | + __FILE__,  | 
                                                        |
| 1328 | + __FUNCTION__,  | 
                                                        |
| 1329 | + __LINE__  | 
                                                        |
| 1330 | + );  | 
                                                        |
| 1331 | + return false;  | 
                                                        |
| 1332 | + }  | 
                                                        |
| 1333 | + }  | 
                                                        |
| 1334 | + return true;  | 
                                                        |
| 1335 | + }  | 
                                                        |
| 1336 | 1336 | }  |