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