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

1.1       www         1: # The LearningOnline Network
                      2: # Simple Page Editor
                      3: #
1.26    ! albertel    4: # $Id: lonsimplepage.pm,v 1.25 2005/04/07 06:56:23 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;
1.24      albertel   43:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        44:     $r->send_http_header;
                     45:     return OK if $r->header_only;
1.25      albertel   46:     my $target=$env{'form.grade_target'};
1.1       www        47: # ------------------------------------------------------------ Print the screen
1.18      sakharuk   48:     if ($target ne 'tex') {
1.23      albertel   49: 	my $html=&Apache::lonxml::xmlbegin();
1.14      sakharuk   50: 	$r->print(<<ENDDOCUMENT);
1.23      albertel   51: $html
1.1       www        52: <head>
                     53: <title>The LearningOnline Network with CAPA</title>
                     54: ENDDOCUMENT
1.14      sakharuk   55:     } else {
1.25      albertel   56: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.14      sakharuk   57:     } 
1.2       www        58:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        59: # Is this even in a course?
1.25      albertel   60:     unless ($env{'request.course.id'}) {
1.18      sakharuk   61: 	if ($target ne 'tex') {
1.14      sakharuk   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: 	}
1.1       www        67:     }
                     68: 
                     69:     $marker=~s/\D//g;
                     70: 
                     71:     unless ($marker) {
                     72: 	$r->print('<body>Invalid call</body>');
                     73:         return OK;
                     74:     }
                     75: 
1.25      albertel   76:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     77:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1       www        78: 
                     79: # --------------------------------------------------------- The syllabus fields
1.13      www        80:     my %syllabusfields=&Apache::lonlocal::texthash(
1.1       www        81:        'aaa_title'         => 'Page Title',
                     82:        'bbb_content'       => 'Content',
                     83:        'ccc_webreferences' => 'Web References');
                     84: 
1.7       www        85: 
                     86: # ------------------------------------------------------------ Get query string
                     87:     &Apache::loncommon::get_unprocessed_cgi
1.16      www        88:                         ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
1.7       www        89: # ----------------------------------------------------- Force menu registration
                     90:     my $addentries='';
1.25      albertel   91:     if ($env{'form.register'}) {
1.7       www        92:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
                     93: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
                     94:        $r->print(&Apache::lonmenu::registerurl(1));
                     95:     }
1.1       www        96: # --------------------------------------------------------------- Force Student
                     97:     my $forcestudent='';
1.25      albertel   98:     if ($env{'form.forcestudent'} || $target eq 'tex' ) { $forcestudent='student'; };
1.16      www        99:      my $forceedit='';
1.25      albertel  100:      if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.1       www       101: 
1.7       www       102: 
1.1       www       103:     my %syllabus=&Apache::lonnet::dump('smppage_'.$marker,$dom,$crs);
                    104:        
                    105: # --------------------------------------- There is such a user, get environment
                    106: 
1.18      sakharuk  107:     if ($target ne 'tex') {
1.21      www       108: 	$r->print(&Apache::lonhtmlcommon::htmlareaheaders().
                    109: 		  '</head>'.&Apache::loncommon::bodytag
1.25      albertel  110: 		  ("Course Page",$forcestudent,$addentries,'',$dom,$env{'form.register'}));
1.14      sakharuk  111:     }
1.1       www       112: 
1.25      albertel  113:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.16      www       114:     my $privileged=$allowed;
                    115:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    116: 	$forcestudent='student';
                    117:     }
1.1       www       118: 
1.18      sakharuk  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:     } 
1.25      albertel  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) {
1.18      sakharuk  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:     }
1.25      albertel  140:     if (($allowed) && ($env{'form.storesyl'})) {
1.18      sakharuk  141: 	foreach (keys %syllabusfields) {
1.25      albertel  142: 	    my $field=$env{'form.'.$_};
1.21      www       143: 	    chomp($field);
1.18      sakharuk  144: 	    $field=~s/\s+$//s;
1.21      www       145: 	    $field=~s/^\s+//s;
                    146: 	    $field=~s/\<br\s*\/*\>$//s;
1.18      sakharuk  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:     }
1.1       www       153: 
                    154: # ---------------------------------------------------------------- Get syllabus
                    155:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.18      sakharuk  156: 	if ($syllabus{'uploaded.photourl'}) {
1.19      sakharuk  157: 	    &Apache::lonnet::allowuploaded('/adm/smppg',
                    158: 					   $syllabus{'uploaded.photourl'});
1.20      albertel  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);
1.18      sakharuk  164: 	    }
1.20      albertel  165: 	    $r->print($image);
1.18      sakharuk  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{$_};
1.26    ! albertel  179: 		&Apache::lonfeedback::newline_to_br(\$message);
1.18      sakharuk  180: 		$message
                    181: 		    =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
                    182: 		$message=&Apache::lontexconvert::msgtexconverted($message);
1.22      www       183: 		if ($allowed) {
                    184: 		    $message=&Apache::lonspeller::markeduptext($message);
                    185: 		}
1.18      sakharuk  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>');
1.14      sakharuk  198: 		    } else {
                    199: 			my $safeinit;
1.18      sakharuk  200: 			$r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
                    201: 		    }
                    202: 		    if ($allowed) {
                    203: 			if ($target ne 'tex') {
1.21      www       204: 			    $r->print('<br /><textarea cols="80" rows="24" name="'.$_.'" id="'.$_.'">'.
1.18      sakharuk  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: 			}
1.14      sakharuk  211: 		    }
                    212: 		} else {
1.18      sakharuk  213: 		    if ($target ne 'tex') {
                    214: 			$r->print('<h1>'.$message.'</h1>');
1.14      sakharuk  215: 		    } else {
                    216: 			my $safeinit;
1.18      sakharuk  217: 			$r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
                    218: 		    }
                    219: 		    if ($allowed) {
1.25      albertel  220: 			if ($env{'form.grade_target'} ne 'tex') {
1.18      sakharuk  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: 			}
1.14      sakharuk  229: 		    }
1.18      sakharuk  230: 		}
                    231: 	    }
                    232: 	}
1.25      albertel  233: 	if ($allowed && ($env{'form.grade_target'} ne 'tex')) {
1.21      www       234: 	    $r->print(&Apache::lonhtmlcommon::htmlareaselectactive
                    235: 		      ('bbb_content').'</form>');
1.18      sakharuk  236: 	}
1.25      albertel  237: 	if ($env{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1       www       238:     } else {
1.18      sakharuk  239: 	$r->print('<p>No page information provided.</p>');
1.1       www       240:     }
1.25      albertel  241:     if ($env{'form.grade_target'} ne 'tex') {
1.14      sakharuk  242: 	$r->print('</body></html>');
                    243:     } else {
                    244: 	$r->print('\end{document}');
                    245:     }
1.1       www       246:     return OK;
                    247: } 
                    248: 
                    249: 1;
                    250: __END__

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