Annotation of loncom/interface/lonpickcourse.pm, revision 1.54

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.54    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.53 2006/11/03 18:42:11 raeburn Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonpickcourse;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::loncoursedata;
                     35: use Apache::lonnet;
1.8       www        36: use Apache::lonlocal;
1.46      raeburn    37: use Apache::longroup;
1.47      www        38: use lib '/home/httpd/lib/perl/';
                     39: use LONCAPA;
1.1       www        40: 
                     41: sub handler {
                     42:     my $r = shift;
1.8       www        43:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        44:     $r->send_http_header;
                     45:     return OK if $r->header_only;
                     46: 
                     47: # ------------------------------------------------------------ Print the screen
1.40      albertel   48: 
1.5       www        49: # Get parameters from query string
1.1       www        50:     &Apache::loncommon::get_unprocessed_cgi
                     51:         ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
1.13      albertel   52: 			       'sincefilter','form','cnumelement',
1.19      raeburn    53: 			       'cdomelement','cnameelement','roleelement',
1.28      raeburn    54:                                'pickedcourse','instcodefilter',
1.48      raeburn    55:                                'ownerfilter','coursefilter','multiple',
1.52      raeburn    56:                                'type','ownerdomfilter']);
1.54    ! raeburn    57: 
        !            58:     my ($type,$title,$jscript,$multelement,$multiple,$name_code,$name_input,
        !            59:         $roleelement);
        !            60:     $type = $env{'form.type'};
        !            61:     if (!defined($env{'form.type'})) {
        !            62:         $type = 'Course';
        !            63:     }
        !            64:     $title = &mt('Selecting a [_1]',$type);
        !            65: 
        !            66:     # Setup for multiple course selections, if flag for multiples set.
        !            67:     ($title,$jscript,$multelement,$multiple) = &multiples_tag($type,$title);
        !            68: 
        !            69:     if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
        !            70:         $name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.".
        !            71:                      "value=cdesc;";
        !            72:         $name_input ='<input type="hidden" name="cnameelement" value="'.
        !            73:                      $env{'form.cnameelement'}.'" />';
        !            74:     }
        !            75: 
        !            76:     my $submitopener = '';
        !            77:     my $autosubmit = '';
        !            78:     my $lastaction = 'self.close()';
        !            79:     if ($env{'form.form'} eq 'cu') {
        !            80:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
        !            81:                       'document.courselist.submit();';
        !            82:     }
        !            83:     if ($env{'form.form'} eq 'portform') {
        !            84:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
        !            85:                       'document.courselist.submit();';
        !            86:     }
        !            87:     my $roledom = $env{'form.roleelement'};
        !            88:     if ($roledom) {
        !            89:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
        !            90:         $submitopener = &Apache::lonroles::processpick();
        !            91:         $autosubmit = 'process_pick("'.$roledom.'")';
        !            92:     }
        !            93: 
        !            94:     my (%filter,%list);
        !            95:     my $filterdisplay;
        !            96:     my $onlyown = 0;
        !            97:     if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) {
        !            98:         $onlyown = 1;
        !            99:     } else {   
        !           100:         $filterdisplay = &build_filters($type,$name_input,$roleelement,
        !           101:                                         $multelement, \%filter,\%list);
        !           102:     }
1.19      raeburn   103: # if called from loncreateuser, report sections, then close
1.50      albertel  104:     my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist,
                    105: 	$accesslist,$accessnameslist);
1.49      raeburn   106:     my $sec_element = 'currsec';
                    107:     my $grplist_element = 'groups';
1.19      raeburn   108:     my $num_sections = 0;
1.49      raeburn   109:     my $num_groups = 0;
                    110:     my $num_roles = 0;
                    111:     my $num_access = 0;
                    112:     my ($cdom,$cnum);
                    113:     if ($env{'form.pickedcourse'}) {
                    114:         ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
                    115:     }
1.27      albertel  116:     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
1.42      albertel  117:         $loaditem{'onload'} ="setSections()";
1.49      raeburn   118:         ($seclist,$num_sections,$groupslist,$num_groups) = 
                    119:              &build_selection_lists($cdom,$cnum,$type,undef,undef,
                    120:                                     $env{'form.form'});
                    121:     }
                    122: # if called from portfolio, report roles, sections, groups and close
                    123:     my ($roles_element,$groups_element,$status_element,$setitems_function);
                    124:     if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) {
                    125:         $loaditem{'onload'} ="setItems()";
                    126:         ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
                    127:          $rolesnameslist,$accesslist,$num_access,$accessnameslist) =
1.54    ! raeburn   128:             &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'});
        !           129:         ($sec_element,$grplist_element,$setitems_function) = 
        !           130:             &setitems_javascript($seclist,$num_sections,$groupslist,$num_groups,
        !           131:                                  $roleslist,$num_roles,$rolesnameslist,
        !           132:                                  $accesslist,$num_access,$accessnameslist);
1.30      raeburn   133:     }
1.41      albertel  134:     $r->print(&Apache::loncommon::start_page($title,undef,
1.42      albertel  135: 					     {'add_entries' => \%loaditem,
1.41      albertel  136: 					      'no_nav_bar'  => 1, }));
1.48      raeburn   137:     my %elements = (
1.53      raeburn   138:                      'Course' => {
1.48      raeburn   139:                                  name  => 'coursepick',
                    140:                                  total => 'coursetotal',
                    141:                                  list  => 'courselist',
                    142:                                },
1.53      raeburn   143:                      'Non-standard course' => {
1.48      raeburn   144:                                  name  => 'grouppick',
                    145:                                  total => 'grouptotal',
                    146:                                  list  => 'grouplist',
                    147:                              },
                    148:                     );
1.54    ! raeburn   149:     my $setsec_func = &setsec_javascript($seclist,$sec_element,$grplist_element,
        !           150:                                          $groupslist,$num_sections);
1.1       www       151:     $r->print(<<ENDSCRIPT);
                    152: <script>
1.35      raeburn   153: function gochoose(cname,cdom,cdesc,multiple,caller) {
1.27      albertel  154:     var openerForm = "$env{'form.form'}";
1.30      raeburn   155:     courseCount = 0;
                    156:     var courses = '';
1.35      raeburn   157:     if (multiple) {
1.33      albertel  158: 	if (typeof(document.courselist.course_id.length) == 'undefined') {
                    159: 	    // only 1 course checkbox was created
                    160: 	    if (document.courselist.course_id.checked) {
                    161: 		courses = courses + document.courselist.course_id.value + "&&";
                    162: 		courseCount ++;
                    163: 	    }
                    164: 	} else {
                    165: 	    for (var j=0; j<document.courselist.course_id.length; j++) {
                    166: 		if (document.courselist.course_id[j].checked) {
                    167: 		    courses = courses + document.courselist.course_id[j].value + "&&";
                    168: 		    courseCount ++;
                    169: 		}
                    170: 	    }
                    171: 	} 
1.48      raeburn   172:         opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
                    173: 	if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
1.33      albertel  174: 	    'undefined') {
1.48      raeburn   175: 	    if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {  
                    176: 		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.33      albertel  177: 	    } else {
1.48      raeburn   178: 		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.33      albertel  179: 	    }
                    180: 	} else {
1.48      raeburn   181: 	    for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) { 
                    182: 		if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {  
                    183: 		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.34      albertel  184: 		} else {
1.48      raeburn   185: 		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.33      albertel  186: 		}
                    187: 	    }
                    188: 	}
                    189: 	if (courseCount > 0) {
                    190: 	    courses = courses.substr(0,courses.length-2);
1.48      raeburn   191: 	    opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
1.33      albertel  192: 	}
1.34      albertel  193:     } else {
1.30      raeburn   194:         $name_code
                    195:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
1.35      raeburn   196:         var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    197:         if (slct.options == undefined) {
1.30      raeburn   198:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
1.35      raeburn   199:         }
                    200:         else {
1.30      raeburn   201:             var i;
                    202:             for (i=0;i<slct.length;i++) {
                    203:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
                    204:             }
1.19      raeburn   205:         }
1.1       www       206:     }
1.18      raeburn   207:     $autosubmit
1.19      raeburn   208:     $lastaction
                    209: }
                    210: 
