File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.31: download - view: text, annotated - select for diffs
Sun Oct 30 02:39:09 2005 UTC (18 years, 6 months ago) by www
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_99_1, HEAD
No, mathematics is not a spelling error

    1: # The LearningOnline Network
    2: # Bulletin Board Handler
    3: #
    4: # $Id: lonbulletin.pm,v 1.31 2005/10/30 02:39:09 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::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:     my $target=$env{'form.grade_target'};
   45: 
   46: # ------------------------------------------------------------ Print the screen
   47:     if ($target ne 'tex') {
   48: 	my $html=&Apache::lonxml::xmlbegin();
   49: 	$r->print(<<ENDDOCUMENT);
   50: $html
   51: <head>
   52: <title>The LearningOnline Network with CAPA</title>
   53: ENDDOCUMENT
   54: } else {
   55: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
   56:     }
   57:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
   58: # Is this even in a course?
   59:     unless ($env{'request.course.id'}) {
   60: 	$r->print('</head><body>Not in a course</body></html>');
   61:         return OK;
   62:     }
   63: 
   64:     $marker=~s/\D//g;
   65: 
   66:     unless ($marker) {
   67: 	$r->print('<body>Invalid call</body>');
   68:         return OK;
   69:     }
   70: 
   71:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
   72:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
   73: 
   74: # --------------------------------------------------------- The syllabus fields
   75:     my %syllabusfields=&Apache::lonlocal::texthash(
   76:        'aaa_title'         => 'Topic',
   77:        'bbb_content'       => 'Task',
   78:        'ccc_webreferences' => 'Web References');
   79: 
   80: # ------------------------------------------------------------ Get Query String
   81:     &Apache::loncommon::get_unprocessed_cgi
   82:                 ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register','origpage']);
   83: # ----------------------------------------------------- Force menu registration
   84:     my $addentries='';
   85:     if ($env{'form.register'}) {
   86:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents();
   87:        if ($env{'form.origpage'}) {
   88:            $addentries .= "document.location='#newpost';";
   89:        }
   90:        $addentries .= '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
   91:        $r->print(&Apache::lonmenu::registerurl(1));
   92:     } elsif ($env{'form.origpage'}) {
   93:          $addentries = "onLoad=\"document.location='#newpost';\"";
   94:     }
   95: # --------------------------------------------------------------- Force Student
   96:     my $forcestudent='';
   97:     if ($env{'form.forcestudent'}) { $forcestudent='student'; }
   98: 
   99:     my $forceedit='';
  100:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
  101: 
  102:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
  103:        
  104: # --------------------------------------- There is such a user, get environment
  105:     if ($target ne 'tex') {   
  106: 	$r->print('</head>'.&Apache::loncommon::bodytag
  107:                   ("Bulletin Board/Discussion",$forcestudent,$addentries,'',$dom,
  108:                   $env{'form.register'}));
  109:     }
  110:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
  111: 
  112:     my $privileged=$allowed;
  113:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  114:  	$forcestudent='student';
  115:     }
  116:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
  117:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
  118:  
  119:       if ($allowed) {
  120:           $r->print(
  121: 	  '<p>'.
  122: &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>'.
  123:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  124:       }  elsif ($privileged and $target ne 'tex') {
  125: 	  $r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'
  126: 		    .&mt('Edit').'</font></a>');
  127:       } 
  128: 
  129:       if (($env{'form.uploaddoc.filename'}) &&
  130:           ($env{'form.storeupl'}) && ($allowed)) {
  131:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  132: 	      if ($syllabus{'uploaded.photourl'}) {
  133: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  134: 	      }
  135: 	      $syllabus{'uploaded.photourl'}=
  136: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
  137:  	  }
  138:           $syllabus{'uploaded.lastmodified'}=time;
  139:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  140:        }
  141:        if (($allowed) && ($env{'form.storesyl'})) {
  142: 	   foreach (keys %syllabusfields) {
  143:                my $field=$env{'form.'.$_};
  144:                $field=~s/\s+$//s;
  145:                $field=&Apache::lonfeedback::clear_out_html($field,1);
  146: 	       $syllabus{$_}=$field;
  147:            }
  148:            $syllabus{'uploaded.lastmodified'}=time;
  149:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  150:        }
  151: 
  152: # ---------------------------------------------------------------- Get syllabus
  153:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
  154:        if ($syllabus{'uploaded.photourl'}) {
  155: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
  156: 					  $syllabus{'uploaded.photourl'});
  157: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
  158: 	       '" align="right" />');
  159:        }
  160:        if ($allowed) {
  161:            $r->print(
  162: 	 '<form method="post" enctype="multipart/form-data">'.
  163:  	 '<input type="hidden" name="forceedit" value="edit" />'.
  164:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  165:          '<input type="file" name="uploaddoc" size="50">'.
  166:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
  167: 	 '</form><form method="post">');
  168:        }
  169:        foreach (sort keys %syllabusfields) {
  170:           if (($syllabus{$_}) || ($allowed)) {
  171:               my $message=$syllabus{$_};
  172: 	      &Apache::lonfeedback::newline_to_br(\$message);
  173: 	      $message
  174:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  175: 	      if ($allowed) {
  176: 		  $message=&Apache::lonspeller::markeduptext($message);
  177: 	      }
  178: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  179: 	      unless ($_ eq 'aaa_title') {
  180: 		if (($_ ne 'bbb_content') || ($allowed)) {
  181: 		    if ($target ne 'tex') {
  182: 			$r->print('<h3>'.$syllabusfields{$_}.'</h3>');
  183: 		    } else {
  184: 			$r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
  185: 		    }
  186: 		}
  187: 		if ($target ne 'tex') {
  188: 		    $r->print('<blockquote>'.
  189:                               $message.'</blockquote>');
  190: 		} else {
  191: 		    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
  192: 		}
  193:                  if ($allowed) {
  194:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
  195: 			   $syllabus{$_}.
  196:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  197: 	        }
  198: 	    } else {
  199:                 if ($target ne 'tex') {
  200: 		    $r->print('<h1>'.$message.'</h1>');
  201: 		} else {
  202: 		    $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
  203: 		}
  204:                 if ($allowed) {
  205:                  $r->print(
  206:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  207: 			   $syllabus{$_}.
  208:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  209:                 }
  210:             }
  211: 	  }
  212:        }
  213:        if ($allowed) {
  214: 	   $r->print('</form>');
  215:        }
  216:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
  217:     } else {
  218:        $r->print('<p>'.&mt('No page information provided.').'</p>');
  219:     }
  220:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
  221:     if ($target ne 'tex') {
  222: 	$r->print(&Apache::lonfeedback::list_discussion
  223: 	           ('board','OPEN','bulletin___'.$marker.'___'.
  224: 	            $r->uri));
  225:     } else {
  226: 	$r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
  227: 	           ('board','OPEN','bulletin___'.$marker.'___'.
  228: 	            $r->uri)));
  229:     }
  230:     if ($target ne 'tex') {$r->print('</body></html>');} else {$r->print('\end{document}');}
  231:     return OK;
  232: } 
  233: 
  234: 1;
  235: __END__

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