Annotation of loncom/interface/lonsyllabus.pm, revision 1.47

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.46      www         4: # $Id: lonsyllabus.pm,v 1.45 2006/03/06 22:17:48 www Exp $
1.1       www         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::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
1.5       www        35: use Apache::lontexconvert;
1.11      www        36: use Apache::lonfeedback;
1.19      www        37: use Apache::lonannounce;
1.23      www        38: use Apache::lonlocal;
1.32      www        39: use Apache::lonhtmlcommon;
1.38      www        40: use Apache::lonspeller();
1.1       www        41: 
                     42: sub handler {
                     43:     my $r = shift;
1.46      www        44:     &Apache::loncommon::content_type($r,'text/html');
                     45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
1.45      www        47: 
1.46      www        48:     my $target=$env{'form.grade_target'};
1.45      www        49: # --------------------------------------------------- Get course info from URL
                     50:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46      www        51: # ------------------------------------------------------------ Get query string
                     52:     &Apache::loncommon::get_unprocessed_cgi
1.47    ! www        53:                         ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
1.45      www        54: # ----------------------------------------------------- Is this even a course?
                     55:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
                     56:     if ($homeserver eq 'no_host') {
                     57:         &Apache::loncommon::content_type($r,'text/html');
                     58:         $r->send_http_header;
                     59:         $r->print('<html><body>'.&mt('No syllabus available').'</body></html>');
                     60:         return OK;
                     61:     }
                     62: # ------------------------------------- There is such a course, get environment
                     63:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46      www        64: 
1.1       www        65: # ------------------------------------------------------------ Print the screen
1.46      www        66:     my $feedurl='http://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss';
1.28      sakharuk   67:     if ($target ne 'tex') {
1.39      albertel   68: 	my $html=&Apache::lonxml::xmlbegin();
1.28      sakharuk   69: 	$r->print(<<ENDDOCUMENT);
1.39      albertel   70: $html
1.1       www        71: <head>
                     72: <title>The LearningOnline Network with CAPA</title>
1.42      www        73: <link rel="alternate" type="application/rss+xml" title="Course Announcements" href="$feedurl" />
1.1       www        74: ENDDOCUMENT
1.28      sakharuk   75:     } else {
1.40      albertel   76: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28      sakharuk   77:     } 
1.46      www        78: # ----------------------------------------------------- Force menu registration
                     79:     my $addentries='';
                     80:     if ($env{'form.register'}) {
                     81:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
                     82:            '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
                     83:        $r->print(&Apache::lonmenu::registerurl(1));
                     84:     }
                     85: # -------------------------------------------------- Let's see who handles this
1.47    ! www        86:     my $externalsyllabus=$courseenv{'externalsyllabus'};
1.46      www        87:     if ($externalsyllabus=~/\w/) {
1.47    ! www        88:        $r->print('</head>');
        !            89:        if ($env{'form.wrapperdisplay'} eq 'menu') {
        !            90: #
        !            91: # Producing the menu buttons
        !            92: #
        !            93:            $r->print('<body bgcolor="#FFFFFF">'.
        !            94:                 &Apache::lonmenu::menubuttons(1,'web',1).'</body></html>');
        !            95:         } else {
        !            96:            if ($env{'browser.interface'} eq 'textual') {
        !            97: #
        !            98: # ssi-based rendering for text-based interface
        !            99: #
        !           100:                $r->print('<body bgcolor="#FFFFFF">'.
        !           101:                         &Apache::lonmenu::menubuttons(1).
        !           102:                         &Apache::lonnet::ssi_body($externalsyllabus).'</body></html>');
        !           103:            } elsif ($env{'environment.remote'} eq 'off') {
        !           104: #
        !           105: # This is inline remote
        !           106: # 
        !           107:                $r->print(<<ENDDOCUMENTINL);
        !           108: <frameset rows="180,*" border=0 $addentries>
        !           109: <frame src="/public/$cdom/$cnum/syllabus?wrapperdisplay=menu">
        !           110: <frame src="$externalsyllabus">
        !           111: </frameset>
        !           112: </html>
        !           113: ENDDOCUMENTINL
        !           114:           } else {
        !           115: #
        !           116: # frame-based rendering for graphical interface
        !           117: #
        !           118:                $r->print(<<ENDDOCUMENT);
        !           119: <frameset rows="1,*" border=0 $addentries>
        !           120: <frame src="/adm/rat/empty.html">
        !           121: <frame src="$externalsyllabus">
        !           122: </frameset>
        !           123: </html>
        !           124: ENDDOCUMENT
        !           125:            }
        !           126:         }
        !           127:         return OK;
        !           128:      } 
1.42      www       129: 
1.46      www       130: # ------------------------------ The buck stops here: internal syllabus display
1.5       www       131: # --------------------------------------------------------- The syllabus fields
1.23      www       132:     my %syllabusfields=&Apache::lonlocal::texthash(
1.5       www       133:        'aaa_instructorinfo' => 'Instructor Information',
                    134:        'bbb_description'    => 'Course Description',
                    135:        'ccc_prereq'         => 'Prerequisites',
1.7       www       136:        'cdc_classhours'     => 'Class Hours',
1.5       www       137:        'ddd_officehours'    => 'Office Hours',
                    138:        'eee_helproom'       => 'Helproom Hours',
1.7       www       139:        'efe_projectinfo'    => 'Project Information',
1.5       www       140:        'fff_examinfo'       => 'Exam Information',
1.7       www       141:        'fgf_deadlines'      => 'Deadlines',
1.5       www       142:        'ggg_grading'        => 'Grading Information',
1.7       www       143:        'hhh_readings'       => 'Readings',
                    144:        'iii_coursepack'     => 'Coursepack',
                    145:        'jjj_weblinks'       => 'Web Links',
1.9       www       146:        'kkk_textbook'       => 'Textbook',
                    147:        'lll_includeurl'     => 'URLs To Include in Syllabus');
1.6       www       148: # --------------------------------------------------------------- Force Student
                    149:     my $forcestudent='';
1.40      albertel  150:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27      www       151:     my $forceedit='';
1.40      albertel  152:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.5       www       153:        
1.45      www       154: # ----------------------------------------------------------------- Make header 
1.28      sakharuk  155:     if ($target ne 'tex') {
1.32      www       156: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
                    157: 		  '</head>'.&Apache::loncommon::bodytag
1.40      albertel  158:             ("Syllabus",$forcestudent,$addentries,'',$cdom,$env{'form.register'}));
1.28      sakharuk  159: 	$r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
                    160:                  $Apache::lonnet::domaindescription{$cdom}.'</h3>');
                    161:     } else {
1.29      sakharuk  162: 	$r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.28      sakharuk  163:                  $Apache::lonnet::domaindescription{$cdom}.'}\\\\');
                    164:     }
