--- loncom/interface/lonwhatsnew.pm	2009/02/18 19:34:08	1.87
+++ loncom/interface/lonwhatsnew.pm	2012/05/10 19:01:40	1.105.2.1
@@ -1,5 +1,5 @@
 #
-# $Id: lonwhatsnew.pm,v 1.87 2009/02/18 19:34:08 schafran Exp $
+# $Id: lonwhatsnew.pm,v 1.105.2.1 2012/05/10 19:01:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -42,6 +42,7 @@ use Time::Local;
 use GDBM_File;
 use lib '/home/httpd/lib/perl/';
 use LONCAPA;
+use HTML::Entities;
 
 #----------------------------
 # handler
@@ -87,7 +88,7 @@ sub handler {
 
     if ( ! $env{'request.course.fn'} || ! $checkallowed{'whatsnew'}) {
         # Not in a course, or no whn priv in course
-        $env{'user.error.msg'}="/adm/whatsnew::whn:0:0:Cannot display what's new page";
+        $env{'user.error.msg'}="/adm/whatsnew:whn:0:0:Cannot display what's new page";
         return HTTP_NOT_ACCEPTABLE;
     }
 
@@ -99,7 +100,7 @@ sub handler {
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/whatsnew',
-              text=>"Display Action Items"});
+              text=>"What's New?"});
     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
@@ -194,7 +195,7 @@ sub display_main_box {
     );
     my %initpage = &Apache::lonlocal::texthash (
                      firstres => "first resource in the $lctype",
-                     whatsnew => "what's new? page",
+                     whatsnew => "What's New Page",
                      userpref => 'your general user preferences',
                      coursespecific => "specific setting for this $lctype",
                    );
@@ -267,7 +268,7 @@ END
 ';
     }
     my $course_type=&Apache::loncommon::course_type();
-    return &Apache::loncommon::start_page($course_type.' Action Items',
+    return &Apache::loncommon::start_page("What's New?",
 					  $scripttag);
 }
 