1.54    ! raeburn   211: $setsec_func
        !           212: 
        !           213: $setitems_function
        !           214: 
        !           215: $jscript
        !           216: </script>
        !           217: $submitopener
        !           218: ENDSCRIPT
        !           219:     $r->print($filterdisplay);
        !           220: 
        !           221: # ---------------------------------------------------------------- Get the data
        !           222:     if ($env{'form.gosearch'} || $onlyown) {
        !           223:         my %courses = &search_courses($r,$type,$onlyown,\%filter);
        !           224:         &display_matched_courses($r,$type,$multiple,%courses);
        !           225:     }
        !           226:     $r->print(&Apache::loncommon::end_page());
        !           227:     return OK;
        !           228: }
        !           229: 
        !           230: sub display_matched_courses {
        !           231:     my ($r,$type,$multiple,%courses) = @_;
        !           232:     $r->print('<form name="courselist" method="post" action="/adm/pickcourse">');
        !           233:     my %by_descrip;
        !           234:     my $numcourses = keys(%courses);
        !           235:     foreach my $course (keys(%courses)) {
        !           236:         my $descr;
        !           237:         if ($courses{$course} =~ m/^([^:]*):/i) {
        !           238:             $descr = &unescape($1);
1.34      albertel  239:         } else {
1.54    ! raeburn   240:             $descr = &unescape($courses{$course});
        !           241:         }
        !           242:         my $description = $descr;
        !           243:         push (@{$by_descrip{$description}}, $course);
        !           244:     }
        !           245:     if ($numcourses > 1 && $multiple) {
        !           246:         $r->print('<input type="button" value="check all"
        !           247:                   onclick="javascript:checkAll(document.courselist.course_id)" />
        !           248:                   &nbsp;&nbsp;<input type="button" value="uncheck all"
        !           249:                   onclick="javascript:uncheckAll(document.courselist.course_id)" />
        !           250:                   <br /><br />');
        !           251:     }
        !           252:     foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
        !           253:         foreach my $course (@{$by_descrip{$description}}) {
        !           254:             my $cleandesc=&HTML::Entities::encode($description,'<>&"');
        !           255:             $cleandesc=~s/'/\\'/g;
        !           256:             my ($cdom,$cnum)=split(/\_/,$course);
        !           257:             my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
        !           258:             $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
        !           259:             $r->print($description.'('.
        !           260:                       ($Apache::lonnet::domaindescription{$cdom}?
        !           261:                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
        !           262:             unless ($instcode eq '') {
        !           263:                 $r->print(" - ".&unescape($instcode));
        !           264:             }
        !           265:             unless ($owner eq '') {
        !           266:                 $r->print(", owner - ".&unescape($owner));
1.23      raeburn   267:             }
1.54    ! raeburn   268:             unless ($ttype eq '') {
        !           269:                 $r->print('('.&Apache::lonnet::unescape($ttype).')');
1.23      raeburn   270:             }
1.54    ! raeburn   271:             if ($multiple) { $r->print("</label>\n"); }
        !           272:             $r->print("<br />\n");
1.19      raeburn   273:         }
                    274:     }
1.54    ! raeburn   275:     if (!%courses) {
        !           276:         $r->print(&mt('None found'));
        !           277:     } elsif ($multiple) {
        !           278:         $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
        !           279:     }
        !           280:     $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
        !           281:               "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
        !           282:               '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
        !           283:               '<input type="hidden" name="cdomelement" value="'.$env{'form.cdomelement'}.'" />'."\n".
        !           284:               '<input type="hidden" name="type" value="'.$type.'" />'."\n");
        !           285:     if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
        !           286:         $r->print('<input type="hidden" name="roleelement" value="'.
        !           287:                   $env{'form.roleelement'}.'" />'."\n");
        !           288:     }
        !           289:     $r->print("</form>\n");
        !           290:     return;
        !           291: }
        !           292: 
        !           293: 
        !           294: sub multiples_tag {
        !           295:     my ($type,$title) = @_;
        !           296:     my ($jscript,$multelement,$multiple);
        !           297:     $multiple = $env{'form.multiple'};
        !           298:     if ($multiple) {
        !           299:         $title = &mt('Selecting [_1](s)',lc($type));
        !           300:         $jscript = &Apache::loncommon::check_uncheck_jscript();
        !           301:         $multelement = '<input type="hidden" name="multiple" value="'.$multiple.'" />';
        !           302:     }
        !           303:     return ($title,$jscript,$multelement,$multiple);
1.1       www       304: }
1.30      raeburn   305: 
1.54    ! raeburn   306: sub build_filters {
        !           307:     my ($type,$name_input,$roleelement,$multelement,$filter,$list) = @_;
        !           308:     my @filters = ('domainfilter','descriptfilter','instcodefilter','ownerfilter','ownerdomfilter');
        !           309:     # course ID filter for DCs only
        !           310:     my ($courseidtag,$domainselectform,$sincefilterform,$ownerdomselectform,
        !           311:         $instcodeform,$typeselectform);
        !           312:     if ($env{'user.adv'} && $env{'form.domainfilter'} &&
        !           313:         exists($env{'user.role.dc./'.$env{'form.domainfilter'}})) {
        !           314:         push(@filters,'coursefilter');
        !           315:         $courseidtag=&mt('LON-CAPA course ID').
        !           316:                      '<input type="text" name="coursefilter" size="25" value="'.                     $list->{'coursefilter'}.'" /><br />';
        !           317:     }
        !           318:     foreach my $item (@filters) {
        !           319:         $filter->{$item} = $env{'form.'.$item};
        !           320:         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
        !           321:             $filter->{$item} =~ s/\W//g;
        !           322:             if (!$filter->{$item}) {
        !           323:                 $filter->{$item} = '';
        !           324:             }
        !           325:         }
        !           326:         if ($item eq 'domainfilter') {
        !           327:             $domainselectform =
        !           328:      &Apache::loncommon::select_dom_form($filter->{$item},'domainfilter',1);
        !           329:         } elsif ($item eq 'ownerdomfilter') {
        !           330:             $ownerdomselectform =
        !           331:      &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
        !           332:         } else {
        !           333:             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
        !           334:         }
        !           335:     }
        !           336: 
        !           337:     # last course activity filter and selection
        !           338:     $filter->{'sincefilter'} = $env{'form.sincefilter'};
        !           339:     $filter->{'sincefilter'} =~ s/[^\d-]//g;
        !           340:     if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
        !           341:     $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
        !           342:        'sincefilter',('-1'=>'',
        !           343:                       '86400' => 'today',
        !           344:                       '604800' => 'last week',
        !           345:                       '2592000' => 'last month',
        !           346:                       '7776000' => 'last three months',
        !           347:                       '15552000' => 'last six months',
        !           348:                       '31104000' => 'last year',
        !           349:                       'select_form_order' =>
        !           350:                       ['-1','86400','604800','2592000','7776000',
        !           351:                       '15552000','31104000']));
        !           352: 
        !           353:     my %lt = (
        !           354:               'cac' => &mt('[_1] Activity',$type),
        !           355:               'cde' => &mt('[_1] Description',$type),
        !           356:               'cdo' => &mt('[_1] Domain',$type),
        !           357:               'cin' => &mt('Course Institutional Code'),
        !           358:               'cow' => &mt("[_1] Owner's Username",$type),
        !           359:               'cod' => &mt("[_1] Owner's Domain", $type),
        !           360:               'cog' => &mt('Course Type')
        !           361:              );
