summaryrefslogtreecommitdiff
path: root/modules/search.module
blob: 7beb1e74c26525496ad5567c05e0db7f32e863f6 (plain)
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
<?php

function search_perm() {
  return array("search content");
}

function search_link($type) {
  if ($type == "page" && user_access("search content")) {
    $links[] = "<a href=\"module.php?mod=search\">search</a>";
  }

  return $links ? $links : array();
}

function search_page() {
  global $theme, $type, $keys, $REQUEST_URI;

  if (user_access("search content")) {
    // verify input:
    $type = check_input($type);
    $keys = check_input($keys);

    // build options list:
    foreach (module_list() as $name) {
      if (module_hook($name, "search")) {
        $options .= "<option value=\"$name\"". ($name == $type ? " selected" : "") .">$name</option>\n";
      }
    }

    // build form:
    $form .= "<form action=\"$REQUEST_URI\" method=\"POST\">\n";
    $form .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" TYPE=\"text\">\n";
    $form .= " <select name=\"type\">$options</select>\n";
    $form .= " <input type=\"submit\" value=\"". t("Search") ."\">\n";
    $form .= "</form>\n";

    // visualize form:
    $theme->header();

    if ($form) {
      $theme->box(t("Search"), $form);
    }

    if ($keys) {
      $theme->box(t("Result"), search_data($keys, $type));
    }

    $theme->footer();
  }
  else {
    $theme->header();
    $theme->box("Access denied", message_access());
    $theme->footer();
  }
}

?>