/sh/directory/search-id.php

https://github.com/michaelmwu/saratogahigh.com · PHP · 91 lines · 73 code · 14 blank · 4 comment · 14 complexity · 845e59b7d9ca6030d391673230f9824d MD5 · raw file

  1. <?
  2. // Michael Wu || saratogahigh.com
  3. // directory/search-id.php: search for students by id
  4. // Most probably an XML request thing
  5. include "../inc/config.php";
  6. $xml->register_function('search_box');
  7. $xml->register_function('search_inner');
  8. $xml->handle_request();
  9. ?>
  10. <style type="text/css"><!--
  11. a.lnks {font-weight: bold}
  12. --></style>
  13. <? function search_box($search_id,$element_id) { ?>
  14. <div style="WIDTH: 210px; POSITION: absolute">
  15. <h1 style="margin-bottom: 0px; margin-top: 5px; font-size: large; padding: 2px; background-color: #eeeeee; border: 1px solid #cccccc">Search by Name</h1>
  16. <form style="margin: 0px" action="#" name="sf" onSubmit="search_for('<?=$search_id?>','<?=$element_id?>',document.getElementById('xfn').value,document.getElementById('xln').value);" method="POST">
  17. <p style="margin-top: 2px">Enter either a first name or last name, or both, to search for. The search will correct many minor spelling errors, so you might get nonexact matches.</p>
  18. <dl>
  19. <dt>First Name</dt>
  20. <dd><input type="text" id="xfn" name="xfn" value="<?=$f?>"></dd>
  21. <dt>Last Name</dt>
  22. <dd><input type="text" id="xln" name="xln" value="<?=$l?>"></dd>
  23. </dl>
  24. <p><input type="submit" name="btn" value="Search" onClick="search_inner('searchid','<?=$element_id?>',document.getElementById('xfn').value,document.getElementById('xln').value);"></p>
  25. </form>
  26. </div>
  27. <div id="search_inner" style="LEFT: 225px; width: 470px; POSITION: absolute">
  28. </div>
  29. <?
  30. }
  31. function search_inner($search_id,$element_id,$f = "",$l = "")
  32. {
  33. $hideall = false;
  34. if($l == "" && $f == "")
  35. $showresults = false;
  36. else
  37. {
  38. // Search by first or last name or both
  39. if($l == "")
  40. $query = "SELECT USER_ID, USER_FN, USER_LN, USER_GR FROM USER_LIST WHERE USER_FN_SOUNDEX=SOUNDEX('" . addslashes($f) . "') ORDER BY (USER_FN='" . addslashes($f) . "') DESC, USER_GR DESC, USER_LN, USER_FN";
  41. else if($f == "")
  42. $query = "SELECT USER_ID, USER_FN, USER_LN, USER_GR FROM USER_LIST WHERE USER_LN_SOUNDEX=SOUNDEX('" . addslashes($l) . "') ORDER BY (USER_LN='" . addslashes($l) . "') DESC, USER_GR DESC, USER_LN, USER_FN";
  43. else
  44. $query = "SELECT USER_ID, USER_FN, USER_LN, USER_GR FROM USER_LIST WHERE USER_LN_SOUNDEX=SOUNDEX('" . addslashes($l) . "') AND USER_FN_SOUNDEX=SOUNDEX('" . addslashes($f) . "') ORDER BY (USER_LN='" . addslashes($l) . "') DESC, (USER_FN='" . addslashes($f) . "') DESC, USER_GR DESC, USER_LN, USER_FN";
  45. $result = mysql_query($query) or die("Query failed");
  46. if(mysql_num_rows($result) == 1)
  47. {
  48. $line = mysql_fetch_array($result, MYSQL_ASSOC);
  49. $hideall = true;
  50. }
  51. $showresults = true;
  52. }
  53. if(!$hideall) { ?>
  54. <? if($showresults) { ?>
  55. <h1 style="margin: 0px; margin-top: 5px; font-size: large; padding: 2px; background-color: #eeeeee; border: 1px solid #cccccc">Search Results</h1>
  56. <?
  57. if(mysql_num_rows($result) > 0)
  58. {
  59. print '<table cellpadding="2">';
  60. while($line = db::fetch_row($result))
  61. print '<tr><td><a style="font-weight: bold" href="#" onClick="return loadID(\'' . $search_id . '\',\'' . $element_id . '\',' . $line['USER_ID'] . ');">' . $line['USER_FN'] . ' ' . $line['USER_LN'] . '</a></td><td>' . GradePrint($line['USER_GR']) . "</td></tr>\n";
  62. print "</table>";
  63. }
  64. else
  65. print "<p>Your search yielded no matches. Check your spelling and try again.</p>";
  66. mysql_free_result($result);
  67. }
  68. }
  69. else
  70. { ?>
  71. <script type="text/javascript">
  72. <!--
  73. loadID('<?=$search_id?>','<?=$element_id>?',<?=$line['USER_ID']?>);
  74. -->
  75. </script>
  76. <? }
  77. } ?>