<?php
###
###
### Copyright 2004, Danny Carlton. Permission is hereby granted to distribute
### copies of this software package as long as you do not charge for it, and the
### copyright notices remain intact. Permission is also granted to use the concepts
### in these scripts for other similar scripts, but you may not simply copy the scripts and claim them as your own.
###
###
if(!$pb_user)
{
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$$key=$value;
}
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS))
{
$$key=$value;
}
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
srand(getmicrotime());
$pagestart=getmicrotime();
$rn = rand(1, 9999);
if(!$begin){$begin=0;}
else{$begin--;}
require("../config.php");
$script_name_in='admin/admin.php';
if($action=='logout')
{
setcookie ("pb_user", "", time()-360);
$pb_user='';
header("Location: $domain/$path$script_name_in");
exit;
}
$userdata=file("admin_data.php");
$userdata[1]=str_replace("\n", '', $userdata[1]);
$real_pw=str_replace("\r", '', $userdata[1]);
if(!$pb_user)
{
if($pw==$real_pw)
{
setcookie ("pb_user", $real_pw, time()+604800);
$pb_user=$real_pw;
}
else{$pb_user='';}
}
if($pb_user!=$real_pw)
{
setcookie ("pb_user", "", time()-360);
echo "<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"../phpBible.css\">
</head>
<body>
<form method=\"POST\" action=\"admin.php?login=yes\">
<div align=\"center\">
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"66\">
<tr>
<td height=\"41\"><font face=\"Verdana\" size=\"2\" color=\"#000080\">Password<br>
<input type=\"password\" name=\"pw\" size=\"20\" class=\"custom_input\"></font></td>
<td><font face=\"Verdana\" size=\"2\"><br>
</font><input type=\"submit\" value=\"Login\" name=\"submit\" class=\"custom_button\"></td>
</tr>
<tr>
<td colspan=\"2\" align=\"right\"></td>
<td align=\"right\"></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>";
exit();
}
$link = mysql_connect($host, $user, $password)
or die("Could not connect : " . mysql_error());
mysql_select_db($db_name) or die("Could not select database");
if($results_side=='left')
{
$results_marker='{{RESULTS LEFT}}';
$results_marker_off='{{RESULTS RIGHT}}';
}
else
{
$results_marker='{{RESULTS RIGHT}}';
$results_marker_off='{{RESULTS LEFT}}';
$lex_left='lex_x=((document.body.scrollWidth-640)/2)+20;';
}
if($site_name){$sn="<a href=\"$main_url\">$site_name</a></b>>><b>";}
$dir="<center><table border=0 style=\"align: left; margin-top: 0; margin-bottom: 0; width: 500;\"><tr><td><font face=\"Verdana\" size=\"1\"><b>$sn<a href=\"../$script_name\">phpBible</a>";
if($keyword){$dir.="</b>>><b>{{DISPLAY}}</b></font>";}
$dir.='</td></tr></table></center>';
$html_template=implode('', file("../_template_main.htm"));
$script_insert="<script>
lex_div.style.display='none';
lex_shadow1.style.display='none';
lex_shadow2.style.display='none'
var old_wi=wi0;
</script>";
if($keyword){$html_template=str_replace('<!--script insert -->', $script_insert, $html_template);}
$html_template=str_replace('phpBible.css', "../phpBible.css?$rn", $html_template);
$html_template=str_replace('{{HEADING}}', "{{HEADING}}$dir", $html_template);
$html_template=str_replace('name="search">', "name=\"search\" action=\"../$script_name\">", $html_template);
$html_template=str_replace('{{HEADING}}', implode('', file('../_template_heading.htm')), $html_template);
$html_template=str_replace('{{FOOTER}}', implode('', file('../_template_footer.htm')), $html_template);
if($keyword)
{
$html_template=str_replace($results_marker_off, implode('', file('../_template_custom2.htm')), $html_template);
}
else
{
$admin_t1_in=file('_template_admin1.php');
for($i=4;$i<count($admin_t1_in);$i++)
{
$admin_t1.=$admin_t1_in[$i];
}
$html_template=str_replace($results_marker_off, $admin_t1, $html_template);
$html_template=str_replace('{{site_name}}', $site_name, $html_template);
$html_template=str_replace('{{main_url}}', $main_url, $html_template);
$html_template=str_replace('{{script_name}}', $script_name, $html_template);
$html_template=str_replace('{{domain}}', $domain, $html_template);
$html_template=str_replace('{{path}}', $path, $html_template);
$html_template=str_replace($results_marker, implode('', file('_template_admin2.htm')), $html_template);
}
$html_template=str_replace('{{VERY DARK}}', $page_very_dark, $html_template);
$html_template=str_replace('{{DARK}}', $page_dark, $html_template);
$html_template=str_replace('{{LIGHT}}', $page_light, $html_template);
$html_template=str_replace('{{MEDIUM}}', $page_medium, $html_template);
$html_template=str_replace('{{MAIN}}', $script_name, $html_template);
if($lex_left){$html_template=str_replace('lex_x=((document.body.scrollWidth-640)/2)+340;', $lex_left, $html_template);}
if($p_display=='par')
{
$html_template=str_replace('value="trad" name="p_display" checked', 'value="trad" name="p_display"', $html_template);
$html_template=str_replace('value="par" name="p_display"', 'value="par" name="p_display" checked', $html_template);
}
if(!$keyword)
{
$html_template=str_replace($results_marker, "<span id=\"wi0\" name=\"wi0\"></span>", $html_template);
}
else
{
#echo "$keyword<br>\n";
if(ereg("[0-9]", $keyword))
{
#echo "number found<br>\n";
$p_key=$keyword;
$p_key=ereg_replace(" +", ' ', $p_key);
$p_keys=explode(' ', $p_key);
#echo "0:$p_keys[0]|1:$p_keys[1]<br>\n";
if(!$p_keys[0])
{
#echo "no pk[0]<br>";
$p_keys[0]=$p_keys[1];
$p_keys[1]=$p_keys[2];
$p_keys[2]=$p_keys[3];
$p_keys[3]='';
}
if(ereg("[0-9]", $p_keys[0]))
{
$p_keys[0]=ereg_replace("[^0-9]", '', $p_keys[0]);
$p_keys[0]="$p_keys[0] $p_keys[1]";
$p_keys[1]="$p_keys[2] $p_keys[3]";
$p_keys[2]='';
#echo "keys: $p_keys[0]|$p_keys[1]|$p_keys[2]|<br>\n";
}
if(ereg("[0-9]", $p_keys[1]))
{
$p_key2=implode(' ', $p_keys);
$p_key2=str_replace($p_keys[0], '', $p_key2);
$reference_key=ereg_replace("[^0-9:,-]", '', $p_key2);
$book_key=$p_keys[0];
}
$keyword_v="$book_key $reference_key";
}
if((strstr(" $keyword", '#')) or (strstr(" $keyword", '~')))
{
#echo "search by strong's<br>\n";
$st_key=str_replace('#', '', $keyword);
$st_key=str_replace('~', '', $st_key);
$st_key=ereg_replace(" +", '', $st_key);
}
$keyword=str_replace("'s", '×', $keyword);
$keyword=ereg_replace("[^a-zA-Z *×\"]", '', $keyword);
$keyword=str_replace('×', "'s", $keyword);
$keyword=str_replace('"', '"', $keyword);
if($keyword_v){$keyword=$keyword_v;}
if($st_key){$keyword="#$st_key";}
$html_template=str_replace('<input type="text" name="keyword" size="20"', "<input value=\"$keyword\" type=\"text\" name=\"keyword\" size=\"20\"", $html_template);
$keyword=str_replace('"', '"', $keyword);
$keyword=str_replace("'s", "\\'s", $keyword);
$keyword_d=str_replace("\\'s", "'s", $keyword);
}
##### check wordcount.dat
$wordcount=file("../wordcount.dat");
for($i=0;$i<count($wordcount);$i++)
{
$wc_a=explode(', ', $wordcount[$i]);
$ws=str_replace("\n", '', $wc_a[2]);
$ws=str_replace("\r", '', $ws);
$wt=str_replace('\\', '', $wc_a[0]);
#echo "|$keyword|--|$wt|<br>\n|$section|--|$ws|<br>\n";
if (($keyword==$wt) and ($section==$ws))
{
$max_rows=str_replace("\n", '', $wc_a[1]);
$wc_source='file';
}
}
$table_name=$table_prefix;
$table_name.='books';
$query = "SELECT * FROM $table_name";
$book_query = mysql_query($query) or die("Query failed : " . mysql_error());
while ($book_in = mysql_fetch_array($book_query, MYSQL_ASSOC))
{
$this_num=$book_in[number];
$book[$this_num]=$book_in[book];
$chapters[$this_num]=$book_in[chapters];
$abbr[$this_num]=$book_in[abbr];
$bc=10+$this_num;
$book_choices.=" <option value=\"$bc\">$book_in[book]\n";
}
mysql_free_result($book_query);
$html_template=str_replace('<option value="10">General Epistles', "<option value=\"10\">General Epistles\n <option value=\"11\">-----------------------\n$book_choices", $html_template);
if($book_key)
{
for($i=0;$i<count($book);$i++)
{
if(strtolower($book[$i])==strtolower($book_key)){$book_num=$i;}
$ab=explode(', ', $abbr[$i]);
for($a=0;$a<count($ab);$a++)
{
if(strtolower($ab[$a])==strtolower($book_key)){$book_num=$i;}
}
}
}
$table_name=$table_prefix;
$table_name.='av';
$dbquerystart0=getmicrotime();
#echo "keyword=$keyword<br>\n";
$keyword2=str_replace('"', '|~~"~~|', $keyword);
$x_keys=explode('"', $keyword2);
for($i=0;$i<count($x_keys);$i++)
{
if((strstr($x_keys[$i], '~~|')) and (strstr($x_keys[$i], '|~~')))
{
$temp=str_replace('|~~', '', $x_keys[$i]);
$temp=str_replace('~~|', '', $temp);
if($search_key){$search_key.='&& ';}
$search_key.="text REGEXP \"[^a-zA-Z]".$temp."[^a-zA-Z]\" ";
}
else
{
$temp="$x_keys[$i] ";
$temp=str_replace('~~|', '', $temp);
$keyword3.=str_replace('|~~', '', $temp);
}
}
$keyword3=rtrim($keyword3);
$keyword3=ltrim($keyword3);
if($keyword3)
{
if($search_key){$search_key.='&& ';}
$keys=explode(' ', $keyword3);
for($i=0;$i<count($keys);$i++)
{
$search_key.="text REGEXP \"[^a-zA-Z]".$keys[$i]."[^a-zA-Z]\" ";
if($i<(count($keys)-1)){$search_key.='&& ';}
}
}
$keyword =str_replace('"', '\\"', $keyword);
if($reference_key)
{
$book_name=str_replace('1 ', '1st ', $book[$book_num]);
$book_name=str_replace('2 ', '2nd ', $book_name);
$book_name=str_replace('3 ', '3rd ', $book_name);
$html_template=str_replace('{{DISPLAY}}', "passage display: $book_name $reference_key", $html_template);
$html_template=str_replace("<input value=\"$keyword\"", "<input value=\"$book_name $reference_key\"", $html_template);
}
else
{
$html_template=str_replace('{{DISPLAY}}', "word search: $keyword", $html_template);
}
if($reference_key)
{
$working_ref=$reference_key;
if(strstr($working_ref, ':'))
{
$temp_a=explode(':', $working_ref);
$chapter=$temp_a[0];
if(strstr($temp_a[1], ','))
{
$temp_b=explode(',', $temp_a[1]);
for($i=0;$i<count($temp_b);$i++)
{
$verse_list.="verse = \"$temp_b[$i]\"";
if($i<(count($temp_b)-1)){$verse_list.=' || ';}
}
$search_key="book = \"$book_num\" && chapter = \"$chapter\" && ($verse_list)";
$max_rows=count($temp_b);
}
elseif(strstr($temp_a[1], '-'))
{
$temp_b=explode('-', $temp_a[1]);
$verse_start=$temp_b[0];
$verse_end=$temp_b[1];
$search_key="book = \"$book_num\" && chapter = \"$chapter\" && verse >= \"$verse_start\" && verse <= \"$verse_end\"";
$max_rows=$verse_start-$verse_end;
}
else
{
$search_key="book = \"$book_num\" && chapter = \"$chapter\" && verse LIKE \"$temp_a[1]\"";
}
}
else
{
$chapter=$working_ref;
$search_key="book = \"$book_num\" && chapter = \"$chapter\"";
#$max_rows=$cha50;
}
}
if($section)
{
if($section==1)
{
$search_key.="&& book < \"40\" ";
$html_template=str_replace('<option value="1">Old Testament', '<option value="1" selected>Old Testament', $html_template);
$section_searched="<br>in the Old Testament";
}
if($section==2)
{
$search_key.="&& book > \"39\" ";
$html_template=str_replace('<option value="2">New Testament', '<option value="2" selected>New Testament', $html_template);
$section_searched="<br>in the New Testament";
}
if($section==3)
{
$search_key.="&& book < \"6\" ";
$html_template=str_replace('<option value="3">Books of Law', '<option value="3" selected>Books of Law', $html_template);
$section_searched="<br>in the Books of Law";
}
if($section==4)
{
$search_key.="&& book > \"5\" && book < \"18\" ";
$html_template=str_replace('<option value="4">Books of History', '<option value="4" selected>Books of History', $html_template);
$section_searched="<br>in the Books of History";
}
if($section==5)
{
$search_key.="&& book > \"17\" && book < \"23\" ";
$html_template=str_replace('<option value="5">Books of Poetry', '<option value="5" selected>Books of Poetry', $html_template);
$section_searched="<br>in the Books of Poetry";
}
if($section==6)
{
$search_key.="&& book > \"22\" && book < \"28\" ";
$html_template=str_replace('<option value="6">Major Prophets', '<option value="6" selected>Major Prophets', $html_template);
$section_searched="<br>in the Major Prophets";
}
if($section==7)
{
$search_key.="&& book > \"27\" && book < \"40\" ";
$html_template=str_replace('<option value="7">Minor Prophets', '<option value="7" selected>Minor Prophets', $html_template);
$section_searched="<br>in the The Gospels";
}
if($section==8)
{
$search_key.="&& book > \"39\" && book < \"44\" ";
$html_template=str_replace('<option value="8">The Gospels', '<option value="8" selected>The Gospels', $html_template);
$section_searched="<br>in the Minor Prophets";
}
if($section==9)
{
$search_key.="&& book > \"44\" && book < \"59\" ";
$html_template=str_replace('<option value="9">Pauline Epistles', '<option value="9" selected>Pauline Epistles', $html_template);
$section_searched="<br>in the Pauline Epistles";
}
if($section==10)
{
$search_key.="&& book > \"58\" && book < \"66\" ";
$html_template=str_replace('<option value="10">General Epistles', '<option value="10" selected>General Epistles', $html_template);
$section_searched="<br>in the General Epistles";
}
if($section>10)
{
$this_book=$section-10;
$search_key.="&& book = \"$this_book\" ";
$html_template=str_replace("<option value=\"$section\">$book[$this_book]", "<option value=\"$section\" selected>$book[$this_book]", $html_template);
$section_searched="<br>in $book[$this_book]";
}
}
$search_key=str_replace('*', '[a-zA-Z*]', $search_key);
if($st_key){$search_key="coding REGEXP \"~$st_key~\"";}
#echo "keyword=$keyword<br>\nsearch key=$search_key<br>\n";
if(($search_key) and (!$max_rows) and (!$reference_key))
{
$query = "SELECT * FROM $table_name WHERE $search_key";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$max_rows = mysql_num_rows($result);
$wordcount[]="$keyword, $max_rows, $section\n";
$data=implode('', $wordcount);
$fp = fopen("wordcount.dat", "w");
fwrite ($fp, $data);
fclose ($fp);
$wc_source='mySQL';
}
$page_max=20;
$verses_left=($max_rows)-$begin;
$dbqueryend0=getmicrotime();
$dbquerystart=getmicrotime();
if(!$book_key){$page_limit=" LIMIT ".$begin.', '.$page_max;}
$query = "SELECT * FROM $table_name WHERE $search_key$page_limit";
$keyword=$keyword_d;
if($search_key){$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);
if($reference_key){$max_rows = mysql_num_rows($result);}
$results .= "<p style=\"text-align: Justify\">";
$wi=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
$offset=0;
$encoding=explode(' ', $line[coding]);
$text_array=explode(' ', $line[text]);
for($c=0;$c<count($encoding);$c++)
{
if(strstr($encoding[$c], '*'))
{
$e_data=explode('~', $encoding[$c]);
$num=$e_data[0]+$offset;
$text_array[$num]="° $text_array[$num]";
$offset--;
}
}
$new_line=implode(' ', $text_array);
$text_array=explode(' ', $new_line);
$c_count=count($encoding)+$inv_word;
for($c=0;$c<count($encoding);$c++)
{
if(strstr($encoding[$c], '~'))
{
$e_data=explode('~', $encoding[$c]);
$word=$e_data[0];
$key_w=str_replace("'", "\\'", $text_array[$word]);
$key_w=str_replace($e_data[2], '', $key_w);
$key_w=str_replace('</i>', '', $key_w);
$key_w=str_replace('<i>', '', $key_w);
if(stristr($text_array[$word], '</i>'))
{
$text_array[$word]=str_replace('</i>', '', $text_array[$word]);
$it2='</i>';
}
if($st_key==$e_data[1]){$text_array[$word]="<FONT style=\"BACKGROUND-COLOR: yellow\">$text_array[$word]</FONT>";}
$text_array[$word]="$it1<span id=\"wi$wi\" name=\"wi$wi\" class=def onclick=\"show_def('$e_data[1]', '$key_w', this);\">$text_array[$word]</span>$it2";
$wi++;$it1='';$it2='';
if($e_data[2])
{
$text_array[$word]=str_replace("$e_data[2]<", '<', $text_array[$e_data[0]]);
$text_array[$word]=str_replace("$e_data[2]')", '\')', $text_array[$word]);
$text_array[$word]="$text_array[$word]$e_data[2]";
$text_array[$word]=str_replace('>*', '>', $text_array[$word]);
$text_array[$word]=str_replace('>,*', '>', $text_array[$word]);
}
}
if(strstr($encoding[$c], '['))
{
$temp=str_replace('[', '', $encoding[$c]);
$temp=str_replace(']', '', $temp);
$text_array[$temp]="<i>$text_array[$temp]";
}
if(strstr($encoding[$c], ']'))
{
$temp=str_replace('[', '', $encoding[$c]);
$temp=str_replace(']', '', $temp);
$text_array[$temp]="$text_array[$temp]</i>";
}
if(strstr($encoding[$c], '¶')){$text_array[0]="¶$text_array[0]";}
}
$verse=implode(' ', $text_array);
$this_book=$line[book];
$book_name=$book[$this_book];
if($book_name=='Psalms'){$book_name='Psalm';}
if(!$reference_key){$book_ref="$book_name $line[chapter]:";}
if((!$reference_key) or ($p_display=='trad'))
{
$verse=str_replace('¶', '', $verse);
$results.= "<b>$book_ref$line[verse]</b> $verse<br>\n";
}
else
{
if(strstr($verse, '¶'))
{
$verse=str_replace('¶', '', $verse);
$results.= "<br> <font size=1><sup>$book_ref$line[verse]</sup></font>$verse ";
}
else
{
$results.= "<font size=1><sup>$book_ref$line[verse]</sup></font>$verse ";
}
}
}
}
if($st_key){$keyword=str_replace('#', '~', $keyword);}
$dbqueryend=getmicrotime();
$results.= "</p>";
mysql_close($link);
$next_r=$begin+21;
$last_r=$begin-19;
$end=$begin+20;
if($end>$max_rows){$end=$max_rows;}
$begin1=$begin+1;
$pages=ceil($max_rows/20);
$page_select_num=$pages;
$this_page=floor($begin/20)+1;
$page_start=1;
if($section){$section_link="§ion=$section";}
if(($this_page>5) and ($pages>10))
{
$page_start=$this_page-4;
if(($pages-$this_page)<5){$page_start=$pages-9;}
$i_page=(($page_start-2)*20)+1;
$page_back="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\"><<</a> ";
}
$page_end=$page_start+($pages-1);
if($page_end>($pages)){$page_end=$pages;}
if(($pages-$this_page)>5)
{
$page_end=$page_start+9;
$i_page=(($page_end)*20)+1;
if($this_page<($pages-4)){$more="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\">>></a>";}
}
if($pages>1)
{
for($i=$page_start;$i<=$page_end;$i++)
{
if($i==$this_page){$page_select.="<b><font color=\"#cccccc\">$i</font></b> ";}
else
{
$i_page=(($i-1)*20)+1;
$page_select.="<a href=\"$script_name?keyword=$keyword&begin=$i_page$section_link\">$i</a> ";
}
}
}
if(!$reference_key)
{
$max="<center>$begin1 - $end of $max_rows verses containing <b>$keyword</b>$section_searched.</center>";
$select_page="<font face=\"verdana\" size=1>$page_back$page_select$more</font>";
if($verses_left>20){$next_20="<b><font face=\"verdana\" size=2><a href=\"$script_name?keyword=$keyword&begin=$next_r$section_link\">next 20></a></font></b>";}
if($begin){$last_20="<b><font face=\"verdana\" size=2><a href=\"$script_name?keyword=$keyword&begin=$last_r$section_link\"><last 20</a></font></b>";}
}
else{$max="<font size=4><b>$book_name $chapter</b></font>";}
if($st_key)
{
$max="<center>$begin1 - $end of $max_rows verses containing <b>Strong's $keyword</b>$section_searched.</center>";
}
if(($keyword) and ($max_rows==0)){$max="Sorry, no results for <b>$keyword</b> could be found$section_searched.";}
$lastnext="<table width=100% border=0><tr><td colspan=2 nowrap>$max</td></tr><tr><td colspan=2 align=center>$select_page</td></tr><tr><td align=left nowrap><font size=2>$last_20</font></td><td align=right nowrap><font size=2>$next_20</font></td></tr><tr><td colspan=2>";
$html_template=str_replace($results_marker, "$lastnext$results</td></tr></table>", $html_template);
$pageend=getmicrotime();
$speed=$pageend-$pagestart;
$dbspeed=$dbqueryend-$dbquerystart;
$dbspeed0=$dbqueryend0-$dbquerystart0;
$predbspeed=$dbquerystart0-$pagestart;
$remaining_time=$pageend-$dbqueryend;
$html_template=str_replace('{{SPEED}}', "<center><font size=2>
$predbspeed seconds before query<br>
mySQL (count total) took $dbspeed0 seconds<br>
mySQL (fetch verses) took $dbspeed seconds<br>
remaining time took $remaining_time seconds<br>
page processed in $speed seconds<br>
</font></center>", $html_template);
if($lexicon=='ipd'){$html_template=str_replace('value="ipd" name="lexicon"', 'value="ipd" checked name="lexicon"', $html_template);}
else{$html_template=str_replace('value="str" name="lexicon"', 'value="str" checked name="lexicon"', $html_template);}
#echo "$wc_source<br>\n";
echo $html_template;
?>