Completed
Branch BUG-10477-answer-cache-id (4bdd94)
by
unknown
36:00 queued 24:53
created
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 2 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[$matches[1]] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[$matches[1]] = $filepath;
18 18
 }
19 19
 //give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //			echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif ( ! $version_string) {
68
-            //			echo "no version string provided: $version_string";
69
-            //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //			echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//			echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif ( ! $version_string) {
68
+			//			echo "no version string provided: $version_string";
69
+			//no version string provided... this must be pre 4.3
70
+			return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//			echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        $table_name = 'esp_currency_payment_method';
153
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		$table_name = 'esp_currency_payment_method';
153
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
154 154
 				CUR_code varchar(6) NOT NULL,
155 155
 				PMD_ID int(11) NOT NULL,
156 156
 				PRIMARY KEY  (CPM_ID),
157 157
 				KEY PMD_ID (PMD_ID)";
158
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
-        $table_name = 'esp_datetime';
160
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
158
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
+		$table_name = 'esp_datetime';
160
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
161 161
 				EVT_ID bigint(20) unsigned NOT NULL,
162 162
 				DTT_name varchar(255) NOT NULL DEFAULT '',
163 163
 				DTT_description text NOT NULL,
@@ -174,25 +174,25 @@  discard block
 block discarded – undo
174 174
 				KEY DTT_EVT_start (DTT_EVT_start),
175 175
 				KEY EVT_ID (EVT_ID),
176 176
 				KEY DTT_is_primary (DTT_is_primary)";
177
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
-        $table_name = "esp_datetime_ticket";
179
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
177
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
+		$table_name = "esp_datetime_ticket";
179
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
180 180
 				DTT_ID int(10) unsigned NOT NULL,
181 181
 				TKT_ID int(10) unsigned NOT NULL,
182 182
 				PRIMARY KEY  (DTK_ID),
183 183
 				KEY DTT_ID (DTT_ID),
184 184
 				KEY TKT_ID (TKT_ID)";
185
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
-        $table_name = 'esp_event_message_template';
187
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
185
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
+		$table_name = 'esp_event_message_template';
187
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
188 188
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
189 189
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
190 190
 				PRIMARY KEY  (EMT_ID),
191 191
 				KEY EVT_ID (EVT_ID),
192 192
 				KEY GRP_ID (GRP_ID)";
193
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
-        $table_name = 'esp_event_meta';
195
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
193
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_event_meta';
195
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
196 196
 				EVT_ID bigint(20) unsigned NOT NULL,
197 197
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
198 198
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -207,34 +207,34 @@  discard block
 block discarded – undo
207 207
 				EVT_donations tinyint(1) NULL,
208 208
 				PRIMARY KEY  (EVTM_ID),
209 209
 				KEY EVT_ID (EVT_ID)";
210
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
-        $table_name = 'esp_event_question_group';
212
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
210
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
+		$table_name = 'esp_event_question_group';
212
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
213 213
 				EVT_ID bigint(20) unsigned NOT NULL,
214 214
 				QSG_ID int(10) unsigned NOT NULL,
215 215
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
216 216
 				PRIMARY KEY  (EQG_ID),
217 217
 				KEY EVT_ID (EVT_ID),
218 218
 				KEY QSG_ID (QSG_ID)";
219
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
-        $table_name = 'esp_event_venue';
221
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
219
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
+		$table_name = 'esp_event_venue';
221
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
222 222
 				EVT_ID bigint(20) unsigned NOT NULL,
223 223
 				VNU_ID bigint(20) unsigned NOT NULL,
224 224
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
225 225
 				PRIMARY KEY  (EVV_ID)";
226
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
-        $table_name = 'esp_extra_meta';
228
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
226
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
+		$table_name = 'esp_extra_meta';
228
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
229 229
 				OBJ_ID int(11) DEFAULT NULL,
230 230
 				EXM_type varchar(45) DEFAULT NULL,
231 231
 				EXM_key varchar(45) DEFAULT NULL,
232 232
 				EXM_value text,
233 233
 				PRIMARY KEY  (EXM_ID),
234 234
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
235
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
-        $table_name = 'esp_extra_join';
237
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
235
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
+		$table_name = 'esp_extra_join';
237
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
238 238
 				EXJ_first_model_id varchar(6) NOT NULL,
239 239
 				EXJ_first_model_name varchar(20) NOT NULL,
240 240
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 				PRIMARY KEY  (EXJ_ID),
243 243
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
244 244
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
245
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
-        $table_name = 'esp_line_item';
247
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
245
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
+		$table_name = 'esp_line_item';
247
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
248 248
 				LIN_code varchar(245) NOT NULL DEFAULT '',
249 249
 				TXN_ID int(11) DEFAULT NULL,
250 250
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
 				PRIMARY KEY  (LIN_ID),
264 264
 				KEY LIN_code (LIN_code(191)),
265 265
 				KEY TXN_ID (TXN_ID)";
266
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
267
-        $table_name = 'esp_log';
268
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
266
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
267
+		$table_name = 'esp_log';
268
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
269 269
 				LOG_time datetime DEFAULT NULL,
270 270
 				OBJ_ID varchar(45) DEFAULT NULL,
271 271
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
 				KEY LOG_time (LOG_time),
277 277
 				KEY OBJ (OBJ_type,OBJ_ID),
278 278
 				KEY LOG_type (LOG_type)";
279
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
-        $table_name = 'esp_message';
281
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
279
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
+		$table_name = 'esp_message';
281
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
285 285
 				GRP_ID int(10) unsigned NULL,
286 286
 				MSG_token varchar(255) NULL,
287 287
 				TXN_ID int(10) unsigned NULL,
@@ -313,18 +313,18 @@  discard block
 block discarded – undo
313 313
 				KEY STS_ID (STS_ID),
314 314
 				KEY MSG_created (MSG_created),
315 315
 				KEY MSG_modified (MSG_modified)";
316
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
-        $table_name = 'esp_message_template';
318
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
316
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
+		$table_name = 'esp_message_template';
318
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
319 319
 				GRP_ID int(10) unsigned NOT NULL,
320 320
 				MTP_context varchar(50) NOT NULL,
321 321
 				MTP_template_field varchar(30) NOT NULL,
322 322
 				MTP_content text NOT NULL,
323 323
 				PRIMARY KEY  (MTP_ID),
324 324
 				KEY GRP_ID (GRP_ID)";
325
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
-        $table_name = 'esp_message_template_group';
327
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
325
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
+		$table_name = 'esp_message_template_group';
327
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
328 328
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
329 329
 				MTP_name varchar(245) NOT NULL DEFAULT '',
330 330
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
337 337
 				PRIMARY KEY  (GRP_ID),
338 338
 				KEY MTP_user_id (MTP_user_id)";
339
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
-        $table_name = 'esp_payment';
341
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
339
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
+		$table_name = 'esp_payment';
341
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
342 342
 				TXN_ID int(10) unsigned DEFAULT NULL,
343 343
 				STS_ID varchar(3) DEFAULT NULL,
344 344
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
 				PRIMARY KEY  (PAY_ID),
356 356
 				KEY PAY_timestamp (PAY_timestamp),
357 357
 				KEY TXN_ID (TXN_ID)";
358
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
359
-        $table_name = 'esp_payment_method';
360
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
358
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
359
+		$table_name = 'esp_payment_method';
360
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
361 361
 				PMD_type varchar(124) DEFAULT NULL,
362 362
 				PMD_name varchar(255) DEFAULT NULL,
363 363
 				PMD_desc text,
@@ -373,24 +373,24 @@  discard block
 block discarded – undo
373 373
 				PRIMARY KEY  (PMD_ID),
374 374
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
375 375
 				KEY PMD_type (PMD_type)";
376
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
-        $table_name = "esp_ticket_price";
378
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
376
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
+		$table_name = "esp_ticket_price";
378
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
379 379
 				TKT_ID int(10) unsigned NOT NULL,
380 380
 				PRC_ID int(10) unsigned NOT NULL,
381 381
 				PRIMARY KEY  (TKP_ID),
382 382
 				KEY TKT_ID (TKT_ID),
383 383
 				KEY PRC_ID (PRC_ID)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
-        $table_name = "esp_ticket_template";
386
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
+		$table_name = "esp_ticket_template";
386
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TTM_name varchar(45) NOT NULL,
388 388
 				TTM_description text,
389 389
 				TTM_file varchar(45),
390 390
 				PRIMARY KEY  (TTM_ID)";
391
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
-        $table_name = 'esp_question';
393
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
391
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
+		$table_name = 'esp_question';
393
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
394 394
 				QST_display_text text NOT NULL,
395 395
 				QST_admin_label varchar(255) NOT NULL,
396 396
 				QST_system varchar(25) DEFAULT NULL,
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
405 405
 				PRIMARY KEY  (QST_ID),
406 406
 				KEY QST_order (QST_order)';
407
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
-        $table_name = 'esp_question_group_question';
409
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
407
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
+		$table_name = 'esp_question_group_question';
409
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
410 410
 				QSG_ID int(10) unsigned NOT NULL,
411 411
 				QST_ID int(10) unsigned NOT NULL,
412 412
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QGQ_ID),
414 414
 				KEY QST_ID (QST_ID),
415 415
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
416
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
-        $table_name = 'esp_question_option';
418
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
416
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
+		$table_name = 'esp_question_option';
418
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
419 419
 				QSO_value varchar(255) NOT NULL,
420 420
 				QSO_desc text NOT NULL,
421 421
 				QST_ID int(10) unsigned NOT NULL,
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
 				PRIMARY KEY  (QSO_ID),
426 426
 				KEY QST_ID (QST_ID),
427 427
 				KEY QSO_order (QSO_order)";
428
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
-        $table_name = 'esp_registration';
430
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
428
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
+		$table_name = 'esp_registration';
430
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
431 431
 				EVT_ID bigint(20) unsigned NOT NULL,
432 432
 				ATT_ID bigint(20) unsigned NOT NULL,
433 433
 				TXN_ID int(10) unsigned NOT NULL,
@@ -451,18 +451,18 @@  discard block
 block discarded – undo
451 451
 				KEY TKT_ID (TKT_ID),
452 452
 				KEY EVT_ID (EVT_ID),
453 453
 				KEY STS_ID (STS_ID)";
454
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
455
-        $table_name = 'esp_registration_payment';
456
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
454
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
455
+		$table_name = 'esp_registration_payment';
456
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
457 457
 					  REG_ID int(10) unsigned NOT NULL,
458 458
 					  PAY_ID int(10) unsigned NULL,
459 459
 					  RPY_amount decimal(10,3) NOT NULL DEFAULT '0.00',
460 460
 					  PRIMARY KEY  (RPY_ID),
461 461
 					  KEY REG_ID (REG_ID),
462 462
 					  KEY PAY_ID (PAY_ID)";
463
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
464
-        $table_name = 'esp_state';
465
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
463
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
464
+		$table_name = 'esp_state';
465
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
466 466
 				CNT_ISO varchar(2) NOT NULL,
467 467
 				STA_abbrev varchar(24) NOT NULL,
468 468
 				STA_name varchar(100) NOT NULL,
@@ -470,9 +470,9 @@  discard block
 block discarded – undo
470 470
 				PRIMARY KEY  (STA_ID),
471 471
 				KEY STA_abbrev (STA_abbrev),
472 472
 				KEY CNT_ISO (CNT_ISO)";
473
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
-        $table_name = 'esp_status';
475
-        $sql = "STS_ID varchar(3) NOT NULL,
473
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
+		$table_name = 'esp_status';
475
+		$sql = "STS_ID varchar(3) NOT NULL,
476 476
 				STS_code varchar(45) NOT NULL,
477 477
 				STS_type varchar(45) NOT NULL,
478 478
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
481 481
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
482 482
 				KEY STS_type (STS_type)";
483
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
-        $table_name = 'esp_transaction';
485
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
483
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
+		$table_name = 'esp_transaction';
485
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
486 486
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
487 487
 				TXN_total decimal(10,3) DEFAULT '0.00',
488 488
 				TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -494,9 +494,9 @@  discard block
 block discarded – undo
494 494
 				PRIMARY KEY  (TXN_ID),
495 495
 				KEY TXN_timestamp (TXN_timestamp),
496 496
 				KEY STS_ID (STS_ID)";
497
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
498
-        $table_name = 'esp_venue_meta';
499
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
497
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
498
+		$table_name = 'esp_venue_meta';
499
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
500 500
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
501 501
 			VNU_address varchar(255) DEFAULT NULL,
502 502
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -515,10 +515,10 @@  discard block
 block discarded – undo
515 515
 			KEY VNU_ID (VNU_ID),
516 516
 			KEY STA_ID (STA_ID),
517 517
 			KEY CNT_ISO (CNT_ISO)";
518
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
-        //modified tables
520
-        $table_name = "esp_price";
521
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
518
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
+		//modified tables
520
+		$table_name = "esp_price";
521
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
522 522
 				PRT_ID tinyint(3) unsigned NOT NULL,
523 523
 				PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
524 524
 				PRC_name varchar(245) NOT NULL,
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 				PRC_parent int(10) unsigned DEFAULT 0,
532 532
 				PRIMARY KEY  (PRC_ID),
533 533
 				KEY PRT_ID (PRT_ID)";
534
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
535
-        $table_name = "esp_price_type";
536
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
534
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
535
+		$table_name = "esp_price_type";
536
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
537 537
 				PRT_name varchar(45) NOT NULL,
538 538
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
539 539
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
543 543
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
544 544
 				PRIMARY KEY  (PRT_ID)";
545
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
-        $table_name = "esp_ticket";
547
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
545
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
+		$table_name = "esp_ticket";
547
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
548 548
 				TTM_ID int(10) unsigned NOT NULL,
549 549
 				TKT_name varchar(245) NOT NULL DEFAULT '',
550 550
 				TKT_description text NOT NULL,
@@ -567,9 +567,9 @@  discard block
 block discarded – undo
567 567
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
568 568
 				PRIMARY KEY  (TKT_ID),
569 569
 				KEY TKT_start_date (TKT_start_date)";
570
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
-        $table_name = 'esp_question_group';
572
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
570
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
+		$table_name = 'esp_question_group';
572
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
573 573
 				QSG_name varchar(255) NOT NULL,
574 574
 				QSG_identifier varchar(100) NOT NULL,
575 575
 				QSG_desc text NULL,
@@ -582,138 +582,138 @@  discard block
 block discarded – undo
582 582
 				PRIMARY KEY  (QSG_ID),
583 583
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
584 584
 				KEY QSG_order (QSG_order)';
585
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
-        //(because many need to convert old string states to foreign keys into the states table)
589
-        $script_4_1_defaults->insert_default_states();
590
-        $script_4_1_defaults->insert_default_countries();
591
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
-        $script_4_5_defaults->insert_default_price_types();
594
-        $script_4_5_defaults->insert_default_prices();
595
-        $script_4_5_defaults->insert_default_tickets();
596
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
-        $script_4_6_defaults->add_default_admin_only_payments();
599
-        $script_4_6_defaults->insert_default_currencies();
600
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
-        $script_4_8_defaults->verify_new_countries();
603
-        $script_4_8_defaults->verify_new_currencies();
604
-        $this->verify_db_collations();
605
-        $this->verify_db_collations_again();
606
-        return true;
607
-    }
585
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
+		//(because many need to convert old string states to foreign keys into the states table)
589
+		$script_4_1_defaults->insert_default_states();
590
+		$script_4_1_defaults->insert_default_countries();
591
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
+		$script_4_5_defaults->insert_default_price_types();
594
+		$script_4_5_defaults->insert_default_prices();
595
+		$script_4_5_defaults->insert_default_tickets();
596
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
+		$script_4_6_defaults->add_default_admin_only_payments();
599
+		$script_4_6_defaults->insert_default_currencies();
600
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
+		$script_4_8_defaults->verify_new_countries();
603
+		$script_4_8_defaults->verify_new_currencies();
604
+		$this->verify_db_collations();
605
+		$this->verify_db_collations_again();
606
+		return true;
607
+	}
608 608
 
609 609
 
610 610
 
611
-    /**
612
-     * @return boolean
613
-     */
614
-    public function schema_changes_after_migration()
615
-    {
616
-        return true;
617
-    }
611
+	/**
612
+	 * @return boolean
613
+	 */
614
+	public function schema_changes_after_migration()
615
+	{
616
+		return true;
617
+	}
618 618
 
619 619
 
620 620
 
621
-    public function migration_page_hooks()
622
-    {
623
-    }
621
+	public function migration_page_hooks()
622
+	{
623
+	}
624 624
 
625 625
 
626 626
 
627
-    /**
628
-     * Verify all EE4 models' tables use utf8mb4 collation
629
-     *
630
-     * @return void
631
-     */
632
-    public function verify_db_collations()
633
-    {
634
-        if (get_option('ee_verified_db_collations', false)) {
635
-            return;
636
-        }
637
-        // grab tables from each model
638
-        $tables_to_check = array();
639
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
-            if (method_exists($model_name, 'instance')) {
641
-                $model_obj = call_user_func(array($model_name, 'instance'));
642
-                if ($model_obj instanceof EEM_Base) {
643
-                    foreach ($model_obj->get_tables() as $table) {
644
-                        if (
645
-                            strpos($table->get_table_name(), 'esp_')
646
-                            && (is_main_site()//for main tables, verify global tables
647
-                                || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
-                            )
649
-                            && function_exists('maybe_convert_table_to_utf8mb4')
650
-                        ) {
651
-                            $tables_to_check[] = $table->get_table_name();
652
-                        }
653
-                    }
654
-                }
655
-            }
656
-        }
657
-        //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
-        //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
-        //of hard-coding this
660
-        $addon_tables = array(
661
-            //mailchimp
662
-            'esp_event_mailchimp_list_group',
663
-            'esp_event_question_mailchimp_field',
664
-            //multisite
665
-            'esp_blog_meta',
666
-            //people
667
-            'esp_people_to_post',
668
-            //promotions
669
-            'esp_promotion',
670
-            'esp_promotion_object',
671
-        );
672
-        foreach ($addon_tables as $table_name) {
673
-                $tables_to_check[] = $table_name;
674
-        }
675
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
-        //ok and now let's remember this was done (without needing to check the db schemas all over again)
677
-        add_option('ee_verified_db_collations', true, null, 'no');
678
-        //seeing how this ran with the fix from 10435, no need to check again
679
-        add_option('ee_verified_db_collations_again',true,null,'no');
680
-    }
627
+	/**
628
+	 * Verify all EE4 models' tables use utf8mb4 collation
629
+	 *
630
+	 * @return void
631
+	 */
632
+	public function verify_db_collations()
633
+	{
634
+		if (get_option('ee_verified_db_collations', false)) {
635
+			return;
636
+		}
637
+		// grab tables from each model
638
+		$tables_to_check = array();
639
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
+			if (method_exists($model_name, 'instance')) {
641
+				$model_obj = call_user_func(array($model_name, 'instance'));
642
+				if ($model_obj instanceof EEM_Base) {
643
+					foreach ($model_obj->get_tables() as $table) {
644
+						if (
645
+							strpos($table->get_table_name(), 'esp_')
646
+							&& (is_main_site()//for main tables, verify global tables
647
+								|| ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
+							)
649
+							&& function_exists('maybe_convert_table_to_utf8mb4')
650
+						) {
651
+							$tables_to_check[] = $table->get_table_name();
652
+						}
653
+					}
654
+				}
655
+			}
656
+		}
657
+		//and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
+		//when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
+		//of hard-coding this
660
+		$addon_tables = array(
661
+			//mailchimp
662
+			'esp_event_mailchimp_list_group',
663
+			'esp_event_question_mailchimp_field',
664
+			//multisite
665
+			'esp_blog_meta',
666
+			//people
667
+			'esp_people_to_post',
668
+			//promotions
669
+			'esp_promotion',
670
+			'esp_promotion_object',
671
+		);
672
+		foreach ($addon_tables as $table_name) {
673
+				$tables_to_check[] = $table_name;
674
+		}
675
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
+		//ok and now let's remember this was done (without needing to check the db schemas all over again)
677
+		add_option('ee_verified_db_collations', true, null, 'no');
678
+		//seeing how this ran with the fix from 10435, no need to check again
679
+		add_option('ee_verified_db_collations_again',true,null,'no');
680
+	}
681 681
 
682 682
 
683 683
 
684
-    /**
685
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
-     * which meant some DB collations might not have been updated
687
-     * @return void
688
-     */
689
-    public function verify_db_collations_again(){
690
-        if (get_option('ee_verified_db_collations_again', false)) {
691
-            return;
692
-        }
693
-        $tables_to_check = array(
694
-            'esp_attendee_meta',
695
-            'esp_message'
696
-        );
697
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
-        add_option('ee_verified_db_collations_again',true,null,'no');
699
-    }
684
+	/**
685
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
+	 * which meant some DB collations might not have been updated
687
+	 * @return void
688
+	 */
689
+	public function verify_db_collations_again(){
690
+		if (get_option('ee_verified_db_collations_again', false)) {
691
+			return;
692
+		}
693
+		$tables_to_check = array(
694
+			'esp_attendee_meta',
695
+			'esp_message'
696
+		);
697
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
+		add_option('ee_verified_db_collations_again',true,null,'no');
699
+	}
700 700
 
701 701
 
702 702
 
703
-    /**
704
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
-     * @param $tables_to_check
706
-     * @return boolean true if logic ran, false if it didn't
707
-     */
708
-    protected function _verify_db_collations_for_tables($tables_to_check)
709
-    {
710
-        foreach ($tables_to_check as $table_name) {
711
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
-                && $this->_get_table_analysis()->tableExists($table_name)
714
-            ) {
715
-                maybe_convert_table_to_utf8mb4($table_name);
716
-            }
717
-        }
718
-    }
703
+	/**
704
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
+	 * @param $tables_to_check
706
+	 * @return boolean true if logic ran, false if it didn't
707
+	 */
708
+	protected function _verify_db_collations_for_tables($tables_to_check)
709
+	{
710
+		foreach ($tables_to_check as $table_name) {
711
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
+			if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
+				&& $this->_get_table_analysis()->tableExists($table_name)
714
+			) {
715
+				maybe_convert_table_to_utf8mb4($table_name);
716
+			}
717
+		}
718
+	}
719 719
 }
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 //unfortunately, this needs to be done upon INCLUSION of this file,
10 10
 //instead of construction, because it only gets constructed on first page load
11 11
 //(all other times it gets resurrected from a wordpress option)
