Annotation of loncom/interface/lonpickcourse.pm, revision 1.85
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.85 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.84 2009/07/29 22:32:44 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.78 raeburn 105: $loaditem{'onload'} .= '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 != '') {
223: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
224: opener.document.title='Role selected. Please stand by.';
225: opener.status='Role selected. Please stand by.';
226: opener.document.rolechoice.newrole.value=courseTarget
227: opener.document.rolechoice.submit();
228: }
229: }
230: else {
231: 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");
232: }
233: ENDTWO
234: } else {
235: $process_pick .= <<"ENDTHREE";
236: if (pickedDomain != dom) {
237: 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");
238: return;
239: }
240: ENDTHREE
241: }
242: $process_pick .= "
243: }
244:
245: </script>
246: ";
247: return $process_pick;
248: }
249:
1.55 raeburn 250: sub create_user_javascript {
251: my ($type) = @_;
252: my $output;
253: #javascript for reporting sections and groups then closing
254: if ($env{'form.pickedcourse'}) {
255: my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
256: my $sec_element = 'currsec';
257: my $grplist_element = 'groups';
258: my ($sections,$groups) =
259: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
260: my $num_sections = scalar(@{$sections});
261: my $seclist = join(',',@{$sections});
262: my $num_groups = scalar(@{$groups});
263: my $groupslist = join(',',@{$groups});
264: $output = qq|
265: <script type="text/javascript">
266: function setSections() {
267: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
268: window.opener.setSect('$seclist');
269: self.close()
270: }
271: </script>
272: |;
273: ;
274: }
275: return $output;
276: }
277:
1.54 raeburn 278: sub display_matched_courses {
1.85 ! raeburn 279: my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
1.55 raeburn 280: if ($env{'form.form'} eq 'portform') {
281: $action = '/adm/portfolio';
282: }
1.68 raeburn 283: my $numcourses = keys(%courses);
1.55 raeburn 284: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 285: if ($env{'form.form'} eq 'modifycourse') {
286: if ($numcourses > 0) {
287: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
288: my $dctitle = &Apache::lonnet::plaintext('dc');
289: my $ccrolechk = ' checked="checked" ';
290: my $menuchk = ' ';
291: if ($env{'form.prevphase'} ne '') {
292: $ccrolechk = ' ';
293: $menuchk = ' checked="checked" ';
294: }
295: $r->print(
1.75 bisitz 296: '<fieldset>'
297: .'<legend>'.&mt('Action').'</legend>'
298: .'<div class="LC_nobreak"><label>'
299: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
300: .' '.&mt('Enter the course with the role of [_1].',$cctitle)
301: .'</label></div>'
302: .'<div class="LC_nobreak"><label>'
303: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> '
304: .&mt('View or modify course settings which only a [_1] may modify.',$dctitle)
305: .'</label></div>'
306: .'</fieldset>'
307: .'<br />'
308: );
1.68 raeburn 309: }
310: }
1.54 raeburn 311: my %by_descrip;
312: foreach my $course (keys(%courses)) {
313: my $descr;
1.64 raeburn 314: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 315: $descr = $courses{$course}{'description'};
1.64 raeburn 316: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 317: $descr = &unescape($1);
1.34 albertel 318: } else {
1.54 raeburn 319: $descr = &unescape($courses{$course});
320: }
321: my $description = $descr;
322: push (@{$by_descrip{$description}}, $course);
323: }
1.71 bisitz 324:
1.54 raeburn 325: if ($numcourses > 1 && $multiple) {
326: $r->print('<input type="button" value="check all"
327: onclick="javascript:checkAll(document.courselist.course_id)" />
328: <input type="button" value="uncheck all"
329: onclick="javascript:uncheckAll(document.courselist.course_id)" />
330: <br /><br />');
331: }
1.71 bisitz 332:
333: if (%courses) {
334: $r->print(&Apache::loncommon::start_data_table());
335: $r->print(&Apache::loncommon::start_data_table_header_row());
336: $r->print('<th>'.&mt('Select').'</th>'
1.76 bisitz 337: .'<th>'.&mt('Course Title').'</th>'
1.71 bisitz 338: .'<th>'.&mt('Domain').'</th>'
339: .'<th>'.&mt('Course Code').'</th>'
1.72 raeburn 340: .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
1.71 bisitz 341: .'<th>'.&mt('Type').'</th>'
342: );
1.79 raeburn 343: if ($showroles) {
344: $r->print('<th>'.&mt("Role(s) for [_1]",
345: &Apache::loncommon::plainname($env{'form.personfilter'},
346: $env{'form.persondomfilter'},'firstname')).'</th>');
347: }
1.71 bisitz 348: $r->print(&Apache::loncommon::end_data_table_header_row());
349: }
1.54 raeburn 350: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
351: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 352: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 353: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
354: $cleandesc=~s/'/\\'/g;
355: my ($cdom,$cnum)=split(/\_/,$course);
1.85 ! raeburn 356: my ($descr,$instcode,$ttype,$canclone,@owners);
1.64 raeburn 357: if (ref($courses{$course}) eq 'HASH') {
358: $descr = $courses{$course}{'description'};
1.85 ! raeburn 359: $instcode = $courses{$course}{'inst_code'};
! 360: $ttype = $courses{$course}{'type'};
! 361: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
! 362: my $cloners = $courses{$course}{'cloners'};
! 363: if ($cloners ne '') {
! 364: my @cloneable = split(',',$cloners);
! 365: if (grep(/^\*$/,@cloneable)) {
! 366: $canclone = 1;
! 367: }
! 368: if (grep(/^\*:\Q$env{'form.clonerudom'}\E$/,@cloneable)) {
! 369: $canclone = 1;
! 370: }
! 371: if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
! 372: $canclone = 1;
! 373: }
! 374: }
! 375: }
1.64 raeburn 376: push(@owners,&unescape($courses{$course}{'owner'}));
377: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
378: foreach my $item (@{$courses{$course}{'co-owners'}}) {
379: push(@owners,&unescape($item));
380: }
381: }
382: } else {
383: my $singleowner;
384: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
385: push(@owners,&unescape($singleowner));
386: }
1.72 raeburn 387: my $ownerstr = join(', ',@owners);
1.85 ! raeburn 388: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).'</td>');
1.71 bisitz 389: $r->print('<td>'.$description.'</td>');
390: $r->print('<td>');
391: $r->print(&Apache::lonnet::domain($cdom,'description')?
392: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
393: $r->print('</td>');
394: $r->print('<td>');
1.64 raeburn 395: if ($instcode ne '') {
1.71 bisitz 396: $r->print(&unescape($instcode));
397: } else {
398: $r->print(' ');
1.54 raeburn 399: }
1.71 bisitz 400: $r->print('</td>');
1.72 raeburn 401: $r->print('<td>'.$ownerstr.'</td>');
1.71 bisitz 402: $r->print('<td>');
1.64 raeburn 403: if ($ttype ne '') {
1.71 bisitz 404: $r->print(&mt(&unescape($ttype)));
405: } else {
406: $r->print(' ');
1.23 raeburn 407: }
1.71 bisitz 408: $r->print('</td>');
1.79 raeburn 409: if ($showroles) {
410: $r->print('<td>');
411: my $rolestr;
412: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
413: my @roles = sort(@{$courses{$course}{'roles'}});
414: foreach my $role (@roles) {
415: if ($role =~ /^cr/) {
416: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
417: $rolestr .= $crtitle.', ';
418: } else {
419: $rolestr .= &Apache::lonnet::plaintext($role,$ttype).', ';
420: }
421: }
422: $rolestr =~ s/\, $//;
423: }
424: $r->print($rolestr.'</td>');
425: }
1.54 raeburn 426: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 427: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 428: # $r->print("<br />\n");
1.19 raeburn 429: }
430: }
1.72 raeburn 431: if (%courses) {
432: $r->print(&Apache::loncommon::end_data_table());
433: }
1.71 bisitz 434:
1.54 raeburn 435: if (!%courses) {
436: $r->print(&mt('None found'));
437: } elsif ($multiple) {
1.57 raeburn 438: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 439: }
440: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
441: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
442: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
443: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
444: $r->print('<input type="hidden" name="roleelement" value="'.
445: $env{'form.roleelement'}.'" />'."\n");
446: }
1.55 raeburn 447: if ($env{'form.form'} eq 'portform') {
448: $r->print('<input type="hidden" name="cnum" value="" />');
449: $r->print('<input type="hidden" name="cdom" value="" />');
450: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
451: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 452: } elsif ($env{'form.form'} eq 'modifycourse') {
1.85 ! raeburn 453: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 454: } else {
455: $r->print('<input type="hidden" name="cnumelement" value="'.
456: $env{'form.cnumelement'}.'" />'."\n".
457: '<input type="hidden" name="cdomelement" value="'.
458: $env{'form.cdomelement'}.'" />'."\n");
1.55 raeburn 459: }
1.78 raeburn 460: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
461: $r->print('<input type="hidden" name="fixeddom" value="'.
462: $env{'form.fixeddom'}.'" />');
463: }
464: if ($env{'form.numtitles'}) {
465: $r->print('<input type="hidden" name="numtitles" value="'.
466: $env{'form.numtitles'}.'" />');
467: }
1.54 raeburn 468: $r->print("</form>\n");
469: return;
470: }
471:
472: sub multiples_tag {
1.55 raeburn 473: my $jscript = &Apache::loncommon::check_uncheck_jscript();
474: my $multelement = '<input type="hidden" name="multiple" value="1" />';
475: return ($jscript,$multelement);
1.1 www 476: }
1.30 raeburn 477:
1.54 raeburn 478: sub build_filters {
1.57 raeburn 479: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.85 ! raeburn 480: $numtitlesref,$caller,$cloneruname,$clonerudom) = @_;
! 481: my ($list,$formname,$fixeddom,$codedom,$jscript);
! 482: $codedom = $env{'request.role.domain'};
1.57 raeburn 483: if (defined($env{'form.form'})) {
1.81 raeburn 484: $formname = $env{'form.form'};
485: } else {
486: $formname = $caller;
1.57 raeburn 487: }
1.84 raeburn 488: my $onchange;
489: unless ($env{'form.interface'} eq 'textual') {
1.85 ! raeburn 490: $onchange = 'javascript:updateFilters(this)';
1.84 raeburn 491: }
1.79 raeburn 492: my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
1.78 raeburn 493: $instcodeform,$typeselectform,$instcodetitle);
1.55 raeburn 494: foreach my $item (@{$filterlist}) {
1.54 raeburn 495: $filter->{$item} = $env{'form.'.$item};
496: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.79 raeburn 497: if ($item eq 'domainfilter') {
1.61 albertel 498: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
499: } elsif ($item eq 'coursefilter') {
500: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
501: } elsif ($item eq 'ownerfilter') {
502: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
1.79 raeburn 503: $filter->{'ownerdomfilter'} =
504: &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
505: $ownerdomselectform =
506: &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
507: 'ownerdomfilter',1);
508: } elsif ($item eq 'personfilter') {
509: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
510: if ($env{'form.persondomfilter'} eq '') {
1.85 ! raeburn 511: unless ($env{'form.gosearch'}) {
1.79 raeburn 512: $filter->{'persondomfilter'} = $env{'request.role.domain'};
513: }
514: } else {
515: $filter->{'persondomfilter'} =
516: &LONCAPA::clean_domain($env{'form.persondomfilter'});
517: }
518: $persondomselectform =
519: &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
520: 'persondomfilter',1);
1.61 albertel 521: } else {
522: $filter->{$item} =~ s/\W//g;
523: }
1.54 raeburn 524: if (!$filter->{$item}) {
525: $filter->{$item} = '';
526: }
527: }
528: if ($item eq 'domainfilter') {
1.63 albertel 529: my $allow_blank = 1;
530: if ($formname eq 'portform') {
531: $filter->{$item} ||= $env{'user.domain'};
532: $allow_blank=0;
1.67 raeburn 533: } elsif ($formname eq 'studentform') {
534: $filter->{$item} ||= $env{'request.role.domain'};
535: $allow_blank=0;
536: }
1.78 raeburn 537: if ($env{'form.fixeddom'}) {
538: $domainselectform = '<input type="hidden" name="domainfilter"'.
539: 'value="'.$env{'request.role.domain'}.'" />'.
540: &Apache::lonnet::domain($env{'request.role.domain'},
541: 'description');
542: $codedom = $env{'request.role.domain'};
1.79 raeburn 543: } else {
1.78 raeburn 544: $domainselectform =
545: &Apache::loncommon::select_dom_form($filter->{$item},
546: 'domainfilter',
1.84 raeburn 547: $allow_blank,'',$onchange);
1.78 raeburn 548: $codedom = $filter->{'domainfilter'};
549: }
1.54 raeburn 550: } else {
551: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
552: }
553: }
554:
555: # last course activity filter and selection
556: $filter->{'sincefilter'} = $env{'form.sincefilter'};
557: $filter->{'sincefilter'} =~ s/[^\d-]//g;
558: if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
559: $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
560: 'sincefilter',('-1'=>'',
561: '86400' => 'today',
562: '604800' => 'last week',
563: '2592000' => 'last month',
564: '7776000' => 'last three months',
565: '15552000' => 'last six months',
566: '31104000' => 'last year',
567: 'select_form_order' =>
568: ['-1','86400','604800','2592000','7776000',
569: '15552000','31104000']));
570:
571: my %lt = (
1.74 bisitz 572: 'cac' => &mt("$type Activity"),
1.76 bisitz 573: 'cde' => &mt("$type Title"),
1.74 bisitz 574: 'cdo' => &mt("$type Domain"),
1.78 raeburn 575: 'ins' => &mt('Institutional Code'),
576: 'inc' => &mt('Institutional Categorization'),
1.79 raeburn 577: 'cow' => &mt("$type Owner/Co-owner"),
578: 'cop' => &mt("$type Personnel Includes"),
1.84 raeburn 579: 'cog' => &mt('Type')
1.54 raeburn 580: );
1.49 raeburn 581:
1.84 raeburn 582: $typeselectform = '<select name="type" size="1"';
583: if ($onchange) {
1.85 ! raeburn 584: $typeselectform .= 'onchange="'.$onchange.'"';
1.84 raeburn 585: }
586: $typeselectform .= '>'."\n";
1.85 ! raeburn 587:
! 588: my ($cloneableonlyform,$cloneabletitle);
! 589: if (exists($filter->{'cloneableonly'})) {
! 590: my $cloneableon = '';
! 591: my $cloneableoff = ' checked="checked"';
! 592: if ($filter->{'cloneableonly'}) {
! 593: $cloneableon = $cloneableoff;
! 594: $cloneableoff = '';
! 595: }
! 596: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Yes').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No').'</label></span>';
! 597: if ($env{'form.form'} eq 'ccrs') {
! 598: $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
! 599: } else {
! 600: $cloneabletitle = &mt('Cloneable by you');
! 601: }
! 602: }
1.80 raeburn 603: my $officialjs;
1.54 raeburn 604: if ($type eq 'Course') {
1.85 ! raeburn 605: if (exists($filter->{'instcodefilter'})) {
! 606: if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
! 607: || ($formname eq 'modifycourse')) {
! 608: $officialjs = 1;
! 609: ($instcodeform,$jscript,$$numtitlesref) =
! 610: &instcode_selectors($codedom,'filterpicker',$officialjs);
! 611: if ($jscript) {
! 612: $jscript = '<script type="text/javascript" language="Javascript">'.
! 613: $jscript.'</script>'."\n";
! 614: }
! 615: }
! 616: if ($instcodeform eq '') {
! 617: $instcodeform =
! 618: '<input type="text" name="instcodefilter" size="10" value="'.
! 619: $list->{'instcodefilter'}.'" />';
! 620: $instcodetitle = $lt{'ins'};
! 621: } else {
! 622: $instcodetitle = $lt{'inc'};
! 623: }
! 624: if ($env{'form.fixeddom'}) {
! 625: $instcodetitle .= '<br />('.$codedom.')';
! 626: }
1.78 raeburn 627: }
1.54 raeburn 628: }
1.84 raeburn 629:
1.83 raeburn 630: foreach my $posstype ('Course','Community') {
1.72 raeburn 631: $typeselectform.='<option value="'.$posstype.'"'.
1.73 bisitz 632: ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
1.54 raeburn 633: }
634: $typeselectform.="</select>";
1.57 raeburn 635: my $output = qq|
1.85 ! raeburn 636: <form method="post" name="filterpicker" action="$action">
1.57 raeburn 637: <input type="hidden" name="form" value="$formname" />
638: |;
639: if ($formname eq 'modifycourse') {
1.68 raeburn 640: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
641: '<input type="hidden" name="prevphase" value="'.
642: $env{'form.prevphase'}.'" />'."\n";
643: } else {
1.57 raeburn 644: my $name_input;
645: if ($env{'form.cnameelement'} ne '') {
646: $name_input = '<input type="hidden" name="cnameelement" value="'.
647: $env{'form.cnameelement'}.'" />';
648: }
649: $output .= qq|
1.27 albertel 650: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
651: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 652: $name_input
1.18 raeburn 653: $roleelement
1.35 raeburn 654: $multelement
1.57 raeburn 655: |;
1.59 raeburn 656: if ($formname eq 'portform') {
1.78 raeburn 657: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59 raeburn 658: }
1.57 raeburn 659: }
1.78 raeburn 660: if ($env{'form.fixeddom'}) {
661: $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
662: }
1.74 bisitz 663: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57 raeburn 664: if ($sincefilterform) {
1.74 bisitz 665: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
666: .$sincefilterform
667: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 668: }
669: if ($domainselectform) {
1.74 bisitz 670: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
671: .$domainselectform
672: .&Apache::lonhtmlcommon::row_closure();
1.78 raeburn 673: }
1.57 raeburn 674: if ($typeselectform) {
1.74 bisitz 675: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
676: .$typeselectform
677: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 678: }
679: if ($instcodeform) {
1.78 raeburn 680: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74 bisitz 681: .$instcodeform
682: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 683: }
684: if (exists($filter->{'ownerfilter'})) {
1.79 raeburn 685: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
686: '<table><tr><td>'.&mt('Username').'<br />'.
687: '<input type="text" name="ownerfilter" size="20" value="'.
688: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
689: $ownerdomselectform.'</td></tr></table>'.
690: &Apache::lonhtmlcommon::row_closure();
691: }
692: if (exists($filter->{'personfilter'})) {
693: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
694: '<table><tr><td>'.&mt('Username').'<br />'.
695: '<input type="text" name="personfilter" size="20" value="'.
696: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
697: $persondomselectform.'</td></tr></table>'.
698: &Apache::lonhtmlcommon::row_closure();
1.57 raeburn 699: }
700: if (exists($filter->{'coursefilter'})) {
1.74 bisitz 701: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
702: .'<input type="text" name="coursefilter" size="25" value="'
703: .$list->{'coursefilter'}.'" />'
704: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 705: }
1.85 ! raeburn 706: if ($cloneableonlyform) {
! 707: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
! 708: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
! 709: }
1.57 raeburn 710: if (exists($filter->{'descriptfilter'})) {
1.74 bisitz 711: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
712: .'<input type="text" name="descriptfilter" size="40" value="'
713: .$list->{'descriptfilter'}.'" />'
714: .&Apache::lonhtmlcommon::row_closure(1);
1.57 raeburn 715: }
1.85 ! raeburn 716: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>';
! 717: my $warning;
! 718: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
! 719: my $cloneruhome=&Apache::lonnet::homeserver($cloneruname,$clonerudom);
! 720: my $cc_clone;
! 721: if ($cloneruhome eq 'no_host') {
! 722: $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
! 723: '</div>';
! 724: } else {
! 725: if ($env{'form.form'} eq 'ccrs') {
! 726: $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
! 727: }
! 728: my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
! 729: 'userroles',['active'], ['cc']);
! 730: foreach my $key (sort(keys(%ccroles))) {
! 731: my ($cnum,$cdom,$role) = split(':',$key);
! 732: $cc_clone .= $cdom.':'.$cnum.'&';
! 733: }
! 734: $cc_clone =~ s/\&$//;
! 735: }
! 736: if ($cc_clone ne '') {
! 737: $output .= '<input type="hidden" name="cc_clone" value="'.$cc_clone.'" />';
! 738: }
! 739: }
! 740: $output .= '<input type="hidden" name="updater" value="">'."\n".
1.84 raeburn 741: '<input type="submit" name="gosearch" value="'.
1.70 raeburn 742: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.85 ! raeburn 743: return $jscript.$warning.$output;
1.78 raeburn 744: }
745:
746: sub instcode_selectors {
1.80 raeburn 747: my ($codedom,$formname,$officialjs) = @_;
1.78 raeburn 748: my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
749: my ($jscript,$totcodes,$numtitles,$lasttitle) =
750: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
1.80 raeburn 751: \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
1.78 raeburn 752: if ($numtitles > 0) {
1.84 raeburn 753: my $official = ' checked="checked" ';
754: my $unofficial = '';
755: if ($env{'form.official'} eq 'off') {
756: $unofficial = $official;
757: $official = '';
1.80 raeburn 758: }
759: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
1.84 raeburn 760: '<input type="radio" name="official" value="on"'.$official.' />'.
1.80 raeburn 761: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1.84 raeburn 762: '<input type="radio" name="official" value="off"'.$unofficial.
1.80 raeburn 763: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
764: &Apache::courseclassifier::build_instcode_selectors($numtitles,
765: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
766: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
767: '<input type="hidden" name="state" value="listing" />'."\n";
1.78 raeburn 768:
769: }
770: return ($output,$jscript,$numtitles);
1.54 raeburn 771: }
772:
773: sub search_courses {
1.85 ! raeburn 774: my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom) = @_;
! 775: my (%courses,%showcourses,$cloner);
1.54 raeburn 776: if (!$onlyown) {
1.71 bisitz 777: $r->print(&mt('Searching ...').'<br /> <br />');
1.6 www 778: $r->rflush();
1.54 raeburn 779: if (($filter->{'ownerfilter'} ne '') ||
780: ($filter->{'ownerdomfilter'} ne '')) {
781: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
782: $filter->{'ownerdomfilter'};
783: }
1.80 raeburn 784: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
1.54 raeburn 785: if (!$filter->{$item}) {
786: $filter->{$item}='.';
787: }
1.52 raeburn 788: }
1.54 raeburn 789: my $timefilter =
790: ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
1.78 raeburn 791: my ($instcodefilter,$regexpok);
792: if ($numtitles) {
1.84 raeburn 793: if ($env{'form.official'} eq 'on') {
1.80 raeburn 794: $instcodefilter =
1.84 raeburn 795: &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
1.80 raeburn 796: $regexpok = 1;
1.84 raeburn 797: } elsif ($env{'form.official'} eq 'off') {
798: $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
799: unless ($instcodefilter eq '') {
800: $regexpok = -1;
801: }
1.80 raeburn 802: }
1.78 raeburn 803: } else {
804: $instcodefilter = $filter->{'instcodefilter'};
805: }
1.80 raeburn 806: if ($instcodefilter eq '') { $instcodefilter = '.'; }
807: if ($type eq '') { $type = '.'; }
1.85 ! raeburn 808:
! 809: if (($clonerudom ne '') && ($cloneruname ne '')) {
! 810: $cloner = $cloneruname.':'.$clonerudom;
! 811: }
1.54 raeburn 812: %courses =
813: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
814: $filter->{'descriptfilter'},
815: $timefilter,
1.78 raeburn 816: $instcodefilter,
1.54 raeburn 817: $filter->{'combownerfilter'},
818: $filter->{'coursefilter'},
1.85 ! raeburn 819: undef,undef,$type,$regexpok,undef,undef,
! 820: undef,undef,$cloner,$env{'form.cc_clone'},
! 821: $filter->{'cloneableonly'});
1.79 raeburn 822: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
823: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
824: $filter->{'persondomfilter'},
825: 'userroles',undef,
826: ['cc','in','ad','ep','ta','cr'],
827: $filter->{'domainfilter'});
828: foreach my $role (keys(%rolehash)) {
829: my ($cnum,$cdom,$courserole) = split(':',$role);
830: my $cid = $cdom.'_'.$cnum;
831: if (exists($courses{$cid})) {
832: if (ref($courses{$cid}) eq 'HASH') {
833: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
834: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
835: push (@{$courses{$cid}{roles}},$courserole);
836: }
837: } else {
838: $courses{$cid}{roles} = [$courserole];
839: }
840: $showcourses{$cid} = $courses{$cid};
841: }
842: }
843: }
844: %courses = %showcourses;
845: }
1.54 raeburn 846: } else {
847: $r->print('<br />');
1.60 raeburn 848: my %coursehash = &Apache::loncommon::findallcourses();
849: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 850: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 851: }
1.2 www 852: }
1.54 raeburn 853: return %courses;
1.18 raeburn 854: }
1.1 www 855:
1.30 raeburn 856: sub course_chooser {
1.85 ! raeburn 857: my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
1.30 raeburn 858: my $output;
1.35 raeburn 859: if ($multiple) {
1.32 albertel 860: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.85 ! raeburn 861: } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) {
! 862: if ($env{'form.form'} eq 'ccrs') {
! 863: $output = &mt('No cloning for ').$env{'form.cloner'}."\n";
! 864: } else {
! 865: $output = &mt('No rights to clone')."\n";
! 866: }
1.30 raeburn 867: } else {
1.71 bisitz 868: $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30 raeburn 869: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
870: }
871: return $output;
1.49 raeburn 872: }
873:
1.55 raeburn 874: sub gochoose_javascript {
1.57 raeburn 875: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 876: my %elements = (
877: 'Course' => {
878: name => 'coursepick',
879: total => 'coursetotal',
880: list => 'courselist',
881: },
1.83 raeburn 882: 'Community' => {
1.55 raeburn 883: name => 'grouppick',
884: total => 'grouptotal',
885: list => 'grouplist',
886: },
887: );
1.57 raeburn 888: my $output .= qq|
1.55 raeburn 889: <script type="text/javascript">
1.57 raeburn 890: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 891: var openerForm = "$env{'form.form'}";
892: courseCount = 0;
893: var courses = '';
1.57 raeburn 894: |;
895: if ($multiple) {
896: $output .= <<"ENDSCRIPT";
897: courseCount = 0;
898: var courses = '';
899: if (typeof(document.courselist.course_id.length) == 'undefined') {
900: // only 1 course checkbox was created
901: if (document.courselist.course_id.checked) {
902: courses = courses + document.courselist.course_id.value + "&&";
903: courseCount ++;
904: }
905: } else {
906: for (var j=0; j<document.courselist.course_id.length; j++) {
907: if (document.courselist.course_id[j].checked) {
908: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 909: courseCount ++;
910: }
1.57 raeburn 911: }
912: }
913: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
914: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
915: 'undefined') {
916: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
917: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 918: } else {
1.57 raeburn 919: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 920: }
1.57 raeburn 921: } else {
922: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
923: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
924: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 925: } else {
1.57 raeburn 926: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 927: }
1.55 raeburn 928: }
1.57 raeburn 929: }
930: if (courseCount > 0) {
931: courses = courses.substr(0,courses.length-2);
932: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
933: }
934: ENDSCRIPT
935: } else {
936: my $name_code;
937: if ($env{'form.cnameelement'} ne '') {
938: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
939: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 940: }
1.57 raeburn 941: $output .= qq|
1.55 raeburn 942: $name_code
943: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
944: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
945: if (slct.options == undefined) {
946: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
947: }
948: else {
949: var i;
950: for (i=0;i<slct.length;i++) {
951: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 952: }
953: }
1.57 raeburn 954: |;
1.54 raeburn 955: }
1.57 raeburn 956: $output .= qq|
1.55 raeburn 957: if (openerForm == 'portform') {
958: document.courselist.cnum.value = cname;
959: document.courselist.cdom.value = cdom;
960: }
961: $autosubmit
962: $lastaction
1.54 raeburn 963: }
1.55 raeburn 964: </script>
1.57 raeburn 965: |;
1.55 raeburn 966: return $output;
1.54 raeburn 967: }
968:
1.55 raeburn 969: 1;
970: __END__
971:
972: =pod
973:
974: =head1 NAME
975:
976: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
977:
978: =head1 SYNOPSIS
979:
980: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
981:
982: =head1 OVERVIEW
983:
984: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
985:
986: =head2 Search Criteria (Screen One)
987:
988: =head3 Criteria:
989:
990: =over 4
991:
992: =item *
993: Course Activity - how recently was course last visited by anyone.
994:
995: =item *
996: Course Domain - the domain of the course
997:
998: =item *
1.84 raeburn 999: Type - Course or Community
1.55 raeburn 1000:
1001: =item *
1002: Course Institutional Code - the institutional identifier assigned to the course
1003:
1004: =item *
1005: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
1006:
1007: =item *
1008: Course Owner's Domain - the domain of the owner of the course
1009:
1010: =item *
1.76 bisitz 1011: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 1012:
1013: =item *
1014: 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).
1015:
1016: =back
1017:
1018: 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'}).
1019:
1020: =head2 Course Display (Screen Two)
1021:
1022: 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:
1023:
1024: =over 4
1025:
1026: =item *
1027: Course description
1028:
1029: =item *
1030: Domain description of course domain
1031:
1032: =item *
1033: Course institutional code
1034:
1035: =item *
1036: Course owner (username:domain)
1037:
1038: =back
1039:
1040: 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.
1041:
1042: 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.
1043:
1044: =head1 SUBROUTINES
1045:
1046: =over 4
1047:
1048: =item *
1049: X<create_user_javascript()>
1050: B<create_user_javascript($type)>:
1051:
1.83 raeburn 1052: Input: 1 - $type - the course type - Course or Community
1.55 raeburn 1053:
1054: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1055:
1056: Side Effects: None
1057:
1058: 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.
1059:
1060:
1061: =item *
1062: X<display_matched_courses()>
1.85 ! raeburn 1063: B<display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses)>:
1.55 raeburn 1064:
1.85 ! raeburn 1065: 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 1066:
1067: Output: 0
1068:
1069: 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.
1070:
1071: =item *
1072: X<multiples_tag()>
1073: B<multiples_tag()>:
1074:
1075:
1076: Input: 0
1077:
1078: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
1079:
1080: Side Effects: None
1081:
1082: =item *
1083: X<build_filters()>
1.85 ! raeburn 1084: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom)>:
1.55 raeburn 1085:
1086:
1.81 raeburn 1087: 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 1088:
1089: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
1090:
1091: Side Effects: None
1092:
1093: =item *
1094: X<search_courses()>
1.85 ! raeburn 1095: B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom)>:
1.55 raeburn 1096:
1097:
1.85 ! raeburn 1098: 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 1099:
1100: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
1101:
1102: Side Effects: None
1103:
1104:
1105: =item *
1106: X<course_chooser()>
1.85 ! raeburn 1107: B<course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone)>:
1.55 raeburn 1108:
1.85 ! raeburn 1109: 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 1110:
1.85 ! raeburn 1111: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection.
1.55 raeburn 1112:
1113: Side Effects: None
1114:
1115:
1116: =item *
1117: X<gochoose_javascript()>
1.57 raeburn 1118: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 1119:
1.66 raeburn 1120: 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 1121:
1122: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1123:
1124: Side Effects: None
1125:
1126: javascript functions used when user selects a course(s). Different behavior depending on context:
1127:
1128: =back
1129:
1130: =over 8
1131:
1132: =item
1133:
1134: (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.
1135:
1136: =item
1137:
1138: (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.
1139:
1140: =item
1141:
1142: (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.
1143:
1144: =item
1.54 raeburn 1145:
1.55 raeburn 1146: (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 1147:
1.55 raeburn 1148: =item
1.54 raeburn 1149:
1.55 raeburn 1150: (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 1151:
1.55 raeburn 1152: =item
1.54 raeburn 1153:
1.55 raeburn 1154: (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 1155:
1.55 raeburn 1156: =item
1.49 raeburn 1157:
1.55 raeburn 1158: (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 1159:
1.84 raeburn 1160: =item
1161:
1162: (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.
1163:
1.55 raeburn 1164: =back
1165:
1166: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>