File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.21: download - view: text, annotated - select for diffs
Thu Jun 3 14:28:39 2004 UTC (19 years, 10 months ago) by www
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
HTMLarea - only have 5 minutes.

There are lots of odd problems with Mozilla, not just meta-refresh, but
also popup windows and one random segmentation fault.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonsimplepage.pm,v 1.21 2004/06/03 14:28:39 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::lonsimplepage;
   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::lonlocal;
   38: use Apache::lonprintout;
   39: use Apache::lonxml;
   40: 
   41: sub handler {
   42:     my $r = shift;
   43:     $r->content_type('text/html');
   44:     $r->send_http_header;
   45:     return OK if $r->header_only;
   46:     my $target=$ENV{'form.grade_target'};
   47: # ------------------------------------------------------------ Print the screen
   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,undef,undef,$marker)=split(/\//,$r->uri);
   58: # Is this even in a course?
   59:     unless ($ENV{'request.course.id'}) {
   60: 	if ($target ne 'tex') {
   61: 	    $r->print('</head><body>Not in a course</body></html>');
   62: 	    return OK;
   63: 	} else {
   64: 	    $r->print('\textbf{Not in a course}\end{document}');
   65: 	}
   66:     }
   67: 
   68:     $marker=~s/\D//g;
   69: 
   70:     unless ($marker) {
   71: 	$r->print('<body>Invalid call</body>');
   72:         return OK;
   73:     }
   74: 
   75:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
   76:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
   77: 
   78: # --------------------------------------------------------- The syllabus fields
   79:     my %syllabusfields=&Apache::lonlocal::texthash(
   80:        'aaa_title'         => 'Page Title',
   81:        'bbb_content'       => 'Content',
   82:        'ccc_webreferences' => 'Web References');
   83: 
   84: 
   85: # ------------------------------------------------------------ Get query string
   86:     &Apache::loncommon::get_unprocessed_cgi
   87:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
   88: # ----------------------------------------------------- Force menu registration
   89:     my $addentries='';
   90:     if ($ENV{'form.register'}) {
   91:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
   92: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
   93:        $r->print(&Apache::lonmenu::registerurl(1));
   94:     }
   95: # --------------------------------------------------------------- Force Student
   96:     my $forcestudent='';
   97:     if ($ENV{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
   98:      my $forceedit='';
   99:      if ($ENV{'form.forceedit'}) { $forceedit='edit'; }
  100: 
  101: 
  102:     my %syllabus=&Apache::lonnet::dump('smppage_'.$marker,$dom,$crs);
  103:        
  104: # --------------------------------------- There is such a user, get environment
  105: 
  106:     if ($target ne 'tex') {
  107: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
  108: 		  '</head>'.&Apache::loncommon::bodytag
  109: 		  ("Course Page",$forcestudent,$addentries,'',$dom,$ENV{'form.register'}));
  110:     }
  111: 
  112:     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
  113:     my $privileged=$allowed;
  114:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  115: 	$forcestudent='student';
  116:     }
  117: 
  118:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
  119:     
  120:     if ($allowed) {
  121: 	$r->print('<p>'.
  122: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Student View').'</font></a>'.
  123: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  124:     } elsif ($privileged and $target ne 'tex') {
  125: 	$r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'.&mt('Edit').'</font></a>');
  126:     } 
  127:     if (($ENV{'form.uploaddoc.filename'} and $target ne 'tex') &&
  128: 	($ENV{'form.storeupl'}) && ($allowed)) {
  129: 	if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  130: 	    if ($syllabus{'uploaded.photourl'}) {
  131: 		&Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  132: 	    }
  133: 	    $syllabus{'uploaded.photourl'}=
  134: 		&Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
  135: 	}
  136: 	$syllabus{'uploaded.lastmodified'}=time;
  137: 	&Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
  138:     }
  139:     if (($allowed) && ($ENV{'form.storesyl'})) {
  140: 	foreach (keys %syllabusfields) {
  141: 	    my $field=$ENV{'form.'.$_};
  142: 	    chomp($field);
  143: 	    $field=~s/\s+$//s;
  144: 	    $field=~s/^\s+//s;
  145: 	    $field=~s/\<br\s*\/*\>$//s;
  146: 	    $field=&Apache::lonfeedback::clear_out_html($field,1);
  147: 	    $syllabus{$_}=$field;
  148: 	}
  149: 	$syllabus{'uploaded.lastmodified'}=time;
  150: 	&Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
  151:     }
  152: 
  153: # ---------------------------------------------------------------- Get syllabus
  154:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  155: 	if ($syllabus{'uploaded.photourl'}) {
  156: 	    &Apache::lonnet::allowuploaded('/adm/smppg',
  157: 					   $syllabus{'uploaded.photourl'});
  158: 	    
  159: 	    my $image='<img src="'.$syllabus{'uploaded.photourl'}.'"
  160:                             align="right" />';
  161: 	    if ($target eq 'tex') {
  162: 		$image=&Apache::lonxml::xmlparse($r,'tex',$image);
  163: 	    }
  164: 	    $r->print($image);
  165: 	}
  166: 	if ($allowed) {
  167: 	    $r->print(
  168: 		      '<form method="post" enctype="multipart/form-data">'.
  169: 		      '<input type="hidden" name="forceedit" value="edit" />'.
  170: 		      '<h3>Upload a Photo</h3>'.
  171: 		      '<input type="file" name="uploaddoc" size="50">'.
  172: 		      '<input type="submit" name="storeupl" value="Upload">'.
  173: 		      '</form><form method="post">');
  174: 	}
  175: 	foreach (sort keys %syllabusfields) {
  176: 	    if (($syllabus{$_}) || ($allowed)) {
  177: 		my $message=$syllabus{$_};
  178: 		$message=~s/\n/\<br \/\>/g;
  179: 		$message
  180: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  181: 		$message=&Apache::lontexconvert::msgtexconverted($message);
  182: 		unless ($_ eq 'aaa_title') {
  183: 		    if (($_ ne 'bbb_content') || ($allowed)) {
  184: 			if ($target ne 'tex') {
  185: 			    $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  186: 			} else {
  187: 			    my $safeinit;
  188: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
  189: 			}
  190: 		    }
  191: 		    if ($target ne 'tex') {
  192: 			$r->print('<blockquote>'.
  193: 				  $message.'</blockquote>');
  194: 		    } else {
  195: 			my $safeinit;
  196: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
  197: 		    }
  198: 		    if ($allowed) {
  199: 			if ($target ne 'tex') {
  200: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
  201: 				      $syllabus{$_}.
  202: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  203: 			} else {
  204: 			    my $safeinit;
  205: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  206: 			}
  207: 		    }
  208: 		} else {
  209: 		    if ($target ne 'tex') {
  210: 			$r->print('<h1>'.$message.'</h1>');
  211: 		    } else {
  212: 			my $safeinit;
  213: 			$r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
  214: 		    }
  215: 		    if ($allowed) {
  216: 			if ($ENV{'form.grade_target'} ne 'tex') {
  217: 			    $r->print(
  218: 				      '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  219: 				      $syllabus{$_}.
  220: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
  221: 			} else {
  222: 			    my $safeinit;
  223: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
  224: 			}
  225: 		    }
  226: 		}
  227: 	    }
  228: 	}
  229: 	if ($allowed && ($ENV{'form.grade_target'} ne 'tex')) {
  230: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
  231: 		      ('bbb_content').'</form>');
  232: 	}
  233: 	if ($ENV{'form.grade_target'} ne 'tex') {$r->print('</p>');}
  234:     } else {
  235: 	$r->print('<p>No page information provided.</p>');
  236:     }
  237:     if ($ENV{'form.grade_target'} ne 'tex') {
  238: 	$r->print('</body></html>');
  239:     } else {
  240: 	$r->print('\end{document}');
  241:     }
  242:     return OK;
  243: } 
  244: 
  245: 1;
  246: __END__

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