1.49      raeburn   362: 
1.54    ! raeburn   363:     $typeselectform =  '<select name="type" size="1"';
        !           364:     $typeselectform .= ">\n";
        !           365:     if ($type eq 'Course') {
        !           366:         $instcodeform = $lt{'cin'}.': <input type="text" name="instcodefilter"
        !           367:  size="10" value="'.$list->{'instcodefilter'}.'" /><br />';
        !           368:     }
        !           369:     foreach my $posstype ('Course','Non-standard course') {
        !           370:         $typeselectform.='<option value="'.$posstype.'" "'.
        !           371:             ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
        !           372:     }
        !           373:     $typeselectform.="</select>";
        !           374:     my $output = <<"END";
1.48      raeburn   375: <form method="post" name="filterpicker" action="/adm/pickcourse">
1.27      albertel  376: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    377: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  378: $name_input
1.27      albertel  379: <input type="hidden" name="form" value="$env{'form.form'}" />
1.18      raeburn   380: $roleelement
1.35      raeburn   381: $multelement
1.8       www       382: $lt{'cac'}: $sincefilterform
1.4       www       383: <br />
1.8       www       384: $lt{'cdo'}: $domainselectform
1.4       www       385: <br />
1.48      raeburn   386: $lt{'cog'}: $typeselectform
1.20      raeburn   387: <br />
1.48      raeburn   388: $instcodeform
1.20      raeburn   389: $lt{'cow'}:
1.54    ! raeburn   390: <input type="text" name="ownerfilter" size="10" value="$list->{'ownerfilter'}" />
1.20      raeburn   391: <br />
1.52      raeburn   392: $lt{'cod'}: $ownerdomselectform
                    393: <br />
