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