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

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.38    ! raeburn     4: # $Id: lonbulletin.pm,v 1.37 2006/07/17 21:59:24 raeburn 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.36      raeburn    38: use Apache::lonhtmlcommon;
                     39: use LONCAPA;
1.1       www        40: 
                     41: sub handler {
                     42:     my $r = shift;
1.16      www        43:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        44:     $r->send_http_header;
                     45:     return OK if $r->header_only;
1.29      albertel   46:     my $target=$env{'form.grade_target'};
1.23      sakharuk   47: 
1.1       www        48: # ------------------------------------------------------------ Print the screen
1.32      albertel   49:     if ($target eq 'tex') {
1.29      albertel   50: 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23      sakharuk   51:     }
1.2       www        52:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        53: # Is this even in a course?
1.32      albertel   54:     if (!$env{'request.course.id'}) {
1.34      albertel   55: 	&Apache::loncommon::simple_error_page($r,'Not in a course',
1.36      raeburn    56: 				                'Not in a course');
1.1       www        57:         return OK;
                     58:     }
                     59: 
                     60:     $marker=~s/\D//g;
                     61: 
1.32      albertel   62:     if (!$marker) {
1.34      albertel   63: 	&Apache::loncommon::simple_error_page($r,'Invalid Call',
                     64: 					      'Invalid Call');
1.1       www        65:         return OK;
                     66:     }
                     67: 
1.29      albertel   68:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     69:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.36      raeburn    70:     my ($group,$grp_desc);
1.1       www        71: 
                     72: # --------------------------------------------------------- The syllabus fields
1.17      www        73:     my %syllabusfields=&Apache::lonlocal::texthash(
1.2       www        74:        'aaa_title'         => 'Topic',
                     75:        'bbb_content'       => 'Task',
1.1       www        76:        'ccc_webreferences' => 'Web References');
                     77: 
1.7       www        78: # ------------------------------------------------------------ Get Query String
                     79:     &Apache::loncommon::get_unprocessed_cgi
1.36      raeburn    80:                 ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register',
1.37      raeburn    81:                                        'origpage','group','ref']);
1.7       www        82: # ----------------------------------------------------- Force menu registration
1.35      albertel   83:     my %addentries;
                     84:     if ($env{'form.origpage'}) {
                     85: 	$addentries{'onload'} = "document.location='#newpost';";
1.7       www        86:     }
1.1       www        87: # --------------------------------------------------------------- Force Student
                     88:     my $forcestudent='';
1.29      albertel   89:     if ($env{'form.forcestudent'}) { $forcestudent='student'; }
1.19      www        90: 
                     91:     my $forceedit='';
1.29      albertel   92:     if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.37      raeburn    93:     my $refarg = '';
                     94:     if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
1.1       www        95: 
                     96:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36      raeburn    97: 
                     98:     my $boardurl = $r->uri;
                     99:     if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
                    100:         if (!exists($syllabus{'group'})) {
                    101:             &Apache::loncommon::simple_error_page($r,'Group information missing',
                    102:                                                  'Group information missing');
                    103: 
                    104:             return OK;
                    105:         } else {
                    106:             $group = $syllabus{'group'};
                    107:             if ($group eq '') {
                    108:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    109:                                                      'Invalid group');
                    110:                 return OK;
                    111:             }
                    112:             my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
                    113:             if (!defined($curr_groups{$group})) {
                    114:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    115:                                                      'Invalid group');
                    116:                 return OK;
                    117:             } else {
                    118:                 my %content = &Apache::longroup::get_group_settings(
                    119:                                                           $curr_groups{$group});
                    120:                 $grp_desc = &unescape($content{'description'});
                    121:             }
                    122:         }
                    123:     }
1.1       www       124:        
                    125: # --------------------------------------- There is such a user, get environment
1.32      albertel  126:     if ($target ne 'tex') {  
                    127: 	my $start_page =
                    128: 	    &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
                    129: 					   {'function'       => $forcestudent,
1.35      albertel  130: 					    'add_entries'    => \%addentries,
1.33      albertel  131: 					    'domain'         => $dom,
1.32      albertel  132: 					    'force_register' =>
                    133: 						$env{'form.register'}});
                    134: 	$r->print($start_page);
