File:  [LON-CAPA] / loncom / interface / lonsyllabus.pm
Revision 1.53: download - view: text, annotated - select for diffs
Tue Aug 1 13:55:07 2006 UTC (17 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_99_3, version_2_1_99_2, HEAD
- validate that the course to be editted is the current course

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

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