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