From ae97f073892a4b5b779a1d6a374dc5f5ca30cbc9 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 31 Mar 2016 16:48:32 -0400 Subject: [PATCH] Major cleanup with locations and schedules --- classes/data/dataEvents.php | 11 +- index.php | 2 +- models/admin/events/list.php | 161 +++++++++++++++-- ..._V0.0.7.sql => create_database_V0.0.8.sql} | 1 + setup/databaseScripts/dbVersions.php | 3 +- .../update_database_V0.0.8.sql | 12 ++ setup/validActions.php | 2 +- views/admin/events/edit.html | 169 +++++++++--------- views/admin/events/editLocation.html | 96 +++++----- views/admin/events/editSchedule.html | 36 ++-- views/admin/events/editStatus.html | 7 + 11 files changed, 322 insertions(+), 178 deletions(-) rename setup/databaseScripts/{create_database_V0.0.7.sql => create_database_V0.0.8.sql} (99%) create mode 100644 setup/databaseScripts/update_database_V0.0.8.sql diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index be46841..7d0b1c6 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -301,6 +301,13 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'a' ), + // Event Phone + 'phone' => array ( + 'field' => 'phone', + 'type' => 'text', + 'use' => 'a' + ), + // Event URL 'url' => array ( 'field' => 'url', @@ -518,14 +525,14 @@ class GlmDataEvents extends GlmDataAbstract $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); // Check ID - $if = ($if - 0); + $id = ($id - 0); if ($id <= 0) { return false; } // Try to get the event data $event = $this->getEntry($id); - if (!event) { + if (!$event) { return false; } diff --git a/index.php b/index.php index e05fa89..e9eb14e 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ * version from this plugin. */ define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.7'); +define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.8'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_EVENTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58'); diff --git a/models/admin/events/list.php b/models/admin/events/list.php index 784cc67..f1168de 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -195,6 +195,9 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } + // Check for new cities and get a table to match the submitted ID with the new city ID + $newCityID = $this->checkNewCities(); + // Do selected option switch ($option) { @@ -222,6 +225,80 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $this->updateTimestamp('created', $this->eventID); $this->updateSlug($this->eventID); + // Look for location data + if (isset($_REQUEST['locID'])) { + + // For each location + foreach ($_REQUEST['locID'] as $locID) { + + // Set the nLoc{id}_event value to the new event + $_REQUEST[$locID.'_event'] = $this->eventID; + + // Check for new cities in this location and if so use the new city real ID + if (isset($_REQEUST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { + $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']]; + } + + // Check if it's a new Location - Here it will be + if ($locID[0] == 'n') { + + // Add the new location + $x = $Locations->insertEntry(true, $locID.'_'); + + } + + } + + } + + // Look for recurrence data + if (isset($_REQUEST['recurID'])) { + + // For each recurrence + foreach ($_REQUEST['recurID'] as $recurID) { + + // Set the nRecur{id}_event value to the new event + $_REQUEST[$recurID.'_event'] = $this->eventID; + + // first check if the event is an all-day event + if (isset($_REQUEST[$recurID.'_all_day'])) { + + // Then take the start date (date only) and stick it into the start time + $red = explode(' ', $_REQUEST[$recurID.'_start_date']); + $_REQUEST[$recurID.'_start_time'] = $red[0]." 00:00"; + $_REQUEST[$recurID.'_end_time'] = $red[0]." 00:00"; + + } + + // Check if it's a new Recurrence - Here it will be + if ($recurID[0] == 'n') { + + // Add the new recurrence + $x = $Recurrences->insertEntry(true, $recurID.'_'); + + // And create time entries + $Recurrences->createRecurrenceTimesEntries($x['fieldData']['id'], true, true); + + } + + } + + // Update our recurrences + $recurrences = $Recurrences->getList("T.event = ".$this->eventID); + + // Check for any updated recurrences + if (isset($_REQUEST['recurUpdated']) && count($_REQUEST['recurUpdated']) > 0) { + foreach ($_REQUEST['recurUpdated'] as $r) { + + // If we have a recurID as a value, then update this recurrence times + if ($r) { + $Recurrences->createRecurrenceTimesEntries($r, true, true); + } + } + } + + } + // Get this again so we have the created date $event = $this->editEntry($this->eventID); @@ -273,19 +350,6 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $eventUpdateError = true; } - // Look for recurrence deletes - if (isset($_REQUEST['deleteRecur']) && count($_REQUEST['deleteRecur'] > 0)) { - foreach ($_REQUEST['deleteRecur'] as $d) { - - // If this was not a new entry that was deleted (in which case it was never added) - if ($d[0] != 'n') { - $Recurrences->deleteTimeEntriesForRecurrance($d, true); - $Recurrences->deleteEntry($d, true); - } - - } - } - // Look for location deletes if (isset($_REQUEST['deleteLocation']) && count($_REQUEST['deleteLocation'] > 0)) { foreach ($_REQUEST['deleteLocation'] as $d) { @@ -302,7 +366,12 @@ class GlmMembersAdmin_events_list extends GlmDataEvents if (isset($_REQUEST['locID'])) { // For each location - foreach ($_REQUEST['locID'] as $locID) { + while (list($id, $locID) = each($_REQUEST['locID'])) { + + // Check for new cities in this location and if so use the new city real ID + if (isset($_REQEUST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { + $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']]; + } // Check if it's a new Location if ($locID[0] == 'n') { @@ -312,14 +381,27 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Otherwise it's an existing location } else { - $Locations->updateEntry($locID, 'id', true, $locID.'_'); + $Locations->updateEntry($id, 'id', true, $locID.'_'); } } } - // Look for recurrence data + // Look for recurrence deletes + if (isset($_REQUEST['deleteRecur']) && count($_REQUEST['deleteRecur'] > 0)) { + foreach ($_REQUEST['deleteRecur'] as $d) { + + // If this was not a new entry that was deleted (in which case it was never added) + if ($d[0] != 'n') { + $Recurrences->deleteTimeEntriesForRecurrance($d, true); + $Recurrences->deleteEntry($d, true); + } + + } + } + + // Look for recurrence data if (isset($_REQUEST['recurID'])) { // For each recurrence @@ -346,7 +428,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Otherwise it's an existing recurrence } else { - $Recurrences->updateEntry($recurID, 'id', true, $recurID.'_'); + $Recurrences->updateEntry($recurID, 'id', true, 'Recur'.$recurID.'_'); } } @@ -577,6 +659,51 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } + /* + * Check for new Cities being added + * + * @return void + */ + public function checkNewCities() + { + // Array of submitted vs new city IDs to return + $newCityID = array(); + + // If we have a new Cities submitted + if (isset($_REQUEST['newCity'])) { + + // Try to add the city + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php'); + $Cities = new GlmDataCities($this->wpdb, $this->config); + + // For each new city submitted + while (list($k, $v) = each($_REQUEST['newCity'])) { + + $cName = trim(filter_var($_REQUEST['newCity'][$k])); + + if ($cName != '') { + + // Try to add the city to cities table + $cID = $Cities->addCity($cName); + + // If the city added OK + if (is_int($cID) && $cID > 0) { + + // Update the Input to show the new ID + // Add this to the newCityID table + $newCityID[$k] = $cID; + } + + } + + } + + return $newCityID; + } + + } + + } diff --git a/setup/databaseScripts/create_database_V0.0.7.sql b/setup/databaseScripts/create_database_V0.0.8.sql similarity index 99% rename from setup/databaseScripts/create_database_V0.0.7.sql rename to setup/databaseScripts/create_database_V0.0.8.sql index 1196594..b22ddf4 100644 --- a/setup/databaseScripts/create_database_V0.0.7.sql +++ b/setup/databaseScripts/create_database_V0.0.8.sql @@ -128,6 +128,7 @@ CREATE TABLE {prefix}events ( descr TEXT NULL, -- Full description text image TINYTEXT NULL, -- Image file name url TINYTEXT NULL, -- Event URL + phone TINYTEXT NULL, -- Event Phone ticket_url TINYTEXT NULL, -- Ticket URL cost TINYTEXT NULL, -- Description of event cost admin_ref_type INT NULL, -- Type of admin contact if using a member contact diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index ceb9573..b324373 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -20,6 +20,7 @@ $glmMembersEventsDbVersions = array( '0.0.4' => array('version' => '0.0.4', 'tables' => 7), '0.0.5' => array('version' => '0.0.5', 'tables' => 7), '0.0.6' => array('version' => '0.0.6', 'tables' => 7), - '0.0.7' => array('version' => '0.0.7', 'tables' => 7) + '0.0.7' => array('version' => '0.0.7', 'tables' => 7), + '0.0.8' => array('version' => '0.0.8', 'tables' => 7) ); diff --git a/setup/databaseScripts/update_database_V0.0.8.sql b/setup/databaseScripts/update_database_V0.0.8.sql new file mode 100644 index 0000000..9166d69 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.8.sql @@ -0,0 +1,12 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.6 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + + +-- Add use end time +ALTER TABLE {prefix}events ADD COLUMN phone TINYTEXT; + diff --git a/setup/validActions.php b/setup/validActions.php index 8595415..e49a8d2 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -33,7 +33,7 @@ $glmMembersEventsAddOnValidActions = array( 'adminActions' => array( 'ajax' => array( - 'pdfOutput' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG + 'pdfOutputs' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG ), 'member' => array( 'events' => GLM_MEMBERS_EVENTS_PLUGIN_SLUG, diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index a2e0f43..0f527b1 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -141,11 +141,13 @@ if (table == 'glm-table-location' && !locationsInited) { initLocations(); + initNewCity(); locationsInited = true; } if (table == 'glm-table-calendar' && !fullCalendarLoaded) { - + + // **** Should probably move all this to a function and check if it's been initialized already $('#eventCalendar').fullCalendar({ {if $haveTimes} events: [ @@ -163,9 +165,6 @@ defaultDate : '{$firstTime.start_time.datetime}', timeFormat : 'h:mma', fixedWeekCount : false, - - - eventClick: function(calEvent, jsEvent, view) { alert('Event: ' + calEvent.title); @@ -176,36 +175,37 @@ }, dayClick: function(date, allDay, jsEvent, view) { - if (allDay) { - alert('Clicked on the entire day: ' + date); - }else{ - alert('Clicked on the slot: ' + date); - } + if (allDay) { + alert('Clicked on the entire day: ' + date); + }else{ + alert('Clicked on the slot: ' + date); + } - alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); + alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); - alert('Current view: ' + view.name); + alert('Current view: ' + view.name); - // change the day's background color just for fun - $(this).css('background-color', 'red'); + // change the day's background color just for fun + $(this).css('background-color', 'red'); - } + } {/if} }); - + fullCalendarLoaded = true; } }); + /* + * General Event Actions + */ + // Add Event Button Action $('#addEventButton').click( function() { window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=list&option=add"; }); - // Flash certain elements for a short time after display - $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500); - {if $haveEvent} // Delete Event dialog $("#deleteEventDialog").dialog({ @@ -229,13 +229,11 @@ {/if} /* - * Locations + * Location Actions */ - var numbLocations = {$numbLocations}; - /* - * Add location using template - */ + // Current number of locations + var numbLocations = {$numbLocations}; // New location ID's start at 0 (have "n" for "new" appended to them in the template) var newLocID = 0; @@ -243,8 +241,8 @@ // Get location template and clear it from HTML so it doesn't get submitted locTemplate = $('#addLocationTemplate').html(); $('#addLocationTemplate').html(''); - - // When adding a new location is requested + + // Request to add a new location $("#addLocation").click( function() { addNewLocationForm(); $('#no-location-msg').remove(); @@ -266,35 +264,18 @@ } locTemp = locTemp + locTemplate; - locTemp = locTemp.replace(/{ newLocID }/g, 'n' + newLocID); // Include "n" to indicate "new" + locTemp = locTemp.replace(/{ newLocID }/g, 'nLoc' + newLocID); // Include "n" to indicate "new" // Append the new location form to the container $('#locationTable').append(locTemp); - initLocation('n' + newLocID); + initLocation('nLoc' + newLocID); } - /* - * Things that need to be renewed each time a location is added - */ + // Function to initialize actions related to a specific location function initLocation(locID) { - // Setup dialog box for adding a new city - $("#newCityDialog").dialog({ - autoOpen: false, - minWidth: 400, - dialogClass: "glm-dialog-no-close" - }); - $('#newCityCancel').click( function() { - $("#newCityDialog").dialog("close"); - }); - - // Ad a new city button action - pop-up dialog - $('#newCityButton').click( function() { - $("#newCityDialog").dialog("open"); - }); - // Delete a location $('.delete-location').on( 'click', function() { locID = $(this).attr('data-id'); @@ -304,6 +285,7 @@ }) initMap(locID); + initNewCity(); } @@ -334,7 +316,7 @@ // Get recurrence template and clear it from HTML so it doesn't get submitted recurTemplate = $('#addRecurrenceTemplate').html(); $('#addRecurrenceTemplate').html(''); - + function addNewRecurrenceForm() { // Tick the new recurrence ID counter and build new HTML from the addRecurrenceTemplate @@ -351,7 +333,7 @@ } recurTemp = recurTemp + recurTemplate; - recurTemp = recurTemp.replace(/{ newRecurID }/g, 'n' + newRecurID); // Include "n" to indicate "new" + recurTemp = recurTemp.replace(/{ newRecurID }/g, 'nRecur' + newRecurID); // Include "n" to indicate "new" // Append the new recurrence form to the container $('#recurrenceTable').append(recurTemp); @@ -477,10 +459,6 @@ $('#addRecurrenceCancel').click( function() { $("#addRecurrenceDialog").dialog("close"); }); - $('#addRecurrenceSubmit').click( function() { - // window.location.replace("{$thisUrl}?page={$thisPage}&glm_action=list&option=delete&event={$event.fieldData.id}"); - }); - /* * Category Selection @@ -639,6 +617,7 @@ // If submit is required and we're laving the page, alert the user $(window).bind('beforeunload', function() { if (glmSubmitRequired) { + return true; } }); @@ -647,67 +626,77 @@ * New City Dialog */ - function addNewCitySetup() { - + var newCityLocation = false; + function initNewCity() { + // Setup dialog box for adding a new city - $(".newCityDialog").dialog({ + $("#newCityDialog").dialog({ autoOpen: false, minWidth: 400, dialogClass: "glm-dialog-no-close" }); - $('.new-city-cancel').click( function() { - locID = $(this).attr('data-id'); - $("#newCityDialog_" + locID).dialog("close"); + $('#newCityCancel').click( function() { + $("#newCityDialog").dialog("close"); + $('#newCityNameTD').removeClass('glm-form-bad-input'); + $('#newCityNameRequired').text(''); + $('#newCityName').val(''); }); - + // Add a new city button action - pop-up dialog $('.new-city-button').click( function() { - locID = $(this).attr('data-id'); - $("#newCityDialog_" + locID).dialog("open"); + newCityLocation = $(this).attr('data-id'); + $("#newCityDialog").dialog("open"); }); + } - addNewCitySetup(); - + // Submit new city - var newCityAdded = false; + var newCityCount = 0 + var listedCities = new Object(); + + // Add list of existing cities for duplicate check + {foreach $locations as $loc} + {foreach $loc.city.list as $v} + listedCities["{$v.name}"] = true; + {/foreach} + {/foreach} + $('.newCitySubmit').click( function() { - locID = $(this).attr('data-id'); - // Get new city name - var newCityName = $('#newCityName_' + locID).val(); + var newCityName = $('#newCityName').val(); // If no name is supplied, notify used it's required if (newCityName == '') { - $('#newCityNameTD_' + locID).addClass('glm-form-bad-input'); - $('#newCityNameRequired_' + locID).text('A city name is required!'); + $('#newCityNameTD').addClass('glm-form-bad-input'); + $('#newCityNameRequired').text('A city name is required!'); + return false; + } else { + $('#newCityNameTD').removeClass('glm-form-bad-input'); + $('#newCityNameRequired').text(''); + } + + // Check list of new cities added to make sure we don't add a duplicate + if (typeof listedCities[newCityName] !== "undefined") { + $('#newCityNameTD').addClass('glm-form-bad-input'); + $('#newCityNameRequired').text('This city is already listed!'); return false; } // Add new city name to the hidden field that will pass the new name to PHP. - $('#cityName_' + locID).val(newCityName); - - // Add new city name to picklist and for storing - Only one permitted per submission - if (newCityAdded) { + newCityCount++; + $('#newCityNames').append(''); - // New city already added, so just update the name and select that one - $('#city_' + locID).val(-1); - $('#city_' + locID + ' option:selected').text(newCityName); + // Remember this city to check for duplicates being added + listedCities[newCityName] = true; - } else { - - // Add the new city name to the city picklist - $('#city_' + locID).append(''); - $('#city_' + locID ).val(-1); - $('#newCityNameTD_' + locID).append(''); - newCityAdded = true; - - } + $('.city-picklist').append(''); + $('#city_' + newCityLocation).val("n_" + newCityCount); // Clear new city name from form - $('#newCityName_' + locID).val(''); + $('#newCityName').val(''); - $("#newCityDialog_" + locID).dialog("close"); + $('#newCityDialog').dialog("close"); }); @@ -736,7 +725,6 @@ var startLon = $('#glmLng_' + locID).val(); location[locID] = new google.maps.LatLng(startLat, startLon); - map[locID] = new google.maps.Map(document.getElementById('locationMap_' + locID), { zoom: 15, disableDefaultUI: false, @@ -816,6 +804,13 @@ } + /* + * Misc support items + */ + + // Flash certain elements for a short time after display + $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500); + }); diff --git a/views/admin/events/editLocation.html b/views/admin/events/editLocation.html index ab951ed..0f293e6 100644 --- a/views/admin/events/editLocation.html +++ b/views/admin/events/editLocation.html @@ -1,8 +1,26 @@ - - + + + + +
+ + + + + +
City Name: + +
+
+

