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