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

1.1       www         1: # The LearningOnline Network
                      2: # Syllabus
                      3: #
1.64    ! raeburn     4: # $Id: lonsyllabus.pm,v 1.63 2008/01/16 17:13:57 bisitz 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.32      www        39: use Apache::lonhtmlcommon;
1.38      www        40: use Apache::lonspeller();
1.54      albertel   41: use HTML::Entities();
1.1       www        42: 
                     43: sub handler {
                     44:     my $r = shift;
1.46      www        45:     &Apache::loncommon::content_type($r,'text/html');
                     46:     $r->send_http_header;
                     47:     return OK if $r->header_only;
1.45      www        48: 
1.46      www        49:     my $target=$env{'form.grade_target'};
1.45      www        50: # --------------------------------------------------- Get course info from URL
                     51:     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46      www        52: # ------------------------------------------------------------ Get query string
                     53:     &Apache::loncommon::get_unprocessed_cgi
1.47      www        54:                         ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
1.45      www        55: # ----------------------------------------------------- Is this even a course?
                     56:     my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
                     57:     if ($homeserver eq 'no_host') {
                     58:         &Apache::loncommon::content_type($r,'text/html');
                     59:         $r->send_http_header;
1.49      albertel   60:       	&Apache::loncommon::simple_error_page($r,'No syllabus available',
                     61: 					      'No syllabus available');
1.45      www        62:         return OK;
                     63:     }
                     64: # ------------------------------------- There is such a course, get environment
                     65:     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46      www        66: 
1.1       www        67: # ------------------------------------------------------------ Print the screen
1.49      albertel   68: 
                     69:     if ($target eq 'tex') {
1.40      albertel   70: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28      sakharuk   71:     } 
1.46      www        72: # -------------------------------------------------- Let's see who handles this
1.47      www        73:     my $externalsyllabus=$courseenv{'externalsyllabus'};
1.49      albertel   74: 
1.46      www        75:     if ($externalsyllabus=~/\w/) {
1.50      albertel   76: 	
1.47      www        77:        if ($env{'form.wrapperdisplay'} eq 'menu') {
1.50      albertel   78: 	   $r->print(&Apache::lonwrapper::simple_menu());
                     79:        } else {	    
                     80: 	   $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
                     81: 						   $externalsyllabus));
                     82:        }
                     83:        return OK;
1.47      www        84:      } 
1.42      www        85: 
1.46      www        86: # ------------------------------ The buck stops here: internal syllabus display
1.5       www        87: # --------------------------------------------------------- The syllabus fields
1.23      www        88:     my %syllabusfields=&Apache::lonlocal::texthash(
1.5       www        89:        'aaa_instructorinfo' => 'Instructor Information',
                     90:        'bbb_description'    => 'Course Description',
                     91:        'ccc_prereq'         => 'Prerequisites',
1.7       www        92:        'cdc_classhours'     => 'Class Hours',
1.5       www        93:        'ddd_officehours'    => 'Office Hours',
                     94:        'eee_helproom'       => 'Helproom Hours',
1.7       www        95:        'efe_projectinfo'    => 'Project Information',
1.5       www        96:        'fff_examinfo'       => 'Exam Information',
1.7       www        97:        'fgf_deadlines'      => 'Deadlines',
1.5       www        98:        'ggg_grading'        => 'Grading Information',
1.7       www        99:        'hhh_readings'       => 'Readings',
                    100:        'iii_coursepack'     => 'Coursepack',
                    101:        'jjj_weblinks'       => 'Web Links',
1.9       www       102:        'kkk_textbook'       => 'Textbook',
                    103:        'lll_includeurl'     => 'URLs To Include in Syllabus');
1.6       www       104: # --------------------------------------------------------------- Force Student
                    105:     my $forcestudent='';
