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

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.36    ! raeburn     4: # $Id: lonbulletin.pm,v 1.35 2006/04/10 19:59:53 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.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',
        !            81:                                        'origpage','group']);
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.1       www        93: 
                     94:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36    ! raeburn    95: 
        !            96:     my $boardurl = $r->uri;
        !            97:     if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
        !            98:         if (!exists($syllabus{'group'})) {
        !            99:             &Apache::loncommon::simple_error_page($r,'Group information missing',
        !           100:                                                  'Group information missing');
        !           101: 
        !           102:             return OK;
        !           103:         } else {
        !           104:             $group = $syllabus{'group'};
        !           105:             if ($group eq '') {
        !           106:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
        !           107:                                                      'Invalid group');
        !           108:                 return OK;
        !           109:             }
        !           110:             my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
        !           111:             if (!defined($curr_groups{$group})) {
        !           112:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
        !           113:                                                      'Invalid group');
        !           114:                 return OK;
        !           115:             } else {
        !           116:                 my %content = &Apache::longroup::get_group_settings(
        !           117:                                                           $curr_groups{$group});
        !           118:                 $grp_desc = &unescape($content{'description'});
        !           119:             }
        !           120:         }
        !           121:     }
1.1       www       122:        
                    123: # --------------------------------------- There is such a user, get environment
1.32      albertel  124:     if ($target ne 'tex') {  
                    125: 	my $start_page =
                    126: 	    &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
                    127: 					   {'function'       => $forcestudent,
1.35      albertel  128: 					    'add_entries'    => \%addentries,
1.33      albertel  129: 					    'domain'         => $dom,
1.32      albertel  130: 					    'force_register' =>
                    131: 						$env{'form.register'}});
                    132: 	$r->print($start_page);
1.36    ! raeburn   133:         if ($group ne '' && $env{'form.group'} eq $group) {
        !           134:             my $gpterm =  &Apache::loncommon::group_term();
        !           135:             my $ucgpterm = $gpterm;
        !           136:             $ucgpterm =~ s/^(\w)/uc($1)/e;
        !           137:             my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo(
        !           138:                                                             $dom,$crs,$group);
        !           139:             my $boardtitle = $$boards{$marker}{'title'};
        !           140:             $boardurl .= '?register=1&group='.$group;
        !           141:             $r->print(&groupboard_breadcrumbs($dom,$crs,$group,$gpterm,
        !           142:                                 $ucgpterm,$grp_desc,$boardurl,$boardtitle));
        !           143:         }
        !           144:     }
        !           145:     my ($allowed);
        !           146:     if ($group ne '') {
        !           147:         $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'});
        !           148:         if (!$allowed) {
        !           149:             $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
        !           150:                                                 '/'.$group);
        !           151:         }
        !           152:         if (!$allowed) {
        !           153:             if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'})) &&
        !           154:                (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
        !           155:                                                 '/'.$group))) { 
        !           156:                  &print_end_page($r,$target);
        !           157:                  return OK;   
        !           158:             }
        !           159:         }
        !           160:     } else {
        !           161:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23      sakharuk  162:     }
1.1       www       163: 
1.19      www       164:     my $privileged=$allowed;
                    165:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
                    166:  	$forcestudent='student';
                    167:     }
1.27      albertel  168:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
1.23      sakharuk  169:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.1       www       170:  
1.23      sakharuk  171:       if ($allowed) {
1.36    ! raeburn   172:           my $query_str = 'forcestudent=1';
        !           173:           if (($group ne '') && ($env{'form.group'} eq $group)) {
        !           174:               $query_str.='&amp;group='.$group;
        !           175:           }
1.1       www       176:           $r->print(
1.6       www       177: 	  '<p>'.
1.36    ! raeburn   178: &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       179:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.23      sakharuk  180:       }  elsif ($privileged and $target ne 'tex') {
1.36    ! raeburn   181:           my $query_str = 'forceedit=edit';
        !           182:           if (($group ne '') && ($env{'form.group'} eq $group)) {
        !           183:               $query_str.='&amp;group='.$group;
        !           184:           }
        !           185: 	  $r->print('<a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'
1.19      www       186: 		    .&mt('Edit').'</font></a>');
                    187:       } 
                    188: 
1.29      albertel  189:       if (($env{'form.uploaddoc.filename'}) &&
                    190:           ($env{'form.storeupl'}) && ($allowed)) {
                    191:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.20      albertel  192: 	      if ($syllabus{'uploaded.photourl'}) {
                    193: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    194: 	      }
                    195: 	      $syllabus{'uploaded.photourl'}=
                    196: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
1.1       www       197:  	  }
                    198:           $syllabus{'uploaded.lastmodified'}=time;
                    199:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    200:        }
