From: Laury GvR Date: Tue, 7 Feb 2017 14:10:09 +0000 (-0500) Subject: Test build L#1.0 X-Git-Tag: v1.0.0^2~516 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=69bbe9ff8382f1a47608cfe737c8044eba5302cc;p=WP-Plugins%2Fglm-member-db-registrations.git Test build L#1.0 --- diff --git a/models/admin/management/general.php b/models/admin/management/general.php deleted file mode 100644 index 696212b..0000000 --- a/models/admin/management/general.php +++ /dev/null @@ -1,1703 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release registrations.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load Management Registrations data abstract -require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; - -/** - * GlmMembersAdmin_management_registrations - * - * PHP version 5 - * - * @category Model - * @package GLM Member DB - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott - * Exp $ - */ -class GlmMembersAdmin_management_registrations extends GlmDataRegistrationsManagement -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * dbh Postgres database connection - * - * @var mixed - * @access public - */ - public $dbh; - /** - * settings used for the schema and tablenames - * - * @var mixed - * @access public - */ - public $settings = array(); - /** - * categories - * - * @var bool - * @access public - */ - public $categories = array(); - public $oldCatMap = array(); - /** - * registrations - * - * @var bool - * @access public - */ - public $registrations = array(); - public $image_owner; - - /** - * Constructor - * - * This contructor performs the work for this model. This model returns - * an array containing the following. - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * '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. - * - * @wpdb object WordPress database object - * - * @return array Array containing status, suggested view, and any data - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - // Run constructor for members data class - parent::__construct(false, false); - - } - - public function importRegistrationImages() - { - require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php'; - $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config); - // get all registrations with images - $sql = " - SELECT id,image,old_registration_id - FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX. "registrations - WHERE image != '' AND image IS NOT NULL"; - $results = $this->wpdb->get_results($sql, ARRAY_A); - $out = '
$results: ' . print_r($results, true) . '
'; - $imgUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/'; - foreach ( $results as $registration ) { - $imageFullUrl = $imgUrl . $registration['image']; - $res = $ImageUpload->storeImage($imageFullUrl); - - if ( $res['newFileName'] ) { - $this->wpdb->update( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations', - array( - 'image' => $res['newFileName'] - ), - array( 'id' => $registration['id'] ), - array( '%s' ), - array( '%d' ) - ); - } - } - return $out; - } - - public function importRegistrationFiles() - { - // get all registrations with images - $sql = " - SELECT id,file1,file2_descr,old_registration_id - FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX. "registrations - WHERE file1 != '' AND file1 IS NOT NULL"; - $results = $this->wpdb->get_results($sql, ARRAY_A); - $fileUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/'; - $out = '
$results: ' . print_r($results, true) . '
'; - foreach ( $results as $registration ) { - if ( $registration['image']) { - $fileFullUrl = $fileUrl . $registration['image']; - $fp = fopen( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $registration['file1'], 'w+' ); - $ch = curl_init( $fileUrl . $registration['file1'] ); - curl_setopt($ch, CURLOPT_TIMEOUT, 50); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - $fileData = curl_exec($ch); - $httpCode = curl_getinfo($ch); - curl_close($ch); - fclose($fp); - // Set correct file permissions - $oldUmask = umask(0); - chmod( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $registration['file1'], 0660 ); - umask($oldUmask); - } - } - return $out; - } - - /** - * modelAction - * - * @param bool $actionData - * @access public - * @return void - */ - public function modelAction($actionData = false) - { - - $option = false; - $test_result = false; - $import_result = false; - $settings_updated = false; - $settings_update_error = false; - $registration_settings = false; - $icalFeedResult = false; - $import_feeds = false; - $option2 = false; - - if (isset($_REQUEST['option'])) { - $option = $_REQUEST['option']; - } - - $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config ); - - switch ($option) { - - case 'timelyImport': - $import = false; - if (isset($_REQUEST['import'])) { - $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN ); - } - $import_result = $this->importFromTimely(); - break; - - case 'icalfeed': - if ( isset( $_REQUEST['option2'] ) ) { - $option2 = filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING ); - } - $icalFeedResult = ''; - if ( $option2 === 'delete' && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { - $this->wpdb->delete( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "feed_import", - array( 'id' => $feed_id ), - '%d' - ); - if ( wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ) ) { - wp_clear_scheduled_hook( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ); - } - } - if ( $option2 === 'refresh' && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { - //$icalFeedResult .= $this->importIcalFeed( $feed_id ); - // Set up the registration schedule - if ( wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ) ) { - wp_clear_scheduled_hook( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ); - } - wp_schedule_registration( time(), GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ); - } - if ( isset( $_REQUEST['feed_url'] ) && $feed_url = filter_var( $_REQUEST['feed_url'], FILTER_VALIDATE_URL ) ) { - // Add this feed url to the table - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "feed_import", - array( - 'feed_url' => $feed_url, - 'created' => current_time( 'mysql' ) - ), - '%s' - ); - $feed_id = $this->wpdb->insert_id; - - // Setup the registration feed to pull on schedule - if ( !wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, $feed_id ) ) { - wp_schedule_registration( time(), GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ); - } - } - - break; - - case 'registrationImagesImport': - - $this->image_owner = filter_var($_REQUEST['img_owner_id'], FILTER_SANITIZE_STRING); - - if ( $this->image_owner ) { - $this->importRegistrationImages(); - $this->importRegistrationFiles(); - $import_result = '

All images and files imported

'; - } else { - $import_result = '
Failure: Not given owner id.
'; - } - - break; - - case 'registrationFilesImport': - break; - - case 'registrationimport': - - $import = false; - if (isset($_REQUEST['import'])) { - $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN ); - } - switch ($import) { - case 'true': - $import_result = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - $db_host = filter_var( $_REQUEST['db_host'], FILTER_SANITIZE_STRING ); - $db_name = filter_var( $_REQUEST['db_name'], FILTER_SANITIZE_STRING ); - $db_user = filter_var( $_REQUEST['db_user'], FILTER_SANITIZE_STRING ); - $db_password = filter_var( $_REQUEST['db_password'], FILTER_SANITIZE_STRING ); - $this->connectPostgresDb($db_host, $db_name, $db_user, $db_password); - - $this->settings = filter_var_array( - $_REQUEST, - array( - 'schema' => FILTER_SANITIZE_STRING, - 'cattablename' => FILTER_SANITIZE_STRING, - 'tablename' => FILTER_SANITIZE_STRING, - 'sdate' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array( - 'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%' - ) - ) - - ) - ); - $import_result .= '
$this->settings: ' . print_r($this->settings, true) . '
'; - $this->addCategories(); - $import_result .= $this->addRegistrations(); - - $import_result .= '
$this->categories: ' . print_r($this->categories, true) . '
'; - - - break; - default: - break; - } - $action = ''; - if (isset($_REQUEST['action'])) { - $action = $_REQUEST['action']; - } - break; - - case 'settings': - - default: - - // Make sure option is set if default - $option = 'settings'; - - // Determine if current user can edit configurations - if (!current_user_can('glm_members_management')) { - return array( - 'status' => false, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'admin/error/index.html', - 'data' => array( - 'reason' => 'User does not have rights to make configuration changes.' - ) - ); - } - - // Check for submission option - $option2 = ''; - if (isset($_REQUEST['option2'])) { - $option2 = $_REQUEST['option2']; - } - - switch($option2) { - - // Update the settings and redisplay the form - case 'submit': - - // Update the registration management settings - $registration_settings = $this->updateEntry(1); - if ($registration_settings['status']) { - $settings_updated = true; - } else { - $settings_update_error = true; - } - - break; - - // Default is to get the current settings and display the form - default: - - // Try to get the first (should be only) entry for general settings. - $registration_settings = $this->editEntry(1); - //echo '
$registration_settings: ' . print_r( $registration_settings, true ) . '
'; - - if ($registration_settings === false) { - - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice("  /models/admin/management/registrations.php: Unable to load registrations management settings.", 'Alert'); - } - - } - - break; - - } - - break; - - } - - $import_feeds = $importFeeds->getList(); - - if ( $import_feeds ) { - foreach ( $import_feeds as $key => &$feed ) { - // check the next run time - $feed['next_runtime'] = wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( (int)$feed['id'] ) ); - } - } - - // Populate the state list for registration default state selection - $registration_settings['registration_default_state'] = $this->config['states']; - - // Compile template data - $template_data = array( - 'import_feeds' => $import_feeds, - 'option' => $option, - 'testResult' => $test_result, - 'importResult' => $import_result, - 'settingsUpdated' => $settings_updated, - 'settingsUpdateError' => $settings_update_error, - 'registrationsSettings' => $registration_settings, - 'icalFeedResult' => $icalFeedResult, - ); - - // Return status, suggested view, and data to controller - return array( - 'status' => true, - 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'admin/management/registrations.html', - 'data' => $template_data - ); - - - } - - /** - * connectPostgresDb - * - * Make a connection to the given database for the site. (postgres) - * Sets the $this->dbh with the postgers database connection - * - * @param mixed $db_host - * @param mixed $db_name - * @param mixed $db_user - * @param mixed $db_password - * @access public - * @return void - */ - public function connectPostgresDb($db_host, $db_name, $db_user, $db_password) - { - $conn_str = "pgsql:"; - if ( $db_host ) { - $conn_part[] = "host={$db_host}"; - } - if ( $db_name ) { - $conn_part[] = "dbname={$db_name}"; - } - if ( $db_user ) { - $conn_part[] = "user={$db_user}"; - } - if ( $db_password ) { - $conn_part[] = "password={$db_password}"; - } - if ( !empty($conn_part) ) { - $conn_str .= implode( " ", $conn_part ); - } - $driver_options = array( - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH, - ); - try { - $this->dbh = new PDO($conn_str, null, null, $driver_options); - $this->dbh->setAttribute( - PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION - ); - } catch(PDOException $e) { - echo '
$e: ' . print_r($e, true) . '
'; - wp_die(); - } - } - - public function getCategoryId( $category ) - { - $category_id = $this->wpdb->get_var( - $this->wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories - WHERE name = %d", - $category - ) - ); - if ( $category_id ) { - return $category_id; - } else { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories', - array( - 'name' => $category, - 'parent' => 0 - ), - arary( - '%s', - '%d' - ) - ); - $category_id = $this->wpdb->insert_id; - return $category_id; - } - } - /** - * addCategories - * - * Checks to see if there's an Registration Category already in the database. - * If not it will create the entry. - * Sets up the class variables - * $this->categories (contains all the categories that get added keyed with - * category id) - * $this->oldCatMap (map of the old category id to new category ids) - * - * @access public - * @return void - */ - public function addCategories() - { - $category_label = ( $this->settings['tablename'] == 'registration' ) ? 'descr' : 'name'; - $return = ''; - $sql = " - SELECT * - FROM {$this->settings['schema']}.{$this->settings['cattablename']} - ORDER BY id"; - $return .= '
$sql: ' . print_r($sql, true) . '
'; - try { - $categories = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); - $return .= '
$categories: ' . print_r($categories, true) . '
'; - foreach ( $categories as $category ) { - // first check to see if the category is already there - $sql = " - SELECT id - FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories - WHERE name = '" . esc_sql( trim($category[$category_label]) ) . "'"; - $return .= '
$sql: ' . print_r($sql, true) . '
'; - $found = $this->wpdb->get_row($sql, ARRAY_A); - $return .= '
$found: ' . print_r($found, true) . '
'; - if ( !isset($found) ) { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories', - array( - 'name' => trim($category[$category_label]), - 'parent' => 0 - ), - array( - '%s', - '%d' - ) - ); - $catid = $this->wpdb->insert_id; - $this->categories[$catid] = trim($category[$category_label]); - $this->oldCatMap[$category['id']] = $catid; - } else { - $this->categories[$found['id']] = trim($category[$category_label]); - $this->oldCatMap[$category['id']] = $found['id']; - } - } - } catch(PDOException $e) { - echo '
$e: ' . print_r($e, true) . '
'; - die('end here'); - } - return $return; - } - - public function addTimelyCategories() { - $category_counter = 0; - $categories = get_terms( 'registrations_categories' ); - foreach ( $categories as $category ) { - ++$category_counter; - // first check to see if the category is already there - $sql = " - SELECT id - FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories - WHERE name = '" . esc_sql( trim($category->name) ) . "'"; - $found = $this->wpdb->get_row($sql, ARRAY_A); - if ( !isset($found) ) { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories', - array( - 'name' => trim($category->name), - 'parent' => $category->parent - ), - array( - '%s', - '%d' - ) - ); - $catid = $this->wpdb->insert_id; - $this->categories[$catid] = trim($category->name); - $this->oldCatMap[$category->term_id] = $catid; - } else { - $this->categories[$found['id']] = trim($category->name); - $this->oldCatMap[$category->term_id] = $found['id']; - } - } - // Store the oldCatMap for the next pages. - update_option( 'glm-member-registration-old-cat-map', serialize( $this->oldCatMap ) ); - return "

