--- /dev/null
+<?php
+/**
+ * Import Brewbakers Images
+ * Will have to do these 10 to 20 at a time.
+ */
+
+$failure = false;
+// Setup the database connection to postgres
+$dbServer = 'localhost';
+$dbName = 'brewbakers';
+$dbUser = 'postgres';
+$resetdb = true;
+$start = ( isset( $_REQUEST['start'] ) ) ? filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ): 0;
+$limit = ( $start === 0 ) ? 20 : 100;
+$totalImages = 0;
+
+$connString = "host=$dbServer dbname=$dbName user=$dbUser";
+$db = @pg_connect( $connString );
+
+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 = 'http://is0.gaslightmedia.com/brewbakers/CKImage/';
+
+
+// Read in all member photos for Homes and RV's
+$image = array();
+$numbImagesFound = 0;
+if (!$failure && $start === 0) {
+ // Grab the photos for homes
+ $sql = "
+ SELECT *
+ FROM homes_photos
+ ORDER BY homes_id,pos";
+ $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 {
+
+ // 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['homes'][$x['homes_id']])) {
+ $image['homes'][$x['homes_id']] = array(
+ 'homes_id' => $x['homes_id'],
+ 'images' => array()
+ );
+ }
+
+ $image['homes'][$x['homes_id']]['images'][] = $x;
+ $numbImagesFound++;
+ }
+ //echo '<pre>$image: ' . print_r( $image, true ) . '</pre>';
+ }
+ }
+}
+if (!$failure) {
+ // Get total count
+ $sql = "
+ SELECT count(*) as total
+ FROM rvs_photos";
+ $res = pg_query($db, $sql);
+ $totalImages = pg_fetch_result( $res, 0, 'total');
+
+ // Grab the photos for rvs
+ $sql = "
+ SELECT *
+ FROM rvs_photos
+ ORDER BY rvs_id,pos";
+ $sql .= " LIMIT $limit OFFSET $start";
+ $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 {
+
+ // 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['rvs'][$x['rvs_id']])) {
+ $image['rvs'][$x['rvs_id']] = array(
+ 'rvs_id' => $x['rvs_id'],
+ 'images' => array()
+ );
+ }
+
+ $image['rvs'][$x['rvs_id']]['images'][] = $x;
+ $numbImagesFound++;
+ }
+ //echo '<pre>$image: ' . print_r( $image, true ) . '</pre>';
+ }
+ }
+}
+function getMemberInfoIdFromOldMemberId( $wpdb, $oldMemberId )
+{
+ return $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+ WHERE member IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d)",
+ $oldMemberId
+ )
+ );
+}
+//echo '<pre>$image: ' . print_r( $image, true ) . '</pre>';
+//exit;
+// Reset member images data tables if needed
+if ( !$failure && $resetdb && $start === 0 ) {
+ // Reset the data
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."images" );
+
+ // 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 );
+ }
+ }
+}
+// If we have image URLs
+if ($image != false) {
+
+ // For each member
+ foreach ($image as $memType) {
+ foreach ($memType as $oldMemberId => $m) {
+
+ $newMemberId = getMemberInfoIdFromOldMemberId( $this->wpdb, $oldMemberId);
+
+ // For each image in this member's gallery
+ if ($m['images']) {
+ foreach ($m['images'] as $i) {
+ // If this is the first image (pos == 1) then add it as the logo
+ if ( $i['pos'] == 1 ) {
+ $imageURL = $imageBaseURL.$i['image'];
+ $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' => $newMemberId ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+
+ $imageURL = $imageBaseURL.$i['image'];
+ $res = $ImageUpload->storeImage ($imageURL, $refType, $refTable, $newMemberId, $i['caption']);
+ }
+ }
+
+ }
+ }
+
+}
+
+$templateData['newStart'] = $start + $limit;
+$templateData['start'] = $start;
+$templateData['total'] = $totalImages;
+$templateData['numbImagesFound'] = $numbImagesFound;
+
+$requestedView = 'import/brewbakersImages.html';
<?php
-
-echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+// Setup the brewbakers image url
+$dbImageURL = 'http://is0.gaslightmedia.com/brewbakers/CKImage/';
+//echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+$rvLimit = false; // set to false to turn off limit
// Setup the database connection to postgres
-$dbServer = 'ds4';
+$dbServer = 'localhost';
$dbName = 'brewbakers';
$dbUser = 'postgres';
-$resetdb = false;
+$resetdb = true;
$rvs = array();
$homes = array();
$amenities = array();
AND r.class = c.id
AND r.manufacturer = man.id
ORDER BY r.id";
+ if ( $rvLimit ) {
+ $sql .= " LIMIT $rvLimit OFFSET 0";
+ }
$res = pg_query( $db, $sql );
$rows = pg_num_rows( $res );
if ( $rows == 0 ) {
}
$failure = true;
}
- echo '<pre>$homes: ' . print_r( $homes, true ) . '</pre>';
+ //echo '<pre>$homes: ' . print_r( $homes, true ) . '</pre>';
}
}
// Reset member data tables if needed
if ( !$failure && $resetdb ) {
- // Reset the database
- if ( !$this->deleteDataTables( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) {
- glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
- break;
- }
- if ( !$this->createDataTables( GLM_MEMBERS_PLUGIN_DB_VERSION ) ) {
- glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
- break;
- }
+ // Reset the data
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."members" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info" );
+ //$this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."amenities" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_field_data" );
}
// 3. Get amenities data
if ( !$failure ) {
}
}
// 4. Get amenity member relation data
+$numbAmenityMembers = 0;
if ( !$failure ) {
// Grab the amenity data
$sql = "
$templateData['genError'] = 'There does not appear to be any amenity relation listed in this database!';
$failure = true;
} else {
- $amenityData = pg_fetch_all( $res );
- if ( count( $amenityData ) != $rows ) {
+ $tmp = pg_fetch_all( $res );
+ if ( count( $tmp ) != $rows ) {
$notice = pg_last_notice( $res );
$templateData['genError'] = 'While reading base amenity relation data, we did not receive the expected number of amenityData! ';
if ( $notice ) {
}
$failure = true;
}
- //echo '<pre>$amenityData: ' . print_r( $amenityData, true ) . '</pre>';
+ $rvAmen = array();
+ foreach ( $tmp as $x ) {
+ // if rv entry hasn't been created yet, add it now
+ if ( !isset( $rvAmen[$x['rvs_id']] ) ) {
+ $rvAmen[$x['rvs_id']] = array();
+ }
+
+ $rvAmen[$x['rvs_id']][] = $x;
+ $numbAmenityMembers++;
+ }
}
}
+//echo '<pre>$rvAmen: ' . print_r( $rvAmen, true ) . '</pre>';
+//var_dump($rvAmen);
+//exit;
function getCategoryId( $wpdb, $name, $parent )
{
// check to see if the category already exists
)
);
}
+function getCustomFieldId( $wpdb, $name )
+{
+ return $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE field_name = %s",
+ $name
+ )
+ );
+}
+$customFieldIds = array(
+ 'year' => getCustomFieldId( $this->wpdb, 'Year' ),
+ 'model' => getCustomFieldId( $this->wpdb, 'Model' ),
+ 'color' => getCustomFieldId( $this->wpdb, 'Color' ),
+ 'length' => getCustomFieldId( $this->wpdb, 'Length' ),
+ 'weight' => getCustomFieldId( $this->wpdb, 'UVW lbs' ),
+ 'sleeping_capacity' => getCustomFieldId( $this->wpdb, 'Sleeping Capacity' ),
+ 'slide_outs' => getCustomFieldId( $this->wpdb, 'Slide Outs' ),
+ 'fresh_water_tank_size' => getCustomFieldId( $this->wpdb, 'Fresh Water (gal)' ),
+ 'black_tank_size' => getCustomFieldId( $this->wpdb, 'Black Water (gal)' ),
+ 'grey_tank_size' => getCustomFieldId( $this->wpdb, 'Gray Water (gal)' ),
+ 'stock_numb' => getCustomFieldId( $this->wpdb, 'Stock #' ),
+ 'msrp' => getCustomFieldId( $this->wpdb, 'MSRP' ),
+ 'make' => getCustomFieldId( $this->wpdb, 'Make' ),
+ 'bedrooms' => getCustomFieldId( $this->wpdb, 'Bedrooms' ),
+ 'bathrooms' => getCustomFieldId( $this->wpdb, 'Bathrooms' ),
+ 'sqft' => getCustomFieldId( $this->wpdb, 'Square Footage' ),
+ 'just_arrived' => getCustomFieldId( $this->wpdb, 'Just Arrived' ),
+ 'red_hot_deal' => getCustomFieldId( $this->wpdb, 'Red Hot Deal' ),
+ 'used' => getCustomFieldId( $this->wpdb, 'Used' ),
+);
+//echo '<pre>$customFieldIds: ' . print_r( $customFieldIds, true ) . '</pre>';
+function addCustomFieldData( $wpdb, $customFieldIds, $ref_dest, $fieldName, $fieldValue )
+{
+ // check the $fieldValue for t or f
+ if ( $fieldValue ) {
+ if ( $fieldValue == 't' ) {
+ $fieldValue = 'Yes';
+ } elseif ( $fieldValue == 'f' ) {
+ $fieldValue = 'No';
+ }
+ }
+ $wpdb->insert(
+ GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data',
+ array(
+ 'field_id' => $customFieldIds[$fieldName],
+ 'ref_dest' => $ref_dest,
+ 'field_data' => ($fieldValue) ? $fieldValue: '',
+ ),
+ array( '%d', '%d', '%s' )
+ );
+}
// 5. Get categories
// Setup three main level categories
// Brands, Manufactures, and Classes
// Grab the Brands from Brewbakers
if ( !$failure ) {
// Add new main level for Brands
- $brandId = addNewCategory( $this->wpdb, 'Brands', 0 );
- echo '<pre>$brandId: ' . print_r( $brandId, true ) . '</pre>';
+ $rvBrandId = addNewCategory( $this->wpdb, 'Brands', 0 );
+ //echo '<pre>$rvBrandId: ' . print_r( $rvBrandId, true ) . '</pre>';
// Get all Brands and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$brands: ' . print_r( $brands, true ) . '</pre>';
foreach ( $brands as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $brandId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $brandId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $rvBrandId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvBrandId );
}
}
}
// Grab the Housing Manufacturers
if ( !$failure ) {
// Add new main level for Brands
- $manufacturerId = addNewCategory( $this->wpdb, 'Housing Manufacturers', 0 );
- echo '<pre>$manufacturerId: ' . print_r( $manufacturerId, true ) . '</pre>';
+ $homeManufacturerId = addNewCategory( $this->wpdb, 'Housing Manufacturers', 0 );
+ //echo '<pre>$homeManufacturerId: ' . print_r( $homeManufacturerId, true ) . '</pre>';
// Get all Manufactures from housing section and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$houseMan: ' . print_r( $houseMan, true ) . '</pre>';
foreach ( $houseMan as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $manufacturerId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $manufacturerId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $homeManufacturerId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeManufacturerId );
}
}
}
// Grab the RV Manufacturers
if ( !$failure ) {
// Add new main level for Brands
- $manufacturerId = addNewCategory( $this->wpdb, 'RV Manufacturers', 0 );
- echo '<pre>$manufacturerId: ' . print_r( $manufacturerId, true ) . '</pre>';
+ $rvManufacturerId = addNewCategory( $this->wpdb, 'RV Manufacturers', 0 );
+ //echo '<pre>$rvManufacturerId: ' . print_r( $rvManufacturerId, true ) . '</pre>';
// Get all Manufactures from rvs section and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$rvMan: ' . print_r( $rvMan, true ) . '</pre>';
foreach ( $rvMan as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $manufacturerId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $manufacturerId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $rvManufacturerId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvManufacturerId );
}
}
}
// Grab the Housing Classes
if ( !$failure ) {
// Add new main level for Brands
- $classId = addNewCategory( $this->wpdb, 'Housing Classes', 0 );
- echo '<pre>$classId: ' . print_r( $classId, true ) . '</pre>';
+ $homeClassId = addNewCategory( $this->wpdb, 'Housing Classes', 0 );
+ //echo '<pre>$homeClassId: ' . print_r( $homeClassId, true ) . '</pre>';
// Get all Manufactures from housing section and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$houseClass: ' . print_r( $houseClass, true ) . '</pre>';
foreach ( $houseClass as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $classId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $classId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $homeClassId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeClassId );
}
}
}
// Grab the RV Classes
if ( !$failure ) {
// Add new main level for Brands
- $classId = addNewCategory( $this->wpdb, 'RV Classes', 0 );
- echo '<pre>$classId: ' . print_r( $classId, true ) . '</pre>';
+ $rvClassId = addNewCategory( $this->wpdb, 'RV Classes', 0 );
+ //echo '<pre>$rvClassId: ' . print_r( $rvClassId, true ) . '</pre>';
// Get all Manufactures from rvs section and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$rvClass: ' . print_r( $rvClass, true ) . '</pre>';
foreach ( $rvClass as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $classId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $classId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $rvClassId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $rvClassId );
}
}
}
// Grab the Homes Models
if ( !$failure ) {
// Add new main level for Models
- $modelId = addNewCategory( $this->wpdb, 'Home Models', 0 );
- echo '<pre>$modelId: ' . print_r( $modelId, true ) . '</pre>';
+ $homeModelId = addNewCategory( $this->wpdb, 'Home Models', 0 );
+ //echo '<pre>$homeModelId: ' . print_r( $homeModelId, true ) . '</pre>';
// Get all Manufactures from rvs section and add them as sub categories
$sql = "
SELECT id,name
}
//echo '<pre>$homeModel: ' . print_r( $homeModel, true ) . '</pre>';
foreach ( $homeModel as $key => $val ) {
- //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $modelId . '</pre>';
- $newCatId = addNewCategory( $this->wpdb, $val['name'], $modelId );
+ //echo '<pre>Adding category for ' . $val['name'] . ' parent ' . $homeModelId . '</pre>';
+ $newCatId = addNewCategory( $this->wpdb, $val['name'], $homeModelId );
}
}
}
// Add the category
$wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenities',
- array( 'name' => $name ),
- '%s'
+ array(
+ 'active' => true,
+ 'name' => $name,
+ 'descr' => '',
+ 'short_descr' => '',
+ 'ref_type' => 20
+ ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
);
return $wpdb->insert_id;
}
// Import Amenities
while (list ($key, $val) = each ($amenity) ) {
$amenityId = addNewAmenity( $this->wpdb, $val['name'] );
- $amenity[$key]['new_id'] = $this->wpdb->insert_id;
+ $amenity[$key]['new_id'] = $amenityId;
}
- //echo '<pre>$amenity: ' . print_r( $amenity, true ) . '</pre>';
+ //echo '<pre>new $amenity: ' . print_r( $amenity, true ) . '</pre>';
}
function getMemberTypeId( $wpdb, $name )
{
// Add member type for Homes
$homeMemberType = addNewMemberType( $this->wpdb, 'Home' );
}
-// Read in all member photos for Homes and RV's
-$image = array();
-$numbImagesFound = 0;
-if (!$failure) {
- $sql = "
- SELECT *
- FROM homes_photos
- ORDER BY homes_id,pos";
- $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 {
-
- // 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['homes_id']])) {
- $image[$x['homes_id']] = array(
- 'homes_id' => $x['homes_id'],
- 'images' => array()
- );
- }
-
- $image[$x['homes_id']]['images'][] = $x;
- $numbImagesFound++;
- }
- //echo '<pre>$image: ' . print_r( $image, true ) . '</pre>';
- }
- }
-}
if (!$failure) {
// Import Members
$numbMembersActive = 0;
// Check for duplicate name
// Build out the Home name from year make model class
$membName = sprintf(
- "%s %s %s %s",
+ "%s %s %s",
$val['year'],
$val['make'],
- $val['model_name'],
$val['class_name']
);
if (isset($namesInserted[$membName])) {
'created' => date('Y-m-d'),
'name' => $membName,
'member_slug' => sanitize_title($membName),
+ 'featured' => ($val['featured'] == 't') ? 1: 0,
+ 'old_member_id' => $val['id']
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%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;
+
+ // Insert Member Information Record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'member' => $membID,
+ 'member_name' => $membName,
+ 'status' => $this->config['status_numb']['Active'],
+ 'reference_name' => 'Imported Member Information',
+ 'descr' => preg_replace('%[\n\r]%', '', $val['description']),
+ 'short_descr' => '',
+ 'addr1' => '',
+ 'addr2' => '',
+ 'city' => 0,
+ 'state' => 0,
+ 'country' => '',
+ 'zip' => '',
+ 'lat' => 0,
+ 'lon' => 0,
+ 'region' => 0,
+ 'phone' => '',
+ 'toll_free' => '',
+ 'url' => '',
+ 'email' => '',
+ 'logo' => '',
+ 'cc_type' => 0,
+ 'notes' => '',
+ 'create_time' => $val['created'],
+ 'modify_time' => ''
+ ),
+ 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;
+ $homeModel = $homeClass = $homeManufacturer = 0;
+ $homeCat = array();
+
+ // Add Member Categories
+ // Get category id for the model_name
+ $homeModel = getCategoryId( $this->wpdb, $val['model_name'], $homeModelId );
+ if ( $homeModel ) {
+ $homeCat[] = array(
+ 'category' => $homeModel,
+ 'member_info' => $infoID
+ );
+ }
+ // Get category id for the class_name
+ $homeClass = getCategoryId( $this->wpdb, $val['class_name'], $homeClassId );
+ if ( $homeClass ) {
+ $homeCat[] = array(
+ 'category' => $homeClass,
+ 'member_info' => $infoID
+ );
+ }
+ // Get category id for the manufacturer_name
+ $homeManufacturer = getCategoryId( $this->wpdb, $val['manufacturer_name'], $homeManufacturerId );
+ if ( $homeManufacturer ) {
+ $homeCat[] = array(
+ 'category' => $homeManufacturer,
+ 'member_info' => $infoID
+ );
+ }
+ // Add Member Categories
+ if (isset($homeCat)) {
+ foreach ($homeCat as $catMemData) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
+ $catMemData,
+ array(
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add Member Amenities (only for rvs)
+
+ // Add Custom Fields
+ // year
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'year', $val['year'] );
+ // make
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'make', $val['make'] );
+ // color
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'color', $val['color'] );
+ // Stock Number
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'stock_numb', $val['stock_numb'] );
+ // MSRP
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'msrp', $val['msrp'] );
+ // Bedrooms
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'bedrooms', $val['bedrooms'] );
+ // Bathrooms
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'bathrooms', $val['bathrooms'] );
+ // Square Footage
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'sqft', $val['sqft'] );
+ // Used
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'used', $val['used'] );
+
+ }
+ //echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+}
+
+$haveCatImportIssues = false;
+$catImportIssues = '';
+if (!$failure) {
+ while (list ($key, $val) = each ($rvs) ) {
+ // Member is active, so set to active-moderated
+ $access = $this->config['access_numb']['Moderated'];
+ $numbMembersActive++;
+
+ // Check for duplicate name
+ // Build out the Home name from year make model class
+ $membName = sprintf(
+ "%s %s %s",
+ $val['year'],
+ $val['model_name'],
+ $val['stock_numb']
+ );
+ 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' => $rvMemberType,
+ 'created' => date('Y-m-d'),
+ 'name' => $membName,
+ 'member_slug' => sanitize_title($membName),
+ 'featured' => ($val['featured'] == 't') ? 1: 0,
'old_member_id' => $val['id']
),
array(
'%s',
'%s',
'%s',
+ '%d',
'%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;
+
+ // Insert Member Information Record
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'member_info',
+ array(
+ 'member' => $membID,
+ 'member_name' => $membName,
+ 'status' => $this->config['status_numb']['Active'],
+ 'reference_name' => 'Imported Member Information',
+ 'descr' => preg_replace('%[\n\r]%', '', $val['description']),
+ 'short_descr' => '',
+ 'addr1' => '',
+ 'addr2' => '',
+ 'city' => 0,
+ 'state' => 0,
+ 'country' => '',
+ 'zip' => '',
+ 'lat' => 0,
+ 'lon' => 0,
+ 'region' => 0,
+ 'phone' => '',
+ 'toll_free' => '',
+ 'url' => '',
+ 'email' => '',
+ 'logo' => '',
+ 'cc_type' => 0,
+ 'notes' => '',
+ 'create_time' => $val['created'],
+ 'modify_time' => ''
+ ),
+ 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;
+ $rvBrand = $rvClass = $rvManufacturer = 0;
+ $rvCat = array();
+
+ // Add Member Categories
+ // Get category id for the model_name
+ $rvBrand = getCategoryId( $this->wpdb, $val['model_name'], $rvBrandId );
+ if ( $rvBrand ) {
+ $rvCat[] = array(
+ 'category' => $rvBrand,
+ 'member_info' => $infoID
+ );
+ }
+ // Get category id for the class_name
+ $rvClass = getCategoryId( $this->wpdb, $val['class_name'], $rvClassId );
+ if ( $rvClass ) {
+ $rvCat[] = array(
+ 'category' => $rvClass,
+ 'member_info' => $infoID
+ );
+ }
+ // Get category id for the manufacturer_name
+ $rvManufacturer = getCategoryId( $this->wpdb, $val['manufacturer_name'], $rvManufacturerId );
+ if ( $rvManufacturer ) {
+ $rvCat[] = array(
+ 'category' => $rvManufacturer,
+ 'member_info' => $infoID
+ );
+ }
+ // Add Member Categories
+ if (isset($rvCat)) {
+ foreach ($rvCat as $catMemData) {
+
+ $res = $this->wpdb->insert(
+ GLM_MEMBERS_PLUGIN_DB_PREFIX.'category_member_info',
+ $catMemData,
+ array(
+ '%d',
+ '%d'
+ )
+ );
+
+ }
+ }
+
+ // Add Member Amenities (only for rvs)
+ if (isset($rvAmen[$val['id']])) {
+ foreach ($rvAmen[$val['id']] as $a) {
+ // Check first if the amenity still exists
+ // Brewbakers may have extra rvs_amenity records for amenities
+ // that don't exists anymore.
+ if ( isset( $amenity[$a['amenity_id']] ) ) {
+ $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 Custom Fields
+ // year
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'year', $val['year'] );
+ // Model
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'model', $val['model_name'] );
+ // length
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'length', $val['length'] );
+ // Weight
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'weight', $val['weight'] );
+ // color
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'color', $val['color'] );
+ // Stock Number
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'stock_numb', $val['stock_numb'] );
+ // MSRP
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'msrp', $val['msrp'] );
+ // Sleeping Capacity
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'sleeping_capacity', $val['sleeping_capacity'] );
+ // Slide Outs
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'slide_outs', $val['slide_outs'] );
+ // Fresh Water
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'fresh_water_tank_size', $val['fresh_water_tank_size'] );
+ // Black Tank
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'black_tank_size', $val['black_tank_size'] );
+ // Grey Tank
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'grey_tank_size', $val['grey_tank_size'] );
+ // Just Arrived
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'just_arrived', $val['just_arrived'] );
+ // Red Hot Heal
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'red_hot_deal', $val['red_hot_deal'] );
+ // Used
+ addCustomFieldData( $this->wpdb, $customFieldIds, $infoID, 'used', $val['used'] );
+
}
- echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+
+}
+// If everything is OK, make data available to the template
+if (!$failure) {
+
+ $templateData['numbMembers'] = count($member);
+ $templateData['numbMembersActive'] = $numbMembersActive;
+ $templateData['numbMembersInactive'] = $numbMembersInactive;
+ $templateData['haveMembImportIssues'] = $haveMembImportIssues;
+ $templateData['membImportIssues'] = $membImportIssues;
+ $templateData['numbCategories'] = count($rvCat) + count($homeCat);
+ $templateData['haveCatImportIssues'] = $haveCatImportIssues;
+ $templateData['catImportIssues'] = $catImportIssues;
+ $templateData['numbAmenities'] = count($amenity);
+ $templateData['numbAmenityMembers'] = $numbAmenityMembers;
+
+ // For testing only
+ $templateData['member'] = $member;
+ $templateData['amenity'] = $amenity;
+ $templateData['rvAmen'] = $rvAmen;
+}
+
+
+if ($failure) {
+ $requestedView = 'import.html';
+} else {
+ $requestedView = 'import/brewbakers.html';
}