/*
- * Get Apha list of first characters in member name
+ * Get Alpha list of first characters in member name
* for those members that have active info.
*
* @param string $where Where clause
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Old/New Member IDs CSV output by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+/*
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_newOldMemberIdsCsv
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /*
+ * Constructor
+ *
+ * This contructor sets up this model. At this time that only includes
+ * storing away the WordPress data object.
+ *
+ * @return object Class object
+ *
+ */
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ /*
+ * Perform Model Action
+ *
+ * This modelAction takes an AJAX image upload and stores the image in the
+ * media/images directory of the plugin.
+ *
+ * This model action does not return, it simply does it's work then calls die();
+ *
+ * @param $actionData
+ *
+ * Echos JSON string as response and does not return
+ */
+ public function modelAction ($actionData = false)
+ {
+
+ $members = $this->wpdb->get_results( "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members ORDER BY name", ARRAY_A );
+
+ header("Content-Type: text/csv");
+ header("Content-Disposition: attachment; filename=file.csv");
+ // Disable caching
+ header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
+ header("Pragma: no-cache"); // HTTP 1.0
+ header("Expires: 0"); // Proxies
+
+ // Output CSV
+ echo '"Member Name","Old Member ID","New Member ID"'."\r\n";
+
+ foreach($members as $m) {
+ echo '"'.$m['name'].'","'.$m['old_member_id'].'","'.$m['id'].'"'."\r\n";
+ }
+
+ die();
+
+ }
+
+}
require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/memberImages.php';
+ break;
+
+ case 'importOldMemberIds':
+
+ require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/oldMemberIds.php';
+
+ break;
+
+ case 'displayOldNewMemberIds':
+
+ require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/displayNewOldMemberIds.php';
+
+ break;
+
default:
break;
}
-
// Return status, suggested view, and data to controller
return array(
'status' => true,
--- /dev/null
+<?php
+/**
+ * Display New/Old Member IDs
+ */
+
+$templateData['members'] = $this->wpdb->get_results( "SELECT * FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members ORDER BY name", ARRAY_A );
+
+$requestedView = 'import/displayNewOldMemberIds.html';
+
+
if ($failure) {
- return array(
- 'status' => true,
- 'menuItemRedirect' => 'management',
- 'modelRedirect' => 'import',
- 'view' => 'admin/management/import.html',
- 'data' => $templateData
- );
-
+ $requestedView = 'import.html';
+} else {
+ $requestedView = 'import/members.html';
}
-$requestedView = 'import/members.html';
-
--- /dev/null
+<?php
+/**
+ * Import Old Member IDs
+ */
+
+$member = false;
+$idMatchingIssues = false;
+
+/*
+ * Check all input
+ */
+
+// Check hostname
+$dbServer = preg_replace("/[^a-zA-Z0-9\._-]+/", "", trim($_REQUEST['dbServer']));
+$templateData['dbServer'] = array('value' => $dbServer, 'problem' => false);
+if (!$dbServer || $dbServer == '' || $dbServer != trim($_REQUEST['dbServer'])) {
+ $templateData['dbServer']['problem'] = 'Server name or IP address was not provided or contained invalid characters.';
+ $failure = true;
+}
+
+// Check database port #
+$dbPort = preg_replace("/[^0-9]+/", "", trim($_REQUEST['dbPort']));
+$templateData['dbPort'] = array('value' => $dbPort, 'problem' => false);
+if (!$dbPort || $dbPort == '' || $dbPort != trim($_REQUEST['dbPort'])) {
+ $templateData['dbPort']['problem'] = 'Server port was not provided or is not a valid nummber.';
+ $failure = true;
+}
+
+// Check database name
+$dbName = preg_replace("/[^a-zA-Z0-9_]+/", "", trim($_REQUEST['dbName']));
+$templateData['dbName'] = array('value' => $dbName, 'problem' => false);
+if (!$dbName || $dbName == '' || $dbName != trim($_REQUEST['dbName'])) {
+ $templateData['dbName']['problem'] = 'Database name was not provided or is not valid for Postgres.';
+ $failure = true;
+}
+
+// Check database user
+$dbUser = preg_replace("/[^a-zA-Z0-9_]+/", "", trim($_REQUEST['dbUser']));
+$templateData['dbUser'] = array('value' => $dbUser, 'problem' => false);
+if (!$dbUser || $dbUser == '' || $dbUser != trim($_REQUEST['dbUser'])) {
+ $templateData['dbUser']['problem'] = 'Database user was not provided or is not valid for Postgres.';
+ $failure = true;
+}
+
+if ($failure) {
+ $templateData['genError'] = 'There was a problem with the database connection information you provided. See below for specific instructions.';
+}
+
+/*
+ * Determine if source database is sane
+ */
+
+// Connect to database
+if (!$failure) {
+ $connString = "host=$dbServer port=$dbPort dbname=$dbName user=$dbUser";
+ $db = @pg_connect($connString);
+ if (!$db) {
+
+ $err = error_get_last();
+ $templateData['genError'] = 'There was a problem connecting to the database. The error message was...<br>'.$err['message'];
+ $failure = true;
+
+ }
+}
+
+// Determine if the members schema exists
+if (!$failure) {
+ $sql = "
+ SELECT EXISTS
+ (
+ SELECT 1
+ FROM information_schema.schemata AS exists
+ WHERE schema_name = 'members'
+ ) AS isMembers
+ ;";
+ $res = pg_query($db, $sql);
+ if (pg_fetch_result($res, 0, 'isMembers') == 'f') {
+ $templateData['genError'] = 'The "members" schema was not found! Is this the right database?';
+ $failure = true;
+ }
+}
+
+/*
+ * Load data from source database
+ */
+
+// Attempt to get member base data
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member
+ ORDER BY member_id
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any members listed in this database!';
+ $failure = true;
+ } else {
+ $member = pg_fetch_all($res);
+ if (count($member) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading base member data, we did not receive the expected number of members! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ }
+ }
+}
+
+/*
+ * Clear old member IDs
+ */
+$this->wpdb->query("UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members SET old_member_id = NULL");
+
+/*
+ * Find new member IDs for old members
+ */
+$notFoundList = array();
+$numbMembersFound = 0;
+$numbMembersNotFound = 0;
+if (!$failure) {
+
+ // For each member in the old database, try to match to new member
+ foreach ( $member as $m ) {
+
+ $oldID = $m['member_id'];
+ $newID = false;
+
+ // Try matching with this name
+ $sql = $this->wpdb->prepare(
+ "SELECT id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members WHERE name = %s",
+ $m['member_name']
+ );
+ $res = $this->wpdb->get_results( $sql, ARRAY_A );
+
+ // If there's only one match, then this should be the new ID
+ if ($this->wpdb->num_rows == 1) {
+ $newID = $res[0]['id'];
+ } else {
+
+ // Try matching street address (line 1)
+ $sql = $this->wpdb->prepare(
+ "SELECT member FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info WHERE addr1 = %s AND status = %d",
+ $m['street'],
+ $this->config['status_numb']['Active']
+ );
+ $res = $this->wpdb->get_results( $sql, ARRAY_A );
+
+ // If there's only one match, this should be the active member info record for the matching member
+ if ($this->wpdb->num_rows == 1) {
+ $newID = $res[0]['member'];
+ }
+
+ }
+
+ // If we matched a member, update the member with the old id
+ if ($newID) {
+
+ $numbMembersFound++;
+
+ $this->wpdb->update(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX."members",
+ array( 'old_member_id' => $m['member_id']),
+ array( 'id' => $newID ),
+ array( '%d' ),
+ array( '%d' )
+ );
+
+ // Otherwise list as not found
+ } else {
+ $numbMembersNotFound++;
+ $notFoundList[] = $m['member_name'];
+ }
+
+ } // each old member
+
+}
+
+// If everything is OK, make data available to the template
+if (!$failure) {
+
+ $templateData['numbOldMembers'] = count($member);
+ $templateData['notFoundList'] = $notFoundList;
+ $templateData['numbMembersFound'] = $numbMembersFound;
+ $templateData['numbMembersNotFound'] = $numbMembersNotFound;
+ $requestedView = 'import/oldMemberIds.html';
+
+} else {
+ $requestedView = 'import.html';
+}
+
$glmMembersValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'imageUpload' => 'glm-member-db'
+ 'imageUpload' => 'glm-member-db',
+ 'newOldMemberIdsCsv' => 'glm-member-db'
),
'dashboardWidget' => array(
'index' => 'glm-member-db'
<a href="{$thisUrl}?page={$thisPage}&glm_action=terms" class="nav-tab{if $thisAction==terms} nav-tab-active{/if}">Terms and Phrases</a>
<a href="{$thisUrl}?page={$thisPage}&glm_action=theme" class="nav-tab{if $thisAction==theme} nav-tab-active{/if}">Theme Settings</a>
<a href="{$thisUrl}?page={$thisPage}&glm_action=development" class="nav-tab{if $thisAction==development} nav-tab-active{/if}">Development</a>
- <a href="{$thisUrl}?page={$thisPage}&glm_action=import" class="nav-tab{if $thisAction==import} nav-tab-active{/if}">Import Members</a>
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=import" class="nav-tab{if $thisAction==import} nav-tab-active{/if}">Members</a>
<a href="{$thisUrl}?page={$thisPage}&glm_action=addons" class="nav-tab{if $thisAction==addons} nav-tab-active{/if}">Add-Ons</a>
<a href="{$thisUrl}?page={$thisPage}&glm_action=hooks" class="nav-tab{if $thisAction==hooks} nav-tab-active{/if}">Hooks</a>
{foreach $addOnTabs as $a}
{include file='admin/management/header.html'}
- <h2>Data Import</h2>
- <p>
- This process exports data from a Postgres legacy Gaslight Media Member DB database and imports that data into this plugin.
- </p>
- <p>
- The process will include the following steps.
- </p>
- <ol>
- <li class="glm-ol-selected">Provide legacy database information and import member data.</li>
- <li>Import any images.</li>
- <li>Review results</li>
- </ol>
-
-
- <h3>Data Import Step 1: Supply database access information.</h3>
+ <h2>Data Import Step 1: Supply database access information.</h2>
{if isset($genError)}
<p>
<h3 class="glm-error">Oops!</h3>
{/if}
<form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
<input type="hidden" name="glm_action" value="import">
- <input type="hidden" name="option" value="members">
<table class="glm-admin-table">
- <!-- Debug Settings -->
-
<tr>
+ <th>Select Action:</th>
+ <td>
+ <input type="radio" name="option" value="members" checked="checked" class="import-type"> Import member data<br>
+ <input type="radio" name="option" value="importOldMemberIds" class="import-type"> Import old member IDs only<br>
+ <input type="radio" name="option" value="displayOldNewMemberIds" class="import-type"> List old/new member IDs
+ </td>
+ </tr>
+ <tr class="for-member-import all-import-fields">
+ <td colspan="2">
+ <p>
+ This process exports data from a Postgres legacy Gaslight Media Member DB database and imports that data into this plugin.
+ </p>
+ <p>
+ The process will include the following steps.
+ </p>
+ <ol>
+ <li class="glm-ol-selected">Provide legacy database information and import member data.</li>
+ <li>Import any images.</li>
+ <li>Review results</li>
+ </ol>
+ </td>
+ </tr>
+ <tr><td colspan="2"> </td></tr>
+ </table>
+ <table class="glm-admin-table">
+ <tr class="all-import-fields">
<th>Database Server: </th>
<td>
<input class="glm-form-text-input-medium" type="text" name="dbServer" placeholder="(complete host name or IP address)" value="{if isset($dbServer)}{$dbServer.value}{/if}">
{/if}
</td>
</tr>
- <tr>
+ <tr class="all-import-fields">
<th>Database Port #: </th>
<td>
<input class="glm-form-text-input-short" type="text" name="dbPort" value="{if isset($dbPort)}{$dbPort.value}{else}5432{/if}">
{/if}
</td>
</tr>
- <tr>
+ <tr class="all-import-fields">
<th>Database Name: </th>
<td>
<input class="glm-form-text-input-medium" type="text" name="dbName" placeholder="(name of database}" value="{if isset($dbName)}{$dbName.value}{/if}">
{/if}
</td>
</tr>
- <tr>
+ <tr class="all-import-fields">
<th>Database User: </th>
<td>
<input class="glm-form-text-input-medium" type="text" name="dbUser" placeholder="(user with read access to this database)" value="{if isset($dbUser)}{$dbUser.value}{/if}">
{/if}
</td>
</tr>
- <tr>
+ <tr class="for-member-import">
<th>Base Original Image URL: </th>
<td>
<input class="glm-form-text-input-medium-long" type="text" name="dbImageURL" placeholder="(i.e. http://is0.gaslightmedia.com/mountpleasantwow/original/)" value="{if isset($dbImageURL)}{$dbImageURL.value}{/if}">
{/if}
</td>
</tr>
- <tr>
+ <tr class="for-member-import">
<th>Reset Database Before Import: </th>
<td>
<input type="checkbox" name="dbReset">
</form>
{/if}
+<script type="text/javascript">
+
+ jQuery(document).ready(function($) {
+
+ $('.import-type').change( function() {
+
+ var selected = $(this).val();
+
+ $('.all-import-fields').removeClass('glm-hidden');
+ $('.for-member-import').removeClass('glm-hidden');
+
+ // if doing member data import
+ if (selected == 'members') {
+ // do nothing
+ } else if (selected == 'importOldMemberIds'){
+ $('.for-member-import').addClass('glm-hidden');
+ } else {
+ $('.for-member-import').addClass('glm-hidden');
+ $('.all-import-fields').addClass('glm-hidden');
+ }
+
+ });
+
+ });
+</script>
+
+
+
{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/management/header.html'}
+
+ <h2>New & Old Member IDs</h2>
+
+ <p><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=newOldMemberIdsCsv">Export as CSV File</a></p>
+
+ <table class="wp-list-table striped glm-admin-table">
+ <tr><th>Member</th><th>Old ID</th><th>New ID</th></tr>
+ {foreach $members as $m}
+ <tr><td>{$m.name}</td><td>{$m.old_member_id}</td><td>{$m.id}</td></tr>
+ {/foreach}
+ </table>
+
+{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/management/header.html'}
+
+ <h2>Import Old Member IDs - Data Import Results</h2>
+ <table class="glm-admin-table">
+ <tr><th>Number of Old Members</th><td>{$numbOldMembers}</td></tr>
+ <tr><th>Number of Members Found</th><td>{$numbMembersFound}</td></tr>
+ <tr><th>Number of Members Not Found</th><td>{$numbMembersNotFound}</td></tr>
+ </table>
+ <table class="wp-list-table striped glm-admin-table">
+ <tr><th>Old members not found in new database</th></tr>
+ {foreach $notFoundList as $n}
+ <tr><td>{$n}</td></tr>
+ {/foreach}
+ </table>
+
+
+{include file='admin/footer.html'}