File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.49: download - view: text, annotated - select for diffs
Tue Mar 21 21:25:33 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- trying to move more towards start_page

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

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