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