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

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

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