[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf /interface groupboards.pm loncoursegroups.pm doc/loncapafiles loncapafiles.lpml

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 30 Jun 2006 08:14:31 -0000


This is a MIME encoded message

--raeburn1151655271
Content-Type: text/plain

raeburn		Fri Jun 30 04:14:31 2006 EDT

  Added files:                 
    /loncom/interface	groupboards.pm 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom	loncapa_apache.conf 
    /loncom/interface	loncoursegroups.pm 
  Log:
  Display of discussion boards in a group, and the ability for users with board creation privileges in the group to add new boards.  When a group is first created a group folder is created containing the group homepage, and a discussion boards folder is created if discussion is enabled for the group. A "course groups" folder is also appended to the top level map in the course, if it does not already exist. Only works with standard courses which use default.sequence as the top level map. Hidden resource parameter is also applied to course group folders with default as hidden, and unhidden set for corresponding groups. Group bulletin boards use coursedom and coursenum as identifiers (instead of user domain and username as for normal boards) to allow them to be differentiated in lonfeedback.pm.  A locking mechanism should be implemented to make group creation atomic to avoid overwriting of .sequence files if two groups are created within a second of each other in the same course. Also need to address modification to group settings, when discussion functionality is enabled/disabled, as folder may need to be created and/or hidden parameter modified.
  
  
--raeburn1151655271
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060630041431.txt"

Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.487 doc/loncapafiles/loncapafiles.lpml:1.488
--- doc/loncapafiles/loncapafiles.lpml:1.487	Mon Jun 19 06:59:44 2006
+++ doc/loncapafiles/loncapafiles.lpml	Fri Jun 30 04:14:24 2006
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.487 2006/06/19 10:59:44 albertel Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.488 2006/06/30 08:14:24 raeburn Exp $ -->
 
 <!--
 
@@ -3948,6 +3948,15 @@
 <status>works/unverified</status>
 </file>
 <file>
+<source>loncom/interface/groupboards.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/groupboards.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Displays bulletin boards in a group and provides a mechanism for users with board creation privileges in a group to create new bulletin boards.
+</description>
+<status>works/unverified</status>
+</file>
+<file>
 <source>loncom/interface/lonmsg.pm</source>
 <target dist='default'>home/httpd/lib/perl/Apache/lonmsg.pm</target>
 <categoryname>handler</categoryname>
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.142 loncom/loncapa_apache.conf:1.143
--- loncom/loncapa_apache.conf:1.142	Mon Jun 26 16:23:28 2006
+++ loncom/loncapa_apache.conf	Fri Jun 30 04:14:27 2006
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.142 2006/06/26 20:23:28 albertel Exp $
+## $Id: loncapa_apache.conf,v 1.143 2006/06/30 08:14:27 raeburn Exp $
 ##
 
 #
@@ -885,6 +885,17 @@
 ErrorDocument     500 /adm/errorhandler
 </Location>
 
+<Location /adm/groupboards>
+AuthType LONCAPA
+Require valid-user
+PerlAuthzHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::groupboards
+ErrorDocument     403 /adm/login
+ErrorDocument     406 /adm/roles
+ErrorDocument     500 /adm/errorhandler
+</Location>
+
 <Location /adm/whatsnew>
 AuthType LONCAPA
 Require valid-user
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.31 loncom/interface/loncoursegroups.pm:1.32
--- loncom/interface/loncoursegroups.pm:1.31	Thu Jun 29 23:33:50 2006
+++ loncom/interface/loncoursegroups.pm	Fri Jun 30 04:14:31 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.31 2006/06/30 03:33:50 albertel Exp $
+# $Id: loncoursegroups.pm,v 1.32 2006/06/30 08:14:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3050,9 +3050,12 @@
 
     if ($result eq 'ok') {
         if ($action eq 'create') {
-            my $put_result = &create_homepage($cdom,$cnum,$groupname,
-                                              \%groupinfo,$tools,$gpterm,
-                                              $ucgpterm);
+            my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
+                                           $description,$tools,\%groupinfo,
+                                           $gpterm,$ucgpterm,$crstype);
+            if ($result ne 'ok') {
+                $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].',$gpterm,$result));    
+            }
             $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
         } else {
             $r->print(&mt('[_1] [_2] was updated.<br />',$ucgpterm,$groupname));
@@ -3578,8 +3581,159 @@
     return ($start_table, $end_table);
 }
 
