File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.46: download - view: text, annotated - select for diffs
Mon Mar 6 23:02:22 2006 UTC (18 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Moving stuff in a more logical order, also prepare for external syllabus

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

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