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

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

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