1.29      albertel  201:        if (($allowed) && ($env{'form.storesyl'})) {
1.1       www       202: 	   foreach (keys %syllabusfields) {
1.29      albertel  203:                my $field=$env{'form.'.$_};
1.1       www       204:                $field=~s/\s+$//s;
1.5       www       205:                $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1       www       206: 	       $syllabus{$_}=$field;
                    207:            }
                    208:            $syllabus{'uploaded.lastmodified'}=time;
                    209:            &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    210:        }
                    211: 
                    212: # ---------------------------------------------------------------- Get syllabus
                    213:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
                    214:        if ($syllabus{'uploaded.photourl'}) {
1.20      albertel  215: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
                    216: 					  $syllabus{'uploaded.photourl'});
                    217: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
                    218: 	       '" align="right" />');
1.1       www       219:        }
                    220:        if ($allowed) {
                    221:            $r->print(
                    222: 	 '<form method="post" enctype="multipart/form-data">'.
1.19      www       223:  	 '<input type="hidden" name="forceedit" value="edit" />'.
                    224:          '<h3>'.&mt('Upload a Photo').'</h3>'.
1.1       www       225:          '<input type="file" name="uploaddoc" size="50">'.
1.19      www       226:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
1.1       www       227: 	 '</form><form method="post">');
                    228:        }
                    229:        foreach (sort keys %syllabusfields) {
                    230:           if (($syllabus{$_}) || ($allowed)) {
                    231:               my $message=$syllabus{$_};
1.30      albertel  232: 	      &Apache::lonfeedback::newline_to_br(\$message);
                    233: 	      $message
1.10      www       234:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.25      www       235: 	      if ($allowed) {
                    236: 		  $message=&Apache::lonspeller::markeduptext($message);
                    237: 	      }
1.31      www       238: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
1.25      www       239: 	      unless ($_ eq 'aaa_title') {
1.2       www       240: 		if (($_ ne 'bbb_content') || ($allowed)) {
1.23      sakharuk  241: 		    if ($target ne 'tex') {
                    242: 			$r->print('<h3>'.$syllabusfields{$_}.'</h3>');
                    243: 		    } else {
                    244: 			$r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
                    245: 		    }
                    246: 		}
                    247: 		if ($target ne 'tex') {
                    248: 		    $r->print('<blockquote>'.
                    249:                               $message.'</blockquote>');
                    250: 		} else {
                    251: 		    $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
1.2       www       252: 		}
                    253:                  if ($allowed) {
1.3       www       254:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
1.1       www       255: 			   $syllabus{$_}.
1.19      www       256:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       257: 	        }
                    258: 	    } else {
1.23      sakharuk  259:                 if ($target ne 'tex') {
                    260: 		    $r->print('<h1>'.$message.'</h1>');
                    261: 		} else {
                    262: 		    $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
                    263: 		}
1.2       www       264:                 if ($allowed) {
                    265:                  $r->print(
1.19      www       266:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
1.2       www       267: 			   $syllabus{$_}.
1.19      www       268:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2       www       269:                 }
                    270:             }
1.1       www       271: 	  }
                    272:        }
                    273:        if ($allowed) {
                    274: 	   $r->print('</form>');
                    275:        }
1.23      sakharuk  276:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.1       www       277:     } else {
1.19      www       278:        $r->print('<p>'.&mt('No page information provided.').'</p>');
1.1       www       279:     }
1.27      albertel  280:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
1.23      sakharuk  281:     if ($target ne 'tex') {
                    282: 	$r->print(&Apache::lonfeedback::list_discussion
                    283: 	           ('board','OPEN','bulletin___'.$marker.'___'.
                    284: 	            $r->uri));
                    285:     } else {
                    286: 	$r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
                    287: 	           ('board','OPEN','bulletin___'.$marker.'___'.
                    288: 	            $r->uri)));
                    289:     }
1.36    ! raeburn   290:     &print_end_page($r,$target);
        !           291:     return OK;
        !           292: }
        !           293: 
        !           294: sub print_end_page {
        !           295:     my ($r,$target) = @_;
1.32      albertel  296:     if ($target ne 'tex') {
1.36    ! raeburn   297:         $r->print(&Apache::loncommon::end_page());
1.32      albertel  298:     } else {
1.36    ! raeburn   299:         $r->print('\end{document}');
1.32      albertel  300:     }
1.36    ! raeburn   301: }
        !           302: 
        !           303: sub groupboard_breadcrumbs {
        !           304:     my ($cdom,$cnum,$group,$gpterm,$ucgpterm,$description,$boardurl,$boardtitle)= @_;
        !           305:     &Apache::lonhtmlcommon::clear_breadcrumbs();
        !           306:     &Apache::lonhtmlcommon::add_breadcrumb
        !           307:         ({href=>"/adm/$cdom/$cnum/$group/smppg",
        !           308:           text=>"$ucgpterm: $description",
        !           309:           title=>"Go to group's home page"},
        !           310:          {href=>"/adm/groupboards?group=$group",
        !           311:           text=>"Discussion Boards",
        !           312:           title=>"Display group discussion boards"},
        !           313:          {href=>"$boardurl",
        !           314:           text=>"$boardtitle",
        !           315:           title=>"$boardtitle"},
        !           316:         );
        !           317:     my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
        !           318:     return $output;
        !           319: }
1.1       www       320: 
                    321: 1;
                    322: __END__

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