File:
[LON-CAPA] /
loncom /
interface /
coursecatalog.pm
Revision
1.7:
download - view:
text,
annotated -
select for diffs
Mon Oct 16 19:39:51 2006 UTC (17 years, 7 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Refactored so access dates, student counts and auto-enrollment status are additional details which are shown on a second page, and only for a single courseID. Search based on select box choices uses lonnet::auto_instcode_defaults() to construct appropriate regular expressions to pass to courseiddump() from selections made. Breadcrumbs added, now there are multiple pages.
1: #
2: # Copyright Michigan State University Board of Trustees
3: #
4: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
5: #
6: # LON-CAPA is free software; you can redistribute it and/or modify
7: # it under the terms of the GNU General Public License as published by
8: # the Free Software Foundation; either version 2 of the License, or
9: # (at your option) any later version.
10: #
11: # LON-CAPA is distributed in the hope that it will be useful,
12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: # GNU General Public License for more details.
15: #
16: # You should have received a copy of the GNU General Public License
17: # along with LON-CAPA; if not, write to the Free Software
18: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: #
20: # /home/httpd/html/adm/gpl.txt
21: #
22: # http://www.lon-capa.org/
23: #
24:
25: package Apache::coursecatalog;
26:
27: use strict;
28: use lib qw(/home/httpd/lib/perl);
29: use Apache::Constants qw(:common);
30: use Apache::loncommon;
31: use Apache::lonhtmlcommon;
32: use Apache::lonnet;
33: use Apache::lonlocal;
34: use Apache::courseclassifier;
35: use Apache::lonacc;
36: use LONCAPA;
37:
38: sub handler {
39: my ($r) = @_;
40: &Apache::loncommon::content_type($r,'text/html');
41: $r->send_http_header;
42: if ($r->header_only) {
43: return OK;
44: }
45: &Apache::lonacc::get_posted_cgi($r);
46: &Apache::lonlocal::get_language_handle($r);
47: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
48: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
49: my $formname = 'coursecatalog';
50: my $domdesc = $Apache::lonnet::domaindescription{$codedom};
51:
52: &Apache::lonhtmlcommon::clear_breadcrumbs();
53: if ($env{'form.coursenum'} ne '') {
54: &course_details($r,$codedom,$formname,$domdesc);
55: } else {
56: &course_selector($r,$codedom,$formname,$domdesc);
57: if ($env{'form.state'} eq 'listing') {
58: $r->print('<br /><br />'.&print_course_listing($codedom).'<br />');
59: }
60: }
61: $r->print(&Apache::loncommon::end_page());
62: return OK;
63: }
64:
65: sub course_details {
66: my ($r,$codedom,$formname,$domdesc) = @_;
67: my $output;
68: my %add_entries = (topmargin => "0",
69: marginheight => "0",);
70: my $start_page =
71: &Apache::loncommon::start_page('Course Catalog','',
72: {
73: 'add_entries' => \%add_entries,
74: 'no_inline_link' => 1,});
75: $r->print($start_page);
76: &Apache::lonhtmlcommon::add_breadcrumb
77: ({href=>"/adm/coursecatalog",
78: text=>"Select courses"},
79: {href=>"javascript:document.$formname.submit()",
80: text=>"Course listing"},
81: {text=>"Course details"});
82: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
83: $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
84: '<form name="coursecatalog" method="post">'.
85: &print_course_listing($codedom).'<br /><br />');
86: $r->print('<a href = "javascript:document.coursecatalog.submit()">'.
87: &mt('Back to course listing').'</a>'.
88: '<input type="hidden" name="sortby" value="'.
89: $env{'form.sortby'}.'" />'.
90: '<input type="hidden" name="state" value="listing" /></form>');
91: }
92:
93: sub course_selector {
94: my ($r,$codedom,$formname,$domdesc) = @_;
95: my %coursecodes = ();
96: my %codes = ();
97: my @codetitles = ();
98: my %cat_titles = ();
99: my %cat_order = ();
100: my %idlist = ();
101: my %idnums = ();
102: my %idlist_titles = ();
103: my %by_year;
104: my %by_sem;
105: my %by_dept;
106: my %cat_items;
107: my $caller = 'global';
108: my $format_reply;
109: my $totcodes = 0;
110: my $jscript = '';
111: my ($numtitles,$lasttitle);
112: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
113: if ($totcodes > 0) {
114: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
115: if ($format_reply eq 'ok') {
116: my $numtypes = @codetitles;
117: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
118: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
119: my $longtitles_str = join('","',@{$longtitles});
120: my $allidlist = $idlist{$codetitles[0]};
121: $numtitles = @codetitles;
122: $lasttitle = $numtitles;
123: if ($numtitles > 4) {
124: $lasttitle = 4;
125: }
126: my @data = ('top');
127: for (my $k=0; $k<$lasttitle; $k++) {
128: my $cat = $codetitles[$k];
129: my $level = 1;
130: $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept); }
131: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
132: $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
133: }
134: if ($env{'form.state'} eq 'listing') {
135: $jscript .= '
136: function setElements() {
137: ';
138: for (my $i=0; $i<@codetitles-1; $i++) {
139: if ($env{'form.'.$codetitles[$i]} != -1) {
140: $jscript .= '
141: for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
142: if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
143: document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
144: }
145: }
146: ';
147: }
148: }
149: $jscript .= ' courseSet()'."\n";
150: if ($env{'form.'.$codetitles[-1]} != -1) {
151: $jscript .= '
152: for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
153: if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
154: document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
155: }
156: }
157: ';
158: }
159: $jscript .= '}';
160: $jscript .= qq|
161: function changeSort(caller) {
162: document.$formname.sortby.value = caller;
163: document.$formname.submit();
164: }
165: function setCourseId(caller) {
166: document.$formname.coursenum.value = caller;
167: document.$formname.submit();
168: }\n|;
169: }
170: my $js = '<script type"text/javascript">'."\n$jscript\n".
171: '</script>';
172: my %add_entries = (topmargin => "0",
173: marginheight => "0",);
174: if ($env{'form.state'} eq 'listing') {
175: $add_entries{'onLoad'} = 'setElements()';
176: }
177: my $start_page =
178: &Apache::loncommon::start_page('Course Catalog',$js,
179: {
180: 'add_entries' => \%add_entries,
181: 'no_inline_link' => 1,});
182: $r->print($start_page);
183: if ($env{'form.state'} eq 'listing') {
184: &Apache::lonhtmlcommon::add_breadcrumb
185: ({href=>"/adm/coursecatalog",
186: text=>"Select courses"},
187: {text=>"Course listing"});
188: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
189: } else {
190: &Apache::lonhtmlcommon::add_breadcrumb
191: ({href=>"/adm/coursecatalog",
192: text=>"Select courses"});
193: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
194: }
195: $r->print('<h3>'.&mt('Display information about official [_1] classes for which LON-CAPA courses have been created:',$domdesc).'</h3>');
196: $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
197: $r->print('<form name="coursecatalog" method="post">');
198: if ($numtitles > 0) {
199: $r->print('<table><tr>');
200: for (my $k=0; $k<$lasttitle-1; $k++) {
201: my @unsorted = @{$cat_items{$codetitles[$k]}};
202: my @items;
203: &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
204: my @longitems;
205: if (defined($cat_titles{$codetitles[$k]})) {
206: foreach my $item (@items) {
207: push(@longitems,$cat_titles{$codetitles[$k]}{$item});
208: }
209: } else {
210: @longitems = @items;
211: }
212: $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
213: '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
214: $r->print('>'."\n".'<option value="0" />All'."\n");
215: for (my $i=0; $i<@items; $i++) {
216: if ($longitems[$i] eq '') {
217: $longitems[$i] = $items[$i];
218: }
219: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
220: }
221: $r->print('</select></td>');
222: }
223: $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
224: '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
225: '<option value="0">All'."\n".
226: '</option>'."\n".'</select>'."\n".
227: '</td>'
228: );
229: $r->print('</tr></table>');
230: if ($numtitles > 4) {
231: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
232: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
233: }
234: }
235: $r->print('<br /><input type="hidden" name="coursenum" value="" /><input type="hidden" name="state" value="listing" /><input type="hidden" name="sortby" value="" /><input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" /></form>');
236: } else {
237: $r->print(&Apache::loncommon::start_page('Course Catalog','',
238: {
239: 'no_inline_link' => 1,}));
240: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc));
241: }
242: return;
243: }
244:
245:
246: sub recurse_options {
247: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
248: if (ref($currlist) eq 'HASH') {
249: $level ++;
250: foreach my $key (sort(keys(%{$currlist}))) {
251: $$data[$level-1]= $key;
252: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
253: }
254: } else {
255: $level --;
256: my @contents = split(/","/,$currlist);
257: foreach my $item (@contents) {
258: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
259: push(@{$cat_options->{$cat}},$item);
260: }
261: if ($level == 3) {
262: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
263: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
264: }
265: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
266: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
267: }
268: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
269: push(@{$by_dept->{$currkey}},$item);
270: }
271:
272: }
273: }
274: }
275: return $level;
276: }
277:
278: sub build_javascript {
279: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
280: my @unsorted = keys(%{$by_year});
281: my @sorted_yrs;
282: &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
283: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
284: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
285: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
286: for (my $i=0; $i<@sorted_yrs; $i++) {
287: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
288: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
289: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
290: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
291: my @sorted_depts;
292: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
293: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
294: for (my $j=0; $j<@sorted_depts; $j++) {
295: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
296: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
297: }
298: }
299: }
300: @unsorted = keys(%{$by_sem});
301: my @sorted_sems;
302: &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
303: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
304: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
305: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
306: for (my $i=0; $i<@sorted_sems; $i++) {
307: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
308: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
309: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
310: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
311: my @sorted_depts;
312: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
313: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
314: for (my $j=0; $j<@sorted_depts; $j++) {
315: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
316: }
317: }
318: }
319: @unsorted = keys(%{$by_dept});
320: my @sorted_deps;
321: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
322: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
323: for (my $k=0; $k<@sorted_deps; $k++) {
324: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
325: }
326: return $output;
327: }
328:
329: sub search_courselist {
330: my ($domain) = @_;
331: my ($instcode,%codedefaults,@code_order);
332: my $defaults_result =
333: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
334: \@code_order);
335: if ($defaults_result eq 'ok') {
336: $instcode ='^';
337: foreach my $item (@code_order) {
338: if ($env{'form.'.$item} eq '0' ) {
339: $instcode .= $codedefaults{$item};
340: } else {
341: $instcode .= $env{'form.'.$item};
342: }
343: }
344: $instcode .= '$';
345: } else {
346: $instcode = '.';
347: }
348: my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
349: undef,undef,'Course',1);
350: return %courses;
351: }
352:
353:
354: sub print_course_listing {
355: my ($domain) = @_;
356: my $output;
357: my %courses;
358: if ($env{'form.coursenum'} ne '') {
359: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
360: $env{'form.coursenum'},
361: undef,undef,'Course');
362: if (keys(%courses) == 0) {
363: $output .= &mt('The courseID provided does not match a course in this domain.');
364: return $output;
365: }
366: } else {
367: %courses = &search_courselist($domain);
368: if (keys(%courses) == 0) {
369: $output = &mt('No courses match the criteria you selected.');
370: return $output;
371: }
372: $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 />');
373: }
374: $output .= &Apache::loncommon::start_data_table().
375: &Apache::loncommon::start_data_table_header_row();
376: my @coltitles = ('Code','Sections','Crosslisted','Title','Owner');
377: my %sortname;
378: if ($env{'form.coursenum'} eq '') {
379: $sortname{'Code'} = 'code';
380: $sortname{'Title'} = 'title';
381: $sortname{'Owner'} = 'owner';
382: }
383: foreach my $item (@coltitles) {
384: $output .= '<th>';
385: if (defined($sortname{$item})) {
386: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
387: } else {
388: $output .= &mt($item);
389: }
390: $output .= '</th>';
391: }
392: if ($env{'form.coursenum'} eq '') {
393: $output .= '<th> </th>';
394: } else {
395: $output .=
396: '<th>'.&mt('Default Access Dates for Students').'</th>'.
397: '<th>'.&mt('Student Counts').'</th>'.
398: '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
399: }
400: &Apache::loncommon::end_data_table_header_row();
401: my %courseinfo = &build_courseinfo_hash(%courses);
402: my %Sortby;
403: foreach my $course (sort(keys(%courses))) {
404: if ($env{'form.sortby'} eq 'code') {
405: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
406: } elsif ($env{'form.sortby'} eq 'owner') {
407: push(@{$Sortby{$courseinfo{$course}{'ownerlastname'}}},$course);
408: } else {
409: push(@{$Sortby{$courseinfo{$course}{'title'}}},$course);
410: }
411: }
412: my @sorted_courses;
413: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {
414: @sorted_courses = sort(keys(%Sortby));
415: } else {
416: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
417: }
418: foreach my $item (@sorted_courses) {
419: foreach my $course (@{$Sortby{$item}}) {
420: $output.=&Apache::loncommon::start_data_table_row();
421: $output.=&courseinfo_row($courseinfo{$course});
422: $output.=&Apache::loncommon::end_data_table_row();
423: }
424: }
425: $output .= &Apache::loncommon::end_data_table();
426: my $echo = &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby']);
427: $output .= $echo;
428: return $output;
429: }
430:
431: sub build_courseinfo_hash {
432: my (%courses) = @_;
433: my %courseinfo;
434: my $now = time;
435: foreach my $course (keys(%courses)) {
436: my $descr;
437: if ($courses{$course} =~ m/^([^:]*):/i) {
438: $descr = &unescape($1);
439: } else {
440: $descr = &unescape($courses{$course});
441: }
442: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
443: $cleandesc=~s/'/\\'/g;
444: my ($cdom,$cnum)=split(/\_/,$course);
445:
446: my ($desc,$instcode,$owner,$ttype) = split(/:/,$courses{$course});
447: $owner = &unescape($owner);
448: my ($ownername,$ownerdom);
449: if ($owner =~ /:/) {
450: ($ownername,$ownerdom) = split(/:/,$owner);
451: } else {
452: $ownername = $owner;
453: if ($owner ne '') {
454: $ownerdom = $cdom;
455: }
456: }
457: my %ownernames;
458: if ($ownername ne '' && $ownerdom ne '') {
459: %ownernames = &Apache::loncommon::getnames($ownername,$ownerdom);
460: }
461: $courseinfo{$course}{'cdom'} = $cdom;
462: $courseinfo{$course}{'cnum'} = $cnum;
463: $courseinfo{$course}{'code'} = $instcode;
464: $courseinfo{$course}{'ownerlastname'} = $ownernames{'lastname'};
465: $courseinfo{$course}{'title'} = $cleandesc;
466: $courseinfo{$course}{'owner'} = $owner;
467:
468: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
469: my @classids;
470: my @crosslistings;
471: my $seclist = &identify_sections($coursehash{'internal.sectionnums'});
472: $courseinfo{$course}{'seclist'} = $seclist;
473: my $xlist_items = &identify_sections($coursehash{'internal.crosslistings'});
474: my $showsyllabus = 1; # default is to include a syllabus link
475: if (defined($coursehash{'showsyllabus'})) {
476: $showsyllabus = $coursehash{'showsyllabus'};
477: }
478: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
479: if (defined($env{'form.coursenum'})) {
480: if ($cnum eq $env{'form.coursenum'}) {
481: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum);
482: $courseinfo{$course}{'autoenrollment'} =
483: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
484: $instcode,$owner,$cdom,$cnum);
485:
486: my $startaccess = '';
487: my $endaccess = '';
488: my $accessdates;
489: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
490: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
491: }
492: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
493: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
494: if ($coursehash{'default_enrollment_end_date'} == 0) {
495: $endaccess = "No ending date";
496: }
497: }
498: if ($startaccess) {
499: $accessdates .= &mt('<i>From:</i> ').$startaccess.'<br />';
500: }
501: if ($endaccess) {
502: $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
503: }
504: $courseinfo{$course}{'access'} = $accessdates;
505: }
506: }
507: if ($xlist_items eq '') {
508: $xlist_items = &mt('No');
509: }
510: $courseinfo{$course}{'xlist'} = $xlist_items;
511: }
512: return %courseinfo;
513: }
514:
515: sub count_students {
516: my ($cdom,$cnum) = @_;
517: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
518: my %student_count = (
519: Active => 0,
520: Future => 0,
521: Expired => 0,
522: );
523: my %idx;
524: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
525: my %status_title = &Apache::lonlocal::texthash(
526: Expired => 'Previous access',
527: Active => 'Current access',
528: Future => 'Future access',
529: );
530:
531: while (my ($student,$data) = each(%$classlist)) {
532: $student_count{$data->[$idx{'status'}]} ++;
533: }
534:
535: my $countslist;
536: foreach my $status ('Active','Future') {
537: $countslist .= '<nobr>'.$status_title{$status}.': '.
538: $student_count{$status}.'</nobr><br />';
539: }
540: return $countslist;
541: }
542:
543: sub courseinfo_row {
544: my ($info) = @_;
545: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
546: $accessdates,$showsyllabus,$counts,$autoenrollment,$output);
547: if (ref($info) eq 'HASH') {
548: $cdom = $info->{'cdom'};
549: $cnum = $info->{'cnum'};
550: $title = $info->{'title'};
551: $ownerlast = $info->{'ownerlastname'};
552: $code = $info->{'code'};
553: $owner = $info->{'owner'};
554: $seclist = $info->{'seclist'};
555: $xlist_items = $info->{'xlist'};
556: $accessdates = $info->{'access'};
557: $counts = $info->{'counts'};
558: $autoenrollment = $info->{'autoenrollment'};
559: $showsyllabus = $info->{'showsyllabus'};
560: } else {
561: $output = '<td colspan="8">'.&mt('No information available for [_1].',
562: $code).'</td>';
563: return $output;
564: }
565: $output .= '<td>'.$code.'</td>'.
566: '<td>'.$seclist.'</td>'.
567: '<td>'.$xlist_items.'</td>'.
568: '<td>'.$title.' <font size="-2">';
569: if ($showsyllabus) {
570: $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom);
571: } else {
572: $output .= ' ';
573: }
574: $output .= '</font></td>'.
575: '<td>'.$ownerlast.'</td>';
576: if ($env{'form.coursenum'} eq '') {
577: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
578: } else {
579: $output .=
580: '<td>'.$accessdates.'</td>'.
581: '<td>'.$counts.'</td>'.
582: '<td>'.$autoenrollment.'</td>';
583: }
584: return $output;
585: }
586:
587: sub identify_sections {
588: my ($seclist) = @_;
589: my @secnums;
590: if ($seclist =~ /,/) {
591: my @sections = split(/,/,$seclist);
592: foreach my $sec (@sections) {
593: $sec =~ s/:[^:]*$//;
594: push(@secnums,$sec);
595: }
596: } else {
597: if ($seclist =~ m/^([^:]+):/) {
598: my $sec = $1;
599: if (!grep(/^\Q$sec\E$/,@secnums)) {
600: push(@secnums,$sec);
601: }
602: }
603: }
604: @secnums = sort {$a <=> $b} @secnums;
605: my $seclist = join(', ',@secnums);
606: return $seclist;
607: }
608:
609: sub get_valid_classes {
610: my ($seclist,$xlist_items,$crscode,$owner,$cdom,$cnum) = @_;
611: my $response;
612: my %validations;
613: @{$validations{'sections'}} = ();
614: @{$validations{'xlists'}} = ();
615: my $totalitems = 0;
616: if ($seclist) {
617: foreach my $sec (split(',',$seclist)) {
618: my $class = $crscode.$sec;
619: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
620: $class) eq 'ok') {
621: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
622: push(@{$validations{'sections'}},$sec);
623: $totalitems ++;
624: }
625: }
626: }
627: }
628: if ($xlist_items) {
629: foreach my $item (split(',',$xlist_items)) {
630: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
631: $item) eq 'ok') {
632: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
633: push(@{$validations{'xlists'}},$item);
634: $totalitems ++;
635: }
636: }
637: }
638: }
639: if ($totalitems > 0) {
640: if (@{$validations{'sections'}}) {
641: $response = &mt('Sections: ').
642: join(',',@{$validations{'sections'}}).'<br />';
643: }
644: if (@{$validations{'xlists'}}) {
645: $response .= &mt('Courses: ').
646: join(',',@{$validations{'xlists'}});
647: }
648: }
649: return $response;
650: }
651:
652: sub javascript_select_filler {
653: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
654: my $output = <<END;
655: function courseSet() {
656: var longtitles = new Array ("$longtitles_str");
657: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
658: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
659: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
660: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
661: var idyears = new Array("$allidlist");
662: var idyr = -1;
663: var idsem = -1;
664: var iddept = -1;
665: document.$formname.Number.length = 0;
666:
667: $scripttext
668:
669: selYear = document.$formname.Year.selectedIndex-1;
670: selSemester = document.$formname.Semester.selectedIndex-1;
671: selDepartment = document.$formname.Department.selectedIndex-1;
672: if (selYear == -1) {
673: if (selSemester == -1) {
674: if (selDepartment > -1) {
675: document.$formname.Number.options[0] = new Option('All','0',false,false);
676: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
677: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
678:
679: }
680: }
681: else {
682: document.$formname.Number.options[0] = new Option("All","0",true,true);
683: }
684: }
685: else {
686: if (selDepartment > -1) {
687: for (var i=0; i<idcse_by_sem_sems.length; i++) {
688: if (idcse_by_sem_sems[i] == valsem) {
689: idsem = i;
690: }
691: }
692: if (idsem != -1) {
693: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
694: if (idcse_by_sem_dept[idsem][i] == valdept) {
695: iddept = i;
696: }
697: }
698: }
699: if (iddept != -1) {
700: document.$formname.Number.options[0] = new Option('All','0',false,false);
701: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
702: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
703: }
704: }
705: else {
706: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
707: }
708: }
709: else {
710: document.$formname.Number.options[0] = new Option("All","0",true,true);
711: }
712: }
713: }
714: else {
715: if (selSemester == -1) {
716: if (selDepartment > -1) {
717: for (var i=0; i<idcse_by_yr_year.length; i++) {
718: if (idcse_by_yr_year[i] == valyr) {
719: idyr = i;
720: }
721: }
722: if (idyr != -1) {
723: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
724: if (idcse_by_yr_dept[idyr][i] == valdept) {
725: iddept = i;
726: }
727: }
728: }
729: if (iddept != -1) {
730: document.$formname.Number.options[0] = new Option('All','0',false,false);
731: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
732: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
733: }
734: }
735: else {
736: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
737: }
738: }
739: else {
740: document.$formname.Number.options[0] = new Option("All","0",true,true);
741: }
742: }
743: else {
744: for (var k=0; k<idyears.length; k++) {
745: if (idyears[k] == valyr) {
746: idyr = k;
747: }
748: }
749: if (idyr != -1) {
750: for (var k=0; k<idsems[idyr].length; k++) {
751: if (idsems[idyr][k] == valsem) {
752: idsem = k;
753: }
754: }
755: }
756: if (idsem != -1) {
757: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
758: if (idcodes[idyr][idsem][k] == valdept) {
759: iddept = k;
760: }
761: }
762: }
763: if (iddept != -1) {
764: document.$formname.Number.options[0] = new Option('All','0',false,false);
765: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
766: var display = idcourses[idyr][idsem][iddept][i];
767: if (longtitles[3] == 1) {
768: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
769: display = idcourseslongs[idyr][idsem][iddept][i]
770: }
771: }
772: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
773: }
774: }
775: else {
776: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
777: }
778: }
779: document.$formname.Number.selectedIndex = 0
780: }
781: }
782: END
783: return $output;
784: }
785:
786: sub autoenroll_info {
787: my ($coursehash,$now,$seclist,$xlist_items,$code,$owner,$cdom,$cnum) = @_;
788: my $autoenrolldates = &mt('Not enabled');
789: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
790: my ($autostart,$autoend);
791: if ( defined($coursehash->{'internal.autostart'}) ) {
792: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
793: }
794: if ( defined($coursehash->{'internal.autoend'}) ) {
795: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
796: }
797: if ($coursehash->{'internal.autostart'} > $now) {
798: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
799: $autoenrolldates = &mt('Not enabled');
800: } else {
801: my $valid_classes =
802: &get_valid_classes($seclist,$xlist_items,$code,
803: $owner,$cdom,$cnum);
804: if ($valid_classes ne '') {
805: $autoenrolldates = &mt('Not enabled<br />Starts: ').
806: $autostart.'<br />'.$valid_classes; }
807: }
808: } else {
809: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
810: $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
811: } else {
812: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
813: $code,$owner,$cdom,$cnum);
814: if ($valid_classes ne '') {
815: $autoenrolldates = &mt('Currently enabled<br />').
816: $valid_classes;
817: }
818: }
819: }
820: }
821: return $autoenrolldates;
822: }
823:
824: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>