File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.43: download - view: text, annotated - select for diffs
Thu Nov 17 22:36:37 2005 UTC (18 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Fixing crappy HTML

    1: # The LearningOnline Network
    2: # Syllabus
    3: #
    4: # $Id: lonsyllabus.pm,v 1.43 2005/11/17 22:36:37 www 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::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::lonnet;
   35: use Apache::lontexconvert;
   36: use Apache::lonfeedback;
   37: use Apache::lonannounce;
   38: use Apache::lonlocal;
   39: use Apache::lonhtmlcommon;
   40: use Apache::lonspeller();
   41: 
   42: sub handler {
   43:     my $r = shift;
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46:     return OK if $r->header_only;
   47: 
   48: # ------------------------------------------------------------ Print the screen
   49:     my $target=$env{'form.grade_target'};
   50:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
   51:     my $feedurl='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss';
   52:     if ($target ne 'tex') {
   53: 	my $html=&Apache::lonxml::xmlbegin();
   54: 	$r->print(<<ENDDOCUMENT);
   55: $html
   56: <head>
   57: <title>The LearningOnline Network with CAPA</title>
   58: <link rel="alternate" type="application/rss+xml" title="Course Announcements" href="$feedurl" />
   59: ENDDOCUMENT
   60:     } else {
   61: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   62:     } 
   63: 
   64: # Is this even a course?
   65:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom); 
   66:     if ($homeserver eq 'no_host') {
   67: 	$r->print('</head><body>'.&mt('No syllabus available').'</body></html>');
   68:         return OK;
   69:     }
   70: # --------------------------------------------------------- The syllabus fields
   71:     my %syllabusfields=&Apache::lonlocal::texthash(
   72:        'aaa_instructorinfo' => 'Instructor Information',
   73:        'bbb_description'    => 'Course Description',
   74:        'ccc_prereq'         => 'Prerequisites',
   75:        'cdc_classhours'     => 'Class Hours',
   76:        'ddd_officehours'    => 'Office Hours',
   77:        'eee_helproom'       => 'Helproom Hours',
   78:        'efe_projectinfo'    => 'Project Information',
   79:        'fff_examinfo'       => 'Exam Information',
   80:        'fgf_deadlines'      => 'Deadlines',
   81:        'ggg_grading'        => 'Grading Information',
   82:        'hhh_readings'       => 'Readings',
   83:        'iii_coursepack'     => 'Coursepack',
   84:        'jjj_weblinks'       => 'Web Links',
   85:        'kkk_textbook'       => 'Textbook',
   86:        'lll_includeurl'     => 'URLs To Include in Syllabus');
   87: 
   88: # ------------------------------------------------------------ Get query string
   89:     &Apache::loncommon::get_unprocessed_cgi
   90:                         ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit']);
   91: # ----------------------------------------------------- Force menu registration
   92:     my $addentries='';
   93:     if ($env{'form.register'}) {
   94:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
   95: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
   96:        $r->print(&Apache::lonmenu::registerurl(1));
   97:     }
   98: # --------------------------------------------------------------- Force Student
   99:     my $forcestudent='';
  100:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
  101:     my $forceedit='';
  102:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
  103:        
  104: # ------------------------------------- There is such a course, get environment
  105:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
  106:     if ($target ne 'tex') {
  107: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
  108: 		  '</head>'.&Apache::loncommon::bodytag
  109:             ("Syllabus",$forcestudent,$addentries,'',$cdom,$env{'form.register'}));
  110: 	$r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
  111:                  $Apache::lonnet::domaindescription{$cdom}.'</h3>');
  112:     } else {
  113: 	$r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
  114:                  $Apache::lonnet::domaindescription{$cdom}.'}\\\\');
  115:     }
  116: # -------------------------------------------------------------- Announcements?
  117:     if ($target ne 'tex') {
  118: 	$r->print(&Apache::lonannounce::showday(time,2,
  119:                          &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)).
  120: 		  '<p>'.&mt('Course Announcement RSS Feed').': '.
  121: 		  '<a href="'.$feedurl.'"><tt>'.$feedurl.'</tt></a></p>');
  122:     } else {
  123: 	$r->print(&Apache::lonxml::xmlparse($r,'tex',
  124: 		       &Apache::lonannounce::showday(time,2,
  125:                        &Apache::lonannounce::readcalendar($cdom.'_'.$cnum))));
  126:     }
  127: # -------------------------------------------------------- Get course personnel
  128:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
  129:     if ($target ne 'tex') {
  130: 	$r->print('<table border="2">');
  131:     } else {
  132: 	$r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
  133:     }
  134:     foreach my $element (sort keys %coursepersonnel) {
  135: 	if ($target ne 'tex') {
  136: 	    $r->print('<tr><td>'.$element.'</td><td>');
  137: 	} else {
  138: 	    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & '); 
  139: 	}
  140:         foreach (split(/\,/,$coursepersonnel{$element})) {
  141: 	    my ($puname,$pudom)=split(/\:/,$_);
  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: 	    }
  150: 	}
  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}\\\\');
  161:     }
  162: # ---------------------------------------------------------- Load syllabus info
  163:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
  164:     my $allowed=0;
  165:     my $privileged=0;
  166: 
  167: # This handler might be called anonymously ...
  168: # ----------------------------------------------------- Only if not public call
  169:     if ($env{'user.environment'}) {
  170: # does this user have privileges to post, etc?
  171:        if ($env{'request.course.id'}) {
  172:           $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  173: 	  $privileged=$allowed;
  174: 	  if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  175: 	      $forcestudent='student';
  176: 	  }
  177:           if ($forcestudent or $target eq 'tex') { $allowed=0; }
  178:        }
  179:        if ($allowed) {
  180:           $r->print('<p>'.
  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://'.
  183: 		    $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
  184:                &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
  185: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
  186: &mt('Show Public View').'</font></a>'.
  187:           &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
  188:           '</p>');
  189:       } elsif ($privileged) {
  190: 	  if ($target ne 'tex') {
  191: 	      $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
  192: 			&mt('Edit').'</font></a>'); 
  193: 	  }
  194:       }
  195:        if (($allowed) && ($env{'form.storesyl'})) {
  196: 	   foreach (keys %syllabusfields) {
  197:                my $field=$env{'form.'.$_};
  198: 	       chomp($field);
  199:                $field=~s/\s+$//s;
  200: 	       $field=~s/^\s+//s;
  201: 	       $field=~s/\<br\s*\/*\>$//s;
  202: 	       $field=&Apache::lonfeedback::clear_out_html($field,1);
  203: 	       $syllabus{$_}=$field;
  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: 	      }
  231:            }
  232:            $syllabus{'uploaded.domain'}=$env{'user.domain'};
  233:            $syllabus{'uploaded.name'}=$env{'user.name'};
  234:            $syllabus{'uploaded.lastmodified'}=time;
  235:            &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
  236:        }
  237:     }
  238: # ---------------------------------------------------------------- Get syllabus
  239:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  240:        my $lastmod=$syllabus{'uploaded.lastmodified'};
  241:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  242:        my $who = &Apache::loncommon::aboutmewrapper(
  243:                     &Apache::loncommon::plainname($syllabus{'uploaded.name'},
  244:                      $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
  245:                      $syllabus{'uploaded.domain'});
  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:        }
  255:        if ($allowed) {
  256: 	   $r->print('<form method="post">'.
  257: 		     '<input type="hidden" name="forceedit" value="edit" />');
  258:        }
  259:        my @htmlids=();
  260:        foreach (sort keys %syllabusfields) {
  261:           if (($syllabus{$_}=~/\w/) || ($allowed)) {
  262:               my $message=$syllabus{$_};
  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);
  271: 	              if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
  272: # make ssi call and remove everything but the body contents
  273: 			  $output=&Apache::lonnet::ssi_body($filelink);
  274: 	              } elsif ($embstyle eq 'img') {
  275: # embed as an image
  276:                          $output='<img src="'.$filelink.'" />';
  277: 		      }
  278: 		      if ($target ne 'tex') {
  279: 			  $message.='<p>'.$output.'</p>';
  280: 		      } else {
  281: 			  $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
  282: 		      }		      
  283:                   }
  284:                   if ($allowed) {
  285:                      $r->print('<h3>'.$syllabusfields{$_}.
  286:           &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
  287: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
  288:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  289: 		 } else {
  290:                   $r->print($message);
  291:                  } 
  292:               } else {
  293: 		  &Apache::lonfeedback::newline_to_br(\$message);
  294:                  $message
  295:            =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  296: 		 if ($allowed) {
  297: 		     $message=&Apache::lonspeller::markeduptext($message);
  298: 		 }
  299: 	         $message=&Apache::lontexconvert::msgtexconverted($message);
  300: 		 if ($target ne 'tex') {
  301: 		     $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
  302:                                $message.'</blockquote>');
  303: 		 } else {
  304: 		     $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
  305: 			       &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
  306: 		 }
  307: 		 push @htmlids,$_;
  308: 	     }
  309:               if ($allowed) {
  310:                  $r->print(
  311: 	   '<br /><textarea cols="80" rows="12" name="'.$_.'" id="'.$_.'">'.
  312: 			   $syllabus{$_}.
  313:            '</textarea> <input type="submit" name="storesyl" value="Store" />');
  314: 	      }
  315: 	  }
  316:        }
  317:        if ($allowed) {
  318: 	   $r->print('</form>'.
  319: 		     &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
  320:        }
  321:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
  322:     } else {
  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>');}
  326:     }
  327:     if ($target ne 'tex') {$r->print('</body></html>');} else {$r->print('\end{document}');}
  328:     return OK;
  329: } 
  330: 
  331: 1;
  332: __END__

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