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

1.1       www         1: # The LearningOnline Network
                      2: # Pick a course
                      3: #
1.53    ! raeburn     4: # $Id: lonpickcourse.pm,v 1.52 2006/07/11 02:28:22 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.5       www        57: # domain filter and selection
1.27      albertel   58:     my $domainfilter=$env{'form.domainfilter'};
1.1       www        59:     $domainfilter=~s/\W//g;
1.4       www        60:     unless ($domainfilter) { $domainfilter=''; }
                     61:     my $domainselectform=&Apache::loncommon::select_dom_form($domainfilter,
                     62:                                                           'domainfilter',1);
1.5       www        63: # description filter
1.27      albertel   64:     my $descriptfilter=$env{'form.descriptfilter'};
1.4       www        65:     unless ($descriptfilter) { $descriptfilter=''; }
1.16      albertel   66:     my $listdescript=&HTML::Entities::encode($descriptfilter,'<>&"');
1.20      raeburn    67: # institutional code filter
1.27      albertel   68:     my $instcodefilter=$env{'form.instcodefilter'};
1.20      raeburn    69:     unless ($instcodefilter) { $instcodefilter=''; }
                     70:     my $listinstcode=&HTML::Entities::encode($instcodefilter,'<>&"');
                     71: # course owner filter
1.27      albertel   72:     my $ownerfilter=$env{'form.ownerfilter'};
1.52      raeburn    73:     $ownerfilter=~s/\W//g;
1.20      raeburn    74:     my $listowner=&HTML::Entities::encode($ownerfilter,'<>&"');
1.52      raeburn    75: # course ownerdomain filter
                     76:     my $ownerdomfilter=$env{'form.ownerdomfilter'};
                     77:     $ownerdomfilter=~s/\W//g;
                     78:     my $ownerdomselectform=
                     79:        &Apache::loncommon::select_dom_form($ownerdomfilter,'ownerdomfilter',1);
1.28      raeburn    80: # course ID filter for DCs only
                     81:     my ($courseidtag,$coursefilter);
                     82:     if ($env{'user.adv'} && $domainfilter && exists($env{'user.role.dc./'.
                     83:                         $domainfilter.'/'})) {
                     84:         $coursefilter=$env{'form.coursefilter'};
                     85:         unless ($coursefilter) { $coursefilter=''; }
                     86:         my $listcourseid=&HTML::Entities::encode($coursefilter,'<>&"');
                     87:         $courseidtag = &mt('LON-CAPA course ID');
1.37      albertel   88:         $courseidtag .= qq|: <input type="text" name="coursefilter" size="25" value="$listcourseid" />
1.28      raeburn    89:         <br />
                     90:         |;
                     91:     }
1.5       www        92: # last course activity filter and selection
1.27      albertel   93:     my $sincefilter=$env{'form.sincefilter'};
1.5       www        94:     $sincefilter=~s/[^\d-]//g;
                     95:     unless ($sincefilter) { $sincefilter=-1; }
                     96:     my $sincefilterform=&Apache::loncommon::select_form($sincefilter,
                     97:        'sincefilter',('-1'=>'',
                     98:                       '86400' => 'today',
                     99:                       '604800' => 'last week',
                    100:                       '2592000' => 'last month',
                    101:                       '7776000' => 'last three months',
                    102:                       '15552000' => 'last six months',
1.9       albertel  103:                       '31104000' => 'last year',
                    104:                       'select_form_order' =>
                    105:                       ['-1','86400','604800','2592000','7776000',
                    106: 		      '15552000','31104000']));
1.19      raeburn   107: # if called from loncreateuser, report sections, then close
1.50      albertel  108:     my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist,
                    109: 	$accesslist,$accessnameslist);
1.49      raeburn   110:     my $sec_element = 'currsec';
                    111:     my $grplist_element = 'groups';