1.28      raeburn   394: $courseidtag
1.8       www       395: $lt{'cde'}:
1.54    ! raeburn   396: <input type="text" name="descriptfilter" size="40" value="$list->{'descriptfilter'}" />
1.5       www       397: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       398: </form>
1.5       www       399: <hr />
1.54    ! raeburn   400: END
        !           401:     return $output; 
        !           402: }
        !           403: 
        !           404: sub search_courses {
        !           405:     my ($r,$type,$onlyown,$filter) = @_;
        !           406:     my %courses;
        !           407:     if (!$onlyown) {
1.8       www       408:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       409:         $r->rflush();
1.54    ! raeburn   410:         if (($filter->{'ownerfilter'} ne '') ||
        !           411:             ($filter->{'ownerdomfilter'} ne '')) {
        !           412:             $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
        !           413:                                            $filter->{'ownerdomfilter'};
        !           414:         }
        !           415:         foreach my $item ('descriptfilter','instcodefilter','coursefilter',
        !           416:                           'combownerfilter') {
        !           417:             if (!$filter->{$item}) {
        !           418:                 $filter->{$item}='.';
        !           419:             }
1.52      raeburn   420:         }
                    421:         if ($type eq '') { $type = '.'; }
1.54    ! raeburn   422:         my $timefilter = 
        !           423:            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
        !           424:         %courses = 
        !           425:             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
        !           426:                                           $filter->{'descriptfilter'},
        !           427:                                           $timefilter,
        !           428:                                           $filter->{'instcodefilter'},
        !           429:                                           $filter->{'combownerfilter'},
        !           430:                                           $filter->{'coursefilter'},
        !           431:                                           undef,undef,$type);
        !           432:     } else {
        !           433:         $r->print('<br />');
        !           434:         foreach my $cid (sort(&Apache::loncommon::findallcourses())) {
        !           435:             $courses{$cid} = $env{'course.'.$cid.'.description'};
1.36      raeburn   436:         }
1.2       www       437:     }
1.54    ! raeburn   438:     return %courses;
1.18      raeburn   439: }
1.1       www       440: 
1.30      raeburn   441: sub course_chooser {
1.35      raeburn   442:     my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30      raeburn   443:     my $output; 
1.35      raeburn   444:     if ($multiple) {
1.32      albertel  445:         $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30      raeburn   446:     } else {
                    447:         $output = '<input type="button" value="Select" onClick="gochoose('.
                    448:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    449:     }
                    450:     return $output;
1.49      raeburn   451: }
                    452: 
