--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Clone Member Information Record
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release glmMemberInfoClone.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+/*
+ * This class provides facilities for cloning a complete event
+ * record including all associated information and images.
+ *
+ */
+class GlmEventClone
+{
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+
+ /**
+ * Constructor
+ *
+ * Clone a event record and anything associated with it
+ * to create a new complete event information record that is identical
+ * to the source except that it is set to "pending".
+ *
+ * @param object $wpdb Word Press database object
+ * @param array $config Configuration data
+ * @param integer $eventInfoID ID of the event info record to clone
+ *
+ * @return integer ID of the new cloned event information record
+ * @access public
+ **/
+ function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ /*
+ * Clone Member Info
+ *
+ * @param integer $id ID of event to clone
+ *
+ * @return void
+ * @access public
+ */
+ public function cloneEvent( $id )
+ {
+
+ // Load Member Info Data Class and get info data for later use
+ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataEvents.php';
+ $Event = new GlmDataEvents( $this->wpdb, $this->config );
+ $event = $Event->getEntry( $id );
+
+ // Create a new event record and get its ID - this also copies images to a new name
+ $newID = $Event->cloneEntry( $id );
+
+ // If the clone was successful
+ if ($newID != false) {
+ // Load recurrences data class to get a blank entry for the template
+ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php';
+ $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+
+ // Update create and update times to now and set event record to pending
+ $t = date( 'Y-m-d H:i:s', time() );
+ $newReferenceName = "CLONED - ".$event['name'];
+ $sql = "
+ UPDATE ".$Event->table."
+ SET created = '$t', updated = '$t', status = ".$this->config['status_numb']['Pending'].", name = '".addslashes($newReferenceName)."'
+ WHERE id = $newID
+ ;";
+ $this->wpdb->query( $sql );
+
+ // Duplicate all event_categories table entries
+ $sql = "
+ INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories
+ (category,event)
+ SELECT category, $newID
+ FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories
+ WHERE event = $id
+ ;";
+
+ $this->wpdb->query( $sql );
+
+ // Duplicate the locations
+ $sql = "
+ INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations
+ (event,name,address,city,state,zip,country,lat,lon,region,phone,url,email,contact_addon_id)
+ SELECT $newID,name,address,city,state,zip,country,lat,lon,region,phone,url,email,contact_addon_id
+ FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."locations
+ WHERE event = $id
+ ";
+ $this->wpdb->query( $sql );
+
+ // Duplicate the recurrences
+ $sql = "
+ INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences
+ (event,name,start_time,start_time_only,end_time,all_day,start_date,from_date,to_date,recurring,month_of_year,
+ week_of_month,day_of_week,by_day_of_month,day_of_month,specific_dates,holiday,holiday_offset)
+ SELECT $newID,name,start_time,start_time_only,end_time,all_day,start_date,from_date,to_date,recurring,month_of_year,
+ week_of_month,day_of_week,by_day_of_month,day_of_month,specific_dates,holiday,holiday_offset
+ FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences
+ WHERE event = $id
+ ";
+ $this->wpdb->query( $sql );
+ // Duplicate the times
+ // Update our recurrences
+ $recurrences = $Recurrences->getList( "T.event = " . $newID );
+ //echo '<pre>$recurrences: ' . print_r( $recurrences, true ) . '</pre>';
+ //exit;
+
+ // Check for any updated recurrences
+ if ( isset( $recurrences ) && count( $recurrences ) > 0 ) {
+ foreach ( $recurrences as $r ) {
+
+ // If we have a recurID as a value, then update this recurrence times
+ if ( isset( $r['id'] ) ) {
+ $Recurrences->createRecurrenceTimesEntries( $r['id'], true, true );
+ }
+ }
+ }
+
+
+ }
+
+ return $newID;
+
+ }
+
+}
+
+?>