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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
<?php
/* OpenDb - Open Lending Database Project
Copyright (C) 2001,2002 by Jason Pell
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// This must be first - includes config.php
require_once("./include/begin.inc.php");
include_once("./include/language.php");
include_once("./include/theme.php");
include_once("./functions/function.php");
include_once("./functions/item_type.php");
include_once("./functions/widgets.php");
include_once("./functions/item.php");
include_once("./functions/parseutils.php");
include_once("./functions/user.php");
include_once("./functions/status_type.php");
function get_search_javascript()
{
return '<script src="./include/search.js" language="JavaScript" type="text/javascript"></script>';
}
function get_search_javascript_arrays(&$itemTypesCount, &$itemTypeSelect, &$categorySelect, &$attrTypeSelect)
{
$buffer = "";
$itemTypeSelect = "";
$attrTypeSelect = "";
$arrayOfAttributes = "";
$arrayOfCategoryTypes = "";
$itemTypesCount=0;
$arrayOfAttributesCount=0;
$itemresults = fetch_item_type_rs();
while($item_type_r = mysql_fetch_array($itemresults, MYSQL_ASSOC))
{
$results = fetch_item_attribute_type_rs($item_type_r['s_item_type'], TRUE, TRUE, TRUE);
// For the case where we have a s_item_type with no attributes associated with it!
if($results)
{
while($attribute_type_r = mysql_fetch_array($results, MYSQL_ASSOC))
{
$display_type = trim($attribute_type_r['display_type']);
$input_type = trim($attribute_type_r['input_type']);
// Do not include any attributes with a defined s_field_type, or a input_type/display_type of hidden.
if((strlen($display_type)>0 || strcasecmp(get_function_type($input_type), "hidden")!==0) && strcasecmp(get_function_type($display_type), "hidden")!==0 && strlen($attribute_type_r['s_field_type'])==0)
{
// Only unique attributes should be added to attribute options object.
if(!is_array($arrayOfUniqueAttributes) || !in_array($attribute_type_r['s_attribute_type'], $arrayOfUniqueAttributes))
{
// This array, is only so we can make sure that we have unique attributes only!
$arrayOfUniqueAttributes[] = $attribute_type_r['s_attribute_type'];
// Set first item_type as default.
$attrTypeSelect .= "\n<option value=\"".$attribute_type_r['s_attribute_type']."\">".$attribute_type_r['sat_prompt']." - ".$attribute_type_r['description'];
}
$arrayOfAttributes .= "\narrayOfAttributes[$arrayOfAttributesCount] = new LookupAttribute(\"".$item_type_r['s_item_type']."\",\"".$attribute_type_r['s_attribute_type']."\",\"".$attribute_type_r['sat_prompt']." - ".$attribute_type_r['description']."\");";
$arrayOfAttributesCount++;
}
}
}
// Get the category_attribute_type for this item_type
$category_attribute_type = fetch_sfieldtype_item_attribute_type($item_type_r['s_item_type'], 'CATEGORY');
// We need this list further down, to work out which of the lookup items are actually categories.
$arrayOfCategoryTypes[] = $category_attribute_type;
$arrayOfItemTypes .= "\narrayOfItemTypes[$itemTypesCount] = new ItemType(\"".$item_type_r['s_item_type']."\",\"".$category_attribute_type."\");";
$itemTypeSelect .= "\n<option value=\"".$item_type_r['s_item_type']."\">".$item_type_r['s_item_type']." - ".$item_type_r['description'];
$itemTypesCount++;
// Get the very first item_type found, in case only one will be found!
if($itemTypesCount==0)
$firstItemType=$item_type_r['s_item_type'];
}
// Give us the whole s_attribute_type_lookup table, whoo baby...
$arrayOfLookupValues = "";
$arrayOfLookupValuesCount=0;
$attresults = fetch_attribute_type_lookup_rs();
while($attribute_type_r = mysql_fetch_array($attresults))
{
if(in_array($attribute_type_r['s_attribute_type'], $arrayOfCategoryTypes) && (!is_array($arrayOfUniqueCategories) || !in_array($attribute_type_r['value'], $arrayOfUniqueCategories)))
$arrayOfUniqueCategories[$attribute_type_r['value']] = $attribute_type_r['display'];
$arrayOfLookupValues .= "\narrayOfLookupValues[$arrayOfLookupValuesCount] = new LookupAttribute(\"".$attribute_type_r['s_attribute_type']."\",\"".$attribute_type_r['value']."\",\"".$attribute_type_r['display']."\");";
$arrayOfLookupValuesCount++;
}
$buffer .= "\n\narrayOfLookupValues = new Array($arrayOfLookupValuesCount);";
$buffer .= $arrayOfLookupValues;
$buffer .= "\n\narrayOfAttributes = new Array($arrayOfAttributesCount);";
$buffer .= $arrayOfAttributes;
$buffer .= "\n\narrayOfItemTypes = new Array($itemTypesCount);";
$buffer .= $arrayOfItemTypes;
$arrayOfUniqueCategoryValues="";
$arrayOfUniqueCatValuesCount=0;
// Now sort all values into alphabetical order!
asort($arrayOfUniqueCategories);
reset($arrayOfUniqueCategories);
while( list($value,$display) = each($arrayOfUniqueCategories))
{
$categorySelect .= "\n<option value=\"$value\">$display";
$arrayOfUniqueCatValues .= "\narrayOfUniqueCatValues[$arrayOfUniqueCatValuesCount] = new LookupAttribute('',\"$value\",\"$display\");";
$arrayOfUniqueCatValuesCount++;
}
$buffer .= "\n\narrayOfUniqueCatValues = new Array($arrayOfUniqueCatValuesCount);";
$buffer .= $arrayOfUniqueCatValues;
// Now wrap and return
return "\n<script language=\"JavaScript\">\n<!-- // hide from stupid browsers\n".
$buffer.
"\n// -->\n</script>\n";
}
//
// Note the "----------- ALL -----------" display values is a
// kludge to support dynamic lov's in netscape 4. We need to
// ensure the size of the lov does not need to get any larger,
// so we set to the largest value it will ever get using the
// ----------- ALL -----------. All the other lov's include
// this as well for uniformity.
//
session_start();
if (is_opendb_valid_session())
{
if(is_valid_s_status_type($HTTP_VARS['s_status_type']))
$s_status_type_search = TRUE;
else
$s_status_type_search = FALSE;
$page_title = $LANG_VARS['item_search'];
if($s_status_type_search)
{
$page_title = replace_lang_var('s_status_type_desc',
fetch_status_type_col($HTTP_VARS['s_status_type'], 'description'),
$LANG_VARS['s_status_type_item_listing']);
}
echo _theme_header($page_title);
echo("<h2>".$page_title."</h2>");
// Include validation javascript here.
echo(get_validation_javascript());
echo(get_search_javascript());
echo(get_search_javascript_arrays($itemTypesCount, $itemTypeSelect, $categorySelect, $attrTypeSelect));
// Two levels of tables, so we can get the search fields surrounded by a table
// with a border, while the search button is outside of this.
echo("<table border=0 cellpadding=0 cellspacing=0><tr><td>".
"<table border=1 cellpadding=0 cellspacing=0><tr><td>".
"<table border=0 cellpadding=1 cellspacing=1>");
echo("<form name=\"search\" method=\"get\" action=\"listings.php\">");
if($s_status_type_search!==TRUE)
{
// Indicate to listings.php that search.php initiated it.
echo("\n<input type=hidden name=\"search_list\" value=\"y\">");
// ------------------------
// TITLE FIELD
// ------------------------
echo format_field(
$LANG_VARS['title'],
NULL,
"\n<input type=text size=50 name=\"title\">".
"\n<br><input type=radio name=\"title_match\" value=\"word\">".$LANG_VARS['word_match']." ".
"\n<input type=radio name=\"title_match\" value=\"partial\" CHECKED>".$LANG_VARS['partial_match']." ".
"\n<input type=radio name=\"title_match\" value=\"exact\">".$LANG_VARS['exact_match']);
// ------------------------
// CATEGORY FIELD
// ------------------------
echo format_field(
$LANG_VARS['category'],
NULL,
"\n<select name=\"category\">".
"\n<option value=\"\">-------------- ".$LANG_VARS['all']." --------------".
$categorySelect.
"\n</select>");
//spacer!
echo("<tr><td class=\"data\" colspan=2> </td></tr>");
// ------------------------
// ATTRIBUTE_TYPE FIELD
// ------------------------
echo format_field(
$LANG_VARS['s_attribute_type'],
NULL,
"\n<select name=\"attribute_type\" onchange=\"populateList(this.options[this.options.selectedIndex].value, this.form['attribute_vals[]'], arrayOfLookupValues, false, '".$LANG_VARS['use_the_value_field']." ---->', true);\">".
"\n<option value=\"\">------------- ".$LANG_VARS['all']." -------------".
$attrTypeSelect.
"\n</select>");
echo format_field(
$LANG_VARS['s_attribute_type_lookup'],
NULL,
"\n<select name=\"attribute_vals[]\">".
"\n<option value=\"\">".$LANG_VARS['use_the_value_field']." ---->".
"\n</select>");
echo format_field(
$LANG_VARS['attribute_val'],
NULL,
"\n<input type=\"text\" name=\"attribute_val\" size=50 value=\"\">".
"\n<br><input type=radio name=\"attr_match\" value=\"word\">".$LANG_VARS['word_match']." ".
"\n<input type=radio name=\"attr_match\" value=\"partial\" CHECKED>".$LANG_VARS['partial_match']." ".
"\n<input type=radio name=\"attr_match\" value=\"exact\">".$LANG_VARS['exact_match']);
//spacer!
echo("<tr><td class=\"data\" colspan=2> </td></tr>");
}
// ------------------------
// S_ITEM_TYPE FIELD
// ------------------------
if($itemTypesCount>1)
{
echo format_field(
$LANG_VARS['item_type'],
NULL,
"\n<select name=\"s_item_type\" ".
"\nonchange=\"populateList(this.options[this.options.selectedIndex].value, this.form.attribute_type, arrayOfAttributes, true, '------------- ".$LANG_VARS['all']." -------------', false);".
"\nif(this.options[this.options.selectedIndex].value.length>0){populateList(get_category_type(this.options[this.options.selectedIndex].value, arrayOfItemTypes), this.form.category, arrayOfLookupValues, false, '------------- ".$LANG_VARS['all']." -------------', false);}".
"else{populateList('', this.form.category, arrayOfUniqueCatValues, true, '------------- ".$LANG_VARS['all']." -------------', false);}\">".
"\n<option value=\"\">-------------- ".$LANG_VARS['all']." --------------".
$itemTypeSelect.
"</select>");
}
// ------------------------
// OWNER FIELD
// ------------------------
// Must pass on not_owner_id if specified.
if(strlen($HTTP_VARS['not_owner_id'])>0)
{
echo("<input type=hidden name=\"not_owner_id\" value=\"".$HTTP_VARS['not_owner_id']."\">");
}
echo(
format_field(
$LANG_VARS['owner'],
NULL,
"\n<select name=\"owner_id\">".
"\n<option value=\"\">-------------- ".$LANG_VARS['all']." --------------".
custom_select(
'owner_id',
fetch_user_rs(get_owner_user_types_r()),
'%fullname% (%user_id%)',
'NA',
NULL,
'user_id'
).
"\n</select>"
)
);
if($s_status_type_search!==TRUE)
{
// ------------------------
// Item Status
// ------------------------
$lookup_results = fetch_status_type_rs(TRUE,TRUE,TRUE);
// Only include Status type restriction, if more than once status type.
if($lookup_results && mysql_num_rows($lookup_results)>1)
{
echo format_field(
$LANG_VARS['s_status_type'],
NULL,
checkbox_grid('s_status_type',
$lookup_results,
'%img%', // mask
'3', // columns
'', // border
'')); // value
}
}
else// if(is_valid_s_status_type($HTTP_VARS['s_status_type']))
{
echo("<input type=hidden name=\"s_status_type\" value=\"".$HTTP_VARS['s_status_type']."\">");
}
if($CONFIG_VARS['item_input.linked_item_support']!==FALSE)
{
echo format_field(
$LANG_VARS['linked_item(s)'],
NULL,
"\n<input type=radio name=\"linked_items\" value=\"include\" CHECKED>".$LANG_VARS['include']." ".
"<input type=radio name=\"linked_items\" value=\"exclude\">".$LANG_VARS['exclude']);
}
//spacer!
echo("<tr><td class=\"data\" colspan=2> </td></tr>");
if($s_status_type_search!==TRUE)
{
// Lets display the field just like item_review.php
$attribute_type_r = fetch_attribute_type_r("S_RATING");
echo get_input_field("rating",
$attribute_type_r['s_attribute_type'],
$attribute_type_r['prompt'],
$attribute_type_r['input_type'],
"N", // Override - Not compulsory in search page.
NULL,//value
TRUE);
}//if($HTTP_VARS['s_status_type_list'] != 'y')
//spacer!
echo("<tr><td class=\"data\" colspan=2> </td></tr>");
// ------------------------
// UPDATE_ON FIELD
// ------------------------
$update_on_length = strlen($CONFIG_VARS['search.datetime_mask']);
$update_on_filter = strlen($CONFIG_VARS['search.datetime_filter'])>0?$CONFIG_VARS['search.datetime_filter']:"0-9 /:";
echo format_field(
$LANG_VARS['updated'],
NULL,
"\n<select name=\"update_on_days\">".
"\n<option value=\"\">".$LANG_VARS['specify_datetime']." ---->".
"\n<option value=\"1\">".$LANG_VARS['one_day_ago'].
"\n<option value=\"7\">".$LANG_VARS['one_week_ago'].
"\n<option value=\"28\">".$LANG_VARS['one_month_ago'].
"\n<option value=\"365\">".$LANG_VARS['one_year_ago'].
"\n</select><br>".
get_input_field("update_on", NULL, NULL,"filtered(".$update_on_length.",".$update_on_length.",".$update_on_filter.")","N",NULL,FALSE).
"<div class=\"help\">(".$CONFIG_VARS['search.datetime_mask'].")</div>".
"\n<input type=hidden name=\"datetimemask\" value=\"".$CONFIG_VARS['search.datetime_mask']."\">");
//spacer!
echo("<tr><td class=\"data\" colspan=2> </td></tr>");
echo format_field(
$LANG_VARS['order_by'],
NULL,
"\n<select name=\"order_by\">".
"\n<option value=\"title\" SELECTED>".$LANG_VARS['title'].
"\n<option value=\"owner_id\">".$LANG_VARS['owner'].
"\n<option value=\"category\">".$LANG_VARS['category'].
"\n<option value=\"s_item_type\">".$LANG_VARS['item_type'].
"\n<option value=\"s_status_type\">".$LANG_VARS['s_status_type'].
"\n<option value=\"update_on\">".$LANG_VARS['update_date'].
"\n</select><br>".
"\n<input type=radio name=\"sortorder\" value=\"ASC\" CHECKED>".$LANG_VARS['asc']." ".
"\n<input type=radio name=\"sortorder\" value=\"DESC\">".$LANG_VARS['desc']);
echo("</td></tr></table>".
"</table></td></tr>");
echo("<tr><td align=center>");
echo("<br><input type=submit value=\"".$LANG_VARS['search_now']."\"><br><br>");
echo("</td></tr>");
echo("</form>");
echo("</table>");
if($s_status_type_search!==TRUE)
{
echo(format_help_block($LANG_VARS['search_help']));
}
echo _theme_footer();
}
else
{
include("./include/invalidsession.php");
}
// Cleanup after begin.inc.php
require_once("./include/end.inc.php");
?>
|