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