[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 18 Aug 2006 22:39:37 -0000


albertel		Fri Aug 18 18:39:37 2006 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  - adding a screen for deleting parameters that are no longer valid (resource
     isn't in the course), curently ugly and un advertised but funtional
  
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.332 loncom/interface/lonparmset.pm:1.333
--- loncom/interface/lonparmset.pm:1.332	Thu Aug 10 11:36:49 2006
+++ loncom/interface/lonparmset.pm	Fri Aug 18 18:39:37 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.332 2006/08/10 15:36:49 albertel Exp $
+# $Id: lonparmset.pm,v 1.333 2006/08/18 22:39:37 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2432,7 +2432,7 @@
 		    }
 		    &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 		} else {
-		    push (@deldata,$thiskey);
+		    push (@deldata,$thiskey,$thiskey.'.type');
 		}
 	    } elsif ($cmd eq 'datepointer') {
 		my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
@@ -2832,9 +2832,127 @@
 	      &Apache::loncommon::end_page());
 }
 
+sub clean_parameters {
+    my ($r) = @_;
+    my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+    my $start_page=&Apache::loncommon::start_page('Clean Parameters');
+    my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
+    $r->print(<<ENDOVER);
+$start_page
+$breadcrumbs
+<form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
+ENDOVER
+# Store modified
+
+    &storedata($r,$crs,$dom);
+
+# Read modified data
+
+    my $resourcedata=&readdata($crs,$dom);
+
+# List data
+
+    $r->print('<h3>'.
+	      &mt('These parameters refer to resources that do not exist.').
+	      '</h3>'.
+	      '<input type="submit" value="'.&mt('Delete Checked Parameters').'" />'.'<br />'.
+	      '<br />');
+    $r->print(&Apache::loncommon::start_data_table().
+	      '<tr>'.
+	      '<th>'.&mt('Delete').'</th>'.
+	      '<th>'.&mt('Parameter').'</th>'.
+	      '</tr>');
+    foreach my $thiskey (sort(keys(%{$resourcedata}))) {
+	next if (!exists($resourcedata->{$thiskey.'.type'})
+		 && $thiskey=~/\.type$/);
+	my %data = &parse_key($thiskey);
+	if (exists($data{'realm_exists'})
+	    && !$data{'realm_exists'}) {
+	    $r->print(&Apache::loncommon::start_data_table_row().
+		      '<tr>'.
+		      '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>'		      );
+	    
+	    $r->print('<td>');
+	    $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
+			  &standard_parameter_names($data{'parameter_name'}),
+			  $resourcedata->{$thiskey}));
+	    $r->print('<br />');
+	    if ($data{'scope_type'} eq 'all') {
+		$r->print(&mt('All users'));
+	    } elsif ($data{'scope_type'} eq 'user') {
+		$r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
+	    } elsif ($data{'scope_type'} eq 'section') {
+		$r->print(&mt('Section: [_1]',$data{'scope'}));
+	    } elsif ($data{'scope_type'} eq 'group') {
+		$r->print(&mt('Group: [_1]',$data{'scope'}));
+	    }
+	    $r->print('<br />');
+	    if ($data{'realm_type'} eq 'all') {
+		$r->print(&mt('All Resources'));
+	    } elsif ($data{'realm_type'} eq 'folder') {
+		$r->print(&mt('Folder: [_1]'),$data{'realm'});
+	    } elsif ($data{'realm_type'} eq 'symb') {
+		my ($map,$resid,$url) =
+		    &Apache::lonnet::decode_symb($data{'realm'});
+		$r->print(&mt('Resource: [_1] <br />&nbsp;&nbsp;&nbsp;with ID: [_2] <br />&nbsp;&nbsp;&nbsp;in folder [_3]',
+			      $url,$resid,$map));
+	    }
+	    $r->print(&mt('Part: [_1]',$data{'parameter_part'}));
+	    $r->print('</td></tr>');
+	
+	}
+    }
+    $r->print(&Apache::loncommon::end_data_table().'<p>'.
+	      '<input type="submit" value="'.&mt('Delete Checked Parameters').'" />'.
+	      '</p></form>'.
+	      &Apache::loncommon::end_page());
+}
+
+sub parse_key {
+    my ($key) = @_;
+    my %data;
+    my ($middle,$part,$name)=
+	($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
+    $data{'scope_type'} = 'all';
+    if ($middle=~/^\[(.*)\]/) {
+       	$data{'scope'} = $1;
+	if ($data{'scope'}=~/^useropt\:(\w+)\:(\w+)/) {
+	    $data{'scope_type'} = 'user';
+	    $data{'scope'} = [$1,$2];
+	} else {
+	    #FIXME check for group scope
+	    $data{'scope_type'} = 'section';
+	}
+	$middle=~s/^\[(.*)\]//;
+    }
+    $middle=~s/\.+$//;
+    $middle=~s/^\.+//;
+    $data{'realm_type'}='all';
+    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
+	$data{'realm'} = $1;
+	$data{'realm_type'} = 'folder';
+	$data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
+	($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
+	&Apache::lonnet::logthis($1." siad ".	$data{'realm_exists'} );
+    } elsif ($middle) {
+	$data{'realm'} = $middle;
+	$data{'realm_type'} = 'symb';
+	$data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
+	my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
+	$data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
+    }
+    
+    $data{'parameter_part'} = $part;
+    $data{'parameter_name'} = $name;
+
+    return %data;
+}
+
 ##################################################
 ##################################################
-                                                                                            
+
 =pod
 
 =item check_cloners
@@ -3618,6 +3736,10 @@
             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 						    text=>"Parameter Change Log"});
 	    &parm_change_log($r);
+        } elsif ($env{'form.action'} eq 'cleanparameters' && $parm_permission) {
+            &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
+						    text=>"Clean Parameters"});
+	    &clean_parameters($r);
 	}       
     } else {
 # ----------------------------- Not in a course, or not allowed to modify parms