UBB.Dev
Posted By: bostongio Beta-[6.4] Paginate PMs - 06/21/2005 1:06 AM
Mod Name / Version: Paginate PMs

Description: This mod puts your PMs into pages (much like forum threads are), which is especially helpful to your users who keep a lot of their PMs lying around.

This code is a simple cut and paste from this functionality found within postlist.php, adapted for use with PMs.



Working Under: UBB.Threads 6.4

Mod Status: Beta

Any pre-requisites:

Author(s): bostongio

Date: 06/20/05

Credits: UBBthreads

Files Altered: viewmessages.php
templates/default/viewmessages.tmpl

New Files:

Database Altered: No

Info/Instructions: In viewmessages.php

Find:

Code
<br />// ---------------------------------------------------------<br />// Ok, we found the profile, now lets put it all onto a page<br />   $html -> send_header("$ubbt_lang[$box]",$Cat,0,$user);<br />


Replace with:

Code
<br />// ---------------------------------------------------------<br />// Ok, we found the profile, now lets put it all onto a page<br />   $html -> send_header("$ubbt_lang[$box]",$Cat,0,$user);<br /><br /><br />// -----------------------------------------<br />// Find out how many posts to show per  page<br />   if (!$PostsPer) {<br />      $PostsPer = $theme['postsperpage'];<br />   }<br /><br />// ---------------------------------------------------------------------<br />// Now we calculate which posts to grab for this page.  We want to grab<br />// one from the previous page and one from the next page so we know what<br />// the previous and nexts posts will be<br />   if (!($page > 0)) {<br />      $Totalgrab = $PostsPer + 1;<br />      $Posts     = $PostsPer + 1;<br />   }<br />   else {<br />      $Startat   = $page * $PostsPer;<br />      $Posts     = $PostsPer + 1;<br />      $Totalgrab = "$Startat, $Posts";<br />   }<br /><br />   $endpage = 1;<br />   $limit = "LIMIT $Totalgrab";<br /><br />


-------------------------------------------------------------------
Find:

Code
<br />// -------------------------<br />// Get any private messages.<br />   $username_q = addslashes($Username);<br />   $query = "<br />    SELECT t1.M_Status, t1.M_Subject, t1.M_Sender, t1.M_Sent, t1.M_Number, t2.U_Username<br />    FROM   {$config['tbprefix']}Messages AS t1,<br />                          {$config['tbprefix']}Users AS t2<br />    WHERE  t1.M_Uid = '{$user['U_Number']}'<br />    AND    t1.M_Status $extra 'X'<br />         AND      t1.M_Sender = t2.U_Number<br />    ORDER BY t1.M_Sent DESC<br />   ";<br />   $sth = $dbh -> do_query($query);<br /><br />   $i = 0;<br />


Replace with:

Code
<br /><br />// -------------------------<br />// Get any private messages.<br />   $username_q = addslashes($Username);<br />   $query = "<br />    SELECT t1.M_Status, t1.M_Subject, t1.M_Sender, t1.M_Sent, t1.M_Number, t2.U_Username<br />    FROM   {$config['tbprefix']}Messages AS t1,<br />                          {$config['tbprefix']}Users AS t2<br />    WHERE  t1.M_Uid = '{$user['U_Number']}'<br />    AND    t1.M_Status $extra 'X'<br />         AND      t1.M_Sender = t2.U_Number<br />    ORDER BY t1.M_Sent DESC<br />    $limit<br />   ";<br />   $sth = $dbh -> do_query($query);<br /><br />   $i = 0;<br /><br />// -------------------------------------------------------------------<br />// If $page is greater than 0 then we need a link to the previous page<br />   if ($page > 0) {<br />      $prev = $page - 1;<br />      $prevstart = "<a class=\"noun\" href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;box=$box&amp;page<br />=$prev&amp;sb=$sb&amp;o=$o\">";<br />      $prevoption = "previous.gif";<br />      $prevstop = "</a>";<br />   }<br />   else {<br />      $prevoption = "greyprevious.gif";<br />   }<br /><br />// ----------------------------------------------------------------------<br />// If total parent posts is greater than $PostsPer*Page then we give them<br />// a link to the next page<br />   if ($nums >= ($PostsPer + 1) ) {<br />      $next = $page + 1;<br />      $nextstart = "<a class=\"noun\" href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;box=$box&amp;page<br />=$next&amp;sb=$sb&amp;o=$o\">";<br />      $nextstop = "</a>";<br />      $nextoption = "next.gif";<br />   }<br />   else {<br />      $nextoption = "greynext.gif";<br />   }<br /><br />


--------------------------------------------------------------------
Find:

Code
<br />   $messagesize = "0";<br />   if (isset($message)) {<br />      $messagesize = sizeof($message);<br />   }<br />


Replace with:

