Annotation of loncom/interface/lonsimplepage.pm, revision 1.14
1.1 www 1: # The LearningOnline Network
2: # Simple Page Editor
3: #
1.14 ! sakharuk 4: # $Id: lonsimplepage.pm,v 1.13 2003/09/17 19:45:39 www 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;
46:
47: # ------------------------------------------------------------ Print the screen
1.14 ! sakharuk 48: if ($ENV{'form.grade_target'} ne 'tex') {
! 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.14 ! sakharuk 60: if ($ENV{'form.grade_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: }
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
87: ($ENV{'QUERY_STRING'},['forcestudent','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: }
1.1 www 95: # --------------------------------------------------------------- Force Student
96: my $forcestudent='';
97: if ($ENV{'form.forcestudent'}) { $forcestudent='student'; };
98:
1.7 www 99:
1.1 www 100: my %syllabus=&Apache::lonnet::dump('smppage_'.$marker,$dom,$crs);
101:
102: # --------------------------------------- There is such a user, get environment
103:
1.14 ! sakharuk 104: if ($ENV{'form.grade_target'} ne 'tex') {
! 105: $r->print('</head>'.&Apache::loncommon::bodytag
! 106: ("Course Page",$forcestudent,$addentries,'',$dom,$ENV{'form.register'}));
! 107: }
1.1 www 108:
1.12 www 109: my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.1 www 110:
111: if ($forcestudent) { $allowed=0; }
112:
113: if ($allowed) {
1.14 ! sakharuk 114: if ($ENV{'form.grade_target'} ne 'tex') {
! 115: $r->print('<p>'.
! 116: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1"><font size="+1">Show Student View</font></a>'.
! 117: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
! 118: }
! 119: }
1.1 www 120: if (($ENV{'form.uploaddoc.filename'}) &&
121: ($ENV{'form.storeupl'}) && ($allowed)) {
1.9 www 122: if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.1 www 123: $syllabus{'uploaded.photourl'}=
124: &Apache::lonnet::userfileupload('uploaddoc',1);
125: }
126: $syllabus{'uploaded.lastmodified'}=time;
127: &Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
128: }
129: if (($allowed) && ($ENV{'form.storesyl'})) {
130: foreach (keys %syllabusfields) {
131: my $field=$ENV{'form.'.$_};
132: $field=~s/\s+$//s;
1.4 www 133: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1 www 134: $syllabus{$_}=$field;
135: }
136: $syllabus{'uploaded.lastmodified'}=time;
137: &Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
138: }
139:
140: # ---------------------------------------------------------------- Get syllabus
141: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
142: if ($syllabus{'uploaded.photourl'}) {
1.14 ! sakharuk 143: if ($ENV{'form.grade_target'} ne 'tex') {
! 144: $r->print('<img src="'.
! 145: &Apache::lonnet::tokenwrapper($syllabus{'uploaded.photourl'}).
! 146: '" align="right" />');
! 147: }
1.1 www 148: }
1.14 ! sakharuk 149: if ($allowed && ($ENV{'form.grade_target'} ne 'tex')) {
1.1 www 150: $r->print(
151: '<form method="post" enctype="multipart/form-data">'.
152: '<h3>Upload a Photo</h3>'.
153: '<input type="file" name="uploaddoc" size="50">'.
154: '<input type="submit" name="storeupl" value="Upload">'.
155: '</form><form method="post">');
156: }
157: foreach (sort keys %syllabusfields) {
158: if (($syllabus{$_}) || ($allowed)) {
159: my $message=$syllabus{$_};
160: $message=~s/\n/\<br \/\>/g;
161: $message
1.10 www 162: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.1 www 163: $message=&Apache::lontexconvert::msgtexconverted($message);
1.2 www 164: unless ($_ eq 'aaa_title') {
165: if (($_ ne 'bbb_content') || ($allowed)) {
1.14 ! sakharuk 166: if ($ENV{'form.grade_target'} ne 'tex') {
! 167: $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
! 168: } else {
! 169: my $safeinit;
! 170: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h3>'.$syllabusfields{$_}.'</h3>'));
! 171: }
! 172: }
! 173: if ($ENV{'form.grade_target'} ne 'tex') {
! 174: $r->print('<blockquote>'.
! 175: $message.'</blockquote>');
! 176: } else {
! 177: my $safeinit;
! 178: $r->print(&Apache::lonxml::xmlparse($r,'tex',$message));
1.2 www 179: }
180: if ($allowed) {
1.14 ! sakharuk 181: if ($ENV{'form.grade_target'} ne 'tex') {
! 182: $r->print('<br /><textarea cols="80" rows="20" name="'.$_.'">'.
1.1 www 183: $syllabus{$_}.
1.14 ! sakharuk 184: '</textarea><input type="submit" name="storesyl" value="Store" />');
! 185: } else {
! 186: my $safeinit;
! 187: $r->print(&Apache::lonxml::xmlparse($r,'tex',$syllabus{$_},$safeinit));
! 188: }
1.2 www 189: }
190: } else {
1.14 ! sakharuk 191: if ($ENV{'form.grade_target'} ne 'tex') {
! 192: $r->print('<h1>'.$message.'</h1>');
! 193: } else {
! 194: my $safeinit;
! 195: $r->print(&Apache::lonxml::xmlparse($r,'tex','<h1>'.$message.'</h1>'));
! 196: }
1.2 www 197: if ($allowed) {
1.14 ! sakharuk 198: if ($ENV{'form.grade_target'} ne 'tex') {
! 199: $r->print(
! 200: '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
! 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: }
1.2 www 207: }
208: }
1.1 www 209: }
210: }
1.14 ! sakharuk 211: if ($allowed && ($ENV{'form.grade_target'} ne 'tex')) {
1.1 www 212: $r->print('</form>');
213: }
1.14 ! sakharuk 214: if ($ENV{'form.grade_target'} ne 'tex') {$r->print('</p>');}
1.1 www 215: } else {
216: $r->print('<p>No page information provided.</p>');
217: }
1.14 ! sakharuk 218: if ($ENV{'form.grade_target'} ne 'tex') {
! 219: $r->print('</body></html>');
! 220: } else {
! 221: $r->print('\end{document}');
! 222: }
1.1 www 223: return OK;
224: }
225:
226: 1;
227: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>