--- loncom/interface/slotrequest.pm 2009/03/20 10:05:08 1.90
+++ loncom/interface/slotrequest.pm 2012/06/09 15:41:26 1.113
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for requesting to have slots added to a students record
#
-# $Id: slotrequest.pm,v 1.90 2009/03/20 10:05:08 bisitz Exp $
+# $Id: slotrequest.pm,v 1.113 2012/06/09 15:41:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,8 +56,12 @@ sub fail {
}
sub start_page {
- my ($r,$title)=@_;
- $r->print(&Apache::loncommon::start_page($title));
+ my ($r,$title,$brcrum)=@_;
+ my $args;
+ if (ref($brcrum) eq 'ARRAY') {
+ $args = {bread_crumbs => $brcrum};
+ }
+ $r->print(&Apache::loncommon::start_page($title,undef,$args));
}
sub end_page {
@@ -133,22 +137,20 @@ sub check_for_reservation {
return 'error: Unable to determine current status';
}
my @got;
- foreach my $slot_name (sort {
- if (ref($slots{$a}) && ref($slots{$b})) {
- return $slots{$a}{'starttime'} <=> $slots{$b}{'starttime'}
- }
- if (ref($slots{$a})) { return -1;}
- if (ref($slots{$b})) { return 1;}
- return 0;
- } @slots) {
+ my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
+ foreach my $slot_name (@sorted_slots) {
next if (!defined($slots{$slot_name}) ||
!ref($slots{$slot_name}));
&Apache::lonxml::debug(time." $slot_name ".
$slots{$slot_name}->{'starttime'}." -- ".
- $slots{$slot_name}->{'startreserve'});
- if ($slots{$slot_name}->{'endtime'} > time &&
- $slots{$slot_name}->{'startreserve'} < time) {
- # between start of reservation times and end of slot
+ $slots{$slot_name}->{'startreserve'}." -- ".
+ $slots{$slot_name}->{'endreserve'});
+ if (($slots{$slot_name}->{'endtime'} > time) &&
+ ($slots{$slot_name}->{'startreserve'} < time) &&
+ ((!$slots{$slot_name}->{'endreserve'}) ||
+ ($slots{$slot_name}->{'endreserve'} > time))) {
+ # between start of reservation time and end of reservation time
+ # and before end of slot
if ($mode eq 'allslots') {
push(@got,$slot_name);
} else {
@@ -340,6 +342,10 @@ sub store_slot_parm {
&Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
'',$env{'user.name'},$env{'user.domain'},
$cnum,$cdom);
+ &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
+ 1,$env{'user.name'},$env{'user.domain'},
+ $env{'user.name'},$env{'user.domain'});
+
return;
}
@@ -533,7 +539,9 @@ sub release_reservation {
context => $env{'form.context'},
);
&Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
- 1,$uname,$udom,$cnum,$cdom);
+ 1,$uname,$udom,$cnum,$cdom);
+ &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
+ 1,$uname,$udom,$uname,$udom);
}
}
@@ -558,7 +566,11 @@ sub release_reservation {
if ($mgr eq 'F') {
$msg = &mt('Released Reservation for user: [_1]',"$uname:$udom");
} else {
- $msg = &mt('Released Reservation: [_1]',$description);
+ $msg = ''.&mt('Released reservation: [_1]',$description).'
';
+ my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ my $subject = &mt('Reservation change: [_1]',$description);
+ my $msgbody = &mt('Reservation released by [_1] for [_2].',$person,$description);
+ $msg .= &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'release');
}
return (1,$msg);
}
@@ -598,8 +610,13 @@ sub delete_slot {
sub return_link {
my ($r) = @_;
- $r->print('
'. - &mt('Return to last resource').'
'); + if (($env{'form.command'} eq 'manageresv') || ($env{'form.context'} eq 'usermanage')) { + $r->print(''.
+ &mt('Return to reservations'));
+ } else {
+ $r->print(' '.
+ &mt('Return to last resource').' '.&mt('Already have a reservation: [_1].',$description1).' '
- .&mt('You can either [_1]Change[_2] your reservation from [_3] to [_4] or'
- ,''
- ,''.$description1.''
- ,''.$description2.'')
- .' '.&mt('Reservation currently unchanged').' '.&mt('To complete the transaction you [_1]must confirm[_2] you want to [_3]process the change[_4] to [_5].'
+ ,'','','','',''.$description2.'')
+ .' '
+ .''
+ .(' 'x3)
+ .''
+ .' '.&mt('Already have a reservation: [_1].',$description1).'
'
+ .&mt('Or you can choose to [_1]make no change[_2] and continue[_2] with the reservation you already had: [_3].'
+ ,'','',''.$description1.'')
+ .'
'.&mt('Success: [_1]',$description).'
'); + $r->print(''.&mt('Successfully signed up: [_1]',$description).'
'); $retvalue = 1; + my $person = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + my $subject = &mt('Reservation change: [_1]',$description); + my $msgbody = &mt('Successful reservation by [_1] for [_2].',$person,$description); + my $msg = &slot_change_messaging($slot{'reservationmsg'},$subject,$msgbody,'reserve'); + if ($msg) { + $r->print($msg); + } } elsif ($reserved < 0) { $r->print(''.&mt('Already reserved: [_1]',$description).'
'); } @@ -698,7 +726,8 @@ $lt{'or'} STUFF if (!$inhibit_return_link) { - $r->print(&mt('or').'').&return_link($r); + $r->print(&mt('or').''); + &return_link($r); } else { $r->print(''); } @@ -731,6 +760,11 @@ sub allowed_slot { if ($slot->{'startreserve'} > time) { return 0; } + # reserve time ended + if (($slot->{'endreserve'}) && + ($slot->{'endreserve'} < time)) { + return 0; + } &Apache::lonxml::debug("$slot_name reserve good"); my $userallowed=0; @@ -805,10 +839,10 @@ sub get_description { } sub show_choices { - my ($r,$symb)=@_; + my ($r,$symb,$formname)=@_; my ($cnum,$cdom)=&get_course(); - my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum); + my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom); my $consumed_uniqueperiods = &get_consumed_uniqueperiods(\%slots); if (ref($consumed_uniqueperiods) eq 'HASH') { if (&Apache::lonnet::error(%$consumed_uniqueperiods)) { @@ -823,7 +857,7 @@ sub show_choices { ''); return; } - my $available; + my (@available,$output); &Apache::lonxml::debug("Checking Slots"); my @got_slots=&check_for_reservation($symb,'allslots'); if ($got_slots[0] =~ /^error: /) { @@ -832,20 +866,33 @@ sub show_choices { ''); return; } - $r->print('' - .&mt('Slot: [_1] has unknown status.',$description) - .' | |
$form | -$description | -$description | \n"; + if ($env{'form.command'} eq 'manageresv') { + $output .= ''; + } else { + $output .= &Apache::loncommon::end_data_table_row(); + } } - - if (!$available) { - $r->print('
'.&mt('No available times.'). - ' '. - &mt('Return to last resource').' |
Deleted slots: | @@ -1153,7 +1234,7 @@ sub show_table { my %name_cache; my $slotsort = sub { - if ($env{'form.order'}=~/^(type|description|endtime|startreserve|ip|symb|allowedsections|allowedusers)$/) { + if ($env{'form.order'}=~/^(type|description|endtime|startreserve|endreserve|ip|symb|allowedsections|allowedusers|reservationmsg)$/) { if (lc($slots{$a}->{$env{'form.order'}}) ne lc($slots{$b}->{$env{'form.order'}})) { return (lc($slots{$a}->{$env{'form.order'}}) @@ -1190,12 +1271,15 @@ sub show_table { if ($tmp =~ /^error: /) { undef(%consumed); } } + my %msgops = &slot_reservationmsg_options(); + foreach my $slot (sort $slotsort (keys(%slots))) { if (!&to_show($slot,$slots{$slot},$when, $env{'form.deleted'},$name_filter)) { next; } + my $reservemsg; if (defined($slots{$slot}->{'type'}) - && $slots{$slot}->{'type'} ne 'schedulable_student') { - #next; + && $slots{$slot}->{'type'} eq 'schedulable_student') { + $reservemsg = $msgops{$slots{$slot}->{'reservationmsg'}}; } my $description=&get_description($slot,$slots{$slot}); my ($id_count,$ids); @@ -1232,6 +1316,8 @@ sub show_table { &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):''); my $start_reserve=($slots{$slot}->{'startreserve'}? &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):''); + my $end_reserve=($slots{$slot}->{'endreserve'}? + &Apache::lonlocal::locallocaltime($slots{$slot}->{'endreserve'}):''); my $unique; if (ref($slots{$slot}{'uniqueperiod'})) { @@ -1288,26 +1374,39 @@ sub show_table { } my $proctors=join(', ',@proctors); + my %lt = &Apache::lonlocal::texthash ( + edit => 'Edit', + delete => 'Delete', + slotlog => 'History', + ); my $edit=(<<"EDITLINK"); -Edit +$lt{'edit'} EDITLINK my $delete=(<<"DELETELINK"); -Delete +$lt{'delete'} DELETELINK + my $showlog=(<<"LOGLINK"); +$lt{'slotlog'} +LOGLINK + my $remove_all=&remove_link($slot,'remove all').'$edit $delete | \n"); + "\n$edit $delete $showlog | \n"); if (exists($show{'name'})) { $colspan++;$r->print("$slot | "); } @@ -1326,6 +1425,12 @@ DELETELINK if (exists($show{'startreserve'})) { $colspan++;$r->print("$start_reserve | \n"); } + if (exists($show{'endreserve'})) { + $colspan++;$r->print("$end_reserve | \n"); + } + if (exists($show{'reservationmsg'})) { + $colspan++;$r->print("$reservemsg | \n"); + } if (exists($show{'secret'})) { $colspan++;$r->print("$slots{$slot}{'secret'} | \n"); } @@ -1366,30 +1471,755 @@ $row_end STUFF } } - $r->print('
'
+ .&mt('Instructors may use a reservation system to place restrictions on when and where assignments can be worked on.')
+ .'
'
+ .&mt('One example is for management of laboratory space, which is only available at certain times, and has a limited number of seats.')
+ .'
'. + &mt('Your reservation status for any such assignments is listed below:'). + '
'. + ''."\n"); + for (my $i=0; $i<$depth; $i++) { + $r->print(''); + } + my $result = ''. + ''.$title.''.(' ' x6).' | '; + my $hasaction; + if ($status == $resource->OPEN) { + if ($get_choices) { + $hasaction = 1; + } + } + if ($hasaction) { + $result .= ''.$msg.' | '. + ''.(' ' x6); + } else { + $result .= ' | '.$msg.' | '; + } + $r->print($result); + if ($hasaction) { + my $formname = 'manageres_'.$reservable; + &show_choices($r,$symb,$formname); + $r->print(''); + } + $r->print('
'. + &mt('Return to slot list').'
'); + return; + } + my $formname = 'reservationslog'; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my %slotlog=&Apache::lonnet::dump('nohist_slotreservationslog',$cdom,$cnum); + if ((keys(%slotlog))[0]=~/^error\:/) { undef(%slotlog); } + + my (%log,@allsymbs); + if (keys(%slotlog)) { + foreach my $key (keys(%slotlog)) { + if (ref($slotlog{$key}) eq 'HASH') { + if (ref($slotlog{$key}{'logentry'}) eq 'HASH') { + if ($slotlog{$key}{'logentry'}{'slot'} eq $env{'form.slotname'}) { + $log{$key} = $slotlog{$key}; + if ($slotlog{$key}{'logentry'}{'symb'} ne '') { + push(@allsymbs,$slotlog{$key}{'logentry'}{'symb'}); + } + } + } + } + } + } + + $r->print(''. + ''. + &mt('Return to slot list').'
'); + return; +} + +sub get_resource_title { + my ($symb,$titles,$maptitles) = @_; + my $title; + if ((ref($titles) eq 'HASH') && (ref($maptitles) eq 'HASH')) { + if (defined($titles->{$symb})) { + $title = $titles->{$symb}; + } else { + $title = &Apache::lonnet::gettitle($symb); + my $maptitle; + my ($mapurl) = &Apache::lonnet::decode_symb($symb); + if (defined($maptitles->{$mapurl})) { + $maptitle = $maptitles->{$mapurl}; + } else { + if ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) { + $maptitle=&mt('Main Course Documents'); + } else { + $maptitle=&Apache::lonnet::gettitle($mapurl); + } + $maptitles->{$mapurl} = $maptitle; + } + if ($maptitle ne '') { + $title .= ' '.&mt('(in [_1])',$maptitle); + } + $titles->{$symb} = $title; + } + } else { + $title = $symb; + } + return $title; +} + +sub reservationlog_contexts { + my ($crstype) = @_; + my %lt = &Apache::lonlocal::texthash ( + any => 'Any', + user => 'By student', + manage => 'Via Slot Manager', + parameter => 'Via Parameter Manager', + reserve => 'Made reservation', + release => 'Dropped reservation', + usermanage => 'By student', + ); + if ($crstype eq 'Community') { + $lt{'user'} = &mt('By member'); + $lt{'usermanage'} = $lt{'user'}; + } + return %lt; +} + +sub display_filter { + my ($formname,$cdom,$cnum,$curr,$version,$allsymbs) = @_; + my $nolink = 1; + my (%titles,%maptitles); + my $output = ''.
+ ''.&mt('Changes/page:').' '. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + ' | '; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'log_start_date', + $curr->{'log_start_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'log_end_date', + $curr->{'log_end_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $crstype = &Apache::loncommon::course_type(); + my %lt = &reservationlog_contexts($crstype); + $output .= ' | '.&mt('Window during which changes occurred:').
+ '
| '; + if (ref($allsymbs) eq 'ARRAY') { + $output .= ' | '.&mt('Resource').' '. + ' | '.
+ &mt('Context:').' | ';
+ } else {
+ $output .= ''.&mt('Action').' '. + ' | ';
+ }
+ $output .= '
'. + &mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.' + ,'2.9.0'); + if ($version) { + $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version); + } + $output .= '
'."\n"; - $result.=' '. - &mt('Specify a file containing the slot definitions.'). - ' |
'."\n";
- my $upfile_select=&Apache::loncommon::upfile_select_html();
- my $ignore=&mt('Ignore First Line');
- $result.=< - - -ENDUPFORM - $result.=' |
'.&mt('Created [quant,_1,slot]',$countdone)."\n".'
'); foreach my $error (@errors) { $r->print(''.$error.'
'."\n"); @@ -1648,6 +2507,32 @@ sub csv_upload_assign { return ''; } +sub slot_command_titles { + my %titles = ( + slotlog => 'Reservation Logs', + showslots => 'Manage Slots', + showresv => 'Reservation History', + manageresv => 'Manage Reservations', + uploadstart => 'Upload Slots File', + csvuploadmap => 'Upload Slots File', + csvuploadassign => 'Upload Slots File', + delete => 'Slot Deletion', + release => 'Reservation Result', + remove_reservation => 'Remove Registration', + get_reservation => 'Request Reservation', + ); + return %titles; +} + +sub slot_reservationmsg_options { + my %options = &Apache::lonlocal::texthash ( + only_student => 'Sent to student', + student_and_user_notes_screen => 'Sent to student and added to user notes', + none => 'None sent and no record in user notes', + ); + return %options; +} + sub handler { my $r=shift; @@ -1659,16 +2544,66 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); - + + my %crumb_titles = &slot_command_titles(); + my $brcrum; + my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + if ($env{'form.command'} eq 'showslots') { + if (($vgr ne 'F') && ($mgr ne 'F')) { + $env{'form.command'} = 'manageresv'; + } + } elsif ($env{'form.command'} eq 'manageresv') { + if (($vgr eq 'F') || ($mgr eq 'F')) { + $env{'form.command'} = 'showslots'; + } + } my $title='Requesting Another Worktime'; - if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') { - $title = 'Managing Slots'; + if ($env{'form.command'} eq 'showresv') { + $title = 'Reservation History'; + if ($env{'form.origin'} eq 'aboutme') { + $brcrum =[{href=>"/adm/$env{'form.udom'}/$env{'form.uname'}/aboutme",text=>'Personal Information Page'}]; + } else { + $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>'Manage Reservations'}]; + } + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=showresv",text=>$title}); + } + } elsif ($env{'form.command'} eq 'manageresv') { + $title = 'Manage Reservations'; + $brcrum =[{href=>"/adm/slotrequest?command=manageresv",text=>$title}]; + } elsif ($vgr eq 'F') { + if ($env{'form.command'} =~ /^(slotlog|showslots|uploadstart|csvuploadmap|csvuploadassign|delete|release|remove_registration)$/) { + $brcrum =[{href=>"/adm/slotrequest?command=showslots", + text=>$crumb_titles{'showslots'}}]; + $title = 'Managing Slots'; + unless ($env{'form.command'} eq 'showslots') { + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}}); + } + } + } + } elsif ($env{'form.command'} eq 'release') { + if ($env{'form.context'} eq 'usermanage') { + $brcrum =[{href=>"/adm/slotrequest?command=manageresv", + text=>$crumb_titles{'showslots'}}]; + $title = 'Manage Reservations'; + if (ref($brcrum) eq 'ARRAY') { + push(@{$brcrum},{href=>"/adm/slotrequest?command=$env{'form.command'}",text=>$crumb_titles{$env{'form.command'}}}); + } + } + } else { + $brcrum =[]; } - &start_page($r,$title); + &start_page($r,$title,$brcrum); - if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { + if ($env{'form.command'} eq 'manageresv') { + my $crstype = &Apache::loncommon::course_type(); + &manage_reservations($r,$crstype); + } elsif ($env{'form.command'} eq 'showresv') { + &show_reservations($r,$env{'form.uname'},$env{'form.udom'}); + } elsif ($env{'form.command'} eq 'showslots' && $vgr eq 'F') { &show_table($r,$mgr); } elsif ($env{'form.command'} eq 'remove_registration' && $mgr eq 'F') { &remove_registration($r); @@ -1695,6 +2630,8 @@ sub handler { } &csv_upload_map($r); } + } elsif ($env{'form.command'} eq 'slotlog' && $mgr eq 'F') { + &show_reservations_log($r); } else { my $symb=&unescape($env{'form.symb'}); if (!defined($symb)) { @@ -1726,7 +2663,26 @@ sub handler { } elsif ($env{'form.command'} eq 'get') { &get_slot($r,$symb); } elsif ($env{'form.command'} eq 'change') { - if (&get_slot($r,$symb,$env{'form.releaseslot'},1)) { + if ($env{'form.nochange'}) { + my $slot_name = $env{'form.releaseslot'}; + my @slots = &check_for_reservation($symb,'allslots'); + my $msg; + if (($slot_name ne '') && (grep(/^\Q$slot_name\E/,@slots))) { + my %slot=&Apache::lonnet::get_slot($env{'form.releaseslot'}); + my $description=&get_description($slot_name,\%slot); + $msg = ''. + &mt('Unchanged reservation: [_1]',$description).'