Annotation of loncom/interface/groupboards.pm, revision 1.23

1.1       raeburn     1: # The LearningOnline Network
                      2: # Group Bulletin Boards Manager
                      3: #
1.23    ! raeburn     4: # $Id: groupboards.pm,v 1.22 2016/02/26 21:44:39 raeburn Exp $
1.14      bisitz      5: #
1.1       raeburn     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::groupboards;
1.2       albertel   30: 
1.1       raeburn    31: use strict;
                     32: use Apache::Constants qw(:common :http);
1.10      albertel   33: use Apache::loncommon();
1.1       raeburn    34: use Apache::lonnet;
1.10      albertel   35: use Apache::lonuserstate();
1.22      raeburn    36: use Apache::longroup;
                     37: use Apache::lonnavmaps;
1.10      albertel   38: use LONCAPA::map();
1.1       raeburn    39: use Apache::lonlocal;
                     40: use LONCAPA;
                     41: 
                     42: sub handler {
                     43:     my ($r) = @_;
                     44:     &Apache::loncommon::content_type($r,'text/html');
                     45:     $r->send_http_header;
                     46:     return OK if $r->header_only;
                     47: 
                     48:     #  Needs to be in a course
                     49:     if (! ($env{'request.course.fn'})) {
                     50:         # Not in a course
                     51:         $env{'user.error.msg'}=
                     52:      "/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
                     53:         return HTTP_NOT_ACCEPTABLE;
                     54:     }
                     55: 
                     56:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.7       raeburn    57:                         ['group','ref']);
1.1       raeburn    58: 
                     59:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     60:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                     61:     my $now = time;
                     62:     my $crstype = &Apache::loncommon::course_type();
                     63:     my $gpterm =  &Apache::loncommon::group_term();
1.5       raeburn    64:     my $ucgpterm = $gpterm;
                     65:     $ucgpterm =~ s/^(\w)/uc($1)/e;
1.13      schafran   66:     my $bodytitle = $ucgpterm.' Discussion Boards';
1.1       raeburn    67:     my $group = $env{'form.group'};
1.5       raeburn    68:     $group =~ s/\W//g;
1.7       raeburn    69:     my ($description,$earlyout,$refarg);
                     70: 
                     71:     if (exists($env{'form.ref'})) {
                     72:         $refarg = 'ref='.$env{'form.ref'};
                     73:     }
1.5       raeburn    74: 
                     75:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.1       raeburn    76:     if (!defined($group)) {
1.21      raeburn    77:         $earlyout = &mt("No $gpterm defined, so there are no $gpterm discussion boards to display");
1.5       raeburn    78:         $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7       raeburn    79:                                  $ucgpterm,$bodytitle,$earlyout,$refarg));
1.5       raeburn    80:         return OK;
                     81:     }
                     82:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
                     83:     if (!defined($curr_groups{$group})) {
1.8       raeburn    84:         $earlyout = &mt('Invalid group');
1.5       raeburn    85:         $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7       raeburn    86:                                  $ucgpterm,$bodytitle,$earlyout,$refarg));
1.1       raeburn    87:         return OK;
                     88:     }
1.5       raeburn    89:     my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
1.6       albertel   90:     $description = &unescape($content{'description'});
1.5       raeburn    91: 
1.1       raeburn    92:     my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                     93:                                             '/'.$group);
1.7       raeburn    94:     my $can_view = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.5       raeburn    95: 
                     96:     if (!$can_view) {
1.7       raeburn    97:         $can_view = &Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.1       raeburn    98:                                           '/'.$group);
1.5       raeburn    99:     }
                    100:     if (!$can_view) {
1.21      raeburn   101:         $earlyout=&mt("You do not have privileges to view discussion boards in this $gpterm");
1.5       raeburn   102:         $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7       raeburn   103:                                  $ucgpterm,$bodytitle,$earlyout,$refarg));
1.5       raeburn   104:         return OK;
                    105:     }
