PluginProbe
Gravity Forms Eway / 1.5.12
Gravity Forms Eway v1.5.12
2.7.0 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 All 56 releases
gravityforms-eway / class.GFEwayAdmin.php

class.GFEwayAdmin.php in Gravity Forms Eway 1.5.12, at class.GFEwayAdmin.php

223 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * class for admin screens
5 */
6 class GFEwayAdmin {
7
8 public $settingsURL;
9
10 private $plugin;
11
12 /**
13 * @param GFEwayPlugin $plugin
14 */
15 public function __construct($plugin) {
16 $this->plugin = $plugin;
17
18 // handle change in settings pages
19 if (class_exists('GFCommon')) {
20 if (version_compare(GFCommon::$version, '1.6.99999', '<')) {
21 // pre-v1.7 settings
22 $this->settingsURL = admin_url('admin.php?page=gf_settings&addon=eWAY+Payments');
23 }
24 else {
25 // post-v1.7 settings
26 $this->settingsURL = admin_url('admin.php?page=gf_settings&subview=eWAY+Payments');
27 }
28 }
29
30 // handle admin init action
31 add_action('admin_init', array($this, 'adminInit'));
32
33 // add GravityForms hooks
34 add_filter('gform_currency_setting_message', array($this, 'gformCurrencySettingMessage'));
35 add_action('gform_payment_status', array($this, 'gformPaymentStatus'), 10, 3);
36 add_action('gform_after_update_entry', array($this, 'gformAfterUpdateEntry'), 10, 2);
37 add_action("gform_entry_info", array($this, 'gformEntryInfo'), 10, 2);
38
39 // hook for showing admin messages
40 add_action('admin_notices', array($this, 'actionAdminNotices'));
41
42 // add action hook for adding plugin action links
43 add_action('plugin_action_links_' . GFEWAY_PLUGIN_NAME, array($this, 'addPluginActionLinks'));
44
45 // hook for adding links to plugin info
46 add_filter('plugin_row_meta', array($this, 'addPluginDetailsLinks'), 10, 2);
47
48 // hook for enqueuing admin styles
49 add_filter('admin_enqueue_scripts', array($this, 'enqueueScripts'));
50 }
51
52 /**
53 * test whether GravityForms plugin is installed and active
54 * @return boolean
55 */
56 public static function isGfActive() {
57 return class_exists('RGForms');
58 }
59
60 /**
61 * handle admin init action
62 */
63 public function adminInit() {
64 if (isset($_GET['page'])) {
65 switch ($_GET['page']) {
66 case 'gf_settings':
67 // add our settings page to the Gravity Forms settings menu
68 RGForms::add_settings_page('eWAY Payments', array($this, 'optionsAdmin'));
69 break;
70 }
71 }
72 }
73
74 /**
75 * only output our stylesheet if this is our admin page
76 */
77 public function enqueueScripts() {
78 $ver = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? time() : GFEWAY_PLUGIN_VERSION;
79 wp_enqueue_style('gfeway-admin', $this->plugin->urlBase . 'style-admin.css', false, $ver);
80 }
81
82 /**
83 * show admin messages
84 */
85 public function actionAdminNotices() {
86 if (!self::isGfActive()) {
87 $this->plugin->showError('Gravity Forms eWAY requires <a href="http://www.gravityforms.com/">Gravity Forms</a> to be installed and activated.');
88 }
89 }
90
91 /**
92 * action hook for adding plugin action links
93 */
94 public function addPluginActionLinks($links) {
95 // add settings link, but only if GravityForms plugin is active
96 if (self::isGfActive()) {
97 $settings_link = sprintf('<a href="%s">%s</a>', $this->settingsURL, __('Settings'));
98 array_unshift($links, $settings_link);
99 }
100
101 return $links;
102 }
103
104 /**
105 * action hook for adding plugin details links
106 */
107 public static function addPluginDetailsLinks($links, $file) {
108 if ($file == GFEWAY_PLUGIN_NAME) {
109 $links[] = '<a href="http://wordpress.org/support/plugin/gravityforms-eway">' . __('Get help') . '</a>';
110 $links[] = '<a href="http://wordpress.org/plugins/gravityforms-eway/">' . __('Rating') . '</a>';
111 $links[] = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=8V9YCKATQHKEN">' . __('Donate') . '</a>';
112 }
113
114 return $links;
115 }
116
117 /**
118 * action hook for showing currency setting message
119 * @param array $menus
120 * @return array
121 */
122 public function gformCurrencySettingMessage() {
123 echo "<div class='gform_currency_message'>NB: Gravity Forms eWAY only supports Australian Dollars (AUD).</div>\n";
124 }
125
126 /**
127 * action hook for building the entry details view
128 * @param int $form_id
129 * @param array $lead
130 */
131 public function gformEntryInfo($form_id, $lead) {
132 $payment_gateway = gform_get_meta($lead['id'], 'payment_gateway');
133 if ($payment_gateway == 'gfeway') {
134 $authcode = gform_get_meta($lead['id'], 'authcode');
135 if ($authcode) {
136 echo 'Auth Code: ', esc_html($authcode), "<br /><br />\n";
137 }
138
139 $beagle_score = gform_get_meta($lead['id'], 'beagle_score');
140 if ($beagle_score) {
141 echo 'Beagle Score: ', esc_html($beagle_score), "<br /><br />\n";
142 }
143 }
144 }
145
146 /**
147 * action hook for processing admin menu item
148 */
149 public function optionsAdmin() {
150 $admin = new GFEwayOptionsAdmin($this->plugin, 'gfeway-options', $this->settingsURL);
151 $admin->process();
152 }
153
154 /**
155 * allow edits to payment status
156 * @param string $payment_status
157 * @param array $form
158 * @param array $lead
159 * @return string
160 */
161 public function gformPaymentStatus($payment_status, $form, $lead) {
162 // make sure payment is not Approved, and that we're editing the lead
163 if ($payment_status == 'Approved' || strtolower(rgpost('save')) <> 'edit') {
164 return $payment_status;
165 }
166
167 // make sure payment is one of ours (probably)
168 $payment_gateway = gform_get_meta($lead['id'], 'payment_gateway');
169 if ((empty($payment_gateway) && $this->plugin->hasFieldType($form['fields'], 'creditcard')) || $payment_gateway != 'gfeway') {
170 return $payment_status;
171 }
172
173 // make sure payment isn't a recurring payment
174 if ($this->plugin->hasFieldType($form['fields'], GFEWAY_FIELD_RECURRING)) {
175 return $payment_status;
176 }
177
178 // create drop down for payment status
179 //~ $payment_string = gform_tooltip("paypal_edit_payment_status","",true);
180 $input = <<<HTML
181 <select name="payment_status">
182 <option value="$payment_status" selected="selected">$payment_status</option>
183 <option value="Approved">Approved</option>
184 </select>
185
186 HTML;
187
188 return $input;
189 }
190
191 /**
192 * update payment status if it has changed
193 * @param array $form
194 * @param int $lead_id
195 */
196 public function gformAfterUpdateEntry($form, $lead_id) {
197 // make sure we have permission
198 check_admin_referer('gforms_save_entry', 'gforms_save_entry');
199
200 // check that save action is for update
201 if (strtolower(rgpost("save")) <> 'update')
202 return;
203
204 // make sure payment is one of ours (probably)
205 $payment_gateway = gform_get_meta($lead_id, 'payment_gateway');
206 if ((empty($payment_gateway) && $this->plugin->hasFieldType($form['fields'], 'creditcard')) || $payment_gateway != 'gfeway') {
207 return;
208 }
209
210 // make sure we have a new payment status
211 $payment_status = rgpost('payment_status');
212 if (empty($payment_status)) {
213 return;
214 }
215
216 // update payment status
217 $lead = GFFormsModel::get_lead($lead_id);
218 $lead["payment_status"] = $payment_status;
219
220 GFFormsModel::update_lead($lead);
221 }
222 }
223