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