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