getPath( 'class', 'com_chronocontact' ) );
// the class name must be the same as the file name without the .php at the end
class cf_watchman
{
//the next 3 fields must be defined for every plugin
var $result_TITLE = "Watchman";
var $result_TOOLTIP = "Open or close your form for different users, or different dates or times.";
var $plugin_name = "cf_watchman"; // must be the same as the class name
var $event = "ONLOAD"; // must be defined and in Uppercase, should be ONSUBMIT, ONLOAD or ONLOADONSUBMIT
// the next function must exist and will have the backend config code
function show_conf($row, $id, $form_id, $option)
{
global $mainframe;
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'plugin.php');
$helper = new ChronoContactHelperPlugin();
$doc->addScript(JURI::base().'components/com_chronocontact/assets/timespinner/timespinner.js');
$doc->addStylesheet(JURI::base().'components/com_chronocontact/assets/timespinner/timespinner.css');
// identify and initialise the parameters used in this plugin
$params_array = array(
'redirect_url' => 'index.php',
'gid' => '29',
'redirect_message_users' => '',
'open' => '',
'redirect_message_open' => '',
'close' => '',
'redirect_message_close' => '',
'days' => '1|2|3|4|5|6|0',
'redirect_message_days' => '',
'open_time' => '',
'redirect_message_open_time' => '',
'close_time' => '',
'redirect_message_close_time' => '',
'debug' => '0');
$params = $helper->loadParams($row, $params_array);
?>
addStyleDeclaration($style);
if ( $script ) $doc->addScriptDeclaration($script);
}
function onload( $option, $row, $params, $html_string )
{
global $mainframe;
$user =& JFactory::getUser();
if ( $params->get('debug') ) {
$style = "div.cf_debug {border:1px solid red; padding:6px;}";
$doc =& JFactory::getDocument();
$doc->addStyleDeclaration($style);
}
$redirected = false;
if ( $params->get('debug') ) {
echo "Debug information
Params: ".print_r($params, true)."
";
}
if ( !$params->get('redirect_url') ) {
$params->set('redirect_url', 'index.php');
}
// Check user groups
// Convert singleton group to array
if ( !is_array($params->get('gid')) ) {
$params_gid = array($params->get('gid'));
} else {
$params_gid = $params->get('gid');
}
if ( !in_array($user->gid, $params_gid)
&& !($user->guest && in_array('29', $params_gid)) ) {
if ( $user->guest ) {
$gid = 'user: guest';
} else {
$gid = 'user: '.$user->gid;
}
$redirected = self::redirect('users', $params, 'User groups ('.implode(', ', $params_gid).' ['.$gid.'])');
}
// Check opening date & time
if ( $params->get('open') && strtotime($params->get('open')) > time() ) {
$redirected = self::redirect('open', $params, 'Open date ('.$params->get('open').')');
}
// Check closing date & time
if ( $params->get('close') && strtotime($params->get('close')) < time() ) {
$redirected = self::redirect('close', $params, 'Close date ('.$params->get('close').')');
}
// Check day of the week
if ( $params->get('days') && !in_array( date('w'), $params->get('days')) ) {
$redirected = self::redirect('days', $params, 'Days of the week ('.implode(', ', $params->get('days')).') '.date('w').'');
}
// Check opening time
$open_minutes = self::getMinutes($params->get('open_time'));
$close_minutes = self::getMinutes($params->get('close_time'));
$now_minutes = self::getMinutes(date('H:i'));
if ( $open_minutes != 0 && $now_minutes < $open_minutes ) {
$redirected = self::redirect('open_time', $params, 'Daily open('.$params->get('open_time').')');
}
if ( $close_minutes != 0 && $now_minutes > $close_minutes ) {
$redirected = self::redirect('close_time', $params, 'Daily open('.$params->get('close_time').')');
}
// show debug 'no redirection message'
if ( $params->get('debug') && !$redirected ) {
echo "No redirection - form is available.
";
}
return $html_string;
}
function redirect($label, $params, $type='' )
{
global $mainframe;
$redirect = "";
if ( $params->get($label) ) {
$redirect = "redirect_message_$label";
$redirect = $params->get($redirect);
}
if ( !$params->get('debug') ) {
$mainframe->redirect( $params->get('redirect_url'), $redirect);
return false;
} else {
echo "$type
Redirecting Now !!!! to $params->get('redirect_url') with message: ".$redirect."
";
return true;
}
}
function getMinutes($time)
{
$time_array = explode(':', $time);
if ( !isset($time_array[1]) ) {
$time_array[1] = 0;
}
return $time_array[0] * 60 + $time_array[1];
}
// this function must exist and may not be changed unless you need to customize something
function save_conf( $option )
{
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'plugin.php');
$helper = new ChronoContactHelperPlugin();
$helper->save_conf($option);
}
}
?>