File:  [LON-CAPA] / loncom / interface / lonsimplepage.pm
Revision 1.24: download - view: text, annotated - select for diffs
Thu Feb 17 08:50:20 2005 UTC (19 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- $r->content_type -> loncommon::content_type

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

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