Annotation of loncom/interface/lonsyllabus.pm, revision 1.27

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

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