12
-$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
12
+$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15 15
     $matches = array();
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         } elseif ( ! $version_string) {
68 68
             //			echo "no version string provided: $version_string";
69 69
             //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
70
+            return false; //changed mind. dont want people thinking they should migrate yet because they cant
71 71
         } else {
72 72
             //			echo "$version_string doesnt apply";
73 73
             return false;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function schema_changes_before_migration()
83 83
     {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
84
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
85 85
         $now_in_mysql = current_time('mysql', true);
86 86
         $table_name = 'esp_answer';
87 87
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         //ok and now let's remember this was done (without needing to check the db schemas all over again)
677 677
         add_option('ee_verified_db_collations', true, null, 'no');
678 678
         //seeing how this ran with the fix from 10435, no need to check again
679
-        add_option('ee_verified_db_collations_again',true,null,'no');
679
+        add_option('ee_verified_db_collations_again', true, null, 'no');
680 680
     }
681 681
 
682 682
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
      * which meant some DB collations might not have been updated
687 687
      * @return void
688 688
      */
689
-    public function verify_db_collations_again(){
689
+    public function verify_db_collations_again() {
690 690
         if (get_option('ee_verified_db_collations_again', false)) {
691 691
             return;
692 692
         }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
             'esp_message'
696 696
         );
697 697
         $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
-        add_option('ee_verified_db_collations_again',true,null,'no');
698
+        add_option('ee_verified_db_collations_again', true, null, 'no');
699 699
     }
700 700
 
701 701
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     {
710 710
         foreach ($tables_to_check as $table_name) {
711 711
             $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
712
+            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
713 713
                 && $this->_get_table_analysis()->tableExists($table_name)
714 714
             ) {
715 715
                 maybe_convert_table_to_utf8mb4($table_name);
Please login to merge, or discard this patch.
core/services/database/TableManager.php 2 patches
Indentation   +243 added lines, -245 removed lines patch added patch discarded remove patch
@@ -17,253 +17,251 @@
 block discarded – undo
17 17
 class TableManager extends \EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var TableAnalysis $table_analysis
22
-     */
23
-    private $table_analysis;
24
-
25
-
26
-
27
-    /**
28
-     * TableManager constructor.
29
-     *
30
-     * @param TableAnalysis $TableAnalysis
31
-     */
32
-    public function __construct(TableAnalysis $TableAnalysis)
33
-    {
34
-        $this->table_analysis = $TableAnalysis;
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Gets the injected table analyzer, or throws an exception
41
-     *
42
-     * @return TableAnalysis
43
-     * @throws \EE_Error
44
-     */
45
-    protected function getTableAnalysis()
46
-    {
47
-        if ($this->table_analysis instanceof TableAnalysis) {
48
-            return $this->table_analysis;
49
-        } else {
50
-            throw new \EE_Error(
51
-                sprintf(
52
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
-                    get_class($this)
54
-                )
55
-            );
56
-        }
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
63
-     * @param string $column_name
64
-     * @param string $column_info
65
-     * @return bool|false|int
66
-     */
67
-    public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
-    {
69
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
-            return false;
71
-        }
72
-        global $wpdb;
73
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
-        $columns = $this->getTableColumns($table_name);
75
-        if ( ! in_array($column_name, $columns)) {
76
-            $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
-            return $wpdb->query($alter_query);
78
-        }
79
-        return true;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the name of all columns on the  table. $table_name can
86
-     * optionally start with $wpdb->prefix or not
87
-     *
88
-     * @global \wpdb $wpdb
89
-     * @param string $table_name
90
-     * @return array
91
-     */
92
-    public function getTableColumns($table_name)
93
-    {
94
-        global $wpdb;
95
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
-        $field_array = array();
97
-        if ( ! empty($table_name)) {
98
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
-            if ($columns !== false) {
100
-                foreach ($columns as $column) {
101
-                    $field_array[] = $column->Field;
102
-                }
103
-            }
104
-        }
105
-        return $field_array;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Drops the specified table from the database. $table_name can
112
-     * optionally start with $wpdb->prefix or not
113
-     *
114
-     * @global \wpdb $wpdb
115
-     * @param string $table_name
116
-     * @return int
117
-     */
118
-    public function dropTable($table_name)
119
-    {
120
-        global $wpdb;
121
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
122
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
-            return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
-        }
125
-        return 0;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
-     * each table name provided has a wpdb prefix attached, and that it exists.
133
-     * Returns the list actually deleted
134
-     *
135
-     * @global WPDB $wpdb
136
-     * @param array $table_names
137
-     * @return array of table names which we deleted
138
-     */
139
-    public function dropTables($table_names)
140
-    {
141
-        $tables_to_delete = array();
142
-        foreach ($table_names as $table_name) {
143
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
145
-                $tables_to_delete[] = $table_name;
146
-            }
147
-        }
148
-        if( ! empty( $tables_to_delete ) ) {
149
-            global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
-        }
152
-        return $tables_to_delete;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Drops the specified index from the specified table. $table_name can
159
-     * optionally start with $wpdb->prefix or not
160
-
161
-     *
20
+	/**
21
+	 * @var TableAnalysis $table_analysis
22
+	 */
23
+	private $table_analysis;
24
+
25
+
26
+
27
+	/**
28
+	 * TableManager constructor.
29
+	 *
30
+	 * @param TableAnalysis $TableAnalysis
31
+	 */
32
+	public function __construct(TableAnalysis $TableAnalysis)
33
+	{
34
+		$this->table_analysis = $TableAnalysis;
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Gets the injected table analyzer, or throws an exception
41
+	 *
42
+	 * @return TableAnalysis
43
+	 * @throws \EE_Error
44
+	 */
45
+	protected function getTableAnalysis()
46
+	{
47
+		if ($this->table_analysis instanceof TableAnalysis) {
48
+			return $this->table_analysis;
49
+		} else {
50
+			throw new \EE_Error(
51
+				sprintf(
52
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
+					get_class($this)
54
+				)
55
+			);
56
+		}
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
63
+	 * @param string $column_name
64
+	 * @param string $column_info
65
+	 * @return bool|false|int
66
+	 */
67
+	public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
+	{
69
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
+			return false;
71
+		}
72
+		global $wpdb;
73
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
+		$columns = $this->getTableColumns($table_name);
75
+		if ( ! in_array($column_name, $columns)) {
76
+			$alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
+			return $wpdb->query($alter_query);
78
+		}
79
+		return true;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the name of all columns on the  table. $table_name can
86
+	 * optionally start with $wpdb->prefix or not
87
+	 *
88
+	 * @global \wpdb $wpdb
89
+	 * @param string $table_name
90
+	 * @return array
91
+	 */
92
+	public function getTableColumns($table_name)
93
+	{
94
+		global $wpdb;
95
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
+		$field_array = array();
97
+		if ( ! empty($table_name)) {
98
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
+			if ($columns !== false) {
100
+				foreach ($columns as $column) {
101
+					$field_array[] = $column->Field;
102
+				}
103
+			}
104
+		}
105
+		return $field_array;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Drops the specified table from the database. $table_name can
112
+	 * optionally start with $wpdb->prefix or not
113
+	 *
114
+	 * @global \wpdb $wpdb
115
+	 * @param string $table_name
116
+	 * @return int
117
+	 */
118
+	public function dropTable($table_name)
119
+	{
120
+		global $wpdb;
121
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
122
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
+			return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
+		}
125
+		return 0;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
+	 * each table name provided has a wpdb prefix attached, and that it exists.
133
+	 * Returns the list actually deleted
134
+	 *
135
+	 * @global WPDB $wpdb
136
+	 * @param array $table_names
137
+	 * @return array of table names which we deleted
138
+	 */
139
+	public function dropTables($table_names)
140
+	{
141
+		$tables_to_delete = array();
142
+		foreach ($table_names as $table_name) {
143
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
145
+				$tables_to_delete[] = $table_name;
146
+			}
147
+		}
148
+		if( ! empty( $tables_to_delete ) ) {
149
+			global $wpdb;
150
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
+		}
152
+		return $tables_to_delete;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Drops the specified index from the specified table. $table_name can
159
+	 * optionally start with $wpdb->prefix or not
160
+	 *
162 161
 *@global \wpdb       $wpdb
163
-     * @param string $table_name
164
-     * @param string $index_name
165
-     * @return int the number of indexes dropped. False if there was a datbase error
166
-     */
167
-    public function dropIndex($table_name, $index_name)
168
-    {
169
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
170
-            return 0;
171
-        }
172
-        global $wpdb;
173
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
174
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
175
-        if (
176
-            $this->getTableAnalysis()->tableExists($table_name)
177
-            && $wpdb->get_var($index_exists_query)
178
-               === $table_name //using get_var with the $index_exists_query returns the table's name
179
-        ) {
180
-            return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
181
-        }
182
-        return 0;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Just creates the requested table. $table_name can
189
-     * optionally start with $wpdb->prefix or not
190
-
191
-     *
162
+	 * @param string $table_name
163
+	 * @param string $index_name
164
+	 * @return int the number of indexes dropped. False if there was a datbase error
165
+	 */
166
+	public function dropIndex($table_name, $index_name)
167
+	{
168
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
169
+			return 0;
170
+		}
171
+		global $wpdb;
172
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
173
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
174
+		if (
175
+			$this->getTableAnalysis()->tableExists($table_name)
176
+			&& $wpdb->get_var($index_exists_query)
177
+			   === $table_name //using get_var with the $index_exists_query returns the table's name
178
+		) {
179
+			return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
180
+		}
181
+		return 0;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Just creates the requested table. $table_name can
188
+	 * optionally start with $wpdb->prefix or not
189
+	 *
192 190
 *@param string       $table_name
193
-     * @param string $create_sql defining the table's columns and indexes
194
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
195
-     * @return void
196
-     * @throws \EE_Error
197
-     */
198
-    public function createTable($table_name, $create_sql, $engine = 'MyISAM')
199
-    {
200
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
201
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
202
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203
-            /** @var \wpdb $wpdb */
204
-            global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
206
-
207
-            //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208
-            //happened. And then we can choose to tell the end user
209
-            $old_show_errors_policy = $wpdb->show_errors(true);
210
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
211
-            ob_start();
212
-            dbDelta($SQL);
213
-            $output = ob_get_contents();
214
-            ob_end_clean();
215
-            $wpdb->show_errors($old_show_errors_policy);
216
-            $wpdb->suppress_errors($old_error_suppression_policy);
217
-            if ( ! empty($output)) {
218
-                throw new \EE_Error($output);
219
-            }
220
-        } else {
221
-            throw new \EE_Error(
222
-                sprintf(
223
-                    __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
224
-                        'event_espresso'),
225
-                    '<br />',
226
-                    $create_sql
227
-                )
228
-            );
229
-        }
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * Drops the specified index if it's size differs from $desired_index_size.
236
-     * WordPress' dbdelta method doesn't automatically change index sizes, so this
237
-     * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
238
-     * If the table doesn't exist, or it exists but the index does not, or returns false
239
-     *
191
+	 * @param string $create_sql defining the table's columns and indexes
192
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
193
+	 * @return void
194
+	 * @throws \EE_Error
195
+	 */
196
+	public function createTable($table_name, $create_sql, $engine = 'MyISAM')
197
+	{
198
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
199
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
200
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
201
+			/** @var \wpdb $wpdb */
202
+			global $wpdb;
203
+			$SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
204
+
205
+			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
206
+			//happened. And then we can choose to tell the end user
207
+			$old_show_errors_policy = $wpdb->show_errors(true);
208
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
209
+			ob_start();
210
+			dbDelta($SQL);
211
+			$output = ob_get_contents();
212
+			ob_end_clean();
213
+			$wpdb->show_errors($old_show_errors_policy);
214
+			$wpdb->suppress_errors($old_error_suppression_policy);
215
+			if ( ! empty($output)) {
216
+				throw new \EE_Error($output);
217
+			}
218
+		} else {
219
+			throw new \EE_Error(
220
+				sprintf(
221
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
222
+						'event_espresso'),
223
+					'<br />',
224
+					$create_sql
225
+				)
226
+			);
227
+		}
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * Drops the specified index if it's size differs from $desired_index_size.
234
+	 * WordPress' dbdelta method doesn't automatically change index sizes, so this
235
+	 * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
236
+	 * If the table doesn't exist, or it exists but the index does not, or returns false
237
+	 *
240 238
 *@param string $table_name
241
-     * @param string $index_name
242
-     * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
243
-     * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
244
-     *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
245
-     * @return bool whether an index was dropped or not
246
-     * @throws /EE_Error if table analysis object isn't defined
247
-     */
248
-    public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
249
-    {
250
-        if($column_name === null){
251
-            $column_name = $index_name;
252
-        }
253
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
254
-            return false;
255
-        }
256
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
257
-        if(empty($index_entries)){
258
-            return false;
259
-        }
260
-        foreach($index_entries as $index_entry){
261
-            if( $column_name === $index_entry->Column_name
262
-                && (string)$desired_index_size !== $index_entry->Sub_part){
263
-                return $this->dropIndex($table_name,$index_name);
264
-            }
265
-        }
266
-        return false;
267
-    }
239
+	 * @param string $index_name
240
+	 * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
241
+	 * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
242
+	 *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
243
+	 * @return bool whether an index was dropped or not
244
+	 * @throws /EE_Error if table analysis object isn't defined
245
+	 */
246
+	public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
247
+	{
248
+		if($column_name === null){
249
+			$column_name = $index_name;
250
+		}
251
+		if(!$this->getTableAnalysis()->tableExists($table_name)){
252
+			return false;
253
+		}
254
+		$index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
255
+		if(empty($index_entries)){
256
+			return false;
257
+		}
258
+		foreach($index_entries as $index_entry){
259
+			if( $column_name === $index_entry->Column_name
260
+				&& (string)$desired_index_size !== $index_entry->Sub_part){
261
+				return $this->dropIndex($table_name,$index_name);
262
+			}
263
+		}
264
+		return false;
265
+	}
268 266
 
269 267
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
                 $tables_to_delete[] = $table_name;
146 146
             }
147 147
         }
148
-        if( ! empty( $tables_to_delete ) ) {
148
+        if ( ! empty($tables_to_delete)) {
149 149
             global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
150
+            $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete));
151 151
         }
152 152
         return $tables_to_delete;
153 153
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203 203
             /** @var \wpdb $wpdb */
204 204
             global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
205
+            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate();
206 206
 
207 207
             //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208 208
             //happened. And then we can choose to tell the end user
@@ -247,20 +247,20 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
249 249
     {
250
-        if($column_name === null){
250
+        if ($column_name === null) {
251 251
             $column_name = $index_name;
252 252
         }
253
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
253
+        if ( ! $this->getTableAnalysis()->tableExists($table_name)) {
254 254
             return false;
255 255
         }
256
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
257
-        if(empty($index_entries)){
256
+        $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
257
+        if (empty($index_entries)) {
258 258
             return false;
259 259
         }
260
-        foreach($index_entries as $index_entry){
261
-            if( $column_name === $index_entry->Column_name
262
-                && (string)$desired_index_size !== $index_entry->Sub_part){
263
-                return $this->dropIndex($table_name,$index_name);
260
+        foreach ($index_entries as $index_entry) {
261
+            if ($column_name === $index_entry->Column_name
262
+                && (string) $desired_index_size !== $index_entry->Sub_part) {
263
+                return $this->dropIndex($table_name, $index_name);
264 264
             }
265 265
         }
266 266
         return false;
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +2960 added lines, -2960 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -23,1844 +23,1844 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if ( ! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = __('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => __('Add Contact', 'event_espresso'),
140
-                'edit'                => __('Edit Contact', 'event_espresso'),
141
-                'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => __("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
-            : $att_id;
173
-        $this->_page_routes = array(
174
-            'default'                            => array(
175
-                'func'       => '_registrations_overview_list_table',
176
-                'capability' => 'ee_read_registrations',
177
-            ),
178
-            'view_registration'                  => array(
179
-                'func'       => '_registration_details',
180
-                'capability' => 'ee_read_registration',
181
-                'obj_id'     => $reg_id,
182
-            ),
183
-            'edit_registration'                  => array(
184
-                'func'               => '_update_attendee_registration_form',
185
-                'noheader'           => true,
186
-                'headers_sent_route' => 'view_registration',
187
-                'capability'         => 'ee_edit_registration',
188
-                'obj_id'             => $reg_id,
189
-                '_REG_ID'            => $reg_id,
190
-            ),
191
-            'trash_registrations'                => array(
192
-                'func'       => '_trash_or_restore_registrations',
193
-                'args'       => array('trash' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_delete_registrations',
196
-            ),
197
-            'restore_registrations'              => array(
198
-                'func'       => '_trash_or_restore_registrations',
199
-                'args'       => array('trash' => false),
200
-                'noheader'   => true,
201
-                'capability' => 'ee_delete_registrations',
202
-            ),
203
-            'delete_registrations'               => array(
204
-                'func'       => '_delete_registrations',
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'new_registration'                   => array(
209
-                'func'       => 'new_registration',
210
-                'capability' => 'ee_edit_registrations',
211
-            ),
212
-            'process_reg_step'                   => array(
213
-                'func'       => 'process_reg_step',
214
-                'noheader'   => true,
215
-                'capability' => 'ee_edit_registrations',
216
-            ),
217
-            'redirect_to_txn'                    => array(
218
-                'func'       => 'redirect_to_txn',
219
-                'noheader'   => true,
220
-                'capability' => 'ee_edit_registrations',
221
-            ),
222
-            'change_reg_status'                  => array(
223
-                'func'       => '_change_reg_status',
224
-                'noheader'   => true,
225
-                'capability' => 'ee_edit_registration',
226
-                'obj_id'     => $reg_id,
227
-            ),
228
-            'approve_registration'               => array(
229
-                'func'       => 'approve_registration',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registration',
232
-                'obj_id'     => $reg_id,
233
-            ),
234
-            'approve_and_notify_registration'    => array(
235
-                'func'       => 'approve_registration',
236
-                'noheader'   => true,
237
-                'args'       => array(true),
238
-                'capability' => 'ee_edit_registration',
239
-                'obj_id'     => $reg_id,
240
-            ),
241
-            'decline_registration'               => array(
242
-                'func'       => 'decline_registration',
243
-                'noheader'   => true,
244
-                'capability' => 'ee_edit_registration',
245
-                'obj_id'     => $reg_id,
246
-            ),
247
-            'decline_and_notify_registration'    => array(
248
-                'func'       => 'decline_registration',
249
-                'noheader'   => true,
250
-                'args'       => array(true),
251
-                'capability' => 'ee_edit_registration',
252
-                'obj_id'     => $reg_id,
253
-            ),
254
-            'pending_registration'               => array(
255
-                'func'       => 'pending_registration',
256
-                'noheader'   => true,
257
-                'capability' => 'ee_edit_registration',
258
-                'obj_id'     => $reg_id,
259
-            ),
260
-            'pending_and_notify_registration'    => array(
261
-                'func'       => 'pending_registration',
262
-                'noheader'   => true,
263
-                'args'       => array(true),
264
-                'capability' => 'ee_edit_registration',
265
-                'obj_id'     => $reg_id,
266
-            ),
267
-            'no_approve_registration'            => array(
268
-                'func'       => 'not_approve_registration',
269
-                'noheader'   => true,
270
-                'capability' => 'ee_edit_registration',
271
-                'obj_id'     => $reg_id,
272
-            ),
273
-            'no_approve_and_notify_registration' => array(
274
-                'func'       => 'not_approve_registration',
275
-                'noheader'   => true,
276
-                'args'       => array(true),
277
-                'capability' => 'ee_edit_registration',
278
-                'obj_id'     => $reg_id,
279
-            ),
280
-            'cancel_registration'                => array(
281
-                'func'       => 'cancel_registration',
282
-                'noheader'   => true,
283
-                'capability' => 'ee_edit_registration',
284
-                'obj_id'     => $reg_id,
285
-            ),
286
-            'cancel_and_notify_registration'     => array(
287
-                'func'       => 'cancel_registration',
288
-                'noheader'   => true,
289
-                'args'       => array(true),
290
-                'capability' => 'ee_edit_registration',
291
-                'obj_id'     => $reg_id,
292
-            ),
293
-            'contact_list'                       => array(
294
-                'func'       => '_attendee_contact_list_table',
295
-                'capability' => 'ee_read_contacts',
296
-            ),
297
-            'add_new_attendee'                   => array(
298
-                'func' => '_create_new_cpt_item',
299
-                'args' => array(
300
-                    'new_attendee' => true,
301
-                    'capability'   => 'ee_edit_contacts',
302
-                ),
303
-            ),
304
-            'edit_attendee'                      => array(
305
-                'func'       => '_edit_cpt_item',
306
-                'capability' => 'ee_edit_contacts',
307
-                'obj_id'     => $att_id,
308
-            ),
309
-            'duplicate_attendee'                 => array(
310
-                'func'       => '_duplicate_attendee',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_contacts',
313
-                'obj_id'     => $att_id,
314
-            ),
315
-            'insert_attendee'                    => array(
316
-                'func'       => '_insert_or_update_attendee',
317
-                'args'       => array(
318
-                    'new_attendee' => true,
319
-                ),
320
-                'noheader'   => true,
321
-                'capability' => 'ee_edit_contacts',
322
-            ),
323
-            'update_attendee'                    => array(
324
-                'func'       => '_insert_or_update_attendee',
325
-                'args'       => array(
326
-                    'new_attendee' => false,
327
-                ),
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_contacts',
330
-                'obj_id'     => $att_id,
331
-            ),
332
-            'trash_attendees'                    => array(
333
-                'func'       => '_trash_or_restore_attendees',
334
-                'args'       => array(
335
-                    'trash' => true,
336
-                ),
337
-                'noheader'   => true,
338
-                'capability' => 'ee_delete_contacts',
339
-                'obj_id'     => $att_id,
340
-            ),
341
-            'restore_attendees'                  => array(
342
-                'func'       => '_trash_or_restore_attendees',
343
-                'args'       => array(
344
-                    'trash' => false,
345
-                ),
346
-                'noheader'   => true,
347
-                'capability' => 'ee_delete_contacts',
348
-                'obj_id'     => $att_id,
349
-            ),
350
-            'resend_registration'                => array(
351
-                'func'       => '_resend_registration',
352
-                'noheader'   => true,
353
-                'capability' => 'ee_send_message',
354
-            ),
355
-            'registrations_report'               => array(
356
-                'func'       => '_registrations_report',
357
-                'noheader'   => true,
358
-                'capability' => 'ee_read_registrations',
359
-            ),
360
-            'contact_list_export'                => array(
361
-                'func'       => '_contact_list_export',
362
-                'noheader'   => true,
363
-                'capability' => 'export',
364
-            ),
365
-            'contact_list_report'                => array(
366
-                'func'       => '_contact_list_report',
367
-                'noheader'   => true,
368
-                'capability' => 'ee_read_contacts',
369
-            ),
370
-        );
371
-    }
372
-
373
-
374
-    protected function _set_page_config()
375
-    {
376
-        $this->_page_config = array(
377
-            'default'           => array(
378
-                'nav'           => array(
379
-                    'label' => __('Overview', 'event_espresso'),
380
-                    'order' => 5,
381
-                ),
382
-                'help_tabs'     => array(
383
-                    'registrations_overview_help_tab'                       => array(
384
-                        'title'    => __('Registrations Overview', 'event_espresso'),
385
-                        'filename' => 'registrations_overview',
386
-                    ),
387
-                    'registrations_overview_table_column_headings_help_tab' => array(
388
-                        'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
-                        'filename' => 'registrations_overview_table_column_headings',
390
-                    ),
391
-                    'registrations_overview_filters_help_tab'               => array(
392
-                        'title'    => __('Registration Filters', 'event_espresso'),
393
-                        'filename' => 'registrations_overview_filters',
394
-                    ),
395
-                    'registrations_overview_views_help_tab'                 => array(
396
-                        'title'    => __('Registration Views', 'event_espresso'),
397
-                        'filename' => 'registrations_overview_views',
398
-                    ),
399
-                    'registrations_regoverview_other_help_tab'              => array(
400
-                        'title'    => __('Registrations Other', 'event_espresso'),
401
-                        'filename' => 'registrations_overview_other',
402
-                    ),
403
-                ),
404
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
405
-                'qtips'         => array('Registration_List_Table_Tips'),
406
-                'list_table'    => 'EE_Registrations_List_Table',
407
-                'require_nonce' => false,
408
-            ),
409
-            'view_registration' => array(
410
-                'nav'           => array(
411
-                    'label'      => __('REG Details', 'event_espresso'),
412
-                    'order'      => 15,
413
-                    'url'        => isset($this->_req_data['_REG_ID'])
414
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
-                        : $this->_admin_base_url,
416
-                    'persistent' => false,
417
-                ),
418
-                'help_tabs'     => array(
419
-                    'registrations_details_help_tab'                    => array(
420
-                        'title'    => __('Registration Details', 'event_espresso'),
421
-                        'filename' => 'registrations_details',
422
-                    ),
423
-                    'registrations_details_table_help_tab'              => array(
424
-                        'title'    => __('Registration Details Table', 'event_espresso'),
425
-                        'filename' => 'registrations_details_table',
426
-                    ),
427
-                    'registrations_details_form_answers_help_tab'       => array(
428
-                        'title'    => __('Registration Form Answers', 'event_espresso'),
429
-                        'filename' => 'registrations_details_form_answers',
430
-                    ),
431
-                    'registrations_details_registrant_details_help_tab' => array(
432
-                        'title'    => __('Contact Details', 'event_espresso'),
433
-                        'filename' => 'registrations_details_registrant_details',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Registration_Details_Help_Tour'),
437
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
-                    array('_registration_details_metaboxes')),
439
-                'require_nonce' => false,
440
-            ),
441
-            'new_registration'  => array(
442
-                'nav'           => array(
443
-                    'label'      => __('Add New Registration', 'event_espresso'),
444
-                    'url'        => '#',
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                ),
448
-                'metaboxes'     => $this->_default_espresso_metaboxes,
449
-                'labels'        => array(
450
-                    'publishbox' => __('Save Registration', 'event_espresso'),
451
-                ),
452
-                'require_nonce' => false,
453
-            ),
454
-            'add_new_attendee'  => array(
455
-                'nav'           => array(
456
-                    'label'      => __('Add Contact', 'event_espresso'),
457
-                    'order'      => 15,
458
-                    'persistent' => false,
459
-                ),
460
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
-                    array('_publish_post_box', 'attendee_editor_metaboxes')),
462
-                'require_nonce' => false,
463
-            ),
464
-            'edit_attendee'     => array(
465
-                'nav'           => array(
466
-                    'label'      => __('Edit Contact', 'event_espresso'),
467
-                    'order'      => 15,
468
-                    'persistent' => false,
469
-                    'url'        => isset($this->_req_data['ATT_ID'])
470
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
-                        : $this->_admin_base_url,
472
-                ),
473
-                'metaboxes'     => array('attendee_editor_metaboxes'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'contact_list'      => array(
477
-                'nav'           => array(
478
-                    'label' => __('Contact List', 'event_espresso'),
479
-                    'order' => 20,
480
-                ),
481
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
482
-                'help_tabs'     => array(
483
-                    'registrations_contact_list_help_tab'                       => array(
484
-                        'title'    => __('Registrations Contact List', 'event_espresso'),
485
-                        'filename' => 'registrations_contact_list',
486
-                    ),
487
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
488
-                        'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
-                        'filename' => 'registrations_contact_list_table_column_headings',
490
-                    ),
491
-                    'registrations_contact_list_views_help_tab'                 => array(
492
-                        'title'    => __('Contact List Views', 'event_espresso'),
493
-                        'filename' => 'registrations_contact_list_views',
494
-                    ),
495
-                    'registrations_contact_list_other_help_tab'                 => array(
496
-                        'title'    => __('Contact List Other', 'event_espresso'),
497
-                        'filename' => 'registrations_contact_list_other',
498
-                    ),
499
-                ),
500
-                'help_tour'     => array('Contact_List_Help_Tour'),
501
-                'metaboxes'     => array(),
502
-                'require_nonce' => false,
503
-            ),
504
-            //override default cpt routes
505
-            'create_new'        => '',
506
-            'edit'              => '',
507
-        );
508
-    }
509
-
510
-
511
-    /**
512
-     * The below methods aren't used by this class currently
513
-     */
514
-    protected function _add_screen_options()
515
-    {
516
-    }
517
-
518
-
519
-    protected function _add_feature_pointers()
520
-    {
521
-    }
522
-
523
-
524
-    public function admin_init()
525
-    {
526
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
-            'event_espresso');
528
-    }
529
-
530
-
531
-    public function admin_notices()
532
-    {
533
-    }
534
-
535
-
536
-    public function admin_footer_scripts()
537
-    {
538
-    }
539
-
540
-
541
-    /**
542
-     *        get list of registration statuses
543
-     *
544
-     * @access private
545
-     * @return void
546
-     */
547
-    private function _get_registration_status_array()
548
-    {
549
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
-    }
551
-
552
-
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    protected function _add_screen_options_contact_list()
560
-    {
561
-        $page_title              = $this->_admin_page_title;
562
-        $this->_admin_page_title = __("Contacts", 'event_espresso');
563
-        $this->_per_page_screen_option();
564
-        $this->_admin_page_title = $page_title;
565
-    }
566
-
567
-
568
-    public function load_scripts_styles()
569
-    {
570
-        //style
571
-        //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
-        wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
-            EVENT_ESPRESSO_VERSION);
574
-        wp_enqueue_style('espresso_reg');
575
-        //script
576
-        wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
-        wp_enqueue_script('espresso_reg');
579
-    }
580
-
581
-
582
-    public function load_scripts_styles_edit_attendee()
583
-    {
584
-        //stuff to only show up on our attendee edit details page.
585
-        $attendee_details_translations = array(
586
-            'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
-                $this->_cpt_model_obj->get_datetime('ATT_created')),
588
-        );
589
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
-        wp_enqueue_script('jquery-validate');
591
-    }
592
-
593
-
594
-    public function load_scripts_styles_view_registration()
595
-    {
596
-        //styles
597
-        wp_enqueue_style('espresso-ui-theme');
598
-        //scripts
599
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
600
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
-    }
602
-
603
-
604
-    public function load_scripts_styles_contact_list()
605
-    {
606
-        wp_deregister_style('espresso_reg');
607
-        wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
-            EVENT_ESPRESSO_VERSION);
609
-        wp_enqueue_style('espresso_att');
610
-    }
611
-
612
-
613
-    public function load_scripts_styles_new_registration()
614
-    {
615
-        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
-            EVENT_ESPRESSO_VERSION, true);
617
-        wp_enqueue_script('ee-spco-for-admin');
618
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
-        EE_Form_Section_Proper::wp_enqueue_scripts();
620
-        EED_Ticket_Selector::load_tckt_slctr_assets();
621
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
622
-    }
623
-
624
-
625
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
-    {
627
-        add_filter('FHEE_load_EE_messages', '__return_true');
628
-    }
629
-
630
-
631
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
-    {
633
-        add_filter('FHEE_load_EE_messages', '__return_true');
634
-    }
635
-
636
-
637
-    protected function _set_list_table_views_default()
638
-    {
639
-        //for notification related bulk actions we need to make sure only active messengers have an option.
640
-        EED_Messages::set_autoloaders();
641
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
642
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
644
-        //key= bulk_action_slug, value= message type.
645
-        $match_array = array(
646
-            'approve_registration'    => 'registration',
647
-            'decline_registration'    => 'declined_registration',
648
-            'pending_registration'    => 'pending_approval',
649
-            'no_approve_registration' => 'not_approved_registration',
650
-            'cancel_registration'     => 'cancelled_registration',
651
-        );
652
-        /** setup reg status bulk actions **/
653
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
-        if (in_array($match_array['approve_registration'], $active_mts)
655
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
-        ) {
657
-            $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
-                'event_espresso');
659
-        }
660
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
-        if (in_array($match_array['decline_registration'], $active_mts)
662
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
-        ) {
664
-            $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
-                'event_espresso');
666
-        }
667
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
-        if (in_array($match_array['pending_registration'], $active_mts)
669
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
-        ) {
671
-            $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
-                'event_espresso');
673
-        }
674
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
-        if (in_array($match_array['no_approve_registration'], $active_mts)
676
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
-        ) {
678
-            $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
-                'event_espresso');
680
-        }
681
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
-        if (in_array($match_array['cancel_registration'], $active_mts)
683
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
-        ) {
685
-            $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
-                'event_espresso');
687
-        }
688
-        $this->_views = array(
689
-            'all'   => array(
690
-                'slug'        => 'all',
691
-                'label'       => __('View All Registrations', 'event_espresso'),
692
-                'count'       => 0,
693
-                'bulk_action' => array_merge($def_reg_status_actions, array(
694
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
-                )),
696
-            ),
697
-            'month' => array(
698
-                'slug'        => 'month',
699
-                'label'       => __('This Month', 'event_espresso'),
700
-                'count'       => 0,
701
-                'bulk_action' => array_merge($def_reg_status_actions, array(
702
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
-                )),
704
-            ),
705
-            'today' => array(
706
-                'slug'        => 'today',
707
-                'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
-                'count'       => 0,
709
-                'bulk_action' => array_merge($def_reg_status_actions, array(
710
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
-                )),
712
-            ),
713
-        );
714
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
-            'espresso_registrations_delete_registration')
716
-        ) {
717
-            $this->_views['incomplete'] = array(
718
-                'slug'        => 'incomplete',
719
-                'label'       => __('Incomplete', 'event_espresso'),
720
-                'count'       => 0,
721
-                'bulk_action' => array(
722
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
-                ),
724
-            );
725
-            $this->_views['trash']      = array(
726
-                'slug'        => 'trash',
727
-                'label'       => __('Trash', 'event_espresso'),
728
-                'count'       => 0,
729
-                'bulk_action' => array(
730
-                    'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
-                    'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
-                ),
733
-            );
734
-        }
735
-    }
736
-
737
-
738
-    protected function _set_list_table_views_contact_list()
739
-    {
740
-        $this->_views = array(
741
-            'in_use' => array(
742
-                'slug'        => 'in_use',
743
-                'label'       => __('In Use', 'event_espresso'),
744
-                'count'       => 0,
745
-                'bulk_action' => array(
746
-                    'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
-                ),
748
-            ),
749
-        );
750
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
-            'espresso_registrations_trash_attendees')
752
-        ) {
753
-            $this->_views['trash'] = array(
754
-                'slug'        => 'trash',
755
-                'label'       => __('Trash', 'event_espresso'),
756
-                'count'       => 0,
757
-                'bulk_action' => array(
758
-                    'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
-                ),
760
-            );
761
-        }
762
-    }
763
-
764
-
765
-    protected function _registration_legend_items()
766
-    {
767
-        $fc_items = array(
768
-            'star-icon'        => array(
769
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
-                'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
-            ),
772
-            'view_details'     => array(
773
-                'class' => 'dashicons dashicons-clipboard',
774
-                'desc'  => __('View Registration Details', 'event_espresso'),
775
-            ),
776
-            'edit_attendee'    => array(
777
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
-                'desc'  => __('Edit Contact Details', 'event_espresso'),
779
-            ),
780
-            'view_transaction' => array(
781
-                'class' => 'dashicons dashicons-cart',
782
-                'desc'  => __('View Transaction Details', 'event_espresso'),
783
-            ),
784
-            'view_invoice'     => array(
785
-                'class' => 'dashicons dashicons-media-spreadsheet',
786
-                'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
-            ),
788
-        );
789
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
-            'espresso_registrations_resend_registration')
791
-        ) {
792
-            $fc_items['resend_registration'] = array(
793
-                'class' => 'dashicons dashicons-email-alt',
794
-                'desc'  => __('Resend Registration Details', 'event_espresso'),
795
-            );
796
-        } else {
797
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
-        }
799
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
-                $fc_items['view_related_messages'] = array(
803
-                    'class' => $related_for_icon['css_class'],
804
-                    'desc'  => $related_for_icon['label'],
805
-                );
806
-            }
807
-        }
808
-        $sc_items = array(
809
-            'approved_status'   => array(
810
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
-            ),
813
-            'pending_status'    => array(
814
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
-            ),
817
-            'wait_list'         => array(
818
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
-            ),
821
-            'incomplete_status' => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
-            ),
825
-            'not_approved'      => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
-            ),
829
-            'declined_status'   => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
-            ),
833
-            'cancelled_status'  => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
-            ),
837
-        );
838
-        return array_merge($fc_items, $sc_items);
839
-    }
840
-
841
-
842
-
843
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
844
-    /**
845
-     * @throws \EE_Error
846
-     */
847
-    protected function _registrations_overview_list_table()
848
-    {
849
-        $this->_template_args['admin_page_header'] = '';
850
-        $EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
-        if ($EVT_ID) {
852
-            if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
-                'espresso_registrations_new_registration', $EVT_ID)
854
-            ) {
855
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
-                        array('event_id' => $EVT_ID), 'add-new-h2');
857
-            }
858
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
-            if ($event instanceof EE_Event) {
860
-                $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
-                    'event_espresso'), '<h3 style="line-height:1.5em;">',
862
-                    '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
-                        'action' => 'edit',
864
-                        'post'   => $event->ID(),
865
-                    ), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
-            }
867
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
-                $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
-                $this->_template_args['admin_page_header'] .= $datetime->name();
874
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
876
-            }
877
-        }
878
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
-        $this->display_admin_list_table_page_with_no_sidebar();
880
-    }
881
-
882
-
883
-    /**
884
-     * This sets the _registration property for the registration details screen
885
-     *
886
-     * @access private
887
-     * @return bool
888
-     */
889
-    private function _set_registration_object()
890
-    {
891
-        //get out if we've already set the object
892
-        if (is_object($this->_registration)) {
893
-            return true;
894
-        }
895
-        $REG    = EEM_Registration::instance();
896
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
-            return true;
899
-        } else {
900
-            $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
-                'event_espresso'), $REG_ID);
902
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
-            $this->_registration = null;
904
-            return false;
905
-        }
906
-    }
907
-
908
-
909
-    /**
910
-     * Used to retrieve registrations for the list table.
911
-     *
912
-     * @param int    $per_page
913
-     * @param bool   $count
914
-     * @param bool   $this_month
915
-     * @param bool   $today
916
-     * @return \EE_Registration[]|int
917
-     */
918
-    public function get_registrations(
919
-        $per_page = 10,
920
-        $count = false,
921
-        $this_month = false,
922
-        $today = false
923
-    ) {
924
-        if( $this_month ) {
925
-            $this->_req_data['status'] = 'month';
926
-        }
927
-        if( $today ) {
928
-            $this->_req_data['status'] = 'today';
929
-        }
930
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
-        /**
932
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
933
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
934
-         * @see EEM_Base::get_all()
935
-         */
936
-        $query_params['group_by'] = '';
937
-
938
-        return $count
939
-            ? EEM_Registration::instance()->count($query_params)
940
-            /** @type EE_Registration[] */
941
-            : EEM_Registration::instance()->get_all($query_params);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
948
-     * Note: this listens to values on the request for some of the query parameters.
949
-     *
950
-     * @param array $request
951
-     * @param int    $per_page
952
-     * @param bool   $count
953
-     * @return array
954
-     */
955
-    protected function _get_registration_query_parameters(
956
-        $request = array(),
957
-        $per_page = 10,
958
-        $count = false
959
-    ) {
960
-
961
-        $query_params = array(
962
-            0                          => $this->_get_where_conditions_for_registrations_query(
963
-                $request
964
-            ),
965
-            'caps'                     => EEM_Registration::caps_read_admin,
966
-            'default_where_conditions' => 'this_model_only',
967
-        );
968
-        if ( ! $count) {
969
-            $query_params = array_merge(
970
-                $query_params,
971
-                $this->_get_orderby_for_registrations_query(),
972
-                $this->_get_limit($per_page)
973
-            );
974
-        }
975
-
976
-        return $query_params;
977
-    }
978
-
979
-
980
-    /**
981
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
982
-     *
983
-     * @param array $request usually the same as $this->_req_data but not necessarily
984
-     * @return array
985
-     */
986
-    protected function _add_event_id_to_where_conditions(array $request)
987
-    {
988
-        $where = array();
989
-        if ( ! empty($request['event_id'])) {
990
-            $where['EVT_ID'] = absint($request['event_id']);
991
-        }
992
-        return $where;
993
-    }
994
-
995
-
996
-    /**
997
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
998
-     *
999
-     * @param array $request usually the same as $this->_req_data but not necessarily
1000
-     * @return array
1001
-     */
1002
-    protected function _add_category_id_to_where_conditions(array $request)
1003
-    {
1004
-        $where = array();
1005
-        if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1006
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1007
-        }
1008
-        return $where;
1009
-    }
1010
-
1011
-
1012
-    /**
1013
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1014
-     *
1015
-     * @param array $request usually the same as $this->_req_data but not necessarily
1016
-     * @return array
1017
-     */
1018
-    protected function _add_datetime_id_to_where_conditions(array $request)
1019
-    {
1020
-        $where = array();
1021
-        if ( ! empty($request['datetime_id'])) {
1022
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1023
-        }
1024
-        if( ! empty($request['DTT_ID'])){
1025
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1026
-        }
1027
-        return $where;
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * Adds the correct registration status to the where conditions for the registrations query.
1033
-     *
1034
-     * @param array $request usually the same as $this->_req_data but not necessarily
1035
-     * @return array
1036
-     */
1037
-    protected function _add_registration_status_to_where_conditions(array $request)
1038
-    {
1039
-        $where = array();
1040
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1041
-        $registration_status = ! empty($request['_reg_status'])
1042
-            ? sanitize_text_field($request['_reg_status'])
1043
-            : '';
1044
-
1045
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if ( ! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = __('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => __('Add Contact', 'event_espresso'),
140
+				'edit'                => __('Edit Contact', 'event_espresso'),
141
+				'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => __("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
+			: $att_id;
173
+		$this->_page_routes = array(
174
+			'default'                            => array(
175
+				'func'       => '_registrations_overview_list_table',
176
+				'capability' => 'ee_read_registrations',
177
+			),
178
+			'view_registration'                  => array(
179
+				'func'       => '_registration_details',
180
+				'capability' => 'ee_read_registration',
181
+				'obj_id'     => $reg_id,
182
+			),
183
+			'edit_registration'                  => array(
184
+				'func'               => '_update_attendee_registration_form',
185
+				'noheader'           => true,
186
+				'headers_sent_route' => 'view_registration',
187
+				'capability'         => 'ee_edit_registration',
188
+				'obj_id'             => $reg_id,
189
+				'_REG_ID'            => $reg_id,
190
+			),
191
+			'trash_registrations'                => array(
192
+				'func'       => '_trash_or_restore_registrations',
193
+				'args'       => array('trash' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_delete_registrations',
196
+			),
197
+			'restore_registrations'              => array(
198
+				'func'       => '_trash_or_restore_registrations',
199
+				'args'       => array('trash' => false),
200
+				'noheader'   => true,
201
+				'capability' => 'ee_delete_registrations',
202
+			),
203
+			'delete_registrations'               => array(
204
+				'func'       => '_delete_registrations',
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'new_registration'                   => array(
209
+				'func'       => 'new_registration',
210
+				'capability' => 'ee_edit_registrations',
211
+			),
212
+			'process_reg_step'                   => array(
213
+				'func'       => 'process_reg_step',
214
+				'noheader'   => true,
215
+				'capability' => 'ee_edit_registrations',
216
+			),
217
+			'redirect_to_txn'                    => array(
218
+				'func'       => 'redirect_to_txn',
219
+				'noheader'   => true,
220
+				'capability' => 'ee_edit_registrations',
221
+			),
222
+			'change_reg_status'                  => array(
223
+				'func'       => '_change_reg_status',
224
+				'noheader'   => true,
225
+				'capability' => 'ee_edit_registration',
226
+				'obj_id'     => $reg_id,
227
+			),
228
+			'approve_registration'               => array(
229
+				'func'       => 'approve_registration',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registration',
232
+				'obj_id'     => $reg_id,
233
+			),
234
+			'approve_and_notify_registration'    => array(
235
+				'func'       => 'approve_registration',
236
+				'noheader'   => true,
237
+				'args'       => array(true),
238
+				'capability' => 'ee_edit_registration',
239
+				'obj_id'     => $reg_id,
240
+			),
241
+			'decline_registration'               => array(
242
+				'func'       => 'decline_registration',
243
+				'noheader'   => true,
244
+				'capability' => 'ee_edit_registration',
245
+				'obj_id'     => $reg_id,
246
+			),
247
+			'decline_and_notify_registration'    => array(
248
+				'func'       => 'decline_registration',
249
+				'noheader'   => true,
250
+				'args'       => array(true),
251
+				'capability' => 'ee_edit_registration',
252
+				'obj_id'     => $reg_id,
253
+			),
254
+			'pending_registration'               => array(
255
+				'func'       => 'pending_registration',
256
+				'noheader'   => true,
257
+				'capability' => 'ee_edit_registration',
258
+				'obj_id'     => $reg_id,
259
+			),
260
+			'pending_and_notify_registration'    => array(
261
+				'func'       => 'pending_registration',
262
+				'noheader'   => true,
263
+				'args'       => array(true),
264
+				'capability' => 'ee_edit_registration',
265
+				'obj_id'     => $reg_id,
266
+			),
267
+			'no_approve_registration'            => array(
268
+				'func'       => 'not_approve_registration',
269
+				'noheader'   => true,
270
+				'capability' => 'ee_edit_registration',
271
+				'obj_id'     => $reg_id,
272
+			),
273
+			'no_approve_and_notify_registration' => array(
274
+				'func'       => 'not_approve_registration',
275
+				'noheader'   => true,
276
+				'args'       => array(true),
277
+				'capability' => 'ee_edit_registration',
278
+				'obj_id'     => $reg_id,
279
+			),
280
+			'cancel_registration'                => array(
281
+				'func'       => 'cancel_registration',
282
+				'noheader'   => true,
283
+				'capability' => 'ee_edit_registration',
284
+				'obj_id'     => $reg_id,
285
+			),
286
+			'cancel_and_notify_registration'     => array(
287
+				'func'       => 'cancel_registration',
288
+				'noheader'   => true,
289
+				'args'       => array(true),
290
+				'capability' => 'ee_edit_registration',
291
+				'obj_id'     => $reg_id,
292
+			),
293
+			'contact_list'                       => array(
294
+				'func'       => '_attendee_contact_list_table',
295
+				'capability' => 'ee_read_contacts',
296
+			),
297
+			'add_new_attendee'                   => array(
298
+				'func' => '_create_new_cpt_item',
299
+				'args' => array(
300
+					'new_attendee' => true,
301
+					'capability'   => 'ee_edit_contacts',
302
+				),
303
+			),
304
+			'edit_attendee'                      => array(
305
+				'func'       => '_edit_cpt_item',
306
+				'capability' => 'ee_edit_contacts',
307
+				'obj_id'     => $att_id,
308
+			),
309
+			'duplicate_attendee'                 => array(
310
+				'func'       => '_duplicate_attendee',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_contacts',
313
+				'obj_id'     => $att_id,
314
+			),
315
+			'insert_attendee'                    => array(
316
+				'func'       => '_insert_or_update_attendee',
317
+				'args'       => array(
318
+					'new_attendee' => true,
319
+				),
320
+				'noheader'   => true,
321
+				'capability' => 'ee_edit_contacts',
322
+			),
323
+			'update_attendee'                    => array(
324
+				'func'       => '_insert_or_update_attendee',
325
+				'args'       => array(
326
+					'new_attendee' => false,
327
+				),
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_contacts',
330
+				'obj_id'     => $att_id,
331
+			),
332
+			'trash_attendees'                    => array(
333
+				'func'       => '_trash_or_restore_attendees',
334
+				'args'       => array(
335
+					'trash' => true,
336
+				),
337
+				'noheader'   => true,
338
+				'capability' => 'ee_delete_contacts',
339
+				'obj_id'     => $att_id,
340
+			),
341
+			'restore_attendees'                  => array(
342
+				'func'       => '_trash_or_restore_attendees',
343
+				'args'       => array(
344
+					'trash' => false,
345
+				),
346
+				'noheader'   => true,
347
+				'capability' => 'ee_delete_contacts',
348
+				'obj_id'     => $att_id,
349
+			),
350
+			'resend_registration'                => array(
351
+				'func'       => '_resend_registration',
352
+				'noheader'   => true,
353
+				'capability' => 'ee_send_message',
354
+			),
355
+			'registrations_report'               => array(
356
+				'func'       => '_registrations_report',
357
+				'noheader'   => true,
358
+				'capability' => 'ee_read_registrations',
359
+			),
360
+			'contact_list_export'                => array(
361
+				'func'       => '_contact_list_export',
362
+				'noheader'   => true,
363
+				'capability' => 'export',
364
+			),
365
+			'contact_list_report'                => array(
366
+				'func'       => '_contact_list_report',
367
+				'noheader'   => true,
368
+				'capability' => 'ee_read_contacts',
369
+			),
370
+		);
371
+	}
372
+
373
+
374
+	protected function _set_page_config()
375
+	{
376
+		$this->_page_config = array(
377
+			'default'           => array(
378
+				'nav'           => array(
379
+					'label' => __('Overview', 'event_espresso'),
380
+					'order' => 5,
381
+				),
382
+				'help_tabs'     => array(
383
+					'registrations_overview_help_tab'                       => array(
384
+						'title'    => __('Registrations Overview', 'event_espresso'),
385
+						'filename' => 'registrations_overview',
386
+					),
387
+					'registrations_overview_table_column_headings_help_tab' => array(
388
+						'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
+						'filename' => 'registrations_overview_table_column_headings',
390
+					),
391
+					'registrations_overview_filters_help_tab'               => array(
392
+						'title'    => __('Registration Filters', 'event_espresso'),
393
+						'filename' => 'registrations_overview_filters',
394
+					),
395
+					'registrations_overview_views_help_tab'                 => array(
396
+						'title'    => __('Registration Views', 'event_espresso'),
397
+						'filename' => 'registrations_overview_views',
398
+					),
399
+					'registrations_regoverview_other_help_tab'              => array(
400
+						'title'    => __('Registrations Other', 'event_espresso'),
401
+						'filename' => 'registrations_overview_other',
402
+					),
403
+				),
404
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
405
+				'qtips'         => array('Registration_List_Table_Tips'),
406
+				'list_table'    => 'EE_Registrations_List_Table',
407
+				'require_nonce' => false,
408
+			),
409
+			'view_registration' => array(
410
+				'nav'           => array(
411
+					'label'      => __('REG Details', 'event_espresso'),
412
+					'order'      => 15,
413
+					'url'        => isset($this->_req_data['_REG_ID'])
414
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
+						: $this->_admin_base_url,
416
+					'persistent' => false,
417
+				),
418
+				'help_tabs'     => array(
419
+					'registrations_details_help_tab'                    => array(
420
+						'title'    => __('Registration Details', 'event_espresso'),
421
+						'filename' => 'registrations_details',
422
+					),
423
+					'registrations_details_table_help_tab'              => array(
424
+						'title'    => __('Registration Details Table', 'event_espresso'),
425
+						'filename' => 'registrations_details_table',
426
+					),
427
+					'registrations_details_form_answers_help_tab'       => array(
428
+						'title'    => __('Registration Form Answers', 'event_espresso'),
429
+						'filename' => 'registrations_details_form_answers',
430
+					),
431
+					'registrations_details_registrant_details_help_tab' => array(
432
+						'title'    => __('Contact Details', 'event_espresso'),
433
+						'filename' => 'registrations_details_registrant_details',
434
+					),
435
+				),
436
+				'help_tour'     => array('Registration_Details_Help_Tour'),
437
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
+					array('_registration_details_metaboxes')),
439
+				'require_nonce' => false,
440
+			),
441
+			'new_registration'  => array(
442
+				'nav'           => array(
443
+					'label'      => __('Add New Registration', 'event_espresso'),
444
+					'url'        => '#',
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+				),
448
+				'metaboxes'     => $this->_default_espresso_metaboxes,
449
+				'labels'        => array(
450
+					'publishbox' => __('Save Registration', 'event_espresso'),
451
+				),
452
+				'require_nonce' => false,
453
+			),
454
+			'add_new_attendee'  => array(
455
+				'nav'           => array(
456
+					'label'      => __('Add Contact', 'event_espresso'),
457
+					'order'      => 15,
458
+					'persistent' => false,
459
+				),
460
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
+					array('_publish_post_box', 'attendee_editor_metaboxes')),
462
+				'require_nonce' => false,
463
+			),
464
+			'edit_attendee'     => array(
465
+				'nav'           => array(
466
+					'label'      => __('Edit Contact', 'event_espresso'),
467
+					'order'      => 15,
468
+					'persistent' => false,
469
+					'url'        => isset($this->_req_data['ATT_ID'])
470
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
+						: $this->_admin_base_url,
472
+				),
473
+				'metaboxes'     => array('attendee_editor_metaboxes'),
474
+				'require_nonce' => false,
475
+			),
476
+			'contact_list'      => array(
477
+				'nav'           => array(
478
+					'label' => __('Contact List', 'event_espresso'),
479
+					'order' => 20,
480
+				),
481
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
482
+				'help_tabs'     => array(
483
+					'registrations_contact_list_help_tab'                       => array(
484
+						'title'    => __('Registrations Contact List', 'event_espresso'),
485
+						'filename' => 'registrations_contact_list',
486
+					),
487
+					'registrations_contact-list_table_column_headings_help_tab' => array(
488
+						'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
+						'filename' => 'registrations_contact_list_table_column_headings',
490
+					),
491
+					'registrations_contact_list_views_help_tab'                 => array(
492
+						'title'    => __('Contact List Views', 'event_espresso'),
493
+						'filename' => 'registrations_contact_list_views',
494
+					),
495
+					'registrations_contact_list_other_help_tab'                 => array(
496
+						'title'    => __('Contact List Other', 'event_espresso'),
497
+						'filename' => 'registrations_contact_list_other',
498
+					),
499
+				),
500
+				'help_tour'     => array('Contact_List_Help_Tour'),
501
+				'metaboxes'     => array(),
502
+				'require_nonce' => false,
503
+			),
504
+			//override default cpt routes
505
+			'create_new'        => '',
506
+			'edit'              => '',
507
+		);
508
+	}
509
+
510
+
511
+	/**
512
+	 * The below methods aren't used by this class currently
513
+	 */
514
+	protected function _add_screen_options()
515
+	{
516
+	}
517
+
518
+
519
+	protected function _add_feature_pointers()
520
+	{
521
+	}
522
+
523
+
524
+	public function admin_init()
525
+	{
526
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
+			'event_espresso');
528
+	}
529
+
530
+
531
+	public function admin_notices()
532
+	{
533
+	}
534
+
535
+
536
+	public function admin_footer_scripts()
537
+	{
538
+	}
539
+
540
+
541
+	/**
542
+	 *        get list of registration statuses
543
+	 *
544
+	 * @access private
545
+	 * @return void
546
+	 */
547
+	private function _get_registration_status_array()
548
+	{
549
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
+	}
551
+
552
+
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	protected function _add_screen_options_contact_list()
560
+	{
561
+		$page_title              = $this->_admin_page_title;
562
+		$this->_admin_page_title = __("Contacts", 'event_espresso');
563
+		$this->_per_page_screen_option();
564
+		$this->_admin_page_title = $page_title;
565
+	}
566
+
567
+
568
+	public function load_scripts_styles()
569
+	{
570
+		//style
571
+		//wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
+		wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
+			EVENT_ESPRESSO_VERSION);
574
+		wp_enqueue_style('espresso_reg');
575
+		//script
576
+		wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
+		wp_enqueue_script('espresso_reg');
579
+	}
580
+
581
+
582
+	public function load_scripts_styles_edit_attendee()
583
+	{
584
+		//stuff to only show up on our attendee edit details page.
585
+		$attendee_details_translations = array(
586
+			'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
+				$this->_cpt_model_obj->get_datetime('ATT_created')),
588
+		);
589
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
+		wp_enqueue_script('jquery-validate');
591
+	}
592
+
593
+
594
+	public function load_scripts_styles_view_registration()
595
+	{
596
+		//styles
597
+		wp_enqueue_style('espresso-ui-theme');
598
+		//scripts
599
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
600
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
+	}
602
+
603
+
604
+	public function load_scripts_styles_contact_list()
605
+	{
606
+		wp_deregister_style('espresso_reg');
607
+		wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
+			EVENT_ESPRESSO_VERSION);
609
+		wp_enqueue_style('espresso_att');
610
+	}
611
+
612
+
613
+	public function load_scripts_styles_new_registration()
614
+	{
615
+		wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
+			EVENT_ESPRESSO_VERSION, true);
617
+		wp_enqueue_script('ee-spco-for-admin');
618
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
+		EE_Form_Section_Proper::wp_enqueue_scripts();
620
+		EED_Ticket_Selector::load_tckt_slctr_assets();
621
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
622
+	}
623
+
624
+
625
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
+	{
627
+		add_filter('FHEE_load_EE_messages', '__return_true');
628
+	}
629
+
630
+
631
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
+	{
633
+		add_filter('FHEE_load_EE_messages', '__return_true');
634
+	}
635
+
636
+
637
+	protected function _set_list_table_views_default()
638
+	{
639
+		//for notification related bulk actions we need to make sure only active messengers have an option.
640
+		EED_Messages::set_autoloaders();
641
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
642
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
644
+		//key= bulk_action_slug, value= message type.
645
+		$match_array = array(
646
+			'approve_registration'    => 'registration',
647
+			'decline_registration'    => 'declined_registration',
648
+			'pending_registration'    => 'pending_approval',
649
+			'no_approve_registration' => 'not_approved_registration',
650
+			'cancel_registration'     => 'cancelled_registration',
651
+		);
652
+		/** setup reg status bulk actions **/
653
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
+		if (in_array($match_array['approve_registration'], $active_mts)
655
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
+		) {
657
+			$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
+				'event_espresso');
659
+		}
660
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
+		if (in_array($match_array['decline_registration'], $active_mts)
662
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
+		) {
664
+			$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
+				'event_espresso');
666
+		}
667
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
+		if (in_array($match_array['pending_registration'], $active_mts)
669
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
+		) {
671
+			$def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
+				'event_espresso');
673
+		}
674
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
+		if (in_array($match_array['no_approve_registration'], $active_mts)
676
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
+		) {
678
+			$def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
+				'event_espresso');
680
+		}
681
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
+		if (in_array($match_array['cancel_registration'], $active_mts)
683
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
+		) {
685
+			$def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
+				'event_espresso');
687
+		}
688
+		$this->_views = array(
689
+			'all'   => array(
690
+				'slug'        => 'all',
691
+				'label'       => __('View All Registrations', 'event_espresso'),
692
+				'count'       => 0,
693
+				'bulk_action' => array_merge($def_reg_status_actions, array(
694
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
+				)),
696
+			),
697
+			'month' => array(
698
+				'slug'        => 'month',
699
+				'label'       => __('This Month', 'event_espresso'),
700
+				'count'       => 0,
701
+				'bulk_action' => array_merge($def_reg_status_actions, array(
702
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
+				)),
704
+			),
705
+			'today' => array(
706
+				'slug'        => 'today',
707
+				'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
+				'count'       => 0,
709
+				'bulk_action' => array_merge($def_reg_status_actions, array(
710
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
+				)),
712
+			),
713
+		);
714
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
+			'espresso_registrations_delete_registration')
716
+		) {
717
+			$this->_views['incomplete'] = array(
718
+				'slug'        => 'incomplete',
719
+				'label'       => __('Incomplete', 'event_espresso'),
720
+				'count'       => 0,
721
+				'bulk_action' => array(
722
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
+				),
724
+			);
725
+			$this->_views['trash']      = array(
726
+				'slug'        => 'trash',
727
+				'label'       => __('Trash', 'event_espresso'),
728
+				'count'       => 0,
729
+				'bulk_action' => array(
730
+					'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
+					'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
+				),
733
+			);
734
+		}
735
+	}
736
+
737
+
738
+	protected function _set_list_table_views_contact_list()
739
+	{
740
+		$this->_views = array(
741
+			'in_use' => array(
742
+				'slug'        => 'in_use',
743
+				'label'       => __('In Use', 'event_espresso'),
744
+				'count'       => 0,
745
+				'bulk_action' => array(
746
+					'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
+				),
748
+			),
749
+		);
750
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
+			'espresso_registrations_trash_attendees')
752
+		) {
753
+			$this->_views['trash'] = array(
754
+				'slug'        => 'trash',
755
+				'label'       => __('Trash', 'event_espresso'),
756
+				'count'       => 0,
757
+				'bulk_action' => array(
758
+					'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
+				),
760
+			);
761
+		}
762
+	}
763
+
764
+
765
+	protected function _registration_legend_items()
766
+	{
767
+		$fc_items = array(
768
+			'star-icon'        => array(
769
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
+				'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
+			),
772
+			'view_details'     => array(
773
+				'class' => 'dashicons dashicons-clipboard',
774
+				'desc'  => __('View Registration Details', 'event_espresso'),
775
+			),
776
+			'edit_attendee'    => array(
777
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
+				'desc'  => __('Edit Contact Details', 'event_espresso'),
779
+			),
780
+			'view_transaction' => array(
781
+				'class' => 'dashicons dashicons-cart',
782
+				'desc'  => __('View Transaction Details', 'event_espresso'),
783
+			),
784
+			'view_invoice'     => array(
785
+				'class' => 'dashicons dashicons-media-spreadsheet',
786
+				'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
+			),
788
+		);
789
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
+			'espresso_registrations_resend_registration')
791
+		) {
792
+			$fc_items['resend_registration'] = array(
793
+				'class' => 'dashicons dashicons-email-alt',
794
+				'desc'  => __('Resend Registration Details', 'event_espresso'),
795
+			);
796
+		} else {
797
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
+		}
799
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
+				$fc_items['view_related_messages'] = array(
803
+					'class' => $related_for_icon['css_class'],
804
+					'desc'  => $related_for_icon['label'],
805
+				);
806
+			}
807
+		}
808
+		$sc_items = array(
809
+			'approved_status'   => array(
810
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
+			),
813
+			'pending_status'    => array(
814
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
+			),
817
+			'wait_list'         => array(
818
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
+			),
821
+			'incomplete_status' => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
+			),
825
+			'not_approved'      => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
+			),
829
+			'declined_status'   => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
+			),
833
+			'cancelled_status'  => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
+			),
837
+		);
838
+		return array_merge($fc_items, $sc_items);
839
+	}
840
+
841
+
842
+
843
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
844
+	/**
845
+	 * @throws \EE_Error
846
+	 */
847
+	protected function _registrations_overview_list_table()
848
+	{
849
+		$this->_template_args['admin_page_header'] = '';
850
+		$EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
+		if ($EVT_ID) {
852
+			if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
+				'espresso_registrations_new_registration', $EVT_ID)
854
+			) {
855
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
+						array('event_id' => $EVT_ID), 'add-new-h2');
857
+			}
858
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
+			if ($event instanceof EE_Event) {
860
+				$this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
+					'event_espresso'), '<h3 style="line-height:1.5em;">',
862
+					'<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
+						'action' => 'edit',
864
+						'post'   => $event->ID(),
865
+					), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
+			}
867
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
+				$this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
+				$this->_template_args['admin_page_header'] .= $datetime->name();
874
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
876
+			}
877
+		}
878
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
+		$this->display_admin_list_table_page_with_no_sidebar();
880
+	}
881
+
882
+
883
+	/**
884
+	 * This sets the _registration property for the registration details screen
885
+	 *
886
+	 * @access private
887
+	 * @return bool
888
+	 */
889
+	private function _set_registration_object()
890
+	{
891
+		//get out if we've already set the object
892
+		if (is_object($this->_registration)) {
893
+			return true;
894
+		}
895
+		$REG    = EEM_Registration::instance();
896
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
+			return true;
899
+		} else {
900
+			$error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
+				'event_espresso'), $REG_ID);
902
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
+			$this->_registration = null;
904
+			return false;
905
+		}
906
+	}
907
+
908
+
909
+	/**
910
+	 * Used to retrieve registrations for the list table.
911
+	 *
912
+	 * @param int    $per_page
913
+	 * @param bool   $count
914
+	 * @param bool   $this_month
915
+	 * @param bool   $today
916
+	 * @return \EE_Registration[]|int
917
+	 */
918
+	public function get_registrations(
919
+		$per_page = 10,
920
+		$count = false,
921
+		$this_month = false,
922
+		$today = false
923
+	) {
924
+		if( $this_month ) {
925
+			$this->_req_data['status'] = 'month';
926
+		}
927
+		if( $today ) {
928
+			$this->_req_data['status'] = 'today';
929
+		}
930
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
+		/**
932
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
933
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
934
+		 * @see EEM_Base::get_all()
935
+		 */
936
+		$query_params['group_by'] = '';
937
+
938
+		return $count
939
+			? EEM_Registration::instance()->count($query_params)
940
+			/** @type EE_Registration[] */
941
+			: EEM_Registration::instance()->get_all($query_params);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
948
+	 * Note: this listens to values on the request for some of the query parameters.
949
+	 *
950
+	 * @param array $request
951
+	 * @param int    $per_page
952
+	 * @param bool   $count
953
+	 * @return array
954
+	 */
955
+	protected function _get_registration_query_parameters(
956
+		$request = array(),
957
+		$per_page = 10,
958
+		$count = false
959
+	) {
960
+
961
+		$query_params = array(
962
+			0                          => $this->_get_where_conditions_for_registrations_query(
963
+				$request
964
+			),
965
+			'caps'                     => EEM_Registration::caps_read_admin,
966
+			'default_where_conditions' => 'this_model_only',
967
+		);
968
+		if ( ! $count) {
969
+			$query_params = array_merge(
970
+				$query_params,
971
+				$this->_get_orderby_for_registrations_query(),
972
+				$this->_get_limit($per_page)
973
+			);
974
+		}
975
+
976
+		return $query_params;
977
+	}
978
+
979
+
980
+	/**
981
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
982
+	 *
983
+	 * @param array $request usually the same as $this->_req_data but not necessarily
984
+	 * @return array
985
+	 */
986
+	protected function _add_event_id_to_where_conditions(array $request)
987
+	{
988
+		$where = array();
989
+		if ( ! empty($request['event_id'])) {
990
+			$where['EVT_ID'] = absint($request['event_id']);
991
+		}
992
+		return $where;
993
+	}
994
+
995
+
996
+	/**
997
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
998
+	 *
999
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1000
+	 * @return array
1001
+	 */
1002
+	protected function _add_category_id_to_where_conditions(array $request)
1003
+	{
1004
+		$where = array();
1005
+		if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1006
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1007
+		}
1008
+		return $where;
1009
+	}
1010
+
1011
+
1012
+	/**
1013
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1014
+	 *
1015
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1016
+	 * @return array
1017
+	 */
1018
+	protected function _add_datetime_id_to_where_conditions(array $request)
1019
+	{
1020
+		$where = array();
1021
+		if ( ! empty($request['datetime_id'])) {
1022
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1023
+		}
1024
+		if( ! empty($request['DTT_ID'])){
1025
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1026
+		}
1027
+		return $where;
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * Adds the correct registration status to the where conditions for the registrations query.
1033
+	 *
1034
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1035
+	 * @return array
1036
+	 */
1037
+	protected function _add_registration_status_to_where_conditions(array $request)
1038
+	{
1039
+		$where = array();
1040
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1041
+		$registration_status = ! empty($request['_reg_status'])
1042
+			? sanitize_text_field($request['_reg_status'])
1043
+			: '';
1044
+
1045
+		/*
1046 1046
          * If filtering by registration status, then we show registrations matching that status.
1047 1047
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations UNLESS
1048 1048
          * viewing trashed registrations.
1049 1049
          */
1050
-        if ( ! empty($registration_status)) {
1051
-            $where['STS_ID'] = $registration_status;
1052
-        } else {
1053
-            //make sure we exclude incomplete registrations, but only if not trashed.
1054
-            if ($view === 'trash') {
1055
-                $where['REG_deleted'] = true;
1056
-            } else if ($view === 'incomplete') {
1057
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1058
-            } else {
1059
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1060
-            }
1061
-        }
1062
-        return $where;
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * Adds any provided date restraints to the where conditions for the registrations query.
1068
-     *
1069
-     * @param array $request usually the same as $this->_req_data but not necessarily
1070
-     * @return array
1071
-     */
1072
-    protected function _add_date_to_where_conditions(array $request)
1073
-    {
1074
-        $where = array();
1075
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1076
-        $month_range             = ! empty($request['month_range'])
1077
-            ? sanitize_text_field($request['month_range'])
1078
-            : '';
1079
-        $retrieve_for_today      = $view === 'today';
1080
-        $retrieve_for_this_month = $view === 'month';
1081
-
1082
-        if ($retrieve_for_today) {
1083
-            $now               = date('Y-m-d', current_time('timestamp'));
1084
-            $where['REG_date'] = array(
1085
-                'BETWEEN',
1086
-                array(
1087
-                    EEM_Registration::instance()->convert_datetime_for_query(
1088
-                        'REG_date',
1089
-                        $now . ' 00:00:00',
1090
-                        'Y-m-d H:i:s'
1091
-                    ),
1092
-                    EEM_Registration::instance()->convert_datetime_for_query(
1093
-                        'REG_date',
1094
-                        $now . ' 23:59:59',
1095
-                        'Y-m-d H:i:s'
1096
-                    ),
1097
-                ),
1098
-            );
1099
-        } elseif ($retrieve_for_this_month) {
1100
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1101
-            $days_this_month        = date('t', current_time('timestamp'));
1102
-            $where['REG_date']      = array(
1103
-                'BETWEEN',
1104
-                array(
1105
-                    EEM_Registration::instance()->convert_datetime_for_query(
1106
-                        'REG_date',
1107
-                        $current_year_and_month . '-01 00:00:00',
1108
-                        'Y-m-d H:i:s'
1109
-                    ),
1110
-                    EEM_Registration::instance()->convert_datetime_for_query(
1111
-                        'REG_date',
1112
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1113
-                        'Y-m-d H:i:s'
1114
-                    ),
1115
-                ),
1116
-            );
1117
-        } elseif ($month_range) {
1118
-            $pieces          = explode(' ', $month_range, 3);
1119
-            $month_requested = ! empty($pieces[0])
1120
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1121
-                : '';
1122
-            $year_requested  = ! empty($pieces[1])
1123
-                ? $pieces[1]
1124
-                : '';
1125
-            //if there is not a month or year then we can't go further
1126
-            if ($month_requested && $year_requested) {
1127
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1128
-                $where['REG_date'] = array(
1129
-                    'BETWEEN',
1130
-                    array(
1131
-                        EEM_Registration::instance()->convert_datetime_for_query(
1132
-                            'REG_date',
1133
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1134
-                            'Y-m-d H:i:s'
1135
-                        ),
1136
-                        EEM_Registration::instance()->convert_datetime_for_query(
1137
-                            'REG_date',
1138
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1139
-                            'Y-m-d H:i:s'
1140
-                        ),
1141
-                    ),
1142
-                );
1143
-            }
1144
-        }
1145
-        return $where;
1146
-    }
1147
-
1148
-
1149
-    /**
1150
-     * Adds any provided search restraints to the where conditions for the registrations query
1151
-     *
1152
-     * @param array $request usually the same as $this->_req_data but not necessarily
1153
-     * @return array
1154
-     */
1155
-    protected function _add_search_to_where_conditions(array $request)
1156
-    {
1157
-        $where = array();
1158
-        if ( ! empty($request['s'])) {
1159
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1160
-            $where['OR'] = array(
1161
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1162
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1163
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1164
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1165
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1166
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1167
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1168
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1169
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1170
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1171
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1172
-                'REG_final_price'                         => array('LIKE', $search_string),
1173
-                'REG_code'                                => array('LIKE', $search_string),
1174
-                'REG_count'                               => array('LIKE', $search_string),
1175
-                'REG_group_size'                          => array('LIKE', $search_string),
1176
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1177
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1178
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1179
-            );
1180
-        }
1181
-        return $where;
1182
-    }
1183
-
1184
-
1185
-    /**
1186
-     * Sets up the where conditions for the registrations query.
1187
-     *
1188
-     * @param array $request
1189
-     * @return array
1190
-     */
1191
-    protected function _get_where_conditions_for_registrations_query($request)
1192
-    {
1193
-        return array_merge(
1194
-            $this->_add_event_id_to_where_conditions($request),
1195
-            $this->_add_category_id_to_where_conditions($request),
1196
-            $this->_add_datetime_id_to_where_conditions($request),
1197
-            $this->_add_registration_status_to_where_conditions($request),
1198
-            $this->_add_date_to_where_conditions($request),
1199
-            $this->_add_search_to_where_conditions($request)
1200
-        );
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * Sets up the orderby for the registrations query.
1206
-     *
1207
-     * @return array
1208
-     */
1209
-    protected function _get_orderby_for_registrations_query()
1210
-    {
1211
-        $orderby_field = ! empty($this->_req_data['orderby'])
1212
-            ? sanitize_text_field($this->_req_data['orderby'])
1213
-            : '';
1214
-        switch ($orderby_field) {
1215
-            case '_REG_ID':
1216
-                $orderby_field = 'REG_ID';
1217
-                break;
1218
-            case '_Reg_status':
1219
-                $orderby_field = 'STS_ID';
1220
-                break;
1221
-            case 'ATT_fname':
1222
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1223
-                break;
1224
-            case 'ATT_lname' :
1225
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1226
-                break;
1227
-            case 'event_name':
1228
-                $orderby_field = 'Event.EVT_name';
1229
-                break;
1230
-            case 'DTT_EVT_start':
1231
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1232
-                break;
1233
-            default: //'REG_date'
1234
-                $orderby_field = 'REG_date';
1235
-        }
1236
-
1237
-        //order
1238
-        $order = ! empty($this->_req_data['order'])
1239
-            ? sanitize_text_field($this->_req_data['order'])
1240
-            : 'DESC';
1241
-
1242
-        //mutate orderby_field
1243
-        $orderby_field = array_combine(
1244
-                (array) $orderby_field,
1245
-                array_fill(0, count($orderby_field), $order)
1246
-            );
1247
-        return array('order_by' => $orderby_field);
1248
-    }
1249
-
1250
-
1251
-    /**
1252
-     * Sets up the limit for the registrations query.
1253
-     *
1254
-     * @param $per_page
1255
-     * @return array
1256
-     */
1257
-    protected function _get_limit($per_page)
1258
-    {
1259
-        $current_page = ! empty($this->_req_data['paged'])
1260
-            ? absint($this->_req_data['paged'])
1261
-            : 1;
1262
-        $per_page     = ! empty($this->_req_data['perpage'])
1263
-            ? $this->_req_data['perpage']
1264
-            : $per_page;
1265
-
1266
-        //-1 means return all results so get out if that's set.
1267
-        if ((int)$per_page === -1) {
1268
-            return array();
1269
-        }
1270
-        $per_page = absint($per_page);
1271
-        $offset   = ($current_page - 1) * $per_page;
1272
-        return array('limit' => array($offset, $per_page));
1273
-    }
1274
-
1275
-
1276
-    public function get_registration_status_array()
1277
-    {
1278
-        return self::$_reg_status;
1279
-    }
1280
-
1281
-
1282
-
1283
-
1284
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1285
-    /**
1286
-     *        generates HTML for the View Registration Details Admin page
1287
-     *
1288
-     * @access protected
1289
-     * @return void
1290
-     */
1291
-    protected function _registration_details()
1292
-    {
1293
-        $this->_template_args = array();
1294
-        $this->_set_registration_object();
1295
-        if (is_object($this->_registration)) {
1296
-            $transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1297
-                : EE_Transaction::new_instance();
1298
-            $this->_session                                = $transaction->session_data();
1299
-            $event_id                                      = $this->_registration->event_ID();
1300
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1301
-            $this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1302
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1303
-            $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1304
-            $this->_template_args['grand_total']           = $transaction->total();
1305
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1306
-            // link back to overview
1307
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1308
-            $this->_template_args['registration']                = $this->_registration;
1309
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1310
-                'action'   => 'default',
1311
-                'event_id' => $event_id,
1312
-            ), REG_ADMIN_URL);
1313
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1314
-                'action' => 'default',
1315
-                'EVT_ID' => $event_id,
1316
-                'page'   => 'espresso_transactions',
1317
-            ), admin_url('admin.php'));
1318
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1319
-                'page'   => 'espresso_events',
1320
-                'action' => 'edit',
1321
-                'post'   => $event_id,
1322
-            ), admin_url('admin.php'));
1323
-            //next and previous links
1324
-            $next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1325
-            $this->_template_args['next_registration']     = $next_reg
1326
-                ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1327
-                    'action'  => 'view_registration',
1328
-                    '_REG_ID' => $next_reg['REG_ID'],
1329
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1330
-            $previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1331
-            $this->_template_args['previous_registration'] = $previous_reg
1332
-                ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1333
-                    'action'  => 'view_registration',
1334
-                    '_REG_ID' => $previous_reg['REG_ID'],
1335
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1336
-            // grab header
1337
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1338
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1339
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1340
-                $this->_template_args, true);
1341
-        } else {
1342
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1343
-        }
1344
-        // the details template wrapper
1345
-        $this->display_admin_page_with_sidebar();
1346
-    }
1347
-
1348
-
1349
-    protected function _registration_details_metaboxes()
1350
-    {
1351
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1352
-        $this->_set_registration_object();
1353
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1354
-        add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1355
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1356
-        add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1357
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1358
-        if ($attendee instanceof EE_Attendee
1359
-            && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1360
-        ) {
1361
-            add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1362
-                array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1363
-        }
1364
-        add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1365
-            array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1366
-        if ($this->_registration->group_size() > 1) {
1367
-            add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1368
-                array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1369
-        }
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * set_reg_status_buttons_metabox
1375
-     *
1376
-     * @access protected
1377
-     * @return string
1378
-     * @throws \EE_Error
1379
-     */
1380
-    public function set_reg_status_buttons_metabox()
1381
-    {
1382
-        $this->_set_registration_object();
1383
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1384
-        echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1385
-            'action' => 'change_reg_status',
1386
-        ), REG_ADMIN_URL));
1387
-        echo $change_reg_status_form->get_html();
1388
-        echo $change_reg_status_form->form_close();
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * @return EE_Form_Section_Proper
1394
-     */
1395
-    protected function _generate_reg_status_change_form()
1396
-    {
1397
-        return new EE_Form_Section_Proper(array(
1398
-            'name'            => 'reg_status_change_form',
1399
-            'html_id'         => 'reg-status-change-form',
1400
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1401
-            'subsections'     => array(
1402
-                'return'             => new EE_Hidden_Input(array(
1403
-                    'name'    => 'return',
1404
-                    'default' => 'view_registration',
1405
-                )),
1406
-                'REG_ID'             => new EE_Hidden_Input(array(
1407
-                    'name'    => 'REG_ID',
1408
-                    'default' => $this->_registration->ID(),
1409
-                )),
1410
-                'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1411
-                        'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
-                        '', 'status-' . $this->_registration->status_ID(),
1413
-                        'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1414
-                'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1415
-                    'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1416
-                    'default'         => $this->_registration->status_ID(),
1417
-                )),
1418
-                'send_notifications' => new EE_Yes_No_Input(array(
1419
-                    'html_label_text' => __('Send Related Messages', 'event_espresso'),
1420
-                    'default'         => false,
1421
-                    'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1422
-                        'event_espresso'),
1423
-                )),
1424
-                'submit'             => new EE_Submit_Input(array(
1425
-                    'html_class'      => 'button-primary',
1426
-                    'html_label_text' => '&nbsp;',
1427
-                    'default'         => __('Update Registration Status', 'event_espresso'),
1428
-                )),
1429
-            ),
1430
-        ));
1431
-    }
1432
-
1433
-
1434
-
1435
-    /**
1436
-     * Returns an array of all the buttons for the various statuses and switch status actions
1437
-     *
1438
-     * @return array
1439
-     */
1440
-    protected function _get_reg_statuses()
1441
-    {
1442
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1443
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1444
-        // get current reg status
1445
-        $current_status = $this->_registration->status_ID();
1446
-        // is registration for free event? This will determine whether to display the pending payment option
1447
-        if ($current_status != EEM_Registration::status_id_pending_payment
1448
-            && $this->_registration->transaction()
1449
-                                   ->is_free()
1450
-        ) {
1451
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1452
-        }
1453
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1454
-    }
1455
-
1456
-
1457
-    /**
1458
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1459
-     *
1460
-     * @param bool $status REG status given for changing registrations to.
1461
-     * @param bool $notify Whether to send messages notifications or not.
1462
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1463
-     */
1464
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1465
-    {
1466
-        if (isset($this->_req_data['reg_status_change_form'])) {
1467
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1468
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1469
-        } else {
1470
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1471
-        }
1472
-        $success = $this->_set_registration_status($REG_IDs, $status);
1473
-        //notify?
1474
-        if ($success
1475
-            && $notify
1476
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1477
-                'espresso_registrations_resend_registration')
1478
-        ) {
1479
-            $this->_process_resend_registration();
1480
-        }
1481
-        return $success;
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1487
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1488
-     *
1489
-     * @param array $REG_IDs
1490
-     * @param bool  $status
1491
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1492
-     *               the array of updated registrations).
1493
-     */
1494
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1495
-    {
1496
-        $success = false;
1497
-        // typecast $REG_IDs
1498
-        $REG_IDs = (array)$REG_IDs;
1499
-        if ( ! empty($REG_IDs)) {
1500
-            $success = true;
1501
-            // set default status if none is passed
1502
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1503
-            // sanitize $REG_IDs
1504
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1505
-            //loop through REG_ID's and change status
1506
-            foreach ($REG_IDs as $REG_ID) {
1507
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1508
-                if ($registration instanceof EE_Registration) {
1509
-                    $registration->set_status($status);
1510
-                    $result = $registration->save();
1511
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1512
-                    $success = $result !== false ? $success : false;
1513
-                }
1514
-            }
1515
-        }
1516
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1517
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1518
-        //return $success and processed registrations
1519
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     * Common logic for setting up success message and redirecting to appropriate route
1525
-     *
1526
-     * @param  string $STS_ID status id for the registration changed to
1527
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1528
-     * @return void
1529
-     */
1530
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1531
-    {
1532
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1533
-            : array('success' => false);
1534
-        $success = isset($result['success']) && $result['success'];
1535
-        //setup success message
1536
-        if ($success) {
1537
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1538
-                $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1539
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1540
-            } else {
1541
-                $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1542
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1543
-            }
1544
-            EE_Error::add_success($msg);
1545
-        } else {
1546
-            EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1547
-                __LINE__, __FUNCTION__);
1548
-        }
1549
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1550
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1551
-        } else {
1552
-            $route = array('action' => 'default');
1553
-        }
1554
-        //unset nonces
1555
-        foreach ($this->_req_data as $ref => $value) {
1556
-            if (strpos($ref, 'nonce') !== false) {
1557
-                unset($this->_req_data[$ref]);
1558
-                continue;
1559
-            }
1560
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1561
-            $this->_req_data[$ref] = $value;
1562
-        }
1563
-        //merge request vars so that the reloaded list table contains any existing filter query params
1564
-        $route = array_merge($this->_req_data, $route);
1565
-        $this->_redirect_after_action($success, '', '', $route, true);
1566
-    }
1567
-
1568
-
1569
-    /**
1570
-     * incoming reg status change from reg details page.
1571
-     *
1572
-     * @return void
1573
-     */
1574
-    protected function _change_reg_status()
1575
-    {
1576
-        $this->_req_data['return'] = 'view_registration';
1577
-        //set notify based on whether the send notifications toggle is set or not
1578
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1579
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1580
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1581
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1582
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1583
-            case EEM_Registration::status_id_approved :
1584
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1585
-                $this->approve_registration($notify);
1586
-                break;
1587
-            case EEM_Registration::status_id_pending_payment :
1588
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1589
-                $this->pending_registration($notify);
1590
-                break;
1591
-            case EEM_Registration::status_id_not_approved :
1592
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1593
-                $this->not_approve_registration($notify);
1594
-                break;
1595
-            case EEM_Registration::status_id_declined :
1596
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1597
-                $this->decline_registration($notify);
1598
-                break;
1599
-            case EEM_Registration::status_id_cancelled :
1600
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1601
-                $this->cancel_registration($notify);
1602
-                break;
1603
-            case EEM_Registration::status_id_wait_list :
1604
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1605
-                $this->waitlist_registration($notify);
1606
-                break;
1607
-            case EEM_Registration::status_id_incomplete :
1608
-            default :
1609
-                $result['success'] = false;
1610
-                unset($this->_req_data['return']);
1611
-                $this->_reg_status_change_return('', false);
1612
-                break;
1613
-        }
1614
-    }
1615
-
1616
-
1617
-    /**
1618
-     * approve_registration
1619
-     *
1620
-     * @access protected
1621
-     * @param bool $notify whether or not to notify the registrant about their approval.
1622
-     * @return void
1623
-     */
1624
-    protected function approve_registration($notify = false)
1625
-    {
1626
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     *        decline_registration
1632
-     *
1633
-     * @access protected
1634
-     * @param bool $notify whether or not to notify the registrant about their status change.
1635
-     * @return void
1636
-     */
1637
-    protected function decline_registration($notify = false)
1638
-    {
1639
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1640
-    }
1641
-
1642
-
1643
-    /**
1644
-     *        cancel_registration
1645
-     *
1646
-     * @access protected
1647
-     * @param bool $notify whether or not to notify the registrant about their status change.
1648
-     * @return void
1649
-     */
1650
-    protected function cancel_registration($notify = false)
1651
-    {
1652
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1653
-    }
1654
-
1655
-
1656
-    /**
1657
-     *        not_approve_registration
1658
-     *
1659
-     * @access protected
1660
-     * @param bool $notify whether or not to notify the registrant about their status change.
1661
-     * @return void
1662
-     */
1663
-    protected function not_approve_registration($notify = false)
1664
-    {
1665
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     *        decline_registration
1671
-     *
1672
-     * @access protected
1673
-     * @param bool $notify whether or not to notify the registrant about their status change.
1674
-     * @return void
1675
-     */
1676
-    protected function pending_registration($notify = false)
1677
-    {
1678
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * waitlist_registration
1684
-     *
1685
-     * @access protected
1686
-     * @param bool $notify whether or not to notify the registrant about their status change.
1687
-     * @return void
1688
-     */
1689
-    protected function waitlist_registration($notify = false)
1690
-    {
1691
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     *        generates HTML for the Registration main meta box
1697
-     *
1698
-     * @access public
1699
-     * @return void
1700
-     */
1701
-    public function _reg_details_meta_box()
1702
-    {
1703
-        EEH_Autoloader::register_line_item_display_autoloaders();
1704
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1705
-        EE_Registry::instance()->load_helper('Line_Item');
1706
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1707
-            : EE_Transaction::new_instance();
1708
-        $this->_session = $transaction->session_data();
1709
-        $filters        = new EE_Line_Item_Filter_Collection();
1710
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1711
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1712
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1713
-            $transaction->total_line_item());
1714
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1715
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1716
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1717
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1718
-            array('EE_Registration' => $this->_registration));
1719
-        $attendee                                = $this->_registration->attendee();
1720
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1721
-            'espresso_transactions_view_transaction')
1722
-        ) {
1723
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1724
-                'action' => 'view_transaction',
1725
-                'TXN_ID' => $transaction->ID(),
1726
-            ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1727
-                'dashicons dashicons-cart');
1728
-        } else {
1729
-            $this->_template_args['view_transaction_button'] = '';
1730
-        }
1731
-        if ($attendee instanceof EE_Attendee
1732
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1733
-                'espresso_registrations_resend_registration')
1734
-        ) {
1735
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1736
-                'action'      => 'resend_registration',
1737
-                '_REG_ID'     => $this->_registration->ID(),
1738
-                'redirect_to' => 'view_registration',
1739
-            ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1740
-                'dashicons dashicons-email-alt');
1741
-        } else {
1742
-            $this->_template_args['resend_registration_button'] = '';
1743
-        }
1744
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1745
-        $payment                               = $transaction->get_first_related('Payment');
1746
-        $payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1747
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1748
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1749
-            : $payment_method;
1750
-        $reg_details                           = array(
1751
-            'payment_method'       => $payment_method->name(),
1752
-            'response_msg'         => $payment->gateway_response(),
1753
-            'registration_id'      => $this->_registration->get('REG_code'),
1754
-            'registration_session' => $this->_registration->session_ID(),
1755
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1756
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1757
-        );
1758
-        if (isset($reg_details['registration_id'])) {
1759
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1760
-            $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1761
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1762
-        }
1763
-        if (isset($reg_details['payment_method'])) {
1764
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1765
-            $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1766
-                'event_espresso');
1767
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1768
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1769
-            $this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1770
-                'event_espresso');
1771
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1772
-        }
1773
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1774
-        $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1775
-            'event_espresso');
1776
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1777
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1778
-        $this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1779
-            'event_espresso');
1780
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1781
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1782
-        $this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1783
-            'event_espresso');
1784
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1785
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1786
-            'action'   => 'default',
1787
-            'event_id' => $this->_registration->event_ID(),
1788
-        ), REG_ADMIN_URL);
1789
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
1790
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
1791
-        $template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1792
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1793
-    }
1794
-
1795
-
1796
-    /**
1797
-     * generates HTML for the Registration Questions meta box.
1798
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1799
-     * otherwise uses new forms system
1800
-     *
1801
-     * @access public
1802
-     * @return void
1803
-     */
1804
-    public function _reg_questions_meta_box()
1805
-    {
1806
-        //allow someone to override this method entirely
1807
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1808
-            $this->_registration)) {
1809
-            $form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1810
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1811
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
1812
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
1813
-            $template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1814
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
1815
-        }
1816
-    }
1817
-
1818
-
1819
-    /**
1820
-     * form_before_question_group
1821
-     *
1822
-     * @deprecated    as of 4.8.32.rc.000
1823
-     * @access        public
1824
-     * @param        string $output
1825
-     * @return        string
1826
-     */
1827
-    public function form_before_question_group($output)
1828
-    {
1829
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1830
-            __('This method would have been protected but was used on a filter callback'
1831
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1832
-            '4.8.32.rc.000');
1833
-        return '
1050
+		if ( ! empty($registration_status)) {
1051
+			$where['STS_ID'] = $registration_status;
1052
+		} else {
1053
+			//make sure we exclude incomplete registrations, but only if not trashed.
1054
+			if ($view === 'trash') {
1055
+				$where['REG_deleted'] = true;
1056
+			} else if ($view === 'incomplete') {
1057
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1058
+			} else {
1059
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1060
+			}
1061
+		}
1062
+		return $where;
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1068
+	 *
1069
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1070
+	 * @return array
1071
+	 */
1072
+	protected function _add_date_to_where_conditions(array $request)
1073
+	{
1074
+		$where = array();
1075
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1076
+		$month_range             = ! empty($request['month_range'])
1077
+			? sanitize_text_field($request['month_range'])
1078
+			: '';
1079
+		$retrieve_for_today      = $view === 'today';
1080
+		$retrieve_for_this_month = $view === 'month';
1081
+
1082
+		if ($retrieve_for_today) {
1083
+			$now               = date('Y-m-d', current_time('timestamp'));
1084
+			$where['REG_date'] = array(
1085
+				'BETWEEN',
1086
+				array(
1087
+					EEM_Registration::instance()->convert_datetime_for_query(
1088
+						'REG_date',
1089
+						$now . ' 00:00:00',
1090
+						'Y-m-d H:i:s'
1091
+					),
1092
+					EEM_Registration::instance()->convert_datetime_for_query(
1093
+						'REG_date',
1094
+						$now . ' 23:59:59',
1095
+						'Y-m-d H:i:s'
1096
+					),
1097
+				),
1098
+			);
1099
+		} elseif ($retrieve_for_this_month) {
1100
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1101
+			$days_this_month        = date('t', current_time('timestamp'));
1102
+			$where['REG_date']      = array(
1103
+				'BETWEEN',
1104
+				array(
1105
+					EEM_Registration::instance()->convert_datetime_for_query(
1106
+						'REG_date',
1107
+						$current_year_and_month . '-01 00:00:00',
1108
+						'Y-m-d H:i:s'
1109
+					),
1110
+					EEM_Registration::instance()->convert_datetime_for_query(
1111
+						'REG_date',
1112
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1113
+						'Y-m-d H:i:s'
1114
+					),
1115
+				),
1116
+			);
1117
+		} elseif ($month_range) {
1118
+			$pieces          = explode(' ', $month_range, 3);
1119
+			$month_requested = ! empty($pieces[0])
1120
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1121
+				: '';
1122
+			$year_requested  = ! empty($pieces[1])
1123
+				? $pieces[1]
1124
+				: '';
1125
+			//if there is not a month or year then we can't go further
1126
+			if ($month_requested && $year_requested) {
1127
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1128
+				$where['REG_date'] = array(
1129
+					'BETWEEN',
1130
+					array(
1131
+						EEM_Registration::instance()->convert_datetime_for_query(
1132
+							'REG_date',
1133
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1134
+							'Y-m-d H:i:s'
1135
+						),
1136
+						EEM_Registration::instance()->convert_datetime_for_query(
1137
+							'REG_date',
1138
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1139
+							'Y-m-d H:i:s'
1140
+						),
1141
+					),
1142
+				);
1143
+			}
1144
+		}
1145
+		return $where;
1146
+	}
1147
+
1148
+
1149
+	/**
1150
+	 * Adds any provided search restraints to the where conditions for the registrations query
1151
+	 *
1152
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1153
+	 * @return array
1154
+	 */
1155
+	protected function _add_search_to_where_conditions(array $request)
1156
+	{
1157
+		$where = array();
1158
+		if ( ! empty($request['s'])) {
1159
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1160
+			$where['OR'] = array(
1161
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1162
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1163
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1164
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1165
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1166
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1167
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1168
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1169
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1170
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1171
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1172
+				'REG_final_price'                         => array('LIKE', $search_string),
1173
+				'REG_code'                                => array('LIKE', $search_string),
1174
+				'REG_count'                               => array('LIKE', $search_string),
1175
+				'REG_group_size'                          => array('LIKE', $search_string),
1176
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1177
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1178
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1179
+			);
1180
+		}
1181
+		return $where;
1182
+	}
1183
+
1184
+
1185
+	/**
1186
+	 * Sets up the where conditions for the registrations query.
1187
+	 *
1188
+	 * @param array $request
1189
+	 * @return array
1190
+	 */
1191
+	protected function _get_where_conditions_for_registrations_query($request)
1192
+	{
1193
+		return array_merge(
1194
+			$this->_add_event_id_to_where_conditions($request),
1195
+			$this->_add_category_id_to_where_conditions($request),
1196
+			$this->_add_datetime_id_to_where_conditions($request),
1197
+			$this->_add_registration_status_to_where_conditions($request),
1198
+			$this->_add_date_to_where_conditions($request),
1199
+			$this->_add_search_to_where_conditions($request)
1200
+		);
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * Sets up the orderby for the registrations query.
1206
+	 *
1207
+	 * @return array
1208
+	 */
1209
+	protected function _get_orderby_for_registrations_query()
1210
+	{
1211
+		$orderby_field = ! empty($this->_req_data['orderby'])
1212
+			? sanitize_text_field($this->_req_data['orderby'])
1213
+			: '';
1214
+		switch ($orderby_field) {
1215
+			case '_REG_ID':
1216
+				$orderby_field = 'REG_ID';
1217
+				break;
1218
+			case '_Reg_status':
1219
+				$orderby_field = 'STS_ID';
1220
+				break;
1221
+			case 'ATT_fname':
1222
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1223
+				break;
1224
+			case 'ATT_lname' :
1225
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1226
+				break;
1227
+			case 'event_name':
1228
+				$orderby_field = 'Event.EVT_name';
1229
+				break;
1230
+			case 'DTT_EVT_start':
1231
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1232
+				break;
1233
+			default: //'REG_date'
1234
+				$orderby_field = 'REG_date';
1235
+		}
1236
+
1237
+		//order
1238
+		$order = ! empty($this->_req_data['order'])
1239
+			? sanitize_text_field($this->_req_data['order'])
1240
+			: 'DESC';
1241
+
1242
+		//mutate orderby_field
1243
+		$orderby_field = array_combine(
1244
+				(array) $orderby_field,
1245
+				array_fill(0, count($orderby_field), $order)
1246
+			);
1247
+		return array('order_by' => $orderby_field);
1248
+	}
1249
+
1250
+
1251
+	/**
1252
+	 * Sets up the limit for the registrations query.
1253
+	 *
1254
+	 * @param $per_page
1255
+	 * @return array
1256
+	 */
1257
+	protected function _get_limit($per_page)
1258
+	{
1259
+		$current_page = ! empty($this->_req_data['paged'])
1260
+			? absint($this->_req_data['paged'])
1261
+			: 1;
1262
+		$per_page     = ! empty($this->_req_data['perpage'])
1263
+			? $this->_req_data['perpage']
1264
+			: $per_page;
1265
+
1266
+		//-1 means return all results so get out if that's set.
1267
+		if ((int)$per_page === -1) {
1268
+			return array();
1269
+		}
1270
+		$per_page = absint($per_page);
1271
+		$offset   = ($current_page - 1) * $per_page;
1272
+		return array('limit' => array($offset, $per_page));
1273
+	}
1274
+
1275
+
1276
+	public function get_registration_status_array()
1277
+	{
1278
+		return self::$_reg_status;
1279
+	}
1280
+
1281
+
1282
+
1283
+
1284
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1285
+	/**
1286
+	 *        generates HTML for the View Registration Details Admin page
1287
+	 *
1288
+	 * @access protected
1289
+	 * @return void
1290
+	 */
1291
+	protected function _registration_details()
1292
+	{
1293
+		$this->_template_args = array();
1294
+		$this->_set_registration_object();
1295
+		if (is_object($this->_registration)) {
1296
+			$transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1297
+				: EE_Transaction::new_instance();
1298
+			$this->_session                                = $transaction->session_data();
1299
+			$event_id                                      = $this->_registration->event_ID();
1300
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1301
+			$this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1302
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1303
+			$this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1304
+			$this->_template_args['grand_total']           = $transaction->total();
1305
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1306
+			// link back to overview
1307
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1308
+			$this->_template_args['registration']                = $this->_registration;
1309
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1310
+				'action'   => 'default',
1311
+				'event_id' => $event_id,
1312
+			), REG_ADMIN_URL);
1313
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1314
+				'action' => 'default',
1315
+				'EVT_ID' => $event_id,
1316
+				'page'   => 'espresso_transactions',
1317
+			), admin_url('admin.php'));
1318
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1319
+				'page'   => 'espresso_events',
1320
+				'action' => 'edit',
1321
+				'post'   => $event_id,
1322
+			), admin_url('admin.php'));
1323
+			//next and previous links
1324
+			$next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1325
+			$this->_template_args['next_registration']     = $next_reg
1326
+				? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1327
+					'action'  => 'view_registration',
1328
+					'_REG_ID' => $next_reg['REG_ID'],
1329
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1330
+			$previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1331
+			$this->_template_args['previous_registration'] = $previous_reg
1332
+				? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1333
+					'action'  => 'view_registration',
1334
+					'_REG_ID' => $previous_reg['REG_ID'],
1335
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1336
+			// grab header
1337
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1338
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1339
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1340
+				$this->_template_args, true);
1341
+		} else {
1342
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1343
+		}
1344
+		// the details template wrapper
1345
+		$this->display_admin_page_with_sidebar();
1346
+	}
1347
+
1348
+
1349
+	protected function _registration_details_metaboxes()
1350
+	{
1351
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1352
+		$this->_set_registration_object();
1353
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1354
+		add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1355
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1356
+		add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1357
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1358
+		if ($attendee instanceof EE_Attendee
1359
+			&& EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1360
+		) {
1361
+			add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1362
+				array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1363
+		}
1364
+		add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1365
+			array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1366
+		if ($this->_registration->group_size() > 1) {
1367
+			add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1368
+				array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1369
+		}
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * set_reg_status_buttons_metabox
1375
+	 *
1376
+	 * @access protected
1377
+	 * @return string
1378
+	 * @throws \EE_Error
1379
+	 */
1380
+	public function set_reg_status_buttons_metabox()
1381
+	{
1382
+		$this->_set_registration_object();
1383
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1384
+		echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1385
+			'action' => 'change_reg_status',
1386
+		), REG_ADMIN_URL));
1387
+		echo $change_reg_status_form->get_html();
1388
+		echo $change_reg_status_form->form_close();
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * @return EE_Form_Section_Proper
1394
+	 */
1395
+	protected function _generate_reg_status_change_form()
1396
+	{
1397
+		return new EE_Form_Section_Proper(array(
1398
+			'name'            => 'reg_status_change_form',
1399
+			'html_id'         => 'reg-status-change-form',
1400
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1401
+			'subsections'     => array(
1402
+				'return'             => new EE_Hidden_Input(array(
1403
+					'name'    => 'return',
1404
+					'default' => 'view_registration',
1405
+				)),
1406
+				'REG_ID'             => new EE_Hidden_Input(array(
1407
+					'name'    => 'REG_ID',
1408
+					'default' => $this->_registration->ID(),
1409
+				)),
1410
+				'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1411
+						'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
+						'', 'status-' . $this->_registration->status_ID(),
1413
+						'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1414
+				'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1415
+					'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1416
+					'default'         => $this->_registration->status_ID(),
1417
+				)),
1418
+				'send_notifications' => new EE_Yes_No_Input(array(
1419
+					'html_label_text' => __('Send Related Messages', 'event_espresso'),
1420
+					'default'         => false,
1421
+					'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1422
+						'event_espresso'),
1423
+				)),
1424
+				'submit'             => new EE_Submit_Input(array(
1425
+					'html_class'      => 'button-primary',
1426
+					'html_label_text' => '&nbsp;',
1427
+					'default'         => __('Update Registration Status', 'event_espresso'),
1428
+				)),
1429
+			),
1430
+		));
1431
+	}
1432
+
1433
+
1434
+
1435
+	/**
1436
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1437
+	 *
1438
+	 * @return array
1439
+	 */
1440
+	protected function _get_reg_statuses()
1441
+	{
1442
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1443
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1444
+		// get current reg status
1445
+		$current_status = $this->_registration->status_ID();
1446
+		// is registration for free event? This will determine whether to display the pending payment option
1447
+		if ($current_status != EEM_Registration::status_id_pending_payment
1448
+			&& $this->_registration->transaction()
1449
+								   ->is_free()
1450
+		) {
1451
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1452
+		}
1453
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1454
+	}
1455
+
1456
+
1457
+	/**
1458
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1459
+	 *
1460
+	 * @param bool $status REG status given for changing registrations to.
1461
+	 * @param bool $notify Whether to send messages notifications or not.
1462
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1463
+	 */
1464
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1465
+	{
1466
+		if (isset($this->_req_data['reg_status_change_form'])) {
1467
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1468
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1469
+		} else {
1470
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1471
+		}
1472
+		$success = $this->_set_registration_status($REG_IDs, $status);
1473
+		//notify?
1474
+		if ($success
1475
+			&& $notify
1476
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1477
+				'espresso_registrations_resend_registration')
1478
+		) {
1479
+			$this->_process_resend_registration();
1480
+		}
1481
+		return $success;
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1487
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1488
+	 *
1489
+	 * @param array $REG_IDs
1490
+	 * @param bool  $status
1491
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1492
+	 *               the array of updated registrations).
1493
+	 */
1494
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1495
+	{
1496
+		$success = false;
1497
+		// typecast $REG_IDs
1498
+		$REG_IDs = (array)$REG_IDs;
1499
+		if ( ! empty($REG_IDs)) {
1500
+			$success = true;
1501
+			// set default status if none is passed
1502
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1503
+			// sanitize $REG_IDs
1504
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1505
+			//loop through REG_ID's and change status
1506
+			foreach ($REG_IDs as $REG_ID) {
1507
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1508
+				if ($registration instanceof EE_Registration) {
1509
+					$registration->set_status($status);
1510
+					$result = $registration->save();
1511
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1512
+					$success = $result !== false ? $success : false;
1513
+				}
1514
+			}
1515
+		}
1516
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1517
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1518
+		//return $success and processed registrations
1519
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 * Common logic for setting up success message and redirecting to appropriate route
1525
+	 *
1526
+	 * @param  string $STS_ID status id for the registration changed to
1527
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1528
+	 * @return void
1529
+	 */
1530
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1531
+	{
1532
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1533
+			: array('success' => false);
1534
+		$success = isset($result['success']) && $result['success'];
1535
+		//setup success message
1536
+		if ($success) {
1537
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1538
+				$msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1539
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1540
+			} else {
1541
+				$msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1542
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1543
+			}
1544
+			EE_Error::add_success($msg);
1545
+		} else {
1546
+			EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1547
+				__LINE__, __FUNCTION__);
1548
+		}
1549
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1550
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1551
+		} else {
1552
+			$route = array('action' => 'default');
1553
+		}
1554
+		//unset nonces
1555
+		foreach ($this->_req_data as $ref => $value) {
1556
+			if (strpos($ref, 'nonce') !== false) {
1557
+				unset($this->_req_data[$ref]);
1558
+				continue;
1559
+			}
1560
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1561
+			$this->_req_data[$ref] = $value;
1562
+		}
1563
+		//merge request vars so that the reloaded list table contains any existing filter query params
1564
+		$route = array_merge($this->_req_data, $route);
1565
+		$this->_redirect_after_action($success, '', '', $route, true);
1566
+	}
1567
+
1568
+
1569
+	/**
1570
+	 * incoming reg status change from reg details page.
1571
+	 *
1572
+	 * @return void
1573
+	 */
1574
+	protected function _change_reg_status()
1575
+	{
1576
+		$this->_req_data['return'] = 'view_registration';
1577
+		//set notify based on whether the send notifications toggle is set or not
1578
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1579
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1580
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1581
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1582
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1583
+			case EEM_Registration::status_id_approved :
1584
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1585
+				$this->approve_registration($notify);
1586
+				break;
1587
+			case EEM_Registration::status_id_pending_payment :
1588
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1589
+				$this->pending_registration($notify);
1590
+				break;
1591
+			case EEM_Registration::status_id_not_approved :
1592
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1593
+				$this->not_approve_registration($notify);
1594
+				break;
1595
+			case EEM_Registration::status_id_declined :
1596
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1597
+				$this->decline_registration($notify);
1598
+				break;
1599
+			case EEM_Registration::status_id_cancelled :
1600
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1601
+				$this->cancel_registration($notify);
1602
+				break;
1603
+			case EEM_Registration::status_id_wait_list :
1604
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1605
+				$this->waitlist_registration($notify);
1606
+				break;
1607
+			case EEM_Registration::status_id_incomplete :
1608
+			default :
1609
+				$result['success'] = false;
1610
+				unset($this->_req_data['return']);
1611
+				$this->_reg_status_change_return('', false);
1612
+				break;
1613
+		}
1614
+	}
1615
+
1616
+
1617
+	/**
1618
+	 * approve_registration
1619
+	 *
1620
+	 * @access protected
1621
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1622
+	 * @return void
1623
+	 */
1624
+	protected function approve_registration($notify = false)
1625
+	{
1626
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 *        decline_registration
1632
+	 *
1633
+	 * @access protected
1634
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1635
+	 * @return void
1636
+	 */
1637
+	protected function decline_registration($notify = false)
1638
+	{
1639
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1640
+	}
1641
+
1642
+
1643
+	/**
1644
+	 *        cancel_registration
1645
+	 *
1646
+	 * @access protected
1647
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1648
+	 * @return void
1649
+	 */
1650
+	protected function cancel_registration($notify = false)
1651
+	{
1652
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1653
+	}
1654
+
1655
+
1656
+	/**
1657
+	 *        not_approve_registration
1658
+	 *
1659
+	 * @access protected
1660
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1661
+	 * @return void
1662
+	 */
1663
+	protected function not_approve_registration($notify = false)
1664
+	{
1665
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 *        decline_registration
1671
+	 *
1672
+	 * @access protected
1673
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1674
+	 * @return void
1675
+	 */
1676
+	protected function pending_registration($notify = false)
1677
+	{
1678
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * waitlist_registration
1684
+	 *
1685
+	 * @access protected
1686
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1687
+	 * @return void
1688
+	 */
1689
+	protected function waitlist_registration($notify = false)
1690
+	{
1691
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 *        generates HTML for the Registration main meta box
1697
+	 *
1698
+	 * @access public
1699
+	 * @return void
1700
+	 */
1701
+	public function _reg_details_meta_box()
1702
+	{
1703
+		EEH_Autoloader::register_line_item_display_autoloaders();
1704
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1705
+		EE_Registry::instance()->load_helper('Line_Item');
1706
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1707
+			: EE_Transaction::new_instance();
1708
+		$this->_session = $transaction->session_data();
1709
+		$filters        = new EE_Line_Item_Filter_Collection();
1710
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1711
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1712
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1713
+			$transaction->total_line_item());
1714
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1715
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1716
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1717
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1718
+			array('EE_Registration' => $this->_registration));
1719
+		$attendee                                = $this->_registration->attendee();
1720
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1721
+			'espresso_transactions_view_transaction')
1722
+		) {
1723
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1724
+				'action' => 'view_transaction',
1725
+				'TXN_ID' => $transaction->ID(),
1726
+			), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1727
+				'dashicons dashicons-cart');
1728
+		} else {
1729
+			$this->_template_args['view_transaction_button'] = '';
1730
+		}
1731
+		if ($attendee instanceof EE_Attendee
1732
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1733
+				'espresso_registrations_resend_registration')
1734
+		) {
1735
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1736
+				'action'      => 'resend_registration',
1737
+				'_REG_ID'     => $this->_registration->ID(),
1738
+				'redirect_to' => 'view_registration',
1739
+			), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1740
+				'dashicons dashicons-email-alt');
1741
+		} else {
1742
+			$this->_template_args['resend_registration_button'] = '';
1743
+		}
1744
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1745
+		$payment                               = $transaction->get_first_related('Payment');
1746
+		$payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1747
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1748
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1749
+			: $payment_method;
1750
+		$reg_details                           = array(
1751
+			'payment_method'       => $payment_method->name(),
1752
+			'response_msg'         => $payment->gateway_response(),
1753
+			'registration_id'      => $this->_registration->get('REG_code'),
1754
+			'registration_session' => $this->_registration->session_ID(),
1755
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1756
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1757
+		);
1758
+		if (isset($reg_details['registration_id'])) {
1759
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1760
+			$this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1761
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1762
+		}
1763
+		if (isset($reg_details['payment_method'])) {
1764
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1765
+			$this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1766
+				'event_espresso');
1767
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1768
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1769
+			$this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1770
+				'event_espresso');
1771
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1772
+		}
1773
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1774
+		$this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1775
+			'event_espresso');
1776
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1777
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1778
+		$this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1779
+			'event_espresso');
1780
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1781
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1782
+		$this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1783
+			'event_espresso');
1784
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1785
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1786
+			'action'   => 'default',
1787
+			'event_id' => $this->_registration->event_ID(),
1788
+		), REG_ADMIN_URL);
1789
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
1790
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
1791
+		$template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1792
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1793
+	}
1794
+
1795
+
1796
+	/**
1797
+	 * generates HTML for the Registration Questions meta box.
1798
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1799
+	 * otherwise uses new forms system
1800
+	 *
1801
+	 * @access public
1802
+	 * @return void
1803
+	 */
1804
+	public function _reg_questions_meta_box()
1805
+	{
1806
+		//allow someone to override this method entirely
1807
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1808
+			$this->_registration)) {
1809
+			$form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1810
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1811
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
1812
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
1813
+			$template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1814
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
1815
+		}
1816
+	}
1817
+
1818
+
1819
+	/**
1820
+	 * form_before_question_group
1821
+	 *
1822
+	 * @deprecated    as of 4.8.32.rc.000
1823
+	 * @access        public
1824
+	 * @param        string $output
1825
+	 * @return        string
1826
+	 */
1827
+	public function form_before_question_group($output)
1828
+	{
1829
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1830
+			__('This method would have been protected but was used on a filter callback'
1831
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1832
+			'4.8.32.rc.000');
1833
+		return '
1834 1834
 	<table class="form-table ee-width-100">
1835 1835
 		<tbody>
1836 1836
 			';
1837
-    }
1838
-
1839
-
1840
-    /**
1841
-     * form_after_question_group
1842
-     *
1843
-     * @deprecated    as of 4.8.32.rc.000
1844
-     * @access        public
1845
-     * @param        string $output
1846
-     * @return        string
1847
-     */
1848
-    public function form_after_question_group($output)
1849
-    {
1850
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1851
-            __('This method would have been protected but was used on a filter callback'
1852
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1853
-            '4.8.32.rc.000');
1854
-        return '
1837
+	}
1838
+
1839
+
1840
+	/**
1841
+	 * form_after_question_group
1842
+	 *
1843
+	 * @deprecated    as of 4.8.32.rc.000
1844
+	 * @access        public
1845
+	 * @param        string $output
1846
+	 * @return        string
1847
+	 */
1848
+	public function form_after_question_group($output)
1849
+	{
1850
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1851
+			__('This method would have been protected but was used on a filter callback'
1852
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1853
+			'4.8.32.rc.000');
1854
+		return '
1855 1855
 			<tr class="hide-if-no-js">
1856 1856
 				<th> </th>
1857 1857
 				<td class="reg-admin-edit-attendee-question-td">
1858 1858
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
1859
-               . esc_attr__('click to edit question', 'event_espresso')
1860
-               . '">
1859
+			   . esc_attr__('click to edit question', 'event_espresso')
1860
+			   . '">
1861 1861
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
1862
-               . __('edit the above question group', 'event_espresso')
1863
-               . '</span>
1862
+			   . __('edit the above question group', 'event_espresso')
1863
+			   . '</span>
1864 1864
 						<div class="dashicons dashicons-edit"></div>
1865 1865
 					</a>
1866 1866
 				</td>
@@ -1868,495 +1868,495 @@  discard block
 block discarded – undo
1868 1868
 		</tbody>
1869 1869
 	</table>
1870 1870
 ';
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * form_form_field_label_wrap
1876
-     *
1877
-     * @deprecated    as of 4.8.32.rc.000
1878
-     * @access        public
1879
-     * @param        string $label
1880
-     * @return        string
1881
-     */
1882
-    public function form_form_field_label_wrap($label)
1883
-    {
1884
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1885
-            __('This method would have been protected but was used on a filter callback'
1886
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1887
-            '4.8.32.rc.000');
1888
-        return '
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * form_form_field_label_wrap
1876
+	 *
1877
+	 * @deprecated    as of 4.8.32.rc.000
1878
+	 * @access        public
1879
+	 * @param        string $label
1880
+	 * @return        string
1881
+	 */
1882
+	public function form_form_field_label_wrap($label)
1883
+	{
1884
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1885
+			__('This method would have been protected but was used on a filter callback'
1886
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1887
+			'4.8.32.rc.000');
1888
+		return '
1889 1889
 			<tr>
1890 1890
 				<th>
1891 1891
 					' . $label . '
1892 1892
 				</th>';
1893
-    }
1894
-
1895
-
1896
-    /**
1897
-     * form_form_field_input__wrap
1898
-     *
1899
-     * @deprecated    as of 4.8.32.rc.000
1900
-     * @access        public
1901
-     * @param        string $input
1902
-     * @return        string
1903
-     */
1904
-    public function form_form_field_input__wrap($input)
1905
-    {
1906
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1907
-            __('This method would have been protected but was used on a filter callback'
1908
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1909
-            '4.8.32.rc.000');
1910
-        return '
1893
+	}
1894
+
1895
+
1896
+	/**
1897
+	 * form_form_field_input__wrap
1898
+	 *
1899
+	 * @deprecated    as of 4.8.32.rc.000
1900
+	 * @access        public
1901
+	 * @param        string $input
1902
+	 * @return        string
1903
+	 */
1904
+	public function form_form_field_input__wrap($input)
1905
+	{
1906
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1907
+			__('This method would have been protected but was used on a filter callback'
1908
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1909
+			'4.8.32.rc.000');
1910
+		return '
1911 1911
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
1912 1912
 					' . $input . '
1913 1913
 				</td>
1914 1914
 			</tr>';
1915
-    }
1916
-
1917
-
1918
-    /**
1919
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
1920
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
1921
-     * to display the page
1922
-     *
1923
-     * @access protected
1924
-     * @return void
1925
-     */
1926
-    protected function _update_attendee_registration_form()
1927
-    {
1928
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1929
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1930
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1931
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
1932
-            if ($success) {
1933
-                $what  = __('Registration Form', 'event_espresso');
1934
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1935
-                    : array('action' => 'default');
1936
-                $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1937
-            }
1938
-        }
1939
-    }
1940
-
1941
-
1942
-    /**
1943
-     * Gets the form for saving registrations custom questions (if done
1944
-     * previously retrieves the cached form object, which may have validation errors in it)
1945
-     *
1946
-     * @param int $REG_ID
1947
-     * @return EE_Registration_Custom_Questions_Form
1948
-     */
1949
-    protected function _get_reg_custom_questions_form($REG_ID)
1950
-    {
1951
-        if ( ! $this->_reg_custom_questions_form) {
1952
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1953
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1954
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
1955
-            );
1956
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
1957
-        }
1958
-        return $this->_reg_custom_questions_form;
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     * Saves
1964
-     *
1965
-     * @access private
1966
-     * @param bool $REG_ID
1967
-     * @return bool
1968
-     */
1969
-    private function _save_reg_custom_questions_form($REG_ID = false)
1970
-    {
1971
-        if ( ! $REG_ID) {
1972
-            EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1973
-                __FUNCTION__, __LINE__);
1974
-        }
1975
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
1976
-        $form->receive_form_submission($this->_req_data);
1977
-        $success = false;
1978
-        if ($form->is_valid()) {
1979
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
1980
-                foreach ($question_group_form->inputs() as $question_id => $input) {
1981
-                    $where_conditions    = array(
1982
-                        'QST_ID' => $question_id,
1983
-                        'REG_ID' => $REG_ID,
1984
-                    );
1985
-                    $possibly_new_values = array(
1986
-                        'ANS_value' => $input->normalized_value(),
1987
-                    );
1988
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1989
-                    if ($answer instanceof EE_Answer) {
1990
-                        $success = $answer->save($possibly_new_values);
1991
-                    } else {
1992
-                        //insert it then
1993
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1994
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
1995
-                        $success     = $answer->save();
1996
-                    }
1997
-                }
1998
-            }
1999
-        } else {
2000
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2001
-        }
2002
-        return $success;
2003
-    }
2004
-
2005
-
2006
-    /**
2007
-     *        generates HTML for the Registration main meta box
2008
-     *
2009
-     * @access public
2010
-     * @return void
2011
-     */
2012
-    public function _reg_attendees_meta_box()
2013
-    {
2014
-        $REG = EEM_Registration::instance();
2015
-        //get all other registrations on this transaction, and cache
2016
-        //the attendees for them so we don't have to run another query using force_join
2017
-        $registrations                           = $REG->get_all(array(
2018
-            array(
2019
-                'TXN_ID' => $this->_registration->transaction_ID(),
2020
-                'REG_ID' => array('!=', $this->_registration->ID()),
2021
-            ),
2022
-            'force_join' => array('Attendee'),
2023
-        ));
2024
-        $this->_template_args['attendees']       = array();
2025
-        $this->_template_args['attendee_notice'] = '';
2026
-        if (empty($registrations)
2027
-            || (is_array($registrations)
2028
-                && ! EEH_Array::get_one_item_from_array($registrations))
2029
-        ) {
2030
-            EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2031
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2032
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2033
-        } else {
2034
-            $att_nmbr = 1;
2035
-            foreach ($registrations as $registration) {
2036
-                /* @var $registration EE_Registration */
2037
-                $attendee                                                    = $registration->attendee()
2038
-                    ? $registration->attendee()
2039
-                    : EEM_Attendee::instance()
2040
-                                  ->create_default_object();
2041
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2042
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2046
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2047
-                    $attendee->full_address_as_array());
2048
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2049
-                    'action' => 'edit_attendee',
2050
-                    'post'   => $attendee->ID(),
2051
-                ), REG_ADMIN_URL);
2052
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2053
-                $att_nmbr++;
2054
-            }
2055
-            //EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2056
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2057
-            //			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2058
-        }
2059
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2060
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
-    }
2062
-
2063
-
2064
-    /**
2065
-     *        generates HTML for the Edit Registration side meta box
2066
-     *
2067
-     * @access public
2068
-     * @return void
2069
-     */
2070
-    public function _reg_registrant_side_meta_box()
2071
-    {
2072
-        /*@var $attendee EE_Attendee */
2073
-        $att_check = $this->_registration->attendee();
2074
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2075
-        //now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2076
-        if ( ! $this->_registration->is_primary_registrant()) {
2077
-            $primary_registration = $this->_registration->get_primary_registration();
2078
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2079
-                : null;
2080
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2081
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2082
-                $primary_registration = null;
2083
-            }
2084
-        } else {
2085
-            $primary_registration = null;
2086
-        }
2087
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2088
-        $this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2089
-        $this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2090
-        $this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2091
-        $this->_template_args['phone']             = $attendee->phone();
2092
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2093
-        //edit link
2094
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2095
-            'action' => 'edit_attendee',
2096
-            'post'   => $attendee->ID(),
2097
-        ), REG_ADMIN_URL);
2098
-        $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2099
-        //create link
2100
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2101
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2102
-                'action'  => 'duplicate_attendee',
2103
-                '_REG_ID' => $this->_registration->ID(),
2104
-            ), REG_ADMIN_URL) : '';
2105
-        $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2106
-        $this->_template_args['att_check']    = $att_check;
2107
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2108
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2109
-    }
2110
-
2111
-
2112
-    /**
2113
-     * trash or restore registrations
2114
-     *
2115
-     * @param  boolean $trash whether to archive or restore
2116
-     * @access protected
2117
-     * @return void
2118
-     */
2119
-    protected function _trash_or_restore_registrations($trash = true)
2120
-    {
2121
-        $REGM    = EEM_Registration::instance();
2122
-        $success = 1;
2123
-        $error   = 0;
2124
-        $tickets = array();
2125
-        $dtts    = array();
2126
-        //if empty _REG_ID then get out because there's nothing to do
2127
-        if (empty($this->_req_data['_REG_ID'])) {
2128
-            $msg = $trash
2129
-                ? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.',
2130
-                    'event_espresso')
2131
-                : __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.',
2132
-                    'event_espresso');
2133
-            EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__);
2134
-            $this->_redirect_after_action(false, '', '', array(), true);
2135
-        }
2136
-        //Checkboxes
2137
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2138
-            // if array has more than one element than success message should be plural
2139
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2140
-            // cycle thru checkboxes
2141
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2142
-                /** @var EE_Registration $REG */
2143
-                $REG           = $REGM->get_one_by_ID($REG_ID);
2144
-                $payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
2145
-                if ($payment_count > 0) {
2146
-                    $name    = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name()
2147
-                        : __('Unknown Attendee', 'event_espresso');
2148
-                    $error   = 1;
2149
-                    $success = 0;
2150
-                    EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2151
-                        'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__);
2152
-                    continue; //can't trash this registration because it has payments.
2153
-                }
2154
-                $ticket                 = $REG->get_first_related('Ticket');
2155
-                $tickets[$ticket->ID()] = $ticket;
2156
-                $dtt                    = $ticket->get_many_related('Datetime');
2157
-                $dtts                   = array_merge($dtts, $dtt);
2158
-                $updated                = $trash ? $REG->delete() : $REG->restore();
2159
-                if ( ! $updated) {
2160
-                    $success = 0;
2161
-                } else {
2162
-                    $success = 2;
2163
-                }/**/
2164
-            }
2165
-        } else {
2166
-            // grab single id and delete
2167
-            $REG_ID                 = absint($this->_req_data['_REG_ID']);
2168
-            $REG                    = $REGM->get_one_by_ID($REG_ID);
2169
-            $ticket                 = $REG->get_first_related('Ticket');
2170
-            $tickets[$ticket->ID()] = $ticket;
2171
-            $dtts                   = $ticket->get_many_related('Datetime');
2172
-            $updated                = $trash ? $REG->delete() : $REG->restore();
2173
-            if ( ! $updated) {
2174
-                $success = 0;
2175
-            }
2176
-        }
2177
-        //now let's update counts
2178
-        EEM_Ticket::instance()->update_tickets_sold($tickets);
2179
-        EEM_Datetime::instance()->update_sold($dtts);
2180
-        $what           = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2181
-        $action_desc    = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2182
-        $overwrite_msgs = $error ? true : false;
2183
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs);
2184
-    }
2185
-
2186
-
2187
-    /**
2188
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2189
-     * registration but also.
2190
-     * 1. Removing relations to EE_Attendee
2191
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2192
-     * ALSO trashed.
2193
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2194
-     * 4. Removing relationships between all tickets and the related registrations
2195
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2196
-     * 6. Deleting permanently any related Checkins.
2197
-     *
2198
-     * @return void
2199
-     */
2200
-    protected function _delete_registrations()
2201
-    {
2202
-        $REG_MDL = EEM_Registration::instance();
2203
-        $success = 1;
2204
-        //Checkboxes
2205
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2206
-            // if array has more than one element than success message should be plural
2207
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2208
-            // cycle thru checkboxes
2209
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2210
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2211
-                if ( ! $REG instanceof EE_Registration) {
2212
-                    continue;
2213
-                }
2214
-                $deleted = $this->_delete_registration($REG);
2215
-                if ( ! $deleted) {
2216
-                    $success = 0;
2217
-                }
2218
-            }
2219
-        } else {
2220
-            // grab single id and delete
2221
-            $REG_ID  = $this->_req_data['_REG_ID'];
2222
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2223
-            $deleted = $this->_delete_registration($REG);
2224
-            if ( ! $deleted) {
2225
-                $success = 0;
2226
-            }
2227
-        }
2228
-        $what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2229
-        $action_desc = __('permanently deleted.', 'event_espresso');
2230
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2236
-     * models get affected.
2237
-     *
2238
-     * @param  EE_Registration $REG registration to be deleted permenantly
2239
-     * @return boolean              true = successful deletion, false = fail.
2240
-     */
2241
-    protected function _delete_registration(EE_Registration $REG)
2242
-    {
2243
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2244
-        $TXN         = $REG->get_first_related('Transaction');
2245
-        $REGS        = $TXN->get_many_related('Registration');
2246
-        $all_trashed = true;
2247
-        foreach ($REGS as $registration) {
2248
-            if ( ! $registration->get('REG_deleted')) {
2249
-                $all_trashed = false;
2250
-            }
2251
-        }
2252
-        if ( ! $all_trashed) {
2253
-            EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2254
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2255
-            return false;
2256
-        }
2257
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2258
-        foreach ($REGS as $registration) {
2259
-            //delete related answers
2260
-            $registration->delete_related_permanently('Answer');
2261
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2262
-            $attendee = $registration->get_first_related('Attendee');
2263
-            if ($attendee instanceof EE_Attendee) {
2264
-                $registration->_remove_relation_to($attendee, 'Attendee');
2265
-            }
2266
-            //now remove relationships to tickets on this registration.
2267
-            $registration->_remove_relations('Ticket');
2268
-            //now delete permanently the checkins related to this registration.
2269
-            $registration->delete_related_permanently('Checkin');
2270
-            if ($registration->ID() === $REG->ID()) {
2271
-                continue;
2272
-            } //we don't want to delete permanently the existing registration just yet.
2273
-            //remove relation to transaction for these registrations if NOT the existing registrations
2274
-            $registration->_remove_relations('Transaction');
2275
-            //delete permanently any related messages.
2276
-            $registration->delete_related_permanently('Message');
2277
-            //now delete this registration permanently
2278
-            $registration->delete_permanently();
2279
-        }
2280
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2281
-        //delete the line items related to the transaction for this registration.
2282
-        $TXN->delete_related_permanently('Line_Item');
2283
-        //we need to remove all the relationships on the transaction
2284
-        $TXN->delete_related_permanently('Payment');
2285
-        $TXN->delete_related_permanently('Extra_Meta');
2286
-        $TXN->delete_related_permanently('Message');
2287
-        //now we can delete this REG permanently (and the transaction of course)
2288
-        $REG->delete_related_permanently('Transaction');
2289
-        return $REG->delete_permanently();
2290
-    }
2291
-
2292
-
2293
-    /**
2294
-     *    generates HTML for the Register New Attendee Admin page
2295
-     *
2296
-     * @access private
2297
-     * @throws \EE_Error
2298
-     * @return void
2299
-     */
2300
-    public function new_registration()
2301
-    {
2302
-        if ( ! $this->_set_reg_event()) {
2303
-            throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2304
-                'event_espresso'));
2305
-        }
2306
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2307
-        // gotta start with a clean slate if we're not coming here via ajax
2308
-        if ( ! defined('DOING_AJAX')
2309
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2310
-        ) {
2311
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2312
-        }
2313
-        $this->_template_args['event_name'] = '';
2314
-        // event name
2315
-        if ($this->_reg_event) {
2316
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2317
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2318
-                'action' => 'edit',
2319
-                'post'   => $this->_reg_event->ID(),
2320
-            ), EVENTS_ADMIN_URL);
2321
-            $edit_event_lnk                     = '<a href="'
2322
-                                                  . $edit_event_url
2323
-                                                  . '" title="'
2324
-                                                  . esc_attr__('Edit ', 'event_espresso')
2325
-                                                  . $this->_reg_event->name()
2326
-                                                  . '">'
2327
-                                                  . __('Edit Event', 'event_espresso')
2328
-                                                  . '</a>';
2329
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2330
-                                                   . $edit_event_lnk
2331
-                                                   . '</span>';
2332
-        }
2333
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2334
-        if (defined('DOING_AJAX')) {
2335
-            $this->_return_json();
2336
-        }
2337
-        // grab header
2338
-        $template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2339
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2340
-            $this->_template_args, true);
2341
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2342
-        // the details template wrapper
2343
-        $this->display_admin_page_with_sidebar();
2344
-    }
2345
-
2346
-
2347
-    /**
2348
-     * This returns the content for a registration step
2349
-     *
2350
-     * @access protected
2351
-     * @return string html
2352
-     */
2353
-    protected function _get_registration_step_content()
2354
-    {
2355
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2356
-            $warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2357
-                'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2358
-                '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2359
-            return '
1915
+	}
1916
+
1917
+
1918
+	/**
1919
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
1920
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
1921
+	 * to display the page
1922
+	 *
1923
+	 * @access protected
1924
+	 * @return void
1925
+	 */
1926
+	protected function _update_attendee_registration_form()
1927
+	{
1928
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1929
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1930
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1931
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
1932
+			if ($success) {
1933
+				$what  = __('Registration Form', 'event_espresso');
1934
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1935
+					: array('action' => 'default');
1936
+				$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1937
+			}
1938
+		}
1939
+	}
1940
+
1941
+
1942
+	/**
1943
+	 * Gets the form for saving registrations custom questions (if done
1944
+	 * previously retrieves the cached form object, which may have validation errors in it)
1945
+	 *
1946
+	 * @param int $REG_ID
1947
+	 * @return EE_Registration_Custom_Questions_Form
1948
+	 */
1949
+	protected function _get_reg_custom_questions_form($REG_ID)
1950
+	{
1951
+		if ( ! $this->_reg_custom_questions_form) {
1952
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1953
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1954
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
1955
+			);
1956
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
1957
+		}
1958
+		return $this->_reg_custom_questions_form;
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 * Saves
1964
+	 *
1965
+	 * @access private
1966
+	 * @param bool $REG_ID
1967
+	 * @return bool
1968
+	 */
1969
+	private function _save_reg_custom_questions_form($REG_ID = false)
1970
+	{
1971
+		if ( ! $REG_ID) {
1972
+			EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1973
+				__FUNCTION__, __LINE__);
1974
+		}
1975
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
1976
+		$form->receive_form_submission($this->_req_data);
1977
+		$success = false;
1978
+		if ($form->is_valid()) {
1979
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
1980
+				foreach ($question_group_form->inputs() as $question_id => $input) {
1981
+					$where_conditions    = array(
1982
+						'QST_ID' => $question_id,
1983
+						'REG_ID' => $REG_ID,
1984
+					);
1985
+					$possibly_new_values = array(
1986
+						'ANS_value' => $input->normalized_value(),
1987
+					);
1988
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1989
+					if ($answer instanceof EE_Answer) {
1990
+						$success = $answer->save($possibly_new_values);
1991
+					} else {
1992
+						//insert it then
1993
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1994
+						$answer      = EE_Answer::new_instance($cols_n_vals);
1995
+						$success     = $answer->save();
1996
+					}
1997
+				}
1998
+			}
1999
+		} else {
2000
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2001
+		}
2002
+		return $success;
2003
+	}
2004
+
2005
+
2006
+	/**
2007
+	 *        generates HTML for the Registration main meta box
2008
+	 *
2009
+	 * @access public
2010
+	 * @return void
2011
+	 */
2012
+	public function _reg_attendees_meta_box()
2013
+	{
2014
+		$REG = EEM_Registration::instance();
2015
+		//get all other registrations on this transaction, and cache
2016
+		//the attendees for them so we don't have to run another query using force_join
2017
+		$registrations                           = $REG->get_all(array(
2018
+			array(
2019
+				'TXN_ID' => $this->_registration->transaction_ID(),
2020
+				'REG_ID' => array('!=', $this->_registration->ID()),
2021
+			),
2022
+			'force_join' => array('Attendee'),
2023
+		));
2024
+		$this->_template_args['attendees']       = array();
2025
+		$this->_template_args['attendee_notice'] = '';
2026
+		if (empty($registrations)
2027
+			|| (is_array($registrations)
2028
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2029
+		) {
2030
+			EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2031
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2032
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2033
+		} else {
2034
+			$att_nmbr = 1;
2035
+			foreach ($registrations as $registration) {
2036
+				/* @var $registration EE_Registration */
2037
+				$attendee                                                    = $registration->attendee()
2038
+					? $registration->attendee()
2039
+					: EEM_Attendee::instance()
2040
+								  ->create_default_object();
2041
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2042
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2046
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2047
+					$attendee->full_address_as_array());
2048
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2049
+					'action' => 'edit_attendee',
2050
+					'post'   => $attendee->ID(),
2051
+				), REG_ADMIN_URL);
2052
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2053
+				$att_nmbr++;
2054
+			}
2055
+			//EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2056
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2057
+			//			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2058
+		}
2059
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2060
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
+	}
2062
+
2063
+
2064
+	/**
2065
+	 *        generates HTML for the Edit Registration side meta box
2066
+	 *
2067
+	 * @access public
2068
+	 * @return void
2069
+	 */
2070
+	public function _reg_registrant_side_meta_box()
2071
+	{
2072
+		/*@var $attendee EE_Attendee */
2073
+		$att_check = $this->_registration->attendee();
2074
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2075
+		//now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2076
+		if ( ! $this->_registration->is_primary_registrant()) {
2077
+			$primary_registration = $this->_registration->get_primary_registration();
2078
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2079
+				: null;
2080
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2081
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2082
+				$primary_registration = null;
2083
+			}
2084
+		} else {
2085
+			$primary_registration = null;
2086
+		}
2087
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2088
+		$this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2089
+		$this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2090
+		$this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2091
+		$this->_template_args['phone']             = $attendee->phone();
2092
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2093
+		//edit link
2094
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2095
+			'action' => 'edit_attendee',
2096
+			'post'   => $attendee->ID(),
2097
+		), REG_ADMIN_URL);
2098
+		$this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2099
+		//create link
2100
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2101
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2102
+				'action'  => 'duplicate_attendee',
2103
+				'_REG_ID' => $this->_registration->ID(),
2104
+			), REG_ADMIN_URL) : '';
2105
+		$this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2106
+		$this->_template_args['att_check']    = $att_check;
2107
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2108
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2109
+	}
2110
+
2111
+
2112
+	/**
2113
+	 * trash or restore registrations
2114
+	 *
2115
+	 * @param  boolean $trash whether to archive or restore
2116
+	 * @access protected
2117
+	 * @return void
2118
+	 */
2119
+	protected function _trash_or_restore_registrations($trash = true)
2120
+	{
2121
+		$REGM    = EEM_Registration::instance();
2122
+		$success = 1;
2123
+		$error   = 0;
2124
+		$tickets = array();
2125
+		$dtts    = array();
2126
+		//if empty _REG_ID then get out because there's nothing to do
2127
+		if (empty($this->_req_data['_REG_ID'])) {
2128
+			$msg = $trash
2129
+				? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.',
2130
+					'event_espresso')
2131
+				: __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.',
2132
+					'event_espresso');
2133
+			EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__);
2134
+			$this->_redirect_after_action(false, '', '', array(), true);
2135
+		}
2136
+		//Checkboxes
2137
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2138
+			// if array has more than one element than success message should be plural
2139
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2140
+			// cycle thru checkboxes
2141
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2142
+				/** @var EE_Registration $REG */
2143
+				$REG           = $REGM->get_one_by_ID($REG_ID);
2144
+				$payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
2145
+				if ($payment_count > 0) {
2146
+					$name    = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name()
2147
+						: __('Unknown Attendee', 'event_espresso');
2148
+					$error   = 1;
2149
+					$success = 0;
2150
+					EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2151
+						'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__);
2152
+					continue; //can't trash this registration because it has payments.
2153
+				}
2154
+				$ticket                 = $REG->get_first_related('Ticket');
2155
+				$tickets[$ticket->ID()] = $ticket;
2156
+				$dtt                    = $ticket->get_many_related('Datetime');
2157
+				$dtts                   = array_merge($dtts, $dtt);
2158
+				$updated                = $trash ? $REG->delete() : $REG->restore();
2159
+				if ( ! $updated) {
2160
+					$success = 0;
2161
+				} else {
2162
+					$success = 2;
2163
+				}/**/
2164
+			}
2165
+		} else {
2166
+			// grab single id and delete
2167
+			$REG_ID                 = absint($this->_req_data['_REG_ID']);
2168
+			$REG                    = $REGM->get_one_by_ID($REG_ID);
2169
+			$ticket                 = $REG->get_first_related('Ticket');
2170
+			$tickets[$ticket->ID()] = $ticket;
2171
+			$dtts                   = $ticket->get_many_related('Datetime');
2172
+			$updated                = $trash ? $REG->delete() : $REG->restore();
2173
+			if ( ! $updated) {
2174
+				$success = 0;
2175
+			}
2176
+		}
2177
+		//now let's update counts
2178
+		EEM_Ticket::instance()->update_tickets_sold($tickets);
2179
+		EEM_Datetime::instance()->update_sold($dtts);
2180
+		$what           = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2181
+		$action_desc    = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2182
+		$overwrite_msgs = $error ? true : false;
2183
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs);
2184
+	}
2185
+
2186
+
2187
+	/**
2188
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2189
+	 * registration but also.
2190
+	 * 1. Removing relations to EE_Attendee
2191
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2192
+	 * ALSO trashed.
2193
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2194
+	 * 4. Removing relationships between all tickets and the related registrations
2195
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2196
+	 * 6. Deleting permanently any related Checkins.
2197
+	 *
2198
+	 * @return void
2199
+	 */
2200
+	protected function _delete_registrations()
2201
+	{
2202
+		$REG_MDL = EEM_Registration::instance();
2203
+		$success = 1;
2204
+		//Checkboxes
2205
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2206
+			// if array has more than one element than success message should be plural
2207
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2208
+			// cycle thru checkboxes
2209
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2210
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2211
+				if ( ! $REG instanceof EE_Registration) {
2212
+					continue;
2213
+				}
2214
+				$deleted = $this->_delete_registration($REG);
2215
+				if ( ! $deleted) {
2216
+					$success = 0;
2217
+				}
2218
+			}
2219
+		} else {
2220
+			// grab single id and delete
2221
+			$REG_ID  = $this->_req_data['_REG_ID'];
2222
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2223
+			$deleted = $this->_delete_registration($REG);
2224
+			if ( ! $deleted) {
2225
+				$success = 0;
2226
+			}
2227
+		}
2228
+		$what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2229
+		$action_desc = __('permanently deleted.', 'event_espresso');
2230
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2236
+	 * models get affected.
2237
+	 *
2238
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2239
+	 * @return boolean              true = successful deletion, false = fail.
2240
+	 */
2241
+	protected function _delete_registration(EE_Registration $REG)
2242
+	{
2243
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2244
+		$TXN         = $REG->get_first_related('Transaction');
2245
+		$REGS        = $TXN->get_many_related('Registration');
2246
+		$all_trashed = true;
2247
+		foreach ($REGS as $registration) {
2248
+			if ( ! $registration->get('REG_deleted')) {
2249
+				$all_trashed = false;
2250
+			}
2251
+		}
2252
+		if ( ! $all_trashed) {
2253
+			EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2254
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2255
+			return false;
2256
+		}
2257
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2258
+		foreach ($REGS as $registration) {
2259
+			//delete related answers
2260
+			$registration->delete_related_permanently('Answer');
2261
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2262
+			$attendee = $registration->get_first_related('Attendee');
2263
+			if ($attendee instanceof EE_Attendee) {
2264
+				$registration->_remove_relation_to($attendee, 'Attendee');
2265
+			}
2266
+			//now remove relationships to tickets on this registration.
2267
+			$registration->_remove_relations('Ticket');
2268
+			//now delete permanently the checkins related to this registration.
2269
+			$registration->delete_related_permanently('Checkin');
2270
+			if ($registration->ID() === $REG->ID()) {
2271
+				continue;
2272
+			} //we don't want to delete permanently the existing registration just yet.
2273
+			//remove relation to transaction for these registrations if NOT the existing registrations
2274
+			$registration->_remove_relations('Transaction');
2275
+			//delete permanently any related messages.
2276
+			$registration->delete_related_permanently('Message');
2277
+			//now delete this registration permanently
2278
+			$registration->delete_permanently();
2279
+		}
2280
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2281
+		//delete the line items related to the transaction for this registration.
2282
+		$TXN->delete_related_permanently('Line_Item');
2283
+		//we need to remove all the relationships on the transaction
2284
+		$TXN->delete_related_permanently('Payment');
2285
+		$TXN->delete_related_permanently('Extra_Meta');
2286
+		$TXN->delete_related_permanently('Message');
2287
+		//now we can delete this REG permanently (and the transaction of course)
2288
+		$REG->delete_related_permanently('Transaction');
2289
+		return $REG->delete_permanently();
2290
+	}
2291
+
2292
+
2293
+	/**
2294
+	 *    generates HTML for the Register New Attendee Admin page
2295
+	 *
2296
+	 * @access private
2297
+	 * @throws \EE_Error
2298
+	 * @return void
2299
+	 */
2300
+	public function new_registration()
2301
+	{
2302
+		if ( ! $this->_set_reg_event()) {
2303
+			throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2304
+				'event_espresso'));
2305
+		}
2306
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2307
+		// gotta start with a clean slate if we're not coming here via ajax
2308
+		if ( ! defined('DOING_AJAX')
2309
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2310
+		) {
2311
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2312
+		}
2313
+		$this->_template_args['event_name'] = '';
2314
+		// event name
2315
+		if ($this->_reg_event) {
2316
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2317
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2318
+				'action' => 'edit',
2319
+				'post'   => $this->_reg_event->ID(),
2320
+			), EVENTS_ADMIN_URL);
2321
+			$edit_event_lnk                     = '<a href="'
2322
+												  . $edit_event_url
2323
+												  . '" title="'
2324
+												  . esc_attr__('Edit ', 'event_espresso')
2325
+												  . $this->_reg_event->name()
2326
+												  . '">'
2327
+												  . __('Edit Event', 'event_espresso')
2328
+												  . '</a>';
2329
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2330
+												   . $edit_event_lnk
2331
+												   . '</span>';
2332
+		}
2333
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2334
+		if (defined('DOING_AJAX')) {
2335
+			$this->_return_json();
2336
+		}
2337
+		// grab header
2338
+		$template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2339
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2340
+			$this->_template_args, true);
2341
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2342
+		// the details template wrapper
2343
+		$this->display_admin_page_with_sidebar();
2344
+	}
2345
+
2346
+
2347
+	/**
2348
+	 * This returns the content for a registration step
2349
+	 *
2350
+	 * @access protected
2351
+	 * @return string html
2352
+	 */
2353
+	protected function _get_registration_step_content()
2354
+	{
2355
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2356
+			$warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2357
+				'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2358
+				'<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2359
+			return '
2360 2360
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2361 2361
 	<script >
2362 2362
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2369,658 +2369,658 @@  discard block
 block discarded – undo
2369 2369
 	        }
