Bunch of fixes including:
- separate browse / detail tabs - cleaner logic - proper sorting in all scenrios - settings stored in the sessions - better cleaner URLs
This commit is contained in:
@@ -14,14 +14,14 @@
|
||||
|
||||
//param needed for comment operations
|
||||
$mode = optional_param('mode','',PARAM_ALPHA);
|
||||
$recordid = optional_param('recordid','',PARAM_INT);
|
||||
$rid = optional_param('rid','',PARAM_INT);
|
||||
$commentid = optional_param('commentid','',PARAM_INT);
|
||||
$confirm = optional_param('confirm','',PARAM_INT);
|
||||
$commentcontent = optional_param('commentcontent','',PARAM_NOTAGS);
|
||||
$template = optional_param('template','',PARAM_ALPHA);
|
||||
|
||||
|
||||
if ((!$record = get_record('data_records','id',$recordid))) {
|
||||
if ((!$record = get_record('data_records','id',$rid))) {
|
||||
if (!$comment = get_record('data_comments','id',$commentid)) {
|
||||
error ('this record does not exist');
|
||||
} else {
|
||||
@@ -39,7 +39,7 @@
|
||||
$newcomment->userid = $USER->id;
|
||||
$newcomment->created = time();
|
||||
$newcomment->modified = time();
|
||||
if (($newcomment->content = $commentcontent) && ($newcomment->recordid = $recordid)) {
|
||||
if (($newcomment->content = $commentcontent) && ($newcomment->recordid = $rid)) {
|
||||
insert_record('data_comments',$newcomment);
|
||||
}
|
||||
redirect('view.php?d='.s($d).'&search='.s($search).'&sort='.s($sort).'&order='.s($order).'&group='.s($group).'&page='.s($page).'&rid='.s($rid), get_string("commentsaved", "data"));
|
||||
|
||||
+50
-62
@@ -564,10 +564,10 @@ function data_add_record($data, $groupid=0){
|
||||
*******************************************************************/
|
||||
function data_tags_check($dataid, $template){
|
||||
//first get all the possible tags
|
||||
$possiblefields = get_records('data_fields','dataid',$dataid);
|
||||
$fields = get_records('data_fields','dataid',$dataid);
|
||||
///then we generate strings to replace
|
||||
$tagsok = true; //let's be optimistic
|
||||
foreach ($possiblefields as $field){
|
||||
foreach ($fields as $field){
|
||||
$pattern="/\[\[".$field->name."\]\]/i";
|
||||
if (preg_match_all($pattern, $template, $dummy)>1){
|
||||
$tagsok = false;
|
||||
@@ -748,7 +748,7 @@ function data_user_complete($course, $user, $mod, $data) {
|
||||
|
||||
if ($records = get_records_sql($sql)){
|
||||
|
||||
data_print_template($records, $data, '', 'singletemplate');
|
||||
data_print_template('singletemplate', $records, $data);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -810,55 +810,54 @@ function data_get_coursemodule_info($coursemodule) {
|
||||
* @param string $template *
|
||||
* output null *
|
||||
************************************************************************/
|
||||
function data_print_template($records, $data, $search, $template, $sort, $page=0, $rid=0, $order='', $group='', $return=false){
|
||||
global $CFG, $course;
|
||||
|
||||
function data_print_template($template, $records, $data, $search='', $return=false){
|
||||
global $CFG;
|
||||
|
||||
static $fields = NULL;
|
||||
static $isteacher;
|
||||
|
||||
if (empty($fields)) {
|
||||
$fieldrecords = get_records('data_fields','dataid', $data->id);
|
||||
foreach ($fieldrecords as $fieldrecord) {
|
||||
$fields[]= data_get_field($fieldrecord, $data);
|
||||
}
|
||||
$isteacher = isteacher($data->course);
|
||||
}
|
||||
|
||||
foreach ($records as $record) { //only 1 record for single mode
|
||||
|
||||
//replacing tags
|
||||
/// Replacing tags
|
||||
$patterns = array();
|
||||
$replacement = array();
|
||||
if ($search || $sort){ //the ids are different for the 2 searches
|
||||
$record->id = $record->recordid;
|
||||
}
|
||||
|
||||
$possiblefields = get_records('data_fields','dataid',$data->id);
|
||||
|
||||
///then we generate strings to replace for normal tags
|
||||
foreach ($possiblefields as $ff) {
|
||||
$patterns[]='/\[\['.$ff->name.'\]\]/i';
|
||||
$field = data_get_field($ff, $data);
|
||||
/// Then we generate strings to replace for normal tags
|
||||
foreach ($fields as $field) {
|
||||
$patterns[]='/\[\['.$field->field->name.'\]\]/i';
|
||||
$replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
|
||||
}
|
||||
|
||||
$record = get_record('data_records','id',$record->id);
|
||||
///replacing special tags (##Edit##, ##Delete##, ##More##)
|
||||
|
||||
/// Replacing special tags (##Edit##, ##Delete##, ##More##)
|
||||
$patterns[]='/\#\#Edit\#\#/i';
|
||||
if (data_isowner($record->id) or isteacheredit($course->id)){
|
||||
$patterns[]='/\#\#Delete\#\#/i';
|
||||
if ($isteacher or data_isowner($record->id)) {
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/add.php?d='
|
||||
.$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.get_string('edit').'" /></a>';
|
||||
}else {
|
||||
$replacement[] = '';
|
||||
}
|
||||
|
||||
$patterns[]='/\#\#Delete\#\#/i';
|
||||
if (data_isowner($record->id) or isteacheredit($course->id)){
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
|
||||
.$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.get_string('delete').'" /></a>';
|
||||
}else {
|
||||
} else {
|
||||
$replacement[] = '';
|
||||
$replacement[] = '';
|
||||
}
|
||||
$patterns[]='/\#\#More\#\#/i';
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id.'&search='.$search.'&sort='.$sort.'&order='.$order.'&group='.$group.'&"><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.'&rid='.$record->id.'"><img src="'.$CFG->pixpath.'/i/search.gif" height="11" width="11" border="0" alt="'.get_string('more').'" /></a>';
|
||||
|
||||
$patterns[]='/\#\#MoreURL\#\#/i';
|
||||
$replacement[] = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id.'&search='.$search.'&sort='.$sort.'&order='.$order.'&group='.$group;
|
||||
$replacement[] = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id;
|
||||
|
||||
|
||||
$patterns[]='/\#\#Approve\#\#/i';
|
||||
if (isteacher($course->id) && ($data->approval) && (!$record->approved)){
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&search='.$search.'&sort='.$sort.'&order='.$order.'&group='.$group.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/show.gif" height="11" width="11" border="0" alt="'.get_string('approve').'" /></a>';
|
||||
if ($isteacher && ($data->approval) && (!$record->approved)){
|
||||
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/show.gif" height="11" width="11" border="0" alt="'.get_string('approve').'" /></a>';
|
||||
} else {
|
||||
$replacement[] = '';
|
||||
}
|
||||
@@ -866,7 +865,7 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
|
||||
$patterns[]='/\#\#Comment\#\#/i';
|
||||
if (($template == 'listtemplate') && ($data->comments)) {
|
||||
$comments = count_records('data_comments','recordid',$record->id);
|
||||
$replacement[] = '<a href="comment.php?recordid='.$record->id.'&d='.$data->id.'&search='.$search.'&sort='.$sort.'&order='.$order.'&group='.$group.'&page='.$page.'">'.$comments.' '.get_string('comment','data').'</a>';
|
||||
$replacement[] = '<a href="comment.php?d='.$data->id.'&rid='.$record->id.'">'.$comments.' '.get_string('comment','data').'</a>';
|
||||
} else {
|
||||
$replacement[] = '';
|
||||
}
|
||||
@@ -890,7 +889,7 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
|
||||
* Printing Ratings Form *
|
||||
*********************************/
|
||||
if (($template == 'singletemplate') && ($data->comments)) { //prints ratings options
|
||||
data_print_comments($data, $record, $search, $template, $sort, $page, $rid, $order, $group);
|
||||
data_print_comments($data, $record);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -912,7 +911,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
|
||||
echo get_string('pagesize','data').':';
|
||||
$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');
|
||||
choose_from_menu($pagesizes, 'perpage', $perpage, 'choose', '', '0');
|
||||
echo ' '.get_string('search').': <input type="text" size="16" name="search" value="'.s($search).'" />';
|
||||
echo ' '.get_string('sortby').':';
|
||||
//foreach field, print the option
|
||||
@@ -940,26 +939,26 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
|
||||
echo '</select>';
|
||||
//print ASC or DESC
|
||||
echo '<input type="submit" value="'.get_string('savesettings','data').'" />';
|
||||
echo '<input type="hidden" name="updatepref" value="1" />';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function data_print_ratings($data, $record) {
|
||||
global $USER, $course;
|
||||
global $USER;
|
||||
|
||||
$ratingsmenuused = false;
|
||||
if ($data->ratings and !empty($USER->id)) {
|
||||
if ($ratings->scale = make_grades_menu($data->scale)) {
|
||||
$ratings->assesspublic = $data->assesspublic;
|
||||
$ratings->allow = (($data->assessed != 2 or isteacher($course->id)) && !isguest());
|
||||
$ratings->allow = (($data->assessed != 2 or isteacher($data->course)) && !isguest());
|
||||
if ($ratings->allow) {
|
||||
echo '<p /><form name="form" method="post" action="rate.php">';
|
||||
echo '<div class="ratings" align="center">';
|
||||
$useratings = true;
|
||||
|
||||
if ($useratings) {
|
||||
if ((isteacher($course->id) or $ratings->assesspublic) and !data_isowner($record->id)) {
|
||||
data_print_ratings_mean($record->id, $ratings->scale, isteacher($course->id));
|
||||
if ((isteacher($data->course) or $ratings->assesspublic) and !data_isowner($record->id)) {
|
||||
data_print_ratings_mean($record->id, $ratings->scale, isteacher($data->course));
|
||||
if (!empty($ratings->allow)) {
|
||||
echo ' ';
|
||||
data_print_rating_menu($record->id, $USER->id, $ratings->scale);
|
||||
@@ -977,12 +976,12 @@ function data_print_ratings($data, $record) {
|
||||
|
||||
if ($data->scale < 0) {
|
||||
if ($scale = get_record("scale", "id", abs($data->scale))) {
|
||||
print_scale_menu_helpbutton($course->id, $scale );
|
||||
print_scale_menu_helpbutton($data->course, $scale );
|
||||
}
|
||||
}
|
||||
|
||||
if ($ratingsmenuused) {
|
||||
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
|
||||
echo '<input type="hidden" name="id" value="'.$data->course.'" />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo "<input type=\"submit\" value=\"".get_string("sendinratings", "data")."\" />";
|
||||
}
|
||||
@@ -1088,7 +1087,7 @@ function data_get_ratings($recordid, $sort="u.firstname ASC") {
|
||||
|
||||
|
||||
//prints all comments + a text box for adding additional comment
|
||||
function data_print_comments($data, $record , $search, $template, $sort, $page=0, $rid=0, $order='', $group='') {
|
||||
function data_print_comments($data, $record) {
|
||||
//foreach comment, print it!
|
||||
//(with links to edit, remove etc, but no reply!!!!!)
|
||||
if ($comments = get_records('data_comments','recordid',$record->id)) {
|
||||
@@ -1100,16 +1099,8 @@ function data_print_comments($data, $record , $search, $template, $sort, $page=0
|
||||
echo '<p /><div align="center"><form method="post" action="comment.php">';
|
||||
echo '<input type="hidden" name="mode" value="add" />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<input type="hidden" name="recordid" value="'.$record->id.'" />';
|
||||
echo '<input type="hidden" name="d" value="'.$data->id.'" />';
|
||||
echo '<input type="hidden" name="search" value="'.$search.'" />';
|
||||
echo '<input type="hidden" name="rid" value="'.$rid.'" />';
|
||||
echo '<input type="hidden" name="sort" value="'.$sort.'" />';
|
||||
echo '<input type="hidden" name="order" value="'.$order.'" />';
|
||||
echo '<input type="hidden" name="group" value="'.$group.'" />';
|
||||
echo '<input type="hidden" name="page" value="'.$page.'" />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
|
||||
echo '<input type="hidden" name="rid" value="'.$record->id.'" />';
|
||||
|
||||
echo '<textarea name="commentcontent"></textarea>';
|
||||
echo '<br><input type="submit" value="'.get_string('addcomment','data').'" />';
|
||||
echo '</form></div>';
|
||||
@@ -1118,7 +1109,7 @@ function data_print_comments($data, $record , $search, $template, $sort, $page=0
|
||||
//prints a single comment entry
|
||||
function data_print_comment($data, $commentid) {
|
||||
|
||||
global $USER, $CFG, $course;
|
||||
global $USER, $CFG;
|
||||
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
@@ -1129,20 +1120,20 @@ function data_print_comment($data, $commentid) {
|
||||
echo '<div align="center"><table cellspacing="0" width ="50%" class="forumpost">';
|
||||
|
||||
echo '<tr class="header"><td class="picture left">';
|
||||
print_user_picture($comment->userid, $course->id, $user->picture);
|
||||
print_user_picture($comment->userid, $data->course, $user->picture);
|
||||
echo '</td>';
|
||||
|
||||
echo '<td class="topic starter" align="left"><div class="author">';
|
||||
$fullname = fullname($user, isteacher($comment->userid));
|
||||
$by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
||||
$user->id.'&course='.$course->id.'">'.$fullname.'</a>';
|
||||
$user->id.'&course='.$data->course.'">'.$fullname.'</a>';
|
||||
$by->date = userdate($comment->modified);
|
||||
print_string('bynameondate', 'data', $by);
|
||||
echo '</div></td></tr>';
|
||||
|
||||
echo '<tr><td class="left side">';
|
||||
if ($group = user_group($course->id, $comment->userid)) {
|
||||
print_group_picture($group, $course->id, false, false, true);
|
||||
if ($group = user_group($data->course, $comment->userid)) {
|
||||
print_group_picture($group, $data->course, false, false, true);
|
||||
} else {
|
||||
echo ' ';
|
||||
}
|
||||
@@ -1158,12 +1149,9 @@ function data_print_comment($data, $commentid) {
|
||||
/// Commands
|
||||
|
||||
echo '<div class="commands">';
|
||||
if (data_isowner($comment->recordid) or isteacher($course->id)) {
|
||||
if (data_isowner($comment->recordid) or isteacher($data->course)) {
|
||||
echo '<a href="'.$CFG->wwwroot.'/mod/data/comment.php?d='.$data->id.'&mode=edit&commentid='.$comment->id.'">'.$stredit.'</a>';
|
||||
}
|
||||
|
||||
if (data_isowner($comment->recordid) or isteacher($course->id)) {
|
||||
echo '| <a href="'.$CFG->wwwroot.'/mod/data/comment.php?d='.$data->id.'&mode=delete&commentid='.$comment->id.'">'.$strdelete.'</a>';
|
||||
echo '| <a href="'.$CFG->wwwroot.'/mod/data/comment.php?d='.$data->id.'&mode=delete&commentid='.$comment->id.'">'.$strdelete.'</a>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
+8
-20
@@ -32,12 +32,17 @@
|
||||
$inactive = NULL;
|
||||
$row = array();
|
||||
|
||||
$row[] = new tabobject('browse', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id, get_string('browse','data'), '', true);
|
||||
$row[] = new tabobject('list', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id, get_string('browse','data'), '', true);
|
||||
if (isset($record)) {
|
||||
$row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id, get_string('detail','data'), '', true);
|
||||
} else {
|
||||
$row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&mode=single', get_string('detail','data'), '', true);
|
||||
}
|
||||
if (isteacher($course->id) or ($data->participants == DATA_STUDENTS_ONLY) or ($data->participants == DATA_TEACHERS_AND_STUDENTS)){
|
||||
$row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/add.php?d='.$data->id, get_string('add','data'), '', true);
|
||||
}
|
||||
if (isteacher($course->id)) {
|
||||
if ($currenttab == 'browse') {
|
||||
if ($currenttab == 'list') {
|
||||
if (get_user_preferences('data_perpage') == 1) {
|
||||
$defaultemplate = 'singletemplate';
|
||||
} else {
|
||||
@@ -64,7 +69,7 @@
|
||||
$row = array();
|
||||
$currenttab ='';
|
||||
foreach ($templatelist as $template) {
|
||||
$row[] = new tabobject($template, "templates.php?d=$d&mode=$template",
|
||||
$row[] = new tabobject($template, "templates.php?d=$data->id&mode=$template",
|
||||
get_string("$template", "data"));
|
||||
if ($template == $mode) {
|
||||
$currenttab = $template;
|
||||
@@ -72,23 +77,6 @@
|
||||
}
|
||||
$tabs[] = $row;
|
||||
}
|
||||
/*
|
||||
if ($currenttab == 'browse' and isset($mode)) {
|
||||
$inactive[] = 'browse';
|
||||
$viewlist = array ('singletemplate', 'listtemplate'); // Standard reports we want to show first
|
||||
|
||||
$row = array();
|
||||
$currenttab ='';
|
||||
foreach ($viewlist as $view) {
|
||||
$row[] = new tabobject($view, "view.php?d=$d&mode=$view",
|
||||
get_string("$view", "data"));
|
||||
if ($view == $mode) {
|
||||
$currenttab = $view;
|
||||
}
|
||||
}
|
||||
$tabs[] = $row;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/// Print out the tabs and continue!
|
||||
|
||||
+200
-204
@@ -30,18 +30,18 @@
|
||||
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
|
||||
$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
|
||||
$rid = optional_param('rid', 0, PARAM_INT); //record id
|
||||
|
||||
$mode = optional_param('mode', '', PARAM_ALPHA); // Force the browse mode ('single')
|
||||
|
||||
|
||||
/// 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
|
||||
$perpagemenu = optional_param('perpage1', 0, PARAM_INT); //value from drop down
|
||||
$sort = optional_param('sort',-1,PARAM_INT); //sort by field
|
||||
$order = optional_param('order','ASC',PARAM_ALPHA); //sort order
|
||||
$group = optional_param('group','0',PARAM_INT); //groupid
|
||||
|
||||
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_record('course_modules', 'id', $id)) {
|
||||
@@ -53,8 +53,22 @@
|
||||
if (! $data = get_record('data', 'id', $cm->instance)) {
|
||||
error('Course module is incorrect');
|
||||
}
|
||||
$record = NULL;
|
||||
|
||||
} else {
|
||||
} else if ($rid) {
|
||||
if (! $record = get_record('data_records', 'id', $rid)) {
|
||||
error('Record ID is incorrect');
|
||||
}
|
||||
if (! $data = get_record('data', 'id', $record->dataid)) {
|
||||
error('Data ID is incorrect');
|
||||
}
|
||||
if (! $course = get_record('course', 'id', $data->course)) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
} else { // We must have $d
|
||||
if (! $data = get_record('data', 'id', $d)) {
|
||||
error('Data ID is incorrect');
|
||||
}
|
||||
@@ -64,33 +78,50 @@
|
||||
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
$record = NULL;
|
||||
}
|
||||
|
||||
require_course_login($course, true, $cm);
|
||||
|
||||
/// If we have an empty Database then redirect because this page is useless without data
|
||||
if (isteacher($course->id)) {
|
||||
if (!record_exists('data_fields','dataid',$data->id)) { // Brand new database!
|
||||
redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id); // Redirect to field entry
|
||||
}
|
||||
}
|
||||
|
||||
/// If we haven't set a sort field use the default sort field
|
||||
if ($sort == -1) {
|
||||
$sort = $data->defaultsort;
|
||||
$order = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
|
||||
|
||||
/// Check further parameters that set browsing preferences
|
||||
if (!isset($SESSION->dataprefs)) {
|
||||
$SESSION->dataprefs = array();
|
||||
}
|
||||
|
||||
//set user preference if available
|
||||
if (isset($_GET['updatepref'])){
|
||||
|
||||
if (!$perpage = $perpagemenu){ //if menu not in use, use the text field
|
||||
$perpage = (int)optional_param('perpage',10);
|
||||
}
|
||||
$perpage = ($perpage <= 0) ? 10 : $perpage ;
|
||||
set_user_preference('data_perpage', $perpage);
|
||||
if (!isset($SESSION->dataprefs[$data->id])) {
|
||||
$SESSION->dataprefs[$data->id] = array();
|
||||
$SESSION->dataprefs[$data->id]['search'] = '';
|
||||
$SESSION->dataprefs[$data->id]['sort'] = $data->defaultsort;
|
||||
$SESSION->dataprefs[$data->id]['order'] = ($data->defaultsortdir == 0) ? 'ASC' : 'DESC';
|
||||
}
|
||||
|
||||
$d = $data->id;//set this so tabs can work properly
|
||||
$search = optional_param('search', $SESSION->dataprefs[$data->id]['search'], PARAM_NOTAGS);
|
||||
$SESSION->dataprefs[$data->id]['search'] = $search; // Make it sticky
|
||||
|
||||
$sort = optional_param('sort', $SESSION->dataprefs[$data->id]['sort'], PARAM_INT);
|
||||
$SESSION->dataprefs[$data->id]['sort'] = $sort; // Make it sticky
|
||||
|
||||
$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);
|
||||
|
||||
if ($perpage < 2) {
|
||||
$perpage = 2;
|
||||
}
|
||||
if ($perpage != $oldperpage) {
|
||||
set_user_preference('data_perpage_'.$data->id, $perpage);
|
||||
}
|
||||
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
|
||||
add_to_log($course->id, 'data', 'view', "view.php?id=$cm->id", $data->id, $cm->id);
|
||||
|
||||
@@ -121,7 +152,8 @@
|
||||
|
||||
echo '<table id="layout-table"><tr>';
|
||||
|
||||
if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
|
||||
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>';
|
||||
@@ -139,7 +171,7 @@
|
||||
echo '<div style="clear:both;"></div>';
|
||||
}
|
||||
|
||||
if ($data->intro and empty($sort) and empty($search) and empty($page) and empty($rid)) {
|
||||
if ($data->intro and empty($sort) and empty($search) and empty($page) and empty($record)) {
|
||||
print_simple_box(format_text($data->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
|
||||
}
|
||||
|
||||
@@ -152,69 +184,60 @@
|
||||
$currentgroup = 0;
|
||||
}
|
||||
|
||||
if ($currentgroup) {
|
||||
$groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
|
||||
$groupparam = "&groupid=$currentgroup";
|
||||
} else {
|
||||
$groupselect = "";
|
||||
$groupparam = "";
|
||||
}
|
||||
|
||||
/// Print the tabs
|
||||
|
||||
$currenttab = 'browse';
|
||||
if ($record or $mode == 'single') {
|
||||
$currenttab = 'single';
|
||||
} else {
|
||||
$currenttab = 'list';
|
||||
}
|
||||
include('tabs.php');
|
||||
|
||||
$perpage = get_user_preferences('data_perpage', 10); //get default per page
|
||||
|
||||
/// 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;
|
||||
if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
|
||||
if ($approverecord->dataid == $data->id) { // Must be from this database
|
||||
$newrecord->id = $approverecord->id;
|
||||
$newrecord->approved = 1;
|
||||
if (update_record('data_records', $newrecord)) {
|
||||
notify(get_string('recordapproved','data'), 'notifysuccess');
|
||||
}
|
||||
if ($perpage == 1) {
|
||||
$rid = $approve;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete any requested records
|
||||
|
||||
if ($delete && confirm_sesskey()) {
|
||||
if (isteacher($course->id) 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);
|
||||
if ($delete && confirm_sesskey() && (isteacher($course->id) or data_isowner($delete))) {
|
||||
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
|
||||
if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
|
||||
if ($deleterecord->dataid == $data->id) { // Must be from this database
|
||||
if ($contents = get_records('data_content','recordid', $deleterecord->id)) {
|
||||
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', $deleterecord->id);
|
||||
delete_records('data_records','id', $deleterecord->id);
|
||||
|
||||
add_to_log($course->id, 'data', 'record delete', "view.php?id=$cm->id", $data->id, $cm->id);
|
||||
|
||||
notify(get_string('recorddeleted','data'), 'notifysuccess');
|
||||
}
|
||||
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'), 'notifysuccess');
|
||||
|
||||
if ($perpage == 1) {
|
||||
$rid = $delete;
|
||||
}
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,174 +249,147 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($rid) { //set per page to 1, if looking for 1 specific record
|
||||
set_user_preference('data_perpage', DATA_PERPAGE_SINGLE);
|
||||
}
|
||||
|
||||
$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.'&';
|
||||
|
||||
|
||||
/// Calculate all the records we're going to show.
|
||||
/// We need to examine the whole dataset to produce the correct paging
|
||||
|
||||
if ((!isteacher($course->id)) && ($data->approval)) {
|
||||
if (isloggedin()) {
|
||||
$approvesql = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
|
||||
$approveselect = ' AND (r.approved=1 OR r.userid='.$USER->id.') ';
|
||||
} else {
|
||||
$approvesql = ' AND r.approved=1 ';
|
||||
$approveselect = ' AND r.approved=1 ';
|
||||
}
|
||||
} else {
|
||||
$approvesql = '';
|
||||
$approveselect = ' ';
|
||||
}
|
||||
|
||||
if ($rid){ //only used for single mode, but rid should not appear in multi view anyway
|
||||
$ridsql = 'AND r.id < '.$rid.' ';
|
||||
|
||||
if ($currentgroup) {
|
||||
$groupselect = " AND (r.groupid = '$currentgroup' OR r.groupid = 0)";
|
||||
} else {
|
||||
$ridsql = '';
|
||||
$groupselect = ' ';
|
||||
}
|
||||
|
||||
if ($sort) { //supports (sort and search)
|
||||
//first find the field that we are sorting
|
||||
|
||||
/// Find the field we are sorting on
|
||||
if ($sort) {
|
||||
$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;
|
||||
$what = ' DISTINCT r.id, r.approved ';
|
||||
$count = ' COUNT(DISTINCT c.recordid) ';
|
||||
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1 ';
|
||||
$where = 'WHERE c.recordid = r.id
|
||||
AND c.fieldid = '.$sort.'
|
||||
AND r.dataid = '.$data->id.'
|
||||
AND c1.recordid = r.id ';
|
||||
$sortorder = ' 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;
|
||||
|
||||
} else if ($search){ //search only, no sort. if in search mode, only search text fields
|
||||
} else if ($search) {
|
||||
$what = ' DISTINCT r.id, r.approved ';
|
||||
$count = ' COUNT(DISTINCT c.recordid) ';
|
||||
$tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r ';
|
||||
$where = 'WHERE c.recordid = r.id
|
||||
AND r.dataid = '.$data->id;
|
||||
$sortorder = ' ORDER BY r.id ';
|
||||
|
||||
$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.'%"';
|
||||
|
||||
$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.'%"';
|
||||
|
||||
} 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(r.id) FROM '.$CFG->prefix
|
||||
.'data_records r WHERE r.dataid ='.$data->id.' '.$groupselect.' '.$approvesql;
|
||||
|
||||
$sqlindex = 'SELECT COUNT(r.id) FROM '.$CFG->prefix
|
||||
.'data_records r WHERE r.dataid ='.$data->id.' '.$groupselect.' '.$ridsql.' '.$approvesql;
|
||||
} else {
|
||||
$what = ' DISTINCT r.id, r.approved ';
|
||||
$count = ' COUNT(r.id) ';
|
||||
$tables = $CFG->prefix.'data_records r ';
|
||||
$where = 'WHERE r.dataid = '.$data->id;
|
||||
$sortorder = ' ORDER BY r.id ';
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/// Restrict by a search if we have one
|
||||
|
||||
if ($search) {
|
||||
$searchselect = ' AND (c.content LIKE "%'.$search.'%") ';
|
||||
} else {
|
||||
$searchselect = ' ';
|
||||
}
|
||||
|
||||
/// To actually fetch the records
|
||||
|
||||
$fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
|
||||
|
||||
$sqlselect = 'SELECT '.$what.$fromsql.$sortorder;
|
||||
|
||||
$sqlcount = 'SELECT '.$count.$fromsql; // Total number of records
|
||||
|
||||
/// Work out the paging numbers
|
||||
|
||||
$totalcount = count_records_sql($sqlcount);
|
||||
|
||||
if (!$records = get_records_sql($sql)){
|
||||
if ($record) { // We need to just show one, so where is it in context?
|
||||
$nowperpage = 1;
|
||||
$mode = 'single';
|
||||
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 c.$sortcontent < '$content' ";
|
||||
} else {
|
||||
$lessthan = " AND c.$sortcontent > '$content' ";
|
||||
}
|
||||
} 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);
|
||||
|
||||
} else if ($mode == 'single') { // We rely on ambient $page settings
|
||||
$nowperpage = 1;
|
||||
|
||||
} else {
|
||||
$nowperpage = $perpage;
|
||||
}
|
||||
|
||||
/// Get the actual records
|
||||
|
||||
$limit = sql_paging_limit($page * $nowperpage, $nowperpage);
|
||||
$records = get_records_sql($sqlselect.$limit);
|
||||
|
||||
if (empty($records)) { // Nothing to show!
|
||||
if ($search){
|
||||
notify(get_string('nomatch','data'));
|
||||
} else {
|
||||
notify(get_string('norecords','data'));
|
||||
}
|
||||
|
||||
data_print_preference_form($data, $perpage, $search);
|
||||
echo '</td></tr></table>';
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
|
||||
/// Print header for list view, and paging bar
|
||||
if ($perpage > 1) {
|
||||
$listmode = 'listtemplate';
|
||||
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
|
||||
echo $data->listtemplateheader;
|
||||
if (empty($data->listtemplate)){
|
||||
notify(get_string('nolisttemplate','data'));
|
||||
} else { // We have some records to print
|
||||
|
||||
if ($mode == 'single') { // Single template
|
||||
$baseurl = 'view.php?d='.$data->id.'&mode=single&';
|
||||
|
||||
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
||||
|
||||
if (empty($data->singletemplate)){
|
||||
notify(get_string('nosingletemplate','data'));
|
||||
}
|
||||
|
||||
data_print_template('singletemplate', $records, $data, $search);
|
||||
|
||||
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
||||
|
||||
} else { // List template
|
||||
$baseurl = 'view.php?d='.$data->id.'&';
|
||||
|
||||
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
||||
|
||||
if (empty($data->listtemplate)){
|
||||
notify(get_string('nolisttemplate','data'));
|
||||
}
|
||||
echo $data->listtemplateheader;
|
||||
data_print_template('listtemplate', $records, $data, $search);
|
||||
echo $data->listtemplatefooter;
|
||||
|
||||
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
|
||||
}
|
||||
} else {
|
||||
$listmode = 'singletemplate';
|
||||
if (empty($data->singletemplate)){
|
||||
notify(get_string('nosingletemplate','data'));
|
||||
}
|
||||
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
|
||||
}
|
||||
|
||||
|
||||
/// Print the template, substituting in all our data
|
||||
data_print_template($records, $data, $search, $listmode, $sort, $page, $rid, $order, $currentgroup);
|
||||
|
||||
/// Print footer
|
||||
if ($perpage > 1){
|
||||
echo $data->listtemplatefooter;
|
||||
}
|
||||
|
||||
print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page');
|
||||
|
||||
data_print_preference_form($data, $perpage, $search, $sort, $order);
|
||||
|
||||
print_footer($course);
|
||||
|
||||
print_footer($course);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user