changes in search, sort etc

This commit is contained in:
moodler 2006-02-03 08:11:36 +00:00
parent 31c1f1c93e
commit cf3e199bce
14 changed files with 247 additions and 139 deletions

View File

@ -26,15 +26,9 @@
require_once('lib.php');
require_once($CFG->libdir.'/blocklib.php');
define('PAGE_DATA_ADD', 'mod-data-add');
define('PAGE_DATA', PAGE_DATA_ADD);
require_once('pagelib.php');
require_login();
page_map_class(PAGE_DATA_ADD, 'page_data');
$DEFINEDPAGES = array(PAGE_DATA_ADD,);
$mode ='addtemplate'; //define the mode for this page, only 1 mode available
$id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database id
@ -77,11 +71,6 @@
add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
// Initialize $PAGE, compute blocks
$PAGE = page_create_instance($data->id);
$pageblocks = blocks_setup($PAGE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
/// Print the page header
if (!empty($edit) && $PAGE->user_allowed_editing()) {
@ -92,17 +81,9 @@
}
}
$PAGE->print_header($course->shortname.': %fullname%');
$strdata = get_string('modulenameplural','data');
echo '<table id="layout-table"><tr>';
if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
echo '</td>';
}
echo '<td id="middle-column">';
print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course));
print_heading(format_string($data->name));
@ -136,7 +117,15 @@
if ($datarecord = data_submitted() and confirm_sesskey()) {
//if rid is present, we are in updating mode
if ($rid){
//set flag to unapproved after each edit
$record = get_record('data_records','id',$rid);
$record->approved = 0;
update_record('data_records',$record);
foreach ($datarecord as $name=>$value){
//this creates a new field subclass object
if ($name != 'MAX_FILE_SIZE' && $name != 'sesskey'){
$currentfield = data_get_field_from_name($name);
@ -163,13 +152,22 @@
}
} ///End of Empty form checking
if (!$emptyform && $recordid = data_add_record($data->id)){ //add instance to data_record
$fields = get_records('data_fields','dataid',$data->id);
//do a manual round of inserting, to make sure even empty conentes get stored
foreach ($fields as $field) {
$content ->recordid = $recordid;
$content ->fieldid = $field->id;
insert_record('data_content',$content);
}
//for each field in the add form, add it to the data_content.
foreach ($datarecord as $name => $value){
if ($name != 'MAX_FILE_SIZE' && $name != 'sesskey'){ //hack to skip these inputs
$currentfield = data_get_field_from_name($name);
//use native subclass method to sore field data
$currentfield->store_data_content($currentfield->id, $recordid, $value, $name);
$currentfield->update_data_content($currentfield->id, $recordid, $value, $name);
}
}
$entrysaved = true;
@ -244,8 +242,6 @@
echo '</form>';
/// Finish the page
echo '</td></tr></table>';
// Print the stuff that need to come after the form fields.
$storedFields = get_records('data_fields', 'dataid', $data->id);
@ -257,6 +253,5 @@
$fieldObj->print_after_form();
}
print_footer($course);
?>
?>

View File

@ -88,6 +88,7 @@ function data_backup_one_mod($bf,$preferences,$data) {
fwrite ($bf,full_tag("RSSTEMPLATE",4,false,$data->rsstemplate));
fwrite ($bf,full_tag("LISTTEMPLATEHEADER",4,false,$data->listtemplateheader));
fwrite ($bf,full_tag("LISTTEMPLATEFOOTER",4,false,$data->listtemplatefooter));
fwrite ($bf,full_tag("APPROVAL",4,false,$data->approval));
// if we've selected to backup users info, then call any other functions we need
// including backing up individual files
@ -280,6 +281,7 @@ function backup_data_records($bf,$preferences,$dataid){
fwrite ($bf,full_tag("DATAID",6,false,$rec_sub->dataid));
fwrite ($bf,full_tag("TIMECREATED",6,false,$rec_sub->timecreated));
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$rec_sub->timemodified));
fwrite ($bf,full_tag("APPROVED",6,false,$rec_sub->approved));
//End submission
backup_data_content($bf,$preferences,$rec_sub->id);

View File

@ -13,6 +13,11 @@ function data_upgrade($oldversion) {
table_column("data_content", "", "content4", "longtext", "", "", "", "not null");
}
if ($oldversion < 2006011901) {
table_column("data", "", "approval", "tinyint", "4", "", "", "not null");
table_column("data_records", "", "approved", "tinyint", "4", "", "", "not null");
}
return true;
}

View File

@ -32,6 +32,7 @@ CREATE TABLE prefix_data (
rsstemplate text NOT NULL default '',
listtemplateheader text NOT NULL default '',
listtemplatefooter text NOT NULL default '',
approval tinyint(4) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='Defines settings for each Database activity';
@ -76,6 +77,7 @@ CREATE TABLE prefix_data_records (
dataid int(10) unsigned NOT NULL default '0',
timecreated int(10) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
approved tinyint(4) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;

View File

@ -13,6 +13,10 @@ function data_upgrade($oldversion) {
table_column("data_content", "", "content4", "text", "", "", "", "not null");
}
if ($oldversion < 2006011901) {
table_column("data", "", "approval", "int", "1", "", "", "not null");
table_column("data_records", "", "approved", "int", "1", "", "", "not null");
}
return true;
}

View File

@ -18,6 +18,7 @@ CREATE TABLE prefix_data (
rsstemplate text NOT NULL default '',
listtemplateheader text NOT NULL default '',
listtemplatefooter text NOT NULL default ''
approval int NOT NULL default '0',
);
@ -59,7 +60,8 @@ CREATE TABLE prefix_data_records (
groupid int4 NOT NULL default '0',
dataid int4 NOT NULL default '0',
timecreated int4 NOT NULL default '0',
timemodified int4 NOT NULL default '0'
timemodified int4 NOT NULL default '0',
approved int NOT NULL default '0',
);

View File

@ -26,15 +26,9 @@
require_once('lib.php');
require_once($CFG->libdir.'/blocklib.php');
define('PAGE_DATA_FIELDS', 'mod-data-fields');
define('PAGE_DATA', PAGE_DATA_FIELDS);
require_once('pagelib.php');
require_login();
page_map_class(PAGE_DATA_FIELDS, 'page_data');
$DEFINEDPAGES = array(PAGE_DATA_FIELDS);
$id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database id
$fid = optional_param('fid', 0 , PARAM_INT); //update field id
@ -72,34 +66,10 @@
}
add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
// Initialize $PAGE, compute blocks
$PAGE = page_create_instance($data->id);
$pageblocks = blocks_setup($PAGE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
$strdata = get_string('modulenameplural','data');
/// Print the page header
if (!empty($edit) && $PAGE->user_allowed_editing()) {
if ($edit == 'on') {
$USER->editing = true;
} else if ($edit == 'off') {
$USER->editing = false;
}
}
$PAGE->print_header($course->shortname.': %fullname%');
echo '<table id="layout-table"><tr>';
if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
echo '</td>';
}
echo '<td id="middle-column">';
print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course));
print_heading(format_string($data->name));
@ -315,8 +285,6 @@
}
/// Finish the page
echo '</td></tr></table>';
print_footer($course);
?>

