File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.37: download - view: text, annotated - select for diffs
Mon Jul 17 21:59:24 2006 UTC (17 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
priv checking for group bulletin board editing for roles which include section specification. Breadcrumbs include link back to listing of groups if board was reached via the "Groups" link.

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

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