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