File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.97: download - view: text, annotated - select for diffs
Sun Sep 20 22:04:57 2009 UTC (14 years, 8 months ago) by amueller
Branches: MAIN
CVS tags: HEAD
closed bug 6010

-Course Coordinator keeps his colour (actually green) when switching between Edit Mode and Public-View Mode.
 vice versa
-The Main Menu doesn't disappear now when switching between Edit Mode and Public-View Mode.

    1: # The LearningOnline Network
    2: # Syllabus
    3: #
    4: # $Id: lonsyllabus.pm,v 1.97 2009/09/20 22:04:57 amueller 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::lonsyllabus;
   30: 
   31: use strict;
   32: use Apache::lontemplate;
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon;
   35: use Apache::lonnet;
   36: use Apache::lontexconvert;
   37: use Apache::lonfeedback;
   38: use Apache::lonannounce;
   39: use Apache::lonlocal;
   40: use Apache::lonhtmlcommon;
   41: use Apache::lonspeller();
   42: use HTML::Entities();
   43: 
   44: sub handler {
   45:     my $r = shift;
   46:     &Apache::loncommon::content_type($r,'text/html');
   47:     $r->send_http_header;
   48:     return OK if $r->header_only;
   49: 
   50:     my $target=$env{'form.grade_target'};
   51: # --------------------------------------------------- Get course info from URL
   52:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
   53: # ------------------------------------------------------------ Get query string
   54:     &Apache::loncommon::get_unprocessed_cgi
   55:                         ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
   56: # ----------------------------------------------------- Is this even a course?
   57:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
   58:     if ($homeserver eq 'no_host') {
   59:         &Apache::loncommon::content_type($r,'text/html');
   60:         $r->send_http_header;
   61:           &Apache::loncommon::simple_error_page($r,'No syllabus available',
   62:                           'No syllabus available');
   63:         return OK;
   64:     }
   65: # ------------------------------------- There is such a course, get environment
   66:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
   67: 
   68: # ------------------------------------------------------------ Print the screen
   69: 
   70:     if ($target eq 'tex') {
   71:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   72:     }
   73: # -------------------------------------------------- Let's see who handles this
   74:     my $externalsyllabus=$courseenv{'externalsyllabus'};
   75: 
   76:     if ($externalsyllabus=~/\w/) {
   77: 
   78:        if ($env{'form.wrapperdisplay'} eq 'menu') {
   79:            $r->print(&Apache::lonwrapper::simple_menu());
   80:        } else {
   81:            $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
   82:                            $externalsyllabus));
   83:        }
   84:        return OK;
   85:     }
   86: 
   87: # ------------------------------ The buck stops here: internal syllabus display
   88: # --------------------------------------------------------- The syllabus fields
   89:     my %syllabusfields=&Apache::lonlocal::texthash(
   90:        'aaa_instructorinfo' => 'Instructor Information',
   91:        'bbb_description'    => 'Course Description',
   92:        'ccc_prereq'         => 'Prerequisites',
   93:        'cdc_classhours'     => 'Class Hours',
   94:        'ddd_officehours'    => 'Office Hours',
   95:        'eee_helproom'       => 'Helproom Hours',
   96:        'efe_projectinfo'    => 'Project Information',
   97:        'fff_examinfo'       => 'Exam Information',
   98:        'fgf_deadlines'      => 'Deadlines',
   99:        'ggg_grading'        => 'Grading Information',
  100:        'hhh_readings'       => 'Readings',
  101:        'iii_coursepack'     => 'Coursepack',
  102:        'jjj_weblinks'       => 'Web Links',
  103:        'kkk_textbook'       => 'Textbook',
  104:        'lll_includeurl'     => 'URLs To Include in Syllabus');
  105: # --------------------------------------------------------------- Force Student
  106:     my $forcestudent='';
  107:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  108:     my $forceedit='';
  109:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
  110: 
  111: # ----------------------------------------------------------------- Make header
  112:     if ($target ne 'tex') {
  113:         my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
  114:         my $js;
  115:         if ($env{'form.backto'} eq 'coursecatalog') {
  116:             $js .= <<"ENDSCRIPT";
  117: 
  118: <script type="text/javascript">
  119: function ToCatalog(caller) {
  120:     numidx = getIndexByName('coursenum');
  121:         if (numidx > -1) {
  122:             if (caller != 'details') {
  123:                 document.backtocat.elements[numidx].value = '';
  124:             }
  125:         }
  126:     document.backtocat.submit();
  127: }
  128: 
  129: function getIndexByName(item) {
  130:     for (var i=0;i<document.backtocat.elements.length;i++) {
  131:         if (document.backtocat.elements[i].name == item) {
  132:             return i;
  133:         }
  134:     }
  135:     return -1;
  136: }
  137: 
  138: </script>
  139: 
  140: ENDSCRIPT
  141:         }
  142:         my $start_page =
  143:          &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
  144:                        {'function'       => undef,
  145:                         'domain'         => $cdom,
  146:                         'force_register' =>
  147:                         $env{'form.register'},});
  148: 
  149:         $r->print($start_page);
  150:         if ($env{'form.backto'} eq 'coursecatalog') {
  151:             &Apache::lonhtmlcommon::clear_breadcrumbs();
  152:             &Apache::lonhtmlcommon::add_breadcrumb
  153:                 ({href=>"javascript:ToCatalog()",
  154:                 text=>"Course Catalog"});
  155:             if ($env{'form.coursenum'} ne '') {
  156:                 &Apache::lonhtmlcommon::add_breadcrumb
  157:                     ({href=>"javascript:ToCatalog('details')",
  158:                     text=>"Course details"});
  159:             }
  160:             &Apache::lonhtmlcommon::add_breadcrumb
  161:                 ({href=>$r->uri,
  162:                 text=>"Course syllabus"});
  163:             $r->print(&Apache::lonhtmlcommon::breadcrumbs());
  164:         }
  165:     }
  166: # ---------------------------------------------------------- Load syllabus info
  167:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
  168:     my $allowed=0;
  169:     my $privileged=0;
  170: 
  171: # This handler might be called anonymously ...
  172: # ----------------------------------------------------- Only if not public call
  173:     if ($env{'user.environment'}) {
  174: # does this user have privileges to post, etc?
  175:         if ($env{'request.course.id'}
  176:         && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
  177:         && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
  178:             $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  179:             $privileged=$allowed;
  180:             if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  181:                 $forcestudent='student';
  182:             }
  183:             if ($forcestudent or $target eq 'tex') { $allowed=0; }
  184:         }
  185:         if (($allowed) && ($env{'form.storesyl'})) {
  186:             foreach my $syl_field (keys(%syllabusfields)) {
  187:                 my $field=$env{'form.'.$syl_field};
  188:                 chomp($field);
  189:                 $field=~s/\s+$//s;
  190:                 $field=~s/^\s+//s;
  191:                 $field=~s/\<br\s*\/*\>$//s;
  192:                 $field=&Apache::lonfeedback::clear_out_html($field,1);
  193:                 $syllabus{$syl_field}=$field;
  194:                 if ($syl_field eq 'lll_includeurl') { # clean up included URLs
  195:                     my $field='';
  196:                     foreach my $value (split(/\n/,$syllabus{$syl_field})) {
  197:                         my $url=$value;
  198: # get rid of leading and trailing spaces
  199:                         $url=~s/^\s+//;
  200:                         $url=~s/\s+$//;
  201:                         if ($url=~m|^https?\://([^/]+)/(.+)$|) {
  202:                             my $host = $1;
  203:                             my $remainder=$2;
  204: # remove the hostname from internal URLs
  205:                             my $hostname = &Apache::lonnet::hostname($host);
  206:                             my %all_hostnames = &Apache::lonnet::all_hostnames();
  207:                             foreach my $possible_host (keys(%all_hostnames)) {
  208:                                 if ($possible_host =~ /\Q$hostname\E/i) {
  209:                                     $url=$remainder;
  210:                                 }
  211:                             }
  212:                         }
  213: # norm internal URLs
  214:                         unless ($url=~/^https?\:/) {
  215:                             $url=&Apache::lonnet::clutter($url);
  216:                         }
  217: # re-assemble field
  218:                         if ($url) {
  219:                             $field.=$url."\n";
  220:                         }
  221:                     }
  222:                     $syllabus{$syl_field}=$field;
  223:                 }
  224:             }
  225:             $syllabus{'uploaded.domain'}=$env{'user.domain'};
  226:             $syllabus{'uploaded.name'}=$env{'user.name'};
  227:             $syllabus{'uploaded.lastmodified'}=time;
  228:             &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
  229:         }
  230:     }
  231: 
  232: #--------Functions
  233:     if( ($allowed || $privileged) && $target ne 'tex') {
  234:         my $functions=&Apache::lonhtmlcommon::start_funclist();
  235:         if ($allowed) {
  236: 			#if you have the register flag, keep it
  237: 			if($env{'form.register'} == 1) {
  238:             	$functions.=&Apache::lonhtmlcommon::add_item_funclist(
  239:                           '<a href="'.$r->uri.'?forcestudent=1&register=1">'
  240:                            .&mt('Show Public View').'</a>'
  241:                            .&Apache::loncommon::help_open_topic(
  242:                                 'Uploaded_Templates_PublicView'));
  243: 			} else {
  244:             	$functions.=&Apache::lonhtmlcommon::add_item_funclist(
  245:                           '<a href="'.$r->uri.'?forcestudent=1">'
  246:                            .&mt('Show Public View').'</a>'
  247:                            .&Apache::loncommon::help_open_topic(
  248:                                 'Uploaded_Templates_PublicView'));
  249: 			}
  250:         } elsif ($privileged) {
  251: 			if($env{'form.register'} == 1) {
  252: 	            $functions.=&Apache::lonhtmlcommon::add_item_funclist(
  253:                            '<a href="'.$r->uri.'?forceedit=1&register=1">'
  254:                             .&mt('Edit').'</a>');
  255: 			} else {
  256: 	            $functions.=&Apache::lonhtmlcommon::add_item_funclist(
  257:                            '<a href="'.$r->uri.'?forceedit=1">'
  258:                             .&mt('Edit').'</a>');
  259: 			}
  260:         }
  261: 
  262:         $functions.=&Apache::lonhtmlcommon::end_funclist();
  263:         $r->print(&Apache::loncommon::head_subbox($functions));
  264:     }
  265: 
  266: #---------------------Print External URL Syllabus Info and Help Text
  267:     if( ($allowed) && ($target ne 'tex') ) {
  268:         my $protocol = $Apache::lonnet::protocol{$homeserver};
  269:           $protocol = 'http' if ($protocol ne 'https');
  270:         $r->print('<p class="LC_info">'
  271:                  .&mt('This syllabus can be publicly viewed at [_1]'
  272:                      ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
  273:                  .'&nbsp;'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
  274:                  .'</p>'
  275:                  .'<p class="LC_info">'
  276:                  .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
  277:                      ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
  278:                  .'</p>'
  279:         );
  280:         #-Print Help Text
  281:         $r->print(&Apache::loncommon::help_open_topic( 
  282:                         'Uploaded_Templates_TextBoxes',
  283:                         &mt('Help with filling in text boxes')));
  284:     }
  285: 
  286: #----------Print last update
  287:     my $lastmod=$syllabus{'uploaded.lastmodified'};
  288:     $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  289:     my $who = &Apache::loncommon::aboutmewrapper(
  290:         &Apache::loncommon::plainname($syllabus{'uploaded.name'},
  291:         $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
  292:         $syllabus{'uploaded.domain'});
  293:     if ($target ne 'tex') {
  294:         $r->print('<div class="LC_info">'.&mt('Last updated').': '.
  295:             $lastmod . ' '.
  296:             ($who ? &mt('by').' '.$who
  297:                            : '' ) .
  298:              '</div>' );
  299: 
  300:     } else {
  301:         $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
  302:             ($who? &mt('by').'\\\\ '.
  303:                     &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
  304:                   :'')
  305:              .'\\\\');
  306:     }
  307: #----------------------------Print Headtitle
  308:     if ($target ne 'tex') {
  309:         $r->print('<h1>'.$courseenv{'description'}.'</h1>');
  310:         $r->print('<h3>'.  &Apache::lonnet::domain($cdom,'description').'</h3>');
  311:     } else {
  312:         $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
  313:         &Apache::lonnet::domain($cdom,'description').'}\\\\');
  314:     }
  315: # -------------------------------------------------------- Get course personnel
  316:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
  317:     if ($target ne 'tex') {
  318:         $r->print(&Apache::lonhtmlcommon::start_pick_box());
  319:     } else {
  320:         $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
  321:     }
  322:     my @personnel=sort(keys(%coursepersonnel));
  323:     my $lastpers=$personnel[$#personnel];
  324:     foreach my $element (@personnel) {
  325:         if ($target ne 'tex') {
  326:             $r->print(&Apache::lonhtmlcommon::row_title($element));
  327:         } else {
  328:             $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
  329:         }
  330:         foreach (split(/\,/,$coursepersonnel{$element})) {
  331:             my ($puname,$pudom)=split(/\:/,$_);
  332:             if ($target ne 'tex') {
  333:                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
  334:                 if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
  335:                     ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
  336:                     $r->print(' '.$courseperson);
  337:                 } else {
  338:                     $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
  339:                               $puname,$pudom));
  340:                 }
  341:             } else {
  342:                 $r->print(' '.&Apache::loncommon::plainname($puname,
  343:                               $pudom).' ');
  344:             }
  345:         }
  346:         if ($target ne 'tex') {
  347:             my $lastclose=$element eq $lastpers?1:0;
  348:             $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
  349:         } else {
  350:             $r->print('\\\\ \hline');
  351:         }
  352:     }
  353:     if ($target ne 'tex') {
  354:         $r->print(&Apache::lonhtmlcommon::end_pick_box());
  355:     } else {
  356:         $r->print('\end{tabular}\\\\');
  357:     }
  358: # -------------------------------------------------------------- Announcements?
  359:     my $day = &Apache::lonannounce::showday(time,2,
  360:              &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
  361:     if ($target ne 'tex') {
  362:         if ($allowed) {
  363:             &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
  364:             $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
  365:             my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
  366:             $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
  367:             &Apache::lontemplate::print_end_template($r);
  368:         } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
  369:             &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
  370:             $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
  371:             &Apache::lontemplate::print_end_template($r);
  372:         }
  373: 
  374:     } else {
  375:         $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
  376:     }
  377: # ---------------------------------------------------------------- Get syllabus
  378:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  379:         if ($allowed) {
  380:             $r->print('<form method="post" action="">'.
  381:             '<input type="hidden" name="forceedit" value="edit" />');
  382:         }
  383:         my @htmlids=();
  384: 
  385:         foreach my $field (sort(keys(%syllabusfields))) {
  386:             if (($syllabus{$field}=~/\w/) || ($allowed)) {
  387:                 my $message=$syllabus{$field};
  388:                 if ($field eq 'lll_includeurl') { # this is the "included" field
  389:                     my $urls=$message;
  390:                     $message='';
  391:                     foreach my $filelink (split(/\n/,$urls)) {
  392:                         my $output='';
  393:                        # embed style?
  394:                         my ($curfext)=($filelink=~/\.([^\.]+)$/);
  395:                         my $embstyle=&Apache::loncommon::fileembstyle($curfext);
  396:                         if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
  397:                             $output=&Apache::lonnet::ssi_body($filelink);
  398:                         } elsif ($embstyle eq 'img') {# embed as an image
  399:                             $output='<img src="'.$filelink.'" />';
  400:                         }
  401:                         if ($output ne '') {
  402:                                if ($target ne 'tex') {
  403:                                    $message.='<p>'.$output.'</p>';
  404:                                } else {
  405:                                    $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
  406:                                }
  407:                         }
  408:                     }
  409:                     if ($allowed) {
  410:                         $r->print('<h3>'.$syllabusfields{$field}.
  411:                         &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>');
  412:                     } else {
  413:                         $r->print($message);
  414:                     }
  415:                 } else {
  416:                     &Apache::lonfeedback::newline_to_br(\$message);
  417:                     $message =~s|(https?\://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
  418:                     if ($allowed) {
  419:                         $message=&Apache::lonspeller::markeduptext($message);
  420:                     }
  421:                     $message=&Apache::lontexconvert::msgtexconverted($message);
  422:                     if ($target ne 'tex') {
  423:                         &Apache::lontemplate::print_template($r, $syllabusfields{$field}, $message,$allowed,'LC_Box');
  424:                     } else {
  425:                         $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
  426:                         &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
  427:                     }
  428:                     push(@htmlids,$field);
  429:                 }
  430:                 if ($allowed) {
  431:                     if ($target ne 'tex') {
  432:                         &Apache::lontemplate::print_editbox_template($r, $syllabus{$field}, $field);
  433:                     }
  434:                 }
  435:             }
  436:         }
  437:         if ($allowed) {
  438:             $r->print('</form>'.
  439:             &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
  440:         }
  441:       # if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
  442:     } else {
  443:         if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
  444:         $r->print(&mt('No syllabus information provided.'));
  445:         if ($target ne 'tex') {$r->print('</p>');}
  446:     }
  447:     if ($target ne 'tex') {
  448:         if ($env{'form.backto'} eq 'coursecatalog') {
  449:             $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
  450:                       &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
  451:                       '</form>');
  452:         }
  453:         $r->print(&Apache::loncommon::end_page());
  454:     } else {
  455:         $r->print('\end{document}');
  456:     }
  457:     return OK;
  458: }
  459: 
  460: 1;
  461: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>