File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.6: download - view: text, annotated - select for diffs
Mon Feb 10 20:03:13 2003 UTC (21 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #1019 fixed.
Additional documentation.

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

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