1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
4: # $Id: coursecatalog.pm,v 1.83 2014/04/28 14:23:47 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: $env{'form.showdom'} = &LONCAPA::clean_domain($env{'form.showdom'});
70: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
71: $codedom = $env{'form.showdom'};
72: } else {
73: $env{'form.showdom'} = '';
74: }
75: }
76: my $domdesc = &Apache::lonnet::domain($codedom,'description');
77: &Apache::lonhtmlcommon::clear_breadcrumbs();
78:
79: my %domconfig =
80: &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
81: my $knownuser = &user_is_known();
82:
83: my ($cathash,$cattype);
84: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
85: $cathash = $domconfig{'coursecategories'}{'cats'};
86: if ($knownuser) {
87: $cattype = $domconfig{'coursecategories'}{'auth'};
88: } else {
89: $cattype = $domconfig{'coursecategories'}{'unauth'};
90: }
91: } else {
92: $cathash = {};
93: $cattype = 'std';
94: }
95: if ($cattype eq 'none') {
96: $r->print(&Apache::loncommon::start_page('Course/Community Catalog'));
97: &Apache::lonhtmlcommon::add_breadcrumb
98: ({href=>"/adm/coursecatalog",
99: text=>"Course/Community Catalog"});
100: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
101: if ($knownuser) {
102: $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
103: } else {
104: if ($domconfig{'coursecategories'}{'auth'} eq 'none') {
105: $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
106: } else {
107: $r->print('<div>'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
108: }
109: }
110: $r->print(&Apache::loncommon::end_page());
111: return OK;
112: }
113:
114: my $cnum;
115: if ($cattype eq 'codesrch') {
116: my ($uniquecode,$codemsg,$brtext);
117: if ($env{'form.uniquecode'}) {
118: $uniquecode = $env{'form.uniquecode'};
119: $uniquecode =~ s/^\s+|\s+$//g;
120: }
121: my $js = '<script type="text/javascript">'."\n".
122: '// <![CDATA['."\n".
123: &courselink_javascript()."\n".
124: '// ]]>'."\n".
125: '</script>'."\n";
126: $r->print(&Apache::loncommon::start_page('Search for a Course/Community',$js));
127: if ($uniquecode =~ /^\w{6}$/) {
128: &Apache::lonhtmlcommon::add_breadcrumb
129: ({href=>"/adm/coursecatalog",
130: text=>"Course/Community Catalog"});
131: $brtext = 'Search Result';
132: } else {
133: $brtext = 'Course/Community Catalog';
134: }
135: &Apache::lonhtmlcommon::add_breadcrumb
136: ({href=>"/adm/coursecatalog",
137: text=>"$brtext"});
138: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
139: $r->print(&coursesearch($codedom,$domdesc,$uniquecode));
140: if ($uniquecode =~ /^\w{6}$/) {
141: $r->print('<hr />');
142: my $confname = $codedom.'-domainconfig';
143: my %codes = &Apache::lonnet::get('uniquecodes',[$uniquecode],$codedom,$confname);
144: if ($codes{$uniquecode}) {
145: $cnum = $codes{$uniquecode};
146: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.',
147: $cnum,undef,undef,'.',1);
148: if (keys(%courses)) {
149: $env{'form.coursenum'} = $cnum;
150: my %courseinfo = &build_courseinfo_hash(\%courses,$knownuser,$codedom);
151: undef($env{'form.coursenum'});
152: if (ref($courseinfo{$codedom.'_'.$cnum}) eq 'HASH') {
153: $r->print(&Apache::lonhtmlcommon::start_pick_box());
154: my @cols = ('title','ownerlastnames','seclist','access');
155: my %lt = &Apache::lonlocal::texthash(
156: title => 'Title',
157: ownerlastnames => 'Owner & Co-owner(s)',
158: seclist => 'Sections',
159: access => 'Default Access Dates for Students',
160: );
161: my @shown;
162: foreach my $item (@cols) {
163: if ($courseinfo{$codedom.'_'.$cnum}{$item}) {
164: push(@shown,$item);
165: }
166: }
167: my $num = 0;
168: foreach my $item (@shown) {
169: $num ++;
170: $r->print(&Apache::lonhtmlcommon::row_title($lt{$item}).
171: $courseinfo{$codedom.'_'.$cnum}{$item});
172: if ($item eq 'title') {
173: if ($courseinfo{$codedom.'_'.$cnum}{'showsyllabus'}) {
174: $r->print(' <font size="-2">'.
175: '<a href="javascript:ToSyllabus('."'$codedom','$cnum'".')">'.
176: &mt('Syllabus').'</a></font>');
177: }
178: }
179: my $arg = ( $num == scalar(@shown) ? 1 : '' );
180: $r->print(&Apache::lonhtmlcommon::row_closure($arg));
181: }
182: $r->print(&Apache::lonhtmlcommon::end_pick_box());
183: my $selfenroll = &selfenroll_status($courseinfo{$codedom.'_'.$cnum},$codedom.'_'.$cnum);
184: if ($selfenroll) {
185: $r->print('<br />'.$selfenroll);
186: }
187: $r->print('<form name="linklaunch" method="post" action="">'."\n".
188: '<input type="hidden" name="backto" value="coursecatalog" />'."\n".
189: '<input type="hidden" name="courseid" value="" />'."\n".
190: '</form>'."\n");
191:
192: } else {
193: $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');
194: }
195: } else {
196: $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');
197: }
198: } else {
199: $codemsg = &mt('No match');
200: }
201: }
202: $r->print('<br />'.&Apache::loncommon::end_page());
203: return OK;
204: } else {
205: if ($env{'form.coursenum'}) {
206: $cnum = $env{'form.coursenum'};
207: }
208: }
209:
210: if ($env{'form.catalog_maxdepth'} ne '') {
211: $env{'form.catalog_maxdepth'} =~ s{\D}{}g;
212: }
213:
214: my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$subcats);
215: if ($env{'form.withsubcats'}) {
216: $subcats = \%subcathash;
217: }
218: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
219: \%idx,\@jsarray,$subcats);
220: my ($numtitles,@codetitles);
221: if (($env{'form.coursenum'} ne '') && ($knownuser)) {
222: &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems,\@codetitles);
223: } else {
224: my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
225: my $wasacctext = &get_wasactive_text();
226: my $catjs = <<"ENDSCRIPT";
227:
228: function setCatDepth(depth) {
229: document.coursecats.catalog_maxdepth.value = depth;
230: if (depth == '') {
231: document.coursecats.currcat_0.value = '';
232: }
233: document.coursecats.submit();
234: return;
235: }
236:
237: function changeSort(caller) {
238: document.$formname.sortby.value = caller;
239: document.$formname.submit();
240: }
241:
242: function setCourseId(caller) {
243: document.$formname.coursenum.value = caller;
244: document.$formname.submit();
245: }
246:
247: ENDSCRIPT
248: $catjs .= &courselink_javascript();
249: if (&user_is_dc($codedom)) {
250: $catjs .= <<ENDTOGGJS
251:
252: function toggleStatuses() {
253: if (document.$formname.showdetails.checked) {
254: document.getElementById('statuschoice').style.display='block';
255: document.getElementById('statuscell').style.borderLeft='1px solid';
256: } else {
257: document.getElementById('statuschoice').style.display='none';
258: document.getElementById('statuscell').style.borderLeft='0px';
259: }
260: return;
261: }
262:
263: function toggleWasActive() {
264: if (document.getElementById('counts_Previous')) {
265: if (document.getElementById('counts_Previous').checked) {
266: document.getElementById('choosewasactive').style.display='block';
267: document.getElementById('choosewasacctext').innerHTML = '$wasacctext';
268: } else {
269: document.getElementById('choosewasactive').style.display='none';
270: document.getElementById('choosewasacctext').innerHTML = '';
271: }
272: }
273: return;
274: }
275:
276: ENDTOGGJS
277: }
278: if ($env{'form.currcat_0'} eq 'instcode::0') {
279: $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
280: $catlinks,$catjs,\@codetitles,$cattype);
281: if ($env{'form.state'} eq 'listing') {
282: $r->print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
283: \@codetitles));
284: }
285: } else {
286: my (%add_entries);
287: my ($currdepth,$deeper) = &get_depth_values();
288: if ($selitem) {
289: my $alert = &mt('Choose a subcategory to display');
290: if (!$deeper) {
291: $alert = &mt('Choose a category to display');
292: }
293: $catjs .= <<ENDJS;
294: function check_selected() {
295: if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
296: alert('$alert');
297: return false;
298: }
299: }
300: ENDJS
301: }
302: $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
303: &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks,undef,$cattype);
304: if ($env{'form.currcat_0'} ne '') {
305: $r->print('<form name="'.$formname.
306: '" method="post" action="/adm/coursecatalog">'.
307: &additional_filters($codedom,$has_subcats)."\n");
308: $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
309: $deeper.'" />'."\n");
310: for (my $i=0; $i<$deeper; $i++) {
311: $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
312: }
313: my $display_button;
314: if ($env{'form.currcat_0'} eq 'communities::0') {
315: $display_button = &mt('Display communities');
316: } else {
317: $display_button = &mt('Display courses');
318: }
319: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
320: '<input type="hidden" name="sortby" value="" />'."\n".
321: '<input type="hidden" name="state" value="listing" />'."\n".
322: '<input type="hidden" name="showdom" value="'.
323: $env{'form.showdom'}.'" />'.
324: '<input type="submit" name="catalogfilter" value="'.
325: $display_button.'" /></form><br /><br />');
326: }
327: if ($env{'form.state'} eq 'listing') {
328: $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles));
329: }
330: }
331: }
332: $r->print('<br />'.&Apache::loncommon::end_page());
333: return OK;
334: }
335:
336: sub course_details {
337: my ($r,$codedom,$formname,$domdesc,$trails,$allitems,$codetitles) = @_;
338: my $output;
339: my %add_entries = (topmargin => "0",
340: marginheight => "0",);
341: my $js = '<script type="text/javascript">'."\n".
342: &courselink_javascript().'</script>'."\n";
343: my $start_page =
344: &Apache::loncommon::start_page('Course/Community Catalog',$js,
345: {'add_entries' => \%add_entries, });
346: $r->print($start_page);
347: if ($env{'form.numtitles'} > 0) {
348: &Apache::lonhtmlcommon::add_breadcrumb
349: ({href=>"/adm/coursecatalog",
350: text=>"Course/Community Catalog"});
351: }
352: my $brtextone = 'Course listing';
353: my $brtexttwo = 'Course details';
354: if ($env{'form.currcat_0'} eq 'communities::0') {
355: $brtextone = 'Community listing';
356: $brtexttwo = 'Community details';
357: }
358: &Apache::lonhtmlcommon::add_breadcrumb
359: ({href=>"javascript:document.$formname.submit()",
360: text=>$brtextone},
361: {text=>$brtexttwo});
362: $r->print(
363: &Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog').
364: '<h2>'.
365: (($env{'form.currcat_0'} eq 'communities::0') ?
366: &mt('Detailed community information:') :
367: &mt('Detailed course information:')).
368: '</h2>'.
369: &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles).
370: '<br />'.
371: '<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
372: &Apache::lonhtmlcommon::actionbox([
373: '<a href = "javascript:document.coursecatalog.submit()">'.
374: (($env{'form.currcat_0'} eq 'communities::0') ?
375: &mt('Back to community listing') : &mt('Back to course listing')).
376: '</a>'
377: ]).
378: &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
379: 'showdetails','courseid']).
380: '</form>');
381: return;
382: }
383:
384: sub coursesearch {
385: my ($codedom,$domdesc,$uniquecode) = @_;
386: my %lt = &Apache::lonlocal::texthash (
387: crlk => 'Course look-up',
388: code => 'Code',
389: ifyo => 'Enter the character code (six letters and numbers)',
390: srch => 'Find course',
391: );
392: return <<"END";
393: <h3>$lt{'crlk'} ($domdesc)</h3>
394: $lt{'ifyo'}
395: <form name="searchbycode" method="post" action="">
396: <span class="LC_nobreak">
397: <input type="text" value="$uniquecode" size="6" name="uniquecode" />
398: <br />
399: <input type="submit" value="$lt{'srch'}" name="srch" /></span>
400: </form>
401: END
402: }
403:
404: sub courselink_javascript {
405: return <<"END";
406:
407: function ToSyllabus(cdom,cnum) {
408: if (cdom == '' || cdom == null) {
409: return;
410: }
411: if (cnum == '' || cnum == null) {
412: return;
413: }
414: document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
415: document.linklaunch.submit();
416: }
417:
418: function ToSelfenroll(courseid) {
419: if (courseid == '') {
420: return;
421: }
422: document.linklaunch.action = "/adm/selfenroll";
423: document.linklaunch.courseid.value = courseid;
424: document.linklaunch.submit();
425: }
426:
427: END
428: }
429:
430: sub instcode_course_selector {
431: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles,$cattype) = @_;
432: my %coursecodes = ();
433: my %codes = ();
434: my %cat_titles = ();
435: my %cat_order = ();
436: my %cat_items;
437: my $caller = 'global';
438: my $format_reply;
439: my %add_entries = (topmargin => "0",
440: marginheight => "0",);
441: my ($jscript,$totcodes,$numtitles,$lasttitle) =
442: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
443: \%cat_items,$codetitles,\%cat_titles,\%cat_order);
444: my $js = '<script type="text/javascript">'."\n".
445: '// <![CDATA['."\n".
446: "$jscript\n$catjs\n".
447: '// ]]>'."\n".
448: '</script>';
449: if ($totcodes) {
450: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
451: $add_entries{'onLoad'} = 'setElements();';
452: }
453: if (&user_is_dc($codedom)) {
454: $add_entries{'onLoad'} .= ' toggleStatuses();toggleWasActive();'
455: }
456: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
457: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
458: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
459: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
460: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
461: '<input type="hidden" name="currcat_0" value="instcode::0" />'.
462: &additional_filters($codedom));
463: if ($numtitles > 0) {
464: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
465: &Apache::courseclassifier::build_instcode_selectors($numtitles,
466: $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order));
467: }
468: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
469: '<input type="hidden" name="sortby" value="" />'."\n".
470: '<input type="hidden" name="state" value="listing" />'."\n".
471: '<input type="submit" name="catalogfilter" value="'.
472: &mt('Display courses').'" />'.
473: '<input type="hidden" name="numtitles" value="'.$numtitles.
474: '" /></form><br /><br />');
475: } else {
476: $js = '<script type="text/javascript">'."\n".
477: '// <![CDATA['."\n".
478: "$catjs\n".
479: '// ]]>'."\n".
480: '</script>';
481: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
482: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
483: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
484: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
485: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
486: '<input type="hidden" name="currcat_0" value="instcode::0" />');
487: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
488: }
489: return $numtitles;
490: }
491:
492: sub cat_header {
493: my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles,$cattype) = @_;
494: my $start_page =
495: &Apache::loncommon::start_page('Course/Community Catalog',$js,
496: { 'add_entries' => $add_entries, });
497: $r->print($start_page);
498: my $brtext = 'Course listing';
499: if ($env{'form.currcat_0'} eq 'communities::0') {
500: $brtext = 'Community listing';
501: }
502: if ($env{'form.state'} eq 'listing') {
503: if ($numtitles > 0) {
504: &Apache::lonhtmlcommon::add_breadcrumb
505: ({href=>"/adm/coursecatalog",
506: text=>"Course/Community Catalog"},
507: {text=>$brtext});
508: } else {
509: &Apache::lonhtmlcommon::add_breadcrumb
510: ({text=>$brtext});
511: }
512: } else {
513: &Apache::lonhtmlcommon::add_breadcrumb
514: ({href=>"/adm/coursecatalog",
515: text=>"Course/Community Catalog"});
516: }
517: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
518: if ($cattype eq 'std') {
519: my $onchange = 'this.form.submit()';
520: $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
521: '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
522: &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
523: if (!$onchange) {
524: $r->print(' <input type="submit" name="godom" value="'.&mt('Change').'" />');
525: }
526: $r->print('</td></tr></table></form>');
527: }
528: $r->print('<form name="coursecats" method="post" action="/adm/coursecatalog"'.
529: ' onsubmit="return check_selected();">'.
530: '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
531: return;
532: }
533:
534: sub category_breadcrumbs {
535: my ($dom,@cats) = @_;
536: my $crumbsymbol = ' ▶ ';
537: my ($currdepth,$deeper) = &get_depth_values();
538: my $currcat_str =
539: '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" />'.
540: '<input type="hidden" name="showdom" value="'.$dom.'" />';
541: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
542: my $has_subcats;
543: my $selitem;
544: if (ref($cats[0]) eq 'ARRAY') {
545: if (@{$cats[0]} == 0) {
546: $catlinks .= &mt('No categories defined in this domain');
547: } elsif (@{$cats[0]} == 1) {
548: if ($cats[0][0] eq 'instcode') {
549: $catlinks .= &mt('Official courses (with institutional codes)');
550: $env{'form.currcat_0'} = 'instcode::0';
551: } elsif ($cats[0][0] eq 'communities') {
552: $catlinks .= &mt('Communities');
553: $env{'form.currcat_0'} = 'communities::0';
554: } else {
555: my $name = $cats[0][0];
556: my $item = &escape($name).'::0';
557: $catlinks .= $name;
558: $env{'form.currcat_0'} = $item;
559: }
560: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
561: } else {
562: $catlinks .= &main_category_selector(@cats);
563: if (($env{'form.currcat_0'} ne '') &&
564: ($env{'form.currcat_0'} ne 'instcode::0')) {
565: $catlinks .= $crumbsymbol;
566: }
567: }
568: } else {
569: $catlinks .= &mt('Official courses (with institutional codes)');
570: $env{'form.currcat_0'} = 'instcode::0';
571: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
572: }
573: if ($deeper) {
574: for (my $i=1; $i<=$deeper; $i++) {
575: my $shallower = $i-1;
576: next if ($shallower == 0);
577: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
578: if ($cat ne '') {
579: $catlinks .= '<td valign="top">'.
580: '<select name="currcat_'.$shallower.'" onchange="'.
581: 'setCatDepth('."'$shallower'".');this.form.submit();">';
582: if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
583: $catlinks .= '<option value="">'.&mt('De-select').'</option>';
584: for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
585: my $name = $cats[$shallower]{$container}[$j];
586: my $item = &escape($name).':'.&escape($container).':'.$shallower;
587: my $selected = '';
588: if ($item eq $env{'form.currcat_'.$shallower}) {
589: $selected = ' selected="selected"';
590: }
591: $catlinks .=
592: '<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
593: }
594: }
595: $catlinks .= '</select>';
596: }
597: unless ($i == $deeper) {
598: $catlinks .= $crumbsymbol;
599: }
600: }
601: my ($cat,$container,$depth);
602: if ($env{'form.currcat_'.$currdepth} eq '') {
603: my $shallower = $currdepth - 1;
604: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
605: } else {
606: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
607: }
608: my $deeperlevel = $depth +1;
609: if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') {
610: $has_subcats = 1;
611: my $buttontext = &mt('Show subcategories');
612: my $selitem = 'currcat_'.$deeperlevel;
613: $catlinks .= ' <select name="'.$selitem.'" onchange="this.form.submit()">';
614: if (@{$cats[$deeperlevel]{$cat}}) {
615: $catlinks .= '<option value="" selected="selected">'.
616: &mt('Subcategory ...').'</option>';
617: }
618: for (my $k=0; $k<@{$cats[$deeperlevel]{$cat}}; $k++) {
619: my $name = $cats[$deeperlevel]{$cat}[$k];
620: my $item = &escape($name).':'.&escape($cat).':'.$deeperlevel;
621: $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
622: }
623: $catlinks .= '</select>'."\n";
624: } elsif ($cat ne 'instcode') {
625: $catlinks .= ' '.&mt('(No subcategories)');
626: }
627: } else {
628: $selitem = 'currcat_0';
629: }
630: $catlinks .= $currcat_str.'</td></tr></table></td>';
631: return ($catlinks,$has_subcats,$selitem);
632: }
633:
634: sub main_category_selector {
635: my (@cats) = @_;
636: my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
637: if (ref($cats[0]) eq 'ARRAY') {
638: if (@{$cats[0]} > 1) {
639: my $selected = '';
640: if ($env{'form.currcat_0'} eq '') {
641: $selected = ' selected="selected"';
642: }
643: $maincatlinks .=
644: '<option value=""'.$selected.'>'.&mt('Select').'</option>'."\n";
645: }
646: for (my $i=0; $i<@{$cats[0]}; $i++) {
647: my $name = $cats[0][$i];
648: my $item = &escape($name).'::0';
649: my $selected;
650: if ($env{'form.currcat_0'} eq $item) {
651: $selected = ' selected="selected"';
652: }
653: $maincatlinks .= '<option value="'.$item.'"'.$selected.'>';
654: if ($name eq 'instcode') {
655: $maincatlinks .= &mt('Official courses (with institutional codes)');
656: } elsif ($name eq 'communities') {
657: $maincatlinks .= &mt('Communities');
658: } else {
659: $maincatlinks .= $name;
660: }
661: $maincatlinks .= '</option>'."\n";
662: }
663: $maincatlinks .= '</select>'."\n";
664: }
665: return $maincatlinks;
666: }
667:
668: sub get_depth_values {
669: my $currdepth = 0;
670: my $deeper = 0;
671: if ($env{'form.catalog_maxdepth'} ne '') {
672: $currdepth = $env{'form.catalog_maxdepth'};
673: if ($env{'form.currcat_'.$currdepth} eq '') {
674: $deeper = $currdepth;
675: } else {
676: $deeper = $currdepth + 1;
677: }
678: }
679: return ($currdepth,$deeper);
680: }
681:
682: sub additional_filters {
683: my ($codedom,$has_subcats) = @_;
684: my $is_dc = &user_is_dc($codedom);
685: my $output = '<div class="LC_left_float">';
686: if ($is_dc) {
687: $output .= '<fieldset><legend>'.&mt('Options').'</legend>';
688: }
689: $output .= '<table><tr><td valign="top">';
690: if (($env{'form.currcat_0'} ne 'instcode::0') &&
691: ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
692: my $include_subcat_status;
693: if ($env{'form.withsubcats'}) {
694: $include_subcat_status = 'checked="checked" ';
695: }
696: my $counter = $env{'form.catalog_maxdepth'};
697: if ($counter > 0) {
698: if ($env{'form.state'} eq 'listing') {
699: $counter --;
700: } elsif ($env{'form.currcat_'.$counter} eq '') {
701: $counter --;
702: }
703: }
704: my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
705: if ($catname ne '') {
706: $output .= '<span class="LC_nobreak"><label>'.
707: '<input type="checkbox" name="withsubcats" value="1" '.
708: $include_subcat_status.'/>'.
709: &mt('Include subcategories within "[_1]"',
710: &unescape($catname)).'</label></span><br />';
711: }
712: }
713: my $show_selfenroll_status;
714: if ($env{'form.showselfenroll'}) {
715: $show_selfenroll_status = 'checked="checked" ';
716: }
717: my $selfenroll_text;
718: if ($env{'form.currcat_0'} eq 'communities::0') {
719: $selfenroll_text = &mt('Only show communities which currently allow self-enrollment (or will allow it in the future)');
720: } else {
721: $selfenroll_text = &mt('Only show courses which currently allow self-enrollment (or will allow it in the future)');
722: }
723: $output .= '<span class="LC_nobreak">'.
724: '<label><input type="checkbox" name="showselfenroll" value="1" '.
725: $show_selfenroll_status.'/>'.$selfenroll_text.
726: '</label></span><br />';
727: if ($is_dc) {
728: my ($titlesref,$orderref) = &get_statustitles('filters');
729: my $showdetails_status;
730: if ($env{'form.showdetails'}) {
731: $showdetails_status = 'checked="checked" ';
732: }
733: my $showhidden_status;
734: if ($env{'form.showhidden'}) {
735: $showhidden_status = 'checked="checked" ';
736: }
737: my @currstatuses = &Apache::loncommon::get_env_multiple('form.showcounts');
738: my $dc_title = &Apache::lonnet::plaintext('dc');
739: my ($details_text,$hidden_text,$statusdisplay,$cellborder);
740: my $wasactivedisplay = 'none';
741: if ($env{'form.showdetails'}) {
742: $statusdisplay = 'block';
743: $cellborder = 'border-left: 1px solid;';
744: if (grep(/^Previous$/,@currstatuses)) {
745: $wasactivedisplay = 'block';
746: }
747: } else {
748: $statusdisplay = 'none';
749: $cellborder = 'border-left: 0px';
750: }
751: if ($env{'form.currcat_0'} eq 'communities::0') {
752: $details_text = &mt('Show full details for each community ([_1] only)',$dc_title);
753: $hidden_text = &mt('Include communities set to be hidden from catalog ([_1] only)',$dc_title);
754: } else {
755: $details_text = &mt('Show full details for each course ([_1] only)',$dc_title);
756: $hidden_text = &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title);
757: }
758: $output .= '<span class="LC_nobreak">'.
759: '<label><input type="checkbox" name="showhidden" value="1" '.
760: $showhidden_status.'/>'.$hidden_text.
761: '</label></span><br />'."\n".
762: '<span class="LC_nobreak">'.
763: '<label><input type="checkbox" name="showdetails" value="1" '.
764: $showdetails_status.'onclick="toggleStatuses();" />'.
765: $details_text.'</label></span></td>'."\n".
766: '<td id="statuscell" valign="top" style="'.$cellborder.'">'.
767: '<div id="statuschoice" style="display:'.$statusdisplay.'">';
768: if (ref($orderref) eq 'ARRAY') {
769: if (@{$orderref} > 0) {
770: foreach my $type (@{$orderref}) {
771: my $checked;
772: if (grep(/^\Q$type\E$/,@currstatuses)) {
773: $checked = ' checked="checked"';
774: }
775: my $title;
776: if (ref($titlesref) eq 'HASH') {
777: $title = $titlesref->{$type};
778: }
779: unless ($title) {
780: $title = &mt($type);
781: }
782: my $onclick;
783: if ($type eq 'Previous') {
784: $onclick = ' onclick="toggleWasActive();"';
785: }
786: $output .= '<span class="LC_nobreak">'.
787: '<label><input type="checkbox" id="counts_'.$type.'"'.
788: ' name="showcounts" value="'.$type.'"'.$checked.$onclick.
789: ' />'.$title.'</label></span>';
790: if ($type eq 'Previous') {
791: my %milestonetext = &Apache::lonlocal::texthash (
792: accessend => 'immediately prior to default end access date',
793: enrollend => 'immediately prior to end date for auto-enrollment',
794: date => 'immediately prior to specific date:',
795: );
796: my @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
797: $output .= '<span id="choosewasacctext" class="LC_nobreak">';
798: if ($checked) {
799: $output .= &get_wasactive_text();
800: }
801: $output .= '</span>'.
802: '<div id="choosewasactive" style="display:'.$wasactivedisplay.'">'.
803: '<table>';
804: my @milestones = ('accessend');
805: if (&Apache::lonnet::auto_run(undef,$codedom)) {
806: push(@milestones,'enrollend');
807: }
808: push(@milestones,'date');
809: foreach my $item (@milestones) {
810: my $checked;
811: if ($env{'form.state'} eq 'listing') {
812: if ($env{'form.wasactive'} eq $item) {
813: $checked = ' checked="checked"';
814: }
815: } elsif ($item eq 'accessend') {
816: $checked = ' checked="checked"';
817: }
818: $output .=
819: '<tr><td width="10"> </td><td>'.
820: '<span class="LC_nobreak"><label>'.
821: '<input type="radio" value="'.$item.'" name="wasactive"'.$checked.' />'.
822: $milestonetext{$item}.'</label></span>';
823: if ($item eq 'date') {
824: my $wasactiveon;
825: if (grep(/^Previous$/,@currstatuses)) {
826: $wasactiveon =
827: &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
828: } else {
829: $wasactiveon = 'now';
830: }
831: $output .= ' '.
832: &Apache::lonhtmlcommon::date_setter('coursecatalog',
833: 'wasactiveon',
834: $wasactiveon,
835: '','','',1,'',
836: '','',1);
837: }
838: $output .= '</td></tr>';
839: }
840: $output .= '</table></div>';
841: }
842: $output .= '<br />';
843: }
844: }
845: }
846: $output .= '</div></td>';
847: } else {
848: $output .= '</td>';
849: }
850: $output .= '</tr></table></fieldset></div>'.
851: '<div style="clear:both;margin:0;"></div>';
852: return $output;
853: }
854:
855: sub user_is_dc {
856: my ($codedom) = @_;
857: if (exists($env{'user.role.dc./'.$codedom.'/'})) {
858: my $livedc = 1;
859: my $now = time;
860: my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
861: if ($start && $start>$now) { $livedc = 0; }
862: if ($end && $end <$now) { $livedc = 0; }
863: return $livedc;
864: }
865: return;
866: }
867:
868: sub get_statustitles {
869: my ($caller) = @_;
870: my @status_order = ('Active','Future','Previous');
871: my %status_title;
872: if ($caller eq 'filters') {
873: %status_title = &Apache::lonlocal::texthash(
874: Previous => 'Show count for past access',
875: Active => 'Show count for current student access',
876: Future => 'Show count for future student access',
877: );
878: if ($env{'form.currcat_0'} eq 'communities::0') {
879: $status_title{'Active'} = 'Show count for current member access';
880: $status_title{'Future'} = 'Show count for future member access';
881: }
882: } else {
883: %status_title = &Apache::lonlocal::texthash(
884: Previous => 'Previous access',
885: Active => 'Current access',
886: Future => 'Future access',
887: );
888: }
889: return (\%status_title,\@status_order);
890: }
891:
892: sub get_wasactive_text {
893: my $wasacctext = ' -- ';
894: if ($env{'form.currcat_0'} eq 'communities::0') {
895: $wasacctext .= &mt('where member access status was current ...');
896: } else {
897: $wasacctext .= &mt('where student access status was current ...');
898: }
899: return $wasacctext;
900: }
901:
902: sub search_official_courselist {
903: my ($domain,$numtitles,$codetitles) = @_;
904: my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles,$codetitles);
905: my $showhidden;
906: if (&user_is_dc($domain)) {
907: $showhidden = $env{'form.showhidden'};
908: }
909: my %courses =
910: &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
911: 'Course',1,$env{'form.showselfenroll'},undef,
912: $showhidden,'coursecatalog');
913: return %courses;
914: }
915:
916: sub search_courselist {
917: my ($domain,$subcats) = @_;
918: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
919: my $filter = $env{'form.currcat_'.$cat_maxdepth};
920: if (($filter eq '') && ($cat_maxdepth > 0)) {
921: my $shallower = $cat_maxdepth - 1;
922: $filter = $env{'form.currcat_'.$shallower};
923: }
924: my %courses;
925: my $filterstr;
926: if ($filter ne '') {
927: if ($env{'form.withsubcats'}) {
928: if (ref($subcats) eq 'HASH') {
929: if (ref($subcats->{$filter}) eq 'ARRAY') {
930: $filterstr = join('&',@{$subcats->{$filter}});
931: if ($filterstr ne '') {
932: $filterstr = $filter.'&'.$filterstr;
933: }
934: } else {
935: $filterstr = $filter;
936: }
937: } else {
938: $filterstr = $filter;
939: }
940: } else {
941: $filterstr = $filter;
942: }
943: my ($showhidden,$typefilter);
944: if (&user_is_dc($domain)) {
945: $showhidden = $env{'form.showhidden'};
946: }
947: if ($env{'form.currcat_0'} eq 'communities::0') {
948: $typefilter = 'Community';
949: } else {
950: $typefilter = '.';
951: }
952: %courses =
953: &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
954: $typefilter,1,$env{'form.showselfenroll'},
955: $filterstr,$showhidden,'coursecatalog');
956: }
957: return %courses;
958: }
959:
960: sub print_course_listing {
961: my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles) = @_;
962: my $output;
963: my %courses;
964: my $knownuser = &user_is_known();
965: my $details = $env{'form.coursenum'};
966: if (&user_is_dc($domain)) {
967: if ($env{'form.showdetails'}) {
968: $details = 1;
969: }
970: }
971: if ($env{'form.coursenum'} ne '') {
972: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
973: $env{'form.coursenum'},
974: undef,undef,'.',1);
975: if (keys(%courses) == 0) {
976: $output = '<p class="LC_error">';
977: if ($env{'form.currcat_0'} eq 'communities::0') {
978: $output .= &mt('The courseID provided does not match a community in this domain.');
979: } else {
980: $output .= &mt('The courseID provided does not match a course in this domain.');
981: }
982: $output .= '</p>';
983: return $output;
984: }
985: } else {
986: if ($env{'form.currcat_0'} eq 'instcode::0') {
987: %courses = &search_official_courselist($domain,$numtitles,$codetitles);
988: } else {
989: %courses = &search_courselist($domain,$subcats);
990: }
991: if (keys(%courses) == 0) {
992: $output = '<p class="LC_info">';
993: if ($env{'form.currcat_0'} eq 'communities::0') {
994: $output .= &mt('No communities match the criteria you selected.');
995: } else {
996: $output .= &mt('No courses match the criteria you selected.');
997: }
998: $output .= '</p>';
999: return $output;
1000: }
1001: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
1002: $output = '<b>'.&mt('Note for students:').'</b> '
1003: .&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.')
1004: .'<br /><br />';
1005: }
1006: }
1007: my $now = time;
1008: $output .= &construct_data_table($knownuser,$domain,\%courses,$details,undef,
1009: $now,$trails,$allitems);
1010: $output .= "\n".'<form name="linklaunch" method="post" action="">'.
1011: '<input type="hidden" name="backto" value="coursecatalog" />'.
1012: '<input type="hidden" name="courseid" value="" />'.
1013: &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
1014: return $output;
1015: }
1016:
1017: sub construct_data_table {
1018: my ($knownuser,$domain,$courses,$details,$usersections,$now,$trails,$allitems) = @_;
1019: my %sortname;
1020: if (($details eq '') || ($env{'form.showdetails'})) {
1021: $sortname{'Code'} = 'code';
1022: $sortname{'Categories'} = 'cats';
1023: $sortname{'Title'} = 'title';
1024: $sortname{'Owner & Co-owner(s)'} = 'owner';
1025: }
1026: my $output = &Apache::loncommon::start_data_table().
1027: &Apache::loncommon::start_data_table_header_row();
1028: my @coltitles = ('Count');
1029: if ($env{'form.currcat_0'} eq 'instcode::0') {
1030: push(@coltitles,'Code');
1031: } else {
1032: push(@coltitles,'Categories');
1033: }
1034: push(@coltitles,('Sections','Crosslisted','Title','Owner & Co-owner(s)'));
1035: if (ref($usersections) eq 'HASH') {
1036: $coltitles[1] = 'Your Section';
1037: }
1038: foreach my $item (@coltitles) {
1039: $output .= '<th>';
1040: if (defined($sortname{$item})) {
1041: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
1042: } elsif ($item eq 'Count') {
1043: $output .= ' ';
1044: } else {
1045: $output .= &mt($item);
1046: }
1047: $output .= '</th>';
1048: }
1049: my (@fields,%fieldtitles,$wasactiveon);
1050: if ($knownuser) {
1051: if ($details) {
1052: if ($env{'form.currcat_0'} eq 'communities::0') {
1053: $output .= '<th>'.&mt('Default Access Dates for Members').'</th>'.
1054: '<th>'.&mt('Member Counts').'</th>';
1055: } else {
1056: $output .=
1057: '<th>'.&mt('Default Access Dates for Students').'</th>'.
1058: '<th>'.&mt('Student Counts').'</th>'.
1059: '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
1060: }
1061: my ($titlesref,$orderref) = &get_statustitles();
1062: my @statuses;
1063: if (&user_is_dc($domain)) {
1064: @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
1065: if (grep(/^Previous$/,@statuses)) {
1066: if ($env{'form.wasactive'} eq 'date') {
1067: $wasactiveon =
1068: &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
1069: } else {
1070: $wasactiveon = $env{'form.wasactive'};
1071: }
1072: }
1073: if (ref($orderref) eq 'ARRAY') {
1074: foreach my $status (@{$orderref}) {
1075: if (grep(/^\Q$status\E$/,@statuses)) {
1076: push(@fields,$status);
1077: }
1078: }
1079: }
1080: } else {
1081: @fields = ('Active','Future');
1082: }
1083: foreach my $status (@fields) {
1084: my $title;
1085: if (ref($titlesref) eq 'HASH') {
1086: $title = $titlesref->{$status};
1087: }
1088: unless ($title) {
1089: $title = &mt($status);
1090: }
1091: $fieldtitles{$status} = $title;
1092: }
1093: } else {
1094: $output .= '<th>'.&mt('Details').'</th>';
1095: }
1096: }
1097: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
1098: &Apache::loncommon::end_data_table_header_row();
1099: my (%numbers,%creditsum);
1100: my ($showcredits,$defofficial,$defunofficial,$deftextbook);
1101: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1102: unless ($env{'form.currcat_0'} eq 'communities::0') {
1103: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1104: $showcredits = 1;
1105: $defofficial = $domdefaults{'officialcredits'};
1106: $defunofficial = $domdefaults{'unofficialcredits'};
1107: $deftextbook = $domdefaults{'textbookcredits'};
1108: }
1109: }
1110: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$details,
1111: $usersections,\@fields,\%fieldtitles,
1112: $wasactiveon,\%numbers,\%creditsum,
1113: $showcredits,$defofficial,$defunofficial,$deftextbook);
1114: my %Sortby;
1115: foreach my $course (sort(keys(%{$courses}))) {
1116: if ($env{'form.sortby'} eq 'code') {
1117: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
1118: } elsif ($env{'form.sortby'} eq 'cats') {
1119: push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
1120: } elsif ($env{'form.sortby'} eq 'owner') {
1121: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
1122: } else {
1123: my $clean_title = $courseinfo{$course}{'title'};
1124: $clean_title =~ s/\W+//g;
1125: if ($clean_title eq '') {
1126: $clean_title = $courseinfo{$course}{'title'};
1127: }
1128: push(@{$Sortby{$clean_title}},$course);
1129: }
1130: }
1131: my @sorted_courses;
1132: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
1133: ($env{'form.sortby'} eq 'cats')) {
1134: @sorted_courses = sort(keys(%Sortby));
1135: } else {
1136: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1137: }
1138: my $count = 1;
1139: my $totalsec = 0;
1140: foreach my $item (@sorted_courses) {
1141: foreach my $course (@{$Sortby{$item}}) {
1142: $output.=&Apache::loncommon::start_data_table_row();
1143: $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
1144: \$count,$now,$course,$trails,$allitems,\%numbers);
1145: $output.=&Apache::loncommon::end_data_table_row();
1146: }
1147: }
1148: if (($knownuser) && ($count > 1) && $env{'form.showdetails'}) {
1149: if (&user_is_dc($domain)) {
1150: my %lt = &Apache::lonlocal::texthash (
1151: 'Active' => 'Total current students',
1152: 'Future' => 'Total future students',
1153: 'Previous' => 'Total previous students',
1154: 'courses' => 'Total unique codes and courses without codes',
1155: 'sections' => 'Total sections',
1156: 'xlists' => 'Total cross-listings',
1157: );
1158: if ($showcredits) {
1159: $lt{'cr_Active'} = &mt('Total current student credit hours');
1160: $lt{'cr_Future'} = &mt('Total future student credit hours');
1161: $lt{'cr_Previous'} = &mt('Total previous student credit hours');
1162: }
1163: if ($env{'form.currcat_0'} eq 'communities::0') {
1164: $lt{'courses'} = &mt('Total communities');
1165: $lt{'Active'} = &mt('Total current members');
1166: $lt{'Future'} = &mt('Total future members');
1167: $lt{'Previous'} = &mt('Total previous members');
1168: }
1169: my $colspan = 8;
1170: if ($showcredits) {
1171: $colspan = 4;
1172: }
1173: $output .= '<tr class="LC_footer_row">'.
1174: '<td colspan="2"> </td>'.
1175: '<td colspan="'.$colspan.'">'.
1176: '<table border="0">';
1177: foreach my $item ('courses','sections','xlists') {
1178: $output .= '<tr>'.
1179: '<td>'.$lt{$item}.'</td><td> </td>'.
1180: '<td align="right">'.$numbers{$item}.'</td>'.
1181: '</tr>'."\n";
1182: }
1183: if (@fields > 0) {
1184: foreach my $status (@fields) {
1185: $output .= '<tr>'.
1186: '<td>'.$lt{$status}.'</td><td> </td>'.
1187: '<td align="right">'.$numbers{$status}.'</td>'.
1188: '</tr>'."\n";
1189: }
1190: }
1191: $output .= '</table></td>';
1192: if ($showcredits) {
1193: $output .= '<td colspan="'.$colspan.'" valign="bottom"><table>';
1194: foreach my $status (@fields) {
1195: $output .= '<tr>'.
1196: '<td>'.$lt{'cr_'.$status}.'</td><td> </td>'.
1197: '<td align="right">'.$creditsum{$status}.'</td></tr>';
1198: }
1199: $output .= '</table></td></tr>';
1200: }
1201: }
1202: }
1203: $output .= &Apache::loncommon::end_data_table();
1204: return $output;
1205: }
1206:
1207: sub build_courseinfo_hash {
1208: my ($courses,$knownuser,$domain,$details,$usersections,$fields,$fieldtitles,
1209: $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_;
1210: my %courseinfo;
1211: my $now = time;
1212: my $gettotals;
1213: if ((keys(%{$courses}) > 0) && (&user_is_dc($domain)) && ($details)) {
1214: $gettotals = 1;
1215: }
1216: my (%uniquecodes,$nocodes,$defcreds);
1217: foreach my $course (keys(%{$courses})) {
1218: my $descr;
1219: if (ref($courses->{$course}) eq 'HASH') {
1220: $descr = $courses->{$course}{'description'};
1221: }
1222: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
1223: $cleandesc=~s/'/\\'/g;
1224: $cleandesc =~ s/^\s+//;
1225: my ($cdom,$cnum)=split(/\_/,$course);
1226: my ($instcode,$singleowner,$ttype,$selfenroll_types,
1227: $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
1228: if (ref($courses->{$course}) eq 'HASH') {
1229: $descr = $courses->{$course}{'description'};
1230: $instcode = $courses->{$course}{'inst_code'};
1231: $singleowner = $courses->{$course}{'owner'};
1232: $ttype = $courses->{$course}{'type'};
1233: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
1234: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
1235: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
1236: $categories = $courses->{$course}{'categories'};
1237: push(@owners,$singleowner);
1238: if ($courses->{$course}{'co-owners'} ne '') {
1239: foreach my $item (split(/,/,$courses->{$course}{'co-owners'})) {
1240: push(@owners,$item);
1241: }
1242: }
1243: }
1244: if ($instcode ne '') {
1245: $uniquecodes{$instcode} = 1;
1246: } else {
1247: $nocodes ++;
1248: }
1249: foreach my $owner (@owners) {
1250: my ($ownername,$ownerdom);
1251: if ($owner =~ /:/) {
1252: ($ownername,$ownerdom) = split(/:/,$owner);
1253: } else {
1254: $ownername = $owner;
1255: if ($owner ne '') {
1256: $ownerdom = $cdom;
1257: }
1258: }
1259: if ($ownername ne '' && $ownerdom ne '') {
1260: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
1261: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
1262: }
1263: }
1264: $courseinfo{$course}{'cdom'} = $cdom;
1265: $courseinfo{$course}{'cnum'} = $cnum;
1266: $courseinfo{$course}{'code'} = $instcode;
1267: my @lastnames;
1268: foreach my $owner (keys(%ownernames)) {
1269: if (ref($ownernames{$owner}) eq 'HASH') {
1270: push(@lastnames,$ownernames{$owner}{'lastname'});
1271: }
1272: }
1273: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
1274: $courseinfo{$course}{'title'} = $cleandesc;
1275: $courseinfo{$course}{'owner'} = $singleowner;
1276: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
1277: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
1278: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
1279: $courseinfo{$course}{'categories'} = $categories;
1280:
1281: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
1282: my @classids;
1283: my @crosslistings;
1284: my ($seclist,$numsec) =
1285: &identify_sections($coursehash{'internal.sectionnums'});
1286: $courseinfo{$course}{'seclist'} = $seclist;
1287: my ($xlist_items,$numxlist) =
1288: &identify_sections($coursehash{'internal.crosslistings'});
1289: if (ref($numbers) eq 'HASH') {
1290: $numbers->{'sections'} += $numsec;
1291: $numbers->{'xlists'} += $numxlist;
1292: }
1293: my $showsyllabus = 1; # default is to include a syllabus link
1294: if (defined($coursehash{'showsyllabus'})) {
1295: $showsyllabus = $coursehash{'showsyllabus'};
1296: }
1297: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
1298: if ($showcredits) {
1299: if ($coursehash{'internal.defaultcredits'}) {
1300: $courseinfo{$course}{'defaultcredits'} = $coursehash{'internal.defaultcredits'};
1301: } elsif ($instcode ne '') {
1302: $courseinfo{$course}{'defaultcredits'} = $defofficial;
1303: } else {
1304: $courseinfo{$course}{'defaultcredits'} = $defunofficial;
1305: }
1306: $defcreds = $courseinfo{$course}{'defaultcredits'};
1307: }
1308: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
1309: ($knownuser && ($details == 1))) {
1310: my $milestone;
1311: if ($wasactiveon eq 'accessend') {
1312: if ($coursehash{'default_enrollment_end_date'}) {
1313: $milestone = $coursehash{'default_enrollment_end_date'};
1314: } else {
1315: $milestone = time;
1316: }
1317: } elsif ($wasactiveon eq 'enrollend') {
1318: if ($coursehash{'internal.autoend'}) {
1319: $milestone = $coursehash{'internal.autoend'};
1320: } else {
1321: $milestone = time;
1322: }
1323: } else {
1324: $milestone = $wasactiveon;
1325: }
1326: $courseinfo{$course}{'counts'} =
1327: &count_students($cdom,$cnum,$numsec,$fields,$fieldtitles,$gettotals,
1328: $numbers,$creditsum,$showcredits,$defcreds,$milestone);
1329: if ($instcode ne '') {
1330: $courseinfo{$course}{'autoenrollment'} =
1331: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
1332: $instcode,\@owners,$cdom,$cnum);
1333: }
1334: my $startaccess = '';
1335: my $endaccess = '';
1336: my $accessdates;
1337: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
1338: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
1339: }
1340: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
1341: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
1342: if ($coursehash{'default_enrollment_end_date'} == 0) {
1343: $endaccess = &mt('No ending date');
1344: }
1345: }
1346: if ($startaccess) {
1347: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
1348: }
1349: if ($endaccess) {
1350: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
1351: }
1352: if (($selfenroll_types ne '') &&
1353: ($selfenroll_end > 0 && $selfenroll_end > $now)) {
1354: my ($selfenroll_start_access,$selfenroll_end_access);
1355: if (($coursehash{'default_enrollment_start_date'} ne
1356: $coursehash{'internal.selfenroll_start_access'}) ||
1357: ($coursehash{'default_enrollment_end_date'} ne
1358: $coursehash{'internal.selfenroll_end_access'})) {
1359: if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
1360: $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
1361: }
1362: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
1363: $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
1364: if ($coursehash{'internal.selfenroll_end_access'} == 0) {
1365: $selfenroll_end_access = &mt('No ending date');
1366: }
1367: }
1368: if ($selfenroll_start_access || $selfenroll_end_access) {
1369: $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
1370: if ($selfenroll_start_access) {
1371: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
1372: }
1373: if ($selfenroll_end_access) {
1374: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
1375: }
1376: }
1377: }
1378: }
1379: $courseinfo{$course}{'access'} = $accessdates;
1380: }
1381: if ($xlist_items eq '') {
1382: $xlist_items = &mt('No');
1383: }
1384: $courseinfo{$course}{'xlist'} = $xlist_items;
1385: }
1386: if (ref($numbers) eq 'HASH') {
1387: $numbers->{'courses'} = $nocodes + scalar(keys(%uniquecodes));
1388: }
1389: return %courseinfo;
1390: }
1391:
1392: sub count_students {
1393: my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$creditsum,
1394: $showcredits,$defcreds,$wasactiveon) = @_;
1395: my $countslist = '<span class="LC_nobreak">'.
1396: &mt('[quant,_1,section,sections,No sections]',$numsec).'</span>';
1397: my (@fields,%titles,$showexpired);
1398: if ((ref($fieldsref) eq 'ARRAY') && (ref($titlesref) eq 'HASH') &&
1399: (ref($numbers) eq 'HASH')) {
1400: @fields = @{$fieldsref};
1401: %titles = %{$titlesref};
1402: if (grep(/^Previous$/,@fields)) {
1403: $showexpired = 1;
1404: }
1405: } else {
1406: return;
1407: }
1408: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1409: my (%student_count,%credit_count);
1410: %student_count = (
1411: Active => 0,
1412: Future => 0,
1413: Previous => 0,
1414: );
1415: if ($showcredits) {
1416: %credit_count = (
1417: Active => 0,
1418: Future => 0,
1419: Previous => 0,
1420: );
1421: }
1422: my %idx;
1423: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1424: $idx{'end'} = &Apache::loncoursedata::CL_END();
1425: $idx{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1426: while (my ($student,$data) = each(%$classlist)) {
1427: my $status = $data->[$idx{'status'}];
1428: my $credits = $data->[$idx{'credits'}];
1429: if ($credits eq '') {
1430: $credits = $defcreds;
1431: }
1432: if ($status eq 'Expired') {
1433: if (($showexpired) &&
1434: ($data->[$idx{'end'}] >= $wasactiveon)) {
1435: $student_count{'Previous'} ++;
1436: if ($showcredits) {
1437: $credit_count{'Previous'} += $credits;
1438: }
1439: }
1440: } else {
1441: $student_count{$status} ++;
1442: if ($showcredits) {
1443: $credit_count{$status} += $credits;
1444: }
1445: }
1446: }
1447: if (@fields) {
1448: $countslist .= ':<br />';
1449: foreach my $status (@fields) {
1450: $countslist .= '<span class="LC_nobreak">'.$titles{$status}.': '.
1451: $student_count{$status}.'</span><br />';
1452: $numbers->{$status} += $student_count{$status};
1453: if ($showcredits) {
1454: $creditsum->{$status} += $credit_count{$status};
1455: }
1456: }
1457: }
1458: return $countslist;
1459: }
1460:
1461: sub courseinfo_row {
1462: my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems,$numbers) = @_;
1463: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1464: $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
1465: if (ref($info) eq 'HASH') {
1466: $cdom = $info->{'cdom'};
1467: $cnum = $info->{'cnum'};
1468: $title = $info->{'title'};
1469: $ownerlast = $info->{'ownerlastnames'};
1470: $code = $info->{'code'};
1471: $owner = $info->{'owner'};
1472: $seclist = $info->{'seclist'};
1473: $xlist_items = $info->{'xlist'};
1474: $accessdates = $info->{'access'};
1475: $counts = $info->{'counts'};
1476: $autoenrollment = $info->{'autoenrollment'};
1477: $showsyllabus = $info->{'showsyllabus'};
1478: $categories = $info->{'categories'};
1479: } else {
1480: $output = '<td colspan="8">'.&mt('No information available for [_1].',
1481: $code).'</td>';
1482: return $output;
1483: }
1484: $output .= '<td>'.$$countref.'</td>';
1485: if ($env{'form.currcat_0'} eq 'instcode::0') {
1486: $output .= '<td>'.$code.'</td>';
1487: } else {
1488: my ($categorylist,@cats);
1489: if ($categories ne '') {
1490: @cats = split('&',$categories);
1491: }
1492: if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
1493: my @categories = map { $trails->[$allitems->{$_}]; } @cats;
1494: $categorylist = join('<br />',@categories);
1495: }
1496: if ($categorylist eq '') {
1497: $categorylist = ' ';
1498: }
1499: $output .= '<td>'.$categorylist.'</td>';
1500: }
1501: $output .= '<td>'.$seclist.'</td>'.
1502: '<td>'.$xlist_items.'</td>'.
1503: '<td>'.$title.' <font size="-2">';
1504: if ($showsyllabus) {
1505: $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.&mt('Syllabus').'</a>';
1506: } else {
1507: $output .= ' ';
1508: }
1509: $output .= '</font></td>'.
1510: '<td>'.$ownerlast.'</td>';
1511: if ($knownuser) {
1512: if ($details) {
1513: $output .=
1514: '<td>'.$accessdates.'</td>'.
1515: '<td>'.$counts.'</td>';
1516: unless ($env{'form.currcat_0'} eq 'communities::0') {
1517: $output .= '<td>'.$autoenrollment.'</td>';
1518: }
1519: } else {
1520: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1521: }
1522: }
1523: my $selfenroll = &selfenroll_status($info,$course);
1524: if ($selfenroll) {
1525: $output .= '<td>'.$selfenroll.'</td>';
1526: } else {
1527: $output .= '<td> </td>';
1528: }
1529: $$countref ++;
1530: return $output;
1531: }
1532:
1533: sub selfenroll_status {
1534: my ($info,$course) = @_;
1535: my $now = time;
1536: my $output;
1537: if (ref($info) eq 'HASH') {
1538: if ($info->{'selfenroll_types'}) {
1539: my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
1540: my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
1541: if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
1542: if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
1543: $output = &mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
1544: } else {
1545: $output = '<a href="javascript:ToSelfenroll('."'$course'".')">'.
1546: &mt('Enroll in course').'</a><br />';
1547: if ($info->{'selfenroll_end'} == 0) {
1548: $output .= &mt('Available permanently');
1549: } elsif ($info->{'selfenroll_end'} > $now) {
1550: $output .= &mt('Self-enrollment ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
1551: }
1552: }
1553: }
1554: }
1555: }
1556: return $output;
1557: }
1558:
1559: sub identify_sections {
1560: my ($seclist) = @_;
1561: my @secnums;
1562: if ($seclist =~ /,/) {
1563: my @sections = split(/,/,$seclist);
1564: foreach my $sec (@sections) {
1565: $sec =~ s/:[^:]*$//;
1566: push(@secnums,$sec);
1567: }
1568: } else {
1569: if ($seclist =~ m/^([^:]+):/) {
1570: my $sec = $1;
1571: if (!grep(/^\Q$sec\E$/,@secnums)) {
1572: push(@secnums,$sec);
1573: }
1574: }
1575: }
1576: @secnums = sort {$a <=> $b} @secnums;
1577: $seclist = join(', ',@secnums);
1578: my $numsec = @secnums;
1579: return ($seclist,$numsec);
1580: }
1581:
1582: sub get_valid_classes {
1583: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1584: my $response;
1585: my %validations;
1586: @{$validations{'sections'}} = ();
1587: @{$validations{'xlists'}} = ();
1588: my $totalitems = 0;
1589: if ($seclist) {
1590: foreach my $sec (split(/, /,$seclist)) {
1591: my $class = $crscode.$sec;
1592: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1593: $class) eq 'ok') {
1594: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1595: push(@{$validations{'sections'}},$sec);
1596: $totalitems ++;
1597: }
1598: }
1599: }
1600: }
1601: if ($xlist_items) {
1602: foreach my $item (split(/, /,$xlist_items)) {
1603: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1604: $item) eq 'ok') {
1605: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1606: push(@{$validations{'xlists'}},$item);
1607: $totalitems ++;
1608: }
1609: }
1610: }
1611: }
1612: if ($totalitems > 0) {
1613: if (@{$validations{'sections'}}) {
1614: $response = &mt('Sections:').' '.
1615: join(', ',@{$validations{'sections'}}).'<br />';
1616: }
1617: if (@{$validations{'xlists'}}) {
1618: $response .= &mt('Courses:').' '.
1619: join(', ',@{$validations{'xlists'}});
1620: }
1621: }
1622: return $response;
1623: }
1624:
1625: sub autoenroll_info {
1626: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1627: my $autoenrolldates = &mt('Not enabled');
1628: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
1629: my ($autostart,$autoend);
1630: if ( defined($coursehash->{'internal.autostart'}) ) {
1631: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
1632: }
1633: if ( defined($coursehash->{'internal.autoend'}) ) {
1634: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
1635: }
1636: if ($coursehash->{'internal.autostart'} > $now) {
1637: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1638: $autoenrolldates = &mt('Not enabled');
1639: } else {
1640: my $valid_classes =
1641: &get_valid_classes($seclist,$xlist_items,$code,
1642: $owners,$cdom,$cnum);
1643: if ($valid_classes ne '') {
1644: $autoenrolldates = &mt('Not enabled').'<br />'
1645: .&mt('Starts: [_1]',$autostart)
1646: .'<br />'.$valid_classes;
1647: }
1648: }
1649: } else {
1650: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1651: $autoenrolldates = &mt('Not enabled').'<br />'
1652: .&mt('Ended: [_1]',$autoend);
1653: } else {
1654: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1655: $code,$owners,$cdom,$cnum);
1656: if ($valid_classes ne '') {
1657: $autoenrolldates = &mt('Currently enabled').'<br />'.
1658: $valid_classes;
1659: }
1660: }
1661: }
1662: }
1663: return $autoenrolldates;
1664: }
1665:
1666: sub user_is_known {
1667: my $known = 0;
1668: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
1669: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
1670: $known = 1;
1671: }
1672: return $known;
1673: }
1674:
1675: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>