+sub add_group_folder {
+    my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
+        $gpterm,$ucgpterm,$crstype) = @_;
+    if ($cdom eq '' || $cnum eq '') {
+        return &mt('Error: invalid course domain or number - group folder creation failed');  
+    }
+    my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
+    $allgrpsmap = $crspath.'default_0.sequence';
+    my $topmap = $navmap->getResourceByUrl($allgrpsmap);
+    undef($navmap);
+    if ($action eq 'create') {
+    # check if default_0.sequence exists.
+        if (!$topmap) {
+            my $grpstitle = &mt('[_1] [_2]',$crstype,$ucgpterm);
+            my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
+            $topmap_url =~ s|/+|/|g;
+            if ($topmap_url =~ m|^/uploaded|) {
+                $outcome = &map_updater($cdom,$cnum,'default_0.sequence',
+                                        'toplevelgroup',$grpstitle,$topmap_url);
+                if ($outcome ne 'ok') {
+                    return $outcome;
+                }
+            } else {
+                $outcome = &mt('Non-standard course - group folder not added.');
+                return $outcome;
+            }
+        }
+        my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
+        $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/grppg';
+        my $grptitle = &mt('Group homepage').' - '.$description;
+        my ($seqid,$discussions,$disctitle);
+        my $outcome = &map_updater($cdom,$cnum,'default_'.$now.'.sequence',
+                                   'grpseq',$grpfolder,$allgrpsmap,$grppage,
+                                   $grptitle);
+        if ($outcome ne 'ok') {
+            return $outcome;
+        }
+        my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
+                                       $tools,$gpterm,$ucgpterm,$now);
+        # Link to folder for bulletin boards
+        $grpmap = $crspath.'default_'.$now.'.sequence';
+        if (grep/^discussion$/,@{$tools}) {
+            $seqid = $now + 1;
+            $disctitle = &mt('Discussion Boards');
+            my $outcome = &map_updater($cdom,$cnum,'default_'.$seqid.
+                                       '.sequence','bbseq',$disctitle,$grpmap);
+            if ($outcome ne 'ok') {
+                return $outcome;
+            }
+            $boardsmap = $crspath.'default_'.$seqid.'.sequence';
+        }
+    } else {
+        #modify group folder if status of discussions tools is changed
+    }
+    my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+    my $navmap = Apache::lonnavmaps::navmap->new();
+    # modify parameters
+    my $parm_result;
+    if ($action eq 'create') {
+        if ($allgrpsmap) { 
+            $parm_result .= &parm_setter($navmap,$cdom,$allgrpsmap,$groupname);
+        }
+        if ($grpmap) {
+            $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
+        }
+        if ($grppage) {
+            $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
+        }
+        if ($boardsmap) {
+            $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
+        }
+    }
+    if ($parm_result) {
+        return $parm_result;
+    } else {
+        return 'ok';
+    }
+}
+
+sub map_updater {
+    my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
+        $starttitle,$endsrc,$endtitle) = @_;
+    my $outcome;
+    $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
+                                       $endtitle);
+    my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
+                                                        $newfile);
+    if ($newmapurl !~ m|^/uploaded|) {
+        $outcome = "Error uploading new folder ($newfile): $newmapurl";
+        return $outcome;
+    } 
+    my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
+    if ($fatal) {
+        $outcome = "Error reading contents of parent folder ($parentmap): $errtext\n";
+        return $outcome;
+    } else {
+        my $newidx=&Apache::lonratedt::getresidx($newmapurl);
+        $Apache::lonratedt::resources[$newidx] = $itemtitle.':'.$newmapurl.
+                                                 ':false:normal:res';
+        $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
+        my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
+        if ($errtext) {
+           $outcome = "Error storing updated parent folder ($parentmap):  $errtext\n";
+            return $outcome;
+        }
+    }
+    return 'ok';
+}
+
+sub new_map {
+    my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
+    my $newmapstr = '
+<map>
+ <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
+ <link from="1" to="2" index="1"></link>
+ <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
+</map>
+';
+    return $newmapstr;
+}
+
+sub parm_setter {
+    my ($navmap,$cdom,$url,$groupname) = @_;
+    my %parmresult;
+    my %hide_settings = (
+                           'course' =>  {
+                                          'num' => 13,
+                                          'set' => 'yes',
+                                        },
+                            'group' =>  {
+                                          'num' => 5,
+                                          'set' => 'no',
+                                          'extra' => $groupname,
+                                        },
+                        );
+    my $res = $navmap->getResourceByUrl($url);
+    my $symb = $res->symb();
+    foreach my $level (keys(%hide_settings)) {
+        $parmresult{$level} =  &Apache::lonparmset::storeparm_by_symb($symb,
+                                                 '0_hiddenresource',
+                                                 $hide_settings{$level}{'num'},
+                                                 $hide_settings{$level}{'set'},
+                                                 'string_yesno',undef,$cdom,
+                                                 undef,undef,
+                                                 $hide_settings{$level}{'extra'});
+    }
+    return %parmresult;
+}
+
 sub create_homepage {
-    my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm) = @_;
+    my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
     my $functionality = join(',',@{$tools});
     my $content = &unescape($$groupinfo{description});
     $content=~s/\s+$//s;
