Annotation of loncom/interface/lonpickcourse.pm, revision 1.112
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.112 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.111 2014/03/13 14:46:46 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;
1.106 raeburn 34: use Apache::lonhtmlcommon;
1.1 www 35: use Apache::loncoursedata;
36: use Apache::lonnet;
1.8 www 37: use Apache::lonlocal;
1.46 raeburn 38: use Apache::longroup;
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.106 raeburn 108: $loaditem{'onload'} .= 'setDefaultCredits();setRoles();setSections();';
1.30 raeburn 109: }
1.112 ! raeburn 110: my $js = &Apache::loncommon::js_changer();
1.107 raeburn 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.105 bisitz 136: $r->print(&Apache::lonhtmlcommon::scripttag($jscript));
1.55 raeburn 137: $r->print($submitopener);
1.54 raeburn 138:
1.55 raeburn 139: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 140: my $filter = {};
141: my $action = '/adm/pickcourse';
1.99 raeburn 142: my ($numtitles,$showroles,$nohost,@codetitles);
1.112 ! raeburn 143: unless ($onlyown) {
1.111 raeburn 144: my $filterlist = ['domainfilter','sincefilter'];
1.94 raeburn 145: # created filter for DCs only
146: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
1.95 raeburn 147: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
148: && $env{'form.form'} ne 'portform') {
1.94 raeburn 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'));
1.79 raeburn 155: if ($env{'form.form'} eq 'rules') {
1.111 raeburn 156: push(@{$filterlist},('personfilter','persondomfilter'));
157: if ($env{'form.persondomfilter'} eq '') {
158: unless ($env{'form.gosearch'}) {
159: $filter->{'persondomfilter'} = $env{'request.role.domain'};
160: }
161: } else {
162: $filter->{'persondomfilter'} =
163: &LONCAPA::clean_domain($env{'form.persondomfilter'});
164: }
1.79 raeburn 165: if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
166: if (&Apache::lonnet::homeserver($env{'form.personfilter'},
167: $env{'form.persondomfilter'}) eq 'no_host') {
168: $nohost = 1;
169: } else {
170: $showroles = 1;
171: }
172: }
173: } else {
1.111 raeburn 174: push(@{$filterlist},('ownerfilter','ownerdomfilter'));
1.79 raeburn 175: }
1.55 raeburn 176: # course ID filter for DCs only
177: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
178: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
179: push(@{$filterlist},'coursefilter');
180: }
1.85 raeburn 181: if ($cloneruname ne '' && $clonerudom ne '') {
182: push(@{$filterlist},'cloneableonly');
183: }
1.111 raeburn 184: if ((ref($filterlist) eq 'ARRAY') && (ref($filter) eq 'HASH')) {
185: foreach my $item (@{$filterlist}) {
186: $filter->{$item} = $env{'form.'.$item};
187: }
188: }
189: if ($env{'form.form'} eq 'portform') {
190: $filter->{'domainfilter'} ||= $env{'user.domain'};
191: } elsif ($env{'form.form'} eq 'studentform') {
192: $filter->{'domainfilter'} ||= $env{'request.role.domain'};
193: }
194: my $codedom;
195: if ($env{'form.fixeddom'}) {
196: $codedom = $env{'request.role.domain'};
197: } else {
198: $codedom = $filter->{'domainfilter'};
199: }
200: my ($clonetext,$clonewarning);
201: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
202: (my $coord_cloneable,$clonewarning) =
203: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
204: if ($env{'form.form'} eq 'ccrs') {
205: $clonetext = '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
206: }
207: if ($coord_cloneable) {
208: $clonetext .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
209: }
210: }
211: $r->print(&Apache::loncommon::build_filters($filterlist,$type,$roleelement,$multelement,
212: $filter,$action,\$numtitles,undef,$cloneruname,
213: $clonerudom,$typeelement,\@codetitles,$codedom,
214: $env{'form.form'},$env{'form.fixeddom'},
215: $env{'form.prevphase'},$env{'form.cnameelement'},
216: $env{'form.cnumelement'},$env{'form.cdomelement'},
217: $env{'form.setroles'},$clonetext,$clonewarning));
1.55 raeburn 218: }
1.54 raeburn 219:
220: # ---------------------------------------------------------------- Get the data
1.85 raeburn 221: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
222: $onlyown) {
1.98 raeburn 223: my $domcloner;
224: if ($env{'form.form'} eq 'ccrs') {
225: if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) &&
226: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
227: $domcloner = 1;
228: }
229: }
1.112 ! raeburn 230: my %courses;
! 231: if (!$onlyown) {
! 232: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
! 233: $r->rflush();
! 234: my $srchdom = $filter->{'domainfilter'};
! 235: %courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
! 236: $cloneruname,$clonerudom,$domcloner,
! 237: \@codetitles,$env{'form.cc_clone'});
! 238: } else {
! 239: $r->print('<br />');
! 240: my %coursehash = &Apache::loncommon::findallcourses();
! 241: foreach my $cid (sort(keys(%coursehash))) {
! 242: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
! 243: }
! 244: }
1.79 raeburn 245: if ($nohost) {
246: $r->print ('<span class="LC_warning">'.
247: &mt('User does not exist - username: [_1], domain: [_2].',
248: '<b>'.$filter->{'personfilter'}.'</b>',
249: '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
250: } else {
1.85 raeburn 251: &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
252: $clonerudom,%courses);
1.79 raeburn 253: }
1.54 raeburn 254: }
255: $r->print(&Apache::loncommon::end_page());
256: return OK;
257: }
258:
1.66 raeburn 259: sub processpick {
260: my $openerform = 'rolechoice';
261: if ($env{'form.form'} eq 'studentform') {
262: $openerform = $env{'form.form'};
263: }
264: my $process_pick = <<"ENDONE";
265: <script type="text/javascript">
266: function process_pick(dom) {
267: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
268: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
269: var okDomain = 0;
270: ENDONE
271: if ($openerform eq 'rolechoice') {
272: $process_pick .= <<"ENDTWO";
273: if (pickedDomain == dom) {
274: if (pickedCourse != '') {
1.88 raeburn 275: var ccrole = "cc";
276: var pickedType = "$env{'form.type'}";
277: if (pickedType == "Community") {
278: ccrole = "co";
279: }
280: var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
1.66 raeburn 281: opener.document.title='Role selected. Please stand by.';
282: opener.status='Role selected. Please stand by.';
283: opener.document.rolechoice.newrole.value=courseTarget
284: opener.document.rolechoice.submit();
285: }
286: }
287: else {
288: 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");
289: }
290: ENDTWO
291: } else {
292: $process_pick .= <<"ENDTHREE";
293: if (pickedDomain != dom) {
294: 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");
295: return;
296: }
297: ENDTHREE
298: }
299: $process_pick .= "
300: }
301:
302: </script>
303: ";
304: return $process_pick;
305: }
306:
1.55 raeburn 307: sub create_user_javascript {
308: my ($type) = @_;
309: my $output;
310: #javascript for reporting sections and groups then closing
311: if ($env{'form.pickedcourse'}) {
1.87 raeburn 312: my %coursedescription =
313: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
314: {'one_time' => '1'});
315: my $cdom = $coursedescription{'domain'};
316: my $cnum = $coursedescription{'num'};
317: my $crstype = $coursedescription{'type'};
1.106 raeburn 318: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
319: my ($showcredits,$credits);
320: if (($crstype ne 'Community') &&
1.109 raeburn 321: (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}))) {
1.106 raeburn 322: $showcredits = 1;
323: $credits = $coursedescription{'internal.defaultcredits'};
324: }
1.55 raeburn 325: my $sec_element = 'currsec';
326: my $grplist_element = 'groups';
327: my ($sections,$groups) =
328: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
329: my $num_sections = scalar(@{$sections});
330: my $seclist = join(',',@{$sections});
331: my $num_groups = scalar(@{$groups});
332: my $groupslist = join(',',@{$groups});
333: $output = qq|
334: <script type="text/javascript">
1.106 raeburn 335: // <![CDATA[
1.55 raeburn 336: function setSections() {
337: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
338: window.opener.setSect('$seclist');
1.87 raeburn 339: self.close();
340: }
341: function setRoles() {
342: window.opener.setRole('$crstype');
1.55 raeburn 343: }
1.106 raeburn 344: |;
345: if ($showcredits) {
346: $output .= qq|
347: function setDefaultCredits() {
348: window.opener.setCredits('$credits');
349: }
350: |;
351: }
352: $output .= qq|
353: // ]]>
1.55 raeburn 354: </script>
355: |;
356: }
357: return $output;
358: }
359:
1.54 raeburn 360: sub display_matched_courses {
1.85 raeburn 361: my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
1.55 raeburn 362: if ($env{'form.form'} eq 'portform') {
363: $action = '/adm/portfolio';
364: }
1.68 raeburn 365: my $numcourses = keys(%courses);
1.55 raeburn 366: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 367: if ($env{'form.form'} eq 'modifycourse') {
368: if ($numcourses > 0) {
1.89 raeburn 369: my $ccrole = 'cc';
370: if ($type eq 'Community') {
371: $ccrole = 'co';
372: }
373: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.68 raeburn 374: my $dctitle = &Apache::lonnet::plaintext('dc');
1.93 raeburn 375: my $ccrolechk = ' ';
376: my $menuchk = ' checked="checked" ';
1.68 raeburn 377: $r->print(
1.106 raeburn 378: '<div class="LC_left_float">'
379: .'<fieldset>'
380: .'<legend>'.&mt('Pick action').'</legend>'
381: .'<span class="LC_nobreak"><label>'
1.75 bisitz 382: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
1.89 raeburn 383: .' ');
384: if ($type eq 'Community') {
385: $r->print(&mt('Enter the community with the role of [_1].',$cctitle));
386: } else {
387: $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
388: }
1.106 raeburn 389: $r->print('</label></span><br />'
390: .'<span class="LC_nobreak"><label>'
1.89 raeburn 391: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> ');
392: if ($type eq 'Community') {
393: $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
394: } else {
395: $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
396: }
1.106 raeburn 397: $r->print('</label></span>'
398: .'</fieldset></div>'
399: .'<br clear="all" />'
1.75 bisitz 400: );
1.68 raeburn 401: }
402: }
1.54 raeburn 403: my %by_descrip;
404: foreach my $course (keys(%courses)) {
405: my $descr;
1.64 raeburn 406: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 407: $descr = $courses{$course}{'description'};
1.64 raeburn 408: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 409: $descr = &unescape($1);
1.34 albertel 410: } else {
1.54 raeburn 411: $descr = &unescape($courses{$course});
412: }
413: my $description = $descr;
414: push (@{$by_descrip{$description}}, $course);
415: }
1.71 bisitz 416:
1.54 raeburn 417: if ($numcourses > 1 && $multiple) {
1.104 bisitz 418: $r->print('<input type="button" value="'.&mt('check all').'"
1.54 raeburn 419: onclick="javascript:checkAll(document.courselist.course_id)" />
1.104 bisitz 420: <input type="button" value="'.&mt('uncheck all').'"
1.54 raeburn 421: onclick="javascript:uncheckAll(document.courselist.course_id)" />
422: <br /><br />');
423: }
1.71 bisitz 424:
425: if (%courses) {
426: $r->print(&Apache::loncommon::start_data_table());
427: $r->print(&Apache::loncommon::start_data_table_header_row());
1.89 raeburn 428: my $titlehdr = &mt('Course Title');
429: if ($type eq 'Community') {
430: $titlehdr = &mt('Community Title');
431: }
1.71 bisitz 432: $r->print('<th>'.&mt('Select').'</th>'
1.89 raeburn 433: .'<th>'.$titlehdr.'</th>'
434: .'<th>'.&mt('Domain').'</th>');
435: unless ($type eq 'Community') {
436: $r->print('<th>'.&mt('Course Code').'</th>');
437: }
438: $r->print('<th>'.&mt('Owner/Co-owner(s)').'</th>');
1.79 raeburn 439: if ($showroles) {
440: $r->print('<th>'.&mt("Role(s) for [_1]",
441: &Apache::loncommon::plainname($env{'form.personfilter'},
442: $env{'form.persondomfilter'},'firstname')).'</th>');
443: }
1.71 bisitz 444: $r->print(&Apache::loncommon::end_data_table_header_row());
445: }
1.92 raeburn 446: my %cc_cloneable;
447: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
448: my ($coord_cloneable,$warning) =
449: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
450: if ($coord_cloneable) {
451: map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable);
452: }
453: }
1.54 raeburn 454: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
455: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 456: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 457: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
458: $cleandesc=~s/'/\\'/g;
459: my ($cdom,$cnum)=split(/\_/,$course);
1.85 raeburn 460: my ($descr,$instcode,$ttype,$canclone,@owners);
1.64 raeburn 461: if (ref($courses{$course}) eq 'HASH') {
462: $descr = $courses{$course}{'description'};
1.85 raeburn 463: $instcode = $courses{$course}{'inst_code'};
464: $ttype = $courses{$course}{'type'};
465: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.98 raeburn 466: if ($env{'form.form'} eq 'ccrs') {
467: if (($env{'request.role.domain'} eq $cdom) &&
468: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
469: $canclone = 1;
470: }
471: }
472: unless ($canclone) {
473: if ($cc_cloneable{$cnum.':'.$cdom}) {
474: $canclone = 1;
475: }
1.92 raeburn 476: }
477: unless ($canclone) {
478: my $cloners = $courses{$course}{'cloners'};
479: if ($cloners ne '') {
480: my @cloneable = split(',',$cloners);
481: if (grep(/^\*$/,@cloneable)) {
482: $canclone = 1;
483: }
1.97 raeburn 484: if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) {
1.92 raeburn 485: $canclone = 1;
486: }
487: if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
488: $canclone = 1;
489: }
1.85 raeburn 490: }
491: }
492: }
1.101 raeburn 493: push(@owners,$courses{$course}{'owner'});
494: if ($courses{$course}{'co-owners'} ne '') {
495: foreach my $item (split(/,/,$courses{$course}{'co-owners'})) {
496: push(@owners,$item);
1.64 raeburn 497: }
498: }
499: } else {
500: my $singleowner;
501: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
502: push(@owners,&unescape($singleowner));
503: }
1.93 raeburn 504: my $ownerstr = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } @owners);
1.85 raeburn 505: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).'</td>');
1.71 bisitz 506: $r->print('<td>'.$description.'</td>');
507: $r->print('<td>');
508: $r->print(&Apache::lonnet::domain($cdom,'description')?
509: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
510: $r->print('</td>');
1.89 raeburn 511: unless ($type eq 'Community') {
512: $r->print('<td>');
513: if ($instcode ne '') {
514: $r->print(&unescape($instcode));
515: } else {
516: $r->print(' ');
517: }
518: $r->print('</td>');
1.54 raeburn 519: }
1.72 raeburn 520: $r->print('<td>'.$ownerstr.'</td>');
1.79 raeburn 521: if ($showroles) {
522: $r->print('<td>');
523: my $rolestr;
524: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
525: my @roles = sort(@{$courses{$course}{'roles'}});
526: foreach my $role (@roles) {
527: if ($role =~ /^cr/) {
528: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
529: $rolestr .= $crtitle.', ';
530: } else {
1.89 raeburn 531: $rolestr .= &Apache::lonnet::plaintext($role,$type).', ';
1.79 raeburn 532: }
533: }
534: $rolestr =~ s/\, $//;
535: }
536: $r->print($rolestr.'</td>');
537: }
1.54 raeburn 538: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 539: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 540: # $r->print("<br />\n");
1.19 raeburn 541: }
542: }
1.72 raeburn 543: if (%courses) {
544: $r->print(&Apache::loncommon::end_data_table());
545: }
1.71 bisitz 546:
1.54 raeburn 547: if (!%courses) {
1.104 bisitz 548: $r->print('<p class="LC_info">'.&mt('None found').'</p>');
1.54 raeburn 549: } elsif ($multiple) {
1.108 bisitz 550: $r->print('<input type="button" value="'.&mt('Submit').'" onclick="gochoose('."'','','')".'" />');
1.54 raeburn 551: }
552: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
553: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
554: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
555: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
556: $r->print('<input type="hidden" name="roleelement" value="'.
557: $env{'form.roleelement'}.'" />'."\n");
558: }
1.55 raeburn 559: if ($env{'form.form'} eq 'portform') {
560: $r->print('<input type="hidden" name="cnum" value="" />');
561: $r->print('<input type="hidden" name="cdom" value="" />');
562: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
563: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 564: } elsif ($env{'form.form'} eq 'modifycourse') {
1.85 raeburn 565: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 566: } else {
567: $r->print('<input type="hidden" name="cnumelement" value="'.
568: $env{'form.cnumelement'}.'" />'."\n".
569: '<input type="hidden" name="cdomelement" value="'.
570: $env{'form.cdomelement'}.'" />'."\n");
1.90 raeburn 571: if ($env{'form.typeelement'} ne '') {
572: $r->print('<input type="hidden" name="typeelement" value="'.
573: $env{'form.typeelement'}.'" />'."\n");
574:
575: }
1.55 raeburn 576: }
1.78 raeburn 577: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
578: $r->print('<input type="hidden" name="fixeddom" value="'.
579: $env{'form.fixeddom'}.'" />');
580: }
581: if ($env{'form.numtitles'}) {
582: $r->print('<input type="hidden" name="numtitles" value="'.
583: $env{'form.numtitles'}.'" />');
584: }
1.54 raeburn 585: $r->print("</form>\n");
586: return;
587: }
588:
589: sub multiples_tag {
1.55 raeburn 590: my $jscript = &Apache::loncommon::check_uncheck_jscript();
591: my $multelement = '<input type="hidden" name="multiple" value="1" />';
592: return ($jscript,$multelement);
1.1 www 593: }
1.30 raeburn 594:
1.92 raeburn 595: sub get_coordinator_cloneable {
596: my ($cloneruname,$clonerudom,$type) = @_;
1.100 www 597: if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
598: my $warning = '<div class="LC_warning">'.&mt('Intended course owner not specified').
599: '</div>';
600: return ('',$warning);
601: } elsif (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
1.92 raeburn 602: my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
603: '</div>';
604: return ('',$warning);
605: } else {
606: my ($cc_clone,$ccrole);
607: if ($type eq 'Community') {
608: $ccrole = 'co';
609: } elsif ($type eq 'Course') {
610: $ccrole = 'cc';
611: }
612: my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
613: 'userroles',['active'], [$ccrole]);
614: foreach my $key (sort(keys(%ccroles))) {
615: my ($cnum,$cdom,$role) = split(':',$key);
616: $cc_clone .= $cdom.':'.$cnum.'&';
617: }
618: $cc_clone =~ s/\&$//;
619: return ($cc_clone);
620: }
621: }
622:
1.30 raeburn 623: sub course_chooser {
1.85 raeburn 624: my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
1.30 raeburn 625: my $output;
1.35 raeburn 626: if ($multiple) {
1.32 albertel 627: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.85 raeburn 628: } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) {
629: if ($env{'form.form'} eq 'ccrs') {
630: $output = &mt('No cloning for ').$env{'form.cloner'}."\n";
631: } else {
632: $output = &mt('No rights to clone')."\n";
633: }
1.30 raeburn 634: } else {
1.108 bisitz 635: $output = '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.30 raeburn 636: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
637: }
638: return $output;
1.49 raeburn 639: }
640:
1.55 raeburn 641: sub gochoose_javascript {
1.57 raeburn 642: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 643: my %elements = (
644: 'Course' => {
645: name => 'coursepick',
646: total => 'coursetotal',
647: list => 'courselist',
648: },
1.83 raeburn 649: 'Community' => {
1.88 raeburn 650: name => 'coursepick',
651: total => 'coursetotal',
652: list => 'courselist',
1.55 raeburn 653: },
654: );
1.107 raeburn 655: my $output = qq|
1.57 raeburn 656: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 657: var openerForm = "$env{'form.form'}";
658: courseCount = 0;
659: var courses = '';
1.57 raeburn 660: |;
661: if ($multiple) {
662: $output .= <<"ENDSCRIPT";
663: courseCount = 0;
664: var courses = '';
665: if (typeof(document.courselist.course_id.length) == 'undefined') {
666: // only 1 course checkbox was created
667: if (document.courselist.course_id.checked) {
668: courses = courses + document.courselist.course_id.value + "&&";
669: courseCount ++;
670: }
671: } else {
672: for (var j=0; j<document.courselist.course_id.length; j++) {
673: if (document.courselist.course_id[j].checked) {
674: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 675: courseCount ++;
676: }
1.57 raeburn 677: }
678: }
679: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
680: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
681: 'undefined') {
682: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
683: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 684: } else {
1.57 raeburn 685: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 686: }
1.57 raeburn 687: } else {
688: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
689: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
690: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 691: } else {
1.57 raeburn 692: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 693: }
1.55 raeburn 694: }
1.57 raeburn 695: }
696: if (courseCount > 0) {
697: courses = courses.substr(0,courses.length-2);
698: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
699: }
700: ENDSCRIPT
701: } else {
1.90 raeburn 702: my ($name_code,$type_code);
1.57 raeburn 703: if ($env{'form.cnameelement'} ne '') {
1.103 raeburn 704: $name_code = <<ENDNAMECODE;
705: var showcdesc = cdesc;
706: if (cdesc.length > 25) {
707: showcdesc = cdesc.substr(0,25)+' ...';
708: }
709: opener.document.$env{'form.form'}.$env{'form.cnameelement'}.value=showcdesc;
710: ENDNAMECODE
1.55 raeburn 711: }
1.90 raeburn 712: if ($env{'form.typeelement'} ne '') {
713: $type_code = 'opener.document.'.$env{'form.form'}.'.'.
714: $env{'form.typeelement'}.'.value=document.courselist.type;';
715: }
716:
1.57 raeburn 717: $output .= qq|
1.55 raeburn 718: $name_code
1.90 raeburn 719: $type_code
1.55 raeburn 720: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
721: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
722: if (slct.options == undefined) {
723: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
724: }
725: else {
726: var i;
727: for (i=0;i<slct.length;i++) {
728: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 729: }
730: }
1.57 raeburn 731: |;
1.54 raeburn 732: }
1.57 raeburn 733: $output .= qq|
1.55 raeburn 734: if (openerForm == 'portform') {
735: document.courselist.cnum.value = cname;
736: document.courselist.cdom.value = cdom;
737: }
738: $autosubmit
739: $lastaction
1.54 raeburn 740: }
1.57 raeburn 741: |;
1.105 bisitz 742: return &Apache::lonhtmlcommon::scripttag($output);
1.54 raeburn 743: }
744:
1.55 raeburn 745: 1;
746: __END__
747:
748: =pod
749:
750: =head1 NAME
751:
752: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
753:
754: =head1 SYNOPSIS
755:
756: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
757:
758: =head1 OVERVIEW
759:
760: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
761:
762: =head2 Search Criteria (Screen One)
763:
764: =head3 Criteria:
765:
766: =over 4
767:
768: =item *
769: Course Activity - how recently was course last visited by anyone.
770:
771: =item *
772: Course Domain - the domain of the course
773:
774: =item *
1.84 raeburn 775: Type - Course or Community
1.55 raeburn 776:
777: =item *
778: Course Institutional Code - the institutional identifier assigned to the course
779:
780: =item *
781: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
782:
783: =item *
784: Course Owner's Domain - the domain of the owner of the course
785:
786: =item *
1.76 bisitz 787: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 788:
789: =item *
790: 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).
791:
792: =back
793:
794: 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'}).
795:
796: =head2 Course Display (Screen Two)
797:
798: 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:
799:
800: =over 4
801:
802: =item *
803: Course description
804:
805: =item *
806: Domain description of course domain
807:
808: =item *
809: Course institutional code
810:
811: =item *
812: Course owner (username:domain)
813:
814: =back
815:
816: 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.
817:
818: 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.
819:
820: =head1 SUBROUTINES
821:
822: =over 4
823:
824: =item *
825: X<create_user_javascript()>
826: B<create_user_javascript($type)>:
827:
1.83 raeburn 828: Input: 1 - $type - the course type - Course or Community
1.55 raeburn 829:
830: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
831:
832: Side Effects: None
833:
834: 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.
835:
836:
837: =item *
838: X<display_matched_courses()>
1.85 raeburn 839: B<display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses)>:
1.55 raeburn 840:
1.85 raeburn 841: 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 842:
843: Output: 0
844:
845: 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.
846:
847: =item *
848: X<multiples_tag()>
849: B<multiples_tag()>:
850:
851:
852: Input: 0
853:
854: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
855:
856: Side Effects: None
857:
858:
859: =item *
860: X<course_chooser()>
1.85 raeburn 861: B<course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone)>:
1.55 raeburn 862:
1.85 raeburn 863: 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 864:
1.85 raeburn 865: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection.
1.55 raeburn 866:
867: Side Effects: None
868:
869:
870: =item *
871: X<gochoose_javascript()>
1.57 raeburn 872: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 873:
1.66 raeburn 874: 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 875:
876: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
877:
878: Side Effects: None
879:
880: javascript functions used when user selects a course(s). Different behavior depending on context:
881:
882: =back
883:
884: =over 8
885:
886: =item
887:
888: (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.
889:
890: =item
891:
892: (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.
893:
894: =item
895:
896: (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.
897:
898: =item
1.54 raeburn 899:
1.55 raeburn 900: (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 901:
1.55 raeburn 902: =item
1.54 raeburn 903:
1.55 raeburn 904: (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 905:
1.55 raeburn 906: =item
1.54 raeburn 907:
1.55 raeburn 908: (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 909:
1.55 raeburn 910: =item
1.49 raeburn 911:
1.102 bisitz 912: (g) Bubblesheet Scanning Operator uploading a bubblesheet file to a course - course number is written to visible form element in opener window. Child window closes.
1.30 raeburn 913:
1.84 raeburn 914: =item
915:
916: (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.
917:
1.55 raeburn 918: =back
919:
920: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>