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 if ($id) { if (! $cm = get_record('course_modules', 'id', $id)) { error('Course Module ID was incorrect'); } if (! $course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } if (! $data = get_record('data', 'id', $cm->instance)) { error('Course module is incorrect'); } } else { if (! $data = get_record('data', 'id', $d)) { 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'); } } if (isteacher($course->id)) { if (!count_records('data_fields','dataid',$data->id)) { // Brand new database! redirect($CFG->wwwroot.'/mod/data/fields.php?d='.$data->id); // Redirect to field entry } } //set user preference if available if (isset($_POST['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); } $d = $data->id;//set this so tabs can work properly 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); if (!empty($edit) && $PAGE->user_allowed_editing()) { if ($edit == 'on') { $USER->editing = true; } else if ($edit == 'off') { $USER->editing = false; } } /// Print the page header $PAGE->print_header($course->shortname.': %fullname%'); echo '
'; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); echo ' | '; } echo '';
print_heading(format_string($data->name));
/// 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?id=$cm->id");
} else {
$currentgroup = 0;
}
if ($currentgroup) {
$groupselect = " AND groupid = '$currentgroup'";
$groupparam = "&groupid=$currentgroup";
} else {
$groupselect = "";
$groupparam = "";
}
/// Print the tabs
$currenttab = 'browse';
include('tabs.php');
/// Print the browsing interface
/***************************
* code to delete a record *
***************************/
if (($delete = optional_param('delete',0,PARAM_INT)) && confirm_sesskey()){
if (isteacheredit($course) or data_isowner($delete)){
if ($confirm = optional_param('confirm',0,PARAM_INT)){
//find all contents in this record?
if ($contents = get_records('data_content','recordid',$delete)){
//for each content, delete the file associated
foreach ($contents as $content){
$field = get_record('data_fields','id',$content->fieldid);
if ($g = data_get_field($field)){ //it is possible that the field is deleted by teacher
$g->delete_data_content_files($data->id, $delete, $content->content);
}
}
delete_records('data_records','id',$delete);
delete_records('data_content','recordid',$delete);
notify (get_string('recorddeleted','data'));
}
}
else { //prints annoying confirmation dialogue
$field = get_record('data_records','id',$delete);
print_simple_box_start('center', '60%');
echo ' ';
echo '';
echo ' ';
print_simple_box_end();
echo ' |