/
gf-sqlserver-integration.php
238 lines (214 loc) · 7.89 KB
/
gf-sqlserver-integration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/*
Plugin Name: Gravity Forms SQL Server Data Integration for Bellevue College
Plugin URI: https://github.com/BellevueCollege/gf-sqlserver-integration
Description: Moves Gravity Forms data to SQL Server for defined models
Author: Bellevue College Integration Team
Version: 2.10
Author URI: http://www.bellevuecollege.edu
GitHub Plugin URI: bellevuecollege/gf-sqlserver-integration
*/
defined( 'ABSPATH' ) or exit;
file_exists( plugin_dir_path( __FILE__ ) . '/config.php' ) ? require_once( 'config.php' ) : die( 'For Plugin gf-sqlserver-integration :: Config file is missing' );
require_once( 'classes/Transaction.php' );
require_once( 'classes/AppliedAccounting_BAS.php' );
require_once( 'classes/ComputerScience_BS.php' );
require_once( 'classes/DataAnalytics_BAS.php' );
require_once( 'classes/HealthcareInformatics_BAS.php' );
require_once( 'classes/HealthcareManagement_BAS.php' );
require_once( 'classes/HealthcarePromotion_BAS.php' );
require_once( 'classes/InteriorDesign_BA.php' );
require_once( 'classes/IST_BAS.php' );
require_once( 'classes/MolecularBiosciences_BAS.php' );
require_once( 'classes/Nursing_RN_BSN.php' );
require_once( 'classes/RadiationImaging_BAS.php' );
require_once( 'classes/RadiationTherapyProgram_AA.php' );
require_once( 'classes/TechPrepPayment.php' );
require_once( 'classes/HealthCareInformaticsCertificate.php' );
require_once( 'classes/RadiologicTechnologyProgram_AA.php' );
require_once( 'classes/HealthCareDataAnalyticsCertificate.php' );
require_once( 'classes/DigitalMarketing_BAS.php' );
require_once( 'classes/ASNConference.php' );
require_once( 'classes/NursingAssistantCertifiedProgram.php' );
require_once( 'classes/RAIS_DosimetryConcentration.php' );
require_once( 'classes/NuclearMedicineProgram_AA.php' );
require_once( 'classes/DiagnosticUltrasoundTechnologyProgram_AA.php' );
require_once( 'classes/NeurodiagnosticTechnologyProgram_AA.php' );
require_once( 'classes/OLSPayments.php' );
require_once( 'classes/PNWCC-Manual.php'); // New Tech Prep 2nd Payment form
//Remove Amex from accepted card types
add_filter( 'gform_creditcard_types', 'remove_amex' );
function remove_amex( $cards ) {
unset( $cards[0] ); // Removes AMEX from the list.
return $cards;
}
//attach processing to post payment action
add_action( 'gform_post_payment_action', 'gfsi_process_submission', 10, 2 );
//process post submission, handle case when no payment.
add_action( 'gform_after_submission', 'gfsi_after_submission', 10, 2 );
//add settings submenu page to form settings
add_filter( 'gform_form_settings_menu', 'gfsi_add_custom_form_settings_menu_item' );
//set content for custom settings menu page
add_action( 'gform_form_settings_page_gfsi_custom_form_settings_page', 'gfsi_custom_form_settings_page' );
//process form submission
function gfsi_process_submission( $entry, $action ) {
GFCommon::log_debug( 'gform_post_payment_action: action =>' . print_r( $action, true ) );
// Get form info so we can get the model type assigned to it
$this_form = GFAPI::get_form( rgar( $entry, 'form_id' ) );
//error_log(print_r($this_form),true);
// var_dump($this_form);
//exit();
$model_type = rgar( $this_form, 'gfsi_model' );
//Instantiate model based on the model type set for the form
$model = null;
switch ( $model_type ) {
case 'InteriorDesign_BA':
$model = new InteriorDesign_BA();
break;
case 'IST_BAS':
$model = new IST_BAS();
break;
case 'DataAnalytics_BAS':
$model = new DataAnalytics_BAS();
break;
case 'AppliedAccounting_BAS':
$model = new AppliedAccounting_BAS();
break;
case 'HealthcareInformatics_BAS':
$model = new HealthcareInformatics_BAS();
break;
case 'HealthcarePromotion_BAS':
$model = new HealthcarePromotion_BAS();
break;
case 'HealthcareManagement_BAS':
$model = new HealthcareManagement_BAS();
break;
case 'RadiationImaging_BAS':
$model = new RadiationImaging_BAS();
break;
case 'MolecularBiosciences_BAS':
$model = new MolecularBiosciences_BAS();
break;
case 'Nursing_RN_BSN':
$model = new Nursing_RN_BSN();
break;
case 'ComputerScience_BS':
$model = new ComputerScience_BS();
break;
case 'TechPrepPayment':
$model = new TechPrepPayment();
break;
case 'HealthCareInformaticsCertificate':
$model = new HealthCareInformaticsCertificate();
break;
case 'RadiationTherapyProgram_AA':
$model = new RadiationTherapyProgram_AA();
break;
case 'RadiologicTechnologyProgram_AA':
$model = new RadiologicTechnologyProgram_AA();
break;
case 'HealthCareDataAnalyticsCertificate':
//error_log("Hello");
$model = new HealthCareDataAnalyticsCertificate();
break;
case 'DigitalMarketing_BAS':
$model = new DigitalMarketing_BAS();
break;
case 'NursingAssistantCertifiedProgram':
$model = new NursingAssistantCertifiedProgram();
break;
case 'RAIS_DosimetryConcentration':
$model = new RAIS_DosimetryConcentration();
break;
case 'NuclearMedicineProgram_AA':
$model = new NuclearMedicineProgram_AA();
break;
case 'DiagnosticUltrasoundTechnologyProgram_AA':
$model = new DiagnosticUltrasoundTechnologyProgram_AA();
break;
case 'NeurodiagnosticTechnologyProgram_AA':
$model = new NeurodiagnosticTechnologyProgram_AA();
break;
case 'OLSPayments':
$model = new OLSPayments();
break;
case 'PNWCC-Manual': // New TechPrep Payment
$model = new PNWCCManual();
break;
// case 'ASNConference':
// error_log("Hello *********************************************");
// $model = new ConferenceRegistration();
// break;
default:
break;
}
//If defined, build the chosen model from the form entry data
try {
if ( ! empty( $model ) ) {
$model->build( $entry );
$model->save();
/*echo '<pre>';
var_dump($model);
echo '</pre>';*/
// exit();
} else {
throw new Exception( 'Model is empty, likely no data model set for form ' . $this_form['title'] );
}
} catch ( Exception $e ) {
error_log( print_r( 'GF SQL Server Integration plugin :: error building and saving model - ' . $e->getMessage(), true ) );
}
GFCommon::log_debug( 'gform_post_payment_action: entry =>' . print_r( $entry, true ) );
}
function gfsi_after_submission( $entry, $form ) {
// Get form info so we can get the model type assigned to it
$this_form = GFAPI::get_form( rgar( $entry, 'form_id' ) );
$model_type = rgar( $this_form, 'gfsi_model' );
//Instantiate model based on the model type set for the form
$model = null;
if ( $model_type != 'ASNConference' ) {
return;
}
switch ( $model_type ) {
case 'ASNConference':
$model = new ASNConference();
break;
default:
break;
}
//If defined, build the chosen model from the form entry data
try {
if ( ! empty( $model ) ) {
$model->build( $entry );
$model->save();
/*echo '<pre>';
var_dump($model);
echo '</pre>';*/
} else {
throw new Exception( 'After submission : Model is empty, likely no data model set for form ' . $this_form['title'] );
}
} catch ( Exception $e ) {
error_log( print_r( 'GF SQL Server Integration plugin :: After submission : error building and saving model - ' . $e->getMessage(), true ) );
}
}
// add a custom menu item to the Form Settings page menu
function gfsi_add_custom_form_settings_menu_item( $menu_items ) {
$menu_items[] = array(
'name' => 'gfsi_custom_form_settings_page',
'label' => __( 'BC SQL Server Data Integration' ),
);
return $menu_items;
}
// handle displaying content for our custom menu when selected
function gfsi_custom_form_settings_page() {
//only provide our menu item if person has appropriate permissions
if ( current_user_can( 'manage_options' ) ) {
$form_id = isset( $_GET['id'] ) ? $_GET['id'] : null;
if ( $form = GFFormsModel::get_form_meta( $form_id ) ) {
GFFormSettings::page_header();
include dirname( __FILE__ ) . '/content/sqlserver-integration-menu-page.php';
GFFormSettings::page_footer();
}
} else {
echo __( 'You do not have the correct permissions to update this setting.' );
}
}