1.40      albertel  106:     if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27      www       107:     my $forceedit='';
1.40      albertel  108:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.5       www       109:        
1.45      www       110: # ----------------------------------------------------------------- Make header 
1.28      sakharuk  111:     if ($target ne 'tex') {
1.60      albertel  112: 	my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.49      albertel  113: 	my $start_page = 
                    114: 	    &Apache::loncommon::start_page("Syllabus", $rss_link,
                    115: 					   {'function'       => $forcestudent,
                    116: 					    'domain'         => $cdom,
                    117: 					    'force_register' =>
                    118: 						$env{'form.register'},});
                    119: 
                    120: 	$r->print($start_page.'<h1>'.$courseenv{'description'}.'</h1><h3>'.
1.58      albertel  121: 		  &Apache::lonnet::domain($cdom,'description').'</h3>');
1.28      sakharuk  122:     } else {
1.29      sakharuk  123: 	$r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.58      albertel  124: 		  &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.28      sakharuk  125:     }
1.19      www       126: # -------------------------------------------------------------- Announcements?
1.49      albertel  127:     my $day = &Apache::lonannounce::showday(time,2,
                    128: 			 &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.35      sakharuk  129:     if ($target ne 'tex') {
1.52      www       130: 	$r->print($day. &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
1.35      sakharuk  131:     } else {
1.49      albertel  132: 	$r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.35      sakharuk  133:     }
1.49      albertel  134: 
1.17      www       135: # -------------------------------------------------------- Get course personnel
                    136:     my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.28      sakharuk  137:     if ($target ne 'tex') {
1.62      albertel  138: 	$r->print(&Apache::loncommon::start_data_table());
1.28      sakharuk  139:     } else {
1.37      sakharuk  140: 	$r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.28      sakharuk  141:     }
1.36      sakharuk  142:     foreach my $element (sort keys %coursepersonnel) {
1.28      sakharuk  143: 	if ($target ne 'tex') {
1.62      albertel  144: 	    $r->print(&Apache::loncommon::start_data_table_row().
                    145: 		      '<td>'.$element.'</td><td>');
1.28      sakharuk  146: 	} else {
1.36      sakharuk  147: 	    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & '); 
1.28      sakharuk  148: 	}
1.36      sakharuk  149:         foreach (split(/\,/,$coursepersonnel{$element})) {
1.17      www       150: 	    my ($puname,$pudom)=split(/\:/,$_);
1.28      sakharuk  151: 	    if ($target ne 'tex') {
1.64    ! raeburn   152:                 my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
        !           153:                 if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
        !           154:                     ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
        !           155: 		    $r->print(' '.$courseperson);
        !           156:                 } else {
        !           157:                     $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson),
        !           158:                               $puname,$pudom);
        !           159:                 }
1.28      sakharuk  160: 	    } else {
                    161: 		$r->print(' '.&Apache::loncommon::plainname($puname,
                    162:                               $pudom).' ');
                    163: 	    }
1.17      www       164: 	}
1.28      sakharuk  165: 	if ($target ne 'tex') {
1.62      albertel  166: 	    $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.28      sakharuk  167: 	} else {
                    168: 	    $r->print('\\\\ \hline');
                    169: 	}
                    170:     }
                    171:     if ($target ne 'tex') {
1.62      albertel  172: 	$r->print(&Apache::loncommon::end_data_table());
1.28      sakharuk  173:     } else {
                    174: 	$r->print('\end{tabular}\\\\');
1.17      www       175:     }
                    176: # ---------------------------------------------------------- Load syllabus info
1.4       www       177:     my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5       www       178:     my $allowed=0;
1.27      www       179:     my $privileged=0;
1.4       www       180: 
1.2       www       181: # This handler might be called anonymously ...
                    182: # ----------------------------------------------------- Only if not public call
