jdarwood007 commited on 2016-12-31 21:17:30
Showing 2 changed files, with 29 additions and 10 deletions.
Signed-off-by: jdarwood007 <unmonitored+github@sleepycode.com>
... | ... |
@@ -222,10 +222,12 @@ function shd_search2() |
222 | 222 |
$context['pagenum'] = 1; |
223 | 223 |
|
224 | 224 |
// Pages. |
225 |
+ $context['current_page'] = $context['pagenum']; |
|
225 | 226 |
$context['next_page'] = $context['pagenum'] + 1; |
226 | 227 |
$context['prev_page'] = $context['pagenum'] < 2 ? 0 : $context['pagenum'] - 1; |
227 | 228 |
|
228 | 229 |
$number_per_page = 20; |
230 |
+ $context['num_pages'] = 1; |
|
229 | 231 |
|
230 | 232 |
// OK, so are there any words? If not, execute this sucker the quick way and get out to the template quick. |
231 | 233 |
$context['search_terms'] = !empty($_POST['search']) ? trim($_POST['search']) : ''; |
... | ... |
@@ -295,6 +297,8 @@ function shd_search2() |
295 | 297 |
else |
296 | 298 |
$context['pagenum'] = 1; |
297 | 299 |
|
300 |
+ $context['num_pages'] = ceil($context['num_results'] / $number_per_page); |
|
301 |
+ |
|
298 | 302 |
$query = shd_db_query('', ' |
299 | 303 |
SELECT hdt.id_ticket, hdt.id_dept, hdd.dept_name, hdt.subject, hdt.urgency, hdt.private, hdt.last_updated, hdtr.body, |
300 | 304 |
hdtr.smileys_enabled, hdtr.id_member AS id_member, IFNULL(mem.real_name, hdtr.poster_name) AS poster_name, hdtr.poster_time |
... | ... |
@@ -456,6 +460,8 @@ function shd_search2() |
456 | 460 |
else |
457 | 461 |
$context['pagenum'] = 1; |
458 | 462 |
|
463 |
+ $context['num_pages'] = ceil($context['num_results'] / $number_per_page); |
|
464 |
+ |
|
459 | 465 |
// Get the results for displaying. |
460 | 466 |
$query = shd_db_query('', ' |
461 | 467 |
SELECT hdt.id_ticket, hdt.id_dept, hdd.dept_name, hdt.subject, hdt.urgency, hdt.private, hdt.last_updated, hdtr.body, |
... | ... |
@@ -307,11 +307,6 @@ function template_search_results() |
307 | 307 |
</h3> |
308 | 308 |
</div>'; |
309 | 309 |
|
310 |
- // Page navigation. It's not your usual page index, and with good reason: we can't use regular links here without risking server hammering. |
|
311 |
- $num_pages = ceil($context['num_results'] / $context['search_params']['limit']); |
|
312 |
- $pages = array(); |
|
313 |
- for ($page = $context['pagenum'] - 2; $page <= $context['pagenum'] + 2; $page++) |
|
314 |
- $pages[] = $page; |
|
315 | 310 |
|
316 | 311 |
// The rest of it would go here, in a nice form that carried everything through for next time, with a button named page whose value would be the page number for each page (plus prev/next) you wanted to display |
317 | 312 |
|
... | ... |
@@ -342,6 +337,15 @@ function template_search_results() |
342 | 337 |
<div class="windowbg">'; |
343 | 338 |
|
344 | 339 |
template_search_navigation('prev'); |
340 |
+ |
|
341 |
+ echo '<div style="width: 50%; margin: 0 auto;">'; |
|
342 |
+ |
|
343 |
+ // Page navigation. It's not your usual page index, and with good reason: we can't use regular links here without risking server hammering. |
|
344 |
+ for ($page = $context['current_page'] - 2; $page <= $context['current_page'] + 2; $page++) |
|
345 |
+ template_search_navigation($page); |
|
346 |
+ |
|
347 |
+ echo '</div>'; |
|
348 |
+ |
|
345 | 349 |
template_search_navigation('next'); |
346 | 350 |
|
347 | 351 |
echo ' |
... | ... |
@@ -349,11 +353,16 @@ function template_search_results() |
349 | 353 |
</div>'; |
350 | 354 |
} |
351 | 355 |
|
352 |
-function template_search_navigation($direction = 'next') |
|
356 |
+function template_search_navigation($page = 'next') |
|
353 | 357 |
{ |
354 | 358 |
global $scripturl, $context, $txt, $smcFunc; |
355 | 359 |
|
356 |
- if ($direction == 'prev' && empty($context['prev_page'])) |
|
360 |
+ // Handle the page check. |
|
361 |
+ if ($page == 'prev' && empty($context['prev_page'])) |
|
362 |
+ return; |
|
363 |
+ elseif ($page == 'next' && $context['current_page'] >= $context['num_pages']) |
|
364 |
+ return; |
|
365 |
+ elseif (is_int($page) && ($page < 1 || $page >= $context['num_pages'])) |
|
357 | 366 |
return; |
358 | 367 |
|
359 | 368 |
echo ' |
... | ... |
@@ -400,14 +409,18 @@ function template_search_navigation($direction = 'next') |
400 | 409 |
echo ' |
401 | 410 |
<input type="hidden" name="search" value="', $smcFunc['htmlspecialchars']($context['search_terms']), '">'; |
402 | 411 |
|
403 |
- if ($direction == 'prev') |
|
412 |
+ if ($page === 'prev') |
|
404 | 413 |
echo ' |
405 | 414 |
<input type="hidden" name="page" value="', $context['prev_page'], '" /> |
406 |
- <input type="submit" value="Previous" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit floatleft" />'; |
|
415 |
+ <input type="submit" value="Previous" onclick="return submitThisOnce(this);" class="button_submit floatleft" />'; |
|
416 |
+ elseif (is_int($page) && $page > 0) |
|
417 |
+ echo ' |
|
418 |
+ <input type="hidden" name="page" value="', $page, '" /> |
|
419 |
+ <input type="submit" value="Page ', $page, '" onclick="return submitThisOnce(this);" class="button_submit floatleft', $context['current_page'] == $page ? ' active' : '', '" />'; |
|
407 | 420 |
else |
408 | 421 |
echo ' |
409 | 422 |
<input type="hidden" name="page" value="', $context['next_page'], '" /> |
410 |
- <input type="submit" value="Next" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />'; |
|
423 |
+ <input type="submit" value="Next" onclick="return submitThisOnce(this);" class="button_submit" />'; |
|
411 | 424 |
|
412 | 425 |
echo '</form>'; |
413 | 426 |
} |
414 | 427 |
\ No newline at end of file |
415 | 428 |