1.36      raeburn   135:         if ($group ne '' && $env{'form.group'} eq $group) {
                    136:             my $gpterm =  &Apache::loncommon::group_term();
                    137:             my $ucgpterm = $gpterm;
                    138:             $ucgpterm =~ s/^(\w)/uc($1)/e;
1.37      raeburn   139:             my ($groupboards,$boards) =
                    140:                 &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
                    141:             my $boardtitle;
                    142:             if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
                    143:                 $boardtitle = $$boards{$$groupboards[0]}{'title'};
                    144:             }
1.36      raeburn   145:             $boardurl .= '?register=1&group='.$group;
1.37      raeburn   146:             $r->print(&groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
1.36      raeburn   147:                                 $ucgpterm,$grp_desc,$boardurl,$boardtitle));
                    148:         }
                    149:     }
                    150:     my ($allowed);
                    151:     if ($group ne '') {
1.37      raeburn   152:         $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.36      raeburn   153:         if (!$allowed) {
                    154:             $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                    155:                                                 '/'.$group);
                    156:         }
                    157:         if (!$allowed) {
1.37      raeburn   158:             if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
1.36      raeburn   159:                (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
                    160:                                                 '/'.$group))) { 
                    161:                  &print_end_page($r,$target);
                    162:                  return OK;   
                    163:             }
                    164:         }
                    165:     } else {
                    166:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23      sakharuk  167:     }
1.1       www       168: 
1.19      www       169:     my $privileged=$allowed;
                    170:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    171:  	$forcestudent='student';
                    172:     }
1.27      albertel  173:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
1.23      sakharuk  174:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.1       www       175:  
1.23      sakharuk  176:       if ($allowed) {
1.36      raeburn   177:           my $query_str = 'forcestudent=1';
                    178:           if (($group ne '') && ($env{'form.group'} eq $group)) {
1.37      raeburn   179:               $query_str.='&amp;group='.$group.'&amp;'.$refarg;
1.36      raeburn   180:           }
1.1       www       181:           $r->print(
1.6       www       182: 	  '<p>'.
1.36      raeburn   183: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'.&mt('Show Student View').'</font></a>'.
1.5       www       184:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.23      sakharuk  185:       }  elsif ($privileged and $target ne 'tex') {
1.36      raeburn   186:           my $query_str = 'forceedit=edit';
                    187:           if (($group ne '') && ($env{'form.group'} eq $group)) {
1.37      raeburn   188:               $query_str.='&amp;group='.$group.'&amp;'.$refarg;
1.36      raeburn   189:           }
                    190: 	  $r->print('<a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'
1.19      www       191: 		    .&mt('Edit').'</font></a>');
                    192:       } 
                    193: 
1.29      albertel  194:       if (($env{'form.uploaddoc.filename'}) &&
                    195:           ($env{'form.storeupl'}) && ($allowed)) {
                    196:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.20      albertel  197: 	      if ($syllabus{'uploaded.photourl'}) {
                    198: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    199: 	      }
1.38    ! raeburn   200:               if ($group ne '') {
        !           201: 	          $syllabus{'uploaded.photourl'}=
        !           202: 		      &Apache::lonnet::userfileupload('uploaddoc',1,
        !           203:                                                       'bulletin/'.$group.'/'.$marker);
        !           204:               } else {
        !           205:                   $syllabus{'uploaded.photourl'}=
        !           206:                       &Apache::lonnet::userfileupload('uploaddoc',1,
        !           207:                                                       'bulletin/'.$marker);
        !           208:               }
1.1       www       209:  	  }
                    210:           $syllabus{'uploaded.lastmodified'}=time;
                    211:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    212:        }
1.29      albertel  213:        if (($allowed) && ($env{'form.storesyl'})) {
1.1       www       214: 	   foreach (keys %syllabusfields) {
1.29      albertel  215:                my $field=$env{'form.'.$_};
1.1       www       216:                $field=~s/\s+$//s;
1.5       www       217:                $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1       www       218: 	       $syllabus{$_}=$field;
                    219:            }
                    220:            $syllabus{'uploaded.lastmodified'}=time;
                    221:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    222:        }
                    223: 
                    224: # ---------------------------------------------------------------- Get syllabus
                    225:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
                    226:        if ($syllabus{'uploaded.photourl'}) {
1.20      albertel  227: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
                    228: 					  $syllabus{'uploaded.photourl'});
                    229: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
                    230: 	       '" align="right" />');
