File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.45: download - view: text, annotated - select for diffs
Mon Mar 6 22:17:48 2006 UTC (18 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
Working on external URL setting for Syllabus

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

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