You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
7.9 KiB
181 lines
7.9 KiB
15 years ago
|
<?PHP
|
||
|
|
||
|
require_once('../../config.php');
|
||
|
require_once('locallib.php');
|
||
|
require_once('lib.php');
|
||
14 years ago
|
|
||
15 years ago
|
$id = required_param('id', PARAM_INT);
|
||
|
$submitsettings = optional_param('submitsettings');
|
||
|
$action = optional_param('action', '', PARAM_MULTILANG);
|
||
|
$stid = optional_param('st', 0, PARAM_INT);
|
||
|
|
||
|
if ($id) {
|
||
14 years ago
|
if (! $cm = $DB->get_record('course_modules', array('id'=> $id))) {
|
||
15 years ago
|
error('Course Module ID was incorrect');
|
||
|
}
|
||
14 years ago
|
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
|
||
15 years ago
|
error('Course is misconfigured');
|
||
|
}
|
||
14 years ago
|
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
|
||
15 years ago
|
error("Course module is incorrect");
|
||
|
}
|
||
|
}
|
||
14 years ago
|
//$attforblockrecord = get_record('attforblock','course',$course->id);
|
||
14 years ago
|
if (! $attforblockrecord = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
|
||
14 years ago
|
error("Course module is incorrect");
|
||
|
}
|
||
15 years ago
|
|
||
|
|
||
|
require_login($course->id);
|
||
|
|
||
14 years ago
|
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
|
||
15 years ago
|
error("No such user in this course");
|
||
|
}
|
||
|
|
||
|
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
|
||
|
print_error('badcontext');
|
||
|
}
|
||
|
|
||
|
require_capability('mod/attforblock:manageattendances', $context);
|
||
|
|
||
|
/// Print headers
|
||
|
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
|
||
|
$navlinks[] = array('name' => get_string('settings', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
|
||
|
$navigation = build_navigation($navlinks);
|
||
|
print_header("$course->shortname: ".$attforblock->name.' - '.get_string('settings','attforblock'), $course->fullname,
|
||
|
$navigation, "", "", true, " ", navmenu($course));
|
||
|
|
||
|
if (!empty($action)) {
|
||
|
switch ($action) {
|
||
|
case 'delete':
|
||
14 years ago
|
if (!$rec = $DB->get_record('attendance_statuses', array('attendanceid'=> $$attforblockrecord->id, 'id'=> $stid))) {
|
||
15 years ago
|
print_error('notfoundstatus', 'attforblock', "attsettings.php?id=$id");
|
||
|
}
|
||
14 years ago
|
if ($DB->count_records('attendance_log', array('statusid'=> $stid))) {
|
||
15 years ago
|
print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id");
|
||
|
}
|
||
|
|
||
|
$confirm = optional_param('confirm');
|
||
|
if (isset($confirm)) {
|
||
14 years ago
|
$DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $rec->id));
|
||
15 years ago
|
// delete_records('attendance_statuses', 'id', $rec->id);
|
||
|
redirect('attsettings.php?id='.$id, get_string('statusdeleted','attforblock'), 3);
|
||
|
}
|
||
|
print_heading(get_string('deletingstatus','attforblock').' :: ' .$course->fullname);
|
||
|
|
||
|
notice_yesno(get_string('deletecheckfull', '', get_string('variable', 'attforblock')).
|
||
|
'<br /><br />'.$rec->acronym.': '.
|
||
|
($rec->description ? $rec->description : get_string('nodescription', 'attforblock')),
|
||
|
"attsettings.php?id=$id&st=$stid&action=delete&confirm=1", $_SERVER['HTTP_REFERER']);
|
||
|
exit;
|
||
|
case 'show':
|
||
14 years ago
|
$DB->set_field('attendance_statuses', 'visible', 1, array('id' => $stid));
|
||
15 years ago
|
break;
|
||
|
case 'hide':
|
||
|
$students = get_users_by_capability($context, 'moodle/legacy:student', '', '', '', '', '', '', false);
|
||
|
$studlist = implode(',', array_keys($students));
|
||
14 years ago
|
if (!$DB->count_records_select('attendance_log', "studentid IN (?) AND statusid = ?", array( $studlist, $stid) )) {
|
||
|
$DB->set_field('attendance_statuses', 'visible', 0, array('id' => $stid));
|
||
15 years ago
|
} else {
|
||
|
print_error('canthidestatus', 'attforblock', "attsettings.php?id=$id");
|
||
|
}
|
||
|
break;
|
||
|
default: //Adding new status
|
||
|
$newacronym = optional_param('newacronym', '', PARAM_MULTILANG);
|
||
|
$newdescription = optional_param('newdescription', '', PARAM_MULTILANG);
|
||
|
$newgrade = optional_param('newgrade', 0, PARAM_INT);
|
||
|
if (!empty($newacronym) && !empty($newdescription)) {
|
||
|
unset($rec);
|
||
|
$rec->courseid = $course->id;
|
||
14 years ago
|
$rec->attendanceid = $attforblock->id;
|
||
15 years ago
|
$rec->acronym = $newacronym;
|
||
|
$rec->description = $newdescription;
|
||
|
$rec->grade = $newgrade;
|
||
14 years ago
|
$DB->insert_record('attendance_statuses', $rec);
|
||
15 years ago
|
add_to_log($course->id, 'attendance', 'setting added', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
|
||
|
} else {
|
||
|
print_error('cantaddstatus', 'attforblock', "attsettings.php?id=$id");
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
show_tabs($cm, $context, 'settings');
|
||
|
|
||
|
if ($submitsettings) {
|
||
|
config_save(); //////////////////////////////
|
||
|
notice(get_string('variablesupdated','attforblock'), 'attsettings.php?id='.$id);
|
||
|
}
|
||
|
|
||
|
$i = 1;
|
||
|
$table->width = '100%';
|
||
|
//$table->tablealign = 'center';
|
||
|
$table->head = array('#',
|
||
|
get_string('acronym','attforblock'),
|
||
|
get_string('description'),
|
||
|
get_string('grade'),
|
||
|
get_string('action'));
|
||
|
$table->align = array('center', 'center', 'center', 'center', 'center', 'center');
|
||
|
//$table->size = array('1px', '1px', '*', '1px', '1px', '1px');
|
||
14 years ago
|
$statuses = get_statuses($attforblockrecord->id, false);
|
||
15 years ago
|
$deltitle = get_string('delete');
|
||
|
foreach($statuses as $st)
|
||
|
{
|
||
|
$table->data[$i][] = $i;
|
||
|
// $table->data[$i][] = $st->status;
|
||
|
$table->data[$i][] = '<input type="text" name="acronym['.$st->id.']" size="2" maxlength="2" value="'.$st->acronym.'" />';
|
||
|
$table->data[$i][] = '<input type="text" name="description['.$st->id.']" size="30" maxlength="30" value="'.$st->description.'" />';
|
||
|
$table->data[$i][] = '<input type="text" name="grade['.$st->id.']" size="4" maxlength="4" value="'.$st->grade.'" />';
|
||
|
|
||
|
$action = $st->visible ? 'hide' : 'show';
|
||
|
$titlevis = get_string($action);
|
||
|
$deleteact = '';
|
||
14 years ago
|
if (!$DB->count_records('attendance_log', array('statusid'=> $st->id))) {
|
||
15 years ago
|
$deleteact = "<a title=\"$deltitle\" href=\"attsettings.php?id=$cm->id&st={$st->id}&action=delete\">".
|
||
|
"<img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"$deltitle\" /></a> ";
|
||
|
}
|
||
|
$table->data[$i][] = "<a title=\"$titlevis\" href=\"attsettings.php?id=$cm->id&st={$st->id}&action=$action\">".
|
||
|
"<img src=\"{$CFG->pixpath}/t/{$action}.gif\" alt=\"$titlevis\" /></a> ".
|
||
|
$deleteact;
|
||
|
$i++;
|
||
|
}
|
||
|
$new_row = array('*',
|
||
|
'<input type="text" name="newacronym" size="2" maxlength="2" value="" />',
|
||
|
'<input type="text" name="newdescription" size="30" maxlength="30" value="" />',
|
||
|
'<input type="text" name="newgrade" size="4" maxlength="4" value="" />',
|
||
|
'<input type="submit" name="action" value="'.get_string('add', 'attforblock').'">'
|
||
|
);
|
||
|
$table->data[$i] = $new_row;
|
||
|
|
||
|
echo '<div align="center"><div class="generalbox boxwidthwide">';
|
||
|
echo '<form aname="gsess" method="post" action="attsettings.php" onSubmit="return validateSession()">';
|
||
|
echo '<h1 class="main help">'.get_string('myvariables','attforblock').helpbutton ('myvariables', get_string('myvariables','attforblock'), 'attforblock', true, false, '', true).'</h1>';
|
||
|
print_table($table);
|
||
|
echo '<input type="hidden" name="id" value="'.$id.'"><br />';
|
||
|
echo '<input type="submit" name="submitsettings" value="'.get_string("update",'attforblock').'">';
|
||
|
echo '</form></div></div>';
|
||
|
|
||
|
print_footer($course);
|
||
|
|
||
|
|
||
|
function config_save()
|
||
|
{
|
||
14 years ago
|
global $course, $user, $attforblockrecord, $DB;
|
||
15 years ago
|
|
||
|
$acronym = required_param('acronym');
|
||
|
$description = required_param('description');
|
||
|
$grade = required_param('grade',PARAM_INT);
|
||
|
|
||
|
foreach ($acronym as $id => $v) {
|
||
14 years ago
|
$rec = $DB->get_record('attendance_statuses', array('id'=> $id));
|
||
15 years ago
|
$rec->acronym = $acronym[$id];
|
||
|
$rec->description = $description[$id];
|
||
|
$rec->grade = $grade[$id];
|
||
14 years ago
|
$DB->update_record('attendance_statuses', $rec);
|
||
15 years ago
|
add_to_log($course->id, 'attendance', 'settings updated', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
|
||
|
}
|
||
|
attforblock_update_grades($attforblockrecord);
|
||
|
}
|
||
|
|
||
|
?>
|