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