Annotation of loncom/interface/coursecatalog.pm, revision 1.45
1.17 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
1.45 ! raeburn 4: # $Id: coursecatalog.pm,v 1.44 2008/09/23 20:31:09 raeburn Exp $
1.1 raeburn 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;
1.7 raeburn 35: use Apache::lonhtmlcommon;
1.1 raeburn 36: use Apache::lonnet;
37: use Apache::lonlocal;
1.6 raeburn 38: use Apache::courseclassifier;
1.1 raeburn 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: }
1.21 albertel 49: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.8 raeburn 50: my $lonidsdir=$r->dir_config('lonIDsDir');
1.21 albertel 51: if ($handle ne '') {
1.8 raeburn 52: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
53: }
1.1 raeburn 54: &Apache::lonacc::get_posted_cgi($r);
55: &Apache::lonlocal::get_language_handle($r);
1.38 raeburn 56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
57: ['sortby','showdom']);
1.28 raeburn 58:
59: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 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: }
1.7 raeburn 67: my $formname = 'coursecatalog';
1.28 raeburn 68: if ($env{'form.showdom'} ne '') {
69: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
70: $codedom = $env{'form.showdom'};
71: }
72: }
1.20 albertel 73: my $domdesc = &Apache::lonnet::domain($codedom,'description');
1.7 raeburn 74: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.35 raeburn 75:
76: my %domconfig =
77: &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
1.36 raeburn 78: my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
1.35 raeburn 79: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
80: $cathash = $domconfig{'coursecategories'}{'cats'};
81: } else {
82: $cathash = {};
83: }
1.36 raeburn 84: my $subcats;
85: if ($env{'form.withsubcats'}) {
86: $subcats = \%subcathash;
87: }
1.35 raeburn 88: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
1.36 raeburn 89: \%idx,\@jsarray,$subcats);
1.8 raeburn 90: if ($env{'form.coursenum'} ne '' && &user_is_known()) {
1.35 raeburn 91: &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
1.7 raeburn 92: } else {
1.36 raeburn 93: my ($catlinks,$has_subcats) = &category_breadcrumbs($codedom,@cats);
1.28 raeburn 94: my $catjs = <<"ENDSCRIPT";
95:
96: function setCatDepth(depth) {
97: document.coursecats.catalog_maxdepth.value = depth;
1.36 raeburn 98: if (depth == '') {
99: document.coursecats.currcat_0.value = '';
100: }
1.28 raeburn 101: document.coursecats.submit();
102: return;
103: }
104:
1.33 raeburn 105: function changeSort(caller) {
106: document.$formname.sortby.value = caller;
107: document.$formname.submit();
108: }
1.40 raeburn 109:
1.33 raeburn 110: function setCourseId(caller) {
111: document.$formname.coursenum.value = caller;
112: document.$formname.submit();
1.37 raeburn 113: }
114:
115: ENDSCRIPT
1.41 raeburn 116: $catjs .= &courselink_javascript();
1.28 raeburn 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 '') {
1.33 raeburn 129: $r->print('<form name="'.$formname.
130: '" method="post" action="/adm/coursecatalog">'.
1.36 raeburn 131: &additional_filters($codedom,$has_subcats)."\n");
1.33 raeburn 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') {
1.36 raeburn 147: $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
1.28 raeburn 148: }
1.18 raeburn 149: }
1.7 raeburn 150: }
1.32 raeburn 151: $r->print('<br />'.&Apache::loncommon::end_page());
1.7 raeburn 152: return OK;
153: }
154:
155: sub course_details {
1.35 raeburn 156: my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
1.7 raeburn 157: my $output;
158: my %add_entries = (topmargin => "0",
159: marginheight => "0",);
1.40 raeburn 160: my $js = '<script type="text/javascript">'."\n".
1.41 raeburn 161: &courselink_javascript().'</script>'."\n";
1.7 raeburn 162: my $start_page =
1.40 raeburn 163: &Apache::loncommon::start_page('Course Catalog',$js,
1.7 raeburn 164: {
165: 'add_entries' => \%add_entries,
166: 'no_inline_link' => 1,});
167: $r->print($start_page);
1.19 raeburn 168: if ($env{'form.numtitles'} > 0) {
169: &Apache::lonhtmlcommon::add_breadcrumb
170: ({href=>"/adm/coursecatalog",
171: text=>"Select courses"});
172: }
1.7 raeburn 173: &Apache::lonhtmlcommon::add_breadcrumb
1.19 raeburn 174: ({href=>"javascript:document.$formname.submit()",
1.7 raeburn 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 />'.
1.35 raeburn 179: &print_course_listing($codedom,undef,$trails,$allitems).
180: '<br /><br />');
1.40 raeburn 181: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
182: '<a href = "javascript:document.coursecatalog.submit()">'.
1.7 raeburn 183: &mt('Back to course listing').'</a>'.
1.41 raeburn 184: &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
185: 'showdetails','courseid']).'</form>');
1.40 raeburn 186: return;
187: }
188:
1.41 raeburn 189: sub courselink_javascript {
1.40 raeburn 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: }
1.41 raeburn 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();
1.40 raeburn 210: }
211:
212: END
1.7 raeburn 213: }
214:
1.40 raeburn 215:
1.28 raeburn 216: sub instcode_course_selector {
217: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
1.1 raeburn 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 = ();
1.6 raeburn 226: my %by_year;
227: my %by_sem;
228: my %by_dept;
229: my %cat_items;
1.1 raeburn 230: my $caller = 'global';
231: my $format_reply;
232: my $totcodes = 0;
233: my $jscript = '';
1.6 raeburn 234: my ($numtitles,$lasttitle);
1.30 raeburn 235: my %add_entries = (topmargin => "0",
236: marginheight => "0",);
237: my $js;
1.22 raeburn 238: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
1.1 raeburn 239: if ($totcodes > 0) {
1.6 raeburn 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;
1.1 raeburn 251: }
1.18 raeburn 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 .= '
1.1 raeburn 267: function setElements() {
268: ';
1.18 raeburn 269: for (my $i=0; $i<@codetitles-1; $i++) {
270: if ($env{'form.'.$codetitles[$i]} != -1) {
271: $jscript .= '
1.1 raeburn 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: ';
1.18 raeburn 278: }
279: }
280: $jscript .= ' courseSet()'."\n";
281: if ($env{'form.'.$codetitles[-1]} != -1) {
282: $jscript .= '
1.6 raeburn 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: ';
1.18 raeburn 289: }
290: $jscript .= '}';
291: }
1.6 raeburn 292: }
1.32 raeburn 293: }
1.30 raeburn 294: $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
295: '</script>';
1.18 raeburn 296: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
1.7 raeburn 297: $add_entries{'onLoad'} = 'setElements()';
298: }
1.28 raeburn 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">'.
1.32 raeburn 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" />'.
1.33 raeburn 305: &additional_filters($codedom));
1.1 raeburn 306: if ($numtitles > 0) {
1.32 raeburn 307: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
1.6 raeburn 308: $r->print('<table><tr>');
309: for (my $k=0; $k<$lasttitle-1; $k++) {
1.26 raeburn 310: my (@items,@unsorted);
311: if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
312: @unsorted = @{$cat_items{$codetitles[$k]}};
313: }
1.6 raeburn 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: }
1.1 raeburn 320: } else {
1.6 raeburn 321: @longitems = @items;
1.1 raeburn 322: }
1.6 raeburn 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++) {
1.1 raeburn 327: if ($longitems[$i] eq '') {
328: $longitems[$i] = $items[$i];
329: }
1.6 raeburn 330: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
1.1 raeburn 331: }
1.6 raeburn 332: $r->print('</select></td>');
1.1 raeburn 333: }
1.6 raeburn 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".
1.32 raeburn 338: '</td></tr></table>'."\n");
1.1 raeburn 339: if ($numtitles > 4) {
1.6 raeburn 340: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
341: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
1.1 raeburn 342: }
1.18 raeburn 343: $r->print('<br />');
344: }
1.33 raeburn 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.
1.37 raeburn 352: '" /></form><br /><br />');
1.5 raeburn 353: } else {
1.45 ! raeburn 354: $js = '<script type"text/javascript">'."\n$catjs\n".'</script>';
1.30 raeburn 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>');
1.1 raeburn 362: }
1.18 raeburn 363: return $numtitles;
1.1 raeburn 364: }
365:
1.28 raeburn 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: }
1.34 raeburn 391: $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
392: '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
1.28 raeburn 393: &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
1.34 raeburn 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>');
1.28 raeburn 397: return;
398: }
399:
400: sub category_breadcrumbs {
1.35 raeburn 401: my ($dom,@cats) = @_;
1.44 raeburn 402: my $crumbsymbol = ' ▶ ';
1.33 raeburn 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.'" />';
1.28 raeburn 405: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
1.36 raeburn 406: my $has_subcats;
1.28 raeburn 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: }
1.44 raeburn 417: $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>'.$crumbsymbol.'</td>';
1.28 raeburn 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)').
1.34 raeburn 424: '<input type="hidden" name="currcat_0" value="instcode::0" />';
1.28 raeburn 425: $env{'form.currcat_0'} = 'instcode::0';
426: } else {
1.36 raeburn 427: $has_subcats = 1;
1.28 raeburn 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: }
1.36 raeburn 434: $catlinks .= '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
1.28 raeburn 435: }
436: for (my $i=0; $i<@{$cats[0]}; $i++) {
437: my $name = $cats[0][$i];
438: my $item = &escape($name).'::0';
1.36 raeburn 439: $catlinks .= '<option value="'.$item.'">';
1.28 raeburn 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".
1.33 raeburn 448: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
1.28 raeburn 449: }
450: } else {
451: $catlinks .= &mt('Official courses (with institutional codes)').
1.34 raeburn 452: '<input type="hidden" name="currcat_0" value="instcode::0" />';
1.28 raeburn 453: $env{'form.currcat_0'} = 'instcode::0';
454: }
455: } else {
1.29 raeburn 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: }
1.28 raeburn 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') {
1.36 raeburn 470: $has_subcats = 1;
471: my $selstr;
1.28 raeburn 472: $catlinks .= ': <select name="currcat_'.$deeper.'">'.
1.36 raeburn 473: '<option value="" selected="selected">'.
474: &mt('Select').'</option>';
1.28 raeburn 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".
1.33 raeburn 481: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
1.28 raeburn 482: }
483: }
484: $catlinks .= $currcat_str.'</td></tr></table></td>';
1.36 raeburn 485: return ($catlinks,$has_subcats);
1.28 raeburn 486: }
487:
1.33 raeburn 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 {
1.36 raeburn 503: my ($codedom,$has_subcats) = @_;
1.33 raeburn 504: my $output = '<table>';
1.36 raeburn 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.'/>'.
1.38 raeburn 524: &mt('Include subcategories within "[_1]"',
525: &unescape($catname)).'</label></td></tr>';
1.36 raeburn 526: }
527: }
1.33 raeburn 528: my $show_selfenroll_status;
529: if ($env{'form.showselfenroll'}) {
530: $show_selfenroll_status = 'checked="checked" ';
531: }
1.36 raeburn 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>';
1.33 raeburn 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" '.
1.36 raeburn 549: $showdetails_status.'/>'.
1.33 raeburn 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: }
1.36 raeburn 557: $output .= '</table><br />';
1.33 raeburn 558: return $output;
559: }
560:
1.16 raeburn 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: }
1.7 raeburn 573:
1.6 raeburn 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:
1.28 raeburn 657: sub search_official_courselist {
1.18 raeburn 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: }
1.7 raeburn 675: }
1.18 raeburn 676: $instcode .= '$';
677: } else {
678: $instcode = '.';
1.7 raeburn 679: }
680: }
1.32 raeburn 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');
1.7 raeburn 689: return %courses;
690: }
691:
1.28 raeburn 692: sub search_courselist {
1.36 raeburn 693: my ($domain,$subcats) = @_;
1.28 raeburn 694: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
695: my $filter = $env{'form.currcat_'.$cat_maxdepth};
1.29 raeburn 696: if (($filter eq '') && ($cat_maxdepth > 0)) {
697: my $shallower = $cat_maxdepth - 1;
698: $filter = $env{'form.currcat_'.$shallower};
699: }
1.28 raeburn 700: my %courses;
1.36 raeburn 701: my $filterstr;
1.28 raeburn 702: if ($filter ne '') {
1.36 raeburn 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: }
1.32 raeburn 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'},
1.36 raeburn 726: $filterstr,$showhidden,'coursecatalog');
1.28 raeburn 727: }
728: return %courses;
729: }
1.6 raeburn 730:
1.1 raeburn 731: sub print_course_listing {
1.36 raeburn 732: my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
1.1 raeburn 733: my $output;
1.7 raeburn 734: my %courses;
1.15 raeburn 735: my $knownuser = &user_is_known();
1.16 raeburn 736: my $details = $env{'form.coursenum'};
737: if (&user_is_dc($domain)) {
738: if ($env{'form.showdetails'}) {
739: $details = 1;
740: }
741: }
1.7 raeburn 742: if ($env{'form.coursenum'} ne '') {
743: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
744: $env{'form.coursenum'},
1.33 raeburn 745: undef,undef,'.',1);
1.7 raeburn 746: if (keys(%courses) == 0) {
747: $output .= &mt('The courseID provided does not match a course in this domain.');
748: return $output;
749: }
1.6 raeburn 750: } else {
1.28 raeburn 751: if ($env{'form.currcat_0'} eq 'instcode::0') {
752: %courses = &search_official_courselist($domain,$numtitles);
753: } else {
1.36 raeburn 754: %courses = &search_courselist($domain,$subcats);
1.28 raeburn 755: }
1.7 raeburn 756: if (keys(%courses) == 0) {
757: $output = &mt('No courses match the criteria you selected.');
758: return $output;
759: }
1.32 raeburn 760: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
1.31 bisitz 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 />';
1.8 raeburn 764: }
1.7 raeburn 765: }
1.27 raeburn 766: my $now = time;
767: my %domconfig =
768: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
1.35 raeburn 769: $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
1.41 raeburn 770: $output .= "\n".'<form name="linklaunch" method="post" action="">'.
1.40 raeburn 771: '<input type="hidden" name="backto" value="coursecatalog" />'.
1.41 raeburn 772: '<input type="hidden" name="courseid" value="" />'.
773: &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
1.15 raeburn 774: return $output;
775: }
776:
777: sub construct_data_table {
1.35 raeburn 778: my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails,
779: $allitems) = @_;
1.7 raeburn 780: my %sortname;
1.16 raeburn 781: if (($details eq '') || ($env{'form.showdetails'})) {
1.7 raeburn 782: $sortname{'Code'} = 'code';
1.35 raeburn 783: $sortname{'Categories'} = 'cats';
1.7 raeburn 784: $sortname{'Title'} = 'title';
1.22 raeburn 785: $sortname{'Owner(s)'} = 'owner';
1.7 raeburn 786: }
1.15 raeburn 787: my $output = &Apache::loncommon::start_data_table().
788: &Apache::loncommon::start_data_table_header_row();
1.35 raeburn 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)'));
1.15 raeburn 796: if (ref($usersections) eq 'HASH') {
797: $coltitles[1] = 'Your Section';
798: }
1.7 raeburn 799: foreach my $item (@coltitles) {
800: $output .= '<th>';
801: if (defined($sortname{$item})) {
802: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
1.24 raeburn 803: } elsif ($item eq 'Count') {
804: $output .= ' ';
1.7 raeburn 805: } else {
806: $output .= &mt($item);
807: }
808: $output .= '</th>';
1.1 raeburn 809: }
1.15 raeburn 810: if ($knownuser) {
811: if ($details) {
1.8 raeburn 812: $output .=
1.7 raeburn 813: '<th>'.&mt('Default Access Dates for Students').'</th>'.
814: '<th>'.&mt('Student Counts').'</th>'.
1.42 bisitz 815: '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
1.15 raeburn 816: } else {
1.27 raeburn 817: $output .= '<th>'.&mt('Details').'</th>';
1.8 raeburn 818: }
1.1 raeburn 819: }
1.27 raeburn 820: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
1.7 raeburn 821: &Apache::loncommon::end_data_table_header_row();
1.15 raeburn 822: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
823: $usersections);
1.7 raeburn 824: my %Sortby;
1.15 raeburn 825: foreach my $course (sort(keys(%{$courses}))) {
1.7 raeburn 826: if ($env{'form.sortby'} eq 'code') {
827: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
1.35 raeburn 828: } elsif ($env{'form.sortby'} eq 'cats') {
829: push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
1.7 raeburn 830: } elsif ($env{'form.sortby'} eq 'owner') {
1.22 raeburn 831: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
1.7 raeburn 832: } else {
1.25 raeburn 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);
1.7 raeburn 839: }
840: }
841: my @sorted_courses;
1.35 raeburn 842: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
843: ($env{'form.sortby'} eq 'cats')) {
1.7 raeburn 844: @sorted_courses = sort(keys(%Sortby));
1.6 raeburn 845: } else {
1.7 raeburn 846: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1.1 raeburn 847: }
1.24 raeburn 848: my $count = 1;
1.7 raeburn 849: foreach my $item (@sorted_courses) {
850: foreach my $course (@{$Sortby{$item}}) {
851: $output.=&Apache::loncommon::start_data_table_row();
1.35 raeburn 852: $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
853: \$count,$now,$course,$trails,$allitems);
1.7 raeburn 854: $output.=&Apache::loncommon::end_data_table_row();
855: }
1.1 raeburn 856: }
1.7 raeburn 857: $output .= &Apache::loncommon::end_data_table();
858: return $output;
859: }
860:
861: sub build_courseinfo_hash {
1.15 raeburn 862: my ($courses,$knownuser,$details,$usersections) = @_;
1.1 raeburn 863: my %courseinfo;
1.7 raeburn 864: my $now = time;
1.15 raeburn 865: foreach my $course (keys(%{$courses})) {
1.1 raeburn 866: my $descr;
1.22 raeburn 867: if (ref($courses->{$course}) eq 'HASH') {
868: $descr = $courses->{$course}{'description'};
1.1 raeburn 869: }
870: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
871: $cleandesc=~s/'/\\'/g;
1.10 raeburn 872: $cleandesc =~ s/^\s+//;
1.1 raeburn 873: my ($cdom,$cnum)=split(/\_/,$course);
1.39 raeburn 874: my ($instcode,$singleowner,$ttype,$selfenroll_types,
1.35 raeburn 875: $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
1.22 raeburn 876: if (ref($courses->{$course}) eq 'HASH') {
877: $descr = $courses->{$course}{'description'};
1.23 raeburn 878: $instcode = $courses->{$course}{'inst_code'};
1.22 raeburn 879: $singleowner = $courses->{$course}{'owner'};
880: $ttype = $courses->{$course}{'type'};
1.27 raeburn 881: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
882: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
883: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
1.35 raeburn 884: $categories = $courses->{$course}{'categories'};
1.22 raeburn 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;
1.1 raeburn 905: }
906: }
907: $courseinfo{$course}{'cdom'} = $cdom;
908: $courseinfo{$course}{'cnum'} = $cnum;
909: $courseinfo{$course}{'code'} = $instcode;
1.22 raeburn 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));
1.1 raeburn 917: $courseinfo{$course}{'title'} = $cleandesc;
1.22 raeburn 918: $courseinfo{$course}{'owner'} = $singleowner;
1.27 raeburn 919: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
920: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
921: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
1.35 raeburn 922: $courseinfo{$course}{'categories'} = $categories;
1.7 raeburn 923:
924: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
925: my @classids;
926: my @crosslistings;
1.15 raeburn 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: }
1.7 raeburn 934: $courseinfo{$course}{'seclist'} = $seclist;
1.15 raeburn 935: my ($xlist_items,$numxlist) =
936: &identify_sections($coursehash{'internal.crosslistings'});
1.7 raeburn 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;
1.15 raeburn 942: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
1.22 raeburn 943: ($knownuser && ($details == 1))) {
1.15 raeburn 944: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec);
945: $courseinfo{$course}{'autoenrollment'} =
946: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
1.22 raeburn 947: $instcode,\@owners,$cdom,$cnum);
1.15 raeburn 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) {
1.34 raeburn 958: $endaccess = &mt('No ending date');
1.15 raeburn 959: }
960: }
961: if ($startaccess) {
1.42 bisitz 962: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
1.7 raeburn 963: }
1.15 raeburn 964: if ($endaccess) {
1.42 bisitz 965: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
1.15 raeburn 966: }
1.34 raeburn 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) {
1.42 bisitz 986: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
1.34 raeburn 987: }
988: if ($selfenroll_end_access) {
1.42 bisitz 989: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
1.34 raeburn 990: }
991: }
992: }
993: }
1.15 raeburn 994: $courseinfo{$course}{'access'} = $accessdates;
1.1 raeburn 995: }
1.7 raeburn 996: if ($xlist_items eq '') {
997: $xlist_items = &mt('No');
1.1 raeburn 998: }
1.7 raeburn 999: $courseinfo{$course}{'xlist'} = $xlist_items;
1.1 raeburn 1000: }
1.7 raeburn 1001: return %courseinfo;
1.1 raeburn 1002: }
1003:
1.7 raeburn 1004: sub count_students {
1.15 raeburn 1005: my ($cdom,$cnum,$numsec) = @_;
1.1 raeburn 1006: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.7 raeburn 1007: my %student_count = (
1008: Active => 0,
1009: Future => 0,
1010: Expired => 0,
1011: );
1.1 raeburn 1012: my %idx;
1013: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1.4 albertel 1014: my %status_title = &Apache::lonlocal::texthash(
1.1 raeburn 1015: Expired => 'Previous access',
1016: Active => 'Current access',
1017: Future => 'Future access',
1018: );
1.7 raeburn 1019:
1.4 albertel 1020: while (my ($student,$data) = each(%$classlist)) {
1.1 raeburn 1021: $student_count{$data->[$idx{'status'}]} ++;
1022: }
1.7 raeburn 1023:
1.43 bisitz 1024: my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'<br />';
1.7 raeburn 1025: foreach my $status ('Active','Future') {
1.43 bisitz 1026: $countslist .= '<span class="LC_nobreak">'.$status_title{$status}.': '.
1027: $student_count{$status}.'</span><br />';
1.1 raeburn 1028: }
1.7 raeburn 1029: return $countslist;
1030: }
1031:
1032: sub courseinfo_row {
1.35 raeburn 1033: my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_;
1.7 raeburn 1034: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1.35 raeburn 1035: $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
1.7 raeburn 1036: if (ref($info) eq 'HASH') {
1037: $cdom = $info->{'cdom'};
1038: $cnum = $info->{'cnum'};
1039: $title = $info->{'title'};
1.22 raeburn 1040: $ownerlast = $info->{'ownerlastnames'};
1.7 raeburn 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'};
1.35 raeburn 1049: $categories = $info->{'categories'};
1.7 raeburn 1050: } else {
1051: $output = '<td colspan="8">'.&mt('No information available for [_1].',
1052: $code).'</td>';
1053: return $output;
1.2 raeburn 1054: }
1.35 raeburn 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>'.
1.7 raeburn 1073: '<td>'.$xlist_items.'</td>'.
1074: '<td>'.$title.' <font size="-2">';
1.2 raeburn 1075: if ($showsyllabus) {
1.40 raeburn 1076: $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.&mt('Syllabus').'</a>';
1.7 raeburn 1077: } else {
1078: $output .= ' ';
1.2 raeburn 1079: }
1080: $output .= '</font></td>'.
1.7 raeburn 1081: '<td>'.$ownerlast.'</td>';
1.15 raeburn 1082: if ($knownuser) {
1083: if ($details) {
1.8 raeburn 1084: $output .=
1.7 raeburn 1085: '<td>'.$accessdates.'</td>'.
1086: '<td>'.$counts.'</td>'.
1087: '<td>'.$autoenrollment.'</td>';
1.15 raeburn 1088: } else {
1089: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1.8 raeburn 1090: }
1.7 raeburn 1091: }
1.27 raeburn 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 {
1.41 raeburn 1100: $output .= '<td><a href="javascript:ToSelfenroll('."'$course'".')">'.&mt('Enroll in course').'</a></td>';
1.27 raeburn 1101: }
1102: $selfenroll = 1;
1103: }
1104: }
1105: if (!$selfenroll) {
1106: $output .= '<td> </td>';
1107: }
1.24 raeburn 1108: $$countref ++;
1.1 raeburn 1109: return $output;
1110: }
1111:
1112: sub identify_sections {
1113: my ($seclist) = @_;
1114: my @secnums;
1115: if ($seclist =~ /,/) {
1.4 albertel 1116: my @sections = split(/,/,$seclist);
1.1 raeburn 1117: foreach my $sec (@sections) {
1118: $sec =~ s/:[^:]*$//;
1119: push(@secnums,$sec);
1120: }
1121: } else {
1122: if ($seclist =~ m/^([^:]+):/) {
1123: my $sec = $1;
1.4 albertel 1124: if (!grep(/^\Q$sec\E$/,@secnums)) {
1125: push(@secnums,$sec);
1.1 raeburn 1126: }
1127: }
1128: }
1129: @secnums = sort {$a <=> $b} @secnums;
1.39 raeburn 1130: $seclist = join(', ',@secnums);
1.15 raeburn 1131: my $numsec = @secnums;
1132: return ($seclist,$numsec);
1.1 raeburn 1133: }
1134:
1.2 raeburn 1135: sub get_valid_classes {
1.22 raeburn 1136: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1.2 raeburn 1137: my $response;
1138: my %validations;
1139: @{$validations{'sections'}} = ();
1140: @{$validations{'xlists'}} = ();
1141: my $totalitems = 0;
1142: if ($seclist) {
1.13 raeburn 1143: foreach my $sec (split(/, /,$seclist)) {
1.2 raeburn 1144: my $class = $crscode.$sec;
1.22 raeburn 1145: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3 albertel 1146: $class) eq 'ok') {
1.2 raeburn 1147: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1.4 albertel 1148: push(@{$validations{'sections'}},$sec);
1.2 raeburn 1149: $totalitems ++;
1150: }
1151: }
1152: }
1153: }
1154: if ($xlist_items) {
1.13 raeburn 1155: foreach my $item (split(/, /,$xlist_items)) {
1.22 raeburn 1156: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3 albertel 1157: $item) eq 'ok') {
1.2 raeburn 1158: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1.4 albertel 1159: push(@{$validations{'xlists'}},$item);
1.2 raeburn 1160: $totalitems ++;
1161: }
1162: }
1163: }
1164: }
1165: if ($totalitems > 0) {
1166: if (@{$validations{'sections'}}) {
1.42 bisitz 1167: $response = &mt('Sections:').' '.
1.14 raeburn 1168: join(', ',@{$validations{'sections'}}).'<br />';
1.2 raeburn 1169: }
1170: if (@{$validations{'xlists'}}) {
1.42 bisitz 1171: $response .= &mt('Courses:').' '.
1.14 raeburn 1172: join(', ',@{$validations{'xlists'}});
1.2 raeburn 1173: }
1174: }
1175: return $response;
1176: }
1177:
1.6 raeburn 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 {
1.9 raeburn 1270: if (selDepartment > -1) {
1271: for (var k=0; k<idyears.length; k++) {
1272: if (idyears[k] == valyr) {
1273: idyr = k;
1274: }
1.6 raeburn 1275: }
1.9 raeburn 1276: if (idyr != -1) {
1277: for (var k=0; k<idsems[idyr].length; k++) {
1278: if (idsems[idyr][k] == valsem) {
1279: idsem = k;
1280: }
1.6 raeburn 1281: }
1282: }
1.9 raeburn 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: }
1.6 raeburn 1288: }
1289: }
1.9 raeburn 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: }
1.6 raeburn 1298: }
1.9 raeburn 1299: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
1.6 raeburn 1300: }
1.9 raeburn 1301: }
1302: else {
1303: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1.6 raeburn 1304: }
1.9 raeburn 1305: }
1.6 raeburn 1306: else {
1.9 raeburn 1307: document.$formname.Number.options[0] = new Option('All','0',true,true);
1.6 raeburn 1308: }
1309: }
1310: document.$formname.Number.selectedIndex = 0
1311: }
1312: }
1313: END
1314: return $output;
1315: }
1.1 raeburn 1316:
1.7 raeburn 1317: sub autoenroll_info {
1.22 raeburn 1318: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1.7 raeburn 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,
1.22 raeburn 1334: $owners,$cdom,$cnum);
1.7 raeburn 1335: if ($valid_classes ne '') {
1.42 bisitz 1336: $autoenrolldates = &mt('Not enabled').'<br />'
1337: .&mt('Starts: [_1]',$autostart)
1338: .'<br />'.$valid_classes;
1339: }
1.7 raeburn 1340: }
1341: } else {
1342: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1.42 bisitz 1343: $autoenrolldates = &mt('Not enabled').'<br />'
1344: .&mt('Ended: [_1]',$autoend);
1.7 raeburn 1345: } else {
1346: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1.22 raeburn 1347: $code,$owners,$cdom,$cnum);
1.7 raeburn 1348: if ($valid_classes ne '') {
1.42 bisitz 1349: $autoenrolldates = &mt('Currently enabled').'<br />'.
1.7 raeburn 1350: $valid_classes;
1351: }
1352: }
1353: }
1354: }
1355: return $autoenrolldates;
1356: }
1357:
1.8 raeburn 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:
1.1 raeburn 1367: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>