File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.21: download - view: text, annotated - select for diffs
Wed May 5 21:04:14 2004 UTC (20 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Posts in discussions now identified as "NEW" if posts were added since user's last visit to resource or bulletin board.  "Speech bubbles" in NAVMAP also displayed for each resource or bulletin board if posts have been added since last visit.

User can set display to be all posts, or only unread posts.  To support cases where there are several "NEW" posts, the time of the previous visit is passed in a query string during hide/make visible, reply or delete operations so that the differentiation of "NEW" posts is retained until the user leaves the bulletin board.  This behavior does not currently apply to discussions associated with resources.

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

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