mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH);
}
+ // Check if media directory has a subdirectory for files
+ if (!file_exists(GLM_MEMBERS_PLUGIN_FILES_PATH)) {
+ mkdir(GLM_MEMBERS_PLUGIN_FILES_PATH);
+ }
+
return;
}
if (isset($_REQUEST[$orderField]) && trim($_REQUEST[$orderField]) == '') {
if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
- glmMembersAdmin::addNotice('<b>dataImages: </b>galleryPositionOrder() unable to find '.$orderField.'data.', 'Process');
+ glmMembersAdmin::addNotice('<b>dataImages: </b>galleryPositionOrder() unable to find '.$orderField.' data. Perhaps there\'s no images at this time.', 'Process');
}
return false;
define('GLM_MEMBERS_PLUGIN_LIB_PATH', GLM_MEMBERS_PLUGIN_PATH.'/lib');
define('GLM_MEMBERS_PLUGIN_MEDIA_PATH', $WPUploadDir['basedir'].'/'.GLM_MEMBERS_PLUGIN_SLUG);
define('GLM_MEMBERS_PLUGIN_IMAGES_PATH', GLM_MEMBERS_PLUGIN_MEDIA_PATH.'/images');
+define('GLM_MEMBERS_PLUGIN_FILES_PATH', GLM_MEMBERS_PLUGIN_MEDIA_PATH.'/files');
define('GLM_MEMBERS_PLUGIN_CONFIG_PATH', GLM_MEMBERS_PLUGIN_PATH.'/config');
$pluginsPath = str_replace(GLM_MEMBERS_PLUGIN_SLUG, '', GLM_MEMBERS_PLUGIN_PATH);
*/
define('GLM_MEMBERS_PLUGIN_VERSION', '1.0.58');
-define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.1.1');
+define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.1.2');
// Check if plugin version is not current in WordPress option and if needed updated it
if (GLM_MEMBERS_PLUGIN_VERSION != get_option('glmMembersDatabasePluginVersion')) {
'time',
'datetime', // Full date and time
'phone',
+ 'file',
'image',
'latitude',
'longitude'
}
function textInput($as, $f, $id, $idField, $op)
{
+
// If this is setup for a new entry, then just return default value
if ($op == 'n') {
$in = '';
}
if (isset($f['maxLength']) && $f['maxLength'] && strlen($in) > $f['maxLength']) {
$this->inputFieldStatus = false;
- $this->inputErrorReason = 'Input is longer than maximum length of '.$f['maxLength'].' characters.';
+ $this->inputErrorReason = 'Input provided is '.strlen($in).' characters. The maximum length is '.$f['maxLength'].' characters.';
return $in;
}
if (isset($f['maxLength'])) {\r
if (trim($in) != '' && $f['maxLength'] && strlen($in) > $f['maxLength']) {\r
$this->inputFieldStatus = false;\r
- $this->inputErrorReason = 'Input is longer than maximum length of '.$f['maxLength'].' characters.';\r
+ $this->inputErrorReason = 'Input provided is '.strlen($in).' characters. The maximum length is '.$f['maxLength'].' characters.';\r
return $in;\r
}
}
function imageInput($as, $f, $id, $idfield, $op)
{
- $haveNewImage = false;
+ $new = false;
+
+ // Check if we have a new image being submitted
+ if (isset($_FILES[$as.'_new']) && is_array($_FILES[$as.'_new']) && $_FILES[$as.'_new']['tmp_name'] != '') {
+ $new = true;
+ }
// If this is setup for a new entry, there is no default image capability
if ($op == 'n') {
}
// If there a request to delete an existing image or a new image and there's a current image
- if (isset($_REQUEST[$as."_delete"]) && ($_REQUEST[$as."_delete"] == 'on' || $new) && $current_img != false) {
+ if ((isset($_REQUEST[$as."_delete"]) && $_REQUEST[$as."_delete"] == 'on') || ($new && $current_img != false)) {
// Scan all the image size directories and remove this image
while (list($k, $v) = each($this->config['imageSizes'])) {
if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$current_img)) {
unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$current_img);
+
}
}
- if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$current_img))
- unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$current_img);
+
+ // And if there's a copy in the original image directory
+ if (is_file(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$current_img)) {
+ unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original/'.$current_img);
+ }
$current_img = '';
}
// Is there a new image being uploaded
- if (isset($_FILES[$as.'_new']) && is_array($_FILES[$as.'_new']) && $_FILES[$as.'_new']['tmp_name'] != '') {
+ if ($new) {
// Get new image using temporary file name
$newImage = wp_get_image_editor($_FILES[$as.'_new']['tmp_name']);
// Get the desired file name and add a timestamp to it to ensure that it's unique
$fInfo = pathinfo($_FILES[$as.'_new']['name']);
- $newFilename = strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
+ $newFilename = $prefix.strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
// Get image temp file name - Not currently using, but should be using to check for resizing sanity
$size = $newImage->get_size();
$sizes = $newImage->multi_resize($this->config['imageSizes']);
// Finally, move the files to the various size directories and rename them back to the correct name
+ reset($this->config['imageSizes']);
while (list($k, $v) = each($this->config['imageSizes'])) {
// Check if size directory needs to be made
return "'".addslashes($in)."'";
}
+ /*
+ * File Field Processing
+ */
+ function fileField($f)
+ {
+ return 'T.'.$f['field'];
+ }
+ function fileOptions($f)
+ {
+ return false;
+ }
+ function fileOutput($f, $d)
+ {
+ return $d;
+ }
+ function fileInput($as, $f, $id, $idfield, $op)
+ {
+
+ $new = false;
+
+ // Check if we have a new file being submitted
+ if (isset($_FILES[$as.'_new']) && is_array($_FILES[$as.'_new']) && $_FILES[$as.'_new']['tmp_name'] != '') {
+ $new = true;
+ }
+
+ // If this is setup for a new entry, there is no default file capability
+ if ($op == 'n') {
+ $in = '';
+ return $in;
+ }
+
+ $current_file = false;
+
+ // Check if there's an existing file
+ if ($id != false) {
+
+ // If no id field is specified, use 'id'
+ if ($idfield == false) {
+ $idfield = 'id';
+ }
+
+ // Get the current file
+ $sql = "SELECT $as
+ FROM $this->table
+ WHERE $idfield = $id;";
+ $d = $this->wpdb->get_row($sql, ARRAY_A);
+
+ if (trim($d[$as]) != '') {
+ $current_file = $d[$as];
+ }
+ }
+
+ // If there a request to delete an existing file or a new file and there's a current one
+ if ((isset($_REQUEST[$as."_delete"]) && $_REQUEST[$as."_delete"] == 'on') || ($new && $current_file != false)) {
+
+ // Remove the current file
+ if (is_file(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$current_file))
+ unlink(GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$current_file);
+
+ $current_file = '';
+
+ }
+
+ // Is there a new file being uploaded
+ if ($new) {
+
+ // Check if there's a maxSize option specified (specified in KBytes
+ if (isset($f['maxSize']) && trim($f['maxSize']) != '') {
+
+ $max = ($f['maxSize'] - 0);
+
+ // Get the size of the uploaded file
+ $fileSize = filesize($_FILES[$as.'_new']['tmp_name']);
+
+ // If it's bigger than the max file size ($fileSize is in Bytes)
+ if ($fileSize > ($max * 1000)) {
+ $this->inputFieldStatus = false;
+ $this->inputErrorReason = 'File uploaded is '.intval($fileSize/1000).' kB. The maximum file size that may be submitted is '.$f['maxSize'].' kB.';
+ return $in;
+ }
+ }
+
+
+ // Check if there's a prefix that should be included in the file name
+ $prefix = '';
+ if (isset($f['f_prefix']) && trim($f['f_prefix']) != '') {
+ $prefix = $f['f_prefix'];
+ }
+
+ // Get the desired file name and add a timestamp to it to ensure that it's unique
+ $fInfo = pathinfo($_FILES[$as.'_new']['name']);
+ $newFilename = $prefix.strtolower($fInfo['filename'].'_'.time().'.'.$fInfo['extension']);
+
+ // Try to store the file using that file name
+ copy($_FILES[$as.'_new']['tmp_name'], GLM_MEMBERS_PLUGIN_FILES_PATH.'/'.$newFilename);
+
+ $current_file = $newFilename;
+
+ }
+
+ return $current_file;
+ }
+ function fileStore($in, $f)
+ {
+ return "'".addslashes($in)."'";
+ }
+
/*
* latitude Field Processing
*/
break;
- case 'readDatabase':
+ case 'members':
- /*
- * 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;
- }
-
- // Check Image URL
- $dbImageURL = filter_var($_REQUEST['dbImageURL'], FILTER_SANITIZE_URL);
- $templateData['dbImageURL'] = array('value' => $dbImageURL, 'problem' => false);
- if (!$dbImageURL || $dbImageURL == '' || $dbImageURL != trim($_REQUEST['dbImageURL'])) {
- $templateData['dbImageURL']['problem'] = 'Image URL does not appear to be valid.';
- $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;
- }
- }
- }
-
- // Read in all amenities
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.amenity
- ORDER BY amenity_name
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $amenity = array();
-
- // Reprocess into array indexed by amenity_id
- foreach ($tmp as $x) {
- $amenity[$x['amenity_id']] = $x;
- }
- }
- }
- }
-
- // Read in member/amenity cross-reference table
- $numbAmenityMembers = 0;
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.member_amenity
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any member/amenity cross-reference entries listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the ameities into an array indexed by amenity_id
- $membAmen = array();
-
- // Reprocess into array grouped by member with the main index the member ID
- foreach ($tmp as $x) {
-
- // If member entry hasn't been created yet, add it now
- if (!isset($membAmen[$x['member_id']])) {
- $membAmen[$x['member_id']] = array();
- }
-
- $membAmen[$x['member_id']][] = $x;
- $numbAmenityMembers++;
- }
- }
- }
- }
-
- // Read in all credit card types
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.ccard_type
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any credit card types listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading credit card type data, we did not receive the expected number of credit card types! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $ccard = array();
-
- // Reprocess into array indexed by ccard_type_id
- foreach ($tmp as $x) {
- $ccard[$x['ccard_type_id']] = $x;
- }
- }
- }
- }
-
- // Read in member/credit card cross-reference table
- $numbCcardMembers = 0;
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.member_ccard_type
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any member/credit card cross-reference entries listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading member/credit card cross-reference data, we did not receive the expected number of entries! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $membCcard = array();
-
- // Reprocess into array grouped by member with the main index the member ID
- foreach ($tmp as $x) {
-
- // If member entry hasn't been created yet, add it now
- if (!isset($membCcard[$x['member_id']])) {
- $membCcard[$x['member_id']] = array();
- }
-
- $membCcard[$x['member_id']][] = $x;
- $numbCcardMembers++;
- }
- }
- }
- }
-
-
- // Read in all member categories
- $haveCatImportIssues = false;
- $catImportIssues = '';
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.category
- ORDER BY category_id
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any categories listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the categories into a higherarchical array
- $category = array();
-
- // Process top level categories first
- foreach ($tmp as $x) {
-
- // If this is a top level category - parent = 0 or points to itself
- if ($x['parent_id'] == 0 || $x['parent_id'] == $x['category_id']) {
-
- foreach ($category as $y) {
- if ($y['name'] == $x['name']) {
- $haveCatImportIssues = true;
- $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') has the same name as another category at the same level. Added as duplicate.</li>';
- }
- }
- reset($category);
-
- $category[$x['category_id']] = $x;
- $category[$x['category_id']]['subcat'] = array();
-
- if ($x['parent_id'] == $x['category_id']) {
- $haveCatImportIssues = true;
- $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') was pointing to itself as a parent. Now a top level category.</li>';
- }
- }
-
- }
-
- // Now look for sub-categories with bad parents and add them as a main category
- reset($tmp);
- foreach ($tmp as $x) {
-
- // If this is NOT a top level category - Parent not 0 and not pointing to itself
- if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
-
- // Check if we don't have the requested parent as a top-level category
- if (!isset($category[$x['parent_id']])) {
- // Since the parent doesn't exist, we're just going to make this one a parent.
- $haveCatImportIssues = true;
- $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') had a bad parent ID ('.$x['parent_id'].'). Now a top level category.</li>';
- $category[$x['category_id']] = $x;
- $category[$x['category_id']]['subcat'] = array();
- }
- }
- }
-
- // Now process all supposedly good sub-categories
- reset($tmp);
- foreach ($tmp as $x) {
-
- // If this is NOT a top level category - Parent not 0 and not pointing to itself
- if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
-
- // Check if we have the requested parent as a top-level category
- if (isset($category[$x['parent_id']])) {
- $category[$x['parent_id']]['subcat'][$x['category_id']] = $x;
- }
- }
- }
- }
- }
- }
-
- // Read in member/Category cross-reference table
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.member_category
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any member/category cross-reference entries listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $membCat = array();
-
- // Reprocess into array grouped by member with the main index the member ID
- foreach ($tmp as $x) {
-
- // If member entry hasn't been created yet, add it now
- if (!isset($membCat[$x['member_id']])) {
- $membCat[$x['member_id']] = array();
- }
-
- $membCat[$x['member_id']][] = $x;
- }
- }
- }
- }
-
- // Read in all cities
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.city
- ORDER BY city_name
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading city data, we did not receive the expected number of cities! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $city = array();
-
- // Reprocess into array indexed by city_id
- foreach ($tmp as $x) {
- $city[$x['city_id']] = $x;
- }
- }
- }
- }
-
- // Read in all states
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.state
- ORDER BY state_name
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any states listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading state data, we did not receive the expected number of states! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $state = array();
-
- // Reprocess into array indexed by state_id
- foreach ($tmp as $x) {
- $state[$x['state_id']] = $x;
- }
- }
- }
- }
-
- // Read in all regions
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.region
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any regions listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading region data, we did not receive the expected number of regions! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $region = array();
-
- // Reprocess into array indexed by state_id
- foreach ($tmp as $x) {
- $region[$x['region_id']] = $x;
- }
- }
- }
- }
-
- // Read in all member photos for member image gallery
- $numbImagesFound = 0;
- if (!$failure) {
- $sql = "
- SELECT *
- FROM members.member_photos
- ;";
- $res = pg_query($db, $sql);
- $rows = pg_num_rows($res);
- if ($rows == 0) {
- $templateData['genError'] = 'There does not appear to be any member photos listed in this database!';
- $failure = true;
- } else {
- $tmp = pg_fetch_all($res);
- if (count($tmp) != $rows) {
- $notice = pg_last_notice($res);
- $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! ';
- if ($notice) {
- $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
- }
- $failure = true;
- } else {
-
- // Since there was no problem, we'll post-process the cities into an array indexed by city_id
- $image = array();
-
- // Reprocess into array grouped by member with the main index the member ID
- foreach ($tmp as $x) {
-
- // If member entry hasn't been created yet, add it now
- if (!isset($image[$x['member_id']])) {
- $image[$x['member_id']] = array(
- 'member_id' => $x['member_id'],
- 'images' => array()
- );
- }
-
- $image[$x['member_id']]['images'][] = $x;
- $numbImagesFound++;
- }
- }
- }
- }
-
- /*
- * If requested, reset the database
- */
-
- // Reset database is Option is selected
- if (!$failure && isset($_REQUEST['dbReset']) && $_REQUEST['dbReset'] == 'on') {
-
- // Get current db version
- $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
-
- // Reset the database
- if (!$this->deleteDataTables($dbVersion)) {
- glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
- break;
- }
- if (!$this->createDataTables($dbVersion)) {
- glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
- break;
- }
-
- glmMembersAdmin::addNotice('<b>Database tables have been reset in preparation importing members.</b><br>', 'AdminNotice');
-
- // Delete Images
- foreach( new RecursiveIteratorIterator(
-
- new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ),
- RecursiveIteratorIterator::CHILD_FIRST ) as $value ) {
- if ($value->isFile()) {
- unlink( $value );
- }
- }
-
- }
-
- /*
- * Start importing data
- */
-
- if (!$failure) {
-
- // Import Cities
- while (list ($key, $val) = each ($city) ) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'cities',
- array(
- 'name' => $val['city_name'],
- ),
- array(
- '%s',
- )
- );
- $city[$key]['new_id'] = $this->wpdb->insert_id;
-
- }
-
- // Import Regions
- while (list ($key, $val) = each ($region) ) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'regions',
- array(
- 'name' => $val['region_name'],
- 'descr' => '',
- 'short_descr' => ''
- ),
- array(
- '%s',
- '%s',
- '%s'
- )
- );
- $region[$key]['new_id'] = $this->wpdb->insert_id;
-
- }
-
- // Import Amenities
- while (list ($key, $val) = each ($amenity) ) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenities',
- array(
- 'active' => true,
- 'name' => $val['amenity_name'],
- 'descr' => '',
- 'short_descr' => '',
- 'ref_type' => $this->config['ref_type_numb']['MemberInfo']
- ),
- array(
- '%d',
- '%s',
- '%s',
- '%s',
- '%d'
- )
- );
- $amenity[$key]['new_id'] = $this->wpdb->insert_id;
-
- }
-
- // Import Categories
- $catTrans = array();
- $numbCategories = 0;
- while (list ($key, $val) = each ($category) ) {
-
- $numbCategories++;
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
- array(
- 'name' => $val['name'],
- 'descr' => '',
- 'short_descr' => '',
- 'parent' => 0
- ),
- array(
- '%s',
- '%s',
- '%s',
- '%d'
- )
- );
- $newID = $this->wpdb->insert_id;
- $category[$key]['new_id'] = $newID;
- $category[$key]['new_parent'] = 0;
-
- $catTrans[$key] = array(
- 'new' => $newID,
- 'parent' => 0
- );
-
- // Do any sub-cats for this category
- while (list ($key2, $val2) = each ($val['subcat']) ) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
- array(
- 'name' => $val2['name'],
- 'descr' => '',
- 'short_descr' => '',
- 'parent' => $category[$key]['new_id']
- ),
- array(
- '%s',
- '%s',
- '%s',
- '%d'
- )
- );
- $newID2 = $this->wpdb->insert_id;
- $category[$key]['subcat'][$key2]['new_id'] = $newID;
- $category[$key]['subcat'][$key2]['new_parent'] = $category[$key]['new_id'];
-
- $catTrans[$key2] = array(
- 'new' => $newID2,
- 'parent' => $newID
- );
-
- }
- }
-
-
-
- // Index Credit Card types - Match to card types in configuration
- while (list ($key, $val) = each ($ccard) ) {
- reset($this->config['credit_card_numb']);
- while (list ($key2, $val2) = each ($this->config['credit_card_numb']) ) {
- if (substr($val['ccard_type_name'], 0, 3) == substr(($key2), 0, 3)) {
- $ccard[$key]['bitpos'] = $val2;
- }
- }
- }
-
- /*
- * Create Defaults Not Provided By Old Member DB
- */
-
- // Member Types
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_type',
- array(
- 'name' => 'Default',
- 'descr' => '',
- ),
- array(
- '%s',
- '%s',
- )
- );
- $defaultMemberType = $this->wpdb->insert_id;
-
- /*
- * Now Start Adding Members
- */
-
- // Import Members
- $numbMembersActive = 0;
- $numbMembersInactive = 0;
- $namesInserted = array();
- $membImportIssues = '';
- $haveMembImportIssues = false;
- $dupeNames = 0;
- while (list ($key, $val) = each ($member) ) {
-
- // Determine if member is active and set access accordingly
- if ($val['active'] == 't') {
-
- // Member is active, so set to active-moderated
- $access = $this->config['access_numb']['Moderated'];
- $numbMembersActive++;
-
- } else {
-
- // Member is not active, so set to no display no access
- $access = $this->config['access_numb']['NotDisplayed'];
- $numbMembersInactive++;
-
- }
-
- // Check for duplicate name
- $membName = $val['member_name'];
- if (isset($namesInserted[$membName])) {
-
- // Bump dupe count and add to name to make this one unique
- $dupeNames++;
- $membName .= ' DUPE-'.$dupeNames;
-
- $membImportIssues .= '<li>Member Duplicate <b>'.$membName.'</b></li>';
- $haveMembImportIssues = true;
-
- }
-
- // Add main member record
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'members',
- array(
- 'access' => $access,
- 'member_type' => $defaultMemberType,
- 'created' => date('Y-m-d'),
- 'name' => $membName,
- 'member_slug' => sanitize_title($val['member_name']),
- 'old_member_id' => $val['member_id']
- ),
- array(
- '%d',
- '%d',
- '%s',
- '%s',
- '%s',
- '%d'
- )
- );
- $membID = $this->wpdb->insert_id;
- $member[$key]['new_id'] = $membID;
-
- // Add this member to the names inserted so we can check for duplicates
- $namesInserted[$membName] = true;
-
- // Create truncated short_descr from descritions - Less tags, html encoded characters, newlines, tabs, etc.
- $stripped = str_replace(PHP_EOL, '', preg_replace('/\t+/', '', preg_replace("/&#?[a-z0-9]{2,8};/i", "", strip_tags($val['description']))));
- $short_descr = implode(' ', array_slice(explode(' ', $stripped), 0, 30));
-
- if (strlen($short_descr) < strlen($stripped)) {
- $short_descr .= ' ...';
- }
-
- // Build Credit Card bitmap
- $ccBits = 0;
- if (isset($membCcard[$val['member_id']])) {
- foreach ($membCcard[$val['member_id']] as $c) {
- $b = $ccard[$c['ccard_type_id']]['bitpos'];
- $ccBits += pow(2, $b);
- }
- }
-
- // Insert Member Information Record
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
- array(
- 'member' => $membID,
- 'member_name' => $val['member_name'],
- 'status' => $this->config['status_numb']['Active'],
- 'reference_name' => 'Imported Member Information',
- 'descr' => $val['description'],
- 'short_descr' => $short_descr,
- 'addr1' => $val['street'],
- 'addr2' => '',
- 'city' => $city[$val['city_id']]['new_id'],
- 'state' => $state[$val['state_id']]['state_abb'],
- 'country' => 'US',
- 'zip' => $val['zip'],
- 'lat' => $val['lat'],
- 'lon' => $val['lon'],
- 'region' => (isset($region[$val['region']]) ? $region[$val['region']]['new_id'] : 0),
- 'phone' => $val['phone'],
- 'toll_free' => $val['toll_free'],
- 'url' => $val['url'],
- 'email' => $val['process_email'],
- 'logo' => '',
- 'cc_type' => $ccBits,
- 'notes' => '',
- 'create_time' => $val['create_date'],
- 'modify_time' => $val['last_update']
- ),
- array(
- '%d',
- '%s',
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
- '%s',
- '%s',
- '%s',
- '%f',
- '%f',
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
- '%s',
- '%s',
- '%s'
- )
- );
- $infoID = $this->wpdb->insert_id;
- $member[$key]['new_info_id'] = $infoID;
-
- // Add Member Categories
- if (isset($membCat[$val['member_id']])) {
- foreach ($membCat[$val['member_id']] as $c) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
- array(
- 'category' => $catTrans[$c['category_id']]['new'],
- 'member_info' => $infoID
- ),
- array(
- '%d',
- '%d'
- )
- );
-
- }
- }
-
- // Add Member Amenities
- if (isset($membAmen[$val['member_id']])) {
- foreach ($membAmen[$val['member_id']] as $a) {
-
- $res = $this->wpdb->insert(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenity_ref',
- array(
- 'amenity' => $amenity[$a['amenity_id']]['new_id'],
- 'ref_type' => $this->config['ref_type_numb']['MemberInfo'],
- 'ref_dest' => $infoID
- ),
- array(
- '%d',
- '%d',
- '%d'
- )
- );
-
- }
- }
-
- // Add logo to image array
- if ($val['logo'] != '') {
- // If member entry hasn't been created yet, add it now
- if (!isset($image[$val['member_id']])) {
- $image[$val['member_id']] = array(
- 'member_id' => $val['member_id'],
- 'images' => false
- );
- }
- $image[$val['member_id']]['logo'] = $val['logo'];
- }
-
- // Update image list with new member IDs
- if (isset($image[$val['member_id']])) {
- $image[$val['member_id']]['new_memberinfo_id'] = $infoID;
- }
-
- }
-
- // Import
-
- }
-
- // If everything is OK, make data available to the template
- if (!$failure) {
-
- update_option( 'glm-member-db-import-imageurl', $dbImageURL);
- update_option( 'glm-member-db-import-image', $image );
-
- $templateData['numbCities'] = count($city);
- $templateData['numbStates'] = count($state);
- $templateData['numbRegions'] = count($region);
- $templateData['numbMembers'] = count($member);
- $templateData['numbMembersActive'] = $numbMembersActive;
- $templateData['numbMembersInactive'] = $numbMembersInactive;
- $templateData['haveMembImportIssues'] = $haveMembImportIssues;
- $templateData['membImportIssues'] = $membImportIssues;
- $templateData['numbCategories'] = count($catTrans);
- $templateData['haveCatImportIssues'] = $haveCatImportIssues;
- $templateData['catImportIssues'] = $catImportIssues;
- $templateData['numbCategoryMembers'] = count($membCat);
- $templateData['numbAmenities'] = count($amenity);
- $templateData['numbAmenityMembers'] = $numbAmenityMembers;
- $templateData['numbImagesFound'] = $numbImagesFound;
- $templateData['numbCcards'] = count($ccard);
- $templateData['numbCcardMembers'] = $numbCcardMembers;
-
- // For testing only
- $templateData['member'] = $member;
- $templateData['defaultMemberType'] = $defaultMemberType;
- $templateData['amenity'] = $amenity;
- $templateData['membAmen'] = $membAmen;
- $templateData['category'] = $category;
- $templateData['membCat'] = $membCat;
- $templateData['catTrans'] = $catTrans;
- $templateData['city'] = $city;
- $templateData['state'] = $state;
- $templateData['region'] = $region;
- $templateData['ccard'] = $ccard;
- $templateData['membCcard'] = $membCcard;
- $templateData['image'] = $image;
- }
-
-
- if ($failure) {
- return array(
- 'status' => true,
- 'menuItemRedirect' => 'management',
- 'modelRedirect' => 'import',
- 'view' => 'admin/management/import.html',
- 'data' => $templateData
- );
-
- }
-
- $requestedView = 'import/readDatabase.html';
+ require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/members.php';
break;
- case 'importImages':
-
- require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
- $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
-
- $refType = $this->config['ref_type_numb']['MemberInfo'];
- $refTable = $this->config['ref_type_table'][$refType];
-
- // Get image array stored in a WordPress option
- $imageBaseURL = get_option( 'glm-member-db-import-imageurl', false );
- $image = get_option( 'glm-member-db-import-image', false );
-
- delete_option( 'glm-member-db-import-imageurl', false );
- delete_option( 'glm-member-db-import-image', false );
-
- // If we have image URLs
- if ($image != false) {
-
- // For each member
- foreach ($image as $m) {
-
- // Import member logo
- if (isset($m['logo'])) {
- $imageURL = $imageBaseURL.$m['logo'];
- $res = $ImageUpload->storeImage ($imageURL);
-
- // If we got a good new filename back, then it should be a good image store
- if ($res['newFileName']) {
-
- // Update the member record with the logo image name
- $res = $this->wpdb->update(
- GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
- array(
- 'logo' => $res['newFileName']
- ),
- array( 'id' => $m['new_memberinfo_id'] ),
- array( '%s' ),
- array( '%d' )
- );
- }
- }
-
- // For each image in this member's gallery
- if ($m['images']) {
- foreach ($m['images'] as $i) {
- $imageURL = $imageBaseURL.$i['image'];
- $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $m['new_memberinfo_id'], $i['caption']);
- }
- }
-
- }
-
- }
+ case 'images':
- $requestedView = 'import/importImages.html';
+ require GLM_MEMBERS_PLUGIN_PATH.'/models/admin/management/import/memberImages.php';
default:
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Data Import
+ *
+ * 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 for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_management_import
+{
+
+ /**
+ * 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 method does the work for this model and returns any resulting data
+ *
+ * @return array Status and data array
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'menuItemRedirect'
+ *
+ * If not false, provides a menu item the controller should
+ * execute after this one. Normally if this is used, there would also be a
+ * modelRedirect value supplied as well.
+ *
+ * 'modelRedirect'
+ *
+ * If not false, provides an action the controller should execute after
+ * this one.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ */
+ public function modelAction ($actionData = false)
+ {
+
+ $templateData = array();
+
+ $requestedView = false;
+ $failure = false;
+
+ $option = '';
+
+ // If there has been a redirect
+ if ($actionData) {
+
+ $templateData = $actionData;
+ $option = 'importSelect';
+
+ // Otherwise check the request for desired option
+ } elseif (isset($_REQUEST['option']) && $_REQUEST['option'] != '') {
+
+ $option = $_REQUEST['option'];
+
+ // Fall back to importSelect
+ } else {
+
+ $option = 'importSelect';
+
+ }
+
+ switch($option) {
+
+ case 'importSelect':
+
+ $requestedView = 'import.html';
+
+ break;
+
+ case 'readDatabase':
+
+ /*
+ * 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;
+ }
+
+ // Check Image URL
+ $dbImageURL = filter_var($_REQUEST['dbImageURL'], FILTER_SANITIZE_URL);
+ $templateData['dbImageURL'] = array('value' => $dbImageURL, 'problem' => false);
+ if (!$dbImageURL || $dbImageURL == '' || $dbImageURL != trim($_REQUEST['dbImageURL'])) {
+ $templateData['dbImageURL']['problem'] = 'Image URL does not appear to be valid.';
+ $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;
+ }
+ }
+ }
+
+ // Read in all amenities
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.amenity
+ ORDER BY amenity_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $amenity = array();
+
+ // Reprocess into array indexed by amenity_id
+ foreach ($tmp as $x) {
+ $amenity[$x['amenity_id']] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in member/amenity cross-reference table
+ $numbAmenityMembers = 0;
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_amenity
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/amenity cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the ameities into an array indexed by amenity_id
+ $membAmen = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membAmen[$x['member_id']])) {
+ $membAmen[$x['member_id']] = array();
+ }
+
+ $membAmen[$x['member_id']][] = $x;
+ $numbAmenityMembers++;
+ }
+ }
+ }
+ }
+
+ // Read in all credit card types
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.ccard_type
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any credit card types listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading credit card type data, we did not receive the expected number of credit card types! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $ccard = array();
+
+ // Reprocess into array indexed by ccard_type_id
+ foreach ($tmp as $x) {
+ $ccard[$x['ccard_type_id']] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in member/credit card cross-reference table
+ $numbCcardMembers = 0;
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_ccard_type
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/credit card cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading member/credit card cross-reference data, we did not receive the expected number of entries! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $membCcard = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membCcard[$x['member_id']])) {
+ $membCcard[$x['member_id']] = array();
+ }
+
+ $membCcard[$x['member_id']][] = $x;
+ $numbCcardMembers++;
+ }
+ }
+ }
+ }
+
+
+ // Read in all member categories
+ $haveCatImportIssues = false;
+ $catImportIssues = '';
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.category
+ ORDER BY category_id
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any categories listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the categories into a higherarchical array
+ $category = array();
+
+ // Process top level categories first
+ foreach ($tmp as $x) {
+
+ // If this is a top level category - parent = 0 or points to itself
+ if ($x['parent_id'] == 0 || $x['parent_id'] == $x['category_id']) {
+
+ foreach ($category as $y) {
+ if ($y['name'] == $x['name']) {
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') has the same name as another category at the same level. Added as duplicate.</li>';
+ }
+ }
+ reset($category);
+
+ $category[$x['category_id']] = $x;
+ $category[$x['category_id']]['subcat'] = array();
+
+ if ($x['parent_id'] == $x['category_id']) {
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') was pointing to itself as a parent. Now a top level category.</li>';
+ }
+ }
+
+ }
+
+ // Now look for sub-categories with bad parents and add them as a main category
+ reset($tmp);
+ foreach ($tmp as $x) {
+
+ // If this is NOT a top level category - Parent not 0 and not pointing to itself
+ if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
+
+ // Check if we don't have the requested parent as a top-level category
+ if (!isset($category[$x['parent_id']])) {
+ // Since the parent doesn't exist, we're just going to make this one a parent.
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') had a bad parent ID ('.$x['parent_id'].'). Now a top level category.</li>';
+ $category[$x['category_id']] = $x;
+ $category[$x['category_id']]['subcat'] = array();
+ }
+ }
+ }
+
+ // Now process all supposedly good sub-categories
+ reset($tmp);
+ foreach ($tmp as $x) {
+
+ // If this is NOT a top level category - Parent not 0 and not pointing to itself
+ if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
+
+ // Check if we have the requested parent as a top-level category
+ if (isset($category[$x['parent_id']])) {
+ $category[$x['parent_id']]['subcat'][$x['category_id']] = $x;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Read in member/Category cross-reference table
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_category
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/category cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $membCat = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membCat[$x['member_id']])) {
+ $membCat[$x['member_id']] = array();
+ }
+
+ $membCat[$x['member_id']][] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in all cities
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.city
+ ORDER BY city_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading city data, we did not receive the expected number of cities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $city = array();
+
+ // Reprocess into array indexed by city_id
+ foreach ($tmp as $x) {
+ $city[$x['city_id']] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in all states
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.state
+ ORDER BY state_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any states listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading state data, we did not receive the expected number of states! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $state = array();
+
+ // Reprocess into array indexed by state_id
+ foreach ($tmp as $x) {
+ $state[$x['state_id']] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in all regions
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.region
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any regions listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading region data, we did not receive the expected number of regions! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $region = array();
+
+ // Reprocess into array indexed by state_id
+ foreach ($tmp as $x) {
+ $region[$x['region_id']] = $x;
+ }
+ }
+ }
+ }
+
+ // Read in all member photos for member image gallery
+ $numbImagesFound = 0;
+ if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_photos
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member photos listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $image = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($image[$x['member_id']])) {
+ $image[$x['member_id']] = array(
+ 'member_id' => $x['member_id'],
+ 'images' => array()
+ );
+ }
+
+ $image[$x['member_id']]['images'][] = $x;
+ $numbImagesFound++;
+ }
+ }
+ }
+ }
+
+ /*
+ * If requested, reset the database
+ */
+
+ // Reset database is Option is selected
+ if (!$failure && isset($_REQUEST['dbReset']) && $_REQUEST['dbReset'] == 'on') {
+
+ // Get current db version
+ $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
+
+ // Reset the database
+ if (!$this->deleteDataTables($dbVersion)) {
+ glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
+ break;
+ }
+ if (!$this->createDataTables($dbVersion)) {
+ glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
+ break;
+ }
+
+ glmMembersAdmin::addNotice('<b>Database tables have been reset in preparation importing members.</b><br>', 'AdminNotice');
+
+ // Delete Images
+ foreach( new RecursiveIteratorIterator(
+
+ new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ),
+ RecursiveIteratorIterator::CHILD_FIRST ) as $value ) {
+ if ($value->isFile()) {
+ unlink( $value );
+ }
+ }
+
+ }
+
+ /*
+ * Start importing data
+ */
+
+ if (!$failure) {
+
+ // Import Cities
+ while (list ($key, $val) = each ($city) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'cities',
+ array(
+ 'name' => $val['city_name'],
+ ),
+ array(
+ '%s',
+ )
+ );
+ $city[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Regions
+ while (list ($key, $val) = each ($region) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'regions',
+ array(
+ 'name' => $val['region_name'],
+ 'descr' => '',
+ 'short_descr' => ''
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s'
+ )
+ );
+ $region[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Amenities
+ while (list ($key, $val) = each ($amenity) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenities',
+ array(
+ 'active' => true,
+ 'name' => $val['amenity_name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'ref_type' => $this->config['ref_type_numb']['MemberInfo']
+ ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $amenity[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Categories
+ $catTrans = array();
+ $numbCategories = 0;
+ while (list ($key, $val) = each ($category) ) {
+
+ $numbCategories++;
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
+ array(
+ 'name' => $val['name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'parent' => 0
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $newID = $this->wpdb->insert_id;
+ $category[$key]['new_id'] = $newID;
+ $category[$key]['new_parent'] = 0;
+
+ $catTrans[$key] = array(
+ 'new' => $newID,
+ 'parent' => 0
+ );
+
+ // Do any sub-cats for this category
+ while (list ($key2, $val2) = each ($val['subcat']) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
+ array(
+ 'name' => $val2['name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'parent' => $category[$key]['new_id']
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $newID2 = $this->wpdb->insert_id;
+ $category[$key]['subcat'][$key2]['new_id'] = $newID;
+ $category[$key]['subcat'][$key2]['new_parent'] = $category[$key]['new_id'];
+
+ $catTrans[$key2] = array(
+ 'new' => $newID2,
+ 'parent' => $newID
+ );
+
+ }
+ }
+
+
+
+ // Index Credit Card types - Match to card types in configuration
+ while (list ($key, $val) = each ($ccard) ) {
+ reset($this->config['credit_card_numb']);
+ while (list ($key2, $val2) = each ($this->config['credit_card_numb']) ) {
+ if (substr($val['ccard_type_name'], 0, 3) == substr(($key2), 0, 3)) {
+ $ccard[$key]['bitpos'] = $val2;
+ }
+ }
+ }
+
+ /*
+ * Create Defaults Not Provided By Old Member DB
+ */
+
+ // Member Types
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_type',
+ array(
+ 'name' => 'Default',
+ 'descr' => '',
+ ),
+ array(
+ '%s',
+ '%s',
+ )
+ );
+ $defaultMemberType = $this->wpdb->insert_id;
+
+ /*
+ * Now Start Adding Members
+ */
+
+ // Import Members
+ $numbMembersActive = 0;
+ $numbMembersInactive = 0;
+ $namesInserted = array();
+ $membImportIssues = '';
+ $haveMembImportIssues = false;
+ $dupeNames = 0;
+ while (list ($key, $val) = each ($member) ) {
+
+ // Determine if member is active and set access accordingly
+ if ($val['active'] == 't') {
+
+ // Member is active, so set to active-moderated
+ $access = $this->config['access_numb']['Moderated'];
+ $numbMembersActive++;
+
+ } else {
+
+ // Member is not active, so set to no display no access
+ $access = $this->config['access_numb']['NotDisplayed'];
+ $numbMembersInactive++;
+
+ }
+
+ // Check for duplicate name
+ $membName = $val['member_name'];
+ if (isset($namesInserted[$membName])) {
+
+ // Bump dupe count and add to name to make this one unique
+ $dupeNames++;
+ $membName .= ' DUPE-'.$dupeNames;
+
+ $membImportIssues .= '<li>Member Duplicate <b>'.$membName.'</b></li>';
+ $haveMembImportIssues = true;
+
+ }
+
+ // Add main member record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'members',
+ array(
+ 'access' => $access,
+ 'member_type' => $defaultMemberType,
+ 'created' => date('Y-m-d'),
+ 'name' => $membName,
+ 'member_slug' => sanitize_title($val['member_name']),
+ 'old_member_id' => $val['member_id']
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $membID = $this->wpdb->insert_id;
+ $member[$key]['new_id'] = $membID;
+
+ // Add this member to the names inserted so we can check for duplicates
+ $namesInserted[$membName] = true;
+
+ // Create truncated short_descr from descritions - Less tags, html encoded characters, newlines, tabs, etc.
+ $stripped = str_replace(PHP_EOL, '', preg_replace('/\t+/', '', preg_replace("/&#?[a-z0-9]{2,8};/i", "", strip_tags($val['description']))));
+ $short_descr = implode(' ', array_slice(explode(' ', $stripped), 0, 30));
+
+ if (strlen($short_descr) < strlen($stripped)) {
+ $short_descr .= ' ...';
+ }
+
+ // Build Credit Card bitmap
+ $ccBits = 0;
+ if (isset($membCcard[$val['member_id']])) {
+ foreach ($membCcard[$val['member_id']] as $c) {
+ $b = $ccard[$c['ccard_type_id']]['bitpos'];
+ $ccBits += pow(2, $b);
+ }
+ }
+
+ // Insert Member Information Record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'member' => $membID,
+ 'member_name' => $val['member_name'],
+ 'status' => $this->config['status_numb']['Active'],
+ 'reference_name' => 'Imported Member Information',
+ 'descr' => $val['description'],
+ 'short_descr' => $short_descr,
+ 'addr1' => $val['street'],
+ 'addr2' => '',
+ 'city' => $city[$val['city_id']]['new_id'],
+ 'state' => $state[$val['state_id']]['state_abb'],
+ 'country' => 'US',
+ 'zip' => $val['zip'],
+ 'lat' => $val['lat'],
+ 'lon' => $val['lon'],
+ 'region' => (isset($region[$val['region']]) ? $region[$val['region']]['new_id'] : 0),
+ 'phone' => $val['phone'],
+ 'toll_free' => $val['toll_free'],
+ 'url' => $val['url'],
+ 'email' => $val['process_email'],
+ 'logo' => '',
+ 'cc_type' => $ccBits,
+ 'notes' => '',
+ 'create_time' => $val['create_date'],
+ 'modify_time' => $val['last_update']
+ ),
+ array(
+ '%d',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%f',
+ '%f',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s'
+ )
+ );
+ $infoID = $this->wpdb->insert_id;
+ $member[$key]['new_info_id'] = $infoID;
+
+ // Add Member Categories
+ if (isset($membCat[$val['member_id']])) {
+ foreach ($membCat[$val['member_id']] as $c) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
+ array(
+ 'category' => $catTrans[$c['category_id']]['new'],
+ 'member_info' => $infoID
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add Member Amenities
+ if (isset($membAmen[$val['member_id']])) {
+ foreach ($membAmen[$val['member_id']] as $a) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenity_ref',
+ array(
+ 'amenity' => $amenity[$a['amenity_id']]['new_id'],
+ 'ref_type' => $this->config['ref_type_numb']['MemberInfo'],
+ 'ref_dest' => $infoID
+ ),
+ array(
+ '%d',
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add logo to image array
+ if ($val['logo'] != '') {
+ // If member entry hasn't been created yet, add it now
+ if (!isset($image[$val['member_id']])) {
+ $image[$val['member_id']] = array(
+ 'member_id' => $val['member_id'],
+ 'images' => false
+ );
+ }
+ $image[$val['member_id']]['logo'] = $val['logo'];
+ }
+
+ // Update image list with new member IDs
+ if (isset($image[$val['member_id']])) {
+ $image[$val['member_id']]['new_memberinfo_id'] = $infoID;
+ }
+
+ }
+
+ // Import
+
+ }
+
+ // If everything is OK, make data available to the template
+ if (!$failure) {
+
+ update_option( 'glm-member-db-import-imageurl', $dbImageURL);
+ update_option( 'glm-member-db-import-image', $image );
+
+ $templateData['numbCities'] = count($city);
+ $templateData['numbStates'] = count($state);
+ $templateData['numbRegions'] = count($region);
+ $templateData['numbMembers'] = count($member);
+ $templateData['numbMembersActive'] = $numbMembersActive;
+ $templateData['numbMembersInactive'] = $numbMembersInactive;
+ $templateData['haveMembImportIssues'] = $haveMembImportIssues;
+ $templateData['membImportIssues'] = $membImportIssues;
+ $templateData['numbCategories'] = count($catTrans);
+ $templateData['haveCatImportIssues'] = $haveCatImportIssues;
+ $templateData['catImportIssues'] = $catImportIssues;
+ $templateData['numbCategoryMembers'] = count($membCat);
+ $templateData['numbAmenities'] = count($amenity);
+ $templateData['numbAmenityMembers'] = $numbAmenityMembers;
+ $templateData['numbImagesFound'] = $numbImagesFound;
+ $templateData['numbCcards'] = count($ccard);
+ $templateData['numbCcardMembers'] = $numbCcardMembers;
+
+ // For testing only
+ $templateData['member'] = $member;
+ $templateData['defaultMemberType'] = $defaultMemberType;
+ $templateData['amenity'] = $amenity;
+ $templateData['membAmen'] = $membAmen;
+ $templateData['category'] = $category;
+ $templateData['membCat'] = $membCat;
+ $templateData['catTrans'] = $catTrans;
+ $templateData['city'] = $city;
+ $templateData['state'] = $state;
+ $templateData['region'] = $region;
+ $templateData['ccard'] = $ccard;
+ $templateData['membCcard'] = $membCcard;
+ $templateData['image'] = $image;
+ }
+
+
+ if ($failure) {
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => 'management',
+ 'modelRedirect' => 'import',
+ 'view' => 'admin/management/import.html',
+ 'data' => $templateData
+ );
+
+ }
+
+ $requestedView = 'import/readDatabase.html';
+
+ break;
+
+ case 'importImages':
+
+ require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
+ $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+ $refType = $this->config['ref_type_numb']['MemberInfo'];
+ $refTable = $this->config['ref_type_table'][$refType];
+
+ // Get image array stored in a WordPress option
+ $imageBaseURL = get_option( 'glm-member-db-import-imageurl', false );
+ $image = get_option( 'glm-member-db-import-image', false );
+
+ delete_option( 'glm-member-db-import-imageurl', false );
+ delete_option( 'glm-member-db-import-image', false );
+
+ // If we have image URLs
+ if ($image != false) {
+
+ // For each member
+ foreach ($image as $m) {
+
+ // Import member logo
+ if (isset($m['logo'])) {
+ $imageURL = $imageBaseURL.$m['logo'];
+ $res = $ImageUpload->storeImage ($imageURL);
+
+ // If we got a good new filename back, then it should be a good image store
+ if ($res['newFileName']) {
+
+ // Update the member record with the logo image name
+ $res = $this->wpdb->update(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'logo' => $res['newFileName']
+ ),
+ array( 'id' => $m['new_memberinfo_id'] ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+ // For each image in this member's gallery
+ if ($m['images']) {
+ foreach ($m['images'] as $i) {
+ $imageURL = $imageBaseURL.$i['image'];
+ $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $m['new_memberinfo_id'], $i['caption']);
+ }
+ }
+
+ }
+
+ }
+
+ $requestedView = 'import/importImages.html';
+
+ default:
+
+ break;
+
+ }
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/management/'.$requestedView,
+ 'data' => $templateData
+ );
+
+ }
+
+ /**
+ * Delete Members Database Tables
+ *
+ * @param string $dbVersion Current version of Members Database
+ *
+ * @return boolean
+ * @access public
+ */
+ public function deleteDataTables($dbVersion)
+ {
+
+ // Read in Database deletion script - assumes the current db version.
+ $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/drop_database_V'.$dbVersion.'.sql';
+ $sql = file_get_contents($sqlFile);
+
+ // Replace {prefix} with table name prefix
+ $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice('Dropping all database tables', 'Process');
+ glmMembersAdmin::addNotice($sql, 'DataBlock', 'Drop Tables SQL');
+ }
+
+ // Removing the tables using the script
+ $this->wpdb->query($sql);
+
+ // If there's been an error, display in debug Alert
+ $queryError = $this->wpdb->last_error;
+ if ($queryError) {
+ glmMembersAdmin::addNotice('<b>Error when deleting database: Database tables may not have existed.</b><br>Check following message.<br>'.$queryError, 'AdminError');
+ }
+
+ return true;
+
+ }
+
+ /**
+ * Create Members Database Tables
+ *
+ * @param string $dbVersion Current version of Members Database
+ *
+ * @return boolean
+ * @access public
+ */
+ public function createDataTables($dbVersion)
+ {
+
+ // Read in Database creation script
+ $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/create_database_V'.$dbVersion.'.sql';
+ $sql = file_get_contents($sqlFile);
+
+ // Replace {prefix} with table name prefix
+ $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+
+ // Split script into separate queries by looking for lines with only "---"
+ $queries = preg_split('/^----$/m', $sql);
+
+ // Try executing all queries to build database
+ $qForDebug = '';
+ do {
+ $q = current($queries);
+ $this->wpdb->query($q);
+ $queryError = $this->wpdb->last_error;
+
+ if ($queryError) {
+ glmMembersAdmin::addNotice('<b>Error when creating database: Database tables may already exist.</b><br>Check following message.<br>'.$queryError, 'AdminError');
+ return false;
+ }
+ $qForDebug .= $queryError.$q;
+
+ } while ($queryError == '' && next($queries));
+
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice('Creating database tables', 'Process');
+ glmMembersAdmin::addNotice($qForDebug, 'DataBlock', 'Create Tables SQL');
+ }
+
+ return true;
+
+ }
+
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * Import Member Images
+ */
+
+require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
+$ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+$refType = $this->config['ref_type_numb']['MemberInfo'];
+$refTable = $this->config['ref_type_table'][$refType];
+
+// Get image array stored in a WordPress option
+$imageBaseURL = get_option( 'glm-member-db-import-imageurl', false );
+$image = get_option( 'glm-member-db-import-image', false );
+
+delete_option( 'glm-member-db-import-imageurl', false );
+delete_option( 'glm-member-db-import-image', false );
+
+// If we have image URLs
+if ($image != false) {
+
+ // For each member
+ foreach ($image as $m) {
+
+ // Import member logo
+ if (isset($m['logo'])) {
+ $imageURL = $imageBaseURL.$m['logo'];
+ $res = $ImageUpload->storeImage ($imageURL);
+
+ // If we got a good new filename back, then it should be a good image store
+ if ($res['newFileName']) {
+
+ // Update the member record with the logo image name
+ $res = $this->wpdb->update(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'logo' => $res['newFileName']
+ ),
+ array( 'id' => $m['new_memberinfo_id'] ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+ // For each image in this member's gallery
+ if ($m['images']) {
+ foreach ($m['images'] as $i) {
+ $imageURL = $imageBaseURL.$i['image'];
+ $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $m['new_memberinfo_id'], $i['caption']);
+ }
+ }
+
+ }
+
+}
+
+$requestedView = 'import/memberImages.html';
--- /dev/null
+<?php
+/**
+ * Import Members
+ */
+
+/*
+ * 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;
+}
+
+// Check Image URL
+$dbImageURL = filter_var($_REQUEST['dbImageURL'], FILTER_SANITIZE_URL);
+$templateData['dbImageURL'] = array('value' => $dbImageURL, 'problem' => false);
+if (!$dbImageURL || $dbImageURL == '' || $dbImageURL != trim($_REQUEST['dbImageURL'])) {
+ $templateData['dbImageURL']['problem'] = 'Image URL does not appear to be valid.';
+ $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;
+ }
+ }
+}
+
+// Read in all amenities
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.amenity
+ ORDER BY amenity_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $amenity = array();
+
+ // Reprocess into array indexed by amenity_id
+ foreach ($tmp as $x) {
+ $amenity[$x['amenity_id']] = $x;
+ }
+ }
+ }
+}
+
+// Read in member/amenity cross-reference table
+$numbAmenityMembers = 0;
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_amenity
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/amenity cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading amenity data, we did not receive the expected number of amenities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the ameities into an array indexed by amenity_id
+ $membAmen = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membAmen[$x['member_id']])) {
+ $membAmen[$x['member_id']] = array();
+ }
+
+ $membAmen[$x['member_id']][] = $x;
+ $numbAmenityMembers++;
+ }
+ }
+ }
+}
+
+// Read in all credit card types
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.ccard_type
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any credit card types listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading credit card type data, we did not receive the expected number of credit card types! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $ccard = array();
+
+ // Reprocess into array indexed by ccard_type_id
+ foreach ($tmp as $x) {
+ $ccard[$x['ccard_type_id']] = $x;
+ }
+ }
+ }
+}
+
+// Read in member/credit card cross-reference table
+$numbCcardMembers = 0;
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_ccard_type
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/credit card cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading member/credit card cross-reference data, we did not receive the expected number of entries! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $membCcard = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membCcard[$x['member_id']])) {
+ $membCcard[$x['member_id']] = array();
+ }
+
+ $membCcard[$x['member_id']][] = $x;
+ $numbCcardMembers++;
+ }
+ }
+ }
+}
+
+
+// Read in all member categories
+$haveCatImportIssues = false;
+$catImportIssues = '';
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.category
+ ORDER BY category_id
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any categories listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the categories into a higherarchical array
+ $category = array();
+
+ // Process top level categories first
+ foreach ($tmp as $x) {
+
+ // If this is a top level category - parent = 0 or points to itself
+ if ($x['parent_id'] == 0 || $x['parent_id'] == $x['category_id']) {
+
+ foreach ($category as $y) {
+ if ($y['name'] == $x['name']) {
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') has the same name as another category at the same level. Added as duplicate.</li>';
+ }
+ }
+ reset($category);
+
+ $category[$x['category_id']] = $x;
+ $category[$x['category_id']]['subcat'] = array();
+
+ if ($x['parent_id'] == $x['category_id']) {
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') was pointing to itself as a parent. Now a top level category.</li>';
+ }
+ }
+
+ }
+
+ // Now look for sub-categories with bad parents and add them as a main category
+ reset($tmp);
+ foreach ($tmp as $x) {
+
+ // If this is NOT a top level category - Parent not 0 and not pointing to itself
+ if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
+
+ // Check if we don't have the requested parent as a top-level category
+ if (!isset($category[$x['parent_id']])) {
+ // Since the parent doesn't exist, we're just going to make this one a parent.
+ $haveCatImportIssues = true;
+ $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') had a bad parent ID ('.$x['parent_id'].'). Now a top level category.</li>';
+ $category[$x['category_id']] = $x;
+ $category[$x['category_id']]['subcat'] = array();
+ }
+ }
+ }
+
+ // Now process all supposedly good sub-categories
+ reset($tmp);
+ foreach ($tmp as $x) {
+
+ // If this is NOT a top level category - Parent not 0 and not pointing to itself
+ if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
+
+ // Check if we have the requested parent as a top-level category
+ if (isset($category[$x['parent_id']])) {
+ $category[$x['parent_id']]['subcat'][$x['category_id']] = $x;
+ }
+ }
+ }
+ }
+ }
+}
+
+// Read in member/Category cross-reference table
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_category
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member/category cross-reference entries listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading category data, we did not receive the expected number of categories! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $membCat = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($membCat[$x['member_id']])) {
+ $membCat[$x['member_id']] = array();
+ }
+
+ $membCat[$x['member_id']][] = $x;
+ }
+ }
+ }
+}
+
+// Read in all cities
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.city
+ ORDER BY city_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any cities listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading city data, we did not receive the expected number of cities! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $city = array();
+
+ // Reprocess into array indexed by city_id
+ foreach ($tmp as $x) {
+ $city[$x['city_id']] = $x;
+ }
+ }
+ }
+}
+
+// Read in all states
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.state
+ ORDER BY state_name
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any states listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading state data, we did not receive the expected number of states! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $state = array();
+
+ // Reprocess into array indexed by state_id
+ foreach ($tmp as $x) {
+ $state[$x['state_id']] = $x;
+ }
+ }
+ }
+}
+
+// Read in all regions
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.region
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any regions listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading region data, we did not receive the expected number of regions! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $region = array();
+
+ // Reprocess into array indexed by state_id
+ foreach ($tmp as $x) {
+ $region[$x['region_id']] = $x;
+ }
+ }
+ }
+}
+
+// Read in all member photos for member image gallery
+$numbImagesFound = 0;
+if (!$failure) {
+ $sql = "
+ SELECT *
+ FROM members.member_photos
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+ if ($rows == 0) {
+ $templateData['genError'] = 'There does not appear to be any member photos listed in this database!';
+ $failure = true;
+ } else {
+ $tmp = pg_fetch_all($res);
+ if (count($tmp) != $rows) {
+ $notice = pg_last_notice($res);
+ $templateData['genError'] = 'While reading member photo data, we did not receive the expected number of member photos! ';
+ if ($notice) {
+ $templateData['genError'] .= 'Perhaps the following message will help.<br>'.$notice;
+ }
+ $failure = true;
+ } else {
+
+ // Since there was no problem, we'll post-process the cities into an array indexed by city_id
+ $image = array();
+
+ // Reprocess into array grouped by member with the main index the member ID
+ foreach ($tmp as $x) {
+
+ // If member entry hasn't been created yet, add it now
+ if (!isset($image[$x['member_id']])) {
+ $image[$x['member_id']] = array(
+ 'member_id' => $x['member_id'],
+ 'images' => array()
+ );
+ }
+
+ $image[$x['member_id']]['images'][] = $x;
+ $numbImagesFound++;
+ }
+ }
+ }
+}
+
+/*
+ * If requested, reset the database
+ */
+
+// Reset database is Option is selected
+if (!$failure && isset($_REQUEST['dbReset']) && $_REQUEST['dbReset'] == 'on') {
+
+ // Get current db version
+ $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
+
+ // Reset the database
+ if (!$this->deleteDataTables($dbVersion)) {
+ glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
+ break;
+ }
+ if (!$this->createDataTables($dbVersion)) {
+ glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
+ break;
+ }
+
+ glmMembersAdmin::addNotice('<b>Database tables have been reset in preparation importing members.</b><br>', 'AdminNotice');
+
+ // Delete Images
+ foreach( new RecursiveIteratorIterator(
+
+ new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ),
+ RecursiveIteratorIterator::CHILD_FIRST ) as $value ) {
+ if ($value->isFile()) {
+ unlink( $value );
+ }
+ }
+
+}
+
+/*
+ * Start importing data
+ */
+
+if (!$failure) {
+
+ // Import Cities
+ while (list ($key, $val) = each ($city) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'cities',
+ array(
+ 'name' => $val['city_name'],
+ ),
+ array(
+ '%s',
+ )
+ );
+ $city[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Regions
+ while (list ($key, $val) = each ($region) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'regions',
+ array(
+ 'name' => $val['region_name'],
+ 'descr' => '',
+ 'short_descr' => ''
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s'
+ )
+ );
+ $region[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Amenities
+ while (list ($key, $val) = each ($amenity) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenities',
+ array(
+ 'active' => true,
+ 'name' => $val['amenity_name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'ref_type' => $this->config['ref_type_numb']['MemberInfo']
+ ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $amenity[$key]['new_id'] = $this->wpdb->insert_id;
+
+ }
+
+ // Import Categories
+ $catTrans = array();
+ $numbCategories = 0;
+ while (list ($key, $val) = each ($category) ) {
+
+ $numbCategories++;
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
+ array(
+ 'name' => $val['name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'parent' => 0
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $newID = $this->wpdb->insert_id;
+ $category[$key]['new_id'] = $newID;
+ $category[$key]['new_parent'] = 0;
+
+ $catTrans[$key] = array(
+ 'new' => $newID,
+ 'parent' => 0
+ );
+
+ // Do any sub-cats for this category
+ while (list ($key2, $val2) = each ($val['subcat']) ) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'categories',
+ array(
+ 'name' => $val2['name'],
+ 'descr' => '',
+ 'short_descr' => '',
+ 'parent' => $category[$key]['new_id']
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $newID2 = $this->wpdb->insert_id;
+ $category[$key]['subcat'][$key2]['new_id'] = $newID;
+ $category[$key]['subcat'][$key2]['new_parent'] = $category[$key]['new_id'];
+
+ $catTrans[$key2] = array(
+ 'new' => $newID2,
+ 'parent' => $newID
+ );
+
+ }
+ }
+
+
+
+ // Index Credit Card types - Match to card types in configuration
+ while (list ($key, $val) = each ($ccard) ) {
+ reset($this->config['credit_card_numb']);
+ while (list ($key2, $val2) = each ($this->config['credit_card_numb']) ) {
+ if (substr($val['ccard_type_name'], 0, 3) == substr(($key2), 0, 3)) {
+ $ccard[$key]['bitpos'] = $val2;
+ }
+ }
+ }
+
+ /*
+ * Create Defaults Not Provided By Old Member DB
+ */
+
+ // Member Types
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_type',
+ array(
+ 'name' => 'Default',
+ 'descr' => '',
+ ),
+ array(
+ '%s',
+ '%s',
+ )
+ );
+ $defaultMemberType = $this->wpdb->insert_id;
+
+ /*
+ * Now Start Adding Members
+ */
+
+ // Import Members
+ $numbMembersActive = 0;
+ $numbMembersInactive = 0;
+ $namesInserted = array();
+ $membImportIssues = '';
+ $haveMembImportIssues = false;
+ $dupeNames = 0;
+ while (list ($key, $val) = each ($member) ) {
+
+ // Determine if member is active and set access accordingly
+ if ($val['active'] == 't') {
+
+ // Member is active, so set to active-moderated
+ $access = $this->config['access_numb']['Moderated'];
+ $numbMembersActive++;
+
+ } else {
+
+ // Member is not active, so set to no display no access
+ $access = $this->config['access_numb']['NotDisplayed'];
+ $numbMembersInactive++;
+
+ }
+
+ // Check for duplicate name
+ $membName = $val['member_name'];
+ if (isset($namesInserted[$membName])) {
+
+ // Bump dupe count and add to name to make this one unique
+ $dupeNames++;
+ $membName .= ' DUPE-'.$dupeNames;
+
+ $membImportIssues .= '<li>Member Duplicate <b>'.$membName.'</b></li>';
+ $haveMembImportIssues = true;
+
+ }
+
+ // Add main member record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'members',
+ array(
+ 'access' => $access,
+ 'member_type' => $defaultMemberType,
+ 'created' => date('Y-m-d'),
+ 'name' => $membName,
+ 'member_slug' => sanitize_title($val['member_name']),
+ 'old_member_id' => $val['member_id']
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ $membID = $this->wpdb->insert_id;
+ $member[$key]['new_id'] = $membID;
+
+ // Add this member to the names inserted so we can check for duplicates
+ $namesInserted[$membName] = true;
+
+ // Create truncated short_descr from descritions - Less tags, html encoded characters, newlines, tabs, etc.
+ $stripped = str_replace(PHP_EOL, '', preg_replace('/\t+/', '', preg_replace("/&#?[a-z0-9]{2,8};/i", "", strip_tags($val['description']))));
+ $short_descr = implode(' ', array_slice(explode(' ', $stripped), 0, 30));
+
+ if (strlen($short_descr) < strlen($stripped)) {
+ $short_descr .= ' ...';
+ }
+
+ // Build Credit Card bitmap
+ $ccBits = 0;
+ if (isset($membCcard[$val['member_id']])) {
+ foreach ($membCcard[$val['member_id']] as $c) {
+ $b = $ccard[$c['ccard_type_id']]['bitpos'];
+ $ccBits += pow(2, $b);
+ }
+ }
+
+ // Insert Member Information Record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'member' => $membID,
+ 'member_name' => $val['member_name'],
+ 'status' => $this->config['status_numb']['Active'],
+ 'reference_name' => 'Imported Member Information',
+ 'descr' => $val['description'],
+ 'short_descr' => $short_descr,
+ 'addr1' => $val['street'],
+ 'addr2' => '',
+ 'city' => $city[$val['city_id']]['new_id'],
+ 'state' => $state[$val['state_id']]['state_abb'],
+ 'country' => 'US',
+ 'zip' => $val['zip'],
+ 'lat' => $val['lat'],
+ 'lon' => $val['lon'],
+ 'region' => (isset($region[$val['region']]) ? $region[$val['region']]['new_id'] : 0),
+ 'phone' => $val['phone'],
+ 'toll_free' => $val['toll_free'],
+ 'url' => $val['url'],
+ 'email' => $val['process_email'],
+ 'logo' => '',
+ 'cc_type' => $ccBits,
+ 'notes' => '',
+ 'create_time' => $val['create_date'],
+ 'modify_time' => $val['last_update']
+ ),
+ array(
+ '%d',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%f',
+ '%f',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%s',
+ '%s',
+ '%s'
+ )
+ );
+ $infoID = $this->wpdb->insert_id;
+ $member[$key]['new_info_id'] = $infoID;
+
+ // Add Member Categories
+ if (isset($membCat[$val['member_id']])) {
+ foreach ($membCat[$val['member_id']] as $c) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
+ array(
+ 'category' => $catTrans[$c['category_id']]['new'],
+ 'member_info' => $infoID
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add Member Amenities
+ if (isset($membAmen[$val['member_id']])) {
+ foreach ($membAmen[$val['member_id']] as $a) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'amenity_ref',
+ array(
+ 'amenity' => $amenity[$a['amenity_id']]['new_id'],
+ 'ref_type' => $this->config['ref_type_numb']['MemberInfo'],
+ 'ref_dest' => $infoID
+ ),
+ array(
+ '%d',
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add logo to image array
+ if ($val['logo'] != '') {
+ // If member entry hasn't been created yet, add it now
+ if (!isset($image[$val['member_id']])) {
+ $image[$val['member_id']] = array(
+ 'member_id' => $val['member_id'],
+ 'images' => false
+ );
+ }
+ $image[$val['member_id']]['logo'] = $val['logo'];
+ }
+
+ // Update image list with new member IDs
+ if (isset($image[$val['member_id']])) {
+ $image[$val['member_id']]['new_memberinfo_id'] = $infoID;
+ }
+
+ }
+
+ // Import
+
+}
+
+// If everything is OK, make data available to the template
+if (!$failure) {
+
+ update_option( 'glm-member-db-import-imageurl', $dbImageURL);
+ update_option( 'glm-member-db-import-image', $image );
+
+ $templateData['numbCities'] = count($city);
+ $templateData['numbStates'] = count($state);
+ $templateData['numbRegions'] = count($region);
+ $templateData['numbMembers'] = count($member);
+ $templateData['numbMembersActive'] = $numbMembersActive;
+ $templateData['numbMembersInactive'] = $numbMembersInactive;
+ $templateData['haveMembImportIssues'] = $haveMembImportIssues;
+ $templateData['membImportIssues'] = $membImportIssues;
+ $templateData['numbCategories'] = count($catTrans);
+ $templateData['haveCatImportIssues'] = $haveCatImportIssues;
+ $templateData['catImportIssues'] = $catImportIssues;
+ $templateData['numbCategoryMembers'] = count($membCat);
+ $templateData['numbAmenities'] = count($amenity);
+ $templateData['numbAmenityMembers'] = $numbAmenityMembers;
+ $templateData['numbImagesFound'] = $numbImagesFound;
+ $templateData['numbCcards'] = count($ccard);
+ $templateData['numbCcardMembers'] = $numbCcardMembers;
+
+ // For testing only
+ $templateData['member'] = $member;
+ $templateData['defaultMemberType'] = $defaultMemberType;
+ $templateData['amenity'] = $amenity;
+ $templateData['membAmen'] = $membAmen;
+ $templateData['category'] = $category;
+ $templateData['membCat'] = $membCat;
+ $templateData['catTrans'] = $catTrans;
+ $templateData['city'] = $city;
+ $templateData['state'] = $state;
+ $templateData['region'] = $region;
+ $templateData['ccard'] = $ccard;
+ $templateData['membCcard'] = $membCcard;
+ $templateData['image'] = $image;
+}
+
+
+if ($failure) {
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => 'management',
+ 'modelRedirect' => 'import',
+ 'view' => 'admin/management/import.html',
+ 'data' => $templateData
+ );
+
+}
+
+$requestedView = 'import/members.html';
+
if ($this->haveMemberInfo) {
// Update the member Info data
- $this->memberInfo = $this->updateEntry($this->memberInfoID, 'id', true, true);
+ $this->memberInfo = $this->updateEntry($this->memberInfoID, 'id', true);
+
if ($this->memberInfo['status']) {
$memberUpdated = true;
} else {
$memberUpdateError = true;
}
- break;
-
} else {
if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
glmMembersAdmin::addNotice("<b> No member information exists, assuming this is a new submission.", 'Process');
}
- // Note that if we don't have an existing member info record, we fall through to "addNew" below.
-
}
+ break;
+
// Add the new member information record
case 'addNew':
+++ /dev/null
--- Gaslight Media Members Database
--- File Created: 12/09/14 15:27:15
--- Database Version: 1.0.43
--- Database Creation Script
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
---
--- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES ****
---
-
--- Amenities
-CREATE TABLE {prefix}amenities (
- id INT NOT NULL AUTO_INCREMENT,
- active TINYINT(1) NULL, -- Amenity is active flag
- name TINYTEXT NULL, -- Name of amenity
- descr TEXT NULL, -- Description of amenity
- short_descr TINYTEXT NULL, -- Short description of amenity
- ref_type INT NULL, -- Type of entity these amenitites are associated with - see plugin.ini ref_type tables
- uses_value BOOLEAN NULL, -- Flag indicating whether the amenity requires a quantity number
- PRIMARY KEY (id),
- INDEX(name(20))
-);
-
-----
-
--- Amenity Reference - Links a specific amenity to a specific entity of type ref_type
-CREATE TABLE {prefix}amenity_ref (
- id INT NOT NULL AUTO_INCREMENT,
- amenity INT NULL, -- Pointer to amenity in amenities table
- ref_type INT NULL, -- Copy of ref_type from matching ameities table entry - to simplify searches
- ref_dest INT NULL, -- Pointer to the specific entity of type ref_type
- amenity_value TINYTEXT NULL, -- Quanity if amenity uses values
- PRIMARY KEY (id),
- INDEX(ref_type),
- INDEX(ref_dest)
-);
-
-----
-
--- Member Cateogries - used with member information records
-CREATE TABLE {prefix}categories (
- id INT NOT NULL AUTO_INCREMENT,
- name TINYTEXT NULL, -- Name of this category
- descr TEXT NULL, -- Description of this category
- short_descr TINYTEXT NULL, -- Short description of this category
- parent INT NULL, -- Pointer to parent category in this table - if there is one
- PRIMARY KEY (id)
-);
-
-----
-
--- Mapping of categories to speific member information records
-CREATE TABLE {prefix}category_member_info (
- id INT NOT NULL AUTO_INCREMENT,
- category INT NULL, -- Pointer to category in categories table
- member_info INT NULL, -- Pointer to member infomation record
- PRIMARY KEY (id),
- CONSTRAINT {prefix}categories_fk_1
- FOREIGN KEY (category)
- REFERENCES {prefix}categories (id)
- ON DELETE CASCADE,
- INDEX(category),
- INDEX(member_info)
-);
-
-----
-
--- Cities
-CREATE TABLE {prefix}cities (
- id INT NOT NULL AUTO_INCREMENT,
- name TINYTEXT NULL, -- Name of city
- PRIMARY KEY (id)
-);
-
-----
-
--- Contacts - used by various entities
-CREATE TABLE {prefix}contacts (
- id INT NOT NULL AUTO_INCREMENT,
- active BOOLEAN NULL, -- Contact is active flag
- access INT NULL, -- Access type - See access table in plugin.ini
- fname TINYTEXT NULL, -- First name of contact
- lname TINYTEXT NULL, -- Last name of contact
- contact_type INT NULL, -- Contact type - see contact_type table (individual, role, ...)
- contact_role INT NULL, -- Contact WordPress user Role
- org TINYTEXT NULL, -- Organization name
- title TINYTEXT NULL, -- Title/Position
- descr TEXT NULL, -- Description of position/responsibilities - Displayed
- image TINYTEXT NULL, -- Image
- addr1 TINYTEXT NULL, -- Address line 1 - Address is for contact, not necessarily for organization
- addr2 TINYTEXT NULL, -- Address line 2
- city INT NULL, -- Pointer to city in cities table
- state TINYTEXT NULL, -- Two character state code - matches states.ini entries
- country TINYTEXT NULL, -- Two character country code - matches countries.ini entries
- zip TINYTEXT NULL, -- ZIP/Postal Code
- lat FLOAT NULL, -- Latitude of contact location
- lon FLOAT NULL, -- Longitude of contact location
- url TINYTEXT NULL, -- URL to information regarding this contact
- office_phone TINYTEXT NULL, -- Office phone number
- home_phone TINYTEXT NULL, -- Home phone number - or after-hours phone number
- mobile_phone TINYTEXT NULL, -- Mobile phone number
- alt_phone TINYTEXT NULL, -- An alternate phone number
- fax TINYTEXT NULL, -- FAX number (do people still use these?)
- email TINYTEXT NULL, -- E-Mail address
- alt_email TINYTEXT NULL, -- Alternate E-Mail address - Also used to log-in
- username TINYTEXT NULL, -- Optional username to use for login
- password TINYTEXT NULL, -- Encrypted password
- notes TEXT NULL, -- Notes - Not displayed on front-end
- create_time TIMESTAMP NULL, -- Create date/time
- modify_time TIMESTAMP NULL, -- Last modified date/time
- ref_type INT NULL, -- Type of entity this contact is associated with
- ref_dest INT NULL, -- Pointer to the specific entity of ref_type this contact is associated with
- PRIMARY KEY (id),
- INDEX(fname(20)),
- INDEX(lname(20)),
- INDEX(city),
- INDEX(zip(10)),
- INDEX(lat),
- INDEX(lon),
- INDEX(email(20))
-);
-
-----
-
--- Images - Images are stored under /wp-content/uploads/glm-member-db/images/{size}/
-CREATE TABLE {prefix}images (
- id INT NOT NULL AUTO_INCREMENT,
- name TINYTEXT NULL, -- Original name of the image - might be URL if copied via HTTP
- status TINYINT(1) NULL, -- Display/Use status - See plugin.ini status table
- selected BOOLEAN NULL, -- A single special image in the current gallery for this entity
- featured BOOLEAN null, -- Image is a member of a group of featured images
- file_name TINYTEXT NULL, -- Stored file name for the image
- descr TEXT NULL, -- Description
- caption TINYTEXT NULL, -- Caption for the image
- position INT NULL, -- Numeric position for sequence of display
- ref_type INT NULL, -- Type of entity this image is associated with
- ref_dest INT NULL, -- Pointer to the specific entity of ref_type this image is associated with
- PRIMARY KEY (id),
- INDEX(name(20)),
- INDEX(file_name(20)),
- INDEX(ref_type),
- INDEX(ref_dest)
-);
-
-----
-
--- Primary member records - One for each member
-CREATE TABLE {prefix}members (
- id INT NOT NULL AUTO_INCREMENT,
- access INT NULL, -- Access type - See access table in plugin.ini
- member_type INT NULL, -- Pointer to member type in member_type table
- created DATE NULL, -- Date member record was created
- name TINYTEXT NULL, -- Member name
- member_slug TINYTEXT NULL, -- Member name slug for canonical URLs (lowercase, "-" for spaces, no punctuation)
- notes TEXT NULL, -- General notes - Not displayed in front-end
- old_member_id INT NULL, -- Old member ID if imported from old database
- PRIMARY KEY (id),
- INDEX(name(20)),
- INDEX(member_slug(20)),
- INDEX(created)
-);
-
-----
-
--- Member information version record - May be multiples per member - Only one with stauts "Active" for a distinct date range
-CREATE TABLE {prefix}member_info (
- id INT NOT NULL AUTO_INCREMENT,
- member INT NULL, -- Pointer to member record in table members
- member_name TINYTEXT NULL, -- Copy of member name from members table entry for fast reference
- status INT NULL, -- Status of this member information record - See plugin.ini status table
- reference_name TINYTEXT NULL, -- Refernce name for this member information record - Not displayed on front-end
- descr TEXT NULL, -- Description
- short_descr TEXT NULL, -- Short description
- addr1 TINYTEXT NULL, -- Main member location address line 1
- addr2 TINYTEXT NULL, -- Address line 2
- city INT NULL, -- Pointer to City in cities table
- state TINYTEXT NULL, -- Two character state code - matches states.ini entries
- country TINYTEXT NULL, -- Two character country code - matches countries.ini entries
- zip TINYTEXT NULL, -- ZIP/Postal code
- lat FLOAT NULL, -- Latitude of member's location
- lon FLOAT NULL, -- Longitude of member's location
- region INT NULL, -- Pointer to entry in regions table
- phone TINYTEXT NULL, -- Primary phone number
- toll_free TINYTEXT NULL, -- Toll Free phone number
- url TINYTEXT NULL, -- URL with information about this member
- email TINYTEXT NULL, -- Main E-Mail address for this member
- logo TINYTEXT NULL, -- Member logo
- cc_type INT NULL, -- Bitmap of credit card types accepted - See credit_card array in plugin.ini
- notes TEXT NULL, -- General notes - Not displayed in front-end
- create_time TIMESTAMP NULL, -- Create date/time
- modify_time TIMESTAMP NULL, -- Last update date/time
- PRIMARY KEY (id),
- INDEX(status),
- INDEX(city),
- INDEX(zip(10)),
- INDEX(lat),
- INDEX(lon),
- INDEX(region)
-);
-
-----
-
--- Member type - Can be used to assign members to different "classes" of membership (i.e. Full, Associate, Premium)
--- Mostly for internal use by the member organization, but could be displayed - Consider a short_description if they are.
-CREATE TABLE {prefix}member_type (
- id INT NOT NULL AUTO_INCREMENT,
- name TINYTEXT NULL, -- Name of member type
- descr TINYTEXT NULL, -- Description of member type
- PRIMARY KEY (id)
-);
-
-----
-
--- Regions - Used to segment members into various geographical regions - can be cities, counties, or other logical regions
-CREATE TABLE {prefix}regions (
- id INT NOT NULL AUTO_INCREMENT,
- name TINYTEXT NULL, -- Name of region
- descr TEXT NULL, -- Descrption of region
- short_descr TINYTEXT NULL, -- Short descroption of region
- PRIMARY KEY (id)
-);
-
-----
-
--- General settings available on Management page in admin - Only 1 entry in this table
--- Items in this table should be all self-explanatory
-CREATE TABLE {prefix}settings_general (
- id INT NOT NULL AUTO_INCREMENT,
- admin_debug BOOLEAN DEFAULT '1',
- admin_debug_verbose BOOLEAN DEFAULT '0',
- front_debug BOOLEAN DEFAULT '0',
- front_debug_verbose BOOLEAN DEFAULT '0',
- google_maps_api_key TINYTEXT DEFAULT '',
- maps_default_lat FLOAT DEFAULT '45.3749',
- maps_default_lon FLOAT DEFAULT '-84.9592',
- maps_default_zoom INTEGER DEFAULT '10',
- time_zone TINYTEXT DEFAULT NULL,
- canonical_member_page TINYTEXT DEFAULT NULL,
- list_show_map BOOLEAN DEFAULT '1',
- list_show_list BOOLEAN DEFAULT '1',
- list_show_search BOOLEAN DEFAULT '1',
- list_show_search_text BOOLEAN DEFAULT '1',
- list_show_search_category BOOLEAN DEFAULT '1',
- list_show_search_amenities BOOLEAN DEFAULT '1',
- list_show_search_alpha BOOLEAN DEFAULT '1',
- list_show_detail_link BOOLEAN DEFAULT '1',
- list_show_logo BOOLEAN DEFAULT '1',
- list_logo_size TINYTEXT NULL,
- list_show_address BOOLEAN DEFAULT '1',
- list_show_street BOOLEAN DEFAULT '1',
- list_show_citystatezip BOOLEAN DEFAULT '1',
- list_show_country BOOLEAN DEFAULT '1',
- list_show_region BOOLEAN DEFAULT '1',
- list_show_descr BOOLEAN DEFAULT '0',
- list_show_short_descr BOOLEAN DEFAULT '1',
- list_show_phone BOOLEAN DEFAULT '1',
- list_show_tollfree BOOLEAN DEFAULT '1',
- list_show_url BOOLEAN DEFAULT '1',
- list_show_url_newtarget BOOLEAN DEFAULT '1',
- list_show_email BOOLEAN DEFAULT '1',
- list_show_categories BOOLEAN DEFAULT '0',
- list_show_creditcards BOOLEAN DEFAULT '0',
- list_show_amenities BOOLEAN DEFAULT '0',
- list_map_show_detaillink BOOLEAN DEFAULT '1',
- list_map_show_logo BOOLEAN DEFAULT '0',
- list_map_logo_size TINYTEXT NULL,
- list_map_show_descr BOOLEAN DEFAULT '0',
- list_map_show_short_descr BOOLEAN DEFAULT '1',
- list_map_show_address BOOLEAN DEFAULT '1',
- list_map_show_street BOOLEAN DEFAULT '1',
- list_map_show_citystatezip BOOLEAN DEFAULT '1',
- list_map_show_country BOOLEAN DEFAULT '1',
- list_map_show_region BOOLEAN DEFAULT '1',
- list_map_show_phone BOOLEAN DEFAULT '1',
- list_map_show_tollfree BOOLEAN DEFAULT '1',
- list_map_show_url BOOLEAN DEFAULT '1',
- list_map_show_url_newtarget BOOLEAN DEFAULT '1',
- list_map_show_email BOOLEAN DEFAULT '1',
- list_map_show_categories BOOLEAN DEFAULT '0',
- list_map_show_creditcards BOOLEAN DEFAULT '0',
- list_map_show_amenities BOOLEAN DEFAULT '0',
- detail_show_map BOOLEAN DEFAULT '1',
- detail_show_directions BOOLEAN DEFAULT '1',
- detail_show_logo BOOLEAN DEFAULT '1',
- detail_logo_size TINYTEXT NULL,
- detail_show_descr BOOLEAN DEFAULT '1',
- detail_show_short_descr BOOLEAN DEFAULT '0',
- detail_show_address BOOLEAN DEFAULT '1',
- detail_show_street BOOLEAN DEFAULT '1',
- detail_show_citystatezip BOOLEAN DEFAULT '1',
- detail_show_country BOOLEAN DEFAULT '1',
- detail_show_region BOOLEAN DEFAULT '1',
- detail_show_phone BOOLEAN DEFAULT '1',
- detail_show_tollfree BOOLEAN DEFAULT '1',
- detail_show_url BOOLEAN DEFAULT '1',
- detail_show_url_newtarget BOOLEAN DEFAULT '1',
- detail_show_email BOOLEAN DEFAULT '1',
- detail_show_categories BOOLEAN DEFAULT '0',
- detail_show_creditcards BOOLEAN DEFAULT '0',
- detail_show_amenities BOOLEAN DEFAULT '1',
- detail_show_imagegallery BOOLEAN DEFAULT '1',
- detail_show_coupons BOOLEAN DEFAULT '0',
- detail_show_packages BOOLEAN DEFAULT '0',
- detail_map_show_logo BOOLEAN DEFAULT '0',
- detail_map_logo_size TINYTEXT NULL,
- detail_map_show_descr BOOLEAN DEFAULT '0',
- detail_map_show_short_descr BOOLEAN DEFAULT '1',
- detail_map_show_address BOOLEAN DEFAULT '1',
- detail_map_show_street BOOLEAN DEFAULT '1',
- detail_map_show_citystatezip BOOLEAN DEFAULT '1',
- detail_map_show_country BOOLEAN DEFAULT '1',
- detail_map_show_region BOOLEAN DEFAULT '1',
- detail_map_show_phone BOOLEAN DEFAULT '1',
- detail_map_show_tollfree BOOLEAN DEFAULT '1',
- detail_map_show_url BOOLEAN DEFAULT '1',
- detail_map_show_url_newtarget BOOLEAN DEFAULT '1',
- detail_map_show_email BOOLEAN DEFAULT '1',
- detail_map_show_categories BOOLEAN DEFAULT '0',
- detail_map_show_creditcards BOOLEAN DEFAULT '0',
- detail_map_show_amenities BOOLEAN DEFAULT '0',
- PRIMARY KEY (id)
-);
-
-----
-
--- Set default entry
-INSERT INTO {prefix}settings_general
- ( id, time_zone, canonical_member_page, list_logo_size, list_map_logo_size, detail_logo_size, detail_map_logo_size )
- VALUES
- ( 1, 'America/Detroit', 'member-detail', 'large', 'thumb', 'large', 'thumb' )
-;
-
-----
-
--- Terms used in site modifiable on Management page in admin - Only 1 entry in this table
--- Tems in this table should be all self-explanatory
-CREATE TABLE {prefix}settings_terms (
- id INT NOT NULL AUTO_INCREMENT,
- term_admin_menu_members TINYTEXT NULL,
- term_admin_menu_member_list TINYTEXT NULL,
- term_admin_menu_member TINYTEXT NULL,
- term_admin_menu_configure TINYTEXT NULL,
- term_admin_menu_settings TINYTEXT NULL,
- term_admin_menu_shortcodes TINYTEXT NULL,
- term_admin_menu_members_dashboard TINYTEXT NULL,
- term_admin_menu_members_list TINYTEXT NULL,
- term_admin_menu_members_reports TINYTEXT NULL,
- term_admin_menu_member_dashboard TINYTEXT NULL,
- term_admin_menu_member_info TINYTEXT NULL,
- term_admin_menu_member_locations TINYTEXT NULL,
- term_admin_menu_member_facilities TINYTEXT NULL,
- term_admin_menu_member_attractions TINYTEXT NULL,
- term_admin_menu_member_contacts TINYTEXT NULL,
- term_admin_menu_configure_member_types TINYTEXT NULL,
- term_admin_menu_configure_member_cats TINYTEXT NULL,
- term_admin_menu_configure_accom_types TINYTEXT NULL,
- term_admin_menu_configure_amenities TINYTEXT NULL,
- term_admin_menu_configure_cities TINYTEXT NULL,
- term_admin_menu_configure_regions TINYTEXT NULL,
- term_admin_menu_settings_general TINYTEXT NULL,
- term_admin_menu_settings_terms TINYTEXT NULL,
- term_admin_menu_settings_development TINYTEXT NULL,
- term_member TINYTEXT NULL,
- term_member_cap TINYTEXT NULL,
- term_member_plur TINYTEXT NULL,
- term_member_plur_cap TINYTEXT NULL,
- term_location TINYTEXT NULL,
- term_location_cap TINYTEXT NULL,
- term_location_plur TINYTEXT NULL,
- term_location_plur_cap TINYTEXT NULL,
- term_facility TINYTEXT NULL,
- term_facility_cap TINYTEXT NULL,
- term_facility_plur TINYTEXT NULL,
- term_facility_plur_cap TINYTEXT NULL,
- term_attraction TINYTEXT NULL,
- term_attraction_cap TINYTEXT NULL,
- term_attraction_plur TINYTEXT NULL,
- term_attraction_plur_cap TINYTEXT NULL,
- term_contact TINYTEXT NULL,
- term_contact_cap TINYTEXT NULL,
- term_contact_plur TINYTEXT NULL,
- term_contact_plur_cap TINYTEXT NULL,
- PRIMARY KEY (id)
-);
-
-----
-
--- Default terms entry
-INSERT INTO {prefix}settings_terms
- (
- id,
- term_admin_menu_members,
- term_admin_menu_member_list,
- term_admin_menu_member,
- term_admin_menu_configure,
- term_admin_menu_settings,
- term_admin_menu_shortcodes,
- term_admin_menu_members_dashboard,
- term_admin_menu_members_list,
- term_admin_menu_members_reports,
- term_admin_menu_member_dashboard,
- term_admin_menu_member_info,
- term_admin_menu_member_locations,
- term_admin_menu_member_facilities,
- term_admin_menu_member_attractions,
- term_admin_menu_member_contacts,
- term_admin_menu_configure_member_types,
- term_admin_menu_configure_member_cats,
- term_admin_menu_configure_accom_types,
- term_admin_menu_configure_amenities,
- term_admin_menu_configure_cities,
- term_admin_menu_configure_regions,
- term_admin_menu_settings_general,
- term_admin_menu_settings_terms,
- term_admin_menu_settings_development,
- term_member,
- term_member_cap,
- term_member_plur,
- term_member_plur_cap,
- term_location,
- term_location_cap,
- term_location_plur,
- term_location_plur_cap,
- term_facility,
- term_facility_cap,
- term_facility_plur,
- term_facility_plur_cap,
- term_attraction,
- term_attraction_cap,
- term_attraction_plur,
- term_attraction_plur_cap,
- term_contact,
- term_contact_cap,
- term_contact_plur,
- term_contact_plur_cap
- )
- VALUES
- (
- 1,
- 'Members',
- 'Member',
- 'Member',
- 'Configure',
- 'Management',
- 'Shortcodes',
- 'Dashboard',
- 'Member List',
- 'Reports',
- 'Member Dashboard',
- 'Member Info',
- 'Locations',
- 'Facilities',
- 'Attractions',
- 'Contacts',
- 'Member Types',
- 'Member Categories',
- 'Accommodation Types',
- 'Amenities',
- 'Cities',
- 'Regions',
- 'General Settings',
- 'Terms & Phrases',
- 'Development',
- 'member',
- 'Member',
- 'members',
- 'Members',
- 'location',
- 'Location',
- 'locations',
- 'Locations',
- 'facility',
- 'Facility',
- 'facilities',
- 'Facilities',
- 'attraction',
- 'Attraction',
- 'attractions',
- 'Attractions',
- 'contact',
- 'Contact',
- 'contacts',
- 'Contacts'
- )
-;
--- /dev/null
+-- Gaslight Media Members Database
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 1.0.43
+-- Database Creation Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+--
+-- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES ****
+--
+
+-- Amenities
+CREATE TABLE {prefix}amenities (
+ id INT NOT NULL AUTO_INCREMENT,
+ active TINYINT(1) NULL, -- Amenity is active flag
+ name TINYTEXT NULL, -- Name of amenity
+ descr TEXT NULL, -- Description of amenity
+ short_descr TINYTEXT NULL, -- Short description of amenity
+ ref_type INT NULL, -- Type of entity these amenitites are associated with - see plugin.ini ref_type tables
+ uses_value BOOLEAN NULL, -- Flag indicating whether the amenity requires a quantity number
+ PRIMARY KEY (id),
+ INDEX(name(20))
+);
+
+----
+
+-- Amenity Reference - Links a specific amenity to a specific entity of type ref_type
+CREATE TABLE {prefix}amenity_ref (
+ id INT NOT NULL AUTO_INCREMENT,
+ amenity INT NULL, -- Pointer to amenity in amenities table
+ ref_type INT NULL, -- Copy of ref_type from matching ameities table entry - to simplify searches
+ ref_dest INT NULL, -- Pointer to the specific entity of type ref_type
+ amenity_value TINYTEXT NULL, -- Quanity if amenity uses values
+ PRIMARY KEY (id),
+ INDEX(ref_type),
+ INDEX(ref_dest)
+);
+
+----
+
+-- Member Cateogries - used with member information records
+CREATE TABLE {prefix}categories (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Name of this category
+ descr TEXT NULL, -- Description of this category
+ short_descr TINYTEXT NULL, -- Short description of this category
+ parent INT NULL, -- Pointer to parent category in this table - if there is one
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Mapping of categories to speific member information records
+CREATE TABLE {prefix}category_member_info (
+ id INT NOT NULL AUTO_INCREMENT,
+ category INT NULL, -- Pointer to category in categories table
+ member_info INT NULL, -- Pointer to member infomation record
+ PRIMARY KEY (id),
+ CONSTRAINT {prefix}categories_fk_1
+ FOREIGN KEY (category)
+ REFERENCES {prefix}categories (id)
+ ON DELETE CASCADE,
+ INDEX(category),
+ INDEX(member_info)
+);
+
+----
+
+-- Cities
+CREATE TABLE {prefix}cities (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Name of city
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Contacts - used by various entities
+CREATE TABLE {prefix}contacts (
+ id INT NOT NULL AUTO_INCREMENT,
+ active BOOLEAN NULL, -- Contact is active flag
+ access INT NULL, -- Access type - See access table in plugin.ini
+ fname TINYTEXT NULL, -- First name of contact
+ lname TINYTEXT NULL, -- Last name of contact
+ contact_type INT NULL, -- Contact type - see contact_type table (individual, role, ...)
+ contact_role INT NULL, -- Contact WordPress user Role
+ org TINYTEXT NULL, -- Organization name
+ title TINYTEXT NULL, -- Title/Position
+ descr TEXT NULL, -- Description of position/responsibilities - Displayed
+ image TINYTEXT NULL, -- Image
+ addr1 TINYTEXT NULL, -- Address line 1 - Address is for contact, not necessarily for organization
+ addr2 TINYTEXT NULL, -- Address line 2
+ city INT NULL, -- Pointer to city in cities table
+ state TINYTEXT NULL, -- Two character state code - matches states.ini entries
+ country TINYTEXT NULL, -- Two character country code - matches countries.ini entries
+ zip TINYTEXT NULL, -- ZIP/Postal Code
+ lat FLOAT NULL, -- Latitude of contact location
+ lon FLOAT NULL, -- Longitude of contact location
+ url TINYTEXT NULL, -- URL to information regarding this contact
+ office_phone TINYTEXT NULL, -- Office phone number
+ home_phone TINYTEXT NULL, -- Home phone number - or after-hours phone number
+ mobile_phone TINYTEXT NULL, -- Mobile phone number
+ alt_phone TINYTEXT NULL, -- An alternate phone number
+ fax TINYTEXT NULL, -- FAX number (do people still use these?)
+ email TINYTEXT NULL, -- E-Mail address
+ alt_email TINYTEXT NULL, -- Alternate E-Mail address - Also used to log-in
+ username TINYTEXT NULL, -- Optional username to use for login
+ password TINYTEXT NULL, -- Encrypted password
+ notes TEXT NULL, -- Notes - Not displayed on front-end
+ create_time TIMESTAMP NULL, -- Create date/time
+ modify_time TIMESTAMP NULL, -- Last modified date/time
+ ref_type INT NULL, -- Type of entity this contact is associated with
+ ref_dest INT NULL, -- Pointer to the specific entity of ref_type this contact is associated with
+ PRIMARY KEY (id),
+ INDEX(fname(20)),
+ INDEX(lname(20)),
+ INDEX(city),
+ INDEX(zip(10)),
+ INDEX(lat),
+ INDEX(lon),
+ INDEX(email(20))
+);
+
+----
+
+-- Files - Files are stored under /wp-content/uploads/glm-member-db/files/
+CREATE TABLE {prefix}files (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Original name of the file - might be URL if copied via HTTP
+ status TINYINT(1) NULL, -- Display/Use status - See plugin.ini status table
+ file_name TINYTEXT NULL, -- Stored file name for the file
+ descr TEXT NULL, -- Description
+ position INT NULL, -- Numeric position for sequence of display
+ ref_type INT NULL, -- Type of entity this image is associated with
+ ref_dest INT NULL, -- Pointer to the specific entity of ref_type this image is associated with
+ PRIMARY KEY (id),
+ INDEX(name(20)),
+ INDEX(file_name(20)),
+ INDEX(ref_type),
+ INDEX(ref_dest)
+);
+
+----
+
+-- Images - Images are stored under /wp-content/uploads/glm-member-db/images/{size}/
+CREATE TABLE {prefix}images (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Original name of the image - might be URL if copied via HTTP
+ status TINYINT(1) NULL, -- Display/Use status - See plugin.ini status table
+ selected BOOLEAN NULL, -- A single special image in the current gallery for this entity
+ featured BOOLEAN null, -- Image is a member of a group of featured images
+ file_name TINYTEXT NULL, -- Stored file name for the image
+ descr TEXT NULL, -- Description
+ caption TINYTEXT NULL, -- Caption for the image
+ position INT NULL, -- Numeric position for sequence of display
+ ref_type INT NULL, -- Type of entity this image is associated with
+ ref_dest INT NULL, -- Pointer to the specific entity of ref_type this image is associated with
+ PRIMARY KEY (id),
+ INDEX(name(20)),
+ INDEX(file_name(20)),
+ INDEX(ref_type),
+ INDEX(ref_dest)
+);
+
+----
+
+-- Primary member records - One for each member
+CREATE TABLE {prefix}members (
+ id INT NOT NULL AUTO_INCREMENT,
+ access INT NULL, -- Access type - See access table in plugin.ini
+ member_type INT NULL, -- Pointer to member type in member_type table
+ created DATE NULL, -- Date member record was created
+ name TINYTEXT NULL, -- Member name
+ member_slug TINYTEXT NULL, -- Member name slug for canonical URLs (lowercase, "-" for spaces, no punctuation)
+ notes TEXT NULL, -- General notes - Not displayed in front-end
+ old_member_id INT NULL, -- Old member ID if imported from old database
+ PRIMARY KEY (id),
+ INDEX(name(20)),
+ INDEX(member_slug(20)),
+ INDEX(created)
+);
+
+----
+
+-- Member information version record - May be multiples per member - Only one with stauts "Active" for a distinct date range
+CREATE TABLE {prefix}member_info (
+ id INT NOT NULL AUTO_INCREMENT,
+ member INT NULL, -- Pointer to member record in table members
+ member_name TINYTEXT NULL, -- Copy of member name from members table entry for fast reference
+ status INT NULL, -- Status of this member information record - See plugin.ini status table
+ reference_name TINYTEXT NULL, -- Refernce name for this member information record - Not displayed on front-end
+ descr TEXT NULL, -- Description
+ short_descr TEXT NULL, -- Short description
+ addr1 TINYTEXT NULL, -- Main member location address line 1
+ addr2 TINYTEXT NULL, -- Address line 2
+ city INT NULL, -- Pointer to City in cities table
+ state TINYTEXT NULL, -- Two character state code - matches states.ini entries
+ country TINYTEXT NULL, -- Two character country code - matches countries.ini entries
+ zip TINYTEXT NULL, -- ZIP/Postal code
+ lat FLOAT NULL, -- Latitude of member's location
+ lon FLOAT NULL, -- Longitude of member's location
+ region INT NULL, -- Pointer to entry in regions table
+ phone TINYTEXT NULL, -- Primary phone number
+ toll_free TINYTEXT NULL, -- Toll Free phone number
+ url TINYTEXT NULL, -- URL with information about this member
+ email TINYTEXT NULL, -- Main E-Mail address for this member
+ logo TINYTEXT NULL, -- Member logo
+ cc_type INT NULL, -- Bitmap of credit card types accepted - See credit_card array in plugin.ini
+ notes TEXT NULL, -- General notes - Not displayed in front-end
+ create_time TIMESTAMP NULL, -- Create date/time
+ modify_time TIMESTAMP NULL, -- Last update date/time
+ PRIMARY KEY (id),
+ INDEX(status),
+ INDEX(city),
+ INDEX(zip(10)),
+ INDEX(lat),
+ INDEX(lon),
+ INDEX(region)
+);
+
+----
+
+-- Member type - Can be used to assign members to different "classes" of membership (i.e. Full, Associate, Premium)
+-- Mostly for internal use by the member organization, but could be displayed - Consider a short_description if they are.
+CREATE TABLE {prefix}member_type (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Name of member type
+ descr TINYTEXT NULL, -- Description of member type
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Regions - Used to segment members into various geographical regions - can be cities, counties, or other logical regions
+CREATE TABLE {prefix}regions (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Name of region
+ descr TEXT NULL, -- Descrption of region
+ short_descr TINYTEXT NULL, -- Short descroption of region
+ PRIMARY KEY (id)
+);
+
+----
+
+-- General settings available on Management page in admin - Only 1 entry in this table
+-- Items in this table should be all self-explanatory
+CREATE TABLE {prefix}settings_general (
+ id INT NOT NULL AUTO_INCREMENT,
+ admin_debug BOOLEAN DEFAULT '1',
+ admin_debug_verbose BOOLEAN DEFAULT '0',
+ front_debug BOOLEAN DEFAULT '0',
+ front_debug_verbose BOOLEAN DEFAULT '0',
+ google_maps_api_key TINYTEXT DEFAULT '',
+ maps_default_lat FLOAT DEFAULT '45.3749',
+ maps_default_lon FLOAT DEFAULT '-84.9592',
+ maps_default_zoom INTEGER DEFAULT '10',
+ time_zone TINYTEXT DEFAULT NULL,
+ canonical_member_page TINYTEXT DEFAULT NULL,
+ list_show_map BOOLEAN DEFAULT '1',
+ list_show_list BOOLEAN DEFAULT '1',
+ list_show_search BOOLEAN DEFAULT '1',
+ list_show_search_text BOOLEAN DEFAULT '1',
+ list_show_search_category BOOLEAN DEFAULT '1',
+ list_show_search_amenities BOOLEAN DEFAULT '1',
+ list_show_search_alpha BOOLEAN DEFAULT '1',
+ list_show_detail_link BOOLEAN DEFAULT '1',
+ list_show_logo BOOLEAN DEFAULT '1',
+ list_logo_size TINYTEXT NULL,
+ list_show_address BOOLEAN DEFAULT '1',
+ list_show_street BOOLEAN DEFAULT '1',
+ list_show_citystatezip BOOLEAN DEFAULT '1',
+ list_show_country BOOLEAN DEFAULT '1',
+ list_show_region BOOLEAN DEFAULT '1',
+ list_show_descr BOOLEAN DEFAULT '0',
+ list_show_short_descr BOOLEAN DEFAULT '1',
+ list_show_phone BOOLEAN DEFAULT '1',
+ list_show_tollfree BOOLEAN DEFAULT '1',
+ list_show_url BOOLEAN DEFAULT '1',
+ list_show_url_newtarget BOOLEAN DEFAULT '1',
+ list_show_email BOOLEAN DEFAULT '1',
+ list_show_categories BOOLEAN DEFAULT '0',
+ list_show_creditcards BOOLEAN DEFAULT '0',
+ list_show_amenities BOOLEAN DEFAULT '0',
+ list_map_show_detaillink BOOLEAN DEFAULT '1',
+ list_map_show_logo BOOLEAN DEFAULT '0',
+ list_map_logo_size TINYTEXT NULL,
+ list_map_show_descr BOOLEAN DEFAULT '0',
+ list_map_show_short_descr BOOLEAN DEFAULT '1',
+ list_map_show_address BOOLEAN DEFAULT '1',
+ list_map_show_street BOOLEAN DEFAULT '1',
+ list_map_show_citystatezip BOOLEAN DEFAULT '1',
+ list_map_show_country BOOLEAN DEFAULT '1',
+ list_map_show_region BOOLEAN DEFAULT '1',
+ list_map_show_phone BOOLEAN DEFAULT '1',
+ list_map_show_tollfree BOOLEAN DEFAULT '1',
+ list_map_show_url BOOLEAN DEFAULT '1',
+ list_map_show_url_newtarget BOOLEAN DEFAULT '1',
+ list_map_show_email BOOLEAN DEFAULT '1',
+ list_map_show_categories BOOLEAN DEFAULT '0',
+ list_map_show_creditcards BOOLEAN DEFAULT '0',
+ list_map_show_amenities BOOLEAN DEFAULT '0',
+ detail_show_map BOOLEAN DEFAULT '1',
+ detail_show_directions BOOLEAN DEFAULT '1',
+ detail_show_logo BOOLEAN DEFAULT '1',
+ detail_logo_size TINYTEXT NULL,
+ detail_show_descr BOOLEAN DEFAULT '1',
+ detail_show_short_descr BOOLEAN DEFAULT '0',
+ detail_show_address BOOLEAN DEFAULT '1',
+ detail_show_street BOOLEAN DEFAULT '1',
+ detail_show_citystatezip BOOLEAN DEFAULT '1',
+ detail_show_country BOOLEAN DEFAULT '1',
+ detail_show_region BOOLEAN DEFAULT '1',
+ detail_show_phone BOOLEAN DEFAULT '1',
+ detail_show_tollfree BOOLEAN DEFAULT '1',
+ detail_show_url BOOLEAN DEFAULT '1',
+ detail_show_url_newtarget BOOLEAN DEFAULT '1',
+ detail_show_email BOOLEAN DEFAULT '1',
+ detail_show_categories BOOLEAN DEFAULT '0',
+ detail_show_creditcards BOOLEAN DEFAULT '0',
+ detail_show_amenities BOOLEAN DEFAULT '1',
+ detail_show_imagegallery BOOLEAN DEFAULT '1',
+ detail_show_coupons BOOLEAN DEFAULT '0',
+ detail_show_packages BOOLEAN DEFAULT '0',
+ detail_map_show_logo BOOLEAN DEFAULT '0',
+ detail_map_logo_size TINYTEXT NULL,
+ detail_map_show_descr BOOLEAN DEFAULT '0',
+ detail_map_show_short_descr BOOLEAN DEFAULT '1',
+ detail_map_show_address BOOLEAN DEFAULT '1',
+ detail_map_show_street BOOLEAN DEFAULT '1',
+ detail_map_show_citystatezip BOOLEAN DEFAULT '1',
+ detail_map_show_country BOOLEAN DEFAULT '1',
+ detail_map_show_region BOOLEAN DEFAULT '1',
+ detail_map_show_phone BOOLEAN DEFAULT '1',
+ detail_map_show_tollfree BOOLEAN DEFAULT '1',
+ detail_map_show_url BOOLEAN DEFAULT '1',
+ detail_map_show_url_newtarget BOOLEAN DEFAULT '1',
+ detail_map_show_email BOOLEAN DEFAULT '1',
+ detail_map_show_categories BOOLEAN DEFAULT '0',
+ detail_map_show_creditcards BOOLEAN DEFAULT '0',
+ detail_map_show_amenities BOOLEAN DEFAULT '0',
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Set default entry
+INSERT INTO {prefix}settings_general
+ ( id, time_zone, canonical_member_page, list_logo_size, list_map_logo_size, detail_logo_size, detail_map_logo_size )
+ VALUES
+ ( 1, 'America/Detroit', 'member-detail', 'large', 'thumb', 'large', 'thumb' )
+;
+
+----
+
+-- Terms used in site modifiable on Management page in admin - Only 1 entry in this table
+-- Tems in this table should be all self-explanatory
+CREATE TABLE {prefix}settings_terms (
+ id INT NOT NULL AUTO_INCREMENT,
+ term_admin_menu_members TINYTEXT NULL,
+ term_admin_menu_member_list TINYTEXT NULL,
+ term_admin_menu_member TINYTEXT NULL,
+ term_admin_menu_configure TINYTEXT NULL,
+ term_admin_menu_settings TINYTEXT NULL,
+ term_admin_menu_shortcodes TINYTEXT NULL,
+ term_admin_menu_members_dashboard TINYTEXT NULL,
+ term_admin_menu_members_list TINYTEXT NULL,
+ term_admin_menu_members_reports TINYTEXT NULL,
+ term_admin_menu_member_dashboard TINYTEXT NULL,
+ term_admin_menu_member_info TINYTEXT NULL,
+ term_admin_menu_member_locations TINYTEXT NULL,
+ term_admin_menu_member_facilities TINYTEXT NULL,
+ term_admin_menu_member_attractions TINYTEXT NULL,
+ term_admin_menu_member_contacts TINYTEXT NULL,
+ term_admin_menu_configure_member_types TINYTEXT NULL,
+ term_admin_menu_configure_member_cats TINYTEXT NULL,
+ term_admin_menu_configure_accom_types TINYTEXT NULL,
+ term_admin_menu_configure_amenities TINYTEXT NULL,
+ term_admin_menu_configure_cities TINYTEXT NULL,
+ term_admin_menu_configure_regions TINYTEXT NULL,
+ term_admin_menu_settings_general TINYTEXT NULL,
+ term_admin_menu_settings_terms TINYTEXT NULL,
+ term_admin_menu_settings_development TINYTEXT NULL,
+ term_member TINYTEXT NULL,
+ term_member_cap TINYTEXT NULL,
+ term_member_plur TINYTEXT NULL,
+ term_member_plur_cap TINYTEXT NULL,
+ term_location TINYTEXT NULL,
+ term_location_cap TINYTEXT NULL,
+ term_location_plur TINYTEXT NULL,
+ term_location_plur_cap TINYTEXT NULL,
+ term_facility TINYTEXT NULL,
+ term_facility_cap TINYTEXT NULL,
+ term_facility_plur TINYTEXT NULL,
+ term_facility_plur_cap TINYTEXT NULL,
+ term_attraction TINYTEXT NULL,
+ term_attraction_cap TINYTEXT NULL,
+ term_attraction_plur TINYTEXT NULL,
+ term_attraction_plur_cap TINYTEXT NULL,
+ term_contact TINYTEXT NULL,
+ term_contact_cap TINYTEXT NULL,
+ term_contact_plur TINYTEXT NULL,
+ term_contact_plur_cap TINYTEXT NULL,
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Default terms entry
+INSERT INTO {prefix}settings_terms
+ (
+ id,
+ term_admin_menu_members,
+ term_admin_menu_member_list,
+ term_admin_menu_member,
+ term_admin_menu_configure,
+ term_admin_menu_settings,
+ term_admin_menu_shortcodes,
+ term_admin_menu_members_dashboard,
+ term_admin_menu_members_list,
+ term_admin_menu_members_reports,
+ term_admin_menu_member_dashboard,
+ term_admin_menu_member_info,
+ term_admin_menu_member_locations,
+ term_admin_menu_member_facilities,
+ term_admin_menu_member_attractions,
+ term_admin_menu_member_contacts,
+ term_admin_menu_configure_member_types,
+ term_admin_menu_configure_member_cats,
+ term_admin_menu_configure_accom_types,
+ term_admin_menu_configure_amenities,
+ term_admin_menu_configure_cities,
+ term_admin_menu_configure_regions,
+ term_admin_menu_settings_general,
+ term_admin_menu_settings_terms,
+ term_admin_menu_settings_development,
+ term_member,
+ term_member_cap,
+ term_member_plur,
+ term_member_plur_cap,
+ term_location,
+ term_location_cap,
+ term_location_plur,
+ term_location_plur_cap,
+ term_facility,
+ term_facility_cap,
+ term_facility_plur,
+ term_facility_plur_cap,
+ term_attraction,
+ term_attraction_cap,
+ term_attraction_plur,
+ term_attraction_plur_cap,
+ term_contact,
+ term_contact_cap,
+ term_contact_plur,
+ term_contact_plur_cap
+ )
+ VALUES
+ (
+ 1,
+ 'Members',
+ 'Member',
+ 'Member',
+ 'Configure',
+ 'Management',
+ 'Shortcodes',
+ 'Dashboard',
+ 'Member List',
+ 'Reports',
+ 'Member Dashboard',
+ 'Member Info',
+ 'Locations',
+ 'Facilities',
+ 'Attractions',
+ 'Contacts',
+ 'Member Types',
+ 'Member Categories',
+ 'Accommodation Types',
+ 'Amenities',
+ 'Cities',
+ 'Regions',
+ 'General Settings',
+ 'Terms & Phrases',
+ 'Development',
+ 'member',
+ 'Member',
+ 'members',
+ 'Members',
+ 'location',
+ 'Location',
+ 'locations',
+ 'Locations',
+ 'facility',
+ 'Facility',
+ 'facilities',
+ 'Facilities',
+ 'attraction',
+ 'Attraction',
+ 'attractions',
+ 'Attractions',
+ 'contact',
+ 'Contact',
+ 'contacts',
+ 'Contacts'
+ )
+;
/**
* Database Versions
*
+ * *** PLEASE NOW INCLUDE A DATE FOR EACH DATABASE VERSION ***
+ * '1.1.2' => array('version' => '1.1.2', 'tables' => 14, 'date' => '4/11/16')
+ *
* An array of past and current Member Database versions.
*
* Each entry below uses a key so code can find data on
'1.0.30' => array('version' => '1.0.30', 'tables' => 26),
'1.0.43' => array('version' => '1.0.43', 'tables' => 26),
'1.1.0' => array('version' => '1.1.0', 'tables' => 13),
- '1.1.1' => array('version' => '1.1.1', 'tables' => 13)
+ '1.1.1' => array('version' => '1.1.1', 'tables' => 13),
+ '1.1.2' => array('version' => '1.1.2', 'tables' => 14, 'date' => '4/11/16')
);
+++ /dev/null
--- Gaslight Media Members Database
--- File Created: 12/09/14 15:27:15
--- Database Version: 1.1.1
--- Database Deletion Script
--- Note: Tables with DELETE CASCADE must appear before referenced table
-
-DROP TABLE IF EXISTS
- {prefix}amenities,
- {prefix}amenity_ref,
- {prefix}category_member_info,
- {prefix}cities,
- {prefix}contacts,
- {prefix}images,
- {prefix}members,
- {prefix}member_info,
- {prefix}member_type,
- {prefix}regions,
- {prefix}settings_general,
- {prefix}settings_terms,
- {prefix}categories
-;
-
--- /dev/null
+-- Gaslight Media Members Database
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 1.1.1
+-- Database Deletion Script
+-- Note: Tables with DELETE CASCADE must appear before referenced table
+
+DROP TABLE IF EXISTS
+ {prefix}amenities,
+ {prefix}amenity_ref,
+ {prefix}category_member_info,
+ {prefix}cities,
+ {prefix}contacts,
+ {prefix}images,
+ {prefix}files,
+ {prefix}members,
+ {prefix}member_info,
+ {prefix}member_type,
+ {prefix}regions,
+ {prefix}settings_general,
+ {prefix}settings_terms,
+ {prefix}categories
+;
+
--- /dev/null
+This directory contains database creation and update scripts for this add-on.
+
+The files in this directory are checked by the checkDatabase() function in the
+main plugin classes/glmPluginSupport.php file.
+
+This directory is optional. If there are no data tables that need to be created
+for this add-on, there should be no files in this directory. The directory may
+also be deleted.
+
+See the "examples" directory for a sample of what can go in this directory.
+Procedure to update database
+-----------------------------
+
+0) Make a backup copy of the site's database.
+
+1) Rename "create_database_Vx.x.x.sql" to new version number.
+ example: create_database_V0.0.9.sql -> create_database_V0.0.10.sql
+
+2) Edit renamed create database file and make desired changes
+
+3) Add a new "update_database_Vx.x.x.sql" named with the correct version #.
+
+4) Edit new update database files with SQL script to make the necessary changes
+ from the previous version to the new version. (i.e. to add new fields,
+ rename fields, insert records, ...)
+
+5) Optionally add an "update_database_Vx.x.x.php" file if PHP scripting is
+ needed to update database content. (i.e. to make changes to database content)
+
+6) Edit the "dbVersions.php" file and add a new line for the new version.
+ *** Now please be sure to add a date for each entry ***
+ i.e. '1.1.2' => array('version' => '1.1.2', 'tables' => 14, 'date' => '4/11/16')
+
+7) When this is all done, edit the index.php file for the plugin/add-on and
+ change "GLM_MEMBERS_{addon}_PLUGIN_DB_VERSION" defined parameter where
+ {addon} is the add-on name.
+
+8) Go to an admin menu item for the main member db plugin or any add-on. If all
+ goes well, the main plugin should have detected the change and updated the
+ database. If not, restore the database and try again.
+9) Check the database to make sure the changes to fields and data are correct.
/*
* Gaslight Media Members Database
*
- * Database Update Script for version 1.0.28
+ * Database Update Script for version 1.0.30
*/
// Update member_info records with member name slug for URLs
-- Gaslight Media Members Database
-- File Created: 12/09/14 15:27:15
--- Database Version: 1.0.28
+-- Database Version: 1.0.30
-- Database Update From Previous Version Script
--
-- To permit each query below to be executed separately,
-- Gaslight Media Members Database
-- File Created: 12/09/14 15:27:15
--- Database Version: 1.0.28
+-- Database Version: 1.0.43
-- Database Update From Previous Version Script
--
-- To permit each query below to be executed separately,
-- Gaslight Media Members Database
-- File Created: 12/09/14 15:27:15
--- Database Version: 1.0.28
+-- Database Version: 1.1.0
-- Database Update From Previous Version Script
--
-- To permit each query below to be executed separately,
-- Gaslight Media Members Database
-- File Created: 12/09/14 15:27:15
--- Database Version: 1.0.28
+-- Database Version: 1.1.1
-- Database Update From Previous Version Script
--
-- To permit each query below to be executed separately,
--- /dev/null
+<?php
+/*
+ * Gaslight Media Members Database
+ *
+ * Database Update Script for version 1.0.28
+ */
+
+// Check if we need to add a "files" subdirectory to this plugin's media directory
+// (usually the slug for this plugin under the "uploads" directory)
+if (!file_exists(GLM_MEMBERS_PLUGIN_FILES_PATH)) {
+ mkdir(GLM_MEMBERS_PLUGIN_FILES_PATH);
+}
+
--- /dev/null
+-- Gaslight Media Members Database
+-- File Created: 11/11/16 15:27:15
+-- Database Version: 1.1.2
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashses
+
+-- Files - Files are stored under /wp-content/uploads/glm-member-db/files/
+CREATE TABLE {prefix}files (
+ id INT NOT NULL AUTO_INCREMENT,
+ name TINYTEXT NULL, -- Original name of the file - might be URL if copied via HTTP
+ status TINYINT(1) NULL, -- Display/Use status - See plugin.ini status table
+ file_name TINYTEXT NULL, -- Stored file name for the file
+ descr TEXT NULL, -- Description
+ position INT NULL, -- Numeric position for sequence of display
+ ref_type INT NULL, -- Type of entity this image is associated with
+ ref_dest INT NULL, -- Pointer to the specific entity of ref_type this image is associated with
+ PRIMARY KEY (id),
+ INDEX(name(20)),
+ INDEX(file_name(20)),
+ INDEX(ref_type),
+ INDEX(ref_dest)
+);
+
{/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="readDatabase">
+ <input type="hidden" name="option" value="members">
<table class="glm-admin-table">
+++ /dev/null
-{include file='admin/management/header.html'}
-
- <h2>Data Import - Test Database</h2>
- <ol>
- <li>Provide legacy database information and import member data.</li>
- <li>Import any images.</li>
- <li class="glm-ol-selected">Review results</li>
- </ol>
-
-
- <h3>Data Import Step 3: Review Results.</h3>
-{if isset($genError)}
- <p>
- <h3 class="glm-error">Oops!</h3>
- <p class="glm-error">{$genError}</p>
- </p>
-{/if}
-
- <h2>Process Complete</h2>
- <p>
- The data and image import process is complete. You should now have all member data and images imported.
- <p>
- <p>
- You should now go to the "Member List" and make sure the data and images have been imported properly.
- </p>
-
-{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/management/header.html'}
+
+ <h2>Data Import - Test Database</h2>
+ <ol>
+ <li>Provide legacy database information and import member data.</li>
+ <li>Import any images.</li>
+ <li class="glm-ol-selected">Review results</li>
+ </ol>
+
+
+ <h3>Data Import Step 3: Review Results.</h3>
+{if isset($genError)}
+ <p>
+ <h3 class="glm-error">Oops!</h3>
+ <p class="glm-error">{$genError}</p>
+ </p>
+{/if}
+
+ <h2>Process Complete</h2>
+ <p>
+ The data and image import process is complete. You should now have all member data and images imported.
+ <p>
+ <p>
+ You should now go to the "Member List" and make sure the data and images have been imported properly.
+ </p>
+
+{include file='admin/footer.html'}
--- /dev/null
+{include file='admin/management/header.html'}
+
+ <h2>Data Import - Test Database</h2>
+ <ol>
+ <li>Provide legacy database information and import member data.</li>
+ <li class="glm-ol-selected">Import any images.</li>
+ <li>Review results</li>
+ </ol>
+
+ <h2>Data Import Results</h2>
+ <table class="glm-admin-table">
+ <tr><th>Cities:</th><td>{$numbCities}</td></tr>
+ <tr><th>States:</th><td>{$numbStates}</td></tr>
+ <tr><th>Regions:</th><td>{$numbRegions}</td></tr>
+ <tr>
+ <th>Members:</th>
+ <td>
+ {$numbMembers}
+ {if $haveMembImportIssues}
+ <ul>{$membImportIssues}</ul>
+ {/if}
+ </td>
+ </tr>
+ <tr><th>Members Active:</th><td>{$numbMembersActive}</td></tr>
+ <tr><th>Members Inactive:</th><td>{$numbMembersInactive}</td></tr>
+ <tr><th>Categories:</th><td>{$numbCategories}</td></tr>
+ <tr>
+ <th>Member Category Entries:</th>
+ <td>
+ {$numbCategoryMembers}
+ {if $haveCatImportIssues}
+ <ul>{$catImportIssues}</ul>
+ {/if}
+ </td>
+ </tr>
+ <tr><th>Amenities:</th><td>{$numbAmenities}</td></tr>
+ <tr><th>Member Amenity Entries:</th><td>{$numbAmenityMembers}</td></tr>
+ <tr><th>Credit Card Types:</th><td>{$numbCcards}</td></tr>
+ <tr><th>Member Credit Card Entries:</th><td>{$numbCcardMembers}</td></tr>
+ <tr><th>Images Found:</th><td>{$numbImagesFound}</td></tr>
+ </table>
+
+ <h3>Data Import Step 2: Import images.</h3>
+{if isset($genError)}
+ <p>
+ <h3 class="glm-error">Oops!</h3>
+ <p class="glm-error">{$genError}</p>
+ </p>
+{/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="images">
+ <p><span class="glm-notice">WARNING:</span> This process may take a very long time!<br>Do not interrupt or re-submit this page.</p>
+ <input type="submit" value="Continue" class="button button-primary">
+ </form>
+
+
+{include file='admin/footer.html'}
+++ /dev/null
-{include file='admin/management/header.html'}
-
- <h2>Data Import - Test Database</h2>
- <ol>
- <li>Provide legacy database information and import member data.</li>
- <li class="glm-ol-selected">Import any images.</li>
- <li>Review results</li>
- </ol>
-
- <h2>Data Import Results</h2>
- <table class="glm-admin-table">
- <tr><th>Cities:</th><td>{$numbCities}</td></tr>
- <tr><th>States:</th><td>{$numbStates}</td></tr>
- <tr><th>Regions:</th><td>{$numbRegions}</td></tr>
- <tr>
- <th>Members:</th>
- <td>
- {$numbMembers}
- {if $haveMembImportIssues}
- <ul>{$membImportIssues}</ul>
- {/if}
- </td>
- </tr>
- <tr><th>Members Active:</th><td>{$numbMembersActive}</td></tr>
- <tr><th>Members Inactive:</th><td>{$numbMembersInactive}</td></tr>
- <tr><th>Categories:</th><td>{$numbCategories}</td></tr>
- <tr>
- <th>Member Category Entries:</th>
- <td>
- {$numbCategoryMembers}
- {if $haveCatImportIssues}
- <ul>{$catImportIssues}</ul>
- {/if}
- </td>
- </tr>
- <tr><th>Amenities:</th><td>{$numbAmenities}</td></tr>
- <tr><th>Member Amenity Entries:</th><td>{$numbAmenityMembers}</td></tr>
- <tr><th>Credit Card Types:</th><td>{$numbCcards}</td></tr>
- <tr><th>Member Credit Card Entries:</th><td>{$numbCcardMembers}</td></tr>
- <tr><th>Images Found:</th><td>{$numbImagesFound}</td></tr>
- </table>
-
- <h3>Data Import Step 2: Import images.</h3>
-{if isset($genError)}
- <p>
- <h3 class="glm-error">Oops!</h3>
- <p class="glm-error">{$genError}</p>
- </p>
-{/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="importImages">
- <p><span class="glm-notice">WARNING:</span> This process may take a very long time!<br>Do not interrupt or re-submit this page.</p>
- <input type="submit" value="Continue" class="button button-primary">
- </form>
-
-
-{include file='admin/footer.html'}
<td {if $memberInfo.fieldFail.descr}class="glm-form-bad-input" data-tabid="glm-member-info-descr"{/if}>
{php}
wp_editor('{$memberInfo.fieldData.descr|escape:quotes}', 'glm_descr', array(
- // 'media_buttons' => true,
+ 'media_buttons' => false,
// 'quicktags' => false,
// 'wpautop' => false, NOTE: Dont's use. Problem when numerous spaces before text.
'textarea_name' => 'descr',