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