File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.4: download - view: text, annotated - select for diffs
Mon Feb 10 15:19:43 2003 UTC (21 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
Help links.

    1: # The LearningOnline Network
    2: # Simple Page Editor
    3: #
    4: # $Id: lonbulletin.pm,v 1.4 2003/02/10 15:19:43 www 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::lonbulletin;
   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::lonxml;
   37: 
   38: sub handler {
   39:     my $r = shift;
   40:     $r->content_type('text/html');
   41:     $r->send_http_header;
   42:     return OK if $r->header_only;
   43: 
   44: # ------------------------------------------------------------ Print the screen
   45:     $r->print(<<ENDDOCUMENT);
   46: <html>
   47: <head>
   48: <title>The LearningOnline Network with CAPA</title>
   49: </head>
   50: ENDDOCUMENT
   51:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
   52: # Is this even in a course?
   53:     unless ($ENV{'request.course.id'}) {
   54: 	$r->print('<body>Not in a course</body>');
   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
   69:     my %syllabusfields=(
   70:        'aaa_title'         => 'Topic',
   71:        'bbb_content'       => 'Task',
   72:        'ccc_webreferences' => 'Web References');
   73: 
   74: # --------------------------------------------------------------- Force Student
   75:     &Apache::loncommon::get_unprocessed_cgi
   76:                                        ($ENV{'QUERY_STRING'},['forcestudent']);
   77:     my $forcestudent='';
   78:     if ($ENV{'form.forcestudent'}) { $forcestudent='student'; };
   79: 
   80:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
   81:        
   82: # --------------------------------------- There is such a user, get environment
   83: 
   84:     $r->print(&Apache::loncommon::bodytag
   85:             ("Bulletin Board/Discussion",$forcestudent,'','',$dom));
   86: 
   87:     my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
   88: 
   89:        if ($forcestudent) { $allowed=0; }
   90:  
   91:        if ($allowed) {
   92:           $r->print(
   93: 	  '<p><a href="'.$r->uri.'?forcestudent=1">Show Public View</a>'.
   94:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').</p>');
   95:       }
   96:       if (($ENV{'form.uploaddoc.filename'}) &&
   97:           ($ENV{'form.storeupl'}) && ($allowed)) {
   98:  	  if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/) {
   99:              $syllabus{'uploaded.photourl'}=
  100:                  &Apache::lonnet::userfileupload('uploaddoc',1);
  101:  	  }
  102:           $syllabus{'uploaded.lastmodified'}=time;
  103:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  104:        }
  105:        if (($allowed) && ($ENV{'form.storesyl'})) {
  106: 	   foreach (keys %syllabusfields) {
  107:                my $field=$ENV{'form.'.$_};
  108:                $field=~s/\s+$//s;
  109:                $field=~s/\</\&lt\;/g;
  110:                $field=~s/\>/\&gt\;/g;
  111: 	       $syllabus{$_}=$field;
  112:            }
  113:            $syllabus{'uploaded.lastmodified'}=time;
  114:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  115:        }
  116: 
  117: # ---------------------------------------------------------------- Get syllabus
  118:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  119:        if ($syllabus{'uploaded.photourl'}) {
  120: 	   $r->print('<img src="'.
  121:              &Apache::lonnet::tokenwrapper($syllabus{'uploaded.photourl'}).
  122:              '" align="right" />');
  123:        }
  124:        if ($allowed) {
  125:            $r->print(
  126: 	 '<form method="post" enctype="multipart/form-data">'.
  127:          '<h3>Upload a Photo</h3>'.
  128:          '<input type="file" name="uploaddoc" size="50">'.
  129:          '<input type="submit" name="storeupl" value="Upload">'.
  130: 	 '</form><form method="post">');
  131:        }
  132:        foreach (sort keys %syllabusfields) {
  133:           if (($syllabus{$_}) || ($allowed)) {
  134:               my $message=$syllabus{$_};
  135:               $message=~s/\n/\<br \/\>/g;
  136:               $message
  137:              =~s/(http\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  138: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  139:             unless ($_ eq 'aaa_title') {
  140: 		if (($_ ne 'bbb_content') || ($allowed)) {
  141:                     $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  142: 		}
  143:                  $r->print('<blockquote>'.
  144:                         $message.'</blockquote>');
  145:                  if ($allowed) {
  146:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
  147: 			   $syllabus{$_}.
  148:            '</textarea><input type="submit" name="storesyl" value="Store" />');
  149: 	        }
  150: 	    } else {
  151: 		$r->print('<h1>'.$message.'</h1>');
  152:                 if ($allowed) {
  153:                  $r->print(
  154:                 '<br />Topic<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  155: 			   $syllabus{$_}.
  156:            '</textarea><input type="submit" name="storesyl" value="Store" />');
  157:                 }
  158:             }
  159: 	  }
  160:        }
  161:        if ($allowed) {
  162: 	   $r->print('</form>');
  163:        }
  164:        $r->print('</p>');
  165:     } else {
  166:        $r->print('<p>No page information provided.</p>');
  167:     }
  168:     $r->print(&Apache::lonxml::xmlend(1,'bulletin___'.$marker.'___'.
  169:              'adm/wrapper'.$r->uri).'</body></html>');
  170:     return OK;
  171: } 
  172: 
  173: 1;
  174: __END__

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