*
* @category glmWordPressPlugin
* @package glmMembersDatabase
- * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @author Chuck Scott <cscott@gaslightmedia.com>
* @license http://www.gaslightmedia.com Gaslightmedia
* @release events.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
- * @link http://dev.gaslightmedia.com/
+ * @link http://dev.gaslightmedia.com/
*/
// Load Management Events data abstract
*
* @category Model
* @package GLM Member DB
- * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @author Chuck Scott <cscott@gaslightmedia.com>
* @license http://www.gaslightmedia.com Gaslightmedia
- * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
- * Exp $
+ * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
*/
class GlmMembersAdmin_management_events extends GlmDataEventsManagement
{
- /**
- * 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();
- /**
- * events
- *
- * @var bool
- * @access public
- */
- public $events = 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 importEventImages()
- {
- require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
- $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
- // get all events with images
- $sql = "
- SELECT id,image,old_event_id
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
- WHERE image != '' AND image IS NOT NULL";
- $results = $this->wpdb->get_results($sql, ARRAY_A);
- $out = '<pre>$results: ' . print_r($results, true) . '</pre>';
- $imgUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/';
- foreach ( $results as $event ) {
- $imageFullUrl = $imgUrl . $event['image'];
- $res = $ImageUpload->storeImage($imageFullUrl);
-
- if ( $res['newFileName'] ) {
- $this->wpdb->update(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
- array(
- 'image' => $res['newFileName']
- ),
- array( 'id' => $event['id'] ),
- array( '%s' ),
- array( '%d' )
- );
- }
- }
- return $out;
- }
-
- public function importEventFiles()
- {
- // get all events with images
- $sql = "
- SELECT id,file1,file2_descr,old_event_id
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
- 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 = '<pre>$results: ' . print_r($results, true) . '</pre>';
- //exit;
- foreach ( $results as $event ) {
- $fileFullUrl = $fileUrl . $event['image'];
- $fp = fopen( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $event['file1'], 'w+' );
- $ch = curl_init( $fileUrl . $event['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 . '/' . $event['file1'], 0660 );
- umask($oldUmask);
- }
- return $out;
- }
-
- /**
- * modelAction
- *
- * @param bool $actionData
- * @access public
- * @return void
- */
- public function modelAction($actionData = false)
- {
-
- $option = false;
- $testResult = false;
- $importResult = false;
- $settingsUpdated = false;
- $settingsUpdateError = false;
- $eventsSettings = false;
-
- if (isset($_REQUEST['option'])) {
- $option = $_REQUEST['option'];
- }
-
- switch ($option) {
-
- case 'tests':
-
- $test = false;
- if (isset($_REQUEST['test'])) {
- $test = $_REQUEST['test'];
- }
-
- switch ($test) {
-
- case 'recurrence':
-
- $testResult = $this->testRecurrence();
-
- break;
-
- default:
- break;
- }
-
- break;
-
- case 'eventImagesImport':
-
- $this->image_owner = filter_var($_REQUEST['img_owner_id'], FILTER_SANITIZE_STRING);
-
- if ( $this->image_owner ) {
- $this->importEventImages();
- $this->importEventFiles();
- $importResult = '<p>All images and files imported</p>';
- } else {
- $importResult = '<pre>Failure: Not given owner id.</pre>';
- }
-
-
- break;
-
- case 'eventFilesImport':
-
-
- break;
-
- case 'eventimport':
-
- $import = false;
- if (isset($_REQUEST['import'])) {
- $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
- }
- switch ($import) {
- case 'true':
- $importResult = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
- $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}%'
- )
- )
-
- )
- );
- $importResult .= '<pre>$this->settings: ' . print_r($this->settings, true) . '</pre>';
- $this->addCategories();
- $importResult .= $this->addEvents();
-
- $importResult .= '<pre>$this->categories: ' . print_r($this->categories, true) . '</pre>';
-
-
- break;
- default:
- break;
- }
- 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 event management settings
- $eventsSettings = $this->updateEntry(1);
- if ($eventsSettings['status']) {
- $settingsUpdated = true;
- } else {
- $settingsUpdateError = 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.
- $eventsSettings = $this->editEntry(1);
-
- if ($eventsSettings === false) {
-
- if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
- glmMembersAdmin::addNotice("<b> /models/admin/management/events.php: Unable to load events management settings.", 'Alert');
- }
-
- }
-
- break;
-
- }
-
- break;
-
- }
-
- // Compile template data
- $templateData = array(
- 'option' => $option,
- 'testResult' => $testResult,
- 'importResult' => $importResult,
- 'settingsUpdated' => $settingsUpdated,
- 'settingsUpdateError' => $settingsUpdateError,
- 'eventsSettings' => $eventsSettings
- );
-
- // Return status, suggested view, and data to controller
- return array(
- 'status' => true,
- 'menuItemRedirect' => false,
- 'modelRedirect' => false,
- 'view' => 'admin/management/events.html',
- 'data' => $templateData
- );
-
-
- }
-
- /**
- * 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)
- {
- $connStr = "pgsql:";
- if ( $db_host ) {
- $connPart[] = "host={$db_host}";
- }
- if ( $db_name ) {
- $connPart[] = "dbname={$db_name}";
- }
- if ( $db_user ) {
- $connPart[] = "user={$db_user}";
- }
- if ( $db_password ) {
- $connPart[] = "password={$db_password}";
- }
- if ( !empty($connPart) ) {
- $connStr .= implode( " ", $connPart );
- }
- $driverOptions = array(
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH,
- );
- try {
- $this->dbh = new PDO($connStr, null, null, $driverOptions);
- $this->dbh->setAttribute(
- PDO::ATTR_ERRMODE,
- PDO::ERRMODE_EXCEPTION
- );
- } catch(PDOException $e) {
- echo '<pre>$e: ' . print_r($e, true) . '</pre>';
- wp_die();
- }
- }
-
- /**
- * Test Recurrance Calculation of Dates
- *
- * @return test Text of test results
- */
- public function testRecurrence()
- {
-
- $res = '';
-
- // Load recurrences class
- require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php';
- $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
-
- // Create sample recurrence entry
- $start_time = '2016/2/27 08:00:00';
- $res .= "First event start date/time: $start_time<br>";
- $end_time = '2016/2/28 17:00:00';
- $res .= "First event end date/time: $end_time<br>";
- $from_date = '2016/2/1';
- $res .= "From date: $from_date<br>";
- $to_date = '2017/3/31';
- $res .= "To date: $to_date<br>";
-
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
- array(
- 'event' => 999999999,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'from_date' => $from_date,
- 'to_date' => $to_date,
- 'all_day' => false,
- 'month_of_year' =>
- pow(2, $this->config['month_bit']['January']) +
- pow(2, $this->config['month_bit']['June']),
- 'week_of_month' =>
- pow(2, $this->config['week_bit']['Third']) +
- pow(2, $this->config['week_bit']['First']),
- 'day_of_week' =>
- pow(2, $this->config['day_bit']['Wednesday']) +
- pow(2, $this->config['day_bit']['Friday']),
- 'day_of_month' =>
- pow(2, 1) + pow(2, 13) + pow(2, 26) + pow(2, 30),
- 'last_day_of_month' => true,
- 'holiday' => 0,
- 'holiday_offset' => 0
- ),
- array(
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d'
- )
- );
- $recurID = $this->wpdb->insert_id;
- if (!$recurID) {
- return 'Error inserting recurrence entry!';
- }
-
- // Run recurrence time function
- $Recurrences->optionIncludeSelectListData = false;
- $times = $Recurrences->createRecurrenceTimesEntries($recurID, true, true);
-
- // Delete test recurrence
- $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', array( 'ID' => $recurID ) );
- $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', array( 'recur_id' => $recurID ) );
-
- $res .= "<h3>Times Entries Generated</h3><pre>".print_r($times,1)."</pre>";
-
- return $res;
-
- }
-
- /**
- * addCategories
- *
- * Checks to see if there's an Event 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()
- {
- $return = '';
- $sql = "
- SELECT *
- FROM {$this->settings['schema']}.{$this->settings['cattablename']}
- ORDER BY id";
- $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
- try {
- $categories = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
- $return .= '<pre>$categories: ' . print_r($categories, true) . '</pre>';
- foreach ( $categories as $category ) {
- // first check to see if the category is already there
- $sql = "
- SELECT id
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories
- WHERE name = '" . esc_sql( trim($category['name']) ) . "'";
- $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
- $found = $this->wpdb->get_row($sql, ARRAY_A);
- $return .= '<pre>$found: ' . print_r($found, true) . '</pre>';
- if ( !isset($found) ) {
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'categories',
- array(
- 'name' => trim($category['name']),
- 'parent' => 0
- ),
- array(
- '%s',
- '%d'
- )
- );
- $catid = $this->wpdb->insert_id;
- $this->categories[$catid] = trim($category['name']);
- $this->oldCatMap[$category['id']] = $catid;
- } else {
- $this->categories[$found['id']] = trim($category['name']);
- $this->oldCatMap[$category['id']] = $found['id'];
- }
- }
- } catch(PDOException $e) {
- echo '<pre>$e: ' . print_r($e, true) . '</pre>';
- die('end here');
- }
- return $return;
- }
-
- /**
- * 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)
- {
+ /**
+ * 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();
+ /**
+ * events
+ *
+ * @var bool
+ * @access public
+ */
+ public $events = 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 importEventImages()
+ {
+ require_once(GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php');
+ $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+ // get all events with images
+ $sql = "
+ SELECT id,image,old_event_id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
+ WHERE image != '' AND image IS NOT NULL";
+ $results = $this->wpdb->get_results($sql, ARRAY_A);
+ $out = '<pre>$results: ' . print_r($results, true) . '</pre>';
+ $imgUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/';
+ foreach ( $results as $event ) {
+ $imageFullUrl = $imgUrl . $event['image'];
+ $res = $ImageUpload->storeImage($imageFullUrl);
+
+ if ( $res['newFileName'] ) {
+ $this->wpdb->update(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+ array(
+ 'image' => $res['newFileName']
+ ),
+ array( 'id' => $event['id'] ),
+ array( '%s' ),
+ array( '%d' )
+ );
+ }
+ }
+ return $out;
+ }
+
+ public function importEventFiles()
+ {
+ // get all events with images
+ $sql = "
+ SELECT id,file1,file2_descr,old_event_id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
+ 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 = '<pre>$results: ' . print_r($results, true) . '</pre>';
+ //exit;
+ foreach ( $results as $event ) {
+ $fileFullUrl = $fileUrl . $event['image'];
+ $fp = fopen( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $event['file1'], 'w+' );
+ $ch = curl_init( $fileUrl . $event['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 . '/' . $event['file1'], 0660 );
+ umask($oldUmask);
+ }
+ return $out;
+ }
+
+ /**
+ * modelAction
+ *
+ * @param bool $actionData
+ * @access public
+ * @return void
+ */
+ public function modelAction($actionData = false)
+ {
+
+ $option = false;
+ $testResult = false;
+ $importResult = false;
+ $settingsUpdated = false;
+ $settingsUpdateError = false;
+ $eventsSettings = false;
+
+ if (isset($_REQUEST['option'])) {
+ $option = $_REQUEST['option'];
+ }
+
+ switch ($option) {
+ case 'timelyImport':
+ $import = false;
+ if (isset($_REQUEST['import'])) {
+ $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
+ }
+ $importResult = $this->importFromTimely();
+ break;
+
+ case 'tests':
+
+ $test = false;
+ if (isset($_REQUEST['test'])) {
+ $test = $_REQUEST['test'];
+ }
+
+ switch ($test) {
+
+ case 'recurrence':
+
+ $testResult = $this->testRecurrence();
+
+ break;
+
+ default:
+ break;
+ }
+
+ break;
+
+ case 'eventImagesImport':
+
+ $this->image_owner = filter_var($_REQUEST['img_owner_id'], FILTER_SANITIZE_STRING);
+
+ if ( $this->image_owner ) {
+ $this->importEventImages();
+ $this->importEventFiles();
+ $importResult = '<p>All images and files imported</p>';
+ } else {
+ $importResult = '<pre>Failure: Not given owner id.</pre>';
+ }
+
+
+ break;
+
+ case 'eventFilesImport':
+
+
+ break;
+
+ case 'eventimport':
+
+ $import = false;
+ if (isset($_REQUEST['import'])) {
+ $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
+ }
+ switch ($import) {
+ case 'true':
+ $importResult = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $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}%'
+ )
+ )
+
+ )
+ );
+ $importResult .= '<pre>$this->settings: ' . print_r($this->settings, true) . '</pre>';
+ $this->addCategories();
+ $importResult .= $this->addEvents();
+
+ $importResult .= '<pre>$this->categories: ' . print_r($this->categories, true) . '</pre>';
+
+
+ break;
+ default:
+ break;
+ }
+ 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 event management settings
+ $eventsSettings = $this->updateEntry(1);
+ if ($eventsSettings['status']) {
+ $settingsUpdated = true;
+ } else {
+ $settingsUpdateError = 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.
+ $eventsSettings = $this->editEntry(1);
+
+ if ($eventsSettings === false) {
+
+ if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+ glmMembersAdmin::addNotice("<b> /models/admin/management/events.php: Unable to load events management settings.", 'Alert');
+ }
+
+ }
+
+ break;
+
+ }
+
+ break;
+
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'option' => $option,
+ 'testResult' => $testResult,
+ 'importResult' => $importResult,
+ 'settingsUpdated' => $settingsUpdated,
+ 'settingsUpdateError' => $settingsUpdateError,
+ 'eventsSettings' => $eventsSettings
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/management/events.html',
+ 'data' => $templateData
+ );
+
+
+ }
+
+ /**
+ * 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)
+ {
+ $connStr = "pgsql:";
+ if ( $db_host ) {
+ $connPart[] = "host={$db_host}";
+ }
+ if ( $db_name ) {
+ $connPart[] = "dbname={$db_name}";
+ }
+ if ( $db_user ) {
+ $connPart[] = "user={$db_user}";
+ }
+ if ( $db_password ) {
+ $connPart[] = "password={$db_password}";
+ }
+ if ( !empty($connPart) ) {
+ $connStr .= implode( " ", $connPart );
+ }
+ $driverOptions = array(
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH,
+ );
+ try {
+ $this->dbh = new PDO($connStr, null, null, $driverOptions);
+ $this->dbh->setAttribute(
+ PDO::ATTR_ERRMODE,
+ PDO::ERRMODE_EXCEPTION
+ );
+ } catch(PDOException $e) {
+ echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+ wp_die();
+ }
+ }
+
+ /**
+ * Test Recurrance Calculation of Dates
+ *
+ * @return test Text of test results
+ */
+ public function testRecurrence()
+ {
+
+ $res = '';
+
+ // Load recurrences class
+ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php';
+ $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+
+ // Create sample recurrence entry
+ $start_time = '2016/2/27 08:00:00';
+ $res .= "First event start date/time: $start_time<br>";
+ $end_time = '2016/2/28 17:00:00';
+ $res .= "First event end date/time: $end_time<br>";
+ $from_date = '2016/2/1';
+ $res .= "From date: $from_date<br>";
+ $to_date = '2017/3/31';
+ $res .= "To date: $to_date<br>";
+
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+ array(
+ 'event' => 999999999,
+ 'start_time' => $start_time,
+ 'end_time' => $end_time,
+ 'from_date' => $from_date,
+ 'to_date' => $to_date,
+ 'all_day' => false,
+ 'month_of_year' =>
+ pow(2, $this->config['month_bit']['January']) +
+ pow(2, $this->config['month_bit']['June']),
+ 'week_of_month' =>
+ pow(2, $this->config['week_bit']['Third']) +
+ pow(2, $this->config['week_bit']['First']),
+ 'day_of_week' =>
+ pow(2, $this->config['day_bit']['Wednesday']) +
+ pow(2, $this->config['day_bit']['Friday']),
+ 'day_of_month' =>
+ pow(2, 1) + pow(2, 13) + pow(2, 26) + pow(2, 30),
+ 'last_day_of_month' => true,
+ 'holiday' => 0,
+ 'holiday_offset' => 0
+ ),
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d'
+ )
+ );
+ $recurID = $this->wpdb->insert_id;
+ if (!$recurID) {
+ return 'Error inserting recurrence entry!';
+ }
+
+ // Run recurrence time function
+ $Recurrences->optionIncludeSelectListData = false;
+ $times = $Recurrences->createRecurrenceTimesEntries($recurID, true, true);
+
+ // Delete test recurrence
+ $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences', array( 'ID' => $recurID ) );
+ $this->wpdb->delete( GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'times', array( 'recur_id' => $recurID ) );
+
+ $res .= "<h3>Times Entries Generated</h3><pre>".print_r($times,1)."</pre>";
+
+ return $res;
+
+ }
+
+ /**
+ * addCategories
+ *
+ * Checks to see if there's an Event 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()
+ {
+ $return = '';
+ $sql = "
+ SELECT *
+ FROM {$this->settings['schema']}.{$this->settings['cattablename']}
+ ORDER BY id";
+ $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+ try {
+ $categories = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+ $return .= '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+ foreach ( $categories as $category ) {
+ // first check to see if the category is already there
+ $sql = "
+ SELECT id
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "categories
+ WHERE name = '" . esc_sql( trim($category['name']) ) . "'";
+ $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+ $found = $this->wpdb->get_row($sql, ARRAY_A);
+ $return .= '<pre>$found: ' . print_r($found, true) . '</pre>';
+ if ( !isset($found) ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'categories',
+ array(
+ 'name' => trim($category['name']),
+ 'parent' => 0
+ ),
+ array(
+ '%s',
+ '%d'
+ )
+ );
+ $catid = $this->wpdb->insert_id;
+ $this->categories[$catid] = trim($category['name']);
+ $this->oldCatMap[$category['id']] = $catid;
+ } else {
+ $this->categories[$found['id']] = trim($category['name']);
+ $this->oldCatMap[$category['id']] = $found['id'];
+ }
+ }
+ } catch(PDOException $e) {
+ echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+ die('end here');
+ }
+ return $return;
+ }
+
+ /**
+ * 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 '<pre>$time: ' . print_r($time, true) . '</pre>';
- if (!$time) {
- return false;
- }
- if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $timeParts)) {
- //die('not found');
- return false;
- }
+ if (!$time) {
+ return false;
+ }
+ if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $timeParts)) {
+ //die('not found');
+ return false;
+ }
echo '<pre>$timeParts: ' . print_r($timeParts, true) . '</pre>';
- //$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 = (!$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 = $timeParts[1];
- // parse the hour from event
- $dateTime = new DateTime();
- $dateTime->setTime($hour, (int)$timeParts[2] );
+ // parse the hour from event
+ $dateTime = new DateTime();
+ $dateTime->setTime($hour, (int)$timeParts[2] );
echo '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
- 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 $cityName Name of the city
- *
- * @access public
- * @return id of city
- */
- public function getCityId($cityName)
- {
- $sql = "
- SELECT id
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
- WHERE name like '" . esc_sql( trim( $cityName ) ) . "'";
- $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( $cityName ) ),
- array( '%s' )
- );
- return $this->wpdb->insert_id;
- } else {
- return $cityId['id'];
- }
- }
-
- /**
- * addEvents
- *
- * Start with a clean set of event tables. ( delete all event data )
- * Grab all events starting with the given start date.
- * Enter them into the new event plugin tables.
- *
- * @access public
- * @return void
- */
- public function addEvents()
- {
- // clear the events tables first
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
- $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
- $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
- $return = '';
- $oldEventFormat = ($this->settings['tablename'] == 'event');
- if ( $oldEventFormat ) {
- $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";
- $prepareSql = "
- SELECT filename,urltext
- FROM {$this->settings['schema']}.files
- WHERE event = :eid";
- $getFileData = $this->dbh->prepare($prepareSql);
- }
- //$sql .=" AND file != '' ";
+ 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 $cityName Name of the city
+ *
+ * @access public
+ * @return id of city
+ */
+ public function getCityId($cityName)
+ {
+ $sql = "
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+ WHERE name like '" . esc_sql( trim( $cityName ) ) . "'";
+ $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( $cityName ) ),
+ array( '%s' )
+ );
+ return $this->wpdb->insert_id;
+ } else {
+ return $cityId['id'];
+ }
+ }
+
+ /**
+ * addEvents
+ *
+ * Start with a clean set of event tables. ( delete all event data )
+ * Grab all events starting with the given start date.
+ * Enter them into the new event plugin tables.
+ *
+ * @access public
+ * @return void
+ */
+ public function addEvents()
+ {
+ // clear the events tables first
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" );
+ $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+ $return = '';
+ $oldEventFormat = ($this->settings['tablename'] == 'event');
+ if ( $oldEventFormat ) {
+ $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";
+ $prepareSql = "
+ SELECT filename,urltext
+ FROM {$this->settings['schema']}.files
+ WHERE event = :eid";
+ $getFileData = $this->dbh->prepare($prepareSql);
+ }
+ //$sql .=" AND file != '' ";
//$sql .= " AND id = 5";
- $this->wpdb->show_errors();
- echo '<pre>$sql: ' . print_r($sql, true) . '</pre>';
- try {
- $events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
- $return .= '<pre>$events: ' . print_r($events, true) . '</pre>';
- foreach ( $events as $event ) {
- $foundMemberId = $refType = null;
- $memberId = (isset($event['member_id'])) ? $event['member_id'] : $event['member'];
- if ( $memberId ) {
- // get the new member id
- $sql = "
- SELECT id
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
- WHERE old_member_id = " . esc_sql( trim($memberId) );
- $foundMemberId = $this->wpdb->get_row($sql, ARRAY_A);
- if ( $foundMemberId ) {
- $foundMemberId = $foundMemberId['id'];
- $refType = $this->config['ref_type_numb']['Member'];
- }
- }
- if ( $oldEventFormat ) {
- $intro = substr(strip_tags($event['descr']), 0, 250);
- $eventData = array(
- 'status' => (($event['visable'] == '1')
- ? $this->config['status_numb']['Active']
- : $this->config['status_numb']['Inactive']),
- 'created' => $event['create_date'],
- 'updated' => $event['create_date'],
- 'approved' => $event['approved_date'],
- 'name' => $event['header'],
- 'intro' => $intro,
- 'descr' => $event['descr'],
- 'image' => $event['img'],
- 'file1' => $event['file'],
- 'file1_descr' => $event['filename'],
- 'cost' => $event['cost'],
- 'url' => $event['url'],
- 'old_event_id' => $event['id'],
- 'ref_type' => $refType,
- 'ref_dest' => $foundMemberId,
- 'admin_name' => $event['admin_contact_name'],
- 'admin_org' => $event['admin_org_name'],
- 'admin_email' => $event['admin_email'],
- 'admin_phone' => $event['admin_phone'],
- 'contact_email' => $event['email'],
- 'contact_name' => $event['contact'],
- 'contact_phone' => $event['phone'],
- 'notes' => $event['notes'],
- 'hide_address' => $event['hide_address'],
- );
- $eventDataFormat = 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 {
- $getFileData->bindParam(':eid', $event['id'], PDO::PARAM_INT);
- $getFileData->execute();
- $file = $filename = '';
- $fileData = $getFileData->fetch(PDO::FETCH_ASSOC);
- if ($fileData ) {
- $file = $fileData['filename'];
- $filename = $fileData['urltext'];
- }
- $intro = ($event['intro'])
- ? substr(strip_tags($event['intro']), 0, 250)
- : substr(strip_tags($event['description']), 0, 250);
- $eventData = array(
- 'status' => (($event['active'] == '1')
- ? $this->config['status_numb']['Active']
- : $this->config['status_numb']['Inactive']),
- 'created' => $event['created'],
- 'updated' => $event['updated'],
- 'approved' => $event['approved'],
- 'name' => $event['header'],
- 'intro' => $intro,
- 'descr' => $event['description'],
- 'image' => $event['image'],
- 'file1' => $file,
- 'file1_descr' => $filename,
- 'cost' => $event['cost'],
- 'url' => $event['website'],
- 'old_event_id' => $event['id'],
- 'ref_type' => $refType,
- 'ref_dest' => $foundMemberId,
- 'admin_name' => $event['admin_contact'],
- 'admin_org' => $event['admin_org'],
- 'admin_email' => $event['admin_email'],
- 'admin_phone' => $event['admin_phone'],
- 'contact_email' => $event['contact_email'],
- 'contact_name' => $event['contact_name'],
- 'contact_phone' => $event['contact_phone'],
- 'notes' => $event['notes'],
- 'hide_address' => $event['hide_address'],
- 'use_member_location' => $event['use_memberloc']
- );
- $eventDataFormat = 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 '<pre>$eventData: ' . print_r($eventData, true) . '</pre>';
- echo '</pre>';
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
- $eventData,
- $eventDataFormat
- );
- $eventId = $this->wpdb->insert_id;
- var_dump( $eventId );
- echo '<pre>$eventId: from insert ' . print_r($eventId, true) . '</pre>';
- if ( !$eventId ) {
- echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
- echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
- }
- // checking for $eventId
- //echo '<pre>$eventId: ' . print_r($eventId, true) . '</pre>';
- if (!$eventId) {
- die('something is wrong no eventId');
- }
- // generate the slug name for this new event
- $eventAbstract = new GlmDataEvents($this->wpdb, $this->config);
- $eventAbstract->updateSlug($eventId);
- // category for event
- if ( $event['topicid'] ) {
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
- array(
- 'event' => $eventId,
- 'category' => $this->oldCatMap[$event['topicid']]
- ),
- array(
- '%d',
- '%d'
- )
- );
- }
- if ( $event['category'] ) {
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
- array(
- 'event' => $eventId,
- 'category' => $this->oldCatMap[$event['category']]
- ),
- array(
- '%d',
- '%d'
- )
- );
- }
- // recurrences for the event
- if (isset($event['reacur'])) {
- $recurringEvent = $event['reacur'];
- if ( $recurringEvent && ( $event['bdate'] == $event['edate'] ) ) {
- $recurringEvent = 0;
- }
- } else {
- $recurringEvent = $event['recurr'];
- if ( $recurringEvent && ( $event['starting'] == $event['ending'] ) ) {
- $recurringEvent = 0;
- }
- }
- $dayOfWeek =
- $monthOfYear =
- $weekOfMonth =
- $byDayOfMonth =
- $lastDayOfMonth = null;
- if ( $recurringEvent ) {
- if ( $event['daysow'] ) {
- $dayOfWeek = $event['daysow'];
- } else {
- $dayOfWeek = 127;
- }
- if ( $event['weekom'] ) {
- switch ($event['weekom']) {
- case '1':
- $weekOfMonth = 1;
- break;
- case '2':
- $weekOfMonth = 2;
- break;
- case '3':
- $weekOfMonth = 4;
- break;
- case '4':
- $weekOfMonth = 8;
- break;
- case '5':
- $weekOfMonth = 16;
- break;
- }
- } else {
- $weekOfMonth = 63;
- }
- $monthOfYear = 4095;
- }
- if ( isset($event['btime']) ) {
- $btime = $this->getTime($event['btime']);
- $etime = $this->getTime($event['etime']);
- } else {
- $btime = $this->getTime($event['starthour']);
- $etime = $this->getTime($event['endhour']);
- }
- $startTimeOnly = ($btime && !$etime);
- if ( $startTimeOnly ) {
- $etime = $btime;
- }
- if ( isset($event['all_day']) ) {
- $allDay = ( $event['all_day'] || !$btime );
- } else {
- $allDay = ( $event['allday'] || !$btime );
- }
- if (isset($event['bdate'])) {
- $fromDate = $event['bdate'];
- $toDate = $event['edate'];
- } else {
- $fromDate = $event['starting'];
- $toDate = $event['ending'];
- }
- $recurData =array(
- 'event' => $eventId,
- 'name' => 'Imported Event Schedule',
- 'start_time' => $btime,
- 'end_time' => $etime,
- 'start_time_only' => $startTimeOnly,
- 'from_date' => $fromDate,
- 'to_date' => $toDate,
- 'all_day' => $allDay,
- 'recurring' => $recurringEvent,
- 'month_of_year' => $monthOfYear,
- 'week_of_month' => $weekOfMonth,
- 'day_of_week' => $dayOfWeek,
- 'by_day_of_month' => $byDayOfMonth,
- 'last_day_of_month' => $lastDayOfMonth
- );
- //echo '<pre>' . print_r( $recurData, true) . '</pre>';
- echo '<pre>$recurData: ' . print_r($recurData, true) . '</pre>';
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
- $recurData,
- array(
- '%d',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%s',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- '%d',
- )
- );
- $recurId = $this->wpdb->insert_id;
- $Recurrences->createRecurrenceTimesEntries( $recurId, true, true );
- // location for the event
- $hasLocation = ($event['loc'] || $event['place']);
- if ( $hasLocation ) {
- $locationData = $locationFormat = array();
- $locationData['event'] = $eventId;
- $locationFormat[] = '%d';
- if ($event['place']) {
- $locationData['name'] = $event['place'];
- $locationFormat[] = '%s';
- }
- if ($event['loc']) {
- $locationData['name'] = $event['loc'];
- $locationFormat[] = '%s';
- }
- if ($event['address']) {
- $locationData['address'] = $event['address'];
- $locationFormat[] = '%s';
- }
- if ($event['city']) {
- $locationData['city'] = $this->getCityId( $event['city'] );
- $locationFormat[] = '%s';
- }
- if ($event['state']) {
- $locationData['state'] = $event['state'];
- $locationFormat[] = '%s';
- }
- if ($event['zip']) {
- $locationData['zip'] = $event['zip'];
- $locationFormat[] = '%s';
- }
- if ($event['lat']) {
- $locationData['lat'] = $event['lat'];
- $locationFormat[] = '%s';
- }
- if ($event['lon']) {
- $locationData['lon'] = $event['lon'];
- $locationFormat[] = '%s';
- }
- $this->wpdb->insert(
- GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
- $locationData,
- $locationFormat
- );
- $locationId = $this->wpdb->insert_id;
- if ( !$locationId ) {
- echo '<pre>$locationData: ' . print_r($locationData, true) . '</pre>';
- die('no return id for location');
- }
- }
- }
- } catch(PDOException $e) {
- echo '<pre>$e: ' . print_r($e, true) . '</pre>';
- die('end here');
- }
- return $return;
- }
+ $this->wpdb->show_errors();
+ echo '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+ try {
+ $events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+ $return .= '<pre>$events: ' . print_r($events, true) . '</pre>';
+ foreach ( $events as $event ) {
+ $foundMemberId = $refType = null;
+ $memberId = (isset($event['member_id'])) ? $event['member_id'] : $event['member'];
+ if ( $memberId ) {
+ // get the new member id
+ $sql = "
+ SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = " . esc_sql( trim($memberId) );
+ $foundMemberId = $this->wpdb->get_row($sql, ARRAY_A);
+ if ( $foundMemberId ) {
+ $foundMemberId = $foundMemberId['id'];
+ $refType = $this->config['ref_type_numb']['Member'];
+ }
+ }
+ if ( $oldEventFormat ) {
+ $intro = substr(strip_tags($event['descr']), 0, 250);
+ $eventData = array(
+ 'status' => (($event['visable'] == '1')
+ ? $this->config['status_numb']['Active']
+ : $this->config['status_numb']['Inactive']),
+ 'created' => $event['create_date'],
+ 'updated' => $event['create_date'],
+ 'approved' => $event['approved_date'],
+ 'name' => $event['header'],
+ 'intro' => $intro,
+ 'descr' => $event['descr'],
+ 'image' => $event['img'],
+ 'file1' => $event['file'],
+ 'file1_descr' => $event['filename'],
+ 'cost' => $event['cost'],
+ 'url' => $event['url'],
+ 'old_event_id' => $event['id'],
+ 'ref_type' => $refType,
+ 'ref_dest' => $foundMemberId,
+ 'admin_name' => $event['admin_contact_name'],
+ 'admin_org' => $event['admin_org_name'],
+ 'admin_email' => $event['admin_email'],
+ 'admin_phone' => $event['admin_phone'],
+ 'contact_email' => $event['email'],
+ 'contact_name' => $event['contact'],
+ 'contact_phone' => $event['phone'],
+ 'notes' => $event['notes'],
+ 'hide_address' => $event['hide_address'],
+ );
+ $eventDataFormat = 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 {
+ $getFileData->bindParam(':eid', $event['id'], PDO::PARAM_INT);
+ $getFileData->execute();
+ $file = $filename = '';
+ $fileData = $getFileData->fetch(PDO::FETCH_ASSOC);
+ if ($fileData ) {
+ $file = $fileData['filename'];
+ $filename = $fileData['urltext'];
+ }
+ $intro = ($event['intro'])
+ ? substr(strip_tags($event['intro']), 0, 250)
+ : substr(strip_tags($event['description']), 0, 250);
+ $eventData = array(
+ 'status' => (($event['active'] == '1')
+ ? $this->config['status_numb']['Active']
+ : $this->config['status_numb']['Inactive']),
+ 'created' => $event['created'],
+ 'updated' => $event['updated'],
+ 'approved' => $event['approved'],
+ 'name' => $event['header'],
+ 'intro' => $intro,
+ 'descr' => $event['description'],
+ 'image' => $event['image'],
+ 'file1' => $file,
+ 'file1_descr' => $filename,
+ 'cost' => $event['cost'],
+ 'url' => $event['website'],
+ 'old_event_id' => $event['id'],
+ 'ref_type' => $refType,
+ 'ref_dest' => $foundMemberId,
+ 'admin_name' => $event['admin_contact'],
+ 'admin_org' => $event['admin_org'],
+ 'admin_email' => $event['admin_email'],
+ 'admin_phone' => $event['admin_phone'],
+ 'contact_email' => $event['contact_email'],
+ 'contact_name' => $event['contact_name'],
+ 'contact_phone' => $event['contact_phone'],
+ 'notes' => $event['notes'],
+ 'hide_address' => $event['hide_address'],
+ 'use_member_location' => $event['use_memberloc']
+ );
+ $eventDataFormat = 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 '<pre>$eventData: ' . print_r($eventData, true) . '</pre>';
+ echo '</pre>';
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events',
+ $eventData,
+ $eventDataFormat
+ );
+ $eventId = $this->wpdb->insert_id;
+ var_dump( $eventId );
+ echo '<pre>$eventId: from insert ' . print_r($eventId, true) . '</pre>';
+ if ( !$eventId ) {
+ echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
+ echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
+ }
+ // checking for $eventId
+ //echo '<pre>$eventId: ' . print_r($eventId, true) . '</pre>';
+ if (!$eventId) {
+ die('something is wrong no eventId');
+ }
+ // generate the slug name for this new event
+ $eventAbstract = new GlmDataEvents($this->wpdb, $this->config);
+ $eventAbstract->updateSlug($eventId);
+ // category for event
+ if ( $event['topicid'] ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
+ array(
+ 'event' => $eventId,
+ 'category' => $this->oldCatMap[$event['topicid']]
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+ }
+ if ( $event['category'] ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
+ array(
+ 'event' => $eventId,
+ 'category' => $this->oldCatMap[$event['category']]
+ ),
+ array(
+ '%d',
+ '%d'
+ )
+ );
+ }
+ // recurrences for the event
+ if (isset($event['reacur'])) {
+ $recurringEvent = $event['reacur'];
+ if ( $recurringEvent && ( $event['bdate'] == $event['edate'] ) ) {
+ $recurringEvent = 0;
+ }
+ } else {
+ $recurringEvent = $event['recurr'];
+ if ( $recurringEvent && ( $event['starting'] == $event['ending'] ) ) {
+ $recurringEvent = 0;
+ }
+ }
+ $dayOfWeek =
+ $monthOfYear =
+ $weekOfMonth =
+ $byDayOfMonth =
+ $lastDayOfMonth = null;
+ if ( $recurringEvent ) {
+ if ( $event['daysow'] ) {
+ $dayOfWeek = $event['daysow'];
+ } else {
+ $dayOfWeek = 127;
+ }
+ if ( $event['weekom'] ) {
+ switch ($event['weekom']) {
+ case '1':
+ $weekOfMonth = 1;
+ break;
+ case '2':
+ $weekOfMonth = 2;
+ break;
+ case '3':
+ $weekOfMonth = 4;
+ break;
+ case '4':
+ $weekOfMonth = 8;
+ break;
+ case '5':
+ $weekOfMonth = 16;
+ break;
+ }
+ } else {
+ $weekOfMonth = 63;
+ }
+ $monthOfYear = 4095;
+ }
+ if ( isset($event['btime']) ) {
+ $btime = $this->getTime($event['btime']);
+ $etime = $this->getTime($event['etime']);
+ } else {
+ $btime = $this->getTime($event['starthour']);
+ $etime = $this->getTime($event['endhour']);
+ }
+ $startTimeOnly = ($btime && !$etime);
+ if ( $startTimeOnly ) {
+ $etime = $btime;
+ }
+ if ( isset($event['all_day']) ) {
+ $allDay = ( $event['all_day'] || !$btime );
+ } else {
+ $allDay = ( $event['allday'] || !$btime );
+ }
+ if (isset($event['bdate'])) {
+ $fromDate = $event['bdate'];
+ $toDate = $event['edate'];
+ } else {
+ $fromDate = $event['starting'];
+ $toDate = $event['ending'];
+ }
+ $recurData =array(
+ 'event' => $eventId,
+ 'name' => 'Imported Event Schedule',
+ 'start_time' => $btime,
+ 'end_time' => $etime,
+ 'start_time_only' => $startTimeOnly,
+ 'from_date' => $fromDate,
+ 'to_date' => $toDate,
+ 'all_day' => $allDay,
+ 'recurring' => $recurringEvent,
+ 'month_of_year' => $monthOfYear,
+ 'week_of_month' => $weekOfMonth,
+ 'day_of_week' => $dayOfWeek,
+ 'by_day_of_month' => $byDayOfMonth,
+ 'last_day_of_month' => $lastDayOfMonth
+ );
+ //echo '<pre>' . print_r( $recurData, true) . '</pre>';
+ echo '<pre>$recurData: ' . print_r($recurData, true) . '</pre>';
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+ $recurData,
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ '%d',
+ )
+ );
+ $recurId = $this->wpdb->insert_id;
+ $Recurrences->createRecurrenceTimesEntries( $recurId, true, true );
+ // location for the event
+ $hasLocation = ($event['loc'] || $event['place']);
+ if ( $hasLocation ) {
+ $locationData = $locationFormat = array();
+ $locationData['event'] = $eventId;
+ $locationFormat[] = '%d';
+ if ($event['place']) {
+ $locationData['name'] = $event['place'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['loc']) {
+ $locationData['name'] = $event['loc'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['address']) {
+ $locationData['address'] = $event['address'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['city']) {
+ $locationData['city'] = $this->getCityId( $event['city'] );
+ $locationFormat[] = '%s';
+ }
+ if ($event['state']) {
+ $locationData['state'] = $event['state'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['zip']) {
+ $locationData['zip'] = $event['zip'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['lat']) {
+ $locationData['lat'] = $event['lat'];
+ $locationFormat[] = '%s';
+ }
+ if ($event['lon']) {
+ $locationData['lon'] = $event['lon'];
+ $locationFormat[] = '%s';
+ }
+ $this->wpdb->insert(
+ GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'locations',
+ $locationData,
+ $locationFormat
+ );
+ $locationId = $this->wpdb->insert_id;
+ if ( !$locationId ) {
+ echo '<pre>$locationData: ' . print_r($locationData, true) . '</pre>';
+ die('no return id for location');
+ }
+ }
+ }
+ } catch(PDOException $e) {
+ echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+ die('end here');
+ }
+ return $return;
+ }
+ public function importFromTimely() {
+ $sql = "SELECT * FROM " . $this->wpdb->prefix . "posts WHERE post_type = 'ai1ec_event'";
+ $results = $this->wpdb->get_results( $sql, ARRAY_A );
+ echo '<p>Total events: ' . count( $results ) . '</p>';
+ if ( !empty( $results ) ) {
+ foreach ( $results as $post ) {
+ // use the posts table data
+ 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 '<pre>$thumbnail: ' . print_r($thumb_src, true) . '</pre>';
+ var_dump( $thumb_src[0] );
+ }
+ }
+ }
+ }
}
?>
/**
* GlmMembersFront_events_list
*
- * @uses GlmDataEvents
+ * @uses GlmDataEvents
* @package GlmMemberEvents
* @version 0.0.1
* @copyright Copyright (c) 2010 All rights reserved.
- * @author Steve Sutton <steve@gaslightmedia.com>
+ * @author Steve Sutton <steve@gaslightmedia.com>
* @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
*/
abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
{
- public $wpdb;
- public $config;
+ public $wpdb;
+ public $config;
- /**
- * __construct
- *
- * @param mixed $wpdb The main Word Press DB Object
- * @param mixed $config The main Config
- *
- * @access public
- * @return void
- */
- public function __construct($wpdb, $config)
- {
- $this->wpdb = $wpdb;
- $this->config = $config;
+ /**
+ * __construct
+ *
+ * @param mixed $wpdb The main Word Press DB Object
+ * @param mixed $config The main Config
+ *
+ * @access public
+ * @return void
+ */
+ public function __construct( $wpdb, $config ) {
+ $this->wpdb = $wpdb;
+ $this->config = $config;
- parent::__construct(false, false);
- }
+ parent::__construct( false, false );
+ }
- public function printEvents()
- {
- echo 'hello';
- //include '/var/www/localhost/htdocs/pdfTest/index.php';
- }
+ public function printEvents() {
+ echo 'hello';
+ //include '/var/www/localhost/htdocs/pdfTest/index.php';
+ }
- /**
- * getCategories
- *
- * Grab all of the categories for the events
- *
- * @access public
- * @return array categories
- */
- public function getCategories()
- {
- $categoryData = new GlmDataEventsCategories( $this->wpdb, $this->config );
- return $categoryData->getCategoriesWithCurrentEvents();
- }
+ /**
+ * getCategories
+ *
+ * Grab all of the categories for the events
+ *
+ * @access public
+ * @return array categories
+ */
+ public function getCategories() {
+ $categoryData = new GlmDataEventsCategories( $this->wpdb, $this->config );
+ return $categoryData->getCategoriesWithCurrentEvents();
+ }
- /**
- * getModelEventsData
- *
- * Return the array of events.
- *
- * @param integer $categoryId Id of the category for filtering events (optional)
- * @param integer $limit Number of events to return (optional)
- * @param integer $memberID Member ID if filtering by member
- *
- * @access public
- * @return array events
- */
- public function getModelEventsData($categoryId = null, $limit = null, $memberId = null)
- {
+ /**
+ * getModelEventsData
+ *
+ * Return the array of events.
+ *
+ * @param integer $categoryId Id of the category for filtering events (optional)
+ * @param integer $limit Number of events to return (optional)
+ * @param integer $memberID Member ID if filtering by member
+ *
+ * @access public
+ * @return array events
+ */
+ public function getModelEventsData($categoryId = null, $limit = null, $memberId = null) {
- $this->postAddTimes = true;
- $where = '';
+ $this->postAddTimes = true;
+ $where = '';
- if ($memberId = filter_var( $memberId, FILTER_VALIDATE_INT )) {
- $where .= "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId AND ";
- }
+ if ($memberId = filter_var( $memberId, FILTER_VALIDATE_INT ) ) {
+ $where .= "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId AND ";
+ }
- // If a catgegory ID is supplied
- if ($catId = filter_var( $categoryId, FILTER_VALIDATE_INT )) {
- $events = $this->getEventsByCategory( $catId, $limit );
+ // If a catgegory ID is supplied
+ if ($catId = filter_var( $categoryId, FILTER_VALIDATE_INT ) ) {
+ $events = $this->getEventsByCategory( $catId, $limit );
- // Else if a category name is supplied
- } else if ($term = filter_var( $categoryId, FILTER_SANITIZE_STRING )) {
- $searchTerm = $this->wpdb->esc_like( $term );
- $where .= "T.name like '%" . $searchTerm . "%'
- AND T.status = " . $this->config['status_numb']['Active'] . "
- AND T.id IN (
- SELECT event
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
- WHERE active
- AND " . $this->dateRange . "
- )
- ";
- $order = "T.id";
- $order .= " LIMIT 2 OFFSET 0";
- $events = $this->getList($where, $order);
+ // Else if a category name is supplied
+ } else if ($term = filter_var( $categoryId, FILTER_SANITIZE_STRING ) ) {
+ $searchTerm = $this->wpdb->esc_like( $term );
+ $where .= "T.name like '%" . $searchTerm . "%'
+ AND T.status = " . $this->config['status_numb']['Active'] . "
+ AND T.id IN (
+ SELECT event
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
+ WHERE active
+ AND " . $this->dateRange . "
+ )
+ ";
+ $order = "T.id";
+ $order .= " LIMIT 2 OFFSET 0";
+ $events = $this->getList($where, $order);
- // Otherwise get all categories
- } else {
+ // Otherwise get all categories
+ } else {
- $where .= "T.status = " . $this->config['status_numb']['Active'] . "
- AND T.id IN (
- SELECT event
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
- WHERE active
- AND " . $this->dateRange . "
- )
- ";
- $events = $this->getList($where);
- }
+ $where .= "T.status = " . $this->config['status_numb']['Active'] . "
+ AND T.id IN (
+ SELECT event
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
+ WHERE active
+ AND " . $this->dateRange . "
+ )
+ ";
+ $events = $this->getList($where);
+ }
- //echo '<pre>$events: ' . print_r($events, true) . '</pre>';
- if ( !empty($events) ) {
- foreach ( $events as &$event ) {
- // grab the first from times and see if it's ongoing or not
- if ($event['times']) {
- reset($event['times']);
- $firstKey = key($event['times']);
- reset($event['times']);
- }
- $event['dates'] = $this->getEventDate(
- strtotime($event['starting_date']),
- strtotime($event['ending_date']),
- 'timestamp'
- );
- }
- }
- $this->postAddTimes = false;
- return $events;
- }
+ //echo '<pre>$events: ' . print_r($events, true) . '</pre>';
+ if ( !empty($events) ) {
+ foreach ( $events as &$event ) {
+ // grab the first from times and see if it's ongoing or not
+ if ($event['times']) {
+ reset($event['times']);
+ $firstKey = key($event['times']);
+ reset($event['times']);
+ }
+ $event['dates'] = $this->getEventDate(
+ strtotime($event['starting_date']),
+ strtotime($event['ending_date']),
+ 'timestamp'
+ );
+ }
+ }
+ $this->postAddTimes = false;
+ return $events;
+ }
- /**
- * getModelEventData
- *
- * Return the event using given eventId
- *
- * @param mixed $eventId Event Id for the entry
- *
- * @access public
- * @return array The event
- */
- public function getModelEventData($eventId)
- {
- $this->postAddTimes = true;
- $this->postAddLocations = true;
- $event = $this->getEntry($eventId);
- if ( $event['url'] ) {
- if ( !preg_match( '/^http:|https:/', $event['url'] ) ) {
- $event['url'] = 'http://' . $event['url'];
- }
- }
- $event['dates'] = $this->getEventDate(
- strtotime($event['starting_date']),
- strtotime($event['ending_date']),
- 'timestamp'
- );
- $this->postAddTimes = false;
- $this->postAddLocations = false;
- return $event;
- }
+ /**
+ * getModelEventData
+ *
+ * Return the event using given eventId
+ *
+ * @param mixed $eventId Event Id for the entry
+ *
+ * @access public
+ * @return array The event
+ */
+ public function getModelEventData($eventId) {
+ $this->postAddTimes = true;
+ $this->postAddLocations = true;
+ $event = $this->getEntry($eventId);
+ if ( $event['url'] ) {
+ if ( !preg_match( '/^http:|https:/', $event['url'] ) ) {
+ $event['url'] = 'http://' . $event['url'];
+ }
+ }
+ $event['dates'] = $this->getEventDate(
+ strtotime($event['starting_date']),
+ strtotime($event['ending_date']),
+ 'timestamp'
+ );
+ $this->postAddTimes = false;
+ $this->postAddLocations = false;
+ return $event;
+ }
- /**
- * modelAction
- *
- * @param bool $actionData Action Data passed to the modelAction
- *
- * @access public
- * @return void
- */
- abstract public function modelAction($actionData = false);
+ /**
+ * modelAction
+ *
+ * @param bool $actionData Action Data passed to the modelAction
+ *
+ * @access public
+ * @return void
+ */
+ abstract public function modelAction($actionData = false);
- /**
- * get_event_date: make the event date human readable
- *
- * @param string $sdate start date
- * @param string $edate end date
- * @param string $dateType dateType Postgres,etc
- * @param boolean $microFormat use microformating on output
- *
- * @return string
- * @access public
- */
- function getEventDate(
- $sdate,
- $edate,
- $dateType,
- $microFormat = false
- ) {
- switch($dateType) {
- case "Postgres":
- $postgresPattern = "/([0-9]{1,2})[/-]([0-9]{1,2})[/-]([0-9]{4})/";
- if (preg_match($postgresPattern, $sdate, $spt)) {
- $mon = $spt[1];
- $day = $spt[2];
- $yr = $spt[3];
- }
+ /**
+ * get_event_date: make the event date human readable
+ *
+ * @param string $sdate start date
+ * @param string $edate end date
+ * @param string $date_type date_type Postgres,etc
+ * @param boolean $micro_format use microformating on output
+ *
+ * @return string
+ * @access public
+ */
+ function getEventDate(
+ $sdate,
+ $edate,
+ $date_type,
+ $micro_format = false
+ ) {
+ switch($date_type) {
+ case "Postgres":
+ $postgresPattern = "/([0-9]{1,2})[/-]([0-9]{1,2})[/-]([0-9]{4})/";
+ if (preg_match( $postgresPattern, $sdate, $spt ) ) {
+ $mon = $spt[1];
+ $day = $spt[2];
+ $yr = $spt[3];
+ }
- if (preg_match($postgresPattern, $edate, $ept)) {
- $mon2 = $ept[1];
- $day2 = $ept[2];
- $yr2 = $ept[3];
- }
- break;
- case "eventstamp":
- case "timestamp":
- $mon = date("m",$sdate);
- $day = date("d",$sdate);
- $yr = date("Y",$sdate);
- $mon2 = date("m",$edate);
- $day2 = date("d",$edate);
- $yr2 = date("Y",$edate);
- break;
- }
+ if (preg_match( $postgresPattern, $edate, $ept ) ) {
+ $mon2 = $ept[1];
+ $day2 = $ept[2];
+ $yr2 = $ept[3];
+ }
+ break;
+ case "eventstamp":
+ case "timestamp":
+ $mon = date( 'm', $sdate );
+ $day = date( 'd', $sdate );
+ $yr = date( 'Y', $sdate );
+ $mon2 = date( 'm', $edate );
+ $day2 = date( 'd', $edate );
+ $yr2 = date( 'Y', $edate );
+ break;
+ }
- $start = mktime(0,0,0,$mon,$day,$yr);
- $end = mktime(0,0,0,$mon2,$day2,$yr2);
- if ($day == $day2 && $mon == $mon2 && $yr == $yr2) {
- $dateparam = "M j, Y";
- $dateBegin = date($dateparam, $start) ;
- $dateEnd = "";
- } elseif ($day == $day2 AND $mon == $mon2 AND $yr != $yr2) {
- $dateparam1 = "M j, Y -";
- $dateparam2 = "Y";
- $dateBegin = date($dateparam1, $start);
- $dateEnd = date($dateparam2, $end);
- } elseif ($day != $day2 AND $mon == $mon2 AND $yr == $yr2) {
- $dateparam1 = "M j -";
- $dateparam2 = "j, Y";
- $dateBegin = date($dateparam1, $start);
- $dateEnd = date($dateparam2, $end);
- } elseif ($day != $day2 AND $mon == $mon2 AND $yr != $yr2) {
- $dateparam1 = "M j, Y -";
- $dateparam2 = "M j, Y";
- $dateBegin = date($dateparam1, $start);
- $dateEnd = date($dateparam2, $end);
- } elseif ($yr == $yr2) {
- $dateparam1 = "M j -";
- $dateparam2 = "M j, Y";
- $dateBegin = date($dateparam1, $start);
- $dateEnd = date($dateparam2, $end);
- } else {
- $dateparam1 = "M j, Y -";
- $dateparam2 = "M j, Y";
- $dateBegin = date($dateparam1, $start);
- $dateEnd = date($dateparam2, $end);
- }
- if ($microFormat) {
- $dateBegin = '<span class="dtstart">
- <span class="value" title="'.date('Y-m-d', $start).'">' .
- $dateBegin . '</span>
- </span>';
- $dateEnd
- = ($dateEnd)
- ? '<span class="dtend">
- <span class="value" title="'.date('Y-m-d', $end).'">' .
- $dateEnd . '</span>
- </span>'
- : '';
- }
- return $dateBegin." ".$dateEnd;
- }
+ $start = mktime( 0, 0, 0, $mon, $day, $yr );
+ $end = mktime( 0, 0, 0, $mon2, $day2, $yr2 );
+ if ( $day == $day2 && $mon == $mon2 && $yr == $yr2 ) {
+ $dateparam = 'M j, Y';
+ $date_begin = date( $dateparam, $start ) ;
+ $date_end = '';
+ } elseif ( $day == $day2 AND $mon == $mon2 AND $yr != $yr2 ) {
+ $dateparam1 = 'M j, Y -';
+ $dateparam2 = 'Y';
+ $date_begin = date( $dateparam1, $start );
+ $date_end = date( $dateparam2, $end );
+ } elseif ( $day != $day2 AND $mon == $mon2 AND $yr == $yr2 ) {
+ $dateparam1 = 'M j -';
+ $dateparam2 = 'j, Y';
+ $date_begin = date( $dateparam1, $start );
+ $date_end = date( $dateparam2, $end );
+ } elseif ( $day != $day2 AND $mon == $mon2 AND $yr != $yr2 ) {
+ $dateparam1 = 'M j, Y -';
+ $dateparam2 = 'M j, Y';
+ $date_begin = date ($dateparam1, $start );
+ $date_end = date( $dateparam2, $end );
+ } elseif ( $yr == $yr2 ) {
+ $dateparam1 = 'M j -';
+ $dateparam2 = 'M j, Y';
+ $date_begin = date( $dateparam1, $start );
+ $date_end = date( $dateparam2, $end );
+ } else {
+ $dateparam1 = 'M j, Y -';
+ $dateparam2 = 'M j, Y';
+ $date_begin = date( $dateparam1, $start );
+ $date_end = date( $dateparam2, $end );
+ }
+ if ($micro_format) {
+ $date_begin = '<span class="dtstart">
+ <span class="value" title="'.date('Y-m-d', $start).'">' .
+ $date_begin . '</span>
+ </span>';
+ $date_end
+ = ($date_end)
+ ? '<span class="dtend">
+ <span class="value" title="'.date('Y-m-d', $end).'">' .
+ $date_end . '</span>
+ </span>'
+ : '';
+ }
+ return $date_begin . ' ' . $date_end;
+ }
}