From 9f1f14fbf1c50179ff0f4f2aa0975616ed4044e6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Apr 2014 10:33:04 +0530 Subject: major changes done, updating to github --- search.inc | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'search.inc') diff --git a/search.inc b/search.inc index 887ec1f..5573d3a 100755 --- a/search.inc +++ b/search.inc @@ -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] = "" . $value . ""; + $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 .= '

'; + $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 '"; } function _list_of_colleges() { -- cgit