Adding $category_counter Categories

"; - } - public function getOldCatMap() - { - return unserialize( get_option('glm-member-registration-old-cat-map') ); - } - /** - * getTime - * - * Given a time string return the the following format of time - * H:i - * hour and minute - * - * @param mixed $time String with any time format - * - * @access public - * @return void - */ - public function getTime($time) - { - //echo '
$time: ' . print_r($time, true) . '
'; - if (!$time) { - return false; - } - if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $time_parts)) { - return false; - } - //echo '
$timeParts: ' . print_r($time_parts, true) . '
'; - //$hour = (!$timeParts[3] || in_array(strtolower(trim($timeParts[3])), array('pm', 'p'))) - // ? ( ((int)$timeParts[1] === 12) ? 12 : (int)$timeParts[1] += 12 ) - // : ( ((int)$timeParts[1] === 12) ? 0 : (int)$timeParts[1] ); - $hour = $time_parts[1]; - if ( in_array( strtolower( $time_parts[3] ), array( 'pm', 'p' ) ) ) { - $hour += 12; - } - if ( in_array( strtolower( $time_parts[3] ), array( 'am', 'a' ) ) ) { - if ( (int)$hour === 12 ) { - $hour = 0; - } - } - $min = ($time_parts[2]) ? $time_parts[2] : 0; - // parse the hour from registration - $dateTime = new DateTime(); - $dateTime->setTime( $hour, $min ); - //cho '
$dateTime: ' . print_r($dateTime, true) . '
'; - return $dateTime->format('H:i'); - } - - /** - * getCityId - * - * Given a city name find and return the id of the city. - * If a city cannot be found then create city with that name. - * - * @param mixed $city_name Name of the city - * - * @access public - * @return id of city - */ - public function getCityId($city_name) - { - if ( !$city_name ) { - return false; - } - $sql = " - SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities - WHERE name like '" . esc_sql( trim( $city_name ) ) . "'"; - $cityId = $this->wpdb->get_row($sql, ARRAY_A); - if ( !$cityId ) { - // then add the city to the city table - $this->wpdb->insert( - GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', - array( 'name' => trim( $city_name ) ), - array( '%s' ) - ); - return $this->wpdb->insert_id; - } else { - return $cityId['id']; - } - } - - /** - * addRegistrations - * - * Start with a clean set of registration tables. ( delete all registration data ) - * Grab all registrations starting with the given start date. - * Enter them into the new registration plugin tables. - * - * @access public - * @return void - */ - public function addRegistrations() - { - // clear the registrations tables first - $this->clearData(); - $Recurrences = new GlmDataRegistrationsRecurrences($this->wpdb, $this->config); - $return = ''; - $old_registration_format = ($this->settings['tablename'] == 'registration'); - if ( $old_registration_format ) { - $sql = " - SELECT * - FROM {$this->settings['schema']}.{$this->settings['tablename']} - WHERE edate >= '{$this->settings['sdate']}'::DATE"; - } else { - $sql = " - SELECT * - FROM {$this->settings['schema']}.{$this->settings['tablename']} - WHERE ending >= '{$this->settings['sdate']}'::DATE"; - $prepare_sql = " - SELECT filename,urltext - FROM {$this->settings['schema']}.files - WHERE registration = :eid"; - $get_file_data = $this->dbh->prepare($prepare_sql); - } - //$sql .=" AND file != '' "; - //$sql .= " AND id = 2838"; - $this->wpdb->show_errors(); - //echo '
$sql: ' . print_r($sql, true) . '
'; - try { - $registrations = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC); - $return .= '
$registrations: ' . print_r($registrations, true) . '
'; - foreach ( $registrations as $registration ) { - $found_member_id = $refType = null; - $member_id = (isset($registration['member_id'])) ? $registration['member_id'] : $registration['member']; - if ( $member_id ) { - // get the new member id - $sql = " - SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members - WHERE old_member_id = " . esc_sql( trim($member_id) ); - $found_member_id = $this->wpdb->get_row($sql, ARRAY_A); - if ( $found_member_id ) { - $found_member_id = $found_member_id['id']; - $refType = $this->config['ref_type_numb']['Member']; - } - } - if ( $old_registration_format ) { - $intro = substr( trip_tags( $registration['descr'] ), 0, 150 ); - // Remove uneeded newlines from both intro and description - $intro = preg_replace( "/\s\s+/", ' ', $intro ); - $descr = preg_replace( "/\s\s+/", ' ', $registration['descr'] ); - $registration_data = array( - 'status' => (($registration['visable'] == '1') - ? $this->config['status_numb']['Active'] - : $this->config['status_numb']['Inactive']), - 'created' => $registration['create_date'], - 'updated' => $registration['create_date'], - 'approved' => $registration['approved_date'], - 'name' => $registration['header'], - 'intro' => $intro, - 'descr' => $descr, - 'image' => $registration['img'], - 'file1' => $registration['file'], - 'file1_descr' => $registration['filename'], - 'cost' => $registration['cost'], - 'url' => $registration['url'], - 'old_registration_id' => $registration['id'], -// 'ref_type' => $refType, - 'ref_type' => 10, - 'ref_dest' => $found_member_id, - 'admin_name' => $registration['admin_contact_name'], - 'admin_org' => $registration['admin_org_name'], - 'admin_email' => $registration['admin_email'], - 'admin_phone' => $registration['admin_phone'], - 'contact_email' => $registration['email'], - 'contact_name' => $registration['contact'], - 'contact_phone' => $registration['phone'], - 'notes' => $registration['notes'], - 'hide_address' => $registration['hide_address'], - ); - $registration_data_format = array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - ); - } else { - $get_file_data->bindParam(':eid', $registration['id'], PDO::PARAM_INT); - $get_file_data->execute(); - $file = $filename = ''; - $fileData = $get_file_data->fetch(PDO::FETCH_ASSOC); - if ($fileData ) { - $file = $fileData['filename']; - $filename = $fileData['urltext']; - } - $intro = ($registration['intro']) - ? substr(strip_tags($registration['intro']), 0, 150) - : substr(strip_tags($registration['description']), 0, 150); - // Remove uneeded newlines from both intro and description - $intro = preg_replace( "/\s\s+/", ' ', $intro ); - $descr = preg_replace( "/\s\s+/", ' ', $registration['description'] ); - $registration_data = array( - 'status' => (($registration['active'] == '1') - ? $this->config['status_numb']['Active'] - : $this->config['status_numb']['Inactive']), - 'created' => $registration['created'], - 'updated' => $registration['updated'], - 'approved' => $registration['approved'], - 'name' => $registration['header'], - 'intro' => $intro, - 'descr' => $descr, - 'image' => $registration['image'], - 'file1' => $file, - 'file1_descr' => $filename, - 'cost' => $registration['cost'], - 'url' => $registration['website'], - 'old_registration_id' => $registration['id'], -// 'ref_type' => $refType, - 'ref_type' => 10, - 'ref_dest' => $found_member_id, - 'admin_name' => $registration['admin_contact'], - 'admin_org' => $registration['admin_org'], - 'admin_email' => $registration['admin_email'], - 'admin_phone' => $registration['admin_phone'], - 'contact_email' => $registration['contact_email'], - 'contact_name' => $registration['contact_name'], - 'contact_phone' => $registration['contact_phone'], - 'notes' => $registration['notes'], - 'hide_address' => $registration['hide_address'], - 'use_member_location' => $registration['use_memberloc'] - ); - $registration_data_format = array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - ); - } - echo ''; - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations', - $registration_data, - $registration_data_format - ); - $registration_id = $this->wpdb->insert_id; - var_dump( $registration_id ); - echo '
$registrationId: from insert ' . print_r($registration_id, true) . '
'; - if ( !$registration_id ) { - echo '
SQL Error: ' . $this->wpdb->last_error . '
'; - echo '
SQL Error: ' . $this->wpdb->print_error() . '
'; - } - // checking for $registrationId - //echo '
$registrationId: ' . print_r($registrationId, true) . '
'; - if (!$registration_id) { - die('something is wrong no registrationId'); - } - // generate the slug name for this new registration - $registration_abstract = new GlmDataRegistrations($this->wpdb, $this->config); - $registration_abstract->updateSlug($registration_id); - // category for registration - if ( $registration['topicid'] ) { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories', - array( - 'registration' => $registration_id, - 'category' => $this->oldCatMap[$registration['topicid']] - ), - array( - '%d', - '%d' - ) - ); - } - if ( $registration['category'] ) { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories', - array( - 'registration' => $registration_id, - 'category' => $this->oldCatMap[$registration['category']] - ), - array( - '%d', - '%d' - ) - ); - } - // recurrences for the registration - if (isset($registration['reacur'])) { - $recurring_registration = $registration['reacur']; - if ( $recurring_registration && ( $registration['bdate'] == $registration['edate'] ) ) { - $recurring_registration = 0; - } - } else { - $recurring_registration = $registration['recurr']; - if ( $recurring_registration && ( $registration['starting'] == $registration['ending'] ) ) { - $recurring_registration = 0; - } - } - $day_of_week = - $month_of_year = - $week_of_month = - $by_day_of_month = - $last_day_of_month = null; - if ( $recurring_registration ) { - if ( $registration['daysow'] ) { - $day_of_week = $registration['daysow']; - } else { - $day_of_week = 127; - } - if ( $registration['weekom'] ) { - switch ($registration['weekom']) { - case '1': - $week_of_month = 1; - break; - case '2': - $week_of_month = 2; - break; - case '3': - $week_of_month = 4; - break; - case '4': - $week_of_month = 8; - break; - case '5': - $week_of_month = 16; - break; - } - } else { - $week_of_month = 63; - } - $month_of_year = 4095; - } else { - $day_of_week = 127; - $month_of_year = 4095; - } - if ( isset($registration['btime']) ) { - $btime = $this->getTime($registration['btime']); - $etime = $this->getTime($registration['etime']); - } else { - $btime = $this->getTime($registration['starthour']); - $etime = $this->getTime($registration['endhour']); - } - $start_time_only = ($btime && !$etime); - if ( $start_time_only ) { - $etime = $btime; - } - if ( isset($registration['all_day']) ) { - $all_day = ( $registration['all_day'] || !$btime ); - } else { - $all_day = ( $registration['allday'] || !$btime ); - } - if (isset($registration['bdate'])) { - $from_date = $registration['bdate']; - $to_date = $registration['edate']; - } else { - $from_date = $registration['starting']; - $to_date = $registration['ending']; - } - $recur_data = array( - 'registration' => $registration_id, - 'name' => 'Imported Registration Schedule', - 'start_time' => $btime, - 'end_time' => $etime, - 'start_time_only' => $start_time_only, - 'from_date' => $from_date, - 'to_date' => $to_date, - 'all_day' => $all_day, - 'recurring' => $recurring_registration, - 'month_of_year' => $month_of_year, - 'week_of_month' => $week_of_month, - 'day_of_week' => $day_of_week, - 'by_day_of_month' => $by_day_of_month, - 'last_day_of_month' => $last_day_of_month - ); - echo '
' . print_r( $recurData, true) . '
'; - echo '
$recurData: ' . print_r($recur_data, true) . '
'; - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'recurrences', - $recur_data, - array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - ) - ); - $recur_id = $this->wpdb->insert_id; - $Recurrences->createRecurrenceTimesEntries( $recur_id, true, true ); - // location for the registration - $has_location = ($registration['loc'] || $registration['place']); - if ( $has_location ) { - $location_data = $location_format = array(); - $location_data['registration'] = $registration_id; - $location_format[] = '%d'; - if ($registration['place']) { - $location_data['name'] = $registration['place']; - $location_format[] = '%s'; - } - if ($registration['loc']) { - $location_data['name'] = $registration['loc']; - $location_format[] = '%s'; - } - if ($registration['address']) { - $location_data['address'] = $registration['address']; - $location_format[] = '%s'; - } - if ($registration['city']) { - $location_data['city'] = $this->getCityId( $registration['city'] ); - $location_format[] = '%s'; - } - if ($registration['state']) { - $location_data['state'] = $registration['state']; - $location_format[] = '%s'; - } - if ($registration['zip']) { - $location_data['zip'] = $registration['zip']; - $location_format[] = '%s'; - } - if ($registration['lat']) { - $location_data['lat'] = $registration['lat']; - $location_format[] = '%s'; - } - if ($registration['lon']) { - $location_data['lon'] = $registration['lon']; - $location_format[] = '%s'; - } - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'locations', - $location_data, - $location_format - ); - $location_id = $this->wpdb->insert_id; - if ( !$location_id ) { - echo '
$locationData: ' . print_r($location_data, true) . '
'; - die('no return id for location'); - } - } - } - } catch(PDOException $e) { - echo '
$e: ' . print_r($e, true) . '
'; - die('end here'); - } - return $return; - } - public function clearData() - { - $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "registrations" ); - $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "recurrences" ); - $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "times" ); - $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "registration_categories" ); - $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "locations" ); - } - public function importFromTimely() { - $limit = 25; - $debug = false; - if ( isset( $_REQUEST['start'] ) ) { - $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); - } else { - $start = 0; - } - if ( $start === 0 ) { - // clear the registrations tables first. - $this->clearData(); - // Add the Categories from Time.ly. - $return_string = $this->addTimelyCategories(); - } else { - $this->oldCatMap = $this->getOldCatMap(); - } - - $yearly_registrations = - $daily_registrations = - $weekly_registrations = - $interval_registrations = - $monthly_registrations = - $custom_date_registrations = 0; - - $Recurrences = new GlmDataRegistrationsRecurrences($this->wpdb, $this->config); - require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php'; - $image_upload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config); - - $sql = " - SELECT * - FROM " . $this->wpdb->prefix . "posts - WHERE post_type = 'ai1ec_registration' - AND post_status = 'publish'"; - $sql .= " LIMIT $limit OFFSET $start"; - $results = $this->wpdb->get_results( $sql, ARRAY_A ); - - $registration_counter = 0; - - if ( !empty( $results ) ) { - foreach ( $results as $post ) { - // Initialize some variables - $serialized_custom_times = null; - if ( $debug ) { - echo '
'; - } - ++$registration_counter; - $sql = " - SELECT * - FROM " . $this->wpdb->prefix . "ai1ec_registrations - WHERE post_id = {$post['ID']}"; - $registration_data = $this->wpdb->get_row( $sql, ARRAY_A ); - $cost_data = unserialize( $registration_data['cost'] ); - $cost = $cost_data['cost']; - $is_free = $cost_data['is_free']; - - // use the posts table data - $image = ''; - if ( has_post_thumbnail( $post['ID'] ) ) { - $thumbnail_id = get_post_thumbnail_id( $post['ID'] ); - $thumb_src = wp_get_attachment_image_src( $thumbnail_id, 'large' ); - //echo '
$thumb_src: ' . print_r($thumb_src, true) . '
'; - $res = $image_upload->storeImage($thumb_src[0]); - //echo '
$res: ' . print_r($res, true) . '
'; - if ( $res['newFileName'] ) { - $image = $res['newFileName']; - } - } - // Insert the registration data - $registration_import_data = array( - 'status' => $this->config['status_numb']['Active'], - 'created' => $post['post_date'], - 'updated' => $post['post_modified'], - 'approved' => $post['post_modified'], - 'name' => $post['post_title'], - 'name_slug' => $post['post_name'], - 'intro' => mb_substr( strip_tags( $post['post_content'] ), 0, 80 ), - 'descr' => $post['post_content'], - 'image' => $image, - 'file1' => null, - 'file1_descr' => null, - 'cost' => $cost, - 'free' => $is_free, - 'url' => $registration_data['contact_url'], - 'old_registration_id' => $post['ID'], -// 'ref_type' => null, - 'ref_type' => 10, - 'ref_dest' => null, - 'admin_name' => $registration_data['contact_name'], - 'admin_org' => null, - 'admin_email' => $registration_data['contact_email'], - 'admin_phone' => $registration_data['contact_phone'], - 'contact_email' => $registration_data['contact_email'], - 'contact_name' => $registration_data['contact_name'], - 'contact_phone' => $registration_data['contact_phone'], - 'notes' => null, - 'hide_address' => null, - 'use_member_location' => 0, - ); - $registration_data_format = array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - ); - $is_insert = $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations', - $registration_import_data, - $registration_data_format - ); - if ( $debug ) { - var_dump( $is_insert ); - } - $registration_id = $this->wpdb->insert_id; - if ( $debug ) { - var_dump( $registration_id ); - } - if ( !$registration_id ) { - $this->wpdb->print_error(); - echo '
$registration_import_data: ' . print_r($registration_import_data, true) . '
'; - echo '
SQL Error: ' . $this->wpdb->last_error . '
'; - echo '
SQL Error: ' . $this->wpdb->print_error() . '
'; - die('something is wrong no registration_id'); - } - // get the post categories - $categories = array(); - $post_terms = wp_get_post_terms( $post['ID'], 'registrations_categories', 'term_id' ); - foreach ( $post_terms as $term ) { - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories', - array( - 'registration' => $registration_id, - 'category' => $this->oldCatMap[$term->term_id] - ), - array( - '%d', - '%d' - ) - ); - } - if ( $debug ) { - echo '
$registration_data: ' . print_r($registration_data, true) . '
'; - echo '
$categories: ' . print_r($categories, true) . '
'; - } - - $by_day_of_month = - $last_day_of_month = null; - - $recurring_registration = - $start_time_only = - $recurring_registration = 0; - - $weekly = - $daily = false; - - $day_of_week = 127; - $month_of_year = 4095; - $week_of_month = 63; - - $custom_times = array(); - $curZone = date_default_timezone_get(); - if ( $debug ) { - echo '
$curZone: ' . print_r($curZone, true) . '
'; - } - if ( $registration_data['timezone_name'] ) { - date_default_timezone_set( $registration_data['timezone_name'] ); - } - $curZone = date_default_timezone_get(); - if ( $debug ) { - echo '
$curZone: ' . print_r($curZone, true) . '
'; - } - - $from_date = date( 'Y-m-d', $registration_data['start'] ); - if ( $debug ) { - echo '
$from_date: ' . print_r($from_date, true) . '
'; - $from_date_time = date( 'Y-m-d H:m:s', $registration_data['start'] ); - echo '
$from_date_time: ' . print_r($from_date_time, true) . '
'; - } - $to_date = date( 'Y-m-d', $registration_data['end'] ); - // check if the $to_date has 0 hr - // if the btime and etime are 00:00 then remove one day from $to_date - if ( date( 'H', $registration_data['end'] ) === '00' ) { - $ending_datetime = new DateTime( $to_date ); - $ending_datetime->modify('- 1 day'); - $to_date = $ending_datetime->format( 'Y-m-d' ); - } - if ( $debug ) { - echo '
$to_date: ' . print_r($to_date, true) . '
'; - $to_date_time = date( 'Y-m-d H:m:s', $registration_data['end'] ); - echo '
$to_date_time: ' . print_r($to_date_time, true) . '
'; - } - $btime = date( 'H:i', $registration_data['start'] ); - if ( $debug ) { - echo '
$btime: ' . print_r($btime, true) . '
'; - } - $etime = date( 'H:i', $registration_data['end'] ); - if ( $debug ) { - echo '
$etime: ' . print_r($etime, true) . '
'; - } - - - if ( $registration_data['recurrence_rules'] ) { - $recurring_registration = 1; - $recurrence_rules = explode( ';', $registration_data['recurrence_rules'] ); - if ( $debug ) { - echo '
$recurrence_rules: ' . print_r($recurrence_rules, true) . '
'; - } - foreach ( $recurrence_rules as $rule ) { - // check for RDATE , which are the custom dates that need to be serialized - if(strpos($rule, 'RDATE') !== false){ - $custom_date_registrations++; - $rdate = $rule; - $rdate = substr($rdate,6); - $custom_times = explode(',', $rdate); - } - if ( preg_match( ';FREQ=(.*);', $rule, $matches ) ) { - if ( $debug ) { - echo '
$matches: ' . print_r($matches, true) . '
'; - } - switch ( $matches[1] ) { - case "WEEKLY": - $weekly_registrations++; - $weekly_rule = $recurrence_rules[1]; - if(strpos($weekly_rule, "INTERVAL") !== false){ - $weekly_interval = substr($weekly_rule, 9); - $loopLimit = floor(52 / $weekly_interval); - $interval_sum = $weekly_interval; - for($i = 0; $i < $loopLimit; $i++ ){ - $date = date('Y-m-d',strtotime($from_date .'+'. $interval_sum .'weeks')); - $interval_dates[] = $date; - $interval_sum += $weekly_interval; - } - $serialized_custom_times = serialize($interval_dates); - } - $weekly = true; - // check for BYDAY - break; - case "DAILY": - $daily_registrations++; - $daily = true; - if(strpos($recurrence_rules[1], "INTERVAL") === false){ - $month_of_year = 4095; - $day_of_month = 2147483647; - $by_day_of_month = true; - } else { - $interval = $recurrence_rules[1]; - $interval = substr($interval, 9); - $loopLimit = floor(365 / $interval); - $interval_sum = $interval; - for($i = 0; $i < $loopLimit; $i++ ){ - $date = date('Y-m-d',strtotime($from_date .'+'. $interval_sum .'days')); - $interval_dates[] = $date; - $interval_sum += $interval; - } - $serialized_custom_times = serialize($interval_dates); - } - - break; - case "YEARLY": - $month_ints = $ints = $month_num = null; - if ( $recurrence_rules[1] ) { - $ints = 0; - $day_of_month = 0; - $yearly_registrations++; - $selected_from_date = substr($from_date, -2); - $selected_from_date--; - $selected_to_date = substr($to_date, -2); - $selected_to_date--; - $month_sum = 0; - $yearly = $recurrence_rules[1]; - $yearly = substr($yearly,8); - $month_ints = explode(',', $yearly); - if ( $debug ) { - echo '
$month_ints: ' . print_r($month_ints, true) . '
'; - } - foreach($month_ints as $ints){ - $ints--; - $ints = pow(2, $ints); - $month_sum += $ints; - } - $month_of_year = $month_sum; - if ( $debug ) { - echo '
$month_of_year: ' . print_r($month_of_year, true) . '
'; - } - if($selected_from_date == $selected_to_date){ - $selected_to_date++; - } - $day_of_month = pow(2,$selected_from_date ) + pow(2, $selected_to_date); - if ( $debug ) { - echo '
$day_of_month: ' . print_r($day_of_month, true) . '
'; - } - if($month_sum){ - $by_day_of_month = 1; - } - } else { - $ints = 0; - $month_sum = 0; - // get the month and day of month from $from_date and $to_date - $start_month = date( 'n', strtotime( $from_date ) ); - $end_month = date( 'n', strtotime( $to_date ) ); - for ( $index = ( $start_month - 1 ); $index <= ( $end_month -1 ); ++$index ) { - $ints = pow( 2, $index ); - $month_sum += $ints; - } - $month_of_year = $month_sum; - // Now do the day_of_month - $ints = 0; - $day_of_month = 0; - $start_day = date( 'j', strtotime( $from_date ) ); - if ( $debug ) { - echo '
$start_day: ' . print_r($start_day, true) . '
'; - } - $end_day = date( 'j', strtotime( $to_date ) ); - if ( $debug ) { - echo '
$end_day: ' . print_r($end_day, true) . '
'; - } - if ( $start_day == $end_day ) { - for ( $index = ( $start_day - 1); $index <= ( $end_day -1 ); ++$index ) { - $ints = pow( 2, $index ); - $day_of_month += $ints; - } - if($day_of_month){ - $by_day_of_month = 1; - } - $ending_datetime = new DateTime( $to_date ); - $ending_date = $ending_datetime->modify('2 years'); - $to_date = $ending_date->format( 'Y-m-d' ); - } else { - $serialized_custom_times = null; - $custom_dates_array = array(); - $this_datetime = null; - // if the dates span more than one day need to build the custom dates array - $starting_datetime = new DateTime( $from_date ); - $ending_datetime = new DateTime( $to_date ); - // loop through for the next 2 years - for ( $year_index = 0; $year_index <= 2; ++$year_index ) { - if ( $year_index !== 0 ) { - // adjust the datetimes plus one year - $starting_datetime->modify( '+ 1 year' ); - $ending_datetime->modify( '+ 1 year' ); - } - $starting_time = $starting_datetime->format( 'U' ); - $ending_time = $ending_datetime->format( 'U' ); - for ($index = $starting_time; $index <= $ending_time; $index += 86400 ) { - $custom_dates_array[] = date( 'Y-m-d', $index ); - } - } - if ( $debug ) { - echo '
$custom_dates_array: ' . print_r($custom_dates_array, true) . '
'; - } - $serialized_custom_times = serialize( $custom_dates_array ); - } - } - break; - case "MONTHLY": - $monthly_registrations++; - $monthly = $recurrence_rules[1]; - $byday_pos = strpos($monthly, "BYday"); - $bymonthday_pos = strpos($monthly, "BYMONTHDAY"); - if($byday_pos === false){ - $monthly = substr($monthly, 11); - $day_ints = explode(',', $monthly); - foreach($day_ints as $day){ - $day--; - $day = pow(2, $day); - $day_sum += $day; - } - $day_of_month = $day_sum; - if($day_sum){ - $by_day_of_month = 1; - } - } - break; - } - } else if ( preg_match( ';COUNT=(.*);', $rule, $matches ) ) { - if ( $debug ) { - echo '
$matches: ' . print_r($matches, true) . '
'; - } - // set the end date to COUNT days from start - try { - $number_of_days = (int)$matches[1] - 1; - $starting_datetime = new DateTime( $from_date ); - $add = ( $number_of_days === 1 ) ? '1 day': $number_of_days . ' days'; - $ending_date = $starting_datetime->modify($add); - $to_date = $ending_date->format( 'Y-m-d' ); - $recurring_registration = 0; - } catch (Exception $e) { - if ( $debug ) { - echo '
$e: ' . print_r($e, true) . '
'; - } - die(); - } - } else if ( preg_match( ';UNTIL=(.*);', $rule, $matches ) ) { - $to_date = date( 'Y-m-d', strtotime( $matches[1] ) ); - - } else if ( preg_match( ';BYMONTH=(.*);', $rule, $matches ) ) { -// $monthly = $recurrence_rules[1]; -// -// $selected_from_date = substr($from_date, -2); -// $selected_from_date--; -// $selected_to_date = substr($to_date, -2); -// $selected_to_date--; -// -// $monthly = substr($monthly, 8); -// $month_ints = explode(',', $monthly); -// foreach($month_ints as $day){ -// $day--; -// $day = pow(2, $day); -// $day_sum += $day; -// } -// $day_of_month = pow(2,$selected_from_date ) + pow(2,$selected_to_date); - - }else if ( preg_match( ';BYday=(.*);', $rule, $matches ) ) { - - if ( $debug ) { - echo '
1354 $matches: ' . print_r($matches, true) . '
'; - } - // check if the selection is the nth week with a selected day, if not parse the input as a list if selected days - if(strpos($matches[1], ",") == false){ - $week_number = substr($matches[1],0, 1); - $week_number = $week_number - 1; - $week_of_month = pow(2, $week_number); - $days[] = substr($matches[1], -2); - $by_day_of_month = 0; - } else { - $days = explode( ',', $matches[1] ); - } - $day_of_week = 0; - foreach ( $days as $day ) { - switch ( $day ) { - case "SU": - $day_of_week += pow(2, 0); - break; - case "MO": - $day_of_week += pow(2, 1); - break; - case "TU": - $day_of_week += pow(2, 2); - break; - case "WE": - $day_of_week += pow(2, 3); - break; - case "TH": - $day_of_week += pow(2, 4); - break; - case "FR": - $day_of_week += pow(2, 5); - break; - case "SA": - $day_of_week += pow(2, 6); - break; - } - } - } - } - if(!empty($custom_times)){ - $stamp = array(); - date_default_timezone_set('UTC'); - $serialized_custom_times = serialize($custom_times); - foreach($custom_times as $custom){ - - $convert = date('U',strtotime($custom)); - $stamp[] = date('Y-m-d', $convert); - } -// $from_date = $to_date = $stamp[0]; - $serialized_custom_times = serialize($stamp); - } - date_default_timezone_set($curZone); - } - if ($recurring_registration && $from_date == $to_date && empty( $custom_times ) ) { - // Add two years to the recurring registration if dates match - $starting_datetime = new DateTime( $from_date ); - $ending_date = $starting_datetime->modify('2 years'); - $to_date = $ending_date->format( 'Y-m-d' ); - } - $all_day = $registration_data['allday']; - - // instant registration is an registration with no end time - $start_time_only = $registration_data['instant_registration']; - if($start_time_only){ - $etime = $btime; - } - - // for the recurrences part - $recur_data = array( - 'registration' => $registration_id, - 'name' => 'Imported', - 'start_time' => $btime, - 'end_time' => $etime, - 'start_time_only' => $start_time_only, - 'from_date' => $from_date, - 'to_date' => $to_date, - 'all_day' => $all_day, - 'recurring' => $recurring_registration, - 'month_of_year' => $month_of_year, - 'week_of_month' => $week_of_month, - 'day_of_week' => $day_of_week, - 'day_of_month' => $day_of_month, - 'by_day_of_month' => $by_day_of_month, - 'last_day_of_month' => $last_day_of_month, - 'specific_dates' => $serialized_custom_times - ); - if ( $debug ) { - echo '
$recur_data: ' . print_r($recur_data, true) . '
'; - } - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'recurrences', - $recur_data, - array( - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%d', - '%s' - ) - ); - $recurr_id = $this->wpdb->insert_id; - $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true ); - // location for the registration - $has_location = ( $registration_data['address'] || $registration_data['venue'] ); - $location_data = $location_format = array(); - if ( $has_location ) { - $location_data['registration'] = $registration_id; - $location_format[] = '%d'; - if ($registration_data['venue']) { - $location_data['name'] = $registration_data['venue']; - $location_format[] = '%s'; - } - if ($registration_data['address']) { - // test the address to see if there's commas - if ( strpos( $registration_data['address'], ',' ) === false) { - $location_data['address'] = $registration_data['address']; - } else { - $location_data['address'] = substr( $registration_data['address'], 0, strpos( $registration_data['address'], ',' ) ); - } - $location_format[] = '%s'; - } - if ($registration_data['city']) { - $location_data['city'] = $this->getCityId( $registration_data['city'] ); - $location_format[] = '%s'; - } - if ($registration_data['province']) { - // need to lookup the state abbreviation - $state_abbr = array_search( $registration_data['province'], $this->config['states'] ); - if ( $state_abbr !== false ) { - $location_data['state'] = $state_abbr; - $location_format[] = '%s'; - } - } - if ($registration_data['postal_code']) { - $location_data['zip'] = $registration_data['postal_code']; - $location_format[] = '%s'; - } - if ($registration_data['latitude']) { - $location_data['lat'] = $registration_data['latitude']; - $location_format[] = '%s'; - } - if ($registration_data['longitude']) { - $location_data['lon'] = $registration_data['longitude']; - $location_format[] = '%s'; - } - $this->wpdb->insert( - GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'locations', - $location_data, - $location_format - ); - $location_id = $this->wpdb->insert_id; - if ( !$location_id ) { - if ( $debug ) { - echo '
$location_data: ' . print_r($location_data, true) . '
'; - } - die('no return id for location'); - } - } - if ( $debug ) { - echo '
'; - } - } - $return_string .= "

