File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.33: download - view: text, annotated - select for diffs
Tue Mar 21 20:41:40 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- typo

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

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