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