1.1       raeburn   106:     if (defined($env{'form.newbul'})) {
                    107:         if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
1.5       raeburn   108:             $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
1.7       raeburn   109:                                      $ucgpterm,$bodytitle,$refarg));
1.16      raeburn   110:             my ($outcome,$newurl,$bbtitle,$lockfreed) = 
1.2       albertel  111: 		&create_board($cdom,$cnum,$group,$env{'form.newbul'});
1.1       raeburn   112:             if ($outcome eq 'ok') {
                    113:                 my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.18      bisitz    114:                 $r->print(&mt('The new discussion board was added successfully.').'<br />');
1.1       raeburn   115:                 $r->print('<table border="0"><tr><td>'.
1.7       raeburn   116:                           '<a href="'.$newurl.'?group='.$group.'&amp;'.$refarg.
                    117:                           '">'.&mt('Edit [_1] board',$bbtitle).'</a></td>'.
1.1       raeburn   118:                            '<td>&nbsp;&nbsp;</td><td>'.
1.7       raeburn   119:                           '<a href="/adm/groupboards?group='.$group.'&amp;'.
                    120:                           $refarg.'">'.&mt('View all group discussion boards').
1.1       raeburn   121:                           '</a></td></tr></table>');
1.16      raeburn   122:                 if ($lockfreed ne 'ok') {
                    123:                     $r->print(&mt('There was a problem removing a lockfile for the group ([_1]).',$description).'<br />'.
1.20      bisitz    124:                               &mt('This may prevent creation of additional discussion boards in this group.').'<br />'.
1.19      raeburn   125:                               &mt('Please contact the [_1]helpdesk[_2] for assistance.',
                    126:                                   '<a href="/adm/helpdesk">','</a>')
                    127:                              );
1.8       raeburn   128:                 }
1.1       raeburn   129:             } else {
1.2       albertel  130:                 $r->print(&mt('There was a problem creating the new discussion board - [_1]','<span class="LC_error">'.$outcome.'</span>').'<br /><a href="/adm/groupboards?group='.$group.'">'.
1.1       raeburn   131:                          &mt('Return to discussion boards').'</a>');
                    132:             }
                    133:             $r->print(&Apache::loncommon::end_page());
                    134:             return OK;
                    135:         }
                    136:     }
                    137:     my $jscript;
                    138:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
                    139:         $jscript = qq|
1.5       raeburn   140: <script type="text/javascript">
1.1       raeburn   141: function makebulboard() {
                    142:    var title=prompt('Discussion Board Title');
                    143:    if (title) {
1.8       raeburn   144:     this.document.forms.newbb.newbul.value=title;
1.1       raeburn   145:     this.document.forms.newbb.submit();
                    146:    }
                    147: }
1.5       raeburn   148: </script>
1.1       raeburn   149: |;
                    150:     }
1.5       raeburn   151:     $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,
1.7       raeburn   152:                              $bodytitle,$refarg,$jscript));
1.4       raeburn   153:     my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum,
                    154:                                                                     $group);
1.1       raeburn   155:     if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
1.5       raeburn   156:         $r->print('<br /><form method="post" name="newbb" action="/adm/groupboards">'.
1.1       raeburn   157:                   "\n".'<input type="button" name="bbbutton" value="'.
                    158:                   &mt('New Discussion Board').
1.17      bisitz    159:                   '" onclick="javascript:makebulboard();" />'."\n".
1.7       raeburn   160:                   '<input type="hidden" name="newbul" />'."\n".
                    161:                   '<input type="hidden" name="group" value="'.$group.'" />'.
                    162:                   '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'.
1.1       raeburn   163:                   "\n".'</form><br />');
                    164:     }
