Annotation of loncom/interface/lonsimplepage.pm, revision 1.18

1.1       www         1: # The LearningOnline Network
                      2: # Simple Page Editor
                      3: #
1.18    ! sakharuk    4: # $Id: lonsimplepage.pm,v 1.17 2004/04/30 23:13:52 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::lonsimplepage;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::loncommon;
                     34: use Apache::lonnet;
                     35: use Apache::lontexconvert;
1.6       matthew    36: use Apache::lonfeedback;
1.13      www        37: use Apache::lonlocal;
1.14      sakharuk   38: use Apache::lonprintout;
                     39: use Apache::lonxml;
1.1       www        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;
1.18    ! sakharuk   46:     my $target=$ENV{'form.grade_target'};
1.1       www        47: # ------------------------------------------------------------ Print the screen
1.18    ! sakharuk   48:     if ($target ne 'tex') {
1.14      sakharuk   49: 	$r->print(<<ENDDOCUMENT);
1.1       www        50: <html>
                     51: <head>
                     52: <title>The LearningOnline Network with CAPA</title>
                     53: ENDDOCUMENT
1.14      sakharuk   54:     } else {
                     55: 	$r->print(&Apache::lonprintout::print_latex_header($ENV{'form.latex_type'}));
                     56:     } 
1.2       www        57:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        58: # Is this even in a course?
                     59:     unless ($ENV{'request.course.id'}) {
1.18    ! sakharuk   60: 	if ($target ne 'tex') {
1.14      sakharuk   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: 	}
1.1       www        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
1.13      www        79:     my %syllabusfields=&Apache::lonlocal::texthash(
1.1       www        80:        'aaa_title'         => 'Page Title',
                     81:        'bbb_content'       => 'Content',
                     82:        'ccc_webreferences' => 'Web References');
                     83: 
1.7       www        84: 
                     85: # ------------------------------------------------------------ Get query string
                     86:     &Apache::loncommon::get_unprocessed_cgi
1.16      www        87:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
1.7       www        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:     }
1.1       www        95: # --------------------------------------------------------------- Force Student
                     96:     my $forcestudent='';