* Required

+ Cancel + +
+ + @@ -19,19 +37,20 @@

- - + + + @@ -39,23 +58,8 @@ @@ -151,8 +155,8 @@
Location Name: - +
Address: - +
Add a new City
-
- - - - - -
City Name: - -
-
-

* Required

- Cancel - -
- - {foreach from=$loc.city.list item=v}
State: - {foreach from=$loc.state.list item=v}
ZIP / Postal Code: - +
Country: - {foreach from=$loc.country.list item=v}
Region: - {foreach from=$loc.region.list item=v} @@ -109,38 +113,38 @@
Phone: - +
Web Address: - +
Email Address: - +
Contact Name: - First: - Last: + First: + Last:
Contact Phone: - +
Contact Email: - +
Location: - - + + Delete Location
Map Location Using Above Address

@@ -178,7 +182,9 @@

+ {if $haveEvent} + {/if} @@ -197,24 +203,9 @@
City -
Add a new City
-
- - - - - -
City Name: - -
-
-

* Required

- Cancel - -
+
Add a new City
- - {foreach from=$newLocation.fieldData.city.list item=v}
- + @@ -62,13 +62,13 @@ @@ -87,7 +87,7 @@ @@ -101,7 +101,7 @@ {if $v.value==6} {/if} - + {/foreach} @@ -112,7 +112,7 @@ @@ -121,7 +121,7 @@
Schedule Name: - +
First occurrence for this schedule
All Day Event: - +
Start Date & Time: - +
Start Date & Time Only - +
End Date & Time: - +
Event Date: - +
 
From Date: - +
To Date: - +
Ongoing Event: - + Check to have event recurr every day from the "From Date" through the "To Date".
{$v.name}   {$v.name}    
All
None
Days of month: - Check to select specific days of the month. + Check to select specific days of the month.
{foreach $r.week_of_month.bitmap as $v} - + {/foreach} @@ -134,7 +134,7 @@
{$v.name}   {$v.name}    
All
None
{foreach $r.day_of_week.bitmap as $v} - + {/foreach} @@ -151,11 +151,11 @@ {/if} {/foreach} @@ -178,13 +178,15 @@
{$v.name} {$v.name}  
All
None
- {$v.name} + {$v.name} - Last day of the month + Last day of the month
All
None
- +
+ {if $haveEvent} + {/if} diff --git a/views/admin/events/editStatus.html b/views/admin/events/editStatus.html index 76def26..5e2a568 100644 --- a/views/admin/events/editStatus.html +++ b/views/admin/events/editStatus.html @@ -165,6 +165,13 @@ {if $event.fieldFail.image}

{$event.fieldFail.image}

{/if} + + + +
Schedule Name:
Event Phone #: + + {if $event.fieldFail.phone}

{$event.fieldFail.phone}

{/if}
+
Web Address (URL): -- 2.17.1