File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.27: download - view: text, annotated - select for diffs
Wed Aug 18 21:14:00 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_99_1, version_1_2_99_0, HEAD
- looks better when there is an image and not alot of text

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

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