@@ -3592,7 +3746,7 @@
                      'abb_links' => $functionality,
                      'bbb_content' => $content,
                      'ccc_webreferences' => '',
-                     'uploaded.lastmodified' => time,
+                     'uploaded.lastmodified' => $now,
                    );
    my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
    return $putresult;

Index: loncom/interface/groupboards.pm
+++ loncom/interface/groupboards.pm
# The LearningOnline Network
# Group Bulletin Boards Manager
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

package Apache::groupboards;
                                                                                
use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon;
use Apache::lonnet;
use Apache::lonnavmaps;
use Apache::lonuserstate;
use Apache::lonratedt;
use Apache::lonlocal;
use LONCAPA;

sub handler {
    my ($r) = @_;
    &Apache::loncommon::content_type($r,'text/html');
    $r->send_http_header;
    return OK if $r->header_only;

    #  Needs to be in a course
    if (! ($env{'request.course.fn'})) {
        # Not in a course
        $env{'user.error.msg'}=
     "/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
        return HTTP_NOT_ACCEPTABLE;
    }

    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                        ['group']);

    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
    my $now = time;
    my $crstype = &Apache::loncommon::course_type();
    my $gpterm =  &Apache::loncommon::group_term();
    my $bodytitle = &mt('[_1] Discussion Boards',$crstype);
    my $group = $env{'form.group'};
    if (!defined($group)) {
        $r->print(&Apache::loncommon::start_page($bodytitle));
        $r->print(&mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm));
        $r->print(&Apache::loncommon::end_page());
        return OK;
    }
    my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
                                            '/'.$group);
    my $can_view=&Apache::lonnet::allowed('pgd',$env{'request.course.id'}.
                                          '/'.$group);
    if (defined($env{'form.newbul'})) {
        if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
            $r->print(&Apache::loncommon::start_page($bodytitle));
            my ($outcome,$symb,$newurl,$bbtitle) = &create_board($cdom,$cnum,
                                                                 $group,
                                                          $env{'form.newbul'});
            if ($outcome eq 'ok') {
                my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                $r->print(&mt('The new discussion board was added successfully.<br />'));
                $r->print('<table border="0"><tr><td>'.
                          '<a href="'.$newurl.'?register=1&symb='.$symb.
                          '&group='.$group.'">'.
                          &mt('Edit [_1] board',$bbtitle).'</a></td>'.
                           '<td>&nbsp;&nbsp;</td><td>'.
                          '<a href="/adm/groupboards?group='.$group.'">'.
                          &mt('View all group discussion boards').
                          '</a></td></tr></table>');
            } else {
                $r->print(&mt('There was a problem creating the new discussion board - [_1]',$outcome).'<br /><a href="/adm/groupboards?group='.$group.'">'.
                         &mt('Return to discussion boards').'</a>');
            }
            $r->print(&Apache::loncommon::end_page());
            return OK;
        }
    }
    my $jscript;
    if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
        $jscript = qq|
