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