Annotation of loncom/interface/lonbulletin.pm, revision 1.34

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

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