Annotation of loncom/interface/lonpickcourse.pm, revision 1.125
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.125 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.124 2017/01/03 17:47:57 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.123 raeburn 40: use JSON::DWIW;
1.1 www 41:
42: sub handler {
43: my $r = shift;
1.123 raeburn 44: if ($env{'form.context'} eq 'adhoc') {
45: &Apache::loncommon::content_type($r,'application/json');
46: $r->send_http_header;
1.125 ! raeburn 47: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'},1);
1.123 raeburn 48: if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {
49: my $response = [];
50: if (@{$possroles}) {
51: foreach my $role (@{$possroles}) {
52: push(@{$response},
53: { name => $role,
54: desc => $description->{$role},
55: });
56: }
57: }
58: $r->print(JSON::DWIW->to_json({roles => $response}));
59: }
60: return OK;
61: }
1.8 www 62: &Apache::loncommon::content_type($r,'text/html');
1.1 www 63: $r->send_http_header;
64: return OK if $r->header_only;
1.123 raeburn 65:
1.1 www 66: # ------------------------------------------------------------ Print the screen
1.40 albertel 67:
1.55 raeburn 68: # Get parameters from query string
1.1 www 69: &Apache::loncommon::get_unprocessed_cgi
1.55 raeburn 70: ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19 raeburn 71: 'cdomelement','cnameelement','roleelement',
1.116 raeburn 72: 'multiple','type','setroles','fixeddom','cloner',
73: 'crscode','crsdom']);
1.90 raeburn 74: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
1.123 raeburn 75: $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom,$crscode,
76: $crsdom,$rolechooser);
1.55 raeburn 77:
1.117 raeburn 78: # Get course type - Course, Community or Placement.
1.54 raeburn 79: $type = $env{'form.type'};
80: if (!defined($env{'form.type'})) {
81: $type = 'Course';
82: }
1.82 bisitz 83: $title = 'Selecting a '.$type;
1.54 raeburn 84:
85: # Setup for multiple course selections, if flag for multiples set.
1.55 raeburn 86: $multiple = $env{'form.multiple'};
87: if ($multiple) {
88: ($jscript,$multelement) = &multiples_tag();
1.82 bisitz 89: $title = 'Selecting '.$type.'(s)';
1.54 raeburn 90: }
91:
1.120 raeburn 92: # if called when a DC or DH is selecting a course
93: my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});
1.54 raeburn 94: if ($roledom) {
1.120 raeburn 95: $roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />';
1.66 raeburn 96: $submitopener = &processpick();
1.120 raeburn 97: $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';
1.123 raeburn 98: if ($rolename eq 'dh') {
99: my %lt = &Apache::lonlocal::texthash(
100: title => 'Ad hoc role selection',
101: preamble => 'Please choose an ad hoc role in the course.',
102: cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
103: );
104:
105: $rolechooser = <<"END";
106: <div id="LC_adhocrole_chooser" title="$lt{'title'}">
107: <p>$lt{'preamble'}</p>
108: <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
109: <div id="LC_choose_adhoc">
110: </div>
111: <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
112: </form>
113: <p>$lt{'cancel'}</p>
114: </div>
115: END
116: }
1.54 raeburn 117: }
1.90 raeburn 118: if ($env{'form.typeelement'} ne '') {
119: $typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />';
120: }
1.54 raeburn 121:
1.92 raeburn 122: # if called when a DC is creating a course for another user.
1.85 raeburn 123: if ($env{'form.form'} eq 'ccrs') {
124: ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/);
1.116 raeburn 125: $crscode = $env{'form.crscode'};
126: $crsdom = $env{'request.role.domain'};
1.85 raeburn 127: }
128:
129: # if called when requesting a course
130: if ($env{'form.form'} eq 'requestcrs') {
131: $cloneruname = $env{'user.name'};
132: $clonerudom = $env{'user.domain'};
1.116 raeburn 133: $crscode = $env{'form.crscode'};
134: $crsdom = $env{'form.crsdom'};
1.85 raeburn 135: }
136:
1.54 raeburn 137: my $onlyown = 0;
1.55 raeburn 138: # if called to assign course-based portfolio access control
1.59 raeburn 139: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 140: $onlyown = 1;
1.49 raeburn 141: }
1.55 raeburn 142:
143: my %loaditem;
1.84 raeburn 144: if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) {
145: if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) {
146: $loaditem{'onload'} = 'setElements(document.filterpicker); ';
147: }
1.78 raeburn 148: }
149:
1.66 raeburn 150: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
151: ($env{'form.pickedcourse'})) {
1.115 raeburn 152: if ($type ne 'Community') {
153: my %coursedescription =
154: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
155: {'one_time' => '1'});
156: my $cdom = $coursedescription{'domain'};
157: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
158: if (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'})) {
159: $loaditem{'onload'} .= 'setDefaultCredits();';
160: }
161: }
162: $loaditem{'onload'} .= 'setRoles();setSections();';
1.30 raeburn 163: }
1.113 raeburn 164: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) && (!$onlyown)) {
165: $loaditem{'onload'} .= 'hideSearching(); ';
166: }
1.112 raeburn 167: my $js = &Apache::loncommon::js_changer();
1.107 raeburn 168: $r->print(&Apache::loncommon::start_page($title,$js,
1.42 albertel 169: {'add_entries' => \%loaditem,
1.41 albertel 170: 'no_nav_bar' => 1, }));
1.55 raeburn 171:
172: if ($env{'form.form'} eq 'portform') {
173: $lastaction = 'document.courselist.submit()';
1.67 raeburn 174: } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
175: !$multiple)) {
1.55 raeburn 176: $lastaction =
177: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
178: 'document.courselist.submit();';
1.34 albertel 179: } else {
1.55 raeburn 180: $lastaction = 'self.close()';
1.1 www 181: }
1.19 raeburn 182:
1.55 raeburn 183: # if called to assign a role in a course to a user via CUSR
1.66 raeburn 184: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68 raeburn 185: $r->print(&create_user_javascript($type));
1.55 raeburn 186: }
1.54 raeburn 187:
1.55 raeburn 188: # print javascript functions for choosing a course
1.85 raeburn 189: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
190: $onlyown) {
1.123 raeburn 191: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction,
192: $rolename,$rolechooser));
1.55 raeburn 193: }
1.105 bisitz 194: $r->print(&Apache::lonhtmlcommon::scripttag($jscript));
1.55 raeburn 195: $r->print($submitopener);
1.54 raeburn 196:
1.55 raeburn 197: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 198: my $filter = {};
199: my $action = '/adm/pickcourse';
1.99 raeburn 200: my ($numtitles,$showroles,$nohost,@codetitles);
1.112 raeburn 201: unless ($onlyown) {
1.111 raeburn 202: my $filterlist = ['domainfilter','sincefilter'];
1.94 raeburn 203: # created filter for DCs only
204: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
1.95 raeburn 205: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})
206: && $env{'form.form'} ne 'portform') {
1.94 raeburn 207: my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
208: if ($loncaparev ne 'unknown_cmd') {
209: push(@{$filterlist},'createdfilter');
210: }
211: }
212: push(@{$filterlist},('descriptfilter','instcodefilter'));
1.79 raeburn 213: if ($env{'form.form'} eq 'rules') {
1.111 raeburn 214: push(@{$filterlist},('personfilter','persondomfilter'));
215: if ($env{'form.persondomfilter'} eq '') {
216: unless ($env{'form.gosearch'}) {
217: $filter->{'persondomfilter'} = $env{'request.role.domain'};
218: }
219: } else {
220: $filter->{'persondomfilter'} =
221: &LONCAPA::clean_domain($env{'form.persondomfilter'});
222: }
1.79 raeburn 223: if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
224: if (&Apache::lonnet::homeserver($env{'form.personfilter'},
225: $env{'form.persondomfilter'}) eq 'no_host') {
226: $nohost = 1;
227: } else {
228: $showroles = 1;
229: }
230: }
231: } else {
1.111 raeburn 232: push(@{$filterlist},('ownerfilter','ownerdomfilter'));
1.79 raeburn 233: }
1.55 raeburn 234: # course ID filter for DCs only
235: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
236: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
237: push(@{$filterlist},'coursefilter');
238: }
1.85 raeburn 239: if ($cloneruname ne '' && $clonerudom ne '') {
240: push(@{$filterlist},'cloneableonly');
241: }
1.111 raeburn 242: if ((ref($filterlist) eq 'ARRAY') && (ref($filter) eq 'HASH')) {
243: foreach my $item (@{$filterlist}) {
244: $filter->{$item} = $env{'form.'.$item};
245: }
246: }
247: if ($env{'form.form'} eq 'portform') {
248: $filter->{'domainfilter'} ||= $env{'user.domain'};
249: } elsif ($env{'form.form'} eq 'studentform') {
250: $filter->{'domainfilter'} ||= $env{'request.role.domain'};
251: }
252: my $codedom;
253: if ($env{'form.fixeddom'}) {
254: $codedom = $env{'request.role.domain'};
255: } else {
256: $codedom = $filter->{'domainfilter'};
257: }
258: my ($clonetext,$clonewarning);
259: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
260: (my $coord_cloneable,$clonewarning) =
261: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
262: if ($env{'form.form'} eq 'ccrs') {
263: $clonetext = '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
264: }
265: if ($coord_cloneable) {
266: $clonetext .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
267: }
1.116 raeburn 268: if ($crscode ne '') {
269: $clonetext .= '<input type="hidden" name="crscode" value="'.$crscode.'" />';
270: }
271: if ($crsdom ne '') {
272: $clonetext .= '<input type="hidden" name="crsdom" value="'.$crsdom.'" />';
273: }
1.111 raeburn 274: }
275: $r->print(&Apache::loncommon::build_filters($filterlist,$type,$roleelement,$multelement,
276: $filter,$action,\$numtitles,undef,$cloneruname,
277: $clonerudom,$typeelement,\@codetitles,$codedom,
278: $env{'form.form'},$env{'form.fixeddom'},
279: $env{'form.prevphase'},$env{'form.cnameelement'},
280: $env{'form.cnumelement'},$env{'form.cdomelement'},
281: $env{'form.setroles'},$clonetext,$clonewarning));
1.55 raeburn 282: }
1.54 raeburn 283:
284: # ---------------------------------------------------------------- Get the data
1.85 raeburn 285: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
286: $onlyown) {
1.98 raeburn 287: my $domcloner;
288: if ($env{'form.form'} eq 'ccrs') {
289: if (($env{'request.role.domain'} eq $env{'form.domainfilter'}) &&
290: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
291: $domcloner = 1;
292: }
293: }
1.112 raeburn 294: my %courses;
295: if (!$onlyown) {
296: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
297: $r->rflush();
298: my $srchdom = $filter->{'domainfilter'};
299: %courses = &Apache::loncommon::search_courses($srchdom,$type,$filter,$numtitles,
300: $cloneruname,$clonerudom,$domcloner,
1.116 raeburn 301: \@codetitles,$env{'form.cc_clone'},
302: $crsdom,$crscode);
1.112 raeburn 303: } else {
304: $r->print('<br />');
305: my %coursehash = &Apache::loncommon::findallcourses();
306: foreach my $cid (sort(keys(%coursehash))) {
307: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
308: }
309: }
1.79 raeburn 310: if ($nohost) {
311: $r->print ('<span class="LC_warning">'.
312: &mt('User does not exist - username: [_1], domain: [_2].',
313: '<b>'.$filter->{'personfilter'}.'</b>',
314: '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
315: } else {
1.85 raeburn 316: &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
1.116 raeburn 317: $clonerudom,$crsdom,$crscode,%courses);
1.79 raeburn 318: }
1.54 raeburn 319: }
320: $r->print(&Apache::loncommon::end_page());
321: return OK;
322: }
323:
1.66 raeburn 324: sub processpick {
325: my $openerform = 'rolechoice';
326: if ($env{'form.form'} eq 'studentform') {
327: $openerform = $env{'form.form'};
328: }
329: my $process_pick = <<"ENDONE";
330: <script type="text/javascript">
1.120 raeburn 331: function process_pick(dom,rolename) {
1.66 raeburn 332: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
333: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
334: var okDomain = 0;
335: ENDONE
336: if ($openerform eq 'rolechoice') {
337: $process_pick .= <<"ENDTWO";
338: if (pickedDomain == dom) {
339: if (pickedCourse != '') {
1.120 raeburn 340: var courseTarget;
341: if (rolename == 'cc') {
342: var ccrole = "cc";
343: var pickedType = "$env{'form.type'}";
344: if (pickedType == "Community") {
345: ccrole = "co";
346: }
347: courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse;
348: } else {
349: if (!/\\W/.test(rolename)) {
350: courseTarget = "cr/"+pickedDomain+"/"+pickedDomain+"-domainconfig/"+rolename+"./"+pickedDomain+"/"+pickedCourse;
351: }
352: }
353: if ((courseTarget != '') && (courseTarget != undefined)) {
354: opener.document.title='Role selected. Please stand by.';
355: opener.status='Role selected. Please stand by.';
356: opener.document.rolechoice.newrole.value=courseTarget;
357: opener.document.rolechoice.submit();
358: } else {
359: alert("Invalid role selection");
360: return;
361: }
1.66 raeburn 362: }
1.120 raeburn 363: }
1.66 raeburn 364: else {
365: 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");
366: }
367: ENDTWO
368: } else {
369: $process_pick .= <<"ENDTHREE";
370: if (pickedDomain != dom) {
371: 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");
372: return;
373: }
374: ENDTHREE
375: }
376: $process_pick .= "
377: }
378:
379: </script>
380: ";
381: return $process_pick;
382: }
383:
1.55 raeburn 384: sub create_user_javascript {
385: my ($type) = @_;
386: my $output;
387: #javascript for reporting sections and groups then closing
388: if ($env{'form.pickedcourse'}) {
1.87 raeburn 389: my %coursedescription =
390: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
391: {'one_time' => '1'});
392: my $cdom = $coursedescription{'domain'};
393: my $cnum = $coursedescription{'num'};
394: my $crstype = $coursedescription{'type'};
1.106 raeburn 395: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
396: my ($showcredits,$credits);
397: if (($crstype ne 'Community') &&
1.109 raeburn 398: (($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}))) {
1.106 raeburn 399: $showcredits = 1;
400: $credits = $coursedescription{'internal.defaultcredits'};
401: }
1.55 raeburn 402: my $sec_element = 'currsec';
403: my $grplist_element = 'groups';
404: my ($sections,$groups) =
405: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
406: my $num_sections = scalar(@{$sections});
407: my $seclist = join(',',@{$sections});
408: my $num_groups = scalar(@{$groups});
409: my $groupslist = join(',',@{$groups});
410: $output = qq|
411: <script type="text/javascript">
1.106 raeburn 412: // <![CDATA[
1.55 raeburn 413: function setSections() {
414: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
415: window.opener.setSect('$seclist');
1.87 raeburn 416: self.close();
417: }
418: function setRoles() {
419: window.opener.setRole('$crstype');
1.55 raeburn 420: }
1.106 raeburn 421: |;
422: if ($showcredits) {
423: $output .= qq|
424: function setDefaultCredits() {
425: window.opener.setCredits('$credits');
426: }
427: |;
428: }
429: $output .= qq|
430: // ]]>
1.55 raeburn 431: </script>
432: |;
433: }
434: return $output;
435: }
436:
1.54 raeburn 437: sub display_matched_courses {
1.116 raeburn 438: my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,$crsdom,$crscode,%courses) = @_;
1.55 raeburn 439: if ($env{'form.form'} eq 'portform') {
440: $action = '/adm/portfolio';
441: }
1.68 raeburn 442: my $numcourses = keys(%courses);
1.125 ! raeburn 443: $r->print('<form name="courselist" method="post" action="'.$action.'" id="LCcoursepicker">');
1.68 raeburn 444: if ($env{'form.form'} eq 'modifycourse') {
445: if ($numcourses > 0) {
1.89 raeburn 446: my $ccrole = 'cc';
447: if ($type eq 'Community') {
448: $ccrole = 'co';
449: }
450: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.68 raeburn 451: my $dctitle = &Apache::lonnet::plaintext('dc');
1.93 raeburn 452: my $ccrolechk = ' ';
1.122 raeburn 453: my $possrole;
1.93 raeburn 454: my $menuchk = ' checked="checked" ';
1.68 raeburn 455: $r->print(
1.106 raeburn 456: '<div class="LC_left_float">'
457: .'<fieldset>'
1.122 raeburn 458: .'<legend>'.&mt('Pick action').'</legend>');
459: my $roleradio = '<span class="LC_nobreak"><label>'.
460: '<input type="radio" name="phase" value="adhocrole"'.$ccrolechk.'/>'.' ';
1.119 raeburn 461: if (&Apache::lonnet::allowed('ccc',$crsdom)) {
1.122 raeburn 462: $possrole = 1;
463: $r->print($roleradio);
1.119 raeburn 464: if ($type eq 'Community') {
465: $r->print(&mt('Enter the community with the role of [_1].',$cctitle));
466: } elsif ($type eq 'Placement') {
467: $r->print(&mt('Enter the placement test with the role of [_1].',$cctitle));
468: } else {
469: $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
470: }
471: } elsif (&Apache::lonnet::allowed('rar',$crsdom)) {
1.125 ! raeburn 472: my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom);
! 473: if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
! 474: if (@{$roles_by_num} > 1) {
! 475: $r->print($roleradio);
1.119 raeburn 476: if ($type eq 'Community') {
1.125 ! raeburn 477: $r->print(&mt('Enter the community with one of the available ad hoc roles.'));
1.119 raeburn 478: } elsif ($type eq 'Placement') {
1.125 ! raeburn 479: $r->print(&mt('Enter the placement test with one of the available ad hoc roles.'));
1.119 raeburn 480: } else {
1.125 ! raeburn 481: $r->print(&mt('Enter the course with one of the available ad hoc roles.'));
1.119 raeburn 482: }
1.125 ! raeburn 483: $possrole = 1;
! 484: } elsif (@{$roles_by_num} == 1) {
! 485: $r->print($roleradio);
! 486: my $rolename = $description->{$roles_by_num->[0]};
1.119 raeburn 487: if ($type eq 'Community') {
1.125 ! raeburn 488: $r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename));
1.119 raeburn 489: } elsif ($type eq 'Placement') {
1.125 ! raeburn 490: $r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename));
1.119 raeburn 491: } else {
1.125 ! raeburn 492: $r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename));
1.119 raeburn 493: }
1.125 ! raeburn 494: $possrole = 1;
! 495: }
! 496: if ($possrole) {
! 497: $r->print('<input type="hidden" name="adhocrole" value="" />');
1.119 raeburn 498: }
499: }
1.89 raeburn 500: }
1.125 ! raeburn 501: if ($possrole) {
1.122 raeburn 502: $r->print('</label></span><br />');
503: }
504: $r->print('<span class="LC_nobreak"><label>'
505: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> ');
1.119 raeburn 506: if (&Apache::lonnet::allowed('ccc',$crsdom)) {
507: if ($type eq 'Community') {
508: $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
509: } elsif ($type eq 'Placement') {
510: $r->print(&mt('View or modify placement test settings which only a [_1] may modify.',$dctitle));
511: } else {
512: $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
513: }
514: } elsif (&Apache::lonnet::allowed('rar',$crsdom)) {
515: if ($type eq 'Community') {
516: $r->print(&mt('View community settings which only a [_1] may modify.',$dctitle));
517: } elsif ($type eq 'Placement') {
518: $r->print(&mt('View placement test settings which only a [_1] may modify.',$dctitle));
519: } else {
520: $r->print(&mt('View course settings which only a [_1] may modify.',$dctitle));
521: }
1.89 raeburn 522: }
1.106 raeburn 523: $r->print('</label></span>'
1.119 raeburn 524: .'</fieldset></div>'
525: .'<br clear="all" />'
526: );
1.68 raeburn 527: }
528: }
1.54 raeburn 529: my %by_descrip;
530: foreach my $course (keys(%courses)) {
531: my $descr;
1.64 raeburn 532: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 533: $descr = $courses{$course}{'description'};
1.64 raeburn 534: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 535: $descr = &unescape($1);
1.34 albertel 536: } else {
1.54 raeburn 537: $descr = &unescape($courses{$course});
538: }
539: my $description = $descr;
540: push (@{$by_descrip{$description}}, $course);
541: }
1.71 bisitz 542:
1.54 raeburn 543: if ($numcourses > 1 && $multiple) {
1.104 bisitz 544: $r->print('<input type="button" value="'.&mt('check all').'"
1.54 raeburn 545: onclick="javascript:checkAll(document.courselist.course_id)" />
1.104 bisitz 546: <input type="button" value="'.&mt('uncheck all').'"
1.54 raeburn 547: onclick="javascript:uncheckAll(document.courselist.course_id)" />
548: <br /><br />');
549: }
1.71 bisitz 550:
551: if (%courses) {
552: $r->print(&Apache::loncommon::start_data_table());
553: $r->print(&Apache::loncommon::start_data_table_header_row());
1.89 raeburn 554: my $titlehdr = &mt('Course Title');
555: if ($type eq 'Community') {
556: $titlehdr = &mt('Community Title');
557: }
1.71 bisitz 558: $r->print('<th>'.&mt('Select').'</th>'
1.89 raeburn 559: .'<th>'.$titlehdr.'</th>'
560: .'<th>'.&mt('Domain').'</th>');
1.117 raeburn 561: unless (($type eq 'Community') || ($type eq 'Placement')) {
1.89 raeburn 562: $r->print('<th>'.&mt('Course Code').'</th>');
563: }
564: $r->print('<th>'.&mt('Owner/Co-owner(s)').'</th>');
1.79 raeburn 565: if ($showroles) {
566: $r->print('<th>'.&mt("Role(s) for [_1]",
567: &Apache::loncommon::plainname($env{'form.personfilter'},
568: $env{'form.persondomfilter'},'firstname')).'</th>');
569: }
1.71 bisitz 570: $r->print(&Apache::loncommon::end_data_table_header_row());
571: }
1.92 raeburn 572: my %cc_cloneable;
573: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
574: my ($coord_cloneable,$warning) =
575: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
576: if ($coord_cloneable) {
577: map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable);
578: }
579: }
1.116 raeburn 580: my (%gotdomdefaults,%gotcodedefaults);
1.54 raeburn 581: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
582: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 583: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 584: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
585: $cleandesc=~s/'/\\'/g;
586: my ($cdom,$cnum)=split(/\_/,$course);
1.85 raeburn 587: my ($descr,$instcode,$ttype,$canclone,@owners);
1.64 raeburn 588: if (ref($courses{$course}) eq 'HASH') {
589: $descr = $courses{$course}{'description'};
1.85 raeburn 590: $instcode = $courses{$course}{'inst_code'};
591: $ttype = $courses{$course}{'type'};
592: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.98 raeburn 593: if ($env{'form.form'} eq 'ccrs') {
594: if (($env{'request.role.domain'} eq $cdom) &&
595: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
596: $canclone = 1;
597: }
598: }
599: unless ($canclone) {
600: if ($cc_cloneable{$cnum.':'.$cdom}) {
601: $canclone = 1;
602: }
1.92 raeburn 603: }
604: unless ($canclone) {
605: my $cloners = $courses{$course}{'cloners'};
1.116 raeburn 606: if ($cloners ne '') {
1.92 raeburn 607: my @cloneable = split(',',$cloners);
608: if (grep(/^\*$/,@cloneable)) {
609: $canclone = 1;
610: }
1.97 raeburn 611: if (grep(/^\*:\Q$clonerudom\E$/,@cloneable)) {
1.92 raeburn 612: $canclone = 1;
613: }
614: if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
615: $canclone = 1;
616: }
1.116 raeburn 617: unless ($canclone) {
618: if (($instcode) && ($crscode) && ($cdom eq $crsdom)) {
619: foreach my $cloner (@cloneable) {
620: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
621: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
622: if ($cloner =~ /\=/) {
623: my (%codedefaults,@code_order);
624: if (ref($gotcodedefaults{$cdom}) eq 'HASH') {
625: if (ref($gotcodedefaults{$cdom}{'defaults'}) eq 'HASH') {
626: %codedefaults = %{$gotcodedefaults{$cdom}{'defaults'}};
627: }
628: if (ref($gotcodedefaults{$cdom}{'order'}) eq 'ARRAY') {
629: @code_order = @{$gotcodedefaults{$cdom}{'order'}};
630: }
631: } else {
632: &Apache::lonnet::auto_instcode_defaults($cdom,
633: \%codedefaults,
634: \@code_order);
635: $gotcodedefaults{$cdom}{'defaults'} = \%codedefaults;
636: $gotcodedefaults{$cdom}{'order'} = \@code_order;
637: }
638: if (@code_order > 0) {
639: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
640: $cloner,$instcode,$crscode)) {
641: $canclone = 1;
642: last;
643: }
644: }
645: }
646: }
647: }
648: }
649: }
650: } else {
651: my %domdefs;
652: if (ref($gotdomdefaults{$cdom}) eq 'HASH') {
653: %domdefs = %{$gotdomdefaults{$cdom}};
654: } else {
655: %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
656: $gotdomdefaults{$cdom} = \%domdefs;
657: }
658: if ($domdefs{'canclone'}) {
659: unless ($domdefs{'canclone'} eq 'none') {
660: if ($domdefs{'canclone'} eq 'domain') {
661: if ($clonerudom eq $cdom) {
662: $canclone = 1;
663: }
664: } elsif (($instcode) && ($crscode) &&
665: ($cdom eq $crsdom)) {
666: my (%codedefaults,@code_order);
667: if (ref($gotcodedefaults{$cdom}) eq 'HASH') {
668: if (ref($gotcodedefaults{$cdom}{'defaults'}) eq 'HASH') {
669: %codedefaults = %{$gotcodedefaults{$cdom}{'defaults'}};
670: }
671: if (ref($gotcodedefaults{$cdom}{'order'}) eq 'ARRAY') {
672: @code_order = @{$gotcodedefaults{$cdom}{'order'}};
673: }
674: } else {
675: &Apache::lonnet::auto_instcode_defaults($cdom,
676: \%codedefaults,
677: \@code_order);
678: $gotcodedefaults{$cdom}{'defaults'} = \%codedefaults;
679: $gotcodedefaults{$cdom}{'order'} = \@code_order;
680: }
681: if (@code_order > 0) {
682: if (&Apache::lonnet::default_instcode_cloning($cdom,$domdefs{'canclone'},
683: $instcode,$crscode,\%codedefaults,
684: \@code_order)) {
685: $canclone = 1;
686: }
687: }
688: }
689: }
690: }
1.85 raeburn 691: }
692: }
693: }
1.101 raeburn 694: push(@owners,$courses{$course}{'owner'});
695: if ($courses{$course}{'co-owners'} ne '') {
696: foreach my $item (split(/,/,$courses{$course}{'co-owners'})) {
697: push(@owners,$item);
1.64 raeburn 698: }
699: }
700: } else {
701: my $singleowner;
702: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
703: push(@owners,&unescape($singleowner));
704: }
1.93 raeburn 705: my $ownerstr = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } @owners);
1.85 raeburn 706: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).'</td>');
1.71 bisitz 707: $r->print('<td>'.$description.'</td>');
708: $r->print('<td>');
709: $r->print(&Apache::lonnet::domain($cdom,'description')?
710: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
711: $r->print('</td>');
1.117 raeburn 712: unless (($type eq 'Community') || ($type eq 'Placement')) {
1.89 raeburn 713: $r->print('<td>');
714: if ($instcode ne '') {
715: $r->print(&unescape($instcode));
716: } else {
717: $r->print(' ');
718: }
719: $r->print('</td>');
1.54 raeburn 720: }
1.72 raeburn 721: $r->print('<td>'.$ownerstr.'</td>');
1.79 raeburn 722: if ($showroles) {
723: $r->print('<td>');
724: my $rolestr;
725: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
726: my @roles = sort(@{$courses{$course}{'roles'}});
727: foreach my $role (@roles) {
728: if ($role =~ /^cr/) {
729: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
730: $rolestr .= $crtitle.', ';
731: } else {
1.89 raeburn 732: $rolestr .= &Apache::lonnet::plaintext($role,$type).', ';
1.79 raeburn 733: }
734: }
735: $rolestr =~ s/\, $//;
736: }
737: $r->print($rolestr.'</td>');
738: }
1.54 raeburn 739: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 740: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 741: # $r->print("<br />\n");
1.19 raeburn 742: }
743: }
1.72 raeburn 744: if (%courses) {
745: $r->print(&Apache::loncommon::end_data_table());
746: }
1.71 bisitz 747:
1.54 raeburn 748: if (!%courses) {
1.104 bisitz 749: $r->print('<p class="LC_info">'.&mt('None found').'</p>');
1.54 raeburn 750: } elsif ($multiple) {
1.108 bisitz 751: $r->print('<input type="button" value="'.&mt('Submit').'" onclick="gochoose('."'','','')".'" />');
1.54 raeburn 752: }
753: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
754: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
755: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
756: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
757: $r->print('<input type="hidden" name="roleelement" value="'.
758: $env{'form.roleelement'}.'" />'."\n");
759: }
1.55 raeburn 760: if ($env{'form.form'} eq 'portform') {
761: $r->print('<input type="hidden" name="cnum" value="" />');
762: $r->print('<input type="hidden" name="cdom" value="" />');
763: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
764: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 765: } elsif ($env{'form.form'} eq 'modifycourse') {
1.125 ! raeburn 766: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state','adhocrole']));
1.57 raeburn 767: } else {
768: $r->print('<input type="hidden" name="cnumelement" value="'.
769: $env{'form.cnumelement'}.'" />'."\n".
770: '<input type="hidden" name="cdomelement" value="'.
771: $env{'form.cdomelement'}.'" />'."\n");
1.90 raeburn 772: if ($env{'form.typeelement'} ne '') {
773: $r->print('<input type="hidden" name="typeelement" value="'.
774: $env{'form.typeelement'}.'" />'."\n");
775:
776: }
1.55 raeburn 777: }
1.78 raeburn 778: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
779: $r->print('<input type="hidden" name="fixeddom" value="'.
780: $env{'form.fixeddom'}.'" />');
781: }
782: if ($env{'form.numtitles'}) {
783: $r->print('<input type="hidden" name="numtitles" value="'.
784: $env{'form.numtitles'}.'" />');
785: }
1.54 raeburn 786: $r->print("</form>\n");
787: return;
788: }
789:
790: sub multiples_tag {
1.55 raeburn 791: my $jscript = &Apache::loncommon::check_uncheck_jscript();
792: my $multelement = '<input type="hidden" name="multiple" value="1" />';
793: return ($jscript,$multelement);
1.1 www 794: }
1.30 raeburn 795:
1.92 raeburn 796: sub get_coordinator_cloneable {
797: my ($cloneruname,$clonerudom,$type) = @_;
1.100 www 798: if (($cloneruname!~/\w/) || ($clonerudom!~/\w/)) {
799: my $warning = '<div class="LC_warning">'.&mt('Intended course owner not specified').
800: '</div>';
801: return ('',$warning);
802: } elsif (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
1.92 raeburn 803: my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
804: '</div>';
805: return ('',$warning);
806: } else {
807: my ($cc_clone,$ccrole);
808: if ($type eq 'Community') {
809: $ccrole = 'co';
1.117 raeburn 810: } else {
1.92 raeburn 811: $ccrole = 'cc';
812: }
813: my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
814: 'userroles',['active'], [$ccrole]);
815: foreach my $key (sort(keys(%ccroles))) {
816: my ($cnum,$cdom,$role) = split(':',$key);
817: $cc_clone .= $cdom.':'.$cnum.'&';
818: }
819: $cc_clone =~ s/\&$//;
820: return ($cc_clone);
821: }
822: }
823:
1.30 raeburn 824: sub course_chooser {
1.85 raeburn 825: my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
1.30 raeburn 826: my $output;
1.35 raeburn 827: if ($multiple) {
1.32 albertel 828: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.85 raeburn 829: } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) {
830: if ($env{'form.form'} eq 'ccrs') {
1.114 bisitz 831: $output = &mt('No cloning for [_1]',$env{'form.cloner'})."\n";
1.85 raeburn 832: } else {
833: $output = &mt('No rights to clone')."\n";
834: }
1.30 raeburn 835: } else {
1.108 bisitz 836: $output = '<input type="button" value="'.&mt('Select').'" onclick="gochoose('.
1.30 raeburn 837: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
838: }
839: return $output;
1.49 raeburn 840: }
841:
1.55 raeburn 842: sub gochoose_javascript {
1.123 raeburn 843: my ($type,$multiple,$autosubmit,$lastaction,$rolename,$rolechooser) = @_;
1.55 raeburn 844: my %elements = (
845: 'Course' => {
846: name => 'coursepick',
847: total => 'coursetotal',
848: list => 'courselist',
849: },
1.83 raeburn 850: 'Community' => {
1.88 raeburn 851: name => 'coursepick',
852: total => 'coursetotal',
853: list => 'courselist',
1.55 raeburn 854: },
1.117 raeburn 855: 'Placement' => {
856: name => 'coursepick',
857: total => 'coursetotal',
858: list => 'courselist',
859: },
1.55 raeburn 860: );
1.123 raeburn 861:
862: my %lt = &Apache::lonlocal::texthash (
863: none => 'You are not eligible to use an ad hoc role for the selected course',
864: ok => 'OK',
865: exit => 'Cancel',
866: );
867: &js_escape(\%lt);
868:
869: my $output;
870: if ($rolechooser) {
871: $output .= qq|
1.125 ! raeburn 872: \$(document).ready(function(){
! 873: \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
! 874: });
1.123 raeburn 875: |;
876: }
877: $output .= qq|
1.57 raeburn 878: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 879: var openerForm = "$env{'form.form'}";
1.123 raeburn 880: var openerRole = "$rolename";
1.55 raeburn 881: courseCount = 0;
882: var courses = '';
1.57 raeburn 883: |;
884: if ($multiple) {
885: $output .= <<"ENDSCRIPT";
886: courseCount = 0;
887: var courses = '';
888: if (typeof(document.courselist.course_id.length) == 'undefined') {
889: // only 1 course checkbox was created
890: if (document.courselist.course_id.checked) {
891: courses = courses + document.courselist.course_id.value + "&&";
892: courseCount ++;
893: }
894: } else {
895: for (var j=0; j<document.courselist.course_id.length; j++) {
896: if (document.courselist.course_id[j].checked) {
897: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 898: courseCount ++;
899: }
1.57 raeburn 900: }
901: }
902: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
903: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
904: 'undefined') {
905: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
906: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 907: } else {
1.57 raeburn 908: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 909: }
1.57 raeburn 910: } else {
911: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
912: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
913: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 914: } else {
1.57 raeburn 915: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 916: }
1.55 raeburn 917: }
1.57 raeburn 918: }
919: if (courseCount > 0) {
920: courses = courses.substr(0,courses.length-2);
921: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
922: }
923: ENDSCRIPT
924: } else {
1.90 raeburn 925: my ($name_code,$type_code);
1.57 raeburn 926: if ($env{'form.cnameelement'} ne '') {
1.103 raeburn 927: $name_code = <<ENDNAMECODE;
928: var showcdesc = cdesc;
929: if (cdesc.length > 25) {
930: showcdesc = cdesc.substr(0,25)+' ...';
931: }
932: opener.document.$env{'form.form'}.$env{'form.cnameelement'}.value=showcdesc;
933: ENDNAMECODE
1.55 raeburn 934: }
1.90 raeburn 935: if ($env{'form.typeelement'} ne '') {
936: $type_code = 'opener.document.'.$env{'form.form'}.'.'.
937: $env{'form.typeelement'}.'.value=document.courselist.type;';
938: }
939:
1.57 raeburn 940: $output .= qq|
1.55 raeburn 941: $name_code
1.90 raeburn 942: $type_code
1.55 raeburn 943: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
944: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
945: if (slct.options == undefined) {
946: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
947: }
948: else {
949: var i;
950: for (i=0;i<slct.length;i++) {
951: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 952: }
953: }
1.57 raeburn 954: |;
1.54 raeburn 955: }
1.123 raeburn 956: $output .= <<ENDJS;
1.55 raeburn 957: if (openerForm == 'portform') {
958: document.courselist.cnum.value = cname;
959: document.courselist.cdom.value = cdom;
960: }
1.123 raeburn 961: if ((openerForm == 'rolechoice') && (openerRole == 'dh')) {
962: \$("#LC_choose_adhoc").empty();
963: var http = new XMLHttpRequest();
964: var url = "/adm/pickcourse";
965: var params = "cid="+cdom+"_"+cname+"&context=adhoc";
966: http.open("POST", url, true);
967: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
968: http.onreadystatechange = function() {
969: if(http.readyState == 4 && http.status == 200) {
970: var data = \$.parseJSON(http.responseText);
971: var len = data.roles.length;
972: if (len == '' || len == null || len == 0) {
973: alert('$lt{none}');
974: } else {
975: if (len == 1) {
976: process_pick(cdom,data.roles[0].name);
977: $lastaction;
978: } else {
979: var str = '';
980: for (var i=0; i<data.roles.length; i++) {
981: \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span> </span>")
982: .appendTo("#LC_choose_adhoc");
983: }
984: \$( "#LC_get_role_0").prop("checked", true);
985: \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
986: \$( "#LC_adhocrole_chooser" ).dialog("open");
987: \$( "#LC_adhocrole_chooser" ).dialog({
988: height: 400,
989: width: 500,
990: modal: true,
991: resizable: false,
992: buttons: [
993: {
994: text: "$lt{'ok'}",
995: click: function() {
996: var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
997: process_pick(cdom,rolename);
998: \$("#LC_adhocrole_chooser").dialog( "close" );
999: $lastaction;
1000: }
1001: },
1002: {
1003: text: "$lt{'exit'}",
1004: click: function() {
1005: \$("#LC_adhocrole_chooser").dialog( "close" );
1006: }
1007: }
1008: ],
1009: });
1010: \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
1011: event.preventDefault();
1012: var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
1013: process_pick(cdom,rolename);
1014: \$("#LC_adhocrole_chooser").dialog( "close" );
1015: $lastaction;
1016: });
1017: }
1018: }
1019: }
1.54 raeburn 1020: }
1.123 raeburn 1021: http.send(params);
1022: } else {
1023: $autosubmit
1024: $lastaction
1025: }
1026: }
1027:
1028: ENDJS
1029: return $rolechooser.&Apache::lonhtmlcommon::scripttag($output);
1030: }
1031:
1.55 raeburn 1032: 1;
1033: __END__
1034:
1035: =pod
1036:
1037: =head1 NAME
1038:
1039: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
1040:
1041: =head1 SYNOPSIS
1042:
1043: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
1044:
1045: =head1 OVERVIEW
1046:
1047: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
1048:
1049: =head2 Search Criteria (Screen One)
1050:
1051: =head3 Criteria:
1052:
1053: =over 4
1054:
1055: =item *
1056: Course Activity - how recently was course last visited by anyone.
1057:
1058: =item *
1059: Course Domain - the domain of the course
1060:
1061: =item *
1.117 raeburn 1062: Type - Course, Community or Placement
1.55 raeburn 1063:
1064: =item *
1065: Course Institutional Code - the institutional identifier assigned to the course
1066:
1067: =item *
1068: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
1069:
1070: =item *
1071: Course Owner's Domain - the domain of the owner of the course
1072:
1073: =item *
1.76 bisitz 1074: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 1075:
1076: =item *
1077: 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).
1078:
1079: =back
1080:
1081: 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'}).
1082:
1083: =head2 Course Display (Screen Two)
1084:
1085: 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:
1086:
1087: =over 4
1088:
1089: =item *
1090: Course description
1091:
1092: =item *
1093: Domain description of course domain
1094:
1095: =item *
1096: Course institutional code
1097:
1098: =item *
1099: Course owner (username:domain)
1100:
1101: =back
1102:
1103: 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.
1104:
1105: 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.
1106:
1107: =head1 SUBROUTINES
1108:
1109: =over 4
1110:
1111: =item *
1112: X<create_user_javascript()>
1113: B<create_user_javascript($type)>:
1114:
1.117 raeburn 1115: Input: 1 - $type - the course type - Course, Community, or Placement
1.55 raeburn 1116:
1117: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1118:
1119: Side Effects: None
1120:
1121: 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.
1122:
1123:
1124: =item *
1125: X<display_matched_courses()>
1.116 raeburn 1126: B<display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,$crsdom,$crscode,%courses)>:
1.55 raeburn 1127:
1.116 raeburn 1128: Input: 8 - 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, domain of new course, institutional code of new course, hash of courses.
1.55 raeburn 1129:
1130: Output: 0
1131:
1132: 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.
1133:
1134: =item *
1135: X<multiples_tag()>
1136: B<multiples_tag()>:
1137:
1138:
1139: Input: 0
1140:
1141: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
1142:
1143: Side Effects: None
1144:
1145:
1146: =item *
1147: X<course_chooser()>
1.85 raeburn 1148: B<course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone)>:
1.55 raeburn 1149:
1.85 raeburn 1150: 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 1151:
1.85 raeburn 1152: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection.
1.55 raeburn 1153:
1154: Side Effects: None
1155:
1156:
1157: =item *
1158: X<gochoose_javascript()>
1.123 raeburn 1159: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction,$rolename)>:
1.55 raeburn 1160:
1.123 raeburn 1161: Input: 5 - 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.; rolename (e.g., dh) of user's current role.
1.55 raeburn 1162:
1163: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1164:
1165: Side Effects: None
1166:
1167: javascript functions used when user selects a course(s). Different behavior depending on context:
1168:
1169: =back
1170:
1171: =over 8
1172:
1173: =item
1174:
1175: (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.
1176:
1177: =item
1178:
1179: (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.
1180:
1181: =item
1182:
1183: (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.
1184:
1185: =item
1.54 raeburn 1186:
1.55 raeburn 1187: (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 1188:
1.55 raeburn 1189: =item
1.54 raeburn 1190:
1.55 raeburn 1191: (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 1192:
1.55 raeburn 1193: =item
1.54 raeburn 1194:
1.55 raeburn 1195: (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 1196:
1.55 raeburn 1197: =item
1.49 raeburn 1198:
1.102 bisitz 1199: (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 1200:
1.84 raeburn 1201: =item
1202:
1203: (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.
1204:
1.55 raeburn 1205: =back
1206:
1207: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>