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

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.35    ! albertel    4: # $Id: lonbulletin.pm,v 1.34 2006/03/21 21:01:22 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
1.35    ! albertel   79:     my %addentries;
        !            80:     if ($env{'form.origpage'}) {
        !            81: 	$addentries{'onload'} = "document.location='#newpost';";
1.7       www        82:     }
1.1       www        83: # --------------------------------------------------------------- Force Student
                     84:     my $forcestudent='';
1.29      albertel   85:     if ($env{'form.forcestudent'}) { $forcestudent='student'; }
1.19      www        86: 
                     87:     my $forceedit='';
1.29      albertel   88:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.1       www        89: 
                     90:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
                     91:        
                     92: # --------------------------------------- There is such a user, get environment
1.32      albertel   93:     if ($target ne 'tex') {  
                     94: 	my $start_page =
                     95: 	    &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
                     96: 					   {'function'       => $forcestudent,
1.35    ! albertel   97: 					    'add_entries'    => \%addentries,
1.33      albertel   98: 					    'domain'         => $dom,
1.32      albertel   99: 					    'force_register' =>
                    100: 						$env{'form.register'}});
                    101: 	$r->print($start_page);
1.23      sakharuk  102:     }
1.29      albertel  103:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.1       www       104: 
1.19      www       105:     my $privileged=$allowed;
                    106:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    107:  	$forcestudent='student';
                    108:     }
1.27      albertel  109:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
1.23      sakharuk  110:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.1       www       111:  
1.23      sakharuk  112:       if ($allowed) {
1.1       www       113:           $r->print(
1.6       www       114: 	  '<p>'.
1.19      www       115: &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       116:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.23      sakharuk  117:       }  elsif ($privileged and $target ne 'tex') {
1.19      www       118: 	  $r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'
                    119: 		    .&mt('Edit').'</font></a>');
                    120:       } 
                    121: 
1.29      albertel  122:       if (($env{'form.uploaddoc.filename'}) &&
                    123:           ($env{'form.storeupl'}) && ($allowed)) {
                    124:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.20      albertel  125: 	      if ($syllabus{'uploaded.photourl'}) {
                    126: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    127: 	      }
                    128: 	      $syllabus{'uploaded.photourl'}=
                    129: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
1.1       www       130:  	  }
                    131:           $syllabus{'uploaded.lastmodified'}=time;
                    132:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    133:        }
1.29      albertel  134:        if (($allowed) && ($env{'form.storesyl'})) {
1.1       www       135: 	   foreach (keys %syllabusfields) {
1.29      albertel  136:                my $field=$env{'form.'.$_};
1.1       www       137:                $field=~s/\s+$//s;
1.5       www       138:                $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1       www       139: 	       $syllabus{$_}=$field;
                    140:            }
                    141:            $syllabus{'uploaded.lastmodified'}=time;
                    142:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    143:        }
                    144: 
                    145: # ---------------------------------------------------------------- Get syllabus
                    146:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
                    147:        if ($syllabus{'uploaded.photourl'}) {
1.20      albertel  148: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
                    149: 					  $syllabus{'uploaded.photourl'});
                    150: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
                    151: 	       '" align="right" />');
1.1       www       152:        }
                    153:        if ($allowed) {
                    154:            $r->print(
                    155: 	 '<form method="post" enctype="multipart/form-data">'.
1.19      www       156:  	 '<input type="hidden" name="forceedit" value="edit" />'.
                    157:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.1       www       158:          '<input type="file" name="uploaddoc" size="50">'.
1.19      www       159:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
1.1       www       160: 	 '</form><form method="post">');
                    161:        }
                    162:        foreach (sort keys %syllabusfields) {
                    163:           if (($syllabus{$_}) || ($allowed)) {
                    164:               my $message=$syllabus{$_};
1.30      albertel  165: 	      &Apache::lonfeedback::newline_to_br(\$message);
                    166: 	      $message
1.10      www       167:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.25      www       168: 	      if ($allowed) {
                    169: 		  $message=&Apache::lonspeller::markeduptext($message);
                    170: 	      }
1.31      www       171: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.25      www       172: 	      unless ($_ eq 'aaa_title') {
1.2       www       173: 		if (($_ ne 'bbb_content') || ($allowed)) {
1.23      sakharuk  174: 		    if ($target ne 'tex') {
                    175: 			$r->print('<h3>'.$syllabusfields{$_}.'</h3>');
                    176: 		    } else {
                    177: 			$r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
                    178: 		    }
                    179: 		}
                    180: 		if ($target ne 'tex') {
                    181: 		    $r->print('<blockquote>'.
                    182:                               $message.'</blockquote>');
                    183: 		} else {
                    184: 		    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
1.2       www       185: 		}
                    186:                  if ($allowed) {
1.3       www       187:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
1.1       www       188: 			   $syllabus{$_}.
1.19      www       189:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       190: 	        }
                    191: 	    } else {
1.23      sakharuk  192:                 if ($target ne 'tex') {
                    193: 		    $r->print('<h1>'.$message.'</h1>');
                    194: 		} else {
                    195: 		    $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
                    196: 		}
1.2       www       197:                 if ($allowed) {
                    198:                  $r->print(
1.19      www       199:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
1.2       www       200: 			   $syllabus{$_}.
1.19      www       201:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       202:                 }
                    203:             }
1.1       www       204: 	  }
                    205:        }
                    206:        if ($allowed) {
                    207: 	   $r->print('</form>');
                    208:        }
1.23      sakharuk  209:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.1       www       210:     } else {
1.19      www       211:        $r->print('<p>'.&mt('No page information provided.').'</p>');
1.1       www       212:     }
1.27      albertel  213:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
1.23      sakharuk  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:     }
1.32      albertel  223:     if ($target ne 'tex') {
                    224: 	$r->print(&Apache::loncommon::end_page());
                    225:     } else {
                    226: 	$r->print('\end{document}');
                    227:     }
1.1       www       228:     return OK;
                    229: } 
                    230: 
                    231: 1;
                    232: __END__

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