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