Add table for the streamsend cache.
// Database table prefixes - change if using add-on tables
global $wpdb;
-define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glmMembersCommunicator');
+define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_membersCommunicator_');
define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersCommunicatorDbVersion');
// Determine which system we're running on - If not provided, assume PRODUCTION
*/
//define('STREAMSEND_DEFAULT_DELIVER_WELCOME', 'false');
-class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator
+class GlmMembersAdmin_communicator_index
{
/**
*/
public function __construct ($wpdb, $config)
{
-
// Save WordPress Database object
$this->wpdb = $wpdb;
// Save plugin configuration object
$this->config = $config;
-
- /*
- * Run constructor for the Communicator data class
- *
- * Note, the third parameter is a flag that indicates to the Contacts
- * data class that it should flag a group of fields as 'view_only'.
- */
- //parent::__construct(false, false, true);
-
}
public function modelAction($actionData = false)
if ( isset( $memberInfo['categories'] ) ) {
$cats = array();
foreach ( $memberInfo['categories'] as $cat ) {
- $cats[] = $cat['name'];
+ $cats[] = $cat['parent_name'] . '/' . $cat['name'];
}
$categories = implode( '|', $cats );
}
'member-type' => 'Member',
);
//echo '<pre>$contactData: ' . print_r( $contactData, true ) . '</pre>';
+ //break;
if ( $ret->contact ) {
- echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
+ //echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
if ( $memberInfo['status']['value'] == 10 ) {
// Update Contact if member is active
+ $streamsend->contactUpdate(
+ $ret->contact->id,
+ $contactData
+ );
} else {
// Delete Contact if member is inactive
+ $streamsend->contactDelete( $memberInfo['email'] );
}
} else {
// Add Contact if member is active
break;
case 'memberContact':
+ $memberContact = $actionData['memberContact']['fieldData'];
+ //echo '<pre>$memberContact: ' . print_r( $memberContact, true ) . '</pre>';
+ if ( isset( $memberContact['email'] ) && $memberContact['email'] ) {
+ $ret = $streamsend->contactSearch( $memberContact['email'] );
+ $contactData = array(
+ 'email-address' => $memberContact['email'],
+ 'company' => $memberContact['ref_dest_name'],
+ 'address1' => $memberContact['addr1'],
+ 'address2' => $memberContact['addr2'],
+ 'city' => $memberContact['city']['name'],
+ 'stateprovince' => $memberContact['state']['name'],
+ 'postal-code' => $memberContact['zip'],
+ 'phone-number' => $memberContact['office_phone'],
+ 'member-type' => 'Member Contact',
+ );
+ if ( $ret->contact ) {
+ echo '<pre>$ret->contact: ' . print_r( $ret->contact, true ) . '</pre>';
+ if ( $memberContact['active']['value'] == 1 ) {
+ // Update Contact if member is active
+ $streamsend->contactUpdate(
+ $ret->contact->id,
+ $contactData
+ );
+ } else {
+ // Delete Contact if member is inactive
+ $streamsend->contactDelete( $memberContact['email'] );
+ }
+ } else {
+ // Add Contact if member is active
+ if ( $memberContact['active']['value'] == 1 ) {
+ $contacts = $streamsend->contactCreate(
+ $contactData,
+ STREAMSEND_DEFAULT_ACTIVATE,
+ STREAMSEND_DEFAULT_DELIVER_ACTIVATION,
+ STREAMSEND_DEFAULT_DELIVER_WELCOME
+ );
+ }
+ }
+ }
+ break;
+ case 'deleteMemberInfo':
+ $memberInfo = $actionData['memberInfo']['fieldData'];
+ $streamsend->contactDelete( $memberInfo['email'] );
+ break;
+ case 'deleteMemberContact':
+ $memberContact = $actionData['memberContact']['fieldData'];
+ $streamsend->contactDelete( $memberContact['email'] );
break;
}
}
- //echo '<pre>$config: ' . print_r( $config, true ) . '</pre>';
-
return array(
'status' => true,
'modelRedirect' => false,
);
-
}
-
-
}
switch ($option) {
- case 'settings':
+ case 'sync':
+ echo '<p>Please stand by whilst we sync you!</p>';
+
+ // Determine if current user can edit configurations
+ if (!current_user_can('glm_members_management')) {
+ return array(
+ 'status' => false,
+ 'menuItemRedirect' => 'error',
+ 'modelRedirect' => 'index',
+ 'view' => 'admin/error/index.html',
+ 'data' => array(
+ 'reason' => 'User does not have rights to make configuration changes.'
+ )
+ );
+ }
+ break;
+
+ case 'settings':
+
+ default:
+
+ // Make sure option is set if default
+ $option = 'settings';
+
+ // Determine if current user can edit configurations
+ if (!current_user_can('glm_members_management')) {
+ return array(
+ 'status' => false,
+ 'menuItemRedirect' => 'error',
+ 'modelRedirect' => 'index',
+ 'view' => 'admin/error/index.html',
+ 'data' => array(
+ 'reason' => 'User does not have rights to make configuration changes.'
+ )
+ );
+ }
+
+ // Check for submission option
+ $option2 = '';
+ if (isset($_REQUEST['option2'])) {
+ $option2 = $_REQUEST['option2'];
+ }
+
+ switch($option2) {
+
+ // Update the settings and redisplay the form
+ case 'submit':
+
+ // Update the event management settings
+ $communicator_settings = $this->updateEntry(1);
+ if ($communicator_settings['status']) {
+ $settings_updated = true;
+ } else {
+ $settings_update_error = true;
+ }
+
+ break;
+
+ // Default is to get the current settings and display the form
+ default:
+
+
+ break;
+
+ }
+
+ break;
- default:
-
- // Make sure option is set if default
- $option = 'settings';
-
- // Determine if current user can edit configurations
- if (!current_user_can('glm_members_management')) {
- return array(
- 'status' => false,
- 'menuItemRedirect' => 'error',
- 'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
- 'reason' => 'User does not have rights to make configuration changes.'
- )
- );
- }
-
- // Check for submission option
- $option2 = '';
- if (isset($_REQUEST['option2'])) {
- $option2 = $_REQUEST['option2'];
- }
-
- switch($option2) {
-
- // Update the settings and redisplay the form
- case 'submit':
-
- // Update the event management settings
- $communicator_settings = $this->updateEntry(1);
- if ($communicator_settings['status']) {
- $settings_updated = true;
- } else {
- $settings_update_error = true;
- }
-
- break;
-
- // Default is to get the current settings and display the form
- default:
-
- // Try to get the first (should be only) entry for general settings.
- $communicator_settings = $this->editEntry(1);
- //echo '<pre>$communicator_settings: ' . print_r( $communicator_settings, true ) . '</pre>';
-
- if ($communicator_settings === false) {
-
- if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
- glmMembersAdmin::addNotice("<b> /models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert');
- }
-
- }
-
- break;
+ }
- }
+ // Try to get the first (should be only) entry for general settings.
+ $communicator_settings = $this->editEntry(1);
- break;
+ if ($communicator_settings === false) {
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice("<b> /models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert');
+ }
}
// Compile template data
$template_data = array(
- 'option' => $option,
- 'settingsUpdated' => $settings_updated,
- 'settingsUpdateError' => $settings_update_error,
- 'communicatorSettings' => $communicator_settings,
+ 'option' => $option,
+ 'settingsUpdated' => $settings_updated,
+ 'settingsUpdateError' => $settings_update_error,
+ 'communicatorSettings' => $communicator_settings,
);
// Return status, suggested view, and data to controller
*/
// Adding Action for when the memberInfo record is saved (new or update)
add_action('glm-member-db-memberinfosave', function($member){
- $memberData = array(
+ $this->controller( 'communicator', 'index', array(
'type' => 'memberInfo',
'memberInfo' => $member
- );
- $this->controller( 'communicator', 'index', $memberData );
-}, 10, 2);
+ ) );
+}, 10, 1);
// Adding Action for when the Member Contact record is saved (new or update)
add_action('glm-member-db-membercontactsave', function($contact){
- // Code here for hook
- echo '<p>Contact action hook</p>';
- echo '<pre>$contact: ' . print_r( $contact, true ) . '</pre>';
+ $this->controller( 'communicator', 'index', array(
+ 'type' => 'memberContact',
+ 'memberContact' => $contact
+ ) );
}, 10, 1);
enable_constant_contact BOOLEAN NULL, -- Constant Contact On Off Flag
constant_contact_password TINYTEXT NULL, -- Constant Contact Password
constant_contact_api_key TINYTEXT NULL, -- Constant Contact API Key
- constant_contact_login TINYTEXT NULL, -- Constant Contact Login
+ constant_contact_login TINYTEXT NULL, -- Constant Contact Login
constant_contact_api_path TINYTEXT NULL, -- Constant Contact API Path
constant_contact_list TINYTEXT NULL, -- Constant Contact List ID
enable_mailchimp BOOLEAN NULL, -- MailChimp On Off
VALUES
( 1, false, false, false )
;
+
+----
+
+-- StreamSend Cache Table
+CREATE TABLE {prefix}streamsend_cache (
+ id INT NOT NULL AUTO_INCREMENT,
+ field_id INT NOT NULL, -- Field id for Member Category
+ field_name TINYTEXT NOT NULL, -- Field Name from StreamSend
+ option_id INT NOT NULL, -- StreamSend field id
+ option_name TINYTEXT NOT NULL, -- StreamSend option name
+ category_id INT NOT NULL, -- Member Category id
+ PRIMARY KEY (id)
+);
*/
$glmMembersCommunicatorDbVersions = array(
- '0.0.1' => array('version' => '0.0.1', 'tables' => 1),
+ '0.0.1' => array('version' => '0.0.1', 'tables' => 2),
);
<!-- Management Settings -->
<table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
+ <tr>
+ <td>
+ <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="communicator">
+ <input type="hidden" name="option" value="sync">
+ <table class="glm-admin-table">
+ <tr>
+ <td colspan="2"><h3>Sync StreamSend</h3></td>
+ </tr>
+ </table>
+ <input type="submit" value="Sync" class="button-primary">
+ </form>
+ </td>
+ </tr>
<tr>
<td colspan="2">
{if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}