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