diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php
index 82db9360084..22bd37f88e6 100644
--- a/lang/en_utf8/data.php
+++ b/lang/en_utf8/data.php
@@ -109,6 +109,8 @@ $string['filesnotgenerated'] = 'Not all files were generated: $a';
$string['filtername'] = 'Database Auto-linking';
$string['footer'] = 'Footer';
$string['forcelinkname'] = 'Forced name for the link';
+$string['foundrecords'] = 'Found records: $a->num/$a->max (reseturl\">Reset filters)';
+$string['foundnorecords'] = 'No records found (reseturl\">Reset filters)';
$string['fromfile'] = 'Import from zip file';
$string['header'] = 'Header';
$string['headeraddtemplate'] = 'Defines the interface when editing entries';
@@ -202,7 +204,7 @@ $string['requireapproval'] = 'Require approval?';
$string['requiredentries'] = 'Required entries';
$string['requiredentriestoview'] = 'Entries required before viewing';
$string['resettemplate'] = 'Reset template';
-$string['resetsettings'] = 'Reset Fields';
+$string['resetsettings'] = 'Reset filters';
$string['resizingimages'] = 'Resizing image thumbnails...';
$string['rows'] = 'rows';
$string['rssglobaldisabled'] = 'Disabled. See site configuration variables.';
diff --git a/mod/data/lib.php b/mod/data/lib.php
index b79577c04da..c0ecdd0150f 100755
--- a/mod/data/lib.php
+++ b/mod/data/lib.php
@@ -961,6 +961,7 @@ function data_print_template($template, $records, $data, $search='',$page=0, $re
.$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'">
';
} else {
$replacement[] = '';
+ $replacement[] = '';
}
$patterns[]='##more##';
$replacement[] = '
';
@@ -1205,7 +1206,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
echo format_text($newtext, FORMAT_HTML, $options);
echo '';
- echo '
|
';
+ echo '
|
';
echo '';
echo '';
echo '';
diff --git a/mod/data/view.php b/mod/data/view.php
index 772a52058b0..d17159619fd 100755
--- a/mod/data/view.php
+++ b/mod/data/view.php
@@ -106,6 +106,13 @@
$SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
}
+ // reset advanced form
+ if (!is_null(optional_param('resetadv', null, PARAM_RAW))) {
+ $SESSION->dataprefs[$data->id]['search_array'] = array();
+ // we need the redirect to cleanup the form state properly
+ redirect("view.php?id=$cm->id&mode=$mode&search=&advanced=1");
+ }
+
$advanced = optional_param('advanced', -1, PARAM_INT);
if ($advanced == -1) {
$advanced = $SESSION->dataprefs[$data->id]['advanced'];
@@ -118,7 +125,7 @@
}
$search_array = $SESSION->dataprefs[$data->id]['search_array'];
-
+
if (!empty($advanced)) {
$search = '';
$vals = array();
@@ -356,7 +363,10 @@
}
include('tabs.php');
- if ($mode != 'asearch') {
+ if ($mode == 'asearch') {
+ $maxcount = 0;
+
+ } else {
/// Approve any requested records
if ($approve && confirm_sesskey() && has_capability('mod/data:approve', $context)) {
@@ -371,15 +381,15 @@
}
}
- // Check the number of entries required against the number of entries already made (doesn't apply to teachers)
- $requiredentries_allowed = true;
- $numentries = data_numentries($data);
- if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
- $data->entriesleft = $data->requiredentries - $numentries;
- $strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data);
- notify($strentrieslefttoadd);
- $requiredentries_allowed = false;
- }
+ // Check the number of entries required against the number of entries already made (doesn't apply to teachers)
+ $requiredentries_allowed = true;
+ $numentries = data_numentries($data);
+ if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
+ $data->entriesleft = $data->requiredentries - $numentries;
+ $strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $data);
+ notify($strentrieslefttoadd);
+ $requiredentries_allowed = false;
+ }
/// We need to examine the whole dataset to produce the correct paging
@@ -414,6 +424,7 @@
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname';
$count = ' COUNT(DISTINCT c.recordid) ';
+ $rids = ' DISTINCT c.recordid ';
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
$where = 'WHERE c.recordid = r.id
AND r.dataid = '.$data->id.'
@@ -450,6 +461,7 @@
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order ';
$count = ' COUNT(DISTINCT c.recordid) ';
+ $rids = ' DISTINCT c.recordid ';
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content cs, '.$CFG->prefix.'user u ';
$where = 'WHERE c.recordid = r.id
AND c.fieldid = '.$sort.'
@@ -483,6 +495,7 @@
} else if ($search) {
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(DISTINCT c.recordid) ';
+ $rids = ' DISTINCT c.recordid ';
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
$where = 'WHERE c.recordid = r.id
AND r.userid = u.id
@@ -513,6 +526,7 @@
} else {
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(r.id) ';
+ $rids = ' COUNT(r.id) ';
$tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
$where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
$sortorder = ' ORDER BY r.timecreated '.$order. ' ';
@@ -527,49 +541,34 @@
/// To actually fetch the records
- $fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
+ $fromsql = "FROM $tables $where $groupselect $approveselect $searchselect";
+ $sqlselect = "SELECT $what $fromsql $sortorder";
+ $sqlcount = "SELECT $count $fromsql"; // Total number of records when searching
+ $sqlrids = "SELECT $rids $fromsql";
+ $sqlmax = "SELECT $count FROM $tables $where $groupselect $approveselect"; // number of all recoirds user may see
- $sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
-
- $sqlcount = 'SELECT '.$count.$fromsql; // Total number of records
-
- /// Work out the paging numbers
+ /// Work out the paging numbers and counts
$totalcount = count_records_sql($sqlcount);
+ if (empty($searchselect)) {
+ $maxcount = $totalcount;
+ } else {
+ $maxcount = count_records_sql($sqlmax);
+ }
if ($record) { // We need to just show one, so where is it in context?
$nowperpage = 1;
$mode = 'single';
- # Following code needs testing to make it work
- # if ($sort) { // We need to search by that field
- # if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
- # $content = addslashes($content);
- # if ($order == 'ASC') {
- # $lessthan = " AND $sortcontentfull < '$content'
- # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
- # } else {
- # $lessthan = " AND $sortcontentfull > '$content'
- # OR ($sortcontentfull = '$content' AND r.id < '$record->id') ";
- # }
- # } else { // Failed to find data (shouldn't happen), so fall back to something easy
- # $lessthan = " r.id < '$record->id' ";
- # }
- # } else {
- # $lessthan = " r.id < '$record->id' ";
- # }
- # $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
- # $page = count_records_sql($sqlindex);
-
-
$page = 0;
- if ($allrecords = get_records_sql($sqlselect)) { // Kludgey but accurate at least!
- foreach ($allrecords as $key => $allrecord) {
+ if ($allrecords = get_records_sql($sqlrids)) { // Kludgey but accurate at least!
+ foreach ($allrecords as $key => $unused) {
if ($key == $record->id) {
break;
}
$page++;
}
+ unset($allrecords);
}
} else if ($mode == 'single') { // We rely on ambient $page settings
@@ -581,26 +580,39 @@
/// Get the actual records
- $records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage);
-
- if (empty($records)) { // Nothing to show!
+ if (!$records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage)) {
+ // Nothing to show!
if ($record) { // Something was requested so try to show that at least (bug 5132)
if (has_capability('mod/data:manageentries', $context) || empty($data->approval) ||
$record->approved || (isloggedin() && $record->userid == $USER->id)) {
if (!$currentgroup || $record->groupid == $currentgroup || $record->groupid == 0) {
- $records[] = $record;
+ // OK, we can show this one
+ $records = array($record->id => $record);
+ $totalcount = 1;
}
}
}
- if ($records) { // OK, we can show this one
- data_print_template('singletemplate', $records, $data, $search, $page);
- } else if ($search){
- notify(get_string('nomatch','data'));
+ }
+
+ if (empty($records)) {
+ if ($maxcount){
+ $a = new object();
+ $a->max = $maxcount;
+ $a->reseturl = "view.php?id=$cm->id&mode=$mode&search=&advanced=0";
+ notify(get_string('foundnorecords','data', $a));
} else {
notify(get_string('norecords','data'));
}
- } else { // We have some records to print
+ } else { // We have some records to print
+
+ if ($maxcount != $totalcount) {
+ $a = new object();
+ $a->num = $totalcount;
+ $a->max = $maxcount;
+ $a->reseturl = "view.php?id=$cm->id&mode=$mode&search=&advanced=0";
+ notify(get_string('foundrecords', 'data', $a), 'notifysuccess');
+ }
if ($mode == 'single') { // Single template
$baseurl = 'view.php?d='.$data->id.'&mode=single&';
@@ -645,7 +657,7 @@
}
//Advanced search form doesn't make sense for single (redirects list view)
- if (($records || $search || $page || $mode == 'asearch') && $mode != 'single') {
+ if (($maxcount || $mode == 'asearch') && $mode != 'single') {
data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
}