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