1.19      raeburn   112:     my $num_sections = 0;
1.49      raeburn   113:     my $num_groups = 0;
                    114:     my $num_roles = 0;
                    115:     my $num_access = 0;
                    116:     my ($cdom,$cnum);
                    117:     if ($env{'form.pickedcourse'}) {
                    118:         ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
                    119:     }
                    120:     my $type = $env{'form.type'};
                    121:     if (!defined($env{'form.type'})) {
                    122:         $type = 'Course';
                    123:     }
1.27      albertel  124:     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
1.42      albertel  125:         $loaditem{'onload'} ="setSections()";
1.49      raeburn   126:         ($seclist,$num_sections,$groupslist,$num_groups) = 
                    127:              &build_selection_lists($cdom,$cnum,$type,undef,undef,
                    128:                                     $env{'form.form'});
                    129:     }
                    130: # if called from portfolio, report roles, sections, groups and close
                    131:     my ($roles_element,$groups_element,$status_element,$setitems_function);
                    132:     if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) {
                    133:         my ($row_id) = ($env{'form.cnumelement'} =~ /^crsnum_(\d+)$/);
                    134:         $roles_element = 'role_'.$row_id.'_1';
                    135:         $groups_element = 'group_'.$row_id.'_1';
                    136:         $sec_element = 'section_'.$row_id.'_1';
                    137:         $status_element = 'access_'.$row_id.'_1';
                    138:         $grplist_element = 'grplist_'.$row_id.'_1';
                    139:         $loaditem{'onload'} ="setItems()";
                    140:         ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
                    141:          $rolesnameslist,$accesslist,$num_access,$accessnameslist) =
                    142:                &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'});
                    143:         $setitems_function = qq|
                    144: function setItems() {
                    145:     opener.document.$env{"form.form"}.activate.checked = true;
                    146:     setRoles();
                    147:     setGroups();
                    148:     setStatus();
                    149:     setSections();
                    150: }
                    151: 
                    152: function setRoles() {
                    153:     var numRoles = $num_roles
                    154:     var rolesArray = new Array("$roleslist");
                    155:     var roleNamesArray = new Array("$rolesnameslist");
                    156:     opener.document.$env{"form.form"}.$roles_element.length = 0;
                    157:     if (numRoles == 0) {
                    158:         opener.document.$env{"form.form"}.$roles_element.multiple=false;
                    159:         opener.document.$env{"form.form"}.$roles_element.size=1;
                    160:         opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('No existing roles','',false,false);
                    161:     } else {
                    162:         if (numRoles == 1) {
                    163:             opener.document.$env{"form.form"}.$roles_element.multiple=false;
                    164:             opener.document.$env{"form.form"}.$roles_element.size=1;
                    165:             opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('Select','',true,true);
                    166:             opener.document.$env{"form.form"}.$roles_element.options[1] = new Option(roleNamesArray[0],rolesArray[0],false,false);
                    167:         } else {
                    168:             for (var i=0; i<numRoles; i++) {
                    169:                 opener.document.$env{"form.form"}.$roles_element.options[i] = new Option(roleNamesArray[i],rolesArray[i],false,false);
                    170:             }
                    171:             opener.document.$env{"form.form"}.$roles_element.multiple=true;
                    172:             if (numRoles < 3) {
                    173:                 opener.document.$env{"form.form"}.$roles_element.size=numRoles;
                    174:             } else {
                    175:                 opener.document.$env{"form.form"}.$roles_element.size=3;
                    176:             }
                    177:             opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
                    178:         }
                    179:     }
                    180: }
                    181: 
                    182: function setStatus() {
                    183:     var numStatus = $num_access;
                    184:     var statusArray = new Array("$accesslist");
                    185:     var statusNamesArray = new Array("$accessnameslist");
                    186:     opener.document.$env{"form.form"}.$status_element.multiple=true;
                    187:     opener.document.$env{"form.form"}.$status_element.size=3;
                    188:     for (var i=0; i<numStatus; i++) {
                    189:         opener.document.$env{"form.form"}.$status_element.options[i] = new Option(statusNamesArray[i],statusArray[i],false,false);
                    190:     }
                    191: }
                    192: 
                    193: function setGroups() {
                    194:     var numGroups = $num_groups;
                    195:     var groupsArray = new Array("$groupslist");
                    196:     opener.document.$env{"form.form"}.$groups_element.length = 0;
                    197:     if (numGroups == 0) {
                    198:         opener.document.$env{"form.form"}.$groups_element.multiple=false;
                    199:         opener.document.$env{"form.form"}.$groups_element.size=1;
                    200:         opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('No existing groups','',false,false);
                    201:     } else {
                    202:         if (numGroups == 1) {
                    203:             opener.document.$env{"form.form"}.$groups_element.multiple=false;
                    204:             opener.document.$env{"form.form"}.$groups_element.size=1;
                    205:             opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('Select','',true,true);
                    206:             opener.document.$env{"form.form"}.$groups_element.options[1] = new Option('No group','',false,false);
                    207:             opener.document.$env{"form.form"}.$groups_element.options[2] = new Option(groupsArray[0],groupsArray[0],false,false);
                    208:         } else {
                    209:             for (var i=0; i<numGroups; i++) {
                    210:                 opener.document.$env{"form.form"}.$groups_element.options[i] = new Option(groupsArray[i],groupsArray[i],false,false);
                    211:             }
                    212:             opener.document.$env{"form.form"}.$groups_element.multiple=true;
                    213:             if (numGroups < 3) {
                    214:                 opener.document.$env{"form.form"}.$groups_element.size=numGroups;
                    215:             } else {
                    216:                 opener.document.$env{"form.form"}.$groups_element.size=3;
                    217:             }
                    218:             opener.document.$env{"form.form"}.$groups_element.options[0].selected = false;
                    219:         }
                    220:     }
                    221: }