1.54    ! raeburn   453: sub setsec_javascript {
        !           454:     my ($seclist,$sec_element,$grplist_element,$groupslist,$num_sections) = @_;
        !           455:     my $sectsections = qq|
        !           456: function setSections() {
        !           457:     var numSections = $num_sections
        !           458:     var sectionsArray = new Array("$seclist")
        !           459:     opener.document.$env{"form.form"}.$sec_element.length = 0
        !           460:     if (numSections == 0) {
        !           461:         opener.document.$env{"form.form"}.$sec_element.multiple=false
        !           462:         opener.document.$env{"form.form"}.$sec_element.size=1;
        !           463:         opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('No existing sections','',false,false)
        !           464:     } else {
        !           465:         if (numSections == 1) {
        !           466:             opener.document.$env{"form.form"}.$sec_element.multiple=false;
        !           467:             opener.document.$env{"form.form"}.$sec_element.size=1;
        !           468:             opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('Select','',true,true);
        !           469:             opener.document.$env{"form.form"}.$sec_element.options[1] = new Option('No section','',false,false)
        !           470:             opener.document.$env{"form.form"}.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
        !           471:         } else {
        !           472:             for (var i=0; i<numSections; i++) {
        !           473:                 opener.document.$env{"form.form"}.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
        !           474:             }
        !           475:             opener.document.$env{"form.form"}.$sec_element.multiple=true
        !           476:             if (numSections < 3) {
        !           477:                 opener.document.$env{"form.form"}.$sec_element.size=numSections;            } else {
        !           478:                 opener.document.$env{"form.form"}.$sec_element.size=3;
        !           479:             }
        !           480:             opener.document.$env{"form.form"}.$sec_element.options[0].selected = false
        !           481:         }
        !           482:     }
        !           483:     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
        !           484:     self.close()
        !           485: }
        !           486: |;
        !           487: }
        !           488: 
        !           489: sub setitems_javascript {
        !           490:     my ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
        !           491:         $rolesnameslist,$accesslist,$num_access,$accessnameslist) = @_;
        !           492:     my ($row_id) = ($env{'form.cnumelement'} =~ /^crsnum_(\d+)$/);
        !           493:     my $roles_element = 'role_'.$row_id.'_1';
        !           494:     my $groups_element = 'group_'.$row_id.'_1';
        !           495:     my $sec_element = 'section_'.$row_id.'_1';
        !           496:     my $status_element = 'access_'.$row_id.'_1';
        !           497:     my $grplist_element = 'grplist_'.$row_id.'_1';
        !           498:     my $setitems_function = qq|
        !           499: function setItems() {
        !           500:     opener.document.$env{"form.form"}.activate.checked = true;
        !           501:     setRoles();
        !           502:     setGroups();
        !           503:     setStatus();
        !           504:     setSections();
        !           505: }
        !           506: 
        !           507: function setRoles() {
        !           508:     var numRoles = $num_roles
        !           509:     var rolesArray = new Array("$roleslist");
        !           510:     var roleNamesArray = new Array("$rolesnameslist");
        !           511:     opener.document.$env{"form.form"}.$roles_element.length = 0;
        !           512:     if (numRoles == 0) {
        !           513:         opener.document.$env{"form.form"}.$roles_element.multiple=false;
        !           514:         opener.document.$env{"form.form"}.$roles_element.size=1;
        !           515:         opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('No existing roles','',false,false);
        !           516:     } else {
        !           517:         if (numRoles == 1) {
        !           518:             opener.document.$env{"form.form"}.$roles_element.multiple=false;
        !           519:             opener.document.$env{"form.form"}.$roles_element.size=1;
        !           520:             opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('Select','',true,true);
        !           521:             opener.document.$env{"form.form"}.$roles_element.options[1] = new Option(roleNamesArray[0],rolesArray[0],false,false);
        !           522:         } else {
        !           523:             for (var i=0; i<numRoles; i++) {
        !           524:                 opener.document.$env{"form.form"}.$roles_element.options[i] = new Option(roleNamesArray[i],rolesArray[i],false,false);
        !           525:             }
        !           526:             opener.document.$env{"form.form"}.$roles_element.multiple=true;
        !           527:             if (numRoles < 3) {
        !           528:                 opener.document.$env{"form.form"}.$roles_element.size=numRoles;
        !           529:             } else {
        !           530:                 opener.document.$env{"form.form"}.$roles_element.size=3;
        !           531:             }
        !           532:             opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
        !           533:         }
        !           534:     }
        !           535: }
        !           536: 
        !           537: function setStatus() {
        !           538:     var numStatus = $num_access;
        !           539:     var statusArray = new Array("$accesslist");
        !           540:     var statusNamesArray = new Array("$accessnameslist");
        !           541:     opener.document.$env{"form.form"}.$status_element.multiple=true;
        !           542:     opener.document.$env{"form.form"}.$status_element.size=3;
        !           543:     for (var i=0; i<numStatus; i++) {
        !           544:         opener.document.$env{"form.form"}.$status_element.options[i] = new Option(statusNamesArray[i],statusArray[i],false,false);
        !           545:     }
        !           546: }
        !           547: 
        !           548: function setGroups() {
        !           549:     var numGroups = $num_groups;
        !           550:     var groupsArray = new Array("$groupslist");
        !           551:     opener.document.$env{"form.form"}.$groups_element.length = 0;
        !           552:     if (numGroups == 0) {
        !           553:         opener.document.$env{"form.form"}.$groups_element.multiple=false;
        !           554:         opener.document.$env{"form.form"}.$groups_element.size=1;
        !           555:         opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('No existing groups','',false,false);
        !           556:     } else {
        !           557:         if (numGroups == 1) {
        !           558:             opener.document.$env{"form.form"}.$groups_element.multiple=false;
        !           559:             opener.document.$env{"form.form"}.$groups_element.size=1;
        !           560:             opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('Select','',true,true);
        !           561:             opener.document.$env{"form.form"}.$groups_element.options[1] = new Option('No group','',false,false);
        !           562:             opener.document.$env{"form.form"}.$groups_element.options[2] = new Option(groupsArray[0],groupsArray[0],false,false);
        !           563:         } else {
        !           564:             for (var i=0; i<numGroups; i++) {
        !           565:                 opener.document.$env{"form.form"}.$groups_element.options[i] = new Option(groupsArray[i],groupsArray[i],false,false);
        !           566:             }
        !           567:             opener.document.$env{"form.form"}.$groups_element.multiple=true;
        !           568:             if (numGroups < 3) {
        !           569:                 opener.document.$env{"form.form"}.$groups_element.size=numGroups;
        !           570:             } else {
        !           571:                 opener.document.$env{"form.form"}.$groups_element.size=3;
        !           572:             }
        !           573:             opener.document.$env{"form.form"}.$groups_element.options[0].selected = false;
        !           574:         }
        !           575:     }
        !           576: }
        !           577: 
        !           578: |;
        !           579:     return ($sec_element,$grplist_element,$setitems_function);
        !           580: 
        !           581: }
        !           582: 