1.1       www       231:        }
                    232:        if ($allowed) {
                    233:            $r->print(
                    234: 	 '<form method="post" enctype="multipart/form-data">'.
1.19      www       235:  	 '<input type="hidden" name="forceedit" value="edit" />'.
                    236:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.1       www       237:          '<input type="file" name="uploaddoc" size="50">'.
1.19      www       238:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
1.1       www       239: 	 '</form><form method="post">');
                    240:        }
                    241:        foreach (sort keys %syllabusfields) {
                    242:           if (($syllabus{$_}) || ($allowed)) {
                    243:               my $message=$syllabus{$_};
1.30      albertel  244: 	      &Apache::lonfeedback::newline_to_br(\$message);
                    245: 	      $message
1.10      www       246:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.25      www       247: 	      if ($allowed) {
                    248: 		  $message=&Apache::lonspeller::markeduptext($message);
                    249: 	      }
1.31      www       250: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.25      www       251: 	      unless ($_ eq 'aaa_title') {
1.2       www       252: 		if (($_ ne 'bbb_content') || ($allowed)) {
1.23      sakharuk  253: 		    if ($target ne 'tex') {
                    254: 			$r->print('<h3>'.$syllabusfields{$_}.'</h3>');
                    255: 		    } else {
                    256: 			$r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
                    257: 		    }
                    258: 		}
                    259: 		if ($target ne 'tex') {
                    260: 		    $r->print('<blockquote>'.
                    261:                               $message.'</blockquote>');
                    262: 		} else {
                    263: 		    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
1.2       www       264: 		}
                    265:                  if ($allowed) {
1.3       www       266:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
1.1       www       267: 			   $syllabus{$_}.
1.19      www       268:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       269: 	        }
                    270: 	    } else {
1.23      sakharuk  271:                 if ($target ne 'tex') {
                    272: 		    $r->print('<h1>'.$message.'</h1>');
                    273: 		} else {
                    274: 		    $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
                    275: 		}
1.2       www       276:                 if ($allowed) {
                    277:                  $r->print(
1.19      www       278:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
1.2       www       279: 			   $syllabus{$_}.
1.19      www       280:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       281:                 }
                    282:             }
1.1       www       283: 	  }
                    284:        }
                    285:        if ($allowed) {
                    286: 	   $r->print('</form>');
                    287:        }
1.23      sakharuk  288:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.1       www       289:     } else {
1.19      www       290:        $r->print('<p>'.&mt('No page information provided.').'</p>');
1.1       www       291:     }
1.27      albertel  292:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
1.23      sakharuk  293:     if ($target ne 'tex') {
                    294: 	$r->print(&Apache::lonfeedback::list_discussion
                    295: 	           ('board','OPEN','bulletin___'.$marker.'___'.
1.37      raeburn   296: 	            $r->uri,undef,$group));
1.23      sakharuk  297:     } else {
                    298: 	$r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
                    299: 	           ('board','OPEN','bulletin___'.$marker.'___'.
1.37      raeburn   300: 	            $r->uri,undef,$group)));
1.23      sakharuk  301:     }
1.36      raeburn   302:     &print_end_page($r,$target);
                    303:     return OK;
                    304: }
                    305: 
                    306: sub print_end_page {
                    307:     my ($r,$target) = @_;
1.32      albertel  308:     if ($target ne 'tex') {
1.36      raeburn   309:         $r->print(&Apache::loncommon::end_page());
1.32      albertel  310:     } else {
1.36      raeburn   311:         $r->print('\end{document}');
1.32      albertel  312:     }
1.36      raeburn   313: }
                    314: 
                    315: sub groupboard_breadcrumbs {
1.37      raeburn   316:     my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
                    317:         $boardtitle)= @_;
1.36      raeburn   318:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.37      raeburn   319:     if ($refarg ne '') {
                    320:         &Apache::lonhtmlcommon::add_breadcrumb
                    321:             ({href=>"/adm/coursegroups",
                    322:               text=>"Groups",
                    323:               title=>"View course groups"});
                    324:     }
1.36      raeburn   325:     &Apache::lonhtmlcommon::add_breadcrumb
1.37      raeburn   326:         ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
1.36      raeburn   327:           text=>"$ucgpterm: $description",
                    328:           title=>"Go to group's home page"},
1.37      raeburn   329:          {href=>"/adm/groupboards?group=$group&amp;$refarg",
1.36      raeburn   330:           text=>"Discussion Boards",
                    331:           title=>"Display group discussion boards"},
                    332:          {href=>"$boardurl",
                    333:           text=>"$boardtitle",
                    334:           title=>"$boardtitle"},
                    335:         );
                    336:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
                    337:     return $output;
                    338: }
1.1       www       339: 
                    340: 1;
                    341: __END__

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