1.45      albertel  222: 
1.49      raeburn   223: |;
1.19      raeburn   224:     }
1.30      raeburn   225:     my $jscript;
1.48      raeburn   226:     my $typeselectform =  '<select name="type" size="1"';
                    227:     $typeselectform .= ">\n";
1.53    ! raeburn   228:     foreach my $posstype ('Course','Non-standard course') { 
1.48      raeburn   229:         $typeselectform.='<option value="'.$posstype.'" "'.
                    230:             ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
                    231:     }
                    232:     $typeselectform.="</select>";
                    233:     my $title = &mt('Selecting a [_1]',$type);
1.35      raeburn   234: # Setup for multiple course selections, if flag for multiples set.
                    235:     my $multiple = $env{'form.multiple'};
                    236:     my $multelement;
                    237:     if ($multiple) {
1.48      raeburn   238:         $title = &mt('Selecting [_1](s)',lc($type));
1.30      raeburn   239:         $jscript = &Apache::loncommon::check_uncheck_jscript();
1.35      raeburn   240:         $multelement = '<input type="hidden" name="multiple" value="'.$multiple.'" />';
1.30      raeburn   241:     }
1.41      albertel  242:     $r->print(&Apache::loncommon::start_page($title,undef,
1.42      albertel  243: 					     {'add_entries' => \%loaditem,
1.41      albertel  244: 					      'no_nav_bar'  => 1, }));
1.48      raeburn   245:     my %lt = (
                    246: 	      'cac' => &mt('[_1] Activity',$type),
                    247: 	      'cde' => &mt('[_1] Description',$type),
                    248: 	      'cdo' => &mt('[_1] Domain',$type),
                    249:               'cin' => &mt('Course Institutional Code'),
                    250:               'cow' => &mt("[_1] Owner's Username",$type),
1.52      raeburn   251:               'cod' => &mt("[_1] Owner's Domain", $type),
1.53    ! raeburn   252:               'cog' => &mt('Course Type')
1.48      raeburn   253:              );
                    254:    
