Diff for /loncom/interface/slotrequest.pm between versions 1.48.2.3 and 1.58

version 1.48.2.3, 2006/03/30 05:13:38 version 1.58, 2006/04/24 23:23:02
Line 54  sub fail { Line 54  sub fail {
   
 sub start_page {  sub start_page {
     my ($r,$title)=@_;      my ($r,$title)=@_;
     my $html=&Apache::lonxml::xmlbegin();      $r->print(&Apache::loncommon::start_page($title));
     $r->print($html.'<head><title>'.&mt($title).'</title></head>');  
     $r->print(&Apache::loncommon::bodytag($title));  
 }  }
   
 sub end_page {  sub end_page {
     my ($r)=@_;      my ($r)=@_;
     $r->print(&Apache::loncommon::endbodytag().'</html>');      $r->print(&Apache::loncommon::end_page());
 }  }
   
 =pod  =pod
Line 256  sub make_reservation { Line 254  sub make_reservation {
     if (&network_error($value)) {       if (&network_error($value)) { 
  return 'error: Unable to determine current status';   return 'error: Unable to determine current status';
     }      }
     my $me=$env{'user.name'}.'@'.$env{'user.domain'};      my $me=$env{'user.name'}.':'.$env{'user.domain'};
     foreach my $key (keys(%consumed)) {      foreach my $key (keys(%consumed)) {
  if ($consumed{$key}->{'name'} eq $me) {   if ($consumed{$key}->{'name'} eq $me) {
     my $num=(split('\0',$key))[1];      my $num=(split('\0',$key))[1];
Line 286  sub make_reservation { Line 284  sub make_reservation {
  return undef;   return undef;
     }      }
           
     my %reservation=('name'      => $env{'user.name'}.'@'.$env{'user.domain'},      my %reservation=('name'      => $env{'user.name'}.':'.$env{'user.domain'},
      'timestamp' => time,       'timestamp' => time,
      'symb'      => $symb);       'symb'      => $symb);
   
Line 399  sub release_all_slot { Line 397  sub release_all_slot {
   
     foreach my $entry (sort { $consumed{$a}{'name'} cmp       foreach my $entry (sort { $consumed{$a}{'name'} cmp 
   $consumed{$b}{'name'} } (keys(%consumed))) {    $consumed{$b}{'name'} } (keys(%consumed))) {
  my ($uname,$udom) = split('@',$consumed{$entry}{'name'});   my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
  my ($result,$msg) =   my ($result,$msg) =
     &release_reservation($slot_name,$uname,$udom,      &release_reservation($slot_name,$uname,$udom,
  $consumed{$entry}{'symb'},$mgr);   $consumed{$entry}{'symb'},$mgr);
Line 467  sub release_reservation { Line 465  sub release_reservation {
     my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,      my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
        "^$slot_name\0");         "^$slot_name\0");
     foreach my $entry (keys(%consumed)) {      foreach my $entry (keys(%consumed)) {
  if ( $consumed{$entry}->{'name'} eq ($uname.'@'.$udom) ) {   if ( $consumed{$entry}->{'name'} eq ($uname.':'.$udom) ) {
     &Apache::lonnet::del('slot_reservations',[$entry],      &Apache::lonnet::del('slot_reservations',[$entry],
  $cdom,$cnum);   $cdom,$cnum);
  }   }
Line 615  STUFF Line 613  STUFF
   
 sub allowed_slot {  sub allowed_slot {
     my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;      my ($slot_name,$slot,$symb,$slots,$consumed_uniqueperiods)=@_;
   
     #already started      #already started
     if ($slot->{'starttime'} < time) {      if ($slot->{'starttime'} < time) {
  # all open slot to be schedulable   # all open slot to be schedulable
  #return 0;   #return 0;
     }      }
     &Apache::lonxml::debug("$slot_name starttime good");      &Apache::lonxml::debug("$slot_name starttime good");
   
     #already ended      #already ended
     if ($slot->{'endtime'} < time) {      if ($slot->{'endtime'} < time) {
  return 0;   return 0;
     }      }
     &Apache::lonxml::debug("$slot_name endtime good");      &Apache::lonxml::debug("$slot_name endtime good");
   
     # not allowed to pick this one      # not allowed to pick this one
     if (defined($slot->{'type'})      if (defined($slot->{'type'})
  && $slot->{'type'} ne 'schedulable_student') {   && $slot->{'type'} ne 'schedulable_student') {
  return 0;   return 0;
     }      }
     &Apache::lonxml::debug("$slot_name type good");      &Apache::lonxml::debug("$slot_name type good");
     # not allowed for this resource  
     if (defined($slot->{'symb'})  
  && $slot->{'symb'} ne $symb) {  
  return 0;  
     }  
     # reserve time not yet started      # reserve time not yet started
     if ($slot->{'startreserve'} > time) {      if ($slot->{'startreserve'} > time) {
  return 0;   return 0;
     }      }
     &Apache::lonxml::debug("$slot_name reserve good");      &Apache::lonxml::debug("$slot_name reserve good");
   
       my $userallowed=0;
       # its for a different set of users
       if (defined($slot->{'allowedsections'})) {
    if (!defined($env{'request.role.sec'})
       && grep(/^No section assigned$/,
       split(',',$slot->{'allowedsections'}))) {
       $userallowed=1;
    }
    if (defined($env{'request.role.sec'})
       && grep(/^\Q$env{'request.role.sec'}\E$/,
       split(',',$slot->{'allowedsections'}))) {
       $userallowed=1;
    }
       }
       &Apache::lonxml::debug("$slot_name sections is $userallowed");
   
       # its for a different set of users
       if (defined($slot->{'allowedusers'})
    && grep(/^\Q$env{'user.name'}:$env{'user.domain'}\E$/,
    split(',',$slot->{'allowedusers'}))) {
    $userallowed=1;
       }
   
       if (!defined($slot->{'allowedusers'})
    && !defined($slot->{'allowedsections'})) {
    $userallowed=1;
       }
   
       &Apache::lonxml::debug("$slot_name user is $userallowed");
       return 0 if (!$userallowed);
   
       # not allowed for this resource
       if (defined($slot->{'symb'})
    && $slot->{'symb'} ne $symb) {
    return 0;
       }
   
     my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,      my $conflict = &check_for_conflict($symb,$slot_name,$slot,$slots,
        $consumed_uniqueperiods);         $consumed_uniqueperiods);
     if ($conflict) {      if ($conflict) {
Line 854  sub show_table { Line 888  sub show_table {
   
     # what to display filtering      # what to display filtering
     my %show_fields=&Apache::lonlocal::texthash(      my %show_fields=&Apache::lonlocal::texthash(
      'name'         => 'Slot Name',       'name'            => 'Slot Name',
      'description'  => 'Description',       'description'     => 'Description',
      'type'         => 'Type',       'type'            => 'Type',
      'starttime'    => 'Start time',       'starttime'       => 'Start time',
      'endtime'      => 'End Time',       'endtime'         => 'End Time',
              'startreserve' => 'Time students can start reserving',               'startreserve'    => 'Time students can start reserving',
      'secret'       => 'Secret Word',       'secret'          => 'Secret Word',
      'maxspace'     => 'Maximum # of students',       'maxspace'        => 'Maximum # of students',
      'ip'           => 'IP or DNS restrictions',       'ip'              => 'IP or DNS restrictions',
      'symb'         => 'Resource slot is restricted to.',       'symb'            => 'Resource slot is restricted to.',
      'uniqueperiod' => 'Period of time slot is unique',       'allowedsections' => 'Sections slot is restricted to.',
      'scheduled'    => 'Scheduled Students',       'allowedusers'    => 'Users slot is restricted to.',
      'proctor'      => 'List of proctors');       'uniqueperiod'    => 'Period of time slot is unique',
        'scheduled'       => 'Scheduled Students',
        'proctor'         => 'List of proctors');
     my @show_order=('name','description','type','starttime','endtime',      my @show_order=('name','description','type','starttime','endtime',
        'startreserve','secret','maxspace','ip','symb',      'startreserve','secret','maxspace','ip','symb',
        'uniqueperiod','scheduled','proctor');      'allowedsections','allowedusers','uniqueperiod',
       'scheduled','proctor');
     my @show =       my @show = 
  (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')   (exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
                             : keys(%show_fields);                              : keys(%show_fields);
Line 975  sub show_table { Line 1012  sub show_table {
   
     my %name_cache;      my %name_cache;
     my $slotsort = sub {      my $slotsort = sub {
  if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) {   if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb|allowedsections|allowedusers)$/) {
     if (lc($slots{$a}->{$env{'form.order'}})      if (lc($slots{$a}->{$env{'form.order'}})
  ne lc($slots{$b}->{$env{'form.order'}})) {   ne lc($slots{$b}->{$env{'form.order'}})) {
  return (lc($slots{$a}->{$env{'form.order'}})    return (lc($slots{$a}->{$env{'form.order'}}) 
Line 1018  sub show_table { Line 1055  sub show_table {
       $consumed{$b}{name} }        $consumed{$b}{name} }
    (keys(%consumed))) {     (keys(%consumed))) {
     my (undef,$id)=split("\0",$entry);      my (undef,$id)=split("\0",$entry);
     my ($uname,$udom) = split('@',$consumed{$entry}{'name'});      my ($uname,$udom) = split(':',$consumed{$entry}{'name'});
     $ids.= '<nobr>';      $ids.= '<nobr>';
     foreach my $item (@stu_display_order) {      foreach my $item (@stu_display_order) {
  if ($stu_display{$item}) {   if ($stu_display{$item}) {
     if ($item eq 'fullname') {      if ($item eq 'fullname') {
  $ids.=$fullname->{"$uname:$udom"}.' ';   $ids.=$fullname->{"$uname:$udom"}.' ';
     } elsif ($item eq 'username') {      } elsif ($item eq 'username') {
  $ids.="<tt>$uname\@$udom</tt> ";   $ids.="<tt>$uname:$udom</tt> ";
     }      }
  }   }
     }      }
Line 1057  sub show_table { Line 1094  sub show_table {
     $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';      $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
  }   }
   
    my $allowedsections;
    if (exists($show{'allowedsections'})) {
       $allowedsections = 
    join(', ',sort(split(/\s*,\s*/,
        $slots{$slot}->{'allowedsections'})));
    }
   
    my @allowedusers;
    if (exists($show{'allowedusers'})) {
       @allowedusers= map {
    my ($uname,$udom)=split(/:/,$_);
    my $fullname=$name_cache{$_};
    if (!defined($fullname)) {
       $fullname = &Apache::loncommon::plainname($uname,$udom);
       $fullname =~s/\s/&nbsp;/g;
       $name_cache{$_} = $fullname;
    }
    &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
       } (sort(split(/\s*,\s*/,$slots{$slot}->{'allowedusers'})));
    }
    my $allowedusers=join(', ',@allowedusers);
   
  my @proctors;   my @proctors;
  my $rowspan=1;   my $rowspan=1;
  my $colspan=1;   my $colspan=1;
Line 1066  sub show_table { Line 1125  sub show_table {
  my ($uname,$udom)=split(/@/,$_);   my ($uname,$udom)=split(/@/,$_);
  my $fullname=$name_cache{$_};   my $fullname=$name_cache{$_};
  if (!defined($fullname)) {   if (!defined($fullname)) {
     &Apache::lonnet::logthis("Gettign $uname $udom");  
     $fullname = &Apache::loncommon::plainname($uname,$udom);      $fullname = &Apache::loncommon::plainname($uname,$udom);
     $fullname =~s/\s/&nbsp;/g;      $fullname =~s/\s/&nbsp;/g;
     $name_cache{$_} = $fullname;      $name_cache{$_} = $fullname;
Line 1123  DELETELINK Line 1181  DELETELINK
  if (exists($show{'symb'})) {   if (exists($show{'symb'})) {
     $colspan++;$r->print("<td>$title</td>\n");      $colspan++;$r->print("<td>$title</td>\n");
  }   }
  if (exists($show{'uniqueperiod'})) {   if (exists($show{'allowedsections'})) {
     $colspan++;$r->print("<td>$unique</td>\n");      $colspan++;$r->print("<td>$allowedsections</td>\n");
    }
    if (exists($show{'allowedusers'})) {
       $colspan++;$r->print("<td>$allowedusers</td>\n");
  }   }
  if (exists($show{'scheduled'})) {   if (exists($show{'scheduled'})) {
     $colspan++;$r->print("<td>$remove_all $ids</td>\n</tr>\n");      $colspan++;$r->print("<td>$remove_all $ids</td>\n</tr>\n");
Line 1309  sub csvupload_fields { Line 1370  sub csvupload_fields {
     ['maxspace','Maximum number of reservations'],      ['maxspace','Maximum number of reservations'],
     ['symb','Resource Restriction'],      ['symb','Resource Restriction'],
     ['uniqueperiod','Date range of slot exclusion'],      ['uniqueperiod','Date range of slot exclusion'],
     ['secret','Secret word proctor uses to validate']);      ['secret','Secret word proctor uses to validate'],
       ['allowedsections','Sections slot is restricted to'],
       ['allowedusers','Users slot is restricted to'],
       );
 }  }
   
 sub csv_upload_assign {  sub csv_upload_assign {
Line 1356  sub csv_upload_assign { Line 1420  sub csv_upload_assign {
  if ($entries{$fields{'endtime'}}) {   if ($entries{$fields{'endtime'}}) {
     $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");      $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
  }   }
   
    # start/endtime must be defined and greater than zero
    if (!$slot{'starttime'}) {
       push(@errors,"$name not created -- Invalid start time");
       next;
    }
    if (!$slot{'endtime'}) {
       push(@errors,"$name not created -- Invalid end time");
       next;
    }
    if ($slot{'starttime'} > $slot{'endtime'}) {
       push(@errors,"$name not created -- Slot starts after it ends");
       next;
    }
   
  if ($entries{$fields{'startreserve'}}) {   if ($entries{$fields{'startreserve'}}) {
     $slot{'startreserve'}=      $slot{'startreserve'}=
  &UnixDate($entries{$fields{'startreserve'}},"%s");   &UnixDate($entries{$fields{'startreserve'}},"%s");
  }   }
    if (defined($slot{'startreserve'})
       && $slot{'startreserve'} > $slot{'starttime'}) {
       push(@errors,"$name not created -- Slot's reservation start time is after the slot's start time.");
       next;
    }
   
  foreach my $key ('ip','proctor','description','maxspace',   foreach my $key ('ip','proctor','description','maxspace',
  'secret','symb') {   'secret','symb') {
     if ($entries{$fields{$key}}) {      if ($entries{$fields{$key}}) {
  $slot{$key}=$entries{$fields{$key}};   $slot{$key}=$entries{$fields{$key}};
     }      }
  }   }
   
  if ($entries{$fields{'uniqueperiod'}}) {   if ($entries{$fields{'uniqueperiod'}}) {
     my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});      my ($start,$end)=split(',',$entries{$fields{'uniqueperiod'}});
     my @times=(&UnixDate($start,"%s"),      my @times=(&UnixDate($start,"%s"),
        &UnixDate($end,"%s"));         &UnixDate($end,"%s"));
     $slot{'uniqueperiod'}=\@times;      $slot{'uniqueperiod'}=\@times;
  }   }
    if (defined($slot{'uniqueperiod'})
       && $slot{'uniqueperiod'}[0] > $slot{'uniqueperiod'}[1]) {
       push(@errors,"$name not created -- Slot's unique period start time is later than the unique period's end time.");
       next;
    }
   
  &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);   &Apache::lonnet::cput('slots',{$name=>\%slot},$cdom,$cname);
  $r->print('.');   $r->print('.');

Removed from v.1.48.2.3  
changed lines
  Added in v.1.58


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>