1.19      www       165: # -------------------------------------------------------------- Announcements?
1.35      sakharuk  166:     if ($target ne 'tex') {
                    167: 	$r->print(&Apache::lonannounce::showday(time,2,
1.44      www       168: 		       &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)).
                    169:                        &Apache::lonrss::advertisefeeds($cnum,$cdom));
1.35      sakharuk  170:     } else {
                    171: 	$r->print(&Apache::lonxml::xmlparse($r,'tex',
                    172: 		       &Apache::lonannounce::showday(time,2,
                    173:                        &Apache::lonannounce::readcalendar($cdom.'_'.$cnum))));
                    174:     }
1.17      www       175: # -------------------------------------------------------- Get course personnel
                    176:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.28      sakharuk  177:     if ($target ne 'tex') {
                    178: 	$r->print('<table border="2">');
                    179:     } else {
1.37      sakharuk  180: 	$r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.28      sakharuk  181:     }
1.36      sakharuk  182:     foreach my $element (sort keys %coursepersonnel) {
1.28      sakharuk  183: 	if ($target ne 'tex') {
1.36      sakharuk  184: 	    $r->print('<tr><td>'.$element.'</td><td>');
1.28      sakharuk  185: 	} else {
1.36      sakharuk  186: 	    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & '); 
1.28      sakharuk  187: 	}
1.36      sakharuk  188:         foreach (split(/\,/,$coursepersonnel{$element})) {
1.17      www       189: 	    my ($puname,$pudom)=split(/\:/,$_);
1.28      sakharuk  190: 	    if ($target ne 'tex') {
                    191: 		$r->print(' '.&Apache::loncommon::aboutmewrapper(
                    192:                               &Apache::loncommon::plainname($puname,
                    193:                               $pudom),$puname,$pudom));
                    194: 	    } else {
                    195: 		$r->print(' '.&Apache::loncommon::plainname($puname,
                    196:                               $pudom).' ');
                    197: 	    }
1.17      www       198: 	}
1.28      sakharuk  199: 	if ($target ne 'tex') {
                    200: 	    $r->print('</td></tr>');
                    201: 	} else {
                    202: 	    $r->print('\\\\ \hline');
                    203: 	}
                    204:     }
                    205:     if ($target ne 'tex') {
                    206: 	$r->print('</table>');
                    207:     } else {
                    208: 	$r->print('\end{tabular}\\\\');
1.17      www       209:     }
                    210: # ---------------------------------------------------------- Load syllabus info
