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