Diff for /loncom/interface/lonparmset.pm between versions 1.342 and 1.365

version 1.342, 2006/10/13 17:40:12 version 1.365, 2007/05/02 01:33:49
Line 65  use Apache::lonlocal; Line 65  use Apache::lonlocal;
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
 use Apache::longroup;  use Apache::longroup;
 use Apache::lonrss;  use Apache::lonrss;
 use LONCAPA;  use LONCAPA qw(:DEFAULT :match);
   
 # --- Caches local to lonparmset  # --- Caches local to lonparmset
   
Line 122  sub parmval_by_symb { Line 122  sub parmval_by_symb {
 # load caches  # load caches
     &cacheparmhash();      &cacheparmhash();
   
     my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);      my $useropt;
       if ($uname ne '' && $udom ne '') {
    $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
       }
   
     my $result='';      my $result='';
     my @outpar=();      my @outpar=();
Line 173  sub parmval_by_symb { Line 176  sub parmval_by_symb {
     }      }
   
 # ------------------------------------------------------ fourth, back to course  # ------------------------------------------------------ fourth, back to course
     if (defined($csec)) {      if ($csec ne '') {
         if (defined($$courseopt{$seclevel})) {          if (defined($$courseopt{$seclevel})) {
     $outpar[9]=$$courseopt{$seclevel};      $outpar[9]=$$courseopt{$seclevel};
     $result=9;      $result=9;
Line 189  sub parmval_by_symb { Line 192  sub parmval_by_symb {
  }   }
     }      }
 # ------------------------------------------------------ fifth, check course group  # ------------------------------------------------------ fifth, check course group
     if (defined($cgroup)) {      if ($cgroup ne '') {
         if (defined($$courseopt{$grplevel})) {          if (defined($$courseopt{$grplevel})) {
             $outpar[6]=$$courseopt{$grplevel};              $outpar[6]=$$courseopt{$grplevel};
             $result=6;              $result=6;
Line 206  sub parmval_by_symb { Line 209  sub parmval_by_symb {
   
 # ---------------------------------------------------------- fifth, check user  # ---------------------------------------------------------- fifth, check user
   
     if (defined($uname)) {      if ($uname ne '') {
  if (defined($$useropt{$courselevel})) {   if (defined($$useropt{$courselevel})) {
     $outpar[3]=$$useropt{$courselevel};      $outpar[3]=$$useropt{$courselevel};
     $result=3;      $result=3;
Line 269  sub resetrulescache { Line 272  sub resetrulescache {
   
 sub rulescache {  sub rulescache {
     my $id=shift;      my $id=shift;
     if ($rulesid ne $env{'request.course.id'}) {      if ($rulesid ne $env{'request.course.id'}
  %rules=();   && !defined($rules{$id})) {
     }  
     unless (defined($rules{$id})) {  
  my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};   my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};   my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);   %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
Line 553  sub valout { Line 554  sub valout {
             }              }
             $result=~s/\s+$//;              $result=~s/\s+$//;
         } elsif (&isdateparm($type)) {          } elsif (&isdateparm($type)) {
             $result = localtime($value).&date_sanity_info($value);              $result = &Apache::lonlocal::locallocaltime($value).
    &date_sanity_info($value);
         } else {          } else {
             $result = $value;              $result = $value;
         }          }
Line 933  sub extractResourceInformation { Line 935  sub extractResourceInformation {
  $$typep{$id}=$1;   $$typep{$id}=$1;
  $$keyp{$id}='';   $$keyp{$id}='';
         $$uris{$id}=$srcf;          $$uris{$id}=$srcf;
  foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {   foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
     if ($_=~/^parameter\_(.*)/) {      next if ($key!~/^parameter_/);
  my $key=$_;  
 # Hidden parameters  # Hidden parameters
  if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {      next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm');
     next;  
  }  
  my $display= &Apache::lonnet::metadata($srcf,$key.'.display');  
  my $name=&Apache::lonnet::metadata($srcf,$key.'.name');  
  my $part= &Apache::lonnet::metadata($srcf,$key.'.part');  
 #  #
 # allparms is a hash of parameter names  # allparms is a hash of parameter names
 #  #
       my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
       if (!exists($$allparms{$name})) {
    my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
  my $parmdis = $display;   my $parmdis = $display;
  $parmdis =~ s/\[Part.*$//g;   $parmdis =~ s/\[Part.*$//g;
                 $$allparms{$name}=$parmdis;   $$allparms{$name}=$parmdis;
  $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');   if (ref($defkeytype)) {
       $$defkeytype{$name}=
    &Apache::lonnet::metadata($srcf,$key.'.type');
    }
       }
   
 #  #
 # allparts is a hash of all parts  # allparts is a hash of all parts
 #  #
  $$allparts{$part} = "Part: $part";      my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
       $$allparts{$part} = "Part: $part";
 #  #
 # Remember all keys going with this resource  # Remember all keys going with this resource
 #  #
  if ($$keyp{$id}) {      if ($$keyp{$id}) {
     $$keyp{$id}.=','.$key;   $$keyp{$id}.=','.$key;
  } else {      } else {
     $$keyp{$id}=$key;   $$keyp{$id}=$key;
  }      }
 #  #
 # Put in order  # Put in order
 #   # 
                 unless ($$keyorder{$key}) {      unless ($$keyorder{$key}) {
                     $$keyorder{$key}=$keyordercnt;   $$keyorder{$key}=$keyordercnt;
                     $keyordercnt++;   $keyordercnt++;
  }  
   
     }      }
  }   }
  $$mapp{$id}=  
     &Apache::lonnet::declutter($resource->enclosing_map_src());  
  $$mapp{$mapid}=$$mapp{$id};   if (!exists($$mapp{$mapid})) {
  $$allmaps{$mapid}=$$mapp{$id};      $$mapp{$id}=
  if ($mapid eq '1') {   &Apache::lonnet::declutter($resource->enclosing_map_src());
     $$maptitles{$mapid}='Main Course Documents';      $$mapp{$mapid}=$$mapp{$id};
       $$allmaps{$mapid}=$$mapp{$id};
       if ($mapid eq '1') {
    $$maptitles{$mapid}='Main Course Documents';
       } else {
    $$maptitles{$mapid}=
       &Apache::lonnet::gettitle($$mapp{$id});    
       }
       $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
       $$symbp{$mapid}=$$mapp{$id}.'___(all)';
  } else {   } else {
     $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));      $$mapp{$id} = $$mapp{$mapid};
  }   }
  $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};  
  $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);   $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
  $$symbp{$mapid}=$$mapp{$id}.'___(all)';  
     }      }
 }  }
   
Line 2033  sub crsenv { Line 2044  sub crsenv {
         if ($name =~ /^default_enrollment_(start|end)_date$/) {          if ($name =~ /^default_enrollment_(start|end)_date$/) {
             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');              $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
         }          }
    #
           # Deal with the emails
           if ($name =~ /\.email$/) {
       my ($user,$domain) = split(/:/,$value);
       if (!defined($user) || !defined($domain)) {
    $setoutput.= '<br /> <span class="LC_error">'.
       &mt("Invalid email address specified, address must be of the form username:domain").
       '</span>';
    undef($value);
       } elsif (&Apache::lonnet::homeserver($user,$domain) eq 'no_host') {
    $setoutput.= '<br /> <span class="LC_error">'.
       &mt("Invalid email address specified, user [_1] is unknown.",$value).
       '</span>';
    undef($value);
       }
           }
         # Get existing cloners          # Get existing cloners
         my @oldcloner = ();          my @oldcloner = ();
         if ($name eq 'cloners') {          if ($name eq 'cloners') {
Line 2120  sub crsenv { Line 2147  sub crsenv {
              'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').               'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
                                  '</b><br />(<tt>user:domain,'.                                   '</b><br />(<tt>user:domain,'.
                                  'user:domain(section;section;...;*;...),...</tt>)',                                   'user:domain(section;section;...;*;...),...</tt>)',
                'question.email.text' => '<b>'.&mt('Custom Text for Resource Content Question Option in Feedback').
                                    '</b>',
              'comment.email'  => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.               'comment.email'  => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
                                  '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',                                   '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
                'comment.email.text' => '<b>'.&mt('Custom Text for Course Content Option in Feedback').
                                    '</b>',
              'policy.email'   => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.               'policy.email'   => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
                                  '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',                                   '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
                'policy.email.text' => '<b>'.&mt('Custom Text for Course Policy Option in Feedback').
                                    '</b>',
              'hideemptyrows'  => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.               'hideemptyrows'  => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
                                  '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',                                   '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
              'pageseparators'  => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.               'pageseparators'  => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
Line 2193  sub crsenv { Line 2226  sub crsenv {
                     ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'.                       ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'. 
                     ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',                      ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
      'print_header_format'       'print_header_format'
          => '<b>Print header format; substitutions:  %n student name %c course id %a assignment',           => '<b>Print header format; substitutions</b>:  %n student name %c course id %a assignment note, numbers after the % limit the field size',
              'anonymous_quiz'               'anonymous_quiz'
                  => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.                   => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
                     ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',                      ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
Line 2206  sub crsenv { Line 2239  sub crsenv {
                  => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.                   => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',                      ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
      'task_messages'       'task_messages'
          => '<b>'.&mt('Send message to student when clicking Done on Tasks. [_1] to send a message only to student, [_2] to send message to student and add record to user information page for instructors. Leave blank to disable.','<tt>only_student</tt>','<tt>student_and_user_notes_screen</tt>').'</b>',           => '<b>'.&mt('Send message to student when clicking Done on Tasks').'</b><br /> ('.&mt('[_1] to send a message only to student, [_2] to send message to student and add record to user information page for instructors. Leave blank to disable.','<tt>only_student</tt>','<tt>student_and_user_notes_screen</tt>').')',
      'disablesigfigs'       'disablesigfigs'
          => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.           => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',                      ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
Line 2221  sub crsenv { Line 2254  sub crsenv {
         my @Display_Order = ('url','description','courseid','cloners','grading',          my @Display_Order = ('url','description','courseid','cloners','grading',
                              'externalsyllabus',                               'externalsyllabus',
                              'default_xml_style','pageseparators',                               'default_xml_style','pageseparators',
                              'question.email','comment.email','policy.email',                               'question.email','question.email.text','comment.email','comment.email.text','policy.email','policy.email.text',
                              'student_classlist_view',                               'student_classlist_view',
                              'plc.roles.denied','plc.users.denied',                               'plc.roles.denied','plc.users.denied',
                              'pch.roles.denied','pch.users.denied',                               'pch.roles.denied','pch.users.denied',
Line 2363  sub readdata { Line 2396  sub readdata {
   
     my $classlist=&Apache::loncoursedata::get_classlist();      my $classlist=&Apache::loncoursedata::get_classlist();
     foreach (keys %$classlist) {      foreach (keys %$classlist) {
         # the following undefs are for 'domain', and 'username' respectively.          if ($_=~/^($match_username)\:($match_domain)$/) {
         if ($_=~/^(\w+)\:(\w+)$/) {  
     my ($tuname,$tudom)=($1,$2);      my ($tuname,$tudom)=($1,$2);
     my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);      my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
             foreach my $userkey (keys %{$useropt}) {              foreach my $userkey (keys %{$useropt}) {
Line 2409  sub storedata { Line 2441  sub storedata {
  $tkey.'.type' => $typeof},   $tkey.'.type' => $typeof},
  $tudom,$tuname) eq 'ok') {   $tudom,$tuname) eq 'ok') {
     &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);      &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
     $r->print('<br />'.&mt('Stored modified parameter for').' '.      $r->print('<br />'.&mt('Saved modified parameter for').' '.
       &Apache::loncommon::plainname($tuname,$tudom));        &Apache::loncommon::plainname($tuname,$tudom));
  } else {   } else {
     $r->print('<div class="LC_error">'.      $r->print('<div class="LC_error">'.
       &mt('Error storing parameters').'</div>');        &mt('Error saving parameters').'</div>');
  }   }
  &Apache::lonnet::devalidateuserresdata($tuname,$tudom);   &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
     } else {      } else {
Line 2443  sub storedata { Line 2475  sub storedata {
  $tkey.'.type' => $typeof},   $tkey.'.type' => $typeof},
  $tudom,$tuname) eq 'ok') {   $tudom,$tuname) eq 'ok') {
     &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);      &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
     $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));      $r->print('<br />'.&mt('Saved modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
  } else {   } else {
     $r->print('<div class="LC_error">'.      $r->print('<div class="LC_error">'.
       &mt('Error storing parameters').'</div>');        &mt('Error saving parameters').'</div>');
  }   }
  &Apache::lonnet::devalidateuserresdata($tuname,$tudom);   &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
     } else {      } else {
Line 2475  sub storedata { Line 2507  sub storedata {
     if ($putentries) {      if ($putentries) {
  if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {   if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
     &log_parmset(\%newdata,0);      &log_parmset(\%newdata,0);
     $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');      $r->print('<h3>'.&mt('Saved [_1] parameter(s)',$putentries/2).'</h3>');
  } else {   } else {
     $r->print('<div class="LC_error">'.      $r->print('<div class="LC_error">'.
       &mt('Error storing parameters').'</div>');        &mt('Error saving parameters').'</div>');
  }   }
  &Apache::lonnet::devalidatecourseresdata($crs,$dom);   &Apache::lonnet::devalidatecourseresdata($crs,$dom);
     }      }
Line 2486  sub storedata { Line 2518  sub storedata {
   
 sub extractuser {  sub extractuser {
     my $key=shift;      my $key=shift;
     return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);      return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
 }  }
   
 sub listdata {  sub listdata {
Line 2544  sub listdata { Line 2576  sub listdata {
     my $section=&mt('All Students');      my $section=&mt('All Students');
     if ($middle=~/^\[(.*)\]/) {      if ($middle=~/^\[(.*)\]/) {
  my $issection=$1;   my $issection=$1;
  if ($issection=~/^useropt\:(\w+)\:(\w+)/) {   if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
     $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);      $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
  } else {   } else {
     $section=&mt('Group/Section').': '.$issection;      $section=&mt('Group/Section').': '.$issection;
Line 2759  ENDOVER Line 2791  ENDOVER
  &listdata($r,$resourcedata,$listdata,$sortorder);   &listdata($r,$resourcedata,$listdata,$sortorder);
     }      }
     $r->print(&tableend().      $r->print(&tableend().
      ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').       ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'').
       '</form>'.&Apache::loncommon::end_page());        '</form>'.&Apache::loncommon::end_page());
 }  }
   
Line 2875  ENDOVER Line 2907  ENDOVER
       '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>'      );        '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>'      );
           
     $r->print('<td>');      $r->print('<td>');
       my $display_value = $resourcedata->{$thiskey};
       if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
    $display_value = 
       &Apache::lonlocal::locallocaltime($display_value);
       }
     $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',      $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
   &standard_parameter_names($data{'parameter_name'}),    &standard_parameter_names($data{'parameter_name'}),
   $resourcedata->{$thiskey}));    $resourcedata->{$thiskey}));
Line 2899  ENDOVER Line 2936  ENDOVER
  $r->print(&mt('Resource: [_1] <br />&nbsp;&nbsp;&nbsp;with ID: [_2] <br />&nbsp;&nbsp;&nbsp;in folder [_3]',   $r->print(&mt('Resource: [_1] <br />&nbsp;&nbsp;&nbsp;with ID: [_2] <br />&nbsp;&nbsp;&nbsp;in folder [_3]',
       $url,$resid,$map));        $url,$resid,$map));
     }      }
     $r->print(&mt('Part: [_1]',$data{'parameter_part'}));      $r->print(' <br />&nbsp;&nbsp;&nbsp;'.&mt('Part: [_1]',$data{'parameter_part'}));
     $r->print('</td></tr>');      $r->print('</td></tr>');
   
  }   }
Line 2918  sub parse_key { Line 2955  sub parse_key {
     $data{'scope_type'} = 'all';      $data{'scope_type'} = 'all';
     if ($middle=~/^\[(.*)\]/) {      if ($middle=~/^\[(.*)\]/) {
         $data{'scope'} = $1;          $data{'scope'} = $1;
  if ($data{'scope'}=~/^useropt\:(\w+)\:(\w+)/) {   if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
     $data{'scope_type'} = 'user';      $data{'scope_type'} = 'user';
     $data{'scope'} = [$1,$2];      $data{'scope'} = [$1,$2];
  } else {   } else {
Line 3197  sub output_row { Line 3234  sub output_row {
         $values = '';          $values = '';
     }      }
     if (!($options =~ /deleted/)) {      if (!($options =~ /deleted/)) {
         $output.='<strong>'.$field_text.':</strong>';  
         $output.='<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /><br />';  
   
         my @options= ( ['active', 'Show to student'],          my @options= ( ['active', 'Show to student'],
    ['onlyone','Student may select only one choice'],                      ['stuadd', 'Provide text area for students to type catalog information'],
    ['stuadd', 'Student may type choices']);                      ['choices','Provide choices for students to select from']);
   #   ['onlyone','Student may select only one choice']);
         if ($added_flag) {          if ($added_flag) {
             push @options,['deleted', 'Delete Metadata Field'];              push @options,['deleted', 'Delete Metadata Field'];
         }          }
          $output = &Apache::loncommon::start_data_table_row();
           $output .= '<td><span class="LC_metadata"><strong>'.$field_text.':</strong></span></td>';
           $output .= &Apache::loncommon::end_data_table_row();
         foreach my $opt (@options) {          foreach my $opt (@options) {
     my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;      my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
     $output.=('&nbsp;'x5).'<label><input type="checkbox" name="'.      $output .= &Apache::loncommon::continue_data_table_row();
         $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.      $output .= '<td>'.('&nbsp;' x 5).'<span class="LC_metadata"><label>
         &mt($opt->[1]).'</label> <br />';                 <input type="checkbox" name="'.
  }                 $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
                  &mt($opt->[1]).'</label></span> </td>';
       $output .= &Apache::loncommon::end_data_table_row();
    }
           $output .= &Apache::loncommon::continue_data_table_row();
           $output .= '<td>'.('&nbsp;' x 10).'<span class="LC_metadata"><input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></span></td>';
           $output .= &Apache::loncommon::end_data_table_row();
           my $multiple_checked;
           my $single_checked;
           if ($options =~ m/onlyone/) {
               $multiple_checked = "";
               $single_checked = " CHECKED ";
           } else {
               $multiple_checked = " CHECKED ";
               $single_checked = "";
           }
    $output .= &Apache::loncommon::continue_data_table_row();
    $output .= '<td>'.('&nbsp;' x 10).'<span class="LC_metadata">
               <input type="radio" name="'.$field_name.'_onlyone" value="multiple" '.$multiple_checked .'/>
               Student may select multiple choices from list</span></td>';
    $output .= &Apache::loncommon::end_data_table_row();
    $output .= &Apache::loncommon::continue_data_table_row();
    $output .= '<td>'.('&nbsp;' x 10).'<span class="LC_metadata">
               <input type="radio" name="'.$field_name.'_onlyone"  value="single" '.$single_checked.'/>
               Student may select only one choice from list</span></td>';
    $output .= &Apache::loncommon::end_data_table_row();
     }      }
     return ($output);      return ($output);
 }  }
Line 3221  sub order_meta_fields { Line 3284  sub order_meta_fields {
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};      my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
     $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));      $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata Fields'));      &Apache::lonhtmlcommon::add_breadcrumb
               ({href=>"/adm/parmset?action=setrestrictmeta",
                 text=>"Restrict Metadata"},
                {text=>"Order Metadata"});
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
     if ($env{'form.storeorder'}) {      if ($env{'form.storeorder'}) {
         my $newpos = $env{'form.newpos'} - 1;          my $newpos = $env{'form.newpos'} - 1;
         my $currentpos = $env{'form.currentpos'} - 1;          my $currentpos = $env{'form.currentpos'} - 1;
Line 3254  sub order_meta_fields { Line 3321  sub order_meta_fields {
        }         }
         }          }
  my $ordered_fields = join ",", @neworder;   my $ordered_fields = join ",", @neworder;
           my $put_result = &Apache::lonnet::put('environment',
                              {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
  &Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields);   &Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields);
     }      }
     my $fields = &get_added_meta_fieldnames();      my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
     my $ordered_fields;      my $ordered_fields;
     my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};      my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
     if (!@fields_in_order) {      if (!@fields_in_order) {
Line 3291  sub order_meta_fields { Line 3360  sub order_meta_fields {
     $r->print('</table>');      $r->print('</table>');
     return 'ok';      return 'ok';
 }  }
   sub continue {
       my $output;
       $output .= '<form action="" method="post">';
       $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
       $output .= '<input type="submit" value="Continue" />';
       return ($output);
   }
 sub addmetafield {  sub addmetafield {
     my ($r)=@_;      my ($r)=@_;
     $r->print(&Apache::loncommon::start_page('Add Metadata Field'));      $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
Line 3298  sub addmetafield { Line 3374  sub addmetafield {
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};      my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};      my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
     if (exists($env{'form.undelete'})) {      if (exists($env{'form.undelete'})) {
         my @meta_fields = &Apache::loncommon::get_env_multiple('form.undelete');          my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
         foreach my $meta_field(@meta_fields) {          foreach my $meta_field(@meta_fields) {
             my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};              my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
             $options =~ s/deleted//;              $options =~ s/deleted//;
Line 3308  sub addmetafield { Line 3384  sub addmetafield {
                                                                                   
             $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');              $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');
         }          }
         $r->print('<form action="" method="post">');          $r->print(&continue());
         $r->print('<input type="hidden" name="action" value="setrestrictmeta" />');  
         $r->print('<input type="submit" value="Continue" />');  
     } elsif (exists($env{'form.fieldname'})) {      } elsif (exists($env{'form.fieldname'})) {
         my $meta_field = $env{'form.fieldname'};          my $meta_field = $env{'form.fieldname'};
         my $display_field = $env{'form.fieldname'};          my $display_field = $env{'form.fieldname'};
Line 3320  sub addmetafield { Line 3394  sub addmetafield {
                             {'metadata.'.$meta_field.'.values'=>"",                              {'metadata.'.$meta_field.'.values'=>"",
                              'metadata.'.$meta_field.'.added'=>"$display_field",                               'metadata.'.$meta_field.'.added'=>"$display_field",
                              'metadata.'.$meta_field.'.options'=>""},$dom,$crs);                               'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
         $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result);          $r->print('Added new Metadata Field <strong>'.$env{'form.fieldname'}."</strong> with result ".$put_result.'<br />');
           $r->print(&continue());
     } else {      } else {
         my $fields = &get_deleted_meta_fieldnames();          my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
         if ($fields) {          if ($fields) {
             $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');              $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');
             $r->print('<form method="post" action="">');              $r->print('<form method="post" action="">');
             foreach my $key(keys(%$fields)) {              foreach my $key(keys(%$fields)) {
                 $r->print('<input type="checkbox" name="undelete" value="'.$key.'" />'.$$fields{$key}.'<br /');                  $r->print('<input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'<br /');
             }              }
             $r->print('<input type="submit" name="undelete" value="Undelete" />');              $r->print('<input type="submit" name="undelete" value="Undelete" />');
             $r->print('</form>');              $r->print('</form>');
Line 3335  sub addmetafield { Line 3410  sub addmetafield {
         $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');          $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');
         $r->print('<input type="text" name="fieldname" /><br />');          $r->print('<input type="text" name="fieldname" /><br />');
         $r->print('<input type="submit" value="Add Metadata Field" />');          $r->print('<input type="submit" value="Add Metadata Field" />');
         $r->print('</form>');  
     }      }
       $r->print('</form>');
 }  }
 sub setrestrictmeta {  sub setrestrictmeta {
     my ($r)=@_;      my ($r)=@_;
Line 3361  sub setrestrictmeta { Line 3436  sub setrestrictmeta {
                if ($env{'form.'.$meta_field.'_stuadd'}) {                 if ($env{'form.'.$meta_field.'_stuadd'}) {
                    $options.='stuadd,';                     $options.='stuadd,';
                }                  } 
                if ($env{'form.'.$meta_field.'_onlyone'}) {                 if ($env{'form.'.$meta_field.'_choices'}) {
                      $options.='choices,';
                  } 
                  if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
                    $options.='onlyone,';                     $options.='onlyone,';
                }                  } 
                if ($env{'form.'.$meta_field.'_active'}) {                 if ($env{'form.'.$meta_field.'_active'}) {
Line 3370  sub setrestrictmeta { Line 3448  sub setrestrictmeta {
                if ($env{'form.'.$meta_field.'_deleted'}) {                 if ($env{'form.'.$meta_field.'_deleted'}) {
                    $options.='deleted,';                     $options.='deleted,';
                }                 }
                  
                     my $name = $save_field;                      my $name = $save_field;
                      $put_result = &Apache::lonnet::put('environment',                       $put_result = &Apache::lonnet::put('environment',
                                                   {'metadata.'.$meta_field.'.options'=>$options,                                                    {'metadata.'.$meta_field.'.options'=>$options,
Line 3385  sub setrestrictmeta { Line 3462  sub setrestrictmeta {
     # Get the default metadata fields      # Get the default metadata fields
     my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');      my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
     # Now get possible added metadata fields      # Now get possible added metadata fields
     my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields);      my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
       my $row_alt = 1;
       $output .= &Apache::loncommon::start_data_table();
     foreach my $field (sort(keys(%metadata_fields))) {      foreach my $field (sort(keys(%metadata_fields))) {
         if ($field ne 'courserestricted') {          if ($field ne 'courserestricted') {
               $row_alt = $row_alt ? 0 : 1;
     $output.= &output_row($r, $field, $metadata_fields{$field});      $output.= &output_row($r, $field, $metadata_fields{$field});
  }   }
     }      }
       my $buttons = (<<ENDButtons);
           <input type="submit" name="restrictmeta" value="Save" />
           </form><br />
           <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
           <input type="submit" name="restrictmeta" value="Add a Metadata Field" />
           </form>
           <br />
           <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
           <input type="submit" name="restrictmeta" value="Order Metadata Fields" />
   ENDButtons
     my $added_flag = 1;      my $added_flag = 1;
     foreach my $field (sort(keys(%$added_metadata_fields))) {      foreach my $field (sort(keys(%$added_metadata_fields))) {
         $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag);          $row_alt = $row_alt ? 0 : 1;
           $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt);
     }      }
       $output .= &Apache::loncommon::end_data_table();
     $r->print(<<ENDenv);             $r->print(<<ENDenv);       
         <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">          <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
         <p>  
         $output          $output
         <input type="submit" name="restrictmeta" value="Update Metadata Restrictions">          $buttons
         </form><br />  
         <form method="post" action="/adm/parmset?action=addmetadata" name="form">  
         <input type="submit" name="restrictmeta" value="Add a Metadata Field">  
         </form>  
         </form><br />  
         <form method="post" action="/adm/parmset?action=ordermetadata" name="form">  
         <input type="submit" name="restrictmeta" value="Order Metadata Fields">  
         </form>          </form>
 ENDenv  ENDenv
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
Line 3414  ENDenv Line 3498  ENDenv
 }  }
 ##################################################  ##################################################
 sub get_added_meta_fieldnames {  sub get_added_meta_fieldnames {
       my ($cid) = @_;
     my %fields;      my %fields;
     foreach my $key(%env) {      foreach my $key(%env) {
         if ($key =~ m/\.metadata\.(.+)\.added$/) {          if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
             my $field_name = $1;              my $field_name = $1;
             my ($display_field_name) = $env{$key};              my ($display_field_name) = $env{$key};
             $fields{$field_name} = $display_field_name;              $fields{$field_name} = $display_field_name;
Line 3425  sub get_added_meta_fieldnames { Line 3510  sub get_added_meta_fieldnames {
     return \%fields;      return \%fields;
 }  }
 sub get_deleted_meta_fieldnames {  sub get_deleted_meta_fieldnames {
       my ($cid) = @_;
     my %fields;      my %fields;
     my ($default_fields) = @_;  
     foreach my $key(%env) {      foreach my $key(%env) {
         if ($key =~ m/\.metadata\.(.+)\.added$/) {          if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
             my $field_name = $1;              my $field_name = $1;
             if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {              if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
                 my ($display_field_name) = $env{$key};                  my ($display_field_name) = $env{$key};
Line 3593  ENDYESNO Line 3678  ENDYESNO
     }      }
     $r->print(&Apache::loncommon::end_data_table().      $r->print(&Apache::loncommon::end_data_table().
       "\n<input type='submit' name='storerules' value='".        "\n<input type='submit' name='storerules' value='".
       &mt('Store Rules')."' /></form>\n".        &mt('Save Rules')."' /></form>\n".
       &Apache::loncommon::end_page());        &Apache::loncommon::end_page());
     return;      return;
 }  }
Line 3690  sub parm_change_log { Line 3775  sub parm_change_log {
                                               \%saveable_parameters);                                                \%saveable_parameters);
     &Apache::loncommon::restore_course_settings('parameter_log',      &Apache::loncommon::restore_course_settings('parameter_log',
                                                 \%saveable_parameters);                                                  \%saveable_parameters);
     if (!$env{'form.show'}) { $env{'form.show'}=10; }      $r->print(&Apache::loncommon::display_filter().
   
     my $countselect =  
  &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,  
     (&mt('all'),10,20,50,100,1000,10000));  
   
     $r->print('<nobr>'.&mt('[_1] Records',$countselect).'</nobr>'.  
               '<label>'.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').                '<label>'.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').
       ' '.&mt('Include parameter types').'</label>'.        ' '.&mt('Include parameter types').'</label>'.
       '<input type="submit" value="'.&mt('Display').'" /></form>');        '<input type="submit" value="'.&mt('Display').'" /></form>');
Line 3708  sub parm_change_log { Line 3787  sub parm_change_log {
       &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.        &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.
       &Apache::loncommon::end_data_table_header_row());        &Apache::loncommon::end_data_table_header_row());
     my $shown=0;      my $shown=0;
     foreach my $id (sort { $parmlog{$b}{'exe_time'}<=>$parmlog{$a}{'exe_time'} } (keys(%parmlog))) {      my $folder='';
       if ($env{'form.displayfilter'} eq 'currentfolder') {
    my $last='';
    if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
    &GDBM_READER(),0640)) {
       $last=$hash{'last_known'};
       untie(%hash);
    }
    if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
       }
       foreach my $id (sort 
       {
    if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
       return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
    }
    my $aid = (split('00000',$a))[-1];
    my $bid = (split('00000',$b))[-1];
    return $bid<=>$aid;
       } (keys(%parmlog))) {
         my @changes=keys(%{$parmlog{$id}{'logentry'}});          my @changes=keys(%{$parmlog{$id}{'logentry'}});
  my $count = 0;   my $count = 0;
  my $time =   my $time =
Line 3729  sub parm_change_log { Line 3826  sub parm_change_log {
    $parmlog{$id}{'exe_udom'});     $parmlog{$id}{'exe_udom'});
  }   }
  my $row_start=&Apache::loncommon::start_data_table_row();   my $row_start=&Apache::loncommon::start_data_table_row();
  $r->print($row_start);  
  my $makenewrow=0;   my $makenewrow=0;
  my %istype=();   my %istype=();
  my $output;   my $output;
Line 3739  sub parm_change_log { Line 3835  sub parm_change_log {
     !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));      !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
             my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=              my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
  &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);   &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
       if ($env{'form.displayfilter'} eq 'currentfolder') {
    if ($folder) {
       if ($middle!~/^\Q$folder\E/) { next; }
    }
       }
     if ($typeflag) {      if ($typeflag) {
  $istype{$parmname}=$value;    $istype{$parmname}=$value; 
  if (!$env{'form.includetypes'}) { next; }    if (!$env{'form.includetypes'}) { next; } 
Line 3791  sub parm_change_log { Line 3892  sub parm_change_log {
     }      }
     $output .= '</td>'.&Apache::loncommon::end_data_table_row();      $output .= '</td>'.&Apache::loncommon::end_data_table_row();
  }   }
  $r->print('<td rowspan="'.$count.'">'.$time.'</td>          if ($env{'form.displayfilter'} eq 'containing') {
       my $wholeentry=$about_me_link.':'.
    $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
    $output;
       if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }        
    }
           if ($count) {
       $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
                        <td rowspan="'.$count.'">'.$about_me_link.                         <td rowspan="'.$count.'">'.$about_me_link.
   '<br /><tt>'.$parmlog{$id}{'exe_uname'}.    '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
           ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.            ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
   $send_msg_link.'</td>'.$output);    $send_msg_link.'</td>'.$output);
       $shown++;
  $shown++;   }
  if (!($env{'form.show'} eq &mt('all')    if (!($env{'form.show'} eq &mt('all') 
       || $shown<=$env{'form.show'})) { last; }        || $shown<=$env{'form.show'})) { last; }
     }      }
Line 3805  sub parm_change_log { Line 3913  sub parm_change_log {
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
 }  }
   
   sub check_for_course_info {
       my $navmap = Apache::lonnavmaps::navmap->new();
       return 1 if ($navmap);
       return 0;
   }
   
 ##################################################  ##################################################
 ##################################################  ##################################################
   
Line 3848  sub handler { Line 3962  sub handler {
  (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||   (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
  &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.   &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
   $env{'request.course.sec'}));    $env{'request.course.sec'}));
     if ($env{'request.course.id'} &&  $parm_permission) {      my $exists = &check_for_course_info();
   
       if ($env{'request.course.id'} &&  $parm_permission && $exists) {
   
         # Start Page          # Start Page
         &Apache::loncommon::content_type($r,'text/html');          &Apache::loncommon::content_type($r,'text/html');
Line 3918  sub handler { Line 4034  sub handler {
  }          }       
     } else {      } else {
 # ----------------------------- Not in a course, or not allowed to modify parms  # ----------------------------- Not in a course, or not allowed to modify parms
  $env{'user.error.msg'}=   if ($exists) {
     "/adm/parmset:opa:0:0:Cannot modify assessment parameters";      $env{'user.error.msg'}=
    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
    } else {
       $env{'user.error.msg'}=
    "/adm/parmset::0:1:Course environment gone, reinitialize the course";
    }
  return HTTP_NOT_ACCEPTABLE;   return HTTP_NOT_ACCEPTABLE;
     }      }
     return OK;      return OK;

Removed from v.1.342  
changed lines
  Added in v.1.365


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