File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.38: download - view: text, annotated - select for diffs
Tue Jul 27 23:35:34 2004 UTC (19 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_99_1, version_1_2_99_0, HEAD
Spelling links

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

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