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

1.1       www         1: # The LearningOnline Network
1.5       www         2: # Bulletin Board Handler
1.1       www         3: #
1.64    ! raeburn     4: # $Id: lonbulletin.pm,v 1.63 2011/05/02 18:32:30 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;
1.39      albertel   39: use HTML::Entities();
1.36      raeburn    40: use LONCAPA;
1.1       www        41: 
                     42: sub handler {
                     43:     my $r = shift;
1.16      www        44:     &Apache::loncommon::content_type($r,'text/html');
1.1       www        45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
1.29      albertel   47:     my $target=$env{'form.grade_target'};
1.23      sakharuk   48: 
1.1       www        49: # ------------------------------------------------------------ Print the screen
1.32      albertel   50:     if ($target eq 'tex') {
1.49      bisitz     51:         $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23      sakharuk   52:     }
1.2       www        53:     my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1       www        54: # Is this even in a course?
1.32      albertel   55:     if (!$env{'request.course.id'}) {
1.49      bisitz     56:         &Apache::loncommon::simple_error_page($r,'Not in a course',
                     57:                                               'Not in a course');
1.1       www        58:         return OK;
                     59:     }
                     60: 
                     61:     $marker=~s/\D//g;
                     62: 
1.32      albertel   63:     if (!$marker) {
1.49      bisitz     64:         &Apache::loncommon::simple_error_page($r,'Invalid Call',
                     65:                                               'Invalid Call');
1.1       www        66:         return OK;
                     67:     }
                     68: 
1.29      albertel   69:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     70:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.36      raeburn    71:     my ($group,$grp_desc);
1.1       www        72: 
                     73: # --------------------------------------------------------- The syllabus fields
1.17      www        74:     my %syllabusfields=&Apache::lonlocal::texthash(
1.2       www        75:        'aaa_title'         => 'Topic',
                     76:        'bbb_content'       => 'Task',
1.1       www        77:        'ccc_webreferences' => 'Web References');
                     78: 
1.7       www        79: # ------------------------------------------------------------ Get Query String
                     80:     &Apache::loncommon::get_unprocessed_cgi
1.64    ! raeburn    81:                 ($ENV{'QUERY_STRING'},['forceedit','register',
1.37      raeburn    82:                                        'origpage','group','ref']);
1.7       www        83: # ----------------------------------------------------- Force menu registration
1.35      albertel   84:     my %addentries;
                     85:     if ($env{'form.origpage'}) {
1.49      bisitz     86:         $addentries{'onload'} = "document.location='#newpost';";
1.7       www        87:     }
1.1       www        88: # --------------------------------------------------------------- Force Student
1.64    ! raeburn    89:     my ($forceedit,$forcestudent);
        !            90:     $forceedit = $env{'form.forceedit'};
        !            91:     if (!$forceedit) {
        !            92:         $forcestudent=1;
        !            93:     }
1.37      raeburn    94:     my $refarg = '';
                     95:     if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
1.1       www        96: 
                     97:     my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36      raeburn    98: 
                     99:     my $boardurl = $r->uri;
                    100:     if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
                    101:         if (!exists($syllabus{'group'})) {
                    102:             &Apache::loncommon::simple_error_page($r,'Group information missing',
                    103:                                                  'Group information missing');
                    104: 
                    105:             return OK;
                    106:         } else {
                    107:             $group = $syllabus{'group'};
                    108:             if ($group eq '') {
                    109:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    110:                                                      'Invalid group');
                    111:                 return OK;
                    112:             }
                    113:             my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
                    114:             if (!defined($curr_groups{$group})) {
                    115:                 &Apache::loncommon::simple_error_page($r,'Invalid group',
                    116:                                                      'Invalid group');
                    117:                 return OK;
                    118:             } else {
                    119:                 my %content = &Apache::longroup::get_group_settings(
                    120:                                                           $curr_groups{$group});
                    121:                 $grp_desc = &unescape($content{'description'});
                    122:             }
                    123:         }
                    124:     }
