AUTOMATIC EVENT RECORD CREATION - Jan 28th, 2021


I needed to automatically create the event records for 2 monthly events on a site for my client, Jazz on J Street. JOJS
Presents! Events, (in a multi record ‘events’ section) and JOJS Live Jam Sessions (in a multi record
‘listen_live’ section.)

I had also created a multi record ‘musicians_listing’ section earlier and wanted to access that information on the
events page using the new ‘Pillbox’ list field format to list the featured performers for each event. Both had a
number of additional criteria that needed to be met. All that’s in another recipe at:
http://thecmsbcookbook.com/recipedetail.php?620

Here’s how to automatically create event records every month:

There were a number of client required variables:
1) The events almost always occurred on the same day and time every month (second Monday, Third Saturday, etc.), but
that could change.
2) JOJS Presents! events were normally only listed on the site’s special events page, and JOJS JAM Sessions were only
normally listed on their live streamed events page., but that could change.
3) JOJS Presents! Events normally had featured performers listed but the Jam Sessions normally didn’t, but that could
change.
4) Their live streaming event page has a next event count down timer that needed to reflect the actual start time for
each event.

To deal with the required variables, I set up a single record editor called ‘Event Parameters’ with the following
fields with field descriptions about the required textual formats:

6 Text fields
JOJS Jam Day (of the month) - This should be entered as Third Tuesday, Last Friday, 1st Monday, etc.
JOJS Presents Day (of the month) - This should be entered as Third Tuesday, Last Friday, 1st
JOJS Jam Start Time - This should be entered as 7:00 PM or 8:30 PM, etc.
JOJS Presents Start time - This should be entered as 7:00 PM or 8:30 PM, etc.
JOJS Jam Countdown Start time -This should be entered in an hh:mm:ss format, so 7 PM would be 19:00:00 and 8:30 PM would
be 20:30:00.
JOJS Presents Countdown Start time - This should be entered in an hh:mm:ss format, so 7 PM would be 19:00:00 and 8:30 PM
would be 20:30:00.

2 Check Boxes
Streaming JOJS Presents - Check if JOJS Presents is going to be streamed going forward
Create JOJS Jam Event Listing - Check if JOJS Jams should have an event listing going forward

I sorted these under the separator headers:
'START TIMES FOR COUNTDOWN TIMER'
'JOJS WEEK, DAY AND TIMES':

HELP PAGE ENTRY
The help page entry for ‘Automatic creation of JOJS JAM and JOJS Presents! records’ is as follows:
There is a new editor called called ‘Event Parameters’ that control the parameters for automatic creation of JOJS
Jam and JOJS Presents! records.
They are:
Under 'START TIMES FOR COUNTDOWN TIMER':
'JOJS JAM Countdown Start time' and 'JOJS Presents Countdown Start time'. These should be entered in an hh:mm:ss format,
so 7 PM would be 19:00:00 and 8:30 PM would be 20:30:00.

Under 'JOJS WEEK, DAY AND TIMES':
'JOJS JAM Day' and 'JOJS Presents Day'. These should be entered as Third Tuesday, Last Friday, 1st Monday, etc.
'JOJS JAM Start Time' and 'JOJS Presents Start Time'. These should be entered as 7:00 PM or 8:30 PM, etc.

It is assumed that JOJS Presents! events will not be streamed for the time being. If that changes going forward, check
the 'Streaming JOJS Presents' check box
It is assumed that JOJS Jam Sessions are listed only as 'listen-live' events. If that changes going forward, check the
'Create JOJS Jam Event Listing' check box

Then, I created 2 record creation pages that are triggered by cron jobs on my cPanel once a month. If you're using the
Auto Backup plugin, you can get the basic command line format for the cron jobs from your 'Admin' > 'Background Tasks'
page, or from the cron tab on your cPanel.

Just an aside, If you're not using the official Auto Backup plugin on all of your sites, I strongly suggest that you get
it (only $59.95 for a single site and $89.95 for unlimited use) and use it.
https://www.interactivetools.com/plugins/auto-backup/

I’ve combine the code for the 2 separate pages, so make 2 copies of the code below and comment out the 2 appropriate
lines for each of the pages. You can add any $colsToValues entries that you need for your specific application.


<?php list($event_parametersRecords, $event_parametersMetaData) = getRecords(array(
'tableName' => 'event_parameters',
'where' => '', // load first record
'limit' => '1',
'allowSearch' => false,
));
$event_parametersRecord = @$event_parametersRecords[0]; // get first record
?>
<?php
// IMPORTANT! Comment out the next line for the 'Create Jam Event' page
$presentsEventDay = strtolower($event_parametersRecord['jojs_presents_day']);
// IMPORTANT! Comment out the next line for the 'Create Presents Event' page
$presentsEventDay = strtolower($event_parametersRecord['jojs_jam_day']);
?>
<?php
$this1 = 'of this month';
$next1 = 'of next month';
$resultThis = $presentsEventDay . ' ' . $this1;
$resultNext = $presentsEventDay . ' ' .$next1;
?>
<?php $eventDate = new DateTime($resultThis); ?>
<?php $currentEventDate = new DateTime($resultThis); ?>
<?php $currentEventDate1 = new DateTime($resultThis); ?>
<?php
$nextEventDate = new DateTime($resultNext); ?>
<?php if ($eventDate < new DateTime()) {
$eventDate->modify($resultNext);
}
?>
<?php $date2 = ($currentEventDate); ?>
<?php $date2->modify('+2 day'); ?>

<?php $currentEventDate2 = $date2->format('F d, Y'); ?>
<?php $date4 = ($currentEventDate1); ?>
<?php $date4->modify('+4 day'); ?>

<?php $currentEventDate4 = $date4->format('F d, Y'); ?>
<?php $today = date('F d, Y'); ?>
<?php if(($today > $currentEventDate2) && ($today < $currentEventDate4)): ?>
<?php
// turn off strict mysql error checking for: STRICT_ALL_TABLES
mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields
are added later)

// add record to listen_live streaming editor

$tablename = 'listen_live';
$colsToValues = array();
$colsToValues['hidden'] = 0;
$colsToValues['createdDate='] = 'NOW()';
$colsToValues['updatedDate='] = 'NOW()';
$colsToValues['createdByUserNum'] = 0;
$colsToValues['upcoming_event_status'] = 0;
$colsToValues['updatedByUserNum'] = 0;
$colsToValues['neverRemove'] = 1;
$colsToValues['is_this_a_jojs_presents_event'] = 1;
$colsToValues['publishDate='] = 'NOW()';
$colsToValues['presentation_date'] = $eventDate->format('Y-m-d 00:00:00');
$colsToValues['travel_directions'] = 1;
$colsToValues['time'] = "7:00 to 10:00 PM";
$colsToValues['youtube_streaming_shortcode'] = 'your youtube channel id here (not the complete url)';
$colsToValues['travel_directions'] = "your travel directions here";
$colsToValues['attendance_fee'] = '10 at the door';
$colsToValues['instructions'] = 'Listen live records are created automatically a few days after the current event
is over. A default image will be shown if there is no special image uploaded. If any information that is unique to this
Jam Session, it must be changed manually.';
$colsToValues['announcement_lead'] = 'New talented and innovative Professional Jazz musicians are featured LIVE
every month';
// Remove any $colsToValues that don't apply anda dd your own $colsToValues entries here

// IMPORTANT! Comment out the next line for 'Create Presents' Event page
if($event_parametersRecord['streaming_jojs_presents'] == 1){ $newRecordNum = mysql_insert($tablename, $colsToValues,
true);}

// add record to the events editor

$tablename2 = 'events';
$colsToValues = array();
$colsToValues['hidden'] = 0;
$colsToValues['createdDate='] = 'NOW()';
$colsToValues['updatedDate='] = 'NOW()';
$colsToValues['createdByUserNum'] = 0;
$colsToValues['updatedByUserNum'] = 0;
$colsToValues['neverRemove'] = 1;
$colsToValues['publishDate='] = 'NOW()';
$colsToValues['presentation_date'] = $eventDate->format('Y-m-d 00:00:00');
$colsToValues['event_title'] = 'Jazz on J Street Presents!';
$colsToValues['performance_times'] = "8:00 to 9:30 PM";
$colsToValues['travel_directions'] = "Your Travel Directions Go Here (Don\'t forget to escape all \' and \" and
any other forbidden characters";
$colsToValues['attendance_fee'] = '10 at the door';
$colsToValues['instructions'] = 'Listen live records are created automatically a few days after the current event
is over. A default image will be shown if there is no special image uploaded. If any information that is unique to this
Jam Session, it must be changed manually.';
$colsToValues['event_description'] = 'Your Even Description Here';
// Remove any $colsToValues that don't apply anda dd your own $colsToValues entries here

// IMPORTANT! Uncomment the next linefor Auto Create Jams Event Page
// if($common_informationRecord['create_jojs_jam_event_listing'] == 1){ $newRecordNum = mysql_insert($tablename2,
$colsToValues, true); }

?>
<?php endif ?>
</body>
</html>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service