@@ -288,7 +289,7 @@ sub display_actions_box {
     my $lctype = lc($crstype);
     my %stulabel = (
                     'Course' => 'students',
-                    'Group' => 'members',
+                    'Community' => 'members',
                    );
     my %lt = &Apache::lonlocal::texthash(
                  'yacc' => 'You are accessing an invalid course',
@@ -327,7 +328,7 @@ sub display_actions_box {
     my %threshold = ();
     my %pagedesc = &Apache::lonlocal::texthash (
                      firstres => 'First resource',
-                     whatsnew => "What's New? page",
+                     whatsnew => "What's New Page",
                      userpref => 'user preference',
                      coursespecific => $lctype.' only',
                      default => 'default',
@@ -341,27 +342,30 @@ sub display_actions_box {
         return;
     }
 
+    my $header = '';
     if ($refpage eq 'start') {
         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
             &GDBM_READER(),0640)) {
-            my $furl=$bighash{'first_url'};
+            my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
             untie(%bighash);
-            $r->print('<span style="font-size: larger;"><a href="'.$furl.'">'.$lt{'gtfr'}.
-                  '</a></span><br />');
+            $header .= '<b><a href="'.$furl.'">'.$lt{'gtfr'}.
+                  '</a></b><br />';
         }
     }
-    $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
+    $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
               .' <span class="LC_nobreak">'
               .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
               .'&nbsp;&nbsp;'
-              .&mt('[_1]Change[_2] for just [_3]this course[_4] or for all [_5]your courses[_6].'
+              .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
                   ,'<b>'
                   ,'</b>'
                   ,'<a href="/adm/whatsnew?command=courseinit&amp;refpage='.$refpage.'">'
                   ,'</a>'
                   ,'<a href="/adm/preferences?action=changecourseinit&amp;refpage='.$refpage.'">'
                   ,'</a>')
-              .' </span><br /><hr />');
+              .' </span>';
+
+    $r->print(&Apache::loncommon::head_subbox($header));
 
     if ($command eq 'reset') {
         $result = &process_reset($cdom,$crs);
@@ -378,12 +382,14 @@ sub display_actions_box {
     unless ($store_result eq 'ok') { 
         &Apache::lonnet::logthis('Error saving whatsnew settings: '.
             $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
-        $result .= &mt('Unable to save visibility settings due to [_1]',
-                       $store_result); 
+        $result .= '<span class="LC_error">'
+                  .&mt('Unable to save visibility settings due to [_1]',
+                       $store_result)
+                  .'</span>';
     }
 
     if ($result) {
-        $r->print($result.'<hr width="100%" />');
+        $r->print($result.'<hr />');
     }
     $r->rflush();
 
@@ -683,7 +689,7 @@ function toggle_countunread(choice) {
     $r->print('<br />'
              .&mt('Choose whether or not to display a count of the number of new posts for each resource or discussion board which has unread posts.')
              .'<br />'
-             .&mt("This can increase the time taken to gather data for the '<i>What's New?</i>' page by a few seconds.")
+             .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'<i>','</i>')
              .'&nbsp;&nbsp;'
              .&mt('Currently set to [_1].','<b>'.$current.'</b>.')
     );
@@ -725,7 +731,7 @@ sub courseinit_config {
                              'anis' => 'and is set to display',
                              'padc' => 'Page display controlled by',
                              'chce' => 'Choose '.$lctype.' entry',
-                             'moce' => 'Modify '.$lctype.' entry',
+                             'moce' => 'Save',
     );
     $r->print(<<"END"); 
 <br />$lt{'chwp'}
@@ -968,6 +974,9 @@ sub check_thresholds {
         if ($resource->handgrade($part) eq 'yes') {
             next;
         }
+        if ($resource->is_anonsurvey($part)) {
+            next;
+        }
         if ($resource->is_survey($part)) {
             next;
         }
@@ -990,6 +999,7 @@ sub check_thresholds {
             $av_attempts = $attempts/$users;
             $av_attempts = sprintf("%.2f",$av_attempts);
         }
+        &Apache::lonnet::statslog($symb,$part,$users,$av_attempts,$degdiff);
         if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) {
             $stats{$part}{degdiff} = $degdiff;
             $stats{$part}{attempts} = $av_attempts;
@@ -1124,7 +1134,7 @@ sub process_reset {
 
 sub process_update {
     my ($uname,$udom,$threshold_titles) = @_;
-    my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br />';
+    my $setoutput = '<b>'.&mt('Changes to threshold(s) for problem tracking:').'</b><br/><br />';
     foreach (keys %env) {
         next if ($_!~/^form\.(.+)\_setparmval$/);
         my $name  = $1;
@@ -1135,17 +1145,17 @@ sub process_update {
            
             my ($shortname) = ($name =~ /^\Q$env{'request.course.id'}\E:threshold_(.+)$/);
             if ($put_result eq 'ok') {
-                $setoutput.=&mt('Set threshold for [_1] to [_2]',
+                $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Set threshold for [_1] to [_2]',
 				'<b>'.$$threshold_titles{$shortname}.'</b>',
-				'<b>'.$value.'</b>').'<br />';
+				'<b>'.$value.'</b>').'<br />');
 	    } else {
-                $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
+                $setoutput.= &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set threshold for [_1] to [_2] due to [_3].',
 				'<b>'.$name.'</b>','<b>'.$value.'</b>',
-				'<tt>'.$put_result.'</tt>').'<br />';
+				'<tt>'.$put_result.'</tt>').'<br />',1);
             }
         }
     }
-    return $setoutput;
+    return &Apache::loncommon::confirmwrapper($setoutput);
 }
 
 sub getnormalmail {
@@ -1160,10 +1170,9 @@ sub getnormalmail {
             &Apache::lonmsg::unpackmsgid($msgid);
         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
             if (defined($sendtime) && $sendtime!~/error/) {
-                my $numsendtime = $sendtime;
-                $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
                 if ($status eq 'new') {
-                    $msgcount ++;
+                $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
+		    $msgcount ++;
                     if ($shortsubj eq '') {
                         $shortsubj = &mt('No subject');
                     }
@@ -1192,7 +1201,6 @@ sub getcritmail {
             &Apache::lonmsg::unpackmsgid($msgid);
         if (($fromcid) && ($fromcid eq  $env{'request.course.id'})) {
             if (defined($sendtime) && $sendtime!~/error/) {
-                my $numsendtime = $sendtime;
                 $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
                 $critmsgcount ++;
                 if ($shortsubj eq '') {
@@ -1427,7 +1435,7 @@ sub checkversions {
                                                      'lastrevisiondate');
                     $revdate =  &Apache::lonlocal::locallocaltime($revdate);
                     my $linkurl=&Apache::lonnet::clutter($key);
-                    my $usedversion=$navmap->usedVersion('version_'.$linkurl);
+                    my $usedversion=$navmap->usedVersion($linkurl);
                     my @resources = $navmap->getResourceByUrl($linkurl,1);
                     if (($usedversion) && ($usedversion ne 'mostrecent')) {
                         $version = $usedversion;     
@@ -1470,9 +1478,9 @@ sub display_handgrade {
             my $linkurl=&Apache::lonnet::clutter($url);
             $linkurl .= '?symb='.&escape($res);
             if ($$ungraded{$res}{'enclink'}) {
-                $linkurl = 
+                $linkurl =
                     $$ungraded{$res}{'enclink'}.'?symb='.$$ungraded{$res}{'encsymb'};
-            } 
+            }
             $r->print('<tr'.$css_class.'><td><a href="'.$linkurl.'">'.$$ungraded{$res}{title}.'</a></td><td class="LC_right_item">'.$$ungraded{$res}{count}.'</td></tr>');
         }
     } elsif ($itemserror) {
@@ -1835,19 +1843,19 @@ sub store_interval_setting {
                                              \%interval_settings,$udom,$uname);
         if ($outcome eq 'ok') {
             if (ref($interval_titles->{$context}) eq 'HASH') {
-                $result = &mt('New filter setting: [_1].','<b>'. 
-                              $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />';
+                $result = &Apache::lonhtmlcommon::confirm_success(&mt('New filter setting: [_1].','<b>'. 
+                              $interval_titles->{$context}->{$env{'form.interval'}}.'</b>').'<br />');
             }
         } else {
 	    my $lctype = lc(&Apache::loncommon::course_type());
             &Apache::lonnet::logthis('Error saving whatsnew '.$context.' interval setting'.
                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
-            $result = &mt('Unable to set interval to [_1] due to [_2].',
+            $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set interval to [_1] due to [_2].',
                          '<b>'.$interval_titles->{$context}->{$env{'form.interval'}}.'</b>',
-                         '<tt>'.$outcome.'</tt>.<br />');
+                         '<tt>'.$outcome.'</tt>'),1);
         }
     }
-    return $result;
+    return &Apache::loncommon::confirmwrapper($result);
 }
 
 sub store_discussion_setting {
@@ -1859,20 +1867,20 @@ sub store_discussion_setting {
         my $outcome = &Apache::lonnet::put('nohist_whatsnew',
                                              \%discussion_settings,$udom,$uname);
         if ($outcome eq 'ok') {
-            $result = &mt('Count unread posts in discussions display set to [_1]',
-                  '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />';
+            $result = &Apache::lonhtmlcommon::confirm_success(&mt('Count unread posts in discussions display set to [_1]',
+                  '<b>'.&mt($env{'form.countunread'}).'</b>').'<br />');
                                                                                   
         } else {
 	    my $lctype = lc(&Apache::loncommon::course_type());
             &Apache::lonnet::logthis('Error saving whatsnew countunread setting'.
                 ' '.$outcome.' for '.$uname.':'.$udom.' in '.$lctype.' '.$cid);
-            $result = &mt('Unable to set "number unread posts display" to [_1]'.
+            $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set "number unread posts display" to [_1]'.
                           ' due to [_2].',
                          '<b>'.&mt($env{'form.countunread'}).'</b>',
-                         '<tt>'.$outcome.'</tt>.<br />');
+                         '<tt>'.$outcome.'</tt>'),1);
         }
     }
-    return $result;
+    return &Apache::loncommon::confirmwrapper($result);
 }
 
 sub store_courseinit_setting {
@@ -1897,30 +1905,29 @@ sub store_courseinit_setting {
                                            \%courseinit_settings,$udom,$uname);
             if ($outcome eq 'ok') {
                 if ($page_control eq 'global preferences') {
-                    $result = &mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'<b>','</b>');
+                    $result = &Apache::lonhtmlcommon::confirm_success(&mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'<b>','</b>'));
                 } else {
-                    $result = &mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
-                                 ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>');
+                    $result = &Apache::lonhtmlcommon::confirm_success(&mt('Page displayed after role selection in this '.$lctype.' set to [_1].'
+                                 ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'));
                 }
             } else {
                 &Apache::lonnet::logthis('Error saving whatsnew courseinit '.
                                          'setting: '.$outcome.' for '.$uname.
                                          ':'.$udom.' in '.$lctype.' '.$cid);
                 if ($page_control eq 'global preferences') {
-                    $result = &mt('Unable to set control of page display to [_1]'.
+                    $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set control of page display to [_1]'.
                           ' due to [_2].',
                          '<b>'.$page_control.'</b>',
-                         '<tt>'.$outcome.'</tt>.<br />');
+                         '<tt>'.$outcome.'</tt>'),1);
                 } else {
-                    $result = &mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
+                    $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].'
                                  ,'<b>'.$$initpage{$env{'form.courseinit_page'}}.'</b>'
-                                 ,'<tt>'.$outcome.'</tt>')
-                             .'<br />';
+                                 ,'<tt>'.$outcome.'</tt>'),1);
                 }
             }
         }
     }
-    return $result;
+    return &Apache::loncommon::confirmwrapper($result);
 }
 
 sub start_box {
@@ -1952,35 +1959,35 @@ sub start_box {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&amp;refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      } elsif ($caller eq 'coursediscussion') {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&amp;refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'newroles') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      }