Добрый день! (Joomla 3, JS 2.8.4)
Необходимо вывести Ajax-счетчик новых сообщений в стандартное меню Joomla (Main menu).
Вывести из БД кол-во сообщений получается, но с перезагрузкой страницы. Также получилось AJAX обновление переменной, прописанной в файле, который лежит в корне сайта. Никак не получается объединить это вместе.
Вот что есть.
Начало файла modules/mod_menu/tmpl/default.php:
defined('_JEXEC') or die;
include_once JPATH_ROOT.'/components/com_community/libraries/core.php';
// Note. It is important to remove spaces between elements.
header('Content-Type: text/javascript; charset=UTF-8');
?>
</ul>
<script type="text/javascript">
function show()
{
$.ajax({
url: 'http://mysite.ru/ajax.php',
type: 'Get',
dataType: 'json',
cache: false,
success: function(html){
$("#bage").html('+' + html);
}
});
}
$(document).ready(function(){
show();
setInterval('show()',5000);
});
</script>
Файл /ajax.php
<?php
$count = 7;
echo $count;
?>
А нужно, чтобы отработал код ниже вместо того, что сейчас в AJAX.php:
$my = CFactory::getUser();
$uId = $my->id;
if(!function_exists('myOwnFunc'))
{
function myOwnFunc($filter)
{
$db = JFactory::getDBO();
$unRead = 0;
// Skip the whole db query if no user specified
if(empty($filter['user_id']))
return 0;
$sql = 'select count('.$db->Quote('1').') as '.$db->quoteName('unread_count');
$sql .= ' from '.$db->quoteName('#__community_msg_recepient');
$sql .= ' where '.$db->quoteName('is_read').' = '.$db->Quote('0');
if(! empty($filter['parent']))
$sql .= ' and '.$db->quoteName('msg_parent').' =' . $db->Quote($filter['parent']);
if(! empty($filter['user_id']))
$sql .= ' and '.$db->quoteName('to').' =' . $db->Quote($filter['user_id']);
$sql .= ' and '.$db->quoteName('deleted').' = '.$db->Quote('0');
$db->setQuery($sql);
$result = $db->loadObject();
if(! empty($result)){
$unRead = $result->unread_count;
}
return $unRead;
}
$count = (int)myOwnFunc( array( 'user_id' => $uId ) );
echo $count;