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

1.1       www         1: # The LearningOnline Network
                      2: # Simple Page Editor
                      3: #
1.13    ! www         4: # $Id: lonsimplepage.pm,v 1.12 2003/09/09 19:39:04 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.1       www        38: 
                     39: sub handler {
                     40:     my $r = shift;
                     41:     $r->content_type('text/html');
                     42:     $r->send_http_header;
                     43:     return OK if $r->header_only;
                     44: 
                     45: # ------------------------------------------------------------ Print the screen
                     46:     $r->print(<<ENDDOCUMENT);
                     47: <html>
                     48: <head>
                     49: <title>The LearningOnline Network with CAPA</title>
                     50: ENDDOCUMENT
1.2       www        51:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        52: # Is this even in a course?
                     53:     unless ($ENV{'request.course.id'}) {
1.8       www        54: 	$r->print('</head><body>Not in a course</body></html>');
1.1       www        55:         return OK;
                     56:     }
                     57: 
                     58:     $marker=~s/\D//g;
                     59: 
                     60:     unless ($marker) {
                     61: 	$r->print('<body>Invalid call</body>');
                     62:         return OK;
                     63:     }
                     64: 
                     65:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                     66:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                     67: 
                     68: # --------------------------------------------------------- The syllabus fields
1.13    ! www        69:     my %syllabusfields=&Apache::lonlocal::texthash(
1.1       www        70:        'aaa_title'         => 'Page Title',
                     71:        'bbb_content'       => 'Content',
                     72:        'ccc_webreferences' => 'Web References');
                     73: 
1.7       www        74: 
                     75: # ------------------------------------------------------------ Get query string
                     76:     &Apache::loncommon::get_unprocessed_cgi
                     77:                         ($ENV{'QUERY_STRING'},['forcestudent','register']);
                     78: # ----------------------------------------------------- Force menu registration
                     79:     my $addentries='';
                     80:     if ($ENV{'form.register'}) {
                     81:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
                     82: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
                     83:        $r->print(&Apache::lonmenu::registerurl(1));
                     84:     }
1.1       www        85: # --------------------------------------------------------------- Force Student
                     86:     my $forcestudent='';
                     87:     if ($ENV{'form.forcestudent'}) { $forcestudent='student'; };
                     88: 
1.7       www        89: 
1.1       www        90:     my %syllabus=&Apache::lonnet::dump('smppage_'.$marker,$dom,$crs);
                     91:        
                     92: # --------------------------------------- There is such a user, get environment
                     93: 
1.7       www        94:     $r->print('</head>'.&Apache::loncommon::bodytag
1.8       www        95:       ("Course Page",$forcestudent,$addentries,'',$dom,$ENV{'form.register'}));
1.1       www        96: 
1.12      www        97:     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.1       www        98: 
                     99:        if ($forcestudent) { $allowed=0; }
                    100:  
                    101:        if ($allowed) {
1.5       www       102:           $r->print('<p>'.
1.11      www       103: &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>'.
1.4       www       104:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.1       www       105:       }
                    106:       if (($ENV{'form.uploaddoc.filename'}) &&
                    107:           ($ENV{'form.storeupl'}) && ($allowed)) {
1.9       www       108:  	  if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.1       www       109:              $syllabus{'uploaded.photourl'}=
                    110:                  &Apache::lonnet::userfileupload('uploaddoc',1);
                    111:  	  }
                    112:           $syllabus{'uploaded.lastmodified'}=time;
                    113:           &Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
                    114:        }
                    115:        if (($allowed) && ($ENV{'form.storesyl'})) {
                    116: 	   foreach (keys %syllabusfields) {
                    117:                my $field=$ENV{'form.'.$_};
                    118:                $field=~s/\s+$//s;
1.4       www       119:                $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1       www       120: 	       $syllabus{$_}=$field;
                    121:            }
                    122:            $syllabus{'uploaded.lastmodified'}=time;
                    123:            &Apache::lonnet::put('smppage_'.$marker,\%syllabus,$dom,$crs);
                    124:        }
                    125: 
                    126: # ---------------------------------------------------------------- Get syllabus
                    127:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
                    128:        if ($syllabus{'uploaded.photourl'}) {
                    129: 	   $r->print('<img src="'.
                    130:              &Apache::lonnet::tokenwrapper($syllabus{'uploaded.photourl'}).
                    131:              '" align="right" />');
                    132:        }
                    133:        if ($allowed) {
                    134:            $r->print(
                    135: 	 '<form method="post" enctype="multipart/form-data">'.
                    136:          '<h3>Upload a Photo</h3>'.
                    137:          '<input type="file" name="uploaddoc" size="50">'.
                    138:          '<input type="submit" name="storeupl" value="Upload">'.
                    139: 	 '</form><form method="post">');
                    140:        }
                    141:        foreach (sort keys %syllabusfields) {
                    142:           if (($syllabus{$_}) || ($allowed)) {
                    143:               my $message=$syllabus{$_};
                    144:               $message=~s/\n/\<br \/\>/g;
                    145:               $message
1.10      www       146:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.1       www       147: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.2       www       148:             unless ($_ eq 'aaa_title') {
                    149: 		if (($_ ne 'bbb_content') || ($allowed)) {
                    150:                     $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
                    151: 		}
                    152:                  $r->print('<blockquote>'.
1.1       www       153:                         $message.'</blockquote>');
1.2       www       154:                  if ($allowed) {
                    155:                 $r->print('<br /><textarea cols="80" rows="20" name="'.$_.'">'.
1.1       www       156: 			   $syllabus{$_}.
                    157:            '</textarea><input type="submit" name="storesyl" value="Store" />');
1.2       www       158: 	        }
                    159: 	    } else {
                    160: 		$r->print('<h1>'.$message.'</h1>');
                    161:                 if ($allowed) {
                    162:                  $r->print(
                    163:                 '<br />Title<br /><textarea cols="80" rows="2" name="'.$_.'">'.
                    164: 			   $syllabus{$_}.
                    165:            '</textarea><input type="submit" name="storesyl" value="Store" />');
                    166:                 }
                    167:             }
1.1       www       168: 	  }
                    169:        }
                    170:        if ($allowed) {
                    171: 	   $r->print('</form>');
                    172:        }
                    173:        $r->print('</p>');
                    174:     } else {
                    175:        $r->print('<p>No page information provided.</p>');
                    176:     }
                    177:     $r->print('</body></html>');
                    178:     return OK;
                    179: } 
                    180: 
                    181: 1;
                    182: __END__

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