File:
[LON-CAPA] /
loncom /
interface /
coursecatalog.pm
Revision
1.33:
download - view:
text,
annotated -
select for diffs
Mon Jun 30 04:07:06 2008 UTC (16 years, 1 month ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- New subroutine: &additional_filters() generates checkboxes to apply in course
search (self-enroll only, DC only: display hidden & show all details).
- "Go" buttons for updating domain used for coursecatalog and category to search
replaced with "Change"
- "Display course" button displayed for both searches for official courses and
for manually assigned categories.
- Some javascript changes so changeSort() and setCourseId() are available for
both types of search. copy_filters() function no longer needed.
1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
4: # $Id: coursecatalog.pm,v 1.33 2008/06/30 04:07:06 raeburn Exp $
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::coursecatalog;
30:
31: use strict;
32: use lib qw(/home/httpd/lib/perl);
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonhtmlcommon;
36: use Apache::lonnet;
37: use Apache::lonlocal;
38: use Apache::courseclassifier;
39: use Apache::lonacc;
40: use LONCAPA;
41:
42: sub handler {
43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: if ($r->header_only) {
47: return OK;
48: }
49: my $handle = &Apache::lonnet::check_for_valid_session($r);
50: my $lonidsdir=$r->dir_config('lonIDsDir');
51: if ($handle ne '') {
52: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
53: }
54: &Apache::lonacc::get_posted_cgi($r);
55: &Apache::lonlocal::get_language_handle($r);
56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
57:
58: my $codedom = &Apache::lonnet::default_login_domain();
59:
60: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
61: $codedom = $env{'user.domain'};
62: if ($env{'request.role.domain'} ne '') {
63: $codedom = $env{'request.role.domain'};
64: }
65: }
66: my $formname = 'coursecatalog';
67: if ($env{'form.showdom'} ne '') {
68: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
69: $codedom = $env{'form.showdom'};
70: }
71: }
72: my $domdesc = &Apache::lonnet::domain($codedom,'description');
73: &Apache::lonhtmlcommon::clear_breadcrumbs();
74: if ($env{'form.coursenum'} ne '' && &user_is_known()) {
75: &course_details($r,$codedom,$formname,$domdesc);
76: } else {
77: my $catlinks = &category_breadcrumbs($codedom);
78: my $catjs = <<"ENDSCRIPT";
79:
80: function setCatDepth(depth) {
81: document.coursecats.catalog_maxdepth.value = depth;
82: document.coursecats.submit();
83: return;
84: }
85:
86: ENDSCRIPT
87: if ($env{'form.state'} eq 'listing') {
88: $catjs .= qq|
89: function changeSort(caller) {
90: document.$formname.sortby.value = caller;
91: document.$formname.submit();
92: }
93: function setCourseId(caller) {
94: document.$formname.coursenum.value = caller;
95: document.$formname.submit();
96: }\n|;
97: }
98: my $numtitles;
99: if ($env{'form.currcat_0'} eq 'instcode::0') {
100: $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
101: $catlinks,$catjs);
102: if ($env{'form.state'} eq 'listing') {
103: $r->print(&print_course_listing($codedom,$numtitles));
104: }
105: } else {
106: my (%add_entries);
107: $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
108: &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
109: if ($env{'form.currcat_0'} ne '') {
110: $r->print('<form name="'.$formname.
111: '" method="post" action="/adm/coursecatalog">'.
112: &additional_filters($codedom)."\n");
113: my ($currdepth,$deeper) = &get_depth_values();
114: $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
115: $deeper.'" />'."\n");
116: for (my $i=0; $i<$deeper; $i++) {
117: $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
118: }
119: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
120: '<input type="hidden" name="sortby" value="" />'."\n".
121: '<input type="hidden" name="state" value="listing" />'."\n".
122: '<input type="hidden" name="showdom" value="'.
123: $env{'form.showdom'}.'" />'.
124: '<input type="submit" name="catalogfilter" value="'.
125: &mt('Display courses').'" /></form><br /><br />');
126: }
127: if ($env{'form.state'} eq 'listing') {
128: $r->print(&print_course_listing($codedom));
129: }
130: }
131: }
132: $r->print('<br />'.&Apache::loncommon::end_page());
133: return OK;
134: }
135:
136: sub course_details {
137: my ($r,$codedom,$formname,$domdesc) = @_;
138: my $output;
139: my %add_entries = (topmargin => "0",
140: marginheight => "0",);
141: my $start_page =
142: &Apache::loncommon::start_page('Course Catalog','',
143: {
144: 'add_entries' => \%add_entries,
145: 'no_inline_link' => 1,});
146: $r->print($start_page);
147: if ($env{'form.numtitles'} > 0) {
148: &Apache::lonhtmlcommon::add_breadcrumb
149: ({href=>"/adm/coursecatalog",
150: text=>"Select courses"});
151: }
152: &Apache::lonhtmlcommon::add_breadcrumb
153: ({href=>"javascript:document.$formname.submit()",
154: text=>"Course listing"},
155: {text=>"Course details"});
156: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
157: $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
158: '<form name="'.$formname.'" method="post">'.
159: &print_course_listing($codedom).'<br /><br />');
160: $r->print('<a href = "javascript:document.coursecatalog.submit()">'.
161: &mt('Back to course listing').'</a>'.
162: '<input type="hidden" name="sortby" value="'.
163: $env{'form.sortby'}.'" />'.
164: '<input type="hidden" name="state" value="listing" /></form>');
165: }
166:
167: sub instcode_course_selector {
168: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
169: my %coursecodes = ();
170: my %codes = ();
171: my @codetitles = ();
172: my %cat_titles = ();
173: my %cat_order = ();
174: my %idlist = ();
175: my %idnums = ();
176: my %idlist_titles = ();
177: my %by_year;
178: my %by_sem;
179: my %by_dept;
180: my %cat_items;
181: my $caller = 'global';
182: my $format_reply;
183: my $totcodes = 0;
184: my $jscript = '';
185: my ($numtitles,$lasttitle);
186: my %add_entries = (topmargin => "0",
187: marginheight => "0",);
188: my $js;
189: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
190: if ($totcodes > 0) {
191: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
192: if ($format_reply eq 'ok') {
193: my $numtypes = @codetitles;
194: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
195: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
196: my $longtitles_str = join('","',@{$longtitles});
197: my $allidlist = $idlist{$codetitles[0]};
198: $numtitles = @codetitles;
199: $lasttitle = $numtitles;
200: if ($numtitles > 4) {
201: $lasttitle = 4;
202: }
203: if ($numtitles == 0) {
204: if (!defined($env{'form.state'})) {
205: $env{'form.state'} = 'listing';
206: }
207: } else {
208: my @data = ('top');
209: for (my $k=0; $k<$lasttitle; $k++) {
210: my $cat = $codetitles[$k];
211: my $level = 1;
212: $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
213: }
214: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
215: $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
216: if ($env{'form.state'} eq 'listing') {
217: $jscript .= '
218: function setElements() {
219: ';
220: for (my $i=0; $i<@codetitles-1; $i++) {
221: if ($env{'form.'.$codetitles[$i]} != -1) {
222: $jscript .= '
223: for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
224: if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
225: document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
226: }
227: }
228: ';
229: }
230: }
231: $jscript .= ' courseSet()'."\n";
232: if ($env{'form.'.$codetitles[-1]} != -1) {
233: $jscript .= '
234: for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
235: if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
236: document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
237: }
238: }
239: ';
240: }
241: $jscript .= '}';
242: }
243: }
244: }
245: $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
246: '</script>';
247: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
248: $add_entries{'onLoad'} = 'setElements()';
249: }
250: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
251: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
252: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
253: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
254: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
255: '<input type="hidden" name="currcat_0" value="instcode::0" />'.
256: &additional_filters($codedom));
257: if ($numtitles > 0) {
258: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
259: $r->print('<table><tr>');
260: for (my $k=0; $k<$lasttitle-1; $k++) {
261: my (@items,@unsorted);
262: if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
263: @unsorted = @{$cat_items{$codetitles[$k]}};
264: }
265: &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
266: my @longitems;
267: if (defined($cat_titles{$codetitles[$k]})) {
268: foreach my $item (@items) {
269: push(@longitems,$cat_titles{$codetitles[$k]}{$item});
270: }
271: } else {
272: @longitems = @items;
273: }
274: $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
275: '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
276: $r->print('>'."\n".'<option value="0" />All'."\n");
277: for (my $i=0; $i<@items; $i++) {
278: if ($longitems[$i] eq '') {
279: $longitems[$i] = $items[$i];
280: }
281: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
282: }
283: $r->print('</select></td>');
284: }
285: $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
286: '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
287: '<option value="0">All'."\n".
288: '</option>'."\n".'</select>'."\n".
289: '</td></tr></table>'."\n");
290: if ($numtitles > 4) {
291: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
292: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
293: }
294: $r->print('<br />');
295: }
296: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
297: '<input type="hidden" name="sortby" value="" />'."\n".
298: '<input type="hidden" name="state" value="listing" />'."\n".
299: '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
300: '<input type="submit" name="catalogfilter" value="'.
301: &mt('Display courses').'" />'.
302: '<input type="hidden" name="numtitles" value="'.$numtitles.
303: '" /></form>');
304: if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
305: $r->print('<br />');
306: }
307: } else {
308: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
309: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
310: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
311: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
312: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
313: '<input type="hidden" name="currcat_0" value="instcode::0" />');
314: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
315: }
316: return $numtitles;
317: }
318:
319: sub cat_header {
320: my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
321: my $start_page =
322: &Apache::loncommon::start_page('Course Catalog',$js,
323: {
324: 'add_entries' => $add_entries,
325: 'no_inline_link' => 1,});
326: $r->print($start_page);
327: if ($env{'form.state'} eq 'listing') {
328: if ($numtitles > 0) {
329: &Apache::lonhtmlcommon::add_breadcrumb
330: ({href=>"/adm/coursecatalog",
331: text=>"Select courses"},
332: {text=>"Course listing"});
333: } else {
334: &Apache::lonhtmlcommon::add_breadcrumb
335: ({text=>"Course listing"});
336: }
337: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
338: } else {
339: &Apache::lonhtmlcommon::add_breadcrumb
340: ({href=>"/adm/coursecatalog",
341: text=>"Select courses"});
342: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
343: }
344: $r->print('<table border="0"><tr>'.
345: '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
346: '<td><b>'.&mt('Domain:').'</b></td><td>'.
347: &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
348: ' <input type="submit" name="godom" value="'.&mt('Change').'"></td></form></tr>'.
349: '<tr><form name="coursecats" method="post" action="/adm/coursecatalog">'.
350: $catlinks.'</form></tr></table>');
351: return;
352: }
353:
354: sub category_breadcrumbs {
355: my ($dom) = @_;
356: my %domconfig =
357: &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
358: my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);
359: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
360: $cathash = $domconfig{'coursecategories'}{'cats'};
361: } else {
362: $cathash = {};
363: }
364: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,
365: \@jsarray);
366: my ($currdepth,$deeper) = &get_depth_values();
367: my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
368: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
369: for (my $i=0; $i<$deeper; $i++) {
370: $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
371: my ($cattitle,$shallower);
372: if ($i == 0) {
373: $cattitle = &mt('Main Categories');
374: } else {
375: $shallower = $i-1;
376: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
377: $cattitle = $cat;
378: }
379: $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>-></td>';
380: }
381: if ($deeper == 0) {
382: $catlinks .= '<td>'.&mt('Main Categories').': ';
383: if (ref($cats[0]) eq 'ARRAY') {
384: if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {
385: $catlinks .= &mt('Official courses (with institutional codes)').
386: '<input type="hidden" name="currcat_0" value="instcode::0">';
387: $env{'form.currcat_0'} = 'instcode::0';
388: } else {
389: $catlinks .= '<select name="currcat_0">'."\n";
390: if (@{$cats[0]} > 1) {
391: my $selstr;
392: if ($env{'form.currcat_0'} eq '') {
393: $selstr = ' selected="selected" ';
394: }
395: $catlinks .= '<option value=""'.$selstr.'>'.&mt('Select').'</option>'."\n";
396: }
397: for (my $i=0; $i<@{$cats[0]}; $i++) {
398: my $name = $cats[0][$i];
399: my $item = &escape($name).'::0';
400: my $selstr;
401: if ($env{'form.currcat_'.$i} eq $item) {
402: $selstr = ' selected="selected" ';
403: }
404: $catlinks .= '<option value="'.$item.'"'.$selstr.'>';
405: if ($name eq 'instcode') {
406: $catlinks .= &mt('Official courses (with institutional codes)');
407: } else {
408: $catlinks .= $name;
409: }
410: $catlinks .= '</option>'."\n";
411: }
412: $catlinks .= '</select>'."\n".
413: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
414: }
415: } else {
416: $catlinks .= &mt('Official courses (with institutional codes)').
417: '<input type="hidden" name="currcat_0" value="instcode::0">';
418: $env{'form.currcat_0'} = 'instcode::0';
419: }
420: } else {
421: my ($cat,$container,$depth);
422: if ($env{'form.currcat_'.$currdepth} eq '') {
423: my $shallower = $currdepth - 1;
424: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
425: } else {
426: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
427: }
428: my $deeper = $depth +1;
429: my $currcat = $cat;
430: if ($cat eq 'instcode') {
431: $currcat = &mt('Official courses (with institutional codes)');
432: }
433: $catlinks .= '<td>'.$currcat;
434: if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
435: $catlinks .= ': <select name="currcat_'.$deeper.'">'.
436: '<option value="" selected="selected">'.&mt('Select').'</option>';
437: for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
438: my $name = $cats[$deeper]{$cat}[$k];
439: my $item = &escape($name).':'.&escape($cat).':'.$deeper;
440: $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
441: }
442: $catlinks .= '</select>'."\n".
443: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
444: }
445: }
446: $catlinks .= $currcat_str.'</td></tr></table></td>';
447: return $catlinks;
448: }
449:
450: sub get_depth_values {
451: my $currdepth = 0;
452: my $deeper = 0;
453: if ($env{'form.catalog_maxdepth'} ne '') {
454: $currdepth = $env{'form.catalog_maxdepth'};
455: if ($env{'form.currcat_'.$currdepth} eq '') {
456: $deeper = $currdepth;
457: } else {
458: $deeper = $currdepth + 1;
459: }
460: }
461: return ($currdepth,$deeper);
462: }
463:
464: sub additional_filters {
465: my ($codedom) = @_;
466: my $output = '<table>';
467: my $show_selfenroll_status;
468: if ($env{'form.showselfenroll'}) {
469: $show_selfenroll_status = 'checked="checked" ';
470: }
471: if (&user_is_dc($codedom)) {
472: my $showdetails_status;
473: if ($env{'form.showdetails'}) {
474: $showdetails_status = 'checked="checked" ';
475: }
476: my $showhidden_status;
477: if ($env{'form.showhidden'}) {
478: $showhidden_status = 'checked="checked" ';
479: }
480: my $dc_title = &Apache::lonnet::plaintext('dc');
481: $output .= '<tr><td>'."\n".
482: '<label><input type="checkbox" name="showdetails" value="1" '.
483: $showdetails_status.'/>'."\n".
484: &mt('Show full details for each course ([_1] only)',$dc_title).
485: '</label>'."\n".'</td></tr><tr><td>'.
486: '<label><input type="checkbox" name="showhidden" value="1" '.
487: $showhidden_status.'/>'.
488: &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
489: '</label>'."\n".'</td></tr>';
490: }
491: $output .= '<tr><td>'.
492: '<label><input type="checkbox" name="showselfenroll" value="1" '.
493: $show_selfenroll_status.'/>'.
494: &mt('Only show courses which allow self-enrollment').
495: '</label></td></tr></table><br />';
496: return $output;
497: }
498:
499: sub user_is_dc {
500: my ($codedom) = @_;
501: if (exists($env{'user.role.dc./'.$codedom.'/'})) {
502: my $livedc = 1;
503: my $now = time;
504: my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
505: if ($start && $start>$now) { $livedc = 0; }
506: if ($end && $end <$now) { $livedc = 0; }
507: return $livedc;
508: }
509: return;
510: }
511:
512: sub recurse_options {
513: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
514: if (ref($currlist) eq 'HASH') {
515: $level ++;
516: foreach my $key (sort(keys(%{$currlist}))) {
517: $$data[$level-1]= $key;
518: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
519: }
520: } else {
521: $level --;
522: my @contents = split(/","/,$currlist);
523: foreach my $item (@contents) {
524: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
525: push(@{$cat_options->{$cat}},$item);
526: }
527: if ($level == 3) {
528: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
529: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
530: }
531: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
532: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
533: }
534: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
535: push(@{$by_dept->{$currkey}},$item);
536: }
537:
538: }
539: }
540: }
541: return $level;
542: }
543:
544: sub build_javascript {
545: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
546: my @unsorted = keys(%{$by_year});
547: my @sorted_yrs;
548: &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
549: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
550: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
551: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
552: for (my $i=0; $i<@sorted_yrs; $i++) {
553: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
554: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
555: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
556: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
557: my @sorted_depts;
558: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
559: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
560: for (my $j=0; $j<@sorted_depts; $j++) {
561: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
562: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
563: }
564: }
565: }
566: @unsorted = keys(%{$by_sem});
567: my @sorted_sems;
568: &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
569: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
570: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
571: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
572: for (my $i=0; $i<@sorted_sems; $i++) {
573: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
574: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
575: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
576: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
577: my @sorted_depts;
578: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
579: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
580: for (my $j=0; $j<@sorted_depts; $j++) {
581: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
582: }
583: }
584: }
585: @unsorted = keys(%{$by_dept});
586: my @sorted_deps;
587: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
588: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
589: for (my $k=0; $k<@sorted_deps; $k++) {
590: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
591: }
592: return $output;
593: }
594:
595: sub search_official_courselist {
596: my ($domain,$numtitles) = @_;
597: my $instcode;
598: if (defined($numtitles) && $numtitles == 0) {
599: $instcode = '.+';
600: } else {
601: my (%codedefaults,@code_order);
602: my $defaults_result =
603: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
604: \@code_order);
605: if ($defaults_result eq 'ok') {
606: $instcode ='^';
607: foreach my $item (@code_order) {
608: if ($env{'form.'.$item} eq '0' ) {
609: $instcode .= $codedefaults{$item};
610: } else {
611: $instcode .= $env{'form.'.$item};
612: }
613: }
614: $instcode .= '$';
615: } else {
616: $instcode = '.';
617: }
618: }
619: my $showhidden;
620: if (&user_is_dc($domain)) {
621: $showhidden = $env{'form.showhidden'};
622: }
623: my %courses =
624: &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
625: 'Course',1,$env{'form.showselfenroll'},undef,
626: $showhidden,'coursecatalog');
627: return %courses;
628: }
629:
630: sub search_courselist {
631: my ($domain) = @_;
632: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
633: my $filter = $env{'form.currcat_'.$cat_maxdepth};
634: if (($filter eq '') && ($cat_maxdepth > 0)) {
635: my $shallower = $cat_maxdepth - 1;
636: $filter = $env{'form.currcat_'.$shallower};
637: }
638: my %courses;
639: if ($filter ne '') {
640: my $showhidden;
641: if (&user_is_dc($domain)) {
642: $showhidden = $env{'form.showhidden'};
643: }
644: %courses =
645: &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
646: '.',1,$env{'form.showselfenroll'},
647: $filter,$showhidden,'coursecatalog');
648: }
649: return %courses;
650: }
651:
652: sub print_course_listing {
653: my ($domain,$numtitles) = @_;
654: my $output;
655: my %courses;
656: my $knownuser = &user_is_known();
657: my $details = $env{'form.coursenum'};
658: if (&user_is_dc($domain)) {
659: if ($env{'form.showdetails'}) {
660: $details = 1;
661: }
662: }
663: if ($env{'form.coursenum'} ne '') {
664: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
665: $env{'form.coursenum'},
666: undef,undef,'.',1);
667: if (keys(%courses) == 0) {
668: $output .= &mt('The courseID provided does not match a course in this domain.');
669: return $output;
670: }
671: } else {
672: if ($env{'form.currcat_0'} eq 'instcode::0') {
673: %courses = &search_official_courselist($domain,$numtitles);
674: } else {
675: %courses = &search_courselist($domain);
676: }
677: if (keys(%courses) == 0) {
678: $output = &mt('No courses match the criteria you selected.');
679: return $output;
680: }
681: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
682: $output = '<b>'.&mt('Note for students:').'</b> '
683: .&mt('If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.')
684: .'<br /><br />';
685: }
686: }
687: my $now = time;
688: my %domconfig =
689: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
690: $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig);
691: $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
692: return $output;
693: }
694:
695: sub construct_data_table {
696: my ($knownuser,$courses,$details,$usersections,$now,$domconfig) = @_;
697: my %sortname;
698: if (($details eq '') || ($env{'form.showdetails'})) {
699: $sortname{'Code'} = 'code';
700: $sortname{'Title'} = 'title';
701: $sortname{'Owner(s)'} = 'owner';
702: }
703: my $output = &Apache::loncommon::start_data_table().
704: &Apache::loncommon::start_data_table_header_row();
705: my @coltitles = ('Count','Code','Sections','Crosslisted','Title','Owner(s)');
706: if (ref($usersections) eq 'HASH') {
707: $coltitles[1] = 'Your Section';
708: }
709: foreach my $item (@coltitles) {
710: $output .= '<th>';
711: if (defined($sortname{$item})) {
712: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
713: } elsif ($item eq 'Count') {
714: $output .= ' ';
715: } else {
716: $output .= &mt($item);
717: }
718: $output .= '</th>';
719: }
720: if ($knownuser) {
721: if ($details) {
722: $output .=
723: '<th>'.&mt('Default Access Dates for Students').'</th>'.
724: '<th>'.&mt('Student Counts').'</th>'.
725: '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
726: } else {
727: $output .= '<th>'.&mt('Details').'</th>';
728: }
729: }
730: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
731: &Apache::loncommon::end_data_table_header_row();
732: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
733: $usersections);
734: my %Sortby;
735: foreach my $course (sort(keys(%{$courses}))) {
736: if ($env{'form.sortby'} eq 'code') {
737: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
738: } elsif ($env{'form.sortby'} eq 'owner') {
739: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
740: } else {
741: my $clean_title = $courseinfo{$course}{'title'};
742: $clean_title =~ s/\W+//g;
743: if ($clean_title eq '') {
744: $clean_title = $courseinfo{$course}{'title'};
745: }
746: push(@{$Sortby{$clean_title}},$course);
747: }
748: }
749: my @sorted_courses;
750: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {
751: @sorted_courses = sort(keys(%Sortby));
752: } else {
753: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
754: }
755: my $count = 1;
756: foreach my $item (@sorted_courses) {
757: foreach my $course (@{$Sortby{$item}}) {
758: $output.=&Apache::loncommon::start_data_table_row();
759: $output.=&courseinfo_row($courseinfo{$course},$knownuser,
760: $details,\$count,$now,$course);
761: $output.=&Apache::loncommon::end_data_table_row();
762: }
763: }
764: $output .= &Apache::loncommon::end_data_table();
765: return $output;
766: }
767:
768: sub build_courseinfo_hash {
769: my ($courses,$knownuser,$details,$usersections) = @_;
770: my %courseinfo;
771: my $now = time;
772: foreach my $course (keys(%{$courses})) {
773: my $descr;
774: if (ref($courses->{$course}) eq 'HASH') {
775: $descr = $courses->{$course}{'description'};
776: }
777: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
778: $cleandesc=~s/'/\\'/g;
779: $cleandesc =~ s/^\s+//;
780: my ($cdom,$cnum)=split(/\_/,$course);
781: my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types,
782: $selfenroll_start,$selfenroll_end,@owners,%ownernames);
783: if (ref($courses->{$course}) eq 'HASH') {
784: $descr = $courses->{$course}{'description'};
785: $instcode = $courses->{$course}{'inst_code'};
786: $singleowner = $courses->{$course}{'owner'};
787: $ttype = $courses->{$course}{'type'};
788: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
789: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
790: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
791: push(@owners,$singleowner);
792: if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
793: foreach my $item (@{$courses->{$course}{'co-owners'}}) {
794: push(@owners,$item);
795: }
796: }
797: }
798: foreach my $owner (@owners) {
799: my ($ownername,$ownerdom) = @_;
800: if ($owner =~ /:/) {
801: ($ownername,$ownerdom) = split(/:/,$owner);
802: } else {
803: $ownername = $owner;
804: if ($owner ne '') {
805: $ownerdom = $cdom;
806: }
807: }
808: if ($ownername ne '' && $ownerdom ne '') {
809: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
810: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
811: }
812: }
813: $courseinfo{$course}{'cdom'} = $cdom;
814: $courseinfo{$course}{'cnum'} = $cnum;
815: $courseinfo{$course}{'code'} = $instcode;
816: my @lastnames;
817: foreach my $owner (keys(%ownernames)) {
818: if (ref($ownernames{$owner}) eq 'HASH') {
819: push(@lastnames,$ownernames{$owner}{'lastname'});
820: }
821: }
822: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
823: $courseinfo{$course}{'title'} = $cleandesc;
824: $courseinfo{$course}{'owner'} = $singleowner;
825: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
826: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
827: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
828:
829: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
830: my @classids;
831: my @crosslistings;
832: my ($seclist,$numsec) =
833: &identify_sections($coursehash{'internal.sectionnums'});
834: if (ref($usersections) eq 'HASH') {
835: if (ref($usersections->{$course}) eq 'ARRAY') {
836: $seclist = join(', ',@{$usersections->{$course}});
837: }
838: }
839: $courseinfo{$course}{'seclist'} = $seclist;
840: my ($xlist_items,$numxlist) =
841: &identify_sections($coursehash{'internal.crosslistings'});
842: my $showsyllabus = 1; # default is to include a syllabus link
843: if (defined($coursehash{'showsyllabus'})) {
844: $showsyllabus = $coursehash{'showsyllabus'};
845: }
846: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
847: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
848: ($knownuser && ($details == 1))) {
849: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec);
850: $courseinfo{$course}{'autoenrollment'} =
851: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
852: $instcode,\@owners,$cdom,$cnum);
853:
854: my $startaccess = '';
855: my $endaccess = '';
856: my $accessdates;
857: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
858: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
859: }
860: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
861: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
862: if ($coursehash{'default_enrollment_end_date'} == 0) {
863: $endaccess = "No ending date";
864: }
865: }
866: if ($startaccess) {
867: $accessdates .= &mt('<i>From:</i> ').$startaccess.'<br />';
868: }
869: if ($endaccess) {
870: $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
871: }
872: $courseinfo{$course}{'access'} = $accessdates;
873: }
874: if ($xlist_items eq '') {
875: $xlist_items = &mt('No');
876: }
877: $courseinfo{$course}{'xlist'} = $xlist_items;
878: }
879: return %courseinfo;
880: }
881:
882: sub count_students {
883: my ($cdom,$cnum,$numsec) = @_;
884: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
885: my %student_count = (
886: Active => 0,
887: Future => 0,
888: Expired => 0,
889: );
890: my %idx;
891: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
892: my %status_title = &Apache::lonlocal::texthash(
893: Expired => 'Previous access',
894: Active => 'Current access',
895: Future => 'Future access',
896: );
897:
898: while (my ($student,$data) = each(%$classlist)) {
899: $student_count{$data->[$idx{'status'}]} ++;
900: }
901:
902: my $countslist = &mt('[quant,_1,section]',$numsec).':<br />';
903: foreach my $status ('Active','Future') {
904: $countslist .= '<nobr>'.$status_title{$status}.': '.
905: $student_count{$status}.'</nobr><br />';
906: }
907: return $countslist;
908: }
909:
910: sub courseinfo_row {
911: my ($info,$knownuser,$details,$countref,$now,$course) = @_;
912: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
913: $accessdates,$showsyllabus,$counts,$autoenrollment,$output);
914: if (ref($info) eq 'HASH') {
915: $cdom = $info->{'cdom'};
916: $cnum = $info->{'cnum'};
917: $title = $info->{'title'};
918: $ownerlast = $info->{'ownerlastnames'};
919: $code = $info->{'code'};
920: $owner = $info->{'owner'};
921: $seclist = $info->{'seclist'};
922: $xlist_items = $info->{'xlist'};
923: $accessdates = $info->{'access'};
924: $counts = $info->{'counts'};
925: $autoenrollment = $info->{'autoenrollment'};
926: $showsyllabus = $info->{'showsyllabus'};
927: } else {
928: $output = '<td colspan="8">'.&mt('No information available for [_1].',
929: $code).'</td>';
930: return $output;
931: }
932: $output .= '<td>'.$$countref.'</td>'.
933: '<td>'.$code.'</td>'.
934: '<td>'.$seclist.'</td>'.
935: '<td>'.$xlist_items.'</td>'.
936: '<td>'.$title.' <font size="-2">';
937: if ($showsyllabus) {
938: $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom);
939: } else {
940: $output .= ' ';
941: }
942: $output .= '</font></td>'.
943: '<td>'.$ownerlast.'</td>';
944: if ($knownuser) {
945: if ($details) {
946: $output .=
947: '<td>'.$accessdates.'</td>'.
948: '<td>'.$counts.'</td>'.
949: '<td>'.$autoenrollment.'</td>';
950: } else {
951: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
952: }
953: }
954: my $selfenroll;
955: if ($info->{'selfenroll_types'}) {
956: my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
957: my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
958: if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
959: if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
960: $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
961: } else {
962: $output .= '<td><a href="/adm/selfenroll?cid='.$course.'">'.&mt('Enroll in course').'</a></td>';
963: }
964: $selfenroll = 1;
965: }
966: }
967: if (!$selfenroll) {
968: $output .= '<td> </td>';
969: }
970: $$countref ++;
971: return $output;
972: }
973:
974: sub identify_sections {
975: my ($seclist) = @_;
976: my @secnums;
977: if ($seclist =~ /,/) {
978: my @sections = split(/,/,$seclist);
979: foreach my $sec (@sections) {
980: $sec =~ s/:[^:]*$//;
981: push(@secnums,$sec);
982: }
983: } else {
984: if ($seclist =~ m/^([^:]+):/) {
985: my $sec = $1;
986: if (!grep(/^\Q$sec\E$/,@secnums)) {
987: push(@secnums,$sec);
988: }
989: }
990: }
991: @secnums = sort {$a <=> $b} @secnums;
992: my $seclist = join(', ',@secnums);
993: my $numsec = @secnums;
994: return ($seclist,$numsec);
995: }
996:
997: sub get_valid_classes {
998: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
999: my $response;
1000: my %validations;
1001: @{$validations{'sections'}} = ();
1002: @{$validations{'xlists'}} = ();
1003: my $totalitems = 0;
1004: if ($seclist) {
1005: foreach my $sec (split(/, /,$seclist)) {
1006: my $class = $crscode.$sec;
1007: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1008: $class) eq 'ok') {
1009: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1010: push(@{$validations{'sections'}},$sec);
1011: $totalitems ++;
1012: }
1013: }
1014: }
1015: }
1016: if ($xlist_items) {
1017: foreach my $item (split(/, /,$xlist_items)) {
1018: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1019: $item) eq 'ok') {
1020: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1021: push(@{$validations{'xlists'}},$item);
1022: $totalitems ++;
1023: }
1024: }
1025: }
1026: }
1027: if ($totalitems > 0) {
1028: if (@{$validations{'sections'}}) {
1029: $response = &mt('Sections: ').
1030: join(', ',@{$validations{'sections'}}).'<br />';
1031: }
1032: if (@{$validations{'xlists'}}) {
1033: $response .= &mt('Courses: ').
1034: join(', ',@{$validations{'xlists'}});
1035: }
1036: }
1037: return $response;
1038: }
1039:
1040: sub javascript_select_filler {
1041: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
1042: my $output = <<END;
1043: function courseSet() {
1044: var longtitles = new Array ("$longtitles_str");
1045: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
1046: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
1047: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
1048: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
1049: var idyears = new Array("$allidlist");
1050: var idyr = -1;
1051: var idsem = -1;
1052: var iddept = -1;
1053: document.$formname.Number.length = 0;
1054:
1055: $scripttext
1056:
1057: selYear = document.$formname.Year.selectedIndex-1;
1058: selSemester = document.$formname.Semester.selectedIndex-1;
1059: selDepartment = document.$formname.Department.selectedIndex-1;
1060: if (selYear == -1) {
1061: if (selSemester == -1) {
1062: if (selDepartment > -1) {
1063: document.$formname.Number.options[0] = new Option('All','0',false,false);
1064: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
1065: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
1066:
1067: }
1068: }
1069: else {
1070: document.$formname.Number.options[0] = new Option("All","0",true,true);
1071: }
1072: }
1073: else {
1074: if (selDepartment > -1) {
1075: for (var i=0; i<idcse_by_sem_sems.length; i++) {
1076: if (idcse_by_sem_sems[i] == valsem) {
1077: idsem = i;
1078: }
1079: }
1080: if (idsem != -1) {
1081: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
1082: if (idcse_by_sem_dept[idsem][i] == valdept) {
1083: iddept = i;
1084: }
1085: }
1086: }
1087: if (iddept != -1) {
1088: document.$formname.Number.options[0] = new Option('All','0',false,false);
1089: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
1090: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
1091: }
1092: }
1093: else {
1094: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1095: }
1096: }
1097: else {
1098: document.$formname.Number.options[0] = new Option("All","0",true,true);
1099: }
1100: }
1101: }
1102: else {
1103: if (selSemester == -1) {
1104: if (selDepartment > -1) {
1105: for (var i=0; i<idcse_by_yr_year.length; i++) {
1106: if (idcse_by_yr_year[i] == valyr) {
1107: idyr = i;
1108: }
1109: }
1110: if (idyr != -1) {
1111: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
1112: if (idcse_by_yr_dept[idyr][i] == valdept) {
1113: iddept = i;
1114: }
1115: }
1116: }
1117: if (iddept != -1) {
1118: document.$formname.Number.options[0] = new Option('All','0',false,false);
1119: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
1120: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
1121: }
1122: }
1123: else {
1124: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1125: }
1126: }
1127: else {
1128: document.$formname.Number.options[0] = new Option("All","0",true,true);
1129: }
1130: }
1131: else {
1132: if (selDepartment > -1) {
1133: for (var k=0; k<idyears.length; k++) {
1134: if (idyears[k] == valyr) {
1135: idyr = k;
1136: }
1137: }
1138: if (idyr != -1) {
1139: for (var k=0; k<idsems[idyr].length; k++) {
1140: if (idsems[idyr][k] == valsem) {
1141: idsem = k;
1142: }
1143: }
1144: }
1145: if (idsem != -1) {
1146: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
1147: if (idcodes[idyr][idsem][k] == valdept) {
1148: iddept = k;
1149: }
1150: }
1151: }
1152: if (iddept != -1) {
1153: document.$formname.Number.options[0] = new Option('All','0',false,false);
1154: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
1155: var display = idcourses[idyr][idsem][iddept][i];
1156: if (longtitles[3] == 1) {
1157: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
1158: display = idcourseslongs[idyr][idsem][iddept][i]
1159: }
1160: }
1161: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
1162: }
1163: }
1164: else {
1165: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1166: }
1167: }
1168: else {
1169: document.$formname.Number.options[0] = new Option('All','0',true,true);
1170: }
1171: }
1172: document.$formname.Number.selectedIndex = 0
1173: }
1174: }
1175: END
1176: return $output;
1177: }
1178:
1179: sub autoenroll_info {
1180: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1181: my $autoenrolldates = &mt('Not enabled');
1182: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
1183: my ($autostart,$autoend);
1184: if ( defined($coursehash->{'internal.autostart'}) ) {
1185: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
1186: }
1187: if ( defined($coursehash->{'internal.autoend'}) ) {
1188: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
1189: }
1190: if ($coursehash->{'internal.autostart'} > $now) {
1191: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1192: $autoenrolldates = &mt('Not enabled');
1193: } else {
1194: my $valid_classes =
1195: &get_valid_classes($seclist,$xlist_items,$code,
1196: $owners,$cdom,$cnum);
1197: if ($valid_classes ne '') {
1198: $autoenrolldates = &mt('Not enabled<br />Starts: ').
1199: $autostart.'<br />'.$valid_classes; }
1200: }
1201: } else {
1202: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1203: $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
1204: } else {
1205: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1206: $code,$owners,$cdom,$cnum);
1207: if ($valid_classes ne '') {
1208: $autoenrolldates = &mt('Currently enabled<br />').
1209: $valid_classes;
1210: }
1211: }
1212: }
1213: }
1214: return $autoenrolldates;
1215: }
1216:
1217: sub user_is_known {
1218: my $known = 0;
1219: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
1220: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
1221: $known = 1;
1222: }
1223: return $known;
1224: }
1225:
1226: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>