Yesterday I was asked to implement something interesting on a Joomla Intranet, a one time popup poll. The requirement was to show a few questions in a modal popup window, so some feedback could be obtained from the users. This modal window needed to be launched immediately when the user visits a particular page on the Intranet, and not have to rely on a user clicking a link. We also only wanted each user to fill out the poll once.


The poll side of things was easy, I decided to use a survey extension that I developed, in this case BF Survey Pro because it's a Joomla 1.5 site, but you could do exactly the same thing on Joomla 2.5 or Joomla 3 using BF Survey Plus. The tricky bit was how to launch a modal window immediately, rather than forcing the user to click on a link or a button.

So I asked my good mate Google, and found a possible solution from Kirby.

This seems like a good starting point, but then I came across this better solution which didn't require an <a> element.

Unfortunately the Intranet site is still Joomla 1.5 (I'm currently in the process of upgrading to Joomla 3), and Joomla 1.5 does not support the SqueezeBox.open, so I ended up using the SqueezeBox.fromElement function. Since the user is already authenticated via Active Directory single sign on, the email address is automatically populated, so I'm using that to determine if the user has already filled out the poll yet, in which case they wont be prompted again. So here is the code I ended up with.

<?php JHTML::_('behavior.modal'); ?>

<?php
$user = &JFactory::getUser();
$db =& JFactory::getDBO();
$query = "SELECT * FROM jos_bfsurveypro_95 where Email='".$user->email."'";
$db->setQuery( $query);
$result=$db->loadResult();

if(!count($result)){
?>

<script>
window.addEvent('domready', function() {
   SqueezeBox.initialize();

    var feedback = new Element('a', {
    'href': "http://intranet/index.php?option=com_bfsurvey_pro&view=onepage&catid=95&Itemid=203&tmpl=component",
    'rel' : "{handler: 'iframe', size: {x: 650, y: 575}}"
    });

    SqueezeBox.fromElement(feedback);

});
</script>

<?php
}
?>


In Joomla 3 (like this site), this code would do the something similar with BF Survey Plus.


<?php JHTML::_('behavior.modal'); ?>

<?php
$user = JFactory::getUser();
$db = JFactory::getDbo();

$query    = $db->getQuery(true);
$query->from('#__bfsurveyplus_11 AS a');
$query->select('a.*');
$query->where('a.Email = '.$db->quote( $db->escape($user->email)));

$db->setQuery((string)$query);
$result=$db->loadResult();

if(!count($result)){
?>

<script>
window.addEvent('domready', function() {

   SqueezeBox.open("http://intranet/index.php?option=com_bfsurvey_plus&view=onepage&catid=11&Itemid=145&tmpl=component", {
       handler: 'iframe',
       size: { x: 500, y: 300 }
   });

});
</script>

<?php
}
?>

Leave your comments

Post comment as a guest

0
Your comments are subject to administrator's moderation.

People in this conversation

  • Guest - peter

    Thanks for coding you provided, it helps to know the information about the users who already filled the info. It's a helpful info when the process of upgrading joomla takes place.

  • Guest - KathyDaunt

    Thanks for the technical post. Its a new information what I learnt on today. New code on Joomla 1.5