2370 2370
 	    }, 800 );
2371 2371
 	</script >';
2372
-        }
2373
-        $template_args = array(
2374
-            'title'                    => '',
2375
-            'content'                  => '',
2376
-            'step_button_text'         => '',
2377
-            'show_notification_toggle' => false,
2378
-        );
2379
-        //to indicate we're processing a new registration
2380
-        $hidden_fields = array(
2381
-            'processing_registration' => array(
2382
-                'type'  => 'hidden',
2383
-                'value' => 0,
2384
-            ),
2385
-            'event_id'                => array(
2386
-                'type'  => 'hidden',
2387
-                'value' => $this->_reg_event->ID(),
2388
-            ),
2389
-        );
2390
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2391
-        $cart = EE_Registry::instance()->SSN->cart();
2392
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2393
-        switch ($step) {
2394
-            case 'ticket' :
2395
-                $hidden_fields['processing_registration']['value'] = 1;
2396
-                $template_args['title']                            = __('Step One: Select the Ticket for this registration',
2397
-                    'event_espresso');
2398
-                $template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2399
-                $template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2400
-                    'event_espresso');
2401
-                $template_args['show_notification_toggle']         = false;
2402
-                break;
2403
-            case 'questions' :
2404
-                $hidden_fields['processing_registration']['value'] = 2;
2405
-                $template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2406
-                    'event_espresso');
2407
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2408
-                $template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2409
-                $template_args['step_button_text']         = __('Save Registration and Continue to Details',
2410
-                    'event_espresso');
2411
-                $template_args['show_notification_toggle'] = true;
2412
-                break;
2413
-        }
2414
-        $this->_set_add_edit_form_tags('process_reg_step',
2415
-            $hidden_fields); //we come back to the process_registration_step route.
2416
-        return EEH_Template::display_template(REG_TEMPLATE_PATH
2417
-                                              . 'reg_admin_register_new_attendee_step_content.template.php',
2418
-            $template_args, true);
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     *        set_reg_event
2424
-     *
2425
-     * @access private
2426
-     * @return boolean
2427
-     */
2428
-    private function _set_reg_event()
2429
-    {
2430
-        if (is_object($this->_reg_event)) {
2431
-            return true;
2432
-        }
2433
-        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2434
-        if ( ! $EVT_ID) {
2435
-            return false;
2436
-        }
2437
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2438
-        return true;
2439
-    }
2440
-
2441
-
2442
-    /**
2443
-     * process_reg_step
2444
-     *
2445
-     * @access        public
2446
-     * @return        string
2447
-     * @throws \RuntimeException
2448
-     * @throws \EE_Error
2449
-     */
2450
-    public function process_reg_step()
2451
-    {
2452
-        EE_System::do_not_cache();
2453
-        $this->_set_reg_event();
2454
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2455
-        EE_Registry::instance()->REQ->set('uts', time());
2456
-        //what step are we on?
2457
-        $cart = EE_Registry::instance()->SSN->cart();
2458
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2459
-        //if doing ajax then we need to verify the nonce
2460
-        if (defined('DOING_AJAX')) {
2461
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2462
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2463
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2464
-        }
2465
-        switch ($step) {
2466
-            case 'ticket' :
2467
-                //process ticket selection
2468
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2469
-                if ($success) {
2470
-                    EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2471
-                        'event_espresso'));
2472
-                } else {
2473
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2474
-                }
2475
-                if (defined('DOING_AJAX')) {
2476
-                    $this->new_registration(); //display next step
2477
-                } else {
2478
-                    $query_args = array(
2479
-                        'action'                  => 'new_registration',
2480
-                        'processing_registration' => 1,
2481
-                        'event_id'                => $this->_reg_event->ID(),
2482
-                        'uts'                     => time(),
2483
-                    );
2484
-                    $this->_redirect_after_action(false, '', '', $query_args, true);
2485
-                }
2486
-                break;
2487
-            case 'questions' :
2488
-                if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2489
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2490
-                }
2491
-                //process registration
2492
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2493
-                if ($cart instanceof EE_Cart) {
2494
-                    $grand_total = $cart->get_cart_grand_total();
2495
-                    if ($grand_total instanceof EE_Line_Item) {
2496
-                        $grand_total->save_this_and_descendants_to_txn();
2497
-                    }
2498
-                }
2499
-                if ( ! $transaction instanceof EE_Transaction) {
2500
-                    $query_args = array(
2501
-                        'action'                  => 'new_registration',
2502
-                        'processing_registration' => 2,
2503
-                        'event_id'                => $this->_reg_event->ID(),
2504
-                        'uts'                     => time(),
2505
-                    );
2506
-                    if (defined('DOING_AJAX')) {
2507
-                        //display registration form again because there are errors (maybe validation?)
2508
-                        $this->new_registration();
2509
-                        return;
2510
-                    } else {
2511
-                        $this->_redirect_after_action(false, '', '', $query_args, true);
2512
-                        return;
2513
-                    }
2514
-                }
2515
-                // maybe update status, and make sure to save transaction if not done already
2516
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2517
-                    $transaction->save();
2518
-                }
2519
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2520
-                $this->_req_data = array();
2521
-                $query_args      = array(
2522
-                    'action'        => 'redirect_to_txn',
2523
-                    'TXN_ID'        => $transaction->ID(),
2524
-                    'EVT_ID'        => $this->_reg_event->ID(),
2525
-                    'event_name'    => urlencode($this->_reg_event->name()),
2526
-                    'redirect_from' => 'new_registration',
2527
-                );
2528
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2529
-                break;
2530
-        }
2531
-        //what are you looking here for?  Should be nothing to do at this point.
2532
-    }
2533
-
2534
-
2535
-    /**
2536
-     * redirect_to_txn
2537
-     *
2538
-     * @access public
2539
-     * @return void
2540
-     */
2541
-    public function redirect_to_txn()
2542
-    {
2543
-        EE_System::do_not_cache();
2544
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2545
-        $query_args = array(
2546
-            'action' => 'view_transaction',
2547
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2548
-            'page'   => 'espresso_transactions',
2549
-        );
2550
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2551
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2552
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2553
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2554
-        }
2555
-        EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2556
-            'event_espresso'));
2557
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2558
-    }
2559
-
2560
-
2561
-    /**
2562
-     *        generates HTML for the Attendee Contact List
2563
-     *
2564
-     * @access protected
2565
-     * @return void
2566
-     */
2567
-    protected function _attendee_contact_list_table()
2568
-    {
2569
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2570
-        $this->_search_btn_label = __('Contacts', 'event_espresso');
2571
-        $this->display_admin_list_table_page_with_no_sidebar();
2572
-    }
2573
-
2574
-
2575
-    /**
2576
-     *        get_attendees
2577
-     *
2578
-     * @param bool $count whether to return count or data.
2579
-     * @access public
2580
-     * @return array
2581
-     */
2582
-    public function get_attendees($per_page, $count = false, $trash = false)
2583
-    {
2584
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2585
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2586
-        $ATT_MDL                    = EEM_Attendee::instance();
2587
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2588
-        switch ($this->_req_data['orderby']) {
2589
-            case 'ATT_ID':
2590
-                $orderby = 'ATT_ID';
2591
-                break;
2592
-            case 'ATT_fname':
2593
-                $orderby = 'ATT_fname';
2594
-                break;
2595
-            case 'ATT_email':
2596
-                $orderby = 'ATT_email';
2597
-                break;
2598
-            case 'ATT_city':
2599
-                $orderby = 'ATT_city';
2600
-                break;
2601
-            case 'STA_ID':
2602
-                $orderby = 'STA_ID';
2603
-                break;
2604
-            case 'CNT_ID':
2605
-                $orderby = 'CNT_ID';
2606
-                break;
2607
-            default:
2608
-                $orderby = 'ATT_lname';
2609
-        }
2610
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2611
-            : 'ASC';
2612
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2613
-            ? $this->_req_data['paged'] : 1;
2614
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2615
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2616
-            ? $this->_req_data['perpage'] : $per_page;
2617
-        $_where       = array();
2618
-        if ( ! empty($this->_req_data['s'])) {
2619
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2620
-            $_where['OR'] = array(
2621
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2622
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2623
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2624
-                'ATT_fname'                         => array('LIKE', $sstr),
2625
-                'ATT_lname'                         => array('LIKE', $sstr),
2626
-                'ATT_short_bio'                     => array('LIKE', $sstr),
2627
-                'ATT_email'                         => array('LIKE', $sstr),
2628
-                'ATT_address'                       => array('LIKE', $sstr),
2629
-                'ATT_address2'                      => array('LIKE', $sstr),
2630
-                'ATT_city'                          => array('LIKE', $sstr),
2631
-                'Country.CNT_name'                  => array('LIKE', $sstr),
2632
-                'State.STA_name'                    => array('LIKE', $sstr),
2633
-                'ATT_phone'                         => array('LIKE', $sstr),
2634
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
2635
-                'Registration.REG_code'             => array('LIKE', $sstr),
2636
-                'Registration.REG_count'            => array('LIKE', $sstr),
2637
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
2638
-            );
2639
-        }
2640
-        $offset = ($current_page - 1) * $per_page;
2641
-        $limit  = $count ? null : array($offset, $per_page);
2642
-        if ($trash) {
2643
-            $_where['status'] = array('!=', 'publish');
2644
-            $all_attendees    = $count
2645
-                ? $ATT_MDL->count(array(
2646
-                    $_where,
2647
-                    'order_by' => array($orderby => $sort),
2648
-                    'limit'    => $limit,
2649
-                ), 'ATT_ID', true)
2650
-                : $ATT_MDL->get_all(array(
2651
-                    $_where,
2652
-                    'order_by' => array($orderby => $sort),
2653
-                    'limit'    => $limit,
2654
-                ));
2655
-        } else {
2656
-            $_where['status'] = array('IN', array('publish'));
2657
-            $all_attendees    = $count
2658
-                ? $ATT_MDL->count(array(
2659
-                    $_where,
2660
-                    'order_by' => array($orderby => $sort),
2661
-                    'limit'    => $limit,
2662
-                ), 'ATT_ID', true)
2663
-                : $ATT_MDL->get_all(array(
2664
-                    $_where,
2665
-                    'order_by' => array($orderby => $sort),
2666
-                    'limit'    => $limit,
2667
-                ));
2668
-        }
2669
-        return $all_attendees;
2670
-    }
2671
-
2672
-
2673
-    /**
2674
-     * This is just taking care of resending the registration confirmation
2675
-     *
2676
-     * @access protected
2677
-     * @return void
2678
-     */
2679
-    protected function _resend_registration()
2680
-    {
2681
-        $this->_process_resend_registration();
2682
-        $query_args = isset($this->_req_data['redirect_to'])
2683
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2684
-            : array(
2685
-                'action' => 'default',
2686
-            );
2687
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2688
-    }
2689
-
2690
-    /**
2691
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2692
-     * to use when selecting registrations
2693
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2694
-     *                                                     the query parameters from the request
2695
-     * @return void ends the request with a redirect or download
2696
-     */
2697
-    public function _registrations_report_base( $method_name_for_getting_query_params )
2698
-    {
2699
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2700
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2701
-                'page'        => 'espresso_batch',
2702
-                'batch'       => 'file',
2703
-                'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2704
-                'filters'     => urlencode(
2705
-                    serialize(
2706
-                        call_user_func(
2707
-                            array( $this, $method_name_for_getting_query_params ),
2708
-                            EEH_Array::is_set(
2709
-                                $this->_req_data,
2710
-                                'filters',
2711
-                                array()
2712
-                            )
2713
-                        )
2714
-                    )
2715
-                ),
2716
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2717
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2718
-                'return_url'  => urlencode($this->_req_data['return_url']),
2719
-            )));
2720
-        } else {
2721
-            $new_request_args = array(
2722
-                'export' => 'report',
2723
-                'action' => 'registrations_report_for_event',
2724
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2725
-            );
2726
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
2727
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2728
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2729
-                $EE_Export = EE_Export::instance($this->_req_data);
2730
-                $EE_Export->export();
2731
-            }
2732
-        }
2733
-    }
2734
-
2735
-
2736
-
2737
-    /**
2738
-     * Creates a registration report using only query parameters in the request
2739
-     * @return void
2740
-     */
2741
-    public function _registrations_report()
2742
-    {
2743
-        $this->_registrations_report_base( '_get_registration_query_parameters' );
2744
-    }
2745
-
2746
-
2747
-    public function _contact_list_export()
2748
-    {
2749
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2750
-            require_once(EE_CLASSES . 'EE_Export.class.php');
2751
-            $EE_Export = EE_Export::instance($this->_req_data);
2752
-            $EE_Export->export_attendees();
2753
-        }
2754
-    }
2755
-
2756
-
2757
-    public function _contact_list_report()
2758
-    {
2759
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2760
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2761
-                'page'        => 'espresso_batch',
2762
-                'batch'       => 'file',
2763
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2764
-                'return_url'  => urlencode($this->_req_data['return_url']),
2765
-            )));
2766
-        } else {
2767
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2768
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2769
-                $EE_Export = EE_Export::instance($this->_req_data);
2770
-                $EE_Export->report_attendees();
2771
-            }
2772
-        }
2773
-    }
2774
-
2775
-
2776
-
2777
-
2778
-
2779
-    /***************************************        ATTENDEE DETAILS        ***************************************/
2780
-    /**
2781
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
2782
-     *
2783
-     * @return void
2784
-     */
2785
-    protected function _duplicate_attendee()
2786
-    {
2787
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2788
-        //verify we have necessary info
2789
-        if (empty($this->_req_data['_REG_ID'])) {
2790
-            EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2791
-                'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2792
-            $query_args = array('action' => $action);
2793
-            $this->_redirect_after_action('', '', '', $query_args, true);
2794
-        }
2795
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2796
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2797
-        $attendee     = $registration->attendee();
2798
-        //remove relation of existing attendee on registration
2799
-        $registration->_remove_relation_to($attendee, 'Attendee');
2800
-        //new attendee
2801
-        $new_attendee = clone $attendee;
2802
-        $new_attendee->set('ATT_ID', 0);
2803
-        $new_attendee->save();
2804
-        //add new attendee to reg
2805
-        $registration->_add_relation_to($new_attendee, 'Attendee');
2806
-        EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2807
-            'event_espresso'));
2808
-        //redirect to edit page for attendee
2809
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2810
-        $this->_redirect_after_action('', '', '', $query_args, true);
2811
-    }
2812
-
2813
-
2814
-    //related to cpt routes
2815
-    protected function _insert_update_cpt_item($post_id, $post)
2816
-    {
2817
-        $success  = true;
2818
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2819
-        //for attendee updates
2820
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2821
-            //note we should only be UPDATING attendees at this point.
2822
-            $updated_fields = array(
2823
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
2824
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
2825
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2826
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2827
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2828
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2829
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2830
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2831
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2832
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2833
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2834
-            );
2835
-            foreach ($updated_fields as $field => $value) {
2836
-                $attendee->set($field, $value);
2837
-            }
2838
-            $success                   = $attendee->save();
2839
-            $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2840
-                array());
2841
-            foreach ($attendee_update_callbacks as $a_callback) {
2842
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2843
-                    throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2844
-                        'event_espresso'), $a_callback));
2845
-                }
2846
-            }
2847
-        }
2848
-        if ($success === false) {
2849
-            EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2850
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2851
-        }
2852
-    }
2853
-
2854
-
2855
-    public function trash_cpt_item($post_id)
2856
-    {
2857
-    }
2858
-
2859
-
2860
-    public function delete_cpt_item($post_id)
2861
-    {
2862
-    }
2863
-
2864
-
2865
-    public function restore_cpt_item($post_id)
2866
-    {
2867
-    }
2868
-
2869
-
2870
-    protected function _restore_cpt_item($post_id, $revision_id)
2871
-    {
2872
-    }
2873
-
2874
-
2875
-    public function attendee_editor_metaboxes()
2876
-    {
2877
-        $this->verify_cpt_object();
2878
-        remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2879
-            'normal', 'core');
2880
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2881
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
2882
-            add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2883
-                $this->_cpt_routes[$this->_req_action], 'normal');
2884
-        }
2885
-        if (post_type_supports('espresso_attendees', 'comments')) {
2886
-            add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2887
-                $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2888
-        }
2889
-        add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2890
-            array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2891
-        add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2892
-            array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2893
-        add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2894
-            array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2895
-    }
2896
-
2897
-
2898
-    /**
2899
-     * Metabox for attendee contact info
2900
-     *
2901
-     * @param  WP_Post $post wp post object
2902
-     * @return string        attendee contact info ( and form )
2903
-     */
2904
-    public function attendee_contact_info($post)
2905
-    {
2906
-        //get attendee object ( should already have it )
2907
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
2908
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2909
-        EEH_Template::display_template($template, $this->_template_args);
2910
-    }
2911
-
2912
-
2913
-    /**
2914
-     * Metabox for attendee details
2915
-     *
2916
-     * @param  WP_Post $post wp post object
2917
-     * @return string        attendee address details (and form)
2918
-     */
2919
-    public function attendee_address_details($post)
2920
-    {
2921
-        //get attendee object (should already have it)
2922
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
2923
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2924
-            'QST_ID'           => 0,
2925
-            'QST_display_text' => __('State/Province', 'event_espresso'),
2926
-            'QST_system'       => 'admin-state',
2927
-        )), EE_Answer::new_instance(array(
2928
-            'ANS_ID'    => 0,
2929
-            'ANS_value' => $this->_cpt_model_obj->state_ID(),
2930
-        )), array(
2931
-            'input_id'       => 'STA_ID',
2932
-            'input_name'     => 'STA_ID',
2933
-            'input_prefix'   => '',
2934
-            'append_qstn_id' => false,
2935
-        )));
2936
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2937
-            'QST_ID'           => 0,
2938
-            'QST_display_text' => __('Country', 'event_espresso'),
2939
-            'QST_system'       => 'admin-country',
2940
-        )), EE_Answer::new_instance(array(
2941
-            'ANS_ID'    => 0,
2942
-            'ANS_value' => $this->_cpt_model_obj->country_ID(),
2943
-        )), array(
2944
-            'input_id'       => 'CNT_ISO',
2945
-            'input_name'     => 'CNT_ISO',
2946
-            'input_prefix'   => '',
2947
-            'append_qstn_id' => false,
2948
-        )));
2949
-        $template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2950
-        EEH_Template::display_template($template, $this->_template_args);
2951
-    }
2952
-
2953
-
2954
-    /**
2955
-     *        _attendee_details
2956
-     *
2957
-     * @access protected
2958
-     * @return void
2959
-     */
2960
-    public function attendee_registrations_meta_box($post)
2961
-    {
2962
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
2963
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2964
-        $template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2965
-        EEH_Template::display_template($template, $this->_template_args);
2966
-    }
2967
-
2968
-
2969
-    /**
2970
-     * add in the form fields for the attendee edit
2971
-     *
2972
-     * @param  WP_Post $post wp post object
2973
-     * @return string        html for new form.
2974
-     */
2975
-    public function after_title_form_fields($post)
2976
-    {
2977
-        if ($post->post_type == 'espresso_attendees') {
2978
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2979
-            $template_args['attendee'] = $this->_cpt_model_obj;
2980
-            EEH_Template::display_template($template, $template_args);
2981
-        }
2982
-    }
2983
-
2984
-
2985
-    /**
2986
-     *        _trash_or_restore_attendee
2987
-     *
2988
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2989
-     * @access protected
2990
-     * @return void
2991
-     */
2992
-    protected function _trash_or_restore_attendees($trash = true)
2993
-    {
2994
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2995
-        $ATT_MDL = EEM_Attendee::instance();
2996
-        $success = 1;
2997
-        //Checkboxes
2998
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2999
-            // if array has more than one element than success message should be plural
3000
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3001
-            // cycle thru checkboxes
3002
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3003
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3004
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3005
-                if ( ! $updated) {
3006
-                    $success = 0;
3007
-                }
3008
-            }
3009
-        } else {
3010
-            // grab single id and delete
3011
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3012
-            //get attendee
3013
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3014
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3015
-            $updated = $att->save();
3016
-            if ( ! $updated) {
3017
-                $success = 0;
3018
-            }
3019
-        }
3020
-        $what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3021
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3022
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3023
-    }
2372
+		}
2373
+		$template_args = array(
2374
+			'title'                    => '',
2375
+			'content'                  => '',
2376
+			'step_button_text'         => '',
2377
+			'show_notification_toggle' => false,
2378
+		);
2379
+		//to indicate we're processing a new registration
2380
+		$hidden_fields = array(
2381
+			'processing_registration' => array(
2382
+				'type'  => 'hidden',
2383
+				'value' => 0,
2384
+			),
2385
+			'event_id'                => array(
2386
+				'type'  => 'hidden',
2387
+				'value' => $this->_reg_event->ID(),
2388
+			),
2389
+		);
2390
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2391
+		$cart = EE_Registry::instance()->SSN->cart();
2392
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2393
+		switch ($step) {
2394
+			case 'ticket' :
2395
+				$hidden_fields['processing_registration']['value'] = 1;
2396
+				$template_args['title']                            = __('Step One: Select the Ticket for this registration',
2397
+					'event_espresso');
2398
+				$template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2399
+				$template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2400
+					'event_espresso');
2401
+				$template_args['show_notification_toggle']         = false;
2402
+				break;
2403
+			case 'questions' :
2404
+				$hidden_fields['processing_registration']['value'] = 2;
2405
+				$template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2406
+					'event_espresso');
2407
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2408
+				$template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2409
+				$template_args['step_button_text']         = __('Save Registration and Continue to Details',
2410
+					'event_espresso');
2411
+				$template_args['show_notification_toggle'] = true;
2412
+				break;
2413
+		}
2414
+		$this->_set_add_edit_form_tags('process_reg_step',
2415
+			$hidden_fields); //we come back to the process_registration_step route.
2416
+		return EEH_Template::display_template(REG_TEMPLATE_PATH
2417
+											  . 'reg_admin_register_new_attendee_step_content.template.php',
2418
+			$template_args, true);
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 *        set_reg_event
2424
+	 *
2425
+	 * @access private
2426
+	 * @return boolean
2427
+	 */
2428
+	private function _set_reg_event()
2429
+	{
2430
+		if (is_object($this->_reg_event)) {
2431
+			return true;
2432
+		}
2433
+		$EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2434
+		if ( ! $EVT_ID) {
2435
+			return false;
2436
+		}
2437
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2438
+		return true;
2439
+	}
2440
+
2441
+
2442
+	/**
2443
+	 * process_reg_step
2444
+	 *
2445
+	 * @access        public
2446
+	 * @return        string
2447
+	 * @throws \RuntimeException
2448
+	 * @throws \EE_Error
2449
+	 */
2450
+	public function process_reg_step()
2451
+	{
2452
+		EE_System::do_not_cache();
2453
+		$this->_set_reg_event();
2454
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2455
+		EE_Registry::instance()->REQ->set('uts', time());
2456
+		//what step are we on?
2457
+		$cart = EE_Registry::instance()->SSN->cart();
2458
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2459
+		//if doing ajax then we need to verify the nonce
2460
+		if (defined('DOING_AJAX')) {
2461
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2462
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2463
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2464
+		}
2465
+		switch ($step) {
2466
+			case 'ticket' :
2467
+				//process ticket selection
2468
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2469
+				if ($success) {
2470
+					EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2471
+						'event_espresso'));
2472
+				} else {
2473
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2474
+				}
2475
+				if (defined('DOING_AJAX')) {
2476
+					$this->new_registration(); //display next step
2477
+				} else {
2478
+					$query_args = array(
2479
+						'action'                  => 'new_registration',
2480
+						'processing_registration' => 1,
2481
+						'event_id'                => $this->_reg_event->ID(),
2482
+						'uts'                     => time(),
2483
+					);
2484
+					$this->_redirect_after_action(false, '', '', $query_args, true);
2485
+				}
2486
+				break;
2487
+			case 'questions' :
2488
+				if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2489
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2490
+				}
2491
+				//process registration
2492
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2493
+				if ($cart instanceof EE_Cart) {
2494
+					$grand_total = $cart->get_cart_grand_total();
2495
+					if ($grand_total instanceof EE_Line_Item) {
2496
+						$grand_total->save_this_and_descendants_to_txn();
2497
+					}
2498
+				}
2499
+				if ( ! $transaction instanceof EE_Transaction) {
2500
+					$query_args = array(
2501
+						'action'                  => 'new_registration',
2502
+						'processing_registration' => 2,
2503
+						'event_id'                => $this->_reg_event->ID(),
2504
+						'uts'                     => time(),
2505
+					);
2506
+					if (defined('DOING_AJAX')) {
2507
+						//display registration form again because there are errors (maybe validation?)
2508
+						$this->new_registration();
2509
+						return;
2510
+					} else {
2511
+						$this->_redirect_after_action(false, '', '', $query_args, true);
2512
+						return;
2513
+					}
2514
+				}
2515
+				// maybe update status, and make sure to save transaction if not done already
2516
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2517
+					$transaction->save();
2518
+				}
2519
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2520
+				$this->_req_data = array();
2521
+				$query_args      = array(
2522
+					'action'        => 'redirect_to_txn',
2523
+					'TXN_ID'        => $transaction->ID(),
2524
+					'EVT_ID'        => $this->_reg_event->ID(),
2525
+					'event_name'    => urlencode($this->_reg_event->name()),
2526
+					'redirect_from' => 'new_registration',
2527
+				);
2528
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2529
+				break;
2530
+		}
2531
+		//what are you looking here for?  Should be nothing to do at this point.
2532
+	}
2533
+
2534
+
2535
+	/**
2536
+	 * redirect_to_txn
2537
+	 *
2538
+	 * @access public
2539
+	 * @return void
2540
+	 */
2541
+	public function redirect_to_txn()
2542
+	{
2543
+		EE_System::do_not_cache();
2544
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2545
+		$query_args = array(
2546
+			'action' => 'view_transaction',
2547
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2548
+			'page'   => 'espresso_transactions',
2549
+		);
2550
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2551
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2552
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2553
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2554
+		}
2555
+		EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2556
+			'event_espresso'));
2557
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2558
+	}
2559
+
2560
+
2561
+	/**
2562
+	 *        generates HTML for the Attendee Contact List
2563
+	 *
2564
+	 * @access protected
2565
+	 * @return void
2566
+	 */
2567
+	protected function _attendee_contact_list_table()
2568
+	{
2569
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2570
+		$this->_search_btn_label = __('Contacts', 'event_espresso');
2571
+		$this->display_admin_list_table_page_with_no_sidebar();
2572
+	}
2573
+
2574
+
2575
+	/**
2576
+	 *        get_attendees
2577
+	 *
2578
+	 * @param bool $count whether to return count or data.
2579
+	 * @access public
2580
+	 * @return array
2581
+	 */
2582
+	public function get_attendees($per_page, $count = false, $trash = false)
2583
+	{
2584
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2585
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2586
+		$ATT_MDL                    = EEM_Attendee::instance();
2587
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2588
+		switch ($this->_req_data['orderby']) {
2589
+			case 'ATT_ID':
2590
+				$orderby = 'ATT_ID';
2591
+				break;
2592
+			case 'ATT_fname':
2593
+				$orderby = 'ATT_fname';
2594
+				break;
2595
+			case 'ATT_email':
2596
+				$orderby = 'ATT_email';
2597
+				break;
2598
+			case 'ATT_city':
2599
+				$orderby = 'ATT_city';
2600
+				break;
2601
+			case 'STA_ID':
2602
+				$orderby = 'STA_ID';
2603
+				break;
2604
+			case 'CNT_ID':
2605
+				$orderby = 'CNT_ID';
2606
+				break;
2607
+			default:
2608
+				$orderby = 'ATT_lname';
2609
+		}
2610
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2611
+			: 'ASC';
2612
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2613
+			? $this->_req_data['paged'] : 1;
2614
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2615
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2616
+			? $this->_req_data['perpage'] : $per_page;
2617
+		$_where       = array();
2618
+		if ( ! empty($this->_req_data['s'])) {
2619
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2620
+			$_where['OR'] = array(
2621
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2622
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2623
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2624
+				'ATT_fname'                         => array('LIKE', $sstr),
2625
+				'ATT_lname'                         => array('LIKE', $sstr),
2626
+				'ATT_short_bio'                     => array('LIKE', $sstr),
2627
+				'ATT_email'                         => array('LIKE', $sstr),
2628
+				'ATT_address'                       => array('LIKE', $sstr),
2629
+				'ATT_address2'                      => array('LIKE', $sstr),
2630
+				'ATT_city'                          => array('LIKE', $sstr),
2631
+				'Country.CNT_name'                  => array('LIKE', $sstr),
2632
+				'State.STA_name'                    => array('LIKE', $sstr),
2633
+				'ATT_phone'                         => array('LIKE', $sstr),
2634
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
2635
+				'Registration.REG_code'             => array('LIKE', $sstr),
2636
+				'Registration.REG_count'            => array('LIKE', $sstr),
2637
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
2638
+			);
2639
+		}
2640
+		$offset = ($current_page - 1) * $per_page;
2641
+		$limit  = $count ? null : array($offset, $per_page);
2642
+		if ($trash) {
2643
+			$_where['status'] = array('!=', 'publish');
2644
+			$all_attendees    = $count
2645
+				? $ATT_MDL->count(array(
2646
+					$_where,
2647
+					'order_by' => array($orderby => $sort),
2648
+					'limit'    => $limit,
2649
+				), 'ATT_ID', true)
2650
+				: $ATT_MDL->get_all(array(
2651
+					$_where,
2652
+					'order_by' => array($orderby => $sort),
2653
+					'limit'    => $limit,
2654
+				));
2655
+		} else {
2656
+			$_where['status'] = array('IN', array('publish'));
2657
+			$all_attendees    = $count
2658
+				? $ATT_MDL->count(array(
2659
+					$_where,
2660
+					'order_by' => array($orderby => $sort),
2661
+					'limit'    => $limit,
2662
+				), 'ATT_ID', true)
2663
+				: $ATT_MDL->get_all(array(
2664
+					$_where,
2665
+					'order_by' => array($orderby => $sort),
2666
+					'limit'    => $limit,
2667
+				));
2668
+		}
2669
+		return $all_attendees;
2670
+	}
2671
+
2672
+
2673
+	/**
2674
+	 * This is just taking care of resending the registration confirmation
2675
+	 *
2676
+	 * @access protected
2677
+	 * @return void
2678
+	 */
2679
+	protected function _resend_registration()
2680
+	{
2681
+		$this->_process_resend_registration();
2682
+		$query_args = isset($this->_req_data['redirect_to'])
2683
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2684
+			: array(
2685
+				'action' => 'default',
2686
+			);
2687
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2688
+	}
2689
+
2690
+	/**
2691
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2692
+	 * to use when selecting registrations
2693
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2694
+	 *                                                     the query parameters from the request
2695
+	 * @return void ends the request with a redirect or download
2696
+	 */
2697
+	public function _registrations_report_base( $method_name_for_getting_query_params )
2698
+	{
2699
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2700
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2701
+				'page'        => 'espresso_batch',
2702
+				'batch'       => 'file',
2703
+				'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2704
+				'filters'     => urlencode(
2705
+					serialize(
2706
+						call_user_func(
2707
+							array( $this, $method_name_for_getting_query_params ),
2708
+							EEH_Array::is_set(
2709
+								$this->_req_data,
2710
+								'filters',
2711
+								array()
2712
+							)
2713
+						)
2714
+					)
2715
+				),
2716
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2717
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2718
+				'return_url'  => urlencode($this->_req_data['return_url']),
2719
+			)));
2720
+		} else {
2721
+			$new_request_args = array(
2722
+				'export' => 'report',
2723
+				'action' => 'registrations_report_for_event',
2724
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2725
+			);
2726
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
2727
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2728
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2729
+				$EE_Export = EE_Export::instance($this->_req_data);
2730
+				$EE_Export->export();
2731
+			}
2732
+		}
2733
+	}
2734
+
2735
+
2736
+
2737
+	/**
2738
+	 * Creates a registration report using only query parameters in the request
2739
+	 * @return void
2740
+	 */
2741
+	public function _registrations_report()
2742
+	{
2743
+		$this->_registrations_report_base( '_get_registration_query_parameters' );
2744
+	}
2745
+
2746
+
2747
+	public function _contact_list_export()
2748
+	{
2749
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2750
+			require_once(EE_CLASSES . 'EE_Export.class.php');
2751
+			$EE_Export = EE_Export::instance($this->_req_data);
2752
+			$EE_Export->export_attendees();
2753
+		}
2754
+	}
2755
+
2756
+
2757
+	public function _contact_list_report()
2758
+	{
2759
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2760
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2761
+				'page'        => 'espresso_batch',
2762
+				'batch'       => 'file',
2763
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2764
+				'return_url'  => urlencode($this->_req_data['return_url']),
2765
+			)));
2766
+		} else {
2767
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2768
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2769
+				$EE_Export = EE_Export::instance($this->_req_data);
2770
+				$EE_Export->report_attendees();
2771
+			}
2772
+		}
2773
+	}
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+	/***************************************        ATTENDEE DETAILS        ***************************************/
2780
+	/**
2781
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
2782
+	 *
2783
+	 * @return void
2784
+	 */
2785
+	protected function _duplicate_attendee()
2786
+	{
2787
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2788
+		//verify we have necessary info
2789
+		if (empty($this->_req_data['_REG_ID'])) {
2790
+			EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2791
+				'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2792
+			$query_args = array('action' => $action);
2793
+			$this->_redirect_after_action('', '', '', $query_args, true);
2794
+		}
2795
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2796
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2797
+		$attendee     = $registration->attendee();
2798
+		//remove relation of existing attendee on registration
2799
+		$registration->_remove_relation_to($attendee, 'Attendee');
2800
+		//new attendee
2801
+		$new_attendee = clone $attendee;
2802
+		$new_attendee->set('ATT_ID', 0);
2803
+		$new_attendee->save();
2804
+		//add new attendee to reg
2805
+		$registration->_add_relation_to($new_attendee, 'Attendee');
2806
+		EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2807
+			'event_espresso'));
2808
+		//redirect to edit page for attendee
2809
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2810
+		$this->_redirect_after_action('', '', '', $query_args, true);
2811
+	}
2812
+
2813
+
2814
+	//related to cpt routes
2815
+	protected function _insert_update_cpt_item($post_id, $post)
2816
+	{
2817
+		$success  = true;
2818
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2819
+		//for attendee updates
2820
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2821
+			//note we should only be UPDATING attendees at this point.
2822
+			$updated_fields = array(
2823
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
2824
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
2825
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2826
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2827
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2828
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2829
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2830
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2831
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2832
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2833
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2834
+			);
2835
+			foreach ($updated_fields as $field => $value) {
2836
+				$attendee->set($field, $value);
2837
+			}
2838
+			$success                   = $attendee->save();
2839
+			$attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2840
+				array());
2841
+			foreach ($attendee_update_callbacks as $a_callback) {
2842
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2843
+					throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2844
+						'event_espresso'), $a_callback));
2845
+				}
2846
+			}
2847
+		}
2848
+		if ($success === false) {
2849
+			EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2850
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2851
+		}
2852
+	}
2853
+
2854
+
2855
+	public function trash_cpt_item($post_id)
2856
+	{
2857
+	}
2858
+
2859
+
2860
+	public function delete_cpt_item($post_id)
2861
+	{
2862
+	}
2863
+
2864
+
2865
+	public function restore_cpt_item($post_id)
2866
+	{
2867
+	}
2868
+
2869
+
2870
+	protected function _restore_cpt_item($post_id, $revision_id)
2871
+	{
2872
+	}
2873
+
2874
+
2875
+	public function attendee_editor_metaboxes()
2876
+	{
2877
+		$this->verify_cpt_object();
2878
+		remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2879
+			'normal', 'core');
2880
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2881
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
2882
+			add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2883
+				$this->_cpt_routes[$this->_req_action], 'normal');
2884
+		}
2885
+		if (post_type_supports('espresso_attendees', 'comments')) {
2886
+			add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2887
+				$this->_cpt_routes[$this->_req_action], 'normal', 'core');
2888
+		}
2889
+		add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2890
+			array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2891
+		add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2892
+			array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2893
+		add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2894
+			array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2895
+	}
2896
+
2897
+
2898
+	/**
2899
+	 * Metabox for attendee contact info
2900
+	 *
2901
+	 * @param  WP_Post $post wp post object
2902
+	 * @return string        attendee contact info ( and form )
2903
+	 */
2904
+	public function attendee_contact_info($post)
2905
+	{
2906
+		//get attendee object ( should already have it )
2907
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2908
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2909
+		EEH_Template::display_template($template, $this->_template_args);
2910
+	}
2911
+
2912
+
2913
+	/**
2914
+	 * Metabox for attendee details
2915
+	 *
2916
+	 * @param  WP_Post $post wp post object
2917
+	 * @return string        attendee address details (and form)
2918
+	 */
2919
+	public function attendee_address_details($post)
2920
+	{
2921
+		//get attendee object (should already have it)
2922
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
2923
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2924
+			'QST_ID'           => 0,
2925
+			'QST_display_text' => __('State/Province', 'event_espresso'),
2926
+			'QST_system'       => 'admin-state',
2927
+		)), EE_Answer::new_instance(array(
2928
+			'ANS_ID'    => 0,
2929
+			'ANS_value' => $this->_cpt_model_obj->state_ID(),
2930
+		)), array(
2931
+			'input_id'       => 'STA_ID',
2932
+			'input_name'     => 'STA_ID',
2933
+			'input_prefix'   => '',
2934
+			'append_qstn_id' => false,
2935
+		)));
2936
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2937
+			'QST_ID'           => 0,
2938
+			'QST_display_text' => __('Country', 'event_espresso'),
2939
+			'QST_system'       => 'admin-country',
2940
+		)), EE_Answer::new_instance(array(
2941
+			'ANS_ID'    => 0,
2942
+			'ANS_value' => $this->_cpt_model_obj->country_ID(),
2943
+		)), array(
2944
+			'input_id'       => 'CNT_ISO',
2945
+			'input_name'     => 'CNT_ISO',
2946
+			'input_prefix'   => '',
2947
+			'append_qstn_id' => false,
2948
+		)));
2949
+		$template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2950
+		EEH_Template::display_template($template, $this->_template_args);
2951
+	}
2952
+
2953
+
2954
+	/**
2955
+	 *        _attendee_details
2956
+	 *
2957
+	 * @access protected
2958
+	 * @return void
2959
+	 */
2960
+	public function attendee_registrations_meta_box($post)
2961
+	{
2962
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
2963
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2964
+		$template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2965
+		EEH_Template::display_template($template, $this->_template_args);
2966
+	}
2967
+
2968
+
2969
+	/**
2970
+	 * add in the form fields for the attendee edit
2971
+	 *
2972
+	 * @param  WP_Post $post wp post object
2973
+	 * @return string        html for new form.
2974
+	 */
2975
+	public function after_title_form_fields($post)
2976
+	{
2977
+		if ($post->post_type == 'espresso_attendees') {
2978
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2979
+			$template_args['attendee'] = $this->_cpt_model_obj;
2980
+			EEH_Template::display_template($template, $template_args);
2981
+		}
2982
+	}
2983
+
2984
+
2985
+	/**
2986
+	 *        _trash_or_restore_attendee
2987
+	 *
2988
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2989
+	 * @access protected
2990
+	 * @return void
2991
+	 */
2992
+	protected function _trash_or_restore_attendees($trash = true)
2993
+	{
2994
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2995
+		$ATT_MDL = EEM_Attendee::instance();
2996
+		$success = 1;
2997
+		//Checkboxes
2998
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2999
+			// if array has more than one element than success message should be plural
3000
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3001
+			// cycle thru checkboxes
3002
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3003
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3004
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3005
+				if ( ! $updated) {
3006
+					$success = 0;
3007
+				}
3008
+			}
3009
+		} else {
3010
+			// grab single id and delete
3011
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3012
+			//get attendee
3013
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3014
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3015
+			$updated = $att->save();
3016
+			if ( ! $updated) {
3017
+				$success = 0;
3018
+			}
3019
+		}
3020
+		$what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3021
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3022
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3023
+	}
3024 3024
 
3025 3025
 }
3026 3026
 
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php 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
-                ); ?>
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
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
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.3.9');
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
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.31.rc.008');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.31.rc.008');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
Please login to merge, or discard this patch.