File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.31: download - view: text, annotated - select for diffs
Mon May 10 14:12:14 2004 UTC (20 years, 1 month ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Added 'tex' target in xmlparse call.

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

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