Annotation of loncom/interface/coursecatalog.pm, revision 1.10
1.1 raeburn 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;
1.7 raeburn 31: use Apache::lonhtmlcommon;
1.1 raeburn 32: use Apache::lonnet;
33: use Apache::lonlocal;
1.6 raeburn 34: use Apache::courseclassifier;
1.1 raeburn 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: }
1.8 raeburn 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: }
1.1 raeburn 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'};
1.7 raeburn 60: my $formname = 'coursecatalog';
61: my $domdesc = $Apache::lonnet::domaindescription{$codedom};
62:
63: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.8 raeburn 64: if ($env{'form.coursenum'} ne '' && &user_is_known()) {
1.7 raeburn 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) = @_;
1.1 raeburn 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 = ();
1.6 raeburn 114: my %by_year;
115: my %by_sem;
116: my %by_dept;
117: my %cat_items;
1.1 raeburn 118: my $caller = 'global';
119: my $format_reply;
120: my $totcodes = 0;
121: my $jscript = '';
1.6 raeburn 122: my ($numtitles,$lasttitle);
123: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
1.1 raeburn 124: if ($totcodes > 0) {
1.6 raeburn 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;
1.1 raeburn 136: }
1.6 raeburn 137: my @data = ('top');
138: for (my $k=0; $k<$lasttitle; $k++) {
139: my $cat = $codetitles[$k];
140: my $level = 1;
1.7 raeburn 141: $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept); }
1.6 raeburn 142: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
143: $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
1.1 raeburn 144: }
145: if ($env{'form.state'} eq 'listing') {
146: $jscript .= '
147: function setElements() {
148: ';
1.6 raeburn 149: for (my $i=0; $i<@codetitles-1; $i++) {
1.1 raeburn 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: }
1.6 raeburn 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: }
1.1 raeburn 170: $jscript .= '}';
171: $jscript .= qq|
172: function changeSort(caller) {
1.7 raeburn 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();
1.1 raeburn 179: }\n|;
180: }
181: my $js = '<script type"text/javascript">'."\n$jscript\n".
182: '</script>';
183: my %add_entries = (topmargin => "0",
1.7 raeburn 184: marginheight => "0",);
185: if ($env{'form.state'} eq 'listing') {
186: $add_entries{'onLoad'} = 'setElements()';
187: }
1.1 raeburn 188: my $start_page =
189: &Apache::loncommon::start_page('Course Catalog',$js,
1.7 raeburn 190: {
1.1 raeburn 191: 'add_entries' => \%add_entries,
192: 'no_inline_link' => 1,});
193: $r->print($start_page);
1.7 raeburn 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: }
1.2 raeburn 206: $r->print('<h3>'.&mt('Display information about official [_1] classes for which LON-CAPA courses have been created:',$domdesc).'</h3>');
1.1 raeburn 207: $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
1.7 raeburn 208: $r->print('<form name="coursecatalog" method="post">');
1.1 raeburn 209: if ($numtitles > 0) {
1.6 raeburn 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: }
1.1 raeburn 220: } else {
1.6 raeburn 221: @longitems = @items;
1.1 raeburn 222: }
1.6 raeburn 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++) {
1.1 raeburn 227: if ($longitems[$i] eq '') {
228: $longitems[$i] = $items[$i];
229: }
1.6 raeburn 230: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
1.1 raeburn 231: }
1.6 raeburn 232: $r->print('</select></td>');
1.1 raeburn 233: }
1.6 raeburn 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".
1.1 raeburn 238: '</td>'
239: );
240: $r->print('</tr></table>');
241: if ($numtitles > 4) {
1.6 raeburn 242: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
243: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
1.1 raeburn 244: }
245: }
1.7 raeburn 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>');
1.5 raeburn 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));
1.1 raeburn 252: }
1.7 raeburn 253: return;
1.1 raeburn 254: }
255:
1.7 raeburn 256:
1.6 raeburn 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:
1.7 raeburn 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:
1.6 raeburn 364:
1.1 raeburn 365: sub print_course_listing {
366: my ($domain) = @_;
367: my $output;
1.7 raeburn 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: }
1.6 raeburn 377: } else {
1.7 raeburn 378: %courses = &search_courselist($domain);
379: if (keys(%courses) == 0) {
380: $output = &mt('No courses match the criteria you selected.');
381: return $output;
382: }
1.8 raeburn 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: }
1.7 raeburn 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>';
1.1 raeburn 404: }
1.8 raeburn 405: if (&user_is_known()) {
406: if ($env{'form.coursenum'} eq '') {
407: $output .= '<th> </th>';
408: } else {
409: $output .=
1.7 raeburn 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>';
1.8 raeburn 413: }
1.1 raeburn 414: }
1.7 raeburn 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));
1.6 raeburn 430: } else {
1.7 raeburn 431: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1.1 raeburn 432: }
1.7 raeburn 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: }
1.1 raeburn 439: }
1.7 raeburn 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) = @_;
1.1 raeburn 448: my %courseinfo;
1.7 raeburn 449: my $now = time;
1.1 raeburn 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;
1.10 ! raeburn 459: $cleandesc =~ s/^\s+//;
1.1 raeburn 460: my ($cdom,$cnum)=split(/\_/,$course);
1.7 raeburn 461:
1.4 albertel 462: my ($desc,$instcode,$owner,$ttype) = split(/:/,$courses{$course});
1.1 raeburn 463: $owner = &unescape($owner);
464: my ($ownername,$ownerdom);
465: if ($owner =~ /:/) {
466: ($ownername,$ownerdom) = split(/:/,$owner);
467: } else {
468: $ownername = $owner;
469: if ($owner ne '') {
470: $ownerdom = $cdom;
471: }
472: }
473: my %ownernames;
474: if ($ownername ne '' && $ownerdom ne '') {
475: %ownernames = &Apache::loncommon::getnames($ownername,$ownerdom);
476: }
477: $courseinfo{$course}{'cdom'} = $cdom;
478: $courseinfo{$course}{'cnum'} = $cnum;
479: $courseinfo{$course}{'code'} = $instcode;
480: $courseinfo{$course}{'ownerlastname'} = $ownernames{'lastname'};
481: $courseinfo{$course}{'title'} = $cleandesc;
1.7 raeburn 482: $courseinfo{$course}{'owner'} = $owner;
483:
484: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
485: my @classids;
486: my @crosslistings;
487: my $seclist = &identify_sections($coursehash{'internal.sectionnums'});
488: $courseinfo{$course}{'seclist'} = $seclist;
489: my $xlist_items = &identify_sections($coursehash{'internal.crosslistings'});
490: my $showsyllabus = 1; # default is to include a syllabus link
491: if (defined($coursehash{'showsyllabus'})) {
492: $showsyllabus = $coursehash{'showsyllabus'};
493: }
494: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
495: if (defined($env{'form.coursenum'})) {
496: if ($cnum eq $env{'form.coursenum'}) {
497: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum);
498: $courseinfo{$course}{'autoenrollment'} =
499: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
500: $instcode,$owner,$cdom,$cnum);
501:
502: my $startaccess = '';
503: my $endaccess = '';
504: my $accessdates;
505: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
506: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
507: }
508: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
509: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
510: if ($coursehash{'default_enrollment_end_date'} == 0) {
511: $endaccess = "No ending date";
512: }
513: }
514: if ($startaccess) {
515: $accessdates .= &mt('<i>From:</i> ').$startaccess.'<br />';
516: }
517: if ($endaccess) {
518: $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
519: }
520: $courseinfo{$course}{'access'} = $accessdates;
521: }
1.1 raeburn 522: }
1.7 raeburn 523: if ($xlist_items eq '') {
524: $xlist_items = &mt('No');
1.1 raeburn 525: }
1.7 raeburn 526: $courseinfo{$course}{'xlist'} = $xlist_items;
1.1 raeburn 527: }
1.7 raeburn 528: return %courseinfo;
1.1 raeburn 529: }
530:
1.7 raeburn 531: sub count_students {
532: my ($cdom,$cnum) = @_;
1.1 raeburn 533: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.7 raeburn 534: my %student_count = (
535: Active => 0,
536: Future => 0,
537: Expired => 0,
538: );
1.1 raeburn 539: my %idx;
540: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1.4 albertel 541: my %status_title = &Apache::lonlocal::texthash(
1.1 raeburn 542: Expired => 'Previous access',
543: Active => 'Current access',
544: Future => 'Future access',
545: );
1.7 raeburn 546:
1.4 albertel 547: while (my ($student,$data) = each(%$classlist)) {
1.1 raeburn 548: $student_count{$data->[$idx{'status'}]} ++;
549: }
1.7 raeburn 550:
1.1 raeburn 551: my $countslist;
1.7 raeburn 552: foreach my $status ('Active','Future') {
1.1 raeburn 553: $countslist .= '<nobr>'.$status_title{$status}.': '.
554: $student_count{$status}.'</nobr><br />';
555: }
1.7 raeburn 556: return $countslist;
557: }
558:
559: sub courseinfo_row {
560: my ($info) = @_;
561: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
562: $accessdates,$showsyllabus,$counts,$autoenrollment,$output);
563: if (ref($info) eq 'HASH') {
564: $cdom = $info->{'cdom'};
565: $cnum = $info->{'cnum'};
566: $title = $info->{'title'};
567: $ownerlast = $info->{'ownerlastname'};
568: $code = $info->{'code'};
569: $owner = $info->{'owner'};
570: $seclist = $info->{'seclist'};
571: $xlist_items = $info->{'xlist'};
572: $accessdates = $info->{'access'};
573: $counts = $info->{'counts'};
574: $autoenrollment = $info->{'autoenrollment'};
575: $showsyllabus = $info->{'showsyllabus'};
576: } else {
577: $output = '<td colspan="8">'.&mt('No information available for [_1].',
578: $code).'</td>';
579: return $output;
1.2 raeburn 580: }
1.7 raeburn 581: $output .= '<td>'.$code.'</td>'.
582: '<td>'.$seclist.'</td>'.
583: '<td>'.$xlist_items.'</td>'.
584: '<td>'.$title.' <font size="-2">';
1.2 raeburn 585: if ($showsyllabus) {
586: $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom);
1.7 raeburn 587: } else {
588: $output .= ' ';
1.2 raeburn 589: }
590: $output .= '</font></td>'.
1.7 raeburn 591: '<td>'.$ownerlast.'</td>';
1.8 raeburn 592: if (&user_is_known()) {
593: if ($env{'form.coursenum'} eq '') {
594: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
595: } else {
596: $output .=
1.7 raeburn 597: '<td>'.$accessdates.'</td>'.
598: '<td>'.$counts.'</td>'.
599: '<td>'.$autoenrollment.'</td>';
1.8 raeburn 600: }
1.7 raeburn 601: }
1.1 raeburn 602: return $output;
603: }
604:
605: sub identify_sections {
606: my ($seclist) = @_;
607: my @secnums;
608: if ($seclist =~ /,/) {
1.4 albertel 609: my @sections = split(/,/,$seclist);
1.1 raeburn 610: foreach my $sec (@sections) {
611: $sec =~ s/:[^:]*$//;
612: push(@secnums,$sec);
613: }
614: } else {
615: if ($seclist =~ m/^([^:]+):/) {
616: my $sec = $1;
1.4 albertel 617: if (!grep(/^\Q$sec\E$/,@secnums)) {
618: push(@secnums,$sec);
1.1 raeburn 619: }
620: }
621: }
622: @secnums = sort {$a <=> $b} @secnums;
623: my $seclist = join(', ',@secnums);
624: return $seclist;
625: }
626:
1.2 raeburn 627: sub get_valid_classes {
628: my ($seclist,$xlist_items,$crscode,$owner,$cdom,$cnum) = @_;
629: my $response;
630: my %validations;
631: @{$validations{'sections'}} = ();
632: @{$validations{'xlists'}} = ();
633: my $totalitems = 0;
634: if ($seclist) {
635: foreach my $sec (split(',',$seclist)) {
636: my $class = $crscode.$sec;
1.3 albertel 637: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
638: $class) eq 'ok') {
1.2 raeburn 639: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1.4 albertel 640: push(@{$validations{'sections'}},$sec);
1.2 raeburn 641: $totalitems ++;
642: }
643: }
644: }
645: }
646: if ($xlist_items) {
647: foreach my $item (split(',',$xlist_items)) {
1.3 albertel 648: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
649: $item) eq 'ok') {
1.2 raeburn 650: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1.4 albertel 651: push(@{$validations{'xlists'}},$item);
1.2 raeburn 652: $totalitems ++;
653: }
654: }
655: }
656: }
657: if ($totalitems > 0) {
658: if (@{$validations{'sections'}}) {
659: $response = &mt('Sections: ').
660: join(',',@{$validations{'sections'}}).'<br />';
661: }
662: if (@{$validations{'xlists'}}) {
663: $response .= &mt('Courses: ').
664: join(',',@{$validations{'xlists'}});
665: }
666: }
667: return $response;
668: }
669:
1.6 raeburn 670: sub javascript_select_filler {
671: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
672: my $output = <<END;
673: function courseSet() {
674: var longtitles = new Array ("$longtitles_str");
675: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
676: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
677: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
678: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
679: var idyears = new Array("$allidlist");
680: var idyr = -1;
681: var idsem = -1;
682: var iddept = -1;
683: document.$formname.Number.length = 0;
684:
685: $scripttext
686:
687: selYear = document.$formname.Year.selectedIndex-1;
688: selSemester = document.$formname.Semester.selectedIndex-1;
689: selDepartment = document.$formname.Department.selectedIndex-1;
690: if (selYear == -1) {
691: if (selSemester == -1) {
692: if (selDepartment > -1) {
693: document.$formname.Number.options[0] = new Option('All','0',false,false);
694: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
695: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
696:
697: }
698: }
699: else {
700: document.$formname.Number.options[0] = new Option("All","0",true,true);
701: }
702: }
703: else {
704: if (selDepartment > -1) {
705: for (var i=0; i<idcse_by_sem_sems.length; i++) {
706: if (idcse_by_sem_sems[i] == valsem) {
707: idsem = i;
708: }
709: }
710: if (idsem != -1) {
711: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
712: if (idcse_by_sem_dept[idsem][i] == valdept) {
713: iddept = i;
714: }
715: }
716: }
717: if (iddept != -1) {
718: document.$formname.Number.options[0] = new Option('All','0',false,false);
719: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
720: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
721: }
722: }
723: else {
724: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
725: }
726: }
727: else {
728: document.$formname.Number.options[0] = new Option("All","0",true,true);
729: }
730: }
731: }
732: else {
733: if (selSemester == -1) {
734: if (selDepartment > -1) {
735: for (var i=0; i<idcse_by_yr_year.length; i++) {
736: if (idcse_by_yr_year[i] == valyr) {
737: idyr = i;
738: }
739: }
740: if (idyr != -1) {
741: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
742: if (idcse_by_yr_dept[idyr][i] == valdept) {
743: iddept = i;
744: }
745: }
746: }
747: if (iddept != -1) {
748: document.$formname.Number.options[0] = new Option('All','0',false,false);
749: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
750: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
751: }
752: }
753: else {
754: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
755: }
756: }
757: else {
758: document.$formname.Number.options[0] = new Option("All","0",true,true);
759: }
760: }
761: else {
1.9 raeburn 762: if (selDepartment > -1) {
763: for (var k=0; k<idyears.length; k++) {
764: if (idyears[k] == valyr) {
765: idyr = k;
766: }
1.6 raeburn 767: }
1.9 raeburn 768: if (idyr != -1) {
769: for (var k=0; k<idsems[idyr].length; k++) {
770: if (idsems[idyr][k] == valsem) {
771: idsem = k;
772: }
1.6 raeburn 773: }
774: }
1.9 raeburn 775: if (idsem != -1) {
776: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
777: if (idcodes[idyr][idsem][k] == valdept) {
778: iddept = k;
779: }
1.6 raeburn 780: }
781: }
1.9 raeburn 782: if (iddept != -1) {
783: document.$formname.Number.options[0] = new Option('All','0',false,false);
784: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
785: var display = idcourses[idyr][idsem][iddept][i];
786: if (longtitles[3] == 1) {
787: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
788: display = idcourseslongs[idyr][idsem][iddept][i]
789: }
1.6 raeburn 790: }
1.9 raeburn 791: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
1.6 raeburn 792: }
1.9 raeburn 793: }
794: else {
795: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1.6 raeburn 796: }
1.9 raeburn 797: }
1.6 raeburn 798: else {
1.9 raeburn 799: document.$formname.Number.options[0] = new Option('All','0',true,true);
1.6 raeburn 800: }
801: }
802: document.$formname.Number.selectedIndex = 0
803: }
804: }
805: END
806: return $output;
807: }
1.1 raeburn 808:
1.7 raeburn 809: sub autoenroll_info {
810: my ($coursehash,$now,$seclist,$xlist_items,$code,$owner,$cdom,$cnum) = @_;
811: my $autoenrolldates = &mt('Not enabled');
812: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
813: my ($autostart,$autoend);
814: if ( defined($coursehash->{'internal.autostart'}) ) {
815: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
816: }
817: if ( defined($coursehash->{'internal.autoend'}) ) {
818: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
819: }
820: if ($coursehash->{'internal.autostart'} > $now) {
821: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
822: $autoenrolldates = &mt('Not enabled');
823: } else {
824: my $valid_classes =
825: &get_valid_classes($seclist,$xlist_items,$code,
826: $owner,$cdom,$cnum);
827: if ($valid_classes ne '') {
828: $autoenrolldates = &mt('Not enabled<br />Starts: ').
829: $autostart.'<br />'.$valid_classes; }
830: }
831: } else {
832: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
833: $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
834: } else {
835: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
836: $code,$owner,$cdom,$cnum);
837: if ($valid_classes ne '') {
838: $autoenrolldates = &mt('Currently enabled<br />').
839: $valid_classes;
840: }
841: }
842: }
843: }
844: return $autoenrolldates;
845: }
846:
1.8 raeburn 847: sub user_is_known {
848: my $known = 0;
849: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
850: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
851: $known = 1;
852: }
853: return $known;
854: }
855:
1.1 raeburn 856: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>