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