File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.23: download - view: text, annotated - select for diffs
Mon May 10 14:10:03 2004 UTC (20 years, 1 month ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bulletin Board discussion can be printed as a separate resource.

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

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