diff options
author | root | 2014-04-10 10:33:04 +0530 |
---|---|---|
committer | root | 2014-04-10 10:33:04 +0530 |
commit | 9f1f14fbf1c50179ff0f4f2aa0975616ed4044e6 (patch) | |
tree | 95b90612cda885fe86061cfe77e0ca191e995f2d /search.inc | |
parent | a37654c53a9c2ccf4980f65f9398c23688f089bd (diff) | |
download | scilab_textbook_companion-9f1f14fbf1c50179ff0f4f2aa0975616ed4044e6.tar.gz scilab_textbook_companion-9f1f14fbf1c50179ff0f4f2aa0975616ed4044e6.tar.bz2 scilab_textbook_companion-9f1f14fbf1c50179ff0f4f2aa0975616ed4044e6.zip |
major changes done, updating to github
Diffstat (limited to 'search.inc')
-rwxr-xr-x | search.inc | 63 |
1 files changed, 60 insertions, 3 deletions
@@ -110,11 +110,36 @@ function textbook_companion_browse_author() return $return_html; } $book_rows = array(); - $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE author like '%s%%' AND approval_status = 1", $query_character); + $book_q = db_query("SELECT pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as id FROM {textbook_companion_preference} pe RIGHT JOIN {textbook_companion_proposal} po on pe.proposal_id=po.id WHERE po.proposal_status=3 and pe.approval_status = 1", $query_character); while ($book_data = db_fetch_object($book_q)) { - $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author); + /* Initial's fix algorithm */ + preg_match_all("/{$query_character}[a-z]+/", $book_data->author, $matches); + + if (count($matches) > 0) { + /* Remove the word "And"/i from the match array and make match bold */ + if (count($matches[0]) > 0) { + + foreach ($matches[0] as $key => $value) { + + if (strtolower($value) == "and") { + unset($matches[$key]); + } + else { + $matches[0][$key] = "<b>" . $value . "</b>"; + $book_data->author = str_replace($value, $matches[0][$key], $book_data->author); + } + } + } + + /* Check count of matches after removing And */ + if (count($matches[0]) > 0) { + $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author); + } + } } + + if (!$book_rows) { $return_html .= "Sorry no books are available with that author's name"; @@ -125,6 +150,38 @@ function textbook_companion_browse_author() return $return_html; } +function textbook_companion_browse_student() +{ + $return_html = _browse_list('student'); + $return_html .= '<br /><br />'; + $query_character = arg(2); + if (!$query_character) { + /* all books */ + $return_html .= "Please select the starting character of the student's name"; + return $return_html; + } + $book_rows = array(); + $query = "SELECT * FROM textbook_companion_proposal WHERE full_name like '".$query_character."%' ORDER BY full_name ASC"; + $student_q = db_query($query); + while ($student_data = db_fetch_object($student_q)) + { + $query = "SELECT * FROM textbook_companion_preference WHERE proposal_id = " . $student_data->id . " AND approval_status = 1"; + $book_q = db_query($query); + while ($book_data = db_fetch_object($book_q)) + { + $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $student_data->full_name); + } + } + if (!$book_rows) + { + $return_html .= "Sorry no books are available with that student's name"; + } else { + $book_header = array('Title of the Book', 'Student Name'); + $return_html .= theme_table($book_header, $book_rows); + } + return $return_html; +} + function _browse_list($type) { $return_html = ''; @@ -135,7 +192,7 @@ function _browse_list($type) if ($char_name != 'Z') $return_html .= ' | '; } - return $return_html; + return '<div id="filter-links">' . $return_html . "</div>"; } function _list_of_colleges() { |