Pm/Search.pm
1001 lines of code
1
package Search;
2
3
#/
4
# to generate a list of UID's based on multiple criteria
5
# this includes two subroutines for HTML'izing output
6
# although, they ought to be moved into the HTML module.<br>
7
8
# <div class=error>search results will never include the loggedin user!
9
# nor will results include admins+</div>
10
# <br><hr>
11
# This module will be upgraded to use Html2.pm
12
# There is no schedule, and it will likely occur in random, small
13
# ways, and slowly move toward full conversion from Html.pm to Html2.pm
14
#/
15
16
my $TABLE_BORDER = 0;
17
18
###################################################################################################################
19
use strict;
20
use warnings;
21
use Exporter;
22
use vars qw($VERSION @ISA @EXPORT_OK @EXPORT);
23
use CGI::Carp qw(fatalsToBrowser);
24
25
###################################################################################################################
26
$VERSION     = 1.00;
27
@ISA         = qw(Exporter);
28
29
@EXPORT = qw(
30
             search
31
             search_results_asHTML
32
            );
33
34
@EXPORT_OK   = qw(
35
                  _tests
36
37
                  search
38
39
                  search_nav
40
                  search_results_asHTML
41
42
                  $last_search_sql_statement
43
                 );
44
45
###################################################################################################################
46
47
use lib "./Pm";
48
49
require Bc_chef;
50
require Bc_misc;
51
require Bc_sql;
52
require Date;
53
require User;
54
require Html;
55
require Html2;
56
57
###################################################################################################################
58
59
60
########################################################################################################################
61
sub search($;$$) {
62
  #*
63
  # to search for UID's which match one or more criteria
64
  # always returns an array reference; array can be empty
65
  # set $DEBUG to 1 to enable debug mode.  set it to 2 to
66
  # display more debug info
67
  #*
68
  my ($terms, $includeAdmins, $DEBUG) = @_; # search terms (eg: gender,2--seeking,7) && include admins (optional, default = 0) && debug on/off toggle (optional, default = 0)
69
  my $rv = \();
70
  my $location_search = 0;
71
  my $dob_search = 0;
72
73
  # some "terms" are not actually stored in the database and must
74
  # be calculated and/or converted/removed from the terms list
75
  if ($terms) {
76
    my @st = split("--", $terms);
77
    if (@st) {
78
      my $sql = "select ID, location, dob";
79
      if ($DEBUG) { $sql .= ", nickname"; }
80
      $sql .= " from users where";
81
      if (not $includeAdmins) {
82
        $sql .= " (security='1' or security='2')";
83
      }
84
85
      foreach my $term (@st) {
86
        my ($col, $val) = split(/,|=/, $term);
87
88
        if ($col eq "age") {
89
          if ($val ne '999') {
90
            # "age" = 1 ---> 18 to 22
91
            # today's date minus earliest age range (ie: 22)
92
            my $year = Date::get_year(); # 2019
93
            $year -= 18 + (($val-1) * 5) + 4; # ie: 2019 - 22 = 1997
94
            my $day = Date::get_today("d", 1);
95
            my $month = Date::get_today("m", 1);
96
            my $sd = $Bc_sql::DB->quote("$year-$month-$day"); # start, or earliest date
97
            my $ed = $Bc_sql::DB->quote(($year+4) . "-$month-$day"); # is this the right end/latest date?
98
            $sql .= " and dob between date($sd) and date($ed)";
99
          }
100
101
        } elsif ($col eq "location") {
102
103
          # location = country-city
104
          # -----------------------
105
          # location = 31-254
106
          # location = 31-31
107
          # location = 5-11
108
          # location = 1-2
109
          # location = 1-22
110
111
          my ($country, $city) = split(/-/, $val);
112
          if ($country ne '999') {
113
            if ($city ne '999') {
114
              $val = $Bc_sql::DB->quote($val);
115
              $sql .= " and location=$val";
116
            } else {
117
              $location_search = $val; # otherwise, we gotta filter after we get the list
118
            }
119
          }
120
121
        } elsif ($col eq "dob") {
122
123
          my ($y, $m, $d) = split('-', $val);
124
          if ($y ne '999' and $m ne '999' and $d ne '999') {
125
            # exact date
126
            $sql .= " and dob >= date('$y-$m-$d') and dob < date('$y-$m-$d', '+1 day')";
127
          } else {
128
            # search by year, month, and/or day!
129
            $dob_search = $val; # tell script to later filter for this dob search
130
          }
131
132
        } else {
133
134
          if ($val ne '999') {
135
            if ($col ne "nickname") {
136
              $col = $Bc_sql::DB->quote_identifier($col);
137
              $val = $Bc_sql::DB->quote($val);
138
              $sql .= " and $col=$val";
139
            } else {
140
              $col = $Bc_sql::DB->quote_identifier($col);
141
              $val = $Bc_sql::DB->quote($val . '%');
142
              $sql .= " and $col like $val";
143
            }
144
          }
145
146
        }
147
      }
148
149
      # now, maybe we have a trailing " where " on the end?
150
      $sql =~ s/( )+$//; # remove trailing spaces
151
      $sql =~ s/ where$//; # remove trailing where
152
      $sql =~ s/ where and/ where/; # fix " where and" glitch, lol
153
154
      my $s = Bc_sql::sql_execute($sql, "search"); # @$s[0] = hash reference. @$s[0]->{ID} = 7EE.....
155
156
      # now, make a list of just UIDs
157
      my @t = ();
158
      if ($DEBUG) {
159
        if ($DEBUG == 2)
160
          { push @t, "displaying nicknames or other data<br>\n"; } else
161
          { push @t, "NOT displaying nicknames or other data<br>\n"; }
162
        if (@t) {
163
          $t[0] .= $sql . "<br>\n";
164
        } else {
165
          push @t, $sql . "<br>\n";
166
        }
167
      }
168
169
      if (ref $s eq "ARRAY") {
170
        my ($country, $city) = split(/-/, $location_search);
171
        if ($DEBUG) {
172
          if ($location_search) { $t[0] .= "Location Search: $city in country #$country<br>\n"; }
173
          if ($dob_search) { $t[0] .= "DOB Search: $dob_search<br>\n"; }
174
        }
175
176
        foreach my $hit (@$s) {
177
          if ($location_search) {
178
            # location search when not exact location (eg: 31-999, or 999-254)
179
            if ($country eq '999') {
180
              push @t, $hit->{ID};
181
            } else {
182
              # specific country
183
              # we already dealt with exact location (31-254)
184
              # so we know the search is for all cities in
185
              # the country being asked for.  but, check anyway
186
              if ($city eq '999') {
187
                my ($hitcountry, $hitcity) = split(/-/, $hit->{location});
188
                if ($DEBUG) {
189
                  if ($hitcountry eq $country) {
190
                    my $data = $hit->{ID};
191
                    if ($DEBUG == 2) {
192
                      $data .=  ": " . $hit->{location};
193
                      $data .= " ($hit->{nickname})";
194
                    }
195
196
                    push @t, $data;
197
                  }
198
                } else {
199
                  if ($hitcountry eq $country) { push @t, $hit->{ID}; }
200
                }
201
              } else {
202
                if ($city eq $hit->{location}) { push @t, $hit->{ID}; }
203
              }
204
            }
205
          } elsif ($dob_search) {
206
            # year, month, and/or day can each be exact or 999
207
            # will not be an exact date
208
            # shouldn't ever be 999-999-999 (submitting form removes this from search terms)
209
            my ($y, $m, $d) = split('-', $dob_search);
210
            my ($hy, $hm, $hd) = split('-', $hit->{dob});
211
212
            my $add = 0;
213
            if    ($y eq $hy   and $m eq '999' and $d eq '999') { $add = 1; } # 2000-999-999
214
            elsif ($y eq $hy   and $m eq $hm   and $d eq '999') { $add = 1; } # 2000-01-999
215
            elsif ($y eq $hy   and $m eq '999' and $d eq $hd)   { $add = 1; } # 2000-999-01
216
            elsif ($y eq '999' and $m eq $hm   and $d eq '999') { $add = 1; } # 999-01-999
217
            elsif ($y eq '999' and $m eq $hm   and $d eq $hd)   { $add = 1; } # 999-01-01
218
            elsif ($y eq '999' and $m eq '999' and $d eq $hd)   { $add = 1; } # 999-999-01
219
            # 999-999-999
220
221
            if ($add) { push @t, $hit->{ID}; }
222
          } else {
223
            push @t, $hit->{ID};
224
          }
225
        }
226
      } elsif (ref $s eq "HASH") {
227
        if (not $DEBUG) { @t = (); }
228
229
        if ($location_search) {
230
          if ($location_search eq $s->{location}) {
231
            if ($DEBUG) {
232
              $t[1] = $s->{ID};
233
              if ($DEBUG == 2) {
234
                $t[1] .= $s->{nickname};
235
              }
236
            } else {
237
              $t[0] = $s->{ID};
238
            }
239
          }
240
        } else {
241
          if ($DEBUG) {
242
            $t[1] = $s->{ID};
243
          } else {
244
            $t[0] = $s->{ID};
245
          }
246
        }
247
      } else {
248
        if ($DEBUG) { $t[0] .= "invalid sql syntax<br>\n"; }
249
      }
250
251
      $rv = \@t;
252
    } else {
253
      if ($DEBUG) { my @t = (); push @t, "split() failed?? \$terms = $terms"; $rv = \@t; }
254
    }
255
  } else {
256
    if ($DEBUG) {
257
      my @t = ("no terms given! \$terms=$terms");
258
      $rv = \@t;
259
    }
260
  }
261
262
  if ($DEBUG) {
263
    $rv->[0] .= "<hr>\n";
264
  }
265
266
  return $rv; # a reference to an array of UID's (can be empty)
267
  #usage: my $uids = search($terms);
268
}
269
270
########################################################################################################################
271
sub search_nav($$$$$$;$) {
272
  #*
273
  # generates a navbar specifically for the search results page
274
  # !i'm not sure why i have included $noResults!
275
  #*
276
  my ($noResults, $sResultsRef, $criteria, $page, $hpp, $spacing, $DEBUG) = @_; # show search form (1) or not (0) && a reference to a list of uid's to search && a reference to a list of criteria to meet && the page to display && the number of hits to display per page && spacing for pretty printing HTML output && toggle debug (optional, default = 0)
277
  if ($DEBUG ne 1) { $DEBUG = 0; }
278
  my $RESULTS_BORDER = 0;
279
280
  if (not $hpp or $hpp < 10) { $hpp = 10; }
281
  if ($hpp > 30) { $hpp = 30; }
282
  my $numPages = int(@$sResultsRef/$hpp);
283
  if ($numPages * $hpp < @$sResultsRef) { $numPages++; }
284
  if (($page+1) > $numPages) { $page = $numPages-1; }
285
  if ($page < 0 or not $page) { $page = 0; }
286
287
  my $start = $page * $hpp;
288
  my $end = $start + $hpp;
289
290
  if ($start < 0) { $start = 0; }
291
  if ($start > @$sResultsRef) { $start = (($numPages - 1)*$hpp); }
292
  if ($end > @$sResultsRef) { $end = @$sResultsRef; }
293
294
  my $terms = "";
295
  foreach my $term (@$criteria) { $terms .= $term . "--"; }
296
297
  my $output = "$spacing<!-- BEGIN MINI SEARCH NAV -->\n";
298
  $output .= "$spacing<table align=center border=$RESULTS_BORDER cellpadding=0 cellspacing=0 width=65%><tr><td align=center><div class=subnavbar>\n";
299
  if ($noResults) {
300
    $output .= "$spacing  <table border=$RESULTS_BORDER cellpadding=0 cellspacing=0 width=100%><tr><td>\n";
301
  } else {
302
    $output .= "$spacing  <table border=$RESULTS_BORDER cellpadding=0 cellspacing=0 width=100%><tr><td><form action=\"#search_list\">\n";
303
304
    ########
305
    my $hppDropdown = "$spacing    <input type=hidden  name=\"$Bc_sql::QUERY_PAGE\" value=\"" . get_constant("SEARCH_PAGE") . "\">\n";
306
    $hppDropdown .= "$spacing    <input type=hidden name='" . get_constant("QUERY_SEARCH_PAGE") . "' value='$page'>\n";
307
    $hppDropdown .= "$spacing    <input type=hidden name=\"" . get_constant("QUERY_SEARCH_TERMS") . "\" value=\"$terms\">\n";
308
    $hppDropdown .= "$spacing    <select name=\"" . get_constant("QUERY_SEARCH_HPP") . "\" onChange=\"this.form.submit();\">\n";
309
    if ($hpp eq 10) { $hppDropdown .= "$spacing      <option value='10' selected>10\n"; } else { $hppDropdown .= "$spacing      <option value='10'>10\n"; }
310
    if ($hpp eq 15) { $hppDropdown .= "$spacing      <option value='15' selected>15\n"; } else { $hppDropdown .= "$spacing      <option value='15'>15\n"; }
311
    if ($hpp eq 20) { $hppDropdown .= "$spacing      <option value='20' selected>20\n"; } else { $hppDropdown .= "$spacing      <option value='20'>20\n"; }
312
    if ($hpp eq 25) { $hppDropdown .= "$spacing      <option value='25' selected>25\n"; } else { $hppDropdown .= "$spacing      <option value='25'>25\n"; }
313
    if ($hpp eq 30) { $hppDropdown .= "$spacing      <option value='30' selected>30\n"; } else { $hppDropdown .= "$spacing      <option value='30'>30\n"; }
314
    $hppDropdown .= "$spacing    </select>\n";
315
    ########
316
317
    $output .= "$spacing    showing <b>" . ($start+1) . "</b> to <b>$end</b> of <b>" . commafied(@$sResultsRef);
318
    $output .= "</b> result";
319
    if (@$sResultsRef > 1 or not @$sResultsRef) { $output .= "s"; }
320
    $output .= " (page <b>" . ($page+1) . "</b> of <b>" . commafied($numPages) . "</b> @ \n";
321
    $output .= $hppDropdown . "$spacing    results per page)<br>\n";
322
    $output .= "$spacing  </form></td></tr><tr><td align=center>\n";
323
  }
324
325
  my $pageRangeStart = $page - 3;
326
  if ($pageRangeStart < 0) { $pageRangeStart = 0; }
327
  my $pageRangeEnd = $pageRangeStart + 7;
328
  if ($pageRangeEnd > $numPages-1) {
329
    $pageRangeEnd = $numPages-1;
330
    $pageRangeStart = $pageRangeEnd - 7;
331
    if ($pageRangeStart < 0) { $pageRangeStart = 0; }
332
  }
333
334
  # nav to first page
335
  if ($page ne 0) {
336
    $output .= "$spacing    <a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&" . get_constant("QUERY_SEARCH_PAGE") . "=0&" . get_constant("QUERY_SEARCH_HPP") . "=$hpp&" . get_constant("QUERY_SEARCH_TERMS") . "=$terms#search_list\">««</a>";
337
  } else {
338
    $output .= "$spacing    ««";
339
  }
340
  $output .= " $Bc_misc::COOL_DOT ";
341
342
  # nav to previous page
343
  if ($page ne 0) {
344
    $output .= "<a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&" . get_constant("QUERY_SEARCH_PAGE") . "=" . ($page-1) . "&" . get_constant("QUERY_SEARCH_HPP") . "=$hpp&" . get_constant("QUERY_SEARCH_TERMS") . "=$terms#search_list\">«</a>";
345
  } else {
346
    $output .= "«";
347
  }
348
  $output .= " $Bc_misc::COOL_DOT ";
349
350
  # the numbers game....what a bitch this is!
351
  if ($pageRangeStart > 0) { $output .= "$Pm::Bc_misc::COOL_DOT $Pm::Bc_misc::COOL_DOT"; }
352
  for (my $pNum = $pageRangeStart; $pNum <= $pageRangeEnd; $pNum++) {
353
    if ($pNum ne $page) {
354
      $output .= "<a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&" . get_constant("QUERY_SEARCH_PAGE") . "=$pNum&" . get_constant("QUERY_SEARCH_HPP") . "=$hpp&" . get_constant("QUERY_SEARCH_TERMS") . "=$terms#search_list\">" . ($pNum+1) . "</a>";
355
    } else {
356
      $output .= "<i>" . ($pNum+1) . "</i>";
357
    }
358
  $output .= " $Bc_misc::COOL_DOT ";
359
  }
360
  if ($pageRangeEnd < $numPages-1) { $output .= "$Pm::Bc_misc::COOL_DOT $Pm::Bc_misc::COOL_DOT"; }
361
362
  # nav to next page
363
  if ($page+1 < $numPages) {
364
    $output .= "<a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&" . get_constant("QUERY_SEARCH_PAGE") . "=" . ($page+1) . "&" . get_constant("QUERY_SEARCH_HPP") . "=$hpp&" . get_constant("QUERY_SEARCH_TERMS") . "=$terms#search_list\">»</a>";
365
  } else {
366
    $output .= "»";
367
  }
368
  $output .= " $Bc_misc::COOL_DOT ";
369
370
  # nav to last page
371
  if ($page+1 ne $numPages) {
372
    $output .= "<a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&" . get_constant("QUERY_SEARCH_PAGE") . "=". ($numPages-1) . "&" . get_constant("QUERY_SEARCH_HPP") . "=$hpp&" . get_constant("QUERY_SEARCH_TERMS") . "=$terms#search_list\">»»</a>";
373
  } else {
374
    $output .= "»»";
375
  }
376
377
  # end the nav and give a link to start a new search
378
  $output .= "\n";
379
  if (not $noResults) {
380
    $output .= "$spacing  </div></td></tr><tr><td align=center>\n";
381
    $output .= "$spacing    <hr class=tiny>\n";
382
    $output .= "$spacing    <small><a href=\"/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "#search_list\">New Search</a></small>\n";
383
  }
384
  $output .= "$spacing  </td></tr></table>\n";
385
  $output .= "$spacing</td></tr></table><br>\n";
386
  $output .= "$spacing<!-- END MINI SEARCH NAV -->\n";
387
  #usage: my $snav = search_nav(\@uList, \@terms, 0, 10, "  ");
388
}
389
390
########################################################################################################################
391
sub search_results_asHTML($$$$;$$) {
392
  #*
393
  # same as search_terms(), but this one wraps the list in HTML
394
  # and displays more than just the UID
395
  #*
396
  my ($usersRef, $termsRef, $page, $spacing, $includeAdmins, $DEBUG) = @_; # a reference to a list of UID's && a reference to the search terms && the page to see && for pretty printing HTML output && include admins or not && debug toggle (optional, default = 0)
397
  if ($DEBUG ne 1) { $DEBUG = 0; }
398
399
  my $DEBUG_HTML = 0;
400
  my $RESULTS_BORDER = 0;
401
402
  my $rv = "";
403
404
  if (not $termsRef) {
405
    $rv = "<br><table align=center border=$RESULTS_BORDER cellpadding=0 cellspacing=0><tr><td align=center>\n";
406
    $rv .= $spacing . "  <script>\n";
407
    $rv .= $spacing . "    function get_gender_state() {\n";
408
    $rv .= $spacing . "      var g = document.getElementById('gender');\n";
409
    $rv .= $spacing . "      var e = document.getElementById('erection_div');\n";
410
    $rv .= $spacing . "      var b = document.getElementById('bust_div');\n";
411
    $rv .= $spacing . "      \n";
412
    $rv .= $spacing . "      //alert(g.options[g.selectedIndex].value);\n";
413
    $rv .= $spacing . "      var s = g.options[g.selectedIndex].value;\n";
414
    $rv .= $spacing . "      if (s == '999') { s = 3; }\n";
415
    $rv .= $spacing . "      \n";
416
    $rv .= $spacing . "      ret" . "urn s;\n";
417
    $rv .= $spacing . "    }\n";
418
    $rv .= $spacing . "  </script>\n";
419
    $rv .= $spacing . "  <input type=hidden name=$Bc_sql::QUERY_PAGE value=\"" . get_constant("SEARCH_PAGE") . "\">\n";
420
    $rv .= $spacing . "  <input type=hidden name=sp value=0>\n";
421
    $rv .= $spacing . "  <input type=hidden name=hpp value=10>\n";
422
423
    # user table column names
424
    #   ID, nickname, email, dob, showbday, lastip, password, race, gender, location, orientation,
425
    #   drugs, wheels, can_host, drinker, smoker, seeking, seeking_gender, erection, bust, eye_clr,
426
    #   hair_clr, weight, height, body, enrolled, subscriber, subscription_date, subscription_type,
427
    #   CCID, TID, security, description, banned
428
429
    my $gender_dd = Html::dropdown("gender", "Gender", -1, "", "toggle_display(get_gender_state(), 'erection_div', 'bust_div');", $spacing . "  ", "", "", get_config("genders", 1), "Doesn't Matter");
430
    my $erection_dd = Html::dropdown("erection", "Erection", -1, "", "", $spacing . "  ", "", "", get_config("erections", 1), "Doesn't Matter");
431
    my $bust_dd = Html::dropdown("bust", "Bust", -1, "", "", $spacing . "  ", "", "", get_config("busts", 1), "Doesn't Matter");
432
    my $race_dd = Html::dropdown("race", "Ethnicity", -1, "", "", $spacing . "  ", "", "", get_config("races", 1), "Doesn't Matter");
433
    my $country_dd = Html::dropdown("country", "Country", -1, "", "populate_with_cities('country', 'city', 'Doesn\\\'t Matter');", $spacing . "  ", "style=\"width: 125px;\"", "", get_countries(1), "Doesn't Matter");
434
    my $city_dd = Html::dropdown("city", "City", -1, "", "", $spacing . "  ", "style=\"width: 125px;\"", "", get_country_cities(-1, 0, 1), "Doesn't Matter");
435
    my $orientation_dd = Html::dropdown("orientation", "Orientation", -1, "", "", $spacing . "  ", "", "", get_config("orientations", 1), "Doesn't Matter");
436
    my $drugs_dd = Html::dropdown("drugs", "Drugs", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Doesn't Matter");
437
    my $wheels_dd = Html::dropdown("wheels", "Wheels", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Doesn't Matter");
438
    my $canhost_dd = Html::dropdown("can_host", "Can Host", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Doesn't Matter");
439
    my $drinker_dd = Html::dropdown("drinker", "Drinker", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Doesn't Matter");
440
    my $smoker_dd = Html::dropdown("smoker", "Smoker", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Doesn't Matter");
441
    my $seeking_dd = Html::dropdown("seeking", "for", -1, "", "", $spacing . "  ", "", "", get_config("styles", 1), "Doesn't Matter");
442
    my $seeking_gender_dd = Html::dropdown("seeking_gender", "Seeking Gender", -1, "", "", $spacing . "  ", "", "", get_config("genders", 1), "Doesn't Matter");
443
    my $eyes_dd = Html::dropdown("eye_clr", "Eye Colour", -1, "", "", $spacing . "  ", "", "", get_config("eyes", 1), "Doesn't Matter");
444
    my $hair_dd = Html::dropdown("hair_clr", "Hair Colour", -1, "", "", $spacing . "  ", "", "", get_config("hair", 1), "Doesn't Matter");
445
    my $weight_dd = Html::dropdown("weight", "Weight", -1, "", "", $spacing . "  ", "", "", get_config("weights", 1), "Doesn't Matter");
446
    my $height_dd = Html::dropdown("height", "Height", -1, "", "", $spacing . "  ", "", "", get_config("heights", 1), "Doesn't Matter");
447
    my $body_dd = Html::dropdown("body", "Body Type", -1, "", "", $spacing . "  ", "", "", get_config("bodies", 1), "Doesn't Matter");
448
449
    my $month_dd = Html::dropdown("dob_month", "Birthdate", -1, "", "", $spacing . "  ", "", "", Html::get_months_forDropdowns(1), "Doesn't Matter");
450
    my $day_dd = Html::dropdown("dob_day", "", -1, "", "", $spacing . "  ", "", "", Html::get_days_forDropdowns(1), "Doesn't Matter");
451
    my $year_dd = Html::dropdown("dob_year", "", -1, "", "", $spacing . "  ", "", "", Html::Date::get_years_forDropdowns(1), "Doesn't Matter");
452
453
    $rv .= $spacing . "  Nickname <input id=s_nickname name=s_nickname placeholder='John or Sally'><hr><br>\n";
454
    $rv .= $month_dd . "\n";
455
    $rv .= $day_dd . "\n";
456
    $rv .= $year_dd . "<hr><br>\n";
457
    $rv .= $orientation_dd . "\n";
458
    $rv .= $race_dd . "<br>\n";
459
    $rv .= $gender_dd . "\n";
460
    $rv .= "<div id=erection_div style='display: inline;'>$erection_dd</div>\n";
461
    $rv .= "<div id=bust_div style='display: inline;'>$bust_dd</div><br>\n";
462
    $rv .= $seeking_gender_dd . "\n";
463
    $rv .= $seeking_dd . "<br>\n";
464
    $rv .= $body_dd . "\n";
465
    $rv .= $weight_dd . "\n";
466
    $rv .= $height_dd . "<br>\n";
467
    $rv .= $eyes_dd . "\n";
468
    $rv .= $hair_dd . "<hr><br>\n";
469
    $rv .= $country_dd . ", " . $city_dd . "<hr><br>\n";
470
    $rv .= $drugs_dd . "\n";
471
    $rv .= $wheels_dd . "\n";
472
    $rv .= $canhost_dd . "<br>\n";
473
    $rv .= $drinker_dd . "\n";
474
    $rv .= $smoker_dd;
475
476
    if (isUserModerator()) {
477
      # include some special options!
478
      #   ID, nickname, email, dob, showbday, lastip, password, race, gender, location, orientation,
479
      #   drugs, wheels, can_host, drinker, smoker, seeking, seeking_gender, erection, bust, eye_clr,
480
      #   hair_clr, weight, height, body, enrolled, subscriber, subscription_date, subscription_type,
481
      #   CCID, TID, security, description, banned
482
      $rv .=  $spacing . "<br><br><hr><font class=notice>Your security level is <i>" . get_security_asWord_friendly($User::USER_DATA->{security}) . "</i>, you get special options!</font><hr><br>\n";
483
      $rv .=  $spacing . "<input id=admins name=admins type=checkbox> <label for=admins>Include Administrators</label>      \n";
484
      $rv .=  $spacing . "<input id=ignoreshowbday name=ignoreshowbday type=checkbox> <label for=ignoreshowbday>Ignore Show Birthday Flag</label><br>\n";
485
486
      my $email = "<input id=s_email name=s_email placeholder='address\@domain.tld'>";
487
      my $lastip = "<input id=lastip name=lastip placeholder='1.23.45.67'>";
488
      my $enrolled = "<input id=enrolled name=enrolled placeholder='2001-01-19'>";
489
      my $subscriber = Html::dropdown("subscriber", "Subscriber", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Either");
490
      my $subscription_date = "<input id=sd name=sd placeholder='2001-01-19'>";
491
      my $subscription_type = Html::dropdown("subtype", "Subscription Type", -1, "", "", $spacing . "  ", "", "", get_config("membership_types", 1), "Any");
492
      my $tid = Html::dropdown("TID", "Theme ID", -1, "", "", $spacing . "  ", "", "", Html::get_themes_forDropdowns(1, 1), "Any");
493
      my $security = Html::dropdown("security", "Security Level", -1, "", "", $spacing . "  ", "", "", Html::get_security_forDropdowns(1), "Any");
494
      my $banned = Html::dropdown("banned", "Banned", -1, "", "", $spacing . "  ", "", "", get_config("yesno", 1), "Either");
495
      my $description = "<input id=desc name=desc placeholder='some words'>";
496
497
      $rv .= $spacing . "<br><hr class=tiny><br>\n";
498
      $rv .= $spacing . "E-Mail Address " . $email . " --\n";
499
      $rv .= $spacing . $security . "<br>\n";
500
      $rv .= $spacing . "Last IP " . $lastip . " --\n";
501
      $rv .= $spacing . $banned . "<br>\n";
502
      $rv .= $spacing . "Enrollment Date " . $enrolled . " --\n";
503
      $rv .= $spacing . $tid . "<br><br><hr class=tiny><br>\n";
504
      $rv .= $spacing . $subscriber . " --\n";
505
      $rv .= $spacing . $subscription_type . "<br>\n";
506
      $rv .= $spacing . "Subscription Date " . $subscription_date . "<br>\n";
507
      $rv .= $spacing . "<br><hr class=tiny><br>\n";
508
      $rv .= $spacing . "Description " . $description . "<br>\n";
509
    } else {
510
      $rv .=  $spacing . "<br>\n";
511
    }
512
513
    $rv .= $spacing . "  <br>\n\n";
514
    $rv .= $spacing . "  <script>\n";
515
    $rv .= $spacing . "    var search_str = \"\";\n";
516
    $rv .= $spacing . "  </script>\n";
517
    $rv .= $spacing . "  <button class=green type=button onclick='build_search_str();'> Search it up! </button>    \n";
518
    $rv .= $spacing . "  <button class=yellow type=button onclick='reset();'> Clear </button>\n";
519
    if ($DEBUG) { $rv .= $spacing . "  <div id=status>DEBUG MODE ENABLED</div>\n"; }
520
    $rv .= $spacing . "  <script>\n";
521
    $rv .= $spacing . "    function clearSelected(eid){\n";
522
    $rv .= $spacing . "      var e = document.getElementById(eid);\n";
523
    $rv .= $spacing . "      if (e) {\n";
524
    $rv .= $spacing . "        e.options[0].selected = true;\n";
525
    $rv .= $spacing . "        for (var i = 1; i < e.options.length; i++) { e.options[i].selected = false; }\n";
526
    $rv .= $spacing . "      }\n";
527
    $rv .= $spacing . "    }\n";
528
    $rv .= "\n";
529
    $rv .= $spacing . "    function clearOptions(eid, label){\n";
530
    $rv .= $spacing . "      var e = document.getElementById(eid);\n";
531
    $rv .= $spacing . "      if (e) {\n";
532
    $rv .= $spacing . "        if (e.options) {\n";
533
    $rv .= $spacing . "          e.innerHTML = \"<option value='' selected disabled>\" + label;\n";
534
    $rv .= $spacing . "        }\n";
535
    $rv .= $spacing . "      }\n";
536
    $rv .= $spacing . "    }\n";
537
    $rv .= "\n";
538
    $rv .= $spacing . "    function reset() {\n";
539
    $rv .= $spacing . "      document.getElementById('s_nickname').value = '';\n";
540
    $rv .= $spacing . "      clearSelected('dob_month');\n";
541
    $rv .= $spacing . "      clearSelected('dob_day');\n";
542
    $rv .= $spacing . "      clearSelected('dob_year');\n";
543
    $rv .= $spacing . "      clearSelected('orientation');\n";
544
    $rv .= $spacing . "      clearSelected('race');\n";
545
    $rv .= $spacing . "      clearSelected('gender');\n";
546
    $rv .= $spacing . "      clearSelected('erection');\n";
547
    $rv .= $spacing . "      clearSelected('bust');\n";
548
    $rv .= $spacing . "      clearSelected('seeking_gender');\n";
549
    $rv .= $spacing . "      clearSelected('seeking');\n";
550
    $rv .= $spacing . "      clearSelected('body');\n";
551
    $rv .= $spacing . "      clearSelected('weight');\n";
552
    $rv .= $spacing . "      clearSelected('height');\n";
553
    $rv .= $spacing . "      clearSelected('eye_clr');\n";
554
    $rv .= $spacing . "      clearSelected('hair_clr');\n";
555
    $rv .= $spacing . "      clearSelected('country');\n";
556
    $rv .= $spacing . "      clearOptions('city', 'Select Country');\n";
557
    $rv .= $spacing . "      clearSelected('drugs');\n";
558
    $rv .= $spacing . "      clearSelected('wheels');\n";
559
    $rv .= $spacing . "      clearSelected('can_host');\n";
560
    $rv .= $spacing . "      clearSelected('drinker');\n";
561
    $rv .= $spacing . "      clearSelected('smoker');\n";
562
    if (isUserModerator()) {
563
      $rv .= "\n";
564
      $rv .= $spacing . "      document.getElementById('admins').checked = '';\n";
565
      $rv .= $spacing . "      document.getElementById('ignoreshowbday').checked = '';\n";
566
      $rv .= $spacing . "      document.getElementById('s_email').value = '';\n";
567
      $rv .= $spacing . "      clearSelected('security');\n";
568
      $rv .= $spacing . "      document.getElementById('lastip').value = '';\n";
569
      $rv .= $spacing . "      clearSelected('banned');\n";
570
      $rv .= $spacing . "      document.getElementById('enrolled').value = '';\n";
571
      $rv .= $spacing . "      clearSelected('TID');\n";
572
      $rv .= $spacing . "      clearSelected('subscriber');\n";
573
      $rv .= $spacing . "      clearSelected('subtype');\n";
574
      $rv .= $spacing . "      document.getElementById('sd').value = '';\n";
575
      $rv .= $spacing . "      document.getElementById('desc').value = '';\n";
576
    }
577
    $rv .= $spacing . "    }\n";
578
    $rv .= "\n";
579
    $rv .= $spacing . "    // build the search string\n";
580
    $rv .= $spacing . "    function build_search_str() {\n";
581
    $rv .= $spacing . "      // so, just create a -- separated list from ALL of the options available\n";
582
    $rv .= $spacing . "      var nn = document.getElementById('s_nickname');\n";
583
    $rv .= $spacing . "      var bm = get_selected('dob_month');\n";
584
    $rv .= $spacing . "      var bd = get_selected('dob_day');\n";
585
    $rv .= $spacing . "      var by = parseInt(get_selected('dob_year')) + 1896;\n";
586
    $rv .= $spacing . "      var o = get_selected('orientation');\n";
587
    $rv .= $spacing . "      var r = get_selected('race');\n";
588
    $rv .= $spacing . "      var g = get_selected('gender');\n";
589
    $rv .= $spacing . "      var er = get_selected('erection');\n";
590
    $rv .= $spacing . "      var bu = get_selected('bust');\n";
591
    $rv .= $spacing . "      var sg = get_selected('seeking_gender');\n";
592
    $rv .= $spacing . "      var se = get_selected('seeking');\n";
593
    $rv .= $spacing . "      var bo = get_selected('body');\n";
594
    $rv .= $spacing . "      var we = get_selected('weight');\n";
595
    $rv .= $spacing . "      var he = get_selected('height');\n";
596
    $rv .= $spacing . "      var ey = get_selected('eye_clr');\n";
597
    $rv .= $spacing . "      var ha = get_selected('hair_clr');\n";
598
    $rv .= $spacing . "      var c = get_selected('city');\n";
599
    $rv .= $spacing . "      var dru = get_selected('drugs');\n";
600
    $rv .= $spacing . "      var wh = get_selected('wheels');\n";
601
    $rv .= $spacing . "      var ch = get_selected('can_host');\n";
602
    $rv .= $spacing . "      var dri = get_selected('drinker');\n";
603
    $rv .= $spacing . "      var sm = get_selected('smoker');\n";
604
    $rv .= "\n";
605
    if (isUserModerator()) {
606
      $rv .= $spacing . "      var em = document.getElementById('s_email');\n";
607
      $rv .= $spacing . "      var sl = get_selected('security');\n";
608
      $rv .= $spacing . "      var ip = document.getElementById('lastip');\n";
609
      $rv .= $spacing . "      var ba = get_selected('banned');\n";
610
      $rv .= $spacing . "      var ed = document.getElementById('enrolled');\n";
611
      $rv .= $spacing . "      var tid = get_selected('TID');\n";
612
      $rv .= $spacing . "      var sub = get_selected('subscriber');\n";
613
      $rv .= $spacing . "      var st = get_selected('subtype');\n";
614
      $rv .= $spacing . "      var sd = document.getElementById('sd');\n";
615
      $rv .= $spacing . "      var d = document.getElementById('desc');\n";
616
      $rv .= "\n";
617
    }
618
    $rv .= $spacing . "      search_str = '';\n";
619
    $rv .= $spacing . "      if (nn.value) add_term('nickname,' + nn.value);\n";
620
    $rv .= $spacing . "      if (bm) {\n";
621
    $rv .= $spacing . "        if (parseInt(bm) < 10) { bm = '0' + bm; }\n";
622
    $rv .= $spacing . "      }\n";
623
    $rv .= $spacing . "      if (bd) {\n";
624
    $rv .= $spacing . "        if (parseInt(bd) < 10) { bd = '0' + bd; }\n";
625
    $rv .= $spacing . "      }\n";
626
    $rv .= $spacing . "      if (bd || bm || by) {\n";
627
    $rv .= $spacing . "        if (!bd) { bd = 999; }\n";
628
    $rv .= $spacing . "        if (!bm) { bm = 999; }\n";
629
    $rv .= $spacing . "        if (!by) { by = 999; }\n";
630
    $rv .= $spacing . "        var bday = by + '-' + bm + '-' + bd;\n";
631
    $rv .= $spacing . "        if (itsadate(bday)) add_term('dob,' + bday);\n";
632
    $rv .= $spacing . "      }\n";
633
    $rv .= $spacing . "      if (o) add_term('orientation,' + o);\n";
634
    $rv .= $spacing . "      if (r) add_term('race,' + r);\n";
635
    $rv .= $spacing . "      if (g) add_term('gender,' + g);\n";
636
    $rv .= $spacing . "      if (er) add_term('erection,' + er);\n";
637
    $rv .= $spacing . "      if (bu) add_term('bust,' + bu);\n";
638
    $rv .= $spacing . "      if (sg) add_term('seeking_gender,' + sg);\n";
639
    $rv .= $spacing . "      if (se) add_term('seeking,' + se);\n";
640
    $rv .= $spacing . "      if (bo) add_term('body,' + bo);\n";
641
    $rv .= $spacing . "      if (we) add_term('weight,' + we);\n";
642
    $rv .= $spacing . "      if (he) add_term('height,' + he);\n";
643
    $rv .= $spacing . "      if (ey) add_term('eye_clr,' + ey);\n";
644
    $rv .= $spacing . "      if (ha) add_term('hair_clr,' + ha);\n";
645
    $rv .= $spacing . "      if (c) add_term('location,' + c);\n";
646
    $rv .= $spacing . "      if (dru) add_term('drugs,' + dru);\n";
647
    $rv .= $spacing . "      if (wh) add_term('wheels,' + wh);\n";
648
    $rv .= $spacing . "      if (ch) add_term('can_host,' + ch);\n";
649
    $rv .= $spacing . "      if (dri) add_term('drinker,' + dri);\n";
650
    $rv .= $spacing . "      if (sm) add_term('smoker,' + sm);\n";
651
    $rv .= "\n";
652
    if (isUserModerator()) {
653
      $rv .= $spacing . "      if (em.value) add_term('email,' + em.value);\n";
654
      $rv .= $spacing . "      if (sl) add_term('security,' + sl);\n";
655
      $rv .= $spacing . "      if (ip.value) add_term('lastip,' + ip.value);\n";
656
      $rv .= $spacing . "      if (ba) add_term('banned,' + ba);\n";
657
      $rv .= $spacing . "      if (ed.value) add_term('enrolled,' + ed.value);\n";
658
      $rv .= $spacing . "      if (tid) add_term('TID,' + tid);\n";
659
      $rv .= $spacing . "      if (sub) add_term('subscriber,' + sub);\n";
660
      $rv .= $spacing . "      if (st) add_term('subscription_type,' + st);\n";
661
      $rv .= $spacing . "      if (sd.value) add_term('subscription_date,' + sd.value);\n";
662
      $rv .= $spacing . "      if (d.value) add_term('description,' + d.value);\n";
663
    }
664
    $rv .= "\n";
665
    if ($DEBUG) {
666
      $rv .= $spacing . "      // debug mode enabled!\n";
667
      $rv .= $spacing . "      if (search_str) {\n";
668
      $rv .= $spacing . "        var status = document.getElementById('status');\n";
669
      $rv .= $spacing . "        status.innerHTML = search_str;\n";
670
      $rv .= $spacing . "      }\n";
671
      $rv .= "\n";
672
      $rv .= $spacing . "      setTimeout(search, 2500);\n";
673
    } else {
674
      $rv .= $spacing . "      search();\n";
675
    }
676
    $rv .= $spacing . "    }\n";
677
    $rv .= "\n";
678
    $rv .= $spacing . "    function search() {\n";
679
    $rv .= $spacing . "      var loc='/?$Bc_sql::QUERY_PAGE=" . get_constant("SEARCH_PAGE") . "&sp=0&hpp=10';";
680
    if (isUserAdmin()) { $rv .= $spacing . "      loc = loc + '&admins=1';\n"; }
681
    $rv .= $spacing . "      loc = loc + '&st=' + search_str;\n";
682
    $rv .= $spacing . "      document.location = loc;\n";
683
    $rv .= $spacing . "    }\n";
684
    $rv .= "\n";
685
    $rv .= $spacing . "    function itsadate(d) {\n";
686
    $rv .= $spacing . "      // to determine if 'd' is a date or not\n";
687
    $rv .= $spacing . "      var rv = 1;\n";
688
    $rv .= $spacing . "      var bits = d.split('-');\n";
689
    $rv .= $spacing . "      if (bits.length < 3) { rv = 0; }\n";
690
    $rv .= $spacing . "      \n";
691
    $rv .= $spacing . "      \n";
692
    $rv .= $spacing . "      ret" . "urn rv;\n";
693
    $rv .= $spacing . "    }\n";
694
    $rv .= "\n";
695
    $rv .= $spacing . "    function add_term(t) {\n";
696
    $rv .= $spacing . "      // adds a search term to 'search_str'\n";
697
    $rv .= $spacing . "      if (!search_str) { search_str = t; } else { search_str = search_str + '--' + t; }\n";
698
    $rv .= $spacing . "      \n";
699
    $rv .= $spacing . "      \n";
700
    $rv .= $spacing . "      \n";
701
    $rv .= $spacing . "      \n";
702
    $rv .= $spacing . "    }\n";
703
    $rv .= $spacing . "  </script>\n";
704
    $rv .= $spacing . "</td></tr></table>\n";
705
706
    return $rv; # a search form when no search terms given
707
  } else {
708
    $rv = $spacing . "<table align=center border=$RESULTS_BORDER cellpadding=0 cellspacing=0><tr><td align=center>\n";
709
710
711
          ##################################################
712
          # this is the actual search!
713
          ##################################################
714
          my @sResults;
715
          my $s = \();
716
          if (isUserAdmin($Bc_sql::LOGGEDIN))
717
            { $s = search($termsRef, $includeAdmins, $DEBUG); } else
718
            { $s = search($termsRef, $includeAdmins, $DEBUG); }
719
          @sResults = @$s;
720
          ##################################################
721
722
723
    if ($DEBUG) {
724
      $rv .= $spacing . "  DEBUG MODE ENABLED for Search::search(...)<hr><br>\n";
725
726
      $rv .= $spacing . "  terms: ";
727
      if (ref $termsRef eq "ARRAY") {
728
        foreach my $term (@$termsRef) {
729
          $rv .= $spacing . "  $term<br>\n";
730
        }
731
      } else {
732
        if ($termsRef) {
733
          $rv .= $spacing . "  $termsRef<br>\n";
734
        } else {
735
          $rv .= $spacing . "  -none-<br>\n";
736
        }
737
      }
738
739
      $rv .= $spacing . "  include admins: $includeAdmins<br>\n";
740
741
      foreach my $L (@sResults) { $rv .= $spacing . "  $L<br>\n"; }
742
743
      return $rv; # debug info when debug is toggled on
744
    }
745
746
    my $hpp = get_param(get_constant("QUERY_SEARCH_HPP"));
747
    if (not $hpp) { $hpp = 10; }
748
    my $numPages = int(@sResults/$hpp);
749
    if ($numPages * $hpp < @sResults) { $numPages++; }
750
    if ($page > $numPages) { $page = 0; }
751
    if ($page < 0) { $page = 0; }
752
753
    my $start = $page * $hpp;
754
    my $end = $start + $hpp;
755
756
    if ($start < 0) { $start = 0; }
757
    if ($start > @sResults) { $start = (($numPages-1)*$hpp); }
758
    if ($end > @sResults) { $end = @sResults; }
759
760
    $rv .= "$spacing  <!-- BEGIN HTML'ified SEARCH RESULTS -->\n";
761
762
    # setup wording for "you searched for"
763
    $rv .= $spacing;
764
    #if (@sResults) { $rv .= " "; }
765
    $rv .= "  You searched for: ";
766
    my %termsHash;
767
    my $termsHashValue = "";
768
    # plug each term into the hash ($name is the key and $value is the value for each key)
769
770
    # wow...
771
    {
772
      my @t = split("--", $termsRef);
773
      $termsRef = \@t;
774
    }
775
    foreach my $term (@$termsRef) {
776
      # ID, nickname, email, dob, showbday, lastip, password, race, gender, location, orientation
777
      # drugs, wheels, can_host, drinker, smoker, seeking, seeking_gender, erection, bust, eye_clr, hair_clr,
778
      # weight, height, body, enrolled, subscriber, subscription_date, subscription_type, CCID, TID, security,
779
      # description, banned
780
781
      $term =~ s/,/=/g;
782
      my ($name, $value) = split("=", $term);
783
      if ($name eq "age") {
784
        if ($value eq "999") {
785
          $termsHashValue = "all";
786
        } else {
787
          $value = 18 + (($value-1) * 5);
788
          $termsHashValue = "$value to " . ($value + 4) . " year old";
789
          if (@$termsRef eq 1) { $termsHashValue .= "s"; }
790
        }
791
      }
792
      if ($name eq "location") {
793
        my ($country, $city) = split("-", $value);
794
        if ($country eq "999") {
795
          $termsHashValue = "everywhere";
796
        } else {
797
          if ($city eq "999") {
798
            $termsHashValue = "All cities in " . get_country_name($value);
799
          } else {
800
            $termsHashValue = "in " . get_city_name($value) . ", " . get_country_name($value);
801
          }
802
        }
803
      }
804
      if ($name eq "ID") { $termsHashValue = "UID $value"; }
805
      if ($name eq "nickname") { $termsHashValue = "users named $value"; }
806
      if ($name eq "email") { $termsHashValue = "email address of $value"; }
807
      if ($name eq "dob") { $termsHashValue = "b-day of $value"; }
808
      if ($name eq "showbday") { if ($value eq 1) { $termsHashValue = "b-days hidden"; } else { $termsHashValue = "b-days visible"; } }
809
      if ($name eq "lastip") { $termsHashValue = "IP address is $value"; }
810
      if ($name eq "password") { $termsHashValue = "Encrypted password of $value"; }
811
      if ($name eq "race") { $termsHashValue = "Ethnicity of $value"; }
812
      if ($name eq "gender") {
813
        if ($value eq 1) { $termsHashValue = "guys"; }
814
        elsif ($value eq 2) { $termsHashValue = "gals"; }
815
        else { $termsHashValue = "guys and gals"; }
816
      }
817
      if ($name eq "seeking_gender") {
818
        if ($value eq 1) { $termsHashValue = "those seeking guys"; }
819
        elsif ($value eq 2) { $termsHashValue = "those seeking gals"; }
820
        else { $termsHashValue = "those seeking guys or gals"; }
821
      }
822
      if ($name eq "race") { $termsHashValue = pluralize(get_race_asWord($value), 2); }
823
      if ($name eq "orientation") { $termsHashValue = pluralize(get_orientation_asWord($value), 2); }
824
      if ($name eq "drugs") { if ($value eq 1) { $termsHashValue = "non-drug users"; } else { $termsHashValue = "drug users"; } }
825
      if ($name eq "wheels") { if ($value eq 1) { $termsHashValue = "those without a vehicle"; } else { $termsHashValue = "those with a vehicle"; } }
826
      if ($name eq "can_host") { if ($value eq 1) { $termsHashValue = "those who cannot host"; } else { $termsHashValue = "those who can host"; } }
827
      if ($name eq "drinker") { if ($value eq 1) { $termsHashValue = "those who don't drink"; } else { $termsHashValue = "those who drink"; } }
828
      if ($name eq "smoker") { if ($value eq 1) { $termsHashValue = "non-smokers"; } else { $termsHashValue = "smokers"; } }
829
      if ($name eq "seeking") { $termsHashValue = "who are seeking " . lc(get_seeking_asWord($value)); }
830
      if ($name eq "erection") { $termsHashValue = "those with $value erections"; }
831
      if ($name eq "bust") { $termsHashValue = "those with $value busts"; }
832
      if ($name eq "eye_clr") { $termsHashValue = "those with " . get_eye_clr_asWord($value) . " eyes"; }
833
      if ($name eq "hair_clr") { $termsHashValue = "those with " . get_hair_clr_asWord($value) . " hair"; }
834
      if ($name eq "weight") { $termsHashValue = "who weigh " . get_weight_asWord($value) . " pounds"; }
835
      if ($name eq "height") { $termsHashValue = "who are about " . get_height_asWord($value) . " tall"; }
836
      if ($name eq "body") { $termsHashValue = "who have " . get_body_asWord($value) . " bodies"; }
837
      if ($name eq "enrolled") { $termsHashValue = "who signed up $value"; }
838
      if ($name eq "subscriber") { if ($value eq 1) { $termsHashValue = "non-subscribers"; } else { $termsHashValue = "subscribers"; } }
839
      if ($name eq "subscription_date") { $termsHashValue = "who subscribed up $value"; }
840
      if ($name eq "subscription_type") { $termsHashValue = "whose subscription type is " . get_subscription_type_asWord($value); }
841
      if ($name eq "CCID") { $termsHashValue = "whose CCID = $value"; }
842
      if ($name eq "TID") { $termsHashValue = "those with TID of $value"; }
843
      if ($name eq "security") { $termsHashValue = "those with a security level of $value"; }
844
      if ($name eq "description") { $termsHashValue = "those with a description of $value"; }
845
      if ($name eq "banned") { if ($value eq 1) { $termsHashValue = "banned users"; } else { $termsHashValue = "non-banned users"; } }
846
847
      $termsHash{$name} = $termsHashValue;
848
    }
849
850
    # show "worded" search terms
851
    foreach my $term (sort keys %termsHash) {
852
      $rv .= "$termsHash{$term} ";
853
    }
854
    $rv =~ s/ $//;
855
    $rv .= "<br>\n";
856
    # end setup wording for "you searched for"
857
858
    # display results
859
    if (not @sResults) {
860
      #$rv .= $spacing . "Your search (" . scalar @$termsRef[0] . ") <b>did not</b> generate any results!\n";
861
      if ($DEBUG) { $rv .= $spacing . "  DEBUG MODE ENABLED<br>\n"; }
862
      $rv .= $spacing . "  Your search <b>did not</b> garner any results!<br>\n";
863
      if ($Bc_sql::LOGGEDIN) {
864
        $rv .= $spacing . "  <a href=\"/?$Bc_sql::QUERY_PAGE=$Bc_sql::CONSTANTS{BROWSE_PAGE}\">Browse</a><br>\n";
865
        $rv .= $spacing . "  <a href=\"/?$Bc_sql::QUERY_PAGE=$Bc_sql::CONSTANTS{SEARCH_PAGE}\">New Search</a>\n";
866
      } else {
867
        $rv .= $spacing . "  Well, you got no results cause you aren't loggedin!\n";
868
      }
869
    } else {
870
      $rv .= $spacing . "  <br>\n";
871
872
      ############## TOP MINI SEARCH NAV
873
      $rv .= search_nav(0, \@sResults, $termsRef, $page, $hpp, "$spacing") . "<br>\n";
874
      ##############
875
876
      $rv .= "$spacing  <!-- START SEARCH RESULTS WRAPPER -->\n";
877
      $rv .= "$spacing  <table align=center border=$RESULTS_BORDER cellpadding=0 cellspacing=0><tr><td valign=top class=search-list>\n";
878
879
      for (my $i = $start; $i < $end; $i++) {
880
        my $uid = $sResults[$i];
881
        if ($uid) {
882
          if ($DEBUG_HTML) {
883
            $rv .= $spacing . "    " . $uid . "<br>\n";
884
          } else {
885
            #$rv .= "<div class=item>" . Html::display_user_card($uid, $spacing . "    ", 0, 0) . "</div>\n";
886
            my %div; {
887
              $div{tag} = "div";
888
              $div{class} = "item";
889
              $div{innerHTML} = Html2::display_user_profile({uid=>$uid, mini=>1});
890
            }
891
892
            $rv .= tag(\%div);
893
          }
894
        }
895
      }
896
897
      $rv .= "$spacing  </td></tr></table><br>\n";
898
      $rv .= "$spacing  <!-- END SEARCH RESULTS WRAPPER -->\n\n";
899
900
      ############## BOTTOM MINI SEARCH NAV
901
      $rv .= search_nav(1, \@sResults, $termsRef, $page, $hpp, $spacing . "  ");
902
      ##############
903
    }
904
905
    $rv .= $spacing . "</td></tr></table>\n";
906
    $rv .= $spacing . "<!-- END HTML'ified SEARCH RESULTS -->\n";
907
  }
908
909
  return $rv; # the search results, HTML'ized
910
  #usage: my $searchOutput = search_results_asHTML(\@uList, \@terms, 0, "  ");
911
}
912
913
########################################################################################################################
914
sub _tests(;$$) {
915
  #*
916
  # to test all <i>Pm::Search</i> functions
917
  #*
918
  my ($extended, $legacy) = @_; # show extended data (optional) && legacy search (1) or new search (0)?
919
  my $rv = "";
920
  my $test = "";
921
  my $test2 = "";
922
  my $test3 = "";
923
  my @test = ();
924
  my @test2 = ();
925
926
  return ""; # override test
927
928
  if ($Bc_sql::DB) {
929
    $legacy = 0;
930
931
    if ($legacy) {
932
      @test = Bc_sql::get_users(1);
933
      $test2 = "location";
934
      $test3 = "31-999";
935
      # my ($usersRef, $name, $value)
936
      @test2 = search_item(\@test, $test2, $test3);
937
      $rv .= Html::display_debug_many("search_item(\\@test, \"$test2\", \"$test3\")", \@test2);
938
      @test2 = search_item(\@test, $test2, $test3, "A", "location");
939
      $rv .= Html::display_debug_many("search_item(\\@test, \"$test2\", \"$test3\", \"A\", \"location\")", \@test2);
940
      @test2 = ("race,5", "gender,2");
941
      $rv .= Html::display_debug_code("search_nav(\0, \\@test, \\\@test2, 0, 10, \"\")", search_nav(0, \@test, \@test2, 0, 10, ""));
942
      $rv .= Html::display_debug_code("search_results_asHTML(\\@test, \\\@test2, 0, \"\")", search_results_asHTML(\@test, \@test2, 0, ""));
943
      @test2 = search_terms(\@test, \@test2);
944
      $rv .= Html::display_debug_many("search_terms(\\@test, \\\@test2)", \@test2);
945
946
    } else {
947
948
      $test = get_param("terms");
949
      $test3 = get_param("admins");
950
      my $test4 = get_param("debug");
951
      my $test5 = get_param("names");
952
      if ($test3 eq "on") { $test3 = 1; } else { $test3 = 0; }
953
      if ($test4 eq "on") { $test4 = 1; } else { $test4 = 0; }
954
      if ($test5 eq "on") { $test5 = 1; $test4 = 2; } else { $test5 = 0; }
955
      if (not $test) { $test = "gender,1--location=31-999"; }
956
      $test2 = search($test, $test3, $test4);
957
      my $dd = "<form id=form action=\"debug.pl#searchtest\" method=post sstyle='display: inline;'>\n";
958
      $dd   .= "  <input type=hidden name=dp value=\"search\">\n";
959
      $dd   .= "  <input name=terms placeholder=\"gender,1 or seeking=999\" size=50 value=\"$test\">\n";
960
      $dd   .= "  <button>Search</button>\n";
961
      $dd   .= "  <button type=reset onclick=\"terms.value=''; admins.checked=''; debug.checked=''; names.checked=''; forms[0].submit();\">Reset</button>\n";
962
      $dd   .= "  <button type=button onclick=\"terms.value=''; admins.checked=''; debug.checked=''; names.checked=''; terms.focus();\">Clear</button>\n";
963
      $dd   .= "  <input type=checkbox name=admins id=admins"; if ($test3) { $dd .= " checked"; } $dd   .= "><label for=admins>+Admins</label>\n";
964
      $dd   .= "  <input type=checkbox name=debug id=debug"; if ($test4) { $dd .= " checked"; } $dd   .= "><label for=debug>Debug</label>\n";
965
      $dd   .= "  <input type=checkbox name=names id=names"; if ($test5) { $dd .= " checked"; } $dd   .= "><label for=names>+More</label>\n";
966
      $dd   .= "</form>\n";
967
      $rv .= Html::display_debug_many("search(\"$test\", $test3, $test4) $dd", $test2, "<br>\n");
968
      $rv .= "<a name=searchtest></a>\n";
969
    }
970
  } else {
971
    $rv .= "DB connection error!<br>\n";
972
  }
973
974
  return $rv; # a scalar of the results of all tests
975
  #usage: print _tests();
976
}
977
978
########################################################################################################################
979
########################################################################################################################
980
########################################################################################################################
981
########################################################################################################################
982
########################################################################################################################
983
########################################################################################################################
984
########################################################################################################################
985
########################################################################################################################
986
########################################################################################################################
987
########################################################################################################################
988
########################################################################################################################
989
########################################################################################################################
990
########################################################################################################################
991
########################################################################################################################
992
########################################################################################################################
993
########################################################################################################################
994
########################################################################################################################
995
########################################################################################################################
996
########################################################################################################################
997
########################################################################################################################
998
########################################################################################################################
999
########################################################################################################################
1000
1001
1;