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