1.18    ! sakharuk   97:     if ($ENV{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
1.16      www        98:      my $forceedit='';
                     99:      if ($ENV{'form.forceedit'}) { $forceedit='edit'; }
1.1       www       100: 
1.7       www       101: 
1.1       www       102:     my %syllabus=&Apache::lonnet::dump('smppage_'.$marker,$dom,$crs);
                    103:        
                    104: # --------------------------------------- There is such a user, get environment
                    105: 
1.18    ! sakharuk  106:     if ($target ne 'tex') {
1.14      sakharuk  107: 	$r->print('</head>'.&Apache::loncommon::bodytag
                    108: 		  ("Course Page",$forcestudent,$addentries,'',$dom,$ENV{'form.register'}));
                    109:     }
1.1       www       110: 
1.12      www       111:     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.16      www       112:     my $privileged=$allowed;
                    113:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    114: 	$forcestudent='student';
                    115:     }
1.1       www       116: 
1.18    ! sakharuk  117:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
        !           118:     
        !           119:     if ($allowed) {
        !           120: 	$r->print('<p>'.
        !           121: 		  &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>'.
        !           122: 		  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
        !           123:     } elsif ($privileged and $target ne 'tex') {
        !           124: 	$r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'.&mt('Edit').'</font></a>');
        !           125:     } 
        !           126:     if (($ENV{'form.uploaddoc.filename'} and $target ne 'tex') &&
        !           127: 	($ENV{'form.storeupl'}) && ($allowed)) {
        !           128: 	if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
        !           129: 	    if ($syllabus{'uploaded.photourl'}) {
        !           130: 		&Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
        !           131: 	    }
        !           132: 	    $syllabus{'uploaded.photourl'}=
        !           133: 		&Apache::lonnet::userfileupload('uploaddoc',1,'simplepage');
        !           134: 	}
        !           135: 	$syllabus{'uploaded.lastmodified'}=time;
        !           136: 	&Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
        !           137:     }
        !           138:     if (($allowed) && ($ENV{'form.storesyl'})) {
        !           139: 	foreach (keys %syllabusfields) {
        !           140: 	    my $field=$ENV{'form.'.$_};
        !           141: 	    $field=~s/\s+$//s;
        !           142: 	    $field=&Apache::lonfeedback::clear_out_html($field,1);
        !           143: 	    $syllabus{$_}=$field;
        !           144: 	}
        !           145: 	$syllabus{'uploaded.lastmodified'}=time;
        !           146: 	&Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
        !           147:     }
1.1       www       148: 
                    149: # ---------------------------------------------------------------- Get syllabus
                    150:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.18    ! sakharuk  151: 	if ($syllabus{'uploaded.photourl'}) {
        !           152: 	    if ($target ne 'tex') {
        !           153: 		&Apache::lonnet::allowuploaded('/adm/smppg',
        !           154: 					       $syllabus{'uploaded.photourl'});
        !           155: 		$r->print('<img src="'.$syllabus{'uploaded.photourl'}.
        !           156: 			  '" align="right" />');
        !           157: 	    } else {
        !           158: 		&Apache::lonnet::allowuploaded('/adm/smppg',
        !           159: 					       $syllabus{'uploaded.photourl'});
        !           160: 		$r->print(&Apache::lonxml::xmlparse($r,'tex','<img src="'.$syllabus{'uploaded.photourl'}.
        !           161: 			  '" align="right" />'));
        !           162: 	    }
        !           163: 	}
        !           164: 	if ($allowed) {
        !           165: 	    $r->print(
        !           166: 		      '<form method="post" enctype="multipart/form-data">'.
        !           167: 		      '<input type="hidden" name="forceedit" value="edit" />'.
        !           168: 		      '<h3>Upload a Photo</h3>'.
        !           169: 		      '<input type="file" name="uploaddoc" size="50">'.
        !           170: 		      '<input type="submit" name="storeupl" value="Upload">'.
        !           171: 		      '</form><form method="post">');
        !           172: 	}
        !           173: 	foreach (sort keys %syllabusfields) {
        !           174: 	    if (($syllabus{$_}) || ($allowed)) {
        !           175: 		my $message=$syllabus{$_};
        !           176: 		$message=~s/\n/\<br \/\>/g;
        !           177: 		$message
        !           178: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
        !           179: 		$message=&Apache::lontexconvert::msgtexconverted($message);
        !           180: 		unless ($_ eq 'aaa_title') {
        !           181: 		    if (($_ ne 'bbb_content') || ($allowed)) {
        !           182: 			if ($target ne 'tex') {
        !           183: 			    $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
        !           184: 			} else {
        !           185: 			    my $safeinit;
        !           186: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
        !           187: 			}
        !           188: 		    }
        !           189: 		    if ($target ne 'tex') {
        !           190: 			$r->print('<blockquote>'.
        !           191: 				  $message.'</blockquote>');
1.14      sakharuk  192: 		    } else {
                    193: 			my $safeinit;
1.18    ! sakharuk  194: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
        !           195: 		    }
        !           196: 		    if ($allowed) {
        !           197: 			if ($target ne 'tex') {
        !           198: 			    $r->print('<br /><textarea cols="80" rows="20" name="'.$_.'">'.
        !           199: 				      $syllabus{$_}.
        !           200: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
        !           201: 			} else {
        !           202: 			    my $safeinit;
        !           203: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
        !           204: 			}
1.14      sakharuk  205: 		    }
                    206: 		} else {
1.18    ! sakharuk  207: 		    if ($target ne 'tex') {
        !           208: 			$r->print('<h1>'.$message.'</h1>');
1.14      sakharuk  209: 		    } else {
                    210: 			my $safeinit;
1.18    ! sakharuk  211: 			$r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
        !           212: 		    }
        !           213: 		    if ($allowed) {
        !           214: 			if ($ENV{'form.grade_target'} ne 'tex') {
        !           215: 			    $r->print(
        !           216: 				      '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
        !           217: 				      $syllabus{$_}.
        !           218: 				      '</textarea><input type="submit" name="storesyl" value="Store" />');
        !           219: 			} else {
        !           220: 			    my $safeinit;
        !           221: 			    $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
        !           222: 			}
1.14      sakharuk  223: 		    }
1.18    ! sakharuk  224: 		}
        !           225: 	    }
        !           226: 	}
        !           227: 	if ($allowed && ($ENV{'form.grade_target'} ne 'tex')) {
        !           228: 	    $r->print('</form>');
        !           229: 	}
        !           230: 	if ($ENV{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1       www       231:     } else {
1.18    ! sakharuk  232: 	$r->print('<p>No page information provided.</p>');
1.1       www       233:     }
1.14      sakharuk  234:     if ($ENV{'form.grade_target'} ne 'tex') {
                    235: 	$r->print('</body></html>');
                    236:     } else {
                    237: 	$r->print('\end{document}');
                    238:     }
1.1       www       239:     return OK;
                    240: } 
                    241: 
                    242: 1;
                    243: __END__

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