1.13      albertel  255:     my ($name_code,$name_input);
1.27      albertel  256:     if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
                    257: 	$name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.value=cdesc;";
1.13      albertel  258: 	$name_input ='<input type="hidden" name="cnameelement" value="'.
1.27      albertel  259: 	    $env{'form.cnameelement'}.'" />';
1.13      albertel  260:     }
1.18      raeburn   261:     my $submitopener = '';
                    262:     my $autosubmit = '';
                    263:     my $roleelement = '';
1.19      raeburn   264:     my $lastaction = 'self.close()';
1.27      albertel  265:     if ($env{'form.form'} eq 'cu') {
1.19      raeburn   266:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                    267:                       'document.courselist.submit();';
                    268:     }
1.49      raeburn   269:     if ($env{'form.form'} eq 'portform') {
                    270:         $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
                    271:                       'document.courselist.submit();';
                    272:     }
1.27      albertel  273:     my $roledom = $env{'form.roleelement'};
1.18      raeburn   274:     if ($roledom) {
                    275:         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
1.36      raeburn   276:         $submitopener = &Apache::lonroles::processpick();
1.18      raeburn   277:         $autosubmit = 'process_pick("'.$roledom.'")';
                    278:     }
1.48      raeburn   279:     my $instcodeform;
                    280:     if ($type eq 'Course') {
1.51      albertel  281:         $instcodeform = $lt{'cin'}.': <input type="text" name="instcodefilter" 
1.48      raeburn   282:  size="10" value="'.$listinstcode.'" /><br />';
                    283:     }
                    284:     my %elements = (
1.53    ! raeburn   285:                      'Course' => {
1.48      raeburn   286:                                  name  => 'coursepick',
                    287:                                  total => 'coursetotal',
                    288:                                  list  => 'courselist',
                    289:                                },
1.53    ! raeburn   290:                      'Non-standard course' => {
1.48      raeburn   291:                                  name  => 'grouppick',
                    292:                                  total => 'grouptotal',
                    293:                                  list  => 'grouplist',
                    294:                              },
                    295:                     );
                    296: 
1.1       www       297:     $r->print(<<ENDSCRIPT);
                    298: <script>
