--- loncom/interface/slotrequest.pm	2005/10/14 19:30:36	1.21
+++ loncom/interface/slotrequest.pm	2005/11/08 03:13:20	1.29
@@ -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.21 2005/10/14 19:30:36 albertel Exp $
+# $Id: slotrequest.pm,v 1.29 2005/11/08 03:13:20 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,11 +53,10 @@ sub fail {
 }
 
 sub start_page {
-    my ($r)=@_;
+    my ($r,$title)=@_;
     my $html=&Apache::lonxml::xmlbegin();
-    $r->print($html.'<head><title>'.
-	      &mt('Request another Worktime').'</title></head>');
-    $r->print(&Apache::loncommon::bodytag('Requesting another Worktime'));
+    $r->print($html.'<head><title>'.&mt($title).'</title></head>');
+    $r->print(&Apache::loncommon::bodytag($title));
 }
 
 sub end_page {
@@ -465,29 +464,66 @@ sub show_table {
 <input type="hidden" name="command" value="uploadstart" />
 <input type="submit" name="start" value="'.&mt('Upload Slot List').'" />
 </form>');
+	$r->print('<form method="POST" action="/adm/helper/newslot.helper">
+<input type="submit" name="newslot" value="'.&mt('Create a New Slot').'" />
+</form>');
     }
+    
+    my %Saveable_Parameters = ('show' => 'array');
+
+    &Apache::loncommon::store_course_settings('chart',\%Saveable_Parameters);
+    &Apache::loncommon::restore_course_settings('chart',\%Saveable_Parameters);
+
+    my %fields=&Apache::lonlocal::texthash(
+	     'name'         => 'Slot Name',
+	     'description'  => 'Description',
+	     'type'         => 'Type',
+	     'starttime'    => 'Start time',
+	     'endtime'      => 'End Time',
+             'startreserve' => 'Time students can start reserving',
+	     'secret'       => 'Secret Word',
+	     'maxspace'     => 'Maxium # of students',
+	     'ip'           => 'IP or DNS restrictions',
+	     'symb'         => 'Resource slot is restricted to.',
+	     'uniqueperiod' => 'Period of time slot is unique',
+	     'proctor'      => 'List of proctors');
+    my @order=('name','description','type','starttime','endtime',
+	       'startreserve','secret','maxspace','ip','symb',
+	       'uniqueperiod','proctor');
+    my @sel = 
+	(exists($env{'form.show'})) ? &Apache::loncommon::get_env_multiple('form.show')
+	                            : keys(%fields);
+    my %sel =  map { $_ => 1 } (@sel);
+
+    $r->print('<form method="POST" action="/adm/slotrequest">
+<input type="hidden" name="command" value="showslots" />
+<input type="submit" name="start" value="'.&mt('Change').'" />');
+    $r->print('<table><tr><td>Show: '.&Apache::loncommon::multiple_select_form('show',\@sel,6,\%fields,\@order).
+	      '</td></tr></table>');
     my $linkstart='<a href="/adm/slotrequest?command=showslots&amp;order=';
     $r->print('<table border="1">
 <tr>
-  <th></th>
-  <th>'.$linkstart.'name"       >Slot name</a></th>
-  <th>'.$linkstart.'type"       >Type</a></th>
-  <th>'.$linkstart.'description">Description</a></th>
-  <th>'.$linkstart.'starttime"  >Start Time</a></th>
-  <th>'.$linkstart.'endtime"    >End Time</a></th>
-  <th>'.$linkstart.'maxspace"   >Max space</a></th>
-  <th>                           Scheduled Students</th>
-  <th>'.$linkstart.'unique"     >Unique Period</a></th>
-</tr>');
+  <th></th>');
+    foreach my $which (@order) {
+	if ($which ne 'proctor' && exists($sel{$which})) {
+	    $r->print('<th>'.$linkstart.$which.'">'.$fields{$which}.'</a></th>');
+	}
+    }
+    $r->print('<th>Scheduled Students</th></tr>');
+
     my %name_cache;
     my $slotsort = sub {
-	if ($env{'form.order'}=~/^(type|name|description|endtime|maxspace)$/) {
+	if ($env{'form.order'}=~/^(type|description|endtime|startreserve|maxspace|ip|symb)$/) {
 	    if (lc($slots{$a}->{$env{'form.order'}})
 		ne lc($slots{$b}->{$env{'form.order'}})) {
 		return (lc($slots{$a}->{$env{'form.order'}}) 
 			cmp lc($slots{$b}->{$env{'form.order'}}));
 	    }
-	} elsif ($env{'form.order'} eq 'unique') {
+	} elsif ($env{'form.order'} eq 'name') {
+	    if (lc($a) cmp lc($b)) {
+		return lc($a) cmp lc($b);
+	    }
+	} elsif ($env{'form.order'} eq 'uniqueperiod') {
 	    
 	    if ($slots{$a}->{'uniqueperiod'}[0] 
 		ne $slots{$b}->{'uniqueperiod'}[0]) {
@@ -515,50 +551,94 @@ sub show_table {
 	    my (undef,$id)=split("\0",$entry);
 	    $ids.= $id.'-> '.$consumed{$entry}->{'name'}.'<br />';
 	}
-	my $start=localtime($slots{$slot}->{'starttime'});
-	my $end=localtime($slots{$slot}->{'endtime'});
+	my $start=($slots{$slot}->{'starttime'}?
+		   &Apache::lonlocal::locallocaltime($slots{$slot}->{'starttime'}):'');
+	my $end=($slots{$slot}->{'endtime'}?
+		 &Apache::lonlocal::locallocaltime($slots{$slot}->{'endtime'}):'');
+	my $start_reserve=($slots{$slot}->{'startreserve'}?
+			   &Apache::lonlocal::locallocaltime($slots{$slot}->{'startreserve'}):'');
+	
 	my $unique;
 	if (ref($slots{$slot}{'uniqueperiod'})) {
 	    $unique=localtime($slots{$slot}{'uniqueperiod'}[0]).','.
 		localtime($slots{$slot}{'uniqueperiod'}[1]);
 	}
-	my @proctors = map {
-	    my ($uname,$udom)=split(/@/,$_);
-	    my $fullname=$name_cache{$_};
-	    if (!defined($fullname)) {
-		&Apache::lonnet::logthis("Gettign $uname $udom");
-		$fullname = &Apache::loncommon::plainname($uname,$udom);
-		$fullname =~s/\s/&nbsp;/g;
-		$name_cache{$_} = $fullname;
-	    }
-	    &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
-	} (split(/\s*,\s*/,$slots{$slot}->{'proctor'}));
-	
+	my $title;
+	if (exists($slots{$slot}{'symb'})) {
+	    my (undef,undef,$res)=
+		&Apache::lonnet::decode_symb($slots{$slot}{'symb'});
+	    $res =   &Apache::lonnet::clutter($res);
+	    $title = &Apache::lonnet::gettitle($slots{$slot}{'symb'});
+	    $title='<a href="'.$res.'?symb='.$slots{$slot}{'symb'}.'">'.$title.'</a>';
+	}
+	my @proctors;
+	my $rowspan=1;
+	my $colspan=1;
+	if (exists($sel{'proctor'})) {
+	    $rowspan=2;
+	    @proctors= map {
+		my ($uname,$udom)=split(/@/,$_);
+		my $fullname=$name_cache{$_};
+		if (!defined($fullname)) {
+		    &Apache::lonnet::logthis("Gettign $uname $udom");
+		    $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}->{'proctor'})));
+	}
 	my $proctors=join(', ',@proctors);
 
 	my $edit=(<<EDITFORM);
-<form method="POST">
-  <input type="hidden" name="command" value="editslot" />
-  <input type="hidden" name="slot" value="$slot" />
+<form method="POST" action="/adm/helper/newslot.helper">
+  <input type="hidden" name="name" value="$slot" />
   <input type="submit" name="Edit" value="Edit" />
 </form>
 EDITFORM
-	$r->print(<<STUFF);
-<tr>
- <td rowspan="2">$edit</td>
- <td>$slot</td>
- <td>$slots{$slot}->{'type'}</td>
- <td>$description</td>
- <td>$start</td>
- <td>$end</td>
- <td>$slots{$slot}->{'maxspace'}</td>
- <td>$ids</td>
- <td>$unique</td>
-</tr>
+ 
+        $r->print("<tr>\n<td rowspan=\"$rowspan\">$edit</td>\n");
+	if (exists($sel{'name'})) {
+	    $colspan++;$r->print("<td>$slot</td>");
+	}
+	if (exists($sel{'type'})) {
+	    $colspan++;$r->print("<td>$slots{$slot}->{'type'}</td>\n");
+	}
+	if (exists($sel{'description'})) {
+	    $colspan++;$r->print("<td>$description</td>\n");
+	}
+	if (exists($sel{'starttime'})) {
+	    $colspan++;$r->print("<td>$start</td>\n");
+	}
+	if (exists($sel{'endtime'})) {
+	    $colspan++;$r->print("<td>$end</td>\n");
+	}
+	if (exists($sel{'startreserve'})) {
+	    $colspan++;$r->print("<td>$start_reserve</td>\n");
+	}
+	if (exists($sel{'secret'})) {
+	    $colspan++;$r->print("<td>$slots{$slot}{'secret'}</td>\n");
+	}
+	if (exists($sel{'maxspace'})) {
+	    $colspan++;$r->print("<td>$slots{$slot}{'maxspace'}</td>\n");
+	}
+	if (exists($sel{'ip'})) {
+	    $colspan++;$r->print("<td>$slots{$slot}{'ip'}</td>\n");
+	}
+	if (exists($sel{'symb'})) {
+	    $colspan++;$r->print("<td>$title</td>\n");
+	}
+	if (exists($sel{'uniqueperiod'})) {
+	    $colspan++;$r->print("<td>$unique</td>\n");
+	}
+	$colspan++;$r->print("<td>$ids</td>\n</tr>\n");
+	if (exists($sel{'proctor'})) {
+	    $r->print(<<STUFF);
 <tr>
- <td colspan="8">$proctors</td>
+ <td colspan="$colspan">$proctors</td>
 </tr>
 STUFF
+        }
     }
     $r->print('</table>');
 }
@@ -761,6 +841,10 @@ sub csv_upload_assign {
 	if ($entries{$fields{'endtime'}}) {
 	    $slot{'endtime'}=&UnixDate($entries{$fields{'endtime'}},"%s");
 	}
+	if ($entries{$fields{'startreserve'}}) {
+	    $slot{'startreserve'}=
+		&UnixDate($entries{$fields{'startreserve'}},"%s");
+	}
 	foreach my $key ('ip','proctor','description','maxspace',
 			 'secret','symb') {
 	    if ($entries{$fields{$key}}) {
@@ -789,9 +873,15 @@ sub handler {
     my $r=shift;
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
-    &start_page($r);
+    
     my $vgr=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
     my $mgr=&Apache::lonnet::allowed('mgr',$env{'request.course.id'});
+    my $title='Requesting Another Worktime';
+    if ($env{'form.command'} =~ /^(showslots|uploadstart|csvuploadmap|csvuploadassign)$/ && $vgr eq 'F') {
+	$title = 'Managing Slots';
+    }
+    &start_page($r,$title);
+
     if ($env{'form.command'} eq 'showslots' && $vgr eq 'F') {
 	&show_table($r,$mgr);
     } elsif ($env{'form.command'} eq 'uploadstart' && $mgr eq 'F') {
@@ -809,8 +899,6 @@ sub handler {
 	    }
 	    &csv_upload_map($r);
 	}
-    } elsif ($env{'form.command'} eq 'editslot' && $mgr eq 'F') {
-	&show_slot_edit($r);
     } else {
 	my $symb=&Apache::lonnet::unescape($env{'form.symb'});
 	my (undef,undef,$res)=&Apache::lonnet::decode_symb($symb);