Annotation of loncom/interface/lonpickcourse.pm, revision 1.79
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.79 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.78 2009/05/01 01:38:20 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.78 raeburn 38: use Apache::courseclassifier;
1.47 www 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.55 raeburn 49: # Get parameters from query string
1.1 www 50: &Apache::loncommon::get_unprocessed_cgi
1.55 raeburn 51: ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19 raeburn 52: 'cdomelement','cnameelement','roleelement',
1.78 raeburn 53: 'multiple','type','setroles','fixeddom']);
1.54 raeburn 54:
1.55 raeburn 55: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
56: $lastaction,$autosubmit,$submitopener);
57:
1.57 raeburn 58: # Get course type - Course or Non-standard Course.
1.54 raeburn 59: $type = $env{'form.type'};
60: if (!defined($env{'form.type'})) {
61: $type = 'Course';
62: }
63: $title = &mt('Selecting a [_1]',$type);
64:
65: # Setup for multiple course selections, if flag for multiples set.
1.55 raeburn 66: $multiple = $env{'form.multiple'};
67: if ($multiple) {
68: ($jscript,$multelement) = &multiples_tag();
69: $title = &mt('Selecting [_1](s)',lc($type));
1.54 raeburn 70: }
71:
1.55 raeburn 72: # if called when a DC is selecting a course
1.54 raeburn 73: my $roledom = $env{'form.roleelement'};
74: if ($roledom) {
75: $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
1.66 raeburn 76: $submitopener = &processpick();
1.54 raeburn 77: $autosubmit = 'process_pick("'.$roledom.'")';
78: }
79:
80: my $onlyown = 0;
1.55 raeburn 81: # if called to assign course-based portfolio access control
1.59 raeburn 82: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 83: $onlyown = 1;
1.49 raeburn 84: }
1.55 raeburn 85:
86: my %loaditem;
1.78 raeburn 87: if ($env{'form.numtitles'}) {
88: $loaditem{'onload'} = 'setElements(); ';
89: }
90:
1.66 raeburn 91: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
92: ($env{'form.pickedcourse'})) {
1.78 raeburn 93: $loaditem{'onload'} .= 'setSections()';
1.30 raeburn 94: }
1.41 albertel 95: $r->print(&Apache::loncommon::start_page($title,undef,
1.42 albertel 96: {'add_entries' => \%loaditem,
1.41 albertel 97: 'no_nav_bar' => 1, }));
1.55 raeburn 98:
99: if ($env{'form.form'} eq 'portform') {
100: $lastaction = 'document.courselist.submit()';
1.67 raeburn 101: } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
102: !$multiple)) {
1.55 raeburn 103: $lastaction =
104: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
105: 'document.courselist.submit();';
1.34 albertel 106: } else {
1.55 raeburn 107: $lastaction = 'self.close()';
1.1 www 108: }
1.19 raeburn 109:
1.55 raeburn 110: # if called to assign a role in a course to a user via CUSR
1.66 raeburn 111: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68 raeburn 112: $r->print(&create_user_javascript($type));
1.55 raeburn 113: }
1.54 raeburn 114:
1.55 raeburn 115: # print javascript functions for choosing a course
116: if ($env{'form.gosearch'} || $onlyown) {
1.58 raeburn 117: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55 raeburn 118: }
1.79 ! raeburn 119: $r->print('<script type="text/javascript" language="Javascript">'.$jscript.
! 120: '</script>');
1.55 raeburn 121: $r->print($submitopener);
1.54 raeburn 122:
1.55 raeburn 123: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 124: my $filter = {};
125: my $action = '/adm/pickcourse';
1.79 ! raeburn 126: my ($numtitles,$showroles,$nohost);
1.55 raeburn 127: if (!$onlyown) {
128: my $filterlist = ['domainfilter','descriptfilter',
1.79 ! raeburn 129: 'instcodefilter'];
! 130: if ($env{'form.form'} eq 'rules') {
! 131: push(@{$filterlist},'personfilter');
! 132: if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
! 133: if (&Apache::lonnet::homeserver($env{'form.personfilter'},
! 134: $env{'form.persondomfilter'}) eq 'no_host') {
! 135: $nohost = 1;
! 136: } else {
! 137: $showroles = 1;
! 138: }
! 139: }
! 140: } else {
! 141: push(@{$filterlist},'ownerfilter');
! 142: }
1.55 raeburn 143: # course ID filter for DCs only
144: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
145: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
146: push(@{$filterlist},'coursefilter');
147: }
148: $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.78 raeburn 149: $filter,$action,\$numtitles));
1.55 raeburn 150: }
1.54 raeburn 151:
152: # ---------------------------------------------------------------- Get the data
153: if ($env{'form.gosearch'} || $onlyown) {
1.78 raeburn 154: my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
1.79 ! raeburn 155: if ($nohost) {
! 156: $r->print ('<span class="LC_warning">'.
! 157: &mt('User does not exist - username: [_1], domain: [_2].',
! 158: '<b>'.$filter->{'personfilter'}.'</b>',
! 159: '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
! 160: } else {
! 161: &display_matched_courses($r,$type,$multiple,$action,$showroles,%courses);
! 162: }
1.54 raeburn 163: }
164: $r->print(&Apache::loncommon::end_page());
165: return OK;
166: }
167:
1.66 raeburn 168: sub processpick {
169: my $openerform = 'rolechoice';
170: if ($env{'form.form'} eq 'studentform') {
171: $openerform = $env{'form.form'};
172: }
173: my $process_pick = <<"ENDONE";
174: <script type="text/javascript">
175: function process_pick(dom) {
176: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
177: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
178: var okDomain = 0;
179: ENDONE
180: if ($openerform eq 'rolechoice') {
181: $process_pick .= <<"ENDTWO";
182: if (pickedDomain == dom) {
183: if (pickedCourse != '') {
184: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
185: opener.document.title='Role selected. Please stand by.';
186: opener.status='Role selected. Please stand by.';
187: opener.document.rolechoice.newrole.value=courseTarget
188: opener.document.rolechoice.submit();
189: }
190: }
191: else {
192: 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");
193: }
194: ENDTWO
195: } else {
196: $process_pick .= <<"ENDTHREE";
197: if (pickedDomain != dom) {
198: 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");
199: return;
200: }
201: ENDTHREE
202: }
203: $process_pick .= "
204: }
205:
206: </script>
207: ";
208: return $process_pick;
209: }
210:
1.55 raeburn 211: sub create_user_javascript {
212: my ($type) = @_;
213: my $output;
214: #javascript for reporting sections and groups then closing
215: if ($env{'form.pickedcourse'}) {
216: my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
217: my $sec_element = 'currsec';
218: my $grplist_element = 'groups';
219: my ($sections,$groups) =
220: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
221: my $num_sections = scalar(@{$sections});
222: my $seclist = join(',',@{$sections});
223: my $num_groups = scalar(@{$groups});
224: my $groupslist = join(',',@{$groups});
225: $output = qq|
226: <script type="text/javascript">
227: function setSections() {
228: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
229: window.opener.setSect('$seclist');
230: self.close()
231: }
232: </script>
233: |;
234: ;
235: }
236: return $output;
237: }
238:
1.54 raeburn 239: sub display_matched_courses {
1.79 ! raeburn 240: my ($r,$type,$multiple,$action,$showroles,%courses) = @_;
1.55 raeburn 241: if ($env{'form.form'} eq 'portform') {
242: $action = '/adm/portfolio';
243: }
1.68 raeburn 244: my $numcourses = keys(%courses);
1.55 raeburn 245: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 246: if ($env{'form.form'} eq 'modifycourse') {
247: if ($numcourses > 0) {
248: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
249: my $dctitle = &Apache::lonnet::plaintext('dc');
250: my $ccrolechk = ' checked="checked" ';
251: my $menuchk = ' ';
252: if ($env{'form.prevphase'} ne '') {
253: $ccrolechk = ' ';
254: $menuchk = ' checked="checked" ';
255: }
256: $r->print(
1.75 bisitz 257: '<fieldset>'
258: .'<legend>'.&mt('Action').'</legend>'
259: .'<div class="LC_nobreak"><label>'
260: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
261: .' '.&mt('Enter the course with the role of [_1].',$cctitle)
262: .'</label></div>'
263: .'<div class="LC_nobreak"><label>'
264: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> '
265: .&mt('View or modify course settings which only a [_1] may modify.',$dctitle)
266: .'</label></div>'
267: .'</fieldset>'
268: .'<br />'
269: );
1.68 raeburn 270: }
271: }
1.54 raeburn 272: my %by_descrip;
273: foreach my $course (keys(%courses)) {
274: my $descr;
1.64 raeburn 275: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 276: $descr = $courses{$course}{'description'};
1.64 raeburn 277: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 278: $descr = &unescape($1);
1.34 albertel 279: } else {
1.54 raeburn 280: $descr = &unescape($courses{$course});
281: }
282: my $description = $descr;
283: push (@{$by_descrip{$description}}, $course);
284: }
1.71 bisitz 285:
1.54 raeburn 286: if ($numcourses > 1 && $multiple) {
287: $r->print('<input type="button" value="check all"
288: onclick="javascript:checkAll(document.courselist.course_id)" />
289: <input type="button" value="uncheck all"
290: onclick="javascript:uncheckAll(document.courselist.course_id)" />
291: <br /><br />');
292: }
1.71 bisitz 293:
294: if (%courses) {
295: $r->print(&Apache::loncommon::start_data_table());
296: $r->print(&Apache::loncommon::start_data_table_header_row());
297: $r->print('<th>'.&mt('Select').'</th>'
1.76 bisitz 298: .'<th>'.&mt('Course Title').'</th>'
1.71 bisitz 299: .'<th>'.&mt('Domain').'</th>'
300: .'<th>'.&mt('Course Code').'</th>'
1.72 raeburn 301: .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
1.71 bisitz 302: .'<th>'.&mt('Type').'</th>'
303: );
1.79 ! raeburn 304: if ($showroles) {
! 305: $r->print('<th>'.&mt("Role(s) for [_1]",
! 306: &Apache::loncommon::plainname($env{'form.personfilter'},
! 307: $env{'form.persondomfilter'},'firstname')).'</th>');
! 308: }
1.71 bisitz 309: $r->print(&Apache::loncommon::end_data_table_header_row());
310: }
1.54 raeburn 311: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
312: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 313: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 314: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
315: $cleandesc=~s/'/\\'/g;
316: my ($cdom,$cnum)=split(/\_/,$course);
1.64 raeburn 317: my ($descr,$instcode,$ttype,@owners);
318: if (ref($courses{$course}) eq 'HASH') {
319: $descr = $courses{$course}{'description'};
1.65 raeburn 320: $instcode = $courses{$course}{'inst_code'};
1.64 raeburn 321: $ttype = $courses{$course}{'type'};
322: push(@owners,&unescape($courses{$course}{'owner'}));
323: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
324: foreach my $item (@{$courses{$course}{'co-owners'}}) {
325: push(@owners,&unescape($item));
326: }
327: }
328: } else {
329: my $singleowner;
330: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
331: push(@owners,&unescape($singleowner));
332: }
1.72 raeburn 333: my $ownerstr = join(', ',@owners);
1.71 bisitz 334: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc).'</td>');
335: $r->print('<td>'.$description.'</td>');
336: $r->print('<td>');
337: $r->print(&Apache::lonnet::domain($cdom,'description')?
338: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
339: $r->print('</td>');
340: $r->print('<td>');
1.64 raeburn 341: if ($instcode ne '') {
1.71 bisitz 342: $r->print(&unescape($instcode));
343: } else {
344: $r->print(' ');
1.54 raeburn 345: }
1.71 bisitz 346: $r->print('</td>');
1.72 raeburn 347: $r->print('<td>'.$ownerstr.'</td>');
1.71 bisitz 348: $r->print('<td>');
1.64 raeburn 349: if ($ttype ne '') {
1.71 bisitz 350: $r->print(&mt(&unescape($ttype)));
351: } else {
352: $r->print(' ');
1.23 raeburn 353: }
1.71 bisitz 354: $r->print('</td>');
1.79 ! raeburn 355: if ($showroles) {
! 356: $r->print('<td>');
! 357: my $rolestr;
! 358: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
! 359: my @roles = sort(@{$courses{$course}{'roles'}});
! 360: foreach my $role (@roles) {
! 361: if ($role =~ /^cr/) {
! 362: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
! 363: $rolestr .= $crtitle.', ';
! 364: } else {
! 365: $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
! 366: }
! 367: }
! 368: $rolestr =~ s/\, $//;
! 369: }
! 370: $r->print($rolestr.'</td>');
! 371: }
1.54 raeburn 372: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 373: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 374: # $r->print("<br />\n");
1.19 raeburn 375: }
376: }
1.72 raeburn 377: if (%courses) {
378: $r->print(&Apache::loncommon::end_data_table());
379: }
1.71 bisitz 380:
1.54 raeburn 381: if (!%courses) {
382: $r->print(&mt('None found'));
383: } elsif ($multiple) {
1.57 raeburn 384: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 385: }
386: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
387: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
388: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
389: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
390: $r->print('<input type="hidden" name="roleelement" value="'.
391: $env{'form.roleelement'}.'" />'."\n");
392: }
1.55 raeburn 393: if ($env{'form.form'} eq 'portform') {
394: $r->print('<input type="hidden" name="cnum" value="" />');
395: $r->print('<input type="hidden" name="cdom" value="" />');
396: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
397: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 398: } elsif ($env{'form.form'} eq 'modifycourse') {
1.78 raeburn 399: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 400: } else {
401: $r->print('<input type="hidden" name="cnumelement" value="'.
402: $env{'form.cnumelement'}.'" />'."\n".
403: '<input type="hidden" name="cdomelement" value="'.
404: $env{'form.cdomelement'}.'" />'."\n");
1.55 raeburn 405: }
1.78 raeburn 406: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
407: $r->print('<input type="hidden" name="fixeddom" value="'.
408: $env{'form.fixeddom'}.'" />');
409: }
410: if ($env{'form.numtitles'}) {
411: $r->print('<input type="hidden" name="numtitles" value="'.
412: $env{'form.numtitles'}.'" />');
413: }
1.54 raeburn 414: $r->print("</form>\n");
415: return;
416: }
417:
418: sub multiples_tag {
1.55 raeburn 419: my $jscript = &Apache::loncommon::check_uncheck_jscript();
420: my $multelement = '<input type="hidden" name="multiple" value="1" />';
421: return ($jscript,$multelement);
1.1 www 422: }
1.30 raeburn 423:
1.54 raeburn 424: sub build_filters {
1.57 raeburn 425: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.78 raeburn 426: $numtitlesref) = @_;
1.55 raeburn 427: my $list;
1.57 raeburn 428: my $formname;
1.78 raeburn 429: my ($fixeddom,$codedom,$jscript);
1.57 raeburn 430: if (defined($env{'form.form'})) {
431: $formname = $env{'form.form'};
432: }
1.79 ! raeburn 433: my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
1.78 raeburn 434: $instcodeform,$typeselectform,$instcodetitle);
1.55 raeburn 435: foreach my $item (@{$filterlist}) {
1.54 raeburn 436: $filter->{$item} = $env{'form.'.$item};
437: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.79 ! raeburn 438: if ($item eq 'domainfilter') {
1.61 albertel 439: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
440: } elsif ($item eq 'coursefilter') {
441: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
442: } elsif ($item eq 'ownerfilter') {
443: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
1.79 ! raeburn 444: $filter->{'ownerdomfilter'} =
! 445: &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
! 446: $ownerdomselectform =
! 447: &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
! 448: 'ownerdomfilter',1);
! 449: } elsif ($item eq 'personfilter') {
! 450: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
! 451: if ($env{'form.persondomfilter'} eq '') {
! 452: unless ($env{'form.gosearch'}) {
! 453: $filter->{'persondomfilter'} = $env{'request.role.domain'};
! 454: }
! 455: } else {
! 456: $filter->{'persondomfilter'} =
! 457: &LONCAPA::clean_domain($env{'form.persondomfilter'});
! 458: }
! 459: $persondomselectform =
! 460: &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
! 461: 'persondomfilter',1);
1.61 albertel 462: } else {
463: $filter->{$item} =~ s/\W//g;
464: }
1.54 raeburn 465: if (!$filter->{$item}) {
466: $filter->{$item} = '';
467: }
468: }
469: if ($item eq 'domainfilter') {
1.63 albertel 470: my $allow_blank = 1;
471: if ($formname eq 'portform') {
472: $filter->{$item} ||= $env{'user.domain'};
473: $allow_blank=0;
1.67 raeburn 474: } elsif ($formname eq 'studentform') {
475: $filter->{$item} ||= $env{'request.role.domain'};
476: $allow_blank=0;
477: }
1.78 raeburn 478: if ($env{'form.fixeddom'}) {
479: $domainselectform = '<input type="hidden" name="domainfilter"'.
480: 'value="'.$env{'request.role.domain'}.'" />'.
481: &Apache::lonnet::domain($env{'request.role.domain'},
482: 'description');
483: $codedom = $env{'request.role.domain'};
1.79 ! raeburn 484: } else {
1.78 raeburn 485: $domainselectform =
486: &Apache::loncommon::select_dom_form($filter->{$item},
487: 'domainfilter',
488: $allow_blank);
489: $codedom = $filter->{'domainfilter'};
490: }
1.54 raeburn 491: } else {
492: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
493: }
494: }
495:
496: # last course activity filter and selection
497: $filter->{'sincefilter'} = $env{'form.sincefilter'};
498: $filter->{'sincefilter'} =~ s/[^\d-]//g;
499: if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
500: $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
501: 'sincefilter',('-1'=>'',
502: '86400' => 'today',
503: '604800' => 'last week',
504: '2592000' => 'last month',
505: '7776000' => 'last three months',
506: '15552000' => 'last six months',
507: '31104000' => 'last year',
508: 'select_form_order' =>
509: ['-1','86400','604800','2592000','7776000',
510: '15552000','31104000']));
511:
512: my %lt = (
1.74 bisitz 513: 'cac' => &mt("$type Activity"),
1.76 bisitz 514: 'cde' => &mt("$type Title"),
1.74 bisitz 515: 'cdo' => &mt("$type Domain"),
1.78 raeburn 516: 'ins' => &mt('Institutional Code'),
517: 'inc' => &mt('Institutional Categorization'),
1.79 ! raeburn 518: 'cow' => &mt("$type Owner/Co-owner"),
! 519: 'cop' => &mt("$type Personnel Includes"),
1.54 raeburn 520: 'cog' => &mt('Course Type')
521: );
1.49 raeburn 522:
1.65 raeburn 523: $typeselectform = '<select name="type" size="1">'."\n";
1.54 raeburn 524: if ($type eq 'Course') {
1.78 raeburn 525: if ($env{'form.fixeddom'}) {
526: ($instcodeform,$jscript,$$numtitlesref) =
527: &instcode_selectors($codedom,'filterpicker');
528: }
529: if ($instcodeform eq '') {
530: $instcodeform =
1.57 raeburn 531: '<input type="text" name="instcodefilter" size="10" value="'.
532: $list->{'instcodefilter'}.'" />';
1.78 raeburn 533: $instcodetitle = $lt{'ins'};
534: } else {
535: $instcodetitle = $lt{'inc'};
536: }
537: if ($env{'form.fixeddom'}) {
538: $instcodetitle .= '<br />('.$codedom.')';
539: }
540: if ($jscript ne '') {
541: $jscript = '<script type="text/javascript" language="Javascript">'.$jscript.
542: '</script>'."\n";
543: }
1.54 raeburn 544: }
1.57 raeburn 545: foreach my $posstype ('Course','Non-standard Course') {
1.72 raeburn 546: $typeselectform.='<option value="'.$posstype.'"'.
1.73 bisitz 547: ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
1.54 raeburn 548: }
549: $typeselectform.="</select>";
1.57 raeburn 550: my $output = qq|
551: <form method="post" name="filterpicker" action="$action">
552: <input type="hidden" name="form" value="$formname" />
553: |;
554: if ($formname eq 'modifycourse') {
1.68 raeburn 555: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
556: '<input type="hidden" name="prevphase" value="'.
557: $env{'form.prevphase'}.'" />'."\n";
558: } else {
1.57 raeburn 559: my $name_input;
560: if ($env{'form.cnameelement'} ne '') {
561: $name_input = '<input type="hidden" name="cnameelement" value="'.
562: $env{'form.cnameelement'}.'" />';
563: }
564: $output .= qq|
1.27 albertel 565: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
566: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 567: $name_input
1.18 raeburn 568: $roleelement
1.35 raeburn 569: $multelement
1.57 raeburn 570: |;
1.59 raeburn 571: if ($formname eq 'portform') {
1.78 raeburn 572: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59 raeburn 573: }
1.57 raeburn 574: }
1.78 raeburn 575: if ($env{'form.fixeddom'}) {
576: $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
577: }
1.74 bisitz 578: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57 raeburn 579: if ($sincefilterform) {
1.74 bisitz 580: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
581: .$sincefilterform
582: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 583: }
584: if ($domainselectform) {
1.74 bisitz 585: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
586: .$domainselectform
587: .&Apache::lonhtmlcommon::row_closure();
1.78 raeburn 588: }
1.57 raeburn 589: if ($typeselectform) {
1.74 bisitz 590: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
591: .$typeselectform
592: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 593: }
594: if ($instcodeform) {
1.78 raeburn 595: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74 bisitz 596: .$instcodeform
597: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 598: }
599: if (exists($filter->{'ownerfilter'})) {
1.79 ! raeburn 600: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
! 601: '<table><tr><td>'.&mt('Username').'<br />'.
! 602: '<input type="text" name="ownerfilter" size="20" value="'.
! 603: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
! 604: $ownerdomselectform.'</td></tr></table>'.
! 605: &Apache::lonhtmlcommon::row_closure();
! 606: }
! 607: if (exists($filter->{'personfilter'})) {
! 608: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
! 609: '<table><tr><td>'.&mt('Username').'<br />'.
! 610: '<input type="text" name="personfilter" size="20" value="'.
! 611: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
! 612: $persondomselectform.'</td></tr></table>'.
! 613: &Apache::lonhtmlcommon::row_closure();
1.57 raeburn 614: }
615: if (exists($filter->{'coursefilter'})) {
1.74 bisitz 616: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
617: .'<input type="text" name="coursefilter" size="25" value="'
618: .$list->{'coursefilter'}.'" />'
619: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 620: }
621: if (exists($filter->{'descriptfilter'})) {
1.74 bisitz 622: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
623: .'<input type="text" name="descriptfilter" size="40" value="'
624: .$list->{'descriptfilter'}.'" />'
625: .&Apache::lonhtmlcommon::row_closure(1);
1.57 raeburn 626: }
1.74 bisitz 627: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.70 raeburn 628: $output .= '<p><input type="submit" name="gosearch" value="'.
629: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.78 raeburn 630: return $jscript.$output;
631: }
632:
633: sub instcode_selectors {
634: my ($codedom,$formname) = @_;
635: my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
636: my ($jscript,$totcodes,$numtitles,$lasttitle) =
637: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
638: \%cat_items,\@codetitles,\%cat_titles,\%cat_order);
639: if ($numtitles > 0) {
640: $output = &Apache::courseclassifier::build_instcode_selectors($numtitles,
641: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
642: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
643: '<input type="hidden" name="state" value="listing" />'."\n";
644:
645: }
646: return ($output,$jscript,$numtitles);
1.54 raeburn 647: }
648:
649: sub search_courses {
1.78 raeburn 650: my ($r,$type,$onlyown,$filter,$numtitles) = @_;
1.79 ! raeburn 651: my (%courses,%showcourses);
1.54 raeburn 652: if (!$onlyown) {
1.71 bisitz 653: $r->print(&mt('Searching ...').'<br /> <br />');
1.6 www 654: $r->rflush();
1.54 raeburn 655: if (($filter->{'ownerfilter'} ne '') ||
656: ($filter->{'ownerdomfilter'} ne '')) {
657: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
658: $filter->{'ownerdomfilter'};
659: }
660: foreach my $item ('descriptfilter','instcodefilter','coursefilter',
661: 'combownerfilter') {
662: if (!$filter->{$item}) {
663: $filter->{$item}='.';
664: }
1.52 raeburn 665: }
666: if ($type eq '') { $type = '.'; }
1.54 raeburn 667: my $timefilter =
668: ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
1.78 raeburn 669: my ($instcodefilter,$regexpok);
670: if ($numtitles) {
671: $instcodefilter =
672: &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
673: $numtitles);
674: $regexpok = 1;
675: } else {
676: $instcodefilter = $filter->{'instcodefilter'};
677: }
1.54 raeburn 678: %courses =
679: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
680: $filter->{'descriptfilter'},
681: $timefilter,
1.78 raeburn 682: $instcodefilter,
1.54 raeburn 683: $filter->{'combownerfilter'},
684: $filter->{'coursefilter'},
1.78 raeburn 685: undef,undef,$type,$regexpok);
1.79 ! raeburn 686: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
! 687: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
! 688: $filter->{'persondomfilter'},
! 689: 'userroles',undef,
! 690: ['cc','in','ad','ep','ta','cr'],
! 691: $filter->{'domainfilter'});
! 692: foreach my $role (keys(%rolehash)) {
! 693: my ($cnum,$cdom,$courserole) = split(':',$role);
! 694: my $cid = $cdom.'_'.$cnum;
! 695: if (exists($courses{$cid})) {
! 696: if (ref($courses{$cid}) eq 'HASH') {
! 697: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
! 698: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
! 699: push (@{$courses{$cid}{roles}},$courserole);
! 700: }
! 701: } else {
! 702: $courses{$cid}{roles} = [$courserole];
! 703: }
! 704: $showcourses{$cid} = $courses{$cid};
! 705: }
! 706: }
! 707: }
! 708: %courses = %showcourses;
! 709: }
1.54 raeburn 710: } else {
711: $r->print('<br />');
1.60 raeburn 712: my %coursehash = &Apache::loncommon::findallcourses();
713: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 714: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 715: }
1.2 www 716: }
1.54 raeburn 717: return %courses;
1.18 raeburn 718: }
1.1 www 719:
1.30 raeburn 720: sub course_chooser {
1.35 raeburn 721: my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30 raeburn 722: my $output;
1.35 raeburn 723: if ($multiple) {
1.32 albertel 724: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30 raeburn 725: } else {
1.71 bisitz 726: $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30 raeburn 727: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
728: }
729: return $output;
1.49 raeburn 730: }
731:
1.55 raeburn 732: sub gochoose_javascript {
1.57 raeburn 733: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 734: my %elements = (
735: 'Course' => {
736: name => 'coursepick',
737: total => 'coursetotal',
738: list => 'courselist',
739: },
1.57 raeburn 740: 'Non-standard Course' => {
1.55 raeburn 741: name => 'grouppick',
742: total => 'grouptotal',
743: list => 'grouplist',
744: },
745: );
1.57 raeburn 746: my $output .= qq|
1.55 raeburn 747: <script type="text/javascript">
1.57 raeburn 748: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 749: var openerForm = "$env{'form.form'}";
750: courseCount = 0;
751: var courses = '';
1.57 raeburn 752: |;
753: if ($multiple) {
754: $output .= <<"ENDSCRIPT";
755: courseCount = 0;
756: var courses = '';
757: if (typeof(document.courselist.course_id.length) == 'undefined') {
758: // only 1 course checkbox was created
759: if (document.courselist.course_id.checked) {
760: courses = courses + document.courselist.course_id.value + "&&";
761: courseCount ++;
762: }
763: } else {
764: for (var j=0; j<document.courselist.course_id.length; j++) {
765: if (document.courselist.course_id[j].checked) {
766: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 767: courseCount ++;
768: }
1.57 raeburn 769: }
770: }
771: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
772: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
773: 'undefined') {
774: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
775: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 776: } else {
1.57 raeburn 777: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 778: }
1.57 raeburn 779: } else {
780: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
781: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
782: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 783: } else {
1.57 raeburn 784: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 785: }
1.55 raeburn 786: }
1.57 raeburn 787: }
788: if (courseCount > 0) {
789: courses = courses.substr(0,courses.length-2);
790: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
791: }
792: ENDSCRIPT
793: } else {
794: my $name_code;
795: if ($env{'form.cnameelement'} ne '') {
796: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
797: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 798: }
1.57 raeburn 799: $output .= qq|
1.55 raeburn 800: $name_code
801: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
802: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
803: if (slct.options == undefined) {
804: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
805: }
806: else {
807: var i;
808: for (i=0;i<slct.length;i++) {
809: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 810: }
811: }
1.57 raeburn 812: |;
1.54 raeburn 813: }
1.57 raeburn 814: $output .= qq|
1.55 raeburn 815: if (openerForm == 'portform') {
816: document.courselist.cnum.value = cname;
817: document.courselist.cdom.value = cdom;
818: }
819: $autosubmit
820: $lastaction
1.54 raeburn 821: }
1.55 raeburn 822: </script>
1.57 raeburn 823: |;
1.55 raeburn 824: return $output;
1.54 raeburn 825: }
826:
1.55 raeburn 827: 1;
828: __END__
829:
830: =pod
831:
832: =head1 NAME
833:
834: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
835:
836: =head1 SYNOPSIS
837:
838: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
839:
840: =head1 OVERVIEW
841:
842: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
843:
844: =head2 Search Criteria (Screen One)
845:
846: =head3 Criteria:
847:
848: =over 4
849:
850: =item *
851: Course Activity - how recently was course last visited by anyone.
852:
853: =item *
854: Course Domain - the domain of the course
855:
856: =item *
1.57 raeburn 857: Course Type - Course or Non-standard Course
1.55 raeburn 858:
859: =item *
860: Course Institutional Code - the institutional identifier assigned to the course
861:
862: =item *
863: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
864:
865: =item *
866: Course Owner's Domain - the domain of the owner of the course
867:
868: =item *
1.76 bisitz 869: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 870:
871: =item *
872: 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).
873:
874: =back
875:
876: 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'}).
877:
878: =head2 Course Display (Screen Two)
879:
880: 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:
881:
882: =over 4
883:
884: =item *
885: Course description
886:
887: =item *
888: Domain description of course domain
889:
890: =item *
891: Course institutional code
892:
893: =item *
894: Course owner (username:domain)
895:
896: =back
897:
898: 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.
899:
900: 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.
901:
902: =head1 SUBROUTINES
903:
904: =over 4
905:
906: =item *
907: X<create_user_javascript()>
908: B<create_user_javascript($type)>:
909:
1.57 raeburn 910: Input: 1 - $type - the course type - Course or Non-standard Course
1.55 raeburn 911:
912: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
913:
914: Side Effects: None
915:
916: 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.
917:
918:
919: =item *
920: X<display_matched_courses()>
1.79 ! raeburn 921: B<display_matched_courses($r,$type,$multiple,$action,$showroles,%courses)>:
1.55 raeburn 922:
1.79 ! raeburn 923: Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), hash of courses.
1.55 raeburn 924:
925: Output: 0
926:
927: 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.
928:
929: =item *
930: X<multiples_tag()>
931: B<multiples_tag()>:
932:
933:
934: Input: 0
935:
936: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
937:
938: Side Effects: None
939:
940: =item *
941: X<build_filters()>
1.78 raeburn 942: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref)>:
1.55 raeburn 943:
944:
1.78 raeburn 945: Input: 7 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number).
1.55 raeburn 946:
947: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
948:
949: Side Effects: None
950:
951: =item *
952: X<search_courses()>
1.78 raeburn 953: B<search_courses($r,$type,$onlyown,$filter,$numtitles)>:
1.55 raeburn 954:
955:
1.78 raeburn 956: 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; for institutional codes - number of categories).
1.55 raeburn 957:
958: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
959:
960: Side Effects: None
961:
962:
963: =item *
964: X<course_chooser()>
965: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
966:
967: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description.
968:
969: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
970:
971: Side Effects: None
972:
973:
974: =item *
975: X<gochoose_javascript()>
1.57 raeburn 976: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 977:
1.66 raeburn 978: 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 979:
980: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
981:
982: Side Effects: None
983:
984: javascript functions used when user selects a course(s). Different behavior depending on context:
985:
986: =back
987:
988: =over 8
989:
990: =item
991:
992: (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.
993:
994: =item
995:
996: (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.
997:
998: =item
999:
1000: (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.
1001:
1002: =item
1.54 raeburn 1003:
1.55 raeburn 1004: (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 1005:
1.55 raeburn 1006: =item
1.54 raeburn 1007:
1.55 raeburn 1008: (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 1009:
1.55 raeburn 1010: =item
1.54 raeburn 1011:
1.55 raeburn 1012: (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 1013:
1.55 raeburn 1014: =item
1.49 raeburn 1015:
1.55 raeburn 1016: (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 1017:
1.55 raeburn 1018: =back
1019:
1020: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>