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