File:  [LON-CAPA] / loncom / interface / lonbulletin.pm
Revision 1.36: download - view: text, annotated - select for diffs
Sat Jul 8 01:23:13 2006 UTC (17 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Adding breadcrumbs to group discussion board display. Group context detected from course domain and course number in URL.  Corresponding groupID is determined from group entry in bulletinpage_$boardid.db file.

    1: # The LearningOnline Network
    2: # Bulletin Board Handler
    3: #
    4: # $Id: lonbulletin.pm,v 1.36 2006/07/08 01:23:13 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']);
   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: 
   94:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
   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:     }
  122:        
  123: # --------------------------------------- There is such a user, get environment
  124:     if ($target ne 'tex') {  
  125: 	my $start_page =
  126: 	    &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
  127: 					   {'function'       => $forcestudent,
  128: 					    'add_entries'    => \%addentries,
  129: 					    'domain'         => $dom,
  130: 					    'force_register' =>
  131: 						$env{'form.register'}});
  132: 	$r->print($start_page);
  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'});
  162:     }
  163: 
  164:     my $privileged=$allowed;
  165:     if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
  166:  	$forcestudent='student';
  167:     }
  168:     if ($target ne 'tex') { $r->print('<table><tr><td>'); }
  169:       if ($forcestudent or $target eq 'tex') { $allowed=0; }
  170:  
  171:       if ($allowed) {
  172:           my $query_str = 'forcestudent=1';
  173:           if (($group ne '') && ($env{'form.group'} eq $group)) {
  174:               $query_str.='&amp;group='.$group;
  175:           }
  176:           $r->print(
  177: 	  '<p>'.
  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>'.
  179:  &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
  180:       }  elsif ($privileged and $target ne 'tex') {
  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">'
  186: 		    .&mt('Edit').'</font></a>');
  187:       } 
  188: 
  189:       if (($env{'form.uploaddoc.filename'}) &&
  190:           ($env{'form.storeupl'}) && ($allowed)) {
  191:  	  if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
  192: 	      if ($syllabus{'uploaded.photourl'}) {
  193: 		  &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
  194: 	      }
  195: 	      $syllabus{'uploaded.photourl'}=
  196: 		  &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
  197:  	  }
  198:           $syllabus{'uploaded.lastmodified'}=time;
  199:           &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
  200:        }
  201:        if (($allowed) && ($env{'form.storesyl'})) {
  202: 	   foreach (keys %syllabusfields) {
  203:                my $field=$env{'form.'.$_};
  204:                $field=~s/\s+$//s;
  205:                $field=&Apache::lonfeedback::clear_out_html($field,1);
  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'}) {
  215: 	   &Apache::lonnet::allowuploaded('/adm/syllabus',
  216: 					  $syllabus{'uploaded.photourl'});
  217: 	   $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
  218: 	       '" align="right" />');
  219:        }
  220:        if ($allowed) {
  221:            $r->print(
  222: 	 '<form method="post" enctype="multipart/form-data">'.
  223:  	 '<input type="hidden" name="forceedit" value="edit" />'.
  224:          '<h3>'.&mt('Upload a Photo').'</h3>'.
  225:          '<input type="file" name="uploaddoc" size="50">'.
  226:          '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
  227: 	 '</form><form method="post">');
  228:        }
  229:        foreach (sort keys %syllabusfields) {
  230:           if (($syllabus{$_}) || ($allowed)) {
  231:               my $message=$syllabus{$_};
  232: 	      &Apache::lonfeedback::newline_to_br(\$message);
  233: 	      $message
  234:         =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
  235: 	      if ($allowed) {
  236: 		  $message=&Apache::lonspeller::markeduptext($message);
  237: 	      }
  238: 	      $message=&Apache::lontexconvert::msgtexconverted($message);
  239: 	      unless ($_ eq 'aaa_title') {
  240: 		if (($_ ne 'bbb_content') || ($allowed)) {
  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).' ');
  252: 		}
  253:                  if ($allowed) {
  254:                 $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
  255: 			   $syllabus{$_}.
  256:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  257: 	        }
  258: 	    } else {
  259:                 if ($target ne 'tex') {
  260: 		    $r->print('<h1>'.$message.'</h1>');
  261: 		} else {
  262: 		    $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
  263: 		}
  264:                 if ($allowed) {
  265:                  $r->print(
  266:                 '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
  267: 			   $syllabus{$_}.
  268:            '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
  269:                 }
  270:             }
  271: 	  }
  272:        }
  273:        if ($allowed) {
  274: 	   $r->print('</form>');
  275:        }
  276:        if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
  277:     } else {
  278:        $r->print('<p>'.&mt('No page information provided.').'</p>');
  279:     }
  280:     if ($target ne 'tex') { $r->print('</td></tr></table>'); }
  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:     }
  290:     &print_end_page($r,$target);
  291:     return OK;
  292: }
  293: 
  294: sub print_end_page {
  295:     my ($r,$target) = @_;
  296:     if ($target ne 'tex') {
  297:         $r->print(&Apache::loncommon::end_page());
  298:     } else {
  299:         $r->print('\end{document}');
  300:     }
  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: }
  320: 
  321: 1;
  322: __END__

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