1.49      raeburn   583: sub build_selection_lists {
                    584:     my ($cdom,$cnum,$type,$needroles,$needaccess,$caller) = @_;
                    585:     my ($sections,$groups,$allroles,$roleshash,$accesshash) = 
                    586:           &Apache::loncommon::get_secgrprole_info($cdom,$cnum,$needroles,$type);
                    587:     if ($caller eq 'portform') {
                    588:         if (@{$sections} == 0) {
                    589:             @{$sections} = ('none');
                    590:         } else {
                    591:             unshift(@{$sections},('all','none'));
                    592:         }
                    593:         if (@{$groups} == 0) {
                    594:             @{$groups} = ('none');
                    595:         } else {
                    596:             unshift(@{$groups},('all','none'));
                    597:         }
                    598: 
                    599:     } 
                    600:     my $num_sections = scalar(@{$sections});
                    601:     my $seclist = join('","',@{$sections});
                    602:     my $num_groups = scalar(@{$groups});
                    603:     my $groupslist = join('","',@{$groups});
                    604:     my ($roleslist,$num_roles,$rolesnameslist,$num_access,$accesslist,
                    605:         $accessnameslist);
                    606:     if ($needroles) {
                    607:         $num_roles = @{$allroles};
                    608:         $roleslist = join('","',@{$allroles});
                    609:         my @allrolesnames; 
                    610:         foreach my $role (@{$allroles}) {
                    611:             push(@allrolesnames,$$roleshash{$role});
                    612:         }  
                    613:         $rolesnameslist = join('","',@allrolesnames);
                    614:     }
                    615:     if ($needaccess) {
                    616:         $num_access = keys(%{$accesshash});
                    617:         my (@allaccess,@allaccessnames);
                    618:         foreach my $key (sort(keys(%{$accesshash}))) {
                    619:             push(@allaccess,$key);
                    620:             push(@allaccessnames,$$accesshash{$key}); 
                    621:         }
                    622:         $accesslist = join('","',@allaccess);
                    623:         $accessnameslist = join('","',@allaccessnames);
                    624:     }
                    625:     return ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,
                    626:             $num_roles,$rolesnameslist,$accesslist,$num_access,$accessnameslist);
                    627: }
1.30      raeburn   628: 
1.1       www       629: 1;
                    630: __END__

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