At least once a week I am approached with a rewrite or modification to someone else’s code. I decided to take on the most recent mod for a friend and am not enjoying it one bit. It is getting harder and harder for me to take on new projects because of garbage like this :
What the hell kind of form validation is that?!
My question is how does this pass company standards? How are people getting away writing this rubbish and being paid top dollar over someone who codes to standards and follows MVC.
I am definitely no PHP guru – but for god sakes start writing maintainable code people!
If you are wondering what inspired this rant – take a gander at this gimmicky product… I need a drink.
Displaying HTML rows with offset background colours is a great way to present large amounts of data in a table – plus it looks nice.
Here are a few ways I display data in this format :
1. PHP Method (for use with browsers with no JavaScript or CSSv3)
We set a variable (i) to the value of 1. We then add 1 to i until it reaches 10. Within the loop we determine if there is a remainder when dividing i by 2, this lets us know if the number is even or odd. We add an odd class to every odd table row – and and even class to every even table row.
Why choose this method :
Choose this method when you know your users will be using older browsers or are unsure if they have javascript enabled.
2. CSSv3 Method (For use with newer browsers)
How it works :
CSS sets the ‘nth-child’ to use the defined background colour.
Why choose this method :
Simplicity!, however beware of outdated browsers.
3. jQuery (for use with JavaScript enabled browsers)
How it works :
Similarly to the CSSv3 method above – however does not require CSSv3 support in the browser. It adds the class ‘odd’ to every other row in the table.
Why choose this method :
Simple to implement however requires JavaScript – do not forget to load jQuery in your document head!
This is a great technique for use with large forms with many values you need to save. It can get in the way if you need individual validation for each value – however it can save a whole ton of time when submitting any number of form fields.
The video isn’t super high quality so I have attached the source here.
This morning I added Growl notifications to Asteristickies using a wonderful PHP class found here.
You do not need to add any third party software to make this work, presuming you have Growl already installed. Configuration is minimal and notifications can be sent to any routable hostname . address.
This weeks project has been a huge learning curve for both Asterisk and communicating with a remote web server. Here are the project goals :
- End user (EU from now on) creates an account on web server.
- EU Inputs their phone number.
- EU immediately receives a call with a random 6 digit number (PIN).
- EU inputs the PIN into the web interface and is now validated.
- EU schedules when they want to be called.
When the user is called, they are sent to an IVR (interactive voice menu) – here is how that should work.
- EU answers the call.
- EU hears prompt to press 1, 2 or 3.
- EU presses 1 and hears a prompt with instructions (it is a breathing exercise)
- EU presses pound to initiate timer and pound once again to end their session.
- EU hears prompt directing them to visit web panel to access results.
OK so you see how this is supposed to work – let me explain how I did it.
Step 1. Phone Number Validation
The user enters their phone number in three separate boxes which are heavily processed for error checking and validation. The number is stored in the database and they are sent to the next page of the wizard. This page displays a button to initiate the call with a text input box below for the phone pin. A random 6 digit number is generated, inserted into the database and also passed to the AMI. An Originate action is called sending the EU to a passwd-verify-custom context in the dial plan.
The EU hears a prompt to wait for their verification number – the six digit number passed from the web server is then read to the EU using SayDigits(${UserPin}). As soon as they enter the PIN in the text box, their phone number is validated and they can begin receiving scheduled calls.
Step 2. Scheduling Calls
The EU is presented with several drop downs : Day (Sunday to Saturday), Hour (01 – 12), Minute (01 – 59), Time (AM – PM). Once the time is selected and the submit button is pressed, an asynchronous post is sent back to the web server for validation and insertion into the database.
It was super easy to run the schedule without having to SCP .call files or open more holes on the Asterisk system. I simply run a cron job every minute that pings a listening PHP script on the web server. PHP queries the database to see if anyone has a call scheduled and has validated their number, PHP will loop through the results creating a new AMI event passing the users unique ID as a dial plan variable.
Part 3. Collecting Key Press Event Data
The IVR is very straight forward. It is used to determine the EPOCH second for the start and stop time for this breathing exercise. On key press, Asterisk runs System(/usr/bin/curl -d “userid=${UserId}&action=start&time=${EPOCH}&key=someuniquehash” <http://tld/script.php>)
This sends back to the web server the following data :
User ID – the user ID sent to the AMI from the web server : Now we know who we called
Action – Start, Stop : Now we know whether to insert or update the record
Time – The Epoch time stamp : Now we know when the key was pressed.
Key – A long string of random characters : This way no one can inject false data from their browser.
Once the phone session is complete, the user can login to their panel and view in depth statistics and compare month and year breathing fluctuation times in an easy to read bar graph.
The key things I have learned during creation of this application will allow me to do anything in the field of Web + Phone integration.
Passing a variable to the dial plan from an AMI event is by far the most powerful:
Variable : <VariableName> = <VariableValue>
This can now be accessed in the dial plan using ${VariableName}
I am creating a video demonstrating how to use the application (for end users) – I will post it up here when it is done. If you want to try it yourself check out Control Pause.