1.40      albertel  183:     if ($env{'user.environment'}) {
1.1       www       184: # does this user have privileges to post, etc?
1.53      albertel  185:        if ($env{'request.course.id'}
                    186: 	   && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
                    187: 	   && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.40      albertel  188:           $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27      www       189: 	  $privileged=$allowed;
                    190: 	  if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    191: 	      $forcestudent='student';
                    192: 	  }
1.30      sakharuk  193:           if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2       www       194:        }
1.6       www       195:        if ($allowed) {
1.12      www       196:           $r->print('<p>'.
1.63      bisitz    197: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p>'.&mt('This syllabus can be publicly viewed at')
1.23      www       198: 		    .' <tt>http://'.
1.57      albertel  199: 		    &Apache::lonnet::hostname($homeserver).$r->uri.'</tt>'.
1.10      www       200:                &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47      www       201:           '<p>'.&mt('You can specify an external URL as Syllabus in the [_1].','<a href="/adm/parmset?action=crsenv">'.&mt('Course Parameters').'</a>').'</p>'.
1.27      www       202: 	  '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
                    203: &mt('Show Public View').'</font></a>'.
1.10      www       204:           &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
                    205:           '</p>');
1.27      www       206:       } elsif ($privileged) {
1.28      sakharuk  207: 	  if ($target ne 'tex') {
                    208: 	      $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
                    209: 			&mt('Edit').'</font></a>'); 
                    210: 	  }
