Annotation of loncom/interface/lonpickcourse.pm, revision 1.78
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.78 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.77 2009/03/16 16:05:40 bisitz Exp $
1.1 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonpickcourse;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::loncoursedata;
35: use Apache::lonnet;
1.8 www 36: use Apache::lonlocal;
1.46 raeburn 37: use Apache::longroup;
1.78 ! raeburn 38: use Apache::courseclassifier;
1.47 www 39: use LONCAPA;
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.78 ! raeburn 53: 'multiple','type','setroles','fixeddom']);
1.54 raeburn 54:
1.55 raeburn 55: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
56: $lastaction,$autosubmit,$submitopener);
57:
1.57 raeburn 58: # Get course type - Course or Non-standard Course.
1.54 raeburn 59: $type = $env{'form.type'};
60: if (!defined($env{'form.type'})) {
61: $type = 'Course';
62: }
63: $title = &mt('Selecting a [_1]',$type);
64:
65: # Setup for multiple course selections, if flag for multiples set.
1.55 raeburn 66: $multiple = $env{'form.multiple'};
67: if ($multiple) {
68: ($jscript,$multelement) = &multiples_tag();
69: $title = &mt('Selecting [_1](s)',lc($type));
1.54 raeburn 70: }
71:
1.55 raeburn 72: # if called when a DC is selecting a course
1.54 raeburn 73: my $roledom = $env{'form.roleelement'};
74: if ($roledom) {
75: $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
1.66 raeburn 76: $submitopener = &processpick();
1.54 raeburn 77: $autosubmit = 'process_pick("'.$roledom.'")';
78: }
79:
80: my $onlyown = 0;
1.55 raeburn 81: # if called to assign course-based portfolio access control
1.59 raeburn 82: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 83: $onlyown = 1;
1.49 raeburn 84: }
1.55 raeburn 85:
86: my %loaditem;
1.78 ! raeburn 87: if ($env{'form.numtitles'}) {
! 88: $loaditem{'onload'} = 'setElements(); ';
! 89: }
! 90:
1.66 raeburn 91: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
92: ($env{'form.pickedcourse'})) {
1.78 ! raeburn 93: $loaditem{'onload'} .= 'setSections()';
1.30 raeburn 94: }
1.41 albertel 95: $r->print(&Apache::loncommon::start_page($title,undef,
1.42 albertel 96: {'add_entries' => \%loaditem,
1.41 albertel 97: 'no_nav_bar' => 1, }));
1.55 raeburn 98:
99: if ($env{'form.form'} eq 'portform') {
100: $lastaction = 'document.courselist.submit()';
1.67 raeburn 101: } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
102: !$multiple)) {
1.55 raeburn 103: $lastaction =
104: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
105: 'document.courselist.submit();';
1.34 albertel 106: } else {
1.55 raeburn 107: $lastaction = 'self.close()';
1.1 www 108: }
1.19 raeburn 109:
1.55 raeburn 110: # if called to assign a role in a course to a user via CUSR
1.66 raeburn 111: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68 raeburn 112: $r->print(&create_user_javascript($type));
1.55 raeburn 113: }
1.54 raeburn 114:
1.55 raeburn 115: # print javascript functions for choosing a course
116: if ($env{'form.gosearch'} || $onlyown) {
1.58 raeburn 117: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55 raeburn 118: }
119: $r->print('<script type="text/javascript">'.$jscript.'</script>');
120: $r->print($submitopener);
1.54 raeburn 121:
1.55 raeburn 122: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 123: my $filter = {};
124: my $action = '/adm/pickcourse';
1.78 ! raeburn 125: my $numtitles;
1.55 raeburn 126: if (!$onlyown) {
127: my $filterlist = ['domainfilter','descriptfilter',
128: 'instcodefilter','ownerfilter',
129: 'ownerdomfilter'];
130: # course ID filter for DCs only
131: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
132: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
133: push(@{$filterlist},'coursefilter');
134: }
135: $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.78 ! raeburn 136: $filter,$action,\$numtitles));
1.55 raeburn 137: }
1.54 raeburn 138:
139: # ---------------------------------------------------------------- Get the data
140: if ($env{'form.gosearch'} || $onlyown) {
1.78 ! raeburn 141: my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
1.57 raeburn 142: &display_matched_courses($r,$type,$multiple,$action,%courses);
1.54 raeburn 143: }
144: $r->print(&Apache::loncommon::end_page());
145: return OK;
146: }
147:
1.66 raeburn 148: sub processpick {
149: my $openerform = 'rolechoice';
150: if ($env{'form.form'} eq 'studentform') {
151: $openerform = $env{'form.form'};
152: }
153: my $process_pick = <<"ENDONE";
154: <script type="text/javascript">
155: function process_pick(dom) {
156: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
157: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
158: var okDomain = 0;
159: ENDONE
160: if ($openerform eq 'rolechoice') {
161: $process_pick .= <<"ENDTWO";
162: if (pickedDomain == dom) {
163: if (pickedCourse != '') {
164: var courseTarget = "cc./"+pickedDomain+"/"+pickedCourse
165: opener.document.title='Role selected. Please stand by.';
166: opener.status='Role selected. Please stand by.';
167: opener.document.rolechoice.newrole.value=courseTarget
168: opener.document.rolechoice.submit();
169: }
170: }
171: else {
172: 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");
173: }
174: ENDTWO
175: } else {
176: $process_pick .= <<"ENDTHREE";
177: if (pickedDomain != dom) {
178: 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");
179: return;
180: }
181: ENDTHREE
182: }
183: $process_pick .= "
184: }
185:
186: </script>
187: ";
188: return $process_pick;
189: }
190:
1.55 raeburn 191: sub create_user_javascript {
192: my ($type) = @_;
193: my $output;
194: #javascript for reporting sections and groups then closing
195: if ($env{'form.pickedcourse'}) {
196: my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
197: my $sec_element = 'currsec';
198: my $grplist_element = 'groups';
199: my ($sections,$groups) =
200: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
201: my $num_sections = scalar(@{$sections});
202: my $seclist = join(',',@{$sections});
203: my $num_groups = scalar(@{$groups});
204: my $groupslist = join(',',@{$groups});
205: $output = qq|
206: <script type="text/javascript">
207: function setSections() {
208: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
209: window.opener.setSect('$seclist');
210: self.close()
211: }
212: </script>
213: |;
214: ;
215: }
216: return $output;
217: }
218:
1.54 raeburn 219: sub display_matched_courses {
1.57 raeburn 220: my ($r,$type,$multiple,$action,%courses) = @_;
1.55 raeburn 221: if ($env{'form.form'} eq 'portform') {
222: $action = '/adm/portfolio';
223: }
1.68 raeburn 224: my $numcourses = keys(%courses);
1.55 raeburn 225: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 226: if ($env{'form.form'} eq 'modifycourse') {
227: if ($numcourses > 0) {
228: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
229: my $dctitle = &Apache::lonnet::plaintext('dc');
230: my $ccrolechk = ' checked="checked" ';
231: my $menuchk = ' ';
232: if ($env{'form.prevphase'} ne '') {
233: $ccrolechk = ' ';
234: $menuchk = ' checked="checked" ';
235: }
236: $r->print(
1.75 bisitz 237: '<fieldset>'
238: .'<legend>'.&mt('Action').'</legend>'
239: .'<div class="LC_nobreak"><label>'
240: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
241: .' '.&mt('Enter the course with the role of [_1].',$cctitle)
242: .'</label></div>'
243: .'<div class="LC_nobreak"><label>'
244: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> '
245: .&mt('View or modify course settings which only a [_1] may modify.',$dctitle)
246: .'</label></div>'
247: .'</fieldset>'
248: .'<br />'
249: );
1.68 raeburn 250: }
251: }
1.54 raeburn 252: my %by_descrip;
253: foreach my $course (keys(%courses)) {
254: my $descr;
1.64 raeburn 255: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 256: $descr = $courses{$course}{'description'};
1.64 raeburn 257: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 258: $descr = &unescape($1);
1.34 albertel 259: } else {
1.54 raeburn 260: $descr = &unescape($courses{$course});
261: }
262: my $description = $descr;
263: push (@{$by_descrip{$description}}, $course);
264: }
1.71 bisitz 265:
1.54 raeburn 266: if ($numcourses > 1 && $multiple) {
267: $r->print('<input type="button" value="check all"
268: onclick="javascript:checkAll(document.courselist.course_id)" />
269: <input type="button" value="uncheck all"
270: onclick="javascript:uncheckAll(document.courselist.course_id)" />
271: <br /><br />');
272: }
1.71 bisitz 273:
274: if (%courses) {
275: $r->print(&Apache::loncommon::start_data_table());
276: $r->print(&Apache::loncommon::start_data_table_header_row());
277: $r->print('<th>'.&mt('Select').'</th>'
1.76 bisitz 278: .'<th>'.&mt('Course Title').'</th>'
1.71 bisitz 279: .'<th>'.&mt('Domain').'</th>'
280: .'<th>'.&mt('Course Code').'</th>'
1.72 raeburn 281: .'<th>'.&mt('Owner/Co-owner(s)').'</th>'
1.71 bisitz 282: .'<th>'.&mt('Type').'</th>'
283: );
284: $r->print(&Apache::loncommon::end_data_table_header_row());
285: }
1.54 raeburn 286: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
287: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 288: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 289: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
290: $cleandesc=~s/'/\\'/g;
291: my ($cdom,$cnum)=split(/\_/,$course);
1.64 raeburn 292: my ($descr,$instcode,$ttype,@owners);
293: if (ref($courses{$course}) eq 'HASH') {
294: $descr = $courses{$course}{'description'};
1.65 raeburn 295: $instcode = $courses{$course}{'inst_code'};
1.64 raeburn 296: $ttype = $courses{$course}{'type'};
297: push(@owners,&unescape($courses{$course}{'owner'}));
298: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
299: foreach my $item (@{$courses{$course}{'co-owners'}}) {
300: push(@owners,&unescape($item));
301: }
302: }
303: } else {
304: my $singleowner;
305: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
306: push(@owners,&unescape($singleowner));
307: }
1.72 raeburn 308: my $ownerstr = join(', ',@owners);
1.71 bisitz 309: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc).'</td>');
310: $r->print('<td>'.$description.'</td>');
311: $r->print('<td>');
312: $r->print(&Apache::lonnet::domain($cdom,'description')?
313: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
314: $r->print('</td>');
315: $r->print('<td>');
1.64 raeburn 316: if ($instcode ne '') {
1.71 bisitz 317: $r->print(&unescape($instcode));
318: } else {
319: $r->print(' ');
1.54 raeburn 320: }
1.71 bisitz 321: $r->print('</td>');
1.72 raeburn 322: $r->print('<td>'.$ownerstr.'</td>');
1.71 bisitz 323: $r->print('<td>');
1.64 raeburn 324: if ($ttype ne '') {
1.71 bisitz 325: $r->print(&mt(&unescape($ttype)));
326: } else {
327: $r->print(' ');
1.23 raeburn 328: }
1.71 bisitz 329: $r->print('</td>');
1.54 raeburn 330: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 331: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 332: # $r->print("<br />\n");
1.19 raeburn 333: }
334: }
1.72 raeburn 335: if (%courses) {
336: $r->print(&Apache::loncommon::end_data_table());
337: }
1.71 bisitz 338:
1.54 raeburn 339: if (!%courses) {
340: $r->print(&mt('None found'));
341: } elsif ($multiple) {
1.57 raeburn 342: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 343: }
344: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
345: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
346: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
347: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
348: $r->print('<input type="hidden" name="roleelement" value="'.
349: $env{'form.roleelement'}.'" />'."\n");
350: }
1.55 raeburn 351: if ($env{'form.form'} eq 'portform') {
352: $r->print('<input type="hidden" name="cnum" value="" />');
353: $r->print('<input type="hidden" name="cdom" value="" />');
354: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
355: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 356: } elsif ($env{'form.form'} eq 'modifycourse') {
1.78 ! raeburn 357: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 358: } else {
359: $r->print('<input type="hidden" name="cnumelement" value="'.
360: $env{'form.cnumelement'}.'" />'."\n".
361: '<input type="hidden" name="cdomelement" value="'.
362: $env{'form.cdomelement'}.'" />'."\n");
1.55 raeburn 363: }
1.78 ! raeburn 364: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
! 365: $r->print('<input type="hidden" name="fixeddom" value="'.
! 366: $env{'form.fixeddom'}.'" />');
! 367: }
! 368: if ($env{'form.numtitles'}) {
! 369: $r->print('<input type="hidden" name="numtitles" value="'.
! 370: $env{'form.numtitles'}.'" />');
! 371: }
1.54 raeburn 372: $r->print("</form>\n");
373: return;
374: }
375:
376: sub multiples_tag {
1.55 raeburn 377: my $jscript = &Apache::loncommon::check_uncheck_jscript();
378: my $multelement = '<input type="hidden" name="multiple" value="1" />';
379: return ($jscript,$multelement);
1.1 www 380: }
1.30 raeburn 381:
1.54 raeburn 382: sub build_filters {
1.57 raeburn 383: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.78 ! raeburn 384: $numtitlesref) = @_;
1.55 raeburn 385: my $list;
1.57 raeburn 386: my $formname;
1.78 ! raeburn 387: my ($fixeddom,$codedom,$jscript);
1.57 raeburn 388: if (defined($env{'form.form'})) {
389: $formname = $env{'form.form'};
390: }
1.55 raeburn 391: my ($domainselectform,$sincefilterform,$ownerdomselectform,
1.78 ! raeburn 392: $instcodeform,$typeselectform,$instcodetitle);
1.55 raeburn 393: foreach my $item (@{$filterlist}) {
1.54 raeburn 394: $filter->{$item} = $env{'form.'.$item};
395: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.61 albertel 396: if ($item eq 'domainfilter' || $item eq 'ownerdomfilter') {
397: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
398: } elsif ($item eq 'coursefilter') {
399: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
400: } elsif ($item eq 'ownerfilter') {
401: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
402: } else {
403: $filter->{$item} =~ s/\W//g;
404: }
1.54 raeburn 405: if (!$filter->{$item}) {
406: $filter->{$item} = '';
407: }
408: }
409: if ($item eq 'domainfilter') {
1.63 albertel 410: my $allow_blank = 1;
411: if ($formname eq 'portform') {
412: $filter->{$item} ||= $env{'user.domain'};
413: $allow_blank=0;
1.67 raeburn 414: } elsif ($formname eq 'studentform') {
415: $filter->{$item} ||= $env{'request.role.domain'};
416: $allow_blank=0;
417: }
1.78 ! raeburn 418: if ($env{'form.fixeddom'}) {
! 419: $domainselectform = '<input type="hidden" name="domainfilter"'.
! 420: 'value="'.$env{'request.role.domain'}.'" />'.
! 421: &Apache::lonnet::domain($env{'request.role.domain'},
! 422: 'description');
! 423: $codedom = $env{'request.role.domain'};
! 424: } else {
! 425: $domainselectform =
! 426: &Apache::loncommon::select_dom_form($filter->{$item},
! 427: 'domainfilter',
! 428: $allow_blank);
! 429: $codedom = $filter->{'domainfilter'};
! 430: }
1.54 raeburn 431: } elsif ($item eq 'ownerdomfilter') {
432: $ownerdomselectform =
433: &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
434: } else {
435: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
436: }
437: }
438:
439: # last course activity filter and selection
440: $filter->{'sincefilter'} = $env{'form.sincefilter'};
441: $filter->{'sincefilter'} =~ s/[^\d-]//g;
442: if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
443: $sincefilterform=&Apache::loncommon::select_form($filter->{'sincefilter'},
444: 'sincefilter',('-1'=>'',
445: '86400' => 'today',
446: '604800' => 'last week',
447: '2592000' => 'last month',
448: '7776000' => 'last three months',
449: '15552000' => 'last six months',
450: '31104000' => 'last year',
451: 'select_form_order' =>
452: ['-1','86400','604800','2592000','7776000',
453: '15552000','31104000']));
454:
455: my %lt = (
1.74 bisitz 456: 'cac' => &mt("$type Activity"),
1.76 bisitz 457: 'cde' => &mt("$type Title"),
1.74 bisitz 458: 'cdo' => &mt("$type Domain"),
1.78 ! raeburn 459: 'ins' => &mt('Institutional Code'),
! 460: 'inc' => &mt('Institutional Categorization'),
1.74 bisitz 461: 'cow' => &mt("$type Owner's Username"),
462: 'cod' => &mt("$type Owner's Domain"),
1.54 raeburn 463: 'cog' => &mt('Course Type')
464: );
1.49 raeburn 465:
1.65 raeburn 466: $typeselectform = '<select name="type" size="1">'."\n";
1.54 raeburn 467: if ($type eq 'Course') {
1.78 ! raeburn 468: if ($env{'form.fixeddom'}) {
! 469: ($instcodeform,$jscript,$$numtitlesref) =
! 470: &instcode_selectors($codedom,'filterpicker');
! 471: }
! 472: if ($instcodeform eq '') {
! 473: $instcodeform =
1.57 raeburn 474: '<input type="text" name="instcodefilter" size="10" value="'.
475: $list->{'instcodefilter'}.'" />';
1.78 ! raeburn 476: $instcodetitle = $lt{'ins'};
! 477: } else {
! 478: $instcodetitle = $lt{'inc'};
! 479: }
! 480: if ($env{'form.fixeddom'}) {
! 481: $instcodetitle .= '<br />('.$codedom.')';
! 482: }
! 483: if ($jscript ne '') {
! 484: $jscript = '<script type="text/javascript" language="Javascript">'.$jscript.
! 485: '</script>'."\n";
! 486: }
1.54 raeburn 487: }
1.57 raeburn 488: foreach my $posstype ('Course','Non-standard Course') {
1.72 raeburn 489: $typeselectform.='<option value="'.$posstype.'"'.
1.73 bisitz 490: ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
1.54 raeburn 491: }
492: $typeselectform.="</select>";
1.57 raeburn 493: my $output = qq|
494: <form method="post" name="filterpicker" action="$action">
495: <input type="hidden" name="form" value="$formname" />
496: |;
497: if ($formname eq 'modifycourse') {
1.68 raeburn 498: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
499: '<input type="hidden" name="prevphase" value="'.
500: $env{'form.prevphase'}.'" />'."\n";
501: } else {
1.57 raeburn 502: my $name_input;
503: if ($env{'form.cnameelement'} ne '') {
504: $name_input = '<input type="hidden" name="cnameelement" value="'.
505: $env{'form.cnameelement'}.'" />';
506: }
507: $output .= qq|
1.27 albertel 508: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
509: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 510: $name_input
1.18 raeburn 511: $roleelement
1.35 raeburn 512: $multelement
1.57 raeburn 513: |;
1.59 raeburn 514: if ($formname eq 'portform') {
1.78 ! raeburn 515: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59 raeburn 516: }
1.57 raeburn 517: }
1.78 ! raeburn 518: if ($env{'form.fixeddom'}) {
! 519: $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
! 520: }
1.74 bisitz 521: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57 raeburn 522: if ($sincefilterform) {
1.74 bisitz 523: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
524: .$sincefilterform
525: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 526: }
527: if ($domainselectform) {
1.74 bisitz 528: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
529: .$domainselectform
530: .&Apache::lonhtmlcommon::row_closure();
1.78 ! raeburn 531: }
1.57 raeburn 532: if ($typeselectform) {
1.74 bisitz 533: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
534: .$typeselectform
535: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 536: }
537: if ($instcodeform) {
1.78 ! raeburn 538: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74 bisitz 539: .$instcodeform
540: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 541: }
542: if (exists($filter->{'ownerfilter'})) {
1.74 bisitz 543: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'})
1.77 bisitz 544: .'<input type="text" name="ownerfilter" size="20" value="'
1.74 bisitz 545: .$list->{'ownerfilter'}.'" />'
546: .&Apache::lonhtmlcommon::row_closure()
547: .&Apache::lonhtmlcommon::row_title($lt{'cod'})
548: .$ownerdomselectform
549: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 550: }
551: if (exists($filter->{'coursefilter'})) {
1.74 bisitz 552: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
553: .'<input type="text" name="coursefilter" size="25" value="'
554: .$list->{'coursefilter'}.'" />'
555: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 556: }
557: if (exists($filter->{'descriptfilter'})) {
1.74 bisitz 558: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
559: .'<input type="text" name="descriptfilter" size="40" value="'
560: .$list->{'descriptfilter'}.'" />'
561: .&Apache::lonhtmlcommon::row_closure(1);
1.57 raeburn 562: }
1.74 bisitz 563: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.70 raeburn 564: $output .= '<p><input type="submit" name="gosearch" value="'.
565: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.78 ! raeburn 566: return $jscript.$output;
! 567: }
! 568:
! 569: sub instcode_selectors {
! 570: my ($codedom,$formname) = @_;
! 571: my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
! 572: my ($jscript,$totcodes,$numtitles,$lasttitle) =
! 573: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
! 574: \%cat_items,\@codetitles,\%cat_titles,\%cat_order);
! 575: if ($numtitles > 0) {
! 576: $output = &Apache::courseclassifier::build_instcode_selectors($numtitles,
! 577: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
! 578: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
! 579: '<input type="hidden" name="state" value="listing" />'."\n";
! 580:
! 581: }
! 582: return ($output,$jscript,$numtitles);
1.54 raeburn 583: }
584:
585: sub search_courses {
1.78 ! raeburn 586: my ($r,$type,$onlyown,$filter,$numtitles) = @_;
1.54 raeburn 587: my %courses;
588: if (!$onlyown) {
1.71 bisitz 589: $r->print(&mt('Searching ...').'<br /> <br />');
1.6 www 590: $r->rflush();
1.54 raeburn 591: if (($filter->{'ownerfilter'} ne '') ||
592: ($filter->{'ownerdomfilter'} ne '')) {
593: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
594: $filter->{'ownerdomfilter'};
595: }
596: foreach my $item ('descriptfilter','instcodefilter','coursefilter',
597: 'combownerfilter') {
598: if (!$filter->{$item}) {
599: $filter->{$item}='.';
600: }
1.52 raeburn 601: }
602: if ($type eq '') { $type = '.'; }
1.54 raeburn 603: my $timefilter =
604: ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
1.78 ! raeburn 605: my ($instcodefilter,$regexpok);
! 606: if ($numtitles) {
! 607: $instcodefilter =
! 608: &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
! 609: $numtitles);
! 610: $regexpok = 1;
! 611: } else {
! 612: $instcodefilter = $filter->{'instcodefilter'};
! 613: }
1.54 raeburn 614: %courses =
615: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
616: $filter->{'descriptfilter'},
617: $timefilter,
1.78 ! raeburn 618: $instcodefilter,
1.54 raeburn 619: $filter->{'combownerfilter'},
620: $filter->{'coursefilter'},
1.78 ! raeburn 621: undef,undef,$type,$regexpok);
1.54 raeburn 622: } else {
623: $r->print('<br />');
1.60 raeburn 624: my %coursehash = &Apache::loncommon::findallcourses();
625: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 626: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 627: }
1.2 www 628: }
1.54 raeburn 629: return %courses;
1.18 raeburn 630: }
1.1 www 631:
1.30 raeburn 632: sub course_chooser {
1.35 raeburn 633: my ($multiple,$cdom,$cnum,$cleandesc) = @_;
1.30 raeburn 634: my $output;
1.35 raeburn 635: if ($multiple) {
1.32 albertel 636: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.30 raeburn 637: } else {
1.71 bisitz 638: $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30 raeburn 639: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
640: }
641: return $output;
1.49 raeburn 642: }
643:
1.55 raeburn 644: sub gochoose_javascript {
1.57 raeburn 645: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 646: my %elements = (
647: 'Course' => {
648: name => 'coursepick',
649: total => 'coursetotal',
650: list => 'courselist',
651: },
1.57 raeburn 652: 'Non-standard Course' => {
1.55 raeburn 653: name => 'grouppick',
654: total => 'grouptotal',
655: list => 'grouplist',
656: },
657: );
1.57 raeburn 658: my $output .= qq|
1.55 raeburn 659: <script type="text/javascript">
1.57 raeburn 660: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 661: var openerForm = "$env{'form.form'}";
662: courseCount = 0;
663: var courses = '';
1.57 raeburn 664: |;
665: if ($multiple) {
666: $output .= <<"ENDSCRIPT";
667: courseCount = 0;
668: var courses = '';
669: if (typeof(document.courselist.course_id.length) == 'undefined') {
670: // only 1 course checkbox was created
671: if (document.courselist.course_id.checked) {
672: courses = courses + document.courselist.course_id.value + "&&";
673: courseCount ++;
674: }
675: } else {
676: for (var j=0; j<document.courselist.course_id.length; j++) {
677: if (document.courselist.course_id[j].checked) {
678: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 679: courseCount ++;
680: }
1.57 raeburn 681: }
682: }
683: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
684: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
685: 'undefined') {
686: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
687: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 688: } else {
1.57 raeburn 689: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 690: }
1.57 raeburn 691: } else {
692: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
693: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
694: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 695: } else {
1.57 raeburn 696: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 697: }
1.55 raeburn 698: }
1.57 raeburn 699: }
700: if (courseCount > 0) {
701: courses = courses.substr(0,courses.length-2);
702: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
703: }
704: ENDSCRIPT
705: } else {
706: my $name_code;
707: if ($env{'form.cnameelement'} ne '') {
708: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
709: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 710: }
1.57 raeburn 711: $output .= qq|
1.55 raeburn 712: $name_code
713: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
714: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
715: if (slct.options == undefined) {
716: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
717: }
718: else {
719: var i;
720: for (i=0;i<slct.length;i++) {
721: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 722: }
723: }
1.57 raeburn 724: |;
1.54 raeburn 725: }
1.57 raeburn 726: $output .= qq|
1.55 raeburn 727: if (openerForm == 'portform') {
728: document.courselist.cnum.value = cname;
729: document.courselist.cdom.value = cdom;
730: }
731: $autosubmit
732: $lastaction
1.54 raeburn 733: }
1.55 raeburn 734: </script>
1.57 raeburn 735: |;
1.55 raeburn 736: return $output;
1.54 raeburn 737: }
738:
1.55 raeburn 739: 1;
740: __END__
741:
742: =pod
743:
744: =head1 NAME
745:
746: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
747:
748: =head1 SYNOPSIS
749:
750: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
751:
752: =head1 OVERVIEW
753:
754: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
755:
756: =head2 Search Criteria (Screen One)
757:
758: =head3 Criteria:
759:
760: =over 4
761:
762: =item *
763: Course Activity - how recently was course last visited by anyone.
764:
765: =item *
766: Course Domain - the domain of the course
767:
768: =item *
1.57 raeburn 769: Course Type - Course or Non-standard Course
1.55 raeburn 770:
771: =item *
772: Course Institutional Code - the institutional identifier assigned to the course
773:
774: =item *
775: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
776:
777: =item *
778: Course Owner's Domain - the domain of the owner of the course
779:
780: =item *
1.76 bisitz 781: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 782:
783: =item *
784: 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).
785:
786: =back
787:
788: 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'}).
789:
790: =head2 Course Display (Screen Two)
791:
792: 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:
793:
794: =over 4
795:
796: =item *
797: Course description
798:
799: =item *
800: Domain description of course domain
801:
802: =item *
803: Course institutional code
804:
805: =item *
806: Course owner (username:domain)
807:
808: =back
809:
810: 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.
811:
812: 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.
813:
814: =head1 SUBROUTINES
815:
816: =over 4
817:
818: =item *
819: X<create_user_javascript()>
820: B<create_user_javascript($type)>:
821:
1.57 raeburn 822: Input: 1 - $type - the course type - Course or Non-standard Course
1.55 raeburn 823:
824: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
825:
826: Side Effects: None
827:
828: 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.
829:
830:
831: =item *
832: X<display_matched_courses()>
1.57 raeburn 833: B<display_matched_courses($r,$type,$multiple,$action,%courses)>:
1.55 raeburn 834:
1.57 raeburn 835: Input: 5 - request object, course type, multiple (0 or 1), form action; hash of courses.
1.55 raeburn 836:
837: Output: 0
838:
839: 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.
840:
841: =item *
842: X<multiples_tag()>
843: B<multiples_tag()>:
844:
845:
846: Input: 0
847:
848: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
849:
850: Side Effects: None
851:
852: =item *
853: X<build_filters()>
1.78 ! raeburn 854: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref)>:
1.55 raeburn 855:
856:
1.78 ! raeburn 857: 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).
1.55 raeburn 858:
859: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
860:
861: Side Effects: None
862:
863: =item *
864: X<search_courses()>
1.78 ! raeburn 865: B<search_courses($r,$type,$onlyown,$filter,$numtitles)>:
1.55 raeburn 866:
867:
1.78 ! raeburn 868: Input: 5 - 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).
1.55 raeburn 869:
870: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
871:
872: Side Effects: None
873:
874:
875: =item *
876: X<course_chooser()>
877: B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
878:
879: Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description.
880:
881: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
882:
883: Side Effects: None
884:
885:
886: =item *
887: X<gochoose_javascript()>
1.57 raeburn 888: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 889:
1.66 raeburn 890: 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 891:
892: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
893:
894: Side Effects: None
895:
896: javascript functions used when user selects a course(s). Different behavior depending on context:
897:
898: =back
899:
900: =over 8
901:
902: =item
903:
904: (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.
905:
906: =item
907:
908: (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.
909:
910: =item
911:
912: (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.
913:
914: =item
1.54 raeburn 915:
1.55 raeburn 916: (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 917:
1.55 raeburn 918: =item
1.54 raeburn 919:
1.55 raeburn 920: (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 921:
1.55 raeburn 922: =item
1.54 raeburn 923:
1.55 raeburn 924: (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 925:
1.55 raeburn 926: =item
1.49 raeburn 927:
1.55 raeburn 928: (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 929:
1.55 raeburn 930: =back
931:
932: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>