File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.25: download - view: text, annotated - select for diffs
Sat Oct 4 20:49:40 2003 UTC (20 years, 7 months ago) by www
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
Internationalization, and in particular, lonlocal:locallocaltime and
Japanese dates.

    1: # The LearningOnline Network
    2: # Syllabus
    3: #
    4: # $Id: lonsyllabus.pm,v 1.25 2003/10/04 20:49:40 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: 
   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:     $r->print(<<ENDDOCUMENT);
   48: <html>
   49: <head>
   50: <title>The LearningOnline Network with CAPA</title>
   51: ENDDOCUMENT
   52:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
   53: # Is this even a course?
   54:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom); 
   55:     if ($homeserver eq 'no_host') {
   56: 	$r->print('</head><body>'.&mt('No syllabus available').'</body></html>');
   57:         return OK;
   58:     }
   59: # --------------------------------------------------------- The syllabus fields
   60:     my %syllabusfields=&Apache::lonlocal::texthash(
   61:        'aaa_instructorinfo' => 'Instructor Information',
   62:        'bbb_description'    => 'Course Description',
   63:        'ccc_prereq'         => 'Prerequisites',
   64:        'cdc_classhours'     => 'Class Hours',
   65:        'ddd_officehours'    => 'Office Hours',
   66:        'eee_helproom'       => 'Helproom Hours',
   67:        'efe_projectinfo'    => 'Project Information',
   68:        'fff_examinfo'       => 'Exam Information',
   69:        'fgf_deadlines'      => 'Deadlines',
   70:        'ggg_grading'        => 'Grading Information',
   71:        'hhh_readings'       => 'Readings',
   72:        'iii_coursepack'     => 'Coursepack',
   73:        'jjj_weblinks'       => 'Web Links',
   74:        'kkk_textbook'       => 'Textbook',
   75:        'lll_includeurl'     => 'URLs To Include in Syllabus');
   76: 
   77: # ------------------------------------------------------------ Get query string
   78:     &Apache::loncommon::get_unprocessed_cgi
   79:                         ($ENV{'QUERY_STRING'},['forcestudent','register']);
   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: # --------------------------------------------------------------- Force Student
   88:     my $forcestudent='';
   89:     if ($ENV{'form.forcestudent'}) { $forcestudent='student'; };
   90:        
   91: # ------------------------------------- There is such a course, get environment
   92:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
   93:     $r->print('</head>'.&Apache::loncommon::bodytag
   94:        ("Syllabus",$forcestudent,$addentries,'',$cdom,$ENV{'form.register'}));
   95:     $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
   96:               $Apache::lonnet::domaindescription{$cdom}.'</h3>');
   97: # -------------------------------------------------------------- Announcements?
   98:     $r->print(&Apache::lonannounce::showday(time,2,
   99:                          &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)));
  100: # -------------------------------------------------------- Get course personnel
  101:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
  102:     $r->print('<table border="2">');
  103:     foreach (sort keys %coursepersonnel) {
  104: 	$r->print('<tr><td>'.$_.'</td><td>');
  105:         foreach (split(/\,/,$coursepersonnel{$_})) {
  106: 	    my ($puname,$pudom)=split(/\:/,$_);
  107: 	    $r->print(' '.&Apache::loncommon::aboutmewrapper(
  108:                           &Apache::loncommon::plainname($puname,
  109:                           $pudom),$puname,$pudom));
  110: 	}
  111:         $r->print('</td></tr>');
  112:     }
  113:     $r->print('</table>');
  114: # ---------------------------------------------------------- Load syllabus info
  115:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
  116:     my $allowed=0;
  117: 
  118: # This handler might be called anonymously ...
  119: # ----------------------------------------------------- Only if not public call
  120:     if ($ENV{'user.environment'}) {
  121: # does this user have privileges to post, etc?
  122:        if ($ENV{'request.course.id'}) {
  123:           $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
  124:           if ($forcestudent) { $allowed=0; }
  125:        }
  126:        if ($allowed) {
  127:           $r->print('<p>'.
  128: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>'.&mt('This syllabus can be publicly viewed at')
  129: 		    .' <tt>http://'.
  130: 		    $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
  131:                &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
  132: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">Show Public View</font></a>'.
  133:           &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
  134:           '</p>');
  135:       }
  136:        if (($allowed) && ($ENV{'form.storesyl'})) {
  137: 	   foreach (keys %syllabusfields) {
  138:                my $field=$ENV{'form.'.$_};
  139:                $field=~s/\s+$//s;
  140:                $field=&Apache::lonfeedback::clear_out_html($field,1);
  141: 	       $syllabus{$_}=$field;
  142:                if ($_ eq 'lll_includeurl') { # clean up included URLs
  143:                   my $field='';
  144: 	          foreach (split(/\n/,$syllabus{$_})) {
  145: 		      my $url=$_;
  146: # get rid of leading and trailing spaces
  147:                       $url=~s/^\s+//;
  148:                       $url=~s/\s+$//;
  149:                       if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
  150:                           my $remainder=$2;
  151: # remove the hostname from internal URLs
  152: 		          foreach (keys %Apache::lonnet::hostname) {
  153:                               if ($1=~/$Apache::lonnet::hostname{$_}/i) {
  154: 			         $url=$remainder;
  155: 			      }
  156: 		          }
  157: 		      }
  158: # norm internal URLs
  159:                       unless ($url=~/^http\:/) {
  160: 		          $url=&Apache::lonnet::clutter($url);
  161:                       }
  162: # re-assemble field
  163:                       if ($url) {
  164: 		          $field.=$url."\n";
  165:                       }
  166: 		  }
  167:                   $syllabus{$_}=$field;
  168: 	      }
  169:            }
  170:            $syllabus{'uploaded.domain'}=$ENV{'user.domain'};
  171:            $syllabus{'uploaded.name'}=$ENV{'user.name'};
  172:            $syllabus{'uploaded.lastmodified'}=time;
  173:            &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
  174:        }
  175:     }
  176: # ---------------------------------------------------------------- Get syllabus
  177:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  178:        my $lastmod=$syllabus{'uploaded.lastmodified'};
  179:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
  180: 
  181:        $r->print('<table><tr><td>'.&mt('Uploaded').':</td><td>'.
  182:  &Apache::loncommon::aboutmewrapper(
  183:  &Apache::loncommon::plainname($syllabus{'uploaded.name'},
  184:                      $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
  185:                      $syllabus{'uploaded.domain'}).
  186:  '</td></tr><tr><td>'.&mt('Last updated').':</td><td>'.
  187:                      $lastmod.
  188:                      '</td></tr></table><p>');
  189:        if ($allowed) {
  190: 	   $r->print('<form method="post">');
  191:        }
  192:        foreach (sort keys %syllabusfields) {
  193:           if (($syllabus{$_}) || ($allowed)) {
  194:               my $message=$syllabus{$_};
  195:               if ($_ eq 'lll_includeurl') { # this is the "included" field
  196: 		  my $urls=$message;
  197:                   $message='';
  198:                   foreach my $filelink (split(/\n/,$urls)) {
  199: 		      my $output='';
  200: # embed style?
  201: 		      my ($curfext)=($filelink=~/\.([^\.]+)$/);
  202:                       my $embstyle=&Apache::loncommon::fileembstyle($curfext);
  203: 	              if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
  204: # make ssi call and remove everything but the body contents
  205: 			  $output=&Apache::lonnet::ssi_body($filelink);
  206: 	              } elsif ($embstyle eq 'img') {
  207: # embed as an image
  208:                          $output='<img src="'.$filelink.'" />';
  209: 		      }
  210:                       $message.='<p>'.$output.'</p>';
  211:                   }
  212:                   if ($allowed) {
  213:                      $r->print('<h3>'.$syllabusfields{$_}.
  214:           &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
  215: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">Show Public View</font></a>'.
  216:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  217: 		 } else {
  218:                   $r->print($message);
  219:                  } 
  220:               } else {
  221:                  $message=~s/\n/\<br \/\>/g;
  222:                  $message
  223:            =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  224: 	         $message=&Apache::lontexconvert::msgtexconverted($message);
  225:                  $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
  226:                         $message.'</blockquote>');
  227: 	     }
  228:               if ($allowed) {
  229:                  $r->print('<br /><textarea cols="80" rows="6" name="'.$_.'">'.
  230: 			   $syllabus{$_}.
  231:            '</textarea><input type="submit" name="storesyl" value="Store" />');
  232: 	      }
  233: 	  }
  234:        }
  235:        if ($allowed) {
  236: 	   $r->print('</form>');
  237:        }
  238:        $r->print('</p>');
  239:     } else {
  240:        $r->print('<p>No syllabus information provided.</p>');
  241:     }
  242:     $r->print('</body></html>');
  243:     return OK;
  244: } 
  245: 
  246: 1;
  247: __END__

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