DemptD |
|
---|---|
How can i make it so that the pagination starts on page 1 and not the last page?
because i have set the sortorder to DESC instead of ASC because it looks more chatlike then and the members liked that better. But i have 4 pages with chat messages now and it opens on page 4 with the oldest messages first. How do i make it so that the pagination opens on page 1 always? minichat.functions.php: <?PHP
/**
* Minichat (Shoutbox) on index with jQuery
*
* @package Cotonti
* @version 0.0.4
* @author esclkm
* @copyright Copyright (c) Mikulik Pavel 2008-2009
* @license BSD
*/
if ( !defined('SED_CODE') ) { die("Wrong URL."); }
/**
* Builds minichat_box
*
* @param string $temlate Use temlate for minichat.
* @param bool $ajax Use If loaded by ajax.
* @param bool $jaxpagination Use If ajax paginated.
* @return string
*/
function minichat_build($template, $ajax=false, $ajaxpagination=false)
{
global $usr, $d, $error_string, $cfg, $db_com, $L, $minichatt, $shoutbox;
$mskin = sed_skinfile('minichat', true);
$minichatt = new XTemplate($mskin);
list($usr['auth_read_com'], $usr['auth_write_com'], $usr['isadmin_com']) = sed_auth('plug', 'minichat');
$issetpage=isset($_GET['chatd']);
$d = sed_import('chatd','G','INT');
if (!$usr['auth_read_com'])
{
$error_string.=$L['minichat_noreadrights']."<br />";
}
if (!empty($error_string))
{
$minichatt->assign("MINICHAT_ERROR",$error_string);
$minichatt->parse("MINICHAT".$template.".MINICHAT_ERRORBLOCK");
}
if ($usr['auth_read_com'])
{
$sql = sed_sql_query("SELECT COUNT(*) FROM $db_com WHERE com_code='chat' ");
$totalitems = mysql_result($sql,0,"COUNT(*)");
if(empty($d) || $d<=0 || $d>$totalitems) $d = 0;
if ($template!='_MAIN')
{
$perpage = $cfg['plugin']['minichat']['minichat_recent'];
$sortorder = "ASC";
$panelchat = "&panel=1";
}
else
{
$perpage = $cfg['plugin']['minichat']['minichat_maxperpage'];
if (!isset($_GET['chatd']) && $totalitems!=0) { $d = $perpage * (ceil($totalitems / $perpage)-1); }
$sortorder = "DESC";
$panelchat = "";
}
$sql = sed_sql_query("SELECT * FROM $db_com WHERE com_code='chat' ORDER BY com_id $sortorder LIMIT $d, $perpage ");
if (sed_sql_numrows($sql)>0)
{
while ($row = sed_sql_fetcharray($sql))
{
$minichat_author = sed_cc($row['com_author']);
$minichat_text = sed_cc($row['com_text']);
$minichat_date = @date($cfg['dateformat'], $row['com_date'] + $usr['timezone'] * 3600);
$minichat_date_short= @date($cfg['formatmonthday'], $row['com_date'] + $usr['timezone'] * 3600);
$minichat_admin = ($usr['isadmin_com']) ? " ".$L['Delete'].": <u>[<a href=\"".sed_url("plug", "e=minichat&a=delete&".sed_xg()."&delitem=".$row['com_id'])."\" onclick=\"return ajaxSend({url: 'plug.php?r=minichat".$panelchat."&pag=1&a=delete&".sed_xg()."&delitem=".$row['com_id']."', divId: 'minichatajaxpagination', errMsg: '".$L['ajaxSenderror']."'});\">x</a>]</u>" : '' ;
$minichat_admin_lite= ($usr['isadmin_com']) ? " [<a href=\"".sed_url("plug", "e=minichat&a=delete&".sed_xg()."&delitem=".$row['com_id'])."\" onclick=\"return ajaxSend({url: 'plug.php?r=minichat".$panelchat."&pag=1&a=delete&".sed_xg()."&delitem=".$row['com_id']."', divId: 'minichatajaxpagination', errMsg: '".$L['ajaxSenderror']."'});\">x</a>]" : '' ;
$minichat_authorlink= sed_build_user($row['com_authorid'], $row['com_author']);
$minichatt-> assign(array(
"MINICHAT_ROW_ID" => $row['com_id'],
"MINICHAT_ROW_AUTHOR" => $minichat_authorlink,
"MINICHAT_ROW_TEXT" => sed_parse($minichat_text, $cfg['plugin']['minichat']['minichat_bbcode'], $cfg['plugin']['minichat']['minichat_bbcode'], 1),
"MINICHAT_ROW_DATE" => $minichat_date,
"MINICHAT_ROW_DATE_SHORT" => $minichat_date_short,
"MINICHAT_ROW_ADMIN" => $minichat_admin,
"MINICHAT_ROW_ADMIN_LITE" => $minichat_admin_lite,
));
$minichatt->parse("MINICHAT".$template.".MINICHAT_ROW");
}
$pagnav = sed_pagination(sed_url('plug','e=minichat'), $d, $totalitems, $perpage, 'chatd', 'ajaxSend', "url: 'plug.php?r=minichat&pag=1".$panelchat."', divId: 'minichatajaxpagination', errMsg: '".$L['ajaxSenderror']."'");
list($pagination_prev, $pagination_next) = sed_pagination_pn(sed_url('plug','e=minichat'), $d, $totalitems, $perpage, TRUE, 'chatd', 'ajaxSend', "url: 'plug.php?r=minichat&pag=1".$panelchat."', divId: 'minichatajaxpagination', errMsg: '".$L['ajaxSenderror']."'");
$minichatt-> assign(array(
"MINICHAT_PAGENAV" => $pagnav,
"MINICHAT_PREV" => $pagination_prev,
"MINICHAT_NEXT" => $pagination_next,
));
$minichatt->parse("MINICHAT".$template.".MINICHAT_PNAV");
}
else
{
$minichatt-> assign("MINICHAT_EMPTYTEXT", $L['minichat_empty']);
$minichatt->parse("MINICHAT".$template.".MINICHAT_EMPTY");
}
if ($usr['auth_write_com'] && !$ajaxpagination)
{
$minichatt->assign(array(
"MINICHAT_FORM_SEND" => "action=\"plug.php?e=minichat\" id=\"minichat_form\" onSubmit=\"return ajaxSend({method: 'POST', formId: 'minichat_form', url: 'plug.php?r=minichat".$panelchat."', divId: 'minichatajax', errMsg: '".$L['ajaxSenderror']."'});\"",
"MINICHAT_FORM_TXT" => "name=\"shoutbox\"",
"MINICHAT_FORM_TEXT" => $shoutbox,
));
$minichatt->parse("MINICHAT".$template.".MINICHAT_FORM");
}
if(!$ajax && !$ajaxpagination)
{
$minichatt->assign(array(
"MINICHAT_DIV_AJAX_BEGIN" => "<div id=\"minichatajax\">",
"MINICHAT_DIV_AJAX_END" => "</div>",
"MINICHAT_LINK" => "<a href=\"plug.php?e=minichat\">".$L['minichat_history']."</a>",
));
}
if ($ajax && !$ajaxpagination)
{ $minichatt->assign("MINICHAT_DIV_AJAX_BEGIN", '<script type="text/javascript">
//<![CDATA[
mini.previewAutorefresh = false;
mini.previewParserPath = "plug.php?r=markitup&x=CAB73666";
$(document).ready(function() {$("textarea.minieditor").markItUp(mini);});
//]]></script>');
}
if(!$ajaxpagination)
{
$minichatt->assign(array(
"MINICHAT_DIV_AJAXPAGINATION_BEGIN" => "<div id=\"minichatajaxpagination\">",
"MINICHAT_DIV_AJAXPAGINATION_END" => "</div>",
));
}
if($template!='_MAIN')
{$autoreloadtime = $cfg['plugin']['minichat']['minichat_recenttimer'];}
else
{$autoreloadtime = $cfg['plugin']['minichat']['minichat_timer'];}
if(!isset($_GET['chatd']) && $autoreloadtime && !$ajax)
{
$autoreload="<script type=\"text/javascript\">
var time=".$autoreloadtime."*1000;
var interval;
interval = setInterval(\"ajaxSend({url: '".sed_url('plug', 'r=minichat')."', data: '&pag=1".$panelchat."', divId: 'minichatajaxpagination', errMsg: '".$L['ajaxSenderror']."'})\", time);
</script>";
$minichatt->assign("MINICHAT_TIMER", $autoreload);
}
if(isset($_GET['chatd']))
{
$autoreload="<script type=\"text/javascript\">clearInterval(interval);</script>";
$minichatt->assign("MINICHAT_TIMER", $autoreload);
}
}
$minichatt->parse("MINICHAT".$template);
}
/**
* ckeck for errors minichat message
* add mew message or delete old message
*
* @return nothing
*/
function minichat_action()
{
global $usr, $error_string, $cfg, $db_com, $L, $shoutbox, $sys;
list($usr['auth_read_com'], $usr['auth_write_com'], $usr['isadmin_com']) = sed_auth('plug', 'minichat');
$shoutbox = trim(sed_import('shoutbox','P','HTM'));
if (!empty($shoutbox) && $usr['auth_write_com'])
{
sed_shield_protect();
$poster_name = $usr['name'];
$poster_id = $usr['id'];
$error_string .= (mb_strlen($shoutbox)<$cfg['plugin']['minichat']['minichat_minchars']) ? $L['minichat_short_message']."<br />" : '';
$error_string .= (mb_strlen($shoutbox)>$cfg['plugin']['minichat']['minichat_maxchars']) ? $L['minichat_long_message']."<br />" : '';
$error_string .= ($poster_id==0) ? $L['minichat_nouser_message']."<br />" : '';
$error_string .= (!$usr['auth_write_com']) ? $L['minichat_nowriterights']."<br />" : '';
if (empty($error_string))
{
$sql = sed_sql_query("INSERT INTO $db_com (com_code, com_author, com_authorid, com_text, com_date,com_isspecial) VALUES ('chat', '".sed_sql_prep($poster_name)."', '".(int)$poster_id."', '".sed_sql_prep($shoutbox)."', '".$sys['now_offset']."', '1')");
sed_shield_update(20,"New minichat message");
$shoutbox='';
}
}
$a = sed_import('a','G','TXT');
if ($a=='delete' && $usr['isadmin_com'])
{
sed_check_xg();
$deleteitem = sed_import('delitem','G','INT');
$sql = sed_sql_query("DELETE FROM $db_com WHERE com_id='$deleteitem'");
sed_log("Deleted minichat message #".$deleteitem."",'adm');
}
}
?>
|