File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.48: download - view: text, annotated - select for diffs
Wed Mar 15 19:41:26 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- converting some interface pages to stop generating </body> <head> </head> </html> and use the helper functions instead

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

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