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