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

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.24    ! sakharuk    4: # $Id: lonbulletin.pm,v 1.23 2004/05/10 14:10:03 sakharuk 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.23      sakharuk   44:     my $target=$ENV{'form.grade_target'};
                     45: 
1.1       www        46: 
1.22      raeburn    47: #    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
1.1       www        48: # ------------------------------------------------------------ Print the screen
1.23      sakharuk   49:     if ($target ne 'tex') {
                     50: 	$r->print(<<ENDDOCUMENT);
1.1       www        51: <html>
                     52: <head>
                     53: <title>The LearningOnline Network with CAPA</title>
                     54: ENDDOCUMENT
1.23      sakharuk   55: } else {
                     56: 	$r->print(&Apache::lonprintout::print_latex_header($ENV{'form.latex_type'}));
                     57:     }
1.2       www        58:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        59: # Is this even in a course?
                     60:     unless ($ENV{'request.course.id'}) {
1.8       www        61: 	$r->print('</head><body>Not in a course</body></html>');
1.1       www        62:         return OK;
                     63:     }
                     64: 
                     65:     $marker=~s/\D//g;
                     66: 
                     67:     unless ($marker) {
                     68: 	$r->print('<body>Invalid call</body>');
                     69:         return OK;
                     70:     }
                     71: 
                     72:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                     73:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                     74: 
                     75: # --------------------------------------------------------- The syllabus fields
1.17      www        76:     my %syllabusfields=&Apache::lonlocal::texthash(
1.2       www        77:        'aaa_title'         => 'Topic',
                     78:        'bbb_content'       => 'Task',
1.1       www        79:        'ccc_webreferences' => 'Web References');
                     80: 
1.7       www        81: # ------------------------------------------------------------ Get Query String
                     82:     &Apache::loncommon::get_unprocessed_cgi
1.19      www        83:                 ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register']);
1.7       www        84: # ----------------------------------------------------- Force menu registration
                     85:     my $addentries='';
                     86:     if ($ENV{'form.register'}) {
                     87:        $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
                     88: 	   '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
                     89:        $r->print(&Apache::lonmenu::registerurl(1));
                     90:     }
1.1       www        91: # --------------------------------------------------------------- Force Student
                     92:     my $forcestudent='';
1.19      www        93:     if ($ENV{'form.forcestudent'}) { $forcestudent='student'; }
                     94: 
                     95:     my $forceedit='';
                     96:     if ($ENV{'form.forceedit'}) { $forceedit='edit'; }
1.1       www        97: 
                     98:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
                     99:        
                    100: # --------------------------------------- There is such a user, get environment
1.23      sakharuk  101:     if ($target ne 'tex') {   
                    102: 	$r->print('</head>'.&Apache::loncommon::bodytag
                    103:                   ("Bulletin Board/Discussion",$forcestudent,$addentries,'',$dom,
                    104:                   $ENV{'form.register'}));
                    105:     }
1.12      www       106:     my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.1       www       107: 
1.19      www       108:     my $privileged=$allowed;
                    109:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    110:  	$forcestudent='student';
                    111:     }
                    112: 
1.23      sakharuk  113:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.1       www       114:  
1.23      sakharuk  115:       if ($allowed) {
1.1       www       116:           $r->print(
1.6       www       117: 	  '<p>'.
1.19      www       118: &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       119:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.23      sakharuk  120:       }  elsif ($privileged and $target ne 'tex') {
1.19      www       121: 	  $r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'
                    122: 		    .&mt('Edit').'</font></a>');
                    123:       } 
                    124: 
1.1       www       125:       if (($ENV{'form.uploaddoc.filename'}) &&
                    126:           ($ENV{'form.storeupl'}) && ($allowed)) {
1.9       www       127:  	  if ($ENV{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.20      albertel  128: 	      if ($syllabus{'uploaded.photourl'}) {
                    129: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    130: 	      }
                    131: 	      $syllabus{'uploaded.photourl'}=
                    132: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
1.1       www       133:  	  }
                    134:           $syllabus{'uploaded.lastmodified'}=time;
                    135:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    136:        }
                    137:        if (($allowed) && ($ENV{'form.storesyl'})) {
                    138: 	   foreach (keys %syllabusfields) {
                    139:                my $field=$ENV{'form.'.$_};
                    140:                $field=~s/\s+$//s;
1.5       www       141:                $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1       www       142: 	       $syllabus{$_}=$field;
                    143:            }
                    144:            $syllabus{'uploaded.lastmodified'}=time;
                    145:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    146:        }
                    147: 
                    148: # ---------------------------------------------------------------- Get syllabus
                    149:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
                    150:        if ($syllabus{'uploaded.photourl'}) {
1.20      albertel  151: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
                    152: 					  $syllabus{'uploaded.photourl'});
                    153: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
                    154: 	       '" align="right" />');
1.1       www       155:        }
                    156:        if ($allowed) {
                    157:            $r->print(
                    158: 	 '<form method="post" enctype="multipart/form-data">'.
1.19      www       159:  	 '<input type="hidden" name="forceedit" value="edit" />'.
                    160:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.1       www       161:          '<input type="file" name="uploaddoc" size="50">'.
1.19      www       162:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
1.1       www       163: 	 '</form><form method="post">');
                    164:        }
                    165:        foreach (sort keys %syllabusfields) {
                    166:           if (($syllabus{$_}) || ($allowed)) {
                    167:               my $message=$syllabus{$_};
                    168:               $message=~s/\n/\<br \/\>/g;
                    169:               $message
1.10      www       170:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.1       www       171: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.2       www       172:             unless ($_ eq 'aaa_title') {
                    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.23      sakharuk  213:     if ($target ne 'tex') {
                    214: 	$r->print(&Apache::lonfeedback::list_discussion
                    215: 	           ('board','OPEN','bulletin___'.$marker.'___'.
                    216: 	            $r->uri));
                    217:     } else {
                    218: 	$r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
                    219: 	           ('board','OPEN','bulletin___'.$marker.'___'.
                    220: 	            $r->uri)));
                    221:     }
                    222:     if ($target ne 'tex') {$r->print('</body></html>');} else {$r->print('\end{document}');}
1.1       www       223:     return OK;
                    224: } 
                    225: 
                    226: 1;
                    227: __END__

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