Annotation of loncom/interface/lonpickcourse.pm, revision 1.93.2.2
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.93.2.2! raeburn 4: # $Id: lonpickcourse.pm,v 1.93.2.1 2010/06/19 01:38:03 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.85 raeburn 39: use LONCAPA qw(:DEFAULT :match);
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.85 raeburn 53: 'multiple','type','setroles','fixeddom','cloner']);
1.90 raeburn 54: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
1.85 raeburn 55: $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
1.55 raeburn 56:
1.83 raeburn 57: # Get course type - Course or Community.
1.54 raeburn 58: $type = $env{'form.type'};
59: if (!defined($env{'form.type'})) {
60: $type = 'Course';
61: }
1.82 bisitz 62: $title = 'Selecting a '.$type;
1.54 raeburn 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();
1.82 bisitz 68: $title = 'Selecting '.$type.'(s)';
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: }
1.90 raeburn 78: if ($env{'form.typeelement'} ne '') {
79: $typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />';
80: }
1.54 raeburn 81:
1.92 raeburn 82: # if called when a DC is creating a course for another user.
1.85 raeburn 83: if ($env{'form.form'} eq 'ccrs') {
84: ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/);
85: }
86:
87: # if called when requesting a course
88: if ($env{'form.form'} eq 'requestcrs') {
89: $cloneruname = $env{'user.name'};
90: $clonerudom = $env{'user.domain'};
91: }
92:
1.54 raeburn 93: my $onlyown = 0;
1.55 raeburn 94: # if called to assign course-based portfolio access control
1.59 raeburn 95: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 96: $onlyown = 1;
1.49 raeburn 97: }
1.55 raeburn 98:
99: my %loaditem;
1.84 raeburn 100: if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) {
101: if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) {
102: $loaditem{'onload'} = 'setElements(document.filterpicker); ';
103: }
1.78 raeburn 104: }
105:
1.66 raeburn 106: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
107: ($env{'form.pickedcourse'})) {
1.89 raeburn 108: $loaditem{'onload'} .= 'setRoles();setSections();';
1.30 raeburn 109: }
1.85 raeburn 110: my $js = &js_changer();
111: $r->print(&Apache::loncommon::start_page($title,$js,
1.42 albertel 112: {'add_entries' => \%loaditem,
1.41 albertel 113: 'no_nav_bar' => 1, }));
1.55 raeburn 114:
115: if ($env{'form.form'} eq 'portform') {
116: $lastaction = 'document.courselist.submit()';
1.67 raeburn 117: } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
118: !$multiple)) {
1.55 raeburn 119: $lastaction =
120: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
121: 'document.courselist.submit();';
1.34 albertel 122: } else {
1.55 raeburn 123: $lastaction = 'self.close()';
1.1 www 124: }
1.19 raeburn 125:
1.55 raeburn 126: # if called to assign a role in a course to a user via CUSR
1.66 raeburn 127: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68 raeburn 128: $r->print(&create_user_javascript($type));
1.55 raeburn 129: }
1.54 raeburn 130:
1.55 raeburn 131: # print javascript functions for choosing a course
1.85 raeburn 132: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
133: $onlyown) {
1.58 raeburn 134: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55 raeburn 135: }
1.79 raeburn 136: $r->print('<script type="text/javascript" language="Javascript">'.$jscript.
137: '</script>');
1.55 raeburn 138: $r->print($submitopener);
1.54 raeburn 139:
1.55 raeburn 140: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 141: my $filter = {};
142: my $action = '/adm/pickcourse';
1.79 raeburn 143: my ($numtitles,$showroles,$nohost);
1.55 raeburn 144: if (!$onlyown) {
1.93.2.2! raeburn 145: my $filterlist = ['domainfilter'];
! 146: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
! 147: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
! 148: && $env{'form.form'} ne 'portform') {
! 149: my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
! 150: if ($loncaparev ne 'unknown_cmd') {
! 151: push(@{$filterlist},'createdfilter');
! 152: }
! 153: }
! 154: push(@{$filterlist},('descriptfilter','instcodefilter'));
! 155:
1.79 raeburn 156: if ($env{'form.form'} eq 'rules') {
157: push(@{$filterlist},'personfilter');
158: if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
159: if (&Apache::lonnet::homeserver($env{'form.personfilter'},
160: $env{'form.persondomfilter'}) eq 'no_host') {
161: $nohost = 1;
162: } else {
163: $showroles = 1;
164: }
165: }
166: } else {
167: push(@{$filterlist},'ownerfilter');
168: }
1.55 raeburn 169: # course ID filter for DCs only
170: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
171: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
172: push(@{$filterlist},'coursefilter');
173: }
1.85 raeburn 174: if ($cloneruname ne '' && $clonerudom ne '') {
175: push(@{$filterlist},'cloneableonly');
176: }
177:
1.55 raeburn 178: $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.85 raeburn 179: $filter,$action,\$numtitles,undef,$cloneruname,
1.90 raeburn 180: $clonerudom,$typeelement));
1.55 raeburn 181: }
1.54 raeburn 182:
183: # ---------------------------------------------------------------- Get the data
1.85 raeburn 184: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
185: $onlyown) {
1.93.2.2! raeburn 186: my $domcloner;
! 187: if ($env{'form.form'} eq 'ccrs') {
! 188: if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) &&
! 189: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
! 190: $domcloner = 1;
! 191: }
! 192: }
1.85 raeburn 193: my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
1.93.2.2! raeburn 194: $cloneruname,$clonerudom,$domcloner);
1.79 raeburn 195: if ($nohost) {
196: $r->print ('<span class="LC_warning">'.
197: &mt('User does not exist - username: [_1], domain: [_2].',
198: '<b>'.$filter->{'personfilter'}.'</b>',
199: '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
200: } else {
1.85 raeburn 201: &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
202: $clonerudom,%courses);
1.79 raeburn 203: }
1.54 raeburn 204: }
205: $r->print(&Apache::loncommon::end_page());
206: return OK;
207: }
208:
1.85 raeburn 209: sub js_changer {
210: return <<"ENDJS";
211: <script type="text/javascript">
212:
213: function updateFilters(caller) {
214: if (typeof(caller) != "undefined") {
215: document.filterpicker.updater.value = caller.name;
216: }
217: document.filterpicker.submit();
218: }
219:
220: </script>
221:
222: ENDJS
223:
224: }
225:
1.66 raeburn 226: sub processpick {
227: my $openerform = 'rolechoice';
228: if ($env{'form.form'} eq 'studentform') {
229: $openerform = $env{'form.form'};
230: }
231: my $process_pick = <<"ENDONE";
232: <script type="text/javascript">
233: function process_pick(dom) {
234: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
235: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
236: var okDomain = 0;
237: ENDONE
238: if ($openerform eq 'rolechoice') {
239: $process_pick .= <<"ENDTWO";
240: if (pickedDomain == dom) {
241: if (pickedCourse != '') {
1.88 raeburn 242: var ccrole = "cc";
243: var pickedType = "$env{'form.type'}";
244: if (pickedType == "Community") {
245: ccrole = "co";
246: }
247: var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
1.66 raeburn 248: opener.document.title='Role selected. Please stand by.';
249: opener.status='Role selected. Please stand by.';
250: opener.document.rolechoice.newrole.value=courseTarget
251: opener.document.rolechoice.submit();
252: }
253: }
254: else {
255: 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");
256: }
257: ENDTWO
258: } else {
259: $process_pick .= <<"ENDTHREE";
260: if (pickedDomain != dom) {
261: 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");
262: return;
263: }
264: ENDTHREE
265: }
266: $process_pick .= "
267: }
268:
269: </script>
270: ";
271: return $process_pick;
272: }
273:
1.55 raeburn 274: sub create_user_javascript {
275: my ($type) = @_;
276: my $output;
277: #javascript for reporting sections and groups then closing
278: if ($env{'form.pickedcourse'}) {
1.87 raeburn 279: my %coursedescription =
280: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
281: {'one_time' => '1'});
282: my $cdom = $coursedescription{'domain'};
283: my $cnum = $coursedescription{'num'};
284: my $crstype = $coursedescription{'type'};
1.55 raeburn 285: my $sec_element = 'currsec';
286: my $grplist_element = 'groups';
287: my ($sections,$groups) =
288: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
289: my $num_sections = scalar(@{$sections});
290: my $seclist = join(',',@{$sections});
291: my $num_groups = scalar(@{$groups});
292: my $groupslist = join(',',@{$groups});
293: $output = qq|
294: <script type="text/javascript">
295: function setSections() {
296: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
297: window.opener.setSect('$seclist');
1.87 raeburn 298: self.close();
299: }
300: function setRoles() {
301: window.opener.setRole('$crstype');
1.55 raeburn 302: }
303: </script>
304: |;
305: ;
306: }
307: return $output;
308: }
309:
1.54 raeburn 310: sub display_matched_courses {
1.85 raeburn 311: my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
1.55 raeburn 312: if ($env{'form.form'} eq 'portform') {
313: $action = '/adm/portfolio';
314: }
1.68 raeburn 315: my $numcourses = keys(%courses);
1.55 raeburn 316: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 317: if ($env{'form.form'} eq 'modifycourse') {
318: if ($numcourses > 0) {
1.89 raeburn 319: my $ccrole = 'cc';
320: if ($type eq 'Community') {
321: $ccrole = 'co';
322: }
323: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.68 raeburn 324: my $dctitle = &Apache::lonnet::plaintext('dc');
1.93 raeburn 325: my $ccrolechk = ' ';
326: my $menuchk = ' checked="checked" ';
1.68 raeburn 327: $r->print(
1.75 bisitz 328: '<fieldset>'
329: .'<legend>'.&mt('Action').'</legend>'
330: .'<div class="LC_nobreak"><label>'
331: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
1.89 raeburn 332: .' ');
333: if ($type eq 'Community') {
334: $r->print(&mt('Enter the community with the role of [_1].',$cctitle));
335: } else {
336: $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
337: }
338: $r->print('</label></div>'
1.75 bisitz 339: .'<div class="LC_nobreak"><label>'
1.89 raeburn 340: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> ');
341: if ($type eq 'Community') {
342: $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
343: } else {
344: $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
345: }
346: $r->print('</label></div>'
1.75 bisitz 347: .'</fieldset>'
348: .'<br />'
349: );
1.68 raeburn 350: }
351: }
1.54 raeburn 352: my %by_descrip;
353: foreach my $course (keys(%courses)) {
354: my $descr;
1.64 raeburn 355: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 356: $descr = $courses{$course}{'description'};
1.64 raeburn 357: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 358: $descr = &unescape($1);
1.34 albertel 359: } else {
1.54 raeburn 360: $descr = &unescape($courses{$course});
361: }
362: my $description = $descr;
363: push (@{$by_descrip{$description}}, $course);
364: }
1.71 bisitz 365:
1.54 raeburn 366: if ($numcourses > 1 && $multiple) {
367: $r->print('<input type="button" value="check all"
368: onclick="javascript:checkAll(document.courselist.course_id)" />
369: <input type="button" value="uncheck all"
370: onclick="javascript:uncheckAll(document.courselist.course_id)" />
371: <br /><br />');
372: }
1.71 bisitz 373:
374: if (%courses) {
375: $r->print(&Apache::loncommon::start_data_table());
376: $r->print(&Apache::loncommon::start_data_table_header_row());
1.89 raeburn 377: my $titlehdr = &mt('Course Title');
378: if ($type eq 'Community') {
379: $titlehdr = &mt('Community Title');
380: }
1.71 bisitz 381: $r->print('<th>'.&mt('Select').'</th>'
1.89 raeburn 382: .'<th>'.$titlehdr.'</th>'
383: .'<th>'.&mt('Domain').'</th>');
384: unless ($type eq 'Community') {
385: $r->print('<th>'.&mt('Course Code').'</th>');
386: }
387: $r->print('<th>'.&mt('Owner/Co-owner(s)').'</th>');
1.79 raeburn 388: if ($showroles) {
389: $r->print('<th>'.&mt("Role(s) for [_1]",
390: &Apache::loncommon::plainname($env{'form.personfilter'},
391: $env{'form.persondomfilter'},'firstname')).'</th>');
392: }
1.71 bisitz 393: $r->print(&Apache::loncommon::end_data_table_header_row());
394: }
1.92 raeburn 395: my %cc_cloneable;
396: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
397: my ($coord_cloneable,$warning) =
398: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
399: if ($coord_cloneable) {
400: map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable);
401: }
402: }
1.54 raeburn 403: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
404: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 405: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 406: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
407: $cleandesc=~s/'/\\'/g;
408: my ($cdom,$cnum)=split(/\_/,$course);
1.85 raeburn 409: my ($descr,$instcode,$ttype,$canclone,@owners);
1.64 raeburn 410: if (ref($courses{$course}) eq 'HASH') {
411: $descr = $courses{$course}{'description'};
1.85 raeburn 412: $instcode = $courses{$course}{'inst_code'};
413: $ttype = $courses{$course}{'type'};
414: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.93.2.2! raeburn 415: if ($env{'form.form'} eq 'ccrs') {
! 416: if (($env{'request.role.domain'} eq $cdom) &&
! 417: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
! 418: $canclone = 1;
! 419: }
! 420: }
! 421: unless ($canclone) {
! 422: if ($cc_cloneable{$cnum.':'.$cdom}) {
! 423: $canclone = 1;
! 424: }
1.92 raeburn 425: }
426: unless ($canclone) {
427: my $cloners = $courses{$course}{'cloners'};
428: if ($cloners ne '') {
429: my @cloneable = split(',',$cloners);
430: if (grep(/^\*$/,@cloneable)) {
431: $canclone = 1;
432: }
1.93.2.1 raeburn 433: if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) {
1.92 raeburn 434: $canclone = 1;
435: }
436: if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
437: $canclone = 1;
438: }
1.85 raeburn 439: }
440: }
441: }
1.64 raeburn 442: push(@owners,&unescape($courses{$course}{'owner'}));
443: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
444: foreach my $item (@{$courses{$course}{'co-owners'}}) {
445: push(@owners,&unescape($item));
446: }
447: }
448: } else {
449: my $singleowner;
450: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
451: push(@owners,&unescape($singleowner));
452: }
1.93 raeburn 453: my $ownerstr = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } @owners);
1.85 raeburn 454: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).'</td>');
1.71 bisitz 455: $r->print('<td>'.$description.'</td>');
456: $r->print('<td>');
457: $r->print(&Apache::lonnet::domain($cdom,'description')?
458: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
459: $r->print('</td>');
1.89 raeburn 460: unless ($type eq 'Community') {
461: $r->print('<td>');
462: if ($instcode ne '') {
463: $r->print(&unescape($instcode));
464: } else {
465: $r->print(' ');
466: }
467: $r->print('</td>');
1.54 raeburn 468: }
1.72 raeburn 469: $r->print('<td>'.$ownerstr.'</td>');
1.79 raeburn 470: if ($showroles) {
471: $r->print('<td>');
472: my $rolestr;
473: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
474: my @roles = sort(@{$courses{$course}{'roles'}});
475: foreach my $role (@roles) {
476: if ($role =~ /^cr/) {
477: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
478: $rolestr .= $crtitle.', ';
479: } else {
1.89 raeburn 480: $rolestr .= &Apache::lonnet::plaintext($role,$type).', ';
1.79 raeburn 481: }
482: }
483: $rolestr =~ s/\, $//;
484: }
485: $r->print($rolestr.'</td>');
486: }
1.54 raeburn 487: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 488: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 489: # $r->print("<br />\n");
1.19 raeburn 490: }
491: }
1.72 raeburn 492: if (%courses) {
493: $r->print(&Apache::loncommon::end_data_table());
494: }
1.71 bisitz 495:
1.54 raeburn 496: if (!%courses) {
497: $r->print(&mt('None found'));
498: } elsif ($multiple) {
1.57 raeburn 499: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 500: }
501: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
502: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
503: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
504: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
505: $r->print('<input type="hidden" name="roleelement" value="'.
506: $env{'form.roleelement'}.'" />'."\n");
507: }
1.55 raeburn 508: if ($env{'form.form'} eq 'portform') {
509: $r->print('<input type="hidden" name="cnum" value="" />');
510: $r->print('<input type="hidden" name="cdom" value="" />');
511: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
512: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 513: } elsif ($env{'form.form'} eq 'modifycourse') {
1.85 raeburn 514: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 515: } else {
516: $r->print('<input type="hidden" name="cnumelement" value="'.
517: $env{'form.cnumelement'}.'" />'."\n".
518: '<input type="hidden" name="cdomelement" value="'.
519: $env{'form.cdomelement'}.'" />'."\n");
1.90 raeburn 520: if ($env{'form.typeelement'} ne '') {
521: $r->print('<input type="hidden" name="typeelement" value="'.
522: $env{'form.typeelement'}.'" />'."\n");
523:
524: }
1.55 raeburn 525: }
1.78 raeburn 526: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
527: $r->print('<input type="hidden" name="fixeddom" value="'.
528: $env{'form.fixeddom'}.'" />');
529: }
530: if ($env{'form.numtitles'}) {
531: $r->print('<input type="hidden" name="numtitles" value="'.
532: $env{'form.numtitles'}.'" />');
533: }
1.54 raeburn 534: $r->print("</form>\n");
535: return;
536: }
537:
538: sub multiples_tag {
1.55 raeburn 539: my $jscript = &Apache::loncommon::check_uncheck_jscript();
540: my $multelement = '<input type="hidden" name="multiple" value="1" />';
541: return ($jscript,$multelement);
1.1 www 542: }
1.30 raeburn 543:
1.54 raeburn 544: sub build_filters {
1.57 raeburn 545: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.90 raeburn 546: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement) = @_;
1.85 raeburn 547: my ($list,$formname,$fixeddom,$codedom,$jscript);
548: $codedom = $env{'request.role.domain'};
1.57 raeburn 549: if (defined($env{'form.form'})) {
1.81 raeburn 550: $formname = $env{'form.form'};
551: } else {
552: $formname = $caller;
1.57 raeburn 553: }
1.84 raeburn 554: my $onchange;
555: unless ($env{'form.interface'} eq 'textual') {
1.85 raeburn 556: $onchange = 'javascript:updateFilters(this)';
1.84 raeburn 557: }
1.93.2.2! raeburn 558: my ($domainselectform,$sincefilterform,$createdfilterform,
! 559: $ownerdomselectform,$persondomselectform,$instcodeform,
! 560: $typeselectform,$instcodetitle);
1.55 raeburn 561: foreach my $item (@{$filterlist}) {
1.54 raeburn 562: $filter->{$item} = $env{'form.'.$item};
563: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.79 raeburn 564: if ($item eq 'domainfilter') {
1.61 albertel 565: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
566: } elsif ($item eq 'coursefilter') {
567: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
568: } elsif ($item eq 'ownerfilter') {
569: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
1.79 raeburn 570: $filter->{'ownerdomfilter'} =
571: &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
572: $ownerdomselectform =
573: &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
574: 'ownerdomfilter',1);
575: } elsif ($item eq 'personfilter') {
576: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
577: if ($env{'form.persondomfilter'} eq '') {
1.85 raeburn 578: unless ($env{'form.gosearch'}) {
1.79 raeburn 579: $filter->{'persondomfilter'} = $env{'request.role.domain'};
580: }
581: } else {
582: $filter->{'persondomfilter'} =
583: &LONCAPA::clean_domain($env{'form.persondomfilter'});
584: }
585: $persondomselectform =
586: &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
587: 'persondomfilter',1);
1.61 albertel 588: } else {
589: $filter->{$item} =~ s/\W//g;
590: }
1.54 raeburn 591: if (!$filter->{$item}) {
592: $filter->{$item} = '';
593: }
594: }
595: if ($item eq 'domainfilter') {
1.63 albertel 596: my $allow_blank = 1;
597: if ($formname eq 'portform') {
598: $filter->{$item} ||= $env{'user.domain'};
599: $allow_blank=0;
1.67 raeburn 600: } elsif ($formname eq 'studentform') {
601: $filter->{$item} ||= $env{'request.role.domain'};
602: $allow_blank=0;
603: }
1.78 raeburn 604: if ($env{'form.fixeddom'}) {
605: $domainselectform = '<input type="hidden" name="domainfilter"'.
606: 'value="'.$env{'request.role.domain'}.'" />'.
607: &Apache::lonnet::domain($env{'request.role.domain'},
608: 'description');
609: $codedom = $env{'request.role.domain'};
1.79 raeburn 610: } else {
1.78 raeburn 611: $domainselectform =
612: &Apache::loncommon::select_dom_form($filter->{$item},
613: 'domainfilter',
1.84 raeburn 614: $allow_blank,'',$onchange);
1.78 raeburn 615: $codedom = $filter->{'domainfilter'};
616: }
1.54 raeburn 617: } else {
618: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
619: }
620: }
621:
1.93.2.2! raeburn 622:
1.54 raeburn 623: # last course activity filter and selection
1.93.2.2! raeburn 624: $sincefilterform = &timebased_select_form('sincefilter',$filter);
! 625:
! 626: # course created filter and selection
! 627: if (exists($filter->{'createdfilter'})) {
! 628: $createdfilterform = &timebased_select_form('createdfilter',$filter);
! 629: }
1.91 bisitz 630:
631: my %lt = &Apache::lonlocal::texthash(
632: 'cac' => "$type Activity",
1.93.2.2! raeburn 633: 'ccr' => "$type Created",
1.91 bisitz 634: 'cde' => "$type Title",
635: 'cdo' => "$type Domain",
636: 'ins' => 'Institutional Code',
637: 'inc' => 'Institutional Categorization',
638: 'cow' => "$type Owner/Co-owner",
639: 'cop' => "$type Personnel Includes",
640: 'cog' => 'Type',
1.54 raeburn 641: );
1.49 raeburn 642:
1.89 raeburn 643: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
644: my $typeval = 'Course';
645: if ($type eq 'Community') {
646: $typeval = 'Community';
647: }
648: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
649: } else {
650: $typeselectform = '<select name="type" size="1"';
651: if ($onchange) {
652: $typeselectform .= 'onchange="'.$onchange.'"';
653: }
654: $typeselectform .= '>'."\n";
655: foreach my $posstype ('Course','Community') {
656: $typeselectform.='<option value="'.$posstype.'"'.
657: ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
658: }
659: $typeselectform.="</select>";
1.84 raeburn 660: }
1.85 raeburn 661:
662: my ($cloneableonlyform,$cloneabletitle);
663: if (exists($filter->{'cloneableonly'})) {
664: my $cloneableon = '';
665: my $cloneableoff = ' checked="checked"';
666: if ($filter->{'cloneableonly'}) {
667: $cloneableon = $cloneableoff;
668: $cloneableoff = '';
669: }
1.86 raeburn 670: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
1.85 raeburn 671: if ($env{'form.form'} eq 'ccrs') {
672: $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
673: } else {
674: $cloneabletitle = &mt('Cloneable by you');
675: }
676: }
1.80 raeburn 677: my $officialjs;
1.54 raeburn 678: if ($type eq 'Course') {
1.85 raeburn 679: if (exists($filter->{'instcodefilter'})) {
680: if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
681: || ($formname eq 'modifycourse')) {
682: $officialjs = 1;
683: ($instcodeform,$jscript,$$numtitlesref) =
684: &instcode_selectors($codedom,'filterpicker',$officialjs);
685: if ($jscript) {
686: $jscript = '<script type="text/javascript" language="Javascript">'.
687: $jscript.'</script>'."\n";
688: }
689: }
690: if ($instcodeform eq '') {
691: $instcodeform =
692: '<input type="text" name="instcodefilter" size="10" value="'.
693: $list->{'instcodefilter'}.'" />';
694: $instcodetitle = $lt{'ins'};
695: } else {
696: $instcodetitle = $lt{'inc'};
697: }
698: if ($env{'form.fixeddom'}) {
699: $instcodetitle .= '<br />('.$codedom.')';
700: }
1.78 raeburn 701: }
1.54 raeburn 702: }
1.84 raeburn 703:
1.57 raeburn 704: my $output = qq|
1.85 raeburn 705: <form method="post" name="filterpicker" action="$action">
1.57 raeburn 706: <input type="hidden" name="form" value="$formname" />
707: |;
708: if ($formname eq 'modifycourse') {
1.68 raeburn 709: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
710: '<input type="hidden" name="prevphase" value="'.
711: $env{'form.prevphase'}.'" />'."\n";
712: } else {
1.57 raeburn 713: my $name_input;
714: if ($env{'form.cnameelement'} ne '') {
715: $name_input = '<input type="hidden" name="cnameelement" value="'.
716: $env{'form.cnameelement'}.'" />';
717: }
718: $output .= qq|
1.27 albertel 719: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
720: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 721: $name_input
1.18 raeburn 722: $roleelement
1.35 raeburn 723: $multelement
1.90 raeburn 724: $typeelement
1.57 raeburn 725: |;
1.59 raeburn 726: if ($formname eq 'portform') {
1.78 raeburn 727: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59 raeburn 728: }
1.57 raeburn 729: }
1.78 raeburn 730: if ($env{'form.fixeddom'}) {
731: $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
732: }
1.74 bisitz 733: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57 raeburn 734: if ($sincefilterform) {
1.74 bisitz 735: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
736: .$sincefilterform
737: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 738: }
1.93.2.2! raeburn 739: if ($createdfilterform) {
! 740: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
! 741: .$createdfilterform
! 742: .&Apache::lonhtmlcommon::row_closure();
! 743: }
1.57 raeburn 744: if ($domainselectform) {
1.74 bisitz 745: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
746: .$domainselectform
747: .&Apache::lonhtmlcommon::row_closure();
1.78 raeburn 748: }
1.57 raeburn 749: if ($typeselectform) {
1.89 raeburn 750: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
751: $output .= $typeselectform;
752: } else {
753: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
754: .$typeselectform
755: .&Apache::lonhtmlcommon::row_closure();
756: }
1.57 raeburn 757: }
758: if ($instcodeform) {
1.78 raeburn 759: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74 bisitz 760: .$instcodeform
761: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 762: }
763: if (exists($filter->{'ownerfilter'})) {
1.79 raeburn 764: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
765: '<table><tr><td>'.&mt('Username').'<br />'.
766: '<input type="text" name="ownerfilter" size="20" value="'.
767: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
768: $ownerdomselectform.'</td></tr></table>'.
769: &Apache::lonhtmlcommon::row_closure();
770: }
771: if (exists($filter->{'personfilter'})) {
772: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
773: '<table><tr><td>'.&mt('Username').'<br />'.
774: '<input type="text" name="personfilter" size="20" value="'.
775: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
776: $persondomselectform.'</td></tr></table>'.
777: &Apache::lonhtmlcommon::row_closure();
1.57 raeburn 778: }
779: if (exists($filter->{'coursefilter'})) {
1.74 bisitz 780: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
781: .'<input type="text" name="coursefilter" size="25" value="'
782: .$list->{'coursefilter'}.'" />'
783: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 784: }
1.85 raeburn 785: if ($cloneableonlyform) {
786: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
787: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
788: }
1.57 raeburn 789: if (exists($filter->{'descriptfilter'})) {
1.74 bisitz 790: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
791: .'<input type="text" name="descriptfilter" size="40" value="'
792: .$list->{'descriptfilter'}.'" />'
793: .&Apache::lonhtmlcommon::row_closure(1);
1.57 raeburn 794: }
1.85 raeburn 795: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>';
1.92 raeburn 796: my ($coord_cloneable,$warning);
1.85 raeburn 797: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.92 raeburn 798: ($coord_cloneable,$warning) =
799: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
800: if ($env{'form.form'} eq 'ccrs') {
801: $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
1.85 raeburn 802: }
1.92 raeburn 803: if ($coord_cloneable) {
804: $output .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
1.85 raeburn 805: }
806: }
807: $output .= '<input type="hidden" name="updater" value="">'."\n".
1.84 raeburn 808: '<input type="submit" name="gosearch" value="'.
1.70 raeburn 809: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.85 raeburn 810: return $jscript.$warning.$output;
1.78 raeburn 811: }
812:
1.93.2.2! raeburn 813: sub timebased_select_form {
! 814: my ($item,$filter) = @_;
! 815: if (ref($filter) eq 'HASH') {
! 816: $filter->{$item} = $env{'form.'.$item};
! 817: $filter->{$item} =~ s/[^\d-]//g;
! 818: if (!$filter->{$item}) { $filter->{$item}=-1; }
! 819: return &Apache::loncommon::select_form(
! 820: $filter->{$item},
! 821: $item,
! 822: ( '-1' => '',
! 823: '86400' => &mt('today'),
! 824: '604800' => &mt('last week'),
! 825: '2592000' => &mt('last month'),
! 826: '7776000' => &mt('last three months'),
! 827: '15552000' => &mt('last six months'),
! 828: '31104000' => &mt('last year'),
! 829: 'select_form_order' =>
! 830: ['-1','86400','604800','2592000','7776000',
! 831: '15552000','31104000']));
! 832: }
! 833: }
! 834:
1.92 raeburn 835: sub get_coordinator_cloneable {
836: my ($cloneruname,$clonerudom,$type) = @_;
837: if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
838: my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
839: '</div>';
840: return ('',$warning);
841: } else {
842: my ($cc_clone,$ccrole);
843: if ($type eq 'Community') {
844: $ccrole = 'co';
845: } elsif ($type eq 'Course') {
846: $ccrole = 'cc';
847: }
848: my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
849: 'userroles',['active'], [$ccrole]);
850: foreach my $key (sort(keys(%ccroles))) {
851: my ($cnum,$cdom,$role) = split(':',$key);
852: $cc_clone .= $cdom.':'.$cnum.'&';
853: }
854: $cc_clone =~ s/\&$//;
855: return ($cc_clone);
856: }
857: }
858:
1.78 raeburn 859: sub instcode_selectors {
1.80 raeburn 860: my ($codedom,$formname,$officialjs) = @_;
1.78 raeburn 861: my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
862: my ($jscript,$totcodes,$numtitles,$lasttitle) =
863: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
1.80 raeburn 864: \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
1.78 raeburn 865: if ($numtitles > 0) {
1.84 raeburn 866: my $official = ' checked="checked" ';
867: my $unofficial = '';
868: if ($env{'form.official'} eq 'off') {
869: $unofficial = $official;
870: $official = '';
1.80 raeburn 871: }
872: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
1.84 raeburn 873: '<input type="radio" name="official" value="on"'.$official.' />'.
1.80 raeburn 874: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1.84 raeburn 875: '<input type="radio" name="official" value="off"'.$unofficial.
1.80 raeburn 876: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
877: &Apache::courseclassifier::build_instcode_selectors($numtitles,
878: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
879: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
880: '<input type="hidden" name="state" value="listing" />'."\n";
1.78 raeburn 881:
882: }
883: return ($output,$jscript,$numtitles);
1.54 raeburn 884: }
885:
886: sub search_courses {
1.93.2.2! raeburn 887: my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner) = @_;
1.89 raeburn 888: my (%courses,%showcourses,$cloner,$ccrole);
889: if ($type eq 'Community') {
890: $ccrole = 'co';
891: } else {
892: $ccrole = 'cc';
893: }
1.54 raeburn 894: if (!$onlyown) {
1.71 bisitz 895: $r->print(&mt('Searching ...').'<br /> <br />');
1.6 www 896: $r->rflush();
1.54 raeburn 897: if (($filter->{'ownerfilter'} ne '') ||
898: ($filter->{'ownerdomfilter'} ne '')) {
899: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
900: $filter->{'ownerdomfilter'};
901: }
1.80 raeburn 902: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
1.54 raeburn 903: if (!$filter->{$item}) {
904: $filter->{$item}='.';
905: }
1.52 raeburn 906: }
1.93.2.2! raeburn 907: my $now = time;
! 908: my $timefilter =
! 909: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
! 910: my ($createdbefore,$createdafter);
! 911: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
! 912: $createdbefore = $now;
! 913: $createdafter = $now-$filter->{'createdfilter'};
! 914: }
1.78 raeburn 915: my ($instcodefilter,$regexpok);
916: if ($numtitles) {
1.84 raeburn 917: if ($env{'form.official'} eq 'on') {
1.80 raeburn 918: $instcodefilter =
1.84 raeburn 919: &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
1.80 raeburn 920: $regexpok = 1;
1.84 raeburn 921: } elsif ($env{'form.official'} eq 'off') {
922: $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
923: unless ($instcodefilter eq '') {
924: $regexpok = -1;
925: }
1.80 raeburn 926: }
1.78 raeburn 927: } else {
928: $instcodefilter = $filter->{'instcodefilter'};
929: }
1.80 raeburn 930: if ($instcodefilter eq '') { $instcodefilter = '.'; }
931: if ($type eq '') { $type = '.'; }
1.85 raeburn 932:
933: if (($clonerudom ne '') && ($cloneruname ne '')) {
934: $cloner = $cloneruname.':'.$clonerudom;
935: }
1.54 raeburn 936: %courses =
937: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
938: $filter->{'descriptfilter'},
939: $timefilter,
1.78 raeburn 940: $instcodefilter,
1.54 raeburn 941: $filter->{'combownerfilter'},
942: $filter->{'coursefilter'},
1.85 raeburn 943: undef,undef,$type,$regexpok,undef,undef,
944: undef,undef,$cloner,$env{'form.cc_clone'},
1.93.2.2! raeburn 945: $filter->{'cloneableonly'},
! 946: $createdbefore,$createdafter,undef,
! 947: $domcloner);
1.79 raeburn 948: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
949: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
950: $filter->{'persondomfilter'},
951: 'userroles',undef,
1.89 raeburn 952: [$ccrole,'in','ad','ep','ta','cr'],
1.79 raeburn 953: $filter->{'domainfilter'});
954: foreach my $role (keys(%rolehash)) {
955: my ($cnum,$cdom,$courserole) = split(':',$role);
956: my $cid = $cdom.'_'.$cnum;
957: if (exists($courses{$cid})) {
958: if (ref($courses{$cid}) eq 'HASH') {
959: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
960: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
961: push (@{$courses{$cid}{roles}},$courserole);
962: }
963: } else {
964: $courses{$cid}{roles} = [$courserole];
965: }
966: $showcourses{$cid} = $courses{$cid};
967: }
968: }
969: }
970: %courses = %showcourses;
971: }
1.54 raeburn 972: } else {
973: $r->print('<br />');
1.60 raeburn 974: my %coursehash = &Apache::loncommon::findallcourses();
975: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 976: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 977: }
1.2 www 978: }
1.54 raeburn 979: return %courses;
1.18 raeburn 980: }
1.1 www 981:
1.30 raeburn 982: sub course_chooser {
1.85 raeburn 983: my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
1.30 raeburn 984: my $output;
1.35 raeburn 985: if ($multiple) {
1.32 albertel 986: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.85 raeburn 987: } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) {
988: if ($env{'form.form'} eq 'ccrs') {
989: $output = &mt('No cloning for ').$env{'form.cloner'}."\n";
990: } else {
991: $output = &mt('No rights to clone')."\n";
992: }
1.30 raeburn 993: } else {
1.71 bisitz 994: $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30 raeburn 995: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
996: }
997: return $output;
1.49 raeburn 998: }
999:
1.55 raeburn 1000: sub gochoose_javascript {
1.57 raeburn 1001: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 1002: my %elements = (
1003: 'Course' => {
1004: name => 'coursepick',
1005: total => 'coursetotal',
1006: list => 'courselist',
1007: },
1.83 raeburn 1008: 'Community' => {
1.88 raeburn 1009: name => 'coursepick',
1010: total => 'coursetotal',
1011: list => 'courselist',
1.55 raeburn 1012: },
1013: );
1.57 raeburn 1014: my $output .= qq|
1.55 raeburn 1015: <script type="text/javascript">
1.57 raeburn 1016: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 1017: var openerForm = "$env{'form.form'}";
1018: courseCount = 0;
1019: var courses = '';
1.57 raeburn 1020: |;
1021: if ($multiple) {
1022: $output .= <<"ENDSCRIPT";
1023: courseCount = 0;
1024: var courses = '';
1025: if (typeof(document.courselist.course_id.length) == 'undefined') {
1026: // only 1 course checkbox was created
1027: if (document.courselist.course_id.checked) {
1028: courses = courses + document.courselist.course_id.value + "&&";
1029: courseCount ++;
1030: }
1031: } else {
1032: for (var j=0; j<document.courselist.course_id.length; j++) {
1033: if (document.courselist.course_id[j].checked) {
1034: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 1035: courseCount ++;
1036: }
1.57 raeburn 1037: }
1038: }
1039: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
1040: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
1041: 'undefined') {
1042: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
1043: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 1044: } else {
1.57 raeburn 1045: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 1046: }
1.57 raeburn 1047: } else {
1048: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
1049: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
1050: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 1051: } else {
1.57 raeburn 1052: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 1053: }
1.55 raeburn 1054: }
1.57 raeburn 1055: }
1056: if (courseCount > 0) {
1057: courses = courses.substr(0,courses.length-2);
1058: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
1059: }
1060: ENDSCRIPT
1061: } else {
1.90 raeburn 1062: my ($name_code,$type_code);
1.57 raeburn 1063: if ($env{'form.cnameelement'} ne '') {
1064: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
1065: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 1066: }
1.90 raeburn 1067: if ($env{'form.typeelement'} ne '') {
1068: $type_code = 'opener.document.'.$env{'form.form'}.'.'.
1069: $env{'form.typeelement'}.'.value=document.courselist.type;';
1070: }
1071:
1.57 raeburn 1072: $output .= qq|
1.55 raeburn 1073: $name_code
1.90 raeburn 1074: $type_code
1.55 raeburn 1075: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
1076: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
1077: if (slct.options == undefined) {
1078: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
1079: }
1080: else {
1081: var i;
1082: for (i=0;i<slct.length;i++) {
1083: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 1084: }
1085: }
1.57 raeburn 1086: |;
1.54 raeburn 1087: }
1.57 raeburn 1088: $output .= qq|
1.55 raeburn 1089: if (openerForm == 'portform') {
1090: document.courselist.cnum.value = cname;
1091: document.courselist.cdom.value = cdom;
1092: }
1093: $autosubmit
1094: $lastaction
1.54 raeburn 1095: }
1.55 raeburn 1096: </script>
1.57 raeburn 1097: |;
1.55 raeburn 1098: return $output;
1.54 raeburn 1099: }
1100:
1.55 raeburn 1101: 1;
1102: __END__
1103:
1104: =pod
1105:
1106: =head1 NAME
1107:
1108: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
1109:
1110: =head1 SYNOPSIS
1111:
1112: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
1113:
1114: =head1 OVERVIEW
1115:
1116: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
1117:
1118: =head2 Search Criteria (Screen One)
1119:
1120: =head3 Criteria:
1121:
1122: =over 4
1123:
1124: =item *
1125: Course Activity - how recently was course last visited by anyone.
1126:
1127: =item *
1128: Course Domain - the domain of the course
1129:
1130: =item *
1.84 raeburn 1131: Type - Course or Community
1.55 raeburn 1132:
1133: =item *
1134: Course Institutional Code - the institutional identifier assigned to the course
1135:
1136: =item *
1137: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
1138:
1139: =item *
1140: Course Owner's Domain - the domain of the owner of the course
1141:
1142: =item *
1.76 bisitz 1143: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 1144:
1145: =item *
1146: 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).
1147:
1148: =back
1149:
1150: 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'}).
1151:
1152: =head2 Course Display (Screen Two)
1153:
1154: 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:
1155:
1156: =over 4
1157:
1158: =item *
1159: Course description
1160:
1161: =item *
1162: Domain description of course domain
1163:
1164: =item *
1165: Course institutional code
1166:
1167: =item *
1168: Course owner (username:domain)
1169:
1170: =back
1171:
1172: 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.
1173:
1174: 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.
1175:
1176: =head1 SUBROUTINES
1177:
1178: =over 4
1179:
1180: =item *
1181: X<create_user_javascript()>
1182: B<create_user_javascript($type)>:
1183:
1.83 raeburn 1184: Input: 1 - $type - the course type - Course or Community
1.55 raeburn 1185:
1186: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1187:
1188: Side Effects: None
1189:
1190: 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.
1191:
1192:
1193: =item *
1194: X<display_matched_courses()>
1.85 raeburn 1195: B<display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses)>:
1.55 raeburn 1196:
1.85 raeburn 1197: Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), username of new course owner, domain of new course owner, hash of courses.
1.55 raeburn 1198:
1199: Output: 0
1200:
1201: 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.
1202:
1203: =item *
1204: X<multiples_tag()>
1205: B<multiples_tag()>:
1206:
1207:
1208: Input: 0
1209:
1210: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
1211:
1212: Side Effects: None
1213:
1214: =item *
1215: X<build_filters()>
1.90 raeburn 1216: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem)>:
1.55 raeburn 1217:
1218:
1.90 raeburn 1219: Input: 11 - 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); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm), username and domain of new course owner who wants to clone, $tyepelem
1.55 raeburn 1220:
1221: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
1222:
1223: Side Effects: None
1224:
1225: =item *
1226: X<search_courses()>
1.93.2.2! raeburn 1227: B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,
! 1228: $domcloner)>:
1.55 raeburn 1229:
1230:
1.93.2.2! raeburn 1231: Input: 8 - 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; optional username of new course owner, optional domain of new course owner). Seventh and eighth needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in domain being filtered by (used when DC is using course creation form).
1.55 raeburn 1232:
1233: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
1234:
1235: Side Effects: None
1236:
1237:
1238: =item *
1239: X<course_chooser()>
1.85 raeburn 1240: B<course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone)>:
1.55 raeburn 1241:
1.85 raeburn 1242: Input: 5 - single (0) or multiple (1) courses; course domain, course number; course description; can clone course (1 if new course owner has cloning rights).
1.55 raeburn 1243:
1.85 raeburn 1244: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection.
1.55 raeburn 1245:
1246: Side Effects: None
1247:
1248:
1249: =item *
1250: X<gochoose_javascript()>
1.57 raeburn 1251: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 1252:
1.66 raeburn 1253: 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 1254:
1255: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1256:
1257: Side Effects: None
1258:
1259: javascript functions used when user selects a course(s). Different behavior depending on context:
1260:
1261: =back
1262:
1263: =over 8
1264:
1265: =item
1266:
1267: (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.
1268:
1269: =item
1270:
1271: (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.
1272:
1273: =item
1274:
1275: (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.
1276:
1277: =item
1.54 raeburn 1278:
1.55 raeburn 1279: (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 1280:
1.55 raeburn 1281: =item
1.54 raeburn 1282:
1.55 raeburn 1283: (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 1284:
1.55 raeburn 1285: =item
1.54 raeburn 1286:
1.55 raeburn 1287: (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 1288:
1.55 raeburn 1289: =item
1.49 raeburn 1290:
1.55 raeburn 1291: (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 1292:
1.84 raeburn 1293: =item
1294:
1295: (h) User requesting creation of a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
1296:
1.55 raeburn 1297: =back
1298:
1299: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>