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