19
And so I did, however I managede to ¤4# up my website totally and had to restore from backup hehe... (rule nr one, if you are not sure what your doing don't do it on your website use a local test server) :) well being that more clever I managed to make the thing go using both a simple small ajax rutine and jquery (looks better)..
Now my problem is that, eventhough it runs, updates, it doesnt change the divs but seem to be using cached values. This is what I got so far.
1) The block main function runs using template 1.
2) block function 1 doesnt really do anything except set the block template 1.
2.1) this template 1 has ajax that calls block function #2 + block template 2 and run the function to fill template2 used in filling the divs in visible block 1.
3) this rutine is being run every 10 seconds.
(confused? I understand! Its a mess but I'm picking up a small notes as I go along hopefully).
here are the functions
Block function 1
Quote:
/**
* Onair Module
*
* Use this to show details, picture and schedule of timed events in a block.
*
* LICENSE
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Michael Albertsen (culex) <http://www.culex.dk>
* @version $Id:simple_now.php 2009-06-19 13:29 culex $
* @since File available since Release 1.0.0
*/
/**
* Create data for block
*
* @param Place $Block getting data
* @param integer $repeat 1
* @return Status
*/
function b_Onair_Show() {
include_once XOOPS_ROOT_PATH.'/modules/onair/include/functions.php';
global $xoopsDB,$xoopsModuleConfig, $XoopsConfig;
$oa_lng = onair_GetModuleOption('language');
if ( file_exists(XOOPS_ROOT_PATH.'/modules/onair/language/'.$oa_lng.'/blocks.php') ) {
include(XOOPS_ROOT_PATH.'/modules/onair/language/'.$oa_lng.'/blocks.php');
}
else {
include(XOOPS_ROOT_PATH.'/modules/onair/language/english/blocks.php');
}
// Get data now
$nowday=date('w');
// Set absolute maximum time of the day
$nextstop="23:59:59";
// Get dir, hight, width, and timetype from config
$oa_imagedir = onair_GetModuleOption('imagedir');
$oa_shothigh = onair_GetModuleOption('shotheight');
$oa_shotwide = onair_GetModuleOption('shotwidth');
$timetype = onair_GetModuleOption('timetype');
// IF timetype = American (12 hour am/pm)
if ($timetype=='1')
{ $nowtime =date('h:i:s a'); }
// IF european time (24 hour)
else if ($timetype=='0'){$nowtime =date('H:i:s');}
$block = array();
$myts =& MyTextSanitizer::getInstance();
// Get data according to current time
$sql = "SELECT * FROM ".$xoopsDB->prefix("oa_program")." WHERE ('$nowtime' BETWEEN oa_start AND oa_stop) AND '$nowday' = oa_day ORDER BY oa_day,oa_start LIMIT 1";
$result=$xoopsDB->queryF($sql);
if ($xoopsDB->getRowsNum($result)>'1') {
$dayoffset='1';
} else {
$dayoffset='0';
}
while($myrow=$xoopsDB->fetchArray($result))
{
$limiter = $myrow['oa_stop'];
$message = array();
$oa_pluginname = $myrow['oa_plugin'];
include XOOPS_ROOT_PATH.'/modules/onair/plugins/plugins.php';
$message['id'] = $myrow['oa_id'];
$message['day'] = onair_Numbers2DaysBlock($myrow['oa_day']);
if ($timetype=='1'){
$message['start'] = date('h:i:s a', strtotime($myrow['oa_start']));
$message['stop'] = date('h:i:s a', strtotime($myrow['oa_stop']));
$nextstop = date('h:i:s a', strtotime($myrow['oa_stop']));
} else if ($timetype=='0'){
$message['start'] = date('H:i:s', strtotime($myrow['oa_start']));
$message['stop'] = date('H:i:s', strtotime($myrow['oa_stop']));
$nextstop = date('H:i:s', strtotime($myrow['oa_stop']));
}
$title = $myts->stripSlashesGPC($myrow["oa_title"]);
$message['title'] = $title;
$station = $myts->stripSlashesGPC($myrow["oa_station"]);
$message['station'] = $station;
$name = $myts->stripSlashesGPC($myrow["oa_name"]);
$message['name'] = $name;
$description = $myts->stripSlashesGPC($myrow["oa_description"]);
$message['description'] = $description;
$image = $myrow["oa_image"];
$message['image'] = "";
$message['host'] = _MB_ONAIR_HOST;
$block['onair'][] = $message;
}
if ($nowday =='6'|$dayoffset>'0'){
$nowday2 = '0';
} else {
$nowday2 = $nowday + $dayoffset;
}
// Get data according to upcomming event
$sqlnext = "SELECT * FROM ".$xoopsDB->prefix("oa_program")." WHERE '$nextstop' <= oa_start AND '$nowday2' = oa_day order by oa_start, oa_stop LIMIT 1";
$resultnext=$xoopsDB->queryF($sqlnext);
if ( $resultnext ){
while($myrownext=$xoopsDB->fetchArray($resultnext))
{
$messagenext = array();
$messagenext['id'] = $myrownext['oa_id'];
$messagenext['day'] = onair_Numbers2DaysBlock($myrownext['oa_day']);
if ($timetype=='1'){
$messagenext['start'] = date('h:i:s a', strtotime($myrownext['oa_start']));
$messagenext['stop'] = date('h:i:s a', strtotime($myrownext['oa_stop']));
} else {
$messagenext['start'] = date('H:i:s', strtotime($myrownext['oa_start']));
$messagenext['stop'] = date('H:i:s', strtotime($myrownext['oa_stop']));
}
$titlenext = $myts->stripSlashesGPC($myrownext["oa_title"]);
$messagenext['title'] = $titlenext;
$stationnext = $myts->stripSlashesGPC($myrownext["oa_station"]);
$messagenext['station'] = $stationnext;
$namenext = $myts->stripSlashesGPC($myrownext["oa_name"]);
$messagenext['name'] = $namenext;
$descriptionnext = $myts->stripSlashesGPC($myrownext["oa_description"]);
$messagenext['description'] = $descriptionnext;
$imagenext = $myts->stripSlashesGPC($myrownext["oa_image"]);
$messagenext['image'] = "";
$messagenext['comup'] = _MB_ONAIR_COMINGUP;
$block['onair2'][] = $messagenext;
}
}else{
echo mysql_error();
return false;
}
return $block;
}
?>
Block Template 1
Quote:
The file called by ajax is this, showing the dummy template filled again with data from block function 1.
Quote:
include '../../mainfile.php';
include_once (XOOPS_ROOT_PATH.'/class/template.php');
include_once(XOOPS_ROOT_PATH.'/modules/onair/blocks/simple_now.php');
$tpl = new XoopsTpl();
$result = b_Onair_Show();
$tpl->assign('block', $result);
$tpl->display('db:onair_ajax.html');
?>
And finaly the dummy module block template #2 called back by ajax to split and fill the divs in block template #1
Quote:
<{foreach item=message from=$block.onair}>
<{$message.station}>
<{$message.title}>
<{$message.image}>
<{$message.host}><{$message.name}>
<{$message.pluginshow}>
<{$message.day}>
<{$message.start}> - <{$message.stop}>
,,,,
<{foreach item=messagenext from=$block.onair2}>
<{$messagenext.comup}>
<{$messagenext.station}>
<{$messagenext.title}>
<{$messagenext.image}>
<{$messagenext.host}><{$messagenext.name}>
<{$messagenext.day}>
<{$messagenext.start}> - <{$messagenext.stop}>
<{/foreach}>
<{/foreach}>
I tried every thing setting
$tpl->xoops_setCaching(0);
$tpl->xoops_setCacheTime(0);
Using
etc etc but nothing.. Hope I am just missing something very simple :-S, or I'' just make meta http-equiv="refresh" content="60"> in block template but this is not optimal I think, but simple and will definitatly work
Programming is like sex:
One mistake and you have to support it for the rest of your life.