Adding $registration_counter Registrations

"; - } - echo $this->config['states']; - $return_string .= "
-            Start: $start
-        
"; - $start += $limit; - $return_string .= "

Next

"; - return $return_string; - } -} - -?> diff --git a/models/admin/management/registrations.php b/models/admin/management/registrations.php new file mode 100644 index 0000000..a0c27c3 --- /dev/null +++ b/models/admin/management/registrations.php @@ -0,0 +1,201 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release registrations.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Registrations data abstract +require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; + +/** + * GlmMembersAdmin_management_registrations + * + * PHP version 5 + * + * @category Model + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmMembersAdmin_management_registrations extends GlmDataRegistrationsManagement +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * dbh Postgres database connection + * + * @var mixed + * @access public + */ + public $dbh; + /** + * settings used for the schema and tablenames + * + * @var mixed + * @access public + */ + public $settings = array(); + /** + * categories + * + * @var bool + * @access public + */ + public $categories = array(); + public $oldCatMap = array(); + /** + * registrations + * + * @var bool + * @access public + */ + public $registrations = array(); + public $image_owner; + + /** + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * '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. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + /** + * modelAction + * + * @param bool $actionData + * @access public + * @return void + */ + public function modelAction($actionData = false) + { + + $option = false; + $test_result = false; + $import_result = false; + $settings_updated = false; + $settings_update_error = false; + $registration_settings = false; + $icalFeedResult = false; + $import_feeds = false; + $option2 = false; + + if (isset($_REQUEST['option'])) { + $option = $_REQUEST['option']; + } + + // Compile template data + $template_data = array( + 'option' => $option, + 'testval' => 'abc' + ); + + echo "
" . print_r("I get here") . "
"; + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/registrations.html', + 'data' => $template_data + ); + + + } + + /** + * connectPostgresDb + * + * Make a connection to the given database for the site. (postgres) + * Sets the $this->dbh with the postgers database connection + * + * @param mixed $db_host + * @param mixed $db_name + * @param mixed $db_user + * @param mixed $db_password + * @access public + * @return void + */ + public function connectPostgresDb($db_host, $db_name, $db_user, $db_password) + { + $conn_str = "pgsql:"; + if ( $db_host ) { + $conn_part[] = "host={$db_host}"; + } + if ( $db_name ) { + $conn_part[] = "dbname={$db_name}"; + } + if ( $db_user ) { + $conn_part[] = "user={$db_user}"; + } + if ( $db_password ) { + $conn_part[] = "password={$db_password}"; + } + if ( !empty($conn_part) ) { + $conn_str .= implode( " ", $conn_part ); + } + $driver_options = array( + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH, + ); + try { + $this->dbh = new PDO($conn_str, null, null, $driver_options); + $this->dbh->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION + ); + } catch(PDOException $e) { + echo '
$e: ' . print_r($e, true) . '
'; + wp_die(); + } + } +} + +?> diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 64ba81f..dd5ba74 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -12,7 +12,7 @@ * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ * @link http://dev.gaslightmedia.com/ */ - +if (current_user_can('glm_members_members')) { if (apply_filters('glm_members_permit_admin_members_registrations_tab', true)) { add_filter('glm-member-db-add-tab-for-management', function($addOnTabs) { @@ -20,11 +20,14 @@ array( 'text' => 'Registrations', 'menu' => 'management', - 'action' => 'general' + 'action' => 'registrations' ) ); $addOnTabs = array_merge($addOnTabs, $newTabs); return $addOnTabs; } ); - } \ No newline at end of file + + } + +} \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php index f55d4ff..0525d8e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -64,7 +64,7 @@ $glmMembersRegistrationsAddOnValidActions = array( 'list' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, ), 'management' => array( - 'general' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG + 'registrations' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG ), ), 'frontActions' => array( diff --git a/views/admin/management/general.html b/views/admin/management/general.html deleted file mode 100644 index 73e52a0..0000000 --- a/views/admin/management/general.html +++ /dev/null @@ -1,368 +0,0 @@ -{include file='admin/management/header.html'} - - - - - - - - - - - - -
- {if $settingsUpdated}

