Diff for /loncom/interface/lonpickcourse.pm between versions 1.93 and 1.100

version 1.93, 2010/03/08 14:43:46 version 1.100, 2010/09/23 21:50:37
Line 140  sub handler { Line 140  sub handler {
 # ------------------------------------------ Display of filters to limit search  # ------------------------------------------ Display of filters to limit search
     my $filter = {};      my $filter = {};
     my $action = '/adm/pickcourse';      my $action = '/adm/pickcourse';
     my ($numtitles,$showroles,$nohost);      my ($numtitles,$showroles,$nohost,@codetitles);
     if (!$onlyown) {      if (!$onlyown) {
         my $filterlist = ['domainfilter','descriptfilter',          my $filterlist = ['domainfilter'];
                           'instcodefilter'];          # created filter for DCs only
           if ($env{'user.adv'} && $env{'form.domainfilter'} &&
               exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
               && $env{'form.form'} ne 'portform') {
               my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
               if ($loncaparev ne 'unknown_cmd') {
                   push(@{$filterlist},'createdfilter');
               }
           }
           push(@{$filterlist},('descriptfilter','instcodefilter'));
         if ($env{'form.form'} eq 'rules') {          if ($env{'form.form'} eq 'rules') {
             push(@{$filterlist},'personfilter');              push(@{$filterlist},'personfilter');
             if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {              if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
Line 168  sub handler { Line 177  sub handler {
   
         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,          $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
                                  $filter,$action,\$numtitles,undef,$cloneruname,                                   $filter,$action,\$numtitles,undef,$cloneruname,
                                  $clonerudom,$typeelement));                                   $clonerudom,$typeelement,\@codetitles));
     }      }
   
 # ---------------------------------------------------------------- Get the data  # ---------------------------------------------------------------- Get the data
     if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||       if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) || 
          $onlyown) {           $onlyown) {
           my $domcloner;
           if ($env{'form.form'} eq 'ccrs') {
               if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) &&
                   (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
                   $domcloner = 1;
               }
           }
         my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,          my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
                                       $cloneruname,$clonerudom);                                        $cloneruname,$clonerudom,$domcloner,\@codetitles);
         if ($nohost) {          if ($nohost) {
             $r->print ('<span class="LC_warning">'.              $r->print ('<span class="LC_warning">'.
                        &mt('User does not exist - username: [_1], domain: [_2].',                         &mt('User does not exist - username: [_1], domain: [_2].',
Line 396  sub display_matched_courses { Line 412  sub display_matched_courses {
                 $instcode = $courses{$course}{'inst_code'};                  $instcode = $courses{$course}{'inst_code'};
                 $ttype = $courses{$course}{'type'};                  $ttype = $courses{$course}{'type'};
                 if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {                  if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
                     if ($cc_cloneable{$courses{$course}{'cnum'}.':'.$courses{$course}{'domain'}}) {                      if ($env{'form.form'} eq 'ccrs') {
                         $canclone = 1;                          if (($env{'request.role.domain'} eq $cdom) &&
                               (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
                               $canclone = 1;
                           }
                       }
                       unless ($canclone) { 
                           if ($cc_cloneable{$cnum.':'.$cdom}) {
                               $canclone = 1;
                           }
                     }                      }
                     unless ($canclone) {                      unless ($canclone) {
                         my $cloners = $courses{$course}{'cloners'};                          my $cloners = $courses{$course}{'cloners'};
Line 406  sub display_matched_courses { Line 430  sub display_matched_courses {
                             if (grep(/^\*$/,@cloneable)) {                              if (grep(/^\*$/,@cloneable)) {
                                 $canclone = 1;                                  $canclone = 1;
                             }                              }
                             if (grep(/^\*:\Q$env{'form.clonerudom'}\E$/,@cloneable)) {                              if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) {
                                 $canclone = 1;                                  $canclone = 1;
                             }                              }
                             if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {                              if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
Line 519  sub multiples_tag { Line 543  sub multiples_tag {
   
 sub build_filters {  sub build_filters {
     my ($filterlist,$type,$roleelement,$multelement,$filter,$action,      my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
         $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement) = @_;          $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_;
     my ($list,$formname,$fixeddom,$codedom,$jscript);      my ($list,$formname,$fixeddom,$codedom,$jscript);
     $codedom = $env{'request.role.domain'};      $codedom = $env{'request.role.domain'};
     if (defined($env{'form.form'})) {      if (defined($env{'form.form'})) {
Line 527  sub build_filters { Line 551  sub build_filters {
     } else {      } else {
         $formname = $caller;          $formname = $caller;
     }      }
     my $onchange;      my $onchange = 'javascript:updateFilters(this)';
     unless ($env{'form.interface'} eq 'textual') {      my ($domainselectform,$sincefilterform,$createdfilterform,
         $onchange = 'javascript:updateFilters(this)';          $ownerdomselectform,$persondomselectform,$instcodeform,
     }          $typeselectform,$instcodetitle);
     my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,  
         $instcodeform,$typeselectform,$instcodetitle);  
     foreach my $item (@{$filterlist}) {      foreach my $item (@{$filterlist}) {
         $filter->{$item} = $env{'form.'.$item};          $filter->{$item} = $env{'form.'.$item};
         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {          if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
Line 595  sub build_filters { Line 617  sub build_filters {
     }      }
   
     # last course activity filter and selection      # last course activity filter and selection
     $filter->{'sincefilter'} = $env{'form.sincefilter'};      $sincefilterform = &timebased_select_form('sincefilter',$filter);
     $filter->{'sincefilter'} =~ s/[^\d-]//g;  
     if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }      # course created filter and selection
     $sincefilterform=&Apache::loncommon::select_form(      if (exists($filter->{'createdfilter'})) {
         $filter->{'sincefilter'},          $createdfilterform = &timebased_select_form('createdfilter',$filter);
         'sincefilter',      }
         (      '-1' => '',  
             '86400' => &mt('today'),  
            '604800' => &mt('last week'),  
           '2592000' => &mt('last month'),  
           '7776000' => &mt('last three months'),  
          '15552000' => &mt('last six months'),  
          '31104000' => &mt('last year'),  
          'select_form_order' =>  
             ['-1','86400','604800','2592000','7776000',  
              '15552000','31104000']));  
   
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                 'cac' => "$type Activity",                  'cac' => "$type Activity",
                   'ccr' => "$type Created", 
                 'cde' => "$type Title",                  'cde' => "$type Title",
                 'cdo' => "$type Domain",                  'cdo' => "$type Domain",
                 'ins' => 'Institutional Code',                  'ins' => 'Institutional Code',
Line 664  sub build_filters { Line 677  sub build_filters {
                 || ($formname eq 'modifycourse')) {                  || ($formname eq 'modifycourse')) {
                 $officialjs = 1;                  $officialjs = 1;
                 ($instcodeform,$jscript,$$numtitlesref) =                   ($instcodeform,$jscript,$$numtitlesref) = 
                     &instcode_selectors($codedom,'filterpicker',$officialjs);                      &instcode_selectors($codedom,'filterpicker',$officialjs,$codetitlesref);
                 if ($jscript) {                  if ($jscript) {
                     $jscript = '<script type="text/javascript" language="Javascript">'.                      $jscript = '<script type="text/javascript" language="Javascript">'.
                                $jscript.'</script>'."\n";                                 $jscript.'</script>'."\n";
Line 719  $typeelement Line 732  $typeelement
                   .$sincefilterform                    .$sincefilterform
                   .&Apache::lonhtmlcommon::row_closure();                    .&Apache::lonhtmlcommon::row_closure();
     }      }
       if ($createdfilterform) {
           $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
                     .$createdfilterform
                     .&Apache::lonhtmlcommon::row_closure();
       }
     if ($domainselectform) {      if ($domainselectform) {
         $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})          $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
                   .$domainselectform                    .$domainselectform
Line 788  $typeelement Line 806  $typeelement
     return $jscript.$warning.$output;      return $jscript.$warning.$output;
 }  }
   
   sub timebased_select_form {
       my ($item,$filter) = @_;
       if (ref($filter) eq 'HASH') {
           $filter->{$item} = $env{'form.'.$item};
           $filter->{$item} =~ s/[^\d-]//g;
           if (!$filter->{$item}) { $filter->{$item}=-1; }
           return &Apache::loncommon::select_form( 
                               $filter->{$item},
                               $item,
                               {      '-1' => '',
                                   '86400' => &mt('today'),
                                  '604800' => &mt('last week'),
                                 '2592000' => &mt('last month'),
                                 '7776000' => &mt('last three months'),
                                '15552000' => &mt('last six months'),
                                '31104000' => &mt('last year'),
                       'select_form_order' =>
                              ['-1','86400','604800','2592000','7776000',
                               '15552000','31104000']});
       }
   }
   
 sub get_coordinator_cloneable {  sub get_coordinator_cloneable {
     my ($cloneruname,$clonerudom,$type) = @_;      my ($cloneruname,$clonerudom,$type) = @_;
     if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {      if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
           my $warning = '<div class="LC_warning">'.&mt('Intended course owner not specified').
                      '</div>';
           return ('',$warning);
       } elsif (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
         my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').          my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
                    '</div>';                     '</div>';
         return ('',$warning);          return ('',$warning);
Line 813  sub get_coordinator_cloneable { Line 857  sub get_coordinator_cloneable {
 }  }
   
 sub instcode_selectors {  sub instcode_selectors {
     my ($codedom,$formname,$officialjs) = @_;      my ($codedom,$formname,$officialjs,$codetitles) = @_;
     my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);      my ($output,%cat_titles,%cat_order,%cat_items);
     my ($jscript,$totcodes,$numtitles,$lasttitle) =      my ($jscript,$totcodes,$numtitles,$lasttitle) =
         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,          &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
                            \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);                             \%cat_items,$codetitles,\%cat_titles,\%cat_order,$officialjs);
     if ($numtitles > 0) {      if ($numtitles > 0) {
         my $official = ' checked="checked" ';          my $official = ' checked="checked" ';
         my $unofficial = '';          my $unofficial = '';
Line 831  sub instcode_selectors { Line 875  sub instcode_selectors {
                    '<input type="radio" name="official" value="off"'.$unofficial.                     '<input type="radio" name="official" value="off"'.$unofficial.
                    ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.                     ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
                    &Apache::courseclassifier::build_instcode_selectors($numtitles,                     &Apache::courseclassifier::build_instcode_selectors($numtitles,
                    $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".                     $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order)."\n".
                    '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".                     '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
                    '<input type="hidden" name="state" value="listing" />'."\n";                     '<input type="hidden" name="state" value="listing" />'."\n";
     
Line 840  sub instcode_selectors { Line 884  sub instcode_selectors {
 }  }
   
 sub search_courses {  sub search_courses {
     my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom) = @_;      my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
     my (%courses,%showcourses,$cloner,$ccrole);      my (%courses,%showcourses,$cloner,$ccrole);
     if ($type eq 'Community') {      if ($type eq 'Community') {
         $ccrole = 'co';          $ccrole = 'co';
Line 860  sub search_courses { Line 904  sub search_courses {
                 $filter->{$item}='.';                  $filter->{$item}='.';
             }              }
         }          }
           my $now = time;
         my $timefilter =           my $timefilter = 
            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});             ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
           my ($createdbefore,$createdafter);
           if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
               $createdbefore = $now;
               $createdafter = $now-$filter->{'createdfilter'};
           }
         my ($instcodefilter,$regexpok);          my ($instcodefilter,$regexpok);
         if ($numtitles) {          if ($numtitles) {
             if ($env{'form.official'} eq 'on') {              if ($env{'form.official'} eq 'on') {
                 $instcodefilter =                   $instcodefilter = 
                     &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);                      &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
                 $regexpok = 1;                  $regexpok = 1;
             } elsif ($env{'form.official'} eq 'off') {              } elsif ($env{'form.official'} eq 'off') {
                 $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);                  $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
                 unless ($instcodefilter eq '') {                  unless ($instcodefilter eq '') {
                     $regexpok = -1;                      $regexpok = -1;
                 }                  }
Line 892  sub search_courses { Line 942  sub search_courses {
                                           $filter->{'coursefilter'},                                            $filter->{'coursefilter'},
                                           undef,undef,$type,$regexpok,undef,undef,                                            undef,undef,$type,$regexpok,undef,undef,
                                           undef,undef,$cloner,$env{'form.cc_clone'},                                            undef,undef,$cloner,$env{'form.cc_clone'},
                                           $filter->{'cloneableonly'});                                            $filter->{'cloneableonly'},
                                             $createdbefore,$createdafter,undef,
                                             $domcloner);
         if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {          if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
             my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},              my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
                                                          $filter->{'persondomfilter'},                                                           $filter->{'persondomfilter'},
Line 1161  Side Effects: None Line 1213  Side Effects: None
   
 =item *  =item *
 X<build_filters()>  X<build_filters()>
 B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem)>:  B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem,$codetitlesref>:
   
   
 Input: 11 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm), username and domain of new course owner who wants to clone, $tyepelem   Input: 12 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm); username and domain of new course owner who wants to clone, $typeelem; reference to array of titles of components in institutional codes (official courses). 
   
 Output: 1 - $output - HTML for display of search criteria, and hidden form elements.   Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
   
Line 1172  Side Effects: None Line 1224  Side Effects: None
   
 =item *  =item *
 X<search_courses()>  X<search_courses()>
 B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom)>:  B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,
                    $domcloner,$codetitles)>:
   
   
 Input: 7 -  request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Last two needed when search is for courses to clone from course request form, or course creation form (DC).     Input: 9 -  request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Seventh and eighth needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in  
   domain being filtered by (used when DC is using course creation form). Ninth is reference to array of titles of components in institutional codes (official courses).
   
 Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.  Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
   

Removed from v.1.93  
changed lines
  Added in v.1.100


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