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 $newtype = optional_param('fieldmenu','',PARAM_ALPHA); //type of the new field //action specifies what action is performed when data is submitted $mode = optional_param('mode','',PARAM_ALPHA); $displayflag = ''; //str to print after an operation, 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 (!isteacheredit($course->id)){ error(get_string('noaccess','data')); } 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; } } $PAGE->print_header($course->shortname.': %fullname%'); echo '
| '; blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); echo ' | '; } echo '';
print_heading(format_string($data->name));
/************************************
* Data Processing *
***********************************/
switch($mode){
case 'add': ///add a new field
if (confirm_sesskey() and $field = data_submitted()){
$sql = 'SELECT * from '.$CFG->prefix.'data_fields WHERE name LIKE "'.$field->name.
'" AND dataid = '.$data->id;
if ($field->name and !get_record_sql($sql)){
$field->dataid = $data->id;
insert_record('data_fields', $field);
$displayflag = get_string('fieldadded','data');
}
else { //no duplicate names allowed in one database!
$displayflag = get_string('invalidfieldname','data');
}
}
break;
case 'delete': ///delete a field
if (confirm_sesskey()){
if ($confirm = optional_param('confirm', 0, PARAM_INT)){
delete_records('data_fields','id',$fid);
$displayflag = get_string('fielddeleted','data');
}
else { //prints annoying confirmation dialogue
$field = get_record('data_fields','id',$fid);
print_simple_box_start('center', '60%');
echo ' ';
echo '';
echo ' ';
print_simple_box_end();
echo ' |