diff -ru database_head/view.php database_mammal/view.php --- database_head/view.php 2006-11-30 12:51:34.000000000 -0800 +++ database_mammal/view.php 2007-02-05 16:47:37.000000000 -0800 @@ -29,7 +29,6 @@ require_once('pagelib.php'); - /// One of these is necessary! $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database id @@ -42,7 +41,6 @@ /// These can be added to perform an action on a record $approve = optional_param('approve', 0, PARAM_INT); //approval recordid $delete = optional_param('delete', 0, PARAM_INT); //delete recordid - if ($id) { if (! $cm = get_record('course_modules', 'id', $id)) { @@ -82,7 +80,6 @@ $record = NULL; } - require_course_login($course, true, $cm); @@ -102,7 +99,6 @@ } } - /// Check further parameters that set browsing preferences if (!isset($SESSION->dataprefs)) { $SESSION->dataprefs = array(); @@ -115,29 +111,63 @@ $SESSION->dataprefs[$data->id]['advanced'] = 0; $SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC'; } + $advanced = optional_param('advanced', $SESSION->dataprefs[$data->id]['advanced'], PARAM_INT); $search_array = $SESSION->dataprefs[$data->id]['search_array']; + if (!empty($advanced)) { $search = ''; $fields = get_records('data_fields', 'dataid', $data->id); - if (!empty($fields)) { + + //Added to ammend paging error. This error would occur when attempting to go from one page of advanced + //search results to another. All fields were reset in the page transfer, and there was no way of determining + //whether or not the user reset them. This would cause a blank search to execute whenever the user attempted + //to see any page of results past the first. + //This fix works as follows: + //$paging flag is set to false when page 0 of the advanced search results is viewed for the first time. + //Viewing any page of results after page 0 passes the false $paging flag though the URL (see line 511) and the + //execution falls through to the second condition below, allowing paging to be set to true. + //Paging remains true and keeps getting passed though the URL until a new search is performed + //(even if page 0 is revisited). + //A false $paging flag generates advanced search results based on the fields input by the user. + //A true $paging flag generates davanced search results from the $SESSION global. + //(See lines 147-154) + if($page == 0 && !isset($paging)) { + $paging = false; + } + else { + $paging = true; + } + + if (!empty($fields)) { foreach($fields as $field) { $searchfield = data_get_field_from_id($field->id, $data); - $val = $searchfield->parse_search_field(); + + //Get field data to build search sql with. If paging is false, get from user. + //If paging is true, get data from $search_array wich is obtained from the $SESSION (see line 116). + if(!$paging) { + $val = $searchfield->parse_search_field(); + } + else { + $val = $search_array[$field->id]->data; + } + if (!empty($val)) { $search_array[$field->id] = new stdClass; $search_array[$field->id]->sql = $searchfield->generate_sql('c'.$field->id, $val); - $search_array[$field->id]->data = $val; - $search .= ' '.$val; + $search_array[$field->id]->data = $val; + $search .= ' '.$val; } else { if (isset($search_array[$field->id])) { // clear it out unset($search_array[$field->id]); } + } } + $pagingFlag = true; //Allows paging. } $SESSION->dataprefs[$data->id]['search_array'] = $search_array; // Make it sticky } @@ -152,7 +182,6 @@ $order = (optional_param('order', $SESSION->dataprefs[$data->id]['order'], PARAM_ALPHA) == 'ASC') ? 'ASC': 'DESC'; $SESSION->dataprefs[$data->id]['order'] = $order; // Make it sticky - $oldperpage = get_user_preferences('data_perpage_'.$data->id, 10); $perpage = optional_param('perpage', $oldperpage, PARAM_INT); @@ -266,7 +295,6 @@ } /// Print the tabs - if ($record or $mode == 'single') { $currenttab = 'single'; } elseif($mode == 'asearch') { @@ -277,6 +305,7 @@ } include('tabs.php'); + if ($mode != 'asearch') { /// Approve any requested records @@ -336,6 +365,7 @@ AND dc.recordid = r.id '; $sortorder = ' ORDER BY '.$sortcontentfull.' '.$order.' , r.id ASC '; $searchselect = ''; + if (!empty($advanced)) { //If advanced box is checked. foreach($search_array as $key => $val) { //what does $search_array hold? $tables .= ', '.$CFG->prefix.'data_content c'.$key.' '; @@ -347,9 +377,9 @@ $searchselect = ' AND (dc.content LIKE "%'.$search.'%") '; } else { $searchselect = ' '; - } - + } } else if ($search) { //Regular searches? + $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname '; $count = ' COUNT(DISTINCT c.recordid) '; $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u '; @@ -358,6 +388,7 @@ AND r.dataid = '.$data->id; $sortorder = ' ORDER BY r.id ASC '; $searchselect = ''; + if (!empty($advanced)) { //Advanced search box again. foreach($search_array as $key => $val) { $tables .= ', '.$CFG->prefix.'data_content c'.$key.' '; @@ -378,7 +409,6 @@ $searchselect = ' '; } - /// To actually fetch the records $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect; @@ -425,6 +455,7 @@ $page++; } + } else if ($mode == 'single') { // We rely on ambient $page settings $nowperpage = 1; @@ -433,10 +464,9 @@ } /// Get the actual records - $limit = sql_paging_limit($page * $nowperpage, $nowperpage); $records = get_records_sql($sqlselect.$limit); - + if (empty($records)) { // Nothing to show! if ($record) { // Something was requested so try to show that at least (bug 5132) if (isteacher($course->id) || empty($data->approval) || @@ -447,8 +477,9 @@ } } if ($records) { // OK, we can show this one + data_print_template('singletemplate', $records, $data, $search, $page); //A call to template printing. Displays the record in the proper template? - } else if ($search){ + } else if ($search){ notify(get_string('nomatch','data')); } else { notify(get_string('norecords','data')); @@ -472,7 +503,13 @@ } else { // List template $baseurl = 'view.php?d='.$data->id.'&'; - + + //send the advanced flag through the URL so it is remembered while paging. + $baseurl .= 'advanced='.$advanced.'&'; + + //pass variable to allow determining whether or not we are paging through results. + $baseurl .= 'paging='.$paging.'&'; + print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page'); if (empty($data->listtemplate)){ @@ -495,7 +532,6 @@ // search form doesn't make sense for single (redirects list view) - //DEBUGGING! if ($records || $search || $page || $mode = 'asearch' && $mode != 'single') { data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode); @@ -512,5 +548,13 @@ echo ''; } + +//Link back to the Museum homesite. + echo "


"; + echo "
Back to the museum homepage
"; + print_footer($course); + + ?>