File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.41: download - view: text, annotated - select for diffs
Mon Jun 6 02:29:46 2005 UTC (19 years ago) by albertel
Branches: MAIN
CVS tags: version_2_0_X, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1, version_1_99_0, HEAD
- more bug#2667 fix up all of the other paces doing the blind \n to <br /> tranlation

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

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