*/
public $config;
- public $regions = array();
- public $counties = array();
+ /**
+ * amenities
+ *
+ * @var $amenities
+ * @access public
+ */
public $amenities = array();
+ /**
+ * categories
+ *
+ * @var $categories
+ * @access public
+ */
public $categories = array();
+ /**
+ * cities
+ *
+ * @var $cities
+ * @access public
+ */
public $cities = array();
+ /**
+ * regions
+ *
+ * @var $regions
+ * @access public
+ */
+ public $regions = array();
+ /**
+ * counties
+ *
+ * @var $counties
+ * @access public
+ */
+ public $counties = array();
+ /**
+ * members
+ *
+ * @var $members
+ * @access public
+ */
public $members = array();
+ /**
+ * errors
+ *
+ * @var $errors
+ * @access public
+ */
+ public $errors = array();
+ /**
+ * wpOptionPrefix
+ *
+ * @var $wpOptionPrefix
+ * @access public
+ */
+ public $wpOptionPrefix = 'glm_members_import_';
/**
* Constructor
'validate' => array(
'id', 'member_name', 'status', 'descr', 'short_descr',
'addr1', 'addr2', 'city', 'state', 'country', 'zip',
+ 'mailing_addr1', 'mailing_addr2', 'mailing_city', 'mailing_state', 'mailing_zip',
'region', 'county', 'lat', 'lon', 'phone', 'toll_free',
'url', 'reservation_url', 'email', 'logo', 'categories', 'amenities' ),
'type' => 'member',
}
//exit;
foreach ( $fileData as $fileHeader => $file ) {
- if ( is_file( $uploadPath . '/' . $file['name'] ) ) {
- $fileData[$fileHeader]['results'] = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] );
+ if ( is_file( $uploadPath . '/' . $file['name'] ) && $fileHeader != 'Member' ) {
+ //$fileData[$fileHeader]['results']
+ $success = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] );
+ if ( $success ) {
+ $fileData[$fileHeader]['results'] = "<p>$fileHeader file processed successfully.</p>";
+ }
+
+ // Store the first files into wp options
+ switch ( $file['type'] ) {
+ case 'amenity':
+ update_option( $this->wpOptionPrefix . $file['type'], $this->amenities );
+ break;
+ case 'category':
+ update_option( $this->wpOptionPrefix . $file['type'], $this->categories );
+ break;
+ case 'city':
+ update_option( $this->wpOptionPrefix . $file['type'], $this->cities );
+ break;
+ case 'region':
+ update_option( $this->wpOptionPrefix . $file['type'], $this->regions );
+ break;
+ case 'county':
+ update_option( $this->wpOptionPrefix . $file['type'], $this->counties );
+ break;
+ }
}
}
+ if ( count( $this->errors ) == 0 ) {
+ $readyToProcess = true;
+ }
$view = 'process.html';
break;
+ case 'processMembers':
+ foreach ( $fileData as $fileHeader => $file ) {
+ if ( is_file( $uploadPath . '/' . $file['name'] ) && $fileHeader != 'Member' ) {
+ // Retrieve the first files from wp options
+ switch ( $file['type'] ) {
+ case 'amenity':
+ $this->amenities = get_option( $this->wpOptionPrefix . $file['type'], array() );
+ break;
+ case 'category':
+ $this->categories = get_option( $this->wpOptionPrefix . $file['type'], array() );
+ break;
+ case 'city':
+ $this->cities = get_option( $this->wpOptionPrefix . $file['type'], array() );
+ break;
+ case 'region':
+ $this->regions = get_option( $this->wpOptionPrefix . $file['type'], array() );
+ break;
+ case 'county':
+ $this->counties = get_option( $this->wpOptionPrefix . $file['type'], array() );
+ break;
+ }
+ } else if ( is_file( $uploadPath . '/' . $file['name'] ) && $fileHeader == 'Member' ) {
+ $fileData[$fileHeader]['results'] = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] );
+ }
+ }
+ $view = 'processMembers.html';
+ break;
+
default:
$view = 'index.html';
// check upload dir to see if they have any files in yet
}
$templateData = array(
+ 'errors' => $this->errors,
'data' => false,
'fileData' => $fileData,
'clearData' => $clearData,
return $fileData;
}
+ /**
+ * processFile
+ *
+ * Processes a file for the member import. Based on the type of file.
+ * Report errors in the $this->errors array.
+ *
+ * @param mixed $fileName File name for the csv file.
+ * @param mixed $type Type (category,amenity,city)
+
+ * @access public
+ * @return void
+ */
public function processFile( $fileName, $type )
{
$ret = '';
+ $errorCount = 0;
switch ( $type ) {
case 'amenity':
$amenityData = $this->readCSVFile( $fileName );
if ( $amenityId ) {
$this->amenities[$data['id']]['new_id'] = $amenityId;
} else {
- $this->wpdb->insert(
+ $success = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenities',
array(
'name' => $data['name']
),
'%s'
);
- $this->amenities[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ if ( $success ) {
+ $this->amenities[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ } else {
+ $errorCount++;
+ $this->errors[] = '<p>There was an error adding amenity</p>';
+ }
}
}
$ret .= '<p>...</p>';
+ return ( $errorCount == 0 );
break;
case 'category':
$categoryData = $this->readCSVFile( $fileName );
if ( $categoryId ) {
$this->categories[$data['id']]['new_id'] = $categoryId;
} else {
- $this->wpdb->insert(
+ $success = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'categories',
array(
'name' => $data['name']
),
'%s'
);
- $this->categories[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ if ( $success ) {
+ $this->categories[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ } else {
+ $errorCount++;
+ $this->errors[] = '<p>There was an error adding category</p>';
+ }
}
}
$ret .= '<p>...</p>';
+ return ( $errorCount == 0 );
break;
case 'city':
$cityData = $this->readCSVFile( $fileName );
if ( $cityId ) {
$this->cities[$data['id']]['new_id'] = $cityId;
} else {
- $this->wpdb->insert(
+ $success = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities',
array(
'name' => $data['name']
),
'%s'
);
- $this->cities[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ if ( $success ) {
+ $this->cities[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ } else {
+ $errorCount++;
+ $this->errors[] = '<p>There was an error adding city</p>';
+ }
}
}
$ret .= '<p>...</p>';
+ return ( $errorCount == 0 );
break;
case 'region':
$regionData = $this->readCSVFile( $fileName );
if ( $regionId ) {
$this->regions[$data['id']]['new_id'] = $regionId;
} else {
- $this->wpdb->insert(
+ $success = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'regions',
array(
'name' => $data['name'],
),
'%s'
);
- $this->regions[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ if ( $success ) {
+ $this->regions[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ } else {
+ $errorCount++;
+ $this->errors[] = '<p>There was an error adding region</p>';
+ }
}
}
$ret .= '<p>...</p>';
+ return ( $errorCount == 0 );
break;
case 'county':
$countyData = $this->readCSVFile( $fileName );
if ( $countyId ) {
$this->counties[$data['id']]['new_id'] = $countyId;
} else {
- $this->wpdb->insert(
+ $success = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'counties',
array(
'name' => $data['name'],
),
'%s'
);
- $this->counties[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ if ( $success ) {
+ $this->counties[$data['id']]['new_id'] = $this->wpdb->insert_id;
+ } else {
+ $errorCount++;
+ $this->errors[] = '<p>There was an error adding county</p>';
+ }
}
}
$ret .= '<p>...</p>';
+ return ( $errorCount == 0 );
break;
case 'member':
$memberData = $this->readCSVFile( $fileName );
);
$memberId = $this->wpdb->insert_id;
$this->members[$data['id']]['new_id'] = $this->wpdb->insert_id;
+
+ // Logo needs to be a complete url.
+
+
// Add the member info record
$insert = $this->wpdb->insert(
GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info',
array(
- 'member' => $memberId,
- 'member_name' => $data['member_name'],
- 'status' => $this->config['status_numb']['Active'],
- 'reference_name' => 'Imported Member Information',
- 'descr' => $data['descr'],
- 'short_descr' => $data['short_descr'],
- 'addr1' => $data['addr1'],
- 'addr2' => $data['addr2'],
- 'city' => ((isset($data['city']) && isset($this->cities[$data['city']]['new_id'])) ? $this->cities[$data['city']]['new_id']: 0),
- 'state' => $data['state'],
- 'country' => $data['country'],
- 'region' => ((isset($data['region']) && isset($this->regions[$data['region']]['new_id'])) ? $this->regions[$data['region']]['new_id']: 0),
- 'county' => ((isset($data['county']) && isset($this->counties[$data['county']]['new_id'])) ? $this->counties[$data['county']]['new_id']: 0),
- 'zip' => $data['zip'],
- 'lat' => $data['lat'],
- 'lon' => $data['lon'],
- 'phone' => $data['phone'],
- 'toll_free' => $data['toll_free'],
- 'url' => $data['url'],
- 'email' => $data['email'],
- 'logo' => $data['logo'],
- 'notes' => '',
- 'create_time' => date( 'Y-m-d' ),
- 'modify_time' => date( 'Y-m-d' ),
- 'cc_type' => 0,
+ 'member' => $memberId,
+ 'member_name' => $data['member_name'],
+ 'status' => $this->config['status_numb']['Active'],
+ 'reference_name' => 'Imported Member Information',
+ 'descr' => $data['descr'],
+ 'short_descr' => $data['short_descr'],
+ 'addr1' => $data['addr1'],
+ 'addr2' => $data['addr2'],
+ 'city' => ((isset($data['city']) && isset($this->cities[$data['city']]['new_id'])) ? $this->cities[$data['city']]['new_id']: 0),
+ 'state' => $data['state'],
+ 'country' => $data['country'],
+ 'region' => ((isset($data['region']) && isset($this->regions[$data['region']]['new_id'])) ? $this->regions[$data['region']]['new_id']: 0),
+ 'county' => ((isset($data['county']) && isset($this->counties[$data['county']]['new_id'])) ? $this->counties[$data['county']]['new_id']: 0),
+ 'zip' => $data['zip'],
+
+ 'mailing_addr1' => $data['mailing_addr1'],
+ 'mailing_addr2' => $data['mailing_addr2'],
+ 'mailing_city' => ((isset($data['mailing_city']) && isset($this->cities[$data['mailing_city']]['new_id'])) ? $this->cities[$data['mailing_city']]['new_id']: 0),
+ 'mailing_state' => $data['mailing_state'],
+ 'mailing_zip' => $data['mailing_zip'],
+
+ 'lat' => $data['lat'],
+ 'lon' => $data['lon'],
+ 'phone' => $data['phone'],
+ 'toll_free' => $data['toll_free'],
+ 'url' => $data['url'],
+ 'reservation_url' => $data['reservation_url'],
+ 'email' => $data['email'],
+ 'logo' => $data['logo'],
+ 'notes' => '',
+ 'create_time' => date( 'Y-m-d' ),
+ 'modify_time' => date( 'Y-m-d' ),
+ 'cc_type' => 0,
),
array(
- '%d',
- '%s',
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
- '%s',
- '%s',
- '%d',
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
+ '%d', // member
+ '%s', // member_name
+ '%d', // status
+ '%s', // reference_name
+ '%s', // descr
+ '%s', // short_descr
+ '%s', // addr1
+ '%s', // addr2
+ '%d', // city
+ '%s', // state
+ '%d', // country
+ '%d', // region
+ '%s', // county
+ '%s', // zip
+ '%s', // mailing_addr1
+ '%s', // mailing_addr2
+ '%d', // mailing_city
+ '%s', // mailing_state
+ '%s', // mailing_zip
+ '%s', // lat
+ '%s', // lon
+ '%s', // phone
+ '%s', // toll_free
+ '%s', // url
+ '%s', // reservation_url
+ '%s', // email
+ '%s', // logo
+ '%s', // notes
+ '%s', // create_time
+ '%s', // modify_time
+ '%d', // cc_type
)
);
if ( !$insert ) {