1.6       www       211:       }
1.40      albertel  212:        if (($allowed) && ($env{'form.storesyl'})) {
1.55      albertel  213: 	   foreach my $syl_field (keys(%syllabusfields)) {
                    214:                my $field=$env{'form.'.$syl_field};
1.33      www       215: 	       chomp($field);
1.5       www       216:                $field=~s/\s+$//s;
1.33      www       217: 	       $field=~s/^\s+//s;
                    218: 	       $field=~s/\<br\s*\/*\>$//s;
                    219: 	       $field=&Apache::lonfeedback::clear_out_html($field,1);
1.55      albertel  220: 	       $syllabus{$syl_field}=$field;
                    221:                if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1.9       www       222:                   my $field='';
1.55      albertel  223: 	          foreach my $value (split(/\n/,$syllabus{$syl_field})) {
                    224: 		      my $url=$value;
1.9       www       225: # get rid of leading and trailing spaces
                    226:                       $url=~s/^\s+//;
                    227:                       $url=~s/\s+$//;
1.55      albertel  228:                       if ($url=~m|^http://([^/]+)/(.+)$|) {
                    229: 			  my $host = $1;
1.9       www       230:                           my $remainder=$2;
                    231: # remove the hostname from internal URLs
1.57      albertel  232: 			  my $hostname = &Apache::lonnet::hostname($host);
                    233: 			  my %all_hostnames = &Apache::lonnet::all_hostnames();
                    234: 		          foreach my $possible_host (keys(%all_hostnames)) {
                    235:                               if ($possible_host =~ /\Q$hostname\E/i) {
1.9       www       236: 			         $url=$remainder;
                    237: 			      }
                    238: 		          }
                    239: 		      }
                    240: # norm internal URLs
                    241:                       unless ($url=~/^http\:/) {
                    242: 		          $url=&Apache::lonnet::clutter($url);
                    243:                       }
                    244: # re-assemble field
                    245:                       if ($url) {
                    246: 		          $field.=$url."\n";
                    247:                       }
                    248: 		  }
1.55      albertel  249:                   $syllabus{$syl_field}=$field;
1.9       www       250: 	      }
1.5       www       251:            }
1.40      albertel  252:            $syllabus{'uploaded.domain'}=$env{'user.domain'};
                    253:            $syllabus{'uploaded.name'}=$env{'user.name'};
1.5       www       254:            $syllabus{'uploaded.lastmodified'}=time;
                    255:            &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
                    256:        }
1.4       www       257:     }
                    258: # ---------------------------------------------------------------- Get syllabus
1.5       www       259:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8       www       260:        my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25      www       261:        $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26      albertel  262:        my $who = &Apache::loncommon::aboutmewrapper(
                    263:                     &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7       www       264:                      $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26      albertel  265:                      $syllabus{'uploaded.domain'});
1.28      sakharuk  266:        if ($target ne 'tex') {
                    267: 	   $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
1.61      albertel  268: 		     $lastmod.'</td><td>'.
                    269: 		     ($who ? &mt('by').' '.$who
                    270:                            : '' ).
1.28      sakharuk  271: 		     '</td></tr></table><p>');
                    272:        } else {
1.61      albertel  273: 	   $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
                    274: 		     ($who? &mt('by').'\\\\ '.
                    275: 		            &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
                    276: 		          :'')
                    277: 		     .'\\\\');
1.28      sakharuk  278:        }
1.5       www       279:        if ($allowed) {
1.27      www       280: 	   $r->print('<form method="post">'.
                    281: 		     '<input type="hidden" name="forceedit" value="edit" />');
1.5       www       282:        }
1.33      www       283:        my @htmlids=();
1.55      albertel  284:        foreach my $field (sort(keys(%syllabusfields))) {
                    285: 	   if (($syllabus{$field}=~/\w/) || ($allowed)) {
                    286: 	       my $message=$syllabus{$field};
                    287: 	       if ($field eq 'lll_includeurl') { # this is the "included" field
                    288: 		   my $urls=$message;
                    289: 		   $message='';
                    290: 		   foreach my $filelink (split(/\n/,$urls)) {
                    291: 		       my $output='';
1.9       www       292: # embed style?
1.55      albertel  293: 		       my ($curfext)=($filelink=~/\.([^\.]+)$/);
                    294: 		       my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                    295: 		       if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9       www       296: # make ssi call and remove everything but the body contents
1.55      albertel  297: 			   $output=&Apache::lonnet::ssi_body($filelink);
                    298: 		       } elsif ($embstyle eq 'img') {
1.9       www       299: # embed as an image
1.55      albertel  300: 			   $output='<img src="'.$filelink.'" />';
                    301: 		       }
                    302: 		       if ($target ne 'tex') {
                    303: 			   $message.='<p>'.$output.'</p>';
                    304: 		       } else {
                    305: 			   $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
                    306: 		       }      
                    307: 		   }
                    308: 		   if ($allowed) {
                    309: 		       $r->print('<h3>'.$syllabusfields{$field}.
                    310: 				 &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
                    311: 				 '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
                    312: 				 &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
                    313: 		   } else {
                    314: 		       $r->print($message);
                    315: 		   } 
                    316: 	       } else {
                    317: 		   &Apache::lonfeedback::newline_to_br(\$message);
1.56      banghart  318: 		   $message =~s|(https*://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
1.55      albertel  319: 		   if ($allowed) {
                    320: 		       $message=&Apache::lonspeller::markeduptext($message);
                    321: 		   }
                    322: 		   $message=&Apache::lontexconvert::msgtexconverted($message);
                    323: 		   if ($target ne 'tex') {
                    324: 		       $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
                    325: 				 $message.'</blockquote>');
                    326: 		   } else {
                    327: 		       $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
                    328: 				 &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
                    329: 		   }
                    330: 		   push(@htmlids,$field);
                    331: 	       }
                    332: 	       if ($allowed) {
                    333: 		   $r->print('<br /><textarea cols="80" rows="12" name="'.$field.'" id="'.$field.'">'.
                    334: 			     &HTML::Entities::encode($syllabus{$field},'"&<>').
1.63      bisitz    335: 			     '</textarea> <input type="submit" name="storesyl" value="'.&mt('Save').'" />');
1.55      albertel  336: 	       }
                    337: 	   }
1.5       www       338:        }
                    339:        if ($allowed) {
1.32      www       340: 	   $r->print('</form>'.
1.33      www       341: 		     &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5       www       342:        }
1.28      sakharuk  343:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4       www       344:     } else {
1.36      sakharuk  345: 	if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');} 
1.63      bisitz    346: 	$r->print(&mt('No syllabus information provided.'));
1.36      sakharuk  347: 	if ($target ne 'tex') {$r->print('</p>');}
1.1       www       348:     }
1.48      albertel  349:     if ($target ne 'tex') {
                    350: 	$r->print(&Apache::loncommon::end_page());
                    351:     } else {
                    352: 	$r->print('\end{document}');
                    353:     }
1.1       www       354:     return OK;
                    355: } 
                    356: 
                    357: 1;
                    358: __END__

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