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