function makebulboard() {
   var title=prompt('Discussion Board Title');
   if (title) {
    this.document.forms.newbb.newbul.value=
        title+'=/adm/$cdom/$cnum/$now/bulletinboard';
    this.document.forms.newbb.submit();
   }
}
|;
    }
    $r->print(&Apache::loncommon::start_page($bodytitle,
                                       '<script type="text/javascript">'.
                                       $jscript.'</script>'));
    if (!$can_view) {
        $r->print(&mt('You do not have privileges to view discussion boards in this [_1]',$crstype));
        return OK;
    }
    my $navmap = Apache::lonnavmaps::navmap->new();
    my @groupboards;
    my %boards;
    my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group);
    if ($grpbbmap) {
        my $bbfolderres = $navmap->getResourceByUrl($grpbbmap);
        if ($bbfolderres) {
            my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0);
            foreach my $res (@boards) {
                my $url = $res->src();
                my $title = $res->title();
                my $symb = $res->symb();
                if ($url =~ m|^/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard|) {
                    push(@groupboards,$symb);
                    %{$boards{$symb}} = (
                                        title => $title,
                                        url => $url,
                                     );
                }
            }
        }
    }
    if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
        $r->print('<form method="post" name="newbb" action="/adm/groupboards">'.
                  "\n".'<input type="button" name="bbbutton" value="'.
                  &mt('New Discussion Board').
                  '" onClick="javascript:makebulboard();" />'."\n".
                  '  <input type="hidden" name="newbul" />'."\n".
                  '  <input type="hidden" name="group" value="'.$group.'" />'.
                  "\n".'</form><br />');
    }
    if (@groupboards) {
        foreach my $board (@groupboards) {
            $r->print('<a href="'.$boards{$board}{'url'}.'?register=1&symb='.$board.'&group='.$group.'">'.$boards{$board}{'title'}.'</a><br />');
        }
    } else {
        $r->print(&mt('There are currently no discussion boards in this [_1].',
                      $gpterm));
    }
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

sub create_board {
    my ($cdom,$cnum,$group,$newboard,$symb) = @_;
    my ($bbtitle,$newurl)=split(/\=/,$newboard);
    $bbtitle=&unescape($bbtitle);
    $newurl=&unescape($newurl);
    my $allbbsmap = &get_bbfolder_url($cdom,$cnum,$group);
    my ($outcome,$symb);
    if ($allbbsmap =~ m|^/uploaded|) {
        my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap);
        if (!$fatal) {
            my $newidx=&Apache::lonratedt::getresidx($newurl);
            $Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl.
                                                   ':false:normal:res';
            $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
            my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1);
            if ($fatal) {
                $outcome = "Error: failed to store discussion boards map - $errtext\n";
            } else {
                $outcome = 'ok';
                $symb = &Apache::lonnet::encode_symb($allbbsmap,$newidx,$newurl);
            }
        } else {
            $outcome = "Error: failed to read all discussion boards map - $errtext\n";
        }
    } else {
        $outcome = 'Error: discussion boards folder absent, '.
                   'or in unexpected location - '.$allbbsmap."\n";
    }
    return ($outcome,$symb,$newurl,$bbtitle);
}

sub get_bbfolder_url {
    my ($cdom,$cnum,$group) = @_;
    my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
    my $grpbbmap;
    if (%curr_groups) {
        my %group_info =  &Apache::longroup::get_group_settings(
                                                    $curr_groups{$group});
        my $creation = $group_info{'creation'};
        my $bbfolder = $creation + 1;
        my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
        $grpbbmap = $crspath.'default_'.$bbfolder.'.sequence';
    }
    return $grpbbmap;
}

1;

--raeburn1151655271--