-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
139 lines (90 loc) · 3.47 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
include_once "utils.php";
include_once "dudleyinclude.php";
session_start();
$search_limit = 100;
$searchstr = '';
$show_results = 0;
$ignorecase = 0;
$errorstr = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$searchstr = trim($_POST['searchstr']);
$ignorecase = $_POST['ignorecase'];
if (strlen($searchstr) < 2) $errorstr .= '<p>Search string too short.';
if (!isset($errorstr) || (strlen($errorstr) < 1)) {
if ($ignorecase) {
$str = db_escape_string('%'.strtolower($searchstr).'%');
$sql = "select stripid from strip where lower(stripdata) like '".$str."'";
} else {
$str = db_escape_string('%'.$searchstr.'%');
$sql = "select stripid from strip where stripdata like '".$str."'";
}
$sql .= " and approved=true and striptime<now() order by stripid";
$res = db_exec($sql);
$numrows = db_numrows($res);
if ($numrows < 1) $errorstr .= '<p>No results.';
else {
$n_search_results = $numrows;
$result_stripids = array();
for ($i = 0; $i < min($numrows,$search_limit); $i++) {
$dat = db_get_rowdata($res, $i);
$result_stripids[] = $dat['stripid'];
}
$show_results = 1;
}
}
}
dud_html_top(array('css'=>$dudley_css_files,
'title'=>strip_tags($dudley_comic_title)));
print '<center>'."\n";
print '<h1>'.$dudley_comic_title.'</h1>'."\n";
print get_dudmenu();
print '<h1>Search Dudley strips</h1>'."\n";
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" enctype="multipart/form-data">'."\n";
if (isset($errorstr) && strlen($errorstr)) print '<div class="errorstr">'.$errorstr.'</div>';
if ($show_results) {
print '<p>Number of hits: '.$n_search_results;
if ($n_search_results > $search_limit) print '<p>Only the first '.$search_limit.' hits are shown.';
$odd=0;
print '<table style="width:50%;border:1px solid black;text-align:center;">';
print '<thead>';
print '<tr>';
print '<td> </td>';
print '<td>Strip ID</td>';
print '<td>Submitted</td>';
print '<td>Author</td>';
print '<td>Published</td>';
print '</tr>';
print '</thead>';
foreach ($result_stripids as $strip_id) {
$sql = "select *,date_trunc('second',submittime) as dtime,date_trunc('second',striptime) as stime,date_trunc('second',age(striptime,now())) as pubdate,date_trunc('second',edittime) as etime from strip where stripid=".$strip_id;
$res = db_exec($sql);
$numrows = db_numrows($res);
if ($numrows > 0) {
for ($i = 0; $i < $numrows; $i++) {
$dat = db_get_rowdata($res, $i);
print '<tr class="'.odd_even($odd++).'">';
print '<td>'.$odd.'. </td>';
print '<td>'.mk_url($dudley_root_url.'?'.$dat['stripid'], $dat['stripid']).'</td>';
print '<td>'.$dat['dtime'].'</td>';
print '<td>';
if (isset($dat['authorid'])) print mk_url('duduser.php?'.$dat['authorid'],$dat['author']);
else print $dat['author'];
print '</td>';
print '<td>'.(($dat['approved'] == 't') ? $dat['stime'] : "not scheduled").'</td>';
print '</tr>'."\n";
}
}
}
print '</table>';
print '<p>';
}
print '<table style="text-align:center;">';
print '<tr><td><input name="searchstr" type="text" size="40" value="'.$searchstr.'"></td></tr>'."\n";
print '<tr><td><label><input name="ignorecase" type="checkbox"'.($ignorecase=="on"?" checked":"").
'> case insensitive</label></td></tr>'."\n";
print '<tr><td colspan="2"><input type="Submit" value="Search"></td></tr>'."\n";
print '</table>';
print '</form>'."\n";
print '</center>'."\n";
dud_html_bottom();