Code
<br />   $messagesize = "0";<br />   if (isset($message)) {<br />      $messagesize = sizeof($message);<br />   }<br /><br />      $query = "<br />         SELECT COUNT(*)<br />    FROM   {$config['tbprefix']}Messages AS t1,<br />           {$config['tbprefix']}Users AS t2<br />    WHERE  t1.M_Uid = '{$user['U_Number']}'<br />    AND    t1.M_Status $extra 'X'<br />    AND    t1.M_Sender = t2.U_Number<br />      ";<br />      $sth = $dbh -> do_query($query);<br />      list($totaltopics) = $dbh -> fetch_array($sth);<br />      $dbh -> finish_sth($sth);<br /><br />   $Threads = $totaltopics;<br />   $TotalP = ceil($Threads/$PostsPer);<br />   if ($TotalP > 0) { $pagejumpers = "Page "; }<br /><br />   $Startpage = $page - 5;<br />   $Endpage   = $page + 5;<br /><br />   if ($Startpage < 0) {<br />      $Endpage = $Endpage - $Startpage;<br />      $Startpage = 0;<br />   }<br />   if ($Endpage > $TotalP) {<br />      $Endpage = $TotalP;<br />      $Startpage = $Endpage - 10;<br />   }<br />   if ($Startpage < 0) { $Startpage = 0; }<br />   if ($Startpage > 0) {<br />      $midprint = intval($Startpage / 2) - 1;<br />  $pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;page=0&amp;box=$box&amp;sb=$sb&am<br />p;o=$o\">1</a> ";<br />$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;page=$midprint&amp;box=$box&amp;sb=<br />$sb&amp;o=$o\">...</a> ";<br />   }<br />   if ($Threads > $PostsPer) {<br />      for ($i = $Startpage; $i <= $Endpage; $i++) {<br />         $printedpage = $i + 1;<br />         if ($i == $page) {<br />            $pagejumpers .= "<strong>[$printedpage]</strong> ";<br />         } else {<br />                 if ($printedpage <= $Endpage) {<br />$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;page=$i&amp;view=$view&amp;box=$box<br />&amp;sb=$sb&amp;o=$o\">$printedpage</a> ";<br />                 }<br />         }<br />      }<br />   }<br />   else {<br />      $pagejumpers .= "1";<br />   }<br />   if ($Endpage < $TotalP) {<br />      $Totalprint = $TotalP - 1;<br />      $midprint = $TotalP - intval(($TotalP - $Endpage) / 2);<br />      $pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;page=$midprint&amp;box=$box&a<br />mp;sb=$sb&amp;o=$o\">...</a> ";<br />      $pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&amp;page=$Totalprint&amp;box=$box<br />&amp;sb=$sb&amp;o=$o\">$TotalP</a> ";<br />   }<br />   $pagejumpers .= "</font>";<br /><br />


===============================================================

In templates/default/viewmessages.tmpl

Find at the bottom of the file:

Code
<br /></td><br /></tr><br />$tbclose<br /><br /></form><br />UBBTPRINT;<br />/* UBBTREMARK */ ?><br />


Replace with:

Code
<br /></td><br /></tr><br /><br /><tr><br /><td colspan="8" class="tdheader" align="right"><br />$pagejumpers<br /></td></tr><br /><br />$tbclose<br /><br /></form><br />UBBTPRINT;<br />/* UBBTREMARK */ ?><br />





Disclaimer: Please backup every file that you intend to modify.
If the modification modifies the database, it's a good idea to backup your database before doing so.

Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop.If you need official support, you'll need to restore unmodified files.
Posted By: AllenAyres Re: Beta-[6.4] Paginate PMs - 06/21/2005 7:13 AM
danke
Posted By: StanCA Re: Beta-[6.4] Paginate PMs - 06/21/2005 11:57 PM
this will work with 6.5.1??? right??
Posted By: bostongio Re: Beta-[6.4] Paginate PMs - 06/22/2005 2:19 PM
I don't have copies of other version of the software, just my 6.4.x version. I'm not sure how much of significance changed between the two versions in viewmessages.php, as that's the key file.
Posted By: StanCA Re: Beta-[6.4] Paginate PMs - 06/22/2005 4:56 PM
getting this message in 6.5.1

Attached picture 128406-Picture1.png
Posted By: Anno Re: Beta-[6.4] Paginate PMs - 06/23/2005 3:03 PM
I knew I have seen this already:
https://www.ubbdev.com/forum/showflat.php/Number/85383
Posted By: bostongio Re: Beta-[6.4] Paginate PMs - 06/23/2005 11:34 PM
Hmm, I couldn't find that but glad to see others were thinking the same thing. That one only went up to 6.3, so here's the answer for 6.4. 6.5 anyone?
Posted By: Anno Re: Beta-[6.4] Paginate PMs - 06/24/2005 9:35 AM
2 issues:

1. In viewmessages.php you are using the variable $nums which is not defined.

2. In viewmessages.tmpl you are not useing the variables $prevoption and $nextoption
© UBB.Developers