';
print_heading(format_string($data->name));
// Do we need to show a link to the RSS feed for the records?
if (isset($CFG->enablerssfeeds) && isset($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
echo '
';
echo '';
}
if ($data->intro) {
print_simple_box(format_text($data->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
echo ' ';
}
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode,
'view.php?d='.$data->id.'&search='.s($search).'&sort='.s($sort).
'&order='.s($order).'&');
} else {
$currentgroup = 0;
}
if ($currentgroup) {
$groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
$groupparam = "&groupid=$currentgroup";
} else {
$groupselect = "";
$groupparam = "";
}
/// Print the tabs
$currenttab = 'browse';
include('tabs.php');
/// Approve any requested records
if ($approve && confirm_sesskey() && isteacher($course->id)) {
if ($record = get_record('data_records', 'id', $approve)) { // Need to check this is valid
if ($record->dataid == $data->id) { // Must be from this database
$newrecord->id = $record->id;
$newrecord->approved = 1;
if (update_record('data_records', $newrecord)) {
notify(get_string('recordapproved','data'), 'notifysuccess');
}
}
}
}
/// Delete any requested records
if ($delete && confirm_sesskey()) {
if (isteacheredit($course) or data_isowner($delete)){
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
if ($contents = get_records('data_content','recordid', $delete)) {
foreach ($contents as $content) { // Delete files or whatever else this field allows
if ($field = data_get_field_from_id($content->fieldid, $data)) { // Might not be there
$field->delete_content($content->recordid);
}
}
}
delete_records('data_content','recordid',$delete);
delete_records('data_records','id',$delete);
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
notify(get_string('recorddeleted','data'));
} else { // Print a confirmation page
notice_yesno(get_string('confirmdeleterecord','data'),
'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
'view.php?d='.$data->id);
print_footer($course);
exit;
}
}
}
// If not editting teacher, check whether user has sufficient records to view
if (!isteacheredit($course->id) and data_numentries($data) < $data->requiredentriestoview){
notify (($data->requiredentriestoview - data_numentries($data)).' '.get_string('insufficiententries','data'));
echo '
';
print_footer($course);
exit;
}
if ($rid){ //set per page to 1, if looking for 1 specific record
set_user_preference('data_perpage', DATA_PERPAGE_SINGLE);
}
/*****************************
* Setting up page variables *
*****************************/
$perpage = get_user_preferences('data_perpage', 10); //get default per page
$baseurl = 'view.php?d='.$data->id.'&search='.s($search).'&sort='.s($sort).'&order='.s($order).'&group='.$currentgroup.'&';
//if database requires approval, then we need to do some work
//and get those approved entries, or entries belongs to owner
if ((!isteacher($course->id)) && ($data->approval)){
$approvesql = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
} else {
$approvesql = '';
}
if ($rid){ //only used for single mode, but rid should not appear in multi view anyway
$ridsql = 'AND r.id < '.$rid.' ';
} else {
$ridsql = '';
}
if ($sort) { //supports (sort and search)
//first find the field that we are sorting
$sortfield = data_get_field_from_id($sort, $data);
$sortcontent = $sortfield->get_sort_field();
///SEARCH AND SORT SQL
$sql = 'SELECT DISTINCT c.recordid, c.recordid
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_records r, '
.$CFG->prefix.'data_content c1
WHERE c.recordid = r.id
AND c1.recordid = r.id
AND r.dataid = '.$data->id.'
AND c.fieldid = '.$sort.' '.$groupselect.'
AND ((c1.content LIKE "%'.$search.'%") OR
(c1.content1 LIKE "%'.$search.'%") OR
(c1.content2 LIKE "%'.$search.'%") OR
(c1.content3 LIKE "%'.$search.'%") OR
(c1.content4 LIKE "%'.$search.'%")) '.$approvesql.'
ORDER BY c.'.$sortcontent.' '.$order.' ';
$sqlcount = 'SELECT COUNT(DISTINCT c.recordid)
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_records r, '
.$CFG->prefix.'data_content c1
WHERE c.recordid = r.id
AND c1.recordid = r.id
AND r.dataid = '.$data->id.'
AND c.fieldid = '.$sort.' '.$groupselect.'
AND ((c1.content LIKE "%'.$search.'%") OR
(c1.content1 LIKE "%'.$search.'%") OR
(c1.content2 LIKE "%'.$search.'%") OR
(c1.content3 LIKE "%'.$search.'%") OR
(c1.content4 LIKE "%'.$search.'%")) '.$approvesql.'
ORDER BY c.'.$sortcontent.' '.$order.' ';
//sqlindex is used to find the number of entries smaller than the current rid
//useful for zooming into single view from multi view (so we can keep track
//of exact and relative position of records
$sqlindex = 'SELECT COUNT(DISTINCT c.recordid)
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_records r, '
.$CFG->prefix.'data_content c1
WHERE c.recordid = r.id
AND c1.recordid = r.id
AND r.dataid = '.$data->id.'
AND c.fieldid = '.$sort.' '.$ridsql.' '.$groupselect.'
AND ((c1.content LIKE "%'.$search.'%") OR
(c1.content1 LIKE "%'.$search.'%") OR
(c1.content2 LIKE "%'.$search.'%") OR
(c1.content3 LIKE "%'.$search.'%") OR
(c1.content4 LIKE "%'.$search.'%")) '.$approvesql.'
ORDER BY c.'.$sortcontent.' '.$order.' ';
} else if ($search){ //search only, no sort. if in search mode, only search text fields
$sql = 'SELECT DISTINCT c.recordid, c.recordid
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_fields f, '
.$CFG->prefix.'data_records r
WHERE c.recordid = r.id '.$groupselect.' '.$approvesql.' AND
c.fieldid = f.id AND f.dataid = '
.$data->id.' AND c.content LIKE "%'.$search.'%" ORDER BY r.id '.$order.' ';
$sqlcount = 'SELECT COUNT(DISTINCT c.recordid)
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_fields f, '
.$CFG->prefix.'data_records r
WHERE c.recordid = r.id '.$groupselect.' '.$approvesql.' AND
c.fieldid = f.id AND f.dataid = '
.$data->id.' AND c.content LIKE "%'.$search.'%" ORDER BY r.id '.$order.' ';
$sqlindex = 'SELECT COUNT(DISTINCT c.recordid)
FROM '.$CFG->prefix.'data_content c, '
.$CFG->prefix.'data_fields f, '
.$CFG->prefix.'data_records r
WHERE c.recordid = r.id '.$groupselect.' '.$approvesql.' AND
c.fieldid = f.id AND f.dataid = '
.$data->id.' '.$ridsql.' AND c.content LIKE "%'.$search.'%" ORDER BY r.id '.$order.' ';
} else { //else get everything, no search, no sort
$sql = 'SELECT * FROM '.$CFG->prefix.'data_records r WHERE r.dataid ='.$data->id.' '.$groupselect.' '.$approvesql.' ORDER BY r.id '.$order.' ';
$sqlcount = 'SELECT COUNT(*) FROM '.$CFG->prefix
.'data_records r WHERE r.dataid ='.$data->id.' '.$groupselect.' '.$approvesql.'ORDER BY r.id '.$order.' ';
$sqlindex = 'SELECT COUNT(*) FROM '.$CFG->prefix
.'data_records r WHERE r.dataid ='.$data->id.' '.$groupselect.' '.$ridsql.' '.$approvesql .'ORDER BY r.id '.$order.' ';
}
if ($rid) { //this is used in zooming
$page = count_records_sql($sqlindex);
}
$limit = $perpage > 1 ? sql_paging_limit($page * $perpage, $perpage)
: $limit = sql_paging_limit($page, DATA_PERPAGE_SINGLE);
$sql = $sql . $limit;
$totalcount = count_records_sql($sqlcount);
if (!$records = get_records_sql($sql)){
if ($search){
notify(get_string('nomatch','data'));
}
else {
notify(get_string('norecords','data'));
}
data_print_preference_form($data, $perpage, $search);
echo '';
print_footer($course);
exit;
}
//print header for multi view
if ($perpage > 1){
echo $data->listtemplateheader;
$listmode = 'listtemplate';
if (empty($data->listtemplate)){
notify(get_string('nolisttemplate','data'));
}
}
else {
$listmode = 'singletemplate';
if (empty($data->singletemplate)){
notify(get_string('nosingletemplate','data'));
}
}
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
//for each record we find, we do a string replacement for tags.
data_print_template($records, $data, $search, $listmode, $sort, $page, $rid, $order, $currentgroup);
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
if ($perpage > 1){
echo $data->listtemplatefooter; //print footer
}
data_print_preference_form($data, $perpage, $search, $sort, $order);
// Finish the page
echo '';
print_footer($course);
?>