1.35      raeburn   299: function gochoose(cname,cdom,cdesc,multiple,caller) {
1.27      albertel  300:     var openerForm = "$env{'form.form'}";
1.30      raeburn   301:     courseCount = 0;
                    302:     var courses = '';
1.35      raeburn   303:     if (multiple) {
1.33      albertel  304: 	if (typeof(document.courselist.course_id.length) == 'undefined') {
                    305: 	    // only 1 course checkbox was created
                    306: 	    if (document.courselist.course_id.checked) {
                    307: 		courses = courses + document.courselist.course_id.value + "&&";
                    308: 		courseCount ++;
                    309: 	    }
                    310: 	} else {
                    311: 	    for (var j=0; j<document.courselist.course_id.length; j++) {
                    312: 		if (document.courselist.course_id[j].checked) {
                    313: 		    courses = courses + document.courselist.course_id[j].value + "&&";
                    314: 		    courseCount ++;
                    315: 		}
                    316: 	    }
                    317: 	} 
1.48      raeburn   318:         opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
                    319: 	if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
1.33      albertel  320: 	    'undefined') {
1.48      raeburn   321: 	    if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {  
                    322: 		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.33      albertel  323: 	    } else {
1.48      raeburn   324: 		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.33      albertel  325: 	    }
                    326: 	} else {
1.48      raeburn   327: 	    for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) { 
                    328: 		if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {  
                    329: 		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.34      albertel  330: 		} else {
1.48      raeburn   331: 		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.33      albertel  332: 		}
                    333: 	    }
                    334: 	}
                    335: 	if (courseCount > 0) {
                    336: 	    courses = courses.substr(0,courses.length-2);
1.48      raeburn   337: 	    opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
1.33      albertel  338: 	}
1.34      albertel  339:     } else {
1.30      raeburn   340:         $name_code
                    341:         opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
1.35      raeburn   342:         var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
                    343:         if (slct.options == undefined) {
1.30      raeburn   344:             opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
1.35      raeburn   345:         }
                    346:         else {
1.30      raeburn   347:             var i;
                    348:             for (i=0;i<slct.length;i++) {
                    349:                 if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
                    350:             }
1.19      raeburn   351:         }
1.1       www       352:     }
1.18      raeburn   353:     $autosubmit
1.19      raeburn   354:     $lastaction
                    355: }
                    356: 
                    357: function setSections() {
                    358:     var numSections = $num_sections
                    359:     var sectionsArray = new Array("$seclist")
1.49      raeburn   360:     opener.document.$env{"form.form"}.$sec_element.length = 0
1.19      raeburn   361:     if (numSections == 0) {
1.49      raeburn   362:         opener.document.$env{"form.form"}.$sec_element.multiple=false
                    363:         opener.document.$env{"form.form"}.$sec_element.size=1;
                    364:         opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('No existing sections','',false,false)
1.34      albertel  365:     } else {
1.23      raeburn   366:         if (numSections == 1) {
1.49      raeburn   367:             opener.document.$env{"form.form"}.$sec_element.multiple=false;
                    368:             opener.document.$env{"form.form"}.$sec_element.size=1;
                    369:             opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('Select','',true,true);
                    370:             opener.document.$env{"form.form"}.$sec_element.options[1] = new Option('No section','',false,false) 
                    371:             opener.document.$env{"form.form"}.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
1.34      albertel  372:         } else {
1.23      raeburn   373:             for (var i=0; i<numSections; i++) {
1.49      raeburn   374:                 opener.document.$env{"form.form"}.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
1.23      raeburn   375:             }
1.49      raeburn   376:             opener.document.$env{"form.form"}.$sec_element.multiple=true
1.23      raeburn   377:             if (numSections < 3) {
1.49      raeburn   378:                 opener.document.$env{"form.form"}.$sec_element.size=numSections;
1.34      albertel  379:             } else {
1.49      raeburn   380:                 opener.document.$env{"form.form"}.$sec_element.size=3;
1.23      raeburn   381:             }
1.49      raeburn   382:             opener.document.$env{"form.form"}.$sec_element.options[0].selected = false
1.19      raeburn   383:         }
                    384:     }
1.49      raeburn   385:     opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
1.19      raeburn   386:     self.close()
1.1       www       387: }
1.30      raeburn   388: 
1.49      raeburn   389: $setitems_function
                    390: 
1.30      raeburn   391: $jscript
1.1       www       392: </script>
1.18      raeburn   393: $submitopener
1.48      raeburn   394: <form method="post" name="filterpicker" action="/adm/pickcourse">
1.27      albertel  395: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
                    396: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13      albertel  397: $name_input
1.27      albertel  398: <input type="hidden" name="form" value="$env{'form.form'}" />
1.18      raeburn   399: $roleelement
1.35      raeburn   400: $multelement
1.8       www       401: $lt{'cac'}: $sincefilterform
1.4       www       402: <br />
1.8       www       403: $lt{'cdo'}: $domainselectform
1.4       www       404: <br />
1.48      raeburn   405: $lt{'cog'}: $typeselectform
1.20      raeburn   406: <br />
1.48      raeburn   407: $instcodeform
1.20      raeburn   408: $lt{'cow'}:
                    409: <input type="text" name="ownerfilter" size="10" value="$listowner" />
                    410: <br />
1.52      raeburn   411: $lt{'cod'}: $ownerdomselectform
                    412: <br />
