--- loncom/interface/lonmsgdisplay.pm 2006/11/29 07:46:39 1.44 +++ loncom/interface/lonmsgdisplay.pm 2006/12/07 01:11:38 1.47 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines for messaging display # -# $Id: lonmsgdisplay.pm,v 1.44 2006/11/29 07:46:39 raeburn Exp $ +# $Id: lonmsgdisplay.pm,v 1.47 2006/12/07 01:11:38 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,24 +138,134 @@ my $interdis; sub folderlist { my $folder=shift; - my @allfolders=&Apache::lonnet::getkeys('email_folders'); - if ($allfolders[0]=~/^error:/) { @allfolders=(); } - return '
':''); + ''. + ($folder=~/^(new|critical)/?'':''); + return $output; +} + +sub get_permanent_folders { + my %permfolders = + &Apache::lonlocal::texthash('' => 'INBOX', + 'trash' => 'TRASH', + 'new' => 'New Messages Only', + 'critical' => 'Critical', + 'sent' => 'Sent Messages', + ); + return %permfolders; } sub scrollbuttons { @@ -195,14 +305,123 @@ sub statuschange { # ============================================================= Make new folder sub makefolder { - my ($newfolder)=@_; - if (($newfolder eq 'sent') - || ($newfolder eq 'critical') - || ($newfolder eq 'trash') - || ($newfolder eq 'new')) { return; } - &Apache::lonnet::put('email_folders',{$newfolder => time}); + my ($newfolder) = @_; + my %permfolders = &get_permanent_folders(); + my %userfolders = &Apache::lonmsg::get_user_folders(); + my ($outcome,$warning); + if (defined($userfolders{$newfolder})) { + return &mt('The folder name: "[_1]" is already in use for an existing folder.',$newfolder); + } + foreach my $perm (keys(%permfolders)) { + if ($permfolders{$perm} eq $newfolder) { + return &mt('The folder name: "[_1]" is already used for one of the folders automatically generated by the system.',$newfolder); + } + } + if (&get_msgfolder_lock() eq 'ok') { + my %counter_hash = &Apache::lonnet::get('email_folders',["\0".'idcount']); + my $lastcount = $counter_hash{"\0".'idcount'}; + my $folder_id = $lastcount + 1; + while (defined($userfolders{$folder_id})) { + $folder_id ++; + } + my %folderinfo = ( id => $folder_id, + created => time, ); + $outcome = + &Apache::lonnet::put('email_folders',{$newfolder => \%folderinfo, + "\0".'idcount' => $folder_id}); + my $releaseresult = &release_msgfolder_lock(); + if ($releaseresult ne 'ok') { + $warning = $releaseresult; + } + } else { + $outcome = + &mt('Error - could not obtain lock on email folders record.'); + } + return ($outcome,$warning); +} + +# ============================================================= Delete folder + +sub deletefolder { + my ($folder)=@_; + my %permfolders = &get_permanent_folders(); + if (defined($permfolders{$folder})) { + return &mt('The folder [_1] may not be deleted',$folder); + } + my %userfolders = &Apache::lonmsg::get_user_folders(); + if (!defined($userfolders{$folder})) { + return &mt('The folder [_1] does not exist so deletion is not required.', + $folder); + } + # check folder is empty; + my $suffix=&Apache::lonmsg::foldersuffix($folder); + my @messages = &Apache::lonnet::getkeys('nohist_email'.$suffix); + if (@messages > 0) { + return &mt('The folder [_1] contains messages so it may not be deleted.'). + '');
- my @allfolders=&Apache::lonnet::getkeys('email_folders');
- if ($allfolders[0]=~/^error:/) { @allfolders=(); }
+ my %gotfolders = &Apache::lonmsg::get_user_folders();
+ my %userfolders;
+ foreach my $key (keys(%gotfolders)) {
+ $userfolders{$key} = $key;
+ }
$r->print(
&Apache::loncommon::select_form('','movetofolder',
- ( map { $_ => $_ } @allfolders))
- );
+ %userfolders));
my $postedstartdis=$startdis+1;
$r->print('');
if ($numblocked > 0) {
my $beginblock = &Apache::lonlocal::locallocaltime($startblock);
my $finishblock = &Apache::lonlocal::locallocaltime($endblock);
$r->print('
'.
- $numblocked.' '.&mt('message(s) is/are not viewable because display of LON-CAPA messages sent to you by other students between').' '.$beginblock.' '.&mt('and').' '.$finishblock.' '.&mt('is currently being blocked because of online exams.'));
+ &mt('[_1,quant,message is, messages are] not viewable because display of LON-CAPA messages sent to you by other students between [_2] and [_3] is currently being blocked because of online exams.',$numblocked,$beginblock,$finishblock));
$r->print(&Apache::loncommon::build_block_table($startblock,$endblock,
\%setters));
}
@@ -1598,9 +1813,10 @@ sub blocktype_text {
'chat' => 'Chat',
'boards' => 'Discussion',
'port' => 'Portfolio',
- 'groups' => 'Groups'
+ 'groups' => 'Groups',
+ 'blogs' => 'Blogs',
);
- my $typeorder = ['com','chat','boards','port','groups'];
+ my $typeorder = ['com','chat','boards','port','groups','blogs'];
return ($typeorder,\%types);
}
@@ -2213,11 +2429,43 @@ sub handler {
}
} elsif ($env{'form.newfolder'}) {
&printheader($r,'','New Folder');
- &makefolder($env{'form.newfolder'});
- &Apache::loncommunicate::menu($r);
- &disall($r,$env{'form.newfolder'});
+ my $showfolder = $env{'form.newfolder'};
+ my ($makeresult,$warning) = &makefolder($env{'form.newfolder'});
+ if ($makeresult eq 'ok') {
+ $r->print(&mt('Mail folder "[_1]" created.',$showfolder).'
');
+ } else {
+ $r->print(&mt('Creation failed.').' '.$makeresult.'
'.
+ $warning);
+ $showfolder = $folder;
+ }
+ &Apache::loncommunicate::menu($r);
+ &disall($r,$showfolder);
} elsif ($env{'form.showcommentbaseurl'}) {
&storedcommentlisting($r);
+ } elsif ($env{'form.folderaction'} eq 'delete') {
+ &printheader($r,'','Deleted Folder');
+ my $showfolder = '';
+ my $delresult = &deletefolder($folder);
+ if ($delresult eq 'ok') {
+ $r->print(&mt('Mail folder "[_1]" deleted.',$folder).'
');
+ } else {
+ $r->print(&mt('Deletion failed.').' '.$delresult.'
');
+ $showfolder = $folder;
+ }
+ &Apache::loncommunicate::menu($r);
+ &disall($r,$showfolder);
+ } elsif ($env{'form.folderaction'} eq 'rename') {
+ &printheader($r,'','Renamed Folder');
+ my $showfolder = $env{'form.renamed'};
+ my $renresult = &renamefolder($folder);
+ if ($renresult eq 'ok') {
+ $r->print(&mt('Mail folder "[_1]" renamed "[_2]".',$folder,$showfolder).'
');
+ } else {
+ $r->print(&mt('Renaming failed.').' '.$renresult.'
');
+ $showfolder = $folder;
+ }
+ &Apache::loncommunicate::menu($r);
+ &disall($r,$showfolder);
} else {
&printheader($r,'','Display All Messages');
&Apache::loncommunicate::menu($r);