Settings Updated

{/if} - {if $settingsUpdateError}Settings Update Error{/if} -

Management Settings

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event Detail Page Permalink Name: - - {if $registrationsSettings.fieldFail.canonical_registration_page}

{$registrationsSettings.fieldFail.canonical_registration_page}

{/if} -
Logo for Event PDF: - {if $registrationsSettings.fieldData.pdf_logo} -
- Delete PDF Logo

- {$registrationsSettings.fieldData.pdf_logo}
- {/if} - -
Use 800 x 114 px For the PDF logo size
- {if $registrationsSettings.fieldFail.pdf_logo}

{$registrationsSettings.fieldFail.pdf_logo}

{/if} -
Footer text for PDF (no html, or the PDF will break) - - {if $registrationsSettings.fieldFail.footer_text}

{$registrationsSettings.fieldFail.footer_text}

{/if} -
Default State for Events:
(will use plugin default '{$settings.default_state}' for registrations if unset)
- -
Front-End Calendar View - -
-
- -
-
- Activate Event Amenities

-
Event Amenities Terms: - - - - - - - - - -
Amenities Singular: - - {if $registrationsSettings.fieldFail.term_registration_amenities_singular}

{$registrationsSettings.fieldFail.term_registration_amenities_singular}

{/if} -
Amenities Plural: - - {if $registrationsSettings.fieldFail.term_registration_amenities_plural}

