File:
[LON-CAPA] /
loncom /
interface /
coursecatalog.pm
Revision
1.41:
download - view:
text,
annotated -
select for diffs
Thu Jul 17 12:00:28 2008 UTC (16 years, 1 month ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_7_0,
version_2_6_99_1,
HEAD
- Change link to "Enroll in course" to javascript:ToSelfenroll() which submits linklaunch form.
- Filters used in coursecatalog display passed to selfenroll to allow breadcrumbs there.
- syllabuslaunch form renamed linklaunch form (no longer used for just syllabus).
- &syllabus_javascript() renamed courselink_javascript() - broader use.
- 'courseid' added as another element to exclude from echo of form input to avoid duplicate
when coming from breadcrumb trail link in self-enroll.
1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
4: # $Id: coursecatalog.pm,v 1.41 2008/07/17 12:00:28 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::coursecatalog;
30:
31: use strict;
32: use lib qw(/home/httpd/lib/perl);
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonhtmlcommon;
36: use Apache::lonnet;
37: use Apache::lonlocal;
38: use Apache::courseclassifier;
39: use Apache::lonacc;
40: use LONCAPA;
41:
42: sub handler {
43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: if ($r->header_only) {
47: return OK;
48: }
49: my $handle = &Apache::lonnet::check_for_valid_session($r);
50: my $lonidsdir=$r->dir_config('lonIDsDir');
51: if ($handle ne '') {
52: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
53: }
54: &Apache::lonacc::get_posted_cgi($r);
55: &Apache::lonlocal::get_language_handle($r);
56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
57: ['sortby','showdom']);
58:
59: my $codedom = &Apache::lonnet::default_login_domain();
60:
61: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
62: $codedom = $env{'user.domain'};
63: if ($env{'request.role.domain'} ne '') {
64: $codedom = $env{'request.role.domain'};
65: }
66: }
67: my $formname = 'coursecatalog';
68: if ($env{'form.showdom'} ne '') {
69: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
70: $codedom = $env{'form.showdom'};
71: }
72: }
73: my $domdesc = &Apache::lonnet::domain($codedom,'description');
74: &Apache::lonhtmlcommon::clear_breadcrumbs();
75:
76: my %domconfig =
77: &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
78: my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
79: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
80: $cathash = $domconfig{'coursecategories'}{'cats'};
81: } else {
82: $cathash = {};
83: }
84: my $subcats;
85: if ($env{'form.withsubcats'}) {
86: $subcats = \%subcathash;
87: }
88: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
89: \%idx,\@jsarray,$subcats);
90: if ($env{'form.coursenum'} ne '' && &user_is_known()) {
91: &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
92: } else {
93: my ($catlinks,$has_subcats) = &category_breadcrumbs($codedom,@cats);
94: my $catjs = <<"ENDSCRIPT";
95:
96: function setCatDepth(depth) {
97: document.coursecats.catalog_maxdepth.value = depth;
98: if (depth == '') {
99: document.coursecats.currcat_0.value = '';
100: }
101: document.coursecats.submit();
102: return;
103: }
104:
105: function changeSort(caller) {
106: document.$formname.sortby.value = caller;
107: document.$formname.submit();
108: }
109:
110: function setCourseId(caller) {
111: document.$formname.coursenum.value = caller;
112: document.$formname.submit();
113: }
114:
115: ENDSCRIPT
116: $catjs .= &courselink_javascript();
117: my $numtitles;
118: if ($env{'form.currcat_0'} eq 'instcode::0') {
119: $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
120: $catlinks,$catjs);
121: if ($env{'form.state'} eq 'listing') {
122: $r->print(&print_course_listing($codedom,$numtitles));
123: }
124: } else {
125: my (%add_entries);
126: $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
127: &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
128: if ($env{'form.currcat_0'} ne '') {
129: $r->print('<form name="'.$formname.
130: '" method="post" action="/adm/coursecatalog">'.
131: &additional_filters($codedom,$has_subcats)."\n");
132: my ($currdepth,$deeper) = &get_depth_values();
133: $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
134: $deeper.'" />'."\n");
135: for (my $i=0; $i<$deeper; $i++) {
136: $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
137: }
138: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
139: '<input type="hidden" name="sortby" value="" />'."\n".
140: '<input type="hidden" name="state" value="listing" />'."\n".
141: '<input type="hidden" name="showdom" value="'.
142: $env{'form.showdom'}.'" />'.
143: '<input type="submit" name="catalogfilter" value="'.
144: &mt('Display courses').'" /></form><br /><br />');
145: }
146: if ($env{'form.state'} eq 'listing') {
147: $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
148: }
149: }
150: }
151: $r->print('<br />'.&Apache::loncommon::end_page());
152: return OK;
153: }
154:
155: sub course_details {
156: my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
157: my $output;
158: my %add_entries = (topmargin => "0",
159: marginheight => "0",);
160: my $js = '<script type="text/javascript">'."\n".
161: &courselink_javascript().'</script>'."\n";
162: my $start_page =
163: &Apache::loncommon::start_page('Course Catalog',$js,
164: {
165: 'add_entries' => \%add_entries,
166: 'no_inline_link' => 1,});
167: $r->print($start_page);
168: if ($env{'form.numtitles'} > 0) {
169: &Apache::lonhtmlcommon::add_breadcrumb
170: ({href=>"/adm/coursecatalog",
171: text=>"Select courses"});
172: }
173: &Apache::lonhtmlcommon::add_breadcrumb
174: ({href=>"javascript:document.$formname.submit()",
175: text=>"Course listing"},
176: {text=>"Course details"});
177: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
178: $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
179: &print_course_listing($codedom,undef,$trails,$allitems).
180: '<br /><br />');
181: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
182: '<a href = "javascript:document.coursecatalog.submit()">'.
183: &mt('Back to course listing').'</a>'.
184: &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
185: 'showdetails','courseid']).'</form>');
186: return;
187: }
188:
189: sub courselink_javascript {
190: return <<"END";
191:
192: function ToSyllabus(cdom,cnum) {
193: if (cdom == '' || cdom == null) {
194: return;
195: }
196: if (cnum == '' || cnum == null) {
197: return;
198: }
199: document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
200: document.linklaunch.submit();
201: }
202:
203: function ToSelfenroll(courseid) {
204: if (courseid == '') {
205: return;
206: }
207: document.linklaunch.action = "/adm/selfenroll";
208: document.linklaunch.courseid.value = courseid;
209: document.linklaunch.submit();
210: }
211:
212: END
213: }
214:
215:
216: sub instcode_course_selector {
217: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
218: my %coursecodes = ();
219: my %codes = ();
220: my @codetitles = ();
221: my %cat_titles = ();
222: my %cat_order = ();
223: my %idlist = ();
224: my %idnums = ();
225: my %idlist_titles = ();
226: my %by_year;
227: my %by_sem;
228: my %by_dept;
229: my %cat_items;
230: my $caller = 'global';
231: my $format_reply;
232: my $totcodes = 0;
233: my $jscript = '';
234: my ($numtitles,$lasttitle);
235: my %add_entries = (topmargin => "0",
236: marginheight => "0",);
237: my $js;
238: $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
239: if ($totcodes > 0) {
240: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
241: if ($format_reply eq 'ok') {
242: my $numtypes = @codetitles;
243: &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
244: my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
245: my $longtitles_str = join('","',@{$longtitles});
246: my $allidlist = $idlist{$codetitles[0]};
247: $numtitles = @codetitles;
248: $lasttitle = $numtitles;
249: if ($numtitles > 4) {
250: $lasttitle = 4;
251: }
252: if ($numtitles == 0) {
253: if (!defined($env{'form.state'})) {
254: $env{'form.state'} = 'listing';
255: }
256: } else {
257: my @data = ('top');
258: for (my $k=0; $k<$lasttitle; $k++) {
259: my $cat = $codetitles[$k];
260: my $level = 1;
261: $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
262: }
263: $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
264: $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
265: if ($env{'form.state'} eq 'listing') {
266: $jscript .= '
267: function setElements() {
268: ';
269: for (my $i=0; $i<@codetitles-1; $i++) {
270: if ($env{'form.'.$codetitles[$i]} != -1) {
271: $jscript .= '
272: for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
273: if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
274: document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
275: }
276: }
277: ';
278: }
279: }
280: $jscript .= ' courseSet()'."\n";
281: if ($env{'form.'.$codetitles[-1]} != -1) {
282: $jscript .= '
283: for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
284: if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
285: document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
286: }
287: }
288: ';
289: }
290: $jscript .= '}';
291: }
292: }
293: }
294: $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
295: '</script>';
296: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
297: $add_entries{'onLoad'} = 'setElements()';
298: }
299: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
300: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
301: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
302: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
303: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
304: '<input type="hidden" name="currcat_0" value="instcode::0" />'.
305: &additional_filters($codedom));
306: if ($numtitles > 0) {
307: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
308: $r->print('<table><tr>');
309: for (my $k=0; $k<$lasttitle-1; $k++) {
310: my (@items,@unsorted);
311: if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
312: @unsorted = @{$cat_items{$codetitles[$k]}};
313: }
314: &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
315: my @longitems;
316: if (defined($cat_titles{$codetitles[$k]})) {
317: foreach my $item (@items) {
318: push(@longitems,$cat_titles{$codetitles[$k]}{$item});
319: }
320: } else {
321: @longitems = @items;
322: }
323: $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
324: '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
325: $r->print('>'."\n".'<option value="0" />All'."\n");
326: for (my $i=0; $i<@items; $i++) {
327: if ($longitems[$i] eq '') {
328: $longitems[$i] = $items[$i];
329: }
330: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
331: }
332: $r->print('</select></td>');
333: }
334: $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
335: '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
336: '<option value="0">All'."\n".
337: '</option>'."\n".'</select>'."\n".
338: '</td></tr></table>'."\n");
339: if ($numtitles > 4) {
340: $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
341: '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
342: }
343: $r->print('<br />');
344: }
345: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
346: '<input type="hidden" name="sortby" value="" />'."\n".
347: '<input type="hidden" name="state" value="listing" />'."\n".
348: '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
349: '<input type="submit" name="catalogfilter" value="'.
350: &mt('Display courses').'" />'.
351: '<input type="hidden" name="numtitles" value="'.$numtitles.
352: '" /></form><br /><br />');
353: } else {
354: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
355: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
356: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
357: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
358: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
359: '<input type="hidden" name="currcat_0" value="instcode::0" />');
360: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
361: }
362: return $numtitles;
363: }
364:
365: sub cat_header {
366: my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
367: my $start_page =
368: &Apache::loncommon::start_page('Course Catalog',$js,
369: {
370: 'add_entries' => $add_entries,
371: 'no_inline_link' => 1,});
372: $r->print($start_page);
373: if ($env{'form.state'} eq 'listing') {
374: if ($numtitles > 0) {
375: &Apache::lonhtmlcommon::add_breadcrumb
376: ({href=>"/adm/coursecatalog",
377: text=>"Select courses"},
378: {text=>"Course listing"});
379: } else {
380: &Apache::lonhtmlcommon::add_breadcrumb
381: ({text=>"Course listing"});
382: }
383: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
384: } else {
385: &Apache::lonhtmlcommon::add_breadcrumb
386: ({href=>"/adm/coursecatalog",
387: text=>"Select courses"});
388: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
389: }
390: $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
391: '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
392: &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
393: ' <input type="submit" name="godom" value="'.&mt('Change').'" /></td></tr></table></form>'.
394: '<form name="coursecats" method="post" action="/adm/coursecatalog">'.
395: '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
396: return;
397: }
398:
399: sub category_breadcrumbs {
400: my ($dom,@cats) = @_;
401: my ($currdepth,$deeper) = &get_depth_values();
402: my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
403: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
404: my $has_subcats;
405: for (my $i=0; $i<$deeper; $i++) {
406: $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
407: my ($cattitle,$shallower);
408: if ($i == 0) {
409: $cattitle = &mt('Main Categories');
410: } else {
411: $shallower = $i-1;
412: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
413: $cattitle = $cat;
414: }
415: $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>-></td>';
416: }
417: if ($deeper == 0) {
418: $catlinks .= '<td>'.&mt('Main Categories').': ';
419: if (ref($cats[0]) eq 'ARRAY') {
420: if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {
421: $catlinks .= &mt('Official courses (with institutional codes)').
422: '<input type="hidden" name="currcat_0" value="instcode::0" />';
423: $env{'form.currcat_0'} = 'instcode::0';
424: } else {
425: $has_subcats = 1;
426: $catlinks .= '<select name="currcat_0">'."\n";
427: if (@{$cats[0]} > 1) {
428: my $selstr;
429: if ($env{'form.currcat_0'} eq '') {
430: $selstr = ' selected="selected" ';
431: }
432: $catlinks .= '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
433: }
434: for (my $i=0; $i<@{$cats[0]}; $i++) {
435: my $name = $cats[0][$i];
436: my $item = &escape($name).'::0';
437: $catlinks .= '<option value="'.$item.'">';
438: if ($name eq 'instcode') {
439: $catlinks .= &mt('Official courses (with institutional codes)');
440: } else {
441: $catlinks .= $name;
442: }
443: $catlinks .= '</option>'."\n";
444: }
445: $catlinks .= '</select>'."\n".
446: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
447: }
448: } else {
449: $catlinks .= &mt('Official courses (with institutional codes)').
450: '<input type="hidden" name="currcat_0" value="instcode::0" />';
451: $env{'form.currcat_0'} = 'instcode::0';
452: }
453: } else {
454: my ($cat,$container,$depth);
455: if ($env{'form.currcat_'.$currdepth} eq '') {
456: my $shallower = $currdepth - 1;
457: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
458: } else {
459: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
460: }
461: my $deeper = $depth +1;
462: my $currcat = $cat;
463: if ($cat eq 'instcode') {
464: $currcat = &mt('Official courses (with institutional codes)');
465: }
466: $catlinks .= '<td>'.$currcat;
467: if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
468: $has_subcats = 1;
469: my $selstr;
470: $catlinks .= ': <select name="currcat_'.$deeper.'">'.
471: '<option value="" selected="selected">'.
472: &mt('Select').'</option>';
473: for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
474: my $name = $cats[$deeper]{$cat}[$k];
475: my $item = &escape($name).':'.&escape($cat).':'.$deeper;
476: $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
477: }
478: $catlinks .= '</select>'."\n".
479: ' <input type="submit" name="gocats" value="'.&mt('Change').'" />';
480: }
481: }
482: $catlinks .= $currcat_str.'</td></tr></table></td>';
483: return ($catlinks,$has_subcats);
484: }
485:
486: sub get_depth_values {
487: my $currdepth = 0;
488: my $deeper = 0;
489: if ($env{'form.catalog_maxdepth'} ne '') {
490: $currdepth = $env{'form.catalog_maxdepth'};
491: if ($env{'form.currcat_'.$currdepth} eq '') {
492: $deeper = $currdepth;
493: } else {
494: $deeper = $currdepth + 1;
495: }
496: }
497: return ($currdepth,$deeper);
498: }
499:
500: sub additional_filters {
501: my ($codedom,$has_subcats) = @_;
502: my $output = '<table>';
503: if (($env{'form.currcat_0'} ne 'instcode::0') &&
504: ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
505: my $include_subcat_status;
506: if ($env{'form.withsubcats'}) {
507: $include_subcat_status = 'checked="checked" ';
508: }
509: my $counter = $env{'form.catalog_maxdepth'};
510: if ($counter > 0) {
511: if ($env{'form.state'} eq 'listing') {
512: $counter --;
513: } elsif ($env{'form.currcat_'.$counter} eq '') {
514: $counter --;
515: }
516: }
517: my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
518: if ($catname ne '') {
519: $output .= '<tr><td><label>'.
520: '<input type="checkbox" name="withsubcats" value="1" '.
521: $include_subcat_status.'/>'.
522: &mt('Include subcategories within "[_1]"',
523: &unescape($catname)).'</label></td></tr>';
524: }
525: }
526: my $show_selfenroll_status;
527: if ($env{'form.showselfenroll'}) {
528: $show_selfenroll_status = 'checked="checked" ';
529: }
530: $output .= '<tr><td>'.
531: '<label><input type="checkbox" name="showselfenroll" value="1" '.
532: $show_selfenroll_status.'/>'.
533: &mt('Only show courses which allow self-enrollment').
534: '</label></td></tr>';
535: if (&user_is_dc($codedom)) {
536: my $showdetails_status;
537: if ($env{'form.showdetails'}) {
538: $showdetails_status = 'checked="checked" ';
539: }
540: my $showhidden_status;
541: if ($env{'form.showhidden'}) {
542: $showhidden_status = 'checked="checked" ';
543: }
544: my $dc_title = &Apache::lonnet::plaintext('dc');
545: $output .= '<tr><td>'."\n".
546: '<label><input type="checkbox" name="showdetails" value="1" '.
547: $showdetails_status.'/>'.
548: &mt('Show full details for each course ([_1] only)',$dc_title).
549: '</label>'."\n".'</td></tr><tr><td>'.
550: '<label><input type="checkbox" name="showhidden" value="1" '.
551: $showhidden_status.'/>'.
552: &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
553: '</label>'."\n".'</td></tr>';
554: }
555: $output .= '</table><br />';
556: return $output;
557: }
558:
559: sub user_is_dc {
560: my ($codedom) = @_;
561: if (exists($env{'user.role.dc./'.$codedom.'/'})) {
562: my $livedc = 1;
563: my $now = time;
564: my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
565: if ($start && $start>$now) { $livedc = 0; }
566: if ($end && $end <$now) { $livedc = 0; }
567: return $livedc;
568: }
569: return;
570: }
571:
572: sub recurse_options {
573: my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
574: if (ref($currlist) eq 'HASH') {
575: $level ++;
576: foreach my $key (sort(keys(%{$currlist}))) {
577: $$data[$level-1]= $key;
578: &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
579: }
580: } else {
581: $level --;
582: my @contents = split(/","/,$currlist);
583: foreach my $item (@contents) {
584: if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
585: push(@{$cat_options->{$cat}},$item);
586: }
587: if ($level == 3) {
588: if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
589: push(@{$by_year->{$data->[1]}->{$currkey}},$item);
590: }
591: if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
592: push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
593: }
594: if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
595: push(@{$by_dept->{$currkey}},$item);
596: }
597:
598: }
599: }
600: }
601: return $level;
602: }
603:
604: sub build_javascript {
605: my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
606: my @unsorted = keys(%{$by_year});
607: my @sorted_yrs;
608: &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
609: my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
610: 'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
611: 'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
612: for (my $i=0; $i<@sorted_yrs; $i++) {
613: my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
614: $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
615: if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
616: @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
617: my @sorted_depts;
618: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
619: $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
620: for (my $j=0; $j<@sorted_depts; $j++) {
621: $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
622: $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
623: }
624: }
625: }
626: @unsorted = keys(%{$by_sem});
627: my @sorted_sems;
628: &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
629: $output .= 'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
630: 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
631: 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
632: for (my $i=0; $i<@sorted_sems; $i++) {
633: my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
634: $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
635: if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
636: @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
637: my @sorted_depts;
638: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
639: $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
640: for (my $j=0; $j<@sorted_depts; $j++) {
641: $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
642: }
643: }
644: }
645: @unsorted = keys(%{$by_dept});
646: my @sorted_deps;
647: &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
648: $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n";
649: for (my $k=0; $k<@sorted_deps; $k++) {
650: $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
651: }
652: return $output;
653: }
654:
655: sub search_official_courselist {
656: my ($domain,$numtitles) = @_;
657: my $instcode;
658: if (defined($numtitles) && $numtitles == 0) {
659: $instcode = '.+';
660: } else {
661: my (%codedefaults,@code_order);
662: my $defaults_result =
663: &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
664: \@code_order);
665: if ($defaults_result eq 'ok') {
666: $instcode ='^';
667: foreach my $item (@code_order) {
668: if ($env{'form.'.$item} eq '0' ) {
669: $instcode .= $codedefaults{$item};
670: } else {
671: $instcode .= $env{'form.'.$item};
672: }
673: }
674: $instcode .= '$';
675: } else {
676: $instcode = '.';
677: }
678: }
679: my $showhidden;
680: if (&user_is_dc($domain)) {
681: $showhidden = $env{'form.showhidden'};
682: }
683: my %courses =
684: &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
685: 'Course',1,$env{'form.showselfenroll'},undef,
686: $showhidden,'coursecatalog');
687: return %courses;
688: }
689:
690: sub search_courselist {
691: my ($domain,$subcats) = @_;
692: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
693: my $filter = $env{'form.currcat_'.$cat_maxdepth};
694: if (($filter eq '') && ($cat_maxdepth > 0)) {
695: my $shallower = $cat_maxdepth - 1;
696: $filter = $env{'form.currcat_'.$shallower};
697: }
698: my %courses;
699: my $filterstr;
700: if ($filter ne '') {
701: if ($env{'form.withsubcats'}) {
702: if (ref($subcats) eq 'HASH') {
703: if (ref($subcats->{$filter}) eq 'ARRAY') {
704: $filterstr = join('&',@{$subcats->{$filter}});
705: if ($filterstr ne '') {
706: $filterstr = $filter.'&'.$filterstr;
707: }
708: } else {
709: $filterstr = $filter;
710: }
711: } else {
712: $filterstr = $filter;
713: }
714: } else {
715: $filterstr = $filter;
716: }
717: my $showhidden;
718: if (&user_is_dc($domain)) {
719: $showhidden = $env{'form.showhidden'};
720: }
721: %courses =
722: &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
723: '.',1,$env{'form.showselfenroll'},
724: $filterstr,$showhidden,'coursecatalog');
725: }
726: return %courses;
727: }
728:
729: sub print_course_listing {
730: my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
731: my $output;
732: my %courses;
733: my $knownuser = &user_is_known();
734: my $details = $env{'form.coursenum'};
735: if (&user_is_dc($domain)) {
736: if ($env{'form.showdetails'}) {
737: $details = 1;
738: }
739: }
740: if ($env{'form.coursenum'} ne '') {
741: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
742: $env{'form.coursenum'},
743: undef,undef,'.',1);
744: if (keys(%courses) == 0) {
745: $output .= &mt('The courseID provided does not match a course in this domain.');
746: return $output;
747: }
748: } else {
749: if ($env{'form.currcat_0'} eq 'instcode::0') {
750: %courses = &search_official_courselist($domain,$numtitles);
751: } else {
752: %courses = &search_courselist($domain,$subcats);
753: }
754: if (keys(%courses) == 0) {
755: $output = &mt('No courses match the criteria you selected.');
756: return $output;
757: }
758: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
759: $output = '<b>'.&mt('Note for students:').'</b> '
760: .&mt('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.')
761: .'<br /><br />';
762: }
763: }
764: my $now = time;
765: my %domconfig =
766: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
767: $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
768: $output .= "\n".'<form name="linklaunch" method="post" action="">'.
769: '<input type="hidden" name="backto" value="coursecatalog" />'.
770: '<input type="hidden" name="courseid" value="" />'.
771: &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
772: return $output;
773: }
774:
775: sub construct_data_table {
776: my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails,
777: $allitems) = @_;
778: my %sortname;
779: if (($details eq '') || ($env{'form.showdetails'})) {
780: $sortname{'Code'} = 'code';
781: $sortname{'Categories'} = 'cats';
782: $sortname{'Title'} = 'title';
783: $sortname{'Owner(s)'} = 'owner';
784: }
785: my $output = &Apache::loncommon::start_data_table().
786: &Apache::loncommon::start_data_table_header_row();
787: my @coltitles = ('Count');
788: if ($env{'form.currcat_0'} eq 'instcode::0') {
789: push(@coltitles,'Code');
790: } else {
791: push(@coltitles,'Categories');
792: }
793: push(@coltitles,('Sections','Crosslisted','Title','Owner(s)'));
794: if (ref($usersections) eq 'HASH') {
795: $coltitles[1] = 'Your Section';
796: }
797: foreach my $item (@coltitles) {
798: $output .= '<th>';
799: if (defined($sortname{$item})) {
800: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
801: } elsif ($item eq 'Count') {
802: $output .= ' ';
803: } else {
804: $output .= &mt($item);
805: }
806: $output .= '</th>';
807: }
808: if ($knownuser) {
809: if ($details) {
810: $output .=
811: '<th>'.&mt('Default Access Dates for Students').'</th>'.
812: '<th>'.&mt('Student Counts').'</th>'.
813: '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
814: } else {
815: $output .= '<th>'.&mt('Details').'</th>';
816: }
817: }
818: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
819: &Apache::loncommon::end_data_table_header_row();
820: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
821: $usersections);
822: my %Sortby;
823: foreach my $course (sort(keys(%{$courses}))) {
824: if ($env{'form.sortby'} eq 'code') {
825: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
826: } elsif ($env{'form.sortby'} eq 'cats') {
827: push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
828: } elsif ($env{'form.sortby'} eq 'owner') {
829: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
830: } else {
831: my $clean_title = $courseinfo{$course}{'title'};
832: $clean_title =~ s/\W+//g;
833: if ($clean_title eq '') {
834: $clean_title = $courseinfo{$course}{'title'};
835: }
836: push(@{$Sortby{$clean_title}},$course);
837: }
838: }
839: my @sorted_courses;
840: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
841: ($env{'form.sortby'} eq 'cats')) {
842: @sorted_courses = sort(keys(%Sortby));
843: } else {
844: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
845: }
846: my $count = 1;
847: foreach my $item (@sorted_courses) {
848: foreach my $course (@{$Sortby{$item}}) {
849: $output.=&Apache::loncommon::start_data_table_row();
850: $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
851: \$count,$now,$course,$trails,$allitems);
852: $output.=&Apache::loncommon::end_data_table_row();
853: }
854: }
855: $output .= &Apache::loncommon::end_data_table();
856: return $output;
857: }
858:
859: sub build_courseinfo_hash {
860: my ($courses,$knownuser,$details,$usersections) = @_;
861: my %courseinfo;
862: my $now = time;
863: foreach my $course (keys(%{$courses})) {
864: my $descr;
865: if (ref($courses->{$course}) eq 'HASH') {
866: $descr = $courses->{$course}{'description'};
867: }
868: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
869: $cleandesc=~s/'/\\'/g;
870: $cleandesc =~ s/^\s+//;
871: my ($cdom,$cnum)=split(/\_/,$course);
872: my ($instcode,$singleowner,$ttype,$selfenroll_types,
873: $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
874: if (ref($courses->{$course}) eq 'HASH') {
875: $descr = $courses->{$course}{'description'};
876: $instcode = $courses->{$course}{'inst_code'};
877: $singleowner = $courses->{$course}{'owner'};
878: $ttype = $courses->{$course}{'type'};
879: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
880: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
881: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
882: $categories = $courses->{$course}{'categories'};
883: push(@owners,$singleowner);
884: if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
885: foreach my $item (@{$courses->{$course}{'co-owners'}}) {
886: push(@owners,$item);
887: }
888: }
889: }
890: foreach my $owner (@owners) {
891: my ($ownername,$ownerdom) = @_;
892: if ($owner =~ /:/) {
893: ($ownername,$ownerdom) = split(/:/,$owner);
894: } else {
895: $ownername = $owner;
896: if ($owner ne '') {
897: $ownerdom = $cdom;
898: }
899: }
900: if ($ownername ne '' && $ownerdom ne '') {
901: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
902: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
903: }
904: }
905: $courseinfo{$course}{'cdom'} = $cdom;
906: $courseinfo{$course}{'cnum'} = $cnum;
907: $courseinfo{$course}{'code'} = $instcode;
908: my @lastnames;
909: foreach my $owner (keys(%ownernames)) {
910: if (ref($ownernames{$owner}) eq 'HASH') {
911: push(@lastnames,$ownernames{$owner}{'lastname'});
912: }
913: }
914: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
915: $courseinfo{$course}{'title'} = $cleandesc;
916: $courseinfo{$course}{'owner'} = $singleowner;
917: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
918: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
919: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
920: $courseinfo{$course}{'categories'} = $categories;
921:
922: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
923: my @classids;
924: my @crosslistings;
925: my ($seclist,$numsec) =
926: &identify_sections($coursehash{'internal.sectionnums'});
927: if (ref($usersections) eq 'HASH') {
928: if (ref($usersections->{$course}) eq 'ARRAY') {
929: $seclist = join(', ',@{$usersections->{$course}});
930: }
931: }
932: $courseinfo{$course}{'seclist'} = $seclist;
933: my ($xlist_items,$numxlist) =
934: &identify_sections($coursehash{'internal.crosslistings'});
935: my $showsyllabus = 1; # default is to include a syllabus link
936: if (defined($coursehash{'showsyllabus'})) {
937: $showsyllabus = $coursehash{'showsyllabus'};
938: }
939: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
940: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
941: ($knownuser && ($details == 1))) {
942: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec);
943: $courseinfo{$course}{'autoenrollment'} =
944: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
945: $instcode,\@owners,$cdom,$cnum);
946:
947: my $startaccess = '';
948: my $endaccess = '';
949: my $accessdates;
950: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
951: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
952: }
953: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
954: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
955: if ($coursehash{'default_enrollment_end_date'} == 0) {
956: $endaccess = &mt('No ending date');
957: }
958: }
959: if ($startaccess) {
960: $accessdates .= &mt('<i>From:</i> ').$startaccess.'<br />';
961: }
962: if ($endaccess) {
963: $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
964: }
965: if (($selfenroll_types ne '') &&
966: ($selfenroll_end > 0 && $selfenroll_end > $now)) {
967: my ($selfenroll_start_access,$selfenroll_end_access);
968: if (($coursehash{'default_enrollment_start_date'} ne
969: $coursehash{'internal.selfenroll_start_access'}) ||
970: ($coursehash{'default_enrollment_end_date'} ne
971: $coursehash{'internal.selfenroll_end_access'})) {
972: if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
973: $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
974: }
975: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
976: $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
977: if ($coursehash{'internal.selfenroll_end_access'} == 0) {
978: $selfenroll_end_access = &mt('No ending date');
979: }
980: }
981: if ($selfenroll_start_access || $selfenroll_end_access) {
982: $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
983: if ($selfenroll_start_access) {
984: $accessdates .= &mt('<i>From:</i> ').$selfenroll_start_access.'<br />';
985: }
986: if ($selfenroll_end_access) {
987: $accessdates .= &mt('<i>To:</i> ').$selfenroll_end_access.'<br />';
988: }
989: }
990: }
991: }
992: $courseinfo{$course}{'access'} = $accessdates;
993: }
994: if ($xlist_items eq '') {
995: $xlist_items = &mt('No');
996: }
997: $courseinfo{$course}{'xlist'} = $xlist_items;
998: }
999: return %courseinfo;
1000: }
1001:
1002: sub count_students {
1003: my ($cdom,$cnum,$numsec) = @_;
1004: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1005: my %student_count = (
1006: Active => 0,
1007: Future => 0,
1008: Expired => 0,
1009: );
1010: my %idx;
1011: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1012: my %status_title = &Apache::lonlocal::texthash(
1013: Expired => 'Previous access',
1014: Active => 'Current access',
1015: Future => 'Future access',
1016: );
1017:
1018: while (my ($student,$data) = each(%$classlist)) {
1019: $student_count{$data->[$idx{'status'}]} ++;
1020: }
1021:
1022: my $countslist = &mt('[quant,_1,section]',$numsec).':<br />';
1023: foreach my $status ('Active','Future') {
1024: $countslist .= '<nobr>'.$status_title{$status}.': '.
1025: $student_count{$status}.'</nobr><br />';
1026: }
1027: return $countslist;
1028: }
1029:
1030: sub courseinfo_row {
1031: my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_;
1032: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1033: $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
1034: if (ref($info) eq 'HASH') {
1035: $cdom = $info->{'cdom'};
1036: $cnum = $info->{'cnum'};
1037: $title = $info->{'title'};
1038: $ownerlast = $info->{'ownerlastnames'};
1039: $code = $info->{'code'};
1040: $owner = $info->{'owner'};
1041: $seclist = $info->{'seclist'};
1042: $xlist_items = $info->{'xlist'};
1043: $accessdates = $info->{'access'};
1044: $counts = $info->{'counts'};
1045: $autoenrollment = $info->{'autoenrollment'};
1046: $showsyllabus = $info->{'showsyllabus'};
1047: $categories = $info->{'categories'};
1048: } else {
1049: $output = '<td colspan="8">'.&mt('No information available for [_1].',
1050: $code).'</td>';
1051: return $output;
1052: }
1053: $output .= '<td>'.$$countref.'</td>';
1054: if ($env{'form.currcat_0'} eq 'instcode::0') {
1055: $output .= '<td>'.$code.'</td>';
1056: } else {
1057: my ($categorylist,@cats);
1058: if ($categories ne '') {
1059: @cats = split('&',$categories);
1060: }
1061: if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
1062: my @categories = map { $trails->[$allitems->{$_}]; } @cats;
1063: $categorylist = join('<br />',@categories);
1064: }
1065: if ($categorylist eq '') {
1066: $categorylist = ' ';
1067: }
1068: $output .= '<td>'.$categorylist.'</td>';
1069: }
1070: $output .= '<td>'.$seclist.'</td>'.
1071: '<td>'.$xlist_items.'</td>'.
1072: '<td>'.$title.' <font size="-2">';
1073: if ($showsyllabus) {
1074: $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.&mt('Syllabus').'</a>';
1075: } else {
1076: $output .= ' ';
1077: }
1078: $output .= '</font></td>'.
1079: '<td>'.$ownerlast.'</td>';
1080: if ($knownuser) {
1081: if ($details) {
1082: $output .=
1083: '<td>'.$accessdates.'</td>'.
1084: '<td>'.$counts.'</td>'.
1085: '<td>'.$autoenrollment.'</td>';
1086: } else {
1087: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1088: }
1089: }
1090: my $selfenroll;
1091: if ($info->{'selfenroll_types'}) {
1092: my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
1093: my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
1094: if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
1095: if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
1096: $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
1097: } else {
1098: $output .= '<td><a href="javascript:ToSelfenroll('."'$course'".')">'.&mt('Enroll in course').'</a></td>';
1099: }
1100: $selfenroll = 1;
1101: }
1102: }
1103: if (!$selfenroll) {
1104: $output .= '<td> </td>';
1105: }
1106: $$countref ++;
1107: return $output;
1108: }
1109:
1110: sub identify_sections {
1111: my ($seclist) = @_;
1112: my @secnums;
1113: if ($seclist =~ /,/) {
1114: my @sections = split(/,/,$seclist);
1115: foreach my $sec (@sections) {
1116: $sec =~ s/:[^:]*$//;
1117: push(@secnums,$sec);
1118: }
1119: } else {
1120: if ($seclist =~ m/^([^:]+):/) {
1121: my $sec = $1;
1122: if (!grep(/^\Q$sec\E$/,@secnums)) {
1123: push(@secnums,$sec);
1124: }
1125: }
1126: }
1127: @secnums = sort {$a <=> $b} @secnums;
1128: $seclist = join(', ',@secnums);
1129: my $numsec = @secnums;
1130: return ($seclist,$numsec);
1131: }
1132:
1133: sub get_valid_classes {
1134: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1135: my $response;
1136: my %validations;
1137: @{$validations{'sections'}} = ();
1138: @{$validations{'xlists'}} = ();
1139: my $totalitems = 0;
1140: if ($seclist) {
1141: foreach my $sec (split(/, /,$seclist)) {
1142: my $class = $crscode.$sec;
1143: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1144: $class) eq 'ok') {
1145: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1146: push(@{$validations{'sections'}},$sec);
1147: $totalitems ++;
1148: }
1149: }
1150: }
1151: }
1152: if ($xlist_items) {
1153: foreach my $item (split(/, /,$xlist_items)) {
1154: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1155: $item) eq 'ok') {
1156: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1157: push(@{$validations{'xlists'}},$item);
1158: $totalitems ++;
1159: }
1160: }
1161: }
1162: }
1163: if ($totalitems > 0) {
1164: if (@{$validations{'sections'}}) {
1165: $response = &mt('Sections: ').
1166: join(', ',@{$validations{'sections'}}).'<br />';
1167: }
1168: if (@{$validations{'xlists'}}) {
1169: $response .= &mt('Courses: ').
1170: join(', ',@{$validations{'xlists'}});
1171: }
1172: }
1173: return $response;
1174: }
1175:
1176: sub javascript_select_filler {
1177: my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
1178: my $output = <<END;
1179: function courseSet() {
1180: var longtitles = new Array ("$longtitles_str");
1181: var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
1182: var valsem = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
1183: var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
1184: var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
1185: var idyears = new Array("$allidlist");
1186: var idyr = -1;
1187: var idsem = -1;
1188: var iddept = -1;
1189: document.$formname.Number.length = 0;
1190:
1191: $scripttext
1192:
1193: selYear = document.$formname.Year.selectedIndex-1;
1194: selSemester = document.$formname.Semester.selectedIndex-1;
1195: selDepartment = document.$formname.Department.selectedIndex-1;
1196: if (selYear == -1) {
1197: if (selSemester == -1) {
1198: if (selDepartment > -1) {
1199: document.$formname.Number.options[0] = new Option('All','0',false,false);
1200: for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
1201: document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
1202:
1203: }
1204: }
1205: else {
1206: document.$formname.Number.options[0] = new Option("All","0",true,true);
1207: }
1208: }
1209: else {
1210: if (selDepartment > -1) {
1211: for (var i=0; i<idcse_by_sem_sems.length; i++) {
1212: if (idcse_by_sem_sems[i] == valsem) {
1213: idsem = i;
1214: }
1215: }
1216: if (idsem != -1) {
1217: for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
1218: if (idcse_by_sem_dept[idsem][i] == valdept) {
1219: iddept = i;
1220: }
1221: }
1222: }
1223: if (iddept != -1) {
1224: document.$formname.Number.options[0] = new Option('All','0',false,false);
1225: for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
1226: document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
1227: }
1228: }
1229: else {
1230: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1231: }
1232: }
1233: else {
1234: document.$formname.Number.options[0] = new Option("All","0",true,true);
1235: }
1236: }
1237: }
1238: else {
1239: if (selSemester == -1) {
1240: if (selDepartment > -1) {
1241: for (var i=0; i<idcse_by_yr_year.length; i++) {
1242: if (idcse_by_yr_year[i] == valyr) {
1243: idyr = i;
1244: }
1245: }
1246: if (idyr != -1) {
1247: for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
1248: if (idcse_by_yr_dept[idyr][i] == valdept) {
1249: iddept = i;
1250: }
1251: }
1252: }
1253: if (iddept != -1) {
1254: document.$formname.Number.options[0] = new Option('All','0',false,false);
1255: for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
1256: document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
1257: }
1258: }
1259: else {
1260: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1261: }
1262: }
1263: else {
1264: document.$formname.Number.options[0] = new Option("All","0",true,true);
1265: }
1266: }
1267: else {
1268: if (selDepartment > -1) {
1269: for (var k=0; k<idyears.length; k++) {
1270: if (idyears[k] == valyr) {
1271: idyr = k;
1272: }
1273: }
1274: if (idyr != -1) {
1275: for (var k=0; k<idsems[idyr].length; k++) {
1276: if (idsems[idyr][k] == valsem) {
1277: idsem = k;
1278: }
1279: }
1280: }
1281: if (idsem != -1) {
1282: for (var k=0; k<idcodes[idyr][idsem].length; k++) {
1283: if (idcodes[idyr][idsem][k] == valdept) {
1284: iddept = k;
1285: }
1286: }
1287: }
1288: if (iddept != -1) {
1289: document.$formname.Number.options[0] = new Option('All','0',false,false);
1290: for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
1291: var display = idcourses[idyr][idsem][iddept][i];
1292: if (longtitles[3] == 1) {
1293: if (idcourseslongs[idyr][idsem][iddept][i] != "") {
1294: display = idcourseslongs[idyr][idsem][iddept][i]
1295: }
1296: }
1297: document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
1298: }
1299: }
1300: else {
1301: document.$formname.Number.options[0] = new Option('No courses','0',true,true);
1302: }
1303: }
1304: else {
1305: document.$formname.Number.options[0] = new Option('All','0',true,true);
1306: }
1307: }
1308: document.$formname.Number.selectedIndex = 0
1309: }
1310: }
1311: END
1312: return $output;
1313: }
1314:
1315: sub autoenroll_info {
1316: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1317: my $autoenrolldates = &mt('Not enabled');
1318: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
1319: my ($autostart,$autoend);
1320: if ( defined($coursehash->{'internal.autostart'}) ) {
1321: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
1322: }
1323: if ( defined($coursehash->{'internal.autoend'}) ) {
1324: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
1325: }
1326: if ($coursehash->{'internal.autostart'} > $now) {
1327: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1328: $autoenrolldates = &mt('Not enabled');
1329: } else {
1330: my $valid_classes =
1331: &get_valid_classes($seclist,$xlist_items,$code,
1332: $owners,$cdom,$cnum);
1333: if ($valid_classes ne '') {
1334: $autoenrolldates = &mt('Not enabled<br />Starts: ').
1335: $autostart.'<br />'.$valid_classes; }
1336: }
1337: } else {
1338: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1339: $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
1340: } else {
1341: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1342: $code,$owners,$cdom,$cnum);
1343: if ($valid_classes ne '') {
1344: $autoenrolldates = &mt('Currently enabled<br />').
1345: $valid_classes;
1346: }
1347: }
1348: }
1349: }
1350: return $autoenrolldates;
1351: }
1352:
1353: sub user_is_known {
1354: my $known = 0;
1355: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
1356: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
1357: $known = 1;
1358: }
1359: return $known;
1360: }
1361:
1362: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>