1.49      bisitz    125: 
1.1       www       126: # --------------------------------------- There is such a user, get environment
1.49      bisitz    127:     if ($target ne 'tex') {
1.64    ! raeburn   128:         my ($course_or_group,$brcrum);
1.49      bisitz    129:         if($group eq '') {
                    130:             $course_or_group="Course";
                    131:         } else {
                    132:             $course_or_group="Group";
                    133:         }
1.36      raeburn   134:         if ($group ne '' && $env{'form.group'} eq $group) {
                    135:             my $gpterm =  &Apache::loncommon::group_term();
                    136:             my $ucgpterm = $gpterm;
                    137:             $ucgpterm =~ s/^(\w)/uc($1)/e;
1.37      raeburn   138:             my ($groupboards,$boards) =
                    139:                 &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
                    140:             my $boardtitle;
                    141:             if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
                    142:                 $boardtitle = $$boards{$$groupboards[0]}{'title'};
                    143:             }
1.36      raeburn   144:             $boardurl .= '?register=1&group='.$group;
1.64    ! raeburn   145:             $brcrum = 
        !           146:                 &groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
        !           147:                                         $ucgpterm,$grp_desc,$boardurl,$boardtitle);
        !           148:         } else {
        !           149:             $brcrum = [];
1.36      raeburn   150:         }
1.64    ! raeburn   151:         my $start_page =
        !           152:             &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
        !           153:                                            {'add_entries'    => \%addentries,
        !           154:                                             'domain'         => $dom,
        !           155:                                             'bread_crumbs'   => $brcrum, 
        !           156:                                             'group'          => $group,
        !           157:                                             'force_register' =>
        !           158:                                                 $env{'form.register'}});
        !           159:         $r->print($start_page);
1.36      raeburn   160:     }
                    161:     my ($allowed);
                    162:     if ($group ne '') {
1.37      raeburn   163:         $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.36      raeburn   164:         if (!$allowed) {
                    165:             $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                    166:                                                 '/'.$group);
                    167:         }
                    168:         if (!$allowed) {
1.37      raeburn   169:             if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
1.36      raeburn   170:                (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.49      bisitz    171:                                                 '/'.$group))) {
1.36      raeburn   172:                  &print_end_page($r,$target);
1.49      bisitz    173:                  return OK;
1.36      raeburn   174:             }
                    175:         }
                    176:     } else {
                    177:         $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23      sakharuk  178:     }
1.1       www       179: 
1.49      bisitz    180:     if ($forcestudent or $target eq 'tex') { $allowed=0; }
                    181: 
                    182:     if (($env{'form.uploaddoc.filename'}) &&
                    183:         ($env{'form.storeupl'}) && ($allowed)) {
                    184:         if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
                    185:             if ($syllabus{'uploaded.photourl'}) {
                    186:                 &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
                    187:             }
                    188:             if ($group ne '') {
                    189:                 $syllabus{'uploaded.photourl'}=
1.62      raeburn   190:                     &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.49      bisitz    191:                                                     'bulletin/'.$group.'/'.$marker);
                    192:             } else {
                    193:                 $syllabus{'uploaded.photourl'}=
1.62      raeburn   194:                     &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.38      raeburn   195:                                                       'bulletin/'.$marker);
1.49      bisitz    196:             }
                    197:         }
                    198:         $syllabus{'uploaded.lastmodified'}=time;
                    199:         &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    200:     }
                    201:     if (($allowed) && ($env{'form.storesyl'})) {
                    202:         foreach my $syl_field (keys(%syllabusfields)) {
                    203:             my $field=$env{'form.'.$syl_field};
                    204:             $field=~s/\s+$//s;
                    205:             $field=&Apache::lonfeedback::clear_out_html($field,1);
                    206:             $syllabus{$syl_field}=$field;
                    207:         }
                    208:         $syllabus{'uploaded.lastmodified'}=time;
                    209:         &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
                    210:     }
1.1       www       211: 
1.54      wenzelju  212: # ---------------------------------------------------------------- Get discussion board
1.1       www       213:     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.56      wenzelju  214:         #Print Topic as Heading
1.57      faziophi  215:         my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
1.56      wenzelju  216:         if ($target ne 'tex') {
                    217:             $r->print('<h2>'.$titletext.'</h2>');
                    218:         } else {
                    219:             $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$titletext).'}\\\\');
                    220:         }
                    221:         #Outputbox and Inputbox for Topic
                    222:         if ($allowed) {
                    223:             $r->print('<form method="post" action="" enctype="multipart/form-data">');
1.57      faziophi  224:             &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
                    225:             $r->print($titletext);
                    226: 			$r->print("<br /><div>");
                    227: 			&Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
                    228: 				'aaa_title', Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
                    229: 			&Apache::lontemplate::print_saveall_template($r);
                    230: 			$r->print("</div>");
                    231: 			&Apache::lontemplate::print_end_template($r);
1.56      wenzelju  232:         }
1.49      bisitz    233:         if ($syllabus{'uploaded.photourl'}) {
                    234:             &Apache::lonnet::allowuploaded('/adm/syllabus',
                    235:                                            $syllabus{'uploaded.photourl'});
                    236:         }