1.4       raeburn   165:     if (@{$groupboards} > 0) {
1.12      bisitz    166:         $r->print('<br />'
                    167:                  .&Apache::loncommon::start_data_table()
                    168:                  .&Apache::loncommon::start_data_table_header_row()
                    169:                  .'<th>'.&mt('Discussion Boards').'</th>'
                    170:                  .&Apache::loncommon::end_data_table_header_row()
                    171:         );
1.4       raeburn   172:         foreach my $board (@{$groupboards}) {
1.5       raeburn   173:             my $board_url = $$boards{$board}{'url'};
                    174:             if ($board_url =~ /\?/) {
                    175:                 $board_url .= '&amp;group='.$group;
                    176:             } else {
                    177:                 $board_url .= '?group='.$group;
                    178:             }
1.12      bisitz    179:             $r->print(&Apache::loncommon::start_data_table_row()
                    180:                      .'<td>'
                    181:                      .'<a href="'.$board_url.'&amp;'.$refarg.'">'
                    182:                      .$$boards{$board}{'title'}.'</a>'
                    183:                      .'</td>'
                    184:                      .&Apache::loncommon::end_data_table_row()
                    185:             );
1.1       raeburn   186:         }
1.12      bisitz    187:         $r->print(&Apache::loncommon::end_data_table());
1.1       raeburn   188:     } else {
1.12      bisitz    189:         $r->print('<p class="LC_info">'
                    190:                  .&mt('There are currently no discussion boards in this '.$gpterm.'.',)
                    191:                  .'</p>'
                    192:         );
1.1       raeburn   193:     }
                    194:     $r->print(&Apache::loncommon::end_page());
                    195:     return OK;
                    196: }
                    197: 
                    198: sub create_board {
1.8       raeburn   199:     my ($cdom,$cnum,$group,$bbtitle) = @_;
1.16      raeburn   200:     my ($outcome,$newurl,$idtype);
1.8       raeburn   201:     $bbtitle=&unescape($bbtitle);
1.16      raeburn   202:     $idtype = 'inc';
                    203:     my ($boardid,$dellock,$error) = 
                    204:         &Apache::lonnet::get_timebased_id($group,'boardids','groupboards',
                    205:                                           $cdom,$cnum);
                    206:     if ($boardid) {
                    207:          $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.'/bulletinboard';
1.8       raeburn   208:     } else {
1.16      raeburn   209:          return ($error,$newurl,$bbtitle,$dellock);
1.8       raeburn   210:     }
1.16      raeburn   211: 
1.8       raeburn   212:     # need to check here if group_boards_$group.sequence is in the course
                    213:     # if not - add it as an item in group_folder_$group.sequence 
1.4       raeburn   214:     my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
1.1       raeburn   215:     if ($allbbsmap =~ m|^/uploaded|) {
1.10      albertel  216:         my ($errtext,$fatal)=&LONCAPA::map::mapread($allbbsmap);
1.1       raeburn   217:         if (!$fatal) {
1.10      albertel  218:             my $newidx=&LONCAPA::map::getresidx($newurl);
                    219:             $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl.
1.1       raeburn   220:                                                    ':false:normal:res';
1.10      albertel  221:             push(@LONCAPA::map::order,$newidx);
1.15      raeburn   222:             my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1,1);
1.1       raeburn   223:             if ($fatal) {
1.11      albertel  224:                 $outcome = "error: failed to save discussion boards map - $errtext\n";
1.1       raeburn   225:             } else {
1.5       raeburn   226:                 my %boardinfo = (
                    227:                   'group' => $group,
                    228:                 );
                    229:                 $outcome = &Apache::lonnet::put('bulletinpage_'.$boardid,
                    230:                                                 \%boardinfo,$cdom,$cnum);
1.1       raeburn   231:             }
                    232:         } else {
1.2       albertel  233:             $outcome = "error: failed to read all discussion boards map - $errtext\n";
1.1       raeburn   234:         }
                    235:     } else {
1.2       albertel  236:         $outcome = 'error: discussion boards folder absent, '.
1.1       raeburn   237:                    'or in unexpected location - '.$allbbsmap."\n";
                    238:     }
1.16      raeburn   239:     return ($outcome,$newurl,$bbtitle,$dellock);
1.1       raeburn   240: }
                    241: 
1.5       raeburn   242: sub display_error {
1.7       raeburn   243:     my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$earlyout,
                    244:         $refarg)=@_;
1.5       raeburn   245:     my $output = &boards_header($cdom,$cnum,$group,$description,$gpterm,
1.7       raeburn   246:                                 $ucgpterm,$bodytitle,$refarg);
1.5       raeburn   247:     $output .= $earlyout;
                    248:     $output .= &Apache::loncommon::end_page();
                    249:     return $output;
                    250: }
                    251: 
                    252: sub boards_header {
1.7       raeburn   253:     my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$refarg,
                    254:         $jscript)=@_;
1.5       raeburn   255:     my $output = &Apache::loncommon::start_page($bodytitle,$jscript);
1.7       raeburn   256:     if ($refarg) {
                    257:         &Apache::lonhtmlcommon::add_breadcrumb
                    258:         ({href=>"/adm/coursegroups",
                    259:           text=>"Groups",
                    260:           title=>"View course groups"},);
                    261:     }
1.22      raeburn   262:     my $view_permission =
                    263:           &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
                    264:     my $navmap=Apache::lonnavmaps::navmap->new();
                    265:     my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
                    266:     if ($grouppagelink) {
                    267:         &Apache::lonhtmlcommon::add_breadcrumb
                    268:             ({href=>$grouppagelink,
1.23    ! raeburn   269:               text=>&mt('Group').": $description",
        !           270:               title=>&mt("Go to group's home page"),
        !           271:               no_mt=>1});
1.22      raeburn   272:     } else {
                    273:         &Apache::lonhtmlcommon::add_breadcrumb
1.23    ! raeburn   274:             ({text=>&mt('Group').": $description",
        !           275:               no_mt=>1});
1.22      raeburn   276:     }
1.5       raeburn   277:     &Apache::lonhtmlcommon::add_breadcrumb
1.22      raeburn   278:          ({href=>"/adm/groupboards?group=$group&amp;$refarg",
1.5       raeburn   279:           text=>"Discussion Boards",
                    280:           title=>"Display group discussion boards"},);
1.23    ! raeburn   281:     $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group discussion boards - [_1]',$description),
        !           282:                                                    undef,undef,undef,undef,1);
1.5       raeburn   283:     return $output;
                    284: }
                    285: 
1.1       raeburn   286: 1;

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