View File

@ -213,6 +213,13 @@ class data_field_base { //base class (text field)
}
/* returns the sortable field for the content. By default, it's just content
* but for some plugins, it could be content 1 - content4
*/
function get_sort_field() {
return 'content';
}
}//end of class data_field_base
@ -648,14 +655,15 @@ function data_get_coursemodule_info($coursemodule) {
* @param string $listmode *
* output null *
************************************************************************/
function data_print_template($records, $data, $search, $listmode){
global $CFG;
function data_print_template($records, $data, $search, $listmode, $sort, $page, $rid, $order){
global $CFG, $course;
foreach ($records as $record){ //only 1 record for single mode
//replacing tags
$patterns = array();
$replacement = array();
if ($search){ //the ids are different for the 2 searches
if ($search || $sort){ //the ids are different for the 2 searches
$record->id = $record->recordid;
}
@ -668,6 +676,7 @@ function data_print_template($records, $data, $search, $listmode){
$replacement[] = highlight($search, $g->display_browse_field($cfield->id, $record->id));
unset($g);
}
///replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='/\#\#Edit\#\#/i';
$patterns[]='/\#\#Delete\#\#/i';
@ -686,13 +695,20 @@ function data_print_template($records, $data, $search, $listmode){
}else {
$replacement[] = '';
}
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
.$data->id.'&amp;rid='.$record->id.'"><img src="'.$CFG->pixpath.'/i/search.gif" height="11" width="11" border="0" alt="'.get_string('more').'" /></a>';
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$record->id.'&amp;search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;"><img src="'.$CFG->pixpath.'/i/search.gif" height="11" width="11" border="0" alt="'.get_string('more').'" /></a>';
///actual replacement of the tags
$newtext = preg_replace($patterns, $replacement, $data->{$listmode});
echo $newtext; //prints the template with tags replaced
//if this record is not yet approved, and database requires approval, print silly button
$record = get_record('data_records','id',$record->id);
if (isteacher($course->id) && (!$record->approved) && $data->approval) {
data_print_approve_button($record->id, $data->id, $page, $rid, $search, $sort, $order);
}
echo '<p></p>';
}
}
@ -705,9 +721,9 @@ function data_print_template($records, $data, $search, $listmode){
* @param string $search *
* output null *
************************************************************************/
function data_print_preference_form($data, $perpage, $search){
function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC'){
echo '<br />';
echo '<form name="options" action="view.php?d='.$data->id.'&amp;search='.s($search).'" method="post">';
echo '<form name="options" action="view.php?d='.$data->id.'&amp;search='.s($search).'&amp;sort='.s($sort).'&amp;order='.s($order).'" method="post">';
echo '<table id="optiontable" align="center">';
echo '<tr><td>'.get_string('search').'</td>';
echo '<td><input type="text" size = "16" name="search" value="'.s($search).'" />';
@ -717,18 +733,62 @@ function data_print_preference_form($data, $perpage, $search){
echo ':</td>';
echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
echo '<td align="left">';
$pagesizes = array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,20=>20,30=>30,40=>40,50=>50);
$pagesizes = array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
choose_from_menu($pagesizes,'perpage1',$perpage,'choose','','0');
echo '<input type="text" id="perpage" name="perpage" size="2" value="'.$perpage.'" />';
echo '</td></tr>';
echo '<tr>';
echo '<tr><td>';
echo 'Sort by:';
echo '</td><td>';
//foreach field, print the option
$fields = get_records('data_fields','dataid',$data->id);
echo '<select name="sort"><option value="0">'.get_string('dateentered','data').'</option>';
foreach ($fields as $field) {
if ($field->id == $sort) {
echo '<option value="'.$field->id.'" SELECTED>'.$field->name.'</option>';
} else {
echo '<option value="'.$field->id.'">'.$field->name.'</option>';
}
}
echo '</select>';
echo '<select name="order">';
if ($order == "ASC") {
echo '<option value="ASC" SELECTED>'.get_string('ascending','data').'</option>';
} else {
echo '<option value="ASC">'.get_string('ascending','data').'</option>';
}
if ($order == "DESC") {
echo '<option value="DESC" SELECTED>'.get_string('descending','data').'</option>';
} else {
echo '<option value="DESC">'.get_string('descending','data').'</option>';
}
//print ASC or DESC
echo '</td></tr><tr>';
echo '<td colspan="2" align="center">';
echo '<input type="submit" value="'.get_string('savepreferences').'" />';
echo '</td></tr></table>';
echo '</form>';
}
//silly function that prints a button
function data_print_approve_button($recordid, $d, $page='0', $rid='0', $search='', $sort='', $order='') {
echo '<div align="center"><form action="approve.php" method="GET">';
echo '<input type="hidden" name="d" value="'.$d.'" />';
echo '<input type="hidden" name="rid" value="'.$rid.'" />';
echo '<input type="hidden" name="page" value="'.$page.'" />';
echo '<input type="hidden" name="search" value="'.$search.'" />';
echo '<input type="hidden" name="sort" value="'.$sort.'" />';
echo '<input type="hidden" name="order" value="'.$order.'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="recordid" value="'.$recordid.'" />';
echo '<input type="submit" value="'.get_string('approve').'" />';
echo '</form></div>';
}
?>
//silly function that approves a record
function data_approve_record($recordid) {
$record = get_record('data_records','id',$recordid);
$record->approved = 1;
update_record('data_records',$record);
}
?>

View File

@ -50,6 +50,9 @@
if (!isset($form->ratings)) {
$form->ratings = 0;
}
if (!isset($form->approval)) {
$form->approval = 0;
}
?>
<script type="text/javascript" language="javascript">
@ -216,7 +219,15 @@
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string('requireapproval', 'data') ?>:</b></td>
<td>
<?php
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
choose_from_menu($ynoptions, 'approval', $form->approval, '');
?>
</td>
</tr>
<?php if (!empty($CFG->data_enablerssfeeds) and !empty($CFG->enablerssfeeds)) { ?>
<tr valign="top">

View File

@ -1,11 +1,12 @@
<?php // $Id$
require_once($CFG->libdir.'/pagelib.php');
define('PAGE_DATA', 'mod-data');
page_map_class(PAGE_DATA, 'page_data');
define('PAGE_DATA_VIEW', 'mod-data-view');
$DEFINEDPAGES = array(PAGE_DATA);
page_map_class(PAGE_DATA_VIEW, 'page_data');
$DEFINEDPAGES = array(PAGE_DATA_VIEW);
/*
*/
@ -81,7 +82,7 @@ class page_data extends page_generic_activity {
}
function get_type() {
return PAGE_DATA;
return PAGE_DATA_VIEW;
}
}

View File

@ -73,7 +73,7 @@ function data_restore_mods($mod,$restore) {
$database->rsstemplate = backup_todb($info['MOD']['#']['RSSTEMPLATE']['0']['#']);
$database->listtemplateheader = backup_todb($info['MOD']['#']['LISTTEMPLATEHEADER']['0']['#']);
$database->listtemplatefooter = backup_todb($info['MOD']['#']['LISTTEMPLATEFOOTER']['0']['#']);
$database->approval = backup_todb($info['MOD']['#']['APPROVAL']['0']['#']);
$newid = insert_record ("data",$database);
//Do some output
@ -172,7 +172,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
$record -> groupid = backup_todb($rec_info['#']['GROUPID']['0']['#']);
$record -> timecreated = backup_todb($rec_info['#']['TIMECREATED']['0']['#']);
$record -> timemodified = backup_todb($rec_info['#']['TIMEMODIFIED']['0']['#']);
$record -> approved = backup_todb($rec_info['#']['APPROVED']['0']['#']);
$user = backup_getid($restore->backup_unique_code,"user",$record->userid);
if ($user) {

View File

@ -26,15 +26,8 @@
require_once('lib.php');
require_once($CFG->libdir.'/blocklib.php');
define('PAGE_DATA_TEMPLATES', 'mod-data-templates');
define('PAGE_DATA', PAGE_DATA_TEMPLATES);
require_once('pagelib.php');
require_login();
page_map_class(PAGE_DATA_TEMPLATES, 'page_data');
$DEFINEDPAGES = array(PAGE_DATA_TEMPLATES,);
$id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database id
$mode = optional_param('mode', '', PARAM_ALPHA);
@ -74,33 +67,12 @@
add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
// Initialize $PAGE, compute blocks
$PAGE = page_create_instance($data->id);
$pageblocks = blocks_setup($PAGE);
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
/// Print the page header
if (!empty($edit) && $PAGE->user_allowed_editing()) {
if ($edit == 'on') {
$USER->editing = true;
} else if ($edit == 'off') {
$USER->editing = false;
}
}
$strdata = get_string('modulenameplural','data');
$PAGE->print_header($course->shortname.': %fullname%');
echo '<table id="layout-table"><tr>';
if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
echo '</td>';
}
echo '<td id="middle-column">';
print_header_simple($data->name, "", "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name", "", "", true, "", navmenu($course));
print_heading(format_string($data->name));
@ -224,7 +196,6 @@
}
/// Finish the page
echo '</td></tr></table>';
print_footer($course);

View File

@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2006011900;
$module->version = 2006011901;
$module->requires = 2005060223; // Requires this Moodle version
$module->cron = 60;

View File

@ -26,21 +26,18 @@
require_once('lib.php');
require_once($CFG->libdir.'/blocklib.php');
define('PAGE_DATA_VIEW', 'mod-data-view');
define('PAGE_DATA', PAGE_DATA_VIEW);
require_once('pagelib.php');
require_login();
page_map_class(PAGE_DATA_VIEW, 'page_data');
$DEFINEDPAGES = array(PAGE_DATA_VIEW,);
$id = optional_param('id', 0, PARAM_INT); // course module id
$d = optional_param('d', 0, PARAM_INT); // database id
$search = optional_param('search','',PARAM_NOTAGS); //search string
$page = optional_param('page', 0, PARAM_INT); //offset of the current record
$rid = optional_param('rid', 0, PARAM_INT); //record id
$perpagemenu = optional_param('perpage1', 0, PARAM_INT); //value from drop down
$sort = optional_param('sort',0,PARAM_INT); //sort by field
$order = optional_param('order','ASC',PARAM_ALPHA); //sort order
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
@ -134,6 +131,9 @@
/// Print the browsing interface
if (optional_param('approved','0',PARAM_INT)) {
print_heading(get_string('recordapproved','data'));
}
/***************************
* code to delete a record *
***************************/
@ -194,37 +194,125 @@
*****************************/
$perpage = get_user_preferences('data_perpage', 10); //get default per page
$baseurl = 'view.php?d='.$data->id.'&amp;search='.$search.'&amp;';
$baseurl = 'view.php?d='.$data->id.'&amp;search='.s($search).'&amp;sort='.s($sort).'&amp;order='.s($order).'&amp;';
//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
$sqlo = 'SELECT COUNT(*) FROM '.$CFG->prefix
.'data_records WHERE id < '.$rid.' AND dataid='.$data->id;
$page = count_records_sql($sqlo);
$ridsql = 'AND r.id < '.$rid.' ';
} else {
$ridsql = '';
}
if ($search){ //if in search mode, only search text fields
if ($sort) { //supports (sort and search)
$sql = 'SELECT DISTINCT c.recordid, c.recordid FROM '.$CFG->prefix.'data_content c LEFT JOIN '
.$CFG->prefix.'data_fields f on c.fieldid = f.id WHERE f.dataid = '
.$data->id.' AND c.content LIKE "%'.$search.'%" ';
//first find the field that we are sorting
$sortfield = data_get_field(get_record('data_fields','id',$sort));
$sortcontent = $sortfield->get_sort_field();
$sqlcount = 'SELECT COUNT(DISTINCT c.recordid) FROM '.$CFG->prefix
.'data_content c LEFT JOIN '.$CFG->prefix
.'data_fields f on c.fieldid = f.id WHERE f.dataid = '
.$data->id.' AND c.content LIKE "%'.$search.'%" ';
}
else { //else get everything
///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.'
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.' ';
$sql = 'SELECT * FROM '.$CFG->prefix.'data_records WHERE dataid ='.$data->id.' ORDER BY id ASC ';
$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.'
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.'
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 '.$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 '.$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 '.$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.' '.$approvesql.' ORDER BY r.id '.$order.' ';
$sqlcount = 'SELECT COUNT(*) FROM '.$CFG->prefix
.'data_records WHERE dataid ='.$data->id.' ';
.'data_records r WHERE r.dataid ='.$data->id.' '.$approvesql.'ORDER BY r.id '.$order.' ';
$sqlindex = 'SELECT COUNT(*) FROM '.$CFG->prefix
.'data_records r WHERE r.dataid ='.$data->id.' '.$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, PERPAGE_SINGLE);
$sql = $sql . $limit;
$totalcount = count_records_sql($sqlcount);
if (!$records = get_records_sql($sql)){
@ -239,7 +327,7 @@
print_footer($course);
exit;
}
//print header for multi view
if ($perpage > 1){
@ -259,15 +347,14 @@
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);
data_print_template($records, $data, $search, $listmode, $sort, $page, $rid, $order);
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
if ($perpage > 1){
echo $data->listtemplatefooter; //print footer
}
data_print_preference_form($data, $perpage, $search);
data_print_preference_form($data, $perpage, $search, $sort, $order);
/// Finish the page