{$registrationsSettings.fieldFail.term_registration_amenities_plural}

{/if} -
-
Event Venue Locations. - Activate Member/Venue Locations

-
-
- -
-
-
- -
-
-

E-Mail Notification Settings

-
Sender Email Address
Recipient Email Address (comma separated)
Email Notification - -
- -
-
- - - - - {if $icalFeedResult} - - - - {/if} - - - - - - -
- {$icalFeedResult} -
-
- - - -
- - -
-
- - - - - - - - - - - - {if $import_feeds} - {foreach $import_feeds as $key => $feed} - - - - - - - - - - - {/foreach} - {/if} -
 Feed UrlCreated DateUpdated DateNext RunEventsDuration 
- Refresh - {$feed.feed_url}{$feed.created}{$feed.updated}{$feed.next_runtime|date_format:"%F %T"}{$feed.registrations}{if $feed.duration} - {*************************************************************************************** - Calculate the duration time in hour:min:sec - hour = time / 3600 - min = (time / 60) % 60 - sec = time % 60 - The smarty way of doing things! - ****************************************************************************************} - {math assign="t_hours" equation="t_time / 3600" t_time=$feed.duration format="%d"} - {math assign="t_minutes" equation="(t_time / 60) % 60" t_time=$feed.duration format="%d"} - {math assign="t_seconds" equation="t_time % 60" t_time=$feed.duration format="%d"} - - {$t_hours}:{$t_minutes}:{$t_seconds} - {/if}Delete
-
- - - - - - {if $importResult} - - - - - {else} - - - - - - - - - - {/if} - -
Redo Times
Return to Import Events
- {$importResult} -

Import from Gaslight Events

-
- - - - -
-
- Database to import from: - - - - - - - - -
-
-
-
- Settings: - - - - - - - - -
- - -
-
-
-
- - - -
-
- Image Style Owner: - - -
- -
-
-
- - {if $importResult} - - - - - {else} - - - - - - - {/if} - - - diff --git a/views/admin/management/registrations.html b/views/admin/management/registrations.html new file mode 100644 index 0000000..69160d2 --- /dev/null +++ b/views/admin/management/registrations.html @@ -0,0 +1,3 @@ +{include file='admin/management/header.html'} + +This is my story
Return to Time.ly Import
- {$importResult} -

Import Time.ly Events

-
- - - - -
- -
-
-