Annotation of loncom/interface/lonpickcourse.pm, revision 1.66
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.66 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.65 2007/10/06 04:32:49 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 LONCAPA;
1.1 www 39:
40: sub handler {
41: my $r = shift;
1.8 www 42: &Apache::loncommon::content_type($r,'text/html');
1.1 www 43: $r->send_http_header;
44: return OK if $r->header_only;
45:
46: # ------------------------------------------------------------ Print the screen
1.40 albertel 47:
1.55 raeburn 48: # Get parameters from query string
1.1 www 49: &Apache::loncommon::get_unprocessed_cgi
1.55 raeburn 50: ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19 raeburn 51: 'cdomelement','cnameelement','roleelement',
1.55 raeburn 52: 'multiple','type','setroles']);
1.54 raeburn 53:
1.55 raeburn 54: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
55: $lastaction,$autosubmit,$submitopener);
56:
1.57 raeburn 57: # Get course type - Course or Non-standard Course.
1.54 raeburn 58: $type = $env{'form.type'};
59: if (!defined($env{'form.type'})) {
60: $type = 'Course';
61: }
62: $title = &mt('Selecting a [_1]',$type);
63:
64: # Setup for multiple course selections, if flag for multiples set.
1.55 raeburn 65: $multiple = $env{'form.multiple'};
66: if ($multiple) {
67: ($jscript,$multelement) = &multiples_tag();
68: $title = &mt('Selecting [_1](s)',lc($type));
1.54 raeburn 69: }
70:
1.55 raeburn 71: # if called when a DC is selecting a course
1.54 raeburn 72: my $roledom = $env{'form.roleelement'};
73: if ($roledom) {
74: $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
1.66 ! raeburn 75: $submitopener = &processpick();
1.54 raeburn 76: $autosubmit = 'process_pick("'.$roledom.'")';
77: }
78:
79: my $onlyown = 0;
1.55 raeburn 80: # if called to assign course-based portfolio access control
1.59 raeburn 81: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 82: $onlyown = 1;
1.49 raeburn 83: }
1.55 raeburn 84:
85: my %loaditem;
1.66 ! raeburn 86: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
! 87: ($env{'form.pickedcourse'})) {
1.42 albertel 88: $loaditem{'onload'} ="setSections()";
1.30 raeburn 89: }
1.41 albertel 90: $r->print(&Apache::loncommon::start_page($title,undef,
1.42 albertel 91: {'add_entries' => \%loaditem,
1.41 albertel 92: 'no_nav_bar' => 1, }));
1.55 raeburn 93:
94: if ($env{'form.form'} eq 'portform') {
95: $lastaction = 'document.courselist.submit()';
1.66 ! raeburn 96: } elsif ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.55 raeburn 97: $lastaction =
98: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
99: 'document.courselist.submit();';
1.34 albertel 100: } else {
1.55 raeburn 101: $lastaction = 'self.close()';
1.1 www 102: }
1.19 raeburn 103:
1.55 raeburn 104: # if called to assign a role in a course to a user via CUSR
1.66 ! raeburn 105: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.55 raeburn 106: $r->print(&create_user_javascript($type));
107: }
1.54 raeburn 108:
1.55 raeburn 109: # print javascript functions for choosing a course
110: if ($env{'form.gosearch'} || $onlyown) {
1.58 raeburn 111: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55 raeburn 112: }
113: $r->print('<script type="text/javascript">'.$jscript.'</script>');
114: $r->print($submitopener);
1.54 raeburn 115:
1.55 raeburn 116: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 117: my $filter = {};
118: my $action = '/adm/pickcourse';
1.55 raeburn 119: if (!$onlyown) {
120: my $filterlist = ['domainfilter','descriptfilter',
121: 'instcodefilter','ownerfilter',
122: 'ownerdomfilter'];
123: # course ID filter for DCs only
124: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
125: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
126: push(@{$filterlist},'coursefilter');
127: }
128: $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.57 raeburn 129: $filter,$action));
1.55 raeburn 130: }
1.54 raeburn 131:
132: # ---------------------------------------------------------------- Get the data
133: if ($env{'form.gosearch'} || $onlyown) {
1.57 raeburn 134: my %courses = &search_courses($r,$type,$onlyown,$filter);
135: &display_matched_courses($r,$type,$multiple,$action,%courses);
1.54 raeburn 136: }
137: $r->print(&Apache::loncommon::end_page());
138: return OK;
139: }
140:
1.66 ! raeburn 141: sub processpick {
! 142: my $openerform = 'rolechoice';
! 143: if ($env{'form.form'} eq 'studentform') {
! 144: $openerform = $env{'form.form'};
! 145: }
! 146: my $process_pick = <<"ENDONE";
! 147: <script type="text/javascript">
! 148: function process_pick(dom) {
! 149: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
! 150: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
! 151: var okDomain = 0;
! 152: ENDONE
! 153: if ($openerform eq 'rolechoice') {
! 154: $process_pick .= <<"ENDTWO";
! 155: if (pickedDomain == dom) {
! 156: if (pickedCourse != '') {
! 157: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
! 158: opener.document.title='Role selected. Please stand by.';
! 159: opener.status='Role selected. Please stand by.';
! 160: opener.document.rolechoice.newrole.value=courseTarget
! 161: opener.document.rolechoice.submit();
! 162: }
! 163: }
! 164: else {
! 165: alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
! 166: }
! 167: ENDTWO
! 168: } else {
! 169: $process_pick .= <<"ENDTHREE";
! 170: if (pickedDomain != dom) {
! 171: alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
! 172: return;
! 173: }
! 174: ENDTHREE
! 175: }
! 176: $process_pick .= "
! 177: }
! 178:
! 179: </script>
! 180: ";
! 181: return $process_pick;
! 182: }
! 183:
1.55 raeburn 184: sub create_user_javascript {
185: my ($type) = @_;
186: my $output;
187: #javascript for reporting sections and groups then closing
188: if ($env{'form.pickedcourse'}) {
189: my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
190: my $sec_element = 'currsec';
191: my $grplist_element = 'groups';
192: my ($sections,$groups) =
193: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
194: my $num_sections = scalar(@{$sections});
195: my $seclist = join(',',@{$sections});
196: my $num_groups = scalar(@{$groups});
197: my $groupslist = join(',',@{$groups});
198: $output = qq|
199: <script type="text/javascript">
200: function setSections() {
201: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
202: window.opener.setSect('$seclist');
203: self.close()
204: }
205: </script>
206: |;
207: ;
208: }
209: return $output;
210: }
211:
1.54 raeburn 212: sub display_matched_courses {
1.57 raeburn 213: my ($r,$type,$multiple,$action,%courses) = @_;
1.55 raeburn 214: if ($env{'form.form'} eq 'portform') {
215: $action = '/adm/portfolio';
216: }
217: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.54 raeburn 218: my %by_descrip;
219: my $numcourses = keys(%courses);
220: foreach my $course (keys(%courses)) {
221: my $descr;
1.64 raeburn 222: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 223: $descr = $courses{$course}{'description'};
1.64 raeburn 224: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 225: $descr = &unescape($1);
1.34 albertel 226: } else {
1.54 raeburn 227: $descr = &unescape($courses{$course});
228: }
229: my $description = $descr;
230: push (@{$by_descrip{$description}}, $course);
231: }
232: if ($numcourses > 1 && $multiple) {
233: $r->print('<input type="button" value="check all"
234: onclick="javascript:checkAll(document.courselist.course_id)" />
235: <input type="button" value="uncheck all"
236: onclick="javascript:uncheckAll(document.courselist.course_id)" />
237: <br /><br />');
238: }
239: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
240: foreach my $course (@{$by_descrip{$description}}) {
241: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
242: $cleandesc=~s/'/\\'/g;
243: my ($cdom,$cnum)=split(/\_/,$course);
1.64 raeburn 244: my ($descr,$instcode,$ttype,@owners);
245: if (ref($courses{$course}) eq 'HASH') {
246: $descr = $courses{$course}{'description'};
1.65 raeburn 247: $instcode = $courses{$course}{'inst_code'};
1.64 raeburn 248: $ttype = $courses{$course}{'type'};
249: push(@owners,&unescape($courses{$course}{'owner'}));
250: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
251: foreach my $item (@{$courses{$course}{'co-owners'}}) {
252: push(@owners,&unescape($item));
253: }
254: }
255: } else {
256: my $singleowner;
257: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
258: push(@owners,&unescape($singleowner));
259: }
260: my $owner = join(', ',@owners);
1.54 raeburn 261: $r->print(&course_chooser($multiple,$cdom,$cnum,$cleandesc));
262: $r->print($description.'('.
1.62 albertel 263: (&Apache::lonnet::domain($cdom,'description')?
264: &Apache::lonnet::domain($cdom,'description'):$cdom).")");
1.64 raeburn 265: if ($instcode ne '') {
1.54 raeburn 266: $r->print(" - ".&unescape($instcode));
267: }
1.64 raeburn 268: if (@owners > 1) {
269: $r->print(', '.&mt('owners').' - ',join(', ',@owners));
270: } elsif (@owners == 1) {
271: $r->print(', '.&mt('owner').' - '.$owner);
1.23 raeburn 272: }
1.64 raeburn 273: if ($ttype ne '') {
1.55 raeburn 274: $r->print('('.&unescape($ttype).')');
1.23 raeburn 275: }
1.54 raeburn 276: if ($multiple) { $r->print("</label>\n"); }
277: $r->print("<br />\n");
1.19 raeburn 278: }
279: }
1.54 raeburn 280: if (!%courses) {
281: $r->print(&mt('None found'));
282: } elsif ($multiple) {
1.57 raeburn 283: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 284: }
285: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
286: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
287: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
288: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
289: $r->print('<input type="hidden" name="roleelement" value="'.
290: $env{'form.roleelement'}.'" />'."\n");
291: }
1.55 raeburn 292: if ($env{'form.form'} eq 'portform') {
293: $r->print('<input type="hidden" name="cnum" value="" />');
294: $r->print('<input type="hidden" name="cdom" value="" />');
295: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
296: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 297: } elsif ($env{'form.form'} eq 'modifycourse') {
298: $r->print('<input type="hidden" name="phase" value="menu" />'."\n");
299: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form']));
300: } else {
301: $r->print('<input type="hidden" name="cnumelement" value="'.
302: $env{'form.cnumelement'}.'" />'."\n".
303: '<input type="hidden" name="cdomelement" value="'.
304: $env{'form.cdomelement'}.'" />'."\n");
1.55 raeburn 305: }
1.54 raeburn 306: $r->print("</form>\n");
307: return;
308: }
309:
310:
311: sub multiples_tag {
1.55 raeburn 312: my $jscript = &Apache::loncommon::check_uncheck_jscript();
313: my $multelement = '<input type="hidden" name="multiple" value="1" />';
314: return ($jscript,$multelement);
1.1 www 315: }
1.30 raeburn 316:
1.54 raeburn 317: sub build_filters {
1.57 raeburn 318: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
319: $caller) = @_;
1.55 raeburn 320: my $list;
1.57 raeburn 321: my $formname;
322: if (defined($env{'form.form'})) {
323: $formname = $env{'form.form'};
324: } else {
325: $formname = $caller;
326: }
1.55 raeburn 327: my ($domainselectform,$sincefilterform,$ownerdomselectform,
1.54 raeburn 328: $instcodeform,$typeselectform);
1.55 raeburn 329: foreach my $item (@{$filterlist}) {
1.54 raeburn 330: $filter->{$item} = $env{'form.'.$item};
331: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.61 albertel 332: if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
333: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
334: } elsif ($item eq 'coursefilter') {
335: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
336: } elsif ($item eq 'ownerfilter') {
337: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
338: } else {
339: $filter->{$item} =~ s/\W//g;
340: }
1.54 raeburn 341: if (!$filter->{$item}) {
342: $filter->{$item} = '';
343: }
344: }
345: if ($item eq 'domainfilter') {
1.63 albertel 346: my $allow_blank = 1;
347: if ($formname eq 'portform') {
348: $filter->{$item} ||= $env{'user.domain'};
349: $allow_blank=0;
350: }
1.54 raeburn 351: $domainselectform =
1.63 albertel 352: &Apache::loncommon::select_dom_form($filter->{$item},
353: 'domainfilter',
354: $allow_blank);
1.54 raeburn 355: } elsif ($item eq 'ownerdomfilter') {
356: $ownerdomselectform =
357: &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
358: } else {
359: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
360: }
361: }
362:
363: # last course activity filter and selection
364: $filter->{'sincefilter'} = $env{'form.sincefilter'};
365: $filter->{'sincefilter'} =~ s/[^\d-]//g;
366: if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
367: $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
368: 'sincefilter',('-1'=>'',
369: '86400' => 'today',
370: '604800' => 'last week',
371: '2592000' => 'last month',
372: '7776000' => 'last three months',
373: '15552000' => 'last six months',
374: '31104000' => 'last year',
375: 'select_form_order' =>
376: ['-1','86400','604800','2592000','7776000',
377: '15552000','31104000']));
378:
379: my %lt = (
380: 'cac' => &mt('[_1] Activity',$type),
381: 'cde' => &mt('[_1] Description',$type),
382: 'cdo' => &mt('[_1] Domain',$type),
383: 'cin' => &mt('Course Institutional Code'),
384: 'cow' => &mt("[_1] Owner's Username",$type),
385: 'cod' => &mt("[_1] Owner's Domain", $type),
386: 'cog' => &mt('Course Type')
387: );
1.49 raeburn 388:
1.65 raeburn 389: $typeselectform = '<select name="type" size="1">'."\n";
1.54 raeburn 390: if ($type eq 'Course') {
1.57 raeburn 391: $instcodeform =
392: '<input type="text" name="instcodefilter" size="10" value="'.
393: $list->{'instcodefilter'}.'" />';
1.54 raeburn 394: }
1.57 raeburn 395: foreach my $posstype ('Course','Non-standard Course') {
1.54 raeburn 396: $typeselectform.='<option value="'.$posstype.'" "'.
397: ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
398: }
399: $typeselectform.="</select>";
1.57 raeburn 400: my $output = qq|
401: <form method="post" name="filterpicker" action="$action">
402: <input type="hidden" name="form" value="$formname" />
403: |;
404: if ($formname eq 'modifycourse') {
405: $output .= '<input type="hidden" name="phase" value="courselist" />';
406: } else {
407: my $name_input;
408: if ($env{'form.cnameelement'} ne '') {
409: $name_input = '<input type="hidden" name="cnameelement" value="'.
410: $env{'form.cnameelement'}.'" />';
411: }
412: $output .= qq|
1.27 albertel 413: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
414: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 415: $name_input
1.18 raeburn 416: $roleelement
1.35 raeburn 417: $multelement
1.57 raeburn 418: |;
1.59 raeburn 419: if ($formname eq 'portform') {
420: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />';
421: }
1.57 raeburn 422: }
423: if ($sincefilterform) {
424: $output .= $lt{'cac'}.': '.$sincefilterform.'<br />'."\n";
425: }
426: if ($domainselectform) {
427: $output .= $lt{'cdo'}.': '.$domainselectform.'<br />'."\n";
428: }
429: if ($typeselectform) {
430: $output .= $lt{'cog'}.': '.$typeselectform.'<br />'."\n";
431: }
432: if ($instcodeform) {
433: $output .= $lt{'cin'}.': '.$instcodeform.'<br />'."\n";
434: }
435: if (exists($filter->{'ownerfilter'})) {
436: $output .= $lt{'cow'}.': '.
437: '<input type="text" name="ownerfilter" size="10" value="'.
438: $list->{'ownerfilter'}.'" /><br />'."\n".
439: $lt{'cod'}.': '.$ownerdomselectform.'<br />'."\n";
440: }
441: if (exists($filter->{'coursefilter'})) {
442: $output .= &mt('LON-CAPA course ID').': '.
443: '<input type="text" name="coursefilter" size="25" value="'.
444: $list->{'coursefilter'}.'" /><br />';
445: }
446: if (exists($filter->{'descriptfilter'})) {
447: $output .=$lt{'cde'}.': '.
448: '<input type="text" name="descriptfilter" size="40" value="'.
449: $list->{'descriptfilter'}.'" />'."\n";
450: }
451: $output .= qq|
1.5 www 452: <p><input type="submit" name="gosearch" value="Search" /></p>
1.4 www 453: </form>
1.5 www 454: <hr />
1.57 raeburn 455: |;
1.54 raeburn 456: return $output;
457: }
458:
459: sub search_courses {
460: my ($r,$type,$onlyown,$filter) = @_;
461: my %courses;
462: if (!$onlyown) {
1.8 www 463: $r->print(&mt('Searching').' ...<br /> <br />');
1.6 www 464: $r->rflush();
1.54 raeburn 465: if (($filter->{'ownerfilter'} ne '') ||
466: ($filter->{'ownerdomfilter'} ne '')) {
467: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
468: $filter->{'ownerdomfilter'};
469: }
470: foreach my $item ('descriptfilter','instcodefilter','coursefilter',
471: 'combownerfilter') {
472: if (!$filter->{$item}) {
473: $filter->{$item}='.';
474: }
1.52 raeburn 475: }
476: if ($type eq '') { $type = '.'; }
1.54 raeburn 477: my $timefilter =
478: ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
479: %courses =
480: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
481: $filter->{'descriptfilter'},
482: $timefilter,
483: $filter->{'instcodefilter'},
484: $filter->{'combownerfilter'},
485: $filter->{'coursefilter'},
486: undef,undef,$type);
487: } else {
488: $r->print('<br />');
1.60 raeburn 489: my %coursehash = &Apache::loncommon::findallcourses();
490: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 491: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 492: }
1.2 www 493: }
1.54 raeburn 494: return %courses;
1.18 raeburn 495: }
1.1 www 496:
1.30 raeburn 497: sub course_chooser {
1.35 raeburn 498: my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30 raeburn 499: my $output;
1.35 raeburn 500: if ($multiple) {
1.32 albertel 501: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30 raeburn 502: } else {
503: $output = '<input type="button" value="Select" onClick="gochoose('.
504: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
505: }
506: return $output;
1.49 raeburn 507: }
508:
1.55 raeburn 509: sub gochoose_javascript {
1.57 raeburn 510: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 511: my %elements = (
512: 'Course' => {
513: name => 'coursepick',
514: total => 'coursetotal',
515: list => 'courselist',
516: },
1.57 raeburn 517: 'Non-standard Course' => {
1.55 raeburn 518: name => 'grouppick',
519: total => 'grouptotal',
520: list => 'grouplist',
521: },
522: );
1.57 raeburn 523: my $output .= qq|
1.55 raeburn 524: <script type="text/javascript">
1.57 raeburn 525: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 526: var openerForm = "$env{'form.form'}";
527: courseCount = 0;
528: var courses = '';
1.57 raeburn 529: |;
530: if ($multiple) {
531: $output .= <<"ENDSCRIPT";
532: courseCount = 0;
533: var courses = '';
534: if (typeof(document.courselist.course_id.length) == 'undefined') {
535: // only 1 course checkbox was created
536: if (document.courselist.course_id.checked) {
537: courses = courses + document.courselist.course_id.value + "&&";
538: courseCount ++;
539: }
540: } else {
541: for (var j=0; j<document.courselist.course_id.length; j++) {
542: if (document.courselist.course_id[j].checked) {
543: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 544: courseCount ++;
545: }
1.57 raeburn 546: }
547: }
548: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
549: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
550: 'undefined') {
551: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
552: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 553: } else {
1.57 raeburn 554: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 555: }
1.57 raeburn 556: } else {
557: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
558: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
559: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 560: } else {
1.57 raeburn 561: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 562: }
1.55 raeburn 563: }
1.57 raeburn 564: }
565: if (courseCount > 0) {
566: courses = courses.substr(0,courses.length-2);
567: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
568: }
569: ENDSCRIPT
570: } else {
571: my $name_code;
572: if ($env{'form.cnameelement'} ne '') {
573: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
574: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 575: }
1.57 raeburn 576: $output .= qq|
1.55 raeburn 577: $name_code
578: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
579: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
580: if (slct.options == undefined) {
581: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
582: }
583: else {
584: var i;
585: for (i=0;i<slct.length;i++) {
586: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 587: }
588: }
1.57 raeburn 589: |;
1.54 raeburn 590: }
1.57 raeburn 591: $output .= qq|
1.55 raeburn 592: if (openerForm == 'portform') {
593: document.courselist.cnum.value = cname;
594: document.courselist.cdom.value = cdom;
595: }
596: $autosubmit
597: $lastaction
1.54 raeburn 598: }
1.55 raeburn 599: </script>
1.57 raeburn 600: |;
1.55 raeburn 601: return $output;
1.54 raeburn 602: }
603:
1.55 raeburn 604: 1;
605: __END__
606:
607: =pod
608:
609: =head1 NAME
610:
611: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
612:
613: =head1 SYNOPSIS
614:
615: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
616:
617: =head1 OVERVIEW
618:
619: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
620:
621: =head2 Search Criteria (Screen One)
622:
623: =head3 Criteria:
624:
625: =over 4
626:
627: =item *
628: Course Activity - how recently was course last visited by anyone.
629:
630: =item *
631: Course Domain - the domain of the course
632:
633: =item *
1.57 raeburn 634: Course Type - Course or Non-standard Course
1.55 raeburn 635:
636: =item *
637: Course Institutional Code - the institutional identifier assigned to the course
638:
639: =item *
640: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
641:
642: =item *
643: Course Owner's Domain - the domain of the owner of the course
644:
645: =item *
646: Course Description - text which appears in the Course Description (or title), as set in the Course Parameters.
647:
648: =item *
649: Course ID - the internal course number (course ID part after initial 'domain_') used by LON-CAPA (this criterion is only displayed to Domain Coordinators selecting a course in the same domain as their DC role).
650:
651: =back
652:
653: The criteria setting screen is not displayed if course picking is done by a user who does not have advanced privileges (as defined by $env{'user.adv'}).
654:
655: =head2 Course Display (Screen Two)
656:
657: A list of courses matching the search criteria is displayed. If the user is not an advanced user, screen one will have been skipped and the courses displayed will be all courses in which the user has currently active roles. The information displayed for each course is:
658:
659: =over 4
660:
661: =item *
662: Course description
663:
664: =item *
665: Domain description of course domain
666:
667: =item *
668: Course institutional code
669:
670: =item *
671: Course owner (username:domain)
672:
673: =back
674:
675: Depending on context, the display may include a single select box for each course, allowing selection of only a single course, or may include checkboxes allowing selection of more than one course.
676:
677: Following selection, and/or submission, the course description, number and domain are transferred to the browser window from which the course picker window was opened. In most cases, the child window containing the course picker screens will be closed. However, in some cases closure will be delayed until a third screen has been displayed (e.g., setting of course-based conditional access controls for portfolio files). In this case the page is generated via /adm/portfolio and the page features select boxes to allow the user to select roles, access types, sections and groups.
678:
679: =head1 SUBROUTINES
680:
681: =over 4
682:
683: =item *
684: X<create_user_javascript()>
685: B<create_user_javascript($type)>:
686:
1.57 raeburn 687: Input: 1 - $type - the course type - Course or Non-standard Course
1.55 raeburn 688:
689: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
690:
691: Side Effects: None
692:
693: javascript code for reporting selected sections (as a string of comma separated sections) and groups in the selected course (as a comma separated list) then calling setSect() javscript function in the opener window (to populate section select box) then closing current window.
694:
695:
696: =item *
697: X<display_matched_courses()>
1.57 raeburn 698: B<display_matched_courses($r,$type,$multiple,$action,%courses)>:
1.55 raeburn 699:
1.57 raeburn 700: Input: 5 - request object, course type, multiple (0 or 1), form action; hash of courses.
1.55 raeburn 701:
702: Output: 0
703:
704: Side Effects: prints select buttons (multiple = 0) or checkboxes (multiple = 1) and hidden form elements for selection of one or more courses which met search criteria.
705:
706: =item *
707: X<multiples_tag()>
708: B<multiples_tag()>:
709:
710:
711: Input: 0
712:
713: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
714:
715: Side Effects: None
716:
717: =item *
718: X<build_filters()>
1.57 raeburn 719: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action)>:
1.55 raeburn 720:
721:
1.57 raeburn 722: Input: 6 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action.
1.55 raeburn 723:
724: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
725:
726: Side Effects: None
727:
728: =item *
729: X<search_courses()>
730: B<search_courses($r,$type,$onlyown,$filter)>:
731:
732:
733: Input: 5 - request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values.
734:
735: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
736:
737: Side Effects: None
738:
739:
740: =item *
741: X<course_chooser()>
742: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
743:
744: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description.
745:
746: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
747:
748: Side Effects: None
749:
750:
751: =item *
752: X<gochoose_javascript()>
1.57 raeburn 753: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 754:
1.66 ! raeburn 755: Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc.
1.55 raeburn 756:
757: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
758:
759: Side Effects: None
760:
761: javascript functions used when user selects a course(s). Different behavior depending on context:
762:
763: =back
764:
765: =over 8
766:
767: =item
768:
769: (a) Domain Coordinator using MAIL to select recipients of broadcast e-mail - && separated list of selected courses written to hidden form element in opener window. Child window closes.
770:
771: =item
772:
773: (b) Domain Coordinator choosing a course for adoption of a CC role from roles screen - write course identifying information to hidden form elements in opener window and automatically submit role selection form in opener window. Child window closes.
774:
775: =item
776:
777: (c) Domain Coordinator creating a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
778:
779: =item
1.54 raeburn 780:
1.55 raeburn 781: (d) User selecting a course for course-based conditional access control for a portfolio file - form is submitted, and new page is displayed for selection of roles, access types, sections and groups to be used in conditional ACL. New page is generated by /adm/portfolio.
1.54 raeburn 782:
1.55 raeburn 783: =item
1.54 raeburn 784:
1.55 raeburn 785: (e) Domain Coordinator assigning a role to a user - form is submitted, and new page does an onload call to a javascript function to (a) write lists of sections and groups to hidden elements in opener window, (b) call function in opener window to dynamically populate select box showing current sections.
1.54 raeburn 786:
1.55 raeburn 787: =item
1.54 raeburn 788:
1.55 raeburn 789: (f) Author modifying a rights entry in a .rights file - selected course number and domain are witten to visible form elements in opener window. Child window closes.
1.54 raeburn 790:
1.55 raeburn 791: =item
1.49 raeburn 792:
1.55 raeburn 793: (g) Scantron Operator uploading a scantron file to a course - course number is written to visible form element in opener window. Child window closes.
1.30 raeburn 794:
1.55 raeburn 795: =back
796:
797: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>