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