1.28      raeburn   413: $courseidtag
1.8       www       414: $lt{'cde'}:
1.15      www       415: <input type="text" name="descriptfilter" size="40" value="$listdescript" />
1.5       www       416: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4       www       417: </form>
1.5       www       418: <hr />
1.1       www       419: ENDSCRIPT
1.2       www       420: # ---------------------------------------------------------------- Get the data
1.27      albertel  421:     if ($env{'form.gosearch'}) {
1.8       www       422:         $r->print(&mt('Searching').' ...<br />&nbsp;<br />');
1.6       www       423:         $r->rflush();
1.5       www       424: 	unless ($descriptfilter) { $descriptfilter='.'; }
1.20      raeburn   425:         unless ($instcodefilter) { $instcodefilter='.'; }
1.52      raeburn   426:         my $combownerfilter;
                    427:         if (($ownerfilter ne '') || ($ownerdomfilter ne '')) {
                    428:             $combownerfilter = $ownerfilter.':'.$ownerdomfilter;
                    429:         }
                    430:         if ($combownerfilter eq '') { $combownerfilter='.'; }
                    431:         if ($coursefilter eq '') { $coursefilter='.'; }
                    432:         if ($type eq '') { $type = '.'; }
1.5       www       433:         my $timefilter=($sincefilter==-1?1:time-$sincefilter);
1.52      raeburn   434: 	my %courses = &Apache::lonnet::courseiddump($domainfilter,$descriptfilter,
                    435:                                      $timefilter,$instcodefilter,$combownerfilter,
                    436:                                      $coursefilter,undef,undef,$type);
1.48      raeburn   437: 	$r->print('<form name="courselist" method="post" action="/adm/pickcourse">');
1.10      albertel  438: 	my %by_descrip;
1.31      albertel  439:         my $numcourses = keys(%courses);
                    440: 	foreach my $course (keys(%courses)) {
1.17      raeburn   441:             my $descr;
1.38      www       442:             if ($courses{$course} =~ m/^([^:]*):/i) {
1.47      www       443:                 $descr = &unescape($1);
1.17      raeburn   444:             } else {
1.47      www       445:                 $descr = &unescape($courses{$course});
1.17      raeburn   446:             }
1.38      www       447:             my $description = $descr;
1.25      raeburn   448:             push (@{$by_descrip{$description}}, $course);
1.10      albertel  449: 	}
1.35      raeburn   450:         if ($numcourses > 1 && $multiple) {
1.30      raeburn   451:             $r->print('<input type="button" value="check all"
                    452:                     onclick="javascript:checkAll(document.courselist.course_id)" />                    &nbsp;&nbsp;<input type="button" value="uncheck all"
                    453:                     onclick="javascript:uncheckAll(document.courselist.course_id)" />
                    454:                     <br /><br />');
                    455:         }
1.39      albertel  456: 	foreach my $description (sort 
                    457: 				 { lc($a) cmp lc($b) } (keys(%by_descrip))) {
1.24      raeburn   458:             foreach my $course (@{$by_descrip{$description}}) {
                    459: 	        my $cleandesc=&HTML::Entities::encode($description,'<>&"');
                    460: 	        $cleandesc=~s/'/\\'/g;
                    461: 	        my ($cdom,$cnum)=split(/\_/,$course);
1.48      raeburn   462:                 my ($descr,$instcode,$owner,$ttype) = split/:/,$courses{$course};
1.35      raeburn   463:                 $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
1.30      raeburn   464: 	        $r->print($description.'('.
1.24      raeburn   465: 		      ($Apache::lonnet::domaindescription{$cdom}?
                    466:                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
                    467:                 unless ($instcode eq '') {
1.47      www       468:                     $r->print(" - ".&unescape($instcode));
1.24      raeburn   469:                 }
                    470:                 unless ($owner eq '') {
1.47      www       471:                     $r->print(", owner - ".&unescape($owner));
1.24      raeburn   472:                 }
1.48      raeburn   473:                 unless ($ttype eq '') {
                    474:                     $r->print('('.&Apache::lonnet::unescape($ttype).')');
                    475:                 }
1.35      raeburn   476: 		if ($multiple) { $r->print("</label>\n"); }
1.24      raeburn   477:                 $r->print("<br />\n");
                    478:             }
1.5       www       479: 	}
1.30      raeburn   480: 	if (!%courses) { 
                    481:             $r->print(&mt('None found'));
1.35      raeburn   482:         } elsif ($multiple) {
1.30      raeburn   483:             $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
                    484:         }
1.27      albertel  485:         $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'."\n".
1.19      raeburn   486:                    '<input type="hidden" name="pickedcourse" value="" />'."\n".
1.27      albertel  487:                    '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
1.48      raeburn   488:                    '<input type="hidden" name="cdomelement" value="'.$env{'form.cdomelement'}.'" />'."\n".
                    489:                    '<input type="hidden" name="type" value="'.$type.'" />'."\n");
1.36      raeburn   490:         if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
                    491:            $r->print('<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />'."\n");
                    492:         }
                    493:         $r->print("</form>\n");
1.2       www       494:     }
1.40      albertel  495:     $r->print(&Apache::loncommon::end_page());
1.1       www       496:     return OK;
1.18      raeburn   497: }
1.1       www       498: 
1.30      raeburn   499: sub course_chooser {
1.35      raeburn   500:     my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30      raeburn   501:     my $output; 
1.35      raeburn   502:     if ($multiple) {
1.32      albertel  503:         $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30      raeburn   504:     } else {
                    505:         $output = '<input type="button" value="Select" onClick="gochoose('.
                    506:                   "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
                    507:     }
                    508:     return $output;
1.49      raeburn   509: }
                    510: 
                    511: sub build_selection_lists {
                    512:     my ($cdom,$cnum,$type,$needroles,$needaccess,$caller) = @_;
                    513:     my ($sections,$groups,$allroles,$roleshash,$accesshash) = 
                    514:           &Apache::loncommon::get_secgrprole_info($cdom,$cnum,$needroles,$type);
                    515:     if ($caller eq 'portform') {
                    516:         if (@{$sections} == 0) {
                    517:             @{$sections} = ('none');
                    518:         } else {
                    519:             unshift(@{$sections},('all','none'));
                    520:         }
                    521:         if (@{$groups} == 0) {
                    522:             @{$groups} = ('none');
                    523:         } else {
                    524:             unshift(@{$groups},('all','none'));
                    525:         }
                    526: 
                    527:     } 
                    528:     my $num_sections = scalar(@{$sections});
                    529:     my $seclist = join('","',@{$sections});
                    530:     my $num_groups = scalar(@{$groups});
                    531:     my $groupslist = join('","',@{$groups});
                    532:     my ($roleslist,$num_roles,$rolesnameslist,$num_access,$accesslist,
                    533:         $accessnameslist);
                    534:     if ($needroles) {
                    535:         $num_roles = @{$allroles};
                    536:         $roleslist = join('","',@{$allroles});
                    537:         my @allrolesnames; 
                    538:         foreach my $role (@{$allroles}) {
                    539:             push(@allrolesnames,$$roleshash{$role});
                    540:         }  
                    541:         $rolesnameslist = join('","',@allrolesnames);
                    542:     }
                    543:     if ($needaccess) {
                    544:         $num_access = keys(%{$accesshash});
                    545:         my (@allaccess,@allaccessnames);
                    546:         foreach my $key (sort(keys(%{$accesshash}))) {
                    547:             push(@allaccess,$key);
                    548:             push(@allaccessnames,$$accesshash{$key}); 
                    549:         }
                    550:         $accesslist = join('","',@allaccess);
                    551:         $accessnameslist = join('","',@allaccessnames);
                    552:     }
                    553:     return ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,
                    554:             $num_roles,$rolesnameslist,$accesslist,$num_access,$accessnameslist);
                    555: }
1.30      raeburn   556: 
1.1       www       557: 1;
                    558: __END__

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