Beehive PHP Cross Reference Discussion Forums

Source: /search_popup.php - 334 lines - 13387 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  
   5  Copyright Project Beehive Forum 2002
   6  
   7  This file is part of Beehive Forum.
   8  
   9  Beehive Forum is free software; you can redistribute it and/or modify
  10  it under the terms of the GNU General Public License as published by
  11  the Free Software Foundation; either version 3 of the License, or
  12  (at your option) any later version.
  13  
  14  Beehive Forum is distributed in the hope that it will be useful,
  15  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  GNU General Public License for more details.
  18  
  19  You should have received a copy of the GNU General Public License
  20  along with Beehive; if not, write to the Free Software
  21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22  USA
  23  
  24  ======================================================================*/
  25  
  26  // Bootstrap
  27  require_once  'boot.php';
  28  
  29  // Required includes
  30  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'form.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'thread.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'user.inc.php';
  37  require_once  BH_INCLUDE_PATH . 'word_filter.inc.php';
  38  // End Required includes
  39  
  40  // Check we're logged in correctly
  41  if (!session::logged_in()) {
  42      html_guest_error();
  43  }
  44  
  45  $type = null;
  46  $obj_id = null;
  47  
  48  // Check if we're allowed multiple-select.
  49  if (isset($_POST['multi']) && $_POST['multi'] == 'Y') {
  50      $multi = 'Y';
  51  } else if (isset($_GET['multi']) && $_GET['multi'] == 'Y') {
  52      $multi = 'Y';
  53  } else {
  54      $multi = 'N';
  55  }
  56  
  57  // Search type
  58  if (isset($_GET['type']) && in_array($_GET['type'], array(SEARCH_LOGON, SEARCH_THREAD))) {
  59  
  60      $type = $_GET['type'];
  61  
  62  } else if (isset($_POST['type']) && in_array($_POST['type'], array(SEARCH_LOGON, SEARCH_THREAD))) {
  63  
  64      $type = $_POST['type'];
  65  
  66  } else {
  67  
  68      html_draw_error(gettext("You must specify type of search to perform"));
  69  }
  70  
  71  // Check the multi selection with the type
  72  if ($type == SEARCH_THREAD) $multi = 'N';
  73  
  74  // Form Object ID
  75  if (isset($_POST['obj_id']) && strlen(trim($_POST['obj_id'])) > 0) {
  76  
  77      $obj_id = trim($_POST['obj_id']);
  78  
  79  } else if (isset($_GET['obj_id']) && strlen(trim($_GET['obj_id'])) > 0) {
  80  
  81      $obj_id = trim($_GET['obj_id']);
  82  
  83  } else {
  84  
  85      html_draw_error(gettext("No form object specified for return text"));
  86  }
  87  
  88  // Current selection
  89  if (isset($_POST['selected']) && is_array($_POST['selected'])) {
  90      $selected_array = array_unique($_POST['selected']);
  91  } else if (isset($_GET['selected']) && strlen(trim($_GET['selected'])) > 0) {
  92      $selected_array = array_unique(preg_split('/,\s*/u', trim($_GET['selected'], ', ')));
  93  } else {
  94      $selected_array = array();
  95  }
  96  
  97  // Make sure the selected_array is not greater than maxmium
  98  if (($type == SEARCH_LOGON) && $multi === 'Y') {
  99      $selected_array = array_splice($selected_array, 0, 10);
 100  } else {
 101      $selected_array = array_splice($selected_array, 0, 1);
 102  }
 103  
 104  // Check for search query
 105  if (isset($_GET['search_query']) && strlen(trim($_GET['search_query']))) {
 106  
 107      $search_query = trim($_GET['search_query']);
 108  
 109  } else if (isset($_POST['search_query']) && strlen(trim($_POST['search_query']))) {
 110  
 111      $search_query = trim($_POST['search_query']);
 112  
 113  } else if (($type == SEARCH_LOGON) && (sizeof($selected_array) > 0)) {
 114  
 115      $search_query = implode(', ', $selected_array);
 116  
 117  } else if (($type == SEARCH_THREAD) && (sizeof($selected_array) > 0)) {
 118  
 119      list($selected_tid) = $selected_array;
 120  
 121      if (($thread_data = thread_get($selected_tid)) !== false) {
 122          $search_query = $thread_data['TITLE'];
 123      }
 124  }
 125  
 126  // Array to hold any error messages
 127  $error_msg_array = array();
 128  
 129  // Selection for page links
 130  if (is_array($selected_array) && sizeof($selected_array) > 0) {
 131      $selected = implode(', ', $selected_array);
 132  } else {
 133      $selected = "";
 134  }
 135  
 136  // Empty array for storing the results of our search
 137  $search_results_array = array();
 138  
 139  // If everything is OK we can perform the search.
 140  if (isset($search_query) && strlen(trim($search_query)) > 0) {
 141  
 142      if ($type == SEARCH_LOGON) {
 143  
 144          $search_results_array = user_search($search_query, $selected_array);
 145  
 146      } else if ($type == SEARCH_THREAD) {
 147  
 148          $search_results_array = thread_search($search_query, $selected_array);
 149      }
 150  }
 151  
 152  html_draw_top(sprintf('title=%s', gettext("Search")), 'pm_popup_disabled', 'js/search_popup.js', 'class=window_title');
 153  
 154  echo "<h1>", gettext("Search"), "</h1>\n";
 155  
 156  if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
 157  
 158      html_display_error_array($error_msg_array, '450', 'center');
 159  
 160  } else if (isset($search_results_array['results_array']) && sizeof($search_results_array['results_array']) < 1 && sizeof($selected_array) < 1) {
 161  
 162      html_display_warning_msg(gettext("Search Returned No Results"), '450', 'center');
 163  
 164  } else {
 165  
 166      echo "<br />\n";
 167  }
 168  
 169  echo "<div align=\"center\">\n";
 170  echo "<form accept-charset=\"utf-8\" action=\"search_popup.php\" method=\"post\">\n";
 171  echo "  ", form_input_hidden("webtag", htmlentities_array($webtag)), "\n";
 172  echo "  ", form_input_hidden("obj_id", htmlentities_array($obj_id)), "\n";
 173  echo "  ", form_input_hidden("type", htmlentities_array($type)), "\n";
 174  echo "  ", form_input_hidden("multi", htmlentities_array($multi)), "\n";
 175  
 176  if (sizeof($selected_array) > 0 || (isset($search_results_array['results_array']) && sizeof($search_results_array['results_array']) > 0)) {
 177  
 178      echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"450\">\n";
 179      echo "    <tr>\n";
 180      echo "      <td align=\"left\">\n";
 181      echo "        <table class=\"box\" width=\"100%\">\n";
 182      echo "          <tr>\n";
 183      echo "            <td align=\"left\" class=\"posthead\">\n";
 184      echo "              <table class=\"posthead\" width=\"100%\">\n";
 185      echo "                <tr>\n";
 186      echo "                  <td class=\"subhead\" align=\"left\">", gettext("Search Results"), "</td>\n";
 187      echo "                </tr>\n";
 188      echo "                <tr>\n";
 189      echo "                  <td align=\"center\">\n";
 190      echo "                    <div class=\"search_popup_results\">\n";
 191      echo "                      <table width=\"95%\">\n";
 192  }
 193  
 194  if (sizeof($selected_array) > 0) {
 195  
 196      foreach ($selected_array as $selected_option) {
 197  
 198          if (($type == SEARCH_LOGON) && ($user_data = user_get_by_logon($selected_option))) {
 199  
 200              if ($multi === 'Y') {
 201  
 202                  echo "                      <tr>\n";
 203                  echo "                        <td align=\"left\">", form_checkbox("selected[]", htmlentities_array($user_data['LOGON']), null, true), "&nbsp;<a href=\"user_profile.php?webtag=$webtag&amp;uid={$user_data['UID']}\" target=\"_blank\" class=\"popup 650x500\">", word_filter_add_ob_tags(format_user_name($user_data['LOGON'], $user_data['NICKNAME']), true), "</a></td>\n";
 204                  echo "                      </tr>\n";
 205  
 206              } else {
 207  
 208                  echo "                      <tr>\n";
 209                  echo "                        <td align=\"left\">", form_radio("selected", htmlentities_array($user_data['LOGON']), null, true), "&nbsp;<a href=\"user_profile.php?webtag=$webtag&amp;uid={$user_data['UID']}\" target=\"_blank\" class=\"popup 650x500\">", word_filter_add_ob_tags(format_user_name($user_data['LOGON'], $user_data['NICKNAME']), true), "</a></td>\n";
 210                  echo "                      </tr>\n";
 211              }
 212  
 213          } else if (($thread_data = thread_get($selected_option)) !== false) {
 214  
 215              echo "                      <tr>\n";
 216              echo "                        <td align=\"left\">", form_radio("selected", $thread_data['TID'], null, true), "&nbsp;<a href=\"messages.php?webtag=$webtag&amp;msg={$thread_data['TID']}.1\" target=\"_blank\">", word_filter_add_ob_tags($thread_data['TITLE'], true), "</a></td>\n";
 217              echo "                      </tr>\n";
 218          }
 219      }
 220  
 221      if (isset($search_results_array['results_array']) && sizeof($search_results_array['results_array']) > 0) {
 222  
 223          echo "                      <tr>\n";
 224          echo "                        <td align=\"left\"><hr /></td>\n";
 225          echo "                      </tr>\n";
 226      }
 227  }
 228  
 229  if (isset($search_results_array['results_array']) && sizeof($search_results_array['results_array']) > 0) {
 230  
 231      foreach ($search_results_array['results_array'] as $search_result) {
 232  
 233          if (($type == SEARCH_LOGON) && !in_array($search_result['LOGON'], $selected_array)) {
 234  
 235              if ($multi === 'Y') {
 236  
 237                  echo "                      <tr>\n";
 238                  echo "                        <td align=\"left\">", form_checkbox("selected[]", htmlentities_array($search_result['LOGON'])), "&nbsp;<a href=\"user_profile.php?webtag=$webtag&amp;uid={$search_result['UID']}\" target=\"_blank\" class=\"popup 650x500\">", word_filter_add_ob_tags(format_user_name($search_result['LOGON'], $search_result['NICKNAME']), true), "</a></td>\n";
 239                  echo "                      </tr>\n";
 240  
 241              } else {
 242  
 243                  echo "                      <tr>\n";
 244                  echo "                        <td align=\"left\">", form_radio("selected", htmlentities_array($search_result['LOGON'])), "&nbsp;<a href=\"user_profile.php?webtag=$webtag&amp;uid={$search_result['UID']}\" target=\"_blank\" class=\"popup 650x500\">", word_filter_add_ob_tags(format_user_name($search_result['LOGON'], $search_result['NICKNAME']), true), "</a></td>\n";
 245                  echo "                      </tr>\n";
 246              }
 247  
 248          } else if (($type == SEARCH_THREAD) && !in_array($search_result['TID'], $selected_array)) {
 249  
 250              echo "                      <tr>\n";
 251              echo "                        <td align=\"left\">", form_radio("selected", $search_result['TID']), "&nbsp;<a href=\"messages.php?webtag=$webtag&amp;msg={$search_result['TID']}.1\" target=\"_blank\">", word_filter_add_ob_tags($search_result['TITLE'], true), "</a></td>\n";
 252              echo "                      </tr>\n";
 253          }
 254      }
 255  }
 256  
 257  if (sizeof($selected_array) > 0 || (isset($search_results_array['results_array']) && sizeof($search_results_array['results_array']) > 0)) {
 258  
 259      echo "                        <tr>\n";
 260      echo "                          <td class=\"postbody\">&nbsp;</td>\n";
 261      echo "                        </tr>\n";
 262      echo "                      </table>\n";
 263      echo "                    </div>\n";
 264      echo "                  </td>\n";
 265      echo "                </tr>\n";
 266      echo "              </table>\n";
 267      echo "            </td>\n";
 268      echo "          </tr>\n";
 269      echo "        </table>\n";
 270      echo "      </td>\n";
 271      echo "    </tr>\n";
 272      echo "    <tr>\n";
 273      echo "      <td class=\"postbody\">&nbsp;</td>\n";
 274      echo "    </tr>\n";
 275      echo "  </table>\n";
 276      echo "  <br />\n";
 277  }
 278  
 279  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"450\">\n";
 280  echo "    <tr>\n";
 281  echo "      <td align=\"left\">\n";
 282  echo "        <table class=\"box\" width=\"100%\">\n";
 283  echo "          <tr>\n";
 284  echo "            <td align=\"left\" class=\"posthead\">\n";
 285  echo "              <table class=\"posthead\" width=\"100%\">\n";
 286  
 287  if ($type == SEARCH_LOGON) {
 288  
 289      echo "                <tr>\n";
 290      echo "                  <td class=\"subhead\" align=\"left\">", gettext("Search For User"), "</td>\n";
 291      echo "                </tr>\n";
 292      echo "                <tr>\n";
 293      echo "                  <td align=\"center\">\n";
 294      echo "                    <table width=\"95%\">\n";
 295      echo "                      <tr>\n";
 296      echo "                        <td align=\"left\" width=\"100\">", gettext("Username"), ":</td>\n";
 297  
 298  } else if ($type == SEARCH_THREAD) {
 299  
 300      echo "                <tr>\n";
 301      echo "                  <td class=\"subhead\" align=\"left\">", gettext("Search For Thread"), "</td>\n";
 302      echo "                </tr>\n";
 303      echo "                <tr>\n";
 304      echo "                  <td align=\"center\">\n";
 305      echo "                    <table width=\"95%\">\n";
 306      echo "                      <tr>\n";
 307      echo "                        <td align=\"left\" width=\"100\">", gettext("Thread title"), ":</td>\n";
 308  }
 309  
 310  echo "                        <td class=\"posthead\" align=\"left\">", form_input_text('search_query', (isset($search_query) ? htmlentities_array($search_query) : ''), 40, 64), form_submit('search', gettext("Search"), 'style="display: none"'), "</td>\n";
 311  echo "                      </tr>\n";
 312  echo "                    </table>\n";
 313  echo "                  </td>\n";
 314  echo "                </tr>\n";
 315  echo "                <tr>\n";
 316  echo "                  <td align=\"left\" colspan=\"6\">&nbsp;</td>\n";
 317  echo "                </tr>\n";
 318  echo "              </table>\n";
 319  echo "            </td>\n";
 320  echo "          </tr>\n";
 321  echo "        </table>\n";
 322  echo "      </td>\n";
 323  echo "    </tr>\n";
 324  echo "  </table>\n";
 325  echo "  <br />\n";
 326  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"450\">\n";
 327  echo "    <tr>\n";
 328  echo "      <td align=\"center\">", form_button('select', gettext("Select")), "&nbsp;", form_submit('search', gettext("Search")), "&nbsp;", form_submit('close_popup', gettext("Close")), "</td>\n";
 329  echo "    </tr>\n";
 330  echo "  </table>\n";
 331  echo "</form>\n";
 332  echo "</div>\n";
 333  
 334  html_draw_bottom();

title

Description

title

Description

title

Description

title

title

Body