Barcode validation/check-in

Infinium - October 27, 2009 - 19:59

Hello everyone.

We're a small team of student developers new to Drupal. We have been designing a module that will:
-Interact with the CiviCRM (CiviEvent) module
-Give event hosts the option to embed barcodes within confirmation e-mails sent to folks who register for the event
-Registered participants may print off the e-mail and check-in to an event by scaning the attached barcode

In the beginning we wanted to modify the CiviEvent code. Eventually it was decided that we would build a Drupal module. Thus far, our module can only check-in/validate participants. The barcode scanner works fine. We also have the code ready for generating barcodes.

These are the issues we're facing:

-Is there a Drupal API function to know the existing databases and how do we know which one is used for CiviCRM? How do we know which is the default for Drupal? Currently, we are working with two databases (though our client may have a different database structure).

-Consider this: An admin hosts a new event and checks the "Embed barcodes" option, which allows barcodes to be generated and sent along with confirmation e-mails to users who register for said event. Our problem: We need a way to modify that e-mail to include the barcode, but without touching any code in the CiviCRM module. Is there any way our module can "intercept" the e-mail before it is sent, modify it, then mail it out?

Thanks for your support.

Question 1) Not that I know

Jay Matwichuk - October 28, 2009 - 01:17

Question 1)
Not that I know of. I recently had to write a database transfer script from one Drupal database to another that was completely different. The fields were all the same, but the original database was a compilation of about 50 modules, while the new one held one module that combined all the bits and pieces that the 50 modules were doing on the other database. To do this, I did a couple of things:
- I installed a fresh Drupal installation. I looked at the database and how many rows were in each table, and I then created a node, and compared how many rows were in each table. This allowed me to tell which tables were affected when creating nodes
- I then created nodes, using dummy values with words that didn't exist. After that I ran a search on the entire database to see where these values ended up. In this way I was able to map the Drupal system to the tables and columns of the database

There may very well be a different way to do this, but if you don't find one, then the above method is tested and true, though it takes a fair bit of time and work to analyze.

Question 2)
hook_mail_alter()

Is it possible to make

Infinium - October 29, 2009 - 15:19

Is it possible to make hook_mail_alter() work on e-mails being sent out by other modules?

Yes, it works on any mail.

Jay Matwichuk - October 29, 2009 - 18:27

Yes, it works on any mail. You just need to find out the ID of the mail being sent (this will be the same each time a particular mail is sent).

I usually do something like this. To get the ID, I will create the alter function like this:

<?php
function modulename_mail_alter(&$message)
{
  die(
$message['id']);
}
?>

Then I trigger whichever mail in particular it is that you want to alter. The system then dies and outputs the ID to the screen. So lets say that the id is 'modulename_mymail'. Next I will change my function to this:

<?php
function modulename_mail_alter(&$message)
{
  if(
$message['id'] == modulename_mymail)
  {
   
// make your changes to $message here. This will change the mail being sent.
 
}
}
?>

If you need to see the contents of $message so you can know exactly what to change, a good piece of code is this:

<?php
function modulename_mail_alter(&$message)
{
  echo
'<pre>', print_r($message), '</pre>';
  die;
}
?>

This gives you the contents of $message laid out in an easy to read format.

Thanks! On a side note, we're

Infinium - October 31, 2009 - 01:14

Thanks!

On a side note, we're trying to add the functionality so that when our barcode module is enabled it automatically creates a custom field for the "Embed barcode?" checkbox option, along with the new tables in the database etc.

Is there a set of Drupal API functions to assist us with this?

you can use hook_install(),

Jay Matwichuk - October 31, 2009 - 12:53

you can use hook_install(), hook_uninstall() and hook_schema() for creating your database tables (and deleting them when the module is uninstalled). You can use hook_form_alter() to add a checkbox to whatever forms you want to add it to.

any progress? Hi I would be

stijnthe1st - November 4, 2009 - 13:23

any progress?

Hi I would be intrested in purchasing this setup.

This system is open source,

Infinium - November 5, 2009 - 15:56

This system is open source, so once it's finished it will be available for anyone use. I believe it's worth mentioning that this module is only designed to function as an extension to CiviCRM (Events, specifically).

For the heck of it, here's a summary of our progress and who we are:

We're a small team of college students developing a Drupal module which allows participants to check-in at events using a barcode (or, if a scanner is unavailable, the barcode's numeral code). This barcode, which is generated at the point of a participant registering for an event through a web application, is attached to confirmation e-mails and sent to the newly-registered users.

Currently we have a working demo which does everything noted above. The problem is that the current solution is a little hacked up by us, so we need to clean it up (so that critical code is moved out of their source, and in to a smarty template).

We still have yet to implement a useful feature that automatically adds an "Embed barcode" checkbox in the administrator's "Create a new event" page. It's possible to add this manually though a custom data field, but we can do something much more elegant than that.

Subscribing

Cayenne - November 5, 2009 - 01:26

This was on my "to do" list!

Need help?

---------------------

"He's said to be outspoken, but nobody's actually seen anyone do it"

Sure. Do you know anything

Infinium - November 7, 2009 - 22:03

Sure. Do you know anything about Smarty templates?

We're trying to attach the barcode to the e-mail by modifying the existing template, but it's giving some resistance... ideally the barcode would either be an attachment, or embedded directly into the e-mail. We're waiting for response from the folks in the Smarty forums.

Any ideas? Alternatives?

Wow! I know nothing about

Cayenne - November 8, 2009 - 20:14

Wow!

I know nothing about Smarty Templates!

I assume, however, that the barcode is rendered as an image and only needs embedding, yes?

---------------------

"He's said to be outspoken, but nobody's actually seen anyone do it"

Bingo. Our present solution

Infinium - November 8, 2009 - 22:13

Bingo.

Our present solution is that we're modifying existing source files within CiviCRM to make their own API calls to attach an image to an email, but this isn't as elegant as only modifying the template alone.

One of the problems is that their API calls make use of the PEAR mailing package. This is an issue for us because:
- We're short on time (code freeze on the 20th!)
- We've got midterms and assignments due in other classes this and next week
- We're suffering from information overload... Drupal, SQL, PHP, CiviCRM/CiviEvent, Apache/SMTP server setup... all picked up within about 30 days alongside material from other classes

We've posted in the Smarty and PEAR forums without any response. Our client doesn't care whether or not we modify their files, but we'd like to keep the scope of our little project strictly within new files.

as far as I know the smarty

stijnthe1st - November 9, 2009 - 13:52

as far as I know the smarty problem is the least. If you succeed in generating a barcode as a jpg.
You store it somewhere - somehow and then you make reference to this picture in smarty. If you want I can have a look.
Just describe clearly what the actual setup is in order to loose the minimum of time.

we can synchronise via skype / msn /

kind regards,

Stijn

 
 

Drupal is a registered trademark of Dries Buytaert.