File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.33: download - view: text, annotated - select for diffs
Thu Jun 3 14:28:39 2004 UTC (20 years ago) by www
Branches: MAIN
CVS tags: version_1_1_99_0, HEAD
HTMLarea - only have 5 minutes.

There are lots of odd problems with Mozilla, not just meta-refresh, but
also popup windows and one random segmentation fault.

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

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