1.4       www       211:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5       www       212:     my $allowed=0;
1.27      www       213:     my $privileged=0;
1.4       www       214: 
1.2       www       215: # This handler might be called anonymously ...
                    216: # ----------------------------------------------------- Only if not public call
1.40      albertel  217:     if ($env{'user.environment'}) {
1.1       www       218: # does this user have privileges to post, etc?
1.40      albertel  219:        if ($env{'request.course.id'}) {
                    220:           $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27      www       221: 	  $privileged=$allowed;
                    222: 	  if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    223: 	      $forcestudent='student';
                    224: 	  }
1.30      sakharuk  225:           if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       226:        }
1.6       www       227:        if ($allowed) {
1.12      www       228:           $r->print('<p>'.
1.23      www       229: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>'.&mt('This syllabus can be publicly viewed at')
                    230: 		    .' <tt>http://'.
1.10      www       231: 		    $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
                    232:                &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47    ! www       233:           '<p>'.&mt('You can specify an external URL as Syllabus in the [_1].','<a href="/adm/parmset?action=crsenv">'.&mt('Course Parameters').'</a>').'</p>'.
1.27      www       234: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
                    235: &mt('Show Public View').'</font></a>'.
1.10      www       236:           &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
                    237:           '</p>');
1.27      www       238:       } elsif ($privileged) {
1.28      sakharuk  239: 	  if ($target ne 'tex') {
                    240: 	      $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
                    241: 			&mt('Edit').'</font></a>'); 
                    242: 	  }
