Added pagination (issue 1)

This commit is contained in:
ivan 2017-09-25 12:39:36 +03:00
parent 5e9f25e430
commit 31003891fa
6 changed files with 73 additions and 9 deletions

6
README
View File

@ -1,8 +1,10 @@
PHPCSV Guestbook version 0.92 PHPCSV Guestbook version 0.93
Simple php guestbook with csv file data storage. Simple php guestbook with csv file data storage.
PHPCSV Guestbook 0.92 requires PHP 5.0 or higher version. Working example: https://zlaxyi.soundragon.su/gb
PHPCSV Guestbook 0.93 requires PHP 5.0 or higher version.
Installation: Installation:

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Administration program file of PHPCSV Guestbook version 0.92 * Administration program file of PHPCSV Guestbook version 0.93
* See settings.php for configuration. * See settings.php for configuration.
* Edit page.php for change appearance. * Edit page.php for change appearance.
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Main program file of PHPCSV Guestbook version 0.92 * Main program file of PHPCSV Guestbook version 0.93
* See settings.php for configuration. * See settings.php for configuration.
* Edit page.php for change appearance. * Edit page.php for change appearance.
* See license.txt for licensing information. * See license.txt for licensing information.
@ -81,8 +81,60 @@ function EntriesView() {
global $Titles; global $Titles;
global $DataStatus; global $DataStatus;
global $Entries; global $Entries;
global $GBpagination;
if ($DataStatus=="empty") echo "$Titles[EmptyFile]"; if ($DataStatus=="empty") echo "$Titles[EmptyFile]";
else { else if (($GBpagination>0)&&(count($Entries)>$GBpagination)) {
$Entries=array_reverse($Entries);
if ($_GET['page']) switch ($_GET['page']) {
case $Titles[First]:
$CurrentPage=0;
break;
case $Titles[Last]:
$CurrentPage=intdiv(count($Entries),$GBpagination);
break;
case "$Titles[Previous]":
$CurrentPage=$_SESSION['currentpage']-1;
break;
case "$Titles[Next]":
$CurrentPage=$_SESSION['currentpage']+1;
break;
default:
$CurrentPage=$_GET['page']-1;
}
else $CurrentPage=0;
for ($e = ($GBpagination*$CurrentPage); $e < ($GBpagination*($CurrentPage+1)); $e++) {
if ($e>=count($Entries)) break;
echo " <div class=\"entry\"><div class=\"messages_header\"><h4>",$Entries[$e][7],". ";
if ($Entries[$e][2]) echo "<a href=\"$Entries[$e][2]\">";
echo "<b>",$Entry[0],"</b>";
if ($Entries[$e][2]) echo "</a>";
if ($Entries[$e][1]) echo " ",$Titles[From]," <b>",$Entries[$e][1],"</b>";
echo ", ",date("j.m.Y, H:i",$Entries[$e][5]),", ",$Titles[Wrote],":</div></h4><br>\n";
echo " ",nl2br($Entries[$e][4]),"<br>\n";
if ($Entries[$e][6]) echo "<br><i><b>$Titles[Response]:</b><br>\n";
if ($Entries[$e][6]) echo nl2br($Entries[$e][6]),"</i><br>\n";
echo "</div><hr>\n";
}
echo "<form action=\".\" method=\"get\">\n";
if ($CurrentPage>0) {
echo " <input type=\"submit\" value=\"$Titles[First]\" name=\"page\"/>\n";
echo " <input type=\"submit\" value=\"$Titles[Previous]\" name=\"page\"/>\n";
}
for ($p = ($CurrentPage-2); $p <= ($CurrentPage+2); $p++) {
$page = $p+1;
if (($p>=0)&&($p<(count($Entries)/$GBpagination))) {
echo " <input type=\"submit\" value=\"$page\" name=\"page\"";
if ($p==$CurrentPage) echo " disabled";
echo "/>\n";
}
}
if ($CurrentPage<((count($Entries)/$GBpagination)-1)) {
echo " <input type=\"submit\" value=\"$Titles[Next]\" name=\"page\"/>\n";
echo " <input type=\"submit\" value=\"$Titles[Last]\" name=\"page\"/>\n";
}
echo "</form>\n";
$_SESSION['currentpage']=$CurrentPage;
} else {
$Entries=array_reverse($Entries); $Entries=array_reverse($Entries);
foreach($Entries as $e=>$Entry) { foreach($Entries as $e=>$Entry) {
echo " <div class=\"entry\"><div class=\"messages_header\"><h4>",$Entry[7],". "; echo " <div class=\"entry\"><div class=\"messages_header\"><h4>",$Entry[7],". ";

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Main page of PHPCSV Guestbook version 0.92 * Main page of PHPCSV Guestbook version 0.93
* See settings.php for configuration. * See settings.php for configuration.
* For changing appearance you can edit this file like simple html. For example: add css tags. * For changing appearance you can edit this file like simple html. For example: add css tags.
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Settings file of PHPCSV Guestbook version 0.92 * Settings file of PHPCSV Guestbook version 0.93
* Edit page.php for change appearance. * Edit page.php for change appearance.
* $GBdata parameter for changing entries data file. * $GBdata parameter for changing entries data file.
* Please, change $GBadmin and $GBpassword parameters for access to administration page. * Please, change $GBadmin and $GBpassword parameters for access to administration page.
@ -10,6 +10,7 @@
$GBdata="gbdb.csv"; $GBdata="gbdb.csv";
$GBadmin="root"; $GBadmin="root";
$GBpassword="password"; $GBpassword="password";
$GBpagination=10; // pagination for entries, 0 - disabled
$GBnotificationmailto=""; // leave empty if you don't want send notification $GBnotificationmailto=""; // leave empty if you don't want send notification
$GBnotificationmailfrom=""; $GBnotificationmailfrom="";
$Titles[HeadTitle]="Guestbook"; $Titles[HeadTitle]="Guestbook";
@ -51,4 +52,8 @@ $Titles[AdminSureDel]="Are you sure to delete";
$Titles[AdminSureDelMessages]="messages"; $Titles[AdminSureDelMessages]="messages";
$Titles[MailSubject]="New entry in your guestbook"; $Titles[MailSubject]="New entry in your guestbook";
$Titles[MailAdmin]="You can edit, delete or reply this message via admin page"; $Titles[MailAdmin]="You can edit, delete or reply this message via admin page";
$Titles[First]="First";
$Titles[Last]="Last";
$Titles[Previous]="<<";
$Titles[Next]=">>";
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Russian version of settings file PHPCSV Guestbook version 0.92 * Russian version of settings file PHPCSV Guestbook version 0.93
* Для руссификации гостевой книги замените оригинальный settings.php на содержимое этого файла. * Для руссификации гостевой книги замените оригинальный settings.php на содержимое этого файла.
* Редактируйте page.php для изменения внешнего вида. * Редактируйте page.php для изменения внешнего вида.
* $GBdata параметр служит для смены файла данных записей гостевой книги. * $GBdata параметр служит для смены файла данных записей гостевой книги.
@ -11,6 +11,7 @@
$GBdata="gbdb.csv"; $GBdata="gbdb.csv";
$GBadmin="root"; $GBadmin="root";
$GBpassword="password"; $GBpassword="password";
$GBpagination=10; // количество записей на странице, 0 - все записи на одной странице
$GBnotificationmailto=""; // оставьте поле пустым, если не хотите отправки уведомлений о новых записях $GBnotificationmailto=""; // оставьте поле пустым, если не хотите отправки уведомлений о новых записях
$GBnotificationmailfrom=""; $GBnotificationmailfrom="";
$Titles[HeadTitle]="Гостевая книга"; $Titles[HeadTitle]="Гостевая книга";
@ -52,4 +53,8 @@ $Titles[AdminSureDel]="Вы уверены, что хотите удалить";
$Titles[AdminSureDelMessages]="сообщений"; $Titles[AdminSureDelMessages]="сообщений";
$Titles[MailSubject]="Новая запись в вашей гостевой книге"; $Titles[MailSubject]="Новая запись в вашей гостевой книге";
$Titles[MailAdmin]="Вы можете редактировать, удалить или ответить на эту запись через страницу администрирования"; $Titles[MailAdmin]="Вы можете редактировать, удалить или ответить на эту запись через страницу администрирования";
$Titles[First]="В начало";
$Titles[Last]="В конец";
$Titles[Previous]="Назад";
$Titles[Next]="Вперед";
?> ?>