1.53      wenzelju  237:         #Outputbox and Inputbox for Image upload
1.49      bisitz    238:         if ($allowed) {
1.57      faziophi  239:         	my $message = '<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>';
                    240:         	&Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
                    241:             $r->print($message);
                    242:             $r->print("<br /><br />");
1.49      bisitz    243:             $r->print(
1.64    ! raeburn   244:                 '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'.
1.49      bisitz    245:                 '<input type="file" name="uploaddoc" size="50" />'.
1.64    ! raeburn   246:                 '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />');
1.57      faziophi  247:             &Apache::lontemplate::print_end_template($r);
1.49      bisitz    248:         }
1.53      wenzelju  249:         #Image in Student view.
                    250:         elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
1.55      wenzelju  251:             $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
1.53      wenzelju  252:         }
1.58      faziophi  253:         
                    254:         my %custom_handlers = ( 'aaa_title' => sub {} );
1.61      raeburn   255: 		&Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields, 
1.58      faziophi  256: 			$target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
1.49      bisitz    257:         if ($allowed) {
1.63      raeburn   258:             $r->print('</form>');
1.49      bisitz    259:         }
1.54      wenzelju  260:         if ($target ne 'tex'){
                    261:             $r->print('<br/><br/><hr/><br/>');
                    262:         }
                    263:         else {
                    264:             $r->print(&Apache::lonxml::xmlparse($r,'tex','<br/><br/><hr/><br/>'));
                    265:         }
1.1       www       266:     } else {
1.60      www       267:         if ($target ne 'tex') {
                    268:            $r->print('<p>'.&mt('No page information provided.').'</p>');
                    269:         }
1.1       www       270:     }
1.53      wenzelju  271:     #Lists discussion posts and box for a new discussion post.
1.23      sakharuk  272:     if ($target ne 'tex') {
1.49      bisitz    273:         $r->print(&Apache::lonfeedback::list_discussion
                    274:                       ('board','OPEN','bulletin___'.$marker.'___'.
                    275:                        $r->uri,undef,$group));
1.23      sakharuk  276:     } else {
1.49      bisitz    277:         $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
                    278:                      ('board','OPEN','bulletin___'.$marker.'___'.
                    279:                       $r->uri,undef,$group)));
1.23      sakharuk  280:     }
1.36      raeburn   281:     &print_end_page($r,$target);
                    282:     return OK;
                    283: }
                    284: 
                    285: sub print_end_page {
                    286:     my ($r,$target) = @_;
1.32      albertel  287:     if ($target ne 'tex') {
1.36      raeburn   288:         $r->print(&Apache::loncommon::end_page());
1.32      albertel  289:     } else {
1.36      raeburn   290:         $r->print('\end{document}');
1.32      albertel  291:     }
1.36      raeburn   292: }
                    293: 
                    294: sub groupboard_breadcrumbs {
1.37      raeburn   295:     my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
                    296:         $boardtitle)= @_;
1.36      raeburn   297:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.64    ! raeburn   298:     my $brcrum = [];
1.37      raeburn   299:     if ($refarg ne '') {
1.64    ! raeburn   300:         push(@{$brcrum},
        !           301:               {href=>"/adm/coursegroups",
        !           302:                text=>"Groups",
        !           303:                title=>"View course groups"});
        !           304:     }
        !           305:     push(@{$brcrum},
        !           306:            {href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
        !           307:             text=>"$ucgpterm: $description",
        !           308:             title=>"Go to group's home page"},
        !           309:            {href=>"/adm/groupboards?group=$group&amp;$refarg",
        !           310:             text=>"Discussion Boards",
        !           311:             title=>"Display group discussion boards"},
        !           312:            {href=>"$boardurl",
        !           313:             text=>"$boardtitle",
        !           314:             title=>"$boardtitle"},
1.36      raeburn   315:         );
1.64    ! raeburn   316:     return $brcrum;
1.36      raeburn   317: }
1.1       www       318: 
                    319: 1;
                    320: __END__

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