The world's most popular open source database
by Duncan Cameron
About this Article
My aim of this article is to create awareness of some of the features available with Lasso Professional 5 to Lasso/MySQL database developers. Showing how they can assist in making solutions development more time saving.
These features are:
The Event_Schedule tag allows a URL and parameters to be loaded by Lasso and then at the requested time Lasso will process the URL, allowing Lasso based scripts to be automated.
Let me set the scene
Your client runs a membership-based directory that allows individuals to subscribe to an annual based subscription. However, the client would like an automated system built into the application that would automatically locate all account holders who meet the following criteria and send the account holder an email to alert them that their accounts are coming to a close.
- 28 days left on their annual account
- 7 days left on their annual account
- 1 day left on their annual account
This means if the account holder has not re-subscribed to the membership-based directory, they will be contacted for a total of three times until their account runs out.
Once their account has run out, it will automatically be disabled, until subscription is met.
Normally you would build a script that is built into the administration interface, that allows the client to find all account holders who do not meet the criteria and then allow them to click a button to activate the script to generate the email alerts.
Alternatively you would have an include within a popular part of the web site that does the search behind the scenes to generate the email alerts.
Alternatively you would have a third party plug-in that would activate the need.
What I am suggesting here is that you have the opportunity to use the [Event_Schedule] feature to ensure that the criteria is met without any third party or plug-in interaction and have Lasso automatically process the event.
To do this, we could have a formatted file that sits in the web site folder, then get Lasso run this file at a given time every day to send out our alerts.
For example, the script for checking accounts could look like this:
<?lassoscript // set the days to do the search for within an array. var: 'arrayDayChecks' = (Array: 28, 7, 1); // check the array is not empty if: $arrayDayChecks->size > 0; // run the script against the number of checks we need to do within the array. loop: $arrayDayChecks->size; // create the date variables for the day checks var: 'dLeftF' = (date_add:(date_getcurrentdate),-Day=($arrayDayChecks->(get:(loop_count)))); var: 'dLeft' = (date_format:$dLeftF, -DateFormat='%Y-%m-%d'); var: 'dLeftD' = (date_format:$dLeftF, -DateFormat='%d %b %Y'); // create variable that the alert email will send to the account holder var: 'Alert' = 'Your account is due to expire in ' + ($arrayDayChecks->(get:(loop_count))) + ' day(s) ' + $dLeftD + '\n\n Please access your account and click UPDATE ACCOUNT.\n\nAdministrator'; // create the SQL query that Lasso will use against the directoryApp database var: 'sql_query'= 'SELECT mship.id AS mshipID, users.u_email AS mshipEmail, users.u_fullname AS mshipName FROM mship, users WHERE mship.mship_dt_end = \'' + $dLeft + '\' AND users.u_approved = \'1\';'; // search the database directoryApp against the requested SQL query inline: -database='directoryApp', -maxrecords='all', -SQL=$sql_query; // if there are account holders that match the query, then run the email script. if: (found_count) > 0; rows; // send the email to all found records email_send: -To=(field:'mshipEmail'), -Fromemail@example.com', -Subject=($arrayDayChecks->(get:(loop_count))) + ' Day Deactivation Alert', -Body='Dear ' + (field:'mshipName') + '( ' + (field:'mshipEmail') + ' )\n\n' + $Alert; // ask the server to sleep between every email sent, so not to overload the server. sleep: 20; /rows; /if; /inline; /loop; /if; ?>
Now that we have our search criteria ready, to tell Lasso to run this script every 24 hours no matter, we would place the following piece of code into a lasso formatted file and place the file into the LassoStartup folder.
What the following script is telling Lasso is:
what format file to run, and where to find it.
How often to run the formatted file in minutes 1440 = 24 hours
Tells Lasso not to delete the event when Lasso is restarted, so it will continue to run over and over again against the requested time delay.
<?lassoscript Event_Schedule: -URL='http://www.domain.com/admin/accountchecks.lasso', -Delay='1440', -Repeat=True, ?>
As you can see from the example given, the [Event_Schedule] feature will save a lot of development time, a lot of administration time and offer your client a solution that is perfect for their need.
The [Event_Schedule] feature can obviously be used for any scheduling requirement, and I have been able to customise the functionality to any need a client has had, and I am sure you will have other needs.
You can enhance this script to disable accounts that are past the notice period and more. If this article has got you thinking and has planted the seed that allows you to know that the functionality is available then I am happy.
Now that you hopefully understand what I have been talking about, please take the example within the article and play around with it, using different variations, searches and conditional statements.
As I always say, If you have fun developing it, your clients will have fun using it.