1.6       www       243:       }
1.40      albertel  244:        if (($allowed) && ($env{'form.storesyl'})) {
1.5       www       245: 	   foreach (keys %syllabusfields) {
1.40      albertel  246:                my $field=$env{'form.'.$_};
1.33      www       247: 	       chomp($field);
1.5       www       248:                $field=~s/\s+$//s;
1.33      www       249: 	       $field=~s/^\s+//s;
                    250: 	       $field=~s/\<br\s*\/*\>$//s;
                    251: 	       $field=&Apache::lonfeedback::clear_out_html($field,1);
1.7       www       252: 	       $syllabus{$_}=$field;
1.9       www       253:                if ($_ eq 'lll_includeurl') { # clean up included URLs
                    254:                   my $field='';
                    255: 	          foreach (split(/\n/,$syllabus{$_})) {
                    256: 		      my $url=$_;
                    257: # get rid of leading and trailing spaces
                    258:                       $url=~s/^\s+//;
                    259:                       $url=~s/\s+$//;
                    260:                       if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
                    261:                           my $remainder=$2;
                    262: # remove the hostname from internal URLs
                    263: 		          foreach (keys %Apache::lonnet::hostname) {
                    264:                               if ($1=~/$Apache::lonnet::hostname{$_}/i) {
                    265: 			         $url=$remainder;
                    266: 			      }
                    267: 		          }
                    268: 		      }
                    269: # norm internal URLs
                    270:                       unless ($url=~/^http\:/) {
                    271: 		          $url=&Apache::lonnet::clutter($url);
                    272:                       }
                    273: # re-assemble field
                    274:                       if ($url) {
                    275: 		          $field.=$url."\n";
                    276:                       }
                    277: 		  }
                    278:                   $syllabus{$_}=$field;
                    279: 	      }
1.5       www       280:            }
1.40      albertel  281:            $syllabus{'uploaded.domain'}=$env{'user.domain'};
                    282:            $syllabus{'uploaded.name'}=$env{'user.name'};
1.5       www       283:            $syllabus{'uploaded.lastmodified'}=time;
                    284:            &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
                    285:        }
1.4       www       286:     }
                    287: # ---------------------------------------------------------------- Get syllabus
1.5       www       288:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8       www       289:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25      www       290:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26      albertel  291:        my $who = &Apache::loncommon::aboutmewrapper(
                    292:                     &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7       www       293:                      $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26      albertel  294:                      $syllabus{'uploaded.domain'});
1.28      sakharuk  295:        if ($target ne 'tex') {
                    296: 	   $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
                    297: 		     $lastmod.'</td><td>'.&mt('by').' '.$who.
                    298: 		     '</td></tr></table><p>');
                    299:        } else {
                    300: 	   $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.&mt('by').'\\\\ '.
                    301: 		     &Apache::loncommon::plainname($syllabus{'uploaded.name'},
                    302:                      $syllabus{'uploaded.domain'}).'\\\\');
                    303:        }
1.5       www       304:        if ($allowed) {
1.27      www       305: 	   $r->print('<form method="post">'.
                    306: 		     '<input type="hidden" name="forceedit" value="edit" />');
1.5       www       307:        }
1.33      www       308:        my @htmlids=();
1.5       www       309:        foreach (sort keys %syllabusfields) {
1.32      www       310:           if (($syllabus{$_}=~/\w/) || ($allowed)) {
1.5       www       311:               my $message=$syllabus{$_};
1.9       www       312:               if ($_ eq 'lll_includeurl') { # this is the "included" field
                    313: 		  my $urls=$message;
                    314:                   $message='';
                    315:                   foreach my $filelink (split(/\n/,$urls)) {
                    316: 		      my $output='';
                    317: # embed style?
                    318: 		      my ($curfext)=($filelink=~/\.([^\.]+)$/);
                    319:                       my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1.12      www       320: 	              if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9       www       321: # make ssi call and remove everything but the body contents
1.13      www       322: 			  $output=&Apache::lonnet::ssi_body($filelink);
1.9       www       323: 	              } elsif ($embstyle eq 'img') {
                    324: # embed as an image
                    325:                          $output='<img src="'.$filelink.'" />';
                    326: 		      }
1.34      sakharuk  327: 		      if ($target ne 'tex') {
                    328: 			  $message.='<p>'.$output.'</p>';
                    329: 		      } else {
                    330: 			  $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
                    331: 		      }		      
1.9       www       332:                   }
                    333:                   if ($allowed) {
                    334:                      $r->print('<h3>'.$syllabusfields{$_}.
1.10      www       335:           &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
1.27      www       336: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
1.10      www       337:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.9       www       338: 		 } else {
                    339:                   $r->print($message);
                    340:                  } 
                    341:               } else {
1.41      albertel  342: 		  &Apache::lonfeedback::newline_to_br(\$message);
1.9       www       343:                  $message
1.20      www       344:            =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.38      www       345: 		 if ($allowed) {
                    346: 		     $message=&Apache::lonspeller::markeduptext($message);
                    347: 		 }
1.9       www       348: 	         $message=&Apache::lontexconvert::msgtexconverted($message);
1.28      sakharuk  349: 		 if ($target ne 'tex') {
                    350: 		     $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
                    351:                                $message.'</blockquote>');
                    352: 		 } else {
                    353: 		     $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
1.31      sakharuk  354: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.28      sakharuk  355: 		 }
1.33      www       356: 		 push @htmlids,$_;
1.9       www       357: 	     }
1.5       www       358:               if ($allowed) {
1.33      www       359:                  $r->print(
                    360: 	   '<br /><textarea cols="80" rows="12" name="'.$_.'" id="'.$_.'">'.
1.5       www       361: 			   $syllabus{$_}.
1.33      www       362:            '</textarea> <input type="submit" name="storesyl" value="Store" />');
1.5       www       363: 	      }
                    364: 	  }
                    365:        }
                    366:        if ($allowed) {
1.32      www       367: 	   $r->print('</form>'.
1.33      www       368: 		     &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5       www       369:        }
1.28      sakharuk  370:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4       www       371:     } else {
1.36      sakharuk  372: 	if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');} 
                    373: 	$r->print('No syllabus information provided.');
                    374: 	if ($target ne 'tex') {$r->print('</p>');}
1.1       www       375:     }
1.28      sakharuk  376:     if ($target ne 'tex') {$r->print('</body></html>');} else {$r->print('\end{document}');}
1.1       www       377:     return OK;
                    378: } 
                    379: 
                    380: 1;
                    381: __END__

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