File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.20: download - view: text, annotated - select for diffs
Fri Apr 30 23:13:52 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- transitioning the tokenwrapper calls to the new mechainsm
- add in code to delete old images off the server
- put relevant images into subdris named after the handler that is creating them

    1: # The LearningOnline Network
    2: # Bulletin Board Handler
    3: #
    4: # $Id: lonbulletin.pm,v 1.20 2004/04/30 23:13:52 albertel 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::lonfeedback;
   37: use Apache::lonlocal;
   38: 
   39: sub handler {
   40:     my $r = shift;
   41:     &Apache::loncommon::content_type($r,'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
   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('</head><body>Not in a course</body></html>');
   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=&Apache::lonlocal::texthash(
   70:        'aaa_title'         => 'Topic',
   71:        'bbb_content'       => 'Task',
   72:        'ccc_webreferences' => 'Web References');
   73: 
   74: # ------------------------------------------------------------ Get Query String
   75:     &Apache::loncommon::get_unprocessed_cgi
   76:                 ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
   77: # ----------------------------------------------------- Force menu registration
   78:     my $addentries='';
   79:     if ($ENV{'form.register'}) {
   80:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
   81: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
   82:        $r->print(&Apache::lonmenu::registerurl(1));
   83:     }
   84: # --------------------------------------------------------------- Force Student
   85:     my $forcestudent='';
   86:     if ($ENV{'form.forcestudent'}) { $forcestudent='student'; }
   87: 
   88:     my $forceedit='';
   89:     if ($ENV{'form.forceedit'}) { $forceedit='edit'; }
   90: 
   91:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
   92:        
   93: # --------------------------------------- There is such a user, get environment
   94: 
   95:     $r->print('</head>'.&Apache::loncommon::bodytag
   96:             ("Bulletin Board/Discussion",$forcestudent,$addentries,'',$dom,
   97:              $ENV{'form.register'}));
   98: 
   99:     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
  100: 
  101:     my $privileged=$allowed;
  102:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  103:  	$forcestudent='student';
  104:     }
  105: 
  106:        if ($forcestudent) { $allowed=0; }
  107:  
  108:        if ($allowed) {
  109:           $r->print(
  110: 	  '<p>'.
  111: &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>'.
  112:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  113:       }  elsif ($privileged) {
  114: 	  $r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'
  115: 		    .&mt('Edit').'</font></a>');
  116:       } 
  117: 
  118:       if (($ENV{'form.uploaddoc.filename'}) &&
  119:           ($ENV{'form.storeupl'}) && ($allowed)) {
  120:  	  if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  121: 	      if ($syllabus{'uploaded.photourl'}) {
  122: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  123: 	      }
  124: 	      $syllabus{'uploaded.photourl'}=
  125: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
  126:  	  }
  127:           $syllabus{'uploaded.lastmodified'}=time;
  128:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  129:        }
  130:        if (($allowed) && ($ENV{'form.storesyl'})) {
  131: 	   foreach (keys %syllabusfields) {
  132:                my $field=$ENV{'form.'.$_};
  133:                $field=~s/\s+$//s;
  134:                $field=&Apache::lonfeedback::clear_out_html($field,1);
  135: 	       $syllabus{$_}=$field;
  136:            }
  137:            $syllabus{'uploaded.lastmodified'}=time;
  138:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  139:        }
  140: 
  141: # ---------------------------------------------------------------- Get syllabus
  142:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  143:        if ($syllabus{'uploaded.photourl'}) {
  144: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
  145: 					  $syllabus{'uploaded.photourl'});
  146: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
  147: 	       '" align="right" />');
  148:        }
  149:        if ($allowed) {
  150:            $r->print(
  151: 	 '<form method="post" enctype="multipart/form-data">'.
  152:  	 '<input type="hidden" name="forceedit" value="edit" />'.
  153:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  154:          '<input type="file" name="uploaddoc" size="50">'.
  155:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
  156: 	 '</form><form method="post">');
  157:        }
  158:        foreach (sort keys %syllabusfields) {
  159:           if (($syllabus{$_}) || ($allowed)) {
  160:               my $message=$syllabus{$_};
  161:               $message=~s/\n/\<br \/\>/g;
  162:               $message
  163:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  164: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  165:             unless ($_ eq 'aaa_title') {
  166: 		if (($_ ne 'bbb_content') || ($allowed)) {
  167:                     $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  168: 		}
  169:                  $r->print('<blockquote>'.
  170:                         $message.'</blockquote>');
  171:                  if ($allowed) {
  172:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
  173: 			   $syllabus{$_}.
  174:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  175: 	        }
  176: 	    } else {
  177: 		$r->print('<h1>'.$message.'</h1>');
  178:                 if ($allowed) {
  179:                  $r->print(
  180:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  181: 			   $syllabus{$_}.
  182:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  183:                 }
  184:             }
  185: 	  }
  186:        }
  187:        if ($allowed) {
  188: 	   $r->print('</form>');
  189:        }
  190:        $r->print('</p>');
  191:     } else {
  192:        $r->print('<p>'.&mt('No page information provided.').'</p>');
  193:     }
  194:     $r->print(&Apache::lonfeedback::list_discussion
  195: 	      ('board','OPEN','bulletin___'.$marker.'___'.
  196: 	       $r->uri).'</body></html>');
  197:     return OK;
  198: } 
  199: 
  200: 1;
  201: __END__

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