Added search feauture
This commit is contained in:
parent
e1b81c2396
commit
4c4d09a953
2
README
2
README
|
@ -1,4 +1,4 @@
|
|||
PHPCSV Guestbook version 0.94
|
||||
PHPCSV Guestbook version 0.95
|
||||
|
||||
Simple php guestbook with csv file data storage.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Administration program file of PHPCSV Guestbook version 0.94
|
||||
* Administration program file of PHPCSV Guestbook
|
||||
* See settings.php for configuration.
|
||||
* Edit page.php for change appearance.
|
||||
*/
|
||||
|
@ -23,16 +23,48 @@ function SaveEntries() {
|
|||
global $GBdata;
|
||||
global $AdminEntries;
|
||||
$fhandle=fopen($GBdata,"w");
|
||||
foreach($AdminEntries as $e=>$Entry) fputcsv($fhandle,$Entry);
|
||||
foreach($AdminEntries as $e=>$Entry) {
|
||||
unset($Entry[7]);
|
||||
fputcsv($fhandle,$Entry);
|
||||
}
|
||||
fclose($fhandle);
|
||||
}
|
||||
|
||||
function Search($SearchQuery) {
|
||||
$Entries=ReadEntries();
|
||||
$SearchResultCount=0;
|
||||
$SearchResult=false;
|
||||
foreach($Entries as $e=>$Entry) {
|
||||
for($p=0; $p<7; $p++) {
|
||||
if (mb_stristr($Entry[$p],$SearchQuery)) {
|
||||
$SearchResult[$SearchResultCount][0]=$e;
|
||||
$SearchResult[$SearchResultCount][1]=$Entry;
|
||||
$SearchResultCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $SearchResult;
|
||||
}
|
||||
|
||||
function AddSearchBar() {
|
||||
global $Titles;
|
||||
global $GBsearch;
|
||||
if (!(($_SESSION["EditStatus"]) or ($_SESSION["DeleteStatus"]=="deletion"))) if ($GBsearch) {
|
||||
echo "<form action=administration.php method=post>";
|
||||
echo "<input type=text name=\"serachq\" value=\"\" maxlength=255>";
|
||||
echo "<input type=submit name=\"search\" value=\"$Titles[Search]\">";
|
||||
echo "</form>";
|
||||
}
|
||||
}
|
||||
|
||||
function AdminHeaderView() {
|
||||
global $Titles;
|
||||
global $GBadmin;
|
||||
global $GBpassword;
|
||||
echo "<h2><a href=\"index.php\">$Titles[AdminHeader]</a></h2>\n";
|
||||
if ($_SESSION["SessionStatus"]==(md5($GBadmin.$GBpassword))) {
|
||||
echo "<div style=\"position: absolute; right: 127px; top: 59px;\">",AddSearchBar(),"</div>";
|
||||
echo "<form action=administration.php method=post>\n";
|
||||
echo " <p align=\"right\"><input type=submit name=\"exit\" value=\"$Titles[AdminExit]\"></p>\n";
|
||||
echo "</form>\n";
|
||||
|
@ -68,6 +100,14 @@ function AdminEntriesView() {
|
|||
echo "<input type=submit name=\"canceledit\" value=\"$Titles[AdminCancel]\">\n";
|
||||
echo "</form>\n";
|
||||
} else {
|
||||
if($_POST['search']&&$_POST['serachq']) {
|
||||
$SearchResult=Search($_POST['serachq']);
|
||||
if ($SearchResult) {
|
||||
$GBpagination=0;
|
||||
unset($AdminEntries);
|
||||
foreach($SearchResult as $n=>$Entry) $AdminEntries[$n]=$Entry[1];
|
||||
} else echo "$Titles[NoResult]: '",$_POST['serachq'],"'.<br>\n";
|
||||
}
|
||||
if (($GBpagination>0)&&(count($AdminEntries)>$GBpagination)) {
|
||||
$Entries=array_reverse($AdminEntries);
|
||||
if ($_GET['page']) switch ($_GET['page']) {
|
||||
|
|
42
index.php
42
index.php
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Main program file of PHPCSV Guestbook version 0.94
|
||||
* Main program file of PHPCSV Guestbook
|
||||
* See settings.php for configuration.
|
||||
* Edit page.php for change appearance.
|
||||
* See license.txt for licensing information.
|
||||
|
@ -77,14 +77,50 @@ function AddEntryView() {
|
|||
}
|
||||
}
|
||||
|
||||
function Search($SearchQuery) {
|
||||
$Entries=ReadEntries();
|
||||
$SearchResultCount=0;
|
||||
$SearchResult=false;
|
||||
foreach($Entries as $e=>$Entry) {
|
||||
for($p=0; $p<7; $p++) {
|
||||
if (mb_stristr($Entry[$p],$SearchQuery)) {
|
||||
$SearchResult[$SearchResultCount][0]=$e;
|
||||
$SearchResult[$SearchResultCount][1]=$Entry;
|
||||
$SearchResultCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $SearchResult;
|
||||
}
|
||||
|
||||
function AddSearchBar() {
|
||||
global $Titles;
|
||||
global $GBsearch;
|
||||
if ($GBsearch) {
|
||||
echo "<form action=index.php method=post>";
|
||||
echo "<input type=text name=\"serachq\" value=\"\" maxlength=255>";
|
||||
echo "<input type=submit name=\"search\" value=\"$Titles[Search]\">";
|
||||
echo "</form>";
|
||||
}
|
||||
}
|
||||
|
||||
function EntriesView() {
|
||||
global $Titles;
|
||||
global $DataStatus;
|
||||
global $Entries;
|
||||
global $GBpagination;
|
||||
if ($DataStatus=="empty") echo "$Titles[EmptyFile]";
|
||||
else if (($GBpagination>0)&&(count($Entries)>$GBpagination)) {
|
||||
$Entries=array_reverse($Entries);
|
||||
else if($_POST['search']&&$_POST['serachq']) {
|
||||
$SearchResult=Search($_POST['serachq']);
|
||||
if ($SearchResult) {
|
||||
$GBpagination=0;
|
||||
unset($Entries);
|
||||
foreach($SearchResult as $n=>$Entry) $Entries[$n]=$Entry[1];
|
||||
} else echo "$Titles[NoResult]: '",$_POST['serachq'],"'.<br>\n";
|
||||
}
|
||||
if (($GBpagination>0)&&(count($Entries)>$GBpagination)) {
|
||||
$Entries=array_reverse($Entries);
|
||||
if ($_GET['page']) switch ($_GET['page']) {
|
||||
case $Titles[First]:
|
||||
$CurrentPage=0;
|
||||
|
|
5
page.php
5
page.php
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Main page of PHPCSV Guestbook version 0.94
|
||||
* Main page of PHPCSV Guestbook
|
||||
* See settings.php for configuration.
|
||||
* For changing appearance you can edit this file like simple html. For example: add css tags.
|
||||
*/
|
||||
|
@ -14,6 +14,9 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div style="position: absolute; right: 5px; top: 25px;"><?php /* Absolute position of SearchBar */ ?>
|
||||
<?php AddSearchBar();?>
|
||||
</div>
|
||||
<?php AddEntryView();?>
|
||||
<hr>
|
||||
<?php EntriesView();?>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Settings file of PHPCSV Guestbook version 0.94
|
||||
* Settings file of PHPCSV Guestbook
|
||||
* Edit page.php for change appearance.
|
||||
* $GBdata parameter for changing entries data file.
|
||||
* Please, change $GBadmin and $GBpassword parameters for access to administration page.
|
||||
|
@ -11,6 +11,7 @@ $GBdata="gbdb.csv";
|
|||
$GBadmin="root";
|
||||
$GBpassword="password";
|
||||
$GBpagination=10; // pagination for entries, 0 - disabled
|
||||
$GBsearch=true; // enable or disable search bar
|
||||
$GBnotificationmailto=""; // leave empty if you don't want send notification
|
||||
$GBnotificationmailfrom="";
|
||||
$Titles[HeadTitle]="Guestbook";
|
||||
|
@ -56,4 +57,6 @@ $Titles[First]="First";
|
|||
$Titles[Last]="Last";
|
||||
$Titles[Previous]="<<";
|
||||
$Titles[Next]=">>";
|
||||
$Titles[Search]="Search";
|
||||
$Titles[NoResult]="No search result";
|
||||
?>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Russian version of settings file PHPCSV Guestbook version 0.94
|
||||
* Russian version of settings file PHPCSV Guestbook
|
||||
* Для руссификации гостевой книги замените оригинальный settings.php на содержимое этого файла.
|
||||
* Редактируйте page.php для изменения внешнего вида.
|
||||
* $GBdata параметр служит для смены файла данных записей гостевой книги.
|
||||
|
@ -12,6 +12,7 @@ $GBdata="gbdb.csv";
|
|||
$GBadmin="root";
|
||||
$GBpassword="password";
|
||||
$GBpagination=10; // количество записей на странице, 0 - все записи на одной странице
|
||||
$GBsearch=true; // включение или отключения строки поиска
|
||||
$GBnotificationmailto=""; // оставьте поле пустым, если не хотите отправки уведомлений о новых записях
|
||||
$GBnotificationmailfrom="";
|
||||
$Titles[HeadTitle]="Гостевая книга";
|
||||
|
@ -57,4 +58,6 @@ $Titles[First]="В начало";
|
|||
$Titles[Last]="В конец";
|
||||
$Titles[Previous]="Назад";
|
||||
$Titles[Next]="Вперед";
|
||||
$Titles[Search]="Поиск